Skip to content

Could not load source file when Debugging #1106

@gfcwfzkm

Description

@gfcwfzkm

Describe the bug
Starting a debug session (with either JLink or STLink, both were tested) results in VSCode being unable to open/find the source file. Adding the additional configuration "postLaunchCommands": ["set substitute-path / ./"] at least let VSCode find the source file with the main entry point, but it still keeps failing to display any other source file.

Only when I set the substitute path ./ to the absolute path on my drive with unix-style path seperator characters, it manages to successfully open the right source files where GDB is pointing to.

I don't think this is the right solution, as that would require me to hard-code the projects location into the launch.json. I did try ${workspaceFolder}, but due to it using the native windows path seperator, that too fails.

It wouldn't surprise me if something is broken on my end, but I can't figure out what it might be and I would be very thankful for any help or pointers.

To Reproduce

Simply starting any debug session on either my desktop or laptop.

Expected behavior

I expect it to correctly figure out which source file to display and open.

Screenshots

Without any postLaunchCommands:

Image

With "postLaunchCommands": ["set substitute-path / ./"]:

Image

Environment (please complete the following information):

  • Cortex-Debug Version 1.12.1
  • OS: Windows 11 Pro
  • GDB Version: GNU gdb (GNU Tools for STM32 12.3.rel1.20240612-1315) 13.2.90.20230627-git
  • Compiler Toolchain Version: (GNU Tools for STM32 12.3.rel1.20240612-1315) 12.3.1 20230626

Please include launch.json

launch.json
{
	// 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": [
		{
			// Quick Test using JLINK to make sure it's not a issue related to a specific debugger
			"name": "Build & Debug - JLink",
			"cwd": "${workspaceFolder}",
			"executable": "${command:cmake.launchTargetPath}",
			"request": "launch",
			"type": "cortex-debug",
			"runToEntryPoint": "main",
			"servertype": "jlink",
			"windows": {
				"serverpath": "C:/Program Files/SEGGER/JLink_V812g/JLinkGDBServerCL",
				"gdbPath": "${env:STM32CLT_PATH}/GNU-tools-for-STM32/bin/arm-none-eabi-gdb",
				"postLaunchCommands": [
					"set substitute-path / C:/Users/pasca/Music/kontron_spitfair"	// This works fully
					//"set substitute-path / \"${workspaceFolder}\""		// Doesn't work due to mixing linux and windows path separators
					//"set substitute-path / ./"	// Only works on the main.cpp file
				]
			},
			"linux": {
				"serverpath": "JLinkGDBServer",
				"gdbPath":"arm-none-eabi-gdb",
			},
			"serverArgs": ["-speed", "12000"],
			"device": "STM32G071RBTx",
			"interface": "swd",
			"svdFile": "${env:STM32CLT_PATH}/STMicroelectronics_CMSIS_SVD/STM32G071.svd",
			"armToolchainPath": "${env:STM32CLT_PATH}/GNU-tools-for-STM32/bin",
			"showDevDebugOutput": "raw",
		},
		{
			"name": "Build & Debug - ST-Link",
			"cwd": "${workspaceFolder}",
			"type": "cortex-debug",
			"executable": "${command:cmake.launchTargetPath}",
			"request": "launch",
			"servertype": "stlink",
			"device": "STM32G071RBTx",	//MCU used
			"interface": "swd",
			"runToEntryPoint": "main",
			"v1": false,				//Change it depending on ST Link version
			"svdFile": "${env:STM32CLT_PATH}/STMicroelectronics_CMSIS_SVD/STM32G071.svd",
			"serverpath": "${env:STM32CLT_PATH}/STLink-gdb-server/bin/ST-LINK_gdbserver",
			"stm32cubeprogrammer":"${env:STM32CLT_PATH}/STM32CubeProgrammer/bin",
			"stlinkPath": "${env:STM32CLT_PATH}/STLink-gdb-server/bin/ST-LINK_gdbserver",
			"armToolchainPath": "${env:STM32CLT_PATH}/GNU-tools-for-STM32/bin",
			"gdbPath": "${env:STM32CLT_PATH}/GNU-tools-for-STM32/bin/arm-none-eabi-gdb",
			"showDevDebugOutput": "raw",
			"serverArgs": [
				"-m","0",
			],
			"postLaunchCommands": [
					//"set substitute-path / ./"	// Only helps for the "main.cpp" file
					"set substitute-path / C:/Users/pasca/Music/kontron_spitfair" // This finally "fixes" it?
			]
		},
		{
			"name": "Attach to MCU - ST-Link",
			"cwd": "${workspaceFolder}",
			"type": "cortex-debug",
			"executable": "${command:cmake.launchTargetPath}",
			"request": "attach",
			"servertype": "stlink",
			"device": "STM32G071RBTx", //MCU used
			"interface": "swd",
			"serialNumber": "",        //Set ST-Link ID if you use multiple at the same time
			"runToEntryPoint": "main",
			"v1": false,				//Change it depending on ST Link version
			"svdFile": "${env:STM32CLT_PATH}/STMicroelectronics_CMSIS_SVD/STM32G071.svd",
			"serverpath": "${env:STM32CLT_PATH}/STLink-gdb-server/bin/ST-LINK_gdbserver",
			"stm32cubeprogrammer":"${env:STM32CLT_PATH}/STM32CubeProgrammer/bin",
			"stlinkPath": "${env:STM32CLT_PATH}/STLink-gdb-server/bin/ST-LINK_gdbserver",
			"armToolchainPath": "${env:STM32CLT_PATH}/GNU-tools-for-STM32/bin",
			"gdbPath":"${env:STM32CLT_PATH}/GNU-tools-for-STM32/bin/arm-none-eabi-gdb",
			"serverArgs": [
				"-m","0",
			],
			"showDevDebugOutput": "raw",
		}
	]
}

