With the latest GDB available, you can debug applications available via HaikuPorts.
In this article we will review how to quickly setup the HaikuPorts build in debug mode and enter into the debugging land:)
Before moving further, you need to have setup HaikuPorts as indicated in Build with HaikuPorts but also QtCreator as reviewed in Debug with GDB.
Today we will debug Emulation Station Desktop Edition (ES-DE) which is available on HaikuPorts.
From the haikuports folder, type the below commands in a Terminal to edit ES-DE recipe :
cd games-emulation/es-de
lpe es_de-3.1.0.recipe &
Then indicate CMAKE_BUILD_TYPE=Debug like below :
Save the recipe. Now compile es_de with the below haikuporter command :
hp es_de
Note : in case a previous build was already compiled, my advice is to delete the "work-*" directory.
The completion of the build should display the below :
Ok great, now go into the directory where the sources were compiled :
cd work-3.1.0/sources/emulationstation-de-842c9966eb73efb3436a4df2dfdd66063ce7361c/
The binary named "es-de" is the program to debug.
Verify if the debug symbols are available :
file es-de
If "with debug_info" is displayed, you can go to the next step.
Launch QtCreator and go into the "Edit > Preferences" menu :
In the "Debugger" section and "General" tab, add a new source paths mapping :
This mapping is necessary in case of ES-DE, because the executable indicates that the sources are in the "/sources" directory, whereas this directory is not a root directory. In order to fix that, indicates :
Adapt the target path depending on your setup. Now go into "Debug > Start Debugging" :
Then indicate :
The command line arguments is important, because in case of ES-DE it will allow to launch it in a windowed mode, instead of full screen which can be tricky when debugging.
Confirm the launch of the debugging with "Ok".
After a few seconds, as indicated in the previous window ("break at main" ticked), there's a default breakpoint in the main() :
Click on "Continue" debugging to make the program run.
ES-DE should be displayed like below on the right :
Put a breakpoint in the file named "SystemView.cpp" in the Input() method.
If you don't know where this file is, below is its location :
es-app/src/views/
If you go back to ES-DE and hit arrow up or down, the breakpoint will take effect.
The program will stop, waiting for you to debug :
You can step into/over and start your debugging.
If you continue the program again, the previous/next system will be displayed as below confirming the debugger is interacting correctly with the program :
Debugging other programs from HaikuPorts will use the same approach :
you will need to identify in the "recipe" which option need to be modified to rebuild the package with debugging information.
Regarding the source paths mapping in QtCreator, I'm not sure if it's always needed, but it was required in the case of ES-DE.
Happy debugging :)