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
10#include "lldb/Host/File.h"
12
13#include <cinttypes>
14
15#include "lldb/lldb-defines.h"
16#include "lldb/lldb-types.h"
17
19#include "lldb/Core/Debugger.h"
20#include "lldb/Core/Module.h"
25#include "lldb/Target/Process.h"
28#include "lldb/Target/Target.h"
29#include "lldb/Target/Thread.h"
30#include "lldb/Utility/Args.h"
33#include "lldb/Utility/State.h"
34#include "lldb/Utility/Stream.h"
35
38#include "lldb/API/SBDebugger.h"
39#include "lldb/API/SBEvent.h"
40#include "lldb/API/SBFile.h"
41#include "lldb/API/SBFileSpec.h"
46#include "lldb/API/SBStream.h"
49#include "lldb/API/SBThread.h"
51#include "lldb/API/SBTrace.h"
53
54using namespace lldb;
55using namespace lldb_private;
56
58
59// SBProcess constructor
60
64
66 : m_opaque_wp(process_sp) {
67 LLDB_INSTRUMENT_VA(this, process_sp);
68}
69
71 LLDB_INSTRUMENT_VA(this, rhs);
72
73 if (this != &rhs)
75 return *this;
76}
77
78// Destructor
79SBProcess::~SBProcess() = default;
80
86
89
90 ProcessSP process_sp(GetSP());
91 if (process_sp) {
92 return ConstString(process_sp->GetPluginName()).GetCString();
93 }
94 return "<Unknown>";
95}
96
97const char *SBProcess::GetShortPluginName() {
99
100 ProcessSP process_sp(GetSP());
101 if (process_sp) {
102 return ConstString(process_sp->GetPluginName()).GetCString();
103 }
104 return "<Unknown>";
105}
106
108
109void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
110
112 LLDB_INSTRUMENT_VA(this);
113
114 m_opaque_wp.reset();
115}
116
117bool SBProcess::IsValid() const {
118 LLDB_INSTRUMENT_VA(this);
119 return this->operator bool();
120}
121SBProcess::operator bool() const {
122 LLDB_INSTRUMENT_VA(this);
123
124 ProcessSP process_sp(m_opaque_wp.lock());
125 return ((bool)process_sp && process_sp->IsValid());
126}
127
128bool SBProcess::RemoteLaunch(char const **argv, char const **envp,
129 const char *stdin_path, const char *stdout_path,
130 const char *stderr_path,
131 const char *working_directory,
132 uint32_t launch_flags, bool stop_at_entry,
134 LLDB_INSTRUMENT_VA(this, argv, envp, stdin_path, stdout_path, stderr_path,
135 working_directory, launch_flags, stop_at_entry, error);
136
137 ProcessSP process_sp(GetSP());
138 if (process_sp) {
139 std::lock_guard<std::recursive_mutex> guard(
140 process_sp->GetTarget().GetAPIMutex());
141 if (process_sp->GetState() == eStateConnected) {
142 if (stop_at_entry)
143 launch_flags |= eLaunchFlagStopAtEntry;
144 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
145 FileSpec(stderr_path),
146 FileSpec(working_directory), launch_flags);
147 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
148 if (exe_module)
149 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
150 if (argv)
151 launch_info.GetArguments().AppendArguments(argv);
152 if (envp)
153 launch_info.GetEnvironment() = Environment(envp);
154 error.SetError(process_sp->Launch(launch_info));
155 } else {
157 "must be in eStateConnected to call RemoteLaunch");
158 }
159 } else {
160 error = Status::FromErrorString("unable to attach pid");
161 }
162
163 return error.Success();
164}
165
168 LLDB_INSTRUMENT_VA(this, pid, error);
169
170 ProcessSP process_sp(GetSP());
171 if (process_sp) {
172 std::lock_guard<std::recursive_mutex> guard(
173 process_sp->GetTarget().GetAPIMutex());
174 if (process_sp->GetState() == eStateConnected) {
175 ProcessAttachInfo attach_info;
176 attach_info.SetProcessID(pid);
177 error.SetError(process_sp->Attach(attach_info));
178 } else {
180 "must be in eStateConnected to call RemoteAttachToProcessWithID");
181 }
182 } else {
183 error = Status::FromErrorString("unable to attach pid");
184 }
185
186 return error.Success();
187}
188
190 LLDB_INSTRUMENT_VA(this);
191
192 uint32_t num_threads = 0;
193 ProcessSP process_sp(GetSP());
194 if (process_sp) {
195 Process::StopLocker stop_locker;
196
197 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
198 std::lock_guard<std::recursive_mutex> guard(
199 process_sp->GetTarget().GetAPIMutex());
200 num_threads = process_sp->GetThreadList().GetSize();
201 }
202 }
203
204 return num_threads;
205}
206
208 LLDB_INSTRUMENT_VA(this);
209
210 SBThread sb_thread;
211 ThreadSP thread_sp;
212 ProcessSP process_sp(GetSP());
213 if (process_sp) {
214 std::lock_guard<std::recursive_mutex> guard(
215 process_sp->GetTarget().GetAPIMutex());
216 thread_sp = process_sp->GetThreadList().GetSelectedThread();
217 sb_thread.SetThread(thread_sp);
218 }
219
220 return sb_thread;
221}
222
224 lldb::addr_t context) {
225 LLDB_INSTRUMENT_VA(this, tid, context);
226
227 SBThread sb_thread;
228 ThreadSP thread_sp;
229 ProcessSP process_sp(GetSP());
230 if (process_sp) {
231 std::lock_guard<std::recursive_mutex> guard(
232 process_sp->GetTarget().GetAPIMutex());
233 thread_sp = process_sp->CreateOSPluginThread(tid, context);
234 sb_thread.SetThread(thread_sp);
235 }
236
237 return sb_thread;
238}
239
241 LLDB_INSTRUMENT_VA(this);
242
243 SBTarget sb_target;
244 TargetSP target_sp;
245 ProcessSP process_sp(GetSP());
246 if (process_sp) {
247 target_sp = process_sp->GetTarget().shared_from_this();
248 sb_target.SetSP(target_sp);
249 }
250
251 return sb_target;
252}
253
254size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
255 LLDB_INSTRUMENT_VA(this, src, src_len);
256
257 size_t ret_val = 0;
258 ProcessSP process_sp(GetSP());
259 if (process_sp) {
261 ret_val = process_sp->PutSTDIN(src, src_len, error);
262 }
263
264 return ret_val;
265}
266
267size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
268 LLDB_INSTRUMENT_VA(this, dst, dst_len);
269
270 size_t bytes_read = 0;
271 ProcessSP process_sp(GetSP());
272 if (process_sp) {
274 bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
275 }
276
277 return bytes_read;
278}
279
280size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
281 LLDB_INSTRUMENT_VA(this, dst, dst_len);
282
283 size_t bytes_read = 0;
284 ProcessSP process_sp(GetSP());
285 if (process_sp) {
287 bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
288 }
289
290 return bytes_read;
291}
292
293size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
294 LLDB_INSTRUMENT_VA(this, dst, dst_len);
295
296 size_t bytes_read = 0;
297 ProcessSP process_sp(GetSP());
298 if (process_sp) {
300 bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
301 }
302
303 return bytes_read;
304}
305
306void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
307 LLDB_INSTRUMENT_VA(this, event, out);
308
309 return ReportEventState(event, out.m_opaque_sp);
310}
311
312void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
313 LLDB_INSTRUMENT_VA(this, event, out);
314 FileSP outfile =
315 std::make_shared<NativeFile>(out, File::eOpenOptionWriteOnly, false);
316 return ReportEventState(event, outfile);
317}
318
319void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
320
321 LLDB_INSTRUMENT_VA(this, event, out);
322
323 if (!out || !out->IsValid())
324 return;
325
326 ProcessSP process_sp(GetSP());
327 if (process_sp) {
328 StreamFile stream(out);
329 const StateType event_state = SBProcess::GetStateFromEvent(event);
330 stream.Printf("Process %" PRIu64 " %s\n", process_sp->GetID(),
331 SBDebugger::StateAsCString(event_state));
332 }
333}
334
336 SBCommandReturnObject &result) {
337 LLDB_INSTRUMENT_VA(this, event, result);
338
339 ProcessSP process_sp(GetSP());
340 if (process_sp) {
341 const StateType event_state = SBProcess::GetStateFromEvent(event);
342 char message[1024];
343 ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
344 process_sp->GetID(), SBDebugger::StateAsCString(event_state));
345
346 result.AppendMessage(message);
347 }
348}
349
351 LLDB_INSTRUMENT_VA(this, thread);
352
353 ProcessSP process_sp(GetSP());
354 if (process_sp) {
355 std::lock_guard<std::recursive_mutex> guard(
356 process_sp->GetTarget().GetAPIMutex());
357 return process_sp->GetThreadList().SetSelectedThreadByID(
358 thread.GetThreadID());
359 }
360 return false;
361}
362
364 LLDB_INSTRUMENT_VA(this, tid);
365
366 bool ret_val = false;
367 ProcessSP process_sp(GetSP());
368 if (process_sp) {
369 std::lock_guard<std::recursive_mutex> guard(
370 process_sp->GetTarget().GetAPIMutex());
371 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
372 }
373
374 return ret_val;
375}
376
378 LLDB_INSTRUMENT_VA(this, index_id);
379
380 bool ret_val = false;
381 ProcessSP process_sp(GetSP());
382 if (process_sp) {
383 std::lock_guard<std::recursive_mutex> guard(
384 process_sp->GetTarget().GetAPIMutex());
385 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
386 }
387
388 return ret_val;
389}
390
392 LLDB_INSTRUMENT_VA(this, index);
393
394 SBThread sb_thread;
395 ThreadSP thread_sp;
396 ProcessSP process_sp(GetSP());
397 if (process_sp) {
398 Process::StopLocker stop_locker;
399 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
400 std::lock_guard<std::recursive_mutex> guard(
401 process_sp->GetTarget().GetAPIMutex());
402 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, false);
403 sb_thread.SetThread(thread_sp);
404 }
405 }
406
407 return sb_thread;
408}
409
411 LLDB_INSTRUMENT_VA(this);
412
413 uint32_t num_queues = 0;
414 ProcessSP process_sp(GetSP());
415 if (process_sp) {
416 Process::StopLocker stop_locker;
417 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
418 std::lock_guard<std::recursive_mutex> guard(
419 process_sp->GetTarget().GetAPIMutex());
420 num_queues = process_sp->GetQueueList().GetSize();
421 }
422 }
423
424 return num_queues;
425}
426
428 LLDB_INSTRUMENT_VA(this, index);
429
430 SBQueue sb_queue;
431 QueueSP queue_sp;
432 ProcessSP process_sp(GetSP());
433 if (process_sp) {
434 Process::StopLocker stop_locker;
435 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
436 std::lock_guard<std::recursive_mutex> guard(
437 process_sp->GetTarget().GetAPIMutex());
438 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
439 sb_queue.SetQueue(queue_sp);
440 }
441 }
442
443 return sb_queue;
444}
445
446uint32_t SBProcess::GetStopID(bool include_expression_stops) {
447 LLDB_INSTRUMENT_VA(this, include_expression_stops);
448
449 ProcessSP process_sp(GetSP());
450 if (process_sp) {
451 std::lock_guard<std::recursive_mutex> guard(
452 process_sp->GetTarget().GetAPIMutex());
453 if (include_expression_stops)
454 return process_sp->GetStopID();
455 else
456 return process_sp->GetLastNaturalStopID();
457 }
458 return 0;
459}
460
462 LLDB_INSTRUMENT_VA(this, stop_id);
463
464 SBEvent sb_event;
465 EventSP event_sp;
466 ProcessSP process_sp(GetSP());
467 if (process_sp) {
468 std::lock_guard<std::recursive_mutex> guard(
469 process_sp->GetTarget().GetAPIMutex());
470 event_sp = process_sp->GetStopEventForStopID(stop_id);
471 sb_event.reset(event_sp);
472 }
473
474 return sb_event;
475}
476
478 LLDB_INSTRUMENT_VA(this, new_state);
479
480 if (ProcessSP process_sp = GetSP()) {
481 std::lock_guard<std::recursive_mutex> guard(
482 process_sp->GetTarget().GetAPIMutex());
483 process_sp->ForceScriptedState(new_state);
484 }
485}
486
488 LLDB_INSTRUMENT_VA(this);
489
490 StateType ret_val = eStateInvalid;
491 ProcessSP process_sp(GetSP());
492 if (process_sp) {
493 std::lock_guard<std::recursive_mutex> guard(
494 process_sp->GetTarget().GetAPIMutex());
495 ret_val = process_sp->GetState();
496 }
497
498 return ret_val;
499}
500
502 LLDB_INSTRUMENT_VA(this);
503
504 int exit_status = 0;
505 ProcessSP process_sp(GetSP());
506 if (process_sp) {
507 std::lock_guard<std::recursive_mutex> guard(
508 process_sp->GetTarget().GetAPIMutex());
509 exit_status = process_sp->GetExitStatus();
510 }
511
512 return exit_status;
513}
514
516 LLDB_INSTRUMENT_VA(this);
517
518 ProcessSP process_sp(GetSP());
519 if (!process_sp)
520 return nullptr;
521
522 std::lock_guard<std::recursive_mutex> guard(
523 process_sp->GetTarget().GetAPIMutex());
524 return ConstString(process_sp->GetExitDescription()).GetCString();
525}
526
528 LLDB_INSTRUMENT_VA(this);
529
531 ProcessSP process_sp(GetSP());
532 if (process_sp)
533 ret_val = process_sp->GetID();
534
535 return ret_val;
536}
537
539 LLDB_INSTRUMENT_VA(this);
540
541 uint32_t ret_val = 0;
542 ProcessSP process_sp(GetSP());
543 if (process_sp)
544 ret_val = process_sp->GetUniqueID();
545 return ret_val;
546}
547
549 LLDB_INSTRUMENT_VA(this);
550
551 ByteOrder byteOrder = eByteOrderInvalid;
552 ProcessSP process_sp(GetSP());
553 if (process_sp)
554 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
555
556 return byteOrder;
557}
558
560 LLDB_INSTRUMENT_VA(this);
561
562 uint32_t size = 0;
563 ProcessSP process_sp(GetSP());
564 if (process_sp)
565 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
566
567 return size;
568}
569
571 LLDB_INSTRUMENT_VA(this);
572
573 SBError sb_error;
574 ProcessSP process_sp(GetSP());
575
576 if (process_sp) {
577 std::lock_guard<std::recursive_mutex> guard(
578 process_sp->GetTarget().GetAPIMutex());
579
580 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
581 sb_error.ref() = process_sp->Resume();
582 else
583 sb_error.ref() = process_sp->ResumeSynchronous(nullptr);
584 } else
585 sb_error = Status::FromErrorString("SBProcess is invalid");
586
587 return sb_error;
588}
589
591 if (ProcessSP process_sp = GetSP()) {
592 if (direction == RunDirection::eRunReverse &&
593 !process_sp->SupportsReverseDirection())
595 "{0} does not support reverse execution of processes",
596 GetPluginName());
597 process_sp->SetBaseDirection(direction);
598 }
599 return Continue();
600}
601
603 LLDB_INSTRUMENT_VA(this);
604
605 SBError sb_error;
606 ProcessSP process_sp(GetSP());
607 if (process_sp) {
608 std::lock_guard<std::recursive_mutex> guard(
609 process_sp->GetTarget().GetAPIMutex());
610 sb_error.SetError(process_sp->Destroy(false));
611 } else
612 sb_error = Status::FromErrorString("SBProcess is invalid");
613
614 return sb_error;
615}
616
618 LLDB_INSTRUMENT_VA(this);
619
620 SBError sb_error;
621 ProcessSP process_sp(GetSP());
622 if (process_sp) {
623 std::lock_guard<std::recursive_mutex> guard(
624 process_sp->GetTarget().GetAPIMutex());
625 sb_error.SetError(process_sp->Halt());
626 } else
627 sb_error = Status::FromErrorString("SBProcess is invalid");
628
629 return sb_error;
630}
631
633 LLDB_INSTRUMENT_VA(this);
634
635 SBError sb_error;
636 ProcessSP process_sp(GetSP());
637 if (process_sp) {
638 std::lock_guard<std::recursive_mutex> guard(
639 process_sp->GetTarget().GetAPIMutex());
640 sb_error.SetError(process_sp->Destroy(true));
641 } else
642 sb_error = Status::FromErrorString("SBProcess is invalid");
643
644 return sb_error;
645}
646
648 LLDB_INSTRUMENT_VA(this);
649
650 // FIXME: This should come from a process default.
651 bool keep_stopped = false;
652 return Detach(keep_stopped);
653}
654
655SBError SBProcess::Detach(bool keep_stopped) {
656 LLDB_INSTRUMENT_VA(this, keep_stopped);
657
658 SBError sb_error;
659 ProcessSP process_sp(GetSP());
660 if (process_sp) {
661 std::lock_guard<std::recursive_mutex> guard(
662 process_sp->GetTarget().GetAPIMutex());
663 sb_error.SetError(process_sp->Detach(keep_stopped));
664 } else
665 sb_error = Status::FromErrorString("SBProcess is invalid");
666
667 return sb_error;
668}
669
671 LLDB_INSTRUMENT_VA(this, signo);
672
673 SBError sb_error;
674 ProcessSP process_sp(GetSP());
675 if (process_sp) {
676 std::lock_guard<std::recursive_mutex> guard(
677 process_sp->GetTarget().GetAPIMutex());
678 sb_error.SetError(process_sp->Signal(signo));
679 } else
680 sb_error = Status::FromErrorString("SBProcess is invalid");
681
682 return sb_error;
683}
684
686 LLDB_INSTRUMENT_VA(this);
687
688 if (auto process_sp = GetSP())
689 return SBUnixSignals{process_sp};
690
691 return SBUnixSignals{};
692}
693
695 LLDB_INSTRUMENT_VA(this);
696
697 ProcessSP process_sp(GetSP());
698 if (process_sp) {
699 process_sp->SendAsyncInterrupt();
700 }
701}
702
704 LLDB_INSTRUMENT_VA(this, tid);
705
706 SBThread sb_thread;
707 ThreadSP thread_sp;
708 ProcessSP process_sp(GetSP());
709 if (process_sp) {
710 Process::StopLocker stop_locker;
711 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
712 std::lock_guard<std::recursive_mutex> guard(
713 process_sp->GetTarget().GetAPIMutex());
714 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
715 sb_thread.SetThread(thread_sp);
716 }
717
718 return sb_thread;
719}
720
722 LLDB_INSTRUMENT_VA(this, index_id);
723
724 SBThread sb_thread;
725 ThreadSP thread_sp;
726 ProcessSP process_sp(GetSP());
727 if (process_sp) {
728 Process::StopLocker stop_locker;
729 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
730 std::lock_guard<std::recursive_mutex> guard(
731 process_sp->GetTarget().GetAPIMutex());
732 thread_sp =
733 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
734 sb_thread.SetThread(thread_sp);
735 }
736
737 return sb_thread;
738}
739
741 LLDB_INSTRUMENT_VA(event);
742
744
745 return ret_val;
746}
747
749 LLDB_INSTRUMENT_VA(event);
750
752
753 return ret_val;
754}
755
761
762const char *
764 size_t idx) {
765 LLDB_INSTRUMENT_VA(event, idx);
766
768 event.get(), idx))
769 .GetCString();
770}
771
773 LLDB_INSTRUMENT_VA(event);
774
775 ProcessSP process_sp =
777 if (!process_sp) {
778 // StructuredData events also know the process they come from. Try that.
780 }
781
782 return SBProcess(process_sp);
783}
784
790
793 LLDB_INSTRUMENT_VA(event);
794
795 return SBStructuredData(event.GetSP());
796}
797
799 LLDB_INSTRUMENT_VA(event);
800
802 nullptr;
803}
804
806 LLDB_INSTRUMENT_VA(event);
807
808 EventSP event_sp = event.GetSP();
809 EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
810 return event_data && (event_data->GetFlavor() ==
812}
813
815 LLDB_INSTRUMENT_VA(this);
816
817 ProcessSP process_sp(GetSP());
818
819 SBBroadcaster broadcaster(process_sp.get(), false);
820
821 return broadcaster;
822}
823
829
831 const void *buf, uint64_t size, const SBAddressRangeList &ranges,
832 uint32_t alignment, uint32_t max_matches, SBError &error) {
833 LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
834
836
837 ProcessSP process_sp(GetSP());
838 if (!process_sp) {
839 error = Status::FromErrorString("SBProcess is invalid");
840 return matches;
841 }
842 Process::StopLocker stop_locker;
843 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
844 error = Status::FromErrorString("process is running");
845 return matches;
846 }
847 std::lock_guard<std::recursive_mutex> guard(
848 process_sp->GetTarget().GetAPIMutex());
849 matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
850 reinterpret_cast<const uint8_t *>(buf), size, ranges.ref().ref(),
851 alignment, max_matches, error.ref());
852 return matches;
853}
854
855lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
856 const SBAddressRange &range,
857 uint32_t alignment, SBError &error) {
858 LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
859
860 ProcessSP process_sp(GetSP());
861
862 if (!process_sp) {
863 error = Status::FromErrorString("SBProcess is invalid");
865 }
866
867 Process::StopLocker stop_locker;
868 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
869 error = Status::FromErrorString("process is running");
871 }
872
873 std::lock_guard<std::recursive_mutex> guard(
874 process_sp->GetTarget().GetAPIMutex());
875 return process_sp->FindInMemory(reinterpret_cast<const uint8_t *>(buf), size,
876 range.ref(), alignment, error.ref());
877}
878
879size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
880 SBError &sb_error) {
881 LLDB_INSTRUMENT_VA(this, addr, dst, dst_len, sb_error);
882
883 if (!dst) {
885 "no buffer provided to read %zu bytes into", dst_len);
886 return 0;
887 }
888
889 size_t bytes_read = 0;
890 ProcessSP process_sp(GetSP());
891
892
893 if (process_sp) {
894 Process::StopLocker stop_locker;
895 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
896 std::lock_guard<std::recursive_mutex> guard(
897 process_sp->GetTarget().GetAPIMutex());
898 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
899 } else {
900 sb_error = Status::FromErrorString("process is running");
901 }
902 } else {
903 sb_error = Status::FromErrorString("SBProcess is invalid");
904 }
905
906 return bytes_read;
907}
908
909size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
910 lldb::SBError &sb_error) {
911 LLDB_INSTRUMENT_VA(this, addr, buf, size, sb_error);
912
913 size_t bytes_read = 0;
914 ProcessSP process_sp(GetSP());
915 if (process_sp) {
916 Process::StopLocker stop_locker;
917 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
918 std::lock_guard<std::recursive_mutex> guard(
919 process_sp->GetTarget().GetAPIMutex());
920 bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
921 sb_error.ref());
922 } else {
923 sb_error = Status::FromErrorString("process is running");
924 }
925 } else {
926 sb_error = Status::FromErrorString("SBProcess is invalid");
927 }
928 return bytes_read;
929}
930
931uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
932 lldb::SBError &sb_error) {
933 LLDB_INSTRUMENT_VA(this, addr, byte_size, sb_error);
934
935 uint64_t value = 0;
936 ProcessSP process_sp(GetSP());
937 if (process_sp) {
938 Process::StopLocker stop_locker;
939 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
940 std::lock_guard<std::recursive_mutex> guard(
941 process_sp->GetTarget().GetAPIMutex());
942 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
943 sb_error.ref());
944 } else {
945 sb_error = Status::FromErrorString("process is running");
946 }
947 } else {
948 sb_error = Status::FromErrorString("SBProcess is invalid");
949 }
950 return value;
951}
952
954 lldb::SBError &sb_error) {
955 LLDB_INSTRUMENT_VA(this, addr, sb_error);
956
958 ProcessSP process_sp(GetSP());
959 if (process_sp) {
960 Process::StopLocker stop_locker;
961 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
962 std::lock_guard<std::recursive_mutex> guard(
963 process_sp->GetTarget().GetAPIMutex());
964 ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref());
965 } else {
966 sb_error = Status::FromErrorString("process is running");
967 }
968 } else {
969 sb_error = Status::FromErrorString("SBProcess is invalid");
970 }
971 return ptr;
972}
973
974size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
975 SBError &sb_error) {
976 LLDB_INSTRUMENT_VA(this, addr, src, src_len, sb_error);
977
978 size_t bytes_written = 0;
979
980 ProcessSP process_sp(GetSP());
981
982 if (process_sp) {
983 Process::StopLocker stop_locker;
984 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
985 std::lock_guard<std::recursive_mutex> guard(
986 process_sp->GetTarget().GetAPIMutex());
987 bytes_written =
988 process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
989 } else {
990 sb_error = Status::FromErrorString("process is running");
991 }
992 }
993
994 return bytes_written;
995}
996
998 LLDB_INSTRUMENT_VA(this, status);
999
1000 ProcessSP process_sp(GetSP());
1001 if (process_sp)
1002 process_sp->GetStatus(status.ref());
1003}
1004
1006 LLDB_INSTRUMENT_VA(this, description);
1007
1008 Stream &strm = description.ref();
1009
1010 ProcessSP process_sp(GetSP());
1011 if (process_sp) {
1012 char path[PATH_MAX];
1013 GetTarget().GetExecutable().GetPath(path, sizeof(path));
1014 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1015 const char *exe_name = nullptr;
1016 if (exe_module)
1017 exe_name = exe_module->GetFileSpec().GetFilename().AsCString(nullptr);
1018
1019 strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1020 process_sp->GetID(), lldb_private::StateAsCString(GetState()),
1021 GetNumThreads(), exe_name ? ", executable = " : "",
1022 exe_name ? exe_name : "");
1023 } else
1024 strm.PutCString("No value");
1025
1026 return true;
1027}
1028
1030 LLDB_INSTRUMENT_VA(this);
1031 SBStructuredData data;
1032 ProcessSP process_sp(GetSP());
1033 if (!process_sp)
1034 return data;
1035
1036 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1037
1038 if (!platform_sp)
1039 return data;
1040
1041 auto expected_data =
1042 platform_sp->FetchExtendedCrashInformation(*process_sp.get());
1043
1044 if (!expected_data) {
1045 LLDB_LOG_ERROR(GetLog(LLDBLog::API), expected_data.takeError(),
1046 "FetchExtendedCrashInformation failed: {0}");
1047 return data;
1048 }
1049
1050 StructuredData::ObjectSP fetched_data = *expected_data;
1051 data.m_impl_up->SetObjectSP(fetched_data);
1052 return data;
1053}
1054
1055uint32_t
1057 LLDB_INSTRUMENT_VA(this, sb_error);
1058
1059 uint32_t num = 0;
1060 ProcessSP process_sp(GetSP());
1061 if (process_sp) {
1062 std::lock_guard<std::recursive_mutex> guard(
1063 process_sp->GetTarget().GetAPIMutex());
1064 std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
1065 if (actual_num) {
1066 num = *actual_num;
1067 } else {
1068 sb_error =
1069 Status::FromErrorString("Unable to determine number of watchpoints");
1070 }
1071 } else {
1072 sb_error = Status::FromErrorString("SBProcess is invalid");
1073 }
1074 return num;
1075}
1076
1077uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
1078 lldb::SBError &sb_error) {
1079 LLDB_INSTRUMENT_VA(this, sb_remote_image_spec, sb_error);
1080
1081 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
1082}
1083
1084uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
1085 const lldb::SBFileSpec &sb_remote_image_spec,
1086 lldb::SBError &sb_error) {
1087 LLDB_INSTRUMENT_VA(this, sb_local_image_spec, sb_remote_image_spec, sb_error);
1088
1089 ProcessSP process_sp(GetSP());
1090 if (process_sp) {
1091 Process::StopLocker stop_locker;
1092 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1093 std::lock_guard<std::recursive_mutex> guard(
1094 process_sp->GetTarget().GetAPIMutex());
1095 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1096 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1097 *sb_remote_image_spec, sb_error.ref());
1098 } else {
1099 sb_error = Status::FromErrorString("process is running");
1100 }
1101 } else {
1102 sb_error = Status::FromErrorString("process is invalid");
1103 }
1105}
1106
1108 SBStringList &paths,
1109 lldb::SBFileSpec &loaded_path,
1111 LLDB_INSTRUMENT_VA(this, image_spec, paths, loaded_path, error);
1112
1113 ProcessSP process_sp(GetSP());
1114 if (process_sp) {
1115 Process::StopLocker stop_locker;
1116 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1117 std::lock_guard<std::recursive_mutex> guard(
1118 process_sp->GetTarget().GetAPIMutex());
1119 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1120 size_t num_paths = paths.GetSize();
1121 std::vector<std::string> paths_vec;
1122 paths_vec.reserve(num_paths);
1123 for (size_t i = 0; i < num_paths; i++)
1124 paths_vec.push_back(paths.GetStringAtIndex(i));
1125 FileSpec loaded_spec;
1126
1127 uint32_t token = platform_sp->LoadImageUsingPaths(
1128 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
1129 if (token != LLDB_INVALID_IMAGE_TOKEN)
1130 loaded_path = loaded_spec;
1131 return token;
1132 } else {
1133 error = Status::FromErrorString("process is running");
1134 }
1135 } else {
1136 error = Status::FromErrorString("process is invalid");
1137 }
1138
1140}
1141
1143 LLDB_INSTRUMENT_VA(this, image_token);
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 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1153 sb_error.SetError(
1154 platform_sp->UnloadImage(process_sp.get(), image_token));
1155 } else {
1156 sb_error = Status::FromErrorString("process is running");
1157 }
1158 } else
1159 sb_error = Status::FromErrorString("invalid process");
1160 return sb_error;
1161}
1162
1164 LLDB_INSTRUMENT_VA(this, event_data);
1165
1166 lldb::SBError sb_error;
1167 ProcessSP process_sp(GetSP());
1168 if (process_sp) {
1169 Process::StopLocker stop_locker;
1170 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1171 std::lock_guard<std::recursive_mutex> guard(
1172 process_sp->GetTarget().GetAPIMutex());
1173 sb_error.SetError(process_sp->SendEventData(event_data));
1174 } else {
1175 sb_error = Status::FromErrorString("process is running");
1176 }
1177 } else
1178 sb_error = Status::FromErrorString("invalid process");
1179 return sb_error;
1180}
1181
1183 LLDB_INSTRUMENT_VA(this);
1184
1185 ProcessSP process_sp(GetSP());
1186 if (process_sp && process_sp->GetSystemRuntime()) {
1187 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1188 return runtime->GetExtendedBacktraceTypes().size();
1189 }
1190 return 0;
1191}
1192
1194 LLDB_INSTRUMENT_VA(this, idx);
1195
1196 ProcessSP process_sp(GetSP());
1197 if (process_sp && process_sp->GetSystemRuntime()) {
1198 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1199 const std::vector<ConstString> &names =
1200 runtime->GetExtendedBacktraceTypes();
1201 if (idx < names.size()) {
1202 return names[idx].AsCString(nullptr);
1203 }
1204 }
1205 return nullptr;
1206}
1207
1209 LLDB_INSTRUMENT_VA(this, addr);
1210
1211 ProcessSP process_sp(GetSP());
1212 SBThreadCollection threads;
1213 if (process_sp) {
1214 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1215 }
1216 return threads;
1217}
1218
1221 LLDB_INSTRUMENT_VA(this, type);
1222
1223 ProcessSP process_sp(GetSP());
1224 if (!process_sp)
1225 return false;
1226
1227 std::lock_guard<std::recursive_mutex> guard(
1228 process_sp->GetTarget().GetAPIMutex());
1229
1230 InstrumentationRuntimeSP runtime_sp =
1231 process_sp->GetInstrumentationRuntime(type);
1232
1233 if (!runtime_sp.get())
1234 return false;
1235
1236 return runtime_sp->IsActive();
1237}
1238
1239lldb::SBError SBProcess::SaveCore(const char *file_name) {
1240 LLDB_INSTRUMENT_VA(this, file_name);
1241 SBSaveCoreOptions options;
1242 options.SetOutputFile(SBFileSpec(file_name));
1244 return SaveCore(options);
1245}
1246
1248 const char *flavor,
1249 SaveCoreStyle core_style) {
1250 LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
1251 SBSaveCoreOptions options;
1252 options.SetOutputFile(SBFileSpec(file_name));
1253 options.SetStyle(core_style);
1254 SBError error = options.SetPluginName(flavor);
1255 if (error.Fail())
1256 return error;
1257 return SaveCore(options);
1258}
1259
1261
1262 LLDB_INSTRUMENT_VA(this, options);
1263
1265 ProcessSP process_sp(GetSP());
1266 if (!process_sp) {
1267 error = Status::FromErrorString("SBProcess is invalid");
1268 return error;
1269 }
1270
1271 if (!options.GetProcess())
1272 options.SetProcess(process_sp);
1273
1274 if (options.GetProcess().GetSP() != process_sp) {
1276 "Save Core Options configured for a different process.");
1277 return error;
1278 }
1279
1280 std::lock_guard<std::recursive_mutex> guard(
1281 process_sp->GetTarget().GetAPIMutex());
1282
1283 if (process_sp->GetState() != eStateStopped) {
1284 error = Status::FromErrorString("the process is not stopped");
1285 return error;
1286 }
1287
1288 error.ref() = PluginManager::SaveCore(options.ref());
1289
1290 return error;
1291}
1292
1295 SBMemoryRegionInfo &sb_region_info) {
1296 LLDB_INSTRUMENT_VA(this, load_addr, sb_region_info);
1297
1298 lldb::SBError sb_error;
1299 ProcessSP process_sp(GetSP());
1300 if (process_sp) {
1301 Process::StopLocker stop_locker;
1302 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1303 std::lock_guard<std::recursive_mutex> guard(
1304 process_sp->GetTarget().GetAPIMutex());
1305
1306 sb_error.ref() =
1307 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
1308 } else {
1309 sb_error = Status::FromErrorString("process is running");
1310 }
1311 } else {
1312 sb_error = Status::FromErrorString("SBProcess is invalid");
1313 }
1314 return sb_error;
1315}
1316
1318 LLDB_INSTRUMENT_VA(this);
1319
1320 lldb::SBMemoryRegionInfoList sb_region_list;
1321
1322 ProcessSP process_sp(GetSP());
1323 Process::StopLocker stop_locker;
1324 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1325 std::lock_guard<std::recursive_mutex> guard(
1326 process_sp->GetTarget().GetAPIMutex());
1327
1328 process_sp->GetMemoryRegions(sb_region_list.ref());
1329 }
1330
1331 return sb_region_list;
1332}
1333
1335 LLDB_INSTRUMENT_VA(this);
1336
1337 lldb::SBProcessInfo sb_proc_info;
1338 ProcessSP process_sp(GetSP());
1339 ProcessInstanceInfo proc_info;
1340 if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1341 sb_proc_info.SetProcessInfo(proc_info);
1342 }
1343 return sb_proc_info;
1344}
1345
1347 LLDB_INSTRUMENT_VA(this);
1348
1349 ProcessSP process_sp(GetSP());
1350 FileSpec core_file;
1351 if (process_sp) {
1352 core_file = process_sp->GetCoreFile();
1353 }
1354 return SBFileSpec(core_file);
1355}
1356
1358 AddressMaskRange addr_range) {
1359 LLDB_INSTRUMENT_VA(this, type, addr_range);
1360
1361 if (ProcessSP process_sp = GetSP()) {
1362 switch (type) {
1364 if (addr_range == eAddressMaskRangeHigh)
1365 return process_sp->GetHighmemCodeAddressMask();
1366 else
1367 return process_sp->GetCodeAddressMask();
1369 if (addr_range == eAddressMaskRangeHigh)
1370 return process_sp->GetHighmemDataAddressMask();
1371 else
1372 return process_sp->GetDataAddressMask();
1374 if (addr_range == eAddressMaskRangeHigh)
1375 return process_sp->GetHighmemDataAddressMask();
1376 else
1377 return process_sp->GetDataAddressMask();
1378 }
1379 }
1381}
1382
1384 AddressMaskRange addr_range) {
1385 LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
1386
1387 if (ProcessSP process_sp = GetSP()) {
1388 switch (type) {
1390 if (addr_range == eAddressMaskRangeAll) {
1391 process_sp->SetCodeAddressMask(mask);
1392 process_sp->SetHighmemCodeAddressMask(mask);
1393 } else if (addr_range == eAddressMaskRangeHigh) {
1394 process_sp->SetHighmemCodeAddressMask(mask);
1395 } else {
1396 process_sp->SetCodeAddressMask(mask);
1397 }
1398 break;
1400 if (addr_range == eAddressMaskRangeAll) {
1401 process_sp->SetDataAddressMask(mask);
1402 process_sp->SetHighmemDataAddressMask(mask);
1403 } else if (addr_range == eAddressMaskRangeHigh) {
1404 process_sp->SetHighmemDataAddressMask(mask);
1405 } else {
1406 process_sp->SetDataAddressMask(mask);
1407 }
1408 break;
1410 if (addr_range == eAddressMaskRangeAll) {
1411 process_sp->SetCodeAddressMask(mask);
1412 process_sp->SetDataAddressMask(mask);
1413 process_sp->SetHighmemCodeAddressMask(mask);
1414 process_sp->SetHighmemDataAddressMask(mask);
1415 } else if (addr_range == eAddressMaskRangeHigh) {
1416 process_sp->SetHighmemCodeAddressMask(mask);
1417 process_sp->SetHighmemDataAddressMask(mask);
1418 } else {
1419 process_sp->SetCodeAddressMask(mask);
1420 process_sp->SetDataAddressMask(mask);
1421 }
1422 break;
1423 }
1424 }
1425}
1426
1428 AddressMaskRange addr_range) {
1429 LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
1430
1432 addr_range);
1433}
1434
1436 LLDB_INSTRUMENT_VA(this, addr, type);
1437
1438 if (ProcessSP process_sp = GetSP()) {
1439 if (type == eAddressMaskTypeAny)
1440 return process_sp->FixAnyAddress(addr);
1441 else if (type == eAddressMaskTypeData)
1442 return process_sp->FixDataAddress(addr);
1443 else if (type == eAddressMaskTypeCode)
1444 return process_sp->FixCodeAddress(addr);
1445 }
1446 return addr;
1447}
1448
1449lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1450 lldb::SBError &sb_error) {
1451 LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);
1452
1454 ProcessSP process_sp(GetSP());
1455 if (process_sp) {
1456 Process::StopLocker stop_locker;
1457 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1458 std::lock_guard<std::recursive_mutex> guard(
1459 process_sp->GetTarget().GetAPIMutex());
1460 addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1461 } else {
1462 sb_error = Status::FromErrorString("process is running");
1463 }
1464 } else {
1465 sb_error = Status::FromErrorString("SBProcess is invalid");
1466 }
1467 return addr;
1468}
1469
1471 LLDB_INSTRUMENT_VA(this, ptr);
1472
1473 lldb::SBError sb_error;
1474 ProcessSP process_sp(GetSP());
1475 if (process_sp) {
1476 Process::StopLocker stop_locker;
1477 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1478 std::lock_guard<std::recursive_mutex> guard(
1479 process_sp->GetTarget().GetAPIMutex());
1480 Status error = process_sp->DeallocateMemory(ptr);
1481 sb_error.SetError(std::move(error));
1482 } else {
1483 sb_error = Status::FromErrorString("process is running");
1484 }
1485 } else {
1486 sb_error = Status::FromErrorString("SBProcess is invalid");
1487 }
1488 return sb_error;
1489}
1490
1492 LLDB_INSTRUMENT_VA(this);
1493 ProcessSP process_sp(GetSP());
1494 return lldb::SBScriptObject((process_sp) ? process_sp->GetImplementation()
1495 : nullptr,
1497}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:394
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:54
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:70
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:81
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:87
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.
SBError SetPluginName(const char *plugin)
Set the plugin name.
SBProcess GetProcess() const
Get the process to save, if the process is not set an invalid SBProcess will be returned.
lldb_private::Stream & ref()
Definition SBStream.cpp:178
uint32_t GetSize() const
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
void SetSP(const lldb::TargetSP &target_sp)
Definition SBTarget.cpp:596
lldb::SBFileSpec GetExecutable()
Definition SBTarget.cpp:569
void SetThread(const lldb::ThreadSP &lldb_object_sp)
Definition SBThread.cpp:315
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 * GetCString() const
Get the string value as a C string.
const char * AsCString(const char *value_if_empty) 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:250
@ eOpenOptionWriteOnly
Definition File.h:52
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:460
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:446
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:4738
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Process.cpp:4722
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition Process.cpp:4783
const char * GetRestartedReasonAtIndex(size_t idx)
Definition Process.h:444
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition Process.cpp:4730
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Process.cpp:4711
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:395
static llvm::StringRef GetStaticBroadcasterClass()
Definition Process.cpp:446
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:63
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.
Log * GetLog(Cat mask)
Retrieve the Log object for the channel associated with the given log enum.
Definition Log.h:327
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:111
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:105
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:117
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