How do you debug the captured mouse game with a gdb GUI?

Everything about development and the OpenMW source code.
Post Reply
RolandDH
Posts: 2
Joined: 04 Jul 2017, 17:36

How do you debug the captured mouse game with a gdb GUI?

Post by RolandDH »

Does any tool support that? On linux? Or does it mean one has to go back to command line gdb?

Edit: Hrmmpf: When I came back from posting this to qtcreator, it had it's mouse activated. So it seems only a matter of massaging it a little.
Chris
Posts: 1626
Joined: 04 Sep 2011, 08:33

Re: How do you debug the captured mouse game with a gdb GUI?

Post by Chris »

It can be pretty annoying to have to play without mouse grabbing, especially if the bug doesn't occur quickly after starting. Luckily there is an alternative for GDB-based debuggers. GDB allows running python script functions when it breaks/stops the program, and can also call functions in the app while it's stopped. This is a script that has helped me:

Code: Select all

#!/usr/bin/python
# release mouse when breaking into debugger for SDL2 programs
# put this next to the executable you wanna debug and name it
# <YourExecutableName>-gdb.py
# Make sure that it's in a subdir of an allowed GDB auto-loading safe-path,
# see https://sourceware.org/gdb/onlinedocs/gdb/Auto_002dloading-safe-path.html
# e.g. by executing in a terminal:
# $ echo "add-auto-load-safe-path /path/to/project" >> ~/.gdbinit

def release_mouse (event):
        gdb.write("GDB/SDL2: Releasing mouse\n")
        gdb.execute("call SDL_SetRelativeMouseMode(0)")

        # TODO: if you use SDL_SetWindowGrab(), you may have to write
        #       function with no arguments to call it with your SDL_Window*
        #       handle and call this as well, like:
        #gdb.execute("call DEBUG_UngrabMouse()")

        # TODO: the following doesn't seem to work, maybe it does for you.
        #       either way, it needs xdotool installed.
        #gdb.execute("exec xdotool key XF86Ungrab")

gdb.events.stop.connect(release_mouse)
gdb.write("GDB/SDL2: installed release mouse for SDL2\n")
Note that the script can be in any sub-directory of the specified safe path, so if you have all your projects in a common directory (e.g. $HOME/projects/openmw, $HOME/projects/somethingelse, $HOME/projects/anotherthing) you can just specify $HOME/projects as the safe path and GDB will allow the script to work for them all.
User avatar
scrawl
Posts: 2152
Joined: 18 Feb 2012, 11:51

Re: How do you debug the captured mouse game with a gdb GUI?

Post by scrawl »

Nifty. If that script is confirmed working for others, maybe it could go on the Wiki as well?
Post Reply