I have an application with a GUI which I run on the command line, directly in the X server, without using a windows manager:
sudo startx app args
I'm trying to debug the application and would like to use gdb. How do I start the application in gdb? I've tried this but it doesn't work:
sudo gdb --args startx app args
I've tried this but it doesn't work
It doesn't work because startx
is a shell script:
$ file /usr/bin/startx
/usr/bin/startx: POSIX shell script, ASCII text executable
You almost certainly don't want to debug a shell script with GDB.
What you probably want is to start the application normally, then attach GDB to it:
sudo startx app args
sudo gdb -p $(pgrep app)
Note also that debugging applications from the same display on which the application runs is ill-advised: if you set a breakpoint in a context where the application has grabbed the X server, then all your keystrokes will go to the application, and there would be no way to continue the application.