Skip to content

Latest commit

 

History

History
434 lines (375 loc) · 45.6 KB

gdbanalysis.md

File metadata and controls

434 lines (375 loc) · 45.6 KB

Analysis of the gdb assert

When using gdb to step into 'c' functions we get an assertion in gdb when stepping through the return statement. Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed. This is really annoying therefore I made an analysis of the gdb protocol sent between gdb and qemu.

The problem can be worked around by not doing n past return statement but instead step up (up) and set a breakpoint at next instruction and then do continue. (c)

Stop here

(gdb) b app_main

(gdb) p $windowstart
$3 = 24
(gdb)  p $windowbase
$4 = 4

(gdb) n

  187     void app_main()                
B+188     {       
  189
  190         esp_log_level_set("*", ESP_LOG_INFO);      
  >191        nvs_flash_init();
  192         system_init();
  193         xTaskCreate(&dump_task, "dump_task", 2048, NULL, 5, NULL);
  194     }                                        




B+>0x400d1984 <app_main>           entry  a1, 48                                                                                                   0x400d1987 <app_main+3>         l32r   a10, 0x400d0274 <_stext+604> 
  0x400d198a <app_main+6>         movi.n a11, 3
  0x400d198c <app_main+8>         call8  0x400d0b48 <esp_log_level_set>
  0x400d198f <app_main+11>        call8  0x400d99d0 <nvs_flash_init()>
  0x400d1992 <app_main+14>        call8  0x400d1a04 <system_init
  0x400d1995 <app_main+17>        l32r   a8, 0x400d017c <_stext+356> 
  0x400d1998 <app_main+20>        s32i.n a8, a1, 0
  0x400d199a <app_main+22>        l32r   a10, 0x400d0278 <_stext+608>   
  0x400d199d <app_main+25>        l32r   a11, 0x400d027c <_stext+612>  
  0x400d19a0 <app_main+28>        l32r   a12, 0x400d014c <_stext+308>      
  0x400d19a3 <app_main+31>        movi.n a13, 0                           

Stop at row 190

(gdb) n

