Skip to content

Commit 5325cac

Browse files
committed
Merge branch 'coredump_save_all_regions_v5.3' into 'release/v5.3'
Save .bss, .data and .heap sections in to the coredump (v5.3) See merge request espressif/esp-idf!30438
2 parents 3e826dd + 0f96e51 commit 5325cac

File tree

16 files changed

+399
-77
lines changed

16 files changed

+399
-77
lines changed

components/espcoredump/Kconfig

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,18 @@ menu "Core dump"
4747
depends on ESP_COREDUMP_DATA_FORMAT_ELF
4848
endchoice
4949

50+
config ESP_COREDUMP_CAPTURE_DRAM
51+
bool "Include whole .bss and .data sections and heap data into core dump file"
52+
default n
53+
#TODO: Heap walker api is not ready for the esp32c5 (IDF-9641)
54+
depends on ESP_COREDUMP_DATA_FORMAT_ELF && !IDF_TARGET_ESP32C5
55+
help
56+
Storing these sections can help with easier debugging and troubleshooting.
57+
However, additional storage space will be required in the core dump partition.
58+
At least 128KB should be reserved, but the actual amount required may vary based
59+
on the application's DRAM usage.
60+
Note that sections located in external RAM will not be stored.
61+
5062
config ESP_COREDUMP_CHECK_BOOT
5163
bool "Check core dump data integrity on boot"
5264
default y
@@ -112,7 +124,8 @@ menu "Core dump"
112124
help
113125
Size of the memory to be reserved for core dump stack. If 0 core dump process will run on
114126
the stack of crashed task/ISR, otherwise special stack will be allocated.
115-
To ensure that core dump itself will not overflow task/ISR stack set this to the value above 800.
127+
To ensure that core dump itself will not overflow task/ISR stack set this to the value around 1300-1800
128+
depending on the chosen checksum calculation method. SHA256 method needs more stack space than CRC32.
116129
NOTE: It eats DRAM.
117130

118131
config ESP_COREDUMP_SUMMARY_STACKDUMP_SIZE

