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.