1ac7ddfbfSEd Maste //===-- SBProcess.cpp -------------------------------------------*- C++ -*-===//
2ac7ddfbfSEd Maste //
3ac7ddfbfSEd Maste // The LLVM Compiler Infrastructure
4ac7ddfbfSEd Maste //
5ac7ddfbfSEd Maste // This file is distributed under the University of Illinois Open Source
6ac7ddfbfSEd Maste // License. See LICENSE.TXT for details.
7ac7ddfbfSEd Maste //
8ac7ddfbfSEd Maste //===----------------------------------------------------------------------===//
9ac7ddfbfSEd Maste
10ac7ddfbfSEd Maste #include "lldb/API/SBProcess.h"
11ac7ddfbfSEd Maste
1235617911SEd Maste #include <inttypes.h>
1335617911SEd Maste
14ac7ddfbfSEd Maste #include "lldb/lldb-defines.h"
15ac7ddfbfSEd Maste #include "lldb/lldb-types.h"
16ac7ddfbfSEd Maste
17ac7ddfbfSEd Maste #include "lldb/Core/Debugger.h"
18ac7ddfbfSEd Maste #include "lldb/Core/Module.h"
199f2f44ceSEd Maste #include "lldb/Core/PluginManager.h"
20ac7ddfbfSEd Maste #include "lldb/Core/StreamFile.h"
214bb0738eSEd Maste #include "lldb/Target/MemoryRegionInfo.h"
22ac7ddfbfSEd Maste #include "lldb/Target/Process.h"
23ac7ddfbfSEd Maste #include "lldb/Target/RegisterContext.h"
2435617911SEd Maste #include "lldb/Target/SystemRuntime.h"
25ac7ddfbfSEd Maste #include "lldb/Target/Target.h"
26ac7ddfbfSEd Maste #include "lldb/Target/Thread.h"
274ba319b5SDimitry Andric #include "lldb/Utility/Args.h"
28f678e45dSDimitry Andric #include "lldb/Utility/Log.h"
29*b5893f02SDimitry Andric #include "lldb/Utility/State.h"
30f678e45dSDimitry Andric #include "lldb/Utility/Stream.h"
31ac7ddfbfSEd Maste
32ac7ddfbfSEd Maste
33ac7ddfbfSEd Maste #include "lldb/API/SBBroadcaster.h"
34ac7ddfbfSEd Maste #include "lldb/API/SBCommandReturnObject.h"
35ac7ddfbfSEd Maste #include "lldb/API/SBDebugger.h"
36ac7ddfbfSEd Maste #include "lldb/API/SBEvent.h"
37ac7ddfbfSEd Maste #include "lldb/API/SBFileSpec.h"
384bb0738eSEd Maste #include "lldb/API/SBMemoryRegionInfo.h"
394bb0738eSEd Maste #include "lldb/API/SBMemoryRegionInfoList.h"
40ac7ddfbfSEd Maste #include "lldb/API/SBStream.h"
41ac7ddfbfSEd Maste #include "lldb/API/SBStringList.h"
42435933ddSDimitry Andric #include "lldb/API/SBStructuredData.h"
43435933ddSDimitry Andric #include "lldb/API/SBThread.h"
44435933ddSDimitry Andric #include "lldb/API/SBThreadCollection.h"
4551690af2SDimitry Andric #include "lldb/API/SBTrace.h"
4651690af2SDimitry Andric #include "lldb/API/SBTraceOptions.h"
470127ef0fSEd Maste #include "lldb/API/SBUnixSignals.h"
48ac7ddfbfSEd Maste
49ac7ddfbfSEd Maste using namespace lldb;
50ac7ddfbfSEd Maste using namespace lldb_private;
51ac7ddfbfSEd Maste
SBProcess()52435933ddSDimitry Andric SBProcess::SBProcess() : m_opaque_wp() {}
53ac7ddfbfSEd Maste
54ac7ddfbfSEd Maste //----------------------------------------------------------------------
55ac7ddfbfSEd Maste // SBProcess constructor
56ac7ddfbfSEd Maste //----------------------------------------------------------------------
57ac7ddfbfSEd Maste
SBProcess(const SBProcess & rhs)58435933ddSDimitry Andric SBProcess::SBProcess(const SBProcess &rhs) : m_opaque_wp(rhs.m_opaque_wp) {}
59ac7ddfbfSEd Maste
SBProcess(const lldb::ProcessSP & process_sp)60435933ddSDimitry Andric SBProcess::SBProcess(const lldb::ProcessSP &process_sp)
61435933ddSDimitry Andric : m_opaque_wp(process_sp) {}
62ac7ddfbfSEd Maste
operator =(const SBProcess & rhs)63435933ddSDimitry Andric const SBProcess &SBProcess::operator=(const SBProcess &rhs) {
64ac7ddfbfSEd Maste if (this != &rhs)
65ac7ddfbfSEd Maste m_opaque_wp = rhs.m_opaque_wp;
66ac7ddfbfSEd Maste return *this;
67ac7ddfbfSEd Maste }
68ac7ddfbfSEd Maste
69ac7ddfbfSEd Maste //----------------------------------------------------------------------
70ac7ddfbfSEd Maste // Destructor
71ac7ddfbfSEd Maste //----------------------------------------------------------------------
~SBProcess()72435933ddSDimitry Andric SBProcess::~SBProcess() {}
73ac7ddfbfSEd Maste
GetBroadcasterClassName()74435933ddSDimitry Andric const char *SBProcess::GetBroadcasterClassName() {
75ac7ddfbfSEd Maste return Process::GetStaticBroadcasterClass().AsCString();
76ac7ddfbfSEd Maste }
77ac7ddfbfSEd Maste
GetPluginName()78435933ddSDimitry Andric const char *SBProcess::GetPluginName() {
79ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
80435933ddSDimitry Andric if (process_sp) {
81ac7ddfbfSEd Maste return process_sp->GetPluginName().GetCString();
82ac7ddfbfSEd Maste }
83ac7ddfbfSEd Maste return "<Unknown>";
84ac7ddfbfSEd Maste }
85ac7ddfbfSEd Maste
GetShortPluginName()86435933ddSDimitry Andric const char *SBProcess::GetShortPluginName() {
87ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
88435933ddSDimitry Andric if (process_sp) {
89ac7ddfbfSEd Maste return process_sp->GetPluginName().GetCString();
90ac7ddfbfSEd Maste }
91ac7ddfbfSEd Maste return "<Unknown>";
92ac7ddfbfSEd Maste }
93ac7ddfbfSEd Maste
GetSP() const94435933ddSDimitry Andric lldb::ProcessSP SBProcess::GetSP() const { return m_opaque_wp.lock(); }
95ac7ddfbfSEd Maste
SetSP(const ProcessSP & process_sp)96435933ddSDimitry Andric void SBProcess::SetSP(const ProcessSP &process_sp) { m_opaque_wp = process_sp; }
97ac7ddfbfSEd Maste
Clear()98435933ddSDimitry Andric void SBProcess::Clear() { m_opaque_wp.reset(); }
99ac7ddfbfSEd Maste
IsValid() const100435933ddSDimitry Andric bool SBProcess::IsValid() const {
101ac7ddfbfSEd Maste ProcessSP process_sp(m_opaque_wp.lock());
102ac7ddfbfSEd Maste return ((bool)process_sp && process_sp->IsValid());
103ac7ddfbfSEd Maste }
104ac7ddfbfSEd 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)105435933ddSDimitry Andric bool SBProcess::RemoteLaunch(char const **argv, char const **envp,
106435933ddSDimitry Andric const char *stdin_path, const char *stdout_path,
107ac7ddfbfSEd Maste const char *stderr_path,
108ac7ddfbfSEd Maste const char *working_directory,
109435933ddSDimitry Andric uint32_t launch_flags, bool stop_at_entry,
110435933ddSDimitry Andric lldb::SBError &error) {
111ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1120127ef0fSEd Maste if (log)
113435933ddSDimitry Andric log->Printf("SBProcess(%p)::RemoteLaunch (argv=%p, envp=%p, stdin=%s, "
114435933ddSDimitry Andric "stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, "
115435933ddSDimitry Andric "stop_at_entry=%i, &error (%p))...",
1160127ef0fSEd Maste static_cast<void *>(m_opaque_wp.lock().get()),
1170127ef0fSEd Maste static_cast<void *>(argv), static_cast<void *>(envp),
118ac7ddfbfSEd Maste stdin_path ? stdin_path : "NULL",
119ac7ddfbfSEd Maste stdout_path ? stdout_path : "NULL",
120ac7ddfbfSEd Maste stderr_path ? stderr_path : "NULL",
121435933ddSDimitry Andric working_directory ? working_directory : "NULL", launch_flags,
122435933ddSDimitry Andric stop_at_entry, static_cast<void *>(error.get()));
123ac7ddfbfSEd Maste
124ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
125435933ddSDimitry Andric if (process_sp) {
126435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
127435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
128435933ddSDimitry Andric if (process_sp->GetState() == eStateConnected) {
129ac7ddfbfSEd Maste if (stop_at_entry)
130ac7ddfbfSEd Maste launch_flags |= eLaunchFlagStopAtEntry;
131*b5893f02SDimitry Andric ProcessLaunchInfo launch_info(FileSpec(stdin_path), FileSpec(stdout_path),
132*b5893f02SDimitry Andric FileSpec(stderr_path),
133*b5893f02SDimitry Andric FileSpec(working_directory), launch_flags);
134ac7ddfbfSEd Maste Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
135ac7ddfbfSEd Maste if (exe_module)
136ac7ddfbfSEd Maste launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
137ac7ddfbfSEd Maste if (argv)
138ac7ddfbfSEd Maste launch_info.GetArguments().AppendArguments(argv);
139ac7ddfbfSEd Maste if (envp)
1404ba319b5SDimitry Andric launch_info.GetEnvironment() = Environment(envp);
141ac7ddfbfSEd Maste error.SetError(process_sp->Launch(launch_info));
142435933ddSDimitry Andric } else {
143ac7ddfbfSEd Maste error.SetErrorString("must be in eStateConnected to call RemoteLaunch");
144ac7ddfbfSEd Maste }
145435933ddSDimitry Andric } else {
146ac7ddfbfSEd Maste error.SetErrorString("unable to attach pid");
147ac7ddfbfSEd Maste }
148ac7ddfbfSEd Maste
149ac7ddfbfSEd Maste if (log) {
150ac7ddfbfSEd Maste SBStream sstr;
151ac7ddfbfSEd Maste error.GetDescription(sstr);
1520127ef0fSEd Maste log->Printf("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s",
1530127ef0fSEd Maste static_cast<void *>(process_sp.get()),
1540127ef0fSEd Maste static_cast<void *>(error.get()), sstr.GetData());
155ac7ddfbfSEd Maste }
156ac7ddfbfSEd Maste
157ac7ddfbfSEd Maste return error.Success();
158ac7ddfbfSEd Maste }
159ac7ddfbfSEd Maste
RemoteAttachToProcessWithID(lldb::pid_t pid,lldb::SBError & error)160435933ddSDimitry Andric bool SBProcess::RemoteAttachToProcessWithID(lldb::pid_t pid,
161435933ddSDimitry Andric lldb::SBError &error) {
162ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
163435933ddSDimitry Andric if (process_sp) {
164435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
165435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
166435933ddSDimitry Andric if (process_sp->GetState() == eStateConnected) {
167ac7ddfbfSEd Maste ProcessAttachInfo attach_info;
168ac7ddfbfSEd Maste attach_info.SetProcessID(pid);
169ac7ddfbfSEd Maste error.SetError(process_sp->Attach(attach_info));
170435933ddSDimitry Andric } else {
171435933ddSDimitry Andric error.SetErrorString(
172435933ddSDimitry Andric "must be in eStateConnected to call RemoteAttachToProcessWithID");
173ac7ddfbfSEd Maste }
174435933ddSDimitry Andric } else {
175ac7ddfbfSEd Maste error.SetErrorString("unable to attach pid");
176ac7ddfbfSEd Maste }
177ac7ddfbfSEd Maste
178ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
179ac7ddfbfSEd Maste if (log) {
180ac7ddfbfSEd Maste SBStream sstr;
181ac7ddfbfSEd Maste error.GetDescription(sstr);
182435933ddSDimitry Andric log->Printf("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64
183435933ddSDimitry Andric ") => SBError (%p): %s",
1840127ef0fSEd Maste static_cast<void *>(process_sp.get()), pid,
1850127ef0fSEd Maste static_cast<void *>(error.get()), sstr.GetData());
186ac7ddfbfSEd Maste }
187ac7ddfbfSEd Maste
188ac7ddfbfSEd Maste return error.Success();
189ac7ddfbfSEd Maste }
190ac7ddfbfSEd Maste
GetNumThreads()191435933ddSDimitry Andric uint32_t SBProcess::GetNumThreads() {
192ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
193ac7ddfbfSEd Maste
194ac7ddfbfSEd Maste uint32_t num_threads = 0;
195ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
196435933ddSDimitry Andric if (process_sp) {
197ac7ddfbfSEd Maste Process::StopLocker stop_locker;
198ac7ddfbfSEd Maste
199ac7ddfbfSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
200435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
201435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
202ac7ddfbfSEd Maste num_threads = process_sp->GetThreadList().GetSize(can_update);
203ac7ddfbfSEd Maste }
204ac7ddfbfSEd Maste
205ac7ddfbfSEd Maste if (log)
2060127ef0fSEd Maste log->Printf("SBProcess(%p)::GetNumThreads () => %d",
2070127ef0fSEd Maste static_cast<void *>(process_sp.get()), num_threads);
208ac7ddfbfSEd Maste
209ac7ddfbfSEd Maste return num_threads;
210ac7ddfbfSEd Maste }
211ac7ddfbfSEd Maste
GetSelectedThread() const212435933ddSDimitry Andric SBThread SBProcess::GetSelectedThread() const {
213ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
214ac7ddfbfSEd Maste
215ac7ddfbfSEd Maste SBThread sb_thread;
216ac7ddfbfSEd Maste ThreadSP thread_sp;
217ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
218435933ddSDimitry Andric if (process_sp) {
219435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
220435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
221ac7ddfbfSEd Maste thread_sp = process_sp->GetThreadList().GetSelectedThread();
222ac7ddfbfSEd Maste sb_thread.SetThread(thread_sp);
223ac7ddfbfSEd Maste }
224ac7ddfbfSEd Maste
225ac7ddfbfSEd Maste if (log)
2260127ef0fSEd Maste log->Printf("SBProcess(%p)::GetSelectedThread () => SBThread(%p)",
2270127ef0fSEd Maste static_cast<void *>(process_sp.get()),
2280127ef0fSEd Maste static_cast<void *>(thread_sp.get()));
229ac7ddfbfSEd Maste
230ac7ddfbfSEd Maste return sb_thread;
231ac7ddfbfSEd Maste }
232ac7ddfbfSEd Maste
CreateOSPluginThread(lldb::tid_t tid,lldb::addr_t context)233435933ddSDimitry Andric SBThread SBProcess::CreateOSPluginThread(lldb::tid_t tid,
234435933ddSDimitry Andric lldb::addr_t context) {
235ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
236ac7ddfbfSEd Maste
237ac7ddfbfSEd Maste SBThread sb_thread;
238ac7ddfbfSEd Maste ThreadSP thread_sp;
239ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
240435933ddSDimitry Andric if (process_sp) {
241435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
242435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
243ac7ddfbfSEd Maste thread_sp = process_sp->CreateOSPluginThread(tid, context);
244ac7ddfbfSEd Maste sb_thread.SetThread(thread_sp);
245ac7ddfbfSEd Maste }
246ac7ddfbfSEd Maste
247ac7ddfbfSEd Maste if (log)
248435933ddSDimitry Andric log->Printf("SBProcess(%p)::CreateOSPluginThread (tid=0x%" PRIx64
249435933ddSDimitry Andric ", context=0x%" PRIx64 ") => SBThread(%p)",
2500127ef0fSEd Maste static_cast<void *>(process_sp.get()), tid, context,
2510127ef0fSEd Maste static_cast<void *>(thread_sp.get()));
252ac7ddfbfSEd Maste
253ac7ddfbfSEd Maste return sb_thread;
254ac7ddfbfSEd Maste }
255ac7ddfbfSEd Maste
GetTarget() const256435933ddSDimitry Andric SBTarget SBProcess::GetTarget() const {
257ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
258ac7ddfbfSEd Maste
259ac7ddfbfSEd Maste SBTarget sb_target;
260ac7ddfbfSEd Maste TargetSP target_sp;
261ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
262435933ddSDimitry Andric if (process_sp) {
263ac7ddfbfSEd Maste target_sp = process_sp->GetTarget().shared_from_this();
264ac7ddfbfSEd Maste sb_target.SetSP(target_sp);
265ac7ddfbfSEd Maste }
266ac7ddfbfSEd Maste
267ac7ddfbfSEd Maste if (log)
2680127ef0fSEd Maste log->Printf("SBProcess(%p)::GetTarget () => SBTarget(%p)",
2690127ef0fSEd Maste static_cast<void *>(process_sp.get()),
2700127ef0fSEd Maste static_cast<void *>(target_sp.get()));
271ac7ddfbfSEd Maste
272ac7ddfbfSEd Maste return sb_target;
273ac7ddfbfSEd Maste }
274ac7ddfbfSEd Maste
PutSTDIN(const char * src,size_t src_len)275435933ddSDimitry Andric size_t SBProcess::PutSTDIN(const char *src, size_t src_len) {
276ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
277ac7ddfbfSEd Maste
278ac7ddfbfSEd Maste size_t ret_val = 0;
279ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
280435933ddSDimitry Andric if (process_sp) {
2815517e702SDimitry Andric Status error;
282ac7ddfbfSEd Maste ret_val = process_sp->PutSTDIN(src, src_len, error);
283ac7ddfbfSEd Maste }
284ac7ddfbfSEd Maste
285ac7ddfbfSEd Maste if (log)
286435933ddSDimitry Andric log->Printf("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%" PRIu64
287435933ddSDimitry Andric ") => %" PRIu64,
2880127ef0fSEd Maste static_cast<void *>(process_sp.get()), src,
289435933ddSDimitry Andric static_cast<uint64_t>(src_len), static_cast<uint64_t>(ret_val));
290ac7ddfbfSEd Maste
291ac7ddfbfSEd Maste return ret_val;
292ac7ddfbfSEd Maste }
293ac7ddfbfSEd Maste
GetSTDOUT(char * dst,size_t dst_len) const294435933ddSDimitry Andric size_t SBProcess::GetSTDOUT(char *dst, size_t dst_len) const {
295ac7ddfbfSEd Maste size_t bytes_read = 0;
296ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
297435933ddSDimitry Andric if (process_sp) {
2985517e702SDimitry Andric Status error;
299ac7ddfbfSEd Maste bytes_read = process_sp->GetSTDOUT(dst, dst_len, error);
300ac7ddfbfSEd Maste }
301ac7ddfbfSEd Maste
302ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
303ac7ddfbfSEd Maste if (log)
304435933ddSDimitry Andric log->Printf(
305435933ddSDimitry Andric "SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64
306435933ddSDimitry Andric ") => %" PRIu64,
307435933ddSDimitry Andric static_cast<void *>(process_sp.get()), static_cast<int>(bytes_read),
308435933ddSDimitry Andric dst, static_cast<uint64_t>(dst_len), static_cast<uint64_t>(bytes_read));
309ac7ddfbfSEd Maste
310ac7ddfbfSEd Maste return bytes_read;
311ac7ddfbfSEd Maste }
312ac7ddfbfSEd Maste
GetSTDERR(char * dst,size_t dst_len) const313435933ddSDimitry Andric size_t SBProcess::GetSTDERR(char *dst, size_t dst_len) const {
314ac7ddfbfSEd Maste size_t bytes_read = 0;
315ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
316435933ddSDimitry Andric if (process_sp) {
3175517e702SDimitry Andric Status error;
318ac7ddfbfSEd Maste bytes_read = process_sp->GetSTDERR(dst, dst_len, error);
319ac7ddfbfSEd Maste }
320ac7ddfbfSEd Maste
321ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
322ac7ddfbfSEd Maste if (log)
323435933ddSDimitry Andric log->Printf(
324435933ddSDimitry Andric "SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64
325435933ddSDimitry Andric ") => %" PRIu64,
326435933ddSDimitry Andric static_cast<void *>(process_sp.get()), static_cast<int>(bytes_read),
327435933ddSDimitry Andric dst, static_cast<uint64_t>(dst_len), static_cast<uint64_t>(bytes_read));
328ac7ddfbfSEd Maste
329ac7ddfbfSEd Maste return bytes_read;
330ac7ddfbfSEd Maste }
331ac7ddfbfSEd Maste
GetAsyncProfileData(char * dst,size_t dst_len) const332435933ddSDimitry Andric size_t SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const {
333ac7ddfbfSEd Maste size_t bytes_read = 0;
334ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
335435933ddSDimitry Andric if (process_sp) {
3365517e702SDimitry Andric Status error;
337ac7ddfbfSEd Maste bytes_read = process_sp->GetAsyncProfileData(dst, dst_len, error);
338ac7ddfbfSEd Maste }
339ac7ddfbfSEd Maste
340ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
341ac7ddfbfSEd Maste if (log)
342435933ddSDimitry Andric log->Printf(
343435933ddSDimitry Andric "SBProcess(%p)::GetAsyncProfileData (dst=\"%.*s\", dst_len=%" PRIu64
344435933ddSDimitry Andric ") => %" PRIu64,
345435933ddSDimitry Andric static_cast<void *>(process_sp.get()), static_cast<int>(bytes_read),
346435933ddSDimitry Andric dst, static_cast<uint64_t>(dst_len), static_cast<uint64_t>(bytes_read));
347ac7ddfbfSEd Maste
348ac7ddfbfSEd Maste return bytes_read;
349ac7ddfbfSEd Maste }
350ac7ddfbfSEd Maste
StartTrace(SBTraceOptions & options,lldb::SBError & error)35151690af2SDimitry Andric lldb::SBTrace SBProcess::StartTrace(SBTraceOptions &options,
35251690af2SDimitry Andric lldb::SBError &error) {
35351690af2SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
35451690af2SDimitry Andric ProcessSP process_sp(GetSP());
35551690af2SDimitry Andric error.Clear();
35651690af2SDimitry Andric SBTrace trace_instance;
35751690af2SDimitry Andric trace_instance.SetSP(process_sp);
35851690af2SDimitry Andric lldb::user_id_t uid = LLDB_INVALID_UID;
35951690af2SDimitry Andric
36051690af2SDimitry Andric if (!process_sp) {
36151690af2SDimitry Andric error.SetErrorString("invalid process");
36251690af2SDimitry Andric } else {
363302affcbSDimitry Andric uid = process_sp->StartTrace(*(options.m_traceoptions_sp), error.ref());
36451690af2SDimitry Andric trace_instance.SetTraceUID(uid);
365302affcbSDimitry Andric LLDB_LOG(log, "SBProcess::returned uid - {0}", uid);
36651690af2SDimitry Andric }
36751690af2SDimitry Andric return trace_instance;
36851690af2SDimitry Andric }
36951690af2SDimitry Andric
ReportEventState(const SBEvent & event,FILE * out) const370435933ddSDimitry Andric void SBProcess::ReportEventState(const SBEvent &event, FILE *out) const {
371ac7ddfbfSEd Maste if (out == NULL)
372ac7ddfbfSEd Maste return;
373ac7ddfbfSEd Maste
374ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
375435933ddSDimitry Andric if (process_sp) {
376ac7ddfbfSEd Maste const StateType event_state = SBProcess::GetStateFromEvent(event);
377ac7ddfbfSEd Maste char message[1024];
378435933ddSDimitry Andric int message_len = ::snprintf(
379435933ddSDimitry Andric message, sizeof(message), "Process %" PRIu64 " %s\n",
380435933ddSDimitry Andric process_sp->GetID(), SBDebugger::StateAsCString(event_state));
381ac7ddfbfSEd Maste
382ac7ddfbfSEd Maste if (message_len > 0)
383ac7ddfbfSEd Maste ::fwrite(message, 1, message_len, out);
384ac7ddfbfSEd Maste }
385ac7ddfbfSEd Maste }
386ac7ddfbfSEd Maste
AppendEventStateReport(const SBEvent & event,SBCommandReturnObject & result)387435933ddSDimitry Andric void SBProcess::AppendEventStateReport(const SBEvent &event,
388435933ddSDimitry Andric SBCommandReturnObject &result) {
389ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
390435933ddSDimitry Andric if (process_sp) {
391ac7ddfbfSEd Maste const StateType event_state = SBProcess::GetStateFromEvent(event);
392ac7ddfbfSEd Maste char message[1024];
393435933ddSDimitry Andric ::snprintf(message, sizeof(message), "Process %" PRIu64 " %s\n",
394435933ddSDimitry Andric process_sp->GetID(), SBDebugger::StateAsCString(event_state));
395ac7ddfbfSEd Maste
396ac7ddfbfSEd Maste result.AppendMessage(message);
397ac7ddfbfSEd Maste }
398ac7ddfbfSEd Maste }
399ac7ddfbfSEd Maste
SetSelectedThread(const SBThread & thread)400435933ddSDimitry Andric bool SBProcess::SetSelectedThread(const SBThread &thread) {
401ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
402435933ddSDimitry Andric if (process_sp) {
403435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
404435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
405435933ddSDimitry Andric return process_sp->GetThreadList().SetSelectedThreadByID(
406435933ddSDimitry Andric thread.GetThreadID());
407ac7ddfbfSEd Maste }
408ac7ddfbfSEd Maste return false;
409ac7ddfbfSEd Maste }
410ac7ddfbfSEd Maste
SetSelectedThreadByID(lldb::tid_t tid)411435933ddSDimitry Andric bool SBProcess::SetSelectedThreadByID(lldb::tid_t tid) {
412ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
413ac7ddfbfSEd Maste
414ac7ddfbfSEd Maste bool ret_val = false;
415ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
416435933ddSDimitry Andric if (process_sp) {
417435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
418435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
419ac7ddfbfSEd Maste ret_val = process_sp->GetThreadList().SetSelectedThreadByID(tid);
420ac7ddfbfSEd Maste }
421ac7ddfbfSEd Maste
422ac7ddfbfSEd Maste if (log)
423435933ddSDimitry Andric log->Printf("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64
424435933ddSDimitry Andric ") => %s",
4250127ef0fSEd Maste static_cast<void *>(process_sp.get()), tid,
4260127ef0fSEd Maste (ret_val ? "true" : "false"));
427ac7ddfbfSEd Maste
428ac7ddfbfSEd Maste return ret_val;
429ac7ddfbfSEd Maste }
430ac7ddfbfSEd Maste
SetSelectedThreadByIndexID(uint32_t index_id)431435933ddSDimitry Andric bool SBProcess::SetSelectedThreadByIndexID(uint32_t index_id) {
432ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
433ac7ddfbfSEd Maste
434ac7ddfbfSEd Maste bool ret_val = false;
435ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
436435933ddSDimitry Andric if (process_sp) {
437435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
438435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
439ac7ddfbfSEd Maste ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID(index_id);
440ac7ddfbfSEd Maste }
441ac7ddfbfSEd Maste
442ac7ddfbfSEd Maste if (log)
443ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s",
4440127ef0fSEd Maste static_cast<void *>(process_sp.get()), index_id,
4450127ef0fSEd Maste (ret_val ? "true" : "false"));
446ac7ddfbfSEd Maste
447ac7ddfbfSEd Maste return ret_val;
448ac7ddfbfSEd Maste }
449ac7ddfbfSEd Maste
GetThreadAtIndex(size_t index)450435933ddSDimitry Andric SBThread SBProcess::GetThreadAtIndex(size_t index) {
451ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
452ac7ddfbfSEd Maste
453ac7ddfbfSEd Maste SBThread sb_thread;
454ac7ddfbfSEd Maste ThreadSP thread_sp;
455ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
456435933ddSDimitry Andric if (process_sp) {
457ac7ddfbfSEd Maste Process::StopLocker stop_locker;
458ac7ddfbfSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
459435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
460435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
461ac7ddfbfSEd Maste thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
462ac7ddfbfSEd Maste sb_thread.SetThread(thread_sp);
463ac7ddfbfSEd Maste }
464ac7ddfbfSEd Maste
465ac7ddfbfSEd Maste if (log)
466ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)",
4670127ef0fSEd Maste static_cast<void *>(process_sp.get()),
4680127ef0fSEd Maste static_cast<uint32_t>(index),
4690127ef0fSEd Maste static_cast<void *>(thread_sp.get()));
470ac7ddfbfSEd Maste
471ac7ddfbfSEd Maste return sb_thread;
472ac7ddfbfSEd Maste }
473ac7ddfbfSEd Maste
GetNumQueues()474435933ddSDimitry Andric uint32_t SBProcess::GetNumQueues() {
47512b93ac6SEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
47612b93ac6SEd Maste
47712b93ac6SEd Maste uint32_t num_queues = 0;
47812b93ac6SEd Maste ProcessSP process_sp(GetSP());
479435933ddSDimitry Andric if (process_sp) {
48012b93ac6SEd Maste Process::StopLocker stop_locker;
481435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
482435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
483435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
48412b93ac6SEd Maste num_queues = process_sp->GetQueueList().GetSize();
48512b93ac6SEd Maste }
4864bb0738eSEd Maste }
48712b93ac6SEd Maste
48812b93ac6SEd Maste if (log)
4890127ef0fSEd Maste log->Printf("SBProcess(%p)::GetNumQueues () => %d",
4900127ef0fSEd Maste static_cast<void *>(process_sp.get()), num_queues);
49112b93ac6SEd Maste
49212b93ac6SEd Maste return num_queues;
49312b93ac6SEd Maste }
49412b93ac6SEd Maste
GetQueueAtIndex(size_t index)495435933ddSDimitry Andric SBQueue SBProcess::GetQueueAtIndex(size_t index) {
49612b93ac6SEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
49712b93ac6SEd Maste
49812b93ac6SEd Maste SBQueue sb_queue;
49912b93ac6SEd Maste QueueSP queue_sp;
50012b93ac6SEd Maste ProcessSP process_sp(GetSP());
501435933ddSDimitry Andric if (process_sp) {
50212b93ac6SEd Maste Process::StopLocker stop_locker;
503435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
504435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
505435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
50612b93ac6SEd Maste queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
50712b93ac6SEd Maste sb_queue.SetQueue(queue_sp);
50812b93ac6SEd Maste }
5094bb0738eSEd Maste }
51012b93ac6SEd Maste
51112b93ac6SEd Maste if (log)
51212b93ac6SEd Maste log->Printf("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)",
5130127ef0fSEd Maste static_cast<void *>(process_sp.get()),
5140127ef0fSEd Maste static_cast<uint32_t>(index),
5150127ef0fSEd Maste static_cast<void *>(queue_sp.get()));
51612b93ac6SEd Maste
51712b93ac6SEd Maste return sb_queue;
51812b93ac6SEd Maste }
51912b93ac6SEd Maste
GetStopID(bool include_expression_stops)520435933ddSDimitry Andric uint32_t SBProcess::GetStopID(bool include_expression_stops) {
521ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
522435933ddSDimitry Andric if (process_sp) {
523435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
524435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
525ac7ddfbfSEd Maste if (include_expression_stops)
526ac7ddfbfSEd Maste return process_sp->GetStopID();
527ac7ddfbfSEd Maste else
528ac7ddfbfSEd Maste return process_sp->GetLastNaturalStopID();
529ac7ddfbfSEd Maste }
530ac7ddfbfSEd Maste return 0;
531ac7ddfbfSEd Maste }
532ac7ddfbfSEd Maste
GetStopEventForStopID(uint32_t stop_id)533435933ddSDimitry Andric SBEvent SBProcess::GetStopEventForStopID(uint32_t stop_id) {
5341c3bbb01SEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
5351c3bbb01SEd Maste
5361c3bbb01SEd Maste SBEvent sb_event;
5371c3bbb01SEd Maste EventSP event_sp;
5381c3bbb01SEd Maste ProcessSP process_sp(GetSP());
539435933ddSDimitry Andric if (process_sp) {
540435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
541435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
5421c3bbb01SEd Maste event_sp = process_sp->GetStopEventForStopID(stop_id);
5431c3bbb01SEd Maste sb_event.reset(event_sp);
5441c3bbb01SEd Maste }
5451c3bbb01SEd Maste
5461c3bbb01SEd Maste if (log)
547435933ddSDimitry Andric log->Printf("SBProcess(%p)::GetStopEventForStopID (stop_id=%" PRIu32
548435933ddSDimitry Andric ") => SBEvent(%p)",
549435933ddSDimitry Andric static_cast<void *>(process_sp.get()), stop_id,
5501c3bbb01SEd Maste static_cast<void *>(event_sp.get()));
5511c3bbb01SEd Maste
5521c3bbb01SEd Maste return sb_event;
5531c3bbb01SEd Maste }
5541c3bbb01SEd Maste
GetState()555435933ddSDimitry Andric StateType SBProcess::GetState() {
556ac7ddfbfSEd Maste
557ac7ddfbfSEd Maste StateType ret_val = eStateInvalid;
558ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
559435933ddSDimitry Andric if (process_sp) {
560435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
561435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
562ac7ddfbfSEd Maste ret_val = process_sp->GetState();
563ac7ddfbfSEd Maste }
564ac7ddfbfSEd Maste
565ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
566ac7ddfbfSEd Maste if (log)
567ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::GetState () => %s",
5680127ef0fSEd Maste static_cast<void *>(process_sp.get()),
569ac7ddfbfSEd Maste lldb_private::StateAsCString(ret_val));
570ac7ddfbfSEd Maste
571ac7ddfbfSEd Maste return ret_val;
572ac7ddfbfSEd Maste }
573ac7ddfbfSEd Maste
GetExitStatus()574435933ddSDimitry Andric int SBProcess::GetExitStatus() {
575ac7ddfbfSEd Maste int exit_status = 0;
576ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
577435933ddSDimitry Andric if (process_sp) {
578435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
579435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
580ac7ddfbfSEd Maste exit_status = process_sp->GetExitStatus();
581ac7ddfbfSEd Maste }
582ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
583ac7ddfbfSEd Maste if (log)
584ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)",
5850127ef0fSEd Maste static_cast<void *>(process_sp.get()), exit_status,
5860127ef0fSEd Maste exit_status);
587ac7ddfbfSEd Maste
588ac7ddfbfSEd Maste return exit_status;
589ac7ddfbfSEd Maste }
590ac7ddfbfSEd Maste
GetExitDescription()591435933ddSDimitry Andric const char *SBProcess::GetExitDescription() {
592ac7ddfbfSEd Maste const char *exit_desc = NULL;
593ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
594435933ddSDimitry Andric if (process_sp) {
595435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
596435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
597ac7ddfbfSEd Maste exit_desc = process_sp->GetExitDescription();
598ac7ddfbfSEd Maste }
599ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
600ac7ddfbfSEd Maste if (log)
601ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::GetExitDescription () => %s",
6020127ef0fSEd Maste static_cast<void *>(process_sp.get()), exit_desc);
603ac7ddfbfSEd Maste return exit_desc;
604ac7ddfbfSEd Maste }
605ac7ddfbfSEd Maste
GetProcessID()606435933ddSDimitry Andric lldb::pid_t SBProcess::GetProcessID() {
607ac7ddfbfSEd Maste lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
608ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
609ac7ddfbfSEd Maste if (process_sp)
610ac7ddfbfSEd Maste ret_val = process_sp->GetID();
611ac7ddfbfSEd Maste
612ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
613ac7ddfbfSEd Maste if (log)
6140127ef0fSEd Maste log->Printf("SBProcess(%p)::GetProcessID () => %" PRIu64,
6150127ef0fSEd Maste static_cast<void *>(process_sp.get()), ret_val);
616ac7ddfbfSEd Maste
617ac7ddfbfSEd Maste return ret_val;
618ac7ddfbfSEd Maste }
619ac7ddfbfSEd Maste
GetUniqueID()620435933ddSDimitry Andric uint32_t SBProcess::GetUniqueID() {
621ac7ddfbfSEd Maste uint32_t ret_val = 0;
622ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
623ac7ddfbfSEd Maste if (process_sp)
624ac7ddfbfSEd Maste ret_val = process_sp->GetUniqueID();
625ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
626ac7ddfbfSEd Maste if (log)
6270127ef0fSEd Maste log->Printf("SBProcess(%p)::GetUniqueID () => %" PRIu32,
6280127ef0fSEd Maste static_cast<void *>(process_sp.get()), ret_val);
629ac7ddfbfSEd Maste return ret_val;
630ac7ddfbfSEd Maste }
631ac7ddfbfSEd Maste
GetByteOrder() const632435933ddSDimitry Andric ByteOrder SBProcess::GetByteOrder() const {
633ac7ddfbfSEd Maste ByteOrder byteOrder = eByteOrderInvalid;
634ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
635ac7ddfbfSEd Maste if (process_sp)
636ac7ddfbfSEd Maste byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
637ac7ddfbfSEd Maste
638ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
639ac7ddfbfSEd Maste if (log)
6400127ef0fSEd Maste log->Printf("SBProcess(%p)::GetByteOrder () => %d",
6410127ef0fSEd Maste static_cast<void *>(process_sp.get()), byteOrder);
642ac7ddfbfSEd Maste
643ac7ddfbfSEd Maste return byteOrder;
644ac7ddfbfSEd Maste }
645ac7ddfbfSEd Maste
GetAddressByteSize() const646435933ddSDimitry Andric uint32_t SBProcess::GetAddressByteSize() const {
647ac7ddfbfSEd Maste uint32_t size = 0;
648ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
649ac7ddfbfSEd Maste if (process_sp)
650ac7ddfbfSEd Maste size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
651ac7ddfbfSEd Maste
652ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
653ac7ddfbfSEd Maste if (log)
6540127ef0fSEd Maste log->Printf("SBProcess(%p)::GetAddressByteSize () => %d",
6550127ef0fSEd Maste static_cast<void *>(process_sp.get()), size);
656ac7ddfbfSEd Maste
657ac7ddfbfSEd Maste return size;
658ac7ddfbfSEd Maste }
659ac7ddfbfSEd Maste
Continue()660435933ddSDimitry Andric SBError SBProcess::Continue() {
661ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
662ac7ddfbfSEd Maste
663ac7ddfbfSEd Maste SBError sb_error;
664ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
665ac7ddfbfSEd Maste
666ac7ddfbfSEd Maste if (log)
6670127ef0fSEd Maste log->Printf("SBProcess(%p)::Continue ()...",
6680127ef0fSEd Maste static_cast<void *>(process_sp.get()));
669ac7ddfbfSEd Maste
670435933ddSDimitry Andric if (process_sp) {
671435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
672435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
673ac7ddfbfSEd Maste
6747aa51b79SEd Maste if (process_sp->GetTarget().GetDebugger().GetAsyncExecution())
6757aa51b79SEd Maste sb_error.ref() = process_sp->Resume();
6767aa51b79SEd Maste else
6777aa51b79SEd Maste sb_error.ref() = process_sp->ResumeSynchronous(NULL);
678435933ddSDimitry Andric } else
679ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
680ac7ddfbfSEd Maste
681435933ddSDimitry Andric if (log) {
682ac7ddfbfSEd Maste SBStream sstr;
683ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
6840127ef0fSEd Maste log->Printf("SBProcess(%p)::Continue () => SBError (%p): %s",
6850127ef0fSEd Maste static_cast<void *>(process_sp.get()),
6860127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData());
687ac7ddfbfSEd Maste }
688ac7ddfbfSEd Maste
689ac7ddfbfSEd Maste return sb_error;
690ac7ddfbfSEd Maste }
691ac7ddfbfSEd Maste
Destroy()692435933ddSDimitry Andric SBError SBProcess::Destroy() {
693ac7ddfbfSEd Maste SBError sb_error;
694ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
695435933ddSDimitry Andric if (process_sp) {
696435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
697435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
6981c3bbb01SEd Maste sb_error.SetError(process_sp->Destroy(false));
699435933ddSDimitry Andric } else
700ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
701ac7ddfbfSEd Maste
702ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
703435933ddSDimitry Andric if (log) {
704ac7ddfbfSEd Maste SBStream sstr;
705ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
706ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::Destroy () => SBError (%p): %s",
7070127ef0fSEd Maste static_cast<void *>(process_sp.get()),
7080127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData());
709ac7ddfbfSEd Maste }
710ac7ddfbfSEd Maste
711ac7ddfbfSEd Maste return sb_error;
712ac7ddfbfSEd Maste }
713ac7ddfbfSEd Maste
Stop()714435933ddSDimitry Andric SBError SBProcess::Stop() {
715ac7ddfbfSEd Maste SBError sb_error;
716ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
717435933ddSDimitry Andric if (process_sp) {
718435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
719435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
720ac7ddfbfSEd Maste sb_error.SetError(process_sp->Halt());
721435933ddSDimitry Andric } else
722ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
723ac7ddfbfSEd Maste
724ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
725435933ddSDimitry Andric if (log) {
726ac7ddfbfSEd Maste SBStream sstr;
727ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
728ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::Stop () => SBError (%p): %s",
7290127ef0fSEd Maste static_cast<void *>(process_sp.get()),
7300127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData());
731ac7ddfbfSEd Maste }
732ac7ddfbfSEd Maste
733ac7ddfbfSEd Maste return sb_error;
734ac7ddfbfSEd Maste }
735ac7ddfbfSEd Maste
Kill()736435933ddSDimitry Andric SBError SBProcess::Kill() {
737ac7ddfbfSEd Maste SBError sb_error;
738ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
739435933ddSDimitry Andric if (process_sp) {
740435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
741435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
7421c3bbb01SEd Maste sb_error.SetError(process_sp->Destroy(true));
743435933ddSDimitry Andric } else
744ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
745ac7ddfbfSEd Maste
746ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
747435933ddSDimitry Andric if (log) {
748ac7ddfbfSEd Maste SBStream sstr;
749ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
750ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::Kill () => SBError (%p): %s",
7510127ef0fSEd Maste static_cast<void *>(process_sp.get()),
7520127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData());
753ac7ddfbfSEd Maste }
754ac7ddfbfSEd Maste
755ac7ddfbfSEd Maste return sb_error;
756ac7ddfbfSEd Maste }
757ac7ddfbfSEd Maste
Detach()758435933ddSDimitry Andric SBError SBProcess::Detach() {
759ac7ddfbfSEd Maste // FIXME: This should come from a process default.
760ac7ddfbfSEd Maste bool keep_stopped = false;
761ac7ddfbfSEd Maste return Detach(keep_stopped);
762ac7ddfbfSEd Maste }
763ac7ddfbfSEd Maste
Detach(bool keep_stopped)764435933ddSDimitry Andric SBError SBProcess::Detach(bool keep_stopped) {
765ac7ddfbfSEd Maste SBError sb_error;
766ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
767435933ddSDimitry Andric if (process_sp) {
768435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
769435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
770ac7ddfbfSEd Maste sb_error.SetError(process_sp->Detach(keep_stopped));
771435933ddSDimitry Andric } else
772ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
773ac7ddfbfSEd Maste
774ac7ddfbfSEd Maste return sb_error;
775ac7ddfbfSEd Maste }
776ac7ddfbfSEd Maste
Signal(int signo)777435933ddSDimitry Andric SBError SBProcess::Signal(int signo) {
778ac7ddfbfSEd Maste SBError sb_error;
779ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
780435933ddSDimitry Andric if (process_sp) {
781435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
782435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
783ac7ddfbfSEd Maste sb_error.SetError(process_sp->Signal(signo));
784435933ddSDimitry Andric } else
785ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
786ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
787435933ddSDimitry Andric if (log) {
788ac7ddfbfSEd Maste SBStream sstr;
789ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
790ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s",
7910127ef0fSEd Maste static_cast<void *>(process_sp.get()), signo,
7920127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData());
793ac7ddfbfSEd Maste }
794ac7ddfbfSEd Maste return sb_error;
795ac7ddfbfSEd Maste }
796ac7ddfbfSEd Maste
GetUnixSignals()797435933ddSDimitry Andric SBUnixSignals SBProcess::GetUnixSignals() {
798b91a7dfcSDimitry Andric if (auto process_sp = GetSP())
799b91a7dfcSDimitry Andric return SBUnixSignals{process_sp};
8000127ef0fSEd Maste
801b91a7dfcSDimitry Andric return {};
8020127ef0fSEd Maste }
8030127ef0fSEd Maste
SendAsyncInterrupt()804435933ddSDimitry Andric void SBProcess::SendAsyncInterrupt() {
805ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
806435933ddSDimitry Andric if (process_sp) {
807ac7ddfbfSEd Maste process_sp->SendAsyncInterrupt();
808ac7ddfbfSEd Maste }
809ac7ddfbfSEd Maste }
810ac7ddfbfSEd Maste
GetThreadByID(tid_t tid)811435933ddSDimitry Andric SBThread SBProcess::GetThreadByID(tid_t tid) {
812ac7ddfbfSEd Maste SBThread sb_thread;
813ac7ddfbfSEd Maste ThreadSP thread_sp;
814ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
815435933ddSDimitry Andric if (process_sp) {
816ac7ddfbfSEd Maste Process::StopLocker stop_locker;
817ac7ddfbfSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
818435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
819435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
820ac7ddfbfSEd Maste thread_sp = process_sp->GetThreadList().FindThreadByID(tid, can_update);
821ac7ddfbfSEd Maste sb_thread.SetThread(thread_sp);
822ac7ddfbfSEd Maste }
823ac7ddfbfSEd Maste
824ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
825ac7ddfbfSEd Maste if (log)
826435933ddSDimitry Andric log->Printf("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64
827435933ddSDimitry Andric ") => SBThread (%p)",
8280127ef0fSEd Maste static_cast<void *>(process_sp.get()), tid,
8290127ef0fSEd Maste static_cast<void *>(thread_sp.get()));
830ac7ddfbfSEd Maste
831ac7ddfbfSEd Maste return sb_thread;
832ac7ddfbfSEd Maste }
833ac7ddfbfSEd Maste
GetThreadByIndexID(uint32_t index_id)834435933ddSDimitry Andric SBThread SBProcess::GetThreadByIndexID(uint32_t index_id) {
835ac7ddfbfSEd Maste SBThread sb_thread;
836ac7ddfbfSEd Maste ThreadSP thread_sp;
837ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
838435933ddSDimitry Andric if (process_sp) {
839ac7ddfbfSEd Maste Process::StopLocker stop_locker;
840ac7ddfbfSEd Maste const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
841435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
842435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
843435933ddSDimitry Andric thread_sp =
844435933ddSDimitry Andric process_sp->GetThreadList().FindThreadByIndexID(index_id, can_update);
845ac7ddfbfSEd Maste sb_thread.SetThread(thread_sp);
846ac7ddfbfSEd Maste }
847ac7ddfbfSEd Maste
848ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
849ac7ddfbfSEd Maste if (log)
850ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)",
8510127ef0fSEd Maste static_cast<void *>(process_sp.get()), index_id,
8520127ef0fSEd Maste static_cast<void *>(thread_sp.get()));
853ac7ddfbfSEd Maste
854ac7ddfbfSEd Maste return sb_thread;
855ac7ddfbfSEd Maste }
856ac7ddfbfSEd Maste
GetStateFromEvent(const SBEvent & event)857435933ddSDimitry Andric StateType SBProcess::GetStateFromEvent(const SBEvent &event) {
858ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
859ac7ddfbfSEd Maste
860ac7ddfbfSEd Maste StateType ret_val = Process::ProcessEventData::GetStateFromEvent(event.get());
861ac7ddfbfSEd Maste
862ac7ddfbfSEd Maste if (log)
8630127ef0fSEd Maste log->Printf("SBProcess::GetStateFromEvent (event.sp=%p) => %s",
8640127ef0fSEd Maste static_cast<void *>(event.get()),
865ac7ddfbfSEd Maste lldb_private::StateAsCString(ret_val));
866ac7ddfbfSEd Maste
867ac7ddfbfSEd Maste return ret_val;
868ac7ddfbfSEd Maste }
869ac7ddfbfSEd Maste
GetRestartedFromEvent(const SBEvent & event)870435933ddSDimitry Andric bool SBProcess::GetRestartedFromEvent(const SBEvent &event) {
871a1bd240cSDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
872a1bd240cSDimitry Andric
873a1bd240cSDimitry Andric bool ret_val = Process::ProcessEventData::GetRestartedFromEvent(event.get());
874a1bd240cSDimitry Andric
875a1bd240cSDimitry Andric if (log)
87698665a58SDimitry Andric log->Printf("SBProcess::%s (event.sp=%p) => %d", __FUNCTION__,
87798665a58SDimitry Andric static_cast<void *>(event.get()), ret_val);
878a1bd240cSDimitry Andric
879a1bd240cSDimitry Andric return ret_val;
880ac7ddfbfSEd Maste }
881ac7ddfbfSEd Maste
GetNumRestartedReasonsFromEvent(const lldb::SBEvent & event)882435933ddSDimitry Andric size_t SBProcess::GetNumRestartedReasonsFromEvent(const lldb::SBEvent &event) {
883ac7ddfbfSEd Maste return Process::ProcessEventData::GetNumRestartedReasons(event.get());
884ac7ddfbfSEd Maste }
885ac7ddfbfSEd Maste
886ac7ddfbfSEd Maste const char *
GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent & event,size_t idx)887435933ddSDimitry Andric SBProcess::GetRestartedReasonAtIndexFromEvent(const lldb::SBEvent &event,
888435933ddSDimitry Andric size_t idx) {
889ac7ddfbfSEd Maste return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
890ac7ddfbfSEd Maste }
891ac7ddfbfSEd Maste
GetProcessFromEvent(const SBEvent & event)892435933ddSDimitry Andric SBProcess SBProcess::GetProcessFromEvent(const SBEvent &event) {
893435933ddSDimitry Andric ProcessSP process_sp =
894435933ddSDimitry Andric Process::ProcessEventData::GetProcessFromEvent(event.get());
895435933ddSDimitry Andric if (!process_sp) {
8964ba319b5SDimitry Andric // StructuredData events also know the process they come from. Try that.
897435933ddSDimitry Andric process_sp = EventDataStructuredData::GetProcessFromEvent(event.get());
898ac7ddfbfSEd Maste }
899ac7ddfbfSEd Maste
900435933ddSDimitry Andric return SBProcess(process_sp);
901435933ddSDimitry Andric }
902435933ddSDimitry Andric
GetInterruptedFromEvent(const SBEvent & event)903435933ddSDimitry Andric bool SBProcess::GetInterruptedFromEvent(const SBEvent &event) {
9041c3bbb01SEd Maste return Process::ProcessEventData::GetInterruptedFromEvent(event.get());
9051c3bbb01SEd Maste }
9061c3bbb01SEd Maste
907435933ddSDimitry Andric lldb::SBStructuredData
GetStructuredDataFromEvent(const lldb::SBEvent & event)908435933ddSDimitry Andric SBProcess::GetStructuredDataFromEvent(const lldb::SBEvent &event) {
909435933ddSDimitry Andric return SBStructuredData(event.GetSP());
910ac7ddfbfSEd Maste }
911ac7ddfbfSEd Maste
EventIsProcessEvent(const SBEvent & event)912435933ddSDimitry Andric bool SBProcess::EventIsProcessEvent(const SBEvent &event) {
913435933ddSDimitry Andric return (event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass()) &&
914435933ddSDimitry Andric !EventIsStructuredDataEvent(event);
915435933ddSDimitry Andric }
916435933ddSDimitry Andric
EventIsStructuredDataEvent(const lldb::SBEvent & event)917435933ddSDimitry Andric bool SBProcess::EventIsStructuredDataEvent(const lldb::SBEvent &event) {
918435933ddSDimitry Andric EventSP event_sp = event.GetSP();
919435933ddSDimitry Andric EventData *event_data = event_sp ? event_sp->GetData() : nullptr;
920435933ddSDimitry Andric return event_data && (event_data->GetFlavor() ==
921435933ddSDimitry Andric EventDataStructuredData::GetFlavorString());
922435933ddSDimitry Andric }
923435933ddSDimitry Andric
GetBroadcaster() const924435933ddSDimitry Andric SBBroadcaster SBProcess::GetBroadcaster() const {
925ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
926ac7ddfbfSEd Maste
927ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
928ac7ddfbfSEd Maste
929ac7ddfbfSEd Maste SBBroadcaster broadcaster(process_sp.get(), false);
930ac7ddfbfSEd Maste
931ac7ddfbfSEd Maste if (log)
9320127ef0fSEd Maste log->Printf("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)",
9330127ef0fSEd Maste static_cast<void *>(process_sp.get()),
9340127ef0fSEd Maste static_cast<void *>(broadcaster.get()));
935ac7ddfbfSEd Maste
936ac7ddfbfSEd Maste return broadcaster;
937ac7ddfbfSEd Maste }
938ac7ddfbfSEd Maste
GetBroadcasterClass()939435933ddSDimitry Andric const char *SBProcess::GetBroadcasterClass() {
940ac7ddfbfSEd Maste return Process::GetStaticBroadcasterClass().AsCString();
941ac7ddfbfSEd Maste }
942ac7ddfbfSEd Maste
ReadMemory(addr_t addr,void * dst,size_t dst_len,SBError & sb_error)943435933ddSDimitry Andric size_t SBProcess::ReadMemory(addr_t addr, void *dst, size_t dst_len,
944435933ddSDimitry Andric SBError &sb_error) {
945ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
946ac7ddfbfSEd Maste
947ac7ddfbfSEd Maste size_t bytes_read = 0;
948ac7ddfbfSEd Maste
949ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
950ac7ddfbfSEd Maste
951ac7ddfbfSEd Maste if (log)
952435933ddSDimitry Andric log->Printf("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64
953435933ddSDimitry Andric ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...",
9540127ef0fSEd Maste static_cast<void *>(process_sp.get()), addr,
9550127ef0fSEd Maste static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
9560127ef0fSEd Maste static_cast<void *>(sb_error.get()));
957ac7ddfbfSEd Maste
958435933ddSDimitry Andric if (process_sp) {
959ac7ddfbfSEd Maste Process::StopLocker stop_locker;
960435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
961435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
962435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
963ac7ddfbfSEd Maste bytes_read = process_sp->ReadMemory(addr, dst, dst_len, sb_error.ref());
964435933ddSDimitry Andric } else {
965ac7ddfbfSEd Maste if (log)
9660127ef0fSEd Maste log->Printf("SBProcess(%p)::ReadMemory() => error: process is running",
9670127ef0fSEd Maste static_cast<void *>(process_sp.get()));
968ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
969ac7ddfbfSEd Maste }
970435933ddSDimitry Andric } else {
971ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
972ac7ddfbfSEd Maste }
973ac7ddfbfSEd Maste
974435933ddSDimitry Andric if (log) {
975ac7ddfbfSEd Maste SBStream sstr;
976ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
977435933ddSDimitry Andric log->Printf("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64
978435933ddSDimitry Andric ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
9790127ef0fSEd Maste static_cast<void *>(process_sp.get()), addr,
9800127ef0fSEd Maste static_cast<void *>(dst), static_cast<uint64_t>(dst_len),
9810127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData(),
9820127ef0fSEd Maste static_cast<uint64_t>(bytes_read));
983ac7ddfbfSEd Maste }
984ac7ddfbfSEd Maste
985ac7ddfbfSEd Maste return bytes_read;
986ac7ddfbfSEd Maste }
987ac7ddfbfSEd Maste
ReadCStringFromMemory(addr_t addr,void * buf,size_t size,lldb::SBError & sb_error)988435933ddSDimitry Andric size_t SBProcess::ReadCStringFromMemory(addr_t addr, void *buf, size_t size,
989435933ddSDimitry Andric lldb::SBError &sb_error) {
990ac7ddfbfSEd Maste size_t bytes_read = 0;
991ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
992435933ddSDimitry Andric if (process_sp) {
993ac7ddfbfSEd Maste Process::StopLocker stop_locker;
994435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
995435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
996435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
997435933ddSDimitry Andric bytes_read = process_sp->ReadCStringFromMemory(addr, (char *)buf, size,
998435933ddSDimitry Andric sb_error.ref());
999435933ddSDimitry Andric } else {
1000ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1001ac7ddfbfSEd Maste if (log)
1002435933ddSDimitry Andric log->Printf("SBProcess(%p)::ReadCStringFromMemory() => error: process "
1003435933ddSDimitry Andric "is running",
10040127ef0fSEd Maste static_cast<void *>(process_sp.get()));
1005ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
1006ac7ddfbfSEd Maste }
1007435933ddSDimitry Andric } else {
1008ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
1009ac7ddfbfSEd Maste }
1010ac7ddfbfSEd Maste return bytes_read;
1011ac7ddfbfSEd Maste }
1012ac7ddfbfSEd Maste
ReadUnsignedFromMemory(addr_t addr,uint32_t byte_size,lldb::SBError & sb_error)1013435933ddSDimitry Andric uint64_t SBProcess::ReadUnsignedFromMemory(addr_t addr, uint32_t byte_size,
1014435933ddSDimitry Andric lldb::SBError &sb_error) {
1015ac7ddfbfSEd Maste uint64_t value = 0;
1016ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1017435933ddSDimitry Andric if (process_sp) {
1018ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1019435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1020435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1021435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
1022435933ddSDimitry Andric value = process_sp->ReadUnsignedIntegerFromMemory(addr, byte_size, 0,
1023435933ddSDimitry Andric sb_error.ref());
1024435933ddSDimitry Andric } else {
1025ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1026ac7ddfbfSEd Maste if (log)
1027435933ddSDimitry Andric log->Printf("SBProcess(%p)::ReadUnsignedFromMemory() => error: process "
1028435933ddSDimitry Andric "is running",
10290127ef0fSEd Maste static_cast<void *>(process_sp.get()));
1030ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
1031ac7ddfbfSEd Maste }
1032435933ddSDimitry Andric } else {
1033ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
1034ac7ddfbfSEd Maste }
1035ac7ddfbfSEd Maste return value;
1036ac7ddfbfSEd Maste }
1037ac7ddfbfSEd Maste
ReadPointerFromMemory(addr_t addr,lldb::SBError & sb_error)1038435933ddSDimitry Andric lldb::addr_t SBProcess::ReadPointerFromMemory(addr_t addr,
1039435933ddSDimitry Andric lldb::SBError &sb_error) {
1040ac7ddfbfSEd Maste lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
1041ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1042435933ddSDimitry Andric if (process_sp) {
1043ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1044435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1045435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1046435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
1047ac7ddfbfSEd Maste ptr = process_sp->ReadPointerFromMemory(addr, sb_error.ref());
1048435933ddSDimitry Andric } else {
1049ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1050ac7ddfbfSEd Maste if (log)
1051435933ddSDimitry Andric log->Printf("SBProcess(%p)::ReadPointerFromMemory() => error: process "
1052435933ddSDimitry Andric "is running",
10530127ef0fSEd Maste static_cast<void *>(process_sp.get()));
1054ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
1055ac7ddfbfSEd Maste }
1056435933ddSDimitry Andric } else {
1057ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
1058ac7ddfbfSEd Maste }
1059ac7ddfbfSEd Maste return ptr;
1060ac7ddfbfSEd Maste }
1061ac7ddfbfSEd Maste
WriteMemory(addr_t addr,const void * src,size_t src_len,SBError & sb_error)1062435933ddSDimitry Andric size_t SBProcess::WriteMemory(addr_t addr, const void *src, size_t src_len,
1063435933ddSDimitry Andric SBError &sb_error) {
1064ac7ddfbfSEd Maste size_t bytes_written = 0;
1065ac7ddfbfSEd Maste
1066ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1067ac7ddfbfSEd Maste
1068ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1069ac7ddfbfSEd Maste
1070ac7ddfbfSEd Maste if (log)
1071435933ddSDimitry Andric log->Printf("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64
1072435933ddSDimitry Andric ", src=%p, src_len=%" PRIu64 ", SBError (%p))...",
10730127ef0fSEd Maste static_cast<void *>(process_sp.get()), addr,
1074435933ddSDimitry Andric static_cast<const void *>(src), static_cast<uint64_t>(src_len),
10750127ef0fSEd Maste static_cast<void *>(sb_error.get()));
1076ac7ddfbfSEd Maste
1077435933ddSDimitry Andric if (process_sp) {
1078ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1079435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1080435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1081435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
1082435933ddSDimitry Andric bytes_written =
1083435933ddSDimitry Andric process_sp->WriteMemory(addr, src, src_len, sb_error.ref());
1084435933ddSDimitry Andric } else {
1085ac7ddfbfSEd Maste if (log)
10860127ef0fSEd Maste log->Printf("SBProcess(%p)::WriteMemory() => error: process is running",
10870127ef0fSEd Maste static_cast<void *>(process_sp.get()));
1088ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
1089ac7ddfbfSEd Maste }
1090ac7ddfbfSEd Maste }
1091ac7ddfbfSEd Maste
1092435933ddSDimitry Andric if (log) {
1093ac7ddfbfSEd Maste SBStream sstr;
1094ac7ddfbfSEd Maste sb_error.GetDescription(sstr);
1095435933ddSDimitry Andric log->Printf("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64
1096435933ddSDimitry Andric ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
10970127ef0fSEd Maste static_cast<void *>(process_sp.get()), addr,
1098435933ddSDimitry Andric static_cast<const void *>(src), static_cast<uint64_t>(src_len),
10990127ef0fSEd Maste static_cast<void *>(sb_error.get()), sstr.GetData(),
11000127ef0fSEd Maste static_cast<uint64_t>(bytes_written));
1101ac7ddfbfSEd Maste }
1102ac7ddfbfSEd Maste
1103ac7ddfbfSEd Maste return bytes_written;
1104ac7ddfbfSEd Maste }
1105ac7ddfbfSEd Maste
GetDescription(SBStream & description)1106435933ddSDimitry Andric bool SBProcess::GetDescription(SBStream &description) {
1107ac7ddfbfSEd Maste Stream &strm = description.ref();
1108ac7ddfbfSEd Maste
1109ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1110435933ddSDimitry Andric if (process_sp) {
1111ac7ddfbfSEd Maste char path[PATH_MAX];
1112ac7ddfbfSEd Maste GetTarget().GetExecutable().GetPath(path, sizeof(path));
1113ac7ddfbfSEd Maste Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1114ac7ddfbfSEd Maste const char *exe_name = NULL;
1115ac7ddfbfSEd Maste if (exe_module)
1116ac7ddfbfSEd Maste exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1117ac7ddfbfSEd Maste
1118ac7ddfbfSEd Maste strm.Printf("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1119435933ddSDimitry Andric process_sp->GetID(), lldb_private::StateAsCString(GetState()),
1120435933ddSDimitry Andric GetNumThreads(), exe_name ? ", executable = " : "",
1121ac7ddfbfSEd Maste exe_name ? exe_name : "");
1122435933ddSDimitry Andric } else
1123ac7ddfbfSEd Maste strm.PutCString("No value");
1124ac7ddfbfSEd Maste
1125ac7ddfbfSEd Maste return true;
1126ac7ddfbfSEd Maste }
1127ac7ddfbfSEd Maste
1128ac7ddfbfSEd Maste uint32_t
GetNumSupportedHardwareWatchpoints(lldb::SBError & sb_error) const1129435933ddSDimitry Andric SBProcess::GetNumSupportedHardwareWatchpoints(lldb::SBError &sb_error) const {
1130ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1131ac7ddfbfSEd Maste
1132ac7ddfbfSEd Maste uint32_t num = 0;
1133ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1134435933ddSDimitry Andric if (process_sp) {
1135435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1136435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
1137ac7ddfbfSEd Maste sb_error.SetError(process_sp->GetWatchpointSupportInfo(num));
1138ac7ddfbfSEd Maste if (log)
1139ac7ddfbfSEd Maste log->Printf("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u",
11400127ef0fSEd Maste static_cast<void *>(process_sp.get()), num);
1141435933ddSDimitry Andric } else {
1142ac7ddfbfSEd Maste sb_error.SetErrorString("SBProcess is invalid");
1143ac7ddfbfSEd Maste }
1144ac7ddfbfSEd Maste return num;
1145ac7ddfbfSEd Maste }
1146ac7ddfbfSEd Maste
LoadImage(lldb::SBFileSpec & sb_remote_image_spec,lldb::SBError & sb_error)1147435933ddSDimitry Andric uint32_t SBProcess::LoadImage(lldb::SBFileSpec &sb_remote_image_spec,
1148435933ddSDimitry Andric lldb::SBError &sb_error) {
11499f2f44ceSEd Maste return LoadImage(SBFileSpec(), sb_remote_image_spec, sb_error);
11509f2f44ceSEd Maste }
11519f2f44ceSEd Maste
LoadImage(const lldb::SBFileSpec & sb_local_image_spec,const lldb::SBFileSpec & sb_remote_image_spec,lldb::SBError & sb_error)1152435933ddSDimitry Andric uint32_t SBProcess::LoadImage(const lldb::SBFileSpec &sb_local_image_spec,
11539f2f44ceSEd Maste const lldb::SBFileSpec &sb_remote_image_spec,
1154435933ddSDimitry Andric lldb::SBError &sb_error) {
11550f5676f4SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1156ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1157435933ddSDimitry Andric if (process_sp) {
1158ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1159435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
11600f5676f4SDimitry Andric if (log)
11610f5676f4SDimitry Andric log->Printf("SBProcess(%p)::LoadImage() => calling Platform::LoadImage"
11620f5676f4SDimitry Andric "for: %s",
11630f5676f4SDimitry Andric static_cast<void *>(process_sp.get()),
11640f5676f4SDimitry Andric sb_local_image_spec.GetFilename());
11650f5676f4SDimitry Andric
1166435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1167435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
11689f2f44ceSEd Maste PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1169435933ddSDimitry Andric return platform_sp->LoadImage(process_sp.get(), *sb_local_image_spec,
1170435933ddSDimitry Andric *sb_remote_image_spec, sb_error.ref());
1171435933ddSDimitry Andric } else {
1172ac7ddfbfSEd Maste if (log)
11730127ef0fSEd Maste log->Printf("SBProcess(%p)::LoadImage() => error: process is running",
11740127ef0fSEd Maste static_cast<void *>(process_sp.get()));
1175ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
1176ac7ddfbfSEd Maste }
11770f5676f4SDimitry Andric } else {
11780f5676f4SDimitry Andric if (log)
11790f5676f4SDimitry Andric log->Printf("SBProcess(%p)::LoadImage() => error: called with invalid"
11800f5676f4SDimitry Andric " process",
11810f5676f4SDimitry Andric static_cast<void *>(process_sp.get()));
11820f5676f4SDimitry Andric sb_error.SetErrorString("process is invalid");
1183ac7ddfbfSEd Maste }
1184ac7ddfbfSEd Maste return LLDB_INVALID_IMAGE_TOKEN;
1185ac7ddfbfSEd Maste }
1186ac7ddfbfSEd Maste
LoadImageUsingPaths(const lldb::SBFileSpec & image_spec,SBStringList & paths,lldb::SBFileSpec & loaded_path,lldb::SBError & error)11874ba319b5SDimitry Andric uint32_t SBProcess::LoadImageUsingPaths(const lldb::SBFileSpec &image_spec,
11884ba319b5SDimitry Andric SBStringList &paths,
11894ba319b5SDimitry Andric lldb::SBFileSpec &loaded_path,
11904ba319b5SDimitry Andric lldb::SBError &error) {
11914ba319b5SDimitry Andric Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
11924ba319b5SDimitry Andric ProcessSP process_sp(GetSP());
11934ba319b5SDimitry Andric if (process_sp) {
11944ba319b5SDimitry Andric Process::StopLocker stop_locker;
11954ba319b5SDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
11964ba319b5SDimitry Andric if (log)
11974ba319b5SDimitry Andric log->Printf("SBProcess(%p)::LoadImageUsingPaths() => "
11984ba319b5SDimitry Andric "calling Platform::LoadImageUsingPaths for: %s",
11994ba319b5SDimitry Andric static_cast<void *>(process_sp.get()),
12004ba319b5SDimitry Andric image_spec.GetFilename());
12014ba319b5SDimitry Andric
12024ba319b5SDimitry Andric std::lock_guard<std::recursive_mutex> guard(
12034ba319b5SDimitry Andric process_sp->GetTarget().GetAPIMutex());
12044ba319b5SDimitry Andric PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
12054ba319b5SDimitry Andric size_t num_paths = paths.GetSize();
12064ba319b5SDimitry Andric std::vector<std::string> paths_vec;
12074ba319b5SDimitry Andric paths_vec.reserve(num_paths);
12084ba319b5SDimitry Andric for (size_t i = 0; i < num_paths; i++)
12094ba319b5SDimitry Andric paths_vec.push_back(paths.GetStringAtIndex(i));
12104ba319b5SDimitry Andric FileSpec loaded_spec;
12114ba319b5SDimitry Andric
12124ba319b5SDimitry Andric uint32_t token = platform_sp->LoadImageUsingPaths(process_sp.get(),
12134ba319b5SDimitry Andric *image_spec,
12144ba319b5SDimitry Andric paths_vec,
12154ba319b5SDimitry Andric error.ref(),
12164ba319b5SDimitry Andric &loaded_spec);
12174ba319b5SDimitry Andric if (token != LLDB_INVALID_IMAGE_TOKEN)
12184ba319b5SDimitry Andric loaded_path = loaded_spec;
12194ba319b5SDimitry Andric return token;
12204ba319b5SDimitry Andric } else {
12214ba319b5SDimitry Andric if (log)
12224ba319b5SDimitry Andric log->Printf("SBProcess(%p)::LoadImageUsingPaths() => error: "
12234ba319b5SDimitry Andric "process is running",
12244ba319b5SDimitry Andric static_cast<void *>(process_sp.get()));
12254ba319b5SDimitry Andric error.SetErrorString("process is running");
12264ba319b5SDimitry Andric }
12274ba319b5SDimitry Andric } else {
12284ba319b5SDimitry Andric if (log)
12294ba319b5SDimitry Andric log->Printf("SBProcess(%p)::LoadImageUsingPaths() => error: "
12304ba319b5SDimitry Andric "called with invalid process",
12314ba319b5SDimitry Andric static_cast<void *>(process_sp.get()));
12324ba319b5SDimitry Andric error.SetErrorString("process is invalid");
12334ba319b5SDimitry Andric }
12344ba319b5SDimitry Andric
12354ba319b5SDimitry Andric return LLDB_INVALID_IMAGE_TOKEN;
12364ba319b5SDimitry Andric }
12374ba319b5SDimitry Andric
UnloadImage(uint32_t image_token)1238435933ddSDimitry Andric lldb::SBError SBProcess::UnloadImage(uint32_t image_token) {
1239ac7ddfbfSEd Maste lldb::SBError sb_error;
1240ac7ddfbfSEd Maste ProcessSP process_sp(GetSP());
1241435933ddSDimitry Andric if (process_sp) {
1242ac7ddfbfSEd Maste Process::StopLocker stop_locker;
1243435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1244435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1245435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
12469f2f44ceSEd Maste PlatformSP platform_sp = process_sp->GetTarget().GetPlatform();
1247435933ddSDimitry Andric sb_error.SetError(
1248435933ddSDimitry Andric platform_sp->UnloadImage(process_sp.get(), image_token));
1249435933ddSDimitry Andric } else {
1250ac7ddfbfSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
1251ac7ddfbfSEd Maste if (log)
12520127ef0fSEd Maste log->Printf("SBProcess(%p)::UnloadImage() => error: process is running",
12530127ef0fSEd Maste static_cast<void *>(process_sp.get()));
12540127ef0fSEd Maste sb_error.SetErrorString("process is running");
12550127ef0fSEd Maste }
1256435933ddSDimitry Andric } else
12570127ef0fSEd Maste sb_error.SetErrorString("invalid process");
12580127ef0fSEd Maste return sb_error;
12590127ef0fSEd Maste }
12600127ef0fSEd Maste
SendEventData(const char * event_data)1261435933ddSDimitry Andric lldb::SBError SBProcess::SendEventData(const char *event_data) {
12620127ef0fSEd Maste lldb::SBError sb_error;
12630127ef0fSEd Maste ProcessSP process_sp(GetSP());
1264435933ddSDimitry Andric if (process_sp) {
12650127ef0fSEd Maste Process::StopLocker stop_locker;
1266435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1267435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1268435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
12690127ef0fSEd Maste sb_error.SetError(process_sp->SendEventData(event_data));
1270435933ddSDimitry Andric } else {
12710127ef0fSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
12720127ef0fSEd Maste if (log)
1273435933ddSDimitry Andric log->Printf(
1274435933ddSDimitry Andric "SBProcess(%p)::SendEventData() => error: process is running",
12750127ef0fSEd Maste static_cast<void *>(process_sp.get()));
1276ac7ddfbfSEd Maste sb_error.SetErrorString("process is running");
1277ac7ddfbfSEd Maste }
1278435933ddSDimitry Andric } else
1279ac7ddfbfSEd Maste sb_error.SetErrorString("invalid process");
1280ac7ddfbfSEd Maste return sb_error;
1281ac7ddfbfSEd Maste }
128235617911SEd Maste
GetNumExtendedBacktraceTypes()1283435933ddSDimitry Andric uint32_t SBProcess::GetNumExtendedBacktraceTypes() {
128435617911SEd Maste ProcessSP process_sp(GetSP());
1285435933ddSDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
128635617911SEd Maste SystemRuntime *runtime = process_sp->GetSystemRuntime();
128735617911SEd Maste return runtime->GetExtendedBacktraceTypes().size();
128835617911SEd Maste }
128935617911SEd Maste return 0;
129035617911SEd Maste }
129135617911SEd Maste
GetExtendedBacktraceTypeAtIndex(uint32_t idx)1292435933ddSDimitry Andric const char *SBProcess::GetExtendedBacktraceTypeAtIndex(uint32_t idx) {
129335617911SEd Maste ProcessSP process_sp(GetSP());
1294435933ddSDimitry Andric if (process_sp && process_sp->GetSystemRuntime()) {
129535617911SEd Maste SystemRuntime *runtime = process_sp->GetSystemRuntime();
1296435933ddSDimitry Andric const std::vector<ConstString> &names =
1297435933ddSDimitry Andric runtime->GetExtendedBacktraceTypes();
1298435933ddSDimitry Andric if (idx < names.size()) {
129935617911SEd Maste return names[idx].AsCString();
1300435933ddSDimitry Andric } else {
130135617911SEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
130235617911SEd Maste if (log)
1303435933ddSDimitry Andric log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => "
1304435933ddSDimitry Andric "error: requested extended backtrace name out of bounds",
13050127ef0fSEd Maste static_cast<void *>(process_sp.get()));
130635617911SEd Maste }
130735617911SEd Maste }
130835617911SEd Maste return NULL;
130935617911SEd Maste }
13107aa51b79SEd Maste
GetHistoryThreads(addr_t addr)1311435933ddSDimitry Andric SBThreadCollection SBProcess::GetHistoryThreads(addr_t addr) {
13127aa51b79SEd Maste ProcessSP process_sp(GetSP());
13137aa51b79SEd Maste SBThreadCollection threads;
1314435933ddSDimitry Andric if (process_sp) {
13157aa51b79SEd Maste threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
13167aa51b79SEd Maste }
13177aa51b79SEd Maste return threads;
13187aa51b79SEd Maste }
13197aa51b79SEd Maste
IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)1320435933ddSDimitry Andric bool SBProcess::IsInstrumentationRuntimePresent(
1321435933ddSDimitry Andric InstrumentationRuntimeType type) {
13227aa51b79SEd Maste ProcessSP process_sp(GetSP());
13237aa51b79SEd Maste if (!process_sp)
13247aa51b79SEd Maste return false;
13257aa51b79SEd Maste
1326435933ddSDimitry Andric InstrumentationRuntimeSP runtime_sp =
1327435933ddSDimitry Andric process_sp->GetInstrumentationRuntime(type);
13287aa51b79SEd Maste
13297aa51b79SEd Maste if (!runtime_sp.get())
13307aa51b79SEd Maste return false;
13317aa51b79SEd Maste
13327aa51b79SEd Maste return runtime_sp->IsActive();
13337aa51b79SEd Maste }
13349f2f44ceSEd Maste
SaveCore(const char * file_name)1335435933ddSDimitry Andric lldb::SBError SBProcess::SaveCore(const char *file_name) {
13369f2f44ceSEd Maste lldb::SBError error;
13379f2f44ceSEd Maste ProcessSP process_sp(GetSP());
1338435933ddSDimitry Andric if (!process_sp) {
13399f2f44ceSEd Maste error.SetErrorString("SBProcess is invalid");
13409f2f44ceSEd Maste return error;
13419f2f44ceSEd Maste }
13429f2f44ceSEd Maste
1343435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1344435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
13459f2f44ceSEd Maste
1346435933ddSDimitry Andric if (process_sp->GetState() != eStateStopped) {
13479f2f44ceSEd Maste error.SetErrorString("the process is not stopped");
13489f2f44ceSEd Maste return error;
13499f2f44ceSEd Maste }
13509f2f44ceSEd Maste
1351*b5893f02SDimitry Andric FileSpec core_file(file_name);
13529f2f44ceSEd Maste error.ref() = PluginManager::SaveCore(process_sp, core_file);
13539f2f44ceSEd Maste return error;
13549f2f44ceSEd Maste }
13554bb0738eSEd Maste
13564bb0738eSEd Maste lldb::SBError
GetMemoryRegionInfo(lldb::addr_t load_addr,SBMemoryRegionInfo & sb_region_info)1357435933ddSDimitry Andric SBProcess::GetMemoryRegionInfo(lldb::addr_t load_addr,
1358435933ddSDimitry Andric SBMemoryRegionInfo &sb_region_info) {
13594bb0738eSEd Maste lldb::SBError sb_error;
13604bb0738eSEd Maste ProcessSP process_sp(GetSP());
1361435933ddSDimitry Andric if (process_sp) {
13624bb0738eSEd Maste Process::StopLocker stop_locker;
1363435933ddSDimitry Andric if (stop_locker.TryLock(&process_sp->GetRunLock())) {
1364435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1365435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
1366*b5893f02SDimitry Andric
1367435933ddSDimitry Andric sb_error.ref() =
1368*b5893f02SDimitry Andric process_sp->GetMemoryRegionInfo(load_addr, sb_region_info.ref());
1369435933ddSDimitry Andric } else {
13704bb0738eSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
13714bb0738eSEd Maste if (log)
1372435933ddSDimitry Andric log->Printf(
1373435933ddSDimitry Andric "SBProcess(%p)::GetMemoryRegionInfo() => error: process is running",
13744bb0738eSEd Maste static_cast<void *>(process_sp.get()));
13754bb0738eSEd Maste sb_error.SetErrorString("process is running");
13764bb0738eSEd Maste }
1377435933ddSDimitry Andric } else {
13784bb0738eSEd Maste sb_error.SetErrorString("SBProcess is invalid");
13794bb0738eSEd Maste }
13804bb0738eSEd Maste return sb_error;
13814bb0738eSEd Maste }
13824bb0738eSEd Maste
GetMemoryRegions()1383435933ddSDimitry Andric lldb::SBMemoryRegionInfoList SBProcess::GetMemoryRegions() {
13844bb0738eSEd Maste lldb::SBMemoryRegionInfoList sb_region_list;
1385*b5893f02SDimitry Andric
13864bb0738eSEd Maste ProcessSP process_sp(GetSP());
13874bb0738eSEd Maste Process::StopLocker stop_locker;
1388*b5893f02SDimitry Andric if (process_sp && stop_locker.TryLock(&process_sp->GetRunLock())) {
1389435933ddSDimitry Andric std::lock_guard<std::recursive_mutex> guard(
1390435933ddSDimitry Andric process_sp->GetTarget().GetAPIMutex());
1391*b5893f02SDimitry Andric
1392*b5893f02SDimitry Andric process_sp->GetMemoryRegions(sb_region_list.ref());
1393435933ddSDimitry Andric } else {
13944bb0738eSEd Maste Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API));
13954bb0738eSEd Maste if (log)
1396435933ddSDimitry Andric log->Printf(
1397435933ddSDimitry Andric "SBProcess(%p)::GetMemoryRegionInfo() => error: process is running",
13984bb0738eSEd Maste static_cast<void *>(process_sp.get()));
13994bb0738eSEd Maste }
1400*b5893f02SDimitry Andric
14014bb0738eSEd Maste return sb_region_list;
14024bb0738eSEd Maste }
1403acac075bSDimitry Andric
GetProcessInfo()1404acac075bSDimitry Andric lldb::SBProcessInfo SBProcess::GetProcessInfo() {
1405acac075bSDimitry Andric lldb::SBProcessInfo sb_proc_info;
1406acac075bSDimitry Andric ProcessSP process_sp(GetSP());
1407acac075bSDimitry Andric ProcessInstanceInfo proc_info;
1408acac075bSDimitry Andric if (process_sp && process_sp->GetProcessInfo(proc_info)) {
1409acac075bSDimitry Andric sb_proc_info.SetProcessInfo(proc_info);
1410acac075bSDimitry Andric }
1411acac075bSDimitry Andric return sb_proc_info;
1412acac075bSDimitry Andric }
1413