espressif / arduino-esp32

Arduino core for the ESP32
GNU Lesser General Public License v2.1
13.63k stars 7.41k forks source link

Inconsistent Arduino sketch debugging using VSCode and ESP Prog #6931

Open zfields opened 2 years ago

zfields commented 2 years ago

Board

Adafruit ESP32 Feather (esp32:esp32:featheresp32)

Device Description

ESP-Prog

Hardware Configuration

No additional hardware is required to reproduce this issue.

Version

v2.0.3

IDE Name

VSCode (Microsoft Arduino Extension to compile and Microsoft C/C++ Extension to debug)

Operating System

Ubuntu 22.04

Flash frequency

80000 kHz (80 MHz)

PSRAM enabled

no

Upload speed

921600

Description

I am experiencing two issues:

  1. Debugger only connects every other attempt (fail/succeed/fail/succeed/...).

    Failed Attempt Log:

    <--   C (setBreakpoints-3): {"command":"setBreakpoints","arguments":{"source":{"name":"NotecardWiFiTriangulator.cpp","path":"/workspaces/EpiCAT/NotecardWiFiTriangulator.cpp"},"lines":[40],"breakpoints":[{"line":40}],"sourceModified":false},"type":"request","seq":3}
    <--   C (setFunctionBreakpoints-4): {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4}
    <--   C (setDataBreakpoints-5): {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
    <--   C (setInstructionBreakpoints-6): {"command":"setInstructionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
    <--   C (setExceptionBreakpoints-7): {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[]},"type":"request","seq":7}
    <--   C (configurationDone-8): {"command":"configurationDone","type":"request","seq":8}
    openocd: Open On-Chip Debugger  v0.11.0-esp32-20220411 (2022-04-11-08:47)
    openocd: Licensed under GNU GPL v2
    openocd: For bug reports, read
    openocd:     http://openocd.org/doc/doxygen/bugs.html
    openocd: adapter speed: 20000 kHz
    openocd: 
    openocd: Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi tdo_sample_edge falling"
    openocd: Info : clock speed 20000 kHz
    openocd: Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : esp32.cpu0: Target halted, PC=0x40164D56, debug_reason=00000000
    openocd: Info : esp32.cpu1: Target halted, PC=0x400D2A23, debug_reason=00000001
    openocd: Info : starting gdb server for esp32.cpu0 on 3333
    openocd: Info : Listening on port 3333 for gdb connections
    =thread-group-added,id="i1"
    GNU gdb (crosstool-NG esp-2022r1-RC1) 9.2.90.20200913-git
    Copyright (C) 2020 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-build_pc-linux-gnu --target=xtensa-esp32-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".
    Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
    =cmd-param-changed,param="pagination",value="off"
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Set GDB target to 'esp32.cpu0'
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu0.irom' size 640 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu0.drom' size 156 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu1.irom' size 640 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu1.drom' size 156 KB
    openocd: Info : Listening on port 6666 for tcl connections
    openocd: Info : Listening on port 4444 for telnet connections
    openocd: Info : accepting 'gdb' connection on tcp/3333
    openocd: Warn : No symbols for FreeRTOS!
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Auto-detected flash bank 'esp32.cpu0.flash' size 4096 KB
    openocd: Info : Using flash bank 'esp32.cpu0.flash' size 4096 KB
    openocd: Info : New GDB Connection: 1, Target esp32.cpu0, state: halted
    0x40164d56 in esp_pm_impl_waiti () at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp- 
    idf/components/hal/esp32/include/hal/cpu_ll.h:183
    [New Thread 1073468284]
    [New Thread 1073449076]
    [New Thread 1073455764]
    [New Thread 1073461212]
    [New Thread 1073445156]
    [Switching to thread 1 (Thread 1073466884)]
    =thread-selected,id="1"
    [New Thread 1073466884]
    openocd: Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : esp32.cpu0: Debug controller was reset.
    openocd: Info : esp32.cpu0: Core was reset.
    openocd: Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
    openocd: Info : esp32.cpu0: Core was reset.
    openocd: Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
    openocd: Info : esp32.cpu1: Debug controller was reset.
    openocd: Info : esp32.cpu1: Core was reset.
    openocd: Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
    <--   C (threads-9): {"command":"threads","type":"request","seq":9}
    ERROR: Unable to start debugging. Failed to find thread 1 for break event
    openocd: shutdown command invoked
    openocd: Info : dropped 'gdb' connection
    The program '/workspaces/EpiCAT/build/EpiCAT.ino.elf' has exited with code 42 (0x0000002a).
    [Inferior 1 (Remote target) detached]
    <--   C (disconnect-10): {"command":"disconnect","arguments":{"restart":false},"type":"request","seq":10}

    Successful Attempt Log:

    <--   C (setBreakpoints-3): {"command":"setBreakpoints","arguments":{"source":{"name":"NotecardWiFiTriangulator.cpp","path":"/workspaces/EpiCAT/NotecardWiFiTriangulator.cpp"},"lines":[40],"breakpoints":[{"line":40}],"sourceModified":false},"type":"request","seq":3}
    <--   C (setFunctionBreakpoints-4): {"command":"setFunctionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":4}
    <--   C (setDataBreakpoints-5): {"command":"setDataBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":5}
    <--   C (setInstructionBreakpoints-6): {"command":"setInstructionBreakpoints","arguments":{"breakpoints":[]},"type":"request","seq":6}
    <--   C (setExceptionBreakpoints-7): {"command":"setExceptionBreakpoints","arguments":{"filters":[],"filterOptions":[]},"type":"request","seq":7}
    <--   C (configurationDone-8): {"command":"configurationDone","type":"request","seq":8}
    openocd: Open On-Chip Debugger  v0.11.0-esp32-20220411 (2022-04-11-08:47)
    openocd: Licensed under GNU GPL v2
    openocd: For bug reports, read
    openocd:     http://openocd.org/doc/doxygen/bugs.html
    openocd: adapter speed: 20000 kHz
    openocd: 
    openocd: Info : ftdi: if you experience problems at higher adapter clocks, try the command "ftdi tdo_sample_edge falling"
    openocd: Info : clock speed 20000 kHz
    openocd: Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
    openocd: Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
    openocd: Info : starting gdb server for esp32.cpu0 on 3333
    openocd: Info : Listening on port 3333 for gdb connections
    =thread-group-added,id="i1"
    GNU gdb (crosstool-NG esp-2022r1-RC1) 9.2.90.20200913-git
    Copyright (C) 2020 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-build_pc-linux-gnu --target=xtensa-esp32-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".
    Warning: Debuggee TargetArchitecture not detected, assuming x86_64.
    =cmd-param-changed,param="pagination",value="off"
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Set GDB target to 'esp32.cpu0'
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu0.irom' size 640 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu0.drom' size 156 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu1.irom' size 640 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : Using flash bank 'esp32.cpu1.drom' size 156 KB
    openocd: Info : Listening on port 6666 for tcl connections
    openocd: Info : Listening on port 4444 for telnet connections
    openocd: Info : accepting 'gdb' connection on tcp/3333
    openocd: Warn : No symbols for FreeRTOS!
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Flash mapping 0: 0x10020 -> 0x3f400020, 154 KB
    openocd: Info : Flash mapping 1: 0x40020 -> 0x400d0020, 637 KB
    openocd: Info : esp32.cpu0: Target halted, PC=0x4009260E, debug_reason=00000001
    openocd: Info : Auto-detected flash bank 'esp32.cpu0.flash' size 4096 KB
    openocd: Info : Using flash bank 'esp32.cpu0.flash' size 4096 KB
    openocd: Info : New GDB Connection: 1, Target esp32.cpu0, state: halted
    0x40000400 in ?? ()
    openocd: Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
    openocd: Info : esp32.cpu0: Debug controller was reset.
    openocd: Info : esp32.cpu0: Core was reset.
    openocd: Info : esp32.cpu0: Target halted, PC=0x500000CF, debug_reason=00000000
    openocd: Info : esp32.cpu0: Core was reset.
    openocd: Info : esp32.cpu0: Target halted, PC=0x40000400, debug_reason=00000000
    openocd: Info : esp32.cpu1: Debug controller was reset.
    openocd: Info : esp32.cpu1: Core was reset.
    openocd: Info : esp32.cpu1: Target halted, PC=0x40000400, debug_reason=00000000
    <--   C (threads-9): {"command":"threads","type":"request","seq":9}
    Note: automatically using hardware breakpoints for read-only addresses.
    <--   C (threads-10): {"command":"threads","type":"request","seq":10}
    openocd: Info : esp32.cpu0: Target halted, PC=0x40164D56, debug_reason=00000000
    openocd: Info : Set GDB target to 'esp32.cpu0'
    esp32.cpu0: Target halted, PC=0x40164D56, debug_reason=00000000
    Set GDB target to 'esp32.cpu0'
    openocd: Info : esp32.cpu1: Target halted, PC=0x400D2A23, debug_reason=00000001
    esp32.cpu1: Target halted, PC=0x400D2A23, debug_reason=00000001
    [New Thread 1073466884]
    [New Thread 1073468284]
    [New Thread 1073455764]
    [New Thread 1073461212]
    [New Thread 1073445156]
    [Switching to Thread 1073449076]
    
    Thread 1 "loopTask" hit Breakpoint 2, blues::NotecardWiFiTriangulator::for_each_cwlap<blues::NotecardWiFiTriangulator::logCachedSsids()::<lambda(char const*)> > (blues::NotecardWiFiTriangulator::<lambda(char const*)>) (func_=..., this=<optimized out>) at /workspaces/EpiCAT/NotecardWiFiTriangulator.cpp:40
    40       for (int i = 0; i < _ap_count; i++) {
    Execute debugger commands using "-exec <command>", for example "-exec info registers" will list registers in use (when GDB is the debugger)
    <--   C (threads-11): {"command":"threads","type":"request","seq":11}
    <--   C (threads-12): {"command":"threads","type":"request","seq":12}
    <--   C (stackTrace-13): {"command":"stackTrace","arguments":{"threadId":-2,"startFrame":0,"levels":20},"type":"request","seq":13}
    <--   C (evaluate-14): {"command":"evaluate","arguments":{"expression":"_ap_count","frameId":1000,"context":"watch"},"type":"request","seq":14}
    <--   C (scopes-15): {"command":"scopes","arguments":{"frameId":1000},"type":"request","seq":15}
    <--   C (variables-16): {"command":"variables","arguments":{"variablesReference":1000},"type":"request","seq":16}
  2. Specifying -c "esp32.cpu1 configure -rtos FreeRTOS" in the OpenOCD parameters, causes the debugger to break at esp_pm_impl_waiti () at /home/runner/work/esp32-arduino-lib-builder/esp32-arduino-lib-builder/esp-idf/components/hal/esp32/include/hal/cpu_ll.h:183.

    I do not appear to be able to "continue" past it, or access other threads.

    image
    Originally specified to suppress the OpenOCD warning, openocd: Warn : No symbols for FreeRTOS!

Sketch

All code can be found at https://github.com/zfields/EpiCAT

Debug Message

both success and failure debug logs are provided above in Description

Other Steps to Reproduce

This can be reproduced from the container. It has all required tools, and can be accessed via the dev container by clicking "Reopen in Container" button.

The Arduino application needs to be flashed directly over USB via the primary bootloader (which flashes the secondary bootloader and partition table). Finally, the sketch can be deployed and debugged via the ESP Prog using OpenOCD.

The Microsoft Arduino extension allows you to directly flash the entire application, then debugging can be performed using the Debugging Menu by selecting "ESP-Prog Debug".

I have checked existing issues, online documentation and the Troubleshooting Guide

SuGlider commented 2 years ago

@P-R-O-C-H-Y - Do you think you can help on this issue? I think you have experience using VSCode/openocd/gdb. Thanks!

@zfields - The precompiled IDF libraries used with Arduino Core have no debug information. I think that the whole final generated firmware has no debug information in order to use gdb.

You may need to create an "Arduino as Component" project and activate -Og compilation option to build it in order to debug it using openocd and gdb.