A querry regarding backtrace in ESP IDF 5.0.7

kesha.modhia
Posts: 54
Joined: Fri May 13, 2022 12:36 pm

A querry regarding backtrace in ESP IDF 5.0.7

Postby kesha.modhia » Fri Mar 28, 2025 7:12 am

Subject : A querry regarding backtrace in ESP IDF 5.0.7

Hello,

I am using ESP32-D0WDQ6 module and ESP-IDF version 5.0.7
I need to know that how to print the Backtrace information with Filename and line number as shown in,
https://docs.espressif.com/projects/esp ... debug.html

As this shows
2 allocations trace (100 entry buffer)
32 bytes (@ 0x3ffaf214) allocated CPU 0 ccount 0x2e9b7384 caller 0x400d276d:0x400d27c1
0x400d276d: leak_some_memory at /path/to/idf/examples/get-started/blink/main/./blink.c:27

0x400d27c1: blink_task at /path/to/idf/examples/get-started/blink/main/./blink.c:52

8 bytes (@ 0x3ffaf804) allocated CPU 0 ccount 0x2e9b79c0 caller 0x400d2776:0x400d27c1
0x400d2776: leak_some_memory at /path/to/idf/examples/get-started/blink/main/./blink.c:29

0x400d27c1: blink_task at /path/to/idf/examples/get-started/blink/main/./blink.c:52

40 bytes 'leaked' in trace (2 allocations)
total allocations 2 total frees 0

and In my case I am only getting this

2 allocations trace (100 entry buffer)
3072 bytes (@ 0x3ffcded4) allocated CPU 0 ccount 0x168b55bc caller 0x400937c0:0x400ddb1b
344 bytes (@ 0x3ffcead8) allocated CPU 0 ccount 0x168b5ebc caller 0x400937ce:0x400ddb1b
3416 bytes 'leaked' in trace (2 allocations)
total allocations 2 total frees 0
2 allocations trace (100 entry buffer)
16384 bytes (@ 0x3ffd3a88) allocated CPU 0 ccount 0x1791d208 caller 0x400937c0:0x400ddb6f
344 bytes (@ 0x3ffd7a8c) allocated CPU 0 ccount 0x1791dac4 caller

Not the Filenames and line number

By surfing i got to know that I need to do it manually
that i dont want to do
just want it to be printed with ESP suggested SDK APIs Supported in v5.0.7

Let me know in detail

MicroController
Posts: 2694
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: A querry regarding backtrace in ESP IDF 5.0.7

Postby MicroController » Fri Mar 28, 2025 8:00 am

Decoding the code addresses to file+linenumber is not done by/on the ESP itself; the chip doesn't have this information.
The decoding needs to be done on the PC side, where the binary's .elf file is available.
You can use addr2line to 'manually' decode addresses, or you can use idf.py monitor to monitor the log output from the ESP and it will decode the addresses for you in the process, giving you the output you found in the documentation. See https://docs.espressif.com/projects/esp ... edump.html .

kesha.modhia
Posts: 54
Joined: Fri May 13, 2022 12:36 pm

Re: A querry regarding backtrace in ESP IDF 5.0.7

Postby kesha.modhia » Fri Mar 28, 2025 10:03 am

Thaks for the quick reply,

How this example is working then, I can not see addrline manually used in this given referance code

https://docs.espressif.com/projects/esp ... debug.html
Example code
#include "esp_heap_trace.h"

#define NUM_RECORDS 100
static heap_trace_record_t trace_record[NUM_RECORDS]; // This buffer must be in internal RAM

...

void app_main()
{
...
ESP_ERROR_CHECK( heap_trace_init_standalone(trace_record, NUM_RECORDS) );
...
}

void some_function()
{
ESP_ERROR_CHECK( heap_trace_start(HEAP_TRACE_LEAKS) );

do_something_you_suspect_is_leaking();

ESP_ERROR_CHECK( heap_trace_stop() );
heap_trace_dump();
...
}
Output :
2 allocations trace (100 entry buffer)
32 bytes (@ 0x3ffaf214) allocated CPU 0 ccount 0x2e9b7384 caller 0x400d276d:0x400d27c1
0x400d276d: leak_some_memory at /path/to/idf/examples/get-started/blink/main/./blink.c:27

0x400d27c1: blink_task at /path/to/idf/examples/get-started/blink/main/./blink.c:52

8 bytes (@ 0x3ffaf804) allocated CPU 0 ccount 0x2e9b79c0 caller 0x400d2776:0x400d27c1
0x400d2776: leak_some_memory at /path/to/idf/examples/get-started/blink/main/./blink.c:29

0x400d27c1: blink_task at /path/to/idf/examples/get-started/blink/main/./blink.c:52


40 bytes 'leaked' in trace (2 allocations)
total allocations 2 total frees 0

MicroController
Posts: 2694
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: A querry regarding backtrace in ESP IDF 5.0.7

Postby MicroController » Fri Mar 28, 2025 1:38 pm

The decoding needs to be done on the PC side
How this example is working then
idf.py monitor, see above

Who is online

Users browsing this forum: Baidu [Spider], ChatGPT-User, meta-externalagent and 3 guests