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. Automatically append source directory to gdb when debugging
Forum Updated to NodeBB v4.3 + New Features

Automatically append source directory to gdb when debugging

Scheduled Pinned Locked Moved Solved Qt Creator and other tools
8 Posts 4 Posters 1.5k Views 2 Watching
  • 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.
  • C Offline
    C Offline
    Creaperdown
    wrote on 4 Jul 2023, 15:30 last edited by
    #1

    Hey, I have external source directories of my library that I want to add to gdb while debugging. In the command line I can do that by calling gdb via gdb --directory=/path/to/sources or by writing directory /path/to/sources while running gdb.

    How would I do this with qt creator? I want gdb to automatically run with these source directories on startup

    J J 2 Replies Last reply 4 Jul 2023, 16:18
    1
    • K Offline
      K Offline
      KH-219Design
      wrote on 4 Jul 2023, 21:11 last edited by
      #6

      I would imagine you can put your command:

      directory /path/to/sources
      

      In this file:

      ~/.gdbinit
      

      I don't use Qt Creator, but I would be surprised if whenever Qt Creator launches gdb it would go out of its way to launch gdb in such a way that inhibits the normal (default gdb) behavior of reading from ~/.gdbinit

      https://sourceware.org/gdb/onlinedocs/gdb/gdbinit-man.html

      In case you end up becoming a fan of ~/.gdbinit, here are some other things to put in it (copied from my own, which accumulates new goodies about once a year):

      # https://sourceware.org/gdb/onlinedocs/gdb/Command-History.html
      set history save on
      
      set max-completions 50
      
      # WISDOM for loading large executables:
      # https://stackoverflow.com/questions/59805689/how-to-make-firefox-startup-faster-in-gdb
      set index-cache on
      

      www.219design.com
      Software | Electrical | Mechanical | Product Design

      C 1 Reply Last reply 4 Jul 2023, 21:19
      0
      • C Creaperdown
        4 Jul 2023, 15:30

        Hey, I have external source directories of my library that I want to add to gdb while debugging. In the command line I can do that by calling gdb via gdb --directory=/path/to/sources or by writing directory /path/to/sources while running gdb.

        How would I do this with qt creator? I want gdb to automatically run with these source directories on startup

        J Offline
        J Offline
        JoeCFD
        wrote on 4 Jul 2023, 16:18 last edited by
        #2

        @Creaperdown I guess this is not needed if your app is linked to the debug build of your lib.

        C 1 Reply Last reply 4 Jul 2023, 16:22
        0
        • J JoeCFD
          4 Jul 2023, 16:18

          @Creaperdown I guess this is not needed if your app is linked to the debug build of your lib.

          C Offline
          C Offline
          Creaperdown
          wrote on 4 Jul 2023, 16:22 last edited by
          #3

          @JoeCFD It is needed. It is linked to the debug build, but the sources are somewhere else on my driver. I got it to work by adding the directory=... for gdb, else it was just able to show me the asm code (the src layout didn't work)

          J 1 Reply Last reply 4 Jul 2023, 22:39
          0
          • C Creaperdown
            4 Jul 2023, 15:30

            Hey, I have external source directories of my library that I want to add to gdb while debugging. In the command line I can do that by calling gdb via gdb --directory=/path/to/sources or by writing directory /path/to/sources while running gdb.

            How would I do this with qt creator? I want gdb to automatically run with these source directories on startup

            J Offline
            J Offline
            JonB
            wrote on 4 Jul 2023, 16:48 last edited by
            #4

            @Creaperdown
            Have a read of https://stackoverflow.com/questions/35367845/qt-creator-gdb-additional-startup-command-additional-attach-command-what-i

            C 1 Reply Last reply 4 Jul 2023, 18:49
            0
            • J JonB
              4 Jul 2023, 16:48

              @Creaperdown
              Have a read of https://stackoverflow.com/questions/35367845/qt-creator-gdb-additional-startup-command-additional-attach-command-what-i

              C Offline
              C Offline
              Creaperdown
              wrote on 4 Jul 2023, 18:49 last edited by
              #5

              @JonB I have already tried adding it to the "Additional Attach Commands", and I see that something is happening with it, since it says:
              /GdbPostAttachCommands: directory /home/creapermann/Programming/Etovex/temp/mulibrum/libs/mupdf/platform/c++/implementation (default: ) *** in the output, but it does not find my sources when debugging. (Calling this command in the raw tui gui makes it work just fine)

              1 Reply Last reply
              0
              • K Offline
                K Offline
                KH-219Design
                wrote on 4 Jul 2023, 21:11 last edited by
                #6

                I would imagine you can put your command:

                directory /path/to/sources
                

                In this file:

                ~/.gdbinit
                

                I don't use Qt Creator, but I would be surprised if whenever Qt Creator launches gdb it would go out of its way to launch gdb in such a way that inhibits the normal (default gdb) behavior of reading from ~/.gdbinit

                https://sourceware.org/gdb/onlinedocs/gdb/gdbinit-man.html

                In case you end up becoming a fan of ~/.gdbinit, here are some other things to put in it (copied from my own, which accumulates new goodies about once a year):

                # https://sourceware.org/gdb/onlinedocs/gdb/Command-History.html
                set history save on
                
                set max-completions 50
                
                # WISDOM for loading large executables:
                # https://stackoverflow.com/questions/59805689/how-to-make-firefox-startup-faster-in-gdb
                set index-cache on
                

                www.219design.com
                Software | Electrical | Mechanical | Product Design

                C 1 Reply Last reply 4 Jul 2023, 21:19
                0
                • K KH-219Design
                  4 Jul 2023, 21:11

                  I would imagine you can put your command:

                  directory /path/to/sources
                  

                  In this file:

                  ~/.gdbinit
                  

                  I don't use Qt Creator, but I would be surprised if whenever Qt Creator launches gdb it would go out of its way to launch gdb in such a way that inhibits the normal (default gdb) behavior of reading from ~/.gdbinit

                  https://sourceware.org/gdb/onlinedocs/gdb/gdbinit-man.html

                  In case you end up becoming a fan of ~/.gdbinit, here are some other things to put in it (copied from my own, which accumulates new goodies about once a year):

                  # https://sourceware.org/gdb/onlinedocs/gdb/Command-History.html
                  set history save on
                  
                  set max-completions 50
                  
                  # WISDOM for loading large executables:
                  # https://stackoverflow.com/questions/59805689/how-to-make-firefox-startup-faster-in-gdb
                  set index-cache on
                  
                  C Offline
                  C Offline
                  Creaperdown
                  wrote on 4 Jul 2023, 21:19 last edited by
                  #7

                  @KH-219Design Thank you, this did what I wanted to achieve. I also appreciate you sharing the other useful settings for the ~/.gbdinit!

                  1 Reply Last reply
                  1
                  • C Creaperdown has marked this topic as solved on 4 Jul 2023, 21:19
                  • C Creaperdown
                    4 Jul 2023, 16:22

                    @JoeCFD It is needed. It is linked to the debug build, but the sources are somewhere else on my driver. I got it to work by adding the directory=... for gdb, else it was just able to show me the asm code (the src layout didn't work)

                    J Offline
                    J Offline
                    JoeCFD
                    wrote on 4 Jul 2023, 22:39 last edited by
                    #8

                    @Creaperdown Sorry. It is needed. I guess I did it only once long ago.

                    ======try this========================

                    Mapping source paths in debugging is useful when the source code paths on the development machine are different from the paths on the machine where the code is being debugged (e.g., when working with different computers or remote machines). Qt Creator allows you to set up source path mappings to ensure that the debugger can locate the correct source files during debugging. Here's how to do it:

                    Open your project in Qt Creator.
                    
                    Go to the "Debug" mode by clicking the "Debug" button on the left toolbar or selecting "Debug" from the "Build & Run" menu.
                    
                    Once in the debug mode, click on the "Debugger" tab located on the left side of the "Debug" view.
                    
                    In the "Debugger" tab, you will find a section called "Source Path Mapping."
                    
                    Click on the "Add" button (+) within the "Source Path Mapping" section.
                    
                    A dialog will pop up where you can enter the mapping details. In this dialog, you need to specify two paths: the path on the machine where the code is being debugged (Target path), and the corresponding path on your development machine (Source path).
                        Target path: This is the path as seen by the debugger on the machine where the code is running or being debugged. It should be the path that the debugger uses to look for the source files.
                        Source path: This is the corresponding path on your development machine where the actual source files are located.
                    
                    After entering the paths, click "OK" to add the mapping.
                    
                    You can add multiple mappings if needed.
                    
                    Restart your debugging session (close and rerun the debugging) to apply the source path mappings.
                    
                    1 Reply Last reply
                    0

                    1/8

                    4 Jul 2023, 15:30

                    • Login

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