gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

DS development > Debugging stack problems

#117944 - SukkoPera - Thu Feb 08, 2007 9:53 pm

I think I am experiencing some problems with the stack, allocating too many local variables and therefore overwriting memory areas not belonging to the stack.

Is there a way to debug this? It would be enough to retrieve the stack position and print it, how can I do it?
_________________
Nintendo DS Lite (White) + Supercard Lite + R4 + Sandisk 1 GB MicroSD
Sony PSP + Firmware 3.03 OE-A2

#117972 - wintermute - Thu Feb 08, 2007 11:25 pm

On the DS a stack overrun should trigger an MPU exception. You could try using the default exception handler in libnds.

http://tinyurl.com/33e4a6

If you want to try tracking the value of the stackpointer then you could use

Code:

register char * stack_ptr asm ("sp");


which defines stack_ptr as a C variable which will hold the current stack address.
_________________
devkitPro - professional toolchains at amateur prices
devkitPro IRC support
Personal Blog

#117977 - SukkoPera - Thu Feb 08, 2007 11:40 pm

Thanks a lot, that's all I needed!
_________________
Nintendo DS Lite (White) + Supercard Lite + R4 + Sandisk 1 GB MicroSD
Sony PSP + Firmware 3.03 OE-A2