I am having difficulty debugging C code with vs-code. I previously had it working but maybe an update has killed it. I am at a loss for how to fix the issue and any guidance would be appreciated. The specific error I get when trying to start debugging is: "Unable to start debugging. Program path [${workspaceRoot}\Debug\bin\main.exe] is missing or invalid."
My folder is a simple helloworld program with a main.c and a makefile. Here is a snapshot of the folder:
helloworld.zip
I am trying to debug on a Windows 10 machine. I have MinGW and LLVM installed (because clang is awesome). MinGW is installed using the MinGW Installation Manager. mingw32-base is version 2013072200. msys-base is version 2013072300.
Running clang --version
in a PowerShell instance returns:
clang version 4.0.1 (tags/RELEASE_401/final)
Target: x86_64-pc-windows-msvc
Thread model: posix
InstalledDir: C:\llvm\bin
Here is the listing of the relevant files in the folder:
#include <stdio.h>
int main(void)
{
printf("Hello world!\n");
printf("Press enter to quit...\n");
getchar();
return 0;
}
SOURCES = main.c
.PHONY: debug
debug: Debug/bin/main.exe
Debug/bin/main.exe: $(SOURCES:%.c=Debug/obj/%.o)
clang -Wall $^ -o $@
Debug/obj/%.o: %.c | Debug
clang -c -g $< -MMD -MP -o $@ -Wall -pedantic -MF Debug/depends/$(@F:.o=.d)
main.o: main.c
Debug:
-mkdir Debug
-mkdir Debug/bin
-mkdir Debug/depends
-mkdir Debug/obj
clean:
rm -rf Debug
rm -rf Release
{
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/Debug/bin/main.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"miDebuggerPath": "C:/MinGW/bin/gdb.exe",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"taskName": "Build",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
},
"type": "shell"
}
]
}
@thndrwrks If the error message you entered is exactly what you get:
this tells me that the variable ${workspaceRoot}
is not specified correctly and hasn't been resolved. If you fix it, that should fix your problem.
from the looks of your copied launch.json
it seems correct so I don't know where that error message is coming from.
@thndrwrks Also, should clang compiled binaries be debuggable with MinGW gdb? You'll have to figure that out too.
@pieandcakes I've figured it out (partially). To answer your first question, the error message has ${workspaceRoot} correctly expanded. The error message is actually of the form C:\my\workspace\path\Debug\bin\main. The path is not the problem.
I was able to fix the error message by switching to mingw64:
"miDebuggerPath": "C:/mingw64/bin/gdb.exe",
I also switched compilers to gcc and I can now debug my program. Debugging programs compiled with clang in MinGW64 gdb doesn't appear to work at the moment (but the program launches successfully). At least I can debug with gcc.
Most helpful comment
@pieandcakes I've figured it out (partially). To answer your first question, the error message has ${workspaceRoot} correctly expanded. The error message is actually of the form C:\my\workspace\path\Debug\bin\main. The path is not the problem.
I was able to fix the error message by switching to mingw64:
"miDebuggerPath": "C:/mingw64/bin/gdb.exe",
I also switched compilers to gcc and I can now debug my program. Debugging programs compiled with clang in MinGW64 gdb doesn't appear to work at the moment (but the program launches successfully). At least I can debug with gcc.