1 //===-- SBProcess.cpp -------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/API/SBProcess.h"
17 #include "lldb/lldb-defines.h"
18 #include "lldb/lldb-types.h"
20 #include "lldb/Interpreter/Args.h"
21 #include "lldb/Core/Debugger.h"
22 #include "lldb/Core/Log.h"
23 #include "lldb/Core/Module.h"
24 #include "lldb/Core/State.h"
25 #include "lldb/Core/Stream.h"
26 #include "lldb/Core/StreamFile.h"
27 #include "lldb/Target/Process.h"
28 #include "lldb/Target/RegisterContext.h"
29 #include "lldb/Target/SystemRuntime.h"
30 #include "lldb/Target/Target.h"
31 #include "lldb/Target/Thread.h"
35 #include "lldb/API/SBBroadcaster.h"
36 #include "lldb/API/SBCommandReturnObject.h"
37 #include "lldb/API/SBDebugger.h"
38 #include "lldb/API/SBEvent.h"
39 #include "lldb/API/SBFileSpec.h"
40 #include "lldb/API/SBThread.h"
41 #include "lldb/API/SBStream.h"
42 #include "lldb/API/SBStringList.h"
45 using namespace lldb_private;
48 SBProcess::SBProcess () :
54 //----------------------------------------------------------------------
55 // SBProcess constructor
56 //----------------------------------------------------------------------
58 SBProcess::SBProcess (const SBProcess& rhs) :
59 m_opaque_wp (rhs.m_opaque_wp)
64 SBProcess::SBProcess (const lldb::ProcessSP &process_sp) :
65 m_opaque_wp (process_sp)
70 SBProcess::operator = (const SBProcess& rhs)
73 m_opaque_wp = rhs.m_opaque_wp;
77 //----------------------------------------------------------------------
79 //----------------------------------------------------------------------
80 SBProcess::~SBProcess()
85 SBProcess::GetBroadcasterClassName ()
87 return Process::GetStaticBroadcasterClass().AsCString();
91 SBProcess::GetPluginName ()
93 ProcessSP process_sp(GetSP());
96 return process_sp->GetPluginName().GetCString();
102 SBProcess::GetShortPluginName ()
104 ProcessSP process_sp(GetSP());
107 return process_sp->GetPluginName().GetCString();
114 SBProcess::GetSP() const
116 return m_opaque_wp.lock();
120 SBProcess::SetSP (const ProcessSP &process_sp)
122 m_opaque_wp = process_sp;
133 SBProcess::IsValid() const
135 ProcessSP process_sp(m_opaque_wp.lock());
136 return ((bool) process_sp && process_sp->IsValid());
140 SBProcess::RemoteLaunch (char const **argv,
142 const char *stdin_path,
143 const char *stdout_path,
144 const char *stderr_path,
145 const char *working_directory,
146 uint32_t launch_flags,
148 lldb::SBError& error)
150 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
152 log->Printf ("SBProcess(%p)::RemoteLaunch (argv=%p, envp=%p, stdin=%s, stdout=%s, stderr=%s, working-dir=%s, launch_flags=0x%x, stop_at_entry=%i, &error (%p))...",
153 m_opaque_wp.lock().get(),
156 stdin_path ? stdin_path : "NULL",
157 stdout_path ? stdout_path : "NULL",
158 stderr_path ? stderr_path : "NULL",
159 working_directory ? working_directory : "NULL",
165 ProcessSP process_sp(GetSP());
168 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
169 if (process_sp->GetState() == eStateConnected)
172 launch_flags |= eLaunchFlagStopAtEntry;
173 ProcessLaunchInfo launch_info (stdin_path,
178 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
180 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
182 launch_info.GetArguments().AppendArguments (argv);
184 launch_info.GetEnvironmentEntries ().SetArguments (envp);
185 error.SetError (process_sp->Launch (launch_info));
189 error.SetErrorString ("must be in eStateConnected to call RemoteLaunch");
194 error.SetErrorString ("unable to attach pid");
199 error.GetDescription (sstr);
200 log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", process_sp.get(), error.get(), sstr.GetData());
203 return error.Success();
207 SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error)
209 ProcessSP process_sp(GetSP());
212 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
213 if (process_sp->GetState() == eStateConnected)
215 ProcessAttachInfo attach_info;
216 attach_info.SetProcessID (pid);
217 error.SetError (process_sp->Attach (attach_info));
221 error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID");
226 error.SetErrorString ("unable to attach pid");
229 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
232 error.GetDescription (sstr);
233 log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64 ") => SBError (%p): %s", process_sp.get(), pid, error.get(), sstr.GetData());
236 return error.Success();
241 SBProcess::GetNumThreads ()
243 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
245 uint32_t num_threads = 0;
246 ProcessSP process_sp(GetSP());
249 Process::StopLocker stop_locker;
251 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
252 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
253 num_threads = process_sp->GetThreadList().GetSize(can_update);
257 log->Printf ("SBProcess(%p)::GetNumThreads () => %d", process_sp.get(), num_threads);
263 SBProcess::GetSelectedThread () const
265 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
269 ProcessSP process_sp(GetSP());
272 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
273 thread_sp = process_sp->GetThreadList().GetSelectedThread();
274 sb_thread.SetThread (thread_sp);
279 log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", process_sp.get(), thread_sp.get());
286 SBProcess::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context)
288 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
292 ProcessSP process_sp(GetSP());
295 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
296 thread_sp = process_sp->CreateOSPluginThread(tid, context);
297 sb_thread.SetThread (thread_sp);
301 log->Printf ("SBProcess(%p)::CreateOSPluginThread (tid=0x%" PRIx64 ", context=0x%" PRIx64 ") => SBThread(%p)", process_sp.get(), tid, context, thread_sp.get());
307 SBProcess::GetTarget() const
309 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
313 ProcessSP process_sp(GetSP());
316 target_sp = process_sp->GetTarget().shared_from_this();
317 sb_target.SetSP (target_sp);
321 log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", process_sp.get(), target_sp.get());
328 SBProcess::PutSTDIN (const char *src, size_t src_len)
330 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
333 ProcessSP process_sp(GetSP());
337 ret_val = process_sp->PutSTDIN (src, src_len, error);
341 log->Printf ("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%d) => %zu",
351 SBProcess::GetSTDOUT (char *dst, size_t dst_len) const
353 size_t bytes_read = 0;
354 ProcessSP process_sp(GetSP());
358 bytes_read = process_sp->GetSTDOUT (dst, dst_len, error);
361 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
363 log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
368 (uint64_t)bytes_read);
374 SBProcess::GetSTDERR (char *dst, size_t dst_len) const
376 size_t bytes_read = 0;
377 ProcessSP process_sp(GetSP());
381 bytes_read = process_sp->GetSTDERR (dst, dst_len, error);
384 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
386 log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
391 (uint64_t)bytes_read);
397 SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const
399 size_t bytes_read = 0;
400 ProcessSP process_sp(GetSP());
404 bytes_read = process_sp->GetAsyncProfileData (dst, dst_len, error);
407 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
409 log->Printf ("SBProcess(%p)::GetProfileData (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
414 (uint64_t)bytes_read);
420 SBProcess::ReportEventState (const SBEvent &event, FILE *out) const
425 ProcessSP process_sp(GetSP());
428 const StateType event_state = SBProcess::GetStateFromEvent (event);
430 int message_len = ::snprintf (message,
432 "Process %" PRIu64 " %s\n",
434 SBDebugger::StateAsCString (event_state));
437 ::fwrite (message, 1, message_len, out);
442 SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result)
444 ProcessSP process_sp(GetSP());
447 const StateType event_state = SBProcess::GetStateFromEvent (event);
451 "Process %" PRIu64 " %s\n",
453 SBDebugger::StateAsCString (event_state));
455 result.AppendMessage (message);
460 SBProcess::SetSelectedThread (const SBThread &thread)
462 ProcessSP process_sp(GetSP());
465 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
466 return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID());
472 SBProcess::SetSelectedThreadByID (lldb::tid_t tid)
474 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
476 bool ret_val = false;
477 ProcessSP process_sp(GetSP());
480 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
481 ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid);
485 log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64 ") => %s",
486 process_sp.get(), tid, (ret_val ? "true" : "false"));
492 SBProcess::SetSelectedThreadByIndexID (uint32_t index_id)
494 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
496 bool ret_val = false;
497 ProcessSP process_sp(GetSP());
500 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
501 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id);
505 log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s",
506 process_sp.get(), index_id, (ret_val ? "true" : "false"));
512 SBProcess::GetThreadAtIndex (size_t index)
514 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
518 ProcessSP process_sp(GetSP());
521 Process::StopLocker stop_locker;
522 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
523 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
524 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
525 sb_thread.SetThread (thread_sp);
530 log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)",
531 process_sp.get(), (uint32_t) index, thread_sp.get());
538 SBProcess::GetStopID(bool include_expression_stops)
540 ProcessSP process_sp(GetSP());
543 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
544 if (include_expression_stops)
545 return process_sp->GetStopID();
547 return process_sp->GetLastNaturalStopID();
553 SBProcess::GetState ()
556 StateType ret_val = eStateInvalid;
557 ProcessSP process_sp(GetSP());
560 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
561 ret_val = process_sp->GetState();
564 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
566 log->Printf ("SBProcess(%p)::GetState () => %s",
568 lldb_private::StateAsCString (ret_val));
575 SBProcess::GetExitStatus ()
578 ProcessSP process_sp(GetSP());
581 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
582 exit_status = process_sp->GetExitStatus ();
584 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
586 log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)",
587 process_sp.get(), exit_status, exit_status);
593 SBProcess::GetExitDescription ()
595 const char *exit_desc = NULL;
596 ProcessSP process_sp(GetSP());
599 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
600 exit_desc = process_sp->GetExitDescription ();
602 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
604 log->Printf ("SBProcess(%p)::GetExitDescription () => %s",
605 process_sp.get(), exit_desc);
610 SBProcess::GetProcessID ()
612 lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
613 ProcessSP process_sp(GetSP());
615 ret_val = process_sp->GetID();
617 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
619 log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, process_sp.get(), ret_val);
625 SBProcess::GetUniqueID()
627 uint32_t ret_val = 0;
628 ProcessSP process_sp(GetSP());
630 ret_val = process_sp->GetUniqueID();
631 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
633 log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, process_sp.get(), ret_val);
638 SBProcess::GetByteOrder () const
640 ByteOrder byteOrder = eByteOrderInvalid;
641 ProcessSP process_sp(GetSP());
643 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
645 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
647 log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder);
653 SBProcess::GetAddressByteSize () const
656 ProcessSP process_sp(GetSP());
658 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
660 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
662 log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size);
668 SBProcess::Continue ()
670 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
673 ProcessSP process_sp(GetSP());
676 log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get());
680 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
682 Error error (process_sp->Resume());
685 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false)
688 log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get());
689 process_sp->WaitForProcessToStop (NULL);
692 sb_error.SetError(error);
695 sb_error.SetErrorString ("SBProcess is invalid");
700 sb_error.GetDescription (sstr);
701 log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", process_sp.get(), sb_error.get(), sstr.GetData());
709 SBProcess::Destroy ()
712 ProcessSP process_sp(GetSP());
715 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
716 sb_error.SetError(process_sp->Destroy());
719 sb_error.SetErrorString ("SBProcess is invalid");
721 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
725 sb_error.GetDescription (sstr);
726 log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s",
740 ProcessSP process_sp(GetSP());
743 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
744 sb_error.SetError (process_sp->Halt());
747 sb_error.SetErrorString ("SBProcess is invalid");
749 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
753 sb_error.GetDescription (sstr);
754 log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s",
767 ProcessSP process_sp(GetSP());
770 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
771 sb_error.SetError (process_sp->Destroy());
774 sb_error.SetErrorString ("SBProcess is invalid");
776 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
780 sb_error.GetDescription (sstr);
781 log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s",
793 // FIXME: This should come from a process default.
794 bool keep_stopped = false;
795 return Detach (keep_stopped);
799 SBProcess::Detach (bool keep_stopped)
802 ProcessSP process_sp(GetSP());
805 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
806 sb_error.SetError (process_sp->Detach(keep_stopped));
809 sb_error.SetErrorString ("SBProcess is invalid");
815 SBProcess::Signal (int signo)
818 ProcessSP process_sp(GetSP());
821 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
822 sb_error.SetError (process_sp->Signal (signo));
825 sb_error.SetErrorString ("SBProcess is invalid");
826 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
830 sb_error.GetDescription (sstr);
831 log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s",
841 SBProcess::SendAsyncInterrupt ()
843 ProcessSP process_sp(GetSP());
846 process_sp->SendAsyncInterrupt ();
851 SBProcess::GetThreadByID (tid_t tid)
855 ProcessSP process_sp(GetSP());
858 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
859 Process::StopLocker stop_locker;
860 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
861 thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update);
862 sb_thread.SetThread (thread_sp);
865 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
868 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)",
878 SBProcess::GetThreadByIndexID (uint32_t index_id)
882 ProcessSP process_sp(GetSP());
885 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
886 Process::StopLocker stop_locker;
887 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
888 thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update);
889 sb_thread.SetThread (thread_sp);
892 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
895 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)",
905 SBProcess::GetStateFromEvent (const SBEvent &event)
907 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
909 StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get());
912 log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(),
913 lldb_private::StateAsCString (ret_val));
919 SBProcess::GetRestartedFromEvent (const SBEvent &event)
921 return Process::ProcessEventData::GetRestartedFromEvent (event.get());
925 SBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event)
927 return Process::ProcessEventData::GetNumRestartedReasons(event.get());
931 SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx)
933 return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
937 SBProcess::GetProcessFromEvent (const SBEvent &event)
939 SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get()));
944 SBProcess::EventIsProcessEvent (const SBEvent &event)
946 return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0;
950 SBProcess::GetBroadcaster () const
952 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
954 ProcessSP process_sp(GetSP());
956 SBBroadcaster broadcaster(process_sp.get(), false);
959 log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(),
966 SBProcess::GetBroadcasterClass ()
968 return Process::GetStaticBroadcasterClass().AsCString();
972 SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error)
974 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
976 size_t bytes_read = 0;
978 ProcessSP process_sp(GetSP());
982 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...",
992 Process::StopLocker stop_locker;
993 if (stop_locker.TryLock(&process_sp->GetRunLock()))
995 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
996 bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref());
1001 log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get());
1002 sb_error.SetErrorString("process is running");
1007 sb_error.SetErrorString ("SBProcess is invalid");
1013 sb_error.GetDescription (sstr);
1014 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1021 (uint64_t)bytes_read);
1028 SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error)
1030 size_t bytes_read = 0;
1031 ProcessSP process_sp(GetSP());
1034 Process::StopLocker stop_locker;
1035 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1037 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1038 bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref());
1042 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1044 log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", process_sp.get());
1045 sb_error.SetErrorString("process is running");
1050 sb_error.SetErrorString ("SBProcess is invalid");
1056 SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error)
1059 ProcessSP process_sp(GetSP());
1062 Process::StopLocker stop_locker;
1063 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1065 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1066 value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref());
1070 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1072 log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", process_sp.get());
1073 sb_error.SetErrorString("process is running");
1078 sb_error.SetErrorString ("SBProcess is invalid");
1084 SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error)
1086 lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
1087 ProcessSP process_sp(GetSP());
1090 Process::StopLocker stop_locker;
1091 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1093 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1094 ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref());
1098 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1100 log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", process_sp.get());
1101 sb_error.SetErrorString("process is running");
1106 sb_error.SetErrorString ("SBProcess is invalid");
1112 SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error)
1114 size_t bytes_written = 0;
1116 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1118 ProcessSP process_sp(GetSP());
1122 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...",
1132 Process::StopLocker stop_locker;
1133 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1135 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1136 bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref());
1141 log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get());
1142 sb_error.SetErrorString("process is running");
1149 sb_error.GetDescription (sstr);
1150 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1157 (uint64_t)bytes_written);
1160 return bytes_written;
1164 SBProcess::GetDescription (SBStream &description)
1166 Stream &strm = description.ref();
1168 ProcessSP process_sp(GetSP());
1171 char path[PATH_MAX];
1172 GetTarget().GetExecutable().GetPath (path, sizeof(path));
1173 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1174 const char *exe_name = NULL;
1176 exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1178 strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1179 process_sp->GetID(),
1180 lldb_private::StateAsCString (GetState()),
1182 exe_name ? ", executable = " : "",
1183 exe_name ? exe_name : "");
1186 strm.PutCString ("No value");
1192 SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const
1194 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1197 ProcessSP process_sp(GetSP());
1200 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1201 sb_error.SetError(process_sp->GetWatchpointSupportInfo (num));
1203 log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u",
1204 process_sp.get(), num);
1208 sb_error.SetErrorString ("SBProcess is invalid");
1214 SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error)
1216 ProcessSP process_sp(GetSP());
1219 Process::StopLocker stop_locker;
1220 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1222 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1223 return process_sp->LoadImage (*sb_image_spec, sb_error.ref());
1227 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1229 log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get());
1230 sb_error.SetErrorString("process is running");
1233 return LLDB_INVALID_IMAGE_TOKEN;
1237 SBProcess::UnloadImage (uint32_t image_token)
1239 lldb::SBError sb_error;
1240 ProcessSP process_sp(GetSP());
1243 Process::StopLocker stop_locker;
1244 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1246 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1247 sb_error.SetError (process_sp->UnloadImage (image_token));
1251 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1253 log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", process_sp.get());
1254 sb_error.SetErrorString("process is running");
1258 sb_error.SetErrorString("invalid process");
1263 SBProcess::GetNumExtendedBacktraceTypes ()
1265 ProcessSP process_sp(GetSP());
1266 if (process_sp && process_sp->GetSystemRuntime())
1268 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1269 return runtime->GetExtendedBacktraceTypes().size();
1275 SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx)
1277 ProcessSP process_sp(GetSP());
1278 if (process_sp && process_sp->GetSystemRuntime())
1280 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1281 const std::vector<ConstString> &names = runtime->GetExtendedBacktraceTypes();
1282 if (idx < names.size())
1284 return names[idx].AsCString();
1288 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1290 log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => error: requested extended backtrace name out of bounds", process_sp.get());