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