Marus / cortex-debug

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

Debugger trying to debug non-existant example.elf which is not in project #1055

Closed Charry2014 closed 3 days ago

Charry2014 commented 3 days ago

Describe the bug This is more a request for help and explanation than reporting a bug - The debugger is always trying to debug a file called example.elf which does not exist and is not mentioned in any makefile I can find - where is this name coming from? The project does not build this file.

On starting the debugger VS Code presents a dialog - Failed to launch GDB: /Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf: No such file or directory. (from interpreter-exec console "load \"/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf\"")

This is building a FreeRTOS project for the Pi 2040. The project builds two .elf files - on_core_zero.elf and on_core_one.elf. If one of these is renamed to example.elf then debugging proceeds normally.

To Reproduce Installed plugins are the standard Raspberry Pi plugin for VS Code, and of course Cortex Debug. The required tools (Pico SDK etc.) are all installed. OpenOCD is installed using xPack to work around this issue. To set up the project I cloned the FreeRTOS Kernel and Community Examples into the same folder, and then selected (at random) the FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore folder to make the project. Having added this folder to the VS Code workspace the project was created and after setting some environment variables it builds fine.

setup.sh

#!/bin/bash

if [ ! -d ./build ]; then
    mkdir ./build
fi
cd ./build
export PICO_SDK_PATH="$HOME"/.pico-sdk
export FREERTOS_KERNEL_PATH="$HOME"/work/projects/vscfreetos/FreeRTOS-Kernel
export PICO_TOOLCHAIN_PATH="$HOME"/.pico-sdk/toolchain/13_2_Rel1/bin

cmake -G Ninja ..

Expected behavior

The debugger should debug the file mentioned in the executable section of launch.json "executable": "${workspaceRoot}/build/on_core_zero.elf",

Environment (please complete the following information):

Launch.json:

        {
            "name": "Pico Debug (Cortex-Debug)",
            "cwd": "${workspaceRoot}",
            "executable": "${workspaceRoot}/build/on_core_zero.elf",
            "request": "launch",
            "showDevDebugOutput": "raw",
            "type": "cortex-debug",
            "servertype": "openocd",
            "gdbPath": "${command:raspberry-pi-pico.getGDBPath}",
            "device": "${command:raspberry-pi-pico.getChipUppercase}",
            "configFiles": [
                "interface/cmsis-dap.cfg",
                "target/${command:raspberry-pi-pico.getTarget}.cfg"
            ],
            "svdFile": "${userHome}/.pico-sdk/sdk/2.0.0/src/${command:raspberry-pi-pico.getChip}/hardware_regs/${command:raspberry-pi-pico.getChipUppercase}.svd",
            "runToEntryPoint": "main",
            // Fix for no_flash binaries, where monitor reset halt doesn't do what is expected
            // Also works fine for flash binaries
            "overrideLaunchCommands": [
                "monitor reset init",
                "load \"${command:raspberry-pi-pico.launchTargetPath}\""
            ],
            "openOCDLaunchCommands": [
                "adapter speed 5000"
            ]
        },