// Set breakpoint at 400d1984 (app_main)
-> $Z0,400d1984,2#e2+
<- $OK#9a+
// ‘vCont[;action[:thread-id]]...’
//  Resume the inferior, specifying different actions for each thread.
-> $vCont;s:1;c#c1+
// Find out if the thread thread-id is alive.
-> $T05thread:01;#07+
// g -read general registers
-> $g#67+
// pc=4000d198a 
<-$8a190d40000000000000000002000000d071fb3fff3c0880c071fb3f00000000ec02fb3f00000000000000000000000001000000000000004062fb3f0000000000000000000000002062fb3f00000000000000000000000000000000000000000000000032050d80f061fb3f000000000000000023000600000000000100000001000000292408804071fb3fe011403f230006002300060000003fb3ffff3fb3230006002300060000003fb3ffff3fb32800fb3f292408803071fb3f03000000230006002300060000003fb3ffff3fb3a04bfb3f01000000584bfb3f15000000e071fb3f000000002072fb3f0a0000000072fb3f00000000f071fb3f0000000000000000000000000000000000000000000000000600000058000000feffbcc296fec51c200006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000002c050d40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000071f00100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000032050d80f061fb3f000000000000000023000600000000000100000001000000292408804071fb3fe011403f230006002300060000003fb3#e0+
// Read one byte 400d198a (<app_main+6>)
$m400d198a,1#c5+
$0c#93+
$m400d1984,6#9d+
$366100a13bfa#1e+
$vCont;s:1;c#c1+
$T05thread:01;#07+
$g#67+
$8c190d40000000000000000002000000d071fb3fff3c0880c071fb3f00000000ec02fb3f00000000000000000000000001000000000000004062fb3f0000000000000000000000002062fb3f00000000000000000000000000000000000000000000000032050d80f061fb3f000000000000000023000600000000000100000001000000292408804071fb3fe011403f030000002300060000003fb3ffff3fb3230006002300060000003fb3ffff3fb32800fb3f292408803071fb3f03000000230006002300060000003fb3ffff3fb3a04bfb3f01000000584bfb3f15000000e071fb3f000000002072fb3f0a0000000072fb3f00000000f071fb3f0000000000000000000000000000000000000000000000000600000058000000feffbcc296fec51c200006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000002c050d40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000072f00100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000032050d80f061fb3f000000000000000023000600000000000100000001000000292408804071fb3fe011403f030000002300060000003fb3#d3+$m400d198c,1#c7+$a5#96+$m400d1984,8#9f+$366100a13bfa0c3b#46+$m400d198a,2#c6+$0c3b#28+
$vCont;s:1;c#c1+
$T05thread:01;#07+
$g#67+
// pc=400d0b48
$480b0d40000000000000000002000000d071fb3fff3c0880c071fb3f00000000ec02fb3f00000000000000000000000001000000000000004062fb3f0000000000000000000000002062fb3f00000000000000000000000000000000000000000000000032050d80f061fb3f0000000000000000230006000000000001000000010000008f190d804071fb3fe011403f030000002300060000003fb3ffff3fb3230006002300060000003fb3ffff3fb32800fb3f292408803071fb3f03000000230006002300060000003fb3ffff3fb3a04bfb3f01000000584bfb3f15000000e071fb3f000000002072fb3f0a0000000072fb3f00000000f071fb3f0000000000000000000000000000000000000000000000000600000058000000feffbcc296fec51c200006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000002c050d40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000073f00100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000032050d80f061fb3f0000000000000000230006000000000001000000010000008f190d804071fb3fe011403f030000002300060000003fb3#93+
$m400d0b48,1#c0+$36#69+$m400d198f,1#ca+
$25#67+
$m400d1984,b#c9+
$366100a13bfa0c3ba51bff#3b+
$m400d198f,2#cb+$2504#cb+$Z0,400d198f,2#14+
$OK#9a+$vCont;c#a8+
$T05thread:01;#07+
$g#67+
//pc=400d198f
$8f190d40292408804061fb3f03000000230206002302060000003fb3ffff3fb3ec02fb3f010000000000000001000000230006002300060000003fb3ffff3fb300000000292408800061fb3f03000000230206002302060000003fb3ffff3fb30000000032050d80f061fb3f0000000000000000230006000000000001000000010000008f190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f010000000000000000000000000000009864fb3f6064fb3f941d08807061fb3f9864fb3f0000000000000000584bfb3f15000000e071fb3fb42d08806061fb3f030000002302060020020600f071fb3f0000000000000000e512004009130040780b0d80000000000600000040000000feffbcc296fec51c20020600000000000000000000003fb30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000006b230840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c0040000000000000000000000000000000000000000000000000480040010000084000000000000000008ef30100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000032050d80f061fb3f0000000000000000230006000000000001000000010000008f190d80d061fb3fe004fb3f03000000e004fb3f00003fb3#43+
$m400d198f,1#ca+
$25#67+
$m400d1984,b#c9+
$366100a13bfa0c3ba51bff#3b+$m3ffb61e4,4#2e+$2062fb3f#2b+
$m3ffb6214,4#fb+
$4062fb3f#2d+$m3ffb61e4,4#2e+$2062fb3f#2b+
$z0,400d198f,2#34+$OK#9a+$qfThreadInfo#bb+
$m1#9e+$qsThreadInfo#c8+$l#6c+$z0,400d1984,2#02+
$OK#9a+

(gdb) s

   64      extern "C" esp_err_t nvs_flash_init(void)                                                                                             65      {                      
  >66          return nvs_flash_init_custom(6, 3);  
   67      }

   0x400d99d0 <nvs_flash_init()>                                           entry  a1, 32 
   0x400d99d3 <nvs_flash_init()+3>                                         movi   a10, 6 
   0x400d99d6 <nvs_flash_init()+6>                                         movi   a11, 3
   0x400d99d9 <nvs_flash_init()+9>                                         call8  0x400d9930 <nvs_flash_init_custom(uint32_t, uint32_t)>         0x400d99dc <nvs_flash_init()+12>                                        or     a2, a10, a10                                                   0x400d99df <nvs_flash_init()+15>                                        retw.n                              

