C++ 调试器不';t在断点处停止-使用c++;和vscode
我正在调试一些C++代码。调试器不会在我设置的断点处停止 我在Ubuntu20上使用vscode 断点是空的,悬停时会显示: “包含此断点的模块尚未加载或无法获取断点地址。” 我的生成文件:C++ 调试器不';t在断点处停止-使用c++;和vscode,c++,visual-studio-code,C++,Visual Studio Code,我正在调试一些C++代码。调试器不会在我设置的断点处停止 我在Ubuntu20上使用vscode 断点是空的,悬停时会显示: “包含此断点的模块尚未加载或无法获取断点地址。” 我的生成文件: CXX = g++ CXX_FLAGS = -g -Wall -std=c++17 O_FILES = main.o \ cache.o TARGET = main all: $(TARGET) $(TARGET): $(O_FILES)
CXX = g++
CXX_FLAGS = -g -Wall -std=c++17
O_FILES = main.o \
cache.o
TARGET = main
all: $(TARGET)
$(TARGET): $(O_FILES)
$(CXX) $(CXX_FLAGS) $(O_FILES) -o $@
.phony: clean
clean:
rm -f *~ *.o $(TARGET)
#dependencies
cache.o: cache.cc cache.hh
tasks.json
我尝试使用g++而不是设置适当的标志,这导致了错误
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++ build active file",
"command": "make",
"args": [
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
launch.json
{
// 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": "g++ - Build and debug active file",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}/main",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"miDebuggerPath": "/usr/bin/gdb"
}
]
}
主要内容:
我的任务或启动文件有问题吗?请不要发布文本添加代码的屏幕截图而不是图像显示您是否生成了
$(O_文件)
?默认情况下制定规则?您确定它们是使用正确的标志正确生成的吗?最好将显式规则添加到build.o from.cpp中。我添加了make的输出和项目目录,它们应该显示正确的对象文件。正如我所说,您的标志都是错误的g++-c-o cache.o cache.cc
——没有-g
标志,因此没有调试信息,也没有-std=c++17
标志。请不要发布文本添加代码的屏幕截图而不是图像显示您是否生成了$(o_文件)
?默认情况下制定规则?您确定它们是使用正确的标志正确生成的吗?最好将显式规则添加到build.o from.cpp中。我添加了make的输出和项目目录,它们应该显示正确的对象文件。正如我所说,您的标志都是错误的g++-c-o cache.o cache.cc
——没有-g
标志,因此没有调试信息,也没有-std=c++17
标志。
#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
#include "cache.hh"
using namespace std;
int main(int argc, char** argv) {
Cache direct_mapped(8, 1);
int a;
cout << direct_mapped.getCacheSize() << endl;
direct_mapped.updateCacheBlock(1, 5, 31);
direct_mapped.printCache(1);
cin >> a;
return 0;
}
g++ -c -o main.o main.cc
g++ -c -o cache.o cache.cc
g++ -g -Wall -std=c++17 main.o cache.o -o main