I'm trying to use VSCode on Windows to remote debug the ESP32 using Olimex ARM-USB-OCD-H JTAG debugger connected to a Linux (Ubuntu) server that is running espressif openocd. The binaries are compiled on the Ubuntu server. The local Windows machine has a the xtensa gdb client that (in theory) should be able to single-step debug the ESP32 when connecting to the remote OpenOCD server. Instead, an error occurs.
{
"version": "0.2.0",
"configurations": [
{
"name": "OpenOCD Debug",
"type": "cppdbg",
"request": "launch",
"miDebuggerPath": "C:/msys32/opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe",
"miDebuggerServerAddress": "192.168.174.129:3333",
"program": "Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
},
{
"text": "file 'Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf'"
},
{
"text": "target remote 192.168.174.129:3333"
},
{
"text": "monitor reset init"
}
],
"externalConsole": false,
"cwd": "Z:/home/gojimmypi/esp/hello_world/build/",
"logging": {
"trace": true,
"traceResponse": true,
"engineLogging": true
}
}
]
}
Note that my Z: drive on Windows is mapped to the root of the Ubuntu file system (running samba there).
gojimmypi@ubuntu : ~/workspace/ESP32/openocd/scripts
0 $ sudo openocd -f interface/ftdi/olimex-arm-usb-ocd-h-1MHz.cfg -c "transport select jtag" -f target/ESP32-RTOS-none.cfg
Open On-Chip Debugger 0.10.0-dev-g372bb59 (2017-05-19-10:35)
Licensed under GNU GPL v2
For bug reports, read
http://openocd.org/doc/doxygen/bugs.html
adapter speed: 1000 kHz
jtag
force hard breakpoints
Info : clock speed 1000 kHz
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Target halted, pc=0x40000400
Info : accepting 'gdb' connection on tcp/3333
Info : JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)
Info : esp32.cpu0: Core was reset (pwrstat=0x1F, after clear 0x0F).
Info : esp32.cpu0: Target halted, pc=0x40000400
esp32.cpu0: target state: halted
Error: timed out while waiting for target halted
TARGET: esp32.cpu1 - Not halted
in procedure 'reset'
in procedure 'ocd_bouncer'
Info : dropped 'gdb' connection
Info : accepting 'gdb' connection on tcp/3333
Info : dropped 'gdb' connection
1: (149) LaunchOptions<LocalLaunchOptions xmlns='http://schemas.microsoft.com/vstudio/MDDDebuggerOptions/2014'
1: (158) LaunchOptions ExePath='Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf'
1: (158) LaunchOptions WorkingDirectory='Z:\home\gojimmypi\esp\hello_world\build\'
1: (158) LaunchOptions ExeArguments=''
1: (158) LaunchOptions MIDebuggerPath='C:/msys32/opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe'
1: (158) LaunchOptions WaitDynamicLibLoad='false'
1: (158) LaunchOptions MIDebuggerServerAddress='192.168.174.129:3333'
1: (158) LaunchOptions>
1: (158) LaunchOptions <SetupCommands>
1: (159) LaunchOptions <Command IgnoreFailures='true' Description='Enable pretty-printing for gdb'>-enable-pretty-printing</Command>
1: (159) LaunchOptions <Command IgnoreFailures='false' Description=''>file 'Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf'</Command>
1: (159) LaunchOptions <Command IgnoreFailures='false' Description=''>target remote 192.168.174.129:3333</Command>
1: (159) LaunchOptions <Command IgnoreFailures='false' Description=''>monitor reset init</Command>
1: (159) LaunchOptions </SetupCommands>
1: (159) LaunchOptions</LocalLaunchOptions>
1: (292) Starting: "C:/msys32/opt/xtensa-esp32-elf/bin/xtensa-esp32-elf-gdb.exe" --interpreter=mi
1: (304) DebuggerPid=7928
1: (335) ->=thread-group-added,id="i1"
1: (336) ->~"GNU gdb (crosstool-NG crosstool-ng-1.22.0-61-gab8375a) 7.10\n"
1: (336) ->~"Copyright (C) 2015 Free Software Foundation, Inc.\n"
1: (336) ->~"License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>\nThis is free software: you are free to change and redistribute it.\nThere is NO WARRANTY, to the extent permitted by law. Type \"show copying\"\nand \"show warranty\" for details.\n"
1: (336) ->~"This GDB was configured as \"--host=i686-host_pc-mingw32 --target=xtensa-esp32-elf\".\nType \"show configuration\" for configuration details."
1: (336) ->~"\nFor bug reporting instructions, please see:\n"
1: (336) ->~"<http://www.gnu.org/software/gdb/bugs/>.\n"
1: (336) ->~"Find the GDB manual and other documentation resources online at:\n<http://www.gnu.org/software/gdb/documentation/>.\n"
1: (336) ->~"For help, type \"help\".\n"
1: (336) ->~"Type \"apropos word\" to search for commands related to \"word\".\n"
1: (336) ->(gdb)
1: (341) <-1001-gdb-set target-async on
1: (346) ->1001^done
1: (346) ->(gdb)
1: (347) 1001: elapsed time 5
1: (352) <-1002-enable-pretty-printing
1: (357) ->1002^done
1: (357) ->(gdb)
1: (357) 1002: elapsed time 4
1: (359) <-1003-interpreter-exec console "file 'Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf'"
1: (373) ->~"Reading symbols from Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf..."
1: (399) ->~"done.\n"
1: (400) ->1003^done
1: (400) ->(gdb)
1: (401) 1003: elapsed time 41
1: (401) <-1004-interpreter-exec console "target remote 192.168.174.129:3333"
1: (428) ->~"Remote debugging using 192.168.174.129:3333\n"
1: (429) ->=thread-group-started,id="i1",pid="42000"
1: (430) ->=thread-created,id="1",group-id="i1"
1: (433) ->~"0x40000400 in ?? ()\n"
1: (433) ->*stopped,frame={addr="0x40000400",func="??",args=[]},thread-id="1",stopped-threads="all"
1: (433) ->1004^done
1: (433) ->(gdb)
1: (445) 1004: elapsed time 44
1: (445) <-1005-thread-info 1
1: (453) ->1005^done,threads=[{id="1",target-id="Remote target",frame={level="0",addr="0x40000400",func="??",args=[]},state="stopped"}]
1: (453) ->(gdb)
1: (454) 1005: elapsed time 9
1: (454) <-1006-interpreter-exec console "monitor reset init"
E thread: {"reason":"started","threadId":-2,"type":"thread"}
1: (491) ->@"JTAG tap: esp32.cpu0 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)\n"
1: (491) ->@"JTAG tap: esp32.cpu1 tap/device found: 0x120034e5 (mfg: 0x272 (Tensilica), part: 0x2003, ver: 0x1)\n"
1: (502) ->@"esp32.cpu0: Core was reset (pwrstat=0x1F, after clear 0x0F).\n"
1: (549) ->@"esp32.cpu0: Target halted, pc=0x40000400\n"
1: (564) ->@"esp32.cpu0: target state: halted\n"
1: (1573) ->@"timed out while waiting for target halted\n"
1: (1573) ->@"TARGET: esp32.cpu1 - Not halted\n"
1: (1574) ->@"in procedure 'reset' \n"
1: (1574) ->@"in procedure 'ocd_bouncer'\n"
1: (1574) ->@"\n"
1: (1574) ->@"\n"
1: (1585) ->1006^done
1: (1585) ->(gdb)
1: (1585) 1006: elapsed time 1131
1: (1585) <-1007-gdb-set solib-search-path Z:/home/gojimmypi/esp/hello_world/build;
1: (1600) ->1007^done
1: (1600) ->(gdb)
1: (1600) 1007: elapsed time 15
1: (1600) <-1008-environment-cd Z:\\home\\gojimmypi\\esp\\hello_world\\build\\
1: (1610) ->1008^done
1: (1610) ->(gdb)
1: (1610) 1008: elapsed time 10
1: (1610) <-1009-interpreter-exec console "show configuration"
1: (1620) ->~"This GDB was configured as follows:\n configure --host=i686-host_pc-mingw32 --target=xtensa-esp32-elf\n"
1: (1620) ->~" --with-auto-load-dir=$debugdir:$datadir/auto-load\n --with-auto-load-safe-path=$debugdir:$datadir/auto-load\n"
1: (1620) ->~" --with-expat\n"
1: (1620) ->~" --with-gdb-datadir=/home/ivan/e/crosstool-NG/builds/xtensa-esp32-elf/share/gdb (relocatable)\n"
1: (1620) ->~" --with-jit-reader-dir=/home/ivan/e/crosstool-NG/builds/xtensa-esp32-elf/lib/gdb (relocatable)\n"
1: (1620) ->~" --without-libunwind-ia64\n"
1: (1620) ->~" --without-lzma\n"
1: (1620) ->~" --without-guile\n"
1: (1620) ->~" --with-separate-debug-dir=/home/ivan/e/crosstool-NG/builds/xtensa-esp32-elf/lib/debug (relocatable)\n"
1: (1620) ->~" --with-sysroot=/home/ivan/e/crosstool-NG/builds/xtensa-esp32-elf/xtensa-esp32-elf/sysroot (relocatable)\n"
1: (1620) ->~" --without-babeltrace\n"
1: (1620) ->~"\n(\"Relocatable\" means the directory can be moved with the GDB installation\ntree, and GDB will still find it.)\n"
1: (1620) ->1009^done
1: (1620) ->(gdb)
1: (1620) 1009: elapsed time 10
E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/MIEngine/WindowsRuntime","data":{"VS.Diagnostics.Debugger.MIEngine.WindowsRuntime":"MinGW"},"type":"output"}
1: (1623) <-1010-file-exec-and-symbols Z:/home/gojimmypi/esp/hello_world/build/hello-world.elf
1: (1647) ->1010^done
1: (1647) ->(gdb)
1: (1647) 1010: elapsed time 24
1: (1647) <-1011-interpreter-exec console "show architecture"
1: (1657) ->~"The target architecture is set automatically (currently xtensa)\n"
1: (1657) ->1011^done
1: (1657) ->(gdb)
1: (1657) 1011: elapsed time 10
1: (1658) <-1012-break-insert main
1: (1674) ->1012^done,bkpt={number="1",type="breakpoint",disp="keep",enabled="y",addr="0x400f4ab0",func="main",file="/home/gojimmypi/esp/hello_world/main/./hello_world_main.c",fullname="Z:\\home\\gojimmypi\\esp\\hello_world\\main\\hello_world_main.c",line="15",thread-groups=["i1"],times="0",original-location="main"}
1: (1674) ->(gdb)
1: (1675) 1012: elapsed time 17
1: (1675) <-1013-target-select remote 192.168.174.129:3333
1: (1685) ->=thread-group-exited,id="i1"
1: (1696) <-logout
E output: {"category":"telemetry","output":"VS/Diagnostics/Debugger/NonFatalError","data":{"VS.Diagnostics.Debugger.NonFatalError.ImplementationName":"Microsoft.MIDebugEngine","VS.Diagnostics.Debugger.NonFatalError.ExceptionType":"System.ArgumentOutOfRangeException","VS.Diagnostics.Debugger.NonFatalError.ExceptionStack":" at OpenDebugAD7.AD7Impl.AD7Port.RemoveProcess(IDebugProcess2 process)\r\n at OpenDebugAD7.AD7DebugSession.<.ctor>b__34_8(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, IDebugThread2 thread, IDebugEvent2 eventObject)\r\n at OpenDebugAD7.AD7DebugSession.Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, IDebugThread2 thread, IDebugEvent2 eventObject, Guid& riidEvent, UInt32 dwAttrib)\r\n at Microsoft.MIDebugEngine.EngineCallback.Send(IDebugEvent2 eventObject, String iidEvent, IDebugProgram2 program, IDebugThread2 thread)\r\n at Microsoft.MIDebugEngine.EngineCallback.OnProcessExit(UInt32 exitCode)\r\n at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass53_0.<.ctor>b__3(Object o, EventArgs args)\r\n at System.EventHandler.Invoke(Object sender, EventArgs e)\r\n at MICore.Debugger.OnDebuggerProcessExit(String exitCode)\r\n at MICore.Debugger.OnStateChanged(String mode, Results results)\r\n at MICore.Debugger.OnStateChanged(String mode, String strresult)\r\n at MICore.Debugger.OnResult(String cmd, String token)\r\n at MICore.Debugger.ProcessStdOutLine(String line)\r\n at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass74_0.<ScheduleStdOutProcessing>b__0()\r\n at Microsoft.MIDebugEngine.WorkerThread.ThreadFunc()","VS.Diagnostics.Debugger.NonFatalError.HResult":-2146233086,"VS.Diagnostics.Debugger.EngineVersion":"14.0.40306.1","VS.Diagnostics.Debugger.AdapterId":"cppdbg","VS.Diagnostics.Debugger.HostVersion":"1.0.30301.1"},"type":"output"}
1: (1705) EXCEPTION: System.ArgumentOutOfRangeException
1: (1705) EXCEPTION: at OpenDebugAD7.AD7Impl.AD7Port.RemoveProcess(IDebugProcess2 process)
1: (1705) EXCEPTION: at OpenDebugAD7.AD7DebugSession.<.ctor>b__34_8(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, IDebugThread2 thread, IDebugEvent2 eventObject)
1: (1705) EXCEPTION: at OpenDebugAD7.AD7DebugSession.Event(IDebugEngine2 engine, IDebugProcess2 process, IDebugProgram2 program, IDebugThread2 thread, IDebugEvent2 eventObject, Guid& riidEvent, UInt32 dwAttrib)
1: (1705) EXCEPTION: at Microsoft.MIDebugEngine.EngineCallback.Send(IDebugEvent2 eventObject, String iidEvent, IDebugProgram2 program, IDebugThread2 thread)
1: (1705) EXCEPTION: at Microsoft.MIDebugEngine.EngineCallback.OnProcessExit(UInt32 exitCode)
1: (1705) EXCEPTION: at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass53_0.<.ctor>b__3(Object o, EventArgs args)
1: (1705) EXCEPTION: at System.EventHandler.Invoke(Object sender, EventArgs e)
1: (1705) EXCEPTION: at MICore.Debugger.OnDebuggerProcessExit(String exitCode)
1: (1705) EXCEPTION: at MICore.Debugger.OnStateChanged(String mode, Results results)
1: (1705) EXCEPTION: at MICore.Debugger.OnStateChanged(String mode, String strresult)
1: (1705) EXCEPTION: at MICore.Debugger.OnResult(String cmd, String token)
1: (1705) EXCEPTION: at MICore.Debugger.ProcessStdOutLine(String line)
1: (1705) EXCEPTION: at Microsoft.MIDebugEngine.DebuggedProcess.<>c__DisplayClass74_0.<ScheduleStdOutProcessing>b__0()
1: (1705) EXCEPTION: at Microsoft.MIDebugEngine.WorkerThread.ThreadFunc()
1: (1707) <--gdb-exit
R: {"success":false,"message":"Unable to start debugging. GDB exited unexpectedly.","request_seq":2,"command":"launch","body":{"error":{"id":1104,"format":"Unable to start debugging. GDB exited unexpectedly.","variables":null}},"running":false,"refs":null,"seq":0,"type":"response"}
C threads: null
R: {"success":true,"message":null,"request_seq":3,"command":"threads","body":{"threads":[{"id":-2,"name":"Thread #-2"}]},"running":false,"refs":null,"seq":0,"type":"response"}
C disconnect: {"restart":false}
R: {"success":true,"message":null,"request_seq":4,"command":"disconnect","body":null,"running":false,"refs":null,"seq":0,"type":"response"}
[Window Title]
Visual Studio Code
[Main Instruction]
Visual Studio Code
[Content]
Version 1.12.2
Commit 19222cdc84ce72202478ba1cec5cb557b71163de
Date 2017-05-10T13:20:36.315Z
Shell 1.6.6
Renderer 56.0.2924.87
Node 7.4.0
[OK]
The target code is the FreeRTOS "hello world" Espressif sample - that needed to be modified a bit as VSCode was complaining that there was no void main(), so I added a little wrapper to appease it. I also disabled the reset with a simple loop.
#include <stdio.h>
#include "freertos/FreeRTOS.h"
#include "freertos/task.h"
#include "esp_system.h"
#include "esp_spi_flash.h"
int main() {
while (1 == 1)
{
printf("Hello world!\n");
/* Print chip information */
esp_chip_info_t chip_info;
esp_chip_info(&chip_info);
printf("This is ESP32 chip with %d CPU cores, WiFi%s%s, ",
chip_info.cores,
(chip_info.features & CHIP_FEATURE_BT) ? "/BT" : "",
(chip_info.features & CHIP_FEATURE_BLE) ? "/BLE" : "");
printf("silicon revision %d, ", chip_info.revision);
printf("%dMB %s flash\n", spi_flash_get_chip_size() / (1024 * 1024),
(chip_info.features & CHIP_FEATURE_EMB_FLASH) ? "embedded" : "external");
for (int i = 10; i >= 0; i--)
{
printf("Looping in %d seconds...\n", i);
vTaskDelay(1000 / portTICK_PERIOD_MS);
}
printf("Looping now.\n");
fflush(stdout);
}
}
void app_main()
{
main();
}
After this error, the ESP32 seems to be unstable and needs to be reset. I was able to otherwise successfully use the GDB client on Linux.
I'm trying to use VSCode on Windows to remote debug the ESP32 using Olimex ARM-USB-OCD-H JTAG debugger connected to a Linux (Ubuntu) server that is running espressif openocd. The binaries are compiled on the Ubuntu server. The local Windows machine has a the xtensa gdb client that (in theory) should be able to single-step debug the ESP32 when connecting to the remote OpenOCD server. Instead, an error occurs.
This is my
launch.jsonfile:Note that my Z: drive on Windows is mapped to the root of the Ubuntu file system (running samba there).
When I press F5 to debug, this output appears on the OpenOCD session:
The line
Info : esp32.cpu0: Target halted, pc=0x40000400is the last displayed before gdb debugging begins. Shown below is the debug console output in VSCode. NoteEXCEPTION: System.ArgumentOutOfRangeExceptionMy VSCode version:
The target code is the FreeRTOS "hello world" Espressif sample - that needed to be modified a bit as VSCode was complaining that there was no
void main(), so I added a little wrapper to appease it. I also disabled the reset with a simple loop.After this error, the ESP32 seems to be unstable and needs to be reset. I was able to otherwise successfully use the GDB client on Linux.