View Issue Details Jump to Notes ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0015901CMakeCMakepublic2016-01-04 03:502016-01-05 01:41
Assigned ToGregor Jasny 
StatusclosedResolutionno change required 
Platformx86_64OSArch LinuxOS Versionno version
Product VersionCMake 3.4.1 
Target VersionFixed in VersionCMake 3.4.1 
Summary0015901: `-Og` does not produce debug symbol in CMake
DescriptionUse `-Og` in CMAKE_CXX_FLAGS, the compiled result does not contain any `.debug_*` section.
Steps To ReproduceCMakeList.txt:

    set(CMAKE_CXX_FLAGS "-std=c++11 -Wall -Wextra -Og")

    #include <iostream>

    int main(void) {
      std::cout << "Hello, world" << std::endl;
      return 0;

Put CMakeList.txt and in the same directory, then execute `cmake .; make; objdump -h Demo | grep .debug`, no result.

For comparison, I compile the by myself: `g++ -std=c++11 -Wall -Wextra -Og; objdump -h a.out | grep .debug`. It returns:

     26 .debug_aranges 00000030 0000000000000000 0000000000000000 00000d32 2**0
     27 .debug_info 00002a64 0000000000000000 0000000000000000 00000d62 2**0
     28 .debug_abbrev 00000651 0000000000000000 0000000000000000 000037c6 2**0
     29 .debug_line 00000372 0000000000000000 0000000000000000 00003e17 2**0
     30 .debug_str 00001a02 0000000000000000 0000000000000000 00004189 2**0
     31 .debug_loc 0000009e 0000000000000000 0000000000000000 00005b8b 2**0
Additional Information$ LANG=C gcc -v
Using built-in specs.
Target: x86_64-unknown-linux-gnu
Configured with: /build/gcc/src/gcc-5.3.0/configure --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib --mandir=/usr/share/man --infodir=/usr/share/info --with-bugurl= [^] --enable-languages=c,c++,ada,fortran,go,lto,objc,obj-c++ --enable-shared --enable-threads=posix --enable-libmpx --with-system-zlib --with-isl --enable-__cxa_atexit --disable-libunwind-exceptions --enable-clocale=gnu --disable-libstdcxx-pch --disable-libssp --enable-gnu-unique-object --enable-linker-build-id --enable-lto --enable-plugin --enable-install-libiberty --with-linker-hash-style=gnu --enable-gnu-indirect-function --disable-multilib --disable-werror --enable-checking=release
Thread model: posix
gcc version 5.3.0 (GCC)
TagsNo tags attached.
Attached Files


Gregor Jasny (developer)
2016-01-04 09:51

could you please post the output of "make clean && make VERBOSE=1" ?
Ben Boeckel (developer)
2016-01-04 11:48

CMAKE_CXX_FLAGS is added before the CMAKE_CXX_FLAGS_<CONFIG> and the Debug configuration adds -O0, so my guess is that -O0 is overriding -Og. Try setting CMAKE_CXX_FLAGS_DEBUG to include -Og (or replace -O0 with -Og if the compiler supports it).
Gregor Jasny (developer)
2016-01-04 12:04

I get the following:

/usr/bin/cmake -H/home/gjasny/tmp -B/home/gjasny/tmp --check-build-system CMakeFiles/Makefile.cmake 0

/usr/bin/cmake -E cmake_progress_start /home/gjasny/tmp/CMakeFiles /home/gjasny/tmp/CMakeFiles/progress.marks

make -f CMakeFiles/Makefile2 all
make[1]: Entering directory '/home/gjasny/tmp'
make -f CMakeFiles/Demo.dir/build.make CMakeFiles/Demo.dir/depend
make[2]: Entering directory '/home/gjasny/tmp'
cd /home/gjasny/tmp && /usr/bin/cmake -E cmake_depends "Unix Makefiles" /home/gjasny/tmp 
/home/gjasny/tmp /home/gjasny/tmp /home/gjasny/tmp /home/gjasny/tmp/CMakeFiles/Demo.dir/DependInfo.cmake 
Dependee "/home/gjasny/tmp/CMakeFiles/Demo.dir/DependInfo.cmake" is newer than depender "/home/gjasny/tmp/CMakeFiles/Demo.dir/depend.internal".

Dependee "/home/gjasny/tmp/CMakeFiles/CMakeDirectoryInformation.cmake" is newer than depender 
Scanning dependencies of target Demo
make[2]: Leaving directory '/home/gjasny/tmp'
make -f CMakeFiles/Demo.dir/build.make CMakeFiles/Demo.dir/build
make[2]: Entering directory '/home/gjasny/tmp'
[ 50%] Building CXX object CMakeFiles/Demo.dir/
/usr/bin/c++     -std=c++11 -Wall -Wextra -Og   -o CMakeFiles/Demo.dir/ -c /home/gjasny/tmp/

[100%] Linking CXX executable Demo
/usr/bin/cmake -E cmake_link_script CMakeFiles/Demo.dir/link.txt --verbose=1
/usr/bin/c++   -std=c++11 -Wall -Wextra -Og   CMakeFiles/Demo.dir/  -o Demo -rdynamic 
make[2]: Leaving directory '/home/gjasny/tmp'
[100%] Built target Demo
make[1]: Leaving directory '/home/gjasny/tmp'
/usr/bin/cmake -E cmake_progress_start /home/gjasny/tmp/CMakeFiles 0

objdump -h Demo | grep .debug

But also this:

gjasny@sid:~/tmp$ g++ -std=c++11 -Wall -Wextra -Og; objdump -h a.out | grep .debug
gjasny@sid:~/tmp$ g++ -std=c++11 -g -Wall -Wextra -Og; objdump -h a.out | grep .debug
 27 .debug_aranges 00000030  0000000000000000  0000000000000000  00000d1d  2**0
 28 .debug_info   00002a64  0000000000000000  0000000000000000  00000d4d  2**0
 29 .debug_abbrev 00000651  0000000000000000  0000000000000000  000037b1  2**0
 30 .debug_line   00000359  0000000000000000  0000000000000000  00003e02  2**0
 31 .debug_str    000019fb  0000000000000000  0000000000000000  0000415b  2**0
 32 .debug_loc    0000009e  0000000000000000  0000000000000000  00005b56  2**0

GCC manual states the following: [^]

Optimize debugging experience. -Og enables optimizations that do not interfere with debugging. It should 
be the optimization level of choice for the standard edit-compile-debug cycle, offering a reasonable 
level of optimization while maintaining fast compilation and a good debugging experience.

So IMHO -Og does not imply -g, it just tells GCC to create code which could be debugged well.

g++ (Debian 5.3.1-5) 5.3.1 20160101; cmake version 3.4.1
Gregor Jasny (developer)
2016-01-04 12:07

What are your GCC_COLLECT flags if you run

g++ -std=c++11 -Wall -Wextra -Og -v ; objdump -h a.out |grep .debug
Ben Boeckel (developer)
2016-01-04 12:12

There's no -g in your compilation line. Set CMAKE_BUILD_TYPE to "Debug" (it's ctest and cpack that use Debug if empty; CMake itself just does nothing special and adds no flags). -Og means to optimize for debugging, but doesn't mean that debugging is enabled. I don't think CMake do so either.
acgtyrant (reporter)
2016-01-04 20:12

