debugging with gdb on linux

A place for users of OGRE to discuss ideas and experiences of utilitising OGRE in their games / demos / applications.
Post Reply
pix
Kobold
Posts: 28
Joined: Thu Sep 02, 2004 7:13 pm
x 1

debugging with gdb on linux

Post by pix »

this comes up on #ogre3d from time to time, so i thought i'd make a note here so people find it.

to debug with gdb on linux, you need to get around the fact that when gdb suspends the ogre application, it doesn't free the keyboard and mouse grab. to get around this, you can set the AllowDeactivateGrabs option in your X server config. then, you can reclaim your mouse and keyboard by hitting ALT + CTRL + KEYPAD /

my laptop doesn't have a separate keypad, so for me it's ALT + CTRL + Fn + /

so, in my /etc/X11/XF86Config-4 (or maybe your /etc/X11/xorg.conf):

Code: Select all

Section "ServerFlags"
...
Option "AllowDeactivateGrabs" "on"
...
EndSection
i assume it's a similar option for XOrg.

you can also release the grab while your ogre application is running normally, but it will still get mouse motion events when the mouse is in the window, so your camera will go a bit crazy as you move your mouse to another app. if your window manager has the option to switch windows from the keyboard, and also warps the mouse-pointer accordingly, your might be able to do something like ALT-TAB to get away from the ogre window without affecting the camera view.

another tip that people might find useful, is that when ogre crashes in fullscreen mode and doesn't reset your screen resolution, you can fix this by running

Code: Select all

xrandr -s 0
if your display is so small you can't get to a terminal, you can switch to a console (probably with CTRL + ALT + 2), logging in and running

Code: Select all

DISPLAY=:0 xrandr -s 0
pix.
Last edited by pix on Mon Jun 12, 2006 5:32 pm, edited 1 time in total.

User avatar
Olex
Hobgoblin
Posts: 593
Joined: Fri Apr 08, 2005 6:08 pm
Location: WA, USA

Post by Olex »

Woohah, this is really a great tip. I get this issue all the time. :D

Thanks a lot!

lakin.wecker
Halfling
Posts: 49
Joined: Tue Feb 28, 2006 5:00 am

Re: debugging with gdb on linux

Post by lakin.wecker »

pix wrote: ...
so, in my XF86Config-4:

Code: Select all

Section "ServerFlags"
...
Option "AllowDeactivateGrabs" "on"
...
EndSection
i assume it's a similar option for XOrg.
Yes, but the configuration file for XOrg, is named xorg.conf and can be found in /etc/X11/xorg.conf for (Ubuntu and Debian based distros).

User avatar
Olex
Hobgoblin
Posts: 593
Joined: Fri Apr 08, 2005 6:08 pm
Location: WA, USA

Post by Olex »

Same for Gentoo.

User avatar
xavier
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 9481
Joined: Fri Feb 18, 2005 2:03 am
Location: Dublin, CA, US
x 22

Post by xavier »

Sweet, thanks. :)

/me puts this on a Post-It on the monitor ;)

User avatar
pjcast
OGRE Retired Team Member
OGRE Retired Team Member
Posts: 2543
Joined: Fri Oct 24, 2003 2:53 am
Location: San Diego, Ca
x 2
Contact:

Post by pjcast »

Yes, defintely nice tips guys :) I always hate when my mouse is locked up.
Have a question about Input? Video? WGE? Come on over... http://www.wreckedgames.com/forum/

User avatar
DoBs
Kobold
Posts: 26
Joined: Fri May 11, 2007 12:07 am
Location: Pisa, Italy
Contact:

Post by DoBs »

In my ubuntu with alt+tab i can't regrab my mouse to ogre application, so i can't continue to work after start debugging.

anyone know how to fix this?

tnx :)

User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

Click on the render window again :)
Image

User avatar
DoBs
Kobold
Posts: 26
Joined: Fri May 11, 2007 12:07 am
Location: Pisa, Italy
Contact:

Post by DoBs »

Yes, i did it, but it don't work right

Before type alt + ctrl + /

i can't exit from my ogre3d application window

after type alt + ctrl + /

the mouse is in the application and in the desktop, and that two cursor isn't alligned

User avatar
Kencho
OGRE Retired Moderator
OGRE Retired Moderator
Posts: 4011
Joined: Fri Sep 19, 2003 6:28 pm
Location: Burgos, Spain
x 2
Contact:

Post by Kencho »

I haven't had any issues with alt+tab in Linux (at least in windowed mode). Anyone can confirm this?
Image

User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 217
Contact:

Re: debugging with gdb on linux

Post by Jabberwocky »

Regarding the original post, the AllowDeactivateGrabs option is no longer supported in newer versions of linux. So this no longer works (at least on Ubuntu 12.04).

I found another way (sort of - see below) to fix the "I can't debug in linux because I have no mouse pointer" problem.
Here's the details: http://who-t.blogspot.ca/2012/01/xkb-br ... -0064.html
That link explains how you can re-enable this functionality. Pay attention to the security warning about this - enabling this feature allows you to bypass your login screen by using these keyboard shortcuts.

Basically, what you're doing is enabling two keyboard shortcuts:
1. cntl-alt-KEYBOARD_DIVIDE : triggers a "XF86Ungrab"
2. cntl-alt-KEYBOARD_MULTIPLY : triggers a "XF86ClearGrab"

So the idea is, when you hit a breakpoint, you hit either of these two keyboard shortcuts and you'll get a mouse pointer back. On my machine, only cntl-alt-KEYBOARD_MULTIPLY seems to work. This isn't perfect, because once you use this shortcut, you can't ever seem to re-attach input to your program. But at least you can get into the debugger at that point.

On Ubuntu (12.04), here's the precise steps I used to enable this key command:
1. Run app "Keyboard Layout" - to find this app, you can type "keyboard" in the search box of the "Dash Home" start button
2. Click "Options..." button
3. Expand "Miscellaneous compatability options"
4. Check "Allow breaking grabs with keyboard actions (warning: security risk)
5. Now, when you hit a breakpoint, hit cntl-alt-KEYBOARD_MULTIPLY to get your mouse pointer.
Image

scrawl
OGRE Expert User
OGRE Expert User
Posts: 1119
Joined: Sat Jan 01, 2011 7:57 pm
x 214

Re: debugging with gdb on linux

Post by scrawl »

Why the hassle? Just add a --debug switch to your app that runs OIS (or whatever input lib you are using) in nonexclusive mode.

User avatar
Jabberwocky
OGRE Moderator
OGRE Moderator
Posts: 2819
Joined: Mon Mar 05, 2007 11:17 pm
Location: Canada
x 217
Contact:

Re: debugging with gdb on linux

Post by Jabberwocky »

If you don't grab the mouse, then it's almost impossible to play the game. You can only turn your character/ship a bit before the mouse goes off the edge of the screen. I guess for some kinds of games, this might not be a big deal. For Salvation Prophecy, there's no way you're going to survive a battle like that! :twisted:

Of course, not all bugs are in the middle of a big battle. But some of them are. And I like to be able to jump into the debugger at any time if my code trips an assert.
Image

Post Reply