1cfca06d7SDimitry Andric //===-- SBProcess.cpp -----------------------------------------------------===//
2f034231aSEd Maste //
35f29bb8aSDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
45f29bb8aSDimitry Andric // See https://llvm.org/LICENSE.txt for license information.
55f29bb8aSDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6f034231aSEd Maste //
7f034231aSEd Maste //===----------------------------------------------------------------------===//
8f034231aSEd Maste
9f034231aSEd Maste #include "lldb/API/SBProcess.h"
106f8fc217SDimitry Andric #include "lldb/Utility/Instrumentation.h"
11f034231aSEd Maste
12344a3780SDimitry Andric #include <cinttypes>
13f21a844fSEd Maste
14f034231aSEd Maste #include "lldb/lldb-defines.h"
15f034231aSEd Maste #include "lldb/lldb-types.h"
16f034231aSEd Maste
17ac9a064cSDimitry Andric #include "lldb/Core/AddressRangeListImpl.h"
18f034231aSEd Maste #include "lldb/Core/Debugger.h"
19f034231aSEd Maste #include "lldb/Core/Module.h"
20e81d9d49SDimitry Andric #include "lldb/Core/PluginManager.h"
21cfca06d7SDimitry Andric #include "lldb/Core/StructuredDataImpl.h"
22b1c73532SDimitry Andric #include "lldb/Host/StreamFile.h"
23f3fbd1c0SDimitry Andric #include "lldb/Target/MemoryRegionInfo.h"
24f034231aSEd Maste #include "lldb/Target/Process.h"
25f034231aSEd Maste #include "lldb/Target/RegisterContext.h"
26f21a844fSEd Maste #include "lldb/Target/SystemRuntime.h"
27f034231aSEd Maste #include "lldb/Target/Target.h"
28f034231aSEd Maste #include "lldb/Target/Thread.h"
29f73363f1SDimitry Andric #include "lldb/Utility/Args.h"
30ac9a064cSDimitry Andric #include "lldb/Utility/LLDBLog.h"
315f29bb8aSDimitry Andric #include "lldb/Utility/ProcessInfo.h"
3294994d37SDimitry Andric #include "lldb/Utility/State.h"
3374a628f7SDimitry Andric #include "lldb/Utility/Stream.h"
34f034231aSEd Maste
35f034231aSEd Maste #include "lldb/API/SBBroadcaster.h"
36f034231aSEd Maste #include "lldb/API/SBCommandReturnObject.h"
37f034231aSEd Maste #include "lldb/API/SBDebugger.h"
38f034231aSEd Maste #include "lldb/API/SBEvent.h"
39ead24645SDimitry Andric #include "lldb/API/SBFile.h"
40f034231aSEd Maste #include "lldb/API/SBFileSpec.h"
41f3fbd1c0SDimitry Andric #include "lldb/API/SBMemoryRegionInfo.h"
42f3fbd1c0SDimitry Andric #include "lldb/API/SBMemoryRegionInfoList.h"
43ac9a064cSDimitry Andric #include "lldb/API/SBSaveCoreOptions.h"
447fa27ce4SDimitry Andric #include "lldb/API/SBScriptObject.h"
45f034231aSEd Maste #include "lldb/API/SBStream.h"
46f034231aSEd Maste #include "lldb/API/SBStringList.h"
4714f1b3e8SDimitry Andric #include "lldb/API/SBStructuredData.h"
4814f1b3e8SDimitry Andric #include "lldb/API/SBThread.h"
4914f1b3e8SDimitry Andric #include "lldb/API/SBThreadCollection.h"
505060b64bSDimitry Andric #include "lldb/API/SBTrace.h"
510cac4ca3SEd Maste #include "lldb/API/SBUnixSignals.h"
52f034231aSEd Maste
53f034231aSEd Maste using namespace lldb;
54f034231aSEd Maste using namespace lldb_private;
55f034231aSEd Maste
SBProcess()566f8fc217SDimitry Andric SBProcess::SBProcess() { LLDB_INSTRUMENT_VA(this); }
57f034231aSEd Maste
585f29bb8aSDimitry Andric // SBProcess constructor
595f29bb8aSDimitry Andric
SBProcess(const SBProcess & rhs)605f29bb8aSDimitry Andric SBProcess::SBProcess(const SBProcess &rhs) : m_opaque_wp(rhs.m_opaque_wp) {
616f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
625f29bb8aSDimitry Andric }
635f29bb8aSDimitry Andric
SBProcess(const lldb::ProcessSP & process_sp)645f29bb8aSDimitry Andric SBProcess::SBProcess(const lldb::ProcessSP &process_sp)
655f29bb8aSDimitry Andric : m_opaque_wp(process_sp) {
666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, process_sp);
675f29bb8aSDimitry Andric }
685f29bb8aSDimitry Andric
operator =(const SBProcess & rhs)695f29bb8aSDimitry Andric const SBProcess &SBProcess::operator=(const SBProcess &rhs) {
706f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, rhs);
715f29bb8aSDimitry Andric
725f29bb8aSDimitry Andric if (this != &rhs)
735f29bb8aSDimitry Andric m_opaque_wp = rhs.m_opaque_wp;
746f8fc217SDimitry Andric return *this;
755f29bb8aSDimitry Andric }
765f29bb8aSDimitry Andric
77f034231aSEd Maste // Destructor
78cfca06d7SDimitry Andric SBProcess::~SBProcess() = default;
79f034231aSEd Maste
GetBroadcasterClassName()8014f1b3e8SDimitry Andric const char *SBProcess::GetBroadcasterClassName() {
816f8fc217SDimitry Andric LLDB_INSTRUMENT();
825f29bb8aSDimitry Andric
83ac9a064cSDimitry Andric return ConstString(Process::GetStaticBroadcasterClass()).AsCString();
84f034231aSEd Maste }
85f034231aSEd Maste
GetPluginName()8614f1b3e8SDimitry Andric const char *SBProcess::GetPluginName() {
876f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
885f29bb8aSDimitry Andric
89f034231aSEd Maste ProcessSP process_sp(GetSP());
9014f1b3e8SDimitry Andric if (process_sp) {
91c0981da4SDimitry Andric return ConstString(process_sp->GetPluginName()).GetCString();
92f034231aSEd Maste }
93f034231aSEd Maste return "<Unknown>";
94f034231aSEd Maste }
95f034231aSEd Maste
GetShortPluginName()9614f1b3e8SDimitry Andric const char *SBProcess::GetShortPluginName() {
976f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
985f29bb8aSDimitry Andric
99f034231aSEd Maste ProcessSP process_sp(GetSP());
10014f1b3e8SDimitry Andric if (process_sp) {
101c0981da4SDimitry Andric return ConstString(process_sp->GetPluginName()).GetCString();
102f034231aSEd Maste }
103f034231aSEd Maste return "<Unknown>";
104f034231aSEd Maste }
105f034231aSEd Maste
GetSP() const10614f1b3e8SDimitry Andric lldb::ProcessSP SBProcess::GetSP() const { return m_opaque_wp.lock(); }
107f034231aSEd Maste
SetSP(const ProcessSP & process_sp)10814f1b3e8SDimitry Andric void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
109f034231aSEd Maste
Clear()1105f29bb8aSDimitry Andric void SBProcess::Clear() {
1116f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1125f29bb8aSDimitry Andric
1135f29bb8aSDimitry Andric m_opaque_wp.reset();
1145f29bb8aSDimitry Andric }
115f034231aSEd Maste
IsValid() const11614f1b3e8SDimitry Andric bool SBProcess::IsValid() const {
1176f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1185f29bb8aSDimitry Andric return this->operator bool();
1195f29bb8aSDimitry Andric }
operator bool() const1205f29bb8aSDimitry Andric SBProcess::operator bool() const {
1216f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1225f29bb8aSDimitry Andric
123f034231aSEd Maste ProcessSP process_sp(m_opaque_wp.lock());
124f034231aSEd Maste return ((bool)process_sp && process_sp->IsValid());
125f034231aSEd Maste }
126f034231aSEd Maste
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)12714f1b3e8SDimitry Andric bool SBProcess::RemoteLaunch(char const **argv, char const **envp,
12814f1b3e8SDimitry Andric const char *stdin_path, const char *stdout_path,
129f034231aSEd Maste const char *stderr_path,
130f034231aSEd Maste const char *working_directory,
13114f1b3e8SDimitry Andric uint32_t launch_flags, bool stop_at_entry,
13214f1b3e8SDimitry Andric lldb::SBError &error) {
1336f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, argv, envp, stdin_path, stdout_path, stderr_path,
1345f29bb8aSDimitry Andric working_directory, launch_flags, stop_at_entry, error);
135f034231aSEd Maste
136f034231aSEd Maste ProcessSP process_sp(GetSP());
13714f1b3e8SDimitry Andric if (process_sp) {
13814f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
13914f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
14014f1b3e8SDimitry Andric if (process_sp->GetState() == eStateConnected) {
141f034231aSEd Maste if (stop_at_entry)
142f034231aSEd Maste launch_flags |= eLaunchFlagStopAtEntry;
14394994d37SDimitry Andric ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
14494994d37SDimitry Andric FileSpec(stderr_path),
14594994d37SDimitry Andric FileSpec(working_directory), launch_flags);
146f034231aSEd Maste Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
147f034231aSEd Maste if (exe_module)
148f034231aSEd Maste launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
149f034231aSEd Maste if (argv)
150f034231aSEd Maste launch_info.GetArguments().AppendArguments(argv);
151f034231aSEd Maste if (envp)
152f73363f1SDimitry Andric launch_info.GetEnvironment() = Environment(envp);
153f034231aSEd Maste error.SetError(process_sp->Launch(launch_info));
15414f1b3e8SDimitry Andric } else {
155f034231aSEd Maste error.SetErrorString("must be in eStateConnected to call RemoteLaunch");
156f034231aSEd Maste }
15714f1b3e8SDimitry Andric } else {
158f034231aSEd Maste error.SetErrorString("unable to attach pid");
159f034231aSEd Maste }
160f034231aSEd Maste
161f034231aSEd Maste return error.Success();
162f034231aSEd Maste }
163f034231aSEd Maste
RemoteAttachToProcessWithID(lldb::pid_t pid,lldb::SBError & error)16414f1b3e8SDimitry Andric bool SBProcess::RemoteAttachToProcessWithID(lldb::pid_t pid,
16514f1b3e8SDimitry Andric lldb::SBError &error) {
1666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, pid, error);
1675f29bb8aSDimitry Andric
168f034231aSEd Maste ProcessSP process_sp(GetSP());
16914f1b3e8SDimitry Andric if (process_sp) {
17014f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
17114f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
17214f1b3e8SDimitry Andric if (process_sp->GetState() == eStateConnected) {
173f034231aSEd Maste ProcessAttachInfo attach_info;
174f034231aSEd Maste attach_info.SetProcessID(pid);
175f034231aSEd Maste error.SetError(process_sp->Attach(attach_info));
17614f1b3e8SDimitry Andric } else {
17714f1b3e8SDimitry Andric error.SetErrorString(
17814f1b3e8SDimitry Andric "must be in eStateConnected to call RemoteAttachToProcessWithID");
179f034231aSEd Maste }
18014f1b3e8SDimitry Andric } else {
181f034231aSEd Maste error.SetErrorString("unable to attach pid");
182f034231aSEd Maste }
183f034231aSEd Maste
184f034231aSEd Maste return error.Success();
185f034231aSEd Maste }
186f034231aSEd Maste
GetNumThreads()18714f1b3e8SDimitry Andric uint32_t SBProcess::GetNumThreads() {
1886f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
189f034231aSEd Maste
190f034231aSEd Maste uint32_t num_threads = 0;
191f034231aSEd Maste ProcessSP process_sp(GetSP());
19214f1b3e8SDimitry Andric if (process_sp) {
193f034231aSEd Maste Process::StopLocker stop_locker;
194f034231aSEd Maste
195f034231aSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
19614f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
19714f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
198f034231aSEd Maste num_threads = process_sp->GetThreadList().GetSize(can_update);
199f034231aSEd Maste }
200f034231aSEd Maste
201f034231aSEd Maste return num_threads;
202f034231aSEd Maste }
203f034231aSEd Maste
GetSelectedThread() const20414f1b3e8SDimitry Andric SBThread SBProcess::GetSelectedThread() const {
2056f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
206f034231aSEd Maste
207f034231aSEd Maste SBThread sb_thread;
208f034231aSEd Maste ThreadSP thread_sp;
209f034231aSEd Maste ProcessSP process_sp(GetSP());
21014f1b3e8SDimitry Andric if (process_sp) {
21114f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
21214f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
213f034231aSEd Maste thread_sp = process_sp->GetThreadList().GetSelectedThread();
214f034231aSEd Maste sb_thread.SetThread(thread_sp);
215f034231aSEd Maste }
216f034231aSEd Maste
2176f8fc217SDimitry Andric return sb_thread;
218f034231aSEd Maste }
219f034231aSEd Maste
CreateOSPluginThread(lldb::tid_t tid,lldb::addr_t context)22014f1b3e8SDimitry Andric SBThread SBProcess::CreateOSPluginThread(lldb::tid_t tid,
22114f1b3e8SDimitry Andric lldb::addr_t context) {
2226f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, tid, context);
223f034231aSEd Maste
224f034231aSEd Maste SBThread sb_thread;
225f034231aSEd Maste ThreadSP thread_sp;
226f034231aSEd Maste ProcessSP process_sp(GetSP());
22714f1b3e8SDimitry Andric if (process_sp) {
22814f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
22914f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
230f034231aSEd Maste thread_sp = process_sp->CreateOSPluginThread(tid, context);
231f034231aSEd Maste sb_thread.SetThread(thread_sp);
232f034231aSEd Maste }
233f034231aSEd Maste
2346f8fc217SDimitry Andric return sb_thread;
235f034231aSEd Maste }
236f034231aSEd Maste
GetTarget() const23714f1b3e8SDimitry Andric SBTarget SBProcess::GetTarget() const {
2386f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
239f034231aSEd Maste
240f034231aSEd Maste SBTarget sb_target;
241f034231aSEd Maste TargetSP target_sp;
242f034231aSEd Maste ProcessSP process_sp(GetSP());
24314f1b3e8SDimitry Andric if (process_sp) {
244f034231aSEd Maste target_sp = process_sp->GetTarget().shared_from_this();
245f034231aSEd Maste sb_target.SetSP(target_sp);
246f034231aSEd Maste }
247f034231aSEd Maste
2486f8fc217SDimitry Andric return sb_target;
249f034231aSEd Maste }
250f034231aSEd Maste
PutSTDIN(const char * src,size_t src_len)25114f1b3e8SDimitry Andric size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
2526f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, src, src_len);
253f034231aSEd Maste
254f034231aSEd Maste size_t ret_val = 0;
255f034231aSEd Maste ProcessSP process_sp(GetSP());
25614f1b3e8SDimitry Andric if (process_sp) {
257b76161e4SDimitry Andric Status error;
258f034231aSEd Maste ret_val = process_sp->PutSTDIN(src, src_len, error);
259f034231aSEd Maste }
260f034231aSEd Maste
261f034231aSEd Maste return ret_val;
262f034231aSEd Maste }
263f034231aSEd Maste
GetSTDOUT(char * dst,size_t dst_len) const26414f1b3e8SDimitry Andric size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
2656f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, dst, dst_len);
2665f29bb8aSDimitry Andric
267f034231aSEd Maste size_t bytes_read = 0;
268f034231aSEd Maste ProcessSP process_sp(GetSP());
26914f1b3e8SDimitry Andric if (process_sp) {
270b76161e4SDimitry Andric Status error;
271f034231aSEd Maste bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
272f034231aSEd Maste }
273f034231aSEd Maste
274f034231aSEd Maste return bytes_read;
275f034231aSEd Maste }
276f034231aSEd Maste
GetSTDERR(char * dst,size_t dst_len) const27714f1b3e8SDimitry Andric size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
2786f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, dst, dst_len);
2795f29bb8aSDimitry Andric
280f034231aSEd Maste size_t bytes_read = 0;
281f034231aSEd Maste ProcessSP process_sp(GetSP());
28214f1b3e8SDimitry Andric if (process_sp) {
283b76161e4SDimitry Andric Status error;
284f034231aSEd Maste bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
285f034231aSEd Maste }
286f034231aSEd Maste
287f034231aSEd Maste return bytes_read;
288f034231aSEd Maste }
289f034231aSEd Maste
GetAsyncProfileData(char * dst,size_t dst_len) const29014f1b3e8SDimitry Andric size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
2916f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, dst, dst_len);
2925f29bb8aSDimitry Andric
293f034231aSEd Maste size_t bytes_read = 0;
294f034231aSEd Maste ProcessSP process_sp(GetSP());
29514f1b3e8SDimitry Andric if (process_sp) {
296b76161e4SDimitry Andric Status error;
297f034231aSEd Maste bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
298f034231aSEd Maste }
299f034231aSEd Maste
300f034231aSEd Maste return bytes_read;
301f034231aSEd Maste }
302f034231aSEd Maste
ReportEventState(const SBEvent & event,SBFile out) const303ead24645SDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, SBFile out) const {
3046f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, event, out);
305ead24645SDimitry Andric
306ead24645SDimitry Andric return ReportEventState(event, out.m_opaque_sp);
307ead24645SDimitry Andric }
308ead24645SDimitry Andric
ReportEventState(const SBEvent & event,FILE * out) const30914f1b3e8SDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
3106f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, event, out);
311ead24645SDimitry Andric FileSP outfile = std::make_shared<NativeFile>(out, false);
312ead24645SDimitry Andric return ReportEventState(event, outfile);
313ead24645SDimitry Andric }
3145f29bb8aSDimitry Andric
ReportEventState(const SBEvent & event,FileSP out) const315ead24645SDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, FileSP out) const {
316ead24645SDimitry Andric
3176f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, event, out);
318ead24645SDimitry Andric
319ead24645SDimitry Andric if (!out || !out->IsValid())
320f034231aSEd Maste return;
321f034231aSEd Maste
322f034231aSEd Maste ProcessSP process_sp(GetSP());
32314f1b3e8SDimitry Andric if (process_sp) {
324ead24645SDimitry Andric StreamFile stream(out);
325f034231aSEd Maste const StateType event_state = SBProcess::GetStateFromEvent(event);
326ac9a064cSDimitry Andric stream.Printf("Process %" PRIu64 " %s\n", process_sp->GetID(),
327ac9a064cSDimitry Andric SBDebugger::StateAsCString(event_state));
328f034231aSEd Maste }
329f034231aSEd Maste }
330f034231aSEd Maste
AppendEventStateReport(const SBEvent & event,SBCommandReturnObject & result)33114f1b3e8SDimitry Andric void SBProcess::AppendEventStateReport(const SBEvent &event,
33214f1b3e8SDimitry Andric SBCommandReturnObject &result) {
3336f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, event, result);
3345f29bb8aSDimitry Andric
335f034231aSEd Maste ProcessSP process_sp(GetSP());
33614f1b3e8SDimitry Andric if (process_sp) {
337f034231aSEd Maste const StateType event_state = SBProcess::GetStateFromEvent(event);
338f034231aSEd Maste char message[1024];
33914f1b3e8SDimitry Andric ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
34014f1b3e8SDimitry Andric process_sp->GetID(), SBDebugger::StateAsCString(event_state));
341f034231aSEd Maste
342f034231aSEd Maste result.AppendMessage(message);
343f034231aSEd Maste }
344f034231aSEd Maste }
345f034231aSEd Maste
SetSelectedThread(const SBThread & thread)34614f1b3e8SDimitry Andric bool SBProcess::SetSelectedThread(const SBThread &thread) {
3476f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, thread);
3485f29bb8aSDimitry Andric
349f034231aSEd Maste ProcessSP process_sp(GetSP());
35014f1b3e8SDimitry Andric if (process_sp) {
35114f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
35214f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
35314f1b3e8SDimitry Andric return process_sp->GetThreadList().SetSelectedThreadByID(
35414f1b3e8SDimitry Andric thread.GetThreadID());
355f034231aSEd Maste }
356f034231aSEd Maste return false;
357f034231aSEd Maste }
358f034231aSEd Maste
SetSelectedThreadByID(lldb::tid_t tid)35914f1b3e8SDimitry Andric bool SBProcess::SetSelectedThreadByID(lldb::tid_t tid) {
3606f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, tid);
361f034231aSEd Maste
362f034231aSEd Maste bool ret_val = false;
363f034231aSEd Maste ProcessSP process_sp(GetSP());
36414f1b3e8SDimitry Andric if (process_sp) {
36514f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
36614f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
367f034231aSEd Maste ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
368f034231aSEd Maste }
369f034231aSEd Maste
370f034231aSEd Maste return ret_val;
371f034231aSEd Maste }
372f034231aSEd Maste
SetSelectedThreadByIndexID(uint32_t index_id)37314f1b3e8SDimitry Andric bool SBProcess::SetSelectedThreadByIndexID(uint32_t index_id) {
3746f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, index_id);
375f034231aSEd Maste
376f034231aSEd Maste bool ret_val = false;
377f034231aSEd Maste ProcessSP process_sp(GetSP());
37814f1b3e8SDimitry Andric if (process_sp) {
37914f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
38014f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
381f034231aSEd Maste ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
382f034231aSEd Maste }
383f034231aSEd Maste
384f034231aSEd Maste return ret_val;
385f034231aSEd Maste }
386f034231aSEd Maste
GetThreadAtIndex(size_t index)38714f1b3e8SDimitry Andric SBThread SBProcess::GetThreadAtIndex(size_t index) {
3886f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, index);
389f034231aSEd Maste
390f034231aSEd Maste SBThread sb_thread;
391f034231aSEd Maste ThreadSP thread_sp;
392f034231aSEd Maste ProcessSP process_sp(GetSP());
39314f1b3e8SDimitry Andric if (process_sp) {
394f034231aSEd Maste Process::StopLocker stop_locker;
395f034231aSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
39614f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
39714f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
398f034231aSEd Maste thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
399f034231aSEd Maste sb_thread.SetThread(thread_sp);
400f034231aSEd Maste }
401f034231aSEd Maste
4026f8fc217SDimitry Andric return sb_thread;
403f034231aSEd Maste }
404f034231aSEd Maste
GetNumQueues()40514f1b3e8SDimitry Andric uint32_t SBProcess::GetNumQueues() {
4066f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
407866dcdacSEd Maste
408866dcdacSEd Maste uint32_t num_queues = 0;
409866dcdacSEd Maste ProcessSP process_sp(GetSP());
41014f1b3e8SDimitry Andric if (process_sp) {
411866dcdacSEd Maste Process::StopLocker stop_locker;
41214f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
41314f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
41414f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
415866dcdacSEd Maste num_queues = process_sp->GetQueueList().GetSize();
416866dcdacSEd Maste }
417f3fbd1c0SDimitry Andric }
418866dcdacSEd Maste
419866dcdacSEd Maste return num_queues;
420866dcdacSEd Maste }
421866dcdacSEd Maste
GetQueueAtIndex(size_t index)42214f1b3e8SDimitry Andric SBQueue SBProcess::GetQueueAtIndex(size_t index) {
4236f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, index);
424866dcdacSEd Maste
425866dcdacSEd Maste SBQueue sb_queue;
426866dcdacSEd Maste QueueSP queue_sp;
427866dcdacSEd Maste ProcessSP process_sp(GetSP());
42814f1b3e8SDimitry Andric if (process_sp) {
429866dcdacSEd Maste Process::StopLocker stop_locker;
43014f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
43114f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
43214f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
433866dcdacSEd Maste queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
434866dcdacSEd Maste sb_queue.SetQueue(queue_sp);
435866dcdacSEd Maste }
436f3fbd1c0SDimitry Andric }
437866dcdacSEd Maste
4386f8fc217SDimitry Andric return sb_queue;
439866dcdacSEd Maste }
440866dcdacSEd Maste
GetStopID(bool include_expression_stops)44114f1b3e8SDimitry Andric uint32_t SBProcess::GetStopID(bool include_expression_stops) {
4426f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, include_expression_stops);
4435f29bb8aSDimitry Andric
444f034231aSEd Maste ProcessSP process_sp(GetSP());
44514f1b3e8SDimitry Andric if (process_sp) {
44614f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
44714f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
448f034231aSEd Maste if (include_expression_stops)
449f034231aSEd Maste return process_sp->GetStopID();
450f034231aSEd Maste else
451f034231aSEd Maste return process_sp->GetLastNaturalStopID();
452f034231aSEd Maste }
453f034231aSEd Maste return 0;
454f034231aSEd Maste }
455f034231aSEd Maste
GetStopEventForStopID(uint32_t stop_id)45614f1b3e8SDimitry Andric SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) {
4576f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, stop_id);
4585e95aa85SEd Maste
4595e95aa85SEd Maste SBEvent sb_event;
4605e95aa85SEd Maste EventSP event_sp;
4615e95aa85SEd Maste ProcessSP process_sp(GetSP());
46214f1b3e8SDimitry Andric if (process_sp) {
46314f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
46414f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4655e95aa85SEd Maste event_sp = process_sp->GetStopEventForStopID(stop_id);
4665e95aa85SEd Maste sb_event.reset(event_sp);
4675e95aa85SEd Maste }
4685e95aa85SEd Maste
4696f8fc217SDimitry Andric return sb_event;
4705e95aa85SEd Maste }
4715e95aa85SEd Maste
ForceScriptedState(StateType new_state)4727fa27ce4SDimitry Andric void SBProcess::ForceScriptedState(StateType new_state) {
4737fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this, new_state);
4747fa27ce4SDimitry Andric
4757fa27ce4SDimitry Andric if (ProcessSP process_sp = GetSP()) {
4767fa27ce4SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
4777fa27ce4SDimitry Andric process_sp->GetTarget().GetAPIMutex());
4787fa27ce4SDimitry Andric process_sp->ForceScriptedState(new_state);
4797fa27ce4SDimitry Andric }
4807fa27ce4SDimitry Andric }
4817fa27ce4SDimitry Andric
GetState()48214f1b3e8SDimitry Andric StateType SBProcess::GetState() {
4836f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
484f034231aSEd Maste
485f034231aSEd Maste StateType ret_val = eStateInvalid;
486f034231aSEd Maste ProcessSP process_sp(GetSP());
48714f1b3e8SDimitry Andric if (process_sp) {
48814f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
48914f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
490f034231aSEd Maste ret_val = process_sp->GetState();
491f034231aSEd Maste }
492f034231aSEd Maste
493f034231aSEd Maste return ret_val;
494f034231aSEd Maste }
495f034231aSEd Maste
GetExitStatus()49614f1b3e8SDimitry Andric int SBProcess::GetExitStatus() {
4976f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
4985f29bb8aSDimitry Andric
499f034231aSEd Maste int exit_status = 0;
500f034231aSEd Maste ProcessSP process_sp(GetSP());
50114f1b3e8SDimitry Andric if (process_sp) {
50214f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
50314f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
504f034231aSEd Maste exit_status = process_sp->GetExitStatus();
505f034231aSEd Maste }
506f034231aSEd Maste
507f034231aSEd Maste return exit_status;
508f034231aSEd Maste }
509f034231aSEd Maste
GetExitDescription()51014f1b3e8SDimitry Andric const char *SBProcess::GetExitDescription() {
5116f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
5125f29bb8aSDimitry Andric
513f034231aSEd Maste ProcessSP process_sp(GetSP());
5147fa27ce4SDimitry Andric if (!process_sp)
5157fa27ce4SDimitry Andric return nullptr;
5167fa27ce4SDimitry Andric
51714f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
51814f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
5197fa27ce4SDimitry Andric return ConstString(process_sp->GetExitDescription()).GetCString();
520f034231aSEd Maste }
521f034231aSEd Maste
GetProcessID()52214f1b3e8SDimitry Andric lldb::pid_t SBProcess::GetProcessID() {
5236f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
5245f29bb8aSDimitry Andric
525f034231aSEd Maste lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
526f034231aSEd Maste ProcessSP process_sp(GetSP());
527f034231aSEd Maste if (process_sp)
528f034231aSEd Maste ret_val = process_sp->GetID();
529f034231aSEd Maste
530f034231aSEd Maste return ret_val;
531f034231aSEd Maste }
532f034231aSEd Maste
GetUniqueID()53314f1b3e8SDimitry Andric uint32_t SBProcess::GetUniqueID() {
5346f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
5355f29bb8aSDimitry Andric
536f034231aSEd Maste uint32_t ret_val = 0;
537f034231aSEd Maste ProcessSP process_sp(GetSP());
538f034231aSEd Maste if (process_sp)
539f034231aSEd Maste ret_val = process_sp->GetUniqueID();
540f034231aSEd Maste return ret_val;
541f034231aSEd Maste }
542f034231aSEd Maste
GetByteOrder() const54314f1b3e8SDimitry Andric ByteOrder SBProcess::GetByteOrder() const {
5446f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
5455f29bb8aSDimitry Andric
546f034231aSEd Maste ByteOrder byteOrder = eByteOrderInvalid;
547f034231aSEd Maste ProcessSP process_sp(GetSP());
548f034231aSEd Maste if (process_sp)
549f034231aSEd Maste byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
550f034231aSEd Maste
551f034231aSEd Maste return byteOrder;
552f034231aSEd Maste }
553f034231aSEd Maste
GetAddressByteSize() const55414f1b3e8SDimitry Andric uint32_t SBProcess::GetAddressByteSize() const {
5556f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
5565f29bb8aSDimitry Andric
557f034231aSEd Maste uint32_t size = 0;
558f034231aSEd Maste ProcessSP process_sp(GetSP());
559f034231aSEd Maste if (process_sp)
560f034231aSEd Maste size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
561f034231aSEd Maste
562f034231aSEd Maste return size;
563f034231aSEd Maste }
564f034231aSEd Maste
Continue()56514f1b3e8SDimitry Andric SBError SBProcess::Continue() {
5666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
567f034231aSEd Maste
568f034231aSEd Maste SBError sb_error;
569f034231aSEd Maste ProcessSP process_sp(GetSP());
570f034231aSEd Maste
57114f1b3e8SDimitry Andric if (process_sp) {
57214f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
57314f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
574f034231aSEd Maste
575205afe67SEd Maste if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
576205afe67SEd Maste sb_error.ref() = process_sp->Resume();
577205afe67SEd Maste else
5785f29bb8aSDimitry Andric sb_error.ref() = process_sp->ResumeSynchronous(nullptr);
57914f1b3e8SDimitry Andric } else
580f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
581f034231aSEd Maste
5826f8fc217SDimitry Andric return sb_error;
583f034231aSEd Maste }
584f034231aSEd Maste
Destroy()58514f1b3e8SDimitry Andric SBError SBProcess::Destroy() {
5866f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
5875f29bb8aSDimitry Andric
588f034231aSEd Maste SBError sb_error;
589f034231aSEd Maste ProcessSP process_sp(GetSP());
59014f1b3e8SDimitry Andric if (process_sp) {
59114f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
59214f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
5935e95aa85SEd Maste sb_error.SetError(process_sp->Destroy(false));
59414f1b3e8SDimitry Andric } else
595f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
596f034231aSEd Maste
5976f8fc217SDimitry Andric return sb_error;
598f034231aSEd Maste }
599f034231aSEd Maste
Stop()60014f1b3e8SDimitry Andric SBError SBProcess::Stop() {
6016f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
6025f29bb8aSDimitry Andric
603f034231aSEd Maste SBError sb_error;
604f034231aSEd Maste ProcessSP process_sp(GetSP());
60514f1b3e8SDimitry Andric if (process_sp) {
60614f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
60714f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
608f034231aSEd Maste sb_error.SetError(process_sp->Halt());
60914f1b3e8SDimitry Andric } else
610f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
611f034231aSEd Maste
6126f8fc217SDimitry Andric return sb_error;
613f034231aSEd Maste }
614f034231aSEd Maste
Kill()61514f1b3e8SDimitry Andric SBError SBProcess::Kill() {
6166f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
6175f29bb8aSDimitry Andric
618f034231aSEd Maste SBError sb_error;
619f034231aSEd Maste ProcessSP process_sp(GetSP());
62014f1b3e8SDimitry Andric if (process_sp) {
62114f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
62214f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
6235e95aa85SEd Maste sb_error.SetError(process_sp->Destroy(true));
62414f1b3e8SDimitry Andric } else
625f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
626f034231aSEd Maste
6276f8fc217SDimitry Andric return sb_error;
628f034231aSEd Maste }
629f034231aSEd Maste
Detach()63014f1b3e8SDimitry Andric SBError SBProcess::Detach() {
6316f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
6325f29bb8aSDimitry Andric
633f034231aSEd Maste // FIXME: This should come from a process default.
634f034231aSEd Maste bool keep_stopped = false;
6356f8fc217SDimitry Andric return Detach(keep_stopped);
636f034231aSEd Maste }
637f034231aSEd Maste
Detach(bool keep_stopped)63814f1b3e8SDimitry Andric SBError SBProcess::Detach(bool keep_stopped) {
6396f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, keep_stopped);
6405f29bb8aSDimitry Andric
641f034231aSEd Maste SBError sb_error;
642f034231aSEd Maste ProcessSP process_sp(GetSP());
64314f1b3e8SDimitry Andric if (process_sp) {
64414f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
64514f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
646f034231aSEd Maste sb_error.SetError(process_sp->Detach(keep_stopped));
64714f1b3e8SDimitry Andric } else
648f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
649f034231aSEd Maste
6506f8fc217SDimitry Andric return sb_error;
651f034231aSEd Maste }
652f034231aSEd Maste
Signal(int signo)65314f1b3e8SDimitry Andric SBError SBProcess::Signal(int signo) {
6546f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, signo);
6555f29bb8aSDimitry Andric
656f034231aSEd Maste SBError sb_error;
657f034231aSEd Maste ProcessSP process_sp(GetSP());
65814f1b3e8SDimitry Andric if (process_sp) {
65914f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
66014f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
661f034231aSEd Maste sb_error.SetError(process_sp->Signal(signo));
66214f1b3e8SDimitry Andric } else
663f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
6645f29bb8aSDimitry Andric
6656f8fc217SDimitry Andric return sb_error;
666f034231aSEd Maste }
667f034231aSEd Maste
GetUnixSignals()66814f1b3e8SDimitry Andric SBUnixSignals SBProcess::GetUnixSignals() {
6696f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
6700cac4ca3SEd Maste
6715f29bb8aSDimitry Andric if (auto process_sp = GetSP())
6726f8fc217SDimitry Andric return SBUnixSignals{process_sp};
6735f29bb8aSDimitry Andric
6746f8fc217SDimitry Andric return SBUnixSignals{};
6750cac4ca3SEd Maste }
6760cac4ca3SEd Maste
SendAsyncInterrupt()67714f1b3e8SDimitry Andric void SBProcess::SendAsyncInterrupt() {
6786f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
6795f29bb8aSDimitry Andric
680f034231aSEd Maste ProcessSP process_sp(GetSP());
68114f1b3e8SDimitry Andric if (process_sp) {
682f034231aSEd Maste process_sp->SendAsyncInterrupt();
683f034231aSEd Maste }
684f034231aSEd Maste }
685f034231aSEd Maste
GetThreadByID(tid_t tid)68614f1b3e8SDimitry Andric SBThread SBProcess::GetThreadByID(tid_t tid) {
6876f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, tid);
6885f29bb8aSDimitry Andric
689f034231aSEd Maste SBThread sb_thread;
690f034231aSEd Maste ThreadSP thread_sp;
691f034231aSEd Maste ProcessSP process_sp(GetSP());
69214f1b3e8SDimitry Andric if (process_sp) {
693f034231aSEd Maste Process::StopLocker stop_locker;
694f034231aSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
69514f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
69614f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
697f034231aSEd Maste thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
698f034231aSEd Maste sb_thread.SetThread(thread_sp);
699f034231aSEd Maste }
700f034231aSEd Maste
7016f8fc217SDimitry Andric return sb_thread;
702f034231aSEd Maste }
703f034231aSEd Maste
GetThreadByIndexID(uint32_t index_id)70414f1b3e8SDimitry Andric SBThread SBProcess::GetThreadByIndexID(uint32_t index_id) {
7056f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, index_id);
7065f29bb8aSDimitry Andric
707f034231aSEd Maste SBThread sb_thread;
708f034231aSEd Maste ThreadSP thread_sp;
709f034231aSEd Maste ProcessSP process_sp(GetSP());
71014f1b3e8SDimitry Andric if (process_sp) {
711f034231aSEd Maste Process::StopLocker stop_locker;
712f034231aSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
71314f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
71414f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
71514f1b3e8SDimitry Andric thread_sp =
71614f1b3e8SDimitry Andric process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
717f034231aSEd Maste sb_thread.SetThread(thread_sp);
718f034231aSEd Maste }
719f034231aSEd Maste
7206f8fc217SDimitry Andric return sb_thread;
721f034231aSEd Maste }
722f034231aSEd Maste
GetStateFromEvent(const SBEvent & event)72314f1b3e8SDimitry Andric StateType SBProcess::GetStateFromEvent(const SBEvent &event) {
7246f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
725f034231aSEd Maste
726f034231aSEd Maste StateType ret_val = Process::ProcessEventData::GetStateFromEvent(event.get());
727f034231aSEd Maste
728f034231aSEd Maste return ret_val;
729f034231aSEd Maste }
730f034231aSEd Maste
GetRestartedFromEvent(const SBEvent & event)73114f1b3e8SDimitry Andric bool SBProcess::GetRestartedFromEvent(const SBEvent &event) {
7326f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7339e6d3549SDimitry Andric
7349e6d3549SDimitry Andric bool ret_val = Process::ProcessEventData::GetRestartedFromEvent(event.get());
7359e6d3549SDimitry Andric
7369e6d3549SDimitry Andric return ret_val;
737f034231aSEd Maste }
738f034231aSEd Maste
GetNumRestartedReasonsFromEvent(const lldb::SBEvent & event)73914f1b3e8SDimitry Andric size_t SBProcess::GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event) {
7406f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7415f29bb8aSDimitry Andric
742f034231aSEd Maste return Process::ProcessEventData::GetNumRestartedReasons(event.get());
743f034231aSEd Maste }
744f034231aSEd Maste
745f034231aSEd Maste const char *
GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent & event,size_t idx)74614f1b3e8SDimitry Andric SBProcess::GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event,
74714f1b3e8SDimitry Andric size_t idx) {
7486f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event, idx);
7495f29bb8aSDimitry Andric
7507fa27ce4SDimitry Andric return ConstString(Process::ProcessEventData::GetRestartedReasonAtIndex(
7517fa27ce4SDimitry Andric event.get(), idx))
7527fa27ce4SDimitry Andric .GetCString();
753f034231aSEd Maste }
754f034231aSEd Maste
GetProcessFromEvent(const SBEvent & event)75514f1b3e8SDimitry Andric SBProcess SBProcess::GetProcessFromEvent(const SBEvent &event) {
7566f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7575f29bb8aSDimitry Andric
75814f1b3e8SDimitry Andric ProcessSP process_sp =
75914f1b3e8SDimitry Andric Process::ProcessEventData::GetProcessFromEvent(event.get());
76014f1b3e8SDimitry Andric if (!process_sp) {
761f73363f1SDimitry Andric // StructuredData events also know the process they come from. Try that.
76214f1b3e8SDimitry Andric process_sp = EventDataStructuredData::GetProcessFromEvent(event.get());
763f034231aSEd Maste }
764f034231aSEd Maste
7656f8fc217SDimitry Andric return SBProcess(process_sp);
76614f1b3e8SDimitry Andric }
76714f1b3e8SDimitry Andric
GetInterruptedFromEvent(const SBEvent & event)76814f1b3e8SDimitry Andric bool SBProcess::GetInterruptedFromEvent(const SBEvent &event) {
7696f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7705f29bb8aSDimitry Andric
7715e95aa85SEd Maste return Process::ProcessEventData::GetInterruptedFromEvent(event.get());
7725e95aa85SEd Maste }
7735e95aa85SEd Maste
77414f1b3e8SDimitry Andric lldb::SBStructuredData
GetStructuredDataFromEvent(const lldb::SBEvent & event)77514f1b3e8SDimitry Andric SBProcess::GetStructuredDataFromEvent(const lldb::SBEvent &event) {
7766f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7775f29bb8aSDimitry Andric
7786f8fc217SDimitry Andric return SBStructuredData(event.GetSP());
779f034231aSEd Maste }
780f034231aSEd Maste
EventIsProcessEvent(const SBEvent & event)78114f1b3e8SDimitry Andric bool SBProcess::EventIsProcessEvent(const SBEvent &event) {
7826f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7835f29bb8aSDimitry Andric
7847fa27ce4SDimitry Andric return Process::ProcessEventData::GetEventDataFromEvent(event.get()) !=
7857fa27ce4SDimitry Andric nullptr;
78614f1b3e8SDimitry Andric }
78714f1b3e8SDimitry Andric
EventIsStructuredDataEvent(const lldb::SBEvent & event)78814f1b3e8SDimitry Andric bool SBProcess::EventIsStructuredDataEvent(const lldb::SBEvent &event) {
7896f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(event);
7905f29bb8aSDimitry Andric
79114f1b3e8SDimitry Andric EventSP event_sp = event.GetSP();
79214f1b3e8SDimitry Andric EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
79314f1b3e8SDimitry Andric return event_data && (event_data->GetFlavor() ==
79414f1b3e8SDimitry Andric EventDataStructuredData::GetFlavorString());
79514f1b3e8SDimitry Andric }
79614f1b3e8SDimitry Andric
GetBroadcaster() const79714f1b3e8SDimitry Andric SBBroadcaster SBProcess::GetBroadcaster() const {
7986f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
799f034231aSEd Maste
800f034231aSEd Maste ProcessSP process_sp(GetSP());
801f034231aSEd Maste
802f034231aSEd Maste SBBroadcaster broadcaster(process_sp.get(), false);
803f034231aSEd Maste
8046f8fc217SDimitry Andric return broadcaster;
805f034231aSEd Maste }
806f034231aSEd Maste
GetBroadcasterClass()80714f1b3e8SDimitry Andric const char *SBProcess::GetBroadcasterClass() {
8086f8fc217SDimitry Andric LLDB_INSTRUMENT();
8095f29bb8aSDimitry Andric
810ac9a064cSDimitry Andric return ConstString(Process::GetStaticBroadcasterClass()).AsCString();
811ac9a064cSDimitry Andric }
812ac9a064cSDimitry Andric
FindRangesInMemory(const void * buf,uint64_t size,const SBAddressRangeList & ranges,uint32_t alignment,uint32_t max_matches,SBError & error)813ac9a064cSDimitry Andric lldb::SBAddressRangeList SBProcess::FindRangesInMemory(
814ac9a064cSDimitry Andric const void *buf, uint64_t size, const SBAddressRangeList &ranges,
815ac9a064cSDimitry Andric uint32_t alignment, uint32_t max_matches, SBError &error) {
816ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, buf, size, ranges, alignment, max_matches, error);
817ac9a064cSDimitry Andric
818ac9a064cSDimitry Andric lldb::SBAddressRangeList matches;
819ac9a064cSDimitry Andric
820ac9a064cSDimitry Andric ProcessSP process_sp(GetSP());
821ac9a064cSDimitry Andric if (!process_sp) {
822ac9a064cSDimitry Andric error.SetErrorString("SBProcess is invalid");
823ac9a064cSDimitry Andric return matches;
824ac9a064cSDimitry Andric }
825ac9a064cSDimitry Andric Process::StopLocker stop_locker;
826ac9a064cSDimitry Andric if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
827ac9a064cSDimitry Andric error.SetErrorString("process is running");
828ac9a064cSDimitry Andric return matches;
829ac9a064cSDimitry Andric }
830ac9a064cSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
831ac9a064cSDimitry Andric process_sp->GetTarget().GetAPIMutex());
832ac9a064cSDimitry Andric matches.m_opaque_up->ref() = process_sp->FindRangesInMemory(
833ac9a064cSDimitry Andric reinterpret_cast<const uint8_t *>(buf), size, ranges.ref().ref(),
834ac9a064cSDimitry Andric alignment, max_matches, error.ref());
835ac9a064cSDimitry Andric return matches;
836ac9a064cSDimitry Andric }
837ac9a064cSDimitry Andric
FindInMemory(const void * buf,uint64_t size,const SBAddressRange & range,uint32_t alignment,SBError & error)838ac9a064cSDimitry Andric lldb::addr_t SBProcess::FindInMemory(const void *buf, uint64_t size,
839ac9a064cSDimitry Andric const SBAddressRange &range,
840ac9a064cSDimitry Andric uint32_t alignment, SBError &error) {
841ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, buf, size, range, alignment, error);
842ac9a064cSDimitry Andric
843ac9a064cSDimitry Andric ProcessSP process_sp(GetSP());
844ac9a064cSDimitry Andric
845ac9a064cSDimitry Andric if (!process_sp) {
846ac9a064cSDimitry Andric error.SetErrorString("SBProcess is invalid");
847ac9a064cSDimitry Andric return LLDB_INVALID_ADDRESS;
848ac9a064cSDimitry Andric }
849ac9a064cSDimitry Andric
850ac9a064cSDimitry Andric Process::StopLocker stop_locker;
851ac9a064cSDimitry Andric if (!stop_locker.TryLock(&process_sp->GetRunLock())) {
852ac9a064cSDimitry Andric error.SetErrorString("process is running");
853ac9a064cSDimitry Andric return LLDB_INVALID_ADDRESS;
854ac9a064cSDimitry Andric }
855ac9a064cSDimitry Andric
856ac9a064cSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
857ac9a064cSDimitry Andric process_sp->GetTarget().GetAPIMutex());
858ac9a064cSDimitry Andric return process_sp->FindInMemory(reinterpret_cast<const uint8_t *>(buf), size,
859ac9a064cSDimitry Andric range.ref(), alignment, error.ref());
860f034231aSEd Maste }
861f034231aSEd Maste
ReadMemory(addr_t addr,void * dst,size_t dst_len,SBError & sb_error)86214f1b3e8SDimitry Andric size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
86314f1b3e8SDimitry Andric SBError &sb_error) {
8646f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, addr, dst, dst_len, sb_error);
865f034231aSEd Maste
8667fa27ce4SDimitry Andric if (!dst) {
8677fa27ce4SDimitry Andric sb_error.SetErrorStringWithFormat(
8687fa27ce4SDimitry Andric "no buffer provided to read %zu bytes into", dst_len);
8697fa27ce4SDimitry Andric return 0;
8707fa27ce4SDimitry Andric }
871f034231aSEd Maste
8727fa27ce4SDimitry Andric size_t bytes_read = 0;
873f034231aSEd Maste ProcessSP process_sp(GetSP());
874f034231aSEd Maste
875f034231aSEd Maste
87614f1b3e8SDimitry Andric if (process_sp) {
877f034231aSEd Maste Process::StopLocker stop_locker;
87814f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
87914f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
88014f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
881f034231aSEd Maste bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
88214f1b3e8SDimitry Andric } else {
883f034231aSEd Maste sb_error.SetErrorString("process is running");
884f034231aSEd Maste }
88514f1b3e8SDimitry Andric } else {
886f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
887f034231aSEd Maste }
888f034231aSEd Maste
889f034231aSEd Maste return bytes_read;
890f034231aSEd Maste }
891f034231aSEd Maste
ReadCStringFromMemory(addr_t addr,void * buf,size_t size,lldb::SBError & sb_error)89214f1b3e8SDimitry Andric size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
89314f1b3e8SDimitry Andric lldb::SBError &sb_error) {
8946f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, addr, buf, size, sb_error);
8955f29bb8aSDimitry Andric
896f034231aSEd Maste size_t bytes_read = 0;
897f034231aSEd Maste ProcessSP process_sp(GetSP());
89814f1b3e8SDimitry Andric if (process_sp) {
899f034231aSEd Maste Process::StopLocker stop_locker;
90014f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
90114f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
90214f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
90314f1b3e8SDimitry Andric bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
90414f1b3e8SDimitry Andric sb_error.ref());
90514f1b3e8SDimitry Andric } else {
906f034231aSEd Maste sb_error.SetErrorString("process is running");
907f034231aSEd Maste }
90814f1b3e8SDimitry Andric } else {
909f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
910f034231aSEd Maste }
911f034231aSEd Maste return bytes_read;
912f034231aSEd Maste }
913f034231aSEd Maste
ReadUnsignedFromMemory(addr_t addr,uint32_t byte_size,lldb::SBError & sb_error)91414f1b3e8SDimitry Andric uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
91514f1b3e8SDimitry Andric lldb::SBError &sb_error) {
9166f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, addr, byte_size, sb_error);
9175f29bb8aSDimitry Andric
918f034231aSEd Maste uint64_t value = 0;
919f034231aSEd Maste ProcessSP process_sp(GetSP());
92014f1b3e8SDimitry Andric if (process_sp) {
921f034231aSEd Maste Process::StopLocker stop_locker;
92214f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
92314f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
92414f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
92514f1b3e8SDimitry Andric value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
92614f1b3e8SDimitry Andric sb_error.ref());
92714f1b3e8SDimitry Andric } else {
928f034231aSEd Maste sb_error.SetErrorString("process is running");
929f034231aSEd Maste }
93014f1b3e8SDimitry Andric } else {
931f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
932f034231aSEd Maste }
933f034231aSEd Maste return value;
934f034231aSEd Maste }
935f034231aSEd Maste
ReadPointerFromMemory(addr_t addr,lldb::SBError & sb_error)93614f1b3e8SDimitry Andric lldb::addr_t SBProcess::ReadPointerFromMemory(addr_t addr,
93714f1b3e8SDimitry Andric lldb::SBError &sb_error) {
9386f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, addr, sb_error);
9395f29bb8aSDimitry Andric
940f034231aSEd Maste lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
941f034231aSEd Maste ProcessSP process_sp(GetSP());
94214f1b3e8SDimitry Andric if (process_sp) {
943f034231aSEd Maste Process::StopLocker stop_locker;
94414f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
94514f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
94614f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
947f034231aSEd Maste ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref());
94814f1b3e8SDimitry Andric } else {
949f034231aSEd Maste sb_error.SetErrorString("process is running");
950f034231aSEd Maste }
95114f1b3e8SDimitry Andric } else {
952f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
953f034231aSEd Maste }
954f034231aSEd Maste return ptr;
955f034231aSEd Maste }
956f034231aSEd Maste
WriteMemory(addr_t addr,const void * src,size_t src_len,SBError & sb_error)95714f1b3e8SDimitry Andric size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
95814f1b3e8SDimitry Andric SBError &sb_error) {
9596f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, addr, src, src_len, sb_error);
9605f29bb8aSDimitry Andric
961f034231aSEd Maste size_t bytes_written = 0;
962f034231aSEd Maste
963f034231aSEd Maste ProcessSP process_sp(GetSP());
964f034231aSEd Maste
96514f1b3e8SDimitry Andric if (process_sp) {
966f034231aSEd Maste Process::StopLocker stop_locker;
96714f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
96814f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
96914f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
97014f1b3e8SDimitry Andric bytes_written =
97114f1b3e8SDimitry Andric process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
97214f1b3e8SDimitry Andric } else {
973f034231aSEd Maste sb_error.SetErrorString("process is running");
974f034231aSEd Maste }
975f034231aSEd Maste }
976f034231aSEd Maste
977f034231aSEd Maste return bytes_written;
978f034231aSEd Maste }
979f034231aSEd Maste
GetStatus(SBStream & status)980ac9a064cSDimitry Andric void SBProcess::GetStatus(SBStream &status) {
981ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, status);
982ac9a064cSDimitry Andric
983ac9a064cSDimitry Andric ProcessSP process_sp(GetSP());
984ac9a064cSDimitry Andric if (process_sp)
985ac9a064cSDimitry Andric process_sp->GetStatus(status.ref());
986ac9a064cSDimitry Andric }
987ac9a064cSDimitry Andric
GetDescription(SBStream & description)98814f1b3e8SDimitry Andric bool SBProcess::GetDescription(SBStream &description) {
9896f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, description);
9905f29bb8aSDimitry Andric
991f034231aSEd Maste Stream &strm = description.ref();
992f034231aSEd Maste
993f034231aSEd Maste ProcessSP process_sp(GetSP());
99414f1b3e8SDimitry Andric if (process_sp) {
995f034231aSEd Maste char path[PATH_MAX];
996f034231aSEd Maste GetTarget().GetExecutable().GetPath(path, sizeof(path));
997f034231aSEd Maste Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
9985f29bb8aSDimitry Andric const char *exe_name = nullptr;
999f034231aSEd Maste if (exe_module)
1000f034231aSEd Maste exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1001f034231aSEd Maste
1002f034231aSEd Maste strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
100314f1b3e8SDimitry Andric process_sp->GetID(), lldb_private::StateAsCString(GetState()),
100414f1b3e8SDimitry Andric GetNumThreads(), exe_name ? ", executable = " : "",
1005f034231aSEd Maste exe_name ? exe_name : "");
100614f1b3e8SDimitry Andric } else
1007f034231aSEd Maste strm.PutCString("No value");
1008f034231aSEd Maste
1009f034231aSEd Maste return true;
1010f034231aSEd Maste }
1011f034231aSEd Maste
GetExtendedCrashInformation()1012cfca06d7SDimitry Andric SBStructuredData SBProcess::GetExtendedCrashInformation() {
10136f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
1014cfca06d7SDimitry Andric SBStructuredData data;
1015cfca06d7SDimitry Andric ProcessSP process_sp(GetSP());
1016cfca06d7SDimitry Andric if (!process_sp)
10176f8fc217SDimitry Andric return data;
1018cfca06d7SDimitry Andric
1019cfca06d7SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1020cfca06d7SDimitry Andric
1021cfca06d7SDimitry Andric if (!platform_sp)
10226f8fc217SDimitry Andric return data;
1023cfca06d7SDimitry Andric
1024cfca06d7SDimitry Andric auto expected_data =
1025cfca06d7SDimitry Andric platform_sp->FetchExtendedCrashInformation(*process_sp.get());
1026cfca06d7SDimitry Andric
1027cfca06d7SDimitry Andric if (!expected_data)
10286f8fc217SDimitry Andric return data;
1029cfca06d7SDimitry Andric
1030cfca06d7SDimitry Andric StructuredData::ObjectSP fetched_data = *expected_data;
1031cfca06d7SDimitry Andric data.m_impl_up->SetObjectSP(fetched_data);
10326f8fc217SDimitry Andric return data;
1033cfca06d7SDimitry Andric }
1034cfca06d7SDimitry Andric
1035f034231aSEd Maste uint32_t
GetNumSupportedHardwareWatchpoints(lldb::SBError & sb_error) const103614f1b3e8SDimitry Andric SBProcess::GetNumSupportedHardwareWatchpoints(lldb::SBError &sb_error) const {
10376f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_error);
1038f034231aSEd Maste
1039f034231aSEd Maste uint32_t num = 0;
1040f034231aSEd Maste ProcessSP process_sp(GetSP());
104114f1b3e8SDimitry Andric if (process_sp) {
104214f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
104314f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
10447fa27ce4SDimitry Andric std::optional<uint32_t> actual_num = process_sp->GetWatchpointSlotCount();
10457fa27ce4SDimitry Andric if (actual_num) {
10467fa27ce4SDimitry Andric num = *actual_num;
10477fa27ce4SDimitry Andric } else {
10487fa27ce4SDimitry Andric sb_error.SetErrorString("Unable to determine number of watchpoints");
10497fa27ce4SDimitry Andric }
105014f1b3e8SDimitry Andric } else {
1051f034231aSEd Maste sb_error.SetErrorString("SBProcess is invalid");
1052f034231aSEd Maste }
1053f034231aSEd Maste return num;
1054f034231aSEd Maste }
1055f034231aSEd Maste
LoadImage(lldb::SBFileSpec & sb_remote_image_spec,lldb::SBError & sb_error)105614f1b3e8SDimitry Andric uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
105714f1b3e8SDimitry Andric lldb::SBError &sb_error) {
10586f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_remote_image_spec, sb_error);
10595f29bb8aSDimitry Andric
1060e81d9d49SDimitry Andric return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
1061e81d9d49SDimitry Andric }
1062e81d9d49SDimitry Andric
LoadImage(const lldb::SBFileSpec & sb_local_image_spec,const lldb::SBFileSpec & sb_remote_image_spec,lldb::SBError & sb_error)106314f1b3e8SDimitry Andric uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
1064e81d9d49SDimitry Andric const lldb::SBFileSpec &sb_remote_image_spec,
106514f1b3e8SDimitry Andric lldb::SBError &sb_error) {
10666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, sb_local_image_spec, sb_remote_image_spec, sb_error);
10675f29bb8aSDimitry Andric
1068f034231aSEd Maste ProcessSP process_sp(GetSP());
106914f1b3e8SDimitry Andric if (process_sp) {
1070f034231aSEd Maste Process::StopLocker stop_locker;
107114f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
107214f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
107314f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1074e81d9d49SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
107514f1b3e8SDimitry Andric return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
107614f1b3e8SDimitry Andric *sb_remote_image_spec, sb_error.ref());
107714f1b3e8SDimitry Andric } else {
1078f034231aSEd Maste sb_error.SetErrorString("process is running");
1079f034231aSEd Maste }
10808b4000f1SDimitry Andric } else {
10818b4000f1SDimitry Andric sb_error.SetErrorString("process is invalid");
1082f034231aSEd Maste }
1083f034231aSEd Maste return LLDB_INVALID_IMAGE_TOKEN;
1084f034231aSEd Maste }
1085f034231aSEd Maste
LoadImageUsingPaths(const lldb::SBFileSpec & image_spec,SBStringList & paths,lldb::SBFileSpec & loaded_path,lldb::SBError & error)1086f73363f1SDimitry Andric uint32_t SBProcess::LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
1087f73363f1SDimitry Andric SBStringList &paths,
1088f73363f1SDimitry Andric lldb::SBFileSpec &loaded_path,
1089f73363f1SDimitry Andric lldb::SBError &error) {
10906f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, image_spec, paths, loaded_path, error);
10915f29bb8aSDimitry Andric
1092f73363f1SDimitry Andric ProcessSP process_sp(GetSP());
1093f73363f1SDimitry Andric if (process_sp) {
1094f73363f1SDimitry Andric Process::StopLocker stop_locker;
1095f73363f1SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1096f73363f1SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1097f73363f1SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1098f73363f1SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1099f73363f1SDimitry Andric size_t num_paths = paths.GetSize();
1100f73363f1SDimitry Andric std::vector<std::string> paths_vec;
1101f73363f1SDimitry Andric paths_vec.reserve(num_paths);
1102f73363f1SDimitry Andric for (size_t i = 0; i < num_paths; i++)
1103f73363f1SDimitry Andric paths_vec.push_back(paths.GetStringAtIndex(i));
1104f73363f1SDimitry Andric FileSpec loaded_spec;
1105f73363f1SDimitry Andric
11065f29bb8aSDimitry Andric uint32_t token = platform_sp->LoadImageUsingPaths(
11075f29bb8aSDimitry Andric process_sp.get(), *image_spec, paths_vec, error.ref(), &loaded_spec);
1108f73363f1SDimitry Andric if (token != LLDB_INVALID_IMAGE_TOKEN)
1109f73363f1SDimitry Andric loaded_path = loaded_spec;
1110f73363f1SDimitry Andric return token;
1111f73363f1SDimitry Andric } else {
1112f73363f1SDimitry Andric error.SetErrorString("process is running");
1113f73363f1SDimitry Andric }
1114f73363f1SDimitry Andric } else {
1115f73363f1SDimitry Andric error.SetErrorString("process is invalid");
1116f73363f1SDimitry Andric }
1117f73363f1SDimitry Andric
1118f73363f1SDimitry Andric return LLDB_INVALID_IMAGE_TOKEN;
1119f73363f1SDimitry Andric }
1120f73363f1SDimitry Andric
UnloadImage(uint32_t image_token)112114f1b3e8SDimitry Andric lldb::SBError SBProcess::UnloadImage(uint32_t image_token) {
11226f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, image_token);
11235f29bb8aSDimitry Andric
1124f034231aSEd Maste lldb::SBError sb_error;
1125f034231aSEd Maste ProcessSP process_sp(GetSP());
112614f1b3e8SDimitry Andric if (process_sp) {
1127f034231aSEd Maste Process::StopLocker stop_locker;
112814f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
112914f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
113014f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1131e81d9d49SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
113214f1b3e8SDimitry Andric sb_error.SetError(
113314f1b3e8SDimitry Andric platform_sp->UnloadImage(process_sp.get(), image_token));
113414f1b3e8SDimitry Andric } else {
11350cac4ca3SEd Maste sb_error.SetErrorString("process is running");
11360cac4ca3SEd Maste }
113714f1b3e8SDimitry Andric } else
11380cac4ca3SEd Maste sb_error.SetErrorString("invalid process");
11396f8fc217SDimitry Andric return sb_error;
11400cac4ca3SEd Maste }
11410cac4ca3SEd Maste
SendEventData(const char * event_data)114214f1b3e8SDimitry Andric lldb::SBError SBProcess::SendEventData(const char *event_data) {
11436f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, event_data);
11445f29bb8aSDimitry Andric
11450cac4ca3SEd Maste lldb::SBError sb_error;
11460cac4ca3SEd Maste ProcessSP process_sp(GetSP());
114714f1b3e8SDimitry Andric if (process_sp) {
11480cac4ca3SEd Maste Process::StopLocker stop_locker;
114914f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
115014f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
115114f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
11520cac4ca3SEd Maste sb_error.SetError(process_sp->SendEventData(event_data));
115314f1b3e8SDimitry Andric } else {
1154f034231aSEd Maste sb_error.SetErrorString("process is running");
1155f034231aSEd Maste }
115614f1b3e8SDimitry Andric } else
1157f034231aSEd Maste sb_error.SetErrorString("invalid process");
11586f8fc217SDimitry Andric return sb_error;
1159f034231aSEd Maste }
1160f21a844fSEd Maste
GetNumExtendedBacktraceTypes()116114f1b3e8SDimitry Andric uint32_t SBProcess::GetNumExtendedBacktraceTypes() {
11626f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
11635f29bb8aSDimitry Andric
1164f21a844fSEd Maste ProcessSP process_sp(GetSP());
116514f1b3e8SDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
1166f21a844fSEd Maste SystemRuntime *runtime = process_sp->GetSystemRuntime();
1167f21a844fSEd Maste return runtime->GetExtendedBacktraceTypes().size();
1168f21a844fSEd Maste }
1169f21a844fSEd Maste return 0;
1170f21a844fSEd Maste }
1171f21a844fSEd Maste
GetExtendedBacktraceTypeAtIndex(uint32_t idx)117214f1b3e8SDimitry Andric const char *SBProcess::GetExtendedBacktraceTypeAtIndex(uint32_t idx) {
11736f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, idx);
11745f29bb8aSDimitry Andric
1175f21a844fSEd Maste ProcessSP process_sp(GetSP());
117614f1b3e8SDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
1177f21a844fSEd Maste SystemRuntime *runtime = process_sp->GetSystemRuntime();
117814f1b3e8SDimitry Andric const std::vector<ConstString> &names =
117914f1b3e8SDimitry Andric runtime->GetExtendedBacktraceTypes();
118014f1b3e8SDimitry Andric if (idx < names.size()) {
1181f21a844fSEd Maste return names[idx].AsCString();
1182f21a844fSEd Maste }
1183f21a844fSEd Maste }
11845f29bb8aSDimitry Andric return nullptr;
1185f21a844fSEd Maste }
1186205afe67SEd Maste
GetHistoryThreads(addr_t addr)118714f1b3e8SDimitry Andric SBThreadCollection SBProcess::GetHistoryThreads(addr_t addr) {
11886f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, addr);
11895f29bb8aSDimitry Andric
1190205afe67SEd Maste ProcessSP process_sp(GetSP());
1191205afe67SEd Maste SBThreadCollection threads;
119214f1b3e8SDimitry Andric if (process_sp) {
1193205afe67SEd Maste threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1194205afe67SEd Maste }
11956f8fc217SDimitry Andric return threads;
1196205afe67SEd Maste }
1197205afe67SEd Maste
IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)119814f1b3e8SDimitry Andric bool SBProcess::IsInstrumentationRuntimePresent(
119914f1b3e8SDimitry Andric InstrumentationRuntimeType type) {
12006f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, type);
12015f29bb8aSDimitry Andric
1202205afe67SEd Maste ProcessSP process_sp(GetSP());
1203205afe67SEd Maste if (!process_sp)
1204205afe67SEd Maste return false;
1205205afe67SEd Maste
1206ead24645SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1207ead24645SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1208ead24645SDimitry Andric
120914f1b3e8SDimitry Andric InstrumentationRuntimeSP runtime_sp =
121014f1b3e8SDimitry Andric process_sp->GetInstrumentationRuntime(type);
1211205afe67SEd Maste
1212205afe67SEd Maste if (!runtime_sp.get())
1213205afe67SEd Maste return false;
1214205afe67SEd Maste
1215205afe67SEd Maste return runtime_sp->IsActive();
1216205afe67SEd Maste }
1217e81d9d49SDimitry Andric
SaveCore(const char * file_name)121814f1b3e8SDimitry Andric lldb::SBError SBProcess::SaveCore(const char *file_name) {
12196f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, file_name);
1220ac9a064cSDimitry Andric SBSaveCoreOptions options;
1221ac9a064cSDimitry Andric options.SetOutputFile(SBFileSpec(file_name));
1222ac9a064cSDimitry Andric options.SetStyle(SaveCoreStyle::eSaveCoreFull);
1223ac9a064cSDimitry Andric return SaveCore(options);
1224145449b1SDimitry Andric }
1225145449b1SDimitry Andric
SaveCore(const char * file_name,const char * flavor,SaveCoreStyle core_style)1226145449b1SDimitry Andric lldb::SBError SBProcess::SaveCore(const char *file_name,
1227145449b1SDimitry Andric const char *flavor,
1228145449b1SDimitry Andric SaveCoreStyle core_style) {
1229145449b1SDimitry Andric LLDB_INSTRUMENT_VA(this, file_name, flavor, core_style);
1230ac9a064cSDimitry Andric SBSaveCoreOptions options;
1231ac9a064cSDimitry Andric options.SetOutputFile(SBFileSpec(file_name));
1232ac9a064cSDimitry Andric options.SetStyle(core_style);
1233ac9a064cSDimitry Andric SBError error = options.SetPluginName(flavor);
1234ac9a064cSDimitry Andric if (error.Fail())
1235ac9a064cSDimitry Andric return error;
1236ac9a064cSDimitry Andric return SaveCore(options);
1237ac9a064cSDimitry Andric }
1238ac9a064cSDimitry Andric
SaveCore(SBSaveCoreOptions & options)1239ac9a064cSDimitry Andric lldb::SBError SBProcess::SaveCore(SBSaveCoreOptions &options) {
1240ac9a064cSDimitry Andric
1241ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, options);
12425f29bb8aSDimitry Andric
1243e81d9d49SDimitry Andric lldb::SBError error;
1244e81d9d49SDimitry Andric ProcessSP process_sp(GetSP());
124514f1b3e8SDimitry Andric if (!process_sp) {
1246e81d9d49SDimitry Andric error.SetErrorString("SBProcess is invalid");
12476f8fc217SDimitry Andric return error;
1248e81d9d49SDimitry Andric }
1249e81d9d49SDimitry Andric
125014f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
125114f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1252e81d9d49SDimitry Andric
125314f1b3e8SDimitry Andric if (process_sp->GetState() != eStateStopped) {
1254e81d9d49SDimitry Andric error.SetErrorString("the process is not stopped");
12556f8fc217SDimitry Andric return error;
1256e81d9d49SDimitry Andric }
1257e81d9d49SDimitry Andric
1258ac9a064cSDimitry Andric error.ref() = PluginManager::SaveCore(process_sp, options.ref());
1259145449b1SDimitry Andric
12606f8fc217SDimitry Andric return error;
1261e81d9d49SDimitry Andric }
1262f3fbd1c0SDimitry Andric
1263f3fbd1c0SDimitry Andric lldb::SBError
GetMemoryRegionInfo(lldb::addr_t load_addr,SBMemoryRegionInfo & sb_region_info)126414f1b3e8SDimitry Andric SBProcess::GetMemoryRegionInfo(lldb::addr_t load_addr,
126514f1b3e8SDimitry Andric SBMemoryRegionInfo &sb_region_info) {
12666f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, load_addr, sb_region_info);
12675f29bb8aSDimitry Andric
1268f3fbd1c0SDimitry Andric lldb::SBError sb_error;
1269f3fbd1c0SDimitry Andric ProcessSP process_sp(GetSP());
127014f1b3e8SDimitry Andric if (process_sp) {
1271f3fbd1c0SDimitry Andric Process::StopLocker stop_locker;
127214f1b3e8SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
127314f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
127414f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
127594994d37SDimitry Andric
127614f1b3e8SDimitry Andric sb_error.ref() =
127794994d37SDimitry Andric process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
127814f1b3e8SDimitry Andric } else {
1279f3fbd1c0SDimitry Andric sb_error.SetErrorString("process is running");
1280f3fbd1c0SDimitry Andric }
128114f1b3e8SDimitry Andric } else {
1282f3fbd1c0SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
1283f3fbd1c0SDimitry Andric }
12846f8fc217SDimitry Andric return sb_error;
1285f3fbd1c0SDimitry Andric }
1286f3fbd1c0SDimitry Andric
GetMemoryRegions()128714f1b3e8SDimitry Andric lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() {
12886f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
12895f29bb8aSDimitry Andric
1290f3fbd1c0SDimitry Andric lldb::SBMemoryRegionInfoList sb_region_list;
129194994d37SDimitry Andric
1292f3fbd1c0SDimitry Andric ProcessSP process_sp(GetSP());
1293f3fbd1c0SDimitry Andric Process::StopLocker stop_locker;
129494994d37SDimitry Andric if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
129514f1b3e8SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
129614f1b3e8SDimitry Andric process_sp->GetTarget().GetAPIMutex());
129794994d37SDimitry Andric
129894994d37SDimitry Andric process_sp->GetMemoryRegions(sb_region_list.ref());
1299f3fbd1c0SDimitry Andric }
130094994d37SDimitry Andric
13016f8fc217SDimitry Andric return sb_region_list;
1302f3fbd1c0SDimitry Andric }
1303ef5d0b5eSDimitry Andric
GetProcessInfo()1304ef5d0b5eSDimitry Andric lldb::SBProcessInfo SBProcess::GetProcessInfo() {
13056f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this);
13065f29bb8aSDimitry Andric
1307ef5d0b5eSDimitry Andric lldb::SBProcessInfo sb_proc_info;
1308ef5d0b5eSDimitry Andric ProcessSP process_sp(GetSP());
1309ef5d0b5eSDimitry Andric ProcessInstanceInfo proc_info;
1310ef5d0b5eSDimitry Andric if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1311ef5d0b5eSDimitry Andric sb_proc_info.SetProcessInfo(proc_info);
1312ef5d0b5eSDimitry Andric }
13136f8fc217SDimitry Andric return sb_proc_info;
13145f29bb8aSDimitry Andric }
13155f29bb8aSDimitry Andric
GetCoreFile()1316ac9a064cSDimitry Andric lldb::SBFileSpec SBProcess::GetCoreFile() {
1317ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this);
1318ac9a064cSDimitry Andric
1319ac9a064cSDimitry Andric ProcessSP process_sp(GetSP());
1320ac9a064cSDimitry Andric FileSpec core_file;
1321ac9a064cSDimitry Andric if (process_sp) {
1322ac9a064cSDimitry Andric core_file = process_sp->GetCoreFile();
1323ac9a064cSDimitry Andric }
1324ac9a064cSDimitry Andric return SBFileSpec(core_file);
1325ac9a064cSDimitry Andric }
1326ac9a064cSDimitry Andric
GetAddressMask(AddressMaskType type,AddressMaskRange addr_range)1327ac9a064cSDimitry Andric addr_t SBProcess::GetAddressMask(AddressMaskType type,
1328ac9a064cSDimitry Andric AddressMaskRange addr_range) {
1329ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, type, addr_range);
1330ac9a064cSDimitry Andric
1331ac9a064cSDimitry Andric if (ProcessSP process_sp = GetSP()) {
1332ac9a064cSDimitry Andric switch (type) {
1333ac9a064cSDimitry Andric case eAddressMaskTypeCode:
1334ac9a064cSDimitry Andric if (addr_range == eAddressMaskRangeHigh)
1335ac9a064cSDimitry Andric return process_sp->GetHighmemCodeAddressMask();
1336ac9a064cSDimitry Andric else
1337ac9a064cSDimitry Andric return process_sp->GetCodeAddressMask();
1338ac9a064cSDimitry Andric case eAddressMaskTypeData:
1339ac9a064cSDimitry Andric if (addr_range == eAddressMaskRangeHigh)
1340ac9a064cSDimitry Andric return process_sp->GetHighmemDataAddressMask();
1341ac9a064cSDimitry Andric else
1342ac9a064cSDimitry Andric return process_sp->GetDataAddressMask();
1343ac9a064cSDimitry Andric case eAddressMaskTypeAny:
1344ac9a064cSDimitry Andric if (addr_range == eAddressMaskRangeHigh)
1345ac9a064cSDimitry Andric return process_sp->GetHighmemDataAddressMask();
1346ac9a064cSDimitry Andric else
1347ac9a064cSDimitry Andric return process_sp->GetDataAddressMask();
1348ac9a064cSDimitry Andric }
1349ac9a064cSDimitry Andric }
1350ac9a064cSDimitry Andric return LLDB_INVALID_ADDRESS_MASK;
1351ac9a064cSDimitry Andric }
1352ac9a064cSDimitry Andric
SetAddressMask(AddressMaskType type,addr_t mask,AddressMaskRange addr_range)1353ac9a064cSDimitry Andric void SBProcess::SetAddressMask(AddressMaskType type, addr_t mask,
1354ac9a064cSDimitry Andric AddressMaskRange addr_range) {
1355ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, type, mask, addr_range);
1356ac9a064cSDimitry Andric
1357ac9a064cSDimitry Andric if (ProcessSP process_sp = GetSP()) {
1358ac9a064cSDimitry Andric switch (type) {
1359ac9a064cSDimitry Andric case eAddressMaskTypeCode:
1360ac9a064cSDimitry Andric if (addr_range == eAddressMaskRangeAll) {
1361ac9a064cSDimitry Andric process_sp->SetCodeAddressMask(mask);
1362ac9a064cSDimitry Andric process_sp->SetHighmemCodeAddressMask(mask);
1363ac9a064cSDimitry Andric } else if (addr_range == eAddressMaskRangeHigh) {
1364ac9a064cSDimitry Andric process_sp->SetHighmemCodeAddressMask(mask);
1365ac9a064cSDimitry Andric } else {
1366ac9a064cSDimitry Andric process_sp->SetCodeAddressMask(mask);
1367ac9a064cSDimitry Andric }
1368ac9a064cSDimitry Andric break;
1369ac9a064cSDimitry Andric case eAddressMaskTypeData:
1370ac9a064cSDimitry Andric if (addr_range == eAddressMaskRangeAll) {
1371ac9a064cSDimitry Andric process_sp->SetDataAddressMask(mask);
1372ac9a064cSDimitry Andric process_sp->SetHighmemDataAddressMask(mask);
1373ac9a064cSDimitry Andric } else if (addr_range == eAddressMaskRangeHigh) {
1374ac9a064cSDimitry Andric process_sp->SetHighmemDataAddressMask(mask);
1375ac9a064cSDimitry Andric } else {
1376ac9a064cSDimitry Andric process_sp->SetDataAddressMask(mask);
1377ac9a064cSDimitry Andric }
1378ac9a064cSDimitry Andric break;
1379ac9a064cSDimitry Andric case eAddressMaskTypeAll:
1380ac9a064cSDimitry Andric if (addr_range == eAddressMaskRangeAll) {
1381ac9a064cSDimitry Andric process_sp->SetCodeAddressMask(mask);
1382ac9a064cSDimitry Andric process_sp->SetDataAddressMask(mask);
1383ac9a064cSDimitry Andric process_sp->SetHighmemCodeAddressMask(mask);
1384ac9a064cSDimitry Andric process_sp->SetHighmemDataAddressMask(mask);
1385ac9a064cSDimitry Andric } else if (addr_range == eAddressMaskRangeHigh) {
1386ac9a064cSDimitry Andric process_sp->SetHighmemCodeAddressMask(mask);
1387ac9a064cSDimitry Andric process_sp->SetHighmemDataAddressMask(mask);
1388ac9a064cSDimitry Andric } else {
1389ac9a064cSDimitry Andric process_sp->SetCodeAddressMask(mask);
1390ac9a064cSDimitry Andric process_sp->SetDataAddressMask(mask);
1391ac9a064cSDimitry Andric }
1392ac9a064cSDimitry Andric break;
1393ac9a064cSDimitry Andric }
1394ac9a064cSDimitry Andric }
1395ac9a064cSDimitry Andric }
1396ac9a064cSDimitry Andric
SetAddressableBits(AddressMaskType type,uint32_t num_bits,AddressMaskRange addr_range)1397ac9a064cSDimitry Andric void SBProcess::SetAddressableBits(AddressMaskType type, uint32_t num_bits,
1398ac9a064cSDimitry Andric AddressMaskRange addr_range) {
1399ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, type, num_bits, addr_range);
1400ac9a064cSDimitry Andric
1401ac9a064cSDimitry Andric SetAddressMask(type, AddressableBits::AddressableBitToMask(num_bits),
1402ac9a064cSDimitry Andric addr_range);
1403ac9a064cSDimitry Andric }
1404ac9a064cSDimitry Andric
FixAddress(addr_t addr,AddressMaskType type)1405ac9a064cSDimitry Andric addr_t SBProcess::FixAddress(addr_t addr, AddressMaskType type) {
1406ac9a064cSDimitry Andric LLDB_INSTRUMENT_VA(this, addr, type);
1407ac9a064cSDimitry Andric
1408ac9a064cSDimitry Andric if (ProcessSP process_sp = GetSP()) {
1409ac9a064cSDimitry Andric if (type == eAddressMaskTypeAny)
1410ac9a064cSDimitry Andric return process_sp->FixAnyAddress(addr);
1411ac9a064cSDimitry Andric else if (type == eAddressMaskTypeData)
1412ac9a064cSDimitry Andric return process_sp->FixDataAddress(addr);
1413ac9a064cSDimitry Andric else if (type == eAddressMaskTypeCode)
1414ac9a064cSDimitry Andric return process_sp->FixCodeAddress(addr);
1415ac9a064cSDimitry Andric }
1416ac9a064cSDimitry Andric return addr;
1417ac9a064cSDimitry Andric }
1418ac9a064cSDimitry Andric
AllocateMemory(size_t size,uint32_t permissions,lldb::SBError & sb_error)1419344a3780SDimitry Andric lldb::addr_t SBProcess::AllocateMemory(size_t size, uint32_t permissions,
1420344a3780SDimitry Andric lldb::SBError &sb_error) {
14216f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, size, permissions, sb_error);
1422344a3780SDimitry Andric
1423344a3780SDimitry Andric lldb::addr_t addr = LLDB_INVALID_ADDRESS;
1424344a3780SDimitry Andric ProcessSP process_sp(GetSP());
1425344a3780SDimitry Andric if (process_sp) {
1426344a3780SDimitry Andric Process::StopLocker stop_locker;
1427344a3780SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1428344a3780SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1429344a3780SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1430344a3780SDimitry Andric addr = process_sp->AllocateMemory(size, permissions, sb_error.ref());
1431344a3780SDimitry Andric } else {
1432344a3780SDimitry Andric sb_error.SetErrorString("process is running");
1433344a3780SDimitry Andric }
1434344a3780SDimitry Andric } else {
1435344a3780SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
1436344a3780SDimitry Andric }
1437344a3780SDimitry Andric return addr;
1438344a3780SDimitry Andric }
1439344a3780SDimitry Andric
DeallocateMemory(lldb::addr_t ptr)1440344a3780SDimitry Andric lldb::SBError SBProcess::DeallocateMemory(lldb::addr_t ptr) {
14416f8fc217SDimitry Andric LLDB_INSTRUMENT_VA(this, ptr);
1442344a3780SDimitry Andric
1443344a3780SDimitry Andric lldb::SBError sb_error;
1444344a3780SDimitry Andric ProcessSP process_sp(GetSP());
1445344a3780SDimitry Andric if (process_sp) {
1446344a3780SDimitry Andric Process::StopLocker stop_locker;
1447344a3780SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1448344a3780SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1449344a3780SDimitry Andric process_sp->GetTarget().GetAPIMutex());
1450344a3780SDimitry Andric Status error = process_sp->DeallocateMemory(ptr);
1451344a3780SDimitry Andric sb_error.SetError(error);
1452344a3780SDimitry Andric } else {
1453344a3780SDimitry Andric sb_error.SetErrorString("process is running");
1454344a3780SDimitry Andric }
1455344a3780SDimitry Andric } else {
1456344a3780SDimitry Andric sb_error.SetErrorString("SBProcess is invalid");
1457344a3780SDimitry Andric }
1458344a3780SDimitry Andric return sb_error;
1459344a3780SDimitry Andric }
14607fa27ce4SDimitry Andric
GetScriptedImplementation()14617fa27ce4SDimitry Andric lldb::SBScriptObject SBProcess::GetScriptedImplementation() {
14627fa27ce4SDimitry Andric LLDB_INSTRUMENT_VA(this);
14637fa27ce4SDimitry Andric ProcessSP process_sp(GetSP());
14647fa27ce4SDimitry Andric return lldb::SBScriptObject((process_sp) ? process_sp->GetImplementation()
14657fa27ce4SDimitry Andric : nullptr,
14667fa27ce4SDimitry Andric eScriptLanguageDefault);
14677fa27ce4SDimitry Andric }
1468