Do popular available debuggers like gdb support things like recording the complete execution of a program and writing it to a file for later reference? Or possibly only recording the state of the stack for certain groups of functions in important files? In the past, I've achieved this with macros for logging and placing them in the code, but it would be nice to be able to do it without having to modify the source code, especially when the number of functions selected for logging is large. Thanks /b/ros.
int main(int argc, char** argv) {
printf("f(2)=%d\n", f(2));
printf("g(2)=%d\n", g(2));
return 0;
}
$ gcc -c -g main.c -o main.o
$ gcc -g -o main main.o
$ main
f(2)=4
g(2)=3
$ gdb main
GNU gdb (GDB) 7.0-ubuntu
Copyright (C) 2009 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 "i486-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>;...
Reading symbols from /home/ryan/C/nm/lang/tests/ran/main...done.
(gdb) gre[K[K[Kbreak f
Breakpoint 1 at 0x80483f2: file main.c, line 8.
(gdb) commands
Type commands for when breakpoint 1 is hit, one per line.
End with a line saying just "end".
>cont
>end
(gdb) break g
Breakpoint 2 at 0x80483e7: file main.c, line 4.
(gdb) commands
Type commands for when breakpoint 2 is hit, one per line.
End with a line saying just "end".
>cont
>end
(gdb) run[K[K[Kset logging on out[K[K[Klog.tt
Copying output to log.tt.
(gdb) run
Starting program: /home/ryan/C/nm/lang/tests/ran/main
Breakpoint 1, f (n=2) at main.c:8
8 return n + 2;
f(2)=4
Breakpoint 2, g (n=2) at main.c:4
4 return n + 1;
g(2)=3
I could write a script that reads a file containing a list of function names to include in the trace, and then generate the input I would normally type into gdb, and have the output of gdb saved to a log. But this seems much more limited than log files. So I will continue using logging for correctness, and debuggers for crashes.
Name:
Anonymous2012-03-09 11:31
gdb also has record, which saves everything so you may step backwards.