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.
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.