【问题标题】:Visual Studio Code Hello World in C Debug Function is not working Programm NullReferenceException:C 调试函数中的 Visual Studio Code Hello World 无法正常工作 Programm NullReferenceException:
【发布时间】: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


【解决方案1】:

在我拥有的版本中看起来是软件中的一个错误。您可以设置 "externalConsole": false 并且调试功能正在运行(这是一种解决方法)。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-07-31
    • 1970-01-01
    • 1970-01-01
    • 2022-12-14
    • 1970-01-01
    相关资源
    最近更新 更多