我在Ubuntu上使用VSCode,调试使用gdb,以下是我要翻译的代码(Main.cpp
):
#include <iostream>
#include <string>
std::string return_string(){//Line 4
std::string abc = "abc";
return(abc);
}
int main(){//Line 9
std::string abc = return_string();//Line 10
std::cout<<abc<<std::endl;//Line 11
return 0;
}
在第10行设置断点,按F10以便进入第11行,但实际上却进入了
basic_string.h
文件。该文件是C++文件,不属于我的项目。有没有办法不进入这些本地的C/C++文件呢?我查看了以下内容:
How to prevent GDB from stepping into every single function
但它似乎只涉及使用gdb原始代码的情况,并建议在gdb中指定skip
命令(https://sourceware.org/gdb/onlinedocs/gdb/Skipping-Over-Functions-and-Files.html)。然而,我通过VSCode界面运行调试器,它提供了一种封装层,使用户不必使用原始的gdb命令-- F10
为跳过,F11
为步入等。是否有一种方法可以在编译和链接代码时就防止某些文件被调试时进入呢?目前,我的makefile发出以下命令进行编译和链接:
(compiling) g++ -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp -c -g -std=c++14 -MMD -MP -MF "build/Debug/GNU-Linux/_ext/1/Main.o.d" -o build/Debug/GNU-Linux/_ext/1/Main.o ../src/Main.cpp
(linking) g++ -fno-common -fPIC -fno-strict-aliasing -fexceptions -fopenmp -o dist/Debug/GNU-Linux/linux build/Debug/GNU-Linux/_ext/1/Main.o -lm -lpthread -ldl
basic_string.h
,这是否符合预期?能避免这种情况发生吗? - Tryerstd::make_unique
和std::function
。 - alter_igel