components/espcoredump/include_core_dump/esp_core_dump_common.h

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,25 @@ extern "C" {
2020
* One can use these definitions to retrieve the start address and/or the size
2121
* of a specific region using the functions below.
2222
*/
23+
2324
typedef enum {
24-
COREDUMP_MEMORY_DRAM,
2525
COREDUMP_MEMORY_IRAM,
26+
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
27+
COREDUMP_MEMORY_DRAM_BSS,
28+
COREDUMP_MEMORY_DRAM_DATA,
29+
#if CONFIG_IDF_TARGET_ESP32P4
30+
COREDUMP_MEMORY_DRAM_BSS_HIGH,
31+
COREDUMP_MEMORY_DRAM_DATA_HIGH,
32+
#endif
33+
#else
34+
COREDUMP_MEMORY_DRAM,
35+
#endif
2636
#if SOC_RTC_MEM_SUPPORTED
2737
COREDUMP_MEMORY_RTC,
2838
COREDUMP_MEMORY_RTC_FAST,
2939
#endif
3040
COREDUMP_MEMORY_MAX,
31-
COREDUMP_MEMORY_START = COREDUMP_MEMORY_DRAM
41+
COREDUMP_MEMORY_START = COREDUMP_MEMORY_IRAM
3242
} coredump_region_t;
3343

3444
/**
@@ -126,6 +136,12 @@ esp_err_t esp_core_dump_write_data(core_dump_write_data_t *wr_data, void *data,
126136
*/
127137
esp_err_t esp_core_dump_write_end(core_dump_write_data_t *wr_data);
128138

139+
/**
140+
* @brief Retrieve the stack information which will be used from the coredump module itself.
141+
* It will show the whole stack boundaries in case the stack is shared with the crashed task.
142+
*/
143+
void esp_core_dump_get_own_stack_info(uint32_t *addr, uint32_t *size);
144+
129145
/**
130146
* @brief Stores the core dump in either binary or ELF format.
131147
*/
@@ -157,7 +173,7 @@ static inline core_dump_task_handle_t esp_core_dump_get_current_task_handle(void
157173
* @brief Get the length, in bytes, of a given memory location. Padding is
158174
* taken into account in this calculation.
159175
*
160-
* @param start Start address of the momery location.
176+
* @param start Start address of the memory location.
161177
* @param end End address of the memory location.
162178
*
163179
* @return Size of the memory location, multiple of sizeof(uint32_t).

components/espcoredump/src/core_dump_common.c

Lines changed: 64 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,25 @@ const static char TAG[] __attribute__((unused)) = "esp_core_dump_common";
2525
/**
2626
* @brief Memory regions to dump, defined at compile time.
2727
*/
28+
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
29+
#if !CONFIG_IDF_TARGET_ESP32P4
30+
extern int _bss_start;
31+
extern int _bss_end;
32+
extern int _data_start;
33+
extern int _data_end;
34+
#else
35+
extern int _bss_start_low;
36+
extern int _bss_end_low;
37+
extern int _data_start_low;
38+
extern int _data_end_low;
39+
extern int _bss_start_high;
40+
extern int _bss_end_high;
41+
extern int _data_start_high;
42+
extern int _data_end_high;
43+
#endif
44+
#endif
45+
46+
/* Regions for the user defined variable locations */
2847
extern int _coredump_dram_start;
2948
extern int _coredump_dram_end;
3049
extern int _coredump_iram_start;
@@ -160,6 +179,7 @@ FORCE_INLINE_ATTR void esp_core_dump_setup_stack(void)
160179
FORCE_INLINE_ATTR void esp_core_dump_report_stack_usage(void)
161180
{
162181
}
182+
163183
#endif // CONFIG_ESP_COREDUMP_STACK_SIZE > 0
164184

165185
static void* s_exc_frame = NULL;
@@ -254,56 +274,64 @@ uint32_t esp_core_dump_get_user_ram_segments(void)
254274
return total_sz;
255275
}
256276

257-
uint32_t esp_core_dump_get_user_ram_size(void)
258-
{
259-
uint32_t total_sz = 0;
260-
261-
total_sz += COREDUMP_GET_MEMORY_SIZE(&_coredump_dram_end, &_coredump_dram_start);
277+
static const struct {
278+
int *start;
279+
int *end;
280+
} s_memory_sections[COREDUMP_MEMORY_MAX] = {
281+
[COREDUMP_MEMORY_IRAM] = { &_coredump_iram_start, &_coredump_iram_end },
282+
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
283+
#if !CONFIG_IDF_TARGET_ESP32P4
284+
[COREDUMP_MEMORY_DRAM_BSS] = { &_bss_start, &_bss_end },
285+
[COREDUMP_MEMORY_DRAM_DATA] = { &_data_start, &_data_end },
286+
#else
287+
[COREDUMP_MEMORY_DRAM_BSS] = { &_bss_start_low, &_bss_end_low },
288+
[COREDUMP_MEMORY_DRAM_DATA] = { &_data_start_low, &_data_end_low },
289+
[COREDUMP_MEMORY_DRAM_BSS_HIGH] = { &_bss_start_high, &_bss_end_high },
290+
[COREDUMP_MEMORY_DRAM_DATA_HIGH] = { &_data_start_high, &_data_end_high },
291+
#endif
292+
#else
293+
[COREDUMP_MEMORY_DRAM] = { &_coredump_dram_start, &_coredump_dram_end },
294+
#endif
262295
#if SOC_RTC_MEM_SUPPORTED
263-
total_sz += COREDUMP_GET_MEMORY_SIZE(&_coredump_rtc_end, &_coredump_rtc_start);
264-
total_sz += COREDUMP_GET_MEMORY_SIZE(&_coredump_rtc_fast_end, &_coredump_rtc_fast_start);
296+
[COREDUMP_MEMORY_RTC] = { &_coredump_rtc_start, &_coredump_rtc_end },
297+
[COREDUMP_MEMORY_RTC_FAST] = { &_coredump_rtc_fast_start, &_coredump_rtc_fast_end },
265298
#endif
266-
total_sz += COREDUMP_GET_MEMORY_SIZE(&_coredump_iram_end, &_coredump_iram_start);
267-
268-
return total_sz;
269-
}
299+
};
270300

271301
int esp_core_dump_get_user_ram_info(coredump_region_t region, uint32_t *start)
272302
{
273303
int total_sz = -1;
274304

275305
ESP_COREDUMP_DEBUG_ASSERT(start != NULL);
276306

277-
switch (region) {
278-
case COREDUMP_MEMORY_DRAM:
279-
*start = (uint32_t)&_coredump_dram_start;
280-
total_sz = (uint8_t *)&_coredump_dram_end - (uint8_t *)&_coredump_dram_start;
281-
break;
282-
283-
case COREDUMP_MEMORY_IRAM:
284-
*start = (uint32_t)&_coredump_iram_start;
285-
total_sz = (uint8_t *)&_coredump_iram_end - (uint8_t *)&_coredump_iram_start;
286-
break;
287-
288-
#if SOC_RTC_MEM_SUPPORTED
289-
case COREDUMP_MEMORY_RTC:
290-
*start = (uint32_t)&_coredump_rtc_start;
291-
total_sz = (uint8_t *)&_coredump_rtc_end - (uint8_t *)&_coredump_rtc_start;
292-
break;
293-
294-
case COREDUMP_MEMORY_RTC_FAST:
295-
*start = (uint32_t)&_coredump_rtc_fast_start;
296-
total_sz = (uint8_t *)&_coredump_rtc_fast_end - (uint8_t *)&_coredump_rtc_fast_start;
297-
break;
298-
#endif
299-
300-
default:
301-
break;
307+
if (region >= COREDUMP_MEMORY_START && region < COREDUMP_MEMORY_MAX) {
308+
total_sz = (uint8_t *)s_memory_sections[region].end - (uint8_t *)s_memory_sections[region].start;
309+
*start = (uint32_t)s_memory_sections[region].start;
302310
}
303311

304312
return total_sz;
305313
}
306314

315+
#if CONFIG_ESP_COREDUMP_CAPTURE_DRAM
316+
void esp_core_dump_get_own_stack_info(uint32_t *addr, uint32_t *size)
317+
{
318+
#if CONFIG_ESP_COREDUMP_STACK_SIZE > 0
319+
/* Custom stack reserved for the coredump */
320+
*addr = (uint32_t)s_coredump_stack;
321+
*size = sizeof(s_coredump_stack);
322+
#else
323+
/* Shared stack with the crashed task */
324+
core_dump_task_handle_t handle = esp_core_dump_get_current_task_handle();
325+
TaskSnapshot_t rtos_snapshot = { 0 };
326+
vTaskGetSnapshot(handle, &rtos_snapshot);
327+
StaticTask_t *current = (StaticTask_t *)handle;
328+
*addr = (uint32_t)current->pxDummy6; //pxStack
329+
*size = (uint32_t)rtos_snapshot.pxTopOfStack - (uint32_t)current->pxDummy6; /* free */
330+
#endif
331+
}
332+
333+
#endif /* CONFIG_ESP_COREDUMP_CAPTURE_DRAM */
334+
307335
inline bool esp_core_dump_tcb_addr_is_sane(uint32_t addr)
308336
{
309337
return esp_core_dump_mem_seg_is_sane(addr, esp_core_dump_get_tcb_len());

0 commit comments

Comments
 (0)