#include #include #include using namespace lldb; using namespace std; const int BREAKPOINT_LINE = 5; bool breakpoint_callback (void *baton, SBProcess &process, SBThread &thread, SBBreakpointLocation &location); int main(int argc, char *argv[]) { SBDebugger::Initialize(); SBError error; SBDebugger debugger = SBDebugger::Create(false); if (!debugger.IsValid()) { cerr << "Error creating debugger." << endl; return 1; } SBTarget target ( debugger.CreateTarget("./debugee", "", "", true, error) ); if (!error.Success()) { cerr << "Error creating target: " << error.GetCString() << endl; return 1; } if (!target.IsValid()) { cerr << "Error: target invalid." << endl; return 1; } SBBreakpoint bp; bp = target.BreakpointCreateByLocation("debugee.cpp", BREAKPOINT_LINE); bp.SetCallback( breakpoint_callback, nullptr ); SBProcess process = target.LaunchSimple(nullptr, nullptr, nullptr); if (!process.IsValid()) { cerr << "Error: Invalid process." << endl; return 1; } SBListener listener = debugger.GetListener(); assert(listener.IsValid()); bool running = true; while (running) { SBEvent event; bool ok = listener.WaitForEvent(UINT32_MAX, event); if (!ok || !event.IsValid()) continue; const uint32_t event_type = event.GetType(); if (SBProcess::EventIsProcessEvent (event)) { if (event_type & SBProcess::eBroadcastBitStateChanged) { StateType event_state = SBProcess::GetStateFromEvent (event); switch (event_state) { case eStateExited: case eStateCrashed: running = false; break; default: break; } } } } return 0; } bool breakpoint_callback (void *baton, SBProcess &process, SBThread &thread, SBBreakpointLocation &location) { SBError error; SBFrame frame( thread.GetSelectedFrame() ); assert(frame.IsValid()); { SBValue foo_value = frame.FindVariable("foo"); foo_value.SetPreferSyntheticValue(true); int count = foo_value.GetNumChildren(); cout << "count = " << count << endl; count = 3; for (int i = 0; i < count; ++i) { SBError error; int x = 0; SBValue child = foo_value.GetChildAtIndex(i, eNoDynamicValues, false); if (child.IsValid()) { x = child.GetValueAsSigned(); } cout << "val = " << x << endl; } } return false; }