Because I wrote a wrong build type “CMAKE_CXX_FLAGS_RELWITHDBGINFO" from the start, so the cmake still cached wrong build type after I fix this typo larer. So I run `ccmake .` and enter the correct build type and re-configure, and it works finally.

So no bug, but I think this cache mechanism is deceptive.
Gregor Jasny (developer)
2016-01-05 01:41

To avoid situations like this you could use a build directory separate from the source tree.

 Issue History
Date Modified Username Field Change
2016-01-04 03:50 acgtyrant New Issue
2016-01-04 09:51 Gregor Jasny Note Added: 0040051
2016-01-04 11:48 Ben Boeckel Note Added: 0040052
2016-01-04 11:49 Ben Boeckel Summary `-Og` dose not produce debug symbol in CMake => `-Og` does not produce debug symbol in CMake
2016-01-04 12:04 Gregor Jasny Note Added: 0040132
2016-01-04 12:07 Gregor Jasny Note Added: 0040133
2016-01-04 12:12 Ben Boeckel Note Added: 0040134
2016-01-04 20:12 acgtyrant Note Added: 0040138
2016-01-05 01:41 Gregor Jasny Note Added: 0040139
2016-01-05 01:41 Gregor Jasny Status new => closed
2016-01-05 01:41 Gregor Jasny Assigned To => Gregor Jasny
2016-01-05 01:41 Gregor Jasny Resolution open => no change required
2016-01-05 01:41 Gregor Jasny Fixed in Version => CMake 3.4.1

Copyright © 2000 - 2018 MantisBT Team