我正在尝试在Visual Studio Code中调试一个C程序。
在我的目录中,我有2个文件test.c和Makefile,以及包含launch和tasks json文件的.vscode文件夹。
我尝试配置这些文件已经三个小时了,在各种论坛和博客上搜索,但似乎没有什么起作用。
我可以使用这两个json文件编译和运行程序。
程序能够正确地运行并显示输出,但是不会在断点处停止,在程序执行期间我无法添加断点,并且已经添加的断点被禁用,并显示以下消息:
包含此断点的模块尚未加载,或者无法获取断点地址。
似乎VSCode在调试阶段无法找到我的test.c文件,即使它在同一个目录中。如果有人能向我展示正确的方法,那将是太好了。
这里,我附上了我文件夹中的内容。
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": [
{
"name": "gcc build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/test",
"args": [],
"stopAtEntry": true,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "tasks",
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "tasks",
"type": "shell",
"command": "make",
"group": {
"kind": "build",
"isDefault": true
}
}
]
}
Makefile
all:
gcc test.c -o ./test
test.c
#include<stdlib.h>
#include<stdio.h>
int main(){
printf("Mandar\n");
printf("Sadye\n");
return 0;
}
感谢您的选择。