ascii-chat 0.6.0
Real-time terminal-based video chat with ASCII art conversion
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
 
LLDBControlleroperator= (const LLDBController &)=delete
 
 LLDBController (LLDBController &&)=delete
 
LLDBControlleroperator= (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< ThreadInfogetThreads () const
 Get list of all threads.
 
std::optional< ThreadInfogetSelectedThread () const
 Get the currently selected thread.
 
bool selectThread (uint64_t thread_id)
 Select a thread by ID.
 
std::vector< FrameInfogetFrames (uint32_t max_frames=0) const
 Get stack frames for the selected thread.
 
std::optional< FrameInfogetFrame (uint32_t frame_index) const
 Get a specific frame by index.
 
std::optional< VariableInforeadVariable (const std::string &name, uint32_t frame_index=0, uint32_t expand_depth=0) const
 Read a variable from the current frame.
 
std::vector< VariableInfolistVariables (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< BreakpointInfogetBreakpoints () const
 Get all breakpoints.
 
std::optional< BreakpointInfogetBreakpoint (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< VariableInfoevaluateExpression (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 106 of file lldb_controller.h.

Constructor & Destructor Documentation

◆ LLDBController() [1/3]

ascii_query::LLDBController::LLDBController ( )
default

◆ ~LLDBController()

ascii_query::LLDBController::~LLDBController ( )

Definition at line 36 of file lldb_controller.cpp.

36{ shutdown(); }
void shutdown()
Shutdown LLDB and release resources.

References shutdown().

◆ LLDBController() [2/3]

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

◆ LLDBController() [3/3]

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

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 103 of file lldb_controller.cpp.

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

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 133 of file lldb_controller.cpp.

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

Referenced by main().

◆ detach()

void ascii_query::LLDBController::detach ( )

Detach from the current process.

The target process continues running after detach.

Definition at line 165 of file lldb_controller.cpp.

165 {
166 if (!isAttached()) {
167 return;
168 }
169
170 lldb::SBError error = process_.Detach();
171 if (error.Fail()) {
172 setError("Detach failed: " + std::string(error.GetCString() ? error.GetCString() : "unknown error"));
173 } else {
174 clearError();
175 }
176}
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

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 611 of file lldb_controller.cpp.

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

◆ getBreakpoint()

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

Get information about a specific breakpoint.

Parameters
breakpoint_idBreakpoint ID
Returns
BreakpointInfo or nullopt if not found

Definition at line 558 of file lldb_controller.cpp.

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

◆ getBreakpoints()

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

Get all breakpoints.

Returns
Vector of BreakpointInfo structs

Definition at line 538 of file lldb_controller.cpp.

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

◆ getFrame()

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

Get a specific frame by index.

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

Definition at line 431 of file lldb_controller.cpp.

431 {
432 lldb::SBFrame frame = getFrameInternal(frame_index);
433 if (!frame.IsValid()) {
434 return std::nullopt;
435 }
436 return frameToInfo(frame);
437}

◆ getFrames()

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

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 407 of file lldb_controller.cpp.

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

◆ getSelectedThread()

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

Get the currently selected thread.

Returns
ThreadInfo or nullopt if no thread selected

Definition at line 375 of file lldb_controller.cpp.

375 {
376 lldb::SBThread thread = getSelectedThreadInternal();
377 if (!thread.IsValid()) {
378 return std::nullopt;
379 }
380 return threadToInfo(thread, true);
381}

◆ getThreads()

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

Get list of all threads.

Returns
Vector of ThreadInfo structs

Definition at line 348 of file lldb_controller.cpp.

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

◆ 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 42 of file lldb_controller.cpp.

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

Referenced by main().

◆ isAttached()

bool ascii_query::LLDBController::isAttached ( ) const

Check if attached to a process.

Returns
true if attached, false otherwise

Definition at line 178 of file lldb_controller.cpp.

178 {
179 if (!process_.IsValid()) {
180 return false;
181 }
182
183 lldb::StateType state = process_.GetState();
184 return state != lldb::eStateInvalid && state != lldb::eStateDetached && state != lldb::eStateExited;
185}
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

Get the last error message.

Returns
Error message string

Definition at line 342 of file lldb_controller.cpp.

342{ return last_error_; }

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

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 474 of file lldb_controller.cpp.

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

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ readVariable()

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

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 443 of file lldb_controller.cpp.

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

◆ 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 523 of file lldb_controller.cpp.

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

◆ resume()

bool ascii_query::LLDBController::resume ( )

Resume the target process.

Returns
true if resumed successfully

Definition at line 250 of file lldb_controller.cpp.

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

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 383 of file lldb_controller.cpp.

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

References thread_id.

◆ 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 503 of file lldb_controller.cpp.

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

◆ shutdown()

void ascii_query::LLDBController::shutdown ( )

Shutdown LLDB and release resources.

Definition at line 73 of file lldb_controller.cpp.

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

References detach(), and isAttached().

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

◆ state()

ProcessState ascii_query::LLDBController::state ( ) const

Get the current process state.

Returns
ProcessState enum value

Definition at line 316 of file lldb_controller.cpp.

316 {
317 if (!process_.IsValid()) {
319 }
320
321 lldb::StateType lldb_state = process_.GetState();
322 switch (lldb_state) {
323 case lldb::eStateInvalid:
325 case lldb::eStateRunning:
326 case lldb::eStateStepping:
328 case lldb::eStateStopped:
329 case lldb::eStateSuspended:
331 case lldb::eStateExited:
333 case lldb::eStateCrashed:
335 case lldb::eStateDetached:
337 default:
339 }
340}
@ 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 280 of file lldb_controller.cpp.

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

◆ stepOut()

bool ascii_query::LLDBController::stepOut ( )

Step out of the current function.

Returns
true if step completed

Definition at line 304 of file lldb_controller.cpp.

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

◆ stepOver()

bool ascii_query::LLDBController::stepOver ( )

Step over the current line.

Returns
true if step completed

Definition at line 292 of file lldb_controller.cpp.

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

◆ stop()

bool ascii_query::LLDBController::stop ( )

Stop the target process.

Returns
true if stopped successfully

Definition at line 212 of file lldb_controller.cpp.

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

References isAttached().

◆ targetName()

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

Get the name of the attached process.

Returns
Process name, or empty string if not attached

Definition at line 194 of file lldb_controller.cpp.

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

Referenced by main().

◆ targetPid()

pid_t ascii_query::LLDBController::targetPid ( ) const

Get the PID of the attached process.

Returns
PID, or 0 if not attached

Definition at line 187 of file lldb_controller.cpp.

187 {
188 if (!process_.IsValid()) {
189 return 0;
190 }
191 return static_cast<pid_t>(process_.GetProcessID());
192}

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 571 of file lldb_controller.cpp.

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

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


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