我正在尝试调试单元测试;在5943号呼叫memcpy_c
时,它应该是恐慌,但不是。为了调试这个,我使用gdb的tracepoint机制来记录来自所有这些调用的数据。
这是我的调试会话:
(gdb) target remote :53268
Remote debugging using :53268
0x00000000004068de in _start ()
(gdb) trace memcpy_c
Tracepoint 1 at 0x402718: file memory.c, line 49.
(gdb) actions
Enter actions for tracepoint 1, one per line.
End with a line saying just "end".
>collect dst, bufsize, src, count
>end
(gdb) break lsc_exit
Breakpoint 2 at 0x406a00
(gdb) tstart
(gdb) continue
Continuing.
Breakpoint 2, 0x0000000000406a00 in lsc_exit ()
(gdb) tstop
我可以获取快照5900的数据:
(gdb) tfind 5900
Found trace frame 5900, tracepoint 1
#0 memcpy_c (dst=0x7fffffffe539, dst@entry=<error reading variable: PC not available>, bufsize=785, bufsize@entry=<error reading variable: PC not available>, src=0x7fffffffe4c8,
src@entry=<error reading variable: PC not available>, count=5, count@entry=<error reading variable: PC not available>) at memory.c:49
49 if (dst == NULL) {
(gdb) tdump
Data collected at tracepoint 1, trace frame 5900:
dst = (void * restrict) 0x7fffffffe539
bufsize = 785
src = (const void * restrict) 0x7fffffffe4c8
count = 5
我无法获取快照5943的数据(我正在尝试调试的最后一个快照):
(gdb) tfind 5943
Found trace frame 5943, tracepoint 1
#0 memcpy_c (dst=<unavailable>, bufsize=<unavailable>, src=<unavailable>, count=<unavailable>) at memory.c:49
49 if (dst == NULL) {
(gdb) tdump
Data collected at tracepoint 1, trace frame 5943:
dst = <unavailable>
bufsize = <unavailable>
src = <unavailable>
count = <unavailable>
可能导致参数显示为<unavailable>
的原因是什么?
供参考,这里是memcpy_c
:
void *memcpy_c(void *restrict dst, ulen bufsize, const void *restrict src, ulen count) {
if (dst == NULL) {
panic_static("memcpy_c destination pointer is NULL");
}
if (src == NULL) {
panic_static("memcpy_c source pointer is NULL");
}
if (count > bufsize) {
panic_static("memcpy_c caught overflow");
}
if (dst + count >= src && dst < src + count) {
panic_static("memcpy_c attempted to use overlapping regions");
}
return memcpy(dst, src, count);
}