1 //===-- SBProcess.cpp -------------------------------------------*- C++ -*-===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "lldb/lldb-python.h"
11 
12 #include "lldb/API/SBProcess.h"
13 
14 // C Includes
15 #include <inttypes.h>
16 
17 #include "lldb/lldb-defines.h"
18 #include "lldb/lldb-types.h"
19 
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"
32 
33 // Project includes
34 
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/SBThreadCollection.h"
42 #include "lldb/API/SBStream.h"
43 #include "lldb/API/SBStringList.h"
44 #include "lldb/API/SBUnixSignals.h"
45 
46 using namespace lldb;
47 using namespace lldb_private;
48 
49 
50 SBProcess::SBProcess () :
51     m_opaque_wp()
52 {
53 }
54 
55 
56 //----------------------------------------------------------------------
57 // SBProcess constructor
58 //----------------------------------------------------------------------
59 
60 SBProcess::SBProcess (const SBProcess& rhs) :
61     m_opaque_wp (rhs.m_opaque_wp)
62 {
63 }
64 
65 
66 SBProcess::SBProcess (const lldb::ProcessSP &process_sp) :
67     m_opaque_wp (process_sp)
68 {
69 }
70 
71 const SBProcess&
72 SBProcess::operator = (const SBProcess& rhs)
73 {
74     if (this != &rhs)
75         m_opaque_wp = rhs.m_opaque_wp;
76     return *this;
77 }
78 
79 //----------------------------------------------------------------------
80 // Destructor
81 //----------------------------------------------------------------------
82 SBProcess::~SBProcess()
83 {
84 }
85 
86 const char *
87 SBProcess::GetBroadcasterClassName ()
88 {
89     return Process::GetStaticBroadcasterClass().AsCString();
90 }
91 
92 const char *
93 SBProcess::GetPluginName ()
94 {
95     ProcessSP process_sp(GetSP());
96     if (process_sp)
97     {
98         return process_sp->GetPluginName().GetCString();
99     }
100     return "<Unknown>";
101 }
102 
103 const char *
104 SBProcess::GetShortPluginName ()
105 {
106     ProcessSP process_sp(GetSP());
107     if (process_sp)
108     {
109         return process_sp->GetPluginName().GetCString();
110     }
111     return "<Unknown>";
112 }
113 
114 
115 lldb::ProcessSP
116 SBProcess::GetSP() const
117 {
118     return m_opaque_wp.lock();
119 }
120 
121 void
122 SBProcess::SetSP (const ProcessSP &process_sp)
123 {
124     m_opaque_wp = process_sp;
125 }
126 
127 void
128 SBProcess::Clear ()
129 {
130     m_opaque_wp.reset();
131 }
132 
133 
134 bool
135 SBProcess::IsValid() const
136 {
137     ProcessSP process_sp(m_opaque_wp.lock());
138     return ((bool) process_sp && process_sp->IsValid());
139 }
140 
141 bool
142 SBProcess::RemoteLaunch (char const **argv,
143                          char const **envp,
144                          const char *stdin_path,
145                          const char *stdout_path,
146                          const char *stderr_path,
147                          const char *working_directory,
148                          uint32_t launch_flags,
149                          bool stop_at_entry,
150                          lldb::SBError& error)
151 {
152     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
153     if (log)
154         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))...",
155                      static_cast<void*>(m_opaque_wp.lock().get()),
156                      static_cast<void*>(argv), static_cast<void*>(envp),
157                      stdin_path ? stdin_path : "NULL",
158                      stdout_path ? stdout_path : "NULL",
159                      stderr_path ? stderr_path : "NULL",
160                      working_directory ? working_directory : "NULL",
161                      launch_flags, stop_at_entry,
162                      static_cast<void*>(error.get()));
163 
164     ProcessSP process_sp(GetSP());
165     if (process_sp)
166     {
167         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
168         if (process_sp->GetState() == eStateConnected)
169         {
170             if (stop_at_entry)
171                 launch_flags |= eLaunchFlagStopAtEntry;
172             ProcessLaunchInfo launch_info (stdin_path,
173                                            stdout_path,
174                                            stderr_path,
175                                            working_directory,
176                                            launch_flags);
177             Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
178             if (exe_module)
179                 launch_info.SetExecutableFile(exe_module->GetPlatformFileSpec(), true);
180             if (argv)
181                 launch_info.GetArguments().AppendArguments (argv);
182             if (envp)
183                 launch_info.GetEnvironmentEntries ().SetArguments (envp);
184             error.SetError (process_sp->Launch (launch_info));
185         }
186         else
187         {
188             error.SetErrorString ("must be in eStateConnected to call RemoteLaunch");
189         }
190     }
191     else
192     {
193         error.SetErrorString ("unable to attach pid");
194     }
195 
196     if (log) {
197         SBStream sstr;
198         error.GetDescription (sstr);
199         log->Printf ("SBProcess(%p)::RemoteLaunch (...) => SBError (%p): %s",
200                      static_cast<void*>(process_sp.get()),
201                      static_cast<void*>(error.get()), sstr.GetData());
202     }
203 
204     return error.Success();
205 }
206 
207 bool
208 SBProcess::RemoteAttachToProcessWithID (lldb::pid_t pid, lldb::SBError& error)
209 {
210     ProcessSP process_sp(GetSP());
211     if (process_sp)
212     {
213         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
214         if (process_sp->GetState() == eStateConnected)
215         {
216             ProcessAttachInfo attach_info;
217             attach_info.SetProcessID (pid);
218             error.SetError (process_sp->Attach (attach_info));
219         }
220         else
221         {
222             error.SetErrorString ("must be in eStateConnected to call RemoteAttachToProcessWithID");
223         }
224     }
225     else
226     {
227         error.SetErrorString ("unable to attach pid");
228     }
229 
230     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
231     if (log) {
232         SBStream sstr;
233         error.GetDescription (sstr);
234         log->Printf ("SBProcess(%p)::RemoteAttachToProcessWithID (%" PRIu64 ") => SBError (%p): %s",
235                      static_cast<void*>(process_sp.get()), pid,
236                      static_cast<void*>(error.get()), sstr.GetData());
237     }
238 
239     return error.Success();
240 }
241 
242 
243 uint32_t
244 SBProcess::GetNumThreads ()
245 {
246     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
247 
248     uint32_t num_threads = 0;
249     ProcessSP process_sp(GetSP());
250     if (process_sp)
251     {
252         Process::StopLocker stop_locker;
253 
254         const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
255         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
256         num_threads = process_sp->GetThreadList().GetSize(can_update);
257     }
258 
259     if (log)
260         log->Printf ("SBProcess(%p)::GetNumThreads () => %d",
261                      static_cast<void*>(process_sp.get()), num_threads);
262 
263     return num_threads;
264 }
265 
266 SBThread
267 SBProcess::GetSelectedThread () const
268 {
269     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
270 
271     SBThread sb_thread;
272     ThreadSP thread_sp;
273     ProcessSP process_sp(GetSP());
274     if (process_sp)
275     {
276         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
277         thread_sp = process_sp->GetThreadList().GetSelectedThread();
278         sb_thread.SetThread (thread_sp);
279     }
280 
281     if (log)
282         log->Printf ("SBProcess(%p)::GetSelectedThread () => SBThread(%p)",
283                      static_cast<void*>(process_sp.get()),
284                      static_cast<void*>(thread_sp.get()));
285 
286     return sb_thread;
287 }
288 
289 SBThread
290 SBProcess::CreateOSPluginThread (lldb::tid_t tid, lldb::addr_t context)
291 {
292     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
293 
294     SBThread sb_thread;
295     ThreadSP thread_sp;
296     ProcessSP process_sp(GetSP());
297     if (process_sp)
298     {
299         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
300         thread_sp = process_sp->CreateOSPluginThread(tid, context);
301         sb_thread.SetThread (thread_sp);
302     }
303 
304     if (log)
305         log->Printf ("SBProcess(%p)::CreateOSPluginThread (tid=0x%" PRIx64 ", context=0x%" PRIx64 ") => SBThread(%p)",
306                      static_cast<void*>(process_sp.get()), tid, context,
307                      static_cast<void*>(thread_sp.get()));
308 
309     return sb_thread;
310 }
311 
312 SBTarget
313 SBProcess::GetTarget() const
314 {
315     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
316 
317     SBTarget sb_target;
318     TargetSP target_sp;
319     ProcessSP process_sp(GetSP());
320     if (process_sp)
321     {
322         target_sp = process_sp->GetTarget().shared_from_this();
323         sb_target.SetSP (target_sp);
324     }
325 
326     if (log)
327         log->Printf ("SBProcess(%p)::GetTarget () => SBTarget(%p)",
328                      static_cast<void*>(process_sp.get()),
329                      static_cast<void*>(target_sp.get()));
330 
331     return sb_target;
332 }
333 
334 
335 size_t
336 SBProcess::PutSTDIN (const char *src, size_t src_len)
337 {
338     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
339 
340     size_t ret_val = 0;
341     ProcessSP process_sp(GetSP());
342     if (process_sp)
343     {
344         Error error;
345         ret_val =  process_sp->PutSTDIN (src, src_len, error);
346     }
347 
348     if (log)
349         log->Printf("SBProcess(%p)::PutSTDIN (src=\"%s\", src_len=%" PRIu64 ") => %" PRIu64,
350                      static_cast<void*>(process_sp.get()), src,
351                      static_cast<uint64_t>(src_len),
352                      static_cast<uint64_t>(ret_val));
353 
354     return ret_val;
355 }
356 
357 size_t
358 SBProcess::GetSTDOUT (char *dst, size_t dst_len) const
359 {
360     size_t bytes_read = 0;
361     ProcessSP process_sp(GetSP());
362     if (process_sp)
363     {
364         Error error;
365         bytes_read = process_sp->GetSTDOUT (dst, dst_len, error);
366     }
367 
368     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
369     if (log)
370         log->Printf ("SBProcess(%p)::GetSTDOUT (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
371                      static_cast<void*>(process_sp.get()),
372                      static_cast<int>(bytes_read), dst,
373                      static_cast<uint64_t>(dst_len),
374                      static_cast<uint64_t>(bytes_read));
375 
376     return bytes_read;
377 }
378 
379 size_t
380 SBProcess::GetSTDERR (char *dst, size_t dst_len) const
381 {
382     size_t bytes_read = 0;
383     ProcessSP process_sp(GetSP());
384     if (process_sp)
385     {
386         Error error;
387         bytes_read = process_sp->GetSTDERR (dst, dst_len, error);
388     }
389 
390     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
391     if (log)
392         log->Printf ("SBProcess(%p)::GetSTDERR (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
393                      static_cast<void*>(process_sp.get()),
394                      static_cast<int>(bytes_read), dst,
395                      static_cast<uint64_t>(dst_len),
396                      static_cast<uint64_t>(bytes_read));
397 
398     return bytes_read;
399 }
400 
401 size_t
402 SBProcess::GetAsyncProfileData(char *dst, size_t dst_len) const
403 {
404     size_t bytes_read = 0;
405     ProcessSP process_sp(GetSP());
406     if (process_sp)
407     {
408         Error error;
409         bytes_read = process_sp->GetAsyncProfileData (dst, dst_len, error);
410     }
411 
412     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
413     if (log)
414         log->Printf ("SBProcess(%p)::GetProfileData (dst=\"%.*s\", dst_len=%" PRIu64 ") => %" PRIu64,
415                      static_cast<void*>(process_sp.get()),
416                      static_cast<int>(bytes_read), dst,
417                      static_cast<uint64_t>(dst_len),
418                      static_cast<uint64_t>(bytes_read));
419 
420     return bytes_read;
421 }
422 
423 void
424 SBProcess::ReportEventState (const SBEvent &event, FILE *out) const
425 {
426     if (out == NULL)
427         return;
428 
429     ProcessSP process_sp(GetSP());
430     if (process_sp)
431     {
432         const StateType event_state = SBProcess::GetStateFromEvent (event);
433         char message[1024];
434         int message_len = ::snprintf (message,
435                                       sizeof (message),
436                                       "Process %" PRIu64 " %s\n",
437                                       process_sp->GetID(),
438                                       SBDebugger::StateAsCString (event_state));
439 
440         if (message_len > 0)
441             ::fwrite (message, 1, message_len, out);
442     }
443 }
444 
445 void
446 SBProcess::AppendEventStateReport (const SBEvent &event, SBCommandReturnObject &result)
447 {
448     ProcessSP process_sp(GetSP());
449     if (process_sp)
450     {
451         const StateType event_state = SBProcess::GetStateFromEvent (event);
452         char message[1024];
453         ::snprintf (message,
454                     sizeof (message),
455                     "Process %" PRIu64 " %s\n",
456                     process_sp->GetID(),
457                     SBDebugger::StateAsCString (event_state));
458 
459         result.AppendMessage (message);
460     }
461 }
462 
463 bool
464 SBProcess::SetSelectedThread (const SBThread &thread)
465 {
466     ProcessSP process_sp(GetSP());
467     if (process_sp)
468     {
469         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
470         return process_sp->GetThreadList().SetSelectedThreadByID (thread.GetThreadID());
471     }
472     return false;
473 }
474 
475 bool
476 SBProcess::SetSelectedThreadByID (lldb::tid_t tid)
477 {
478     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
479 
480     bool ret_val = false;
481     ProcessSP process_sp(GetSP());
482     if (process_sp)
483     {
484         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
485         ret_val = process_sp->GetThreadList().SetSelectedThreadByID (tid);
486     }
487 
488     if (log)
489         log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%4.4" PRIx64 ") => %s",
490                      static_cast<void*>(process_sp.get()), tid,
491                      (ret_val ? "true" : "false"));
492 
493     return ret_val;
494 }
495 
496 bool
497 SBProcess::SetSelectedThreadByIndexID (uint32_t index_id)
498 {
499     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
500 
501     bool ret_val = false;
502     ProcessSP process_sp(GetSP());
503     if (process_sp)
504     {
505         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
506         ret_val = process_sp->GetThreadList().SetSelectedThreadByIndexID (index_id);
507     }
508 
509     if (log)
510         log->Printf ("SBProcess(%p)::SetSelectedThreadByID (tid=0x%x) => %s",
511                      static_cast<void*>(process_sp.get()), index_id,
512                      (ret_val ? "true" : "false"));
513 
514     return ret_val;
515 }
516 
517 SBThread
518 SBProcess::GetThreadAtIndex (size_t index)
519 {
520     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
521 
522     SBThread sb_thread;
523     ThreadSP thread_sp;
524     ProcessSP process_sp(GetSP());
525     if (process_sp)
526     {
527         Process::StopLocker stop_locker;
528         const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
529         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
530         thread_sp = process_sp->GetThreadList().GetThreadAtIndex(index, can_update);
531         sb_thread.SetThread (thread_sp);
532     }
533 
534     if (log)
535         log->Printf ("SBProcess(%p)::GetThreadAtIndex (index=%d) => SBThread(%p)",
536                      static_cast<void*>(process_sp.get()),
537                      static_cast<uint32_t>(index),
538                      static_cast<void*>(thread_sp.get()));
539 
540     return sb_thread;
541 }
542 
543 uint32_t
544 SBProcess::GetNumQueues ()
545 {
546     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
547 
548     uint32_t num_queues = 0;
549     ProcessSP process_sp(GetSP());
550     if (process_sp)
551     {
552         Process::StopLocker stop_locker;
553 
554         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
555         num_queues = process_sp->GetQueueList().GetSize();
556     }
557 
558     if (log)
559         log->Printf ("SBProcess(%p)::GetNumQueues () => %d",
560                      static_cast<void*>(process_sp.get()), num_queues);
561 
562     return num_queues;
563 }
564 
565 SBQueue
566 SBProcess::GetQueueAtIndex (size_t index)
567 {
568     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
569 
570     SBQueue sb_queue;
571     QueueSP queue_sp;
572     ProcessSP process_sp(GetSP());
573     if (process_sp)
574     {
575         Process::StopLocker stop_locker;
576         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
577         queue_sp = process_sp->GetQueueList().GetQueueAtIndex(index);
578         sb_queue.SetQueue (queue_sp);
579     }
580 
581     if (log)
582         log->Printf ("SBProcess(%p)::GetQueueAtIndex (index=%d) => SBQueue(%p)",
583                      static_cast<void*>(process_sp.get()),
584                      static_cast<uint32_t>(index),
585                      static_cast<void*>(queue_sp.get()));
586 
587     return sb_queue;
588 }
589 
590 
591 uint32_t
592 SBProcess::GetStopID(bool include_expression_stops)
593 {
594     ProcessSP process_sp(GetSP());
595     if (process_sp)
596     {
597         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
598         if (include_expression_stops)
599             return process_sp->GetStopID();
600         else
601             return process_sp->GetLastNaturalStopID();
602     }
603     return 0;
604 }
605 
606 SBEvent
607 SBProcess::GetStopEventForStopID(uint32_t stop_id)
608 {
609     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
610 
611     SBEvent sb_event;
612     EventSP event_sp;
613     ProcessSP process_sp(GetSP());
614     if (process_sp)
615     {
616         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
617         event_sp = process_sp->GetStopEventForStopID(stop_id);
618         sb_event.reset(event_sp);
619     }
620 
621     if (log)
622         log->Printf ("SBProcess(%p)::GetStopEventForStopID (stop_id=%" PRIu32 ") => SBEvent(%p)",
623                      static_cast<void*>(process_sp.get()),
624                      stop_id,
625                      static_cast<void*>(event_sp.get()));
626 
627     return sb_event;
628 }
629 
630 StateType
631 SBProcess::GetState ()
632 {
633 
634     StateType ret_val = eStateInvalid;
635     ProcessSP process_sp(GetSP());
636     if (process_sp)
637     {
638         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
639         ret_val = process_sp->GetState();
640     }
641 
642     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
643     if (log)
644         log->Printf ("SBProcess(%p)::GetState () => %s",
645                      static_cast<void*>(process_sp.get()),
646                      lldb_private::StateAsCString (ret_val));
647 
648     return ret_val;
649 }
650 
651 
652 int
653 SBProcess::GetExitStatus ()
654 {
655     int exit_status = 0;
656     ProcessSP process_sp(GetSP());
657     if (process_sp)
658     {
659         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
660         exit_status = process_sp->GetExitStatus ();
661     }
662     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
663     if (log)
664         log->Printf ("SBProcess(%p)::GetExitStatus () => %i (0x%8.8x)",
665                      static_cast<void*>(process_sp.get()), exit_status,
666                      exit_status);
667 
668     return exit_status;
669 }
670 
671 const char *
672 SBProcess::GetExitDescription ()
673 {
674     const char *exit_desc = NULL;
675     ProcessSP process_sp(GetSP());
676     if (process_sp)
677     {
678         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
679         exit_desc = process_sp->GetExitDescription ();
680     }
681     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
682     if (log)
683         log->Printf ("SBProcess(%p)::GetExitDescription () => %s",
684                      static_cast<void*>(process_sp.get()), exit_desc);
685     return exit_desc;
686 }
687 
688 lldb::pid_t
689 SBProcess::GetProcessID ()
690 {
691     lldb::pid_t ret_val = LLDB_INVALID_PROCESS_ID;
692     ProcessSP process_sp(GetSP());
693     if (process_sp)
694         ret_val = process_sp->GetID();
695 
696     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
697     if (log)
698         log->Printf ("SBProcess(%p)::GetProcessID () => %" PRIu64,
699                      static_cast<void*>(process_sp.get()), ret_val);
700 
701     return ret_val;
702 }
703 
704 uint32_t
705 SBProcess::GetUniqueID()
706 {
707     uint32_t ret_val = 0;
708     ProcessSP process_sp(GetSP());
709     if (process_sp)
710         ret_val = process_sp->GetUniqueID();
711     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
712     if (log)
713         log->Printf ("SBProcess(%p)::GetUniqueID () => %" PRIu32,
714                      static_cast<void*>(process_sp.get()), ret_val);
715     return ret_val;
716 }
717 
718 ByteOrder
719 SBProcess::GetByteOrder () const
720 {
721     ByteOrder byteOrder = eByteOrderInvalid;
722     ProcessSP process_sp(GetSP());
723     if (process_sp)
724         byteOrder = process_sp->GetTarget().GetArchitecture().GetByteOrder();
725 
726     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
727     if (log)
728         log->Printf ("SBProcess(%p)::GetByteOrder () => %d",
729                      static_cast<void*>(process_sp.get()), byteOrder);
730 
731     return byteOrder;
732 }
733 
734 uint32_t
735 SBProcess::GetAddressByteSize () const
736 {
737     uint32_t size = 0;
738     ProcessSP process_sp(GetSP());
739     if (process_sp)
740         size =  process_sp->GetTarget().GetArchitecture().GetAddressByteSize();
741 
742     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
743     if (log)
744         log->Printf ("SBProcess(%p)::GetAddressByteSize () => %d",
745                      static_cast<void*>(process_sp.get()), size);
746 
747     return size;
748 }
749 
750 SBError
751 SBProcess::Continue ()
752 {
753     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
754 
755     SBError sb_error;
756     ProcessSP process_sp(GetSP());
757 
758     if (log)
759         log->Printf ("SBProcess(%p)::Continue ()...",
760                      static_cast<void*>(process_sp.get()));
761 
762     if (process_sp)
763     {
764         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
765 
766         if (process_sp->GetTarget().GetDebugger().GetAsyncExecution ())
767             sb_error.ref() = process_sp->Resume ();
768         else
769             sb_error.ref() = process_sp->ResumeSynchronous (NULL);
770     }
771     else
772         sb_error.SetErrorString ("SBProcess is invalid");
773 
774     if (log)
775     {
776         SBStream sstr;
777         sb_error.GetDescription (sstr);
778         log->Printf ("SBProcess(%p)::Continue () => SBError (%p): %s",
779                      static_cast<void*>(process_sp.get()),
780                      static_cast<void*>(sb_error.get()), sstr.GetData());
781     }
782 
783     return sb_error;
784 }
785 
786 
787 SBError
788 SBProcess::Destroy ()
789 {
790     SBError sb_error;
791     ProcessSP process_sp(GetSP());
792     if (process_sp)
793     {
794         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
795         sb_error.SetError(process_sp->Destroy(false));
796     }
797     else
798         sb_error.SetErrorString ("SBProcess is invalid");
799 
800     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
801     if (log)
802     {
803         SBStream sstr;
804         sb_error.GetDescription (sstr);
805         log->Printf ("SBProcess(%p)::Destroy () => SBError (%p): %s",
806                      static_cast<void*>(process_sp.get()),
807                      static_cast<void*>(sb_error.get()), sstr.GetData());
808     }
809 
810     return sb_error;
811 }
812 
813 
814 SBError
815 SBProcess::Stop ()
816 {
817     SBError sb_error;
818     ProcessSP process_sp(GetSP());
819     if (process_sp)
820     {
821         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
822         sb_error.SetError (process_sp->Halt());
823     }
824     else
825         sb_error.SetErrorString ("SBProcess is invalid");
826 
827     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
828     if (log)
829     {
830         SBStream sstr;
831         sb_error.GetDescription (sstr);
832         log->Printf ("SBProcess(%p)::Stop () => SBError (%p): %s",
833                      static_cast<void*>(process_sp.get()),
834                      static_cast<void*>(sb_error.get()), sstr.GetData());
835     }
836 
837     return sb_error;
838 }
839 
840 SBError
841 SBProcess::Kill ()
842 {
843     SBError sb_error;
844     ProcessSP process_sp(GetSP());
845     if (process_sp)
846     {
847         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
848         sb_error.SetError (process_sp->Destroy(true));
849     }
850     else
851         sb_error.SetErrorString ("SBProcess is invalid");
852 
853     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
854     if (log)
855     {
856         SBStream sstr;
857         sb_error.GetDescription (sstr);
858         log->Printf ("SBProcess(%p)::Kill () => SBError (%p): %s",
859                      static_cast<void*>(process_sp.get()),
860                      static_cast<void*>(sb_error.get()), sstr.GetData());
861     }
862 
863     return sb_error;
864 }
865 
866 SBError
867 SBProcess::Detach ()
868 {
869     // FIXME: This should come from a process default.
870     bool keep_stopped = false;
871     return Detach (keep_stopped);
872 }
873 
874 SBError
875 SBProcess::Detach (bool keep_stopped)
876 {
877     SBError sb_error;
878     ProcessSP process_sp(GetSP());
879     if (process_sp)
880     {
881         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
882         sb_error.SetError (process_sp->Detach(keep_stopped));
883     }
884     else
885         sb_error.SetErrorString ("SBProcess is invalid");
886 
887     return sb_error;
888 }
889 
890 SBError
891 SBProcess::Signal (int signo)
892 {
893     SBError sb_error;
894     ProcessSP process_sp(GetSP());
895     if (process_sp)
896     {
897         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
898         sb_error.SetError (process_sp->Signal (signo));
899     }
900     else
901         sb_error.SetErrorString ("SBProcess is invalid");
902     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
903     if (log)
904     {
905         SBStream sstr;
906         sb_error.GetDescription (sstr);
907         log->Printf ("SBProcess(%p)::Signal (signo=%i) => SBError (%p): %s",
908                      static_cast<void*>(process_sp.get()), signo,
909                      static_cast<void*>(sb_error.get()), sstr.GetData());
910     }
911     return sb_error;
912 }
913 
914 SBUnixSignals
915 SBProcess::GetUnixSignals()
916 {
917     SBUnixSignals sb_unix_signals;
918     ProcessSP process_sp(GetSP());
919     if (process_sp)
920     {
921         sb_unix_signals.SetSP(process_sp);
922     }
923 
924     return sb_unix_signals;
925 }
926 
927 void
928 SBProcess::SendAsyncInterrupt ()
929 {
930     ProcessSP process_sp(GetSP());
931     if (process_sp)
932     {
933         process_sp->SendAsyncInterrupt ();
934     }
935 }
936 
937 SBThread
938 SBProcess::GetThreadByID (tid_t tid)
939 {
940     SBThread sb_thread;
941     ThreadSP thread_sp;
942     ProcessSP process_sp(GetSP());
943     if (process_sp)
944     {
945         Process::StopLocker stop_locker;
946         const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
947         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
948         thread_sp = process_sp->GetThreadList().FindThreadByID (tid, can_update);
949         sb_thread.SetThread (thread_sp);
950     }
951 
952     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
953     if (log)
954         log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%4.4" PRIx64 ") => SBThread (%p)",
955                      static_cast<void*>(process_sp.get()), tid,
956                      static_cast<void*>(thread_sp.get()));
957 
958     return sb_thread;
959 }
960 
961 SBThread
962 SBProcess::GetThreadByIndexID (uint32_t index_id)
963 {
964     SBThread sb_thread;
965     ThreadSP thread_sp;
966     ProcessSP process_sp(GetSP());
967     if (process_sp)
968     {
969         Process::StopLocker stop_locker;
970         const bool can_update = stop_locker.TryLock(&process_sp->GetRunLock());
971         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
972         thread_sp = process_sp->GetThreadList().FindThreadByIndexID (index_id, can_update);
973         sb_thread.SetThread (thread_sp);
974     }
975 
976     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
977     if (log)
978         log->Printf ("SBProcess(%p)::GetThreadByID (tid=0x%x) => SBThread (%p)",
979                      static_cast<void*>(process_sp.get()), index_id,
980                      static_cast<void*>(thread_sp.get()));
981 
982     return sb_thread;
983 }
984 
985 StateType
986 SBProcess::GetStateFromEvent (const SBEvent &event)
987 {
988     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
989 
990     StateType ret_val = Process::ProcessEventData::GetStateFromEvent (event.get());
991 
992     if (log)
993         log->Printf ("SBProcess::GetStateFromEvent (event.sp=%p) => %s",
994                      static_cast<void*>(event.get()),
995                      lldb_private::StateAsCString (ret_val));
996 
997     return ret_val;
998 }
999 
1000 bool
1001 SBProcess::GetRestartedFromEvent (const SBEvent &event)
1002 {
1003     return Process::ProcessEventData::GetRestartedFromEvent (event.get());
1004 }
1005 
1006 size_t
1007 SBProcess::GetNumRestartedReasonsFromEvent (const lldb::SBEvent &event)
1008 {
1009     return Process::ProcessEventData::GetNumRestartedReasons(event.get());
1010 }
1011 
1012 const char *
1013 SBProcess::GetRestartedReasonAtIndexFromEvent (const lldb::SBEvent &event, size_t idx)
1014 {
1015     return Process::ProcessEventData::GetRestartedReasonAtIndex(event.get(), idx);
1016 }
1017 
1018 SBProcess
1019 SBProcess::GetProcessFromEvent (const SBEvent &event)
1020 {
1021     SBProcess process(Process::ProcessEventData::GetProcessFromEvent (event.get()));
1022     return process;
1023 }
1024 
1025 bool
1026 SBProcess::GetInterruptedFromEvent (const SBEvent &event)
1027 {
1028     return Process::ProcessEventData::GetInterruptedFromEvent(event.get());
1029 }
1030 
1031 bool
1032 SBProcess::EventIsProcessEvent (const SBEvent &event)
1033 {
1034     return event.GetBroadcasterClass() == SBProcess::GetBroadcasterClass();
1035 }
1036 
1037 SBBroadcaster
1038 SBProcess::GetBroadcaster () const
1039 {
1040     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1041 
1042     ProcessSP process_sp(GetSP());
1043 
1044     SBBroadcaster broadcaster(process_sp.get(), false);
1045 
1046     if (log)
1047         log->Printf ("SBProcess(%p)::GetBroadcaster () => SBBroadcaster (%p)",
1048                      static_cast<void*>(process_sp.get()),
1049                      static_cast<void*>(broadcaster.get()));
1050 
1051     return broadcaster;
1052 }
1053 
1054 const char *
1055 SBProcess::GetBroadcasterClass ()
1056 {
1057     return Process::GetStaticBroadcasterClass().AsCString();
1058 }
1059 
1060 size_t
1061 SBProcess::ReadMemory (addr_t addr, void *dst, size_t dst_len, SBError &sb_error)
1062 {
1063     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1064 
1065     size_t bytes_read = 0;
1066 
1067     ProcessSP process_sp(GetSP());
1068 
1069     if (log)
1070         log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p))...",
1071                      static_cast<void*>(process_sp.get()), addr,
1072                      static_cast<void*>(dst), static_cast<uint64_t>(dst_len),
1073                      static_cast<void*>(sb_error.get()));
1074 
1075     if (process_sp)
1076     {
1077         Process::StopLocker stop_locker;
1078         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1079         {
1080             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1081             bytes_read = process_sp->ReadMemory (addr, dst, dst_len, sb_error.ref());
1082         }
1083         else
1084         {
1085             if (log)
1086                 log->Printf ("SBProcess(%p)::ReadMemory() => error: process is running",
1087                              static_cast<void*>(process_sp.get()));
1088             sb_error.SetErrorString("process is running");
1089         }
1090     }
1091     else
1092     {
1093         sb_error.SetErrorString ("SBProcess is invalid");
1094     }
1095 
1096     if (log)
1097     {
1098         SBStream sstr;
1099         sb_error.GetDescription (sstr);
1100         log->Printf ("SBProcess(%p)::ReadMemory (addr=0x%" PRIx64 ", dst=%p, dst_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1101                      static_cast<void*>(process_sp.get()), addr,
1102                      static_cast<void*>(dst), static_cast<uint64_t>(dst_len),
1103                      static_cast<void*>(sb_error.get()), sstr.GetData(),
1104                      static_cast<uint64_t>(bytes_read));
1105     }
1106 
1107     return bytes_read;
1108 }
1109 
1110 size_t
1111 SBProcess::ReadCStringFromMemory (addr_t addr, void *buf, size_t size, lldb::SBError &sb_error)
1112 {
1113     size_t bytes_read = 0;
1114     ProcessSP process_sp(GetSP());
1115     if (process_sp)
1116     {
1117         Process::StopLocker stop_locker;
1118         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1119         {
1120             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1121             bytes_read = process_sp->ReadCStringFromMemory (addr, (char *)buf, size, sb_error.ref());
1122         }
1123         else
1124         {
1125             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1126             if (log)
1127                 log->Printf ("SBProcess(%p)::ReadCStringFromMemory() => error: process is running",
1128                              static_cast<void*>(process_sp.get()));
1129             sb_error.SetErrorString("process is running");
1130         }
1131     }
1132     else
1133     {
1134         sb_error.SetErrorString ("SBProcess is invalid");
1135     }
1136     return bytes_read;
1137 }
1138 
1139 uint64_t
1140 SBProcess::ReadUnsignedFromMemory (addr_t addr, uint32_t byte_size, lldb::SBError &sb_error)
1141 {
1142     uint64_t value = 0;
1143     ProcessSP process_sp(GetSP());
1144     if (process_sp)
1145     {
1146         Process::StopLocker stop_locker;
1147         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1148         {
1149             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1150             value = process_sp->ReadUnsignedIntegerFromMemory (addr, byte_size, 0, sb_error.ref());
1151         }
1152         else
1153         {
1154             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1155             if (log)
1156                 log->Printf ("SBProcess(%p)::ReadUnsignedFromMemory() => error: process is running",
1157                              static_cast<void*>(process_sp.get()));
1158             sb_error.SetErrorString("process is running");
1159         }
1160     }
1161     else
1162     {
1163         sb_error.SetErrorString ("SBProcess is invalid");
1164     }
1165     return value;
1166 }
1167 
1168 lldb::addr_t
1169 SBProcess::ReadPointerFromMemory (addr_t addr, lldb::SBError &sb_error)
1170 {
1171     lldb::addr_t ptr = LLDB_INVALID_ADDRESS;
1172     ProcessSP process_sp(GetSP());
1173     if (process_sp)
1174     {
1175         Process::StopLocker stop_locker;
1176         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1177         {
1178             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1179             ptr = process_sp->ReadPointerFromMemory (addr, sb_error.ref());
1180         }
1181         else
1182         {
1183             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1184             if (log)
1185                 log->Printf ("SBProcess(%p)::ReadPointerFromMemory() => error: process is running",
1186                              static_cast<void*>(process_sp.get()));
1187             sb_error.SetErrorString("process is running");
1188         }
1189     }
1190     else
1191     {
1192         sb_error.SetErrorString ("SBProcess is invalid");
1193     }
1194     return ptr;
1195 }
1196 
1197 size_t
1198 SBProcess::WriteMemory (addr_t addr, const void *src, size_t src_len, SBError &sb_error)
1199 {
1200     size_t bytes_written = 0;
1201 
1202     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1203 
1204     ProcessSP process_sp(GetSP());
1205 
1206     if (log)
1207         log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p))...",
1208                      static_cast<void*>(process_sp.get()), addr,
1209                      static_cast<const void*>(src),
1210                      static_cast<uint64_t>(src_len),
1211                      static_cast<void*>(sb_error.get()));
1212 
1213     if (process_sp)
1214     {
1215         Process::StopLocker stop_locker;
1216         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1217         {
1218             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1219             bytes_written = process_sp->WriteMemory (addr, src, src_len, sb_error.ref());
1220         }
1221         else
1222         {
1223             if (log)
1224                 log->Printf ("SBProcess(%p)::WriteMemory() => error: process is running",
1225                              static_cast<void*>(process_sp.get()));
1226             sb_error.SetErrorString("process is running");
1227         }
1228     }
1229 
1230     if (log)
1231     {
1232         SBStream sstr;
1233         sb_error.GetDescription (sstr);
1234         log->Printf ("SBProcess(%p)::WriteMemory (addr=0x%" PRIx64 ", src=%p, src_len=%" PRIu64 ", SBError (%p): %s) => %" PRIu64,
1235                      static_cast<void*>(process_sp.get()), addr,
1236                      static_cast<const void*>(src),
1237                      static_cast<uint64_t>(src_len),
1238                      static_cast<void*>(sb_error.get()), sstr.GetData(),
1239                      static_cast<uint64_t>(bytes_written));
1240     }
1241 
1242     return bytes_written;
1243 }
1244 
1245 bool
1246 SBProcess::GetDescription (SBStream &description)
1247 {
1248     Stream &strm = description.ref();
1249 
1250     ProcessSP process_sp(GetSP());
1251     if (process_sp)
1252     {
1253         char path[PATH_MAX];
1254         GetTarget().GetExecutable().GetPath (path, sizeof(path));
1255         Module *exe_module = process_sp->GetTarget().GetExecutableModulePointer();
1256         const char *exe_name = NULL;
1257         if (exe_module)
1258             exe_name = exe_module->GetFileSpec().GetFilename().AsCString();
1259 
1260         strm.Printf ("SBProcess: pid = %" PRIu64 ", state = %s, threads = %d%s%s",
1261                      process_sp->GetID(),
1262                      lldb_private::StateAsCString (GetState()),
1263                      GetNumThreads(),
1264                      exe_name ? ", executable = " : "",
1265                      exe_name ? exe_name : "");
1266     }
1267     else
1268         strm.PutCString ("No value");
1269 
1270     return true;
1271 }
1272 
1273 uint32_t
1274 SBProcess::GetNumSupportedHardwareWatchpoints (lldb::SBError &sb_error) const
1275 {
1276     Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1277 
1278     uint32_t num = 0;
1279     ProcessSP process_sp(GetSP());
1280     if (process_sp)
1281     {
1282         Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1283         sb_error.SetError(process_sp->GetWatchpointSupportInfo (num));
1284         if (log)
1285             log->Printf ("SBProcess(%p)::GetNumSupportedHardwareWatchpoints () => %u",
1286                          static_cast<void*>(process_sp.get()), num);
1287     }
1288     else
1289     {
1290         sb_error.SetErrorString ("SBProcess is invalid");
1291     }
1292     return num;
1293 }
1294 
1295 uint32_t
1296 SBProcess::LoadImage (lldb::SBFileSpec &sb_image_spec, lldb::SBError &sb_error)
1297 {
1298     ProcessSP process_sp(GetSP());
1299     if (process_sp)
1300     {
1301         Process::StopLocker stop_locker;
1302         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1303         {
1304             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1305             return process_sp->LoadImage (*sb_image_spec, sb_error.ref());
1306         }
1307         else
1308         {
1309             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1310             if (log)
1311                 log->Printf ("SBProcess(%p)::LoadImage() => error: process is running",
1312                              static_cast<void*>(process_sp.get()));
1313             sb_error.SetErrorString("process is running");
1314         }
1315     }
1316     return LLDB_INVALID_IMAGE_TOKEN;
1317 }
1318 
1319 lldb::SBError
1320 SBProcess::UnloadImage (uint32_t image_token)
1321 {
1322     lldb::SBError sb_error;
1323     ProcessSP process_sp(GetSP());
1324     if (process_sp)
1325     {
1326         Process::StopLocker stop_locker;
1327         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1328         {
1329             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1330             sb_error.SetError (process_sp->UnloadImage (image_token));
1331         }
1332         else
1333         {
1334             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1335             if (log)
1336                 log->Printf ("SBProcess(%p)::UnloadImage() => error: process is running",
1337                              static_cast<void*>(process_sp.get()));
1338             sb_error.SetErrorString("process is running");
1339         }
1340     }
1341     else
1342         sb_error.SetErrorString("invalid process");
1343     return sb_error;
1344 }
1345 
1346 lldb::SBError
1347 SBProcess::SendEventData (const char *event_data)
1348 {
1349     lldb::SBError sb_error;
1350     ProcessSP process_sp(GetSP());
1351     if (process_sp)
1352     {
1353         Process::StopLocker stop_locker;
1354         if (stop_locker.TryLock(&process_sp->GetRunLock()))
1355         {
1356             Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex());
1357             sb_error.SetError (process_sp->SendEventData (event_data));
1358         }
1359         else
1360         {
1361             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1362             if (log)
1363                 log->Printf ("SBProcess(%p)::SendEventData() => error: process is running",
1364                              static_cast<void*>(process_sp.get()));
1365             sb_error.SetErrorString("process is running");
1366         }
1367     }
1368     else
1369         sb_error.SetErrorString("invalid process");
1370     return sb_error;
1371 }
1372 
1373 uint32_t
1374 SBProcess::GetNumExtendedBacktraceTypes ()
1375 {
1376     ProcessSP process_sp(GetSP());
1377     if (process_sp && process_sp->GetSystemRuntime())
1378     {
1379         SystemRuntime *runtime = process_sp->GetSystemRuntime();
1380         return runtime->GetExtendedBacktraceTypes().size();
1381     }
1382     return 0;
1383 }
1384 
1385 const char *
1386 SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx)
1387 {
1388     ProcessSP process_sp(GetSP());
1389     if (process_sp && process_sp->GetSystemRuntime())
1390     {
1391         SystemRuntime *runtime = process_sp->GetSystemRuntime();
1392         const std::vector<ConstString> &names = runtime->GetExtendedBacktraceTypes();
1393         if (idx < names.size())
1394         {
1395             return names[idx].AsCString();
1396         }
1397         else
1398         {
1399             Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1400             if (log)
1401                 log->Printf("SBProcess(%p)::GetExtendedBacktraceTypeAtIndex() => error: requested extended backtrace name out of bounds",
1402                             static_cast<void*>(process_sp.get()));
1403         }
1404     }
1405     return NULL;
1406 }
1407 
1408 SBThreadCollection
1409 SBProcess::GetHistoryThreads (addr_t addr)
1410 {
1411     ProcessSP process_sp(GetSP());
1412     SBThreadCollection threads;
1413     if (process_sp)
1414     {
1415         threads = SBThreadCollection(process_sp->GetHistoryThreads(addr));
1416     }
1417     return threads;
1418 }
1419 
1420 bool
1421 SBProcess::IsInstrumentationRuntimePresent(InstrumentationRuntimeType type)
1422 {
1423     ProcessSP process_sp(GetSP());
1424     if (! process_sp)
1425         return false;
1426 
1427     InstrumentationRuntimeSP runtime_sp = process_sp->GetInstrumentationRuntime(type);
1428 
1429     if (! runtime_sp.get())
1430         return false;
1431 
1432     return runtime_sp->IsActive();
1433 }
1434