Attach text from Debug Console

Debug Console (postLaunchCommands empty)
Cortex-Debug: VSCode debugger extension version 1.12.1 git(652d042). Usage info: https://github.com/Marus/cortex-debug#usage
"configuration": {
    "name": "Build & Debug - ST-Link",
    "cwd": "C:\\Users\\pasca\\Music\\kontron_spitfair",
    "type": "cortex-debug",
    "executable": "C:/Users/pasca/Downloads/cmake_builds/kontron_spitfair/debug/src/spitfair.elf",
    "request": "launch",
    "servertype": "stlink",
    "device": "STM32G071RBTx",
    "interface": "swd",
    "runToEntryPoint": "main",
    "v1": false,
    "svdFile": "C:\\ST\\STM32CubeCLT_1.16.0/STMicroelectronics_CMSIS_SVD/STM32G071.svd",
    "serverpath": "C:\\ST\\STM32CubeCLT_1.16.0/STLink-gdb-server/bin/ST-LINK_gdbserver",
    "stm32cubeprogrammer": "C:\\ST\\STM32CubeCLT_1.16.0/STM32CubeProgrammer/bin",
    "stlinkPath": "C:\\ST\\STM32CubeCLT_1.16.0/STLink-gdb-server/bin/ST-LINK_gdbserver",
    "armToolchainPath": "C:\\ST\\STM32CubeCLT_1.16.0/GNU-tools-for-STM32/bin",
    "gdbPath": "C:\\ST\\STM32CubeCLT_1.16.0/GNU-tools-for-STM32/bin/arm-none-eabi-gdb",
    "showDevDebugOutput": "raw",
    "serverArgs": [
        "-m",
        "0"
    ],
    "postLaunchCommands": [],
    "__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": [],
    "preAttachCommands": [],
    "postAttachCommands": [],
    "preRestartCommands": [],
    "postRestartCommands": [],
    "preResetCommands": [],
    "postResetCommands": [],
    "toolchainPath": "C:\\ST\\STM32CubeCLT_1.16.0/GNU-tools-for-STM32/bin",
    "toolchainPrefix": "arm-none-eabi",
    "extensionPath": "c:/Users/pasca/.vscode/extensions/marus25.cortex-debug-1.12.1",
    "registerUseNaturalFormat": true,
    "variableUseNaturalFormat": false,
    "pvtVersion": "1.12.1",
    "__sessionId": "d4de9845-6425-4452-b01a-7dbd98b00054",
    "pvtShowDevDebugOutput": "raw"
}
Reading symbols from C:/ST/STM32CubeCLT_1.16.0/GNU-tools-for-STM32/bin/arm-none-eabi-objdump.exe --syms -C -h -w C:/Users/pasca/Downloads/cmake_builds/kontron_spitfair/debug/src/spitfair.elf
Reading symbols from c:/st/stm32cubeclt_1.16.0/gnu-tools-for-stm32/bin/arm-none-eabi-nm.exe --defined-only -S -l -C -p C:/Users/pasca/Downloads/cmake_builds/kontron_spitfair/debug/src/spitfair.elf
Launching GDB: "C:\\ST\\STM32CubeCLT_1.16.0/GNU-tools-for-STM32/bin/arm-none-eabi-gdb" -q --interpreter=mi2
1-gdb-version
Setting GDB-Server CWD: C:\ST\STM32CubeCLT_1.16.0/STLink-gdb-server/bin
Launching gdb-server: "C:\\ST\\STM32CubeCLT_1.16.0/STLink-gdb-server/bin/ST-LINK_gdbserver" -p 50000 -cp "C:\\ST\\STM32CubeCLT_1.16.0/STM32CubeProgrammer/bin" --swd --halt -m 0
    Please check TERMINAL tab (gdb-server) for output from C:\ST\STM32CubeCLT_1.16.0/STLink-gdb-server/bin/ST-LINK_gdbserver
