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/Host/DynamicLibrary.h"
42 #include "lldb/Interpreter/Args.h"
43 #include "lldb/Interpreter/CommandInterpreter.h"
44 #include "lldb/Interpreter/OptionGroupPlatform.h"
45 #include "lldb/Target/Process.h"
46 #include "lldb/Target/TargetList.h"
49 using namespace lldb_private;
52 SBInputReader::SBInputReader()
55 SBInputReader::~SBInputReader()
60 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)
66 SBInputReader::SetIsDone(bool)
70 SBInputReader::IsActive() const
75 static lldb::DynamicLibrarySP
76 LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error)
78 lldb::DynamicLibrarySP dynlib_sp(new lldb_private::DynamicLibrary(spec));
79 if (dynlib_sp && dynlib_sp->IsValid())
81 typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger);
83 lldb::SBDebugger debugger_sb(debugger_sp);
84 // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function.
85 // TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays
86 LLDBCommandPluginInit init_func = dynlib_sp->GetSymbol<LLDBCommandPluginInit>("_ZN4lldb16PluginInitializeENS_10SBDebuggerE");
89 if (init_func(debugger_sb))
92 error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)");
96 error.SetErrorString("plug-in is missing the required initialization: lldb::PluginInitialize(lldb::SBDebugger)");
102 error.SetErrorString("this file does not represent a loadable dylib");
104 error.SetErrorString("no such file");
106 return lldb::DynamicLibrarySP();
110 SBDebugger::Initialize ()
112 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
115 log->Printf ("SBDebugger::Initialize ()");
117 SBCommandInterpreter::InitializeSWIG ();
119 Debugger::Initialize(LoadPlugin);
123 SBDebugger::Terminate ()
125 Debugger::Terminate();
131 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
134 log->Printf ("SBDebugger(%p)::Clear ()", m_opaque_sp.get());
137 m_opaque_sp->ClearIOHandlers ();
145 return SBDebugger::Create(false, NULL, NULL);
149 SBDebugger::Create(bool source_init_files)
151 return SBDebugger::Create (source_init_files, NULL, NULL);
155 SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, void *baton)
158 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
161 debugger.reset(Debugger::CreateInstance(callback, baton));
166 debugger.GetDescription (sstr);
167 log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData());
170 SBCommandInterpreter interp = debugger.GetCommandInterpreter();
171 if (source_init_files)
173 interp.get()->SkipLLDBInitFiles(false);
174 interp.get()->SkipAppInitFiles (false);
175 SBCommandReturnObject result;
176 interp.SourceInitFileInHomeDirectory(result);
180 interp.get()->SkipLLDBInitFiles(true);
181 interp.get()->SkipAppInitFiles (true);
187 SBDebugger::Destroy (SBDebugger &debugger)
189 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
194 debugger.GetDescription (sstr);
195 log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData());
198 Debugger::Destroy (debugger.m_opaque_sp);
200 if (debugger.m_opaque_sp.get() != NULL)
201 debugger.m_opaque_sp.reset();
205 SBDebugger::MemoryPressureDetected ()
207 // Since this function can be call asynchronously, we allow it to be
208 // non-mandatory. We have seen deadlocks with this function when called
209 // so we need to safeguard against this until we can determine what is
210 // causing the deadlocks.
211 Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
213 const bool mandatory = false;
216 log->Printf ("SBDebugger::MemoryPressureDetected (), mandatory = %d", mandatory);
219 ModuleList::RemoveOrphanSharedModules(mandatory);
222 SBDebugger::SBDebugger () :
227 SBDebugger::SBDebugger(const lldb::DebuggerSP &debugger_sp) :
228 m_opaque_sp(debugger_sp)
232 SBDebugger::SBDebugger(const SBDebugger &rhs) :
233 m_opaque_sp (rhs.m_opaque_sp)
238 SBDebugger::operator = (const SBDebugger &rhs)
242 m_opaque_sp = rhs.m_opaque_sp;
247 SBDebugger::~SBDebugger ()
252 SBDebugger::IsValid() const
254 return m_opaque_sp.get() != NULL;
259 SBDebugger::SetAsync (bool b)
262 m_opaque_sp->SetAsyncExecution(b);
266 SBDebugger::GetAsync ()
269 return m_opaque_sp->GetAsyncExecution();
275 SBDebugger::SkipLLDBInitFiles (bool b)
278 m_opaque_sp->GetCommandInterpreter().SkipLLDBInitFiles (b);
282 SBDebugger::SkipAppInitFiles (bool b)
285 m_opaque_sp->GetCommandInterpreter().SkipAppInitFiles (b);
288 // Shouldn't really be settable after initialization as this could cause lots of problems; don't want users
289 // trying to switch modes in the middle of a debugging session.
291 SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership)
293 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
296 log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(),
297 fh, transfer_ownership);
300 m_opaque_sp->SetInputFileHandle (fh, transfer_ownership);
304 SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership)
306 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
310 log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(),
311 fh, transfer_ownership);
314 m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership);
318 SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership)
320 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
324 log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(),
325 fh, transfer_ownership);
328 m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership);
332 SBDebugger::GetInputFileHandle ()
336 StreamFileSP stream_file_sp (m_opaque_sp->GetInputFile());
338 return stream_file_sp->GetFile().GetStream();
344 SBDebugger::GetOutputFileHandle ()
348 StreamFileSP stream_file_sp (m_opaque_sp->GetOutputFile());
350 return stream_file_sp->GetFile().GetStream();
356 SBDebugger::GetErrorFileHandle ()
361 StreamFileSP stream_file_sp (m_opaque_sp->GetErrorFile());
363 return stream_file_sp->GetFile().GetStream();
369 SBDebugger::SaveInputTerminalState()
372 m_opaque_sp->SaveInputTerminalState();
376 SBDebugger::RestoreInputTerminalState()
379 m_opaque_sp->RestoreInputTerminalState();
383 SBDebugger::GetCommandInterpreter ()
385 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
387 SBCommandInterpreter sb_interpreter;
389 sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter());
392 log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)",
393 m_opaque_sp.get(), sb_interpreter.get());
395 return sb_interpreter;
399 SBDebugger::HandleCommand (const char *command)
403 TargetSP target_sp (m_opaque_sp->GetSelectedTarget());
404 Mutex::Locker api_locker;
406 api_locker.Lock(target_sp->GetAPIMutex());
408 SBCommandInterpreter sb_interpreter(GetCommandInterpreter ());
409 SBCommandReturnObject result;
411 sb_interpreter.HandleCommand (command, result, false);
413 if (GetErrorFileHandle() != NULL)
414 result.PutError (GetErrorFileHandle());
415 if (GetOutputFileHandle() != NULL)
416 result.PutOutput (GetOutputFileHandle());
418 if (m_opaque_sp->GetAsyncExecution() == false)
420 SBProcess process(GetCommandInterpreter().GetProcess ());
421 ProcessSP process_sp (process.GetSP());
425 Listener &lldb_listener = m_opaque_sp->GetListener();
426 while (lldb_listener.GetNextEventForBroadcaster (process_sp.get(), event_sp))
428 SBEvent event(event_sp);
429 HandleProcessEvent (process, event, GetOutputFileHandle(), GetErrorFileHandle());
437 SBDebugger::GetListener ()
439 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
441 SBListener sb_listener;
443 sb_listener.reset(&m_opaque_sp->GetListener(), false);
446 log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)", m_opaque_sp.get(),
453 SBDebugger::HandleProcessEvent (const SBProcess &process, const SBEvent &event, FILE *out, FILE *err)
455 if (!process.IsValid())
458 TargetSP target_sp (process.GetTarget().GetSP());
462 const uint32_t event_type = event.GetType();
463 char stdio_buffer[1024];
466 Mutex::Locker api_locker (target_sp->GetAPIMutex());
468 if (event_type & (Process::eBroadcastBitSTDOUT | Process::eBroadcastBitStateChanged))
470 // Drain stdout when we stop just in case we have any bytes
471 while ((len = process.GetSTDOUT (stdio_buffer, sizeof (stdio_buffer))) > 0)
473 ::fwrite (stdio_buffer, 1, len, out);
476 if (event_type & (Process::eBroadcastBitSTDERR | Process::eBroadcastBitStateChanged))
478 // Drain stderr when we stop just in case we have any bytes
479 while ((len = process.GetSTDERR (stdio_buffer, sizeof (stdio_buffer))) > 0)
481 ::fwrite (stdio_buffer, 1, len, err);
484 if (event_type & Process::eBroadcastBitStateChanged)
486 StateType event_state = SBProcess::GetStateFromEvent (event);
488 if (event_state == eStateInvalid)
491 bool is_stopped = StateIsStoppedState (event_state);
493 process.ReportEventState (event, out);
498 SBDebugger::GetSourceManager ()
500 SBSourceManager sb_source_manager (*this);
501 return sb_source_manager;
506 SBDebugger::GetDefaultArchitecture (char *arch_name, size_t arch_name_len)
508 if (arch_name && arch_name_len)
510 ArchSpec default_arch = Target::GetDefaultArchitecture ();
512 if (default_arch.IsValid())
514 const std::string &triple_str = default_arch.GetTriple().str();
515 if (!triple_str.empty())
516 ::snprintf (arch_name, arch_name_len, "%s", triple_str.c_str());
518 ::snprintf (arch_name, arch_name_len, "%s", default_arch.GetArchitectureName());
522 if (arch_name && arch_name_len)
529 SBDebugger::SetDefaultArchitecture (const char *arch_name)
533 ArchSpec arch (arch_name);
536 Target::SetDefaultArchitecture (arch);
544 SBDebugger::GetScriptingLanguage (const char *script_language_name)
547 return Args::StringToScriptLanguage (script_language_name,
548 eScriptLanguageDefault,
553 SBDebugger::GetVersionString ()
555 return lldb_private::GetVersion();
559 SBDebugger::StateAsCString (StateType state)
561 return lldb_private::StateAsCString (state);
565 SBDebugger::StateIsRunningState (StateType state)
567 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
569 const bool result = lldb_private::StateIsRunningState (state);
571 log->Printf ("SBDebugger::StateIsRunningState (state=%s) => %i",
572 StateAsCString (state), result);
578 SBDebugger::StateIsStoppedState (StateType state)
580 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
582 const bool result = lldb_private::StateIsStoppedState (state, false);
584 log->Printf ("SBDebugger::StateIsStoppedState (state=%s) => %i",
585 StateAsCString (state), result);
591 SBDebugger::CreateTarget (const char *filename,
592 const char *target_triple,
593 const char *platform_name,
594 bool add_dependent_modules,
595 lldb::SBError& sb_error)
602 OptionGroupPlatform platform_options (false);
603 platform_options.SetPlatformName (platform_name);
605 sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
608 add_dependent_modules,
612 if (sb_error.Success())
613 sb_target.SetSP (target_sp);
617 sb_error.SetErrorString("invalid target");
620 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
623 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)",
628 add_dependent_modules,
629 sb_error.GetCString(),
637 SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename,
638 const char *target_triple)
644 const bool add_dependent_modules = true;
645 Error error (m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
648 add_dependent_modules,
651 sb_target.SetSP (target_sp);
654 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
657 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)",
658 m_opaque_sp.get(), filename, target_triple, target_sp.get());
665 SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_cstr)
667 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
674 const bool add_dependent_modules = true;
676 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
679 add_dependent_modules,
685 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
686 sb_target.SetSP (target_sp);
692 log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)",
693 m_opaque_sp.get(), filename, arch_cstr, target_sp.get());
700 SBDebugger::CreateTarget (const char *filename)
706 ArchSpec arch = Target::GetDefaultArchitecture ();
708 const bool add_dependent_modules = true;
710 PlatformSP platform_sp(m_opaque_sp->GetPlatformList().GetSelectedPlatform());
711 error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp,
714 add_dependent_modules,
720 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
721 sb_target.SetSP (target_sp);
724 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
727 log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)",
728 m_opaque_sp.get(), filename, target_sp.get());
734 SBDebugger::DeleteTarget (lldb::SBTarget &target)
739 TargetSP target_sp(target.GetSP());
742 // No need to lock, the target list is thread safe
743 result = m_opaque_sp->GetTargetList().DeleteTarget (target_sp);
744 target_sp->Destroy();
746 const bool mandatory = true;
747 ModuleList::RemoveOrphanSharedModules(mandatory);
751 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
754 log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", m_opaque_sp.get(), target.m_opaque_sp.get(), result);
760 SBDebugger::GetTargetAtIndex (uint32_t idx)
765 // No need to lock, the target list is thread safe
766 sb_target.SetSP (m_opaque_sp->GetTargetList().GetTargetAtIndex (idx));
772 SBDebugger::GetIndexOfTarget (lldb::SBTarget target)
775 lldb::TargetSP target_sp = target.GetSP();
782 return m_opaque_sp->GetTargetList().GetIndexOfTarget (target.GetSP());
786 SBDebugger::FindTargetWithProcessID (lldb::pid_t pid)
791 // No need to lock, the target list is thread safe
792 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcessID (pid));
798 SBDebugger::FindTargetWithFileAndArch (const char *filename, const char *arch_name)
801 if (m_opaque_sp && filename && filename[0])
803 // No need to lock, the target list is thread safe
804 ArchSpec arch (arch_name, m_opaque_sp->GetPlatformList().GetSelectedPlatform().get());
805 TargetSP target_sp (m_opaque_sp->GetTargetList().FindTargetWithExecutableAndArchitecture (FileSpec(filename, false), arch_name ? &arch : NULL));
806 sb_target.SetSP (target_sp);
812 SBDebugger::FindTargetWithLLDBProcess (const ProcessSP &process_sp)
817 // No need to lock, the target list is thread safe
818 sb_target.SetSP (m_opaque_sp->GetTargetList().FindTargetWithProcess (process_sp.get()));
825 SBDebugger::GetNumTargets ()
829 // No need to lock, the target list is thread safe
830 return m_opaque_sp->GetTargetList().GetNumTargets ();
836 SBDebugger::GetSelectedTarget ()
838 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
844 // No need to lock, the target list is thread safe
845 target_sp = m_opaque_sp->GetTargetList().GetSelectedTarget ();
846 sb_target.SetSP (target_sp);
852 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
853 log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(),
854 target_sp.get(), sstr.GetData());
861 SBDebugger::SetSelectedTarget (SBTarget &sb_target)
863 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
865 TargetSP target_sp (sb_target.GetSP());
868 m_opaque_sp->GetTargetList().SetSelectedTarget (target_sp.get());
873 sb_target.GetDescription (sstr, eDescriptionLevelBrief);
874 log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(),
875 target_sp.get(), sstr.GetData());
880 SBDebugger::GetSelectedPlatform()
882 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
884 SBPlatform sb_platform;
885 DebuggerSP debugger_sp(m_opaque_sp);
888 sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform());
892 log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s", m_opaque_sp.get(),
893 sb_platform.GetSP().get(), sb_platform.GetName());
899 SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform)
901 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
903 DebuggerSP debugger_sp(m_opaque_sp);
906 debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP());
910 log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)", m_opaque_sp.get(),
911 sb_platform.GetSP().get(), sb_platform.GetName());
916 SBDebugger::DispatchInput (void* baton, const void *data, size_t data_len)
918 DispatchInput (data,data_len);
922 SBDebugger::DispatchInput (const void *data, size_t data_len)
924 // Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
927 // log->Printf ("SBDebugger(%p)::DispatchInput (data=\"%.*s\", size_t=%" PRIu64 ")",
928 // m_opaque_sp.get(),
930 // (const char *) data,
931 // (uint64_t)data_len);
934 // m_opaque_sp->DispatchInput ((const char *) data, data_len);
938 SBDebugger::DispatchInputInterrupt ()
941 m_opaque_sp->DispatchInputInterrupt ();
945 SBDebugger::DispatchInputEndOfFile ()
948 m_opaque_sp->DispatchInputEndOfFile ();
952 SBDebugger::PushInputReader (SBInputReader &reader)
957 SBDebugger::RunCommandInterpreter (bool auto_handle_events,
961 m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events, spawn_thread);
965 SBDebugger::reset (const DebuggerSP &debugger_sp)
967 m_opaque_sp = debugger_sp;
971 SBDebugger::get () const
973 return m_opaque_sp.get();
977 SBDebugger::ref () const
979 assert (m_opaque_sp.get());
983 const lldb::DebuggerSP &
984 SBDebugger::get_sp () const
990 SBDebugger::FindDebuggerWithID (int id)
992 // No need to lock, the debugger list is thread safe
993 SBDebugger sb_debugger;
994 DebuggerSP debugger_sp = Debugger::FindDebuggerWithID (id);
996 sb_debugger.reset (debugger_sp);
1001 SBDebugger::GetInstanceName()
1004 return m_opaque_sp->GetInstanceName().AsCString();
1010 SBDebugger::SetInternalVariable (const char *var_name, const char *value, const char *debugger_instance_name)
1013 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1017 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1018 error = debugger_sp->SetPropertyValue (&exe_ctx,
1019 eVarSetOperationAssign,
1025 error.SetErrorStringWithFormat ("invalid debugger instance name '%s'", debugger_instance_name);
1028 sb_error.SetError(error);
1033 SBDebugger::GetInternalVariableValue (const char *var_name, const char *debugger_instance_name)
1035 SBStringList ret_value;
1036 DebuggerSP debugger_sp(Debugger::FindDebuggerWithInstanceName (ConstString(debugger_instance_name)));
1040 ExecutionContext exe_ctx (debugger_sp->GetCommandInterpreter().GetExecutionContext());
1041 lldb::OptionValueSP value_sp (debugger_sp->GetPropertyValue (&exe_ctx,
1047 StreamString value_strm;
1048 value_sp->DumpValue (&exe_ctx, value_strm, OptionValue::eDumpOptionValue);
1049 const std::string &value_str = value_strm.GetString();
1050 if (!value_str.empty())
1052 StringList string_list;
1053 string_list.SplitIntoLines(value_str);
1054 return SBStringList(&string_list);
1058 return SBStringList();
1062 SBDebugger::GetTerminalWidth () const
1065 return m_opaque_sp->GetTerminalWidth ();
1070 SBDebugger::SetTerminalWidth (uint32_t term_width)
1073 m_opaque_sp->SetTerminalWidth (term_width);
1077 SBDebugger::GetPrompt() const
1079 Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API));
1082 log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"", m_opaque_sp.get(),
1083 (m_opaque_sp ? m_opaque_sp->GetPrompt() : ""));
1086 return m_opaque_sp->GetPrompt ();
1091 SBDebugger::SetPrompt (const char *prompt)
1094 m_opaque_sp->SetPrompt (prompt);
1099 SBDebugger::GetScriptLanguage() const
1102 return m_opaque_sp->GetScriptLanguage ();
1103 return eScriptLanguageNone;
1107 SBDebugger::SetScriptLanguage (ScriptLanguage script_lang)
1111 m_opaque_sp->SetScriptLanguage (script_lang);
1116 SBDebugger::SetUseExternalEditor (bool value)
1119 return m_opaque_sp->SetUseExternalEditor (value);
1124 SBDebugger::GetUseExternalEditor ()
1127 return m_opaque_sp->GetUseExternalEditor ();
1132 SBDebugger::SetUseColor (bool value)
1135 return m_opaque_sp->SetUseColor (value);
1140 SBDebugger::GetUseColor () const
1143 return m_opaque_sp->GetUseColor ();
1148 SBDebugger::GetDescription (SBStream &description)
1150 Stream &strm = description.ref();
1154 const char *name = m_opaque_sp->GetInstanceName().AsCString();
1155 user_id_t id = m_opaque_sp->GetID();
1156 strm.Printf ("Debugger (instance: \"%s\", id: %" PRIu64 ")", name, id);
1159 strm.PutCString ("No value");
1168 return m_opaque_sp->GetID();
1169 return LLDB_INVALID_UID;
1174 SBDebugger::SetCurrentPlatform (const char *platform_name)
1179 PlatformSP platform_sp (Platform::Create (platform_name, sb_error.ref()));
1183 bool make_selected = true;
1184 m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected);
1191 SBDebugger::SetCurrentPlatformSDKRoot (const char *sysroot)
1195 PlatformSP platform_sp (m_opaque_sp->GetPlatformList().GetSelectedPlatform());
1199 platform_sp->SetSDKRootDirectory (ConstString (sysroot));
1207 SBDebugger::GetCloseInputOnEOF () const
1210 return m_opaque_sp->GetCloseInputOnEOF ();
1215 SBDebugger::SetCloseInputOnEOF (bool b)
1218 m_opaque_sp->SetCloseInputOnEOF (b);
1222 SBDebugger::GetCategory (const char* category_name)
1224 if (!category_name || *category_name == 0)
1225 return SBTypeCategory();
1227 TypeCategoryImplSP category_sp;
1229 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, false))
1230 return SBTypeCategory(category_sp);
1232 return SBTypeCategory();
1236 SBDebugger::CreateCategory (const char* category_name)
1238 if (!category_name || *category_name == 0)
1239 return SBTypeCategory();
1241 TypeCategoryImplSP category_sp;
1243 if (DataVisualization::Categories::GetCategory(ConstString(category_name), category_sp, true))
1244 return SBTypeCategory(category_sp);
1246 return SBTypeCategory();
1250 SBDebugger::DeleteCategory (const char* category_name)
1252 if (!category_name || *category_name == 0)
1255 return DataVisualization::Categories::Delete(ConstString(category_name));
1259 SBDebugger::GetNumCategories()
1261 return DataVisualization::Categories::GetCount();
1265 SBDebugger::GetCategoryAtIndex (uint32_t index)
1267 return SBTypeCategory(DataVisualization::Categories::GetCategoryAtIndex(index));
1271 SBDebugger::GetDefaultCategory()
1273 return GetCategory("default");
1277 SBDebugger::GetFormatForType (SBTypeNameSpecifier type_name)
1279 SBTypeCategory default_category_sb = GetDefaultCategory();
1280 if (default_category_sb.GetEnabled())
1281 return default_category_sb.GetFormatForType(type_name);
1282 return SBTypeFormat();
1285 #ifndef LLDB_DISABLE_PYTHON
1287 SBDebugger::GetSummaryForType (SBTypeNameSpecifier type_name)
1289 if (type_name.IsValid() == false)
1290 return SBTypeSummary();
1291 return SBTypeSummary(DataVisualization::GetSummaryForType(type_name.GetSP()));
1293 #endif // LLDB_DISABLE_PYTHON
1296 SBDebugger::GetFilterForType (SBTypeNameSpecifier type_name)
1298 if (type_name.IsValid() == false)
1299 return SBTypeFilter();
1300 return SBTypeFilter(DataVisualization::GetFilterForType(type_name.GetSP()));
1303 #ifndef LLDB_DISABLE_PYTHON
1305 SBDebugger::GetSyntheticForType (SBTypeNameSpecifier type_name)
1307 if (type_name.IsValid() == false)
1308 return SBTypeSynthetic();
1309 return SBTypeSynthetic(DataVisualization::GetSyntheticForType(type_name.GetSP()));
1311 #endif // LLDB_DISABLE_PYTHON
1314 SBDebugger::EnableLog (const char *channel, const char **categories)
1318 uint32_t log_options = LLDB_LOG_OPTION_PREPEND_TIMESTAMP | LLDB_LOG_OPTION_PREPEND_THREAD_NAME;
1319 StreamString errors;
1320 return m_opaque_sp->EnableLog (channel, categories, NULL, log_options, errors);
1328 SBDebugger::SetLoggingCallback (lldb::LogOutputCallback log_callback, void *baton)
1332 return m_opaque_sp->SetLoggingCallback (log_callback, baton);