When you want to find the division by zero

That was the crash:

esp32_rng_initialize: Initializing RNG                                                 
esp32_bt_controller_init: BT controller compile version [a4c513b]                         
btdm_controller_mem_init: .data initialise [0x3ffae6e0] <== [0x4000d890]                  
btdm_controller_mem_init: .bss initialise [0x3ffb0000] - [0x3ffb09a8]                     
btdm_controller_mem_init: .bss initialise [0x3ffb09a8] - [0x3ffb1ddc]                     
btdm_controller_mem_init: .bss initialise [0x3ffb1ddc] - [0x3ffb2730]                     
btdm_controller_mem_init: .bss initialise [0x3ffb2730] - [0x3ffb6388]                     
btdm_controller_mem_init: .bss initialise [0x3ffb8000] - [0x3ffb9a20]                     
btdm_controller_mem_init: .bss initialise [0x3ffbdb28] - [0x3ffbdb5c]                     
esp32_bt_controller_init: BT controller compile version [a4c513b]                         
esp_ble_set_isr: n=5 f=0x4008b66c arg=0 irq=9                                             
esp_ble_set_isr: n=8 f=0x4008b6ac arg=0 irq=12                                            
esp_ble_set_isr: n=7 f=0x4008b654 arg=0 irq=11                                            
xtensa_user_panic: User Exception: EXCCAUSE=0006 task: btController                       
xtensa_registerdump:    PC: 401395f5    PS: 00060830                                      
xtensa_registerdump:    A0: 80082724    A1: 3ffcf4d0    A2: 00000064    A3: 00000001      
xtensa_registerdump:    A4: 00000000    A5: 00000000    A6: 00000008    A7: 3ffcf500      
xtensa_registerdump:    A8: 00000002    A9: 00000000   A10: 00000000   A11: 00000003      
xtensa_registerdump:   A12: 00000064   A13: 00000000   A14: 401353dc   A15: 3ffcf470      
xtensa_registerdump:   SAR: 00000020 CAUSE: 00000006 VADDR: 00000000                      
xtensa_registerdump:  LBEG: 4000c2e0  LEND: 4000c2f6  LCNT: ffffffff                      
xtensa_registerdump:  TMP0: 400808d8  TMP1: 3ffcf2b0                                      
xtensa_btdump: Backtrace0: 400d75ca:3ffcf1f0                                              
xtensa_btdump: Backtrace1: 400d6a72:3ffcf220                                              
xtensa_btdump: Backtrace2: 400d6b91:3ffcf240                                              
xtensa_btdump: Backtrace3: 400d69f1:3ffcf280                                              
xtensa_btdump: Backtrace4: 400808f5:3ffcf2b0                                              
xtensa_btdump: Backtrace5: 40020:3ffcf310                                                 
xtensa_btdump: BACKTRACE Done                                                             
xtensa_dumpstate: sp:         3ffcf1d0                                                    
xtensa_dumpstate: stack base: 3ffca650                                                    
xtensa_dumpstate: stack size: 00000830                                                    
xtensa_dumpstate: ERROR: Stack pointer is not within allocated stack                      
xtensa_stackdump: 3ffca640: 3ffca648 00000000 74696e69 00000000 5ee9e106 37b32ee5 28740f1f
xtensa_stackdump: 3ffca660: 00249f00 0229e9f6 00001248 39e31955 024e9b23 3ffca760 00000008
xtensa_stackdump: 3ffca680: 97d9ef5b 6dd407fc b93f0ef9 a36e5f42 57d5eb86 7ee10181 3418aa79
xtensa_stackdump: 3ffca6a0: 00249f00 024e88f6 0000122d 5ae6c916 00000000 3ffca7a0 0000000d
xtensa_stackdump: 3ffca6c0: e5dccdf8 a46e4975 b4e1445e 2de35921 3597ef13 ee69dee2 87e50029
xtensa_stackdump: 3ffca6e0: 400d69f4 00000000 00000000 3c763775 00000000 3ffca7a0 4ac6d383
xtensa_stackdump: 3ffca700: 2bd71b13 b5b239b7 a9848d40 851cf774 00040023 3ffca760 0001804f
xtensa_stackdump: 3ffca720: 3ffca2a0 00000007 3ffc39f0 0db63a00 00000000 3ffca7a0 d5530f84
xtensa_stackdump: 3ffca740: deb0b36e 2aa265a8 86547725 240f53e1 00040023 3ffca7a0 0001804f
xtensa_stackdump: 3ffca760: 00000040 00000007 3ffc39f0 3ffca900 00000000 3ffca7a0 00000070
xtensa_stackdump: 3ffca780: 00000008 3ffca980 800d7982 3ffca950 00060520 3ffcab84 3ffcabcc
xtensa_stackdump: 3ffca7a0: 400d825e 00060530 800e6d95 3ffca9c0 00000000 00000109 3f407888
xtensa_stackdump: 3ffca7c0: 3ffbdb5c 3ffca9c0 800d825c 3ffca980 00000000 0000007f 00000070
xtensa_stackdump: 3ffca7e0: 00000008 3ffca980 00000006 27c52b29 3ffca2a0 4000c2e0 4000c2ff
xtensa_stackdump: 3ffca800: 40080740 3ffca7a0 93853250 100a3ffa 0df76fbe e56a121e 741236e8

The EXCCAUSE=0006 means division by zero

So, let to disassemble to return address (A0)

(gdb) disassemble /m 0x40082724
Dump of assembler code for function btdm_us_2_lpcycles:
warning: Source file is more recent than executable.
1462 {
0x400826d0 <+0>: entry a1, 64
0x400826d3 <+3>: mov.n a7, a1
0x400826d5 <+5>: s32i.n a2, a7, 16

1463 uint64_t cycles;
1464 cycles = ((uint64_t)(us) << g_btdm_lpcycle_us_frac) / g_btdm_lpcycle_us; 0x400826d7 <+7>: l32i.n a2, a7, 16
0x400826d9 <+9>: mov.n a8, a2
0x400826db <+11>: movi.n a9, 0
0x400826dd <+13>: l32r a2, 0x400806f4
0x400826e0 <+16>: l8ui a2, a2, 0
0x400826e3 <+19>: movi.n a3, 32
0x400826e5 <+21>: and a3, a2, a3
0x400826e8 <+24>: movi.n a6, 0
0x400826ea <+26>: srli a13, a8, 1
0x400826ed <+29>: movi.n a12, -1
0x400826ef <+31>: xor a12, a2, a12
0x400826f2 <+34>: ssr a12
0x400826f5 <+37>: srl a12, a13
---Type to continue, or q to quit---q

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s