Automatically append source directory to gdb when debugging
-
wrote on 4 Jul 2023, 15:30 last edited by
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 writingdirectory /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
-
wrote on 4 Jul 2023, 21:11 last edited by
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
-
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 writingdirectory /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
wrote on 4 Jul 2023, 16:18 last edited by@Creaperdown I guess this is not needed if your app is linked to the debug build of your lib.
-
@Creaperdown I guess this is not needed if your app is linked to the debug build of your lib.
wrote on 4 Jul 2023, 16:22 last edited by@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)
-
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 writingdirectory /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
wrote on 4 Jul 2023, 16:48 last edited by -
wrote on 4 Jul 2023, 18:49 last edited by
@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) -
wrote on 4 Jul 2023, 21:11 last edited by
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
-
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
wrote on 4 Jul 2023, 21:19 last edited by@KH-219Design Thank you, this did what I wanted to achieve. I also appreciate you sharing the other useful settings for the ~/.gbdinit!
-
-
@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)
wrote on 4 Jul 2023, 22:39 last edited by@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/8