【发布时间】:2019-01-05 18:36:26
【问题描述】:
我尝试在 Ubuntu 18.04.1 上使用 Visual Studio Code 1.30.1 中的调试功能作为调试扩展,我使用来自 ms-vscode.cpptools 的 C/C++ 0.20.1。 我用 gcc -Wall -g main.c -o main 编译了 main.c
这是main.c的代码
#include <stdio.h>
int main ()
{
printf("Hello World\n");
}
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": [
{
// for Linux
"name": "gdb C",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceRoot}/a.out",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": true,
"MIMode": "gdb",
//"preLaunchTask": "build cunit",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
当我启动调试器时,我得到了
Stopping due to fatal error: NullReferenceException: Object reference not set to an instance of an object
Visual Studio 代码版本:
版本:1.30.1 提交:dea8705087adb1b5e5ae1d9123278e178656186a 日期:2018-12-18T18:07:32.870Z 电子:2.0.12 铬:61.0.3163.100 Node.js:8.9.3 V8:6.1.534.41 操作系统:Linux x64 4.15.0-43-generic
tasks.json:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Build C",
"type": "shell",
"group": {
"kind": "build",
"isDefault": true
},
//"command":"gcc -g main.c -std=c11 -Werror -Wall -lm"
"command":"gcc -Wall -g main.c"
}
]
}
【问题讨论】:
-
是否已安装
gdb并且对程序可见? -
为什么要搞乱
json?你可以直接运行gdb -
为什么在 C 程序中使用
g++工具? -
是的。它已安装并且:gdb 已经是最新版本(8.1-0ubuntu3)。如何检查能见度?
-
如何检查可见性? 'cd' 到包含可执行文件的目录。然后输入
gdb如果gdb运行,那么它是可见的。
标签: c json ubuntu debugging visual-studio-code