Attach text from Debug Console

Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
"configuration": {
    "name": "Pico Debug (Cortex-Debug)",
    "cwd": "/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore",
    "executable": "/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/on_core_zero.elf",
    "request": "launch",
    "showDevDebugOutput": "raw",
    "type": "cortex-debug",
    "servertype": "openocd",
    "gdbPath": "/Users/toby/.pico-sdk/toolchain/13_2_Rel1/bin/arm-none-eabi-gdb",
    "device": "RP2040",
    "configFiles": [
        "interface/cmsis-dap.cfg",
        "target/rp2040.cfg"
    ],
    "svdFile": "/Users/toby/.pico-sdk/sdk/2.0.0/src/rp2040/hardware_regs/RP2040.svd",
    "runToEntryPoint": "main",
    "overrideLaunchCommands": [
        "monitor reset init",
        "load \"/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf\""
    ],
    "openOCDLaunchCommands": [
        "adapter speed 5000"
    ],
    "__configurationTarget": 6,
    "gdbServerConsolePort": 55878,
    "pvtAvoidPorts": [],
    "chainedConfigurations": {
        "enabled": false
    },
    "debuggerArgs": [],
    "swoConfig": {
        "enabled": false,
        "decoders": [],
        "cpuFrequency": 0,
        "swoFrequency": 0,
        "source": "probe"
    },
    "rttConfig": {
        "enabled": false,
        "decoders": []
    },
    "graphConfig": [],
    "preLaunchCommands": [],
    "postLaunchCommands": [],
    "preAttachCommands": [],
    "postAttachCommands": [],
    "preRestartCommands": [],
    "postRestartCommands": [],
    "preResetCommands": [],
    "postResetCommands": [],
    "searchDir": [],
    "toolchainPrefix": "arm-none-eabi",
    "extensionPath": "/Users/toby/.vscode/extensions/marus25.cortex-debug-1.12.1",
    "registerUseNaturalFormat": true,
    "variableUseNaturalFormat": true,
    "pvtVersion": "1.12.1",
    "__sessionId": "42ccfaa7-3c7d-4d6a-9413-30d7b4b3ad08",
    "pvtShowDevDebugOutput": "raw"
}
Reading symbols from /Users/toby/.pico-sdk/toolchain/13_2_Rel1/bin/arm-none-eabi-objdump --syms -C -h -w /Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/on_core_zero.elf
Reading symbols from /Users/toby/.pico-sdk/toolchain/13_2_Rel1/bin/arm-none-eabi-nm --defined-only -S -l -C -p /Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/on_core_zero.elf
Launching GDB: /Users/toby/.pico-sdk/toolchain/13_2_Rel1/bin/arm-none-eabi-gdb -q --interpreter=mi2
1-gdb-version
Launching gdb-server: openocd -c "gdb_port 50000" -c "tcl_port 50001" -c "telnet_port 50002" -s /Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore -f /Users/toby/.vscode/extensions/marus25.cortex-debug-1.12.1/support/openocd-helpers.tcl -f interface/cmsis-dap.cfg -f target/rp2040.cfg -c "adapter speed 5000"
    Please check TERMINAL tab (gdb-server) for output from openocd