Finished reading symbols from objdump: Time: 32 ms
Finished reading symbols from nm: Time: 36 ms
-> =thread-group-added,id="i1"
-> ~"GNU gdb (GNU Tools for STM32 12.3.rel1.20240612-1315) 13.2.90.20230627-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-w64-mingw32 --target=arm-none-eabi\".\n"
-> ~"Type \"show configuration\" for configuration details.\n"
-> ~"For bug reporting instructions, please see:\n"
-> ~"<https://www.gnu.org/software/gdb/bugs/>.\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 c:/Users/pasca/.vscode/extensions/marus25.cortex-debug-1.12.1/support/gdbsupport.init"
-> 6^done
7-interpreter-exec console "source c:/Users/pasca/.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 0x10"
-> ~"Output radix now set to decimal 16, hex 10, octal 20.\n"
Output radix now set to decimal 16, hex 10, octal 20.
-> =cmd-param-changed,param="output-radix",value="16"
-> 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 "C:/Users/pasca/Downloads/cmake_builds/kontron_spitfair/debug/src/spitfair.elf"
-> 10^done
11-target-select extended-remote localhost:50000
-> =thread-group-started,id="i1",pid="42000"
-> =thread-created,id="1",group-id="i1"
-> ~"Reset_Handler () at C:/Users/pasca/Music/kontron_spitfair/lib/stm32cubemx\\startup_stm32g071xx.s:60\n"
Reset_Handler () at C:/Users/pasca/Music/kontron_spitfair/lib/stm32cubemx\startup_stm32g071xx.s:60
-> ~"60\t  ldr   r0, =_estack\n"
60	  ldr   r0, =_estack
-> *stopped,frame={addr="0x08001198",func="Reset_Handler",args=[],file="C:/Users/pasca/Music/kontron_spitfair/lib/stm32cubemx\\startup_stm32g071xx.s",fullname="C:\\Users\\pasca\\Music\\kontron_spitfair\\lib\\stm32cubemx\\startup_stm32g071xx.s",line="60",arch="armv6s-m"},thread-id="1",stopped-threads="all",core="0"
mi2.status = stopped
Program stopped, probably due to a reset and/or halt issued by debugger
-> 11^connected
12-interpreter-exec console "monitor reset"
-> @"STM32 Successfully completed reset operation (System reset)\n"
STM32 Successfully completed reset operation (System reset)
-> 12^done
13-target-download
-> 13+download,{section=".isr_vector",section-size="188",total-size="511779"}
-> 13+download,{section=".isr_vector",section-sent="188",section-size="188",total-sent="188",total-size="511779"}
-> 13+download,{section=".text",section-size="4512",total-size="511779"}
-> 13+download,{section=".rodata",section-size="144",total-size="511779"}
-> 13+download,{section=".init_array",section-size="4",total-size="511779"}
-> 13+download,{section=".fini_array",section-size="4",total-size="511779"}
-> 13+download,{section=".data",section-size="4",total-size="511779"}
-> 13^done,address="0x08001198",load-size="4856",transfer-rate="88288",write-rate="809"
14-interpreter-exec console "monitor reset"
-> @"STM32 Successfully completed reset operation (System reset)\n"
STM32 Successfully completed reset operation (System reset)
-> 14^done
15-interpreter-exec console "monitor halt"
-> @"Trying to halt core...\n"
Trying to halt core...
-> 15^done
Returning dummy thread-id to workaround VSCode issue with pause button not working
Returning dummy stack frame to workaround VSCode issue with pause button not working: {"threadId":1,"startFrame":0,"levels":20}
16-break-insert -t --function main
-> ~"Note: automatically using hardware breakpoints for read-only addresses.\n"
Note: automatically using hardware breakpoints for read-only addresses.
-> 16^done,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0800024e",func="main()",file="/src/main.cpp",fullname="/src/main.cpp",line="4",thread-groups=["i1"],times="0",original-location="-function main"}
17-exec-continue --all
-> 17^running
-> *running,thread-id="all"
mi2.status = running
-> =breakpoint-modified,bkpt={number="1",type="breakpoint",disp="del",enabled="y",addr="0x0800024e",func="main()",file="/src/main.cpp",fullname="/src/main.cpp",line="4",thread-groups=["i1"],times="1",original-location="-function main"}
-> ~"\n"

