gdb ddd
Debugger used for stepping though C++ code, see Program crashes gdb for a quick gdb session example.
$ C++ -g -o test test.cpp
$ gdb test
-g3 for extra debug info.
-gstabs+ produce stabs format debugging info.
-pg generate profile info.
run > outputfile
set confirm off - turn off conformation!
break filename:function
break filename:32
break classname::function
break d4tess.cpp:181 if w==5 - Conditional
condition number expression - place condition on breakpoint.
continue or c - continue execution.
enable number , disable number
to turn on and off breakpoints.
delete <number> deletes breakpoint.
info breakpoints lists current breakpoints
watch expr - the program will pause when the value changes
watch x == 3
clear
backtrace or bt to display the stack.
until
print EXP
print v[0]@25 - prints out the first 25 values.
print (d4tri)(vi[0])@5 prints the first 5 values of vector<d4tri>vi. Since this is
a STL vector a cast was needed.
list function/line number
print flag=false - sets the value and prints it.
display x - constant variable display
undisplay x
list - source code
info args - function arguments
info locals - function local variables
When running program inside gdb, can suspend and reenter.
Ctrl+z matched with fg fg.
gdb can have difficulty with templates. Resort to the old cout as an alternative.
Configuration
~/.gdbinit file.
set confirm off set history filename ~/.gdbhistory set history save set history size 400
DDD - front end GUI for debuggers. doc
I use DDD as a better way to manage gdb.
For me ddd makes using gdb much faster. gdb does crash at times. kill and reopen the file.
I still enter many gdb commands at ddd's command line as it is faster.
Defining a command
[Buggy GUI]
Commands < Define Command...
Command ptk
In text box
define print *tk.current end
click Button to make command a button.
(tk()==tag2)
hover over tag2 to get its value, ptk button to print value and compare.
cout << SHOW3(tk()) << endl
cout << SHOW3(tag2) << endl
same way with code.
Could have right clicked on tk.current and
selected .
To delete the button
Commands > Edit button > select
Console, Source or Data buttons > backspace to clear the window >
Apply