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"
31#include "lldb/Utility/Args.h"
34#include "lldb/Utility/State.h"
35#include "lldb/Utility/Stream.h"
36
37#include "lldb/API/SBAddress.h"
40#include "lldb/API/SBDebugger.h"
41#include "lldb/API/SBEvent.h"
42#include "lldb/API/SBFile.h"
43#include "lldb/API/SBFileSpec.h"
48#include "lldb/API/SBStream.h"
51#include "lldb/API/SBThread.h"
53#include "lldb/API/SBTrace.h"
55
56using namespace lldb;
57using namespace lldb_private;
58
60
61// SBProcess constructor
62
66
68 : m_opaque_wp(process_sp) {
69 LLDB_INSTRUMENT_VA(this, process_sp);
70}
71
73 LLDB_INSTRUMENT_VA(this, rhs);
74
75 if (this != &rhs)
77 return *this;
78}
79
80// Destructor
81SBProcess::~SBProcess() = default;
82
88
91
92 ProcessSP process_sp(GetSP());
93 if (process_sp) {
94 return ConstString(process_sp->GetPluginName()).GetCString();
95 }
96 return "<Unknown>";
97}
98
99const char *SBProcess::GetShortPluginName() {
100 LLDB_INSTRUMENT_VA(this);
101
102 ProcessSP process_sp(GetSP());
103 if (process_sp) {
104 return ConstString(process_sp->GetPluginName()).GetCString();
105 }
106 return "<Unknown>";
107}
108
110
111void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
112
114 LLDB_INSTRUMENT_VA(this);
115
116 m_opaque_wp.reset();
117}
118
119bool SBProcess::IsValid() const {
120 LLDB_INSTRUMENT_VA(this);
121 return this->operator bool();
122}
123SBProcess::operator bool() const {
124 LLDB_INSTRUMENT_VA(this);
125
126 ProcessSP process_sp(m_opaque_wp.lock());
127 return ((bool)process_sp && process_sp->IsValid());
128}
129
130bool SBProcess::RemoteLaunch(char const **argv, char const **envp,
131 const char *stdin_path, const char *stdout_path,
132 const char *stderr_path,
133 const char *working_directory,
134 uint32_t launch_flags, bool stop_at_entry,
136 LLDB_INSTRUMENT_VA(this, argv, envp, stdin_path, stdout_path, stderr_path,
137 working_directory, launch_flags, stop_at_entry, error);
138
139 ProcessSP process_sp(GetSP());
140 if (process_sp) {
141 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
142 std::lock_guard<TargetAPIMutex> guard(api_lock);
143 if (process_sp->GetState() == eStateConnected) {
144 if (stop_at_entry)
145 launch_flags |= eLaunchFlagStopAtEntry;
146 ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
147 FileSpec(stderr_path),
148 FileSpec(working_directory), launch_flags);
149 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
150 if (exe_module)
151 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
152 if (argv)
153 launch_info.GetArguments().AppendArguments(argv);
154 if (envp)
155 launch_info.GetEnvironment() = Environment(envp);
156 error.SetError(process_sp->Launch(launch_info));
157 } else {
159 "must be in eStateConnected to call RemoteLaunch");
160 }
161 } else {
162 error = Status::FromErrorString("unable to attach pid");
163 }
164
165 return error.Success();
166}
167
170 LLDB_INSTRUMENT_VA(this, pid, error);
171
172 ProcessSP process_sp(GetSP());
173 if (process_sp) {
174 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
175 std::lock_guard<TargetAPIMutex> guard(api_lock);
176 if (process_sp->GetState() == eStateConnected) {
177 ProcessAttachInfo attach_info;
178 attach_info.SetProcessID(pid);
179 error.SetError(process_sp->Attach(attach_info));
180 } else {
182 "must be in eStateConnected to call RemoteAttachToProcessWithID");
183 }
184 } else {
185 error = Status::FromErrorString("unable to attach pid");
186 }
187
188 return error.Success();
189}
190
192 LLDB_INSTRUMENT_VA(this);
193
194 uint32_t num_threads = 0;
195 ProcessSP process_sp(GetSP());
196 if (process_sp) {
197 Process::StopLocker stop_locker;
198
199 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
200 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
201 std::lock_guard<TargetAPIMutex> guard(api_lock);
202 num_threads = process_sp->GetThreadList().GetSize();
203 }
204 }
205
206 return num_threads;
207}
208
210 LLDB_INSTRUMENT_VA(this);
211
212 SBThread sb_thread;
213 ThreadSP thread_sp;
214 ProcessSP process_sp(GetSP());
215 if (process_sp) {
216 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
217 std::lock_guard<TargetAPIMutex> guard(api_lock);
218 thread_sp = process_sp->GetThreadList().GetSelectedThread();
219 sb_thread.SetThread(thread_sp);
220 }
221
222 return sb_thread;
223}
224
226 lldb::addr_t context) {
227 LLDB_INSTRUMENT_VA(this, tid, context);
228
229 SBThread sb_thread;
230 ThreadSP thread_sp;
231 ProcessSP process_sp(GetSP());
232 if (process_sp) {
233 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
234 std::lock_guard<TargetAPIMutex> guard(api_lock);
235 thread_sp = process_sp->CreateOSPluginThread(tid, context);
236 sb_thread.SetThread(thread_sp);
237 }
238
239 return sb_thread;
240}
241
243 LLDB_INSTRUMENT_VA(this);
244
245 SBTarget sb_target;
246 TargetSP target_sp;
247 ProcessSP process_sp(GetSP());
248 if (process_sp) {
249 target_sp = process_sp->GetTarget().shared_from_this();
250 sb_target.SetSP(target_sp);
251 }
252
253 return sb_target;
254}
255
256size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
257 LLDB_INSTRUMENT_VA(this, src, src_len);
258
259 size_t ret_val = 0;
260 ProcessSP process_sp(GetSP());
261 if (process_sp) {
263 ret_val = process_sp->PutSTDIN(src, src_len, error);
264 }
265
266 return ret_val;
267}
268
269size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
270 LLDB_INSTRUMENT_VA(this, dst, dst_len);
271
272 size_t bytes_read = 0;
273 ProcessSP process_sp(GetSP());
274 if (process_sp) {
276 bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
277 }
278
279 return bytes_read;
280}
281
282size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
283 LLDB_INSTRUMENT_VA(this, dst, dst_len);
284
285 size_t bytes_read = 0;
286 ProcessSP process_sp(GetSP());
287 if (process_sp) {
289 bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
290 }
291
292 return bytes_read;
293}
294
295size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
296 LLDB_INSTRUMENT_VA(this, dst, dst_len);
297
298 size_t bytes_read = 0;
299 ProcessSP process_sp(GetSP());
300 if (process_sp) {
302 bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
303 }
304
305 return bytes_read;
306}
307
308void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
309 LLDB_INSTRUMENT_VA(this, event, out);
310
311 return ReportEventState(event, out.m_opaque_sp);
312}
313
314void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
315 LLDB_INSTRUMENT_VA(this, event, out);
316 FileSP outfile =
317 std::make_shared<NativeFile>(out, File::eOpenOptionWriteOnly, false);
318 return ReportEventState(event, outfile);
319}
320
321void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
322
323 LLDB_INSTRUMENT_VA(this, event, out);
324
325 if (!out || !out->IsValid())
326 return;
327
328 ProcessSP process_sp(GetSP());
329 if (process_sp) {
330 StreamFile stream(out);
331 const StateType event_state = SBProcess::GetStateFromEvent(event);
332 stream.Printf("Process %" PRIu64 " %s\n", process_sp->GetID(),
333 SBDebugger::StateAsCString(event_state));
334 }
335}
336
338 SBCommandReturnObject &result) {
339 LLDB_INSTRUMENT_VA(this, event, result);
340
341 ProcessSP process_sp(GetSP());
342 if (process_sp) {
343 const StateType event_state = SBProcess::GetStateFromEvent(event);
344 char message[1024];
345 ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
346 process_sp->GetID(), SBDebugger::StateAsCString(event_state));
347
348 result.AppendMessage(message);
349 }
350}
351
353 LLDB_INSTRUMENT_VA(this, thread);
354
355 ProcessSP process_sp(GetSP());
356 if (process_sp) {
357 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
358 std::lock_guard<TargetAPIMutex> guard(api_lock);
359 return process_sp->GetThreadList().SetSelectedThreadByID(
360 thread.GetThreadID());
361 }
362 return false;
363}
364
366 LLDB_INSTRUMENT_VA(this, tid);
367
368 bool ret_val = false;
369 ProcessSP process_sp(GetSP());
370 if (process_sp) {
371 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
372 std::lock_guard<TargetAPIMutex> guard(api_lock);
373 ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
374 }
375
376 return ret_val;
377}
378
380 LLDB_INSTRUMENT_VA(this, index_id);
381
382 bool ret_val = false;
383 ProcessSP process_sp(GetSP());
384 if (process_sp) {
385 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
386 std::lock_guard<TargetAPIMutex> guard(api_lock);
387 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
388 }
389
390 return ret_val;
391}
392
394 LLDB_INSTRUMENT_VA(this, index);
395
396 SBThread sb_thread;
397 ThreadSP thread_sp;
398 ProcessSP process_sp(GetSP());
399 if (process_sp) {
400 Process::StopLocker stop_locker;
401 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
402 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
403 std::lock_guard<TargetAPIMutex> guard(api_lock);
404 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, false);
405 sb_thread.SetThread(thread_sp);
406 }
407 }
408
409 return sb_thread;
410}
411
413 LLDB_INSTRUMENT_VA(this);
414
415 uint32_t num_queues = 0;
416 ProcessSP process_sp(GetSP());
417 if (process_sp) {
418 Process::StopLocker stop_locker;
419 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
420 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
421 std::lock_guard<TargetAPIMutex> guard(api_lock);
422 num_queues = process_sp->GetQueueList().GetSize();
423 }
424 }
425
426 return num_queues;
427}
428
430 LLDB_INSTRUMENT_VA(this, index);
431
432 SBQueue sb_queue;
433 QueueSP queue_sp;
434 ProcessSP process_sp(GetSP());
435 if (process_sp) {
436 Process::StopLocker stop_locker;
437 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
438 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
439 std::lock_guard<TargetAPIMutex> guard(api_lock);
440 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
441 sb_queue.SetQueue(queue_sp);
442 }
443 }
444
445 return sb_queue;
446}
447
448uint32_t SBProcess::GetStopID(bool include_expression_stops) {
449 LLDB_INSTRUMENT_VA(this, include_expression_stops);
450
451 ProcessSP process_sp(GetSP());
452 if (process_sp) {
453 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
454 std::lock_guard<TargetAPIMutex> guard(api_lock);
455 if (include_expression_stops)
456 return process_sp->GetStopID();
457 else
458 return process_sp->GetLastNaturalStopID();
459 }
460 return 0;
461}
462
464 LLDB_INSTRUMENT_VA(this, stop_id);
465
466 SBEvent sb_event;
467 EventSP event_sp;
468 ProcessSP process_sp(GetSP());
469 if (process_sp) {
470 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
471 std::lock_guard<TargetAPIMutex> guard(api_lock);
472 event_sp = process_sp->GetStopEventForStopID(stop_id);
473 sb_event.reset(event_sp);
474 }
475
476 return sb_event;
477}
478
480 LLDB_INSTRUMENT_VA(this, new_state);
481
482 if (ProcessSP process_sp = GetSP()) {
483 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
484 std::lock_guard<TargetAPIMutex> guard(api_lock);
485 process_sp->ForceScriptedState(new_state);
486 }
487}
488
490 LLDB_INSTRUMENT_VA(this);
491
492 StateType ret_val = eStateInvalid;
493 ProcessSP process_sp(GetSP());
494 if (process_sp) {
495 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
496 std::lock_guard<TargetAPIMutex> guard(api_lock);
497 ret_val = process_sp->GetState();
498 }
499
500 return ret_val;
501}
502
504 LLDB_INSTRUMENT_VA(this);
505
506 int exit_status = 0;
507 ProcessSP process_sp(GetSP());
508 if (process_sp) {
509 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
510 std::lock_guard<TargetAPIMutex> guard(api_lock);
511 exit_status = process_sp->GetExitStatus();
512 }
513
514 return exit_status;
515}
516
518 LLDB_INSTRUMENT_VA(this);
519
520 ProcessSP process_sp(GetSP());
521 if (!process_sp)
522 return nullptr;
523
524 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
525 std::lock_guard<TargetAPIMutex> guard(api_lock);
526 return ConstString(process_sp->GetExitDescription()).GetCString();
527}
528
530 LLDB_INSTRUMENT_VA(this);
531
533 ProcessSP process_sp(GetSP());
534 if (process_sp)
535 ret_val = process_sp->GetID();
536
537 return ret_val;
538}
539
541 LLDB_INSTRUMENT_VA(this);
542
543 uint32_t ret_val = 0;
544 ProcessSP process_sp(GetSP());
545 if (process_sp)
546 ret_val = process_sp->GetUniqueID();
547 return ret_val;
548}
549
551 LLDB_INSTRUMENT_VA(this);
552
553 ByteOrder byteOrder = eByteOrderInvalid;
554 ProcessSP process_sp(GetSP());
555 if (process_sp)
556 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
557
558 return byteOrder;
559}
560
562 LLDB_INSTRUMENT_VA(this);
563
564 uint32_t size = 0;
565 ProcessSP process_sp(GetSP());
566 if (process_sp)
567 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
568
569 return size;
570}
571
573 LLDB_INSTRUMENT_VA(this);
574
575 SBError sb_error;
576 ProcessSP process_sp(GetSP());
577
578 if (process_sp) {
579 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
580 std::lock_guard<TargetAPIMutex> guard(api_lock);
581
582 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
583 sb_error.ref() = process_sp->Resume();
584 else
585 sb_error.ref() = process_sp->ResumeSynchronous(nullptr);
586 } else
587 sb_error = Status::FromErrorString("SBProcess is invalid");
588
589 return sb_error;
590}
591
593 if (ProcessSP process_sp = GetSP()) {
594 if (direction == RunDirection::eRunReverse &&
595 !process_sp->SupportsReverseDirection())
597 "{0} does not support reverse execution of processes",
598 GetPluginName());
599 process_sp->SetBaseDirection(direction);
600 }
601 return Continue();
602}
603
605 LLDB_INSTRUMENT_VA(this);
606
607 SBError sb_error;
608 ProcessSP process_sp(GetSP());
609 if (process_sp) {
610 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
611 std::lock_guard<TargetAPIMutex> guard(api_lock);
612 sb_error.SetError(process_sp->Destroy(false));
613 } else
614 sb_error = Status::FromErrorString("SBProcess is invalid");
615
616 return sb_error;
617}
618
620 LLDB_INSTRUMENT_VA(this);
621
622 SBError sb_error;
623 ProcessSP process_sp(GetSP());
624 if (process_sp) {
625 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
626 std::lock_guard<TargetAPIMutex> guard(api_lock);
627 sb_error.SetError(process_sp->Halt());
628 } else
629 sb_error = Status::FromErrorString("SBProcess is invalid");
630
631 return sb_error;
632}
633
635 LLDB_INSTRUMENT_VA(this);
636
637 SBError sb_error;
638 ProcessSP process_sp(GetSP());
639 if (process_sp) {
640 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
641 std::lock_guard<TargetAPIMutex> guard(api_lock);
642 sb_error.SetError(process_sp->Destroy(true));
643 } else
644 sb_error = Status::FromErrorString("SBProcess is invalid");
645
646 return sb_error;
647}
648
650 LLDB_INSTRUMENT_VA(this);
651
652 // FIXME: This should come from a process default.
653 bool keep_stopped = false;
654 return Detach(keep_stopped);
655}
656
657SBError SBProcess::Detach(bool keep_stopped) {
658 LLDB_INSTRUMENT_VA(this, keep_stopped);
659
660 SBError sb_error;
661 ProcessSP process_sp(GetSP());
662 if (process_sp) {
663 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
664 std::lock_guard<TargetAPIMutex> guard(api_lock);
665 sb_error.SetError(process_sp->Detach(keep_stopped));
666 } else
667 sb_error = Status::FromErrorString("SBProcess is invalid");
668
669 return sb_error;
670}
671
673 LLDB_INSTRUMENT_VA(this, signo);
674
675 SBError sb_error;
676 ProcessSP process_sp(GetSP());
677 if (process_sp) {
678 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
679 std::lock_guard<TargetAPIMutex> guard(api_lock);
680 sb_error.SetError(process_sp->Signal(signo));
681 } else
682 sb_error = Status::FromErrorString("SBProcess is invalid");
683
684 return sb_error;
685}
686
688 LLDB_INSTRUMENT_VA(this);
689
690 if (auto process_sp = GetSP())
691 return SBUnixSignals{process_sp};
692
693 return SBUnixSignals{};
694}
695
697 LLDB_INSTRUMENT_VA(this);
698
699 ProcessSP process_sp(GetSP());
700 if (process_sp) {
701 process_sp->SendAsyncInterrupt();
702 }
703}
704
706 LLDB_INSTRUMENT_VA(this, tid);
707
708 SBThread sb_thread;
709 ThreadSP thread_sp;
710 ProcessSP process_sp(GetSP());
711 if (process_sp) {
712 Process::StopLocker stop_locker;
713 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
714 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
715 std::lock_guard<TargetAPIMutex> guard(api_lock);
716 thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
717 sb_thread.SetThread(thread_sp);
718 }
719
720 return sb_thread;
721}
722
724 LLDB_INSTRUMENT_VA(this, index_id);
725
726 SBThread sb_thread;
727 ThreadSP thread_sp;
728 ProcessSP process_sp(GetSP());
729 if (process_sp) {
730 Process::StopLocker stop_locker;
731 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
732 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
733 std::lock_guard<TargetAPIMutex> guard(api_lock);
734 thread_sp =
735 process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
736 sb_thread.SetThread(thread_sp);
737 }
738
739 return sb_thread;
740}
741
743 LLDB_INSTRUMENT_VA(event);
744
746
747 return ret_val;
748}
749
751 LLDB_INSTRUMENT_VA(event);
752
754
755 return ret_val;
756}
757
763
764const char *
766 size_t idx) {
767 LLDB_INSTRUMENT_VA(event, idx);
768
770 event.get(), idx))
771 .GetCString();
772}
773
775 LLDB_INSTRUMENT_VA(event);
776
777 ProcessSP process_sp =
779 if (!process_sp) {
780 // StructuredData events also know the process they come from. Try that.
782 }
783
784 return SBProcess(process_sp);
785}
786
792
795 LLDB_INSTRUMENT_VA(event);
796
797 return SBStructuredData(event.GetSP());
798}
799
801 LLDB_INSTRUMENT_VA(event);
802
804 nullptr;
805}
806
808 LLDB_INSTRUMENT_VA(event);
809
810 EventSP event_sp = event.GetSP();
811 EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
812 return event_data && (event_data->GetFlavor() ==
814}
815
817 LLDB_INSTRUMENT_VA(this);
818
819 ProcessSP process_sp(GetSP());
820
821 SBBroadcaster broadcaster(process_sp.get(), false);
822
823 return broadcaster;
824}
825
831
833 const void *buf, uint64_t size, const SBAddressRangeList &ranges,
834 uint32_t alignment, uint32_t max_matches, SBError &error) {
835 LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
836
838
839 ProcessSP process_sp(GetSP());
840 if (!process_sp) {
841 error = Status::FromErrorString("SBProcess is invalid");
842 return matches;
843 }
844 Process::StopLocker stop_locker;
845 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
846 error = Status::FromErrorString("process is running");
847 return matches;
848 }
849 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
850 std::lock_guard<TargetAPIMutex> guard(api_lock);
851 matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
852 reinterpret_cast<const uint8_t *>(buf), size, ranges.ref().ref(),
853 alignment, max_matches, error.ref());
854 return matches;
855}
856
857lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
858 const SBAddressRange &range,
859 uint32_t alignment, SBError &error) {
860 LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
861
862 ProcessSP process_sp(GetSP());
863
864 if (!process_sp) {
865 error = Status::FromErrorString("SBProcess is invalid");
867 }
868
869 Process::StopLocker stop_locker;
870 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
871 error = Status::FromErrorString("process is running");
873 }
874
875 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
876 std::lock_guard<TargetAPIMutex> guard(api_lock);
877 return process_sp->FindInMemory(reinterpret_cast<const uint8_t *>(buf), size,
878 range.ref(), alignment, error.ref());
879}
880
881size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
882 SBError &sb_error) {
883 LLDB_INSTRUMENT_VA(this, addr, dst, dst_len, sb_error);
884
885 if (!dst) {
887 "no buffer provided to read %zu bytes into", dst_len);
888 return 0;
889 }
890
891 size_t bytes_read = 0;
892 ProcessSP process_sp(GetSP());
893
894 if (process_sp) {
895 Process::StopLocker stop_locker;
896 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
897 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
898 std::lock_guard<TargetAPIMutex> guard(api_lock);
899 bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
900 } else {
901 sb_error = Status::FromErrorString("process is running");
902 }
903 } else {
904 sb_error = Status::FromErrorString("SBProcess is invalid");
905 }
906
907 return bytes_read;
908}
909
910size_t SBProcess::ReadMemory(SBProcessAddress process_addr, void *dst,
911 size_t dst_len, SBError &sb_error) {
912 LLDB_INSTRUMENT_VA(this, process_addr, dst, dst_len, sb_error);
913
914 if (!dst) {
916 "no buffer provided to read %zu bytes into", dst_len);
917 return 0;
918 }
919
920 ProcessSP process_sp(GetSP());
921 if (!process_sp) {
922 sb_error = Status::FromErrorString("SBProcess is invalid");
923 return 0;
924 }
925
926 Process::StopLocker stop_locker;
927 if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
928 sb_error = Status::FromErrorString("process is running");
929 return 0;
930 }
931
932 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
933 std::lock_guard<TargetAPIMutex> guard(api_lock);
934 return process_sp->ReadMemory(process_addr.ref(), dst, dst_len,
935 sb_error.ref());
936}
937
939 SBError &sb_error) {
940 LLDB_INSTRUMENT_VA(this, name, sb_error);
941
942 ProcessSP process_sp(GetSP());
943 if (!process_sp) {
944 sb_error = Status::FromErrorString("SBProcess is invalid");
946 }
947
948 if (!name || !name[0]) {
949 sb_error = Status::FromErrorString("an address space name is required");
951 }
952
953 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
954 std::lock_guard<TargetAPIMutex> guard(api_lock);
955 llvm::Expected<AddressSpaceInfo> info = process_sp->GetAddressSpaceInfo(name);
956 if (!info) {
957 sb_error = Status::FromError(info.takeError());
959 }
960 sb_error.Clear();
961 return info->space_id;
962}
963
964size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
965 lldb::SBError &sb_error) {
966 LLDB_INSTRUMENT_VA(this, addr, buf, size, sb_error);
967
968 size_t bytes_read = 0;
969 ProcessSP process_sp(GetSP());
970 if (process_sp) {
971 Process::StopLocker stop_locker;
972 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
973 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
974 std::lock_guard<TargetAPIMutex> guard(api_lock);
975 bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
976 sb_error.ref());
977 } else {
978 sb_error = Status::FromErrorString("process is running");
979 }
980 } else {
981 sb_error = Status::FromErrorString("SBProcess is invalid");
982 }
983 return bytes_read;
984}
985
986uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
987 lldb::SBError &sb_error) {
988 LLDB_INSTRUMENT_VA(this, addr, byte_size, sb_error);
989
990 uint64_t value = 0;
991 ProcessSP process_sp(GetSP());
992 if (process_sp) {
993 Process::StopLocker stop_locker;
994 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
995 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
996 std::lock_guard<TargetAPIMutex> guard(api_lock);
997 value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
998 sb_error.ref());
999 } else {
1000 sb_error = Status::FromErrorString("process is running");
1001 }
1002 } else {
1003 sb_error = Status::FromErrorString("SBProcess is invalid");
1004 }
1005 return value;
1006}
1007
1009 lldb::SBError &sb_error) {
1010 LLDB_INSTRUMENT_VA(this, addr, sb_error);
1011
1013 ProcessSP process_sp(GetSP());
1014 if (process_sp) {
1015 Process::StopLocker stop_locker;
1016 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1017 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1018 std::lock_guard<TargetAPIMutex> guard(api_lock);
1019 if (llvm::Expected<lldb::addr_t> ptr_or_err =
1020 process_sp->ReadPointerFromMemory(addr))
1021 ptr = *ptr_or_err;
1022 else
1023 sb_error = Status::FromError(ptr_or_err.takeError());
1024 } else {
1025 sb_error = Status::FromErrorString("process is running");
1026 }
1027 } else {
1028 sb_error = Status::FromErrorString("SBProcess is invalid");
1029 }
1030 return ptr;
1031}
1032
1033size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
1034 SBError &sb_error) {
1035 LLDB_INSTRUMENT_VA(this, addr, src, src_len, sb_error);
1036
1037 size_t bytes_written = 0;
1038
1039 ProcessSP process_sp(GetSP());
1040
1041 if (process_sp) {
1042 Process::StopLocker stop_locker;
1043 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1044 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1045 std::lock_guard<TargetAPIMutex> guard(api_lock);
1046 bytes_written =
1047 process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
1048 } else {
1049 sb_error = Status::FromErrorString("process is running");
1050 }
1051 }
1052
1053 return bytes_written;
1054}
1055
1057 LLDB_INSTRUMENT_VA(this, status);
1058
1059 ProcessSP process_sp(GetSP());
1060 if (process_sp)
1061 process_sp->GetStatus(status.ref());
1062}
1063
1065 LLDB_INSTRUMENT_VA(this, description);
1066
1067 Stream &strm = description.ref();
1068
1069 ProcessSP process_sp(GetSP());
1070 if (process_sp) {
1071 char path[PATH_MAX];
1072 GetTarget().GetExecutable().GetPath(path, sizeof(path));
1073 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1074 const char *exe_name = nullptr;
1075 if (exe_module)
1076 exe_name = ConstString(exe_module->GetFileSpec().GetFilename())
1077 .AsCString(nullptr);
1078
1079 strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1080 process_sp->GetID(), lldb_private::StateAsCString(GetState()),
1081 GetNumThreads(), exe_name ? ", executable = " : "",
1082 exe_name ? exe_name : "");
1083 } else
1084 strm.PutCString("No value");
1085
1086 return true;
1087}
1088
1090 LLDB_INSTRUMENT_VA(this);
1091 SBStructuredData data;
1092 ProcessSP process_sp(GetSP());
1093 if (!process_sp)
1094 return data;
1095
1096 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1097
1098 if (!platform_sp)
1099 return data;
1100
1101 auto expected_data =
1102 platform_sp->FetchExtendedCrashInformation(*process_sp.get());
1103
1104 if (!expected_data) {
1105 LLDB_LOG_ERROR(GetLog(LLDBLog::API), expected_data.takeError(),
1106 "FetchExtendedCrashInformation failed: {0}");
1107 return data;
1108 }
1109
1110 StructuredData::ObjectSP fetched_data = *expected_data;
1111 data.m_impl_up->SetObjectSP(fetched_data);
1112 return data;
1113}
1114
1115uint32_t
1117 LLDB_INSTRUMENT_VA(this, sb_error);
1118
1119 uint32_t num = 0;
1120 ProcessSP process_sp(GetSP());
1121 if (process_sp) {
1122 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1123 std::lock_guard<TargetAPIMutex> guard(api_lock);
1124 std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
1125 if (actual_num) {
1126 num = *actual_num;
1127 } else {
1128 sb_error =
1129 Status::FromErrorString("Unable to determine number of watchpoints");
1130 }
1131 } else {
1132 sb_error = Status::FromErrorString("SBProcess is invalid");
1133 }
1134 return num;
1135}
1136
1137uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
1138 lldb::SBError &sb_error) {
1139 LLDB_INSTRUMENT_VA(this, sb_remote_image_spec, sb_error);
1140
1141 return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
1142}
1143
1144uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
1145 const lldb::SBFileSpec &sb_remote_image_spec,
1146 lldb::SBError &sb_error) {
1147 LLDB_INSTRUMENT_VA(this, sb_local_image_spec, sb_remote_image_spec, sb_error);
1148
1149 ProcessSP process_sp(GetSP());
1150 if (process_sp) {
1151 Process::StopLocker stop_locker;
1152 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1153 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1154 std::lock_guard<TargetAPIMutex> guard(api_lock);
1155 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1156 return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1157 *sb_remote_image_spec, sb_error.ref());
1158 } else {
1159 sb_error = Status::FromErrorString("process is running");
1160 }
1161 } else {
1162 sb_error = Status::FromErrorString("process is invalid");
1163 }
1165}
1166
1168 SBStringList &paths,
1169 lldb::SBFileSpec &loaded_path,
1171 LLDB_INSTRUMENT_VA(this, image_spec, paths, loaded_path, error);
1172
1173 ProcessSP process_sp(GetSP());
1174 if (process_sp) {
1175 Process::StopLocker stop_locker;
1176 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1177 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1178 std::lock_guard<TargetAPIMutex> guard(api_lock);
1179 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1180 size_t num_paths = paths.GetSize();
1181 std::vector<std::string> paths_vec;
1182 paths_vec.reserve(num_paths);
1183 for (size_t i = 0; i < num_paths; i++)
1184 paths_vec.push_back(paths.GetStringAtIndex(i));
1185 FileSpec loaded_spec;
1186
1187 uint32_t token = platform_sp->LoadImageUsingPaths(
1188 process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
1189 if (token != LLDB_INVALID_IMAGE_TOKEN)
1190 loaded_path = loaded_spec;
1191 return token;
1192 } else {
1193 error = Status::FromErrorString("process is running");
1194 }
1195 } else {
1196 error = Status::FromErrorString("process is invalid");
1197 }
1198
1200}
1201
1203 LLDB_INSTRUMENT_VA(this, image_token);
1204
1205 lldb::SBError sb_error;
1206 ProcessSP process_sp(GetSP());
1207 if (process_sp) {
1208 Process::StopLocker stop_locker;
1209 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1210 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1211 std::lock_guard<TargetAPIMutex> guard(api_lock);
1212 PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1213 sb_error.SetError(
1214 platform_sp->UnloadImage(process_sp.get(), image_token));
1215 } else {
1216 sb_error = Status::FromErrorString("process is running");
1217 }
1218 } else
1219 sb_error = Status::FromErrorString("invalid process");
1220 return sb_error;
1221}
1222
1224 LLDB_INSTRUMENT_VA(this, event_data);
1225
1226 lldb::SBError sb_error;
1227 ProcessSP process_sp(GetSP());
1228 if (process_sp) {
1229 Process::StopLocker stop_locker;
1230 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1231 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1232 std::lock_guard<TargetAPIMutex> guard(api_lock);
1233 sb_error.SetError(process_sp->SendEventData(event_data));
1234 } else {
1235 sb_error = Status::FromErrorString("process is running");
1236 }
1237 } else
1238 sb_error = Status::FromErrorString("invalid process");
1239 return sb_error;
1240}
1241
1243 LLDB_INSTRUMENT_VA(this);
1244
1245 ProcessSP process_sp(GetSP());
1246 if (process_sp && process_sp->GetSystemRuntime()) {
1247 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1248 return runtime->GetExtendedBacktraceTypes().size();
1249 }
1250 return 0;
1251}
1252
1254 LLDB_INSTRUMENT_VA(this, idx);
1255
1256 ProcessSP process_sp(GetSP());
1257 if (process_sp && process_sp->GetSystemRuntime()) {
1258 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1259 const std::vector<ConstString> &names =
1260 runtime->GetExtendedBacktraceTypes();
1261 if (idx < names.size()) {
1262 return names[idx].AsCString(nullptr);
1263 }
1264 }
1265 return nullptr;
1266}
1267
1269 LLDB_INSTRUMENT_VA(this, addr);
1270
1271 ProcessSP process_sp(GetSP());
1272 SBThreadCollection threads;
1273 if (process_sp) {
1274 threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1275 }
1276 return threads;
1277}
1278
1281 LLDB_INSTRUMENT_VA(this, type);
1282
1283 ProcessSP process_sp(GetSP());
1284 if (!process_sp)
1285 return false;
1286
1287 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1288 std::lock_guard<TargetAPIMutex> guard(api_lock);
1289
1290 InstrumentationRuntimeSP runtime_sp =
1291 process_sp->GetInstrumentationRuntime(type);
1292
1293 if (!runtime_sp.get())
1294 return false;
1295
1296 return runtime_sp->IsActive();
1297}
1298
1299lldb::SBError SBProcess::SaveCore(const char *file_name) {
1300 LLDB_INSTRUMENT_VA(this, file_name);
1301 SBSaveCoreOptions options;
1302 options.SetOutputFile(SBFileSpec(file_name));
1304 return SaveCore(options);
1305}
1306
1308 const char *flavor,
1309 SaveCoreStyle core_style) {
1310 LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
1311 SBSaveCoreOptions options;
1312 options.SetOutputFile(SBFileSpec(file_name));
1313 options.SetStyle(core_style);
1314 SBError error = options.SetPluginName(flavor);
1315 if (error.Fail())
1316 return error;
1317 return SaveCore(options);
1318}
1319
1321
1322 LLDB_INSTRUMENT_VA(this, options);
1323
1325 ProcessSP process_sp(GetSP());
1326 if (!process_sp) {
1327 error = Status::FromErrorString("SBProcess is invalid");
1328 return error;
1329 }
1330
1331 if (!options.GetProcess())
1332 options.SetProcess(process_sp);
1333
1334 if (options.GetProcess().GetSP() != process_sp) {
1336 "Save Core Options configured for a different process.");
1337 return error;
1338 }
1339
1340 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1341 std::lock_guard<TargetAPIMutex> guard(api_lock);
1342
1343 if (process_sp->GetState() != eStateStopped) {
1344 error = Status::FromErrorString("the process is not stopped");
1345 return error;
1346 }
1347
1348 error.ref() = PluginManager::SaveCore(options.ref());
1349
1350 return error;
1351}
1352
1355 SBMemoryRegionInfo &sb_region_info) {
1356 LLDB_INSTRUMENT_VA(this, load_addr, sb_region_info);
1357
1358 lldb::SBError sb_error;
1359 ProcessSP process_sp(GetSP());
1360 if (process_sp) {
1361 Process::StopLocker stop_locker;
1362 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1363 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1364 std::lock_guard<TargetAPIMutex> guard(api_lock);
1365
1366 sb_error.ref() =
1367 process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
1368 } else {
1369 sb_error = Status::FromErrorString("process is running");
1370 }
1371 } else {
1372 sb_error = Status::FromErrorString("SBProcess is invalid");
1373 }
1374 return sb_error;
1375}
1376
1378 LLDB_INSTRUMENT_VA(this);
1379
1380 lldb::SBMemoryRegionInfoList sb_region_list;
1381
1382 ProcessSP process_sp(GetSP());
1383 Process::StopLocker stop_locker;
1384 if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1385 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1386 std::lock_guard<TargetAPIMutex> guard(api_lock);
1387
1388 process_sp->GetMemoryRegions(sb_region_list.ref());
1389 }
1390
1391 return sb_region_list;
1392}
1393
1395 LLDB_INSTRUMENT_VA(this);
1396
1397 lldb::SBProcessInfo sb_proc_info;
1398 ProcessSP process_sp(GetSP());
1399 ProcessInstanceInfo proc_info;
1400 if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1401 sb_proc_info.SetProcessInfo(proc_info);
1402 }
1403 return sb_proc_info;
1404}
1405
1407 LLDB_INSTRUMENT_VA(this);
1408
1409 ProcessSP process_sp(GetSP());
1410 FileSpec core_file;
1411 if (process_sp) {
1412 core_file = process_sp->GetCoreFile();
1413 }
1414 return SBFileSpec(core_file);
1415}
1416
1418 LLDB_INSTRUMENT_VA(this);
1419
1420 ProcessSP process_sp(GetSP());
1421 if (!process_sp)
1422 return false;
1423 return process_sp->IsLiveDebugSession();
1424}
1425
1427 AddressMaskRange addr_range) {
1428 LLDB_INSTRUMENT_VA(this, type, addr_range);
1429
1430 if (ProcessSP process_sp = GetSP()) {
1431 switch (type) {
1433 if (addr_range == eAddressMaskRangeHigh)
1434 return process_sp->GetHighmemCodeAddressMask();
1435 else
1436 return process_sp->GetCodeAddressMask();
1438 if (addr_range == eAddressMaskRangeHigh)
1439 return process_sp->GetHighmemDataAddressMask();
1440 else
1441 return process_sp->GetDataAddressMask();
1443 if (addr_range == eAddressMaskRangeHigh)
1444 return process_sp->GetHighmemDataAddressMask();
1445 else
1446 return process_sp->GetDataAddressMask();
1447 }
1448 }
1450}
1451
1453 AddressMaskRange addr_range) {
1454 LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
1455
1456 if (ProcessSP process_sp = GetSP()) {
1457 switch (type) {
1459 if (addr_range == eAddressMaskRangeAll) {
1460 process_sp->SetCodeAddressMask(mask);
1461 process_sp->SetHighmemCodeAddressMask(mask);
1462 } else if (addr_range == eAddressMaskRangeHigh) {
1463 process_sp->SetHighmemCodeAddressMask(mask);
1464 } else {
1465 process_sp->SetCodeAddressMask(mask);
1466 }
1467 break;
1469 if (addr_range == eAddressMaskRangeAll) {
1470 process_sp->SetDataAddressMask(mask);
1471 process_sp->SetHighmemDataAddressMask(mask);
1472 } else if (addr_range == eAddressMaskRangeHigh) {
1473 process_sp->SetHighmemDataAddressMask(mask);
1474 } else {
1475 process_sp->SetDataAddressMask(mask);
1476 }
1477 break;
1479 if (addr_range == eAddressMaskRangeAll) {
1480 process_sp->SetCodeAddressMask(mask);
1481 process_sp->SetDataAddressMask(mask);
1482 process_sp->SetHighmemCodeAddressMask(mask);
1483 process_sp->SetHighmemDataAddressMask(mask);
1484 } else if (addr_range == eAddressMaskRangeHigh) {
1485 process_sp->SetHighmemCodeAddressMask(mask);
1486 process_sp->SetHighmemDataAddressMask(mask);
1487 } else {
1488 process_sp->SetCodeAddressMask(mask);
1489 process_sp->SetDataAddressMask(mask);
1490 }
1491 break;
1492 }
1493 }
1494}
1495
1497 AddressMaskRange addr_range) {
1498 LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
1499
1501 addr_range);
1502}
1503
1505 LLDB_INSTRUMENT_VA(this, addr, type);
1506
1507 if (ProcessSP process_sp = GetSP()) {
1508 if (type == eAddressMaskTypeAny)
1509 return process_sp->FixAnyAddress(addr);
1510 else if (type == eAddressMaskTypeData)
1511 return process_sp->FixDataAddress(addr);
1512 else if (type == eAddressMaskTypeCode)
1513 return process_sp->FixCodeAddress(addr);
1514 }
1515 return addr;
1516}
1517
1518lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1519 lldb::SBError &sb_error) {
1520 LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);
1521
1523 ProcessSP process_sp(GetSP());
1524 if (process_sp) {
1525 Process::StopLocker stop_locker;
1526 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1527 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1528 std::lock_guard<TargetAPIMutex> guard(api_lock);
1529 addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1530 } else {
1531 sb_error = Status::FromErrorString("process is running");
1532 }
1533 } else {
1534 sb_error = Status::FromErrorString("SBProcess is invalid");
1535 }
1536 return addr;
1537}
1538
1540 LLDB_INSTRUMENT_VA(this, ptr);
1541
1542 lldb::SBError sb_error;
1543 ProcessSP process_sp(GetSP());
1544 if (process_sp) {
1545 Process::StopLocker stop_locker;
1546 if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1547 TargetAPIMutex api_lock = process_sp->GetTarget().GetAPIMutex();
1548 std::lock_guard<TargetAPIMutex> guard(api_lock);
1549 Status error = process_sp->DeallocateMemory(ptr);
1550 sb_error.SetError(std::move(error));
1551 } else {
1552 sb_error = Status::FromErrorString("process is running");
1553 }
1554 } else {
1555 sb_error = Status::FromErrorString("SBProcess is invalid");
1556 }
1557 return sb_error;
1558}
1559
1561 LLDB_INSTRUMENT_VA(this);
1562 ProcessSP process_sp(GetSP());
1563 return lldb::SBScriptObject((process_sp) ? process_sp->GetImplementation()
1564 : nullptr,
1566}
static llvm::raw_ostream & error(Stream &strm)
#define LLDB_INSTRUMENT()
#define LLDB_INSTRUMENT_VA(...)
#define LLDB_LOG_ERROR(log, error,...)
Definition Log.h:405
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
void Clear()
Definition SBError.cpp:63
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:64
lldb_private::MemoryRegionInfos & ref()
lldb_private::MemoryRegionInfo & ref()
A memory address, optionally in a non-default address space.
Definition SBAddress.h:134
lldb_private::ProcessAddress & ref()
void SetProcessInfo(const lldb_private::ProcessInstanceInfo &proc_info_ref)
const lldb::SBProcess & operator=(const lldb::SBProcess &rhs)
Definition SBProcess.cpp:72
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:83
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:606
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:612
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:89
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:613
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:625
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.
bool IsLiveDebugSession() const
Check whether this process is a live debug session, as opposed to a post-mortem session such as a cor...
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::addr_space_t GetAddressSpaceID(const char *name, lldb::SBError &error)
Resolve an address space name to its id, or LLDB_INVALID_ADDRESS_SPACE_ID.
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:179
uint32_t GetSize() const
const char * GetStringAtIndex(size_t idx)
StructuredDataImplUP m_impl_up
void SetSP(const lldb::TargetSP &target_sp)
Definition SBTarget.cpp:602
lldb::SBFileSpec GetExecutable()
Definition SBTarget.cpp:575
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:56
llvm::StringRef GetFilename() const
Filename string const get accessor.
Definition FileSpec.h:248
A class that describes an executable image and its associated object and symbol files.
Definition Module.h:91
const FileSpec & GetPlatformFileSpec() const
Get accessor for the module platform file specification.
Definition Module.h:461
const FileSpec & GetFileSpec() const
Get const accessor for the module file specification.
Definition Module.h:447
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:68
Environment & GetEnvironment()
Definition ProcessInfo.h:86
bool TryLock(ProcessRunLock *lock)
Try to acquire the read lock.
static bool GetRestartedFromEvent(const Event *event_ptr)
Definition Process.cpp:4814
static lldb::ProcessSP GetProcessFromEvent(const Event *event_ptr)
Definition Process.cpp:4798
static bool GetInterruptedFromEvent(const Event *event_ptr)
Definition Process.cpp:4859
const char * GetRestartedReasonAtIndex(size_t idx)
Definition Process.h:456
static lldb::StateType GetStateFromEvent(const Event *event_ptr)
Definition Process.cpp:4806
static const Process::ProcessEventData * GetEventDataFromEvent(const Event *event_ptr)
Definition Process.cpp:4787
ProcessRunLock::ProcessRunLocker StopLocker
Definition Process.h:407
static llvm::StringRef GetStaticBroadcasterClass()
Definition Process.cpp:462
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
static Status FromError(llvm::Error error)
Avoid using this in new code. Migrate APIs to llvm::Expected instead.
Definition Status.cpp:136
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.
A Lockable handle over a Target's API mutex, returned by Target::GetAPIMutex() and backing the public...
#define LLDB_INVALID_ADDRESS_SPACE_ID
#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:338
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:76
class LLDB_API SBStructuredData
Definition SBDefines.h:113
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:107
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:119
InstrumentationRuntimeType
std::shared_ptr< lldb_private::Event > EventSP
uint64_t pid_t
Definition lldb-types.h:84
ByteOrder
Byte ordering definitions.
uint64_t addr_t
Definition lldb-types.h:80
uint64_t addr_space_t
Definition lldb-types.h:81
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:85
#define PATH_MAX