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();
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 return data;
1046
1047 StructuredData::ObjectSP fetched_data = *expected_data;
1048 data.m_impl_up->SetObjectSP(fetched_data);
1049 return data;
1050}
1051
1052uint32_t
1054 LLDB_INSTRUMENT_VA(this, sb_error);
1055
1056 uint32_t num = 0;
1057 ProcessSP process_sp(GetSP());
1058 if (process_sp) {
1059 std::lock_guard<std::recursive_mutex> guard(
1060 process_sp->GetTarget().GetAPIMutex());
1061 std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
1062 if (actual_num) {
1063 num = *actual_num;
1064 } else {
1065 sb_error =
1066 Status::FromErrorString("Unable to determine number of watchpoints");
1067 }
1068 } else {
1069 sb_error = Status::FromErrorString("SBProcess is invalid");
1070 }
1071 return num;
1072}
1073
1074uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
1075 lldb::SBError &sb_error) {
1076 LLDB_INSTRUMENT_VA(this, sb_remote_image_spec, sb_error);
1077
1078 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
1079}
1080
1081uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
1082 const lldb::SBFileSpec &sb_remote_image_spec,
1083 lldb::SBError &sb_error) {
1084 LLDB_INSTRUMENT_VA(this, sb_local_image_spec, sb_remote_image_spec, sb_error);
1085
1086 ProcessSP process_sp(GetSP());
1087 if (process_sp) {
1088 Process::StopLocker stop_locker;
1089 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1090 std::lock_guard<std::recursive_mutex> guard(
1091 process_sp->GetTarget().GetAPIMutex());
1092 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1093 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1094 *sb_remote_image_spec, sb_error.ref());
1095 } else {
1096 sb_error = Status::FromErrorString("process is running");
1097 }
1098 } else {
1099 sb_error = Status::FromErrorString("process is invalid");
1100 }
1102}
1103
1105 SBStringList &paths,
1106 lldb::SBFileSpec &loaded_path,
1108 LLDB_INSTRUMENT_VA(this, image_spec, paths, loaded_path, error);
1109
1110 ProcessSP process_sp(GetSP());
1111 if (process_sp) {
1112 Process::StopLocker stop_locker;
1113 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1114 std::lock_guard<std::recursive_mutex> guard(
1115 process_sp->GetTarget().GetAPIMutex());
1116 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1117 size_t num_paths = paths.GetSize();
1118 std::vector<std::string> paths_vec;
1119 paths_vec.reserve(num_paths);
1120 for (size_t i = 0; i < num_paths; i++)
1121 paths_vec.push_back(paths.GetStringAtIndex(i));
1122 FileSpec loaded_spec;
1123
1124 uint32_t token = platform_sp->LoadImageUsingPaths(
1125 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
1126 if (token != LLDB_INVALID_IMAGE_TOKEN)
1127 loaded_path = loaded_spec;
1128 return token;
1129 } else {
1130 error = Status::FromErrorString("process is running");
1131 }
1132 } else {
1133 error = Status::FromErrorString("process is invalid");
1134 }
1135
1137}
1138
1140 LLDB_INSTRUMENT_VA(this, image_token);
1141
1142 lldb::SBError sb_error;
1143 ProcessSP process_sp(GetSP());
1144 if (process_sp) {
1145 Process::StopLocker stop_locker;
1146 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1147 std::lock_guard<std::recursive_mutex> guard(
1148 process_sp->GetTarget().GetAPIMutex());
1149 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1150 sb_error.SetError(
1151 platform_sp->UnloadImage(process_sp.get(), image_token));
1152 } else {
1153 sb_error = Status::FromErrorString("process is running");
1154 }
1155 } else
1156 sb_error = Status::FromErrorString("invalid process");
1157 return sb_error;
1158}
1159
1161 LLDB_INSTRUMENT_VA(this, event_data);
1162
1163 lldb::SBError sb_error;
1164 ProcessSP process_sp(GetSP());
1165 if (process_sp) {
1166 Process::StopLocker stop_locker;
1167 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1168 std::lock_guard<std::recursive_mutex> guard(
1169 process_sp->GetTarget().GetAPIMutex());
1170 sb_error.SetError(process_sp->SendEventData(event_data));
1171 } else {
1172 sb_error = Status::FromErrorString("process is running");
1173 }
1174 } else
1175 sb_error = Status::FromErrorString("invalid process");
1176 return sb_error;
1177}
1178
1180 LLDB_INSTRUMENT_VA(this);
1181
1182 ProcessSP process_sp(GetSP());
1183 if (process_sp && process_sp->GetSystemRuntime()) {
1184 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1185 return runtime->GetExtendedBacktraceTypes().size();
1186 }
1187 return 0;
1188}
1189
1191 LLDB_INSTRUMENT_VA(this, idx);
1192
1193 ProcessSP process_sp(GetSP());
1194 if (process_sp && process_sp->GetSystemRuntime()) {
1195 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1196 const std::vector<ConstString> &names =
1197 runtime->GetExtendedBacktraceTypes();
1198 if (idx < names.size()) {
1199 return names[idx].AsCString();
1200 }
1201 }
1202 return nullptr;
1203}
1204
1206 LLDB_INSTRUMENT_VA(this, addr);
1207
1208 ProcessSP process_sp(GetSP());
1209 SBThreadCollection threads;
1210 if (process_sp) {
1211 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1212 }
1213 return threads;
1214}
1215
1218 LLDB_INSTRUMENT_VA(this, type);
1219
1220 ProcessSP process_sp(GetSP());
1221 if (!process_sp)
1222 return false;
1223
1224 std::lock_guard<std::recursive_mutex> guard(
1225 process_sp->GetTarget().GetAPIMutex());
1226
1227 InstrumentationRuntimeSP runtime_sp =
1228 process_sp->GetInstrumentationRuntime(type);
1229
1230 if (!runtime_sp.get())
1231 return false;
1232
1233 return runtime_sp->IsActive();
1234}
1235
1236lldb::SBError SBProcess::SaveCore(const char *file_name) {
1237 LLDB_INSTRUMENT_VA(this, file_name);
1238 SBSaveCoreOptions options;
1239 options.SetOutputFile(SBFileSpec(file_name));
1241 return SaveCore(options);
1242}
1243
1245 const char *flavor,
1246 SaveCoreStyle core_style) {
1247 LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
1248 SBSaveCoreOptions options;
1249 options.SetOutputFile(SBFileSpec(file_name));
1250 options.SetStyle(core_style);
1251 SBError error = options.SetPluginName(flavor);
1252 if (error.Fail())
1253 return error;
1254 return SaveCore(options);
1255}
1256
1258
1259 LLDB_INSTRUMENT_VA(this, options);
1260
1262 ProcessSP process_sp(GetSP());
1263 if (!process_sp) {
1264 error = Status::FromErrorString("SBProcess is invalid");
1265 return error;
1266 }
1267
1268 if (!options.GetProcess())
1269 options.SetProcess(process_sp);
1270
1271 if (options.GetProcess().GetSP() != process_sp) {
1273 "Save Core Options configured for a different process.");
1274 return error;
1275 }
1276
1277 std::lock_guard<std::recursive_mutex> guard(
1278 process_sp->GetTarget().GetAPIMutex());
1279
1280 if (process_sp->GetState() != eStateStopped) {
1281 error = Status::FromErrorString("the process is not stopped");
1282 return error;
1283 }
1284
1285 error.ref() = PluginManager::SaveCore(options.ref());
1286
1287 return error;
1288}
1289
1292 SBMemoryRegionInfo &sb_region_info) {
1293 LLDB_INSTRUMENT_VA(this, load_addr, sb_region_info);
1294
1295 lldb::SBError sb_error;
1296 ProcessSP process_sp(GetSP());
1297 if (process_sp) {
1298 Process::StopLocker stop_locker;
1299 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1300 std::lock_guard<std::recursive_mutex> guard(
1301 process_sp->GetTarget().GetAPIMutex());
1302
1303 sb_error.ref() =
1304 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
1305 } else {
1306 sb_error = Status::FromErrorString("process is running");
1307 }
1308 } else {
1309 sb_error = Status::FromErrorString("SBProcess is invalid");
1310 }
1311 return sb_error;
1312}
1313
1315 LLDB_INSTRUMENT_VA(this);
1316
1317 lldb::SBMemoryRegionInfoList sb_region_list;
1318
1319 ProcessSP process_sp(GetSP());
1320 Process::StopLocker stop_locker;
1321 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1322 std::lock_guard<std::recursive_mutex> guard(
1323 process_sp->GetTarget().GetAPIMutex());
1324
1325 process_sp->GetMemoryRegions(sb_region_list.ref());
1326 }
1327
1328 return sb_region_list;
1329}
1330
1332 LLDB_INSTRUMENT_VA(this);
1333
1334 lldb::SBProcessInfo sb_proc_info;
1335 ProcessSP process_sp(GetSP());
1336 ProcessInstanceInfo proc_info;
1337 if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1338 sb_proc_info.SetProcessInfo(proc_info);
1339 }
1340 return sb_proc_info;
1341}
1342
1344 LLDB_INSTRUMENT_VA(this);
1345
1346 ProcessSP process_sp(GetSP());
1347 FileSpec core_file;
1348 if (process_sp) {
1349 core_file = process_sp->GetCoreFile();
1350 }
1351 return SBFileSpec(core_file);
1352}
1353
1355 AddressMaskRange addr_range) {
1356 LLDB_INSTRUMENT_VA(this, type, addr_range);
1357
1358 if (ProcessSP process_sp = GetSP()) {
1359 switch (type) {
1361 if (addr_range == eAddressMaskRangeHigh)
1362 return process_sp->GetHighmemCodeAddressMask();
1363 else
1364 return process_sp->GetCodeAddressMask();
1366 if (addr_range == eAddressMaskRangeHigh)
1367 return process_sp->GetHighmemDataAddressMask();
1368 else
1369 return process_sp->GetDataAddressMask();
1371 if (addr_range == eAddressMaskRangeHigh)
1372 return process_sp->GetHighmemDataAddressMask();
1373 else
1374 return process_sp->GetDataAddressMask();
1375 }
1376 }
1378}
1379
1381 AddressMaskRange addr_range) {
1382 LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
1383
1384 if (ProcessSP process_sp = GetSP()) {
1385 switch (type) {
1387 if (addr_range == eAddressMaskRangeAll) {
1388 process_sp->SetCodeAddressMask(mask);
1389 process_sp->SetHighmemCodeAddressMask(mask);
1390 } else if (addr_range == eAddressMaskRangeHigh) {
1391 process_sp->SetHighmemCodeAddressMask(mask);
1392 } else {
1393 process_sp->SetCodeAddressMask(mask);
1394 }
1395 break;
1397 if (addr_range == eAddressMaskRangeAll) {
1398 process_sp->SetDataAddressMask(mask);
1399 process_sp->SetHighmemDataAddressMask(mask);
1400 } else if (addr_range == eAddressMaskRangeHigh) {
1401 process_sp->SetHighmemDataAddressMask(mask);
1402 } else {
1403 process_sp->SetDataAddressMask(mask);
1404 }
1405 break;
1407 if (addr_range == eAddressMaskRangeAll) {
1408 process_sp->SetCodeAddressMask(mask);
1409 process_sp->SetDataAddressMask(mask);
1410 process_sp->SetHighmemCodeAddressMask(mask);
1411 process_sp->SetHighmemDataAddressMask(mask);
1412 } else if (addr_range == eAddressMaskRangeHigh) {
1413 process_sp->SetHighmemCodeAddressMask(mask);
1414 process_sp->SetHighmemDataAddressMask(mask);
1415 } else {
1416 process_sp->SetCodeAddressMask(mask);
1417 process_sp->SetDataAddressMask(mask);
1418 }
1419 break;
1420 }
1421 }
1422}
1423
1425 AddressMaskRange addr_range) {
1426 LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
1427
1429 addr_range);
1430}
1431
1433 LLDB_INSTRUMENT_VA(this, addr, type);
1434
1435 if (ProcessSP process_sp = GetSP()) {
1436 if (type == eAddressMaskTypeAny)
1437 return process_sp->FixAnyAddress(addr);
1438 else if (type == eAddressMaskTypeData)
1439 return process_sp->FixDataAddress(addr);
1440 else if (type == eAddressMaskTypeCode)
1441 return process_sp->FixCodeAddress(addr);
1442 }
1443 return addr;
1444}
1445
1446lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1447 lldb::SBError &sb_error) {
1448 LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);
1449
1451 ProcessSP process_sp(GetSP());
1452 if (process_sp) {
1453 Process::StopLocker stop_locker;
1454 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1455 std::lock_guard<std::recursive_mutex> guard(
1456 process_sp->GetTarget().GetAPIMutex());
1457 addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1458 } else {
1459 sb_error = Status::FromErrorString("process is running");
1460 }
1461 } else {
1462 sb_error = Status::FromErrorString("SBProcess is invalid");
1463 }
1464 return addr;
1465}
1466
1468 LLDB_INSTRUMENT_VA(this, ptr);
1469
1470 lldb::SBError sb_error;
1471 ProcessSP process_sp(GetSP());
1472 if (process_sp) {
1473 Process::StopLocker stop_locker;
1474 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1475 std::lock_guard<std::recursive_mutex> guard(
1476 process_sp->GetTarget().GetAPIMutex());
1477 Status error = process_sp->DeallocateMemory(ptr);
1478 sb_error.SetError(std::move(error));
1479 } else {
1480 sb_error = Status::FromErrorString("process is running");
1481 }
1482 } else {
1483 sb_error = Status::FromErrorString("SBProcess is invalid");
1484 }
1485 return sb_error;
1486}
1487
1489 LLDB_INSTRUMENT_VA(this);
1490 ProcessSP process_sp(GetSP());
1491 return lldb::SBScriptObject((process_sp) ? process_sp->GetImplementation()
1492 : nullptr,
1494}
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: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.
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: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:581
lldb::SBFileSpec GetExecutable()
Definition SBTarget.cpp:554
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 * 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
@ 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: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:4462
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Process.cpp:4446
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition Process.cpp:4507
const char * GetRestartedReasonAtIndex(size_t idx)
Definition Process.h:442
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition Process.cpp:4454
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Process.cpp:4435
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:393
static llvm::StringRef GetStaticBroadcasterClass()
Definition Process.cpp:421
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: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