Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GCC: How to generate line number debug information only?

I would like to improve the build speed of a large project. The opt build is compiled with -O2 -g. I noticed that without -g, compilation becomes faster, about 10-20%. The resulting binary has enough information to analyze crashes, except for the line numbers. Is there a way to include line number information but nothing else?

According to http://gcc.gnu.org/onlinedocs/gcc/Debugging-Options.html, line numbers are produced only at level 2 (i.e. -g2 or the default of -g) or above. But according to this http://gcc.gnu.org/wiki/DebugFission, line numbers are only a fraction of the debug information (1%). So for me it would be best to have -g0 or -g1 but with line numbers. Is this possible?

Best regards, Martin

like image 869
Martin Richtarsky Avatar asked Jul 28 '13 11:07

Martin Richtarsky


People also ask

How do you find line segment fault number?

GDB can give you the line where a crash occurred with the "bt" (short for "backtrace") command after the program has seg faulted. This will give you not only the line of the crash, but the whole stack of the program (so you can see what called the function where the crash happened).

Which GCC flag is used to generate debug information for any binary file?

gcc -g generates debug information to be used by GDB debugger.

What is RelwithDebInfo?

exerpt: "RelwithDebInfo is quite similar to Release mode. It produces fully optimized code, but also builds the program database, and inserts debug line information to give a debugger a good chance at guessing where in the code you are at any time."


1 Answers

Googling the Clang option mentioned by Matthieu, I found a patch for gcc that does what I want. It has been submitted for trunk but has been pending since two years. This means stock GCC is not able to do this, but with this patch it can do it using the option "-gmlt"

http://old.nabble.com/-patch--Add-new--gmlt-option-for-min.-debug-info-with-line-tables-%28issue4440072%29-td31482851.html

like image 161
Martin Richtarsky Avatar answered Oct 04 '22 16:10

Martin Richtarsky