【发布时间】:2017-05-31 05:37:40
【问题描述】:
我的操作系统版本是 sierra 10.12.1,vs 代码版本是 1.8.1。我在 vs 代码中安装了 c++ 插件。然后我创建了一个 c++ 项目。 有我的 c++ 源文件。
my_simple.cc
int main(int argc, char const *argv[])
{
printf("%s\n", "******begin******");
int a = 1;
int b = a;
printf("%s\n", "******end******");
return 0;
}
launch.json
{
"version": "0.2.0",
"configurations": [
{
"preLaunchTask": "pre_compile",
"showDisplayString": true,
"name": "my_debug",
"type": "cppdbg",
"request": "launch",
"program": "${file}.o",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceRoot}",
"environment": [],
"externalConsole": false,
"osx": {
"MIMode": "lldb"
}
}
]
}
tasks.json
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "0.1.0",
"command": "g++",
"isShellCommand": true,
"args": [
],
"showOutput": "always",
"echoCommand": true,
"suppressTaskName": true,
"tasks": [
{
"taskName": "pre_compile",
"args": [
"${file}",
"-o${file}.o"
],
"isBuildCommand": true
}
]
}
当我向 my_simple.cc 添加一些断点然后按 f5 编译并运行它时。断点没有按预期工作。请帮我找出我的代码中的错误。谢谢
【问题讨论】:
-
你在哪里设置断点?编译器可能正在优化不存在的变量(您从不使用它们)。
-
请注意,编译器可以将您的函数优化为:
int main(int argc, char const *argv[]) { fputs("******begin******\n******end******\n",stdout); return 0 }- 但这种攻击程度是不寻常的。 -
我尝试添加'printf("%i\n", b);',然后设置断点。但是断点还是不行。
标签: c++ macos debugging visual-studio-code