LLDB mainline
SBProcess.cpp
Go to the documentation of this file.
1//===-- SBProcess.cpp -----------------------------------------------------===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8
11
12#include <cinttypes>
13
14#include "lldb/lldb-defines.h"
15#include "lldb/lldb-types.h"
16
18#include "lldb/Core/Debugger.h"
19#include "lldb/Core/Module.h"
24#include "lldb/Target/Process.h"
27#include "lldb/Target/Target.h"
28#include "lldb/Target/Thread.h"
29#include "lldb/Utility/Args.h"
32#include "lldb/Utility/State.h"
33#include "lldb/Utility/Stream.h"
34
37#include "lldb/API/SBDebugger.h"
38#include "lldb/API/SBEvent.h"
39#include "lldb/API/SBFile.h"
40#include "lldb/API/SBFileSpec.h"
45#include "lldb/API/SBStream.h"
48#include "lldb/API/SBThread.h"
50#include "lldb/API/SBTrace.h"
52
53using namespace lldb;
54using namespace lldb_private;
55
57
58// SBProcess constructor
59
60SBProcess::SBProcess(const SBProcess &rhs) : m_opaque_wp(rhs.m_opaque_wp) {
61 LLDB_INSTRUMENT_VA(this, rhs);
62}
63
65 : m_opaque_wp(process_sp) {
66 LLDB_INSTRUMENT_VA(this, process_sp);
67}
68
70 LLDB_INSTRUMENT_VA(this, rhs);
71
72 if (this != &rhs)
74 return *this;
75}
76
77// Destructor
78SBProcess::~SBProcess() = default;
79
82
84}
85
88
89 ProcessSP process_sp(GetSP());
90 if (process_sp) {
91 return ConstString(process_sp->GetPluginName()).GetCString();
92 }
93 return "<Unknown>";
94}
95
96const char *SBProcess::GetShortPluginName() {
98
99 ProcessSP process_sp(GetSP());
100 if (process_sp) {
101 return ConstString(process_sp->GetPluginName()).GetCString();
102 }
103 return "<Unknown>";
104}
105
107
108void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
109
111 LLDB_INSTRUMENT_VA(this);
112
113 m_opaque_wp.reset();
114}
115
116bool SBProcess::IsValid() const {
117 LLDB_INSTRUMENT_VA(this);
118 return this->operator bool();
119}
120SBProcess::operator bool() const {
121 LLDB_INSTRUMENT_VA(this);
122
123 ProcessSP process_sp(m_opaque_wp.lock());
124 return ((bool)process_sp && process_sp->IsValid());
125}
126
127bool SBProcess::RemoteLaunch(char const **argv, char const **envp,
128 const char *stdin_path, const char *stdout_path,
129 const char *stderr_path,
130 const char *working_directory,
131 uint32_t launch_flags, bool stop_at_entry,
133 LLDB_INSTRUMENT_VA(this, argv, envp, stdin_path, stdout_path, stderr_path,
134 working_directory, launch_flags, stop_at_entry, error);
135
136 ProcessSP process_sp(GetSP());
137 if (process_sp) {
138 std::lock_guard<std::recursive_mutex> guard(
139 process_sp->GetTarget().GetAPIMutex());
140 if (process_sp->GetState() == eStateConnected) {
141 if (stop_at_entry)
142 launch_flags |= eLaunchFlagStopAtEntry;
143 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
144 FileSpec(stderr_path),
145 FileSpec(working_directory), launch_flags);
146 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
147 if (exe_module)
148 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
149 if (argv)
150 launch_info.GetArguments().AppendArguments(argv);
151 if (envp)
152 launch_info.GetEnvironment() = Environment(envp);
153 error.SetError(process_sp->Launch(launch_info));
154 } else {
155 error.SetErrorString("must be in eStateConnected to call RemoteLaunch");
156 }
157 } else {
158 error.SetErrorString("unable to attach pid");
159 }
160
161 return error.Success();
162}
163
166 LLDB_INSTRUMENT_VA(this, pid, error);
167
168 ProcessSP process_sp(GetSP());
169 if (process_sp) {
170 std::lock_guard<std::recursive_mutex> guard(
171 process_sp->GetTarget().GetAPIMutex());
172 if (process_sp->GetState() == eStateConnected) {
173 ProcessAttachInfo attach_info;
174 attach_info.SetProcessID(pid);
175 error.SetError(process_sp->Attach(attach_info));
176 } else {
177 error.SetErrorString(
178 "must be in eStateConnected to call RemoteAttachToProcessWithID");
179 }
180 } else {
181 error.SetErrorString("unable to attach pid");
182 }
183
184 return error.Success();
185}
186
188 LLDB_INSTRUMENT_VA(this);
189
190 uint32_t num_threads = 0;
191 ProcessSP process_sp(GetSP());
192 if (process_sp) {
193 Process::StopLocker stop_locker;
194
195 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
196 std::lock_guard<std::recursive_mutex> guard(
197 process_sp->GetTarget().GetAPIMutex());
198 num_threads = process_sp->GetThreadList().GetSize(can_update);
199 }
200
201 return num_threads;
202}
203
205 LLDB_INSTRUMENT_VA(this);
206
207 SBThread sb_thread;
208 ThreadSP thread_sp;
209 ProcessSP process_sp(GetSP());
210 if (process_sp) {
211 std::lock_guard<std::recursive_mutex> guard(
212 process_sp->GetTarget().GetAPIMutex());
213 thread_sp = process_sp->GetThreadList().GetSelectedThread();
214 sb_thread.SetThread(thread_sp);
215 }
216
217 return sb_thread;
218}
219
221 lldb::addr_t context) {
222 LLDB_INSTRUMENT_VA(this, tid, context);
223
224 SBThread sb_thread;
225 ThreadSP thread_sp;
226 ProcessSP process_sp(GetSP());
227 if (process_sp) {
228 std::lock_guard<std::recursive_mutex> guard(
229 process_sp->GetTarget().GetAPIMutex());
230 thread_sp = process_sp->CreateOSPluginThread(tid, context);
231 sb_thread.SetThread(thread_sp);
232 }
233
234 return sb_thread;
235}
236
238 LLDB_INSTRUMENT_VA(this);
239
240 SBTarget sb_target;
241 TargetSP target_sp;
242 ProcessSP process_sp(GetSP());
243 if (process_sp) {
244 target_sp = process_sp->GetTarget().shared_from_this();
245 sb_target.SetSP(target_sp);
246 }
247
248 return sb_target;
249}
250
251size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
252 LLDB_INSTRUMENT_VA(this, src, src_len);
253
254 size_t ret_val = 0;
255 ProcessSP process_sp(GetSP());
256 if (process_sp) {
258 ret_val = process_sp->PutSTDIN(src, src_len, error);
259 }
260
261 return ret_val;
262}
263
264size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
265 LLDB_INSTRUMENT_VA(this, dst, dst_len);
266
267 size_t bytes_read = 0;
268 ProcessSP process_sp(GetSP());
269 if (process_sp) {
271 bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
272 }
273
274 return bytes_read;
275}
276
277size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
278 LLDB_INSTRUMENT_VA(this, dst, dst_len);
279
280 size_t bytes_read = 0;
281 ProcessSP process_sp(GetSP());
282 if (process_sp) {
284 bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
285 }
286
287 return bytes_read;
288}
289
290size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
291 LLDB_INSTRUMENT_VA(this, dst, dst_len);
292
293 size_t bytes_read = 0;
294 ProcessSP process_sp(GetSP());
295 if (process_sp) {
297 bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
298 }
299
300 return bytes_read;
301}
302
303void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
304 LLDB_INSTRUMENT_VA(this, event, out);
305
306 return ReportEventState(event, out.m_opaque_sp);
307}
308
309void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
310 LLDB_INSTRUMENT_VA(this, event, out);
311 FileSP outfile = std::make_shared<NativeFile>(out, false);
312 return ReportEventState(event, outfile);
313}
314
315void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
316
317 LLDB_INSTRUMENT_VA(this, event, out);
318
319 if (!out || !out->IsValid())
320 return;
321
322 ProcessSP process_sp(GetSP());
323 if (process_sp) {
324 StreamFile stream(out);
325 const StateType event_state = SBProcess::GetStateFromEvent(event);
326 stream.Printf("Process %" PRIu64 " %s\n", process_sp->GetID(),
327 SBDebugger::StateAsCString(event_state));
328 }
329}
330
332 SBCommandReturnObject &result) {
333 LLDB_INSTRUMENT_VA(this, event, result);
334
335 ProcessSP process_sp(GetSP());
336 if (process_sp) {
337 const StateType event_state = SBProcess::GetStateFromEvent(event);
338 char message[1024];
339 ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
340 process_sp->GetID(), SBDebugger::StateAsCString(event_state));
341
342 result.AppendMessage(message);
343 }
344}
345
347 LLDB_INSTRUMENT_VA(this, thread);
348
349 ProcessSP process_sp(GetSP());
350 if (process_sp) {
351 std::lock_guard<std::recursive_mutex> guard(
352 process_sp->GetTarget().GetAPIMutex());
353 return process_sp->GetThreadList().SetSelectedThreadByID(
354 thread.GetThreadID());
355 }
356 return false;
357}
358
360 LLDB_INSTRUMENT_VA(this, tid);
361
362 bool ret_val = false;
363 ProcessSP process_sp(GetSP());
364 if (process_sp) {
365 std::lock_guard<std::recursive_mutex> guard(
366 process_sp->GetTarget().GetAPIMutex());
367 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
368 }
369
370 return ret_val;
371}
372
374 LLDB_INSTRUMENT_VA(this, index_id);
375
376 bool ret_val = false;
377 ProcessSP process_sp(GetSP());
378 if (process_sp) {
379 std::lock_guard<std::recursive_mutex> guard(
380 process_sp->GetTarget().GetAPIMutex());
381 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
382 }
383
384 return ret_val;
385}
386
388 LLDB_INSTRUMENT_VA(this, index);
389
390 SBThread sb_thread;
391 ThreadSP thread_sp;
392 ProcessSP process_sp(GetSP());
393 if (process_sp) {
394 Process::StopLocker stop_locker;
395 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
396 std::lock_guard<std::recursive_mutex> guard(
397 process_sp->GetTarget().GetAPIMutex());
398 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
399 sb_thread.SetThread(thread_sp);
400 }
401
402 return sb_thread;
403}
404
406 LLDB_INSTRUMENT_VA(this);
407
408 uint32_t num_queues = 0;
409 ProcessSP process_sp(GetSP());
410 if (process_sp) {
411 Process::StopLocker stop_locker;
412 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
413 std::lock_guard<std::recursive_mutex> guard(
414 process_sp->GetTarget().GetAPIMutex());
415 num_queues = process_sp->GetQueueList().GetSize();
416 }
417 }
418
419 return num_queues;
420}
421
423 LLDB_INSTRUMENT_VA(this, index);
424
425 SBQueue sb_queue;
426 QueueSP queue_sp;
427 ProcessSP process_sp(GetSP());
428 if (process_sp) {
429 Process::StopLocker stop_locker;
430 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
431 std::lock_guard<std::recursive_mutex> guard(
432 process_sp->GetTarget().GetAPIMutex());
433 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
434 sb_queue.SetQueue(queue_sp);
435 }
436 }
437
438 return sb_queue;
439}
440
441uint32_t SBProcess::GetStopID(bool include_expression_stops) {
442 LLDB_INSTRUMENT_VA(this, include_expression_stops);
443
444 ProcessSP process_sp(GetSP());
445 if (process_sp) {
446 std::lock_guard<std::recursive_mutex> guard(
447 process_sp->GetTarget().GetAPIMutex());
448 if (include_expression_stops)
449 return process_sp->GetStopID();
450 else
451 return process_sp->GetLastNaturalStopID();
452 }
453 return 0;
454}
455
457 LLDB_INSTRUMENT_VA(this, stop_id);
458
459 SBEvent sb_event;
460 EventSP event_sp;
461 ProcessSP process_sp(GetSP());
462 if (process_sp) {
463 std::lock_guard<std::recursive_mutex> guard(
464 process_sp->GetTarget().GetAPIMutex());
465 event_sp = process_sp->GetStopEventForStopID(stop_id);
466 sb_event.reset(event_sp);
467 }
468
469 return sb_event;
470}
471
473 LLDB_INSTRUMENT_VA(this, new_state);
474
475 if (ProcessSP process_sp = GetSP()) {
476 std::lock_guard<std::recursive_mutex> guard(
477 process_sp->GetTarget().GetAPIMutex());
478 process_sp->ForceScriptedState(new_state);
479 }
480}
481
483 LLDB_INSTRUMENT_VA(this);
484
485 StateType ret_val = eStateInvalid;
486 ProcessSP process_sp(GetSP());
487 if (process_sp) {
488 std::lock_guard<std::recursive_mutex> guard(
489 process_sp->GetTarget().GetAPIMutex());
490 ret_val = process_sp->GetState();
491 }
492
493 return ret_val;
494}
495
497 LLDB_INSTRUMENT_VA(this);
498
499 int exit_status = 0;
500 ProcessSP process_sp(GetSP());
501 if (process_sp) {
502 std::lock_guard<std::recursive_mutex> guard(
503 process_sp->GetTarget().GetAPIMutex());
504 exit_status = process_sp->GetExitStatus();
505 }
506
507 return exit_status;
508}
509
511 LLDB_INSTRUMENT_VA(this);
512
513 ProcessSP process_sp(GetSP());
514 if (!process_sp)
515 return nullptr;
516
517 std::lock_guard<std::recursive_mutex> guard(
518 process_sp->GetTarget().GetAPIMutex());
519 return ConstString(process_sp->GetExitDescription()).GetCString();
520}
521
523 LLDB_INSTRUMENT_VA(this);
524
526 ProcessSP process_sp(GetSP());
527 if (process_sp)
528 ret_val = process_sp->GetID();
529
530 return ret_val;
531}
532
534 LLDB_INSTRUMENT_VA(this);
535
536 uint32_t ret_val = 0;
537 ProcessSP process_sp(GetSP());
538 if (process_sp)
539 ret_val = process_sp->GetUniqueID();
540 return ret_val;
541}
542
544 LLDB_INSTRUMENT_VA(this);
545
546 ByteOrder byteOrder = eByteOrderInvalid;
547 ProcessSP process_sp(GetSP());
548 if (process_sp)
549 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
550
551 return byteOrder;
552}
553
555 LLDB_INSTRUMENT_VA(this);
556
557 uint32_t size = 0;
558 ProcessSP process_sp(GetSP());
559 if (process_sp)
560 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
561
562 return size;
563}
564
566 LLDB_INSTRUMENT_VA(this);
567
568 SBError sb_error;
569 ProcessSP process_sp(GetSP());
570
571 if (process_sp) {
572 std::lock_guard<std::recursive_mutex> guard(
573 process_sp->GetTarget().GetAPIMutex());
574
575 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
576 sb_error.ref() = process_sp->Resume();
577 else
578 sb_error.ref() = process_sp->ResumeSynchronous(nullptr);
579 } else
580 sb_error.SetErrorString("SBProcess is invalid");
581
582 return sb_error;
583}
584
586 LLDB_INSTRUMENT_VA(this);
587
588 SBError sb_error;
589 ProcessSP process_sp(GetSP());
590 if (process_sp) {
591 std::lock_guard<std::recursive_mutex> guard(
592 process_sp->GetTarget().GetAPIMutex());
593 sb_error.SetError(process_sp->Destroy(false));
594 } else
595 sb_error.SetErrorString("SBProcess is invalid");
596
597 return sb_error;
598}
599
601 LLDB_INSTRUMENT_VA(this);
602
603 SBError sb_error;
604 ProcessSP process_sp(GetSP());
605 if (process_sp) {
606 std::lock_guard<std::recursive_mutex> guard(
607 process_sp->GetTarget().GetAPIMutex());
608 sb_error.SetError(process_sp->Halt());
609 } else
610 sb_error.SetErrorString("SBProcess is invalid");
611
612 return sb_error;
613}
614
616 LLDB_INSTRUMENT_VA(this);
617
618 SBError sb_error;
619 ProcessSP process_sp(GetSP());
620 if (process_sp) {
621 std::lock_guard<std::recursive_mutex> guard(
622 process_sp->GetTarget().GetAPIMutex());
623 sb_error.SetError(process_sp->Destroy(true));
624 } else
625 sb_error.SetErrorString("SBProcess is invalid");
626
627 return sb_error;
628}
629
631 LLDB_INSTRUMENT_VA(this);
632
633 // FIXME: This should come from a process default.
634 bool keep_stopped = false;
635 return Detach(keep_stopped);
636}
637
638SBError SBProcess::Detach(bool keep_stopped) {
639 LLDB_INSTRUMENT_VA(this, keep_stopped);
640
641 SBError sb_error;
642 ProcessSP process_sp(GetSP());
643 if (process_sp) {
644 std::lock_guard<std::recursive_mutex> guard(
645 process_sp->GetTarget().GetAPIMutex());
646 sb_error.SetError(process_sp->Detach(keep_stopped));
647 } else
648 sb_error.SetErrorString("SBProcess is invalid");
649
650 return sb_error;
651}
652
654 LLDB_INSTRUMENT_VA(this, signo);
655
656 SBError sb_error;
657 ProcessSP process_sp(GetSP());
658 if (process_sp) {
659 std::lock_guard<std::recursive_mutex> guard(
660 process_sp->GetTarget().GetAPIMutex());
661 sb_error.SetError(process_sp->Signal(signo));
662 } else
663 sb_error.SetErrorString("SBProcess is invalid");
664
665 return sb_error;
666}
667
669 LLDB_INSTRUMENT_VA(this);
670
671 if (auto process_sp = GetSP())
672 return SBUnixSignals{process_sp};
673
674 return SBUnixSignals{};
675}
676
678 LLDB_INSTRUMENT_VA(this);
679
680 ProcessSP process_sp(GetSP());
681 if (process_sp) {
682 process_sp->SendAsyncInterrupt();
683 }
684}
685
687 LLDB_INSTRUMENT_VA(this, tid);
688
689 SBThread sb_thread;
690 ThreadSP thread_sp;
691 ProcessSP process_sp(GetSP());
692 if (process_sp) {
693 Process::StopLocker stop_locker;
694 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
695 std::lock_guard<std::recursive_mutex> guard(
696 process_sp->GetTarget().GetAPIMutex());
697 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
698 sb_thread.SetThread(thread_sp);
699 }
700
701 return sb_thread;
702}
703
705 LLDB_INSTRUMENT_VA(this, index_id);
706
707 SBThread sb_thread;
708 ThreadSP thread_sp;
709 ProcessSP process_sp(GetSP());
710 if (process_sp) {
711 Process::StopLocker stop_locker;
712 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
713 std::lock_guard<std::recursive_mutex> guard(
714 process_sp->GetTarget().GetAPIMutex());
715 thread_sp =
716 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
717 sb_thread.SetThread(thread_sp);
718 }
719
720 return sb_thread;
721}
722
724 LLDB_INSTRUMENT_VA(event);
725
727
728 return ret_val;
729}
730
732 LLDB_INSTRUMENT_VA(event);
733
735
736 return ret_val;
737}
738
740 LLDB_INSTRUMENT_VA(event);
741
743}
744
745const char *
747 size_t idx) {
748 LLDB_INSTRUMENT_VA(event, idx);
749
751 event.get(), idx))
752 .GetCString();
753}
754
756 LLDB_INSTRUMENT_VA(event);
757
758 ProcessSP process_sp =
760 if (!process_sp) {
761 // StructuredData events also know the process they come from. Try that.
763 }
764
765 return SBProcess(process_sp);
766}
767
769 LLDB_INSTRUMENT_VA(event);
770
772}
773
776 LLDB_INSTRUMENT_VA(event);
777
778 return SBStructuredData(event.GetSP());
779}
780
782 LLDB_INSTRUMENT_VA(event);
783
785 nullptr;
786}
787
789 LLDB_INSTRUMENT_VA(event);
790
791 EventSP event_sp = event.GetSP();
792 EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
793 return event_data && (event_data->GetFlavor() ==
795}
796
798 LLDB_INSTRUMENT_VA(this);
799
800 ProcessSP process_sp(GetSP());
801
802 SBBroadcaster broadcaster(process_sp.get(), false);
803
804 return broadcaster;
805}
806
809
811}
812
814 const void *buf, uint64_t size, const SBAddressRangeList &ranges,
815 uint32_t alignment, uint32_t max_matches, SBError &error) {
816 LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
817
819
820 ProcessSP process_sp(GetSP());
821 if (!process_sp) {
822 error.SetErrorString("SBProcess is invalid");
823 return matches;
824 }
825 Process::StopLocker stop_locker;
826 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
827 error.SetErrorString("process is running");
828 return matches;
829 }
830 std::lock_guard<std::recursive_mutex> guard(
831 process_sp->GetTarget().GetAPIMutex());
832 matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
833 reinterpret_cast<const uint8_t *>(buf), size, ranges.ref().ref(),
834 alignment, max_matches, error.ref());
835 return matches;
836}
837
838lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
839 const SBAddressRange &range,
840 uint32_t alignment, SBError &error) {
841 LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
842
843 ProcessSP process_sp(GetSP());
844
845 if (!process_sp) {
846 error.SetErrorString("SBProcess is invalid");
848 }
849
850 Process::StopLocker stop_locker;
851 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
852 error.SetErrorString("process is running");
854 }
855
856 std::lock_guard<std::recursive_mutex> guard(
857 process_sp->GetTarget().GetAPIMutex());
858 return process_sp->FindInMemory(reinterpret_cast<const uint8_t *>(buf), size,
859 range.ref(), alignment, error.ref());
860}
861
862size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
863 SBError &sb_error) {
864 LLDB_INSTRUMENT_VA(this, addr, dst, dst_len, sb_error);
865
866 if (!dst) {
867 sb_error.SetErrorStringWithFormat(
868 "no buffer provided to read %zu bytes into", dst_len);
869 return 0;
870 }
871
872 size_t bytes_read = 0;
873 ProcessSP process_sp(GetSP());
874
875
876 if (process_sp) {
877 Process::StopLocker stop_locker;
878 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
879 std::lock_guard<std::recursive_mutex> guard(
880 process_sp->GetTarget().GetAPIMutex());
881 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
882 } else {
883 sb_error.SetErrorString("process is running");
884 }
885 } else {
886 sb_error.SetErrorString("SBProcess is invalid");
887 }
888
889 return bytes_read;
890}
891
892size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
893 lldb::SBError &sb_error) {
894 LLDB_INSTRUMENT_VA(this, addr, buf, size, sb_error);
895
896 size_t bytes_read = 0;
897 ProcessSP process_sp(GetSP());
898 if (process_sp) {
899 Process::StopLocker stop_locker;
900 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
901 std::lock_guard<std::recursive_mutex> guard(
902 process_sp->GetTarget().GetAPIMutex());
903 bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
904 sb_error.ref());
905 } else {
906 sb_error.SetErrorString("process is running");
907 }
908 } else {
909 sb_error.SetErrorString("SBProcess is invalid");
910 }
911 return bytes_read;
912}
913
914uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
915 lldb::SBError &sb_error) {
916 LLDB_INSTRUMENT_VA(this, addr, byte_size, sb_error);
917
918 uint64_t value = 0;
919 ProcessSP process_sp(GetSP());
920 if (process_sp) {
921 Process::StopLocker stop_locker;
922 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
923 std::lock_guard<std::recursive_mutex> guard(
924 process_sp->GetTarget().GetAPIMutex());
925 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
926 sb_error.ref());
927 } else {
928 sb_error.SetErrorString("process is running");
929 }
930 } else {
931 sb_error.SetErrorString("SBProcess is invalid");
932 }
933 return value;
934}
935
937 lldb::SBError &sb_error) {
938 LLDB_INSTRUMENT_VA(this, addr, sb_error);
939
941 ProcessSP process_sp(GetSP());
942 if (process_sp) {
943 Process::StopLocker stop_locker;
944 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
945 std::lock_guard<std::recursive_mutex> guard(
946 process_sp->GetTarget().GetAPIMutex());
947 ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref());
948 } else {
949 sb_error.SetErrorString("process is running");
950 }
951 } else {
952 sb_error.SetErrorString("SBProcess is invalid");
953 }
954 return ptr;
955}
956
957size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
958 SBError &sb_error) {
959 LLDB_INSTRUMENT_VA(this, addr, src, src_len, sb_error);
960
961 size_t bytes_written = 0;
962
963 ProcessSP process_sp(GetSP());
964
965 if (process_sp) {
966 Process::StopLocker stop_locker;
967 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
968 std::lock_guard<std::recursive_mutex> guard(
969 process_sp->GetTarget().GetAPIMutex());
970 bytes_written =
971 process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
972 } else {
973 sb_error.SetErrorString("process is running");
974 }
975 }
976
977 return bytes_written;
978}
979
981 LLDB_INSTRUMENT_VA(this, status);
982
983 ProcessSP process_sp(GetSP());
984 if (process_sp)
985 process_sp->GetStatus(status.ref());
986}
987
989 LLDB_INSTRUMENT_VA(this, description);
990
991 Stream &strm = description.ref();
992
993 ProcessSP process_sp(GetSP());
994 if (process_sp) {
995 char path[PATH_MAX];
996 GetTarget().GetExecutable().GetPath(path, sizeof(path));
997 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
998 const char *exe_name = nullptr;
999 if (exe_module)
1000 exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1001
1002 strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1003 process_sp->GetID(), lldb_private::StateAsCString(GetState()),
1004 GetNumThreads(), exe_name ? ", executable = " : "",
1005 exe_name ? exe_name : "");
1006 } else
1007 strm.PutCString("No value");
1008
1009 return true;
1010}
1011
1013 LLDB_INSTRUMENT_VA(this);
1014 SBStructuredData data;
1015 ProcessSP process_sp(GetSP());
1016 if (!process_sp)
1017 return data;
1018
1019 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1020
1021 if (!platform_sp)
1022 return data;
1023
1024 auto expected_data =
1025 platform_sp->FetchExtendedCrashInformation(*process_sp.get());
1026
1027 if (!expected_data)
1028 return data;
1029
1030 StructuredData::ObjectSP fetched_data = *expected_data;
1031 data.m_impl_up->SetObjectSP(fetched_data);
1032 return data;
1033}
1034
1035uint32_t
1037 LLDB_INSTRUMENT_VA(this, sb_error);
1038
1039 uint32_t num = 0;
1040 ProcessSP process_sp(GetSP());
1041 if (process_sp) {
1042 std::lock_guard<std::recursive_mutex> guard(
1043 process_sp->GetTarget().GetAPIMutex());
1044 std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
1045 if (actual_num) {
1046 num = *actual_num;
1047 } else {
1048 sb_error.SetErrorString("Unable to determine number of watchpoints");
1049 }
1050 } else {
1051 sb_error.SetErrorString("SBProcess is invalid");
1052 }
1053 return num;
1054}
1055
1056uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
1057 lldb::SBError &sb_error) {
1058 LLDB_INSTRUMENT_VA(this, sb_remote_image_spec, sb_error);
1059
1060 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
1061}
1062
1063uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
1064 const lldb::SBFileSpec &sb_remote_image_spec,
1065 lldb::SBError &sb_error) {
1066 LLDB_INSTRUMENT_VA(this, sb_local_image_spec, sb_remote_image_spec, sb_error);
1067
1068 ProcessSP process_sp(GetSP());
1069 if (process_sp) {
1070 Process::StopLocker stop_locker;
1071 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1072 std::lock_guard<std::recursive_mutex> guard(
1073 process_sp->GetTarget().GetAPIMutex());
1074 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1075 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1076 *sb_remote_image_spec, sb_error.ref());
1077 } else {
1078 sb_error.SetErrorString("process is running");
1079 }
1080 } else {
1081 sb_error.SetErrorString("process is invalid");
1082 }
1084}
1085
1087 SBStringList &paths,
1088 lldb::SBFileSpec &loaded_path,
1090 LLDB_INSTRUMENT_VA(this, image_spec, paths, loaded_path, error);
1091
1092 ProcessSP process_sp(GetSP());
1093 if (process_sp) {
1094 Process::StopLocker stop_locker;
1095 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1096 std::lock_guard<std::recursive_mutex> guard(
1097 process_sp->GetTarget().GetAPIMutex());
1098 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1099 size_t num_paths = paths.GetSize();
1100 std::vector<std::string> paths_vec;
1101 paths_vec.reserve(num_paths);
1102 for (size_t i = 0; i < num_paths; i++)
1103 paths_vec.push_back(paths.GetStringAtIndex(i));
1104 FileSpec loaded_spec;
1105
1106 uint32_t token = platform_sp->LoadImageUsingPaths(
1107 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
1108 if (token != LLDB_INVALID_IMAGE_TOKEN)
1109 loaded_path = loaded_spec;
1110 return token;
1111 } else {
1112 error.SetErrorString("process is running");
1113 }
1114 } else {
1115 error.SetErrorString("process is invalid");
1116 }
1117
1119}
1120
1122 LLDB_INSTRUMENT_VA(this, image_token);
1123
1124 lldb::SBError sb_error;
1125 ProcessSP process_sp(GetSP());
1126 if (process_sp) {
1127 Process::StopLocker stop_locker;
1128 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1129 std::lock_guard<std::recursive_mutex> guard(
1130 process_sp->GetTarget().GetAPIMutex());
1131 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1132 sb_error.SetError(
1133 platform_sp->UnloadImage(process_sp.get(), image_token));
1134 } else {
1135 sb_error.SetErrorString("process is running");
1136 }
1137 } else
1138 sb_error.SetErrorString("invalid process");
1139 return sb_error;
1140}
1141
1143 LLDB_INSTRUMENT_VA(this, event_data);
1144
1145 lldb::SBError sb_error;
1146 ProcessSP process_sp(GetSP());
1147 if (process_sp) {
1148 Process::StopLocker stop_locker;
1149 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1150 std::lock_guard<std::recursive_mutex> guard(
1151 process_sp->GetTarget().GetAPIMutex());
1152 sb_error.SetError(process_sp->SendEventData(event_data));
1153 } else {
1154 sb_error.SetErrorString("process is running");
1155 }
1156 } else
1157 sb_error.SetErrorString("invalid process");
1158 return sb_error;
1159}
1160
1162 LLDB_INSTRUMENT_VA(this);
1163
1164 ProcessSP process_sp(GetSP());
1165 if (process_sp && process_sp->GetSystemRuntime()) {
1166 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1167 return runtime->GetExtendedBacktraceTypes().size();
1168 }
1169 return 0;
1170}
1171
1173 LLDB_INSTRUMENT_VA(this, idx);
1174
1175 ProcessSP process_sp(GetSP());
1176 if (process_sp && process_sp->GetSystemRuntime()) {
1177 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1178 const std::vector<ConstString> &names =
1179 runtime->GetExtendedBacktraceTypes();
1180 if (idx < names.size()) {
1181 return names[idx].AsCString();
1182 }
1183 }
1184 return nullptr;
1185}
1186
1188 LLDB_INSTRUMENT_VA(this, addr);
1189
1190 ProcessSP process_sp(GetSP());
1191 SBThreadCollection threads;
1192 if (process_sp) {
1193 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1194 }
1195 return threads;
1196}
1197
1200 LLDB_INSTRUMENT_VA(this, type);
1201
1202 ProcessSP process_sp(GetSP());
1203 if (!process_sp)
1204 return false;
1205
1206 std::lock_guard<std::recursive_mutex> guard(
1207 process_sp->GetTarget().GetAPIMutex());
1208
1209 InstrumentationRuntimeSP runtime_sp =
1210 process_sp->GetInstrumentationRuntime(type);
1211
1212 if (!runtime_sp.get())
1213 return false;
1214
1215 return runtime_sp->IsActive();
1216}
1217
1218lldb::SBError SBProcess::SaveCore(const char *file_name) {
1219 LLDB_INSTRUMENT_VA(this, file_name);
1220 SBSaveCoreOptions options;
1221 options.SetOutputFile(SBFileSpec(file_name));
1223 return SaveCore(options);
1224}
1225
1227 const char *flavor,
1228 SaveCoreStyle core_style) {
1229 LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
1230 SBSaveCoreOptions options;
1231 options.SetOutputFile(SBFileSpec(file_name));
1232 options.SetStyle(core_style);
1233 SBError error = options.SetPluginName(flavor);
1234 if (error.Fail())
1235 return error;
1236 return SaveCore(options);
1237}
1238
1240
1241 LLDB_INSTRUMENT_VA(this, options);
1242
1244 ProcessSP process_sp(GetSP());
1245 if (!process_sp) {
1246 error.SetErrorString("SBProcess is invalid");
1247 return error;
1248 }
1249
1250 std::lock_guard<std::recursive_mutex> guard(
1251 process_sp->GetTarget().GetAPIMutex());
1252
1253 if (process_sp->GetState() != eStateStopped) {
1254 error.SetErrorString("the process is not stopped");
1255 return error;
1256 }
1257
1258 error.ref() = PluginManager::SaveCore(process_sp, options.ref());
1259
1260 return error;
1261}
1262
1265 SBMemoryRegionInfo &sb_region_info) {
1266 LLDB_INSTRUMENT_VA(this, load_addr, sb_region_info);
1267
1268 lldb::SBError sb_error;
1269 ProcessSP process_sp(GetSP());
1270 if (process_sp) {
1271 Process::StopLocker stop_locker;
1272 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1273 std::lock_guard<std::recursive_mutex> guard(
1274 process_sp->GetTarget().GetAPIMutex());
1275
1276 sb_error.ref() =
1277 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
1278 } else {
1279 sb_error.SetErrorString("process is running");
1280 }
1281 } else {
1282 sb_error.SetErrorString("SBProcess is invalid");
1283 }
1284 return sb_error;
1285}
1286
1288 LLDB_INSTRUMENT_VA(this);
1289
1290 lldb::SBMemoryRegionInfoList sb_region_list;
1291
1292 ProcessSP process_sp(GetSP());
1293 Process::StopLocker stop_locker;
1294 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1295 std::lock_guard<std::recursive_mutex> guard(
1296 process_sp->GetTarget().GetAPIMutex());
1297
1298 process_sp->GetMemoryRegions(sb_region_list.ref());
1299 }
1300
1301 return sb_region_list;
1302}
1303
1305 LLDB_INSTRUMENT_VA(this);
1306
1307 lldb::SBProcessInfo sb_proc_info;
1308 ProcessSP process_sp(GetSP());
1309 ProcessInstanceInfo proc_info;
1310 if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1311 sb_proc_info.SetProcessInfo(proc_info);
1312 }
1313 return sb_proc_info;
1314}
1315
1317 LLDB_INSTRUMENT_VA(this);
1318
1319 ProcessSP process_sp(GetSP());
1320 FileSpec core_file;
1321 if (process_sp) {
1322 core_file = process_sp->GetCoreFile();
1323 }
1324 return SBFileSpec(core_file);
1325}
1326
1328 AddressMaskRange addr_range) {
1329 LLDB_INSTRUMENT_VA(this, type, addr_range);
1330
1331 if (ProcessSP process_sp = GetSP()) {
1332 switch (type) {
1334 if (addr_range == eAddressMaskRangeHigh)
1335 return process_sp->GetHighmemCodeAddressMask();
1336 else
1337 return process_sp->GetCodeAddressMask();
1339 if (addr_range == eAddressMaskRangeHigh)
1340 return process_sp->GetHighmemDataAddressMask();
1341 else
1342 return process_sp->GetDataAddressMask();
1344 if (addr_range == eAddressMaskRangeHigh)
1345 return process_sp->GetHighmemDataAddressMask();
1346 else
1347 return process_sp->GetDataAddressMask();
1348 }
1349 }
1351}
1352
1354 AddressMaskRange addr_range) {
1355 LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
1356
1357 if (ProcessSP process_sp = GetSP()) {
1358 switch (type) {
1360 if (addr_range == eAddressMaskRangeAll) {
1361 process_sp->SetCodeAddressMask(mask);
1362 process_sp->SetHighmemCodeAddressMask(mask);
1363 } else if (addr_range == eAddressMaskRangeHigh) {
1364 process_sp->SetHighmemCodeAddressMask(mask);
1365 } else {
1366 process_sp->SetCodeAddressMask(mask);
1367 }
1368 break;
1370 if (addr_range == eAddressMaskRangeAll) {
1371 process_sp->SetDataAddressMask(mask);
1372 process_sp->SetHighmemDataAddressMask(mask);
1373 } else if (addr_range == eAddressMaskRangeHigh) {
1374 process_sp->SetHighmemDataAddressMask(mask);
1375 } else {
1376 process_sp->SetDataAddressMask(mask);
1377 }
1378 break;
1380 if (addr_range == eAddressMaskRangeAll) {
1381 process_sp->SetCodeAddressMask(mask);
1382 process_sp->SetDataAddressMask(mask);
1383 process_sp->SetHighmemCodeAddressMask(mask);
1384 process_sp->SetHighmemDataAddressMask(mask);
1385 } else if (addr_range == eAddressMaskRangeHigh) {
1386 process_sp->SetHighmemCodeAddressMask(mask);
1387 process_sp->SetHighmemDataAddressMask(mask);
1388 } else {
1389 process_sp->SetCodeAddressMask(mask);
1390 process_sp->SetDataAddressMask(mask);
1391 }
1392 break;
1393 }
1394 }
1395}
1396
1398 AddressMaskRange addr_range) {
1399 LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
1400
1402 addr_range);
1403}
1404
1406 LLDB_INSTRUMENT_VA(this, addr, type);
1407
1408 if (ProcessSP process_sp = GetSP()) {
1409 if (type == eAddressMaskTypeAny)
1410 return process_sp->FixAnyAddress(addr);
1411 else if (type == eAddressMaskTypeData)
1412 return process_sp->FixDataAddress(addr);
1413 else if (type == eAddressMaskTypeCode)
1414 return process_sp->FixCodeAddress(addr);
1415 }
1416 return addr;
1417}
1418
1419lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1420 lldb::SBError &sb_error) {
1421 LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);
1422
1424 ProcessSP process_sp(GetSP());
1425 if (process_sp) {
1426 Process::StopLocker stop_locker;
1427 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1428 std::lock_guard<std::recursive_mutex> guard(
1429 process_sp->GetTarget().GetAPIMutex());
1430 addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1431 } else {
1432 sb_error.SetErrorString("process is running");
1433 }
1434 } else {
1435 sb_error.SetErrorString("SBProcess is invalid");
1436 }
1437 return addr;
1438}
1439
1441 LLDB_INSTRUMENT_VA(this, ptr);
1442
1443 lldb::SBError sb_error;
1444 ProcessSP process_sp(GetSP());
1445 if (process_sp) {
1446 Process::StopLocker stop_locker;
1447 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1448 std::lock_guard<std::recursive_mutex> guard(
1449 process_sp->GetTarget().GetAPIMutex());
1450 Status error = process_sp->DeallocateMemory(ptr);
1451 sb_error.SetError(error);
1452 } else {
1453 sb_error.SetErrorString("process is running");
1454 }
1455 } else {
1456 sb_error.SetErrorString("SBProcess is invalid");
1457 }
1458 return sb_error;
1459}
1460
1462 LLDB_INSTRUMENT_VA(this);
1463 ProcessSP process_sp(GetSP());
1464 return lldb::SBScriptObject((process_sp) ? process_sp->GetImplementation()
1465 : nullptr,
1467}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
std::unique_ptr< lldb_private::AddressRangeListImpl > m_opaque_up
lldb_private::AddressRangeListImpl & ref() const
lldb_private::AddressRange & ref() const
void AppendMessage(const char *message)
static const char * StateAsCString(lldb::StateType state)
Definition: SBDebugger.cpp:745
void SetErrorString(const char *err_str)
Definition: SBError.cpp:132
void SetError(uint32_t err, lldb::ErrorType type)
Definition: SBError.cpp:106
lldb_private::Status & ref()
Definition: SBError.cpp:167
lldb_private::Event * get() const
Definition: SBEvent.cpp:134
void reset(lldb::EventSP &event_sp)
Definition: SBEvent.cpp:145
lldb::EventSP & GetSP() const
Definition: SBEvent.cpp:132
uint32_t GetPath(char *dst_path, size_t dst_len) const
Definition: SBFileSpec.cpp:140
FileSP m_opaque_sp
Definition: SBFile.h:51
lldb_private::MemoryRegionInfos & ref()
lldb_private::MemoryRegionInfo & ref()
void SetProcessInfo(const lldb_private::ProcessInstanceInfo &proc_info_ref)
const lldb::SBProcess & operator=(const lldb::SBProcess &rhs)
Definition: SBProcess.cpp:69
static size_t GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:739
lldb::SBError SendEventData(const char *data)
Definition: SBProcess.cpp:1142
lldb::SBBroadcaster GetBroadcaster() const
Definition: SBProcess.cpp:797
lldb::SBError Detach()
Definition: SBProcess.cpp:630
lldb::SBThread GetThreadAtIndex(size_t index)
Definition: SBProcess.cpp:387
static const char * GetBroadcasterClassName()
Definition: SBProcess.cpp:80
void AppendEventStateReport(const lldb::SBEvent &event, lldb::SBCommandReturnObject &result)
Definition: SBProcess.cpp:331
lldb::SBError Continue()
Definition: SBProcess.cpp:565
uint32_t GetNumThreads()
Definition: SBProcess.cpp:187
uint32_t GetNumExtendedBacktraceTypes()
Return the number of different thread-origin extended backtraces this process can support.
Definition: SBProcess.cpp:1161
size_t PutSTDIN(const char *src, size_t src_len)
Definition: SBProcess.cpp:251
lldb::SBQueue GetQueueAtIndex(size_t index)
Definition: SBProcess.cpp:422
void ReportEventState(const lldb::SBEvent &event, FILE *out) const
Definition: SBProcess.cpp:309
lldb::SBFileSpec GetCoreFile()
Get the file specification for the core file that is currently being used for the process.
Definition: SBProcess.cpp:1316
const char * GetExitDescription()
Definition: SBProcess.cpp:510
lldb::SBThread GetThreadByIndexID(uint32_t index_id)
Definition: SBProcess.cpp:704
static const char * GetBroadcasterClass()
Definition: SBProcess.cpp:807
static lldb::SBStructuredData GetStructuredDataFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:775
lldb::ProcessSP GetSP() const
Definition: SBProcess.cpp:106
lldb::addr_t FindInMemory(const void *buf, uint64_t size, const SBAddressRange &range, uint32_t alignment, SBError &error)
Definition: SBProcess.cpp:838
lldb::pid_t GetProcessID()
Gets the process ID.
Definition: SBProcess.cpp:522
lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, lldb::SBError &error)
Allocate memory within the process.
Definition: SBProcess.cpp:1419
static bool EventIsStructuredDataEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:788
lldb::SBError UnloadImage(uint32_t image_token)
Definition: SBProcess.cpp:1121
lldb::SBProcessInfo GetProcessInfo()
Return information about the process.
Definition: SBProcess.cpp:1304
uint32_t GetUniqueID()
Gets the unique ID associated with this process object.
Definition: SBProcess.cpp:533
bool GetDescription(lldb::SBStream &description)
Definition: SBProcess.cpp:988
size_t GetAsyncProfileData(char *dst, size_t dst_len) const
Definition: SBProcess.cpp:290
lldb::addr_t FixAddress(lldb::addr_t addr, lldb::AddressMaskType type=lldb::eAddressMaskTypeAny)
Clear the non-address bits of an addr value and return a virtual address in memory.
Definition: SBProcess.cpp:1405
uint32_t GetNumQueues()
Definition: SBProcess.cpp:405
lldb::StateType GetState()
Definition: SBProcess.cpp:482
lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context)
Definition: SBProcess.cpp:220
lldb::SBError Destroy()
Definition: SBProcess.cpp:585
lldb::SBScriptObject GetScriptedImplementation()
Definition: SBProcess.cpp:1461
void GetStatus(SBStream &status)
Definition: SBProcess.cpp:980
lldb::ByteOrder GetByteOrder() const
Definition: SBProcess.cpp:543
size_t ReadCStringFromMemory(addr_t addr, void *char_buf, size_t size, lldb::SBError &error)
Definition: SBProcess.cpp:892
lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error)
Definition: SBProcess.cpp:936
lldb::SBError DeallocateMemory(lldb::addr_t ptr)
Deallocate memory in the process.
Definition: SBProcess.cpp:1440
static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:723
lldb::SBThread GetSelectedThread() const
Definition: SBProcess.cpp:204
bool SetSelectedThreadByIndexID(uint32_t index_id)
Definition: SBProcess.cpp:373
size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error)
Definition: SBProcess.cpp:862
const char * GetExtendedBacktraceTypeAtIndex(uint32_t idx)
Return the name of one of the thread-origin extended backtrace methods.
Definition: SBProcess.cpp:1172
lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id)
Definition: SBProcess.cpp:686
bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error)
Remote connection related functions.
Definition: SBProcess.cpp:164
lldb::SBTarget GetTarget() const
Definition: SBProcess.cpp:237
lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size, const SBAddressRangeList &ranges, uint32_t alignment, uint32_t max_matches, SBError &error)
Definition: SBProcess.cpp:813
const char * GetPluginName()
Definition: SBProcess.cpp:86
bool RemoteLaunch(char const **argv, char const **envp, const char *stdin_path, const char *stdout_path, const char *stderr_path, const char *working_directory, uint32_t launch_flags, bool stop_at_entry, lldb::SBError &error)
Definition: SBProcess.cpp:127
void SetAddressMask(lldb::AddressMaskType type, lldb::addr_t mask, lldb::AddressMaskRange addr_range=lldb::eAddressMaskRangeLow)
Set the current address mask that can be applied to addresses before reading from memory.
Definition: SBProcess.cpp:1353
size_t GetSTDOUT(char *dst, size_t dst_len) const
Definition: SBProcess.cpp:264
lldb::SBEvent GetStopEventForStopID(uint32_t stop_id)
Gets the stop event corresponding to stop ID.
Definition: SBProcess.cpp:456
lldb::SBError Signal(int signal)
Definition: SBProcess.cpp:653
static bool GetInterruptedFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:768
lldb::SBError Stop()
Definition: SBProcess.cpp:600
lldb::addr_t GetAddressMask(lldb::AddressMaskType type, lldb::AddressMaskRange addr_range=lldb::eAddressMaskRangeLow)
Get the current address mask that will be applied to addresses before reading from memory.
Definition: SBProcess.cpp:1327
lldb::ProcessWP m_opaque_wp
Definition: SBProcess.h:607
uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const
Definition: SBProcess.cpp:1036
uint32_t LoadImageUsingPaths(const lldb::SBFileSpec &image_spec, SBStringList &paths, lldb::SBFileSpec &loaded_path, lldb::SBError &error)
Load a shared library into this process, starting with a library name and a list of paths,...
Definition: SBProcess.cpp:1086
uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error)
Load a shared library into this process.
Definition: SBProcess.cpp:1056
void SetAddressableBits(AddressMaskType type, uint32_t num_bits, AddressMaskRange addr_range=lldb::eAddressMaskRangeLow)
Set the number of bits used for addressing in this Process.
Definition: SBProcess.cpp:1397
static const char * GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx)
Definition: SBProcess.cpp:746
lldb::SBUnixSignals GetUnixSignals()
Definition: SBProcess.cpp:668
lldb::SBError Kill()
Definition: SBProcess.cpp:615
lldb::SBThreadCollection GetHistoryThreads(addr_t addr)
Definition: SBProcess.cpp:1187
bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)
Definition: SBProcess.cpp:1198
bool SetSelectedThread(const lldb::SBThread &thread)
Definition: SBProcess.cpp:346
bool SetSelectedThreadByID(lldb::tid_t tid)
Definition: SBProcess.cpp:359
void SendAsyncInterrupt()
Definition: SBProcess.cpp:677
static bool GetRestartedFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:731
static bool EventIsProcessEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:781
lldb::SBError GetMemoryRegionInfo(lldb::addr_t load_addr, lldb::SBMemoryRegionInfo &region_info)
Query the address load_addr and store the details of the memory region that contains it in the suppli...
Definition: SBProcess.cpp:1264
void SetSP(const lldb::ProcessSP &process_sp)
Definition: SBProcess.cpp:108
size_t WriteMemory(addr_t addr, const void *buf, size_t size, lldb::SBError &error)
Definition: SBProcess.cpp:957
lldb::SBError SaveCore(const char *file_name, const char *flavor, SaveCoreStyle core_style)
Save the state of the process in a core file.
Definition: SBProcess.cpp:1226
lldb::SBMemoryRegionInfoList GetMemoryRegions()
Return the list of memory regions within the process.
Definition: SBProcess.cpp:1287
uint32_t GetAddressByteSize() const
Definition: SBProcess.cpp:554
SBStructuredData GetExtendedCrashInformation()
Definition: SBProcess.cpp:1012
uint32_t GetStopID(bool include_expression_stops=false)
Definition: SBProcess.cpp:441
uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size, lldb::SBError &error)
Definition: SBProcess.cpp:914
bool IsValid() const
Definition: SBProcess.cpp:116
void ForceScriptedState(StateType new_state)
If the process is a scripted process, changes its state to the new state.
Definition: SBProcess.cpp:472
static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event)
Definition: SBProcess.cpp:755
size_t GetSTDERR(char *dst, size_t dst_len) const
Definition: SBProcess.cpp:277
void SetQueue(const lldb::QueueSP &queue_sp)
Definition: SBQueue.cpp:254
void SetStyle(lldb::SaveCoreStyle style)
Set the Core dump style.
void SetOutputFile(SBFileSpec output_file)
lldb_private::SaveCoreOptions & ref() const
SBError SetPluginName(const char *plugin)
Set the plugin name.
lldb_private::Stream & ref()
Definition: SBStream.cpp:177
uint32_t GetSize() const
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
void SetSP(const lldb::TargetSP &target_sp)
Definition: SBTarget.cpp:587
lldb::SBFileSpec GetExecutable()
Definition: SBTarget.cpp:559
lldb::tid_t GetThreadID() const
Definition: SBThread.cpp:376
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition: SBThread.cpp:372
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits)
void AppendArguments(const Args &rhs)
Definition: Args.cpp:297
A uniqued constant string class.
Definition: ConstString.h:40
const char * AsCString(const char *value_if_empty=nullptr) const
Get the string value as a C string.
Definition: ConstString.h:188
const char * GetCString() const
Get the string value as a C string.
Definition: ConstString.h:216
static llvm::StringRef GetFlavorString()
Definition: Event.cpp:273
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition: Event.cpp:247
virtual llvm::StringRef GetFlavor() const =0
A file utility class.
Definition: FileSpec.h:56
const ConstString & GetFilename() const
Filename string const get accessor.
Definition: FileSpec.h:240
A class that describes an executable image and its associated object and symbol files.
Definition: Module.h:88
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition: Module.h:466
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition: Module.h:452
static Status SaveCore(const lldb::ProcessSP &process_sp, const lldb_private::SaveCoreOptions &core_options)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
Definition: ProcessInfo.cpp:65
void SetProcessID(lldb::pid_t pid)
Definition: ProcessInfo.h:70
Environment & GetEnvironment()
Definition: ProcessInfo.h:88
static bool GetRestartedFromEvent(const Event *event_ptr)
Definition: Process.cpp:4376
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition: Process.cpp:4360
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition: Process.cpp:4421
const char * GetRestartedReasonAtIndex(size_t idx)
Definition: Process.h:429
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition: Process.cpp:4368
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition: Process.cpp:4349
static llvm::StringRef GetStaticBroadcasterClass()
Definition: Process.cpp:440
An error handling class.
Definition: Status.h:44
A stream class that can stream formatted output to a file.
Definition: Stream.h:28
size_t Printf(const char *format,...) __attribute__((format(printf
Output printf formatted output to the stream.
Definition: Stream.cpp:134
size_t PutCString(llvm::StringRef cstr)
Output a C string to the stream.
Definition: Stream.cpp:65
std::shared_ptr< Object > ObjectSP
A plug-in interface definition class for system runtimes.
Definition: SystemRuntime.h:43
virtual const std::vector< ConstString > & GetExtendedBacktraceTypes()
Return a list of thread origin extended backtraces that may be available.
#define LLDB_INVALID_ADDRESS_MASK
Address Mask Bits not used for addressing are set to 1 in the mask; all mask bits set is an invalid v...
Definition: lldb-defines.h:133
#define LLDB_INVALID_IMAGE_TOKEN
Definition: lldb-defines.h:85
#define LLDB_INVALID_ADDRESS
Definition: lldb-defines.h:82
#define LLDB_INVALID_PROCESS_ID
Definition: lldb-defines.h:89
A class that represents a running process on the host machine.
const char * StateAsCString(lldb::StateType state)
Converts a StateType to a C string.
Definition: State.cpp:14
Definition: SBAddress.h:15
@ eScriptLanguageDefault
std::shared_ptr< lldb_private::Queue > QueueSP
Definition: lldb-forward.h:395
std::shared_ptr< lldb_private::Thread > ThreadSP
Definition: lldb-forward.h:445
AddressMaskRange
Used in the SBProcess AddressMask/FixAddress methods.
@ eAddressMaskRangeAll
@ eAddressMaskRangeHigh
std::shared_ptr< lldb_private::Platform > PlatformSP
Definition: lldb-forward.h:385
StateType
Process and Thread States.
@ eStateConnected
Process is connected to remote debug services, but not launched or attached to anything yet.
@ eStateStopped
Process or thread is stopped and can be examined.
std::shared_ptr< lldb_private::Process > ProcessSP
Definition: lldb-forward.h:386
InstrumentationRuntimeType
std::shared_ptr< lldb_private::Event > EventSP
Definition: lldb-forward.h:342
uint64_t pid_t
Definition: lldb-types.h:83
ByteOrder
Byte ordering definitions.
@ eByteOrderInvalid
uint64_t addr_t
Definition: lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
Definition: lldb-forward.h:443
AddressMaskType
Used in the SBProcess AddressMask/FixAddress methods.
@ eAddressMaskTypeData
@ eAddressMaskTypeAll
@ eAddressMaskTypeAny
@ eAddressMaskTypeCode
std::shared_ptr< lldb_private::File > FileSP
Definition: lldb-forward.h:350
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP
Definition: lldb-forward.h:357
uint64_t tid_t
Definition: lldb-types.h:84
#define PATH_MAX