diff options
Diffstat (limited to 'contrib/llvm/tools/lldb/source/API/SBDebugger.cpp')
-rw-r--r-- | contrib/llvm/tools/lldb/source/API/SBDebugger.cpp | 153 |
1 files changed, 84 insertions, 69 deletions
diff --git a/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp b/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp index 8d6887a..dae5675 100644 --- a/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp @@ -38,13 +38,14 @@ #include "lldb/Core/State.h" #include "lldb/Core/StreamFile.h" #include "lldb/DataFormatters/DataVisualization.h" -#include "lldb/Host/DynamicLibrary.h" #include "lldb/Interpreter/Args.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/OptionGroupPlatform.h" #include "lldb/Target/Process.h" #include "lldb/Target/TargetList.h" +#include "llvm/Support/DynamicLibrary.h" + using namespace lldb; using namespace lldb_private; @@ -72,22 +73,22 @@ SBInputReader::IsActive() const return false; } -static lldb::DynamicLibrarySP +static llvm::sys::DynamicLibrary LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& error) { - lldb::DynamicLibrarySP dynlib_sp(new lldb_private::DynamicLibrary(spec)); - if (dynlib_sp && dynlib_sp->IsValid()) + llvm::sys::DynamicLibrary dynlib = llvm::sys::DynamicLibrary::getPermanentLibrary(spec.GetPath().c_str()); + if (dynlib.isValid()) { typedef bool (*LLDBCommandPluginInit) (lldb::SBDebugger& debugger); lldb::SBDebugger debugger_sb(debugger_sp); // This calls the bool lldb::PluginInitialize(lldb::SBDebugger debugger) function. // TODO: mangle this differently for your system - on OSX, the first underscore needs to be removed and the second one stays - LLDBCommandPluginInit init_func = dynlib_sp->GetSymbol<LLDBCommandPluginInit>("_ZN4lldb16PluginInitializeENS_10SBDebuggerE"); + LLDBCommandPluginInit init_func = (LLDBCommandPluginInit)dynlib.getAddressOfSymbol("_ZN4lldb16PluginInitializeENS_10SBDebuggerE"); if (init_func) { if (init_func(debugger_sb)) - return dynlib_sp; + return dynlib; else error.SetErrorString("plug-in refused to load (lldb::PluginInitialize(lldb::SBDebugger) returned false)"); } @@ -103,7 +104,7 @@ LoadPlugin (const lldb::DebuggerSP &debugger_sp, const FileSpec& spec, Error& er else error.SetErrorString("no such file"); } - return lldb::DynamicLibrarySP(); + return llvm::sys::DynamicLibrary(); } void @@ -131,8 +132,9 @@ SBDebugger::Clear () Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBDebugger(%p)::Clear ()", m_opaque_sp.get()); - + log->Printf ("SBDebugger(%p)::Clear ()", + static_cast<void*>(m_opaque_sp.get())); + if (m_opaque_sp) m_opaque_sp->ClearIOHandlers (); @@ -158,13 +160,24 @@ SBDebugger::Create(bool source_init_files, lldb::LogOutputCallback callback, voi Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); SBDebugger debugger; + + // Currently we have issues if this function is called simultaneously on two different + // threads. The issues mainly revolve around the fact that the lldb_private::FormatManager + // uses global collections and having two threads parsing the .lldbinit files can cause + // mayhem. So to get around this for now we need to use a mutex to prevent bad things + // from happening. + static Mutex g_mutex(Mutex::eMutexTypeRecursive); + Mutex::Locker locker(g_mutex); + debugger.reset(Debugger::CreateInstance(callback, baton)); if (log) { SBStream sstr; debugger.GetDescription (sstr); - log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData()); + log->Printf ("SBDebugger::Create () => SBDebugger(%p): %s", + static_cast<void*>(debugger.m_opaque_sp.get()), + sstr.GetData()); } SBCommandInterpreter interp = debugger.GetCommandInterpreter(); @@ -187,16 +200,18 @@ void SBDebugger::Destroy (SBDebugger &debugger) { Log *log (GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - + if (log) { SBStream sstr; debugger.GetDescription (sstr); - log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", debugger.m_opaque_sp.get(), sstr.GetData()); + log->Printf ("SBDebugger::Destroy () => SBDebugger(%p): %s", + static_cast<void*>(debugger.m_opaque_sp.get()), + sstr.GetData()); } - + Debugger::Destroy (debugger.m_opaque_sp); - + if (debugger.m_opaque_sp.get() != NULL) debugger.m_opaque_sp.reset(); } @@ -293,8 +308,9 @@ SBDebugger::SetInputFileHandle (FILE *fh, bool transfer_ownership) Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(), - fh, transfer_ownership); + log->Printf ("SBDebugger(%p)::SetInputFileHandle (fh=%p, transfer_ownership=%i)", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(fh), transfer_ownership); if (m_opaque_sp) m_opaque_sp->SetInputFileHandle (fh, transfer_ownership); @@ -307,8 +323,9 @@ SBDebugger::SetOutputFileHandle (FILE *fh, bool transfer_ownership) if (log) - log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(), - fh, transfer_ownership); + log->Printf ("SBDebugger(%p)::SetOutputFileHandle (fh=%p, transfer_ownership=%i)", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(fh), transfer_ownership); if (m_opaque_sp) m_opaque_sp->SetOutputFileHandle (fh, transfer_ownership); @@ -321,8 +338,9 @@ SBDebugger::SetErrorFileHandle (FILE *fh, bool transfer_ownership) if (log) - log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)", m_opaque_sp.get(), - fh, transfer_ownership); + log->Printf ("SBDebugger(%p)::SetErrorFileHandle (fh=%p, transfer_ownership=%i)", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(fh), transfer_ownership); if (m_opaque_sp) m_opaque_sp->SetErrorFileHandle (fh, transfer_ownership); @@ -389,8 +407,9 @@ SBDebugger::GetCommandInterpreter () sb_interpreter.reset (&m_opaque_sp->GetCommandInterpreter()); if (log) - log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)", - m_opaque_sp.get(), sb_interpreter.get()); + log->Printf ("SBDebugger(%p)::GetCommandInterpreter () => SBCommandInterpreter(%p)", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(sb_interpreter.get())); return sb_interpreter; } @@ -443,8 +462,9 @@ SBDebugger::GetListener () sb_listener.reset(&m_opaque_sp->GetListener(), false); if (log) - log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)", m_opaque_sp.get(), - sb_listener.get()); + log->Printf ("SBDebugger(%p)::GetListener () => SBListener(%p)", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(sb_listener.get())); return sb_listener; } @@ -601,14 +621,14 @@ SBDebugger::CreateTarget (const char *filename, sb_error.Clear(); OptionGroupPlatform platform_options (false); platform_options.SetPlatformName (platform_name); - + sb_error.ref() = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, filename, target_triple, add_dependent_modules, &platform_options, target_sp); - + if (sb_error.Success()) sb_target.SetSP (target_sp); } @@ -616,20 +636,14 @@ SBDebugger::CreateTarget (const char *filename, { sb_error.SetErrorString("invalid target"); } - + Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - { - log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)", - m_opaque_sp.get(), - filename, - target_triple, - platform_name, - add_dependent_modules, - sb_error.GetCString(), - target_sp.get()); - } - + log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\", triple=%s, platform_name=%s, add_dependent_modules=%u, error=%s) => SBTarget(%p)", + static_cast<void*>(m_opaque_sp.get()), filename, + target_triple, platform_name, add_dependent_modules, + sb_error.GetCString(), static_cast<void*>(target_sp.get())); + return sb_target; } @@ -650,13 +664,12 @@ SBDebugger::CreateTargetWithFileAndTargetTriple (const char *filename, target_sp)); sb_target.SetSP (target_sp); } - + Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - { - log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)", - m_opaque_sp.get(), filename, target_triple, target_sp.get()); - } + log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndTargetTriple (filename=\"%s\", triple=%s) => SBTarget(%p)", + static_cast<void*>(m_opaque_sp.get()), filename, + target_triple, static_cast<void*>(target_sp.get())); return sb_target; } @@ -688,10 +701,9 @@ SBDebugger::CreateTargetWithFileAndArch (const char *filename, const char *arch_ } if (log) - { - log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)", - m_opaque_sp.get(), filename, arch_cstr, target_sp.get()); - } + log->Printf ("SBDebugger(%p)::CreateTargetWithFileAndArch (filename=\"%s\", arch=%s) => SBTarget(%p)", + static_cast<void*>(m_opaque_sp.get()), filename, arch_cstr, + static_cast<void*>(target_sp.get())); return sb_target; } @@ -723,10 +735,9 @@ SBDebugger::CreateTarget (const char *filename) } Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - { - log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", - m_opaque_sp.get(), filename, target_sp.get()); - } + log->Printf ("SBDebugger(%p)::CreateTarget (filename=\"%s\") => SBTarget(%p)", + static_cast<void*>(m_opaque_sp.get()), filename, + static_cast<void*>(target_sp.get())); return sb_target; } @@ -750,9 +761,9 @@ SBDebugger::DeleteTarget (lldb::SBTarget &target) Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) - { - log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", m_opaque_sp.get(), target.m_opaque_sp.get(), result); - } + log->Printf ("SBDebugger(%p)::DeleteTarget (SBTarget(%p)) => %i", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(target.m_opaque_sp.get()), result); return result; } @@ -850,8 +861,9 @@ SBDebugger::GetSelectedTarget () { SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); - log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), - target_sp.get(), sstr.GetData()); + log->Printf ("SBDebugger(%p)::GetSelectedTarget () => SBTarget(%p): %s", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(target_sp.get()), sstr.GetData()); } return sb_target; @@ -871,8 +883,9 @@ SBDebugger::SetSelectedTarget (SBTarget &sb_target) { SBStream sstr; sb_target.GetDescription (sstr, eDescriptionLevelBrief); - log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", m_opaque_sp.get(), - target_sp.get(), sstr.GetData()); + log->Printf ("SBDebugger(%p)::SetSelectedTarget () => SBTarget(%p): %s", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(target_sp.get()), sstr.GetData()); } } @@ -888,10 +901,10 @@ SBDebugger::GetSelectedPlatform() sb_platform.SetSP(debugger_sp->GetPlatformList().GetSelectedPlatform()); } if (log) - { - log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s", m_opaque_sp.get(), - sb_platform.GetSP().get(), sb_platform.GetName()); - } + log->Printf ("SBDebugger(%p)::GetSelectedPlatform () => SBPlatform(%p): %s", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(sb_platform.GetSP().get()), + sb_platform.GetName()); return sb_platform; } @@ -899,17 +912,18 @@ void SBDebugger::SetSelectedPlatform(SBPlatform &sb_platform) { Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - + DebuggerSP debugger_sp(m_opaque_sp); if (debugger_sp) { debugger_sp->GetPlatformList().SetSelectedPlatform(sb_platform.GetSP()); } + if (log) - { - log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)", m_opaque_sp.get(), - sb_platform.GetSP().get(), sb_platform.GetName()); - } + log->Printf ("SBDebugger(%p)::SetSelectedPlatform (SBPlatform(%p) %s)", + static_cast<void*>(m_opaque_sp.get()), + static_cast<void*>(sb_platform.GetSP().get()), + sb_platform.GetName()); } void @@ -1077,9 +1091,10 @@ const char * SBDebugger::GetPrompt() const { Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - + if (log) - log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"", m_opaque_sp.get(), + log->Printf ("SBDebugger(%p)::GetPrompt () => \"%s\"", + static_cast<void*>(m_opaque_sp.get()), (m_opaque_sp ? m_opaque_sp->GetPrompt() : "")); if (m_opaque_sp) |