开发者

Debugging in Linux using core dumps

开发者 https://www.devze.com 2022-12-20 08:38 出处:网络
What are the \'best practices\' when it comes to debugging core dumps using GDB? Currently, I am facing a problem:

What are the 'best practices' when it comes to debugging core dumps using GDB?

Currently, I am facing a problem:

  • The release version of my application is compiled without the '-g' compiler flag.
  • The debug version of my application (compiled with '-g') is archived (along with the source code, and a copy of the release binary).

Recently, when a user gave me a core dump, I tried debugging it using

gdb --core=./core.pid ./my_app_debug-bin

The core was created by my_app_release-bin. There seems to be some kind of mismatch between the core f开发者_如何学Goile and the binary.

On the other hand, if I try

gdb --core=./core.pid ./my_app_release-bin

the core matches but I am unable to get source code line numbers (although I get the function names).

Is this what is practised? Because I feel I am missing something here.


It sounds like there are other differences between your release and debug build then simply the absence/presence of the -g flag. Assuming that's the case, there is nothing you can do right now, but you can adjust your build to handle this better:

Here's what we do at my place of work.

  1. Include the -g flag when building the release version.
  2. Archive that version.
  3. run strip --strip-unneeded on the binary before shipping it to customers.

Now, when we get a crash we can use the archived version with symbols to do debugging.

One thing to note is that if your release version includes optimization, debugging may be difficult even with symbols. For example, the optimizer can reorder your code so even though the debugger will say you crashed on line N, you can't assume that the code actually executed line N-1.


You need to do some additional stuff to create binaries with stripped debug information that you can then debug from cores. Best description I could find is here


No, you don't miss anything. debug and release are just different binaries, so the core files of release don't match the debug binary. You have to look at machine code to get something from the release core dump.

You probably have to ask your user how the crash happened and collect additional log information or whatever you app produces.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号