View Full Version : Debugging with gdb on linux
chippo
January 6th, 2007, 08:47 AM
Greets,
I found some bugs (possibly) in legacy-2, which I'd like to look at with gdb.
So, I do an 'svn update' in the TRUNK, and get 'At revision 414.'. An 'svn diff' confirms that I've only modified the Makefile as wanted. Then, I ('make clean' and) recompile legacy without OPT=1, and confirm that all the objects are being compiled with '-g -O0'. And the linking too.
Now, I'd like to run Legacy under gdb control from a virtual console (vc) onto my X server, so that I can single step through code etc., while the game is running.
So I bring up an xterm, and type:
xhost +
echo $DISPLAY
Then I switch to the vc and type:
cd /usr/local/chippo/games/legacy-2/
export LD_LIBRARY_PATH=/usr/local/chippo/lib
export DOOMWADDIR=/usr/share/games/doom
export DISPLAY=:0.0
./Legacy -iwad freedoom.wad
Now, I was expecting the game to run on my Xserver as before, but it just returns to the prompt, without running the game.
Anyone know what I've done wrong? Usually when you mess up X authentication, you get some error message to guide you.
TIA,
chippo
PS: Of course, I tried exactly the same commands in an xterm - works fine. I also tried -devparm, but that doesn't seem to do anything, even when running it from the xterm (where I get to slay some monsters at least).
MR_ROCKET
January 6th, 2007, 09:01 AM
I have no idea about Linux, just going by what you said and what I see.
You'd think if something like that happens though, there would be something to tell you why. or possibly whats missing.
Have you tried it with Doom2 as the Iwad and whether the -nocheckwadversion cvar would work?
Smite will probably be here shortly, until then I thought I'd step in here and say hey :D
chippo
January 6th, 2007, 09:36 AM
Have you tried it with Doom2 as the Iwad
I can't, 'cos I don't have one. Was there a shareware version of Doom2? I thought so, until a few days ago, when I couldn't find one anywhere.
whether the -nocheckwadversion cvar would work?
Well, that _should_ make zero difference, because I have the correct version of legacy.wad. I can know that that's true, 'cos when I run the game from an xterm, I don't need -nocheckwadversion. But lemme check.... Nope. As expected it makes no difference.
Smite will probably be here shortly, until then I thought I'd step in here and say hey :D
Hey Bra! Togetherness in the slaughter.
Ciao,
chip
smite-meister
January 6th, 2007, 12:22 PM
Now, I'd like to run Legacy under gdb control from a virtual console (vc) onto my X server, so that I can single step through code etc., while the game is running.
Why not run Legacy in windowed mode? You can keep the gdb window and the Legacy window side-by-side.
chippo
January 6th, 2007, 03:07 PM
Why not run Legacy in windowed mode?
Of course! That's the right way to do it. What an idiot I am!
But sadly, since I don't understand why it won't work from the vc, I _have_ to study it further. :-( But it would be good to get right, in case someone wants to gdb for a bug that only occurs in fullscreen.
But now that I know how to get hold of stdout and stderr, I'm sure it'll be easy.
Tchuss,
chipli
chippo
January 7th, 2007, 03:55 AM
Why not run Legacy in windowed mode?
Er, how does one do that? I checked all the command line options in docs/legacy.html but I don't see -full or -windowed or some such.
smite-meister
January 7th, 2007, 04:49 AM
Either edit ~/.legacy/config.cfg or glconfig.cfg, making sure there is a line that reads 'fullscreen "No"', or, in the game menu, set
Options -> Video options -> fullscreen
to "No". Then exit the game so the config is saved.
rustyslacker
January 7th, 2007, 07:27 AM
Maybe you should try renaming your freedoom wad to doom2.wad. Dunno if it'll help though. *thumbs*
chippo
January 7th, 2007, 07:58 AM
Maybe you should try renaming your freedoom wad to doom2.wad. Dunno if it'll help though. *thumbs*
It might well, but I don't care to. I can do all the butchery I want with legacy-1.43 (with opengl and sound working). My efforts with legacy-2 are to pin the bugs down and fix 'em. I don't (yet) have any WADs that legacy-1 can't play that legacy-2 can.
But thanks for the advice, though.
rustyslacker
January 7th, 2007, 08:02 AM
Oh, it works with legacy 1.x with that name?
Never mind then. *scurries away*
chippo
January 7th, 2007, 08:32 AM
Oh, it works with legacy 1.x with that name?
Yup. But I think I know why that surprises you.
I think that legacy-1 would _not_ work, if you _only_ had one WAD called 'freedoom.wad'. Then, your advice would be neccessary. But I have another WAD, an Id shareware WAD, called 'Doom1.wad' in the DOOMWADDIR. I think that the existance of this (correctly named) WAD satisfies the legacy-1 conditions that you were trying to steer me around.
I also realize that we're getting a bit off topic for a "Legacy 2.0 Development" forum.
chippo
January 9th, 2007, 08:33 AM
When speaking about debugging legacy-2 on the vc with gdb while the game is running in fullscreen in X:But it would be good to get right, in case someone wants to gdb for a bug that only occurs in fullscreen.
I just got it working! The trick is to use screen (the unix program).
The procedure is:
- bring up an xterm
- cd to the source directory
- (run the game with ./Legacy ... to confirm that you've got everything setup right, and exit)
- run 'screen'
- run 'gdb Legacy'
- set any break points you might like
- type 'run <params>'
- play the game to get to the breakpoints or some error (seg fault etc.)
- switch to a vc
- login and type 'screen -d -r'
And you're inside gdb of the running game.
If you're debugging a crash, when you're finished with gdb and want it all over, be sure to issue the continure command ('c') so that the SDL parachute can deploy and fix X up for you. If you forget to do that, you might have lost your mouse and/or lost the ability to get out of the low-res of the game with CTRL-ALT-+. But you should be able to switch desktops with CTRL-ALT-(cursor(arrow) key). Find an xterm lying around and then run some SDL fullscreen app (which won't bomb) and exit from it correctly to get back your mouse and the correct res.
I happened to pioneer this method while looking at a hexen bug. With my shareware WAD, hexen starts (in opengl and fullscreen) and shows the splash screen when I hit ESC for the menu, it crashes with no interesting error messages.
Here's a transcript of my using this method. I followed the first few steps of my recipe above (without setting any break points), and typed 'run -opengl -iwad hexen.wad'. Then the game appeared, and I hit escape. Then to the vc, login, 'screen -d -r':(gdb) run -opengl -iwad hexen.wad
Starting program: /usr/local/chippo/games/legacy-2/Legacy -opengl -iwad hexen.wad
[Thread debugging using libthread_db enabled]
[New Thread -1223260448 (LWP 12568)]
[New Thread -1224324176 (LWP 12573)]
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1223260448 (LWP 12568)]
0x0805c1f8 in GameInfo::Read_MAPINFO (this=0x8298980) at g_mapinfo.cpp:737
737 info->nextlevel = warptransmap[info->warpnext]->mapnumber;
(gdb) bt
#0 0x0805c1f8 in GameInfo::Read_MAPINFO (this=0x8298980) at g_mapinfo.cpp:737
#1 0x0811dd7b in Menu::Open () at menu/menu.cpp:3036
#2 0x0811e23c in Menu::Responder (ev=0x82af520) at menu/menu.cpp:2726
#3 0x08138b84 in D_ProcessEvents () at d_main.cpp:144
#4 0x081a7696 in GameInfo::TryRunTics (this=0x8298980, elapsed=1)
at sv_main.cpp:327
#5 0x08138c40 in D_DoomLoop () at d_main.cpp:190
#6 0x081aac32 in main (argc=4, argv=0xbfc83584) at i_main.cpp:37
(gdb) list
732 info = r->second;
733
734 // set normal and secret exits
735 // 'nextlevel' overrides 'next'
736 if (info->nextlevel < 0 && info->warpnext > 0)
737 info->nextlevel = warptransmap[info->warpnext]->mapnumber;
738 }
739
740 // backwards compatibility
741 if (episodes.empty() && !mapinfo.empty())
(gdb) p info->warpnext
$1 = 5
(gdb) p warptransmap[5]
Attempt to take address of value not located in memory.
(gdb) p warptransmap
$2 = {_M_t = {
_M_impl = {<std::allocator<std::_Rb_tree_node<std::pair<const int, MapInfo*> > >> = {<__gnu_cxx::new_allocator<std::_Rb_tree_node<std::pair<const int, MapInfo*> > >> = {<No data fields>}, <No data fields>},
_M_key_compare = {<> = {<No data fields>}, <No data fields>},
_M_header = {_M_color = std::_S_red, _M_parent = 0x85f17f0,
_M_left = 0x85f17d0, _M_right = 0x85f1850}, _M_node_count = 5}}}
(gdb) c
Continuing.
[Thread -1224324176 (zombie) exited]
Program exited with code 01.
I'm not asking anyone to look into this issue; I intend to do that myself and only posted it as a proof of concept. But, of course, if someone just happens to know, well...
When you've back in X, then it can be quite useful to reattach to the screen session (again with screen -d -r) so that you can cut'n'paste stuff from the gdb session into other things (like I did here).
Tchuss,
chip
vBulletin® v3.8.3, Copyright ©2000-2010, Jelsoft Enterprises Ltd.