14

Does anybody experience mixing -g (debugging symbols) and -O2 (best safe optimization) with gcc compiler?
I have to debug crashes of a release program distributed to final users that could send me back the core file.
I've always used to call:

gdb << myprogram >> << core file >>

and see where the trouble is. Now I can just see the call-trace but having no debugging symbols I'm quite in trouble.

Any idea?

Nan Xiao
  • 15,571
  • 16
  • 87
  • 149
Mr.Gate
  • 420
  • 4
  • 12

2 Answers2

12

It works fine.

Or well, due to the optimization sometimes the source you're stepping through with the debugger doesn't match up exactly with the source, but IMHO despite this having the debug symbols makes debugging much easier.

janneb
  • 34,114
  • 2
  • 76
  • 93
7

We use both together in production environment, which makes debugging a lot easier if the customer have only seen a crash once. It gives you a pretty good idea where the problem is (not if it was a memory corruption).

In theory adding -g shouldn't really affect the performance, although the executable gets large. In embedded environment it is a big trade-off.

tothphu
  • 859
  • 10
  • 21
  • 5
    The image with the symbols is only needed by the debugger. If you're using a remote debugger or doing post-mortem debugging from a core file, the image running on the target can have the symbols stripped from it. – Michael Burr Mar 05 '12 at 00:06
  • small point: if you use ccache to speed up building, -g (by default) forces ccache to take not of the path of the source files, so builds in different directories do no benefit from the caching. – Jack Wasey May 01 '18 at 20:52
  • Recent ccache has hints in docs to improve the situation, https://ccache.dev/manual/latest.html#_compiling_in_different_directories – user7610 Jun 22 '19 at 11:31