【发布时间】:2022-01-02 09:02:49
【问题描述】:
我的目标是:我想进入 STL istream 的某行代码。所以我使用自定义构建的 "LIBC++13" 和 "Debug" 构建类型(我使用的命令显示在底部),所以(我认为)我可以得到一个完全可调试的 STL 版本,并且能够进入我想要的一切。但是我遇到了问题。
这是我对istream、BREAKPOINT A(Line 1447) 的断点设置并想进入Line 310:
// -*- C++ -*-
//===--------------------------- istream ----------------------------------===//
// ..................(other).....................
basic_istream<_CharT, _Traits>&
operator>>(basic_istream<_CharT, _Traits>& __is,
basic_string<_CharT, _Traits, _Allocator>& __str)
{
ios_base::iostate __state = ios_base::goodbit;
typename basic_istream<_CharT, _Traits>::sentry __sen(__is); // BREAKPOINT A (Line 1447)
if (__sen) // Line 1448
{
// ...
}
// ..................(other).....................
template <class _CharT, class _Traits>
basic_istream<_CharT, _Traits>::sentry::sentry(basic_istream<_CharT, _Traits>& __is,
bool __noskipws)
: __ok_(false)
{
if (__is.good()) // Want To Step Into Here (Line 310)
{
// ...
}
和程序:
#include <fstream>
#include <string>
using namespace std;
int main()
{
ifstream ifs{"testdata.txt"};
string tmp{};
ifs >> tmp;
}
我的问题是:使用 GDB,当我停在 “BREAKPOINT A” 时,我可以踏入 “Line 310”。但是对于 LLDB,当我停在 “BREAKPOINT A” 时,我无法 踏入 “Line 310”,而尝试踏入会导致执行停止在“Line 1448”,它只是跳过了“Line 310”。那是为什么?而且,无论是使用 LLDB 还是 GBD,我都无法在 “Line 310” 处显式设置断点。不知道我的情况发生了什么。
所以我的问题是:为什么 STL 中的某些代码行会被 LLDB 跳过/忽略? (就我而言,即第 310 行)
LIBC++13 是通过命令构建的:(使用Building Libcxx Guides 中的示例,/usr/local/myllvm 是我的安装位置)
cmake -G Ninja -S llvm -B build \
-DLLVM_ENABLE_PROJECTS="libcxx;libcxxabi" \
-DCMAKE_BUILD_TYPE="Debug" \
-DCMAKE_INSTALL_PREFIX="/usr/local/myllvm" \
-DCMAKE_CXX_COMPILER="clang++"
程序使用recommended 选项编译:
clang++ -nostdinc++ -nostdlib++ \
-isystem /usr/local/myllvm/include/c++/v1 \
-L /usr/local/myllvm/lib \
-Wl,-rpath,/usr/local/myllvm/lib \
-lc++ -g -O0 test1.cpp
【问题讨论】:
-
你想进入
good()函数吗?不了解 LLDB,但有些函数非常简单,以至于它们可能即使在调试模式下也会被内联。good()只是检查错误状态标志是否仍然为零,所以无论如何也没什么可看的。 -
@BoP 是的,但事实上我什至无法到达那条线,即将调用
good()的线。如果它们即使在调试模式下也是内联的,我们是否有一些方法来改变这种强制行为?
标签: c++ debugging gdb lldb libc++