GDBStub throws exception

sake402
Posts: 7
Joined: Fri Sep 30, 2016 6:18 am

GDBStub throws exception

Postby sake402 » Sat Feb 03, 2018 11:48 pm

Hello guys

So I have an application I need to debug with GDBStub. I compiled my application along side gdb stub and then a fatal exception 3 begins. I decompiled the the elf to find the location of the exception and it turs out to be within gdbstub_init itself

Code: Select all

Fatal exception (3):
epc1=0x4026ffc4
epc2=0x00000000
epc3=0x402213bb
epcvaddr=0x401010b8
depc=0x00000000
retn_add=0x4027084c


Address 4026ffc4 is this

Code: Select all

static void ATTR_GDBINIT install_exceptions() {
//Replace the user_fatal_exception_handler by a jump to our own code
int *ufe=(int*)user_fatal_exception_handler;
//This mess encodes as a relative jump instruction to user_fatal_exception_handler
*ufe=((((int)gdbstub_user_exception_entry-(int)user_fatal_exception_handler)-4)<<6)|6;
4026ffb0: ffff41 l32r a4, 4026ffac <getaregval+0x24>
4026ffb3: fffd21 l32r a2, 4026ffa8 <getaregval+0x20>
4026ffb6: fcc222 addi a2, a2, -4
4026ffb9: c02240 sub a2, a2, a4
4026ffbc: 1122a0 slli a2, a2, 6
4026ffbf: 630c movi.n a3, 6
4026ffc1: 202230 or a2, a2, a3
4026ffc4: 005422 s16i a2, a4, 0
4026ffc7: f52020 extui a2, a2, 16, 16
4026ffca: 015422 s16i a2, a4, 2
4026ffcd: f00d ret.n


I realized gdb was trying to modify the IRAM address of user_fatal_exception_handler in the SDK.
But I dont understand why it throws at this point

Bernard
Posts: 4
Joined: Tue Apr 17, 2018 10:49 pm
Location: France

Re: GDBStub throws exception

Postby Bernard » Fri Jun 08, 2018 11:39 pm

A little bit late but, did you check the address of user_fatal_exception_handler() function?
The only thing I can imagine is that this function is at a location you are not authorized to write and this will generate the exception...

jcmvbkbc
Posts: 13
Joined: Fri Oct 24, 2014 7:27 pm

Re: GDBStub throws exception

Postby jcmvbkbc » Wed Jul 11, 2018 4:47 am

Bernard wrote:The only thing I can imagine is that this function is at a location you are not authorized to write and this will generate the exception...

It's because IRAM may only be read and written in aligned 32-bit words, but the failing instruction attempts to write 16 bits.

Who is online

Users browsing this forum: No registered users and 14 guests