GCC 4.8: Does -Og imply -g?

gcc

Solution

Short answer: No, you must still add `-g` manually.

Long answer:

I have struggled to find a hard answer straight from the source, so I decided to test it out myself using the methods described here: How to check if program was compiled with debug symbols?

I built an executable with the `-O3` flag and without `-g`. Using `objdump --syms <file> | grep debug` yielded nothing, as expected.

I then built an executable with `-g` and without any optimization flags. The same `objdump` command yielded six results such as this:

`0000000000000000 l d .debug_info 0000000000000000 .debug_info`

I finally built an executable with the `-Og` flag and without `-g`. The `objdump` command yielded nothing. That implies that debug symbols are not present in this case.

While I can't find any explicit documentation from GCC itself, the Gentoo Wiki (as mentioned before by Marco Scannadinari) confirms my assertion that `-Og` does not imply `-g`.

Problem

Recently the documentation for GCC 4.8 was updated which now introduces a new optimization switch, `-Og`. This [..] addresses the need for fast compilation and a superior debugging experience while providing a reasonable level of runtime performance. Overall experience for development should be better than the default optimization level -O0. Does this switch imply `-g` or do I have to add it to my `CXXFLAGS` manually?

Original source

Related problems