$Z0,400d1984,2#e2+
$OK#9a+$vCont;s:1;c#c1+$T05thread:01;#07
+$g#67
//pc =400d99d0+$d0990d40292408804061fb3f03000000230206002302060000003fb3ffff3fb3ec02fb3f010000000000000001000000230006002300060000003fb3ffff3fb300000000292408800061fb3f03000000230206002302060000003fb3ffff3fb30000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f010000000000000000000000000000009864fb3f6064fb3f941d08807061fb3f9864fb3f0000000000000000584bfb3f15000000e071fb3fb42d08806061fb3f030000002302060020020600f071fb3f0000000000000000e512004009130040780b0d80000000000600000040000000feffbcc296fec51c20020600000000000000000000003fb30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000006b230840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c0040000000000000000000000000000000000000000000000000480040010000084000000000000000008ff30100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3#dc+$m400d99d0,1#c8+$36#69+$m400d1992,1#97++$m400d1984,e#cc[6 bytes missing in capture file]++$m3ffb61e4,4#2e[32 bytes missing in capture file]++$m3ffb6214,4#fb[12 bytes missing in capture file]++$m3ffb61e4,4#2e[12 bytes missing in capture file]++$m400d99d3,2#cc[12 bytes missing in capture file]+$a2a0#24+$Z0,400d99d3,2#15+$OK#9a+$vCont;c#a8+$T05thread:01;#07+$g#67+$d3990d40292408804061fb3f03000000230206002302060000003fb3ffff3fb3ec02fb3f010000000000000001000000230006002300060000003fb3ffff3fb300000000292408800061fb3f03000000230206002302060000003fb3ffff3fb30000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f010000000000000000000000000000009864fb3f6064fb3f941d08807061fb3f9864fb3f0000000000000000584bfb3f15000000e071fb3fb42d08806061fb3f030000002302060020020600f071fb3f0000000000000000e512004009130040780b0d80000000000800000040010000feffbcc296fec51c20020600000000000000000000003fb30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000006b230840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000091f30100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f01000000000000000000000000000000#51+$m400d99d3,1#cb++$m400d99d0,3#ca[6 bytes missing in capture file]+$364100#2e+$z0,400d99d3,2#35+$OK#9a+$m400d1992,1#97+$25#67+$m400d1984,e#cc+$366100a13bfa0c3ba51bff250408#6e+$m3ffb61e4,4#2e+$2062fb3f#2b+$m3ffb6214,4#fb+$4062fb3f#2d+$m3ffb61e4,4#2e+$2062fb3f#2b+$qfThreadInfo#bb+$m1#9e+$qsThreadInfo#c8+$l#6c+$z0,400d1984,2#02+$OK#9a+

(gdb) n (gdb) layout next

   64      extern "C" esp_err_t nvs_flash_init(void)                                                                                             
   65      {                                                                                                                                     
   66          return nvs_flash_init_custom(6, 3);  
  >67      }                                                                                                                                                    
   
   ──────────────────────────────────────────────────────────────────────────────────────────────────
    0x400d99d0 <nvs_flash_init()>                                           entry  a1, 32
    0x400d99d3 <nvs_flash_init()+3>                                         movi   a10, 6 
    0x400d99d6 <nvs_flash_init()+6>                                         movi   a11, 3 
    0x400d99d9 <nvs_flash_init()+9>                                         call8  0x400d9930 <nvs_flash_init_custom(uint32_t, uint32_t)
    0x400d99dc <nvs_flash_init()+12>                                        or     a2, a10, a10 
 >  0x400d99df <nvs_flash_init()+15>                                       retw.n


   0x400d9930 <nvs_flash_init_custom(uint32_t, uint32_t)>          entry  a1, 32                          
   0x400d9933 <nvs_flash_init_custom(uint32_t, uint32_t)+3>        l32r   a8, 0x400d03f4 <_stext+988>
   0x400d9936 <nvs_flash_init_custom(uint32_t, uint32_t)+6>        l32i.n a8, a8, 0                           
   0x400d9938 <nvs_flash_init_custom(uint32_t, uint32_t)+8>        beqz.n a8, 0x400d9948 nvs_flash_init_custom(uint32_t, uint32_t)+24>		
   0x400d993a <nvs_flash_init_custom(uint32_t, uint32_t)+10>       l32r   a10, 0x400d03f8 <_stext+992>  
   0x400d993d <nvs_flash_init_custom(uint32_t, uint32_t)+13>       movi.n a11, 45 
   0x400d993f <nvs_flash_init_custom(uint32_t, uint32_t)+15>       l32r   a12, 0x400d040c <_stext+1012>       0x400d9942 <nvs_flash_init_custom(uint32_t, uint32_t)+18>       l32r   a13, 0x400d0410 <_stext+1016>       0x400d9945 <nvs_flash_init_custom(uint32_t, uint32_t)+21>       call8  0x400d0c24 <__assert_func>          0x400d9948 <nvs_flash_init_custom(uint32_t, uint32_t)+24>       movi   a10, 1       
   0x400d994b <nvs_flash_init_custom(uint32_t, uint32_t)+27>       call8  0x40081e20 <xQueueCreateMutex> 
   0x400d994e <nvs_flash_init_custom(uint32_t, uint32_t)+30>       l32r   a8, 0x400d03f4 <_stext+988>  


