1

When I try to build the source with debug mode the stack shown is totally diffrent and in case of release there are only a few methods shown in the backtrace with gdb , Why does this happen ? Is this because in debug mode there are extra methods , How can have two methods have the same address in debug and release mode . Also in that case How can I build to to have accurate address information with complete stack trace . Any help would be appreciated since I am new to debugging on Linux , Windows it was much easier it seems with pdb files .

3 Answers 3

1

As discussed in the comments to @rockoder's answer, besides lacking debug symbols (which would be included with -g) in an optimized build whole function calls may not be present any more due to inlining.

Sign up to request clarification or add additional context in comments.

Comments

1

When I try to build the source with debug mode the stack shown is totally diffrent and in case of release there are only a few methods shown in the backtrace with gdb , Why does this happen ? Is this because in debug mode there are extra methods?

It is probably just due to compiler optimizations. What you call release build is probably built with compiler speed optimizations enabled and debug symbols disabled. Speed optimizations include code inlining which just copies function code in place instead of calling it, so function is not visible in call stack. There could also be some extra/different methods, if the code was written with some appropriate preprocessor checks.

How can have two methods have the same address in debug and release mode .

Depends on what your debug and release mode are. If they use same compiler optimizations and differ only in debug information, methods will have same addresses. If you debug build is not optimized (-O0 on GCC) then methods will be larger, as much unnecessary work is done, for example variables are read from memory before every manipulation and written back after it. Since each method will probably be smaller, functions will have different addresses, as they are generally packed one after another.

Also in that case How can I build to to have accurate address information with complete stack trace .

Enable debug information. On GCC that would be -g3 (or -g or similar). This adds enough information for code address <-> source line queries (either from debugger or crash stack dump).

Any help would be appreciated since I am new to debugging on Linux , Windows it was much easier it seems with pdb files .

Are there any significant differences with Windows binaries debugging?

Comments

0

g++/gcc has many options used for debugging a program but the most common one is -g. Refer link. The first option discussed is -g.

Some additional information here.

Example:

Compile code without -g:

g++ broken.cpp -o broken_release

Compile code with -g:

g++ -g broken.cpp -o broken_debug

Now fire ls -l and note the size different between the files broken_release and broken_debug. Size of broken_debug should be greater then that of broken_release. That's because it contains debug information which could be used by debuggers like gdb.

3 Comments

+1 @Manu343726, yes it does. It is totally relevant to this part: "When I try to build the source with debug mode the stack shown is totally diffrent and in case of release there are only a few methods shown in the backtrace with gdb , Why does this happen ?"
@rerx writting the g++ -g documentation is not an answer to that question.... The answer is the lack of debugging simbols and the optimizations (Inlining, in the case of less functions) performed by the compiler on release mode.
@Manu, true optimizations like inlining will also play a role. But leaving out -g is just that: not providing debugging symbols.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.