This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

gcc -g1 does not do what the docs say?


Hi all,

The -g1 option is described in the GCC manual as follows:

"Request debugging information and also use level to specify how much information. The default level is 2.
...
Level 1 produces minimal information, enough for making backtraces in parts of the program that you don’t plan to debug. This includes descriptions of functions and external variables, and line number tables, but no information about local variables."

From that description, I assumed that variables with external linkage will have a debugging information present. I tried using -g1 option with DWARF format, using a simple file that has just one line:

int foo;

When compiled with `gcc -c -O2 -gdwarf-4 -g1`, it does not produce the Debugging Information Entry (DIE) for this variable, despite that variable having an external linkage. It does produce a DIE for it with the default debugging level (-g2). I tried various versions of GCC, from 7.1.0 to 9.2.0, all behave in the same way. I also tried adding an __attribute__((externally_visible)) to that variable, but still got no DIE is generated for it.

Am I missing something? Or is it a bug in GCC?

Here is an example using GCC 9.2 that comes with Ubuntu 19.10:

aneyman@supox:/tmp$ cat foo.c
int foo __attribute__((externally_visible));
aneyman@supox:/tmp$ gcc -c -O2 -gdwarf -g1 foo.c
aneyman@supox:/tmp$ readelf -wi foo.o
aneyman@supox:/tmp$ gcc -c -O2 -gdwarf -g2 foo.c
aneyman@supox:/tmp$ readelf -wi foo.o
...
<1><1d>: Abbrev Number: 2 (DW_TAG_variable)
    <1e>   DW_AT_name        : foo

Regards,
Alexey.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]