如何在C语言的macO上的Visual Studio Code中启动调试?

问题描述 投票:0回答:2

我有一个简单的项目,只有一个main.c文件和info.h文件。我正在使用makefile进行构建

myprog1 : main.o
    gcc -g main.o -Wall -ansi -pedantic -o myprog1
main.o : main.c info.h
    gcc -c main.c -Wall -ansi -pedantic -o main.o

我单击Debug -> Start debugging -> C++ (GDB/LLDB),然后生成文件(我编辑了编名称,添加了-g标志,stopAtEntry = true)

{
    // 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": "(lldb) Launch",
            "type": "cppdbg",
            "request": "launch",
            "program": "${workspaceFolder}/myprog1",
            "args": [
               "-g"
            ],
            "stopAtEntry": true,
            "cwd": "${workspaceFolder}",
            "environment": [],
            "externalConsole": false,
            "MIMode": "lldb"
        }
    ]
}

当我单击Run Debug时,它只会忽略带有消息的调试点

包含此断点的模块尚未加载或无法获得断点地址

我已经阅读了很多可能的问题,但是对我有帮助...

我在做什么错?

c debugging visual-studio-code
2个回答
0
投票

首先,它是C程序,而不是C ++程序,因此使用错误的调试器。 C ++调试器期望“名称修改”,但GCC不会执行“名称修改”]


0
投票

要注意的一件事是,您正在-g标志以及通过编译器传递-g标志。 IIRC,LLDB没有-g选项,因此最有可能出现问题。除非在“ info.h”中未外部定义任何声明,否则makefile可能会出现问题,尽管您可能无法编译适当的可执行文件,但makefile并不包含所有必需的目标文件(我之所以提及此原因仅是因为您可以即使vscode中的任务返回错误,仍然可以继续进行调试。

旁注:尽管LLDB应该能够调试GCC编译的代码,但我还是建议您使用Clang来编译代码,因为它也是LLVM工具链的一部分。有关此内容的更多信息:Is it possible to debug a gcc-compiled program using lldb, or debug a clang-compiled program using gdb?

© www.soinside.com 2019 - 2024. All rights reserved.