When running a Qt application with a debugger (gdb), the option --nograb is implicitly passed to the application. This prevents the application from stealing your keyboard, so you're still in control of the console where GDB runs if something goes wrong.
Sometimes this is undesirable. I had to obtain a backtrace of some segmentation fault in Klipper (the KDE clipboard tool), which was only reproducible when Klipper is in a state that it grabbed the keyboard. The solution is to open a shell outside X and doing the following steps:
- Set the display variable, otherwise your application won't start:
$ export DISPLAY=:0 - Start your application with GDB and run the application.
$ gdb `which klipper`
(gdb) set args --nofork --dograb
(gdb) runSo you see I'm passing --dograb to the application to make sure the keyboard can be grabbed. --nofork is often necessary for KDE applications.
- Go back to your X display and reproduce the crash while the application resides in grabbed state. X won't respond to anything you type, because the application hasn't ungrabbed the keyboard so far.
- Go back to your GDB session on one of your virtual terminals (Ctrl+Alt+F1), this shortcut still works, fortunately
. - And type:
(gdb) set logging on
(gdb) bt
(gdb) quitto obtain your backtrace (saved in gdb.txt) and quit GDB. When you return to X, your keyboard will just work fine now because the grabbing application has ended.