Marus / cortex-debug

Visual Studio Code extension for enhancing debug capabilities for Cortex-M Microcontrollers
MIT License
984 stars 238 forks source link

Target not reported as halted with rust project #1001

Closed mrgdoubleyou closed 5 months ago

mrgdoubleyou commented 5 months ago

I am in the process of setting up a VSCode configuration for a rust project and a Cortex-M4 device on Windows. The launch seems to work correctly, however it appears that my target never halts. I'm wondering if perhaps the VSCode side is unaware of the actual target status as the halt button is greyed out: image

My first debug approach was to see why the target wasn't halting. However, when running manually with GDB server and GDB, it appears that the target is halted. See attached logs below. The GDB server command is the same command that cortex-debug is issuing during the launch. gdb_server_log.txt gdb_log.txt

Is it possible that the target isn't exactly halting at main and therefore confusing the debugger?

My launch.json is listed below and the "vscode" debug console output is here: debug_console.txt

Here is the gdb server console from the VSCode initiated session: cortex_debug_gdb_server_log.txt

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Cortex Debug",
            "cwd": "${workspaceFolder}",
            "executable": "./target/thumbv7em-none-eabihf/debug/rsc",
            "request": "launch",
            "type": "cortex-debug",
            "runToEntryPoint": "main",
            "servertype": "jlink",
            "serverpath": "C:/Program Files/SEGGER/JLink_V796a/JLinkGDBServerCL.exe",
            "serverArgs": ["-settingsfile", "./cfg/JLinkSettings.ini", "-speed", "2000"],
            "device": "VA416xx",
            "interface": "swd",
            "serialNumber": "",
            "jlinkscript":"./cfg/JLinkSettings.jlinkscript",
            "svdFile": "./cfg/va416xx.svd",
            "armToolchainPath": "C:/Program Files (x86)/Arm GNU Toolchain arm-none-eabi/13.2 Rel1/bin",
            "showDevDebugOutput": "vscode"
        }
    ]
}

My rust program is simple and was more or less generated with: cargo generate --git https://github.com/rust-embedded/cortex-m-quickstart

#![no_main]
#![no_std]

use panic_halt as _;

use cortex_m_rt::entry;

#[entry]
fn main() -> ! {
    loop {
        let mut i = 0;
        i += 1;
    }
}

Versions are:

mrgdoubleyou commented 5 months ago

As another data point, I can see the same issue using qemu as described here: https://doc.rust-lang.org/beta/embedded-book/start/qemu.html

mrgdoubleyou commented 5 months ago

Okay, I have solved the mystery and the error is all on my side. I was launching the debugger with Ctrl+F5 as that is the default for the Keil IDE. Turns out that is the wrong key and I wanted F5 all along.

mrgdoubleyou commented 5 months ago

Thanks for the wonderful extension!