-> ~"Temporary breakpoint 1, main () at /src/main.cpp:4\n"
Temporary breakpoint 1, main () at /src/main.cpp:4
-> &"4\t/src/main.cpp: No such file or directory.\n"
4	/src/main.cpp: No such file or directory.
-> *stopped,reason="breakpoint-hit",disp="del",bkptno="1",frame={addr="0x0800024e",func="main",args=[],file="/src/main.cpp",fullname="/src/main.cpp",line="4",arch="armv6s-m"},thread-id="1",stopped-threads="all",core="0"
mi2.status = stopped
-> =breakpoint-deleted,id="1"
18-thread-list-ids
-> 18^done,thread-ids={thread-id="1"},current-thread-id="1",number-of-threads="1"
19-thread-info 1
-> 19^done,threads=[{id="1",target-id="Thread 1",name="main",frame={level="0",addr="0x0800024e",func="main",args=[],file="/src/main.cpp",fullname="/src/main.cpp",line="4",arch="armv6s-m"},state="stopped",core="0"}]
20-stack-list-frames --thread 1 0 19
-> 20^done,stack=[frame={level="0",addr="0x0800024e",func="main",file="/src/main.cpp",fullname="/src/main.cpp",line="4",arch="armv6s-m"}]
21-stack-info-frame --thread 1 --frame 0
-> 21^done,frame={level="0",addr="0x0800024e",func="main",file="/src/main.cpp",fullname="/src/main.cpp",line="4",arch="armv6s-m"}
22-stack-list-variables --thread 1 --frame 0 --simple-values
-> 22^done,variables=[]

Additional context

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions