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::GetNumQueues ()
540 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
542 uint32_t num_queues = 0;
543 ProcessSP process_sp(GetSP());
546 Process::StopLocker stop_locker;
548 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
549 num_queues = process_sp->GetQueueList().GetSize();
553 log->Printf ("SBProcess(%p)::GetNumQueues () => %d", process_sp.get(), num_queues);
559 SBProcess::GetQueueAtIndex (size_t index)
561 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
565 ProcessSP process_sp(GetSP());
568 Process::StopLocker stop_locker;
569 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
570 queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
571 sb_queue.SetQueue (queue_sp);
576 log->Printf ("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)",
577 process_sp.get(), (uint32_t) index, queue_sp.get());
585 SBProcess::GetStopID(bool include_expression_stops)
587 ProcessSP process_sp(GetSP());
590 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
591 if (include_expression_stops)
592 return process_sp->GetStopID();
594 return process_sp->GetLastNaturalStopID();
600 SBProcess::GetState ()
603 StateType ret_val = eStateInvalid;
604 ProcessSP process_sp(GetSP());
607 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
608 ret_val = process_sp->GetState();
611 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
613 log->Printf ("SBProcess(%p)::GetState () => %s",
615 lldb_private::StateAsCString (ret_val));
622 SBProcess::GetExitStatus ()
625 ProcessSP process_sp(GetSP());
628 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
629 exit_status = process_sp->GetExitStatus ();
631 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
633 log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)",
634 process_sp.get(), exit_status, exit_status);
640 SBProcess::GetExitDescription ()
642 const char *exit_desc = NULL;
643 ProcessSP process_sp(GetSP());
646 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
647 exit_desc = process_sp->GetExitDescription ();
649 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
651 log->Printf ("SBProcess(%p)::GetExitDescription () => %s",
652 process_sp.get(), exit_desc);
657 SBProcess::GetProcessID ()
659 lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
660 ProcessSP process_sp(GetSP());
662 ret_val = process_sp->GetID();
664 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
666 log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, process_sp.get(), ret_val);
672 SBProcess::GetUniqueID()
674 uint32_t ret_val = 0;
675 ProcessSP process_sp(GetSP());
677 ret_val = process_sp->GetUniqueID();
678 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
680 log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, process_sp.get(), ret_val);
685 SBProcess::GetByteOrder () const
687 ByteOrder byteOrder = eByteOrderInvalid;
688 ProcessSP process_sp(GetSP());
690 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
692 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
694 log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder);
700 SBProcess::GetAddressByteSize () const
703 ProcessSP process_sp(GetSP());
705 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
707 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
709 log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size);
715 SBProcess::Continue ()
717 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
720 ProcessSP process_sp(GetSP());
723 log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get());
727 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
729 Error error (process_sp->Resume());
732 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false)
735 log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get());
736 process_sp->WaitForProcessToStop (NULL);
739 sb_error.SetError(error);
742 sb_error.SetErrorString ("SBProcess is invalid");
747 sb_error.GetDescription (sstr);
748 log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", process_sp.get(), sb_error.get(), sstr.GetData());
756 SBProcess::Destroy ()
759 ProcessSP process_sp(GetSP());
762 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
763 sb_error.SetError(process_sp->Destroy());
766 sb_error.SetErrorString ("SBProcess is invalid");
768 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
772 sb_error.GetDescription (sstr);
773 log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s",
787 ProcessSP process_sp(GetSP());
790 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
791 sb_error.SetError (process_sp->Halt());
794 sb_error.SetErrorString ("SBProcess is invalid");
796 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
800 sb_error.GetDescription (sstr);
801 log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s",
814 ProcessSP process_sp(GetSP());
817 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
818 sb_error.SetError (process_sp->Destroy());
821 sb_error.SetErrorString ("SBProcess is invalid");
823 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
827 sb_error.GetDescription (sstr);
828 log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s",
840 // FIXME: This should come from a process default.
841 bool keep_stopped = false;
842 return Detach (keep_stopped);
846 SBProcess::Detach (bool keep_stopped)
849 ProcessSP process_sp(GetSP());
852 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
853 sb_error.SetError (process_sp->Detach(keep_stopped));
856 sb_error.SetErrorString ("SBProcess is invalid");
862 SBProcess::Signal (int signo)
865 ProcessSP process_sp(GetSP());
868 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
869 sb_error.SetError (process_sp->Signal (signo));
872 sb_error.SetErrorString ("SBProcess is invalid");
873 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
877 sb_error.GetDescription (sstr);
878 log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s",
888 SBProcess::SendAsyncInterrupt ()
890 ProcessSP process_sp(GetSP());
893 process_sp->SendAsyncInterrupt ();
898 SBProcess::GetThreadByID (tid_t tid)
902 ProcessSP process_sp(GetSP());
905 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
906 Process::StopLocker stop_locker;
907 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
908 thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update);
909 sb_thread.SetThread (thread_sp);
912 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
915 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)",
925 SBProcess::GetThreadByIndexID (uint32_t index_id)
929 ProcessSP process_sp(GetSP());
932 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
933 Process::StopLocker stop_locker;
934 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
935 thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update);
936 sb_thread.SetThread (thread_sp);
939 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
942 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)",
952 SBProcess::GetStateFromEvent (const SBEvent &event)
954 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
956 StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get());
959 log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(),
960 lldb_private::StateAsCString (ret_val));
966 SBProcess::GetRestartedFromEvent (const SBEvent &event)
968 return Process::ProcessEventData::GetRestartedFromEvent (event.get());
972 SBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event)
974 return Process::ProcessEventData::GetNumRestartedReasons(event.get());
978 SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx)
980 return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
984 SBProcess::GetProcessFromEvent (const SBEvent &event)
986 SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get()));
991 SBProcess::EventIsProcessEvent (const SBEvent &event)
993 return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0;
997 SBProcess::GetBroadcaster () const
999 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1001 ProcessSP process_sp(GetSP());
1003 SBBroadcaster broadcaster(process_sp.get(), false);
1006 log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(),
1013 SBProcess::GetBroadcasterClass ()
1015 return Process::GetStaticBroadcasterClass().AsCString();
1019 SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error)
1021 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1023 size_t bytes_read = 0;
1025 ProcessSP process_sp(GetSP());
1029 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...",
1039 Process::StopLocker stop_locker;
1040 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1042 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1043 bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref());
1048 log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get());
1049 sb_error.SetErrorString("process is running");
1054 sb_error.SetErrorString ("SBProcess is invalid");
1060 sb_error.GetDescription (sstr);
1061 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1068 (uint64_t)bytes_read);
1075 SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error)
1077 size_t bytes_read = 0;
1078 ProcessSP process_sp(GetSP());
1081 Process::StopLocker stop_locker;
1082 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1084 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1085 bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref());
1089 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1091 log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", process_sp.get());
1092 sb_error.SetErrorString("process is running");
1097 sb_error.SetErrorString ("SBProcess is invalid");
1103 SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error)
1106 ProcessSP process_sp(GetSP());
1109 Process::StopLocker stop_locker;
1110 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1112 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1113 value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref());
1117 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1119 log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", process_sp.get());
1120 sb_error.SetErrorString("process is running");
1125 sb_error.SetErrorString ("SBProcess is invalid");
1131 SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error)
1133 lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
1134 ProcessSP process_sp(GetSP());
1137 Process::StopLocker stop_locker;
1138 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1140 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1141 ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref());
1145 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1147 log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", process_sp.get());
1148 sb_error.SetErrorString("process is running");
1153 sb_error.SetErrorString ("SBProcess is invalid");
1159 SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error)
1161 size_t bytes_written = 0;
1163 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1165 ProcessSP process_sp(GetSP());
1169 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...",
1179 Process::StopLocker stop_locker;
1180 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1182 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1183 bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref());
1188 log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get());
1189 sb_error.SetErrorString("process is running");
1196 sb_error.GetDescription (sstr);
1197 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1204 (uint64_t)bytes_written);
1207 return bytes_written;
1211 SBProcess::GetDescription (SBStream &description)
1213 Stream &strm = description.ref();
1215 ProcessSP process_sp(GetSP());
1218 char path[PATH_MAX];
1219 GetTarget().GetExecutable().GetPath (path, sizeof(path));
1220 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1221 const char *exe_name = NULL;
1223 exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1225 strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1226 process_sp->GetID(),
1227 lldb_private::StateAsCString (GetState()),
1229 exe_name ? ", executable = " : "",
1230 exe_name ? exe_name : "");
1233 strm.PutCString ("No value");
1239 SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const
1241 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1244 ProcessSP process_sp(GetSP());
1247 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1248 sb_error.SetError(process_sp->GetWatchpointSupportInfo (num));
1250 log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u",
1251 process_sp.get(), num);
1255 sb_error.SetErrorString ("SBProcess is invalid");
1261 SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error)
1263 ProcessSP process_sp(GetSP());
1266 Process::StopLocker stop_locker;
1267 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1269 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1270 return process_sp->LoadImage (*sb_image_spec, sb_error.ref());
1274 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1276 log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get());
1277 sb_error.SetErrorString("process is running");
1280 return LLDB_INVALID_IMAGE_TOKEN;
1284 SBProcess::UnloadImage (uint32_t image_token)
1286 lldb::SBError sb_error;
1287 ProcessSP process_sp(GetSP());
1290 Process::StopLocker stop_locker;
1291 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1293 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1294 sb_error.SetError (process_sp->UnloadImage (image_token));
1298 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1300 log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", process_sp.get());
1301 sb_error.SetErrorString("process is running");
1305 sb_error.SetErrorString("invalid process");
1310 SBProcess::GetNumExtendedBacktraceTypes ()
1312 ProcessSP process_sp(GetSP());
1313 if (process_sp && process_sp->GetSystemRuntime())
1315 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1316 return runtime->GetExtendedBacktraceTypes().size();
1322 SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx)
1324 ProcessSP process_sp(GetSP());
1325 if (process_sp && process_sp->GetSystemRuntime())
1327 SystemRuntime *runtime = process_sp->GetSystemRuntime();
1328 const std::vector<ConstString> &names = runtime->GetExtendedBacktraceTypes();
1329 if (idx < names.size())
1331 return names[idx].AsCString();
1335 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1337 log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => error: requested extended backtrace name out of bounds", process_sp.get());