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
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
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 {
156 "must be in eStateConnected to call RemoteLaunch");
157 }
158 } else {
159 error = Status::FromErrorString("unable to attach pid");
160 }
161
162 return error.Success();
163}
164
167 LLDB_INSTRUMENT_VA(this, pid, error);
168
169 ProcessSP process_sp(GetSP());
170 if (process_sp) {
171 std::lock_guard<std::recursive_mutex> guard(
172 process_sp->GetTarget().GetAPIMutex());
173 if (process_sp->GetState() == eStateConnected) {
174 ProcessAttachInfo attach_info;
175 attach_info.SetProcessID(pid);
176 error.SetError(process_sp->Attach(attach_info));
177 } else {
179 "must be in eStateConnected to call RemoteAttachToProcessWithID");
180 }
181 } else {
182 error = Status::FromErrorString("unable to attach pid");
183 }
184
185 return error.Success();
186}
187
189 LLDB_INSTRUMENT_VA(this);
190
191 uint32_t num_threads = 0;
192 ProcessSP process_sp(GetSP());
193 if (process_sp) {
194 Process::StopLocker stop_locker;
195
196 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
197 std::lock_guard<std::recursive_mutex> guard(
198 process_sp->GetTarget().GetAPIMutex());
199 num_threads = process_sp->GetThreadList().GetSize();
200 }
201 }
202
203 return num_threads;
204}
205
207 LLDB_INSTRUMENT_VA(this);
208
209 SBThread sb_thread;
210 ThreadSP thread_sp;
211 ProcessSP process_sp(GetSP());
212 if (process_sp) {
213 std::lock_guard<std::recursive_mutex> guard(
214 process_sp->GetTarget().GetAPIMutex());
215 thread_sp = process_sp->GetThreadList().GetSelectedThread();
216 sb_thread.SetThread(thread_sp);
217 }
218
219 return sb_thread;
220}
221
223 lldb::addr_t context) {
224 LLDB_INSTRUMENT_VA(this, tid, context);
225
226 SBThread sb_thread;
227 ThreadSP thread_sp;
228 ProcessSP process_sp(GetSP());
229 if (process_sp) {
230 std::lock_guard<std::recursive_mutex> guard(
231 process_sp->GetTarget().GetAPIMutex());
232 thread_sp = process_sp->CreateOSPluginThread(tid, context);
233 sb_thread.SetThread(thread_sp);
234 }
235
236 return sb_thread;
237}
238
240 LLDB_INSTRUMENT_VA(this);
241
242 SBTarget sb_target;
243 TargetSP target_sp;
244 ProcessSP process_sp(GetSP());
245 if (process_sp) {
246 target_sp = process_sp->GetTarget().shared_from_this();
247 sb_target.SetSP(target_sp);
248 }
249
250 return sb_target;
251}
252
253size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
254 LLDB_INSTRUMENT_VA(this, src, src_len);
255
256 size_t ret_val = 0;
257 ProcessSP process_sp(GetSP());
258 if (process_sp) {
260 ret_val = process_sp->PutSTDIN(src, src_len, error);
261 }
262
263 return ret_val;
264}
265
266size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
267 LLDB_INSTRUMENT_VA(this, dst, dst_len);
268
269 size_t bytes_read = 0;
270 ProcessSP process_sp(GetSP());
271 if (process_sp) {
273 bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
274 }
275
276 return bytes_read;
277}
278
279size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
280 LLDB_INSTRUMENT_VA(this, dst, dst_len);
281
282 size_t bytes_read = 0;
283 ProcessSP process_sp(GetSP());
284 if (process_sp) {
286 bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
287 }
288
289 return bytes_read;
290}
291
292size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
293 LLDB_INSTRUMENT_VA(this, dst, dst_len);
294
295 size_t bytes_read = 0;
296 ProcessSP process_sp(GetSP());
297 if (process_sp) {
299 bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
300 }
301
302 return bytes_read;
303}
304
305void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
306 LLDB_INSTRUMENT_VA(this, event, out);
307
308 return ReportEventState(event, out.m_opaque_sp);
309}
310
311void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
312 LLDB_INSTRUMENT_VA(this, event, out);
313 FileSP outfile = std::make_shared<NativeFile>(out, false);
314 return ReportEventState(event, outfile);
315}
316
317void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
318
319 LLDB_INSTRUMENT_VA(this, event, out);
320
321 if (!out || !out->IsValid())
322 return;
323
324 ProcessSP process_sp(GetSP());
325 if (process_sp) {
326 StreamFile stream(out);
327 const StateType event_state = SBProcess::GetStateFromEvent(event);
328 stream.Printf("Process %" PRIu64 " %s\n", process_sp->GetID(),
329 SBDebugger::StateAsCString(event_state));
330 }
331}
332
334 SBCommandReturnObject &result) {
335 LLDB_INSTRUMENT_VA(this, event, result);
336
337 ProcessSP process_sp(GetSP());
338 if (process_sp) {
339 const StateType event_state = SBProcess::GetStateFromEvent(event);
340 char message[1024];
341 ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
342 process_sp->GetID(), SBDebugger::StateAsCString(event_state));
343
344 result.AppendMessage(message);
345 }
346}
347
349 LLDB_INSTRUMENT_VA(this, thread);
350
351 ProcessSP process_sp(GetSP());
352 if (process_sp) {
353 std::lock_guard<std::recursive_mutex> guard(
354 process_sp->GetTarget().GetAPIMutex());
355 return process_sp->GetThreadList().SetSelectedThreadByID(
356 thread.GetThreadID());
357 }
358 return false;
359}
360
362 LLDB_INSTRUMENT_VA(this, tid);
363
364 bool ret_val = false;
365 ProcessSP process_sp(GetSP());
366 if (process_sp) {
367 std::lock_guard<std::recursive_mutex> guard(
368 process_sp->GetTarget().GetAPIMutex());
369 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
370 }
371
372 return ret_val;
373}
374
376 LLDB_INSTRUMENT_VA(this, index_id);
377
378 bool ret_val = false;
379 ProcessSP process_sp(GetSP());
380 if (process_sp) {
381 std::lock_guard<std::recursive_mutex> guard(
382 process_sp->GetTarget().GetAPIMutex());
383 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
384 }
385
386 return ret_val;
387}
388
390 LLDB_INSTRUMENT_VA(this, index);
391
392 SBThread sb_thread;
393 ThreadSP thread_sp;
394 ProcessSP process_sp(GetSP());
395 if (process_sp) {
396 Process::StopLocker stop_locker;
397 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
398 std::lock_guard<std::recursive_mutex> guard(
399 process_sp->GetTarget().GetAPIMutex());
400 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, false);
401 sb_thread.SetThread(thread_sp);
402 }
403 }
404
405 return sb_thread;
406}
407
409 LLDB_INSTRUMENT_VA(this);
410
411 uint32_t num_queues = 0;
412 ProcessSP process_sp(GetSP());
413 if (process_sp) {
414 Process::StopLocker stop_locker;
415 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
416 std::lock_guard<std::recursive_mutex> guard(
417 process_sp->GetTarget().GetAPIMutex());
418 num_queues = process_sp->GetQueueList().GetSize();
419 }
420 }
421
422 return num_queues;
423}
424
426 LLDB_INSTRUMENT_VA(this, index);
427
428 SBQueue sb_queue;
429 QueueSP queue_sp;
430 ProcessSP process_sp(GetSP());
431 if (process_sp) {
432 Process::StopLocker stop_locker;
433 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
434 std::lock_guard<std::recursive_mutex> guard(
435 process_sp->GetTarget().GetAPIMutex());
436 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
437 sb_queue.SetQueue(queue_sp);
438 }
439 }
440
441 return sb_queue;
442}
443
444uint32_t SBProcess::GetStopID(bool include_expression_stops) {
445 LLDB_INSTRUMENT_VA(this, include_expression_stops);
446
447 ProcessSP process_sp(GetSP());
448 if (process_sp) {
449 std::lock_guard<std::recursive_mutex> guard(
450 process_sp->GetTarget().GetAPIMutex());
451 if (include_expression_stops)
452 return process_sp->GetStopID();
453 else
454 return process_sp->GetLastNaturalStopID();
455 }
456 return 0;
457}
458
460 LLDB_INSTRUMENT_VA(this, stop_id);
461
462 SBEvent sb_event;
463 EventSP event_sp;
464 ProcessSP process_sp(GetSP());
465 if (process_sp) {
466 std::lock_guard<std::recursive_mutex> guard(
467 process_sp->GetTarget().GetAPIMutex());
468 event_sp = process_sp->GetStopEventForStopID(stop_id);
469 sb_event.reset(event_sp);
470 }
471
472 return sb_event;
473}
474
476 LLDB_INSTRUMENT_VA(this, new_state);
477
478 if (ProcessSP process_sp = GetSP()) {
479 std::lock_guard<std::recursive_mutex> guard(
480 process_sp->GetTarget().GetAPIMutex());
481 process_sp->ForceScriptedState(new_state);
482 }
483}
484
486 LLDB_INSTRUMENT_VA(this);
487
488 StateType ret_val = eStateInvalid;
489 ProcessSP process_sp(GetSP());
490 if (process_sp) {
491 std::lock_guard<std::recursive_mutex> guard(
492 process_sp->GetTarget().GetAPIMutex());
493 ret_val = process_sp->GetState();
494 }
495
496 return ret_val;
497}
498
500 LLDB_INSTRUMENT_VA(this);
501
502 int exit_status = 0;
503 ProcessSP process_sp(GetSP());
504 if (process_sp) {
505 std::lock_guard<std::recursive_mutex> guard(
506 process_sp->GetTarget().GetAPIMutex());
507 exit_status = process_sp->GetExitStatus();
508 }
509
510 return exit_status;
511}
512
514 LLDB_INSTRUMENT_VA(this);
515
516 ProcessSP process_sp(GetSP());
517 if (!process_sp)
518 return nullptr;
519
520 std::lock_guard<std::recursive_mutex> guard(
521 process_sp->GetTarget().GetAPIMutex());
522 return ConstString(process_sp->GetExitDescription()).GetCString();
523}
524
526 LLDB_INSTRUMENT_VA(this);
527
529 ProcessSP process_sp(GetSP());
530 if (process_sp)
531 ret_val = process_sp->GetID();
532
533 return ret_val;
534}
535
537 LLDB_INSTRUMENT_VA(this);
538
539 uint32_t ret_val = 0;
540 ProcessSP process_sp(GetSP());
541 if (process_sp)
542 ret_val = process_sp->GetUniqueID();
543 return ret_val;
544}
545
547 LLDB_INSTRUMENT_VA(this);
548
549 ByteOrder byteOrder = eByteOrderInvalid;
550 ProcessSP process_sp(GetSP());
551 if (process_sp)
552 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
553
554 return byteOrder;
555}
556
558 LLDB_INSTRUMENT_VA(this);
559
560 uint32_t size = 0;
561 ProcessSP process_sp(GetSP());
562 if (process_sp)
563 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
564
565 return size;
566}
567
569 LLDB_INSTRUMENT_VA(this);
570
571 SBError sb_error;
572 ProcessSP process_sp(GetSP());
573
574 if (process_sp) {
575 std::lock_guard<std::recursive_mutex> guard(
576 process_sp->GetTarget().GetAPIMutex());
577
578 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
579 sb_error.ref() = process_sp->Resume();
580 else
581 sb_error.ref() = process_sp->ResumeSynchronous(nullptr);
582 } else
583 sb_error = Status::FromErrorString("SBProcess is invalid");
584
585 return sb_error;
586}
587
589 if (ProcessSP process_sp = GetSP()) {
590 if (direction == RunDirection::eRunReverse &&
591 !process_sp->SupportsReverseDirection())
593 "{0} does not support reverse execution of processes",
594 GetPluginName());
595 process_sp->SetBaseDirection(direction);
596 }
597 return Continue();
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->Destroy(false));
609 } else
610 sb_error = Status::FromErrorString("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->Halt());
624 } else
625 sb_error = Status::FromErrorString("SBProcess is invalid");
626
627 return sb_error;
628}
629
631 LLDB_INSTRUMENT_VA(this);
632
633 SBError sb_error;
634 ProcessSP process_sp(GetSP());
635 if (process_sp) {
636 std::lock_guard<std::recursive_mutex> guard(
637 process_sp->GetTarget().GetAPIMutex());
638 sb_error.SetError(process_sp->Destroy(true));
639 } else
640 sb_error = Status::FromErrorString("SBProcess is invalid");
641
642 return sb_error;
643}
644
646 LLDB_INSTRUMENT_VA(this);
647
648 // FIXME: This should come from a process default.
649 bool keep_stopped = false;
650 return Detach(keep_stopped);
651}
652
653SBError SBProcess::Detach(bool keep_stopped) {
654 LLDB_INSTRUMENT_VA(this, keep_stopped);
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->Detach(keep_stopped));
662 } else
663 sb_error = Status::FromErrorString("SBProcess is invalid");
664
665 return sb_error;
666}
667
669 LLDB_INSTRUMENT_VA(this, signo);
670
671 SBError sb_error;
672 ProcessSP process_sp(GetSP());
673 if (process_sp) {
674 std::lock_guard<std::recursive_mutex> guard(
675 process_sp->GetTarget().GetAPIMutex());
676 sb_error.SetError(process_sp->Signal(signo));
677 } else
678 sb_error = Status::FromErrorString("SBProcess is invalid");
679
680 return sb_error;
681}
682
684 LLDB_INSTRUMENT_VA(this);
685
686 if (auto process_sp = GetSP())
687 return SBUnixSignals{process_sp};
688
689 return SBUnixSignals{};
690}
691
693 LLDB_INSTRUMENT_VA(this);
694
695 ProcessSP process_sp(GetSP());
696 if (process_sp) {
697 process_sp->SendAsyncInterrupt();
698 }
699}
700
702 LLDB_INSTRUMENT_VA(this, tid);
703
704 SBThread sb_thread;
705 ThreadSP thread_sp;
706 ProcessSP process_sp(GetSP());
707 if (process_sp) {
708 Process::StopLocker stop_locker;
709 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
710 std::lock_guard<std::recursive_mutex> guard(
711 process_sp->GetTarget().GetAPIMutex());
712 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
713 sb_thread.SetThread(thread_sp);
714 }
715
716 return sb_thread;
717}
718
720 LLDB_INSTRUMENT_VA(this, index_id);
721
722 SBThread sb_thread;
723 ThreadSP thread_sp;
724 ProcessSP process_sp(GetSP());
725 if (process_sp) {
726 Process::StopLocker stop_locker;
727 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
728 std::lock_guard<std::recursive_mutex> guard(
729 process_sp->GetTarget().GetAPIMutex());
730 thread_sp =
731 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
732 sb_thread.SetThread(thread_sp);
733 }
734
735 return sb_thread;
736}
737
739 LLDB_INSTRUMENT_VA(event);
740
742
743 return ret_val;
744}
745
747 LLDB_INSTRUMENT_VA(event);
748
750
751 return ret_val;
752}
753
759
760const char *
762 size_t idx) {
763 LLDB_INSTRUMENT_VA(event, idx);
764
766 event.get(), idx))
767 .GetCString();
768}
769
771 LLDB_INSTRUMENT_VA(event);
772
773 ProcessSP process_sp =
775 if (!process_sp) {
776 // StructuredData events also know the process they come from. Try that.
778 }
779
780 return SBProcess(process_sp);
781}
782
788
791 LLDB_INSTRUMENT_VA(event);
792
793 return SBStructuredData(event.GetSP());
794}
795
797 LLDB_INSTRUMENT_VA(event);
798
800 nullptr;
801}
802
804 LLDB_INSTRUMENT_VA(event);
805
806 EventSP event_sp = event.GetSP();
807 EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
808 return event_data && (event_data->GetFlavor() ==
810}
811
813 LLDB_INSTRUMENT_VA(this);
814
815 ProcessSP process_sp(GetSP());
816
817 SBBroadcaster broadcaster(process_sp.get(), false);
818
819 return broadcaster;
820}
821
827
829 const void *buf, uint64_t size, const SBAddressRangeList &ranges,
830 uint32_t alignment, uint32_t max_matches, SBError &error) {
831 LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
832
834
835 ProcessSP process_sp(GetSP());
836 if (!process_sp) {
837 error = Status::FromErrorString("SBProcess is invalid");
838 return matches;
839 }
840 Process::StopLocker stop_locker;
841 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
842 error = Status::FromErrorString("process is running");
843 return matches;
844 }
845 std::lock_guard<std::recursive_mutex> guard(
846 process_sp->GetTarget().GetAPIMutex());
847 matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
848 reinterpret_cast<const uint8_t *>(buf), size, ranges.ref().ref(),
849 alignment, max_matches, error.ref());
850 return matches;
851}
852
853lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
854 const SBAddressRange &range,
855 uint32_t alignment, SBError &error) {
856 LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
857
858 ProcessSP process_sp(GetSP());
859
860 if (!process_sp) {
861 error = Status::FromErrorString("SBProcess is invalid");
863 }
864
865 Process::StopLocker stop_locker;
866 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
867 error = Status::FromErrorString("process is running");
869 }
870
871 std::lock_guard<std::recursive_mutex> guard(
872 process_sp->GetTarget().GetAPIMutex());
873 return process_sp->FindInMemory(reinterpret_cast<const uint8_t *>(buf), size,
874 range.ref(), alignment, error.ref());
875}
876
877size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
878 SBError &sb_error) {
879 LLDB_INSTRUMENT_VA(this, addr, dst, dst_len, sb_error);
880
881 if (!dst) {
883 "no buffer provided to read %zu bytes into", dst_len);
884 return 0;
885 }
886
887 size_t bytes_read = 0;
888 ProcessSP process_sp(GetSP());
889
890
891 if (process_sp) {
892 Process::StopLocker stop_locker;
893 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
894 std::lock_guard<std::recursive_mutex> guard(
895 process_sp->GetTarget().GetAPIMutex());
896 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
897 } else {
898 sb_error = Status::FromErrorString("process is running");
899 }
900 } else {
901 sb_error = Status::FromErrorString("SBProcess is invalid");
902 }
903
904 return bytes_read;
905}
906
907size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
908 lldb::SBError &sb_error) {
909 LLDB_INSTRUMENT_VA(this, addr, buf, size, sb_error);
910
911 size_t bytes_read = 0;
912 ProcessSP process_sp(GetSP());
913 if (process_sp) {
914 Process::StopLocker stop_locker;
915 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
916 std::lock_guard<std::recursive_mutex> guard(
917 process_sp->GetTarget().GetAPIMutex());
918 bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
919 sb_error.ref());
920 } else {
921 sb_error = Status::FromErrorString("process is running");
922 }
923 } else {
924 sb_error = Status::FromErrorString("SBProcess is invalid");
925 }
926 return bytes_read;
927}
928
929uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
930 lldb::SBError &sb_error) {
931 LLDB_INSTRUMENT_VA(this, addr, byte_size, sb_error);
932
933 uint64_t value = 0;
934 ProcessSP process_sp(GetSP());
935 if (process_sp) {
936 Process::StopLocker stop_locker;
937 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
938 std::lock_guard<std::recursive_mutex> guard(
939 process_sp->GetTarget().GetAPIMutex());
940 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
941 sb_error.ref());
942 } else {
943 sb_error = Status::FromErrorString("process is running");
944 }
945 } else {
946 sb_error = Status::FromErrorString("SBProcess is invalid");
947 }
948 return value;
949}
950
952 lldb::SBError &sb_error) {
953 LLDB_INSTRUMENT_VA(this, addr, sb_error);
954
956 ProcessSP process_sp(GetSP());
957 if (process_sp) {
958 Process::StopLocker stop_locker;
959 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
960 std::lock_guard<std::recursive_mutex> guard(
961 process_sp->GetTarget().GetAPIMutex());
962 ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref());
963 } else {
964 sb_error = Status::FromErrorString("process is running");
965 }
966 } else {
967 sb_error = Status::FromErrorString("SBProcess is invalid");
968 }
969 return ptr;
970}
971
972size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
973 SBError &sb_error) {
974 LLDB_INSTRUMENT_VA(this, addr, src, src_len, sb_error);
975
976 size_t bytes_written = 0;
977
978 ProcessSP process_sp(GetSP());
979
980 if (process_sp) {
981 Process::StopLocker stop_locker;
982 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
983 std::lock_guard<std::recursive_mutex> guard(
984 process_sp->GetTarget().GetAPIMutex());
985 bytes_written =
986 process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
987 } else {
988 sb_error = Status::FromErrorString("process is running");
989 }
990 }
991
992 return bytes_written;
993}
994
996 LLDB_INSTRUMENT_VA(this, status);
997
998 ProcessSP process_sp(GetSP());
999 if (process_sp)
1000 process_sp->GetStatus(status.ref());
1001}
1002
1004 LLDB_INSTRUMENT_VA(this, description);
1005
1006 Stream &strm = description.ref();
1007
1008 ProcessSP process_sp(GetSP());
1009 if (process_sp) {
1010 char path[PATH_MAX];
1011 GetTarget().GetExecutable().GetPath(path, sizeof(path));
1012 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1013 const char *exe_name = nullptr;
1014 if (exe_module)
1015 exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1016
1017 strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1018 process_sp->GetID(), lldb_private::StateAsCString(GetState()),
1019 GetNumThreads(), exe_name ? ", executable = " : "",
1020 exe_name ? exe_name : "");
1021 } else
1022 strm.PutCString("No value");
1023
1024 return true;
1025}
1026
1028 LLDB_INSTRUMENT_VA(this);
1029 SBStructuredData data;
1030 ProcessSP process_sp(GetSP());
1031 if (!process_sp)
1032 return data;
1033
1034 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1035
1036 if (!platform_sp)
1037 return data;
1038
1039 auto expected_data =
1040 platform_sp->FetchExtendedCrashInformation(*process_sp.get());
1041
1042 if (!expected_data)
1043 return data;
1044
1045 StructuredData::ObjectSP fetched_data = *expected_data;
1046 data.m_impl_up->SetObjectSP(fetched_data);
1047 return data;
1048}
1049
1050uint32_t
1052 LLDB_INSTRUMENT_VA(this, sb_error);
1053
1054 uint32_t num = 0;
1055 ProcessSP process_sp(GetSP());
1056 if (process_sp) {
1057 std::lock_guard<std::recursive_mutex> guard(
1058 process_sp->GetTarget().GetAPIMutex());
1059 std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
1060 if (actual_num) {
1061 num = *actual_num;
1062 } else {
1063 sb_error =
1064 Status::FromErrorString("Unable to determine number of watchpoints");
1065 }
1066 } else {
1067 sb_error = Status::FromErrorString("SBProcess is invalid");
1068 }
1069 return num;
1070}
1071
1072uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
1073 lldb::SBError &sb_error) {
1074 LLDB_INSTRUMENT_VA(this, sb_remote_image_spec, sb_error);
1075
1076 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
1077}
1078
1079uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
1080 const lldb::SBFileSpec &sb_remote_image_spec,
1081 lldb::SBError &sb_error) {
1082 LLDB_INSTRUMENT_VA(this, sb_local_image_spec, sb_remote_image_spec, sb_error);
1083
1084 ProcessSP process_sp(GetSP());
1085 if (process_sp) {
1086 Process::StopLocker stop_locker;
1087 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1088 std::lock_guard<std::recursive_mutex> guard(
1089 process_sp->GetTarget().GetAPIMutex());
1090 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1091 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1092 *sb_remote_image_spec, sb_error.ref());
1093 } else {
1094 sb_error = Status::FromErrorString("process is running");
1095 }
1096 } else {
1097 sb_error = Status::FromErrorString("process is invalid");
1098 }
1100}
1101
1103 SBStringList &paths,
1104 lldb::SBFileSpec &loaded_path,
1106 LLDB_INSTRUMENT_VA(this, image_spec, paths, loaded_path, error);
1107
1108 ProcessSP process_sp(GetSP());
1109 if (process_sp) {
1110 Process::StopLocker stop_locker;
1111 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1112 std::lock_guard<std::recursive_mutex> guard(
1113 process_sp->GetTarget().GetAPIMutex());
1114 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1115 size_t num_paths = paths.GetSize();
1116 std::vector<std::string> paths_vec;
1117 paths_vec.reserve(num_paths);
1118 for (size_t i = 0; i < num_paths; i++)
1119 paths_vec.push_back(paths.GetStringAtIndex(i));
1120 FileSpec loaded_spec;
1121
1122 uint32_t token = platform_sp->LoadImageUsingPaths(
1123 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
1124 if (token != LLDB_INVALID_IMAGE_TOKEN)
1125 loaded_path = loaded_spec;
1126 return token;
1127 } else {
1128 error = Status::FromErrorString("process is running");
1129 }
1130 } else {
1131 error = Status::FromErrorString("process is invalid");
1132 }
1133
1135}
1136
1138 LLDB_INSTRUMENT_VA(this, image_token);
1139
1140 lldb::SBError sb_error;
1141 ProcessSP process_sp(GetSP());
1142 if (process_sp) {
1143 Process::StopLocker stop_locker;
1144 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1145 std::lock_guard<std::recursive_mutex> guard(
1146 process_sp->GetTarget().GetAPIMutex());
1147 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1148 sb_error.SetError(
1149 platform_sp->UnloadImage(process_sp.get(), image_token));
1150 } else {
1151 sb_error = Status::FromErrorString("process is running");
1152 }
1153 } else
1154 sb_error = Status::FromErrorString("invalid process");
1155 return sb_error;
1156}
1157
1159 LLDB_INSTRUMENT_VA(this, event_data);
1160
1161 lldb::SBError sb_error;
1162 ProcessSP process_sp(GetSP());
1163 if (process_sp) {
1164 Process::StopLocker stop_locker;
1165 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1166 std::lock_guard<std::recursive_mutex> guard(
1167 process_sp->GetTarget().GetAPIMutex());
1168 sb_error.SetError(process_sp->SendEventData(event_data));
1169 } else {
1170 sb_error = Status::FromErrorString("process is running");
1171 }
1172 } else
1173 sb_error = Status::FromErrorString("invalid process");
1174 return sb_error;
1175}
1176
1178 LLDB_INSTRUMENT_VA(this);
1179
1180 ProcessSP process_sp(GetSP());
1181 if (process_sp && process_sp->GetSystemRuntime()) {
1182 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1183 return runtime->GetExtendedBacktraceTypes().size();
1184 }
1185 return 0;
1186}
1187
1189 LLDB_INSTRUMENT_VA(this, idx);
1190
1191 ProcessSP process_sp(GetSP());
1192 if (process_sp && process_sp->GetSystemRuntime()) {
1193 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1194 const std::vector<ConstString> &names =
1195 runtime->GetExtendedBacktraceTypes();
1196 if (idx < names.size()) {
1197 return names[idx].AsCString();
1198 }
1199 }
1200 return nullptr;
1201}
1202
1204 LLDB_INSTRUMENT_VA(this, addr);
1205
1206 ProcessSP process_sp(GetSP());
1207 SBThreadCollection threads;
1208 if (process_sp) {
1209 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1210 }
1211 return threads;
1212}
1213
1216 LLDB_INSTRUMENT_VA(this, type);
1217
1218 ProcessSP process_sp(GetSP());
1219 if (!process_sp)
1220 return false;
1221
1222 std::lock_guard<std::recursive_mutex> guard(
1223 process_sp->GetTarget().GetAPIMutex());
1224
1225 InstrumentationRuntimeSP runtime_sp =
1226 process_sp->GetInstrumentationRuntime(type);
1227
1228 if (!runtime_sp.get())
1229 return false;
1230
1231 return runtime_sp->IsActive();
1232}
1233
1234lldb::SBError SBProcess::SaveCore(const char *file_name) {
1235 LLDB_INSTRUMENT_VA(this, file_name);
1236 SBSaveCoreOptions options;
1237 options.SetOutputFile(SBFileSpec(file_name));
1239 return SaveCore(options);
1240}
1241
1243 const char *flavor,
1244 SaveCoreStyle core_style) {
1245 LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
1246 SBSaveCoreOptions options;
1247 options.SetOutputFile(SBFileSpec(file_name));
1248 options.SetStyle(core_style);
1249 SBError error = options.SetPluginName(flavor);
1250 if (error.Fail())
1251 return error;
1252 return SaveCore(options);
1253}
1254
1256
1257 LLDB_INSTRUMENT_VA(this, options);
1258
1260 ProcessSP process_sp(GetSP());
1261 if (!process_sp) {
1262 error = Status::FromErrorString("SBProcess is invalid");
1263 return error;
1264 }
1265
1266 if (!options.GetProcess())
1267 options.SetProcess(process_sp);
1268
1269 if (options.GetProcess().GetSP() != process_sp) {
1271 "Save Core Options configured for a different process.");
1272 return error;
1273 }
1274
1275 std::lock_guard<std::recursive_mutex> guard(
1276 process_sp->GetTarget().GetAPIMutex());
1277
1278 if (process_sp->GetState() != eStateStopped) {
1279 error = Status::FromErrorString("the process is not stopped");
1280 return error;
1281 }
1282
1283 error.ref() = PluginManager::SaveCore(options.ref());
1284
1285 return error;
1286}
1287
1290 SBMemoryRegionInfo &sb_region_info) {
1291 LLDB_INSTRUMENT_VA(this, load_addr, sb_region_info);
1292
1293 lldb::SBError sb_error;
1294 ProcessSP process_sp(GetSP());
1295 if (process_sp) {
1296 Process::StopLocker stop_locker;
1297 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1298 std::lock_guard<std::recursive_mutex> guard(
1299 process_sp->GetTarget().GetAPIMutex());
1300
1301 sb_error.ref() =
1302 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
1303 } else {
1304 sb_error = Status::FromErrorString("process is running");
1305 }
1306 } else {
1307 sb_error = Status::FromErrorString("SBProcess is invalid");
1308 }
1309 return sb_error;
1310}
1311
1313 LLDB_INSTRUMENT_VA(this);
1314
1315 lldb::SBMemoryRegionInfoList sb_region_list;
1316
1317 ProcessSP process_sp(GetSP());
1318 Process::StopLocker stop_locker;
1319 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1320 std::lock_guard<std::recursive_mutex> guard(
1321 process_sp->GetTarget().GetAPIMutex());
1322
1323 process_sp->GetMemoryRegions(sb_region_list.ref());
1324 }
1325
1326 return sb_region_list;
1327}
1328
1330 LLDB_INSTRUMENT_VA(this);
1331
1332 lldb::SBProcessInfo sb_proc_info;
1333 ProcessSP process_sp(GetSP());
1334 ProcessInstanceInfo proc_info;
1335 if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1336 sb_proc_info.SetProcessInfo(proc_info);
1337 }
1338 return sb_proc_info;
1339}
1340
1342 LLDB_INSTRUMENT_VA(this);
1343
1344 ProcessSP process_sp(GetSP());
1345 FileSpec core_file;
1346 if (process_sp) {
1347 core_file = process_sp->GetCoreFile();
1348 }
1349 return SBFileSpec(core_file);
1350}
1351
1353 AddressMaskRange addr_range) {
1354 LLDB_INSTRUMENT_VA(this, type, addr_range);
1355
1356 if (ProcessSP process_sp = GetSP()) {
1357 switch (type) {
1359 if (addr_range == eAddressMaskRangeHigh)
1360 return process_sp->GetHighmemCodeAddressMask();
1361 else
1362 return process_sp->GetCodeAddressMask();
1364 if (addr_range == eAddressMaskRangeHigh)
1365 return process_sp->GetHighmemDataAddressMask();
1366 else
1367 return process_sp->GetDataAddressMask();
1369 if (addr_range == eAddressMaskRangeHigh)
1370 return process_sp->GetHighmemDataAddressMask();
1371 else
1372 return process_sp->GetDataAddressMask();
1373 }
1374 }
1376}
1377
1379 AddressMaskRange addr_range) {
1380 LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
1381
1382 if (ProcessSP process_sp = GetSP()) {
1383 switch (type) {
1385 if (addr_range == eAddressMaskRangeAll) {
1386 process_sp->SetCodeAddressMask(mask);
1387 process_sp->SetHighmemCodeAddressMask(mask);
1388 } else if (addr_range == eAddressMaskRangeHigh) {
1389 process_sp->SetHighmemCodeAddressMask(mask);
1390 } else {
1391 process_sp->SetCodeAddressMask(mask);
1392 }
1393 break;
1395 if (addr_range == eAddressMaskRangeAll) {
1396 process_sp->SetDataAddressMask(mask);
1397 process_sp->SetHighmemDataAddressMask(mask);
1398 } else if (addr_range == eAddressMaskRangeHigh) {
1399 process_sp->SetHighmemDataAddressMask(mask);
1400 } else {
1401 process_sp->SetDataAddressMask(mask);
1402 }
1403 break;
1405 if (addr_range == eAddressMaskRangeAll) {
1406 process_sp->SetCodeAddressMask(mask);
1407 process_sp->SetDataAddressMask(mask);
1408 process_sp->SetHighmemCodeAddressMask(mask);
1409 process_sp->SetHighmemDataAddressMask(mask);
1410 } else if (addr_range == eAddressMaskRangeHigh) {
1411 process_sp->SetHighmemCodeAddressMask(mask);
1412 process_sp->SetHighmemDataAddressMask(mask);
1413 } else {
1414 process_sp->SetCodeAddressMask(mask);
1415 process_sp->SetDataAddressMask(mask);
1416 }
1417 break;
1418 }
1419 }
1420}
1421
1423 AddressMaskRange addr_range) {
1424 LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
1425
1427 addr_range);
1428}
1429
1431 LLDB_INSTRUMENT_VA(this, addr, type);
1432
1433 if (ProcessSP process_sp = GetSP()) {
1434 if (type == eAddressMaskTypeAny)
1435 return process_sp->FixAnyAddress(addr);
1436 else if (type == eAddressMaskTypeData)
1437 return process_sp->FixDataAddress(addr);
1438 else if (type == eAddressMaskTypeCode)
1439 return process_sp->FixCodeAddress(addr);
1440 }
1441 return addr;
1442}
1443
1444lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1445 lldb::SBError &sb_error) {
1446 LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);
1447
1449 ProcessSP process_sp(GetSP());
1450 if (process_sp) {
1451 Process::StopLocker stop_locker;
1452 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1453 std::lock_guard<std::recursive_mutex> guard(
1454 process_sp->GetTarget().GetAPIMutex());
1455 addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1456 } else {
1457 sb_error = Status::FromErrorString("process is running");
1458 }
1459 } else {
1460 sb_error = Status::FromErrorString("SBProcess is invalid");
1461 }
1462 return addr;
1463}
1464
1466 LLDB_INSTRUMENT_VA(this, ptr);
1467
1468 lldb::SBError sb_error;
1469 ProcessSP process_sp(GetSP());
1470 if (process_sp) {
1471 Process::StopLocker stop_locker;
1472 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1473 std::lock_guard<std::recursive_mutex> guard(
1474 process_sp->GetTarget().GetAPIMutex());
1475 Status error = process_sp->DeallocateMemory(ptr);
1476 sb_error.SetError(std::move(error));
1477 } else {
1478 sb_error = Status::FromErrorString("process is running");
1479 }
1480 } else {
1481 sb_error = Status::FromErrorString("SBProcess is invalid");
1482 }
1483 return sb_error;
1484}
1485
1487 LLDB_INSTRUMENT_VA(this);
1488 ProcessSP process_sp(GetSP());
1489 return lldb::SBScriptObject((process_sp) ? process_sp->GetImplementation()
1490 : nullptr,
1492}
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)
Convert a state type to a string.
void SetError(uint32_t err, lldb::ErrorType type)
Definition SBError.cpp:124
lldb_private::Status & ref()
Definition SBError.cpp:191
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
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)
lldb::SBError SendEventData(const char *data)
lldb::SBBroadcaster GetBroadcaster() const
lldb::SBError Detach()
lldb::SBThread GetThreadAtIndex(size_t index)
static const char * GetBroadcasterClassName()
Definition SBProcess.cpp:80
void AppendEventStateReport(const lldb::SBEvent &event, lldb::SBCommandReturnObject &result)
lldb::SBError Continue()
uint32_t GetNumThreads()
uint32_t GetNumExtendedBacktraceTypes()
Return the number of different thread-origin extended backtraces this process can support.
size_t PutSTDIN(const char *src, size_t src_len)
lldb::SBQueue GetQueueAtIndex(size_t index)
void ReportEventState(const lldb::SBEvent &event, FILE *out) const
lldb::SBFileSpec GetCoreFile()
Get the file specification for the core file that is currently being used for the process.
const char * GetExitDescription()
lldb::SBThread GetThreadByIndexID(uint32_t index_id)
static const char * GetBroadcasterClass()
static lldb::SBStructuredData GetStructuredDataFromEvent(const lldb::SBEvent &event)
friend class SBSaveCoreOptions
Definition SBProcess.h:590
lldb::ProcessSP GetSP() const
lldb::addr_t FindInMemory(const void *buf, uint64_t size, const SBAddressRange &range, uint32_t alignment, SBError &error)
lldb::pid_t GetProcessID()
Gets the process ID.
lldb::addr_t AllocateMemory(size_t size, uint32_t permissions, lldb::SBError &error)
Allocate memory within the process.
static bool EventIsStructuredDataEvent(const lldb::SBEvent &event)
lldb::SBError UnloadImage(uint32_t image_token)
lldb::SBProcessInfo GetProcessInfo()
Return information about the process.
uint32_t GetUniqueID()
Gets the unique ID associated with this process object.
bool GetDescription(lldb::SBStream &description)
size_t GetAsyncProfileData(char *dst, size_t dst_len) const
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.
friend class SBTarget
Definition SBProcess.h:596
uint32_t GetNumQueues()
lldb::StateType GetState()
lldb::SBThread CreateOSPluginThread(lldb::tid_t tid, lldb::addr_t context)
lldb::SBError Destroy()
lldb::SBScriptObject GetScriptedImplementation()
void GetStatus(SBStream &status)
lldb::ByteOrder GetByteOrder() const
size_t ReadCStringFromMemory(addr_t addr, void *char_buf, size_t size, lldb::SBError &error)
lldb::addr_t ReadPointerFromMemory(addr_t addr, lldb::SBError &error)
lldb::SBError DeallocateMemory(lldb::addr_t ptr)
Deallocate memory in the process.
static lldb::StateType GetStateFromEvent(const lldb::SBEvent &event)
lldb::SBThread GetSelectedThread() const
bool SetSelectedThreadByIndexID(uint32_t index_id)
size_t ReadMemory(addr_t addr, void *buf, size_t size, lldb::SBError &error)
const char * GetExtendedBacktraceTypeAtIndex(uint32_t idx)
Return the name of one of the thread-origin extended backtrace methods.
lldb::SBThread GetThreadByID(lldb::tid_t sb_thread_id)
bool RemoteAttachToProcessWithID(lldb::pid_t pid, lldb::SBError &error)
Remote connection related functions.
lldb::SBTarget GetTarget() const
lldb::SBAddressRangeList FindRangesInMemory(const void *buf, uint64_t size, const SBAddressRangeList &ranges, uint32_t alignment, uint32_t max_matches, SBError &error)
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)
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.
size_t GetSTDOUT(char *dst, size_t dst_len) const
lldb::SBEvent GetStopEventForStopID(uint32_t stop_id)
Gets the stop event corresponding to stop ID.
lldb::SBError Signal(int signal)
friend class SBThread
Definition SBProcess.h:597
static bool GetInterruptedFromEvent(const lldb::SBEvent &event)
lldb::SBError Stop()
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.
lldb::ProcessWP m_opaque_wp
Definition SBProcess.h:609
uint32_t GetNumSupportedHardwareWatchpoints(lldb::SBError &error) const
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,...
uint32_t LoadImage(lldb::SBFileSpec &remote_image_spec, lldb::SBError &error)
Load a shared library into this process.
void SetAddressableBits(AddressMaskType type, uint32_t num_bits, AddressMaskRange addr_range=lldb::eAddressMaskRangeLow)
Set the number of bits used for addressing in this Process.
static const char * GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event, size_t idx)
lldb::SBUnixSignals GetUnixSignals()
lldb::SBError Kill()
lldb::SBThreadCollection GetHistoryThreads(addr_t addr)
bool IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)
bool SetSelectedThread(const lldb::SBThread &thread)
bool SetSelectedThreadByID(lldb::tid_t tid)
void SendAsyncInterrupt()
static bool GetRestartedFromEvent(const lldb::SBEvent &event)
static bool EventIsProcessEvent(const lldb::SBEvent &event)
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...
void SetSP(const lldb::ProcessSP &process_sp)
size_t WriteMemory(addr_t addr, const void *buf, size_t size, lldb::SBError &error)
lldb::SBError SaveCore(const char *file_name, const char *flavor, SaveCoreStyle core_style)
Save the state of the process in a core file.
lldb::SBMemoryRegionInfoList GetMemoryRegions()
Return the list of memory regions within the process.
lldb::SBError ContinueInDirection(lldb::RunDirection direction)
uint32_t GetAddressByteSize() const
SBStructuredData GetExtendedCrashInformation()
uint32_t GetStopID(bool include_expression_stops=false)
uint64_t ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size, lldb::SBError &error)
bool IsValid() const
void ForceScriptedState(StateType new_state)
If the process is a scripted process, changes its state to the new state.
static lldb::SBProcess GetProcessFromEvent(const lldb::SBEvent &event)
size_t GetSTDERR(char *dst, size_t dst_len) const
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)
Set the output file path.
lldb_private::SaveCoreOptions & ref() const
SBError SetProcess(lldb::SBProcess process)
Set the process to save, or unset if supplied with a default constructed process.
SBProcess GetProcess()
Get the process to save, if the process is not set an invalid SBProcess will be returned.
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:580
lldb::SBFileSpec GetExecutable()
Definition SBTarget.cpp:553
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition SBThread.cpp:291
static lldb::addr_t AddressableBitToMask(uint32_t addressable_bits)
void AppendArguments(const Args &rhs)
Definition Args.cpp:307
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.
const char * GetCString() const
Get the string value as a C string.
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:57
const ConstString & GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:251
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:90
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition Module.h:468
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:454
static Status SaveCore(lldb_private::SaveCoreOptions &core_options)
void SetExecutableFile(const FileSpec &exe_file, bool add_exe_file_as_first_arg)
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:4420
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Process.cpp:4404
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition Process.cpp:4465
const char * GetRestartedReasonAtIndex(size_t idx)
Definition Process.h:445
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition Process.cpp:4412
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Process.cpp:4393
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:396
static llvm::StringRef GetStaticBroadcasterClass()
Definition Process.cpp:422
An error handling class.
Definition Status.h:118
static Status FromErrorStringWithFormat(const char *format,...) __attribute__((format(printf
Definition Status.cpp:106
static Status FromErrorString(const char *str)
Definition Status.h:141
static Status static Status FromErrorStringWithFormatv(const char *format, Args &&...args)
Definition Status.h:151
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.
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...
#define LLDB_INVALID_IMAGE_TOKEN
#define LLDB_INVALID_ADDRESS
#define LLDB_INVALID_PROCESS_ID
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
@ eScriptLanguageDefault
std::shared_ptr< lldb_private::Queue > QueueSP
class LLDB_API SBFileSpec
Definition SBDefines.h:75
class LLDB_API SBStructuredData
Definition SBDefines.h:110
RunDirection
Execution directions.
std::shared_ptr< lldb_private::Thread > ThreadSP
AddressMaskRange
Used in the SBProcess AddressMask/FixAddress methods.
@ eAddressMaskRangeHigh
class LLDB_API SBScriptObject
Definition SBDefines.h:104
std::shared_ptr< lldb_private::Platform > PlatformSP
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
class LLDB_API SBThreadCollection
Definition SBDefines.h:116
InstrumentationRuntimeType
std::shared_ptr< lldb_private::Event > EventSP
uint64_t pid_t
Definition lldb-types.h:83
ByteOrder
Byte ordering definitions.
uint64_t addr_t
Definition lldb-types.h:80
std::shared_ptr< lldb_private::Target > TargetSP
AddressMaskType
Used in the SBProcess AddressMask/FixAddress methods.
std::shared_ptr< lldb_private::File > FileSP
std::shared_ptr< lldb_private::InstrumentationRuntime > InstrumentationRuntimeSP
uint64_t tid_t
Definition lldb-types.h:84
#define PATH_MAX