What are some of your favorite tricks to debug C++ programs with gdb ?
Interested in all tricks but also
how you call methods (which may be virtual) on objects from within gdb
inspecting STL objects (pretty printing them)
preventing gdb from going into STL code with continue
dealing with inlining, threads, tcmalloc (or custom allocators)
Keeping history of gdb commands across different sessions
Use ctrl-c to interrupt the application. Then run "signal SIGINT" from the GDB prompt, which will send this signal to your application, causing it to do the same things it would normally have done when you do ctrl-c from the command line.
If the target environment supports it, gdb can allow you to “rewind” the program by running it backward. A target environment that supports reverse execution should be able to “undo” the changes in machine state that have taken place as the program was executing normally.
Diagnose the infinite loop. Start calc from within gdb using the run command. It will go into an infinite loop. Press Ctrl-C (like before) to stop your program.
Try DDD when you debug C++; DDD can dynamically load source code for shared libraries, and display multiple variables while you debug.
1.
set print object
This enables the evaluation of the object hierarchy by looking at the vtable. So you can see what type a reference/pointer to a base class is.
2.
Get the debug infos or unstripped libraries for the system libs (most importantly: pthread and libstdc++) since otherwise debugging multithreaded apps isn't working nicely in gdb.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With