Can gdb debug an inferior that grabs the mouse?

Viewed 43

When gdb hits a breakpoint, while inferior has grabbed the mouse, my mouse does not work. Since I use gdb within an IDE, that completely freezes the computer. Hours of search only showed "--no_grab" somewhere, which is not in any gdb documentation. So the question is: Is there a command or option to tell gdb to momentarily ungrab the mouse while stopped at a breakpoint?

I was also curious whether xlib could indicate that some window has grabbed the mouse, and provide the ID of the window? This search never provided an answer.

I will be more than glad to know neither is possible, and stop further search. Thanks.

1 Answers

GDB has no understanding of xlib, or of the idea of grabbing (or ungrabbing) the mouse, this is all part of the program you are debugging.

You could potentially, from GDB, call the correct library function to ungrab the mouse, the documentation for this can be found here, but would look something like:

(gdb) call function_to_ungrab_mouse()

Of course, this would leave your program in an unexpected state, so when you resume it might not behave as you expect, so before you continue you might want to call the function to grab the mouse again.

If you know that a particular breakpoint is at a location where the mouse is grabbed, and you always want to ungrab when you hit that breakpoint, then you could make use of breakpoint commands, these are documented here, but would look something like:

(gdb) break LOCATION_WHERE_MOUSE_IS_GRABBED
(gdb) commands
call function_to_ungrab_mouse()
end
(gdb)

Another option to consider, if you have the facilities, is remote debugging. On the machine running the X application you want to debug you can use gdbserver to either start, or attach to the application. Then, on a different machine you can run GDB and connect to gdbserver. Now when the application breaks, and the mouse is grabbed, your second machine will not be impacted, and you can continue to debug. Of course, the setup with gdbserver can be a little more involved, you'll need access to the application source code on the machine running GDB, and you'll need network access between the two machines, but this could be a solution.

Related