-->
Page 1 of 1

GDBStub throws exception

PostPosted: Sat Feb 03, 2018 10:42 am
by sake402
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 allFatal exception (3):
epc1=0x4026ffc4
epc2=0x00000000
epc3=0x402213bb
epcvaddr=0x401010b8
depc=0x00000000
retn_add=0x4027084c



Address 4026ffc4 is this

Code: Select allstatic 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