I am trying to explore the behaviour of a complex C++ application using Clang and LLDB. I have set a breakpoint in my applicaiton. Once I reach that breakpoint, I would like to create an instance of a simple C++ class and then call a method in the context of that breakpoint.
For example, here is my application:
#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;
}
Inside the breakpoint above, I would like to:
- Clear the
points
vector - Create a new
Point
instance - Add it to the vector
- Continue execution
This example is trivial, but often I have a considerably bigger application. Is this possible using expr
?
Update
I receive this error when trying to clear the points:
(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
I can create an object, which is good!
(lldb) expr auto $x = Point{1, 2}
(lldb) expr $x
(Point) $x = {
x = 1
y = 2
}
However, I cannot push it into my vector:
(lldb) expr points.push_back($x)
error: Couldn't lookup symbols:
__ZNSt3__16vectorI5PointNS_9allocatorIS1_EEE9push_backERKS1_