Not needed, although you may want to consider always building with -g (sometimes, you may even need to try and debug optimized (-O1, -O2, etc) code; why not leave -g on? For releases, you can always just run strip on the binary.
Yes. Build just that file with -g .
Not needed, although you may want to consider always building with -g (sometimes, you may even need to try and debug optimized (-O1, -O2, etc) code; why not leave -g on? For releases, you can always just run strip on the binary.
Yes. Build just that file with -g .
I don't think there is a big difference between the usage of gdb in big, medium or small projects. However, for big projects you must consider the amount of space required for the build, because the debugging info increases the size of the object and executable files.
- If you initially underestimate the need for debugging of the whole solution you will likely suffer from your decision in the future. It is always good when the build could be done with or without debugging information, so write your build scripts carefully.
- Yes, but consider my previous answer. Sometimes the problem could be coming from a module for which you don't have debugging info.
Videos
- backtrace full: Complete backtrace with local variables
- up, down, frame: Move through frames
- watch: Suspend the process when a certain condition is met
- set print pretty on: Prints out prettily formatted C source code
- set logging on: Log debugging session to show to others for support
- set print array on: Pretty array printing
- finish: Continue till end of function
- enable and disable: Enable/disable breakpoints
- tbreak: Break once, and then remove the breakpoint
- where: Line number currently being executed
- info locals: View all local variables
- info args: View all function arguments
- list: view source
- rbreak: break on function matching regular expression
Start gdb with a textual user interface
gdb -tui
Maybe not the sort of "tip" you were looking for, but I have to say that my experience after a few years of moving from C++ & STL to C++ & boost & STL is that I now spend a lot less time in GDB than I used to. I put this down to a number of things:
- boost smart pointers (particularly "shared pointer", and the pointer containers when performance is needed). I can't remember the last time I had to write an explicit delete (delete is the "goto" of C++ IMHO). There goes a lot of GDB time tracking down invalid and leaking pointers.
- boost is full of proven code for things you'd probably hack together an inferior version of otherwise. e.g
boost::bimapis great for the common pattern of LRU caching logic. There goes another heap of GDB time. - Adopting unittesting.
boost::test's AUTO macros mean it's an absolute doddle to set up test cases (easier than CppUnit). This catches lots of stuff long before it gets built into anything you'd have to attach a debugger to. - Related to that, tools like
boost::bindmake it easier to design-for-test. e.g algorithms can be more generic and less tied up with the types they operate on; this makes plugging them into test shims/proxies/mock objects etc easier (that and the fact that exposure to boost's template-tasticness will encourage you to "dare to template" things you'd never have considered before, yielding similar testing benefits). boost::array. "C array" performance, with range checking in debug builds.- boost is full of great code you can't help but learn from
You might look at:
Inspecting standard container (std::map) contents with gdb