Debugging exceptions

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
kazade
Insane DCEmu
Insane DCEmu
Posts: 145
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Tue May 02, 2017 3:11 pm
Has thanked: 3 times
Been thanked: 34 times

Debugging exceptions

Post by kazade »

I'm just wondering if there is a way I can get more information from an exception like this one?

Code: Select all

Unhandled exception: PC 8c09d9fe, code 1, evt 00e0
 R0-R7: 00000001 4328e3ff 00000004 00000000 00000053 8c7dc35c 8c7dc65c 00000004
 R8-R15: ffffff18 ffffff18 8c149c60 ffffff00 8cfff9ec 8cfff898 8cfff874 8cfff874
 SR 40000100 PR 8c09d9f6
Stack Trace: frame pointers not enabled!
kernel panic: unhandled IRQ/Exception
arch: aborting the system
I'm guessing the two RX rows are the register values, and PC is the program counter? Is there some way to use this info to figure out where the exception was triggered?

Also, it says "frame pointers not enabled" but I've tried -fno-omit-frame-pointer and removed -fno-frame-pointer from environ.sh and still I get the same thing.
User avatar
BlueCrab
The Crabby Overlord
The Crabby Overlord
Posts: 5660
Joined: Mon May 27, 2002 11:31 am
Location: Sailing the Skies of Arcadia
Has thanked: 9 times
Been thanked: 69 times
Contact:

Re: Debugging exceptions

Post by BlueCrab »

To answer the second question first, to get frame pointers to work, you need to compile KOS with frame pointers enabled, as well as your program. Open up your environ script, and make the default KOS_CFLAGS something like this:

Code: Select all

export KOS_CFLAGS="-O2 -DFRAME_POINTERS -fno-omit-frame-pointer"
Then do a "make clean" and a "make" on KOS itself, then your own code too.

And now, to answer the second question, the easiest thing to do is to use sh-elf-addr2line on the elf file you're debugging. Check the PC, PR, and all of the frame pointer addresses that look sane and hopefully that'll help you out.

Also, looking up the event code in the SH4 programming manual can be helpful too. In your case, evt 00e0 corresponds to an address error on a read access. Usually, that means you've attempted to read something from an unaligned address (so, attempting to read a 32-bit value from an address that isn't divisible by 4 or a 16-bit value from an odd address). For reference, evt 0100 is the same thing, but for a write access. Those are probably the two most common exceptions you'll see. :wink:
kazade
Insane DCEmu
Insane DCEmu
Posts: 145
Joined: Tue May 02, 2017 3:11 pm
Has thanked: 3 times
Been thanked: 34 times

Re: Debugging exceptions

Post by kazade »

Thanks that's really helpful. It turned out to be me accessing an uninitialized pointer (which I tracked down with logging statements :P )
Post Reply