ascii-chat
Binary v0.16.50-198-g78f51665f
Library lib/v0.3.2-2240-g78f51665f
Video chat in your terminal
Loading...
Searching...
No Matches
ascii_query::LLDBController Class Reference

LLDB process controller. More...

#include <src/tooling/query/lldb_controller.h>

Public Member Functions

 LLDBController ()
 ~LLDBController ()
 LLDBController (const LLDBController &)=delete
LLDBController & operator= (const LLDBController &)=delete
 LLDBController (LLDBController &&)=delete
LLDBController & operator= (LLDBController &&)=delete
bool initialize ()
 Initialize LLDB. Must be called before any other methods.
void shutdown ()
 Shutdown LLDB and release resources.
bool attach (pid_t pid)
 Attach to a process by PID.
bool attachByName (const std::string &process_name, bool wait_for=false)
 Attach to a process by name.
void detach ()
 Detach from the current process.
bool isAttached () const
 Check if attached to a process.
pid_t targetPid () const
 Get the PID of the attached process.
std::string targetName () const
 Get the name of the attached process.
bool stop ()
 Stop the target process.
bool resume ()
 Resume the target process.
bool stepInto ()
 Single step the current thread (step into).
bool stepOver ()
 Step over the current line.
bool stepOut ()
 Step out of the current function.
ProcessState state () const
 Get the current process state.
const std::string & lastError () const
 Get the last error message.
std::vector< ThreadInfo > getThreads () const
 Get list of all threads.
std::optional< ThreadInfo > getSelectedThread () const
 Get the currently selected thread.
bool selectThread (uint64_t thread_id)
 Select a thread by ID.
std::vector< FrameInfo > getFrames (uint32_t max_frames=0) const
 Get stack frames for the selected thread.
std::optional< FrameInfo > getFrame (uint32_t frame_index) const
 Get a specific frame by index.
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.
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.
int32_t setBreakpoint (const std::string &file, uint32_t line, const std::string &condition="")
 Set a breakpoint at file:line.
bool removeBreakpoint (int32_t breakpoint_id)
 Remove a breakpoint.
std::vector< BreakpointInfo > getBreakpoints () const
 Get all breakpoints.
std::optional< BreakpointInfo > getBreakpoint (int32_t breakpoint_id) const
 Get information about a specific breakpoint.
bool waitForBreakpoint (uint32_t timeout_ms=0)
 Wait for any breakpoint to be hit.
std::optional< VariableInfo > evaluateExpression (const std::string &expression, uint32_t frame_index=0) const
 Evaluate an expression in the current context.

Detailed Description

LLDB process controller.

Wraps LLDB's SB API to provide process attachment, breakpoint management, and variable inspection for the query tool.

Definition at line 114 of file lldb_controller.h.

Constructor & Destructor Documentation

◆ LLDBController() [1/3]

ascii_query::LLDBController::LLDBController ( )
default

◆ ~LLDBController()

ascii_query::LLDBController::~LLDBController ( )

Definition at line 39 of file lldb_controller.cpp.

39 {
40 shutdown();
41}
void shutdown()
Shutdown LLDB and release resources.

References shutdown().

◆ LLDBController() [2/3]

ascii_query::LLDBController::LLDBController ( const LLDBController & )
delete

References LLDBController().

◆ LLDBController() [3/3]

ascii_query::LLDBController::LLDBController ( LLDBController && )
delete

References LLDBController().

Member Function Documentation

◆ attach()

bool ascii_query::LLDBController::attach ( pid_t pid)

Attach to a process by PID.

Parameters
pidProcess ID to attach to
Returns
true on success, false on failure

On success, the target process is stopped.

Definition at line 108 of file lldb_controller.cpp.