Finished reading symbols from objdump: Time: 49 ms
Finished reading symbols from nm: Time: 79 ms
-> =thread-group-added,id="i1"
-> ~"GNU gdb (Arm GNU Toolchain 13.2.rel1 (Build arm-13.7)) 13.2.90.20231008-git\n"
-> ~"Copyright (C) 2023 Free Software Foundation, Inc.\n"
-> ~"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."
-> ~"\nType \"show copying\" and \"show warranty\" for details.\n"
-> ~"This GDB was configured as \"--host=x86_64-apple-darwin21.6.0 --target=arm-none-eabi\".\n"
-> ~"Type \"show configuration\" for configuration details.\n"
-> ~"For bug reporting instructions, please see:\n"
-> ~"<https://bugs.linaro.org/>.\n"
-> ~"Find the GDB manual and other documentation resources online at:\n    <"
-> ~"http://www.gnu.org/software/gdb/documentation/>.\n\n"
-> ~"For help, type \"help\".\n"
-> ~"Type \"apropos word\" to search for commands related to \"word\".\n"
-> 1^done
2-gdb-set mi-async on
-> 2^done
3-interpreter-exec console "set print demangle on"
-> 3^done
4-interpreter-exec console "set print asm-demangle on"
-> =cmd-param-changed,param="print asm-demangle",value="on"
-> 4^done
5-enable-pretty-printing
-> 5^done
6-interpreter-exec console "source /Users/toby/.vscode/extensions/marus25.cortex-debug-1.12.1/support/gdbsupport.init"
-> 6^done
7-interpreter-exec console "source /Users/toby/.vscode/extensions/marus25.cortex-debug-1.12.1/support/gdb-swo.init"
-> =cmd-param-changed,param="language",value="c"
-> =cmd-param-changed,param="language",value="auto"
-> 7^done
8-interpreter-exec console "set output-radix 0xa"
-> ~"Output radix now set to decimal 10, hex a, octal 12.\n"
Output radix now set to decimal 10, hex a, octal 12.
-> 8^done
9-interpreter-exec console "set input-radix 0xa"
-> ~"Input radix now set to decimal 10, hex a, octal 12.\n"
Input radix now set to decimal 10, hex a, octal 12.
-> 9^done
10-file-exec-and-symbols "/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/on_core_zero.elf"
-> 10^done
11-target-select extended-remote localhost:50000
-> =thread-group-started,id="i1",pid="42000"
-> =thread-created,id="1",group-id="i1"
-> =thread-created,id="2",group-id="i1"
-> &"warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread\n"
warning: multi-threaded target stopped without sending a thread-id, using first non-exited thread
-> ~"0x10001bf8 in prvCheckTasksWaitingTermination () at /Users/toby/work/projects/vscfreetos/FreeRTOS-Kernel/tasks.c:6065\n"
0x10001bf8 in prvCheckTasksWaitingTermination () at /Users/toby/work/projects/vscfreetos/FreeRTOS-Kernel/tasks.c:6065
-> ~"6065\t        while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U )\n"
6065            while( uxDeletedTasksWaitingCleanUp > ( UBaseType_t ) 0U )
-> *stopped,frame={addr="0x10001bf8",func="prvCheckTasksWaitingTermination",args=[],file="/Users/toby/work/projects/vscfreetos/FreeRTOS-Kernel/tasks.c",fullname="/Users/toby/work/projects/vscfreetos/FreeRTOS-Kernel/tasks.c",line="6065",arch="armv6s-m"},thread-id="1",stopped-threads="all"
mi2.status = stopped
Program stopped, probably due to a reset and/or halt issued by debugger
-> 11^connected
12-interpreter-exec console "monitor reset init"
-> @"[rp2040.core0] halted due to breakpoint, current mode: Thread \n"
[rp2040.core0] halted due to breakpoint, current mode: Thread
-> @"xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00\n"
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
-> @"[rp2040.core1] halted due to debug-request, current mode: Thread \n"
[rp2040.core1] halted due to debug-request, current mode: Thread
-> @"xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00\n"
xPSR: 0xf1000000 pc: 0x000000ea msp: 0x20041f00
-> 12^done
13-interpreter-exec console "load \"/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf\""
-> &"/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf: No such file or directory.\n"
/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf: No such file or directory.
-> 13^error,msg="/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf: No such file or directory."
Failed to launch GDB: /Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf: No such file or directory. (from interpreter-exec console "load \"/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf\"")

Additional context This is my first step into debugging Pi FreeRTOS projects in C so any help gratefully received.

haneefdm commented 3 days ago

You are the one forcing the load of example.elf from your launch.json

            "overrideLaunchCommands": [
                "monitor reset init",
                "load \"${command:raspberry-pi-pico.launchTargetPath}\""
            ],

In the debug console, you will see the above translated into

    "overrideLaunchCommands": [
        "monitor reset init",
        "load \"/Users/toby/work/projects/vscfreetos/FreeRTOS-Community-Supported-Demos/CORTEX_M0+_RP2040/OnEitherCore/build/example.elf\""
    ],

Please contact whoever gave you this template. When you override things, you are on your own and have to understand what is going on.

Charry2014 commented 3 days ago

Thank you, thank you. That is the magic - kicking myself for missing that, but many thanks for your help.

The template doing this most likely is the standard Raspberry Pi extension for VS Code, which I do not understand - but I am learning. Thank you again for your help.