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