$Z0,400d1984,2#e2+$OK#9a+$vCont;s:1;c#c1+$T05thread:01;#07+$g#67
// pc=400d99d6+$d6990d40292408804061fb3f03000000230206002302060000003fb3ffff3fb3ec02fb3f010000000000000001000000230006002300060000003fb3ffff3fb300000000292408800061fb3f03000000230206002302060000003fb3ffff3fb30000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f060000000000000000000000000000009864fb3f6064fb3f941d08807061fb3f9864fb3f0000000000000000584bfb3f15000000e071fb3fb42d08806061fb3f030000002302060020020600f071fb3f0000000000000000e512004009130040780b0d80000000000800000040010000feffbcc296fec51c20020600000000000000000000003fb30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000006b230840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000092f30100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f06000000000000000000000000000000#5f+$m400d99d6,1#ce+$b2#94+$m400d99d0,6#cd+$364100a2a006#b8+$vCont;s:1;c#c1+$T05thread:01;#07+
$g#67+
// pc=400d99d9
$d9990d40292408804061fb3f03000000230206002302060000003fb3ffff3fb3ec02fb3f010000000000000001000000230006002300060000003fb3ffff3fb300000000292408800061fb3f03000000230206002302060000003fb3ffff3fb30000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f060000000300000000000000000000009864fb3f6064fb3f941d08807061fb3f9864fb3f0000000000000000584bfb3f15000000e071fb3fb42d08806061fb3f030000002302060020020600f071fb3f0000000000000000e512004009130040780b0d80000000000800000040010000feffbcc296fec51c20020600000000000000000000003fb30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000006b230840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000093f30100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600ba0b0d809061fb3f06000000030000000000000000000000#69+$m400d99d9,1#d1+$65#6b+$m400d99d0,9#d0+$364100a2a006b2a003#40+$vCont;s:1;c#c1+$T05thread:01;#07+
$g#67+
// pc=400d9930 ???
$30990d40292408804061fb3f03000000230206002302060000003fb3ffff3fb3ec02fb3f010000000000000001000000230006002300060000003fb3ffff3fb300000000292408800061fb3f03000000230206002302060000003fb3ffff3fb30000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600dc990d809061fb3f060000000300000000000000000000009864fb3f6064fb3f941d08807061fb3f9864fb3f0000000000000000584bfb3f15000000e071fb3fb42d08806061fb3f030000002302060020020600f071fb3f0000000000000000e512004009130040780b0d80000000000800000040010000feffbcc296fec51c20020600000000000000000000003fb30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000015000000000000000000000000000000000000000000000000000000000000006b230840000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c00400000000000000000000000000000000000000000000000004800400100000840000000000000000094f30100cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600dc990d809061fb3f06000000030000000000000000000000#f8+$m400d9930,1#97+$36#69+$m400d99dc,1#fb+$a0#91+$m400d99d0,c#fa+$364100a2a006b2a00365f5ff#12+
$m400d99dc,2#fc+
$a02a#24+
// Set breakpoint at 400d99dc after rerurn from call
$Z0,400d99dc,2#45+$OK#9a+
$vCont;c#a8+$T05thread:01;#07+
$g#67
// pc=400d99dc+$dc990d40b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000029240880e060fb3f03000000230c0600230c060000003fb3ffff3fb31000000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000800000000010000feffbcc296fec51c200a0600000000000000000000003fb3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001500000000000000000000000000000000000000000000000000000000000000cc990d40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c004000000000000000000000000000000000000000000000000048004001000008400000000000000000e00b0200cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000092190d80d061fb3fe004fb3f03000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f0000000000000000#58+
$m400d99dc,1#fb+$a0#91+$m400d99d0,c#fa+$364100a2a006b2a00365f5ff#12+$m3ffb61c4,4#2c+$f061fb3f#5e+$m3ffb61e4,4#2e+$2062fb3f#2b+$m3ffb61c4,4#2c+$f061fb3f#5e+$z0,400d99dc,2#65+$OK#9a+$qfThreadInfo#bb+$m1#9e+$qsThreadInfo#c8+$l#6c+
// Remove breakpoint
$z0,400d1984,2#02+
$OK#9a+
(gdb) p	$windowbase
$1 = 10
(gdb) p $windowstart
$2 = 1024

