英文:
VS Code C++/Cmake project, debugging info and breakpoints not working
问题
I have translated the provided text, removing any code parts as you requested:
我有一个在C++项目中编写的简单的Hello World代码。我已经配置了CMake文件如下:
这是我的launch.json文件:
程序可以正常运行。它接受我的输入然后退出。然而,程序没有显示任何信息,也没有在我的断点处停止。
这是main.cpp文件:
announcable和announcer类只是用来测试链接并打印一些内容。
我在M1 Mac Air上运行MacOS。
我希望能看到关于我的变量和调用栈的常规信息,我期望程序会在断点处停止。
英文:
I have a simple hello world code written in c++ in a porject. I have configured the CMake file as the following:
cmake_minimum_required(VERSION 3.1)
project(test_project VERSION 1.0
DESCRIPTION "testing cmake"
LANGUAGES CXX)
add_library(announcable STATIC Libs/announcable.cpp Libs/announcable.h)
add_library(announcer STATIC Libs/announcer.cpp Libs/announcer.h)
target_include_directories(announcable PUBLIC include)
target_include_directories(announcer PUBLIC include)
add_executable(app main.cpp)
target_link_libraries(app PUBLIC announcable)
target_link_libraries(app PUBLIC announcer)`
this is my launch.json
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
// Resolved by CMake Tools:
"program": "${command:cmake.launchTargetPath}",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [
{
// add the directory where our target was built to the PATHs
// it gets resolved by CMake Tools:
"name": "PATH",
"value": "$PATH:${command:cmake.launchTargetDirectory}"
},
{
"name": "OTHER_VALUE",
"value": "Something something"
}
],
"externalConsole": true,
"MIMode": "lldb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
}
]
}
the program runs fine. It takes my input and quits. However, the program doesn't show any information and doesn't stop at my breakpoints.
this is the main.cpp file
#include <iostream>
#include "Libs/announcer.h"
#include "Libs/announcable.h"
int main(int argc, char* argv[]) {
std::cout << "I'm a bunny girl\n";
Announcable announcbl("merrrowwww");
Announcer announcr(&announcbl);
announcr.announce();
std::string test;
std::cin >> test;
return 0;
}
the announcable and announcer classes are just to test linking and only print something.
I'm running on MacOS on an M1 Mac Air
I was hoping to see the usual info on my variables and call stack and I was expecting the program to stop at the breakpoint.
答案1
得分: 0
我终于成功让我的调试器工作,并且在广泛阅读文档后修复了我代码中的内存泄漏问题。
这只是我的配置,你应该更改相关部分以适应你的系统和需求。
首先,我创建了 c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
这是我的 launch.json 文件,请将 "program" 参数更改为你的可执行文件:
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
"targetArchitecture": "arm64",
"program": "${workspaceFolder}/build/Bunget",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
}
]
}
我还将以下内容添加到我的 settings.json
{
"cmake.debugConfig": {
"type": "lldb"
}
}
希望这个答案能帮助将来有人解决与调试器相同的冻结或内存泄漏问题。
英文:
I finally managed to get my debugger working and fix a memory leak problem that I had with my code after extensively reading the documentation
this is simply my configuration, you should change the relevant portions to match your system and needs.
firstly I created the c_cpp_properties.json
{
"configurations": [
{
"name": "Mac",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"macFrameworkPath": [
"/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/System/Library/Frameworks"
],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "macos-clang-arm64",
"configurationProvider": "ms-vscode.cmake-tools"
}
],
"version": 4
}
this is my launch.json file, change the "program" argument to your executable:
{
"version": "0.2.0",
"configurations": [
{
"name": "(lldb) Launch",
"type": "lldb",
"request": "launch",
"targetArchitecture": "arm64",
"program": "${workspaceFolder}/build/Bunget",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "lldb",
}
]
}
I also added this to my settings.json
{
"cmake.debugConfig": {
"type": "lldb"
},
I hope that this answer may help someone in the future struggling with the same debugging freezing and or memory leak issues with the debugger.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论