Unsolved No source code when debugging library code
-
Hello,
I'm trying to use QtCreator to debug a simple project made of :- a shared library
- an executable linked with the library
The CMakefile is as follows :
cmake_minimum_required(VERSION 3.2) project(proj LANGUAGES C) set(libname lib) set(exename exe) set(libdir ${CMAKE_SOURCE_DIR}/lib) set(exedir ${CMAKE_SOURCE_DIR}/exe) add_compile_options( -g -O1 -fno-omit-frame-pointer ) add_library(${libname} SHARED ${libdir}/lib.c ${libdir}/lib.h ) # Executable sources set(exesrc ${exedir}/main.c ) add_executable(${exename} ${exesrc} ) # link with library target_link_libraries(${exename} PRIVATE ${libname} ) install(TARGETS ${libname} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} ) install(TARGETS ${exename} DESTINATION ${CMAKE_INSTALL_BINDIR} )
In the debugger, everything works fine when stepping through code in the executable file main.c
But when the executable calls a function defined in the library, the debugger switches to disassembly.
Is there a way to display source code instead ?When the library source code is added the executable target, the debugger is able to display source code. However, it would be preferrable to not duplicate the library code in the executable.
Thanks
-
@kaam said in No source code when debugging library code:
Is there a way to display source code instead ?
You need a debug version of that library (built in debug mode).
-
@kaam said in No source code when debugging library code:
add_compile_options(
-g -O1
-fno-omit-frame-pointer
)Thanks for the answer. The library is part of the project.
There is a global add_compile_options at the beginning of the CMakeLists file.
It adds -g -O1 -fno-omit-frame-pointer to all targets, including the library. So the library is also built with debug options
When running the file command on the library, it prints : with debug_info, not stripped -
@kaam said in No source code when debugging library code:
It adds -g -O1 -fno-omit-frame-pointer to all targets,
That's not how CMake build types works, make sure those options are really added to your targets (I doubt). Either use the correct CMAKE_BUILD_TYPE and or modify the pre-defined values for those build types. But CMAKE_BUILD_TYPE=Debug should be good for your debuggin problem.
-
@Christian-Ehrlicher It's the default debug setting. There is -DCMAKE_BUILD_TYPE:STRING=Debug in the Project configuration window.
-
Seems to work fine here with a dummy main.c
#include "../lib/lib.h" int main() { int foo = 0; foo = addone(foo); return 0; }
and dummy lib.h
int addone(int foo);
lib.c
int addone(int foo) { return foo + 1; }
Stepping into addone from main.c opens foo.c
If you open View > Views > Debugger Log, that might show helpful information why it might not work for you after the "script theDumper.executeStep" execution.