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"
14 #include "lldb/lldb-defines.h"
15 #include "lldb/lldb-types.h"
17 #include "lldb/Interpreter/Args.h"
18 #include "lldb/Core/Debugger.h"
19 #include "lldb/Core/Log.h"
20 #include "lldb/Core/Module.h"
21 #include "lldb/Core/State.h"
22 #include "lldb/Core/Stream.h"
23 #include "lldb/Core/StreamFile.h"
24 #include "lldb/Target/Process.h"
25 #include "lldb/Target/RegisterContext.h"
26 #include "lldb/Target/Target.h"
27 #include "lldb/Target/Thread.h"
31 #include "lldb/API/SBBroadcaster.h"
32 #include "lldb/API/SBCommandReturnObject.h"
33 #include "lldb/API/SBDebugger.h"
34 #include "lldb/API/SBEvent.h"
35 #include "lldb/API/SBFileSpec.h"
36 #include "lldb/API/SBThread.h"
37 #include "lldb/API/SBStream.h"
38 #include "lldb/API/SBStringList.h"
41 using namespace lldb_private;
44 SBProcess::SBProcess () :
50 //----------------------------------------------------------------------
51 // SBProcess constructor
52 //----------------------------------------------------------------------
54 SBProcess::SBProcess (const SBProcess& rhs) :
55 m_opaque_wp (rhs.m_opaque_wp)
60 SBProcess::SBProcess (const lldb::ProcessSP &process_sp) :
61 m_opaque_wp (process_sp)
66 SBProcess::operator = (const SBProcess& rhs)
69 m_opaque_wp = rhs.m_opaque_wp;
73 //----------------------------------------------------------------------
75 //----------------------------------------------------------------------
76 SBProcess::~SBProcess()
81 SBProcess::GetBroadcasterClassName ()
83 return Process::GetStaticBroadcasterClass().AsCString();
87 SBProcess::GetPluginName ()
89 ProcessSP process_sp(GetSP());
92 return process_sp->GetPluginName().GetCString();
98 SBProcess::GetShortPluginName ()
100 ProcessSP process_sp(GetSP());
103 return process_sp->GetPluginName().GetCString();
110 SBProcess::GetSP() const
112 return m_opaque_wp.lock();
116 SBProcess::SetSP (const ProcessSP &process_sp)
118 m_opaque_wp = process_sp;
129 SBProcess::IsValid() const
131 ProcessSP process_sp(m_opaque_wp.lock());
132 return ((bool) process_sp && process_sp->IsValid());
136 SBProcess::RemoteLaunch (char const **argv,
138 const char *stdin_path,
139 const char *stdout_path,
140 const char *stderr_path,
141 const char *working_directory,
142 uint32_t launch_flags,
144 lldb::SBError& error)
146 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
148 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))...",
149 m_opaque_wp.lock().get(),
152 stdin_path ? stdin_path : "NULL",
153 stdout_path ? stdout_path : "NULL",
154 stderr_path ? stderr_path : "NULL",
155 working_directory ? working_directory : "NULL",
161 ProcessSP process_sp(GetSP());
164 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
165 if (process_sp->GetState() == eStateConnected)
168 launch_flags |= eLaunchFlagStopAtEntry;
169 ProcessLaunchInfo launch_info (stdin_path,
174 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
176 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
178 launch_info.GetArguments().AppendArguments (argv);
180 launch_info.GetEnvironmentEntries ().SetArguments (envp);
181 error.SetError (process_sp->Launch (launch_info));
185 error.SetErrorString ("must be in eStateConnected to call RemoteLaunch");
190 error.SetErrorString ("unable to attach pid");
195 error.GetDescription (sstr);
196 log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s", process_sp.get(), error.get(), sstr.GetData());
199 return error.Success();
203 SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error)
205 ProcessSP process_sp(GetSP());
208 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
209 if (process_sp->GetState() == eStateConnected)
211 ProcessAttachInfo attach_info;
212 attach_info.SetProcessID (pid);
213 error.SetError (process_sp->Attach (attach_info));
217 error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID");
222 error.SetErrorString ("unable to attach pid");
225 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
228 error.GetDescription (sstr);
229 log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64 ") => SBError (%p): %s", process_sp.get(), pid, error.get(), sstr.GetData());
232 return error.Success();
237 SBProcess::GetNumThreads ()
239 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
241 uint32_t num_threads = 0;
242 ProcessSP process_sp(GetSP());
245 Process::StopLocker stop_locker;
247 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
248 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
249 num_threads = process_sp->GetThreadList().GetSize(can_update);
253 log->Printf ("SBProcess(%p)::GetNumThreads () => %d", process_sp.get(), num_threads);
259 SBProcess::GetSelectedThread () const
261 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
265 ProcessSP process_sp(GetSP());
268 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
269 thread_sp = process_sp->GetThreadList().GetSelectedThread();
270 sb_thread.SetThread (thread_sp);
275 log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)", process_sp.get(), thread_sp.get());
282 SBProcess::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context)
284 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
288 ProcessSP process_sp(GetSP());
291 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
292 thread_sp = process_sp->CreateOSPluginThread(tid, context);
293 sb_thread.SetThread (thread_sp);
297 log->Printf ("SBProcess(%p)::CreateOSPluginThread (tid=0x%" PRIx64 ", context=0x%" PRIx64 ") => SBThread(%p)", process_sp.get(), tid, context, thread_sp.get());
303 SBProcess::GetTarget() const
305 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
309 ProcessSP process_sp(GetSP());
312 target_sp = process_sp->GetTarget().shared_from_this();
313 sb_target.SetSP (target_sp);
317 log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)", process_sp.get(), target_sp.get());
324 SBProcess::PutSTDIN (const char *src, size_t src_len)
326 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
329 ProcessSP process_sp(GetSP());
333 ret_val = process_sp->PutSTDIN (src, src_len, error);
337 log->Printf ("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%d) => %lu",
347 SBProcess::GetSTDOUT (char *dst, size_t dst_len) const
349 size_t bytes_read = 0;
350 ProcessSP process_sp(GetSP());
354 bytes_read = process_sp->GetSTDOUT (dst, dst_len, error);
357 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
359 log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
364 (uint64_t)bytes_read);
370 SBProcess::GetSTDERR (char *dst, size_t dst_len) const
372 size_t bytes_read = 0;
373 ProcessSP process_sp(GetSP());
377 bytes_read = process_sp->GetSTDERR (dst, dst_len, error);
380 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
382 log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
387 (uint64_t)bytes_read);
393 SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const
395 size_t bytes_read = 0;
396 ProcessSP process_sp(GetSP());
400 bytes_read = process_sp->GetAsyncProfileData (dst, dst_len, error);
403 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
405 log->Printf ("SBProcess(%p)::GetProfileData (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
410 (uint64_t)bytes_read);
416 SBProcess::ReportEventState (const SBEvent &event, FILE *out) const
421 ProcessSP process_sp(GetSP());
424 const StateType event_state = SBProcess::GetStateFromEvent (event);
426 int message_len = ::snprintf (message,
428 "Process %" PRIu64 " %s\n",
430 SBDebugger::StateAsCString (event_state));
433 ::fwrite (message, 1, message_len, out);
438 SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result)
440 ProcessSP process_sp(GetSP());
443 const StateType event_state = SBProcess::GetStateFromEvent (event);
447 "Process %" PRIu64 " %s\n",
449 SBDebugger::StateAsCString (event_state));
451 result.AppendMessage (message);
456 SBProcess::SetSelectedThread (const SBThread &thread)
458 ProcessSP process_sp(GetSP());
461 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
462 return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID());
468 SBProcess::SetSelectedThreadByID (lldb::tid_t tid)
470 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
472 bool ret_val = false;
473 ProcessSP process_sp(GetSP());
476 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
477 ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid);
481 log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64 ") => %s",
482 process_sp.get(), tid, (ret_val ? "true" : "false"));
488 SBProcess::SetSelectedThreadByIndexID (uint32_t index_id)
490 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
492 bool ret_val = false;
493 ProcessSP process_sp(GetSP());
496 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
497 ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id);
501 log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s",
502 process_sp.get(), index_id, (ret_val ? "true" : "false"));
508 SBProcess::GetThreadAtIndex (size_t index)
510 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
514 ProcessSP process_sp(GetSP());
517 Process::StopLocker stop_locker;
518 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
519 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
520 thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
521 sb_thread.SetThread (thread_sp);
526 log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)",
527 process_sp.get(), (uint32_t) index, thread_sp.get());
534 SBProcess::GetStopID(bool include_expression_stops)
536 ProcessSP process_sp(GetSP());
539 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
540 if (include_expression_stops)
541 return process_sp->GetStopID();
543 return process_sp->GetLastNaturalStopID();
549 SBProcess::GetState ()
552 StateType ret_val = eStateInvalid;
553 ProcessSP process_sp(GetSP());
556 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
557 ret_val = process_sp->GetState();
560 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
562 log->Printf ("SBProcess(%p)::GetState () => %s",
564 lldb_private::StateAsCString (ret_val));
571 SBProcess::GetExitStatus ()
574 ProcessSP process_sp(GetSP());
577 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
578 exit_status = process_sp->GetExitStatus ();
580 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
582 log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)",
583 process_sp.get(), exit_status, exit_status);
589 SBProcess::GetExitDescription ()
591 const char *exit_desc = NULL;
592 ProcessSP process_sp(GetSP());
595 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
596 exit_desc = process_sp->GetExitDescription ();
598 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
600 log->Printf ("SBProcess(%p)::GetExitDescription () => %s",
601 process_sp.get(), exit_desc);
606 SBProcess::GetProcessID ()
608 lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
609 ProcessSP process_sp(GetSP());
611 ret_val = process_sp->GetID();
613 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
615 log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64, process_sp.get(), ret_val);
621 SBProcess::GetUniqueID()
623 uint32_t ret_val = 0;
624 ProcessSP process_sp(GetSP());
626 ret_val = process_sp->GetUniqueID();
627 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
629 log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32, process_sp.get(), ret_val);
634 SBProcess::GetByteOrder () const
636 ByteOrder byteOrder = eByteOrderInvalid;
637 ProcessSP process_sp(GetSP());
639 byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
641 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
643 log->Printf ("SBProcess(%p)::GetByteOrder () => %d", process_sp.get(), byteOrder);
649 SBProcess::GetAddressByteSize () const
652 ProcessSP process_sp(GetSP());
654 size = process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
656 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
658 log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d", process_sp.get(), size);
664 SBProcess::Continue ()
666 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
669 ProcessSP process_sp(GetSP());
672 log->Printf ("SBProcess(%p)::Continue ()...", process_sp.get());
676 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
678 Error error (process_sp->Resume());
681 if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false)
684 log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", process_sp.get());
685 process_sp->WaitForProcessToStop (NULL);
688 sb_error.SetError(error);
691 sb_error.SetErrorString ("SBProcess is invalid");
696 sb_error.GetDescription (sstr);
697 log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s", process_sp.get(), sb_error.get(), sstr.GetData());
705 SBProcess::Destroy ()
708 ProcessSP process_sp(GetSP());
711 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
712 sb_error.SetError(process_sp->Destroy());
715 sb_error.SetErrorString ("SBProcess is invalid");
717 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
721 sb_error.GetDescription (sstr);
722 log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s",
736 ProcessSP process_sp(GetSP());
739 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
740 sb_error.SetError (process_sp->Halt());
743 sb_error.SetErrorString ("SBProcess is invalid");
745 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
749 sb_error.GetDescription (sstr);
750 log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s",
763 ProcessSP process_sp(GetSP());
766 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
767 sb_error.SetError (process_sp->Destroy());
770 sb_error.SetErrorString ("SBProcess is invalid");
772 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
776 sb_error.GetDescription (sstr);
777 log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s",
789 // FIXME: This should come from a process default.
790 bool keep_stopped = false;
791 return Detach (keep_stopped);
795 SBProcess::Detach (bool keep_stopped)
798 ProcessSP process_sp(GetSP());
801 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
802 sb_error.SetError (process_sp->Detach(keep_stopped));
805 sb_error.SetErrorString ("SBProcess is invalid");
811 SBProcess::Signal (int signo)
814 ProcessSP process_sp(GetSP());
817 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
818 sb_error.SetError (process_sp->Signal (signo));
821 sb_error.SetErrorString ("SBProcess is invalid");
822 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
826 sb_error.GetDescription (sstr);
827 log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s",
837 SBProcess::SendAsyncInterrupt ()
839 ProcessSP process_sp(GetSP());
842 process_sp->SendAsyncInterrupt ();
847 SBProcess::GetThreadByID (tid_t tid)
851 ProcessSP process_sp(GetSP());
854 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
855 Process::StopLocker stop_locker;
856 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
857 thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update);
858 sb_thread.SetThread (thread_sp);
861 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
864 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)",
874 SBProcess::GetThreadByIndexID (uint32_t index_id)
878 ProcessSP process_sp(GetSP());
881 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
882 Process::StopLocker stop_locker;
883 const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
884 thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update);
885 sb_thread.SetThread (thread_sp);
888 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
891 log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)",
901 SBProcess::GetStateFromEvent (const SBEvent &event)
903 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
905 StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get());
908 log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s", event.get(),
909 lldb_private::StateAsCString (ret_val));
915 SBProcess::GetRestartedFromEvent (const SBEvent &event)
917 return Process::ProcessEventData::GetRestartedFromEvent (event.get());
921 SBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event)
923 return Process::ProcessEventData::GetNumRestartedReasons(event.get());
927 SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx)
929 return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
933 SBProcess::GetProcessFromEvent (const SBEvent &event)
935 SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get()));
940 SBProcess::EventIsProcessEvent (const SBEvent &event)
942 return strcmp (event.GetBroadcasterClass(), SBProcess::GetBroadcasterClass()) == 0;
946 SBProcess::GetBroadcaster () const
948 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
950 ProcessSP process_sp(GetSP());
952 SBBroadcaster broadcaster(process_sp.get(), false);
955 log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)", process_sp.get(),
962 SBProcess::GetBroadcasterClass ()
964 return Process::GetStaticBroadcasterClass().AsCString();
968 SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error)
970 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
972 size_t bytes_read = 0;
974 ProcessSP process_sp(GetSP());
978 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...",
988 Process::StopLocker stop_locker;
989 if (stop_locker.TryLock(&process_sp->GetRunLock()))
991 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
992 bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref());
997 log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running", process_sp.get());
998 sb_error.SetErrorString("process is running");
1003 sb_error.SetErrorString ("SBProcess is invalid");
1009 sb_error.GetDescription (sstr);
1010 log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1017 (uint64_t)bytes_read);
1024 SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error)
1026 size_t bytes_read = 0;
1027 ProcessSP process_sp(GetSP());
1030 Process::StopLocker stop_locker;
1031 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1033 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1034 bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref());
1038 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1040 log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running", process_sp.get());
1041 sb_error.SetErrorString("process is running");
1046 sb_error.SetErrorString ("SBProcess is invalid");
1052 SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error)
1055 ProcessSP process_sp(GetSP());
1058 Process::StopLocker stop_locker;
1059 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1061 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1062 value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref());
1066 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1068 log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running", process_sp.get());
1069 sb_error.SetErrorString("process is running");
1074 sb_error.SetErrorString ("SBProcess is invalid");
1080 SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error)
1082 lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
1083 ProcessSP process_sp(GetSP());
1086 Process::StopLocker stop_locker;
1087 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1089 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1090 ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref());
1094 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1096 log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running", process_sp.get());
1097 sb_error.SetErrorString("process is running");
1102 sb_error.SetErrorString ("SBProcess is invalid");
1108 SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error)
1110 size_t bytes_written = 0;
1112 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1114 ProcessSP process_sp(GetSP());
1118 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...",
1128 Process::StopLocker stop_locker;
1129 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1131 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1132 bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref());
1137 log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running", process_sp.get());
1138 sb_error.SetErrorString("process is running");
1145 sb_error.GetDescription (sstr);
1146 log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1153 (uint64_t)bytes_written);
1156 return bytes_written;
1160 SBProcess::GetDescription (SBStream &description)
1162 Stream &strm = description.ref();
1164 ProcessSP process_sp(GetSP());
1167 char path[PATH_MAX];
1168 GetTarget().GetExecutable().GetPath (path, sizeof(path));
1169 Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1170 const char *exe_name = NULL;
1172 exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1174 strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1175 process_sp->GetID(),
1176 lldb_private::StateAsCString (GetState()),
1178 exe_name ? ", executable = " : "",
1179 exe_name ? exe_name : "");
1182 strm.PutCString ("No value");
1188 SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const
1190 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1193 ProcessSP process_sp(GetSP());
1196 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1197 sb_error.SetError(process_sp->GetWatchpointSupportInfo (num));
1199 log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u",
1200 process_sp.get(), num);
1204 sb_error.SetErrorString ("SBProcess is invalid");
1210 SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error)
1212 ProcessSP process_sp(GetSP());
1215 Process::StopLocker stop_locker;
1216 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1218 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1219 return process_sp->LoadImage (*sb_image_spec, sb_error.ref());
1223 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1225 log->Printf ("SBProcess(%p)::LoadImage() => error: process is running", process_sp.get());
1226 sb_error.SetErrorString("process is running");
1229 return LLDB_INVALID_IMAGE_TOKEN;
1233 SBProcess::UnloadImage (uint32_t image_token)
1235 lldb::SBError sb_error;
1236 ProcessSP process_sp(GetSP());
1239 Process::StopLocker stop_locker;
1240 if (stop_locker.TryLock(&process_sp->GetRunLock()))
1242 Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1243 sb_error.SetError (process_sp->UnloadImage (image_token));
1247 Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1249 log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running", process_sp.get());
1250 sb_error.SetErrorString("process is running");
1254 sb_error.SetErrorString("invalid process");