tags:

views:

918

answers:

5

I am a beginner in GDB and I got it working correctly. However, I am wondering how this is used in big projects. I have a project where build is done using makefile and g++. For GDB to work, we need to compile with debug symbols on, right (g++ -g files)?

Question

  1. Do I need to create a new target in makefile something like "debug", so that I can make a debug build like make debug. Is this the best practice?
  2. Suppose, I need to debug only foo.cpp and is it possible to generate debug symbols only for that other than building whole program including main?

Any thoughts?

A: 

gdb will work without the symbols; it's just that the output is much less useful then.

  1. It's a matter of preference. I build everything by default in debug mode, and do make release when necessary.
  2. Yes.
+2  A: 
  1. 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.

  2. Yes. Build just that file with -g .

Mikeage
What do you mean by "For releases, you can always just run strip on the binary" ? Can you explain?
Appu
http://www.sourceware.org/binutils/docs-2.16/binutils/strip.htmlWith -g, your code will be somewhat larger than without. There's no way to easily add debugging symbols, but you can easily remove them with strip.
Mikeage
+1  A: 

Hello,

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.

  1. 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.
  2. Yes, but consider my previous answer. Sometimes the problem could be coming from a module for which you don't have debugging info.
A: 

In big projects here where I work we always build with most verbose debugging info possible (like, '-ggdb3' for native gdb format or '-gdwarf-2 -g3' for access to macros in gdb).

When we're done with debugging, we just use 'strip' command to strip all debugging info from the binaries.

gcc -ggdb3 blah.c -o blah
strip blah
HMage
A: 

You can always have the debug version's saved somewhere, and if you ever need to re-bind the symbol info, after your debugging the stripped/release version, you can just go "file /path" and gdb will re-read the symbols for that target. Also you can use "symbol-file /path" to configure symbol information to be bound to a stripped file.

RandomNickName42