16#include <lldb/API/LLDB.h>
27using pid_t = lldb::pid_t;
151 bool attachByName(
const std::string &process_name,
bool wait_for =
false);
222 [[nodiscard]]
const std::string &
lastError()
const;
232 [[nodiscard]] std::vector<ThreadInfo>
getThreads()
const;
263 [[nodiscard]] std::optional<FrameInfo>
getFrame(
uint32_t frame_index)
const;
276 [[nodiscard]] std::optional<VariableInfo>
readVariable(
const std::string &name,
uint32_t frame_index = 0,
287 [[nodiscard]] std::vector<VariableInfo>
listVariables(
uint32_t frame_index = 0,
bool include_args =
true,
288 bool include_locals =
true,
bool include_statics =
false)
const;
321 [[nodiscard]] std::optional<BreakpointInfo>
getBreakpoint(int32_t breakpoint_id)
const;
340 [[nodiscard]] std::optional<VariableInfo>
evaluateExpression(
const std::string &expression,
345 mutable lldb::SBDebugger debugger_;
346 mutable lldb::SBTarget target_;
347 mutable lldb::SBProcess process_;
348 mutable lldb::SBListener listener_;
351 bool initialized_ =
false;
352 mutable std::string last_error_;
355 void setError(
const std::string &msg)
const;
356 void clearError()
const;
359 void syncProcessState()
const;
362 bool waitForState(lldb::StateType target_state,
uint32_t timeout_sec = 5)
const;
364 [[nodiscard]] lldb::SBThread getSelectedThreadInternal()
const;
365 [[nodiscard]] lldb::SBFrame getFrameInternal(
uint32_t index)
const;
368 [[nodiscard]]
static ThreadInfo threadToInfo(lldb::SBThread &thread,
bool is_selected);
369 [[nodiscard]]
static FrameInfo frameToInfo(lldb::SBFrame &frame);
371 [[nodiscard]]
static BreakpointInfo breakpointToInfo(lldb::SBBreakpoint bp);
int32_t setBreakpoint(const std::string &file, uint32_t line, const std::string &condition="")
Set a breakpoint at file:line.
std::optional< VariableInfo > evaluateExpression(const std::string &expression, uint32_t frame_index=0) const
Evaluate an expression in the current context.
bool attachByName(const std::string &process_name, bool wait_for=false)
Attach to a process by name.
bool removeBreakpoint(int32_t breakpoint_id)
Remove a breakpoint.
bool stepInto()
Single step the current thread (step into)
pid_t targetPid() const
Get the PID of the attached process.
LLDBController & operator=(LLDBController &&)=delete
std::string targetName() const
Get the name of the attached process.
bool selectThread(uint64_t thread_id)
Select a thread by ID.
std::optional< VariableInfo > readVariable(const std::string &name, uint32_t frame_index=0, uint32_t expand_depth=0) const
Read a variable from the current frame.
const std::string & lastError() const
Get the last error message.
std::vector< VariableInfo > listVariables(uint32_t frame_index=0, bool include_args=true, bool include_locals=true, bool include_statics=false) const
List all variables in scope at a frame.
bool initialize()
Initialize LLDB. Must be called before any other methods.
void shutdown()
Shutdown LLDB and release resources.
LLDBController(LLDBController &&)=delete
bool stop()
Stop the target process.
bool isAttached() const
Check if attached to a process.
LLDBController & operator=(const LLDBController &)=delete
LLDBController(const LLDBController &)=delete
std::vector< ThreadInfo > getThreads() const
Get list of all threads.
std::optional< FrameInfo > getFrame(uint32_t frame_index) const
Get a specific frame by index.
std::vector< BreakpointInfo > getBreakpoints() const
Get all breakpoints.
bool resume()
Resume the target process.
std::vector< FrameInfo > getFrames(uint32_t max_frames=0) const
Get stack frames for the selected thread.
bool stepOver()
Step over the current line.
std::optional< BreakpointInfo > getBreakpoint(int32_t breakpoint_id) const
Get information about a specific breakpoint.
bool stepOut()
Step out of the current function.
void detach()
Detach from the current process.
bool attach(pid_t pid)
Attach to a process by PID.
ProcessState state() const
Get the current process state.
std::optional< ThreadInfo > getSelectedThread() const
Get the currently selected thread.
bool waitForBreakpoint(uint32_t timeout_ms=0)
Wait for any breakpoint to be hit.
unsigned long long uint64_t
ProcessState
Process state enumeration.
@ Exited
Process has exited.
@ Crashed
Process crashed.
@ Detached
Detached from process.
@ Invalid
No valid process attached.
@ Running
Process is running normally.
@ Stopped
Process is stopped (breakpoint, signal, etc.)
int32_t id
LLDB breakpoint ID.
std::string condition
Condition expression (may be empty)
bool enabled
Is breakpoint enabled?
uint32_t line
Line number.
bool resolved
Is breakpoint resolved (has valid location)?
uint32_t hit_count
Number of times hit.
std::string file
Source file.
uint32_t line
Line number.
std::string function
Function name.
uint64_t pc
Program counter.
uint64_t fp
Frame pointer.
uint32_t index
Frame index (0 = innermost)
std::string file
Source file.
std::string name
Thread name (may be empty)
uint32_t line
Current line number.
bool is_selected
Is this the selected thread?
std::string stop_reason
Why thread is stopped (if stopped)
std::string function
Current function name.
uint32_t index
Index in thread list.
std::string file
Current source file.
Variable information (from LLDB SBValue)
std::vector< VariableInfo > children
Struct members / array elements.
std::string value
Value as string.
bool is_aggregate
Whether this is struct/class/array.
size_t size
Size in bytes.
std::string type
Type name.
std::string name
Variable name.
bool is_pointer
Whether this is a pointer type.
std::string summary
LLDB summary (for complex types)
bool is_valid
Whether value could be read.
uint64_t address
Memory address.