在LLDB中,我可以调用方法并创建c++类的实例吗?
In LLDB, can I call methods and make instances of C++ classes?
我正在尝试探索使用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_
可以在调试器中创建对象。告诉调试器您希望在表达式解析器中创建持久对象的技巧是,在创建或引用它时给它一个以"$"开头的名称。然后lldb将确保该对象继续存在。
但是,请注意: 中提到的使用STL类时的注意事项使用XCode/LLDB打印/调试libc++ STL
相关文章:
- 从C++实例化QML
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- OpenGL - 在抛出"__gnu_cxx::recursive_init_error"实例后终止调用?
- 如何在c++中为模板函数实例创建快捷方式
- 在C++中,是否可以基于给定的标识符创建基类的新实例,反之亦然
- 设计一个只能由特定类实例化的类(如果可能的话,通过make_unique)
- 如何创建一个空的全局类并在启动时实例化它
- 无法创建抽象类的实例
- 多个文件的内存分配错误"在抛出 'std :: bad_alloc' what (): std :: bad_alloc 的实例后终止调用" [C++]
- 在两个类中共享相同的函数调用,并在不需要时避免空实例化
- 我收到以下错误:抛出'std::bad_alloc'实例后终止调用
- 建议在运行时将带有类实例的列表从c++导入qml
- 约束和显式模板实例化
- 通过实例理解std::move及其目的
- 为什么包含windows.h会产生语法错误,从而阻止类的实例化?(C2146,C2065)
- 有没有一种"cleaner"的方法可以在指向基的指针向量中找到派生类的第一个实例?
- 正在生成未知类实例
- 从DLL中删除类的实例
- 在std::vector上存储带有模板的类实例
- 为什么创建友元类的实例会导致"undefined reference to"错误?