https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93751
Bug ID: 93751
Summary: -g1 does not do behave per manual
Product: gcc
Version: 10.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: debug
Assignee: unassigned at gcc dot gnu.org
Reporter: stilor at att dot net
Target Milestone: ---
Reported here, https://gcc.gnu.org/ml/gcc-help/2020-02/msg00062.html; I was
advised to file a bug in Bugzilla.
The `-g1` option is described in the GCC manual as:
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."
However, GCC's behavior differs when DWARF debug format is used: `-g1` does not
produce the DIEs for external variables, only for function descriptions. As I
was told in the email thread above, this is also inconsistent with other debug
formats (which do follow the description of the `-g1` in the manual).
Easily demonstratable by compiling a simple file and feeding the object to
`readelf -wi`:
```
int foo;
static int bar;
```
With `-g2` or `-g`, the object file contains DIEs for both `foo` and `bar`.
With `-g1`, it contains neither even though it is supposed to still have `foo`.