# Debugging SDL

**URL:** <https://discourse.libsdl.org/t/debugging-sdl/7854>\
**Category:** SDL Development\
**Created:** [December 1, 2002, 10:38am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854 "2002-12-01T10:38:01Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Duncan\_Hughes](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Duncan\_Hughes](https://discourse.libsdl.org/u/Duncan_Hughes)\
**Post date:** [December 1, 2002, 10:38am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/1 "2002-12-01T10:38:01Z")

</div>

Hi Folks, I’m new to SDL and I’m finding debugging a bit of a nightmare. I’m  
working mostly from the console in mipsEEel-linux and find that certain  
operations will cause my code to crash, SDL seems to take complete control of  
the input devices on my system and i can’t swap to another virtual terminal  
to kill the process off or even reset the system and i’m forced to do a hard  
reboot.  
Is there a way I can get back to a shell once SDL has crashed? I don’t really  
want to work in X because of the speed difference.

Thanks  
dunch.–

* * *

Duncan Hughes (@Duncan_Hughes)

* * *

---

<div class="post-metadata">

**Author:** ![slouken](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/s/ec9cab/32.png) [@slouken](https://discourse.libsdl.org/u/slouken)\
**Post date:** [December 3, 2002, 11:34pm UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/2 "2002-12-03T23:34:03Z")

</div>

> Hi Folks, I’m new to SDL and I’m finding debugging a bit of a nightmare. I’m  
> working mostly from the console in mipsEEel-linux and find that certain  
> operations will cause my code to crash, SDL seems to take complete control of  
> the input devices on my system and i can’t swap to another virtual terminal  
> to kill the process off or even reset the system and i’m forced to do a hard  
> reboot.  
> Is there a way I can get back to a shell once SDL has crashed?

Is SDL handling the crash and calling the SDL\_Parachute function to reset  
the video mode?

See ya,  
-Sam Lantinga, Software Engineer, Blizzard Entertainment

---

<div class="post-metadata">

**Author:** ![Duncan\_Hughes](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Duncan\_Hughes](https://discourse.libsdl.org/u/Duncan_Hughes)\
**Post date:** [December 4, 2002, 6:48am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/3 "2002-12-04T06:48:01Z")

</div>

not that I can see, when SDL crashes all i have is a blank (graphics mode)  
screen with an (imovable) mouse cursor in the top left corner.  
I’ve found that crashes are far less frequent when I use C rather than C++ so  
I’m back coding in C (which is a bit of a nuisance as I’d like to use the  
STL).  
To compound the problem, I’m working on Playstation2 Linux which doesn’t  
behave entirely like Intel Linux, I can’t use gdb with and SDL graphics mode  
application unless I’m working from XWindows.

Is there a flag I can set to ensure calling the SDL\_Parachute function or  
something similar?

Thanks  
dunch.On Wednesday 04 December 2002 07:30, Sam Lantinga wrote:

> > Hi Folks, I’m new to SDL and I’m finding debugging a bit of a nightmare.  
> > I’m working mostly from the console in mipsEEel-linux and find that  
> > certain operations will cause my code to crash, SDL seems to take  
> > complete control of the input devices on my system and i can’t swap to  
> > another virtual terminal to kill the process off or even reset the system  
> > and i’m forced to do a hard reboot.  
> > Is there a way I can get back to a shell once SDL has crashed?
> 
> Is SDL handling the crash and calling the SDL\_Parachute function to reset  
> the video mode?

---

<div class="post-metadata">

**Author:** ![Christopher\_Thielen](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/c/ce73a5/32.png) [@Christopher\_Thielen](https://discourse.libsdl.org/u/Christopher_Thielen)\
**Post date:** [December 4, 2002, 7:13am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/4 "2002-12-04T07:13:01Z")

</div>

Er, my method is always if SDL initializes correctly, I call  
atexit(SDL\_Quit) before doing anything else, so if my program seg faults  
or there’s a crash, SDL\_Quit() will still be called. I don’t know if  
you’re already doing something like this though. atexit() is an ANSI  
function I believe.On Wed, 2002-12-04 at 07:55, Duncan Hughes wrote:

> Is there a flag I can set to ensure calling the SDL\_Parachute function or  
> something similar?

–  
Chris Thielen \<@Christopher\_Thielen\>

---

<div class="post-metadata">

**Author:** ![Glenn\_Maynard](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/g/bcef8e/32.png) [@Glenn\_Maynard](https://discourse.libsdl.org/u/Glenn_Maynard)\
**Post date:** [December 4, 2002, 9:37am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/5 "2002-12-04T09:37:00Z")

</div>

atexit() handlers won’t be called if your program exits abnormally (eg  
via a signal).

If you have a SEGV handler and you exit() from it, it might, but then  
you’re probably not able to write a core file, which would make  
debugging much harder.On Wed, Dec 04, 2002 at 07:04:28AM -0800, Chris Thielen wrote:

> > Is there a flag I can set to ensure calling the SDL\_Parachute function or  
> > something similar?
> 
> Er, my method is always if SDL initializes correctly, I call  
> atexit(SDL\_Quit) before doing anything else, so if my program seg faults  
> or there’s a crash, SDL\_Quit() will still be called. I don’t know if  
> you’re already doing something like this though. atexit() is an ANSI  
> function I believe.

–  
Glenn Maynard

---

<div class="post-metadata">

**Author:** ![Duncan\_Hughes](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Duncan\_Hughes](https://discourse.libsdl.org/u/Duncan_Hughes)\
**Post date:** [December 4, 2002, 11:04am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/6 "2002-12-04T11:04:01Z")

</div>

> > Is there a flag I can set to ensure calling the SDL\_Parachute function or  
> > something similar?

> Er, my method is always if SDL initializes correctly, I call  
> atexit(SDL\_Quit) before doing anything else, so if my program seg faults  
> or there’s a crash, SDL\_Quit() will still be called. I don’t know if  
> you’re already doing something like this though. atexit() is an ANSI  
> function I believe.

yeah, I’m already doing that and i’ve written a signal handler to call  
SDL\_Quit whenever I press ctrl+c but that doesn’t work either.

It seems that SDL grabs complete control of the keyboard/mouse/display  
whenever i run from the console and when it locks up I’m unable to regain  
control of the system, for example if I set a breakpoint in gdb, the program  
runs until the breakpoint is hit but then keeps control of the  
screen/keyboard so I’ve effectively lost control of the sytem.

I suspect that this is a problem with the SDL/Playstation2 drivers and I’m  
hoping that someone on the list has some experience of the ps2 and can tell  
me for sure.

Oh well, I am starting to make a little progress now with SDL which I think is  
a really good library. I’m just having a few teething troubles.

Thanks, dunch.On Wed, 2002-12-04 at 07:55, Duncan Hughes wrote:  
On Wed, 2002-12-04 at 07:04:28, Chris Thielen wrote:

---

<div class="post-metadata">

**Author:** ![Loren\_Osborn](https://discourse.libsdl.org/letter_avatar_proxy/v4/letter/l/7c8e57/32.png) [@Loren\_Osborn](https://discourse.libsdl.org/u/Loren_Osborn)\
**Post date:** [December 4, 2002, 11:39am UTC](https://discourse.libsdl.org/t/debugging-sdl/7854/7 "2002-12-04T11:39:01Z")

</div>

What I typically do is telnet (or ssh or whatever) into my test system  
from another box, and (in X) run it in the debugger on the test-box  
display from a telnet terminal, or (for fbcon) attach to it with the  
debugger after it’s already running…

Hope that helps…

-LorenOn Wed, 2002-12-04 at 12:11, Duncan Hughes wrote:

> yeah, I’m already doing that and i’ve written a signal handler to call  
> SDL\_Quit whenever I press ctrl+c but that doesn’t work either.
> 
> It seems that SDL grabs complete control of the keyboard/mouse/display  
> whenever i run from the console and when it locks up I’m unable to regain  
> control of the system, for example if I set a breakpoint in gdb, the program  
> runs until the breakpoint is hit but then keeps control of the  
> screen/keyboard so I’ve effectively lost control of the sytem.
> 
> I suspect that this is a problem with the SDL/Playstation2 drivers and I’m  
> hoping that someone on the list has some experience of the ps2 and can tell  
> me for sure.
> 
> Oh well, I am starting to make a little progress now with SDL which I think is  
> a really good library. I’m just having a few teething troubles.
