Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt Creator and other tools
  4. No source code when debugging library code

No source code when debugging library code

Scheduled Pinned Locked Moved Unsolved Qt Creator and other tools
6 Posts 4 Posters 653 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kaam
    wrote on last edited by
    #1

    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

    jsulmJ 1 Reply Last reply
    0
    • K kaam

      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

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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).

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • K Offline
        K Offline
        kaam
        wrote on last edited by
        #3

        @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

        Christian EhrlicherC 1 Reply Last reply
        0
        • K kaam

          @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

          Christian EhrlicherC Offline
          Christian EhrlicherC Offline
          Christian Ehrlicher
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @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.

          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
          Visit the Qt Academy at https://academy.qt.io/catalog

          K 1 Reply Last reply
          2
          • Christian EhrlicherC Christian Ehrlicher

            @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.

            K Offline
            K Offline
            kaam
            wrote on last edited by
            #5

            @Christian-Ehrlicher It's the default debug setting. There is -DCMAKE_BUILD_TYPE:STRING=Debug in the Project configuration window.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              ziller
              wrote on last edited by ziller
              #6

              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.

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved