I'm using a code where I deliberately put a bug. This is the following:
- #include <stdio.h>
- #include <string.h>
- typedef struct Params_struct
- {
- char aString[20];
- void (*functionPointer)(char * data);
- } Params;
- void CalledWithFunctionPointer(char * data)
- {
- printf("%s\n", data);
- }
- int foo(Params *params)
- {
- int x = 1;
- for (int i = 0; i < 10; i++)
- {
- x += i * x;
- }
- params->functionPointer(params->aString);
- memset(params->aString,5,1024); // <---THE BUG IS HERE!
- x++;
- return x;
- }
- void app_main(void)
- {
- Params params;
- sprintf(params.aString, "hello world!");
- params.functionPointer = CalledWithFunctionPointer;
- int result = foo(¶ms);
- printf("%d\n", result);
- }
Basically I run
Code: Select all
openocd -c "set ESP_RTOS none" -f ./debug/esp32-wrover-kit-3.3v.cfg
Code: Select all
openocd -f ./debug/esp32-wrover-kit-3.3v.cfg
I encounter some problem when I click on START DEBUGGING. It sometimes works and sometimes no.
Basically, the problem seems to corrupt the memory of the ESP32. The only way I found to solve this is to re-flash the ESP32 and hope it won't crash again in the next debug session. It's very tiring...
In the code above, there is a breakpoint in line 23. It stops here but when I continue by one step, the debugger quits.
Ok, it is the exception generated (I think). But the monitor behaves in a strange way, and if I click the reset button of the ESP32 nothing changes, it continues to show an incoherent output. I obtain the following ouput on terminal:
Code: Select all
I (0) cpu_start: App cpu up.
I (215) cpu_start: Pro cpu start user code
I (215) cpu_start: cpu freq: 160000000
I (215) cpu_start: Application information:
I (220) cpu_start: Project name: debug_with_esp_prog
I (226) cpu_start: App version: 1
I (230) cpu_start: Compile time: Mar 20 2022 18:02:31
I (236) cpu_start: ELF file SHA256: 8df520702e34edc9...
I (242) cpu_start: ESP-IDF: -128-NOTFOUND
I (248) heap_init: Initializing. RAM available for dynamic allocation:
I (255) heap_init: At 3FFAE6E0 len 00001920 (6 KiB): DRAM
I (261) heap_init: At 3FFB2C28 len 0002D3D8 (180 KiB): DRAM
I (267) heap_init: At 3FFE0440 len 00003AE0 (14 KiB): D/IRAM
I (273) heap_init: At 3FFE4350 len 0001BCB0 (111 KiB): D/IRAM
I (280) heap_init: At 4008B160 len 00014EA0 (83 KiB): IRAM
I (287) spi_flash: detected chip: generic
I (291) spi_flash: flash io: dio
I (296) cpu_start: Starting scheduler on PRO CPU.
I (0) cpu_start: Starting scheduler on APP CPU.
hello world!
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6616
load:0xd0012000,len:4197935
1162 mmu set 00010000, pos 00010000
1162 mmu set 00020000, pos 00020000
1162 mmu set 00030000, pos 00030000
1162 mmu set 00040000, pos 00040000
1162 mmu set 00050000, pos 00050000
1162 mmu set 00060000, pos 00060000
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6616
load:0xd0012000,len:4197935
ets Jun 8 2016 00:22:57
rst:0x10 (RTCWDT_RTC_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6616
load:0xd0012000,len:4197935
1162 mmu set 00010000, pos 00010000
1162 mmu set 00020000, pos 00020000
Code: Select all
I (28) boot: ESP-IDF -128-NOTFOUND 2nd stage bootloader
I (28) boot: compile time 18:03:17
I (29) boot: chip revision: 1
I (32) boot_comm: chip revision: 1, min. bootloader chip revision: 0
I (39) boot.esp32: SPI Speed : 40MHz
I (44) boot.esp32: SPI Mode : DIO
I (48) boot.esp32: SPI Flash Size : 4MB
I (53) boot: Enabling RNG early entropy source...
I (58) boot: Partition Table:
I (62) boot: ## Label Usage Type ST Offset Length
I (69) boot: 0 nvs WiFi data 01 02 00009000 00006000
I (76) boot: 1 phy_init RF data 01 01 0000f000 00001000
I (84) boot: 2 factory factory app 00 00 00010000 00100000
I (91) boot: End of partition table
I (96) boot_comm: chip revision: 1, min. application chip revision: 0
I (103) esp_image: segment 0: paddr=00010020 vaddr=3f400020 size=0780ch ( 30732) map
I (122) esp_image: segment 1: paddr=00017834 vaddr=3ffb0000 size=02340h ( 9024) load
I (126) esp_image: segment 2: paddr=00019b7c vaddr=40080000 size=0649ch ( 25756) load
I (141) esp_image: segment 3: paddr=00020020 vaddr=400d0020 size=149c8h ( 84424) map
I (172) esp_image: segment 4: paddr=000349f0 vaddr=4008649c size=04cc4h ( 19652) load
I (180) esp_image: segment 5: paddr=000396bc vaddr=50000000 size=00010h ( 16) load
I (186) boot: Loaded app from partition at offset 0x10000
I (186) boot: Disabling RNG early entropy source...
I (200) cpu_start: Pro cpu up.
Guru Meditation Error: Core 0 panic'ed (IllegalInstruction). Exception was unhandled.
Memory dump at 0x400d42b8: ffffffff ffffffff ffffffff
0x400d42b8: esp_intr_alloc at C:/esp/esp-idf/components/esp_hw_support/intr_alloc.c:605
Setting breakpoint at 0x400d42bc and returning...
0x400d42bc: esp_chip_info at C:/esp/esp-idf/components/esp_hw_support/port/esp32/chip_info.c:14
ets Jun 8 2016 00:22:57
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:6616
load:0x40078000,len:14780
ho 0 tail 12 room 4
load:0x40080400,len:3792
0x40080400: _init at ??:?
Is there an explanation about what I'm doing wrong?