Creating symbol table for gdb using cmake
Asked Answered
A

5

79

Is there any way to create only symbol table using cmake for gdb ?

Ascus answered 3/11, 2011 at 6:0 Comment(0)
N
-13

The usual way to produce debugging information for gdb is to pass -g to the gcc or g++ compiler (and also at linking time).

Look into the Cmake FAQ for how to get a debuggable executable.

Neuro answered 3/11, 2011 at 6:10 Comment(4)
I want only symbol table is it possible ?Ascus
It probably is possible, but it is not a cmake specific question. I think that they are some Linux utilities (perhaps binutils related) to extract debugging information from an ELF executable, but I never used them. moythreads.com/wordpress/2009/08/31/…Neuro
When folks ask a question it is rare that they wanted to be pointed to a manual. Thanks but no thanks....Chain
it IS a cmake question. With gcc or clang, when profiling, you generally enable both symbols and optimization (-g -O2). Whereas with clang you have optimization enabled in release mode, and symbols in debug mode.Constanceconstancia
L
158

Add this line to the file CMakeLists.txt:

set(CMAKE_BUILD_TYPE Debug)
Levalloisian answered 26/6, 2012 at 11:1 Comment(2)
This also disables optimization. For profiling instead of debugging, you generally want both optimization and symbols (aka -g O2). How to do this with clang?Constanceconstancia
I added this flag to my cmake file however I dont see any difference in the size of the binary which is usually increased after adding -g which flag for adding debug symbols.Abigail
M
132

Compile in Release mode optimized but adding debug symbols, useful for profiling:

cmake -DCMAKE_BUILD_TYPE=RelWithDebInfo ...

or compile with NO optimization and adding debug symbols:

cmake -DCMAKE_BUILD_TYPE=Debug ...
Meneau answered 31/1, 2014 at 10:50 Comment(1)
Note that RelWithDebInfo is great, but also changes the optimization from -O3 to -O2 due to historic reasons: gitlab.kitware.com/cmake/cmake/-/merge_requests/591Butlery
S
1

If you're using QtCreator, remove (or comment out) any line containing CMAKE_BUILD_TYPE:

# set(CMAKE_BUILD_TYPE Debug) 
# set(CMAKE_BUILD_TYPE Release) <- comment out such lines 

Reason: if you explicitly set CMAKE_BUILD_TYPE in your CmakeLists.txt, QtCreator will not allow you to set any other target.

Semanteme answered 4/11, 2021 at 14:50 Comment(0)
T
0

If you need the debug symbols for profiling then paste this into CMakeLists.txt:

set(CMAKE_BUILD_TYPE RelWithDebInfo)
Talbot answered 18/2, 2021 at 13:51 Comment(0)
N
-13

The usual way to produce debugging information for gdb is to pass -g to the gcc or g++ compiler (and also at linking time).

Look into the Cmake FAQ for how to get a debuggable executable.

Neuro answered 3/11, 2011 at 6:10 Comment(4)
I want only symbol table is it possible ?Ascus
It probably is possible, but it is not a cmake specific question. I think that they are some Linux utilities (perhaps binutils related) to extract debugging information from an ELF executable, but I never used them. moythreads.com/wordpress/2009/08/31/…Neuro
When folks ask a question it is rare that they wanted to be pointed to a manual. Thanks but no thanks....Chain
it IS a cmake question. With gcc or clang, when profiling, you generally enable both symbols and optimization (-g -O2). Whereas with clang you have optimization enabled in release mode, and symbols in debug mode.Constanceconstancia

© 2022 - 2024 — McMap. All rights reserved.