VS代码不会在Mac上的任何断点处停止
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了VS代码不会在Mac上的任何断点处停止相关的知识,希望对你有一定的参考价值。
我正在尝试在VS Code中测试调试器,我相信我已经正确配置了launch.json和tasks.json,但是调试器并没有在我的断点处停止。
我尝试重新安装VS代码,重新配置,尝试使用其他源文件。。但是我无法运行此调试器。我是一个初学者,因此很可能是我所缺少的东西。
我希望调试器在第8行停止。
writeassignment.cpp
#include <iostream>
using namespace std;
int main(int argc, char ** argv)
int array [9] = -10, -7, -1, 0, 4, 7, 8, 12, 19;
int i, j, sum = 4;
for (i = 0; i <= 8; i++)
for (j = i + 1; j <= 8; j++)
int a = array[i];
int b = array[j];
cout << "a: " << a << " b: " << b << " i: " << i << " j: " << j << endl;
if (a + b == sum)
cout << a << " + " << b << " = " << sum << endl;
//exit;
return -1;
tasks.json
"version": "2.0.0",
"tasks": [
"type": "shell",
"label": "g++ build active file",
"command": "/usr/bin/g++",
"args": [
"-g",
"$file",
"-o",
"$fileDirname/$fileBasenameNoExtension"
],
"options":
"cwd": "/usr/bin"
,
"problemMatcher": [
"$gcc"
],
"group":
"kind": "build",
"isDefault": true
]
launch.json
"version": "0.2.0",
"configurations": [
"name": "(lldb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "$workspaceFolder/writtenassignment",
"args": [],
"stopAtEntry": true,
"cwd": "$workspaceFolder",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
]
AFAIK,只有在构建可执行文件时未添加-g
编译器标志的情况下,断点才起作用或不被触发。
我从您的launch.json中注意到,您没有调用task.json中设置的构建任务。通常,您在启动配置中指定一个preLaunchTask
,它会在运行之前从task.json调用构建任务来重建可执行文件。
我认为发生的事情是,在[[没有-g
之前已经编译了[[书面分配,然后再次启动它时,并没有使用-g
对其进行重建。
tasks.json
"type": "shell",
"label": "build-writtenassignment",
"command": "/usr/bin/g++",
"args": [
"-g",
"$workspaceFolder/writtenassignment.cpp",
"-o",
"$workspaceFolder/writtenassignment"
],
"options":
"cwd": "/usr/bin"
,
"problemMatcher": [
"$gcc"
],
"group":
"kind": "build",
"isDefault": true
launch.json
"name": "run-writtenassignment",
"type": "cppdbg",
"request": "launch",
"preLaunchTask": "build-writtenassignment", # <--------- ADDED
"program": "$workspaceFolder/writtenassignment",
"args": [],
"stopAtEntry": true,
"cwd": "$workspaceFolder",
"environment": [],
"externalConsole": false,
"MIMode": "lldb"
我添加了一个preLaunchTask
来调用tasks.json
中的构建任务(我重命名了每个配置,以使其更易于引用)。我还明确指定了文件
writeedassignment.cpp和输出writingassignment
而不是$file
。然后只需从“调试”面板运行它即可。以上是关于VS代码不会在Mac上的任何断点处停止的主要内容,如果未能解决你的问题,请参考以下文章