cpp tools debug gdb rr ddd - ghdrako/doc_snipets GitHub Wiki
- https://rr-project.org/ - C/C++ debugging tool for Linux
- https://en.wikipedia.org/wiki/Rr_(debugging)
- https://begriffs.com/posts/2022-07-17-debugging-gdb-ddd.html
- https://www.brendangregg.com/blog/2016-08-09/gdb-example-ncurses.html
- https://jvns.ca/blog/2021/05/17/how-to-look-at-the-stack-in-gdb/
- https://jvns.ca/blog/2016/08/10/how-does-gdb-work/
- lista komend
Debuging proces
- adding trace code,
- recompiling the program,
$ gcc -g -Wall -o insert_sort ins.c
-
-g
option to GCC to tell the compiler to save the symbol table
-
- running the program and analyzing the output of the trace code,
- removing the trace code after the bug is fixed,
- repeating these steps for each new bug that is discovered.
- start in TUI mode
$ gdb insert_sort --tui
CTRL-X-A
- command toggles you in and out of TUI mode and is useful if you wish, for example, to temporarily leave TUI mode so that you can read GDB’s online help more conveniently, or so that you can see more of your GDB command history together on one screen.
- run program withou argument
(gdb) run
(gdb) r
- run program with argument
(gdb) run <args>
(gdb) r <args>
(gdb) run 12 5
- passing the args to the debugger
% gdb --args a.out 1 2 3
(gdb) run
- set arguments in debugger
(gdb) set args 1 2 3
(gdb) run
- Set environment variables for process before launching
(gdb) set env DEBUG 1
- Show the arguments that will be or were passed to the program when run
(gdb) show args
- Attach to the process with process ID 123
(gdb) attach 123
- Attach to the process named a.out
(gdb) attach a.out
- Wait for a process named a.out to launch and attach
(gdb) attach -waitfor a.out
- Do a source level single step
(gdb) step
(gdb) s
- Do a source level single step over
(gdb) next
(gdb) n
- Do an instruction level single step
(gdb) stepi
(gdb) si
Do an instruction level single step over
(gdb) nexti
(gdb) ni
- Step out of the currently selected frame
(gdb) finish
- Return immediately from the currently selected frame, with an optional return value
(gdb) return <RETURN EXPRESSION>
- inspecting variables
(gdb) print j
(gdb) p j
- watchpoint combines the notions of breakpoint and variable inspection. , GDB will pause execution whenever the value of z changes.
(gdb) watch z
- find the first point in the execution of the program at which the value of z exceeds 28
(gdb) watch (z > 28)
(gdb) frame 1
$rr record /your/application --args
...
something go wrong
$rr replay #start gdb session
GNU gdb (GDB)