【发布时间】:2017-03-09 23:33:54
【问题描述】:
我正在尝试使用 Clang 和 LLDB 探索复杂 C++ 应用程序的行为。我在我的应用程序中设置了一个断点。到达该断点后,我想创建一个简单 C++ 类的实例,然后在该断点的上下文中调用方法。
例如,这是我的应用程序:
#include <iostream>
#include <vector>
struct Point {
int x;
int y;
};
int main() {
std::vector<Point> points;
points.push_back(Point{3, 4});
// <--------- Breakpoint here
int total = 0;
for (const auto& p : points) {
total += p.x * p.y;
}
std::cout << "Total: " << total << std::endl;
return 0;
}
在上面的断点内,我想:
- 清除
points向量 - 创建一个新的
Point实例 - 将其添加到向量中
- 继续执行
这个例子很简单,但我经常有一个更大的应用程序。这可以使用expr 吗?
更新
我在尝试清除积分时收到此错误:
(lldb) expr points.clear()
warning: could not load any Objective-C class information. This will significantly reduce the quality of type information available.
error: Couldn't lookup symbols:
__ZNSt3__16vectorI5PointNS_9allocatorIS1_EEE5clearEv
我可以创建一个对象,这很好!
(lldb) expr auto $x = Point{1, 2}
(lldb) expr $x
(Point) $x = {
x = 1
y = 2
}
但是,我无法将它推入我的向量中:
(lldb) expr points.push_back($x)
error: Couldn't lookup symbols:
__ZNSt3__16vectorI5PointNS_9allocatorIS1_EEE9push_backERKS1_
【问题讨论】: