1 //===-- SBDebugger.cpp ------------------------------------------*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "lldb/lldb-python.h"
12 #include "lldb/API/SBDebugger.h"
14 #include "lldb/lldb-private.h"
16 #include "lldb/API/SBListener.h"
17 #include "lldb/API/SBBroadcaster.h"
18 #include "lldb/API/SBCommandInterpreter.h"
19 #include "lldb/API/SBCommandReturnObject.h"
20 #include "lldb/API/SBError.h"
21 #include "lldb/API/SBEvent.h"
22 #include "lldb/API/SBFrame.h"
23 #include "lldb/API/SBProcess.h"
24 #include "lldb/API/SBSourceManager.h"
25 #include "lldb/API/SBStream.h"
26 #include "lldb/API/SBStringList.h"
27 #include "lldb/API/SBTarget.h"
28 #include "lldb/API/SBThread.h"
29 #include "lldb/API/SBTypeCategory.h"
30 #include "lldb/API/SBTypeFormat.h"
31 #include "lldb/API/SBTypeFilter.h"
32 #include "lldb/API/SBTypeNameSpecifier.h"
33 #include "lldb/API/SBTypeSummary.h"
34 #include "lldb/API/SBTypeSynthetic.h"
37 #include "lldb/Core/Debugger.h"
38 #include "lldb/Core/State.h"
39 #include "lldb/Core/StreamFile.h"
40 #include "lldb/DataFormatters/DataVisualization.h"
41 #include "lldb/Interpreter/Args.h"
42 #include "lldb/Interpreter/CommandInterpreter.h"
43 #include "lldb/Interpreter/OptionGroupPlatform.h"
44 #include "lldb/Target/Process.h"
45 #include "lldb/Target/TargetList.h"
47 #include "llvm/Support/DynamicLibrary.h"
50 using namespace lldb_private;
53 SBInputReader::SBInputReader()
56 SBInputReader::~SBInputReader()
61 SBInputReader::Initialize(lldb::SBDebugger& sb_debugger, unsigned long (*)(void*, lldb::SBInputReader*, lldb::InputReaderAction, char const*, unsigned long), void*, lldb::InputReaderGranularity, char const*, char const*, bool)
67 SBInputReader::SetIsDone(bool)
71 SBInputReader::IsActive() const
76 static llvm::sys::DynamicLibrary
77 LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
79 llvm::sys::DynamicLibrary dynlib = llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str());
82 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
84 lldb::SBDebugger debugger_sb(debugger_sp);
85 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
86 // TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
87 LLDBCommandPluginInit init_func = (LLDBCommandPluginInit)dynlib.getAddressOfSymbol("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
90 if (init_func(debugger_sb))
93 error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)");
97 error.SetErrorString("plug-in is missing the required initialization: lldb::PluginInitialize(lldb::SBDebugger)");
103 error.SetErrorString("this file does not represent a loadable dylib");
105 error.SetErrorString("no such file");
107 return llvm::sys::DynamicLibrary();
111 SBDebugger::Initialize ()
113 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
116 log->Printf ("SBDebugger::Initialize ()");
118 SBCommandInterpreter::InitializeSWIG ();
120 Debugger::Initialize(LoadPlugin);
124 SBDebugger::Terminate ()
126 Debugger::Terminate();
132 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
135 log->Printf ("SBDebugger(%p)::Clear ()",
136 static_cast<void*>(m_opaque_sp.get()));
139 m_opaque_sp->ClearIOHandlers ();
147 return SBDebugger::Create(false, NULL, NULL);
151 SBDebugger::Create(bool source_init_files)
153 return SBDebugger::Create (source_init_files, NULL, NULL);
157 SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton)
160 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
164 // Currently we have issues if this function is called simultaneously on two different
165 // threads. The issues mainly revolve around the fact that the lldb_private::FormatManager
166 // uses global collections and having two threads parsing the .lldbinit files can cause
167 // mayhem. So to get around this for now we need to use a mutex to prevent bad things
169 static Mutex g_mutex(Mutex::eMutexTypeRecursive);
170 Mutex::Locker locker(g_mutex);
172 debugger.reset(Debugger::CreateInstance(callback, baton));
177 debugger.GetDescription (sstr);
178 log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s",
179 static_cast<void*>(debugger.m_opaque_sp.get()),
183 SBCommandInterpreter interp = debugger.GetCommandInterpreter();
184 if (source_init_files)
186 interp.get()->SkipLLDBInitFiles(false);
187 interp.get()->SkipAppInitFiles (false);
188 SBCommandReturnObject result;
189 interp.SourceInitFileInHomeDirectory(result);
193 interp.get()->SkipLLDBInitFiles(true);
194 interp.get()->SkipAppInitFiles (true);
200 SBDebugger::Destroy (SBDebugger &debugger)
202 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
207 debugger.GetDescription (sstr);
208 log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s",
209 static_cast<void*>(debugger.m_opaque_sp.get()),
213 Debugger::Destroy (debugger.m_opaque_sp);
215 if (debugger.m_opaque_sp.get() != NULL)
216 debugger.m_opaque_sp.reset();
220 SBDebugger::MemoryPressureDetected ()
222 // Since this function can be call asynchronously, we allow it to be
223 // non-mandatory. We have seen deadlocks with this function when called
224 // so we need to safeguard against this until we can determine what is
225 // causing the deadlocks.
226 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
228 const bool mandatory = false;
231 log->Printf ("SBDebugger::MemoryPressureDetected (), mandatory = %d", mandatory);
234 ModuleList::RemoveOrphanSharedModules(mandatory);
237 SBDebugger::SBDebugger () :
242 SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) :
243 m_opaque_sp(debugger_sp)
247 SBDebugger::SBDebugger(const SBDebugger &rhs) :
248 m_opaque_sp (rhs.m_opaque_sp)
253 SBDebugger::operator = (const SBDebugger &rhs)
257 m_opaque_sp = rhs.m_opaque_sp;
262 SBDebugger::~SBDebugger ()
267 SBDebugger::IsValid() const
269 return m_opaque_sp.get() != NULL;
274 SBDebugger::SetAsync (bool b)
277 m_opaque_sp->SetAsyncExecution(b);
281 SBDebugger::GetAsync ()
284 return m_opaque_sp->GetAsyncExecution();
290 SBDebugger::SkipLLDBInitFiles (bool b)
293 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
297 SBDebugger::SkipAppInitFiles (bool b)
300 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles (b);
303 // Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
304 // trying to switch modes in the middle of a debugging session.
306 SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership)
308 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
311 log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)",
312 static_cast<void*>(m_opaque_sp.get()),
313 static_cast<void*>(fh), transfer_ownership);
316 m_opaque_sp->SetInputFileHandle (fh, transfer_ownership);
320 SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership)
322 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
326 log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)",
327 static_cast<void*>(m_opaque_sp.get()),
328 static_cast<void*>(fh), transfer_ownership);
331 m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership);
335 SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership)
337 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
341 log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)",
342 static_cast<void*>(m_opaque_sp.get()),
343 static_cast<void*>(fh), transfer_ownership);
346 m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership);
350 SBDebugger::GetInputFileHandle ()
354 StreamFileSP stream_file_sp (m_opaque_sp->GetInputFile());
356 return stream_file_sp->GetFile().GetStream();
362 SBDebugger::GetOutputFileHandle ()
366 StreamFileSP stream_file_sp (m_opaque_sp->GetOutputFile());
368 return stream_file_sp->GetFile().GetStream();
374 SBDebugger::GetErrorFileHandle ()
379 StreamFileSP stream_file_sp (m_opaque_sp->GetErrorFile());
381 return stream_file_sp->GetFile().GetStream();
387 SBDebugger::SaveInputTerminalState()
390 m_opaque_sp->SaveInputTerminalState();
394 SBDebugger::RestoreInputTerminalState()
397 m_opaque_sp->RestoreInputTerminalState();
401 SBDebugger::GetCommandInterpreter ()
403 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
405 SBCommandInterpreter sb_interpreter;
407 sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter());
410 log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)",
411 static_cast<void*>(m_opaque_sp.get()),
412 static_cast<void*>(sb_interpreter.get()));
414 return sb_interpreter;
418 SBDebugger::HandleCommand (const char *command)
422 TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
423 Mutex::Locker api_locker;
425 api_locker.Lock(target_sp->GetAPIMutex());
427 SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
428 SBCommandReturnObject result;
430 sb_interpreter.HandleCommand (command, result, false);
432 if (GetErrorFileHandle() != NULL)
433 result.PutError (GetErrorFileHandle());
434 if (GetOutputFileHandle() != NULL)
435 result.PutOutput (GetOutputFileHandle());
437 if (m_opaque_sp->GetAsyncExecution() == false)
439 SBProcess process(GetCommandInterpreter().GetProcess ());
440 ProcessSP process_sp (process.GetSP());
444 Listener &lldb_listener = m_opaque_sp->GetListener();
445 while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp))
447 SBEvent event(event_sp);
448 HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
456 SBDebugger::GetListener ()
458 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
460 SBListener sb_listener;
462 sb_listener.reset(&m_opaque_sp->GetListener(), false);
465 log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)",
466 static_cast<void*>(m_opaque_sp.get()),
467 static_cast<void*>(sb_listener.get()));
473 SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err)
475 if (!process.IsValid())
478 TargetSP target_sp (process.GetTarget().GetSP());
482 const uint32_t event_type = event.GetType();
483 char stdio_buffer[1024];
486 Mutex::Locker api_locker (target_sp->GetAPIMutex());
488 if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
490 // Drain stdout when we stop just in case we have any bytes
491 while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0)
493 ::fwrite (stdio_buffer, 1, len, out);
496 if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged))
498 // Drain stderr when we stop just in case we have any bytes
499 while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0)
501 ::fwrite (stdio_buffer, 1, len, err);
504 if (event_type & Process::eBroadcastBitStateChanged)
506 StateType event_state = SBProcess::GetStateFromEvent (event);
508 if (event_state == eStateInvalid)
511 bool is_stopped = StateIsStoppedState (event_state);
513 process.ReportEventState (event, out);
518 SBDebugger::GetSourceManager ()
520 SBSourceManager sb_source_manager (*this);
521 return sb_source_manager;
526 SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len)
528 if (arch_name && arch_name_len)
530 ArchSpec default_arch = Target::GetDefaultArchitecture ();
532 if (default_arch.IsValid())
534 const std::string &triple_str = default_arch.GetTriple().str();
535 if (!triple_str.empty())
536 ::snprintf (arch_name, arch_name_len, "%s", triple_str.c_str());
538 ::snprintf (arch_name, arch_name_len, "%s", default_arch.GetArchitectureName());
542 if (arch_name && arch_name_len)
549 SBDebugger::SetDefaultArchitecture (const char *arch_name)
553 ArchSpec arch (arch_name);
556 Target::SetDefaultArchitecture (arch);
564 SBDebugger::GetScriptingLanguage (const char *script_language_name)
567 return Args::StringToScriptLanguage (script_language_name,
568 eScriptLanguageDefault,
573 SBDebugger::GetVersionString ()
575 return lldb_private::GetVersion();
579 SBDebugger::StateAsCString (StateType state)
581 return lldb_private::StateAsCString (state);
585 SBDebugger::StateIsRunningState (StateType state)
587 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
589 const bool result = lldb_private::StateIsRunningState (state);
591 log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i",
592 StateAsCString (state), result);
598 SBDebugger::StateIsStoppedState (StateType state)
600 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
602 const bool result = lldb_private::StateIsStoppedState (state, false);
604 log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i",
605 StateAsCString (state), result);
611 SBDebugger::CreateTarget (const char *filename,
612 const char *target_triple,
613 const char *platform_name,
614 bool add_dependent_modules,
615 lldb::SBError& sb_error)
622 OptionGroupPlatform platform_options (false);
623 platform_options.SetPlatformName (platform_name);
625 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
628 add_dependent_modules,
632 if (sb_error.Success())
633 sb_target.SetSP (target_sp);
637 sb_error.SetErrorString("invalid target");
640 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
642 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)",
643 static_cast<void*>(m_opaque_sp.get()), filename,
644 target_triple, platform_name, add_dependent_modules,
645 sb_error.GetCString(), static_cast<void*>(target_sp.get()));
651 SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
652 const char *target_triple)
658 const bool add_dependent_modules = true;
659 Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
662 add_dependent_modules,
665 sb_target.SetSP (target_sp);
668 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
670 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)",
671 static_cast<void*>(m_opaque_sp.get()), filename,
672 target_triple, static_cast<void*>(target_sp.get()));
678 SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_cstr)
680 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
687 const bool add_dependent_modules = true;
689 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
692 add_dependent_modules,
698 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
699 sb_target.SetSP (target_sp);
704 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)",
705 static_cast<void*>(m_opaque_sp.get()), filename, arch_cstr,
706 static_cast<void*>(target_sp.get()));
712 SBDebugger::CreateTarget (const char *filename)
719 const bool add_dependent_modules = true;
720 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
723 add_dependent_modules,
729 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
730 sb_target.SetSP (target_sp);
733 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
735 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
736 static_cast<void*>(m_opaque_sp.get()), filename,
737 static_cast<void*>(target_sp.get()));
742 SBDebugger::DeleteTarget (lldb::SBTarget &target)
747 TargetSP target_sp(target.GetSP());
750 // No need to lock, the target list is thread safe
751 result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
752 target_sp->Destroy();
754 const bool mandatory = true;
755 ModuleList::RemoveOrphanSharedModules(mandatory);
759 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
761 log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i",
762 static_cast<void*>(m_opaque_sp.get()),
763 static_cast<void*>(target.m_opaque_sp.get()), result);
768 SBDebugger::GetTargetAtIndex (uint32_t idx)
773 // No need to lock, the target list is thread safe
774 sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
780 SBDebugger::GetIndexOfTarget (lldb::SBTarget target)
783 lldb::TargetSP target_sp = target.GetSP();
790 return m_opaque_sp->GetTargetList().GetIndexOfTarget (target.GetSP());
794 SBDebugger::FindTargetWithProcessID (lldb::pid_t pid)
799 // No need to lock, the target list is thread safe
800 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
806 SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name)
809 if (m_opaque_sp && filename && filename[0])
811 // No need to lock, the target list is thread safe
812 ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
813 TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
814 sb_target.SetSP (target_sp);
820 SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp)
825 // No need to lock, the target list is thread safe
826 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
833 SBDebugger::GetNumTargets ()
837 // No need to lock, the target list is thread safe
838 return m_opaque_sp->GetTargetList().GetNumTargets ();
844 SBDebugger::GetSelectedTarget ()
846 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
852 // No need to lock, the target list is thread safe
853 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget ();
854 sb_target.SetSP (target_sp);
860 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
861 log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s",
862 static_cast<void*>(m_opaque_sp.get()),
863 static_cast<void*>(target_sp.get()), sstr.GetData());
870 SBDebugger::SetSelectedTarget (SBTarget &sb_target)
872 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
874 TargetSP target_sp (sb_target.GetSP());
877 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
882 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
883 log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s",
884 static_cast<void*>(m_opaque_sp.get()),
885 static_cast<void*>(target_sp.get()), sstr.GetData());
890 SBDebugger::GetSelectedPlatform()
892 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
894 SBPlatform sb_platform;
895 DebuggerSP debugger_sp(m_opaque_sp);
898 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
901 log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s",
902 static_cast<void*>(m_opaque_sp.get()),
903 static_cast<void*>(sb_platform.GetSP().get()),
904 sb_platform.GetName());
909 SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform)
911 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
913 DebuggerSP debugger_sp(m_opaque_sp);
916 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
920 log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)",
921 static_cast<void*>(m_opaque_sp.get()),
922 static_cast<void*>(sb_platform.GetSP().get()),
923 sb_platform.GetName());
927 SBDebugger::DispatchInput (void* baton, const void *data, size_t data_len)
929 DispatchInput (data,data_len);
933 SBDebugger::DispatchInput (const void *data, size_t data_len)
935 // Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
938 // log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
939 // m_opaque_sp.get(),
941 // (const char *) data,
942 // (uint64_t)data_len);
945 // m_opaque_sp->DispatchInput ((const char *) data, data_len);
949 SBDebugger::DispatchInputInterrupt ()
952 m_opaque_sp->DispatchInputInterrupt ();
956 SBDebugger::DispatchInputEndOfFile ()
959 m_opaque_sp->DispatchInputEndOfFile ();
963 SBDebugger::PushInputReader (SBInputReader &reader)
968 SBDebugger::RunCommandInterpreter (bool auto_handle_events,
973 CommandInterpreterRunOptions options;
975 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events,
982 SBDebugger::RunCommandInterpreter (bool auto_handle_events,
984 SBCommandInterpreterRunOptions &options,
986 bool &quit_requested,
987 bool &stopped_for_crash)
992 CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter();
993 interp.RunCommandInterpreter(auto_handle_events, spawn_thread, options.ref());
994 num_errors = interp.GetNumErrors();
995 quit_requested = interp.GetQuitRequested();
996 stopped_for_crash = interp.GetStoppedForCrash();
1001 SBDebugger::reset (const DebuggerSP &debugger_sp)
1003 m_opaque_sp = debugger_sp;
1007 SBDebugger::get () const
1009 return m_opaque_sp.get();
1013 SBDebugger::ref () const
1015 assert (m_opaque_sp.get());
1016 return *m_opaque_sp;
1019 const lldb::DebuggerSP &
1020 SBDebugger::get_sp () const
1026 SBDebugger::FindDebuggerWithID (int id)
1028 // No need to lock, the debugger list is thread safe
1029 SBDebugger sb_debugger;
1030 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
1032 sb_debugger.reset (debugger_sp);
1037 SBDebugger::GetInstanceName()
1040 return m_opaque_sp->GetInstanceName().AsCString();
1046 SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name)
1049 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1053 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1054 error = debugger_sp->SetPropertyValue (&exe_ctx,
1055 eVarSetOperationAssign,
1061 error.SetErrorStringWithFormat ("invalid debugger instance name '%s'", debugger_instance_name);
1064 sb_error.SetError(error);
1069 SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name)
1071 SBStringList ret_value;
1072 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1076 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1077 lldb::OptionValueSP value_sp (debugger_sp->GetPropertyValue (&exe_ctx,
1083 StreamString value_strm;
1084 value_sp->DumpValue (&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1085 const std::string &value_str = value_strm.GetString();
1086 if (!value_str.empty())
1088 StringList string_list;
1089 string_list.SplitIntoLines(value_str);
1090 return SBStringList(&string_list);
1094 return SBStringList();
1098 SBDebugger::GetTerminalWidth () const
1101 return m_opaque_sp->GetTerminalWidth ();
1106 SBDebugger::SetTerminalWidth (uint32_t term_width)
1109 m_opaque_sp->SetTerminalWidth (term_width);
1113 SBDebugger::GetPrompt() const
1115 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1118 log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"",
1119 static_cast<void*>(m_opaque_sp.get()),
1120 (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
1123 return m_opaque_sp->GetPrompt ();
1128 SBDebugger::SetPrompt (const char *prompt)
1131 m_opaque_sp->SetPrompt (prompt);
1136 SBDebugger::GetScriptLanguage() const
1139 return m_opaque_sp->GetScriptLanguage ();
1140 return eScriptLanguageNone;
1144 SBDebugger::SetScriptLanguage (ScriptLanguage script_lang)
1148 m_opaque_sp->SetScriptLanguage (script_lang);
1153 SBDebugger::SetUseExternalEditor (bool value)
1156 return m_opaque_sp->SetUseExternalEditor (value);
1161 SBDebugger::GetUseExternalEditor ()
1164 return m_opaque_sp->GetUseExternalEditor ();
1169 SBDebugger::SetUseColor (bool value)
1172 return m_opaque_sp->SetUseColor (value);
1177 SBDebugger::GetUseColor () const
1180 return m_opaque_sp->GetUseColor ();
1185 SBDebugger::GetDescription (SBStream &description)
1187 Stream &strm = description.ref();
1191 const char *name = m_opaque_sp->GetInstanceName().AsCString();
1192 user_id_t id = m_opaque_sp->GetID();
1193 strm.Printf ("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
1196 strm.PutCString ("No value");
1205 return m_opaque_sp->GetID();
1206 return LLDB_INVALID_UID;
1211 SBDebugger::SetCurrentPlatform (const char *platform_name_cstr)
1216 if (platform_name_cstr && platform_name_cstr[0])
1218 ConstString platform_name (platform_name_cstr);
1219 PlatformSP platform_sp (Platform::Find (platform_name));
1223 // Already have a platform with this name, just select it
1224 m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp);
1228 // We don't have a platform by this name yet, create one
1229 platform_sp = Platform::Create (platform_name, sb_error.ref());
1232 // We created the platform, now append and select it
1233 bool make_selected = true;
1234 m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
1240 sb_error.ref().SetErrorString("invalid platform name");
1245 sb_error.ref().SetErrorString("invalid debugger");
1251 SBDebugger::SetCurrentPlatformSDKRoot (const char *sysroot)
1255 PlatformSP platform_sp (m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1259 platform_sp->SetSDKRootDirectory (ConstString (sysroot));
1267 SBDebugger::GetCloseInputOnEOF () const
1270 return m_opaque_sp->GetCloseInputOnEOF ();
1275 SBDebugger::SetCloseInputOnEOF (bool b)
1278 m_opaque_sp->SetCloseInputOnEOF (b);
1282 SBDebugger::GetCategory (const char* category_name)
1284 if (!category_name || *category_name == 0)
1285 return SBTypeCategory();
1287 TypeCategoryImplSP category_sp;
1289 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, false))
1290 return SBTypeCategory(category_sp);
1292 return SBTypeCategory();
1296 SBDebugger::CreateCategory (const char* category_name)
1298 if (!category_name || *category_name == 0)
1299 return SBTypeCategory();
1301 TypeCategoryImplSP category_sp;
1303 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, true))
1304 return SBTypeCategory(category_sp);
1306 return SBTypeCategory();
1310 SBDebugger::DeleteCategory (const char* category_name)
1312 if (!category_name || *category_name == 0)
1315 return DataVisualization::Categories::Delete(ConstString(category_name));
1319 SBDebugger::GetNumCategories()
1321 return DataVisualization::Categories::GetCount();
1325 SBDebugger::GetCategoryAtIndex (uint32_t index)
1327 return SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index));
1331 SBDebugger::GetDefaultCategory()
1333 return GetCategory("default");
1337 SBDebugger::GetFormatForType (SBTypeNameSpecifier type_name)
1339 SBTypeCategory default_category_sb = GetDefaultCategory();
1340 if (default_category_sb.GetEnabled())
1341 return default_category_sb.GetFormatForType(type_name);
1342 return SBTypeFormat();
1345 #ifndef LLDB_DISABLE_PYTHON
1347 SBDebugger::GetSummaryForType (SBTypeNameSpecifier type_name)
1349 if (type_name.IsValid() == false)
1350 return SBTypeSummary();
1351 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));
1353 #endif // LLDB_DISABLE_PYTHON
1356 SBDebugger::GetFilterForType (SBTypeNameSpecifier type_name)
1358 if (type_name.IsValid() == false)
1359 return SBTypeFilter();
1360 return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));
1363 #ifndef LLDB_DISABLE_PYTHON
1365 SBDebugger::GetSyntheticForType (SBTypeNameSpecifier type_name)
1367 if (type_name.IsValid() == false)
1368 return SBTypeSynthetic();
1369 return SBTypeSynthetic(DataVisualization::GetSyntheticForType(type_name.GetSP()));
1371 #endif // LLDB_DISABLE_PYTHON
1374 SBDebugger::EnableLog (const char *channel, const char **categories)
1378 uint32_t log_options = LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1379 StreamString errors;
1380 return m_opaque_sp->EnableLog (channel, categories, NULL, log_options, errors);
1388 SBDebugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1392 return m_opaque_sp->SetLoggingCallback (log_callback, baton);