Marus / cortex-debug

Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
MIT License
1.02k stars 241 forks source link

Bug: unknown command: 'halt' when connecting to a QEMU gdbserver #1039

Closed smwikipedia closed 3 months ago

smwikipedia commented 3 months ago

Describe the bug I launch the qemu-system-arm with -s option, which start a gdbserver on -gdb tcp::1234. Then I connect Cortex Debug to the gdbserver with below launch.json in Visual Studio Code.

        {
            "type": "cortex-debug",
            "request": "attach",
            "name": "Attach to gdbserver with Cortex Debug",
            "executable": "<somewhere>/MyBinary.elf",
            "servertype": "external",
            "gdbTarget": "11.22.33.44:1234",
            "gdbPath": "<somewhere>/arm-gnu-toolchain-13.3.rel1-x86_64-arm-none-eabi/bin/arm-none-eabi-gdb",
            "debuggerArgs": ["-ex", "b reset_handler"],

            "cwd": "${workspaceRoot}",
        },

Then in the Visual Studio Code's Debug Console window, below message is printed. The unknown command: 'halt' is printed on the last line.

And the -ex "b reset_handler" argument is not executed.

The similar set up works fine with Native Debug extension for Visual Studio Code.

Finished reading symbols from objdump: Time: 20 ms
Finished reading symbols from nm: Time: 34 ms
No symbol table is loaded.  Use the "file" command.
Make breakpoint pending on future shared library load? (y or [n]) [answered N; input not from terminal]
Output radix now set to decimal 10, hex a, octal 12.
Input radix now set to decimal 10, hex a, octal 12.
0x00000000 in ?? ()
Program stopped, probably due to a reset and/or halt issued by debugger
unknown command: 'halt'   <================== HERE!

I guess the Cortex Debug is still expecting an OpenOCD gdbserver, though I specify external for the "servertype". Because AFAIK, the halt command is only meaningful to OpenOCD.

The error message of "halt" command may be not critical.

But the failure of -ex option is critical.

haneefdm commented 3 months ago

halt is meaningful to most gdb-servers. When you have external server type, you have to supply all the required commands to make debug possible. external means we have no idea what your are doing or why, so some reasonable defaults are used. Please read our docs and how our debugger works and what it expects...

https://github.com/Marus/cortex-debug/wiki/Cortex-Debug-Under-the-hood

Note that we do not issue any halt command to the server. We issue that command to gdb and it is supposed to do the right thing based on the server. If your gdb does not support a halt, many things will not work.