108 {
109 if (!initialized_) {
110 setError("LLDB not initialized");
111 return false;
112 }
113
114 // Create an empty target - LLDB will fill it in when we attach
115 lldb::SBError error;
116 target_ = debugger_.CreateTarget("", "", "", false, error);
117 if (!target_.IsValid()) {
118 setError("Failed to create target: " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
119 return false;
120 }
121
122 // Attach to process
123 lldb::SBAttachInfo attach_info(pid);
124 attach_info.SetListener(listener_);
125
126 process_ = target_.Attach(attach_info, error);
127 if (!process_.IsValid() || error.Fail()) {
128 setError("Failed to attach to PID " + std::to_string(pid) + ": " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
129 debugger_.DeleteTarget(target_);
130 return false;
131 }
132
133 clearError();
134 return true;
135}

Referenced by main().

◆ attachByName()

bool ascii_query::LLDBController::attachByName ( const std::string & process_name,
bool wait_for = false )

Attach to a process by name.

Parameters
process_nameName of process to attach to
wait_forIf true, wait for process to start
Returns
true on success, false on failure

Definition at line 137 of file lldb_controller.cpp.

137 {
138 if (!initialized_) {
139 setError("LLDB not initialized");
140 return false;
141 }
142
143 // Create an empty target
144 lldb::SBError error;
145 target_ = debugger_.CreateTarget("", "", "", false, error);
146 if (!target_.IsValid()) {
147 setError("Failed to create target: " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
148 return false;
149 }
150
151 // Attach by name
152 lldb::SBAttachInfo attach_info;
153 attach_info.SetExecutable(process_name.c_str());
154 attach_info.SetWaitForLaunch(wait_for, false); // false = don't async
155 attach_info.SetListener(listener_);
156
157 process_ = target_.Attach(attach_info, error);
158 if (!process_.IsValid() || error.Fail()) {
159 setError("Failed to attach to process '" + process_name + "': " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
160 debugger_.DeleteTarget(target_);
161 return false;
162 }
163
164 clearError();
165 return true;
166}

Referenced by main().

◆ detach()

void ascii_query::LLDBController::detach ( )

Detach from the current process.

The target process continues running after detach.

Definition at line 168 of file lldb_controller.cpp.

168 {
169 if (!isAttached()) {
170 return;
171 }
172
173 lldb::SBError error = process_.Detach();
174 if (error.Fail()) {
175 setError("Detach failed: " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
176 } else {
177 clearError();
178 }
179}
bool isAttached() const
Check if attached to a process.

References isAttached().

Referenced by main(), and shutdown().

◆ evaluateExpression()

std::optional< VariableInfo > ascii_query::LLDBController::evaluateExpression ( const std::string & expression,
uint32_t frame_index = 0 ) const
nodiscard

Evaluate an expression in the current context.

Parameters
expressionExpression to evaluate
frame_indexWhich frame context (0 = current)
Returns
VariableInfo with result, or nullopt on failure

Definition at line 613 of file lldb_controller.cpp.

613 {
614 lldb::SBFrame frame = getFrameInternal(frame_index);
615 if (!frame.IsValid()) {
616 return std::nullopt;
617 }
618
619 lldb::SBExpressionOptions options;
620 options.SetIgnoreBreakpoints(true);
621 options.SetFetchDynamicValue(lldb::eDynamicDontRunTarget);
622
623 lldb::SBValue result = frame.EvaluateExpression(expression.c_str(), options);
624 if (!result.IsValid()) {
625 return std::nullopt;
626 }
627
628 lldb::SBError error = result.GetError();
629 if (error.Fail()) {
630 return std::nullopt;
631 }
632
633 return valueToInfo(result, 0);
634}

◆ getBreakpoint()

std::optional< BreakpointInfo > ascii_query::LLDBController::getBreakpoint ( int32_t breakpoint_id) const
nodiscard

Get information about a specific breakpoint.

Parameters
breakpoint_idBreakpoint ID
Returns
BreakpointInfo or nullopt if not found

Definition at line 561 of file lldb_controller.cpp.

561 {
562 if (!target_.IsValid()) {
563 return std::nullopt;
564 }
565
566 lldb::SBBreakpoint bp = target_.FindBreakpointByID(static_cast<lldb::break_id_t>(breakpoint_id));
567 if (!bp.IsValid()) {
568 return std::nullopt;
569 }
570
571 return breakpointToInfo(bp);
572}

◆ getBreakpoints()

std::vector< BreakpointInfo > ascii_query::LLDBController::getBreakpoints ( ) const
nodiscard

Get all breakpoints.

Returns
Vector of BreakpointInfo structs

Definition at line 541 of file lldb_controller.cpp.

541 {
542 std::vector<BreakpointInfo> result;
543
544 if (!target_.IsValid()) {
545 return result;
546 }
547
548 uint32_t num_breakpoints = target_.GetNumBreakpoints();
549 result.reserve(num_breakpoints);
550
551 for (uint32_t i = 0; i < num_breakpoints; i++) {
552 lldb::SBBreakpoint bp = target_.GetBreakpointAtIndex(i);
553 if (bp.IsValid()) {
554 result.push_back(breakpointToInfo(bp));
555 }
556 }
557
558 return result;
559}
unsigned int uint32_t

◆ getFrame()

std::optional< FrameInfo > ascii_query::LLDBController::getFrame ( uint32_t frame_index) const
nodiscard

Get a specific frame by index.

Parameters
frame_indexFrame index (0 = innermost)
Returns
FrameInfo or nullopt if index out of range

Definition at line 436 of file lldb_controller.cpp.

436 {
437 lldb::SBFrame frame = getFrameInternal(frame_index);
438 if (!frame.IsValid()) {
439 return std::nullopt;
440 }
441 return frameToInfo(frame);
442}

◆ getFrames()

std::vector< FrameInfo > ascii_query::LLDBController::getFrames ( uint32_t max_frames = 0) const
nodiscard

Get stack frames for the selected thread.

Parameters
max_framesMaximum number of frames to return (0 = all)
Returns
Vector of FrameInfo structs

Definition at line 412 of file lldb_controller.cpp.

412 {
413 std::vector<FrameInfo> result;
414
415 lldb::SBThread thread = getSelectedThreadInternal();
416 if (!thread.IsValid()) {
417 return result;
418 }
419
420 uint32_t num_frames = thread.GetNumFrames();
421 if (max_frames > 0 && num_frames > max_frames) {
422 num_frames = max_frames;
423 }
424
425 result.reserve(num_frames);
426 for (uint32_t i = 0; i < num_frames; i++) {
427 lldb::SBFrame frame = thread.GetFrameAtIndex(i);
428 if (frame.IsValid()) {
429 result.push_back(frameToInfo(frame));
430 }
431 }
432
433 return result;
434}

◆ getSelectedThread()

std::optional< ThreadInfo > ascii_query::LLDBController::getSelectedThread ( ) const
nodiscard

Get the currently selected thread.

Returns
ThreadInfo or nullopt if no thread selected

Definition at line 380 of file lldb_controller.cpp.

380 {
381 lldb::SBThread thread = getSelectedThreadInternal();
382 if (!thread.IsValid()) {
383 return std::nullopt;
384 }
385 return threadToInfo(thread, true);
386}

◆ getThreads()

std::vector< ThreadInfo > ascii_query::LLDBController::getThreads ( ) const
nodiscard

Get list of all threads.

Returns
Vector of ThreadInfo structs

Definition at line 353 of file lldb_controller.cpp.

353 {
354 std::vector<ThreadInfo> result;
355
356 if (!process_.IsValid()) {
357 return result;
358 }
359
360 // Sync state to ensure we have fresh thread info
361 syncProcessState();
362
363 lldb::SBThread selected = process_.GetSelectedThread();
364 uint64_t selected_id = selected.IsValid() ? selected.GetThreadID() : 0;
365
366 uint32_t num_threads = process_.GetNumThreads();
367 result.reserve(num_threads);
368
369 for (uint32_t i = 0; i < num_threads; i++) {
370 lldb::SBThread thread = process_.GetThreadAtIndex(i);
371 if (thread.IsValid()) {
372 bool is_selected = (thread.GetThreadID() == selected_id);
373 result.push_back(threadToInfo(thread, is_selected));
374 }
375 }
376
377 return result;
378}
unsigned long long uint64_t

◆ initialize()

bool ascii_query::LLDBController::initialize ( )

Initialize LLDB. Must be called before any other methods.

Returns
true on success, false on failure

Definition at line 47 of file lldb_controller.cpp.

47 {
48 if (initialized_) {
49 return true;
50 }
51
52 // Initialize LLDB
53 lldb::SBDebugger::Initialize();
54
55 // Create debugger instance
56 debugger_ = lldb::SBDebugger::Create(false); // false = no source manager
57 if (!debugger_.IsValid()) {
58 setError("Failed to create LLDB debugger instance");
59 return false;
60 }
61
62 // Don't echo commands
63 debugger_.SetAsync(true);
64
65 // Create a listener for process events
66 listener_ = debugger_.GetListener();
67 if (!listener_.IsValid()) {
68 setError("Failed to create LLDB listener");
69 lldb::SBDebugger::Destroy(debugger_);
70 return false;
71 }
72
73 initialized_ = true;
74 clearError();
75 return true;
76}

Referenced by main().

◆ isAttached()

bool ascii_query::LLDBController::isAttached ( ) const
nodiscard

Check if attached to a process.

Returns
true if attached, false otherwise

Definition at line 181 of file lldb_controller.cpp.

181 {
182 if (!process_.IsValid()) {
183 return false;
184 }
185
186 lldb::StateType state = process_.GetState();
187 return state != lldb::eStateInvalid && state != lldb::eStateDetached && state != lldb::eStateExited;
188}
ProcessState state() const
Get the current process state.

References state().

Referenced by detach(), main(), resume(), shutdown(), and stop().

◆ lastError()

const std::string & ascii_query::LLDBController::lastError ( ) const
nodiscard

Get the last error message.

Returns
Error message string

Definition at line 345 of file lldb_controller.cpp.

345 {
346 return last_error_;
347}

Referenced by main().

◆ listVariables()

std::vector< VariableInfo > ascii_query::LLDBController::listVariables ( uint32_t frame_index = 0,
bool include_args = true,
bool include_locals = true,
bool include_statics = false ) const
nodiscard

List all variables in scope at a frame.

Parameters
frame_indexWhich frame (0 = current)
include_argsInclude function arguments
include_localsInclude local variables
include_staticsInclude static variables
Returns
Vector of VariableInfo structs

Definition at line 478 of file lldb_controller.cpp.

478 {
479 std::vector<VariableInfo> result;
480
481 lldb::SBFrame frame = getFrameInternal(frame_index);
482 if (!frame.IsValid()) {
483 return result;
484 }
485
486 lldb::SBValueList vars = frame.GetVariables(include_args, include_locals, include_statics,
487 true); // true = in_scope_only
488
489 uint32_t num_vars = vars.GetSize();
490 result.reserve(num_vars);
491
492 for (uint32_t i = 0; i < num_vars; i++) {
493 lldb::SBValue value = vars.GetValueAtIndex(i);
494 if (value.IsValid()) {
495 result.push_back(valueToInfo(value, 0)); // Don't expand by default
496 }
497 }
498
499 return result;
500}

◆ operator=() [1/2]

LLDBController & ascii_query::LLDBController::operator= ( const LLDBController & )
delete

References LLDBController().

◆ operator=() [2/2]

LLDBController & ascii_query::LLDBController::operator= ( LLDBController && )
delete

References index, and LLDBController().

◆ readVariable()

std::optional< VariableInfo > ascii_query::LLDBController::readVariable ( const std::string & name,
uint32_t frame_index = 0,
uint32_t expand_depth = 0 ) const
nodiscard

Read a variable from the current frame.

Parameters
nameVariable name (supports dot notation for members)
frame_indexWhich frame to read from (0 = current)
expand_depthHow deep to expand struct members (0 = don't expand)
Returns
VariableInfo or nullopt if not found

Definition at line 448 of file lldb_controller.cpp.

448 {
449 lldb::SBFrame frame = getFrameInternal(frame_index);
450 if (!frame.IsValid()) {
451 return std::nullopt;
452 }
453
454 // Try to find the variable
455 // First, check if it's a path expression (has dots or arrows)
456 lldb::SBValue value;
457
458 if (name.find('.') != std::string::npos || name.find("->") != std::string::npos || name.find('[') != std::string::npos) {
459 // Path expression - use GetValueForVariablePath
460 value = frame.GetValueForVariablePath(name.c_str());
461 } else {
462 // Simple name - try FindVariable first
463 value = frame.FindVariable(name.c_str());
464
465 // If not found, try as a register
466 if (!value.IsValid()) {
467 value = frame.FindRegister(name.c_str());
468 }
469 }
470
471 if (!value.IsValid()) {
472 return std::nullopt;
473 }
474
475 return valueToInfo(value, expand_depth);
476}

◆ removeBreakpoint()

bool ascii_query::LLDBController::removeBreakpoint ( int32_t breakpoint_id)

Remove a breakpoint.

Parameters
breakpoint_idBreakpoint ID to remove
Returns
true if breakpoint was found and removed

Definition at line 526 of file lldb_controller.cpp.

526 {
527 if (!target_.IsValid()) {
528 setError("No valid target");
529 return false;
530 }
531
532 bool result = target_.BreakpointDelete(static_cast<lldb::break_id_t>(breakpoint_id));
533 if (!result) {
534 setError("Failed to delete breakpoint " + std::to_string(breakpoint_id));
535 } else {
536 clearError();
537 }
538 return result;
539}

◆ resume()

bool ascii_query::LLDBController::resume ( )

Resume the target process.

Returns
true if resumed successfully

Definition at line 253 of file lldb_controller.cpp.

253 {
254 if (!isAttached()) {
255 setError("Not attached to a process");
256 return false;
257 }
258
259 // Sync state first
260 syncProcessState();
261
262 // Check if already running
263 lldb::StateType current = process_.GetState();
264 if (current == lldb::eStateRunning || current == lldb::eStateStepping) {
265 clearError();
266 return true;
267 }
268
269 lldb::SBError error = process_.Continue();
270 if (error.Fail()) {
271 setError("Failed to resume process: " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
272 return false;
273 }
274
275 // Wait briefly for process to start running (async mode)
276 // Note: We don't wait long because running is the target state
277 waitForState(lldb::eStateRunning, 2);
278
279 clearError();
280 return true;
281}

References isAttached().

Referenced by main(), and waitForBreakpoint().

◆ selectThread()

bool ascii_query::LLDBController::selectThread ( uint64_t thread_id)

Select a thread by ID.

Parameters
thread_idThread ID to select
Returns
true if thread was found and selected

Definition at line 388 of file lldb_controller.cpp.

388 {
389 if (!process_.IsValid()) {
390 setError("No valid process");
391 return false;
392 }
393
394 uint32_t num_threads = process_.GetNumThreads();
395 for (uint32_t i = 0; i < num_threads; i++) {
396 lldb::SBThread thread = process_.GetThreadAtIndex(i);
397 if (thread.IsValid() && thread.GetThreadID() == thread_id) {
398 process_.SetSelectedThread(thread);
399 clearError();
400 return true;
401 }
402 }
403
404 setError("Thread ID " + std::to_string(thread_id) + " not found");
405 return false;
406}

◆ setBreakpoint()

int32_t ascii_query::LLDBController::setBreakpoint ( const std::string & file,
uint32_t line,
const std::string & condition = "" )

Set a breakpoint at file:line.

Parameters
fileSource file path
lineLine number
conditionOptional condition expression
Returns
Breakpoint ID, or -1 on failure

Definition at line 506 of file lldb_controller.cpp.

506 {
507 if (!target_.IsValid()) {
508 setError("No valid target");
509 return -1;
510 }
511
512 lldb::SBBreakpoint bp = target_.BreakpointCreateByLocation(file.c_str(), line);
513 if (!bp.IsValid()) {
514 setError("Failed to create breakpoint at " + file + ":" + std::to_string(line));
515 return -1;
516 }
517
518 if (!condition.empty()) {
519 bp.SetCondition(condition.c_str());
520 }
521
522 clearError();
523 return static_cast<int32_t>(bp.GetID());
524}

◆ shutdown()

void ascii_query::LLDBController::shutdown ( )

Shutdown LLDB and release resources.

Definition at line 78 of file lldb_controller.cpp.

78 {
79 if (!initialized_) {
80 return;
81 }
82
83 // Detach if still attached
84 if (isAttached()) {
85 detach();
86 }
87
88 // Delete target if valid
89 if (target_.IsValid()) {
90 debugger_.DeleteTarget(target_);
91 }
92
93 // Destroy debugger
94 if (debugger_.IsValid()) {
95 lldb::SBDebugger::Destroy(debugger_);
96 }
97
98 // Terminate LLDB
99 lldb::SBDebugger::Terminate();
100
101 initialized_ = false;
102}
void detach()
Detach from the current process.

References detach(), and isAttached().

Referenced by main(), and ~LLDBController().

◆ state()

ProcessState ascii_query::LLDBController::state ( ) const
nodiscard

Get the current process state.

Returns
ProcessState enum value

Definition at line 319 of file lldb_controller.cpp.

319 {
320 if (!process_.IsValid()) {
322 }
323
324 lldb::StateType lldb_state = process_.GetState();
325 switch (lldb_state) {
326 case lldb::eStateInvalid:
328 case lldb::eStateRunning:
329 case lldb::eStateStepping:
331 case lldb::eStateStopped:
332 case lldb::eStateSuspended:
334 case lldb::eStateExited:
336 case lldb::eStateCrashed:
338 case lldb::eStateDetached:
340 default:
342 }
343}
@ 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.).

References ascii_query::Crashed, ascii_query::Detached, ascii_query::Exited, ascii_query::Invalid, ascii_query::Running, and ascii_query::Stopped.

Referenced by isAttached(), main(), and waitForBreakpoint().

◆ stepInto()

bool ascii_query::LLDBController::stepInto ( )

Single step the current thread (step into).

Returns
true if step completed

Definition at line 283 of file lldb_controller.cpp.

283 {
284 lldb::SBThread thread = getSelectedThreadInternal();
285 if (!thread.IsValid()) {
286 setError("No valid thread selected");
287 return false;
288 }
289
290 thread.StepInto();
291 clearError();
292 return true;
293}

◆ stepOut()

bool ascii_query::LLDBController::stepOut ( )

Step out of the current function.

Returns
true if step completed

Definition at line 307 of file lldb_controller.cpp.

307 {
308 lldb::SBThread thread = getSelectedThreadInternal();
309 if (!thread.IsValid()) {
310 setError("No valid thread selected");
311 return false;
312 }
313
314 thread.StepOut();
315 clearError();
316 return true;
317}

◆ stepOver()

bool ascii_query::LLDBController::stepOver ( )

Step over the current line.

Returns
true if step completed

Definition at line 295 of file lldb_controller.cpp.

295 {
296 lldb::SBThread thread = getSelectedThreadInternal();
297 if (!thread.IsValid()) {
298 setError("No valid thread selected");
299 return false;
300 }
301
302 thread.StepOver();
303 clearError();
304 return true;
305}

◆ stop()

bool ascii_query::LLDBController::stop ( )

Stop the target process.

Returns
true if stopped successfully

Definition at line 215 of file lldb_controller.cpp.

215 {
216 if (!isAttached()) {
217 setError("Not attached to a process");
218 return false;
219 }
220
221 // Sync state first to ensure we have the current process state
222 syncProcessState();
223
224 // Check if already stopped
225 lldb::StateType current = process_.GetState();
226 if (current == lldb::eStateStopped || current == lldb::eStateSuspended) {
227 clearError();
228 return true;
229 }
230
231 // Only try to stop if running
232 if (current != lldb::eStateRunning && current != lldb::eStateStepping) {
233 setError("Process is not running (state: " + std::to_string(static_cast<int>(current)) + ")");
234 return false;
235 }
236
237 lldb::SBError error = process_.Stop();
238 if (error.Fail()) {
239 setError("Failed to stop process: " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
240 return false;
241 }
242
243 // Wait for process to actually stop (async mode)
244 if (!waitForState(lldb::eStateStopped, 5)) {
245 setError("Timeout waiting for process to stop");
246 return false;
247 }
248
249 clearError();
250 return true;
251}

References isAttached().

◆ targetName()

std::string ascii_query::LLDBController::targetName ( ) const
nodiscard

Get the name of the attached process.

Returns
Process name, or empty string if not attached

Definition at line 197 of file lldb_controller.cpp.

197 {
198 if (!target_.IsValid()) {
199 return "";
200 }
201
202 lldb::SBFileSpec exe = target_.GetExecutable();
203 if (!exe.IsValid()) {
204 return "";
205 }
206
207 const char *filename = exe.GetFilename();
208 return filename ? filename : "";
209}

Referenced by main().

◆ targetPid()

pid_t ascii_query::LLDBController::targetPid ( ) const
nodiscard

Get the PID of the attached process.

Returns
PID, or 0 if not attached

Definition at line 190 of file lldb_controller.cpp.

190 {
191 if (!process_.IsValid()) {
192 return 0;
193 }
194 return static_cast<pid_t>(process_.GetProcessID());
195}

Referenced by main().

◆ waitForBreakpoint()

bool ascii_query::LLDBController::waitForBreakpoint ( uint32_t timeout_ms = 0)

Wait for any breakpoint to be hit.

Parameters
timeout_msTimeout in milliseconds (0 = no timeout)
Returns
true if breakpoint was hit, false on timeout

Definition at line 574 of file lldb_controller.cpp.

574 {
575 if (!process_.IsValid()) {
576 setError("No valid process");
577 return false;
578 }
579
580 // First, resume the process if it's stopped
581 if (state() == ProcessState::Stopped) {
582 if (!resume()) {
583 return false;
584 }
585 }
586
587 // Wait for process to stop
588 lldb::SBEvent event;
589 uint32_t timeout_sec = (timeout_ms + 999) / 1000; // Round up to seconds
590
591 while (true) {
592 bool got_event = listener_.WaitForEvent(timeout_sec, event);
593 if (!got_event) {
594 setError("Timeout waiting for breakpoint");
595 return false;
596 }
597
598 lldb::StateType new_state = lldb::SBProcess::GetStateFromEvent(event);
599 if (new_state == lldb::eStateStopped) {
600 clearError();
601 return true;
602 } else if (new_state == lldb::eStateExited || new_state == lldb::eStateCrashed || new_state == lldb::eStateDetached) {
603 setError("Process exited/crashed while waiting for breakpoint");
604 return false;
605 }
606 }
607}
bool resume()
Resume the target process.

References resume(), state(), and ascii_query::Stopped.


The documentation for this class was generated from the following files: