1 //===-- SBDebugger.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/SBDebugger.h"
11 
12 #include "lldb/lldb-include.h"
13 
14 #include "lldb/API/SBListener.h"
15 #include "lldb/API/SBBroadcaster.h"
16 #include "lldb/API/SBCommandInterpreter.h"
17 #include "lldb/API/SBCommandReturnObject.h"
18 #include "lldb/API/SBEvent.h"
19 #include "lldb/API/SBFrame.h"
20 #include "lldb/API/SBInputReader.h"
21 #include "lldb/API/SBProcess.h"
22 #include "lldb/API/SBSourceManager.h"
23 #include "lldb/API/SBStream.h"
24 #include "lldb/API/SBStringList.h"
25 #include "lldb/API/SBTarget.h"
26 #include "lldb/API/SBThread.h"
27 #include "lldb/Core/Debugger.h"
28 #include "lldb/Core/State.h"
29 #include "lldb/Interpreter/Args.h"
30 #include "lldb/Interpreter/CommandInterpreter.h"
31 #include "lldb/Target/Process.h"
32 #include "lldb/Target/TargetList.h"
33 
34 using namespace lldb;
35 using namespace lldb_private;
36 
37 void
38 SBDebugger::Initialize ()
39 {
40     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
41 
42     if (log)
43         log->Printf ("SBDebugger::Initialize ()");
44 
45     Debugger::Initialize();
46 }
47 
48 void
49 SBDebugger::Terminate ()
50 {
51     Debugger::Terminate();
52 }
53 
54 void
55 SBDebugger::Clear ()
56 {
57     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
58 
59     if (log)
60         log->Printf ("SBDebugger(%p)::Clear ()", m_opaque_sp.get());
61 
62     if (m_opaque_sp)
63         m_opaque_sp->CleanUpInputReaders ();
64 
65     m_opaque_sp.reset();
66 }
67 
68 SBDebugger
69 SBDebugger::Create()
70 {
71     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
72 
73     SBDebugger debugger;
74     debugger.reset(Debugger::CreateInstance());
75 
76     if (log)
77     {
78         SBStream sstr;
79         debugger.GetDescription (sstr);
80         log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData());
81     }
82 
83     return debugger;
84 }
85 
86 void
87 SBDebugger::Destroy (SBDebugger &debugger)
88 {
89     LogSP log (lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
90 
91     if (log)
92     {
93         SBStream sstr;
94         debugger.GetDescription (sstr);
95         log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData());
96     }
97 
98     Debugger::Destroy (debugger.m_opaque_sp);
99 
100     if (debugger.m_opaque_sp.get() != NULL)
101         debugger.m_opaque_sp.reset();
102 }
103 
104 SBDebugger::SBDebugger () :
105     m_opaque_sp ()
106 {
107 }
108 
109 SBDebugger::SBDebugger(const SBDebugger &rhs) :
110     m_opaque_sp (rhs.m_opaque_sp)
111 {
112 }
113 
114 SBDebugger &
115 SBDebugger::operator = (const SBDebugger &rhs)
116 {
117     if (this != &rhs)
118     {
119         m_opaque_sp = rhs.m_opaque_sp;
120     }
121     return *this;
122 }
123 
124 SBDebugger::~SBDebugger ()
125 {
126 }
127 
128 bool
129 SBDebugger::IsValid() const
130 {
131     return m_opaque_sp.get() != NULL;
132 }
133 
134 
135 void
136 SBDebugger::SetAsync (bool b)
137 {
138     if (m_opaque_sp)
139         m_opaque_sp->SetAsyncExecution(b);
140 }
141 
142 void
143 SBDebugger::SkipLLDBInitFiles (bool b)
144 {
145     if (m_opaque_sp)
146         m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
147 }
148 
149 // Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
150 // trying to switch modes in the middle of a debugging session.
151 void
152 SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership)
153 {
154     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
155 
156     if (log)
157         log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(),
158                      fh, transfer_ownership);
159 
160     if (m_opaque_sp)
161         m_opaque_sp->SetInputFileHandle (fh, transfer_ownership);
162 }
163 
164 void
165 SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership)
166 {
167     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
168 
169 
170     if (log)
171         log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(),
172                      fh, transfer_ownership);
173 
174     if (m_opaque_sp)
175         m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership);
176 }
177 
178 void
179 SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership)
180 {
181     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
182 
183 
184     if (log)
185         log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(),
186                      fh, transfer_ownership);
187 
188     if (m_opaque_sp)
189         m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership);
190 }
191 
192 FILE *
193 SBDebugger::GetInputFileHandle ()
194 {
195     if (m_opaque_sp)
196         return m_opaque_sp->GetInputFileHandle();
197     return NULL;
198 }
199 
200 FILE *
201 SBDebugger::GetOutputFileHandle ()
202 {
203     if (m_opaque_sp)
204         return m_opaque_sp->GetOutputFileHandle();
205     return NULL;
206 }
207 
208 FILE *
209 SBDebugger::GetErrorFileHandle ()
210 {
211     if (m_opaque_sp)
212         return m_opaque_sp->GetErrorFileHandle();
213     return NULL;
214 }
215 
216 SBCommandInterpreter
217 SBDebugger::GetCommandInterpreter ()
218 {
219     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
220 
221     SBCommandInterpreter sb_interpreter;
222     if (m_opaque_sp)
223         sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter());
224 
225     if (log)
226         log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)",
227                      m_opaque_sp.get(), sb_interpreter.get());
228 
229     return sb_interpreter;
230 }
231 
232 void
233 SBDebugger::HandleCommand (const char *command)
234 {
235     if (m_opaque_sp)
236     {
237         TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
238         Mutex::Locker api_locker;
239         if (target_sp)
240             api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
241 
242         SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
243         SBCommandReturnObject result;
244 
245         sb_interpreter.HandleCommand (command, result, false);
246 
247         if (GetErrorFileHandle() != NULL)
248             result.PutError (GetErrorFileHandle());
249         if (GetOutputFileHandle() != NULL)
250             result.PutOutput (GetOutputFileHandle());
251 
252         if (m_opaque_sp->GetAsyncExecution() == false)
253         {
254             SBProcess process(GetCommandInterpreter().GetProcess ());
255             if (process.IsValid())
256             {
257                 EventSP event_sp;
258                 Listener &lldb_listener = m_opaque_sp->GetListener();
259                 while (lldb_listener.GetNextEventForBroadcaster (process.get(), event_sp))
260                 {
261                     SBEvent event(event_sp);
262                     HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
263                 }
264             }
265         }
266     }
267 }
268 
269 SBListener
270 SBDebugger::GetListener ()
271 {
272     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
273 
274     SBListener sb_listener;
275     if (m_opaque_sp)
276         sb_listener.reset(&m_opaque_sp->GetListener(), false);
277 
278     if (log)
279         log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)", m_opaque_sp.get(),
280                      sb_listener.get());
281 
282     return sb_listener;
283 }
284 
285 void
286 SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err)
287 {
288     if (!process.IsValid())
289         return;
290 
291     const uint32_t event_type = event.GetType();
292     char stdio_buffer[1024];
293     size_t len;
294 
295     Mutex::Locker api_locker (process.GetTarget()->GetAPIMutex());
296 
297     if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
298     {
299         // Drain stdout when we stop just in case we have any bytes
300         while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0)
301             if (out != NULL)
302                 ::fwrite (stdio_buffer, 1, len, out);
303     }
304 
305     if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged))
306     {
307         // Drain stderr when we stop just in case we have any bytes
308         while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0)
309             if (err != NULL)
310                 ::fwrite (stdio_buffer, 1, len, err);
311     }
312 
313     if (event_type & Process::eBroadcastBitStateChanged)
314     {
315         StateType event_state = SBProcess::GetStateFromEvent (event);
316 
317         if (event_state == eStateInvalid)
318             return;
319 
320         bool is_stopped = StateIsStoppedState (event_state);
321         if (!is_stopped)
322             process.ReportEventState (event, out);
323     }
324 }
325 
326 SBSourceManager &
327 SBDebugger::GetSourceManager ()
328 {
329     static SourceManager g_lldb_source_manager;
330     static SBSourceManager g_sb_source_manager (&g_lldb_source_manager);
331     return g_sb_source_manager;
332 }
333 
334 
335 bool
336 SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len)
337 {
338     if (arch_name && arch_name_len)
339     {
340         ArchSpec default_arch = lldb_private::Target::GetDefaultArchitecture ();
341 
342         if (default_arch.IsValid())
343         {
344             ::snprintf (arch_name, arch_name_len, "%s", default_arch.AsCString());
345             return true;
346         }
347     }
348     if (arch_name && arch_name_len)
349         arch_name[0] = '\0';
350     return false;
351 }
352 
353 
354 bool
355 SBDebugger::SetDefaultArchitecture (const char *arch_name)
356 {
357     if (arch_name)
358     {
359         ArchSpec arch (arch_name);
360         if (arch.IsValid())
361         {
362             lldb_private::Target::SetDefaultArchitecture (arch);
363             return true;
364         }
365     }
366     return false;
367 }
368 
369 ScriptLanguage
370 SBDebugger::GetScriptingLanguage (const char *script_language_name)
371 {
372 
373     return Args::StringToScriptLanguage (script_language_name,
374                                          eScriptLanguageDefault,
375                                          NULL);
376 }
377 
378 const char *
379 SBDebugger::GetVersionString ()
380 {
381     return lldb_private::GetVersion();
382 }
383 
384 const char *
385 SBDebugger::StateAsCString (lldb::StateType state)
386 {
387     return lldb_private::StateAsCString (state);
388 }
389 
390 bool
391 SBDebugger::StateIsRunningState (lldb::StateType state)
392 {
393     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
394 
395     const bool result = lldb_private::StateIsRunningState (state);
396     if (log)
397         log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i",
398                      lldb_private::StateAsCString (state), result);
399 
400     return result;
401 }
402 
403 bool
404 SBDebugger::StateIsStoppedState (lldb::StateType state)
405 {
406     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
407 
408     const bool result = lldb_private::StateIsStoppedState (state);
409     if (log)
410         log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i",
411                      lldb_private::StateAsCString (state), result);
412 
413     return result;
414 }
415 
416 
417 SBTarget
418 SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
419                                                  const char *target_triple)
420 {
421     SBTarget target;
422     if (m_opaque_sp)
423     {
424         ArchSpec arch;
425         FileSpec file_spec (filename, true);
426         arch.SetArchFromTargetTriple(target_triple);
427         TargetSP target_sp;
428         Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file_spec, arch, NULL, true, target_sp));
429         target.reset (target_sp);
430     }
431 
432     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
433     if (log)
434     {
435         log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)",
436                      m_opaque_sp.get(), filename, target_triple, target.get());
437     }
438 
439     return target;
440 }
441 
442 SBTarget
443 SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *archname)
444 {
445     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
446 
447     SBTarget target;
448     if (m_opaque_sp)
449     {
450         FileSpec file (filename, true);
451         ArchSpec arch = lldb_private::Target::GetDefaultArchitecture ();
452         TargetSP target_sp;
453         Error error;
454 
455         if (archname != NULL)
456         {
457             ArchSpec arch2 (archname);
458             error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch2, NULL, true, target_sp);
459         }
460         else
461         {
462             if (!arch.IsValid())
463                 arch = LLDB_ARCH_DEFAULT;
464 
465             error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch, NULL, true, target_sp);
466 
467             if (error.Fail())
468             {
469                 if (arch == LLDB_ARCH_DEFAULT_32BIT)
470                     arch = LLDB_ARCH_DEFAULT_64BIT;
471                 else
472                     arch = LLDB_ARCH_DEFAULT_32BIT;
473 
474                 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch, NULL, true, target_sp);
475             }
476         }
477 
478         if (error.Success())
479         {
480             m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
481             target.reset(target_sp);
482         }
483     }
484 
485     if (log)
486     {
487         log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)",
488                      m_opaque_sp.get(), filename, archname, target.get());
489     }
490 
491     return target;
492 }
493 
494 SBTarget
495 SBDebugger::CreateTarget (const char *filename)
496 {
497     SBTarget target;
498     if (m_opaque_sp)
499     {
500         FileSpec file (filename, true);
501         ArchSpec arch = lldb_private::Target::GetDefaultArchitecture ();
502         TargetSP target_sp;
503         Error error;
504 
505         if (!arch.IsValid())
506             arch = LLDB_ARCH_DEFAULT;
507 
508         error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch, NULL, true, target_sp);
509 
510         if (error.Fail())
511         {
512             if (arch == LLDB_ARCH_DEFAULT_32BIT)
513                 arch = LLDB_ARCH_DEFAULT_64BIT;
514             else
515                 arch = LLDB_ARCH_DEFAULT_32BIT;
516 
517             error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, file, arch, NULL, true, target_sp);
518         }
519 
520         if (error.Success())
521         {
522             m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
523             target.reset (target_sp);
524         }
525     }
526     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
527     if (log)
528     {
529         log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
530                      m_opaque_sp.get(), filename, target.get());
531     }
532     return target;
533 }
534 
535 SBTarget
536 SBDebugger::GetTargetAtIndex (uint32_t idx)
537 {
538     SBTarget sb_target;
539     if (m_opaque_sp)
540     {
541         // No need to lock, the target list is thread safe
542         sb_target.reset(m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
543     }
544     return sb_target;
545 }
546 
547 SBTarget
548 SBDebugger::FindTargetWithProcessID (pid_t pid)
549 {
550     SBTarget sb_target;
551     if (m_opaque_sp)
552     {
553         // No need to lock, the target list is thread safe
554         sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
555     }
556     return sb_target;
557 }
558 
559 SBTarget
560 SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name)
561 {
562     SBTarget sb_target;
563     if (m_opaque_sp && filename && filename[0])
564     {
565         // No need to lock, the target list is thread safe
566         ArchSpec arch;
567         if (arch_name)
568             arch.SetArch(arch_name);
569         TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
570         sb_target.reset(target_sp);
571     }
572     return sb_target;
573 }
574 
575 SBTarget
576 SBDebugger::FindTargetWithLLDBProcess (const lldb::ProcessSP &process_sp)
577 {
578     SBTarget sb_target;
579     if (m_opaque_sp)
580     {
581         // No need to lock, the target list is thread safe
582         sb_target.reset(m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
583     }
584     return sb_target;
585 }
586 
587 
588 uint32_t
589 SBDebugger::GetNumTargets ()
590 {
591     if (m_opaque_sp)
592     {
593         // No need to lock, the target list is thread safe
594         return m_opaque_sp->GetTargetList().GetNumTargets ();
595     }
596     return 0;
597 }
598 
599 SBTarget
600 SBDebugger::GetSelectedTarget ()
601 {
602     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
603 
604     SBTarget sb_target;
605     if (m_opaque_sp)
606     {
607         // No need to lock, the target list is thread safe
608         sb_target.reset(m_opaque_sp->GetTargetList().GetSelectedTarget ());
609     }
610 
611     if (log)
612     {
613         SBStream sstr;
614         sb_target.GetDescription (sstr, lldb::eDescriptionLevelBrief);
615         log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(),
616                      sb_target.get(), sstr.GetData());
617     }
618 
619     return sb_target;
620 }
621 
622 void
623 SBDebugger::DispatchInput (void *baton, const void *data, size_t data_len)
624 {
625     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
626 
627     if (log)
628         log->Printf ("SBDebugger(%p)::DispatchInput (baton=%p, data=\"%.*s\", size_t=%zu)", m_opaque_sp.get(),
629                      baton, (int) data_len, (const char *) data, data_len);
630 
631     if (m_opaque_sp)
632         m_opaque_sp->DispatchInput ((const char *) data, data_len);
633 }
634 
635 void
636 SBDebugger::DispatchInputInterrupt ()
637 {
638     if (m_opaque_sp)
639         m_opaque_sp->DispatchInputInterrupt ();
640 }
641 
642 void
643 SBDebugger::DispatchInputEndOfFile ()
644 {
645     if (m_opaque_sp)
646         m_opaque_sp->DispatchInputEndOfFile ();
647 }
648 
649 void
650 SBDebugger::PushInputReader (SBInputReader &reader)
651 {
652     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
653 
654     if (log)
655         log->Printf ("SBDebugger(%p)::PushInputReader (SBInputReader(%p))", m_opaque_sp.get(), &reader);
656 
657     if (m_opaque_sp && reader.IsValid())
658     {
659         TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
660         Mutex::Locker api_locker;
661         if (target_sp)
662             api_locker.Reset(target_sp->GetAPIMutex().GetMutex());
663         InputReaderSP reader_sp(*reader);
664         m_opaque_sp->PushInputReader (reader_sp);
665     }
666 }
667 
668 void
669 SBDebugger::reset (const lldb::DebuggerSP &debugger_sp)
670 {
671     m_opaque_sp = debugger_sp;
672 }
673 
674 Debugger *
675 SBDebugger::get () const
676 {
677     return m_opaque_sp.get();
678 }
679 
680 Debugger &
681 SBDebugger::ref () const
682 {
683     assert (m_opaque_sp.get());
684     return *m_opaque_sp;
685 }
686 
687 
688 SBDebugger
689 SBDebugger::FindDebuggerWithID (int id)
690 {
691     // No need to lock, the debugger list is thread safe
692     SBDebugger sb_debugger;
693     lldb::DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
694     if (debugger_sp)
695         sb_debugger.reset (debugger_sp);
696     return sb_debugger;
697 }
698 
699 const char *
700 SBDebugger::GetInstanceName()
701 {
702     if (m_opaque_sp)
703         return m_opaque_sp->GetInstanceName().AsCString();
704     else
705         return NULL;
706 }
707 
708 SBError
709 SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name)
710 {
711     lldb::UserSettingsControllerSP root_settings_controller = lldb_private::Debugger::GetSettingsController();
712 
713     Error err = root_settings_controller->SetVariable (var_name, value, lldb::eVarSetOperationAssign, true,
714                                                        debugger_instance_name);
715     SBError sb_error;
716     sb_error.SetError (err);
717 
718     return sb_error;
719 }
720 
721 lldb::SBStringList
722 SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name)
723 {
724     SBStringList ret_value;
725     lldb::SettableVariableType var_type;
726     lldb_private::Error err;
727 
728     lldb::UserSettingsControllerSP root_settings_controller = lldb_private::Debugger::GetSettingsController();
729 
730     StringList value = root_settings_controller->GetVariable (var_name, var_type, debugger_instance_name, err);
731 
732     if (err.Success())
733     {
734         for (unsigned i = 0; i != value.GetSize(); ++i)
735             ret_value.AppendString (value.GetStringAtIndex(i));
736     }
737     else
738     {
739         ret_value.AppendString (err.AsCString());
740     }
741 
742 
743     return ret_value;
744 }
745 
746 uint32_t
747 SBDebugger::GetTerminalWidth () const
748 {
749     if (m_opaque_sp)
750         return m_opaque_sp->GetTerminalWidth ();
751     return 0;
752 }
753 
754 void
755 SBDebugger::SetTerminalWidth (uint32_t term_width)
756 {
757     if (m_opaque_sp)
758         m_opaque_sp->SetTerminalWidth (term_width);
759 }
760 
761 const char *
762 SBDebugger::GetPrompt() const
763 {
764     LogSP log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
765 
766     if (log)
767         log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"", m_opaque_sp.get(),
768                      (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
769 
770     if (m_opaque_sp)
771         return m_opaque_sp->GetPrompt ();
772     return 0;
773 }
774 
775 void
776 SBDebugger::SetPrompt (const char *prompt)
777 {
778     if (m_opaque_sp)
779         m_opaque_sp->SetPrompt (prompt);
780 }
781 
782 
783 lldb::ScriptLanguage
784 SBDebugger::GetScriptLanguage() const
785 {
786     if (m_opaque_sp)
787         return m_opaque_sp->GetScriptLanguage ();
788     return eScriptLanguageNone;
789 }
790 
791 void
792 SBDebugger::SetScriptLanguage (lldb::ScriptLanguage script_lang)
793 {
794     if (m_opaque_sp)
795     {
796         m_opaque_sp->SetScriptLanguage (script_lang);
797     }
798 }
799 
800 bool
801 SBDebugger::SetUseExternalEditor (bool value)
802 {
803     if (m_opaque_sp)
804         return m_opaque_sp->SetUseExternalEditor (value);
805     return false;
806 }
807 
808 bool
809 SBDebugger::GetUseExternalEditor ()
810 {
811     if (m_opaque_sp)
812         return m_opaque_sp->GetUseExternalEditor ();
813     return false;
814 }
815 
816 bool
817 SBDebugger::GetDescription (SBStream &description)
818 {
819     if (m_opaque_sp)
820     {
821         const char *name = m_opaque_sp->GetInstanceName().AsCString();
822         lldb::user_id_t id = m_opaque_sp->GetID();
823         description.Printf ("Debugger (instance: \"%s\", id: %d)", name, id);
824     }
825     else
826         description.Printf ("No value");
827 
828     return true;
829 }
830 
831 lldb::user_id_t
832 SBDebugger::GetID()
833 {
834     if (m_opaque_sp)
835         return m_opaque_sp->GetID();
836     return LLDB_INVALID_UID;
837 }
838