gdb对tracepoint的描述
In some applications, it is not feasible for the debugger to interrupt the program's execution long enough for the developer to learn anything helpful about its behavior. If the program's correctness depends on its real-time behavior, delays introduced by a debugger might cause the program to change its behavior drastically, or perhaps fail, even when the code itself is correct. It is useful to be able to observe the program's behavior without interrupting it.
I.demo
i.tracepoint.c
#include <stdio.h> #include <unistd.h> int indx; int main(int argc, char *argv[]) { int res; indx = 0; while ( indx < 10000 ) { res = indx * 2; printf("%d\n", res); sleep(1); indx++; } return 0; }
ii.Makefile
all: gcc -g tracepoint.c -o tracepoint
iii.command
file tracepoint target remote 127.0.0.1:1234 trace tracepoint.c:15 actions collect indx end tstart break tracepoint.c:14 continue continue 10 tstop tstatus tfind start while($trace_frame != -1) printf "Frame %d : indx = %d\n", $trace_frame, indx tfind end
II 测试
i ./tracepoint
[redhat@localhost test]$ ./tracepoint 0 2 4
ii gdbserver
[redhat@localhost src]$ gdbserver --attach 127.0.0.1:1234 `pidof tracepoint` Attached; pid = 18812 Listening on port 1234 Remote debugging from host 127.0.0.1
iii gdb
[redhat@localhost test]$ gdb --command=command GNU gdb (GDB) Red Hat Enterprise Linux (7.2-50.el6) Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-redhat-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>. 0x00000038d8aaab80 in __nanosleep_nocancel () from /lib64/libc.so.6 Created trace state variable $trace_timestamp for target's variable 1. Tracepoint 1 at 0x40054b: file tracepoint.c, line 15. Breakpoint 2 at 0x400541: file tracepoint.c, line 14. Breakpoint 2, main (argc=1, argv=0x7fff716cb1c8) at tracepoint.c:14 14 sleep(1); Breakpoint 2, main (argc=1, argv=0x7fff716cb1c8) at tracepoint.c:14 14 sleep(1); Trace stopped by a tstop command. Collected 11 trace frames. Trace buffer has 5242649 bytes of 5242880 bytes free (0% full). Trace will stop if GDB disconnects. Not looking at any trace frame. Found trace frame 0, tracepoint 1 Frame 0 : indx = 325 Found trace frame 1, tracepoint 1 Frame 1 : indx = 326 Found trace frame 2, tracepoint 1 Frame 2 : indx = 327 Found trace frame 3, tracepoint 1 Frame 3 : indx = 328 Found trace frame 4, tracepoint 1 Frame 4 : indx = 329 Found trace frame 5, tracepoint 1 Frame 5 : indx = 330 Found trace frame 6, tracepoint 1 Frame 6 : indx = 331 Found trace frame 7, tracepoint 1 Frame 7 : indx = 332 Found trace frame 8, tracepoint 1 Frame 8 : indx = 333 Found trace frame 9, tracepoint 1 Frame 9 : indx = 334 Found trace frame 10, tracepoint 1 Frame 10 : indx = 335 No trace frame found Missing separate debuginfos, use: debuginfo-install glibc-2.12-1.47.el6.x86_64 (gdb)
III.locals
局部变量目前有问题,暂未找到原因
(gdb) actions Enter actions for tracepoint 1, one per line. End with a line saying just "end". >collect res DWARF operator DW_OP_call_frame_cfa cannot be translated to an agent expression (gdb) actions Enter actions for tracepoint 1, one per line. End with a line saying just "end". >collect $locals >end (gdb) tstart DWARF operator DW_OP_call_frame_cfa cannot be translated to an agent expression (gdb)