(gdb) n

(gdb) p $windowbase
$5 = 8
(gdb) p $windowstart
$6 = 1024
// Why here??
   0x40080000 <_WindowOverflow4>           s32e   a0, a5, -16  
   0x40080003 <_WindowOverflow4+3>         s32e   a1, a5, -12 
   0x40080006 <_WindowOverflow4+6>         s32e   a2, a5, -8   
   0x40080009 <_WindowOverflow4+9>         s32e   a3, a5, -4                                               0x4008000c <_WindowOverflow4+12>        rfwo               

Register-window underflow occurs when a return instruction decrements to a window that has been spilled (indicated by its WindowStart bit being cleared). The processor saves the current PC in EPC[1] and transfers to one of three underflow handlers based on the register window decrement. When the MMU Option is configured, it is necessary for the handlers to access the stack with the same privilege level as the code that raised the exception. Two special instructions, L32E and S32E, are therefore added by the Windowed Register Option for this purpose. In addition, these instructions use negative offsets in the formation of the virtual address, which saves several instructions in the handlers.

$Z0,400d1984,2#e2+$OK#9a+$vCont;s:1;c#c1+$T05thread:01;#07+
$g#67+
//pc=4008000c
$c0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000029240880e060fb3f03000000230c0600230c060000003fb3ffff3fb31000000092190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb3000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001500000000000000000000000000000000000000000000000000000000000000df990d40000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000054090040280a0040f80a0040680c004000000000000000000000000000000000000000000000000048004001000008400000000000000000e20b0200cdcd0000000000000000000000000000f28d050000000000000000000000000000000000000000000000000029240880e060fb3f03000000230c0600230c060000003fb3ffff3fb31000000092190d80d061fb3f0000000003000000e004fb3f00003fb3#88+
$m400800c0,4#8c+$00c90910#c6+
$m400800c0,20#ba+
$00c90910d90920e90970d10930f90940870950970960a70970b7090035000000#37+
$m3ffb61c0,4#28+$32050d80#c6+
// Set register 0x19 (25=ar24??) WHY?
$P19=32050d80#bd+
// Weird very empty packet, qemu don't recognize or support whatever GDB just sent?
$#00+
// Set registers!! gdb taking over??
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80e060fb3f03000000230c0600230c060000003fb3ffff3fb31000000092190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#b5+
$OK#9a+
$m3ffb61c4,4#2c+
$f061fb3f#5e+$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f03000000230c0600230c060000003fb3ffff3fb31000000092190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#b7+$OK#9a+$m3ffb61c8,4#30+
$00000000#80+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000230c0600230c060000003fb3ffff3fb31000000092190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#b4+
$OK#9a+
$m3ffb61e4,4#2e+
$2062fb3f#2b+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000230c0600230c060000003fb3ffff3fb32062fb3f92190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#5e+
$OK#9a+$m3ffb61cc,4#5b+$00000000#80+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f0000000000000000230c060000003fb3ffff3fb32062fb3f92190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#20+
$OK#9a+$m3ffb6200,4#f6+$23000600#8b+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000000000002300060000003fb3ffff3fb32062fb3f92190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#ed+$OK#9a+
$m3ffb6204,4#fa+
$00000000#80+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000000000002300060000000000ffff3fb32062fb3f92190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#7f+
$OK#9a+$m3ffb6208,4#fe+$01000000#81+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000000000002300060000000000010000002062fb3f92190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#3a+
$OK#9a+$m3ffb620c,4#29+
$01000000#81+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000000000002300060000000000010000000100000092190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#90+
$OK#9a+
$Gc0000840b42d08804061fb3f03000000230c0600200c0600000000007474fb3f3c74fb3f292408802061fb3f03000000230c0600230c060000003fb3ffff3fb300000000010000000000000001000000000000001800000000000000000000000000000032050d80f061fb3f00000000000000002300060000000000010000001000000092190d80d061fb3f0000000003000000e004fb3f00003fb3ffff3fb323000600dc990d80b061fb3f00000000001efb3f00000000000000009864fb3f6064fb3fcc990d807061fb3f010000000000000000000000000000007474fb3f3c74fb3f941d08805061fb3f7474fb3f000000000000000001000000000000006061fb3f99160040aa160040fdffffff000000000600000000010000feffbcc296fec51c30080600000000000000000000003fb300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000#90+
$OK#9a+
$p0#a0+$#00+
$m40080080,40#91+
$00c94900d10910d94920e94930f94940804950904960a04970b04900340000000000000000000000000000000000000000000000000000000000000000000000#33+
$m400800c0,40#bc+
$00c90910d90920e90970d10930f90940870950970960a70970b70900350000000000000000000000000000000000000000000000000000000000000000000000#37+

