Description
JTAG 适配器类型。
esp32c3 build-in USB JTAG.
用于编译和加载正在调试的应用程序的 ESP-IDF 版本号。
IDF 4.3
用于调试的操作系统的详细信息。
windows8.1 msys2 mingw64 & mingw32 或者 ubuntu
操作系统是在本地计算机运行还是在虚拟机上运行?
本地计算机
创建一个能够演示问题的简单示例工程,描述复现该问题的步骤。且这个调试示例不能受到 Wi-Fi 协议栈引入的非确定性行为的影响,因而再次遇到同样问题时,更容易复现。
就是blink示例工程。
初步现象总结:
1.只要esp32c3刚烧写程序后处于Staying in flasher stub,GDB就能成功连接上,并能可以bt和dump 内存成功,si单步也能成功。可是这个时候调试不了应用程序,因为在flasher stub状态,没有跑应用。
2。在1的情况下,esp32复位后,应用程序跑起来了,但是GDB就连不上openocd,报 Failed to probe flash, size 0 KB。auto_probe failed。猜测是复位造成某个地方状态不对,造成openocd调用 esp_flash_get_size()执行失败。
复制步骤与相关日志:
esp32复位后
然后gdb连接不成功,输出以下错误:
$ ./riscv32-esp-elf-gdb.exe /e/blink.elf
GNU gdb (crosstool-NG 1.24.0.123_64eb9ff) 8.3.1.20191211-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from E:/blink.elf...
(gdb) target remote :3333
Remote debugging using :3333
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Remote replied unexpectedly to 'vMustReplyEmpty': PacketSize=4000;qXfer:memory-map:read+;qXfer:features:read+;qXfer:threads:read+;QStartNoAckMode+;vContSupported+
openocd输出
Info : accepting 'gdb' connection on tcp/3333
Warn : No symbols for FreeRTOS!
Error: Failed to write stub section!
Error: Failed to run flasher stub (-4)!
Warn : Failed to get flash mappings (-4)!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Failed to wait algorithm (-4)!
Error: Algorithm run failed (-4)!
Error: Failed to run flasher stub (-4)!
Warn : not enough working area available(requested 7640)
Error: no working area available, can't alloc space for stub code!
Error: Failed to run flasher stub (-308)!
Error: Failed to probe flash, size 0 KB
Error: auto_probe failed
Error: Connect failed. Consider setting up a gdb-attach event for the target to prepare target for GDB connect, or use 'gdb_memory_map disable'.
Error: attempted 'gdb' connection rejected
然后猜测是Failed to run flasher stub 造成的问题。
然后用telnet localhost 4444发现其实openocd可以工作,可以reg pc 成功dump pc的值,mdb能正常dump 内存内容。
当然bp断点工作有一些异常。所以USB通路上应该没有什么问题。
然后偶然发现,刚烧写程序后,GDB是能连上openocd. 也能基本的工作一下。可以bt和dump 内存成功
$ ./riscv32-esp-elf-gdb.exe /e/blink.elf
GNU gdb (crosstool-NG 1.24.0.123_64eb9ff) 8.3.1.20191211-git
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later http://gnu.org/licenses/gpl.html
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Type "show copying" and "show warranty" for details.
This GDB was configured as "--host=x86_64-host_w64-mingw32 --target=riscv32-esp-elf".
Type "show configuration" for configuration details.
For bug reporting instructions, please see:
http://www.gnu.org/software/gdb/bugs/.
Find the GDB manual and other documentation resources online at:
http://www.gnu.org/software/gdb/documentation/.
For help, type "help".
Type "apropos word" to search for commands related to "word"...
Reading symbols from E:/blink.elf...
(gdb) target remote :3333
Remote debugging using :3333
Ignoring packet error, continuing...
warning: unrecognized item "timeout" in "qSupported" response
Remote replied unexpectedly to 'vMustReplyEmpty': PacketSize=4000;qXfer:memory-map:read+;qXfer:features:read+;qXfer:threads:read+;QStartNoAckMode+;vContSupported+
Undefined command: "". Try "help".
(gdb) target remote :3333
Remote debugging using :3333
0x40380786 in get_all_caps (heap=0x0)
at /root/ws/esp8266/esp-idf/components/heap/heap_private.h:56
56 /root/ws/esp8266/esp-idf/components/heap/heap_private.h: No such file or directory.
(gdb) (gdb) bt
#0 0x40380786 in get_all_caps (heap=0x0)
at /root/ws/esp8266/esp-idf/components/heap/heap_private.h:56
#1 heap_caps_realloc (ptr=0x0, size=1070137420, caps=1070153884)
at /root/ws/esp8266/esp-idf/components/heap/heap_caps.c:350
#2 0x4941484f in ?? ()
Backtrace stopped: previous frame inner to this frame (corrupt stack?)
x /32x 0x40380786 可以bt和dump 内存成功
0x40380786 <heap_caps_realloc+72>: 0xa483dff5 0x478508ca 0x080aa623 0x02f10423
0x40380796 <heap_caps_realloc+88>: 0x0014c783 0x15234709 0x04a302e1 0xd60202f1
0x403807a6 <heap_caps_realloc+104>: 0x86634729 0x474d06e7 0x08e78063 0x45a13e2d
0x403807b6 <heap_caps_realloc+120>: 0x36391028 0x0034c703 0x0024c783 0x07226691
0x403807c6 <heap_caps_realloc+136>: 0x87938f5d 0xf5630106 0x051306e7 0x346d0db0
0x403807d6 <heap_caps_realloc+152>: 0x0dc00513 0x05133455 0x3c790ee0 0xbf793629
0x40380786 <heap_caps_realloc+72>: 0xa483dff5 0x478508ca 0x080aa623 0x02f10423
0x403807e6 <heap_caps_realloc+168>: 0x0007a023 0xb5d10791 0x403805b7 0x85934601
0x403807f6 <heap_caps_realloc+184>: 0x45150365 0xffc80097 0xe0a080e7 0x60000737
0x40380796 <heap_caps_realloc+88>: 0x0014c783 0x15234709 0x04a302e1 0xd60202f1
0x403807a6 <heap_caps_realloc+104>: 0x86634729 0x474d06e7 0x08e78063 0x45a13e2d
0x403807b6 <heap_caps_realloc+120>: 0x36391028 0x0034c703 0x0024c783 0x07226691
0x403807c6 <heap_caps_realloc+136>: 0x87938f5d 0xf5630106 0x051306e7 0x346d0db0
0x403807d6 <heap_caps_realloc+152>: 0x0dc00513 0x05133455 0x3c790ee0 0xbf793629
0x403807e6 <heap_caps_realloc+168>: 0x0007a023 0xb5d10791 0x403805b7 0x85934601
0x403807f6 <heap_caps_realloc+184>: 0x45150365 0xffc80097 0xe0a080e7 0x60000737
但是一旦复位后,blink程序跑起来,灯闪。GDB就连不上openocd. 报之前的问题。
并且openocd输出
Info : accepting 'gdb' connection on tcp/3333
Warn : No symbols for FreeRTOS!
Error: Failed to write stub section!
Error: Failed to run flasher stub (-4)!
Warn : Failed to get flash mappings (-4)!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Hart is not halted!
Error: Failed to wait algorithm (-4)!
Error: Algorithm run failed (-4)!
Error: Failed to run flasher stub (-4)!
Warn : not enough working area available(requested 7640)
Error: no working area available, can't alloc space for stub code!
所以从现象上看应该是某个地方状态出了点小问题,进一步发现只要芯片Staying in flasher stub,GDB就能100%连上
Staying in flasher stub时
root@localhost:~/ws# esptool.py --chip esp32c3 -p /dev/ttyUSB0 -b 460800 --before=default_reset --after=no_reset_stub write_flash --flash_mode dio --flash_freq 40m --flash_size 4MB 0x8000 ./partition-table.bin
esptool.py v3.1
Serial port /dev/ttyUSB0
Connecting....
Chip is unknown ESP32-C3 (revision 3)
Features: Wi-Fi
Crystal is 40MHz
MAC: 7c:df:a1:c0:11:48
Uploading stub...
Running stub...
Stub running...
Changing baud rate to 460800
Changed.
Configuring flash size...
Flash will be erased from 0x00008000 to 0x00008fff...
Compressed 3072 bytes to 103...
Wrote 3072 bytes (103 compressed) at 0x00008000 in 0.1 seconds (effective 366.9 kbit/s)...
Hash of data verified.
Leaving...
Staying in flasher stub.