At this point we get an assertion in gdb and can not continue.

 Assertion `regnum >= 0 && regnum < regcache->descr->nr_raw_registers' failed.
 Regnum is 116 and nr_raw_registers is 105

From gdb xtensa-config.c
   XTREG(116,464,32, 4, 4,0x02b1,0x0007,-2, 2,0x1000,epc1,        0,0,0,0,0,0)

From xtensa-tdep.c
static void
xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
				     xtensa_frame_cache_t *cache,
				     CORE_ADDR pc)
{
...
  /* Read PC of interrupted function from EPC1 register.  */
  epc1_regnum = xtensa_find_register_by_name (gdbarch,"epc1");
  if (epc1_regnum < 0)
    error(_("Unable to read Xtensa register EPC1"));

  //cache->ra = xtensa_read_register (epc1_regnum);
  cache->pc = get_frame_func (this_frame);
}
esp-idf/components/freertos/xtensa_vectors.S
  1935    _WindowUnderflow8:                                                                                                                     
  1936                                                                                                                                           1937        l32e    a0, a9, -16     /* restore a0 from call[i+1]'s stack frame */   
  1938        l32e    a1, a9, -12     /* restore a1 from call[i+1]'s stack frame */
  1939        l32e    a2, a9,  -8     /* restore a2 from call[i+1]'s stack frame */
  1940        l32e    a7, a1, -12     /* a7 <- call[i-1]'s sp 
  1941                                   (used to find end of call[i]'s frame) */ 
  1942        l32e    a3, a9,  -4     /* restore a3 from call[i+1]'s stack frame */  
  1943        l32e    a4, a7, -32     /* restore a4 from call[i]'s stack frame */       
              l32e    a5, a7, -28     /* restore a5 from call[i]'s stack frame */
              l32e    a6, a7, -24     /* restore a6 from call[i]'s stack frame */
              l32e    a7, a7, -20     /* restore a7 from call[i]'s stack frame */
              rfwu

   0x400800c0 <_WindowUnderflow8>          l32e   a0, a9, -16 
   0x400800c3 <_WindowUnderflow8+3>        l32e   a1, a9, -12  
   0x400800c6 <_WindowUnderflow8+6>        l32e   a2, a9, -8 
   0x400800c9 <_WindowUnderflow8+9>        l32e   a7, a1, -12  
   0x400800cc <_WindowUnderflow8+12>       l32e   a3, a9, -4   
   0x400800cf <_WindowUnderflow8+15>       l32e   a4, a7, -32    
   0x400800d2 <_WindowUnderflow8+18>       l32e   a5, a7, -28     
   0x400800d5 <_WindowUnderflow8+21>       l32e   a6, a7, -24      
   0x400800d8 <_WindowUnderflow8+24>       l32e   a7, a7, -20   
   0x400800db <_WindowUnderflow8+27>       rfwu   

##gdb debug xtensa I also found this to aid furher xtensa debugging

(gdb) set debug xtensa 10
(gdb) b nvs_flash_init
(trace) xtensa_breakpoint_from_pc (pc = 0x400d99d0)
Breakpoint 1 at 0x400d99d0: file /home/olas/esp/esp-idf/components/nvs_flash/src/nvs_api.cpp, line 65.
(gdb) c
Continuing.
(trace) xtensa_breakpoint_from_pc (pc = 0x400d99d0)
(trace) xtensa_unwind_pc (next_frame = 0x11fe9e0)
(info ) [xtensa_unwind_pc] pc = 0x400d99d0
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_pseudo_register_read (... regnum = 165 (a8) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)

Breakpoint 1, nvs_flash_init () at /home/olas/esp/esp-idf/components/nvs_flash/src/nvs_api.cpp:65
65	{
(gdb) n
(trace) xtensa_unwind_pc (next_frame = 0x11fe9e0)
(info ) [xtensa_unwind_pc] pc = 0x400d99d3
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_pseudo_register_read (... regnum = 157 (a0) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)
66	    return nvs_flash_init_custom(6, 3);
(gdb) n
(trace) xtensa_breakpoint_from_pc (pc = 0x400d99d0)
(trace) xtensa_unwind_pc (next_frame = 0x11fe9e0)
(info ) [xtensa_unwind_pc] pc = 0x400d99d6
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_pseudo_register_read (... regnum = 157 (a0) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)
(trace) xtensa_unwind_pc (next_frame = 0x11fe9e0)
(info ) [xtensa_unwind_pc] pc = 0x400d99d9
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_pseudo_register_read (... regnum = 157 (a0) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)
(trace) xtensa_unwind_pc (next_frame = 0x11fe9e0)
(info ) [xtensa_unwind_pc] pc = 0x400d9930
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_pseudo_register_read (... regnum = 165 (a8) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)
(trace) xtensa_unwind_pc (next_frame = 0x11feab0)
(info ) [xtensa_unwind_pc] pc = 0x400d99dc
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_breakpoint_from_pc (pc = 0x400d99dc)
(trace) xtensa_breakpoint_from_pc (pc = 0x400d99dc)
(trace) xtensa_unwind_pc (next_frame = 0x11fe9e0)
(info ) [xtensa_unwind_pc] pc = 0x400d99dc
(trace) xtensa_alloc_frame_cache ()
(trace) xtensa_pseudo_register_read (... regnum = 157 (a0) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)
(trace) xtensa_pseudo_register_read (... regnum = 158 (a1) ...)

(trace) xtensa_break_WindowUnderflow8 = 0x400d99dc)                                                            1937		800c0d99d0
(trace) xtensa_unwind_pc (next_frame = 0x14279e0)
(info ) [xtensa_unwind_pc] pc = 0x400800c0
(trace) xtensa_alloc_frame_cache ()
(trace) call0_classify_opcode (..., opc = 67)um = 157 (a0) ...)
(trace) call0_classify_opcode (..., opc = 67)
(trace) call0_classify_opcode (..., opc = 67)
(trace) call0_classify_opcode (..., opc = 67)
(gdb) n call0_classify_opcode (..., opc = 67)
(trace) call0_classify_opcode (..., opc = 67)
(trace) call0_classify_opcode (..., opc = 67)
(info ) call0_classify_opcode (..., opc = 67)
(trace) call0_classify_opcode (..., opc = 67)
(trace) call0_classify_opcode (..., opc = 66)um = 157 (a0) ...)
(trace) xtensa_unwind_pc (next_frame = 0x1427ab0)
(info ) [xtensa_unwind_pc] pc = 0x400800c0
(trace) xtensa_alloc_frame_cache ()
_WindowUnderflow8 () at /home/olas/esp/esp-idf/components/freertos/./xtensa_vectors.S:1937

##Patched gdb To stop the assert the following patches has been applied to gdb


remote.c:
process_g_packet (struct regcache *regcache)
...

  //  if (buf_len > 2 * rsa->sizeof_g_packet)
  //  error (_("Remote 'g' packet reply is too long: %s"), rs->buf);

    if(buf_len > 2 * rsa->sizeof_g_packet) {
        rsa->sizeof_g_packet = buf_len;
        for(i = 0; i < gdbarch_num_regs(gdbarch); i++){
            if(rsa->regs->pnum == -1)
               continue;

            if(rsa->regs->offset >= rsa->sizeof_g_packet)
               rsa->regs->in_g_packet = 0;
            else
               rsa->regs->in_g_packet = 1;
        } 
    }  

xtensa-tdep.c
/* Handle Window Overflow / Underflow exception frames.  */

static void
xtensa_window_interrupt_frame_cache (struct frame_info *this_frame,
				     xtensa_frame_cache_t *cache,
				     CORE_ADDR pc)
{
...
  /* Read PC of interrupted function from EPC1 register.  */
  epc1_regnum = xtensa_find_register_by_name (gdbarch,"epc1");
  if (epc1_regnum < 0)
    error(_("Unable to read Xtensa register EPC1"));
  printf("READING EPC1!!\n");
  //cache->ra = xtensa_read_register (epc1_regnum);
  cache->pc = get_frame_func (this_frame);
  // Return adress is ot same as PC but allows us to continue debugging
  cache->ra = cache->pc;
}