diff options
Diffstat (limited to 'contrib/llvm/tools/lldb/source/API')
24 files changed, 1720 insertions, 160 deletions
diff --git a/contrib/llvm/tools/lldb/source/API/SBAddress.cpp b/contrib/llvm/tools/lldb/source/API/SBAddress.cpp index 6aec072..d6e32b6 100644 --- a/contrib/llvm/tools/lldb/source/API/SBAddress.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBAddress.cpp @@ -23,19 +23,19 @@ using namespace lldb_private; SBAddress::SBAddress () : - m_opaque_ap () + m_opaque_ap (new Address()) { } SBAddress::SBAddress (const Address *lldb_object_ptr) : - m_opaque_ap () + m_opaque_ap (new Address()) { if (lldb_object_ptr) ref() = *lldb_object_ptr; } SBAddress::SBAddress (const SBAddress &rhs) : - m_opaque_ap () + m_opaque_ap (new Address()) { if (rhs.IsValid()) ref() = rhs.ref(); @@ -49,7 +49,7 @@ SBAddress::SBAddress (lldb::SBSection section, lldb::addr_t offset) : // Create an address by resolving a load address using the supplied target SBAddress::SBAddress (lldb::addr_t load_addr, lldb::SBTarget &target) : - m_opaque_ap() + m_opaque_ap(new Address()) { SetLoadAddress (load_addr, target); } @@ -68,7 +68,7 @@ SBAddress::operator = (const SBAddress &rhs) if (rhs.IsValid()) ref() = rhs.ref(); else - m_opaque_ap.reset(); + m_opaque_ap.reset (new Address()); } return *this; } @@ -82,7 +82,7 @@ SBAddress::IsValid () const void SBAddress::Clear () { - m_opaque_ap.reset(); + m_opaque_ap.reset (new Address()); } void @@ -100,13 +100,13 @@ SBAddress::SetAddress (const Address *lldb_object_ptr) if (lldb_object_ptr) ref() = *lldb_object_ptr; else - m_opaque_ap.reset(); + m_opaque_ap.reset (new Address()); } lldb::addr_t SBAddress::GetFileAddress () const { - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) return m_opaque_ap->GetFileAddress(); else return LLDB_INVALID_ADDRESS; @@ -121,7 +121,7 @@ SBAddress::GetLoadAddress (const SBTarget &target) const TargetSP target_sp (target.GetSP()); if (target_sp) { - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) { Mutex::Locker api_locker (target_sp->GetAPIMutex()); addr = m_opaque_ap->GetLoadAddress (target_sp.get()); @@ -162,7 +162,7 @@ SBAddress::SetLoadAddress (lldb::addr_t load_addr, lldb::SBTarget &target) bool SBAddress::OffsetAddress (addr_t offset) { - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) { addr_t addr_offset = m_opaque_ap->GetOffset(); if (addr_offset != LLDB_INVALID_ADDRESS) @@ -178,7 +178,7 @@ lldb::SBSection SBAddress::GetSection () { lldb::SBSection sb_section; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) sb_section.SetSP (m_opaque_ap->GetSection()); return sb_section; } @@ -186,7 +186,7 @@ SBAddress::GetSection () lldb::addr_t SBAddress::GetOffset () { - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) return m_opaque_ap->GetOffset(); return 0; } @@ -233,7 +233,7 @@ SBAddress::GetDescription (SBStream &description) // Call "ref()" on the stream to make sure it creates a backing stream in // case there isn't one already... Stream &strm = description.ref(); - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) { m_opaque_ap->Dump (&strm, NULL, @@ -255,7 +255,7 @@ SBModule SBAddress::GetModule () { SBModule sb_module; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) sb_module.SetSP (m_opaque_ap->GetModule()); return sb_module; } @@ -264,7 +264,7 @@ SBSymbolContext SBAddress::GetSymbolContext (uint32_t resolve_scope) { SBSymbolContext sb_sc; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) m_opaque_ap->CalculateSymbolContext (&sb_sc.ref(), resolve_scope); return sb_sc; } @@ -273,7 +273,7 @@ SBCompileUnit SBAddress::GetCompileUnit () { SBCompileUnit sb_comp_unit; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) sb_comp_unit.reset(m_opaque_ap->CalculateSymbolContextCompileUnit()); return sb_comp_unit; } @@ -282,7 +282,7 @@ SBFunction SBAddress::GetFunction () { SBFunction sb_function; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) sb_function.reset(m_opaque_ap->CalculateSymbolContextFunction()); return sb_function; } @@ -291,7 +291,7 @@ SBBlock SBAddress::GetBlock () { SBBlock sb_block; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) sb_block.SetPtr(m_opaque_ap->CalculateSymbolContextBlock()); return sb_block; } @@ -300,7 +300,7 @@ SBSymbol SBAddress::GetSymbol () { SBSymbol sb_symbol; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) sb_symbol.reset(m_opaque_ap->CalculateSymbolContextSymbol()); return sb_symbol; } @@ -309,7 +309,7 @@ SBLineEntry SBAddress::GetLineEntry () { SBLineEntry sb_line_entry; - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) { LineEntry line_entry; if (m_opaque_ap->CalculateSymbolContextLineEntry (line_entry)) @@ -321,7 +321,7 @@ SBAddress::GetLineEntry () AddressClass SBAddress::GetAddressClass () { - if (m_opaque_ap.get()) + if (m_opaque_ap->IsValid()) return m_opaque_ap->GetAddressClass(); return eAddressClassInvalid; } diff --git a/contrib/llvm/tools/lldb/source/API/SBBreakpoint.cpp b/contrib/llvm/tools/lldb/source/API/SBBreakpoint.cpp index a950ca9..dd4c80c 100644 --- a/contrib/llvm/tools/lldb/source/API/SBBreakpoint.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBBreakpoint.cpp @@ -13,6 +13,7 @@ #include "lldb/API/SBEvent.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" +#include "lldb/API/SBStringList.h" #include "lldb/API/SBThread.h" #include "lldb/Breakpoint/Breakpoint.h" @@ -653,6 +654,83 @@ SBBreakpoint::SetScriptCallbackBody (const char *callback_body_text) return sb_error; } +bool +SBBreakpoint::AddName (const char *new_name) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + log->Printf ("SBBreakpoint(%p)::AddName (name=%s)", + static_cast<void*>(m_opaque_sp.get()), + new_name); + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + Error error; // Think I'm just going to swallow the error here, it's probably more annoying to have to provide it. + return m_opaque_sp->AddName(new_name, error); + } + + return false; +} + +void +SBBreakpoint::RemoveName (const char *name_to_remove) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + log->Printf ("SBBreakpoint(%p)::RemoveName (name=%s)", + static_cast<void*>(m_opaque_sp.get()), + name_to_remove); + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->RemoveName(name_to_remove); + } +} + +bool +SBBreakpoint::MatchesName (const char *name) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + log->Printf ("SBBreakpoint(%p)::MatchesName (name=%s)", + static_cast<void*>(m_opaque_sp.get()), + name); + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->MatchesName(name); + } + + return false; +} + +void +SBBreakpoint::GetNames (SBStringList &names) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + log->Printf ("SBBreakpoint(%p)::GetNames ()", + static_cast<void*>(m_opaque_sp.get())); + + if (m_opaque_sp) + { + Mutex::Locker api_locker (m_opaque_sp->GetTarget().GetAPIMutex()); + std::vector<std::string> names_vec; + m_opaque_sp->GetNames(names_vec); + for (std::string name : names_vec) + { + names.AppendString (name.c_str()); + } + } +} + lldb_private::Breakpoint * SBBreakpoint::operator->() const { diff --git a/contrib/llvm/tools/lldb/source/API/SBCommandInterpreter.cpp b/contrib/llvm/tools/lldb/source/API/SBCommandInterpreter.cpp index e1adea7..193d06e 100644 --- a/contrib/llvm/tools/lldb/source/API/SBCommandInterpreter.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBCommandInterpreter.cpp @@ -20,6 +20,7 @@ #include "lldb/API/SBBroadcaster.h" #include "lldb/API/SBCommandReturnObject.h" #include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBExecutionContext.h" #include "lldb/API/SBProcess.h" #include "lldb/API/SBTarget.h" #include "lldb/API/SBListener.h" @@ -29,6 +30,100 @@ using namespace lldb; using namespace lldb_private; +SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() +{ + m_opaque_up.reset(new CommandInterpreterRunOptions()); +} + +SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions() +{ + +} + +bool +SBCommandInterpreterRunOptions::GetStopOnContinue () const +{ + return m_opaque_up->GetStopOnContinue(); +} + +void +SBCommandInterpreterRunOptions::SetStopOnContinue (bool stop_on_continue) +{ + m_opaque_up->SetStopOnContinue(stop_on_continue); +} + +bool +SBCommandInterpreterRunOptions::GetStopOnError () const +{ + return m_opaque_up->GetStopOnError(); +} + +void +SBCommandInterpreterRunOptions::SetStopOnError (bool stop_on_error) +{ + m_opaque_up->SetStopOnError(stop_on_error); +} + +bool +SBCommandInterpreterRunOptions::GetStopOnCrash () const +{ + return m_opaque_up->GetStopOnCrash(); +} + +void +SBCommandInterpreterRunOptions::SetStopOnCrash (bool stop_on_crash) +{ + m_opaque_up->SetStopOnCrash(stop_on_crash); +} + +bool +SBCommandInterpreterRunOptions::GetEchoCommands () const +{ + return m_opaque_up->GetEchoCommands(); +} + +void +SBCommandInterpreterRunOptions::SetEchoCommands (bool echo_commands) +{ + m_opaque_up->SetEchoCommands(echo_commands); +} + +bool +SBCommandInterpreterRunOptions::GetPrintResults () const +{ + return m_opaque_up->GetPrintResults(); +} + +void +SBCommandInterpreterRunOptions::SetPrintResults (bool print_results) +{ + m_opaque_up->SetPrintResults(print_results); +} + +bool +SBCommandInterpreterRunOptions::GetAddToHistory () const +{ + return m_opaque_up->GetAddToHistory(); +} + +void +SBCommandInterpreterRunOptions::SetAddToHistory (bool add_to_history) +{ + m_opaque_up->SetAddToHistory(add_to_history); +} + +lldb_private::CommandInterpreterRunOptions * +SBCommandInterpreterRunOptions::get () const +{ + return m_opaque_up.get(); +} + +lldb_private::CommandInterpreterRunOptions & +SBCommandInterpreterRunOptions::ref () const +{ + return *m_opaque_up.get(); +} + class CommandPluginInterfaceImplementation : public CommandObjectParsed { public: @@ -128,6 +223,13 @@ SBCommandInterpreter::GetIOHandlerControlSequence(char ch) lldb::ReturnStatus SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnObject &result, bool add_to_history) { + SBExecutionContext sb_exe_ctx; + return HandleCommand (command_line, sb_exe_ctx, result, add_to_history); +} + +lldb::ReturnStatus +SBCommandInterpreter::HandleCommand (const char *command_line, SBExecutionContext &override_context, SBCommandReturnObject &result, bool add_to_history) +{ Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) @@ -135,11 +237,21 @@ SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnOb static_cast<void*>(m_opaque_ptr), command_line, static_cast<void*>(result.get()), add_to_history); + ExecutionContext ctx, *ctx_ptr; + if (override_context.get()) + { + ctx = override_context.get()->Lock(true); + ctx_ptr = &ctx; + } + else + ctx_ptr = nullptr; + + result.Clear(); if (command_line && m_opaque_ptr) { result.ref().SetInteractive(false); - m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref()); + m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref(), ctx_ptr); } else { @@ -162,6 +274,54 @@ SBCommandInterpreter::HandleCommand (const char *command_line, SBCommandReturnOb return result.GetStatus(); } +void +SBCommandInterpreter::HandleCommandsFromFile (lldb::SBFileSpec &file, + lldb::SBExecutionContext &override_context, + lldb::SBCommandInterpreterRunOptions &options, + lldb::SBCommandReturnObject result) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + + if (log) + { + SBStream s; + file.GetDescription (s); + log->Printf ("SBCommandInterpreter(%p)::HandleCommandsFromFile (file=\"%s\", SBCommandReturnObject(%p))", + static_cast<void*>(m_opaque_ptr), s.GetData(), + static_cast<void*>(result.get())); + } + + if (!m_opaque_ptr) + { + result->AppendError ("SBCommandInterpreter is not valid."); + result->SetStatus (eReturnStatusFailed); + return; + } + + if (!file.IsValid()) + { + SBStream s; + file.GetDescription (s); + result->AppendErrorWithFormat ("File is not valid: %s.", s.GetData()); + result->SetStatus (eReturnStatusFailed); + } + + FileSpec tmp_spec = file.ref(); + ExecutionContext ctx, *ctx_ptr; + if (override_context.get()) + { + ctx = override_context.get()->Lock(true); + ctx_ptr = &ctx; + } + else + ctx_ptr = nullptr; + + + m_opaque_ptr->HandleCommandsFromFile (tmp_spec, ctx_ptr, options.ref(), result.ref()); + +} + + int SBCommandInterpreter::HandleCompletion (const char *current_line, const char *cursor, @@ -434,6 +594,7 @@ LLDBSwigPythonCallTypeScript (const char *python_function_name, void *session_dictionary, const lldb::ValueObjectSP& valobj_sp, void** pyfunct_wrapper, + const lldb::TypeSummaryOptionsSP& options_sp, std::string& retval); extern "C" void* @@ -442,6 +603,17 @@ LLDBSwigPythonCreateSyntheticProvider (const char *python_class_name, const lldb::ValueObjectSP& valobj_sp); +extern "C" void* +LLDBSwigPythonCreateScriptedThreadPlan (const char *python_class_name, + const char *session_dictionary_name, + const lldb::ThreadPlanSP& thread_plan_sp); + +extern "C" bool +LLDBSWIGPythonCallThreadPlan (void *implementor, + const char *method_name, + Event *event_sp, + bool &got_error); + extern "C" uint32_t LLDBSwigPython_CalculateNumChildren (void *implementor); @@ -463,12 +635,16 @@ LLDBSwigPython_UpdateSynthProviderInstance (void* implementor); extern "C" bool LLDBSwigPython_MightHaveChildrenSynthProviderInstance (void* implementor); +extern "C" void * +LLDBSwigPython_GetValueSynthProviderInstance (void* implementor); + extern "C" bool LLDBSwigPythonCallCommand (const char *python_function_name, const char *session_dictionary_name, lldb::DebuggerSP& debugger, const char* args, - lldb_private::CommandReturnObject &cmd_retobj); + lldb_private::CommandReturnObject &cmd_retobj, + lldb::ExecutionContextRefSP exe_ctx_ref_sp); extern "C" bool LLDBSwigPythonCallModuleInit (const char *python_module_name, @@ -504,6 +680,12 @@ LLDBSWIGPythonRunScriptKeywordFrame (const char* python_function_name, lldb::StackFrameSP& frame, std::string& output); +extern "C" bool +LLDBSWIGPythonRunScriptKeywordValue (const char* python_function_name, + const char* session_dictionary_name, + lldb::ValueObjectSP& value, + std::string& output); + extern "C" void* LLDBSWIGPython_GetDynamicSetting (void* module, const char* setting, @@ -532,6 +714,7 @@ SBCommandInterpreter::InitializeSWIG () LLDBSWIGPython_GetValueObjectSPFromSBValue, LLDBSwigPython_UpdateSynthProviderInstance, LLDBSwigPython_MightHaveChildrenSynthProviderInstance, + LLDBSwigPython_GetValueSynthProviderInstance, LLDBSwigPythonCallCommand, LLDBSwigPythonCallModuleInit, LLDBSWIGPythonCreateOSPlugin, @@ -539,7 +722,10 @@ SBCommandInterpreter::InitializeSWIG () LLDBSWIGPythonRunScriptKeywordThread, LLDBSWIGPythonRunScriptKeywordTarget, LLDBSWIGPythonRunScriptKeywordFrame, - LLDBSWIGPython_GetDynamicSetting); + LLDBSWIGPythonRunScriptKeywordValue, + LLDBSWIGPython_GetDynamicSetting, + LLDBSwigPythonCreateScriptedThreadPlan, + LLDBSWIGPythonCallThreadPlan); #endif } } diff --git a/contrib/llvm/tools/lldb/source/API/SBCommunication.cpp b/contrib/llvm/tools/lldb/source/API/SBCommunication.cpp index df0b864..956b6cf 100644 --- a/contrib/llvm/tools/lldb/source/API/SBCommunication.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBCommunication.cpp @@ -10,8 +10,8 @@ #include "lldb/API/SBCommunication.h" #include "lldb/API/SBBroadcaster.h" #include "lldb/Core/Communication.h" -#include "lldb/Core/ConnectionFileDescriptor.h" #include "lldb/Core/Log.h" +#include "lldb/Host/ConnectionFileDescriptor.h" using namespace lldb; using namespace lldb_private; @@ -71,7 +71,7 @@ SBCommunication::Connect (const char *url) if (m_opaque) { if (!m_opaque->HasConnection ()) - m_opaque->SetConnection (new ConnectionFileDescriptor()); + m_opaque->SetConnection(Connection::CreateDefaultConnection(url)); return m_opaque->Connect (url, NULL); } return eConnectionStatusNoConnection; diff --git a/contrib/llvm/tools/lldb/source/API/SBCompileUnit.cpp b/contrib/llvm/tools/lldb/source/API/SBCompileUnit.cpp index 03c2571..5d904ce 100644 --- a/contrib/llvm/tools/lldb/source/API/SBCompileUnit.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBCompileUnit.cpp @@ -228,6 +228,14 @@ SBCompileUnit::FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_fi return 0; } +lldb::LanguageType +SBCompileUnit::GetLanguage () +{ + if (m_opaque_ptr) + return m_opaque_ptr->GetLanguage(); + return lldb::eLanguageTypeUnknown; +} + bool SBCompileUnit::IsValid () const { diff --git a/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp b/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp index dae5675..a95f2ff 100644 --- a/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBDebugger.cpp @@ -715,16 +715,13 @@ SBDebugger::CreateTarget (const char *filename) TargetSP target_sp; if (m_opaque_sp) { - ArchSpec arch = Target::GetDefaultArchitecture (); Error error; const bool add_dependent_modules = true; - - PlatformSP platform_sp(m_opaque_sp->GetPlatformList().GetSelectedPlatform()); - error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, + error = m_opaque_sp->GetTargetList().CreateTarget (*m_opaque_sp, filename, - arch, + NULL, add_dependent_modules, - platform_sp, + NULL, target_sp); if (error.Success()) @@ -972,7 +969,32 @@ SBDebugger::RunCommandInterpreter (bool auto_handle_events, bool spawn_thread) { if (m_opaque_sp) - m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events, spawn_thread); + { + CommandInterpreterRunOptions options; + + m_opaque_sp->GetCommandInterpreter().RunCommandInterpreter(auto_handle_events, + spawn_thread, + options); + } +} + +void +SBDebugger::RunCommandInterpreter (bool auto_handle_events, + bool spawn_thread, + SBCommandInterpreterRunOptions &options, + int &num_errors, + bool &quit_requested, + bool &stopped_for_crash) + +{ + if (m_opaque_sp) + { + CommandInterpreter &interp = m_opaque_sp->GetCommandInterpreter(); + interp.RunCommandInterpreter(auto_handle_events, spawn_thread, options.ref()); + num_errors = interp.GetNumErrors(); + quit_requested = interp.GetQuitRequested(); + stopped_for_crash = interp.GetStoppedForCrash(); + } } void @@ -1186,19 +1208,42 @@ SBDebugger::GetID() SBError -SBDebugger::SetCurrentPlatform (const char *platform_name) +SBDebugger::SetCurrentPlatform (const char *platform_name_cstr) { SBError sb_error; if (m_opaque_sp) { - PlatformSP platform_sp (Platform::Create (platform_name, sb_error.ref())); - - if (platform_sp) + if (platform_name_cstr && platform_name_cstr[0]) { - bool make_selected = true; - m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected); + ConstString platform_name (platform_name_cstr); + PlatformSP platform_sp (Platform::Find (platform_name)); + + if (platform_sp) + { + // Already have a platform with this name, just select it + m_opaque_sp->GetPlatformList().SetSelectedPlatform(platform_sp); + } + else + { + // We don't have a platform by this name yet, create one + platform_sp = Platform::Create (platform_name, sb_error.ref()); + if (platform_sp) + { + // We created the platform, now append and select it + bool make_selected = true; + m_opaque_sp->GetPlatformList().Append (platform_sp, make_selected); + } + } + } + else + { + sb_error.ref().SetErrorString("invalid platform name"); } } + else + { + sb_error.ref().SetErrorString("invalid debugger"); + } return sb_error; } diff --git a/contrib/llvm/tools/lldb/source/API/SBEvent.cpp b/contrib/llvm/tools/lldb/source/API/SBEvent.cpp index 57a699f..c62c495 100644 --- a/contrib/llvm/tools/lldb/source/API/SBEvent.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBEvent.cpp @@ -43,6 +43,12 @@ SBEvent::SBEvent (EventSP &event_sp) : { } +SBEvent::SBEvent (Event *event_ptr) : + m_event_sp (), + m_opaque_ptr (event_ptr) +{ +} + SBEvent::SBEvent (const SBEvent &rhs) : m_event_sp (rhs.m_event_sp), m_opaque_ptr (rhs.m_opaque_ptr) diff --git a/contrib/llvm/tools/lldb/source/API/SBExecutionContext.cpp b/contrib/llvm/tools/lldb/source/API/SBExecutionContext.cpp new file mode 100644 index 0000000..dc20c60 --- /dev/null +++ b/contrib/llvm/tools/lldb/source/API/SBExecutionContext.cpp @@ -0,0 +1,129 @@ +//===-- SBExecutionContext.cpp ------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBExecutionContext.h" + +#include "lldb/API/SBTarget.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBThread.h" +#include "lldb/API/SBFrame.h" + +#include "lldb/Target/ExecutionContext.h" + +using namespace lldb; +using namespace lldb_private; + +SBExecutionContext::SBExecutionContext() : +m_exe_ctx_sp() +{ +} + +SBExecutionContext::SBExecutionContext (const lldb::SBExecutionContext &rhs) : +m_exe_ctx_sp(rhs.m_exe_ctx_sp) +{ +} + +SBExecutionContext::SBExecutionContext (lldb::ExecutionContextRefSP exe_ctx_ref_sp) : +m_exe_ctx_sp(exe_ctx_ref_sp) +{ +} + +SBExecutionContext::SBExecutionContext (const lldb::SBTarget &target) : +m_exe_ctx_sp(new ExecutionContextRef()) +{ + m_exe_ctx_sp->SetTargetSP(target.GetSP()); +} + +SBExecutionContext::SBExecutionContext (const lldb::SBProcess &process) : +m_exe_ctx_sp(new ExecutionContextRef()) +{ + m_exe_ctx_sp->SetProcessSP(process.GetSP()); +} + +SBExecutionContext::SBExecutionContext (lldb::SBThread thread) : +m_exe_ctx_sp(new ExecutionContextRef()) +{ + m_exe_ctx_sp->SetThreadPtr(thread.get()); +} + +SBExecutionContext::SBExecutionContext (const lldb::SBFrame &frame) : +m_exe_ctx_sp(new ExecutionContextRef()) +{ + m_exe_ctx_sp->SetFrameSP(frame.GetFrameSP()); +} + +SBExecutionContext::~SBExecutionContext() +{ +} + +const SBExecutionContext & +SBExecutionContext::operator = (const lldb::SBExecutionContext &rhs) +{ + m_exe_ctx_sp = rhs.m_exe_ctx_sp; + return *this; +} + +ExecutionContextRef * +SBExecutionContext::get () const +{ + return m_exe_ctx_sp.get(); +} + +SBTarget +SBExecutionContext::GetTarget () const +{ + SBTarget sb_target; + if (m_exe_ctx_sp) + { + TargetSP target_sp(m_exe_ctx_sp->GetTargetSP()); + if (target_sp) + sb_target.SetSP(target_sp); + } + return sb_target; +} + +SBProcess +SBExecutionContext::GetProcess () const +{ + SBProcess sb_process; + if (m_exe_ctx_sp) + { + ProcessSP process_sp(m_exe_ctx_sp->GetProcessSP()); + if (process_sp) + sb_process.SetSP(process_sp); + } + return sb_process; +} + +SBThread +SBExecutionContext::GetThread () const +{ + SBThread sb_thread; + if (m_exe_ctx_sp) + { + ThreadSP thread_sp(m_exe_ctx_sp->GetThreadSP()); + if (thread_sp) + sb_thread.SetThread(thread_sp); + } + return sb_thread; +} + +SBFrame +SBExecutionContext::GetFrame () const +{ + SBFrame sb_frame; + if (m_exe_ctx_sp) + { + StackFrameSP frame_sp(m_exe_ctx_sp->GetFrameSP()); + if (frame_sp) + sb_frame.SetFrameSP(frame_sp); + } + return sb_frame; +} + diff --git a/contrib/llvm/tools/lldb/source/API/SBFunction.cpp b/contrib/llvm/tools/lldb/source/API/SBFunction.cpp index 3d185da..bf5e918 100644 --- a/contrib/llvm/tools/lldb/source/API/SBFunction.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBFunction.cpp @@ -227,5 +227,15 @@ SBFunction::GetBlock () return sb_block; } +lldb::LanguageType +SBFunction::GetLanguage () +{ + if (m_opaque_ptr) + { + if (m_opaque_ptr->GetCompileUnit()) + return m_opaque_ptr->GetCompileUnit()->GetLanguage(); + } + return lldb::eLanguageTypeUnknown; +} diff --git a/contrib/llvm/tools/lldb/source/API/SBHostOS.cpp b/contrib/llvm/tools/lldb/source/API/SBHostOS.cpp index ec1e2f2..008ca4d 100644 --- a/contrib/llvm/tools/lldb/source/API/SBHostOS.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBHostOS.cpp @@ -13,6 +13,9 @@ #include "lldb/Core/Log.h" #include "lldb/Host/Host.h" #include "lldb/Host/HostInfo.h" +#include "lldb/Host/HostNativeThread.h" +#include "lldb/Host/HostThread.h" +#include "lldb/Host/ThreadLauncher.h" using namespace lldb; using namespace lldb_private; @@ -69,31 +72,54 @@ SBHostOS::ThreadCreate // FIXME: You should log the return value? - return Host::ThreadCreate (name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL); + HostThread thread(ThreadLauncher::LaunchThread(name, thread_function, thread_arg, error_ptr ? error_ptr->get() : NULL)); + return thread.Release(); } void SBHostOS::ThreadCreated (const char *name) { - Host::ThreadCreated (name); } bool SBHostOS::ThreadCancel (lldb::thread_t thread, SBError *error_ptr) { - return Host::ThreadCancel (thread, error_ptr ? error_ptr->get() : NULL); + Error error; + HostThread host_thread(thread); + error = host_thread.Cancel(); + if (error_ptr) + error_ptr->SetError(error); + host_thread.Release(); + return error.Success(); } bool SBHostOS::ThreadDetach (lldb::thread_t thread, SBError *error_ptr) { - return Host::ThreadDetach (thread, error_ptr ? error_ptr->get() : NULL); + Error error; +#if defined(_WIN32) + if (error_ptr) + error_ptr->SetErrorString("ThreadDetach is not supported on this platform"); +#else + HostThread host_thread(thread); + error = host_thread.GetNativeThread().Detach(); + if (error_ptr) + error_ptr->SetError(error); + host_thread.Release(); +#endif + return error.Success(); } bool SBHostOS::ThreadJoin (lldb::thread_t thread, lldb::thread_result_t *result, SBError *error_ptr) { - return Host::ThreadJoin (thread, result, error_ptr ? error_ptr->get() : NULL); + Error error; + HostThread host_thread(thread); + error = host_thread.Join(result); + if (error_ptr) + error_ptr->SetError(error); + host_thread.Release(); + return error.Success(); } diff --git a/contrib/llvm/tools/lldb/source/API/SBInstruction.cpp b/contrib/llvm/tools/lldb/source/API/SBInstruction.cpp index 2334cc0..eccc4e2 100644 --- a/contrib/llvm/tools/lldb/source/API/SBInstruction.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBInstruction.cpp @@ -20,6 +20,7 @@ #include "lldb/Core/DataExtractor.h" #include "lldb/Core/Disassembler.h" #include "lldb/Core/EmulateInstruction.h" +#include "lldb/Core/Module.h" #include "lldb/Core/StreamFile.h" #include "lldb/Target/ExecutionContext.h" #include "lldb/Target/StackFrame.h" @@ -170,9 +171,15 @@ SBInstruction::GetDescription (lldb::SBStream &s) { if (m_opaque_sp) { + SymbolContext sc; + const Address &addr = m_opaque_sp->GetAddress(); + ModuleSP module_sp (addr.GetModule()); + if (module_sp) + module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); // Use the "ref()" instead of the "get()" accessor in case the SBStream // didn't have a stream already created, one will get created... - m_opaque_sp->Dump (&s.ref(), 0, true, false, NULL); + const char *disassemble_format = "${addr-file-or-load}: "; + m_opaque_sp->Dump (&s.ref(), 0, true, false, NULL, &sc, NULL, disassemble_format); return true; } return false; @@ -186,8 +193,14 @@ SBInstruction::Print (FILE *out) if (m_opaque_sp) { + SymbolContext sc; + const Address &addr = m_opaque_sp->GetAddress(); + ModuleSP module_sp (addr.GetModule()); + if (module_sp) + module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); StreamFile out_stream (out, false); - m_opaque_sp->Dump (&out_stream, 0, true, false, NULL); + const char *disassemble_format = "${addr-file-or-load}: "; + m_opaque_sp->Dump (&out_stream, 0, true, false, NULL, &sc, NULL, disassemble_format); } } diff --git a/contrib/llvm/tools/lldb/source/API/SBInstructionList.cpp b/contrib/llvm/tools/lldb/source/API/SBInstructionList.cpp index fe22d9c..31585b3 100644 --- a/contrib/llvm/tools/lldb/source/API/SBInstructionList.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBInstructionList.cpp @@ -11,7 +11,9 @@ #include "lldb/API/SBInstruction.h" #include "lldb/API/SBStream.h" #include "lldb/Core/Disassembler.h" +#include "lldb/Core/Module.h" #include "lldb/Core/Stream.h" +#include "lldb/Symbol/SymbolContext.h" using namespace lldb; using namespace lldb_private; @@ -100,12 +102,24 @@ SBInstructionList::GetDescription (lldb::SBStream &description) // exist already inside description... Stream &sref = description.ref(); const uint32_t max_opcode_byte_size = m_opaque_sp->GetInstructionList().GetMaxOpcocdeByteSize(); + const char *disassemble_format = "${addr-file-or-load}: "; + SymbolContext sc; + SymbolContext prev_sc; for (size_t i=0; i<num_instructions; ++i) { Instruction *inst = m_opaque_sp->GetInstructionList().GetInstructionAtIndex (i).get(); if (inst == NULL) break; - inst->Dump (&sref, max_opcode_byte_size, true, false, NULL); + + const Address &addr = inst->GetAddress(); + prev_sc = sc; + ModuleSP module_sp (addr.GetModule()); + if (module_sp) + { + module_sp->ResolveSymbolContextForAddress(addr, eSymbolContextEverything, sc); + } + + inst->Dump (&sref, max_opcode_byte_size, true, false, NULL, &sc, &prev_sc, disassemble_format); sref.EOL(); } return true; diff --git a/contrib/llvm/tools/lldb/source/API/SBListener.cpp b/contrib/llvm/tools/lldb/source/API/SBListener.cpp index bad9ba8..8731873 100644 --- a/contrib/llvm/tools/lldb/source/API/SBListener.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBListener.cpp @@ -69,6 +69,12 @@ SBListener::SBListener (Listener &listener) : { } +SBListener::SBListener (const lldb::ListenerSP &listener_sp) : + m_opaque_sp (listener_sp), + m_opaque_ptr (listener_sp.get()) +{ +} + SBListener::~SBListener () { } diff --git a/contrib/llvm/tools/lldb/source/API/SBPlatform.cpp b/contrib/llvm/tools/lldb/source/API/SBPlatform.cpp index 9914852..d3e769a 100644 --- a/contrib/llvm/tools/lldb/source/API/SBPlatform.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBPlatform.cpp @@ -269,7 +269,8 @@ SBPlatform::SBPlatform (const char *platform_name) : m_opaque_sp () { Error error; - m_opaque_sp = Platform::Create (platform_name, error); + if (platform_name && platform_name[0]) + m_opaque_sp = Platform::Create (ConstString(platform_name), error); } SBPlatform::~SBPlatform() diff --git a/contrib/llvm/tools/lldb/source/API/SBProcess.cpp b/contrib/llvm/tools/lldb/source/API/SBProcess.cpp index 41efd86..9a0b23b 100644 --- a/contrib/llvm/tools/lldb/source/API/SBProcess.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBProcess.cpp @@ -38,6 +38,7 @@ #include "lldb/API/SBEvent.h" #include "lldb/API/SBFileSpec.h" #include "lldb/API/SBThread.h" +#include "lldb/API/SBThreadCollection.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBStringList.h" #include "lldb/API/SBUnixSignals.h" @@ -738,18 +739,10 @@ SBProcess::Continue () { Mutex::Locker api_locker (process_sp->GetTarget().GetAPIMutex()); - Error error (process_sp->Resume()); - if (error.Success()) - { - if (process_sp->GetTarget().GetDebugger().GetAsyncExecution () == false) - { - if (log) - log->Printf ("SBProcess(%p)::Continue () waiting for process to stop...", - static_cast<void*>(process_sp.get())); - process_sp->WaitForProcessToStop (NULL); - } - } - sb_error.SetError(error); + if (process_sp->GetTarget().GetDebugger().GetAsyncExecution ()) + sb_error.ref() = process_sp->Resume (); + else + sb_error.ref() = process_sp->ResumeSynchronous (NULL); } else sb_error.SetErrorString ("SBProcess is invalid"); @@ -1381,3 +1374,30 @@ SBProcess::GetExtendedBacktraceTypeAtIndex (uint32_t idx) } return NULL; } + +SBThreadCollection +SBProcess::GetHistoryThreads (addr_t addr) +{ + ProcessSP process_sp(GetSP()); + SBThreadCollection threads; + if (process_sp) + { + threads = SBThreadCollection(process_sp->GetHistoryThreads(addr)); + } + return threads; +} + +bool +SBProcess::IsInstrumentationRuntimePresent(InstrumentationRuntimeType type) +{ + ProcessSP process_sp(GetSP()); + if (! process_sp) + return false; + + InstrumentationRuntimeSP runtime_sp = process_sp->GetInstrumentationRuntime(type); + + if (! runtime_sp.get()) + return false; + + return runtime_sp->IsActive(); +} diff --git a/contrib/llvm/tools/lldb/source/API/SBSection.cpp b/contrib/llvm/tools/lldb/source/API/SBSection.cpp index 3fb84e8..809eca6 100644 --- a/contrib/llvm/tools/lldb/source/API/SBSection.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBSection.cpp @@ -250,6 +250,14 @@ SBSection::GetSectionType () return eSectionTypeInvalid; } +uint32_t +SBSection::GetTargetByteSize () +{ + SectionSP section_sp (GetSP()); + if (section_sp.get()) + return section_sp->GetTargetByteSize(); + return 0; +} bool SBSection::operator == (const SBSection &rhs) diff --git a/contrib/llvm/tools/lldb/source/API/SBTarget.cpp b/contrib/llvm/tools/lldb/source/API/SBTarget.cpp index 3d5828c..b87b1ac 100644 --- a/contrib/llvm/tools/lldb/source/API/SBTarget.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBTarget.cpp @@ -58,6 +58,7 @@ #include "lldb/Interpreter/CommandReturnObject.h" #include "../source/Commands/CommandObjectBreakpoint.h" +#include "llvm/Support/Regex.h" using namespace lldb; @@ -132,6 +133,18 @@ SBLaunchInfo::SetExecutableFile (SBFileSpec exe_file, bool add_as_first_arg) m_opaque_sp->SetExecutableFile(exe_file.ref(), add_as_first_arg); } +SBListener +SBLaunchInfo::GetListener () +{ + return SBListener(m_opaque_sp->GetListener()); +} + +void +SBLaunchInfo::SetListener (SBListener &listener) +{ + m_opaque_sp->SetListener(listener.GetSP()); +} + uint32_t SBLaunchInfo::GetNumArguments () { @@ -235,13 +248,16 @@ SBLaunchInfo::SetProcessPluginName (const char *plugin_name) const char * SBLaunchInfo::GetShell () { - return m_opaque_sp->GetShell(); + // Constify this string so that it is saved in the string pool. Otherwise + // it would be freed when this function goes out of scope. + ConstString shell(m_opaque_sp->GetShell().GetPath().c_str()); + return shell.AsCString(); } void SBLaunchInfo::SetShell (const char * path) { - m_opaque_sp->SetShell (path); + m_opaque_sp->SetShell (FileSpec(path, false)); } uint32_t @@ -516,6 +532,17 @@ SBAttachInfo::ParentProcessIDIsValid() return m_opaque_sp->ParentProcessIDIsValid(); } +SBListener +SBAttachInfo::GetListener () +{ + return SBListener(m_opaque_sp->GetListener()); +} + +void +SBAttachInfo::SetListener (SBListener &listener) +{ + m_opaque_sp->SetListener(listener.GetSP()); +} //---------------------------------------------------------------------- // SBTarget constructor @@ -583,6 +610,19 @@ SBTarget::GetProcess () return sb_process; } +SBPlatform +SBTarget::GetPlatform () +{ + TargetSP target_sp(GetSP()); + if (!target_sp) + return SBPlatform(); + + SBPlatform platform; + platform.m_opaque_sp = target_sp->GetPlatform(); + + return platform; +} + SBDebugger SBTarget::GetDebugger () const { @@ -734,9 +774,9 @@ SBTarget::Launch launch_info.GetEnvironmentEntries ().SetArguments (envp); if (listener.IsValid()) - error.SetError (target_sp->Launch(listener.ref(), launch_info)); - else - error.SetError (target_sp->Launch(target_sp->GetDebugger().GetListener(), launch_info)); + launch_info.SetListener(listener.GetSP()); + + error.SetError (target_sp->Launch(launch_info, NULL)); sb_process.SetSP(target_sp->GetProcessSP()); } @@ -800,7 +840,7 @@ SBTarget::Launch (SBLaunchInfo &sb_launch_info, SBError& error) if (arch_spec.IsValid()) launch_info.GetArchitecture () = arch_spec; - error.SetError (target_sp->Launch (target_sp->GetDebugger().GetListener(), launch_info)); + error.SetError (target_sp->Launch (launch_info, NULL)); sb_process.SetSP(target_sp->GetProcessSP()); } else @@ -1000,7 +1040,7 @@ SBTarget::AttachToProcessWithID // If we are doing synchronous mode, then wait for the // process to stop! if (target_sp->GetDebugger().GetAsyncExecution () == false) - process_sp->WaitForProcessToStop (NULL); + process_sp->WaitForProcessToStop (NULL); } } else @@ -1227,6 +1267,22 @@ SBTarget::ResolveLoadAddress (lldb::addr_t vm_addr) return sb_addr; } +lldb::SBAddress +SBTarget::ResolveFileAddress (lldb::addr_t file_addr) +{ + lldb::SBAddress sb_addr; + Address &addr = sb_addr.ref(); + TargetSP target_sp(GetSP()); + if (target_sp) + { + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + if (target_sp->ResolveFileAddress (file_addr, addr)) + return sb_addr; + } + + addr.SetRawAddress(file_addr); + return sb_addr; +} lldb::SBAddress SBTarget::ResolvePastLoadAddress (uint32_t stop_id, lldb::addr_t vm_addr) @@ -1261,6 +1317,27 @@ SBTarget::ResolveSymbolContextForAddress (const SBAddress& addr, return sc; } +size_t +SBTarget::ReadMemory (const SBAddress addr, + void *buf, + size_t size, + lldb::SBError &error) +{ + SBError sb_error; + size_t bytes_read = 0; + TargetSP target_sp(GetSP()); + if (target_sp) + { + Mutex::Locker api_locker (target_sp->GetAPIMutex()); + bytes_read = target_sp->ReadMemory(addr.ref(), false, buf, size, sb_error.ref()); + } + else + { + sb_error.SetErrorString("invalid target"); + } + + return bytes_read; +} SBBreakpoint SBTarget::BreakpointCreateByLocation (const char *file, @@ -1868,30 +1945,10 @@ SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type) lldb::ValueObjectSP new_value_sp; if (IsValid() && name && *name && addr.IsValid() && type.IsValid()) { - lldb::addr_t address(addr.GetLoadAddress(*this)); - lldb::TypeImplSP type_impl_sp (type.GetSP()); - ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(true).GetPointerType ()); - if (pointer_ast_type) - { - lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); - - ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); - ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), - pointer_ast_type, - ConstString(name), - buffer, - exe_ctx.GetByteOrder(), - exe_ctx.GetAddressByteSize())); - - if (ptr_result_valobj_sp) - { - ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); - Error err; - new_value_sp = ptr_result_valobj_sp->Dereference(err); - if (new_value_sp) - new_value_sp->SetName(ConstString(name)); - } - } + lldb::addr_t load_addr(addr.GetLoadAddress(*this)); + ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); + ClangASTType ast_type(type.GetSP()->GetClangASTType(true)); + new_value_sp = ValueObject::CreateValueObjectFromAddress(name, load_addr, exe_ctx, ast_type); } sb_value.SetSP(new_value_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -1908,6 +1965,58 @@ SBTarget::CreateValueFromAddress (const char *name, SBAddress addr, SBType type) return sb_value; } +lldb::SBValue +SBTarget::CreateValueFromData (const char *name, lldb::SBData data, lldb::SBType type) +{ + SBValue sb_value; + lldb::ValueObjectSP new_value_sp; + if (IsValid() && name && *name && data.IsValid() && type.IsValid()) + { + DataExtractorSP extractor(*data); + ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); + ClangASTType ast_type(type.GetSP()->GetClangASTType(true)); + new_value_sp = ValueObject::CreateValueObjectFromData(name, *extractor, exe_ctx, ast_type); + } + sb_value.SetSP(new_value_sp); + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) + { + if (new_value_sp) + log->Printf ("SBTarget(%p)::CreateValueFromData => \"%s\"", + static_cast<void*>(m_opaque_sp.get()), + new_value_sp->GetName().AsCString()); + else + log->Printf ("SBTarget(%p)::CreateValueFromData => NULL", + static_cast<void*>(m_opaque_sp.get())); + } + return sb_value; +} + +lldb::SBValue +SBTarget::CreateValueFromExpression (const char *name, const char* expr) +{ + SBValue sb_value; + lldb::ValueObjectSP new_value_sp; + if (IsValid() && name && *name && expr && *expr) + { + ExecutionContext exe_ctx (ExecutionContextRef(ExecutionContext(m_opaque_sp.get(),false))); + new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expr, exe_ctx); + } + sb_value.SetSP(new_value_sp); + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) + { + if (new_value_sp) + log->Printf ("SBTarget(%p)::CreateValueFromExpression => \"%s\"", + static_cast<void*>(m_opaque_sp.get()), + new_value_sp->GetName().AsCString()); + else + log->Printf ("SBTarget(%p)::CreateValueFromExpression => NULL", + static_cast<void*>(m_opaque_sp.get())); + } + return sb_value; +} + bool SBTarget::DeleteAllWatchpoints () { @@ -2057,6 +2166,28 @@ SBTarget::GetTriple () } uint32_t +SBTarget::GetDataByteSize () +{ + TargetSP target_sp(GetSP()); + if (target_sp) + { + return target_sp->GetArchitecture().GetDataByteSize() ; + } + return 0; +} + +uint32_t +SBTarget::GetCodeByteSize () +{ + TargetSP target_sp(GetSP()); + if (target_sp) + { + return target_sp->GetArchitecture().GetCodeByteSize() ; + } + return 0; +} + +uint32_t SBTarget::GetAddressByteSize() { TargetSP target_sp(GetSP()); @@ -2154,6 +2285,34 @@ SBTarget::FindFunctions (const char *name, uint32_t name_type_mask) return sb_sc_list; } +lldb::SBSymbolContextList +SBTarget::FindGlobalFunctions(const char *name, uint32_t max_matches, MatchType matchtype) +{ + lldb::SBSymbolContextList sb_sc_list; + if (name && name[0]) + { + TargetSP target_sp(GetSP()); + if (target_sp) + { + std::string regexstr; + switch (matchtype) + { + case eMatchTypeRegex: + target_sp->GetImages().FindFunctions(RegularExpression(name), true, true, true, *sb_sc_list); + break; + case eMatchTypeStartsWith: + regexstr = llvm::Regex::escape(name) + ".*"; + target_sp->GetImages().FindFunctions(RegularExpression(regexstr.c_str()), true, true, true, *sb_sc_list); + break; + default: + target_sp->GetImages().FindFunctions(ConstString(name), eFunctionNameTypeAny, true, true, true, *sb_sc_list); + break; + } + } + } + return sb_sc_list; +} + lldb::SBType SBTarget::FindFirstType (const char* typename_cstr) { @@ -2188,14 +2347,19 @@ SBTarget::FindFirstType (const char* typename_cstr) if (objc_language_runtime) { - TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor(); + DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); - if (objc_type_vendor) + if (objc_decl_vendor) { - std::vector <ClangASTType> types; + std::vector <clang::NamedDecl *> decls; - if (objc_type_vendor->FindTypes(const_typename, true, 1, types) > 0) - return SBType(types[0]); + if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) + { + if (ClangASTType type = ClangASTContext::GetTypeForDecl(decls[0])) + { + return SBType(type); + } + } } } } @@ -2261,17 +2425,20 @@ SBTarget::FindTypes (const char* typename_cstr) if (objc_language_runtime) { - TypeVendor *objc_type_vendor = objc_language_runtime->GetTypeVendor(); + DeclVendor *objc_decl_vendor = objc_language_runtime->GetDeclVendor(); - if (objc_type_vendor) + if (objc_decl_vendor) { - std::vector <ClangASTType> types; + std::vector <clang::NamedDecl *> decls; - if (objc_type_vendor->FindTypes(const_typename, true, UINT32_MAX, types)) + if (objc_decl_vendor->FindDecls(const_typename, true, 1, decls) > 0) { - for (ClangASTType &type : types) + for (clang::NamedDecl *decl : decls) { - sb_type_list.Append(SBType(type)); + if (ClangASTType type = ClangASTContext::GetTypeForDecl(decl)) + { + sb_type_list.Append(SBType(type)); + } } } } @@ -2321,6 +2488,61 @@ SBTarget::FindGlobalVariables (const char *name, uint32_t max_matches) return sb_value_list; } +SBValueList +SBTarget::FindGlobalVariables(const char *name, uint32_t max_matches, MatchType matchtype) +{ + SBValueList sb_value_list; + + TargetSP target_sp(GetSP()); + if (name && target_sp) + { + VariableList variable_list; + const bool append = true; + + std::string regexstr; + uint32_t match_count; + switch (matchtype) + { + case eMatchTypeNormal: + match_count = target_sp->GetImages().FindGlobalVariables(ConstString(name), + append, + max_matches, + variable_list); + break; + case eMatchTypeRegex: + match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(name), + append, + max_matches, + variable_list); + break; + case eMatchTypeStartsWith: + regexstr = llvm::Regex::escape(name) + ".*"; + match_count = target_sp->GetImages().FindGlobalVariables(RegularExpression(regexstr.c_str()), + append, + max_matches, + variable_list); + break; + } + + + if (match_count > 0) + { + ExecutionContextScope *exe_scope = target_sp->GetProcessSP().get(); + if (exe_scope == NULL) + exe_scope = target_sp.get(); + for (uint32_t i = 0; i<match_count; ++i) + { + lldb::ValueObjectSP valobj_sp(ValueObjectVariable::Create(exe_scope, variable_list.GetVariableAtIndex(i))); + if (valobj_sp) + sb_value_list.Append(SBValue(valobj_sp)); + } + } + } + + return sb_value_list; +} + + lldb::SBValue SBTarget::FindFirstGlobalVariable (const char* name) { diff --git a/contrib/llvm/tools/lldb/source/API/SBThread.cpp b/contrib/llvm/tools/lldb/source/API/SBThread.cpp index a0bfa43..6524d10 100644 --- a/contrib/llvm/tools/lldb/source/API/SBThread.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBThread.cpp @@ -41,6 +41,7 @@ #include "lldb/API/SBEvent.h" #include "lldb/API/SBFrame.h" #include "lldb/API/SBProcess.h" +#include "lldb/API/SBThreadPlan.h" #include "lldb/API/SBValue.h" using namespace lldb; @@ -194,6 +195,7 @@ SBThread::GetStopReasonDataCount () case eStopReasonExec: case eStopReasonPlanComplete: case eStopReasonThreadExiting: + case eStopReasonInstrumentation: // There is no data for these stop reasons. return 0; @@ -254,6 +256,7 @@ SBThread::GetStopReasonDataAtIndex (uint32_t idx) case eStopReasonExec: case eStopReasonPlanComplete: case eStopReasonThreadExiting: + case eStopReasonInstrumentation: // There is no data for these stop reasons. return 0; @@ -305,6 +308,26 @@ SBThread::GetStopReasonDataAtIndex (uint32_t idx) return 0; } +bool +SBThread::GetStopReasonExtendedInfoAsJSON (lldb::SBStream &stream) +{ + Stream &strm = stream.ref(); + + ExecutionContext exe_ctx (m_opaque_sp.get()); + if (! exe_ctx.HasThreadScope()) + return false; + + + StopInfoSP stop_info = exe_ctx.GetThreadPtr()->GetStopInfo(); + StructuredData::ObjectSP info = stop_info->GetExtendedInfo(); + if (! info) + return false; + + info->Dump(strm); + + return true; +} + size_t SBThread::GetStopDescription (char *dst, size_t dst_len) { @@ -687,15 +710,11 @@ SBThread::ResumeNewPlan (ExecutionContext &exe_ctx, ThreadPlan *new_plan) // Why do we need to set the current thread by ID here??? process->GetThreadList().SetSelectedThreadByID (thread->GetID()); - sb_error.ref() = process->Resume(); - - if (sb_error.Success()) - { - // If we are doing synchronous mode, then wait for the - // process to stop yet again! - if (process->GetTarget().GetDebugger().GetAsyncExecution () == false) - process->WaitForProcessToStop (NULL); - } + + if (process->GetTarget().GetDebugger().GetAsyncExecution ()) + sb_error.ref() = process->Resume (); + else + sb_error.ref() = process->ResumeSynchronous (NULL); return sb_error; } @@ -918,7 +937,9 @@ SBThread::RunToAddress (lldb::addr_t addr) Thread *thread = exe_ctx.GetThreadPtr(); - ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans, target_addr, stop_other_threads)); + ThreadPlanSP new_plan_sp(thread->QueueThreadPlanForRunToAddress (abort_other_plans, + target_addr, + stop_other_threads)); // This returns an error, we should use it! ResumeNewPlan (exe_ctx, new_plan_sp.get()); @@ -1073,6 +1094,46 @@ SBThread::StepOverUntil (lldb::SBFrame &sb_frame, } SBError +SBThread::StepUsingScriptedThreadPlan (const char *script_class_name) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + SBError sb_error; + + Mutex::Locker api_locker; + ExecutionContext exe_ctx (m_opaque_sp.get(), api_locker); + + if (log) + { + log->Printf ("SBThread(%p)::StepUsingScriptedThreadPlan: class name: %s", + static_cast<void*>(exe_ctx.GetThreadPtr()), + script_class_name); + } + + + if (!exe_ctx.HasThreadScope()) + { + sb_error.SetErrorString("this SBThread object is invalid"); + return sb_error; + } + + Thread *thread = exe_ctx.GetThreadPtr(); + ThreadPlanSP thread_plan_sp = thread->QueueThreadPlanForStepScripted(false, script_class_name, false); + + if (thread_plan_sp) + sb_error = ResumeNewPlan(exe_ctx, thread_plan_sp.get()); + else + { + sb_error.SetErrorStringWithFormat("Error queuing thread plan for class: %s.", script_class_name); + if (log) + log->Printf ("SBThread(%p)::StepUsingScriptedThreadPlan: Error queuing thread plan for class: %s", + static_cast<void*>(exe_ctx.GetThreadPtr()), + script_class_name); + } + + return sb_error; +} + +SBError SBThread::JumpToLine (lldb::SBFileSpec &file_spec, uint32_t line) { Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); @@ -1473,7 +1534,8 @@ SBThread::GetExtendedBacktraceThread (const char *type) const char *queue_name = new_thread_sp->GetQueueName(); if (queue_name == NULL) queue_name = ""; - log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", + log->Printf ("SBThread(%p)::GetExtendedBacktraceThread() => new extended Thread " + "created (%p) with queue_id 0x%" PRIx64 " queue name '%s'", static_cast<void*>(exe_ctx.GetThreadPtr()), static_cast<void*>(new_thread_sp.get()), new_thread_sp->GetQueueID(), @@ -1515,3 +1577,24 @@ SBThread::SafeToCallFunctions () return thread_sp->SafeToCallFunctions(); return true; } + +lldb_private::Thread * +SBThread::operator->() +{ + ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); + if (thread_sp) + return thread_sp.get(); + else + return NULL; +} + +lldb_private::Thread * +SBThread::get() +{ + ThreadSP thread_sp(m_opaque_sp->GetThreadSP()); + if (thread_sp) + return thread_sp.get(); + else + return NULL; +} + diff --git a/contrib/llvm/tools/lldb/source/API/SBThreadCollection.cpp b/contrib/llvm/tools/lldb/source/API/SBThreadCollection.cpp new file mode 100644 index 0000000..841f932 --- /dev/null +++ b/contrib/llvm/tools/lldb/source/API/SBThreadCollection.cpp @@ -0,0 +1,97 @@ +//===-- SBThreadCollection.cpp ----------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/API/SBThreadCollection.h" +#include "lldb/API/SBThread.h" +#include "lldb/Target/ThreadList.h" + +using namespace lldb; +using namespace lldb_private; + + +SBThreadCollection::SBThreadCollection () : + m_opaque_sp() +{ +} + +SBThreadCollection::SBThreadCollection(const SBThreadCollection &rhs) : + m_opaque_sp (rhs.m_opaque_sp) +{ +} + +const SBThreadCollection & +SBThreadCollection::operator = (const SBThreadCollection &rhs) +{ + if (this != &rhs) + m_opaque_sp = rhs.m_opaque_sp; + return *this; +} + +SBThreadCollection::SBThreadCollection (const ThreadCollectionSP &threads) : + m_opaque_sp(threads) +{ +} + +SBThreadCollection::~SBThreadCollection () +{ +} + +void +SBThreadCollection::SetOpaque (const lldb::ThreadCollectionSP &threads) +{ + m_opaque_sp = threads; +} + +lldb_private::ThreadCollection * +SBThreadCollection::get() const +{ + return m_opaque_sp.get(); +} + +lldb_private::ThreadCollection * +SBThreadCollection::operator->() const +{ + return m_opaque_sp.operator->(); +} + +lldb::ThreadCollectionSP & +SBThreadCollection::operator*() +{ + return m_opaque_sp; +} + +const lldb::ThreadCollectionSP & +SBThreadCollection::operator*() const +{ + return m_opaque_sp; +} + + +bool +SBThreadCollection::IsValid () const +{ + return m_opaque_sp.get() != NULL; +} + +size_t +SBThreadCollection::GetSize () +{ + if (m_opaque_sp) + return m_opaque_sp->GetSize(); + return 0; +} + +SBThread +SBThreadCollection::GetThreadAtIndex(size_t idx) +{ + SBThread thread; + if (m_opaque_sp && idx < m_opaque_sp->GetSize()) + thread = m_opaque_sp->GetThreadAtIndex(idx); + return thread; +} diff --git a/contrib/llvm/tools/lldb/source/API/SBThreadPlan.cpp b/contrib/llvm/tools/lldb/source/API/SBThreadPlan.cpp new file mode 100644 index 0000000..02b1a8d --- /dev/null +++ b/contrib/llvm/tools/lldb/source/API/SBThreadPlan.cpp @@ -0,0 +1,285 @@ +//===-- SBThread.cpp --------------------------------------------*- C++ -*-===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// + +#include "lldb/lldb-python.h" + +#include "lldb/API/SBThread.h" + +#include "lldb/API/SBSymbolContext.h" +#include "lldb/API/SBFileSpec.h" +#include "lldb/API/SBStream.h" +#include "lldb/Breakpoint/BreakpointLocation.h" +#include "lldb/Core/Debugger.h" +#include "lldb/Core/State.h" +#include "lldb/Core/Stream.h" +#include "lldb/Core/StreamFile.h" +#include "lldb/Core/StructuredData.h" +#include "lldb/Interpreter/CommandInterpreter.h" +#include "lldb/Target/SystemRuntime.h" +#include "lldb/Target/Thread.h" +#include "lldb/Target/ThreadPlan.h" +#include "lldb/Target/Process.h" +#include "lldb/Target/Queue.h" +#include "lldb/Symbol/SymbolContext.h" +#include "lldb/Symbol/CompileUnit.h" +#include "lldb/Target/StopInfo.h" +#include "lldb/Target/Target.h" +#include "lldb/Target/ThreadPlan.h" +#include "lldb/Target/ThreadPlanPython.h" +#include "lldb/Target/ThreadPlanStepInstruction.h" +#include "lldb/Target/ThreadPlanStepOut.h" +#include "lldb/Target/ThreadPlanStepRange.h" +#include "lldb/Target/ThreadPlanStepInRange.h" + + +#include "lldb/API/SBAddress.h" +#include "lldb/API/SBDebugger.h" +#include "lldb/API/SBEvent.h" +#include "lldb/API/SBFrame.h" +#include "lldb/API/SBProcess.h" +#include "lldb/API/SBThreadPlan.h" +#include "lldb/API/SBValue.h" + +using namespace lldb; +using namespace lldb_private; + +//---------------------------------------------------------------------- +// Constructors +//---------------------------------------------------------------------- +SBThreadPlan::SBThreadPlan () +{ +} + +SBThreadPlan::SBThreadPlan (const ThreadPlanSP& lldb_object_sp) : + m_opaque_sp (lldb_object_sp) +{ +} + +SBThreadPlan::SBThreadPlan (const SBThreadPlan &rhs) : + m_opaque_sp (rhs.m_opaque_sp) +{ + +} + +SBThreadPlan::SBThreadPlan (lldb::SBThread &sb_thread, const char *class_name) +{ + Thread *thread = sb_thread.get(); + if (thread) + m_opaque_sp.reset(new ThreadPlanPython(*thread, class_name)); +} + +//---------------------------------------------------------------------- +// Assignment operator +//---------------------------------------------------------------------- + +const lldb::SBThreadPlan & +SBThreadPlan::operator = (const SBThreadPlan &rhs) +{ + if (this != &rhs) + m_opaque_sp = rhs.m_opaque_sp; + return *this; +} +//---------------------------------------------------------------------- +// Destructor +//---------------------------------------------------------------------- +SBThreadPlan::~SBThreadPlan() +{ +} + +lldb_private::ThreadPlan * +SBThreadPlan::get() +{ + return m_opaque_sp.get(); +} + +bool +SBThreadPlan::IsValid() const +{ + return m_opaque_sp.get() != NULL; +} + +void +SBThreadPlan::Clear () +{ + m_opaque_sp.reset(); +} + +lldb::StopReason +SBThreadPlan::GetStopReason() +{ + return eStopReasonNone; +} + +size_t +SBThreadPlan::GetStopReasonDataCount() +{ + return 0; +} + +uint64_t +SBThreadPlan::GetStopReasonDataAtIndex(uint32_t idx) +{ + return 0; +} + +SBThread +SBThreadPlan::GetThread () const +{ + if (m_opaque_sp) + { + return SBThread(m_opaque_sp->GetThread().shared_from_this()); + } + else + return SBThread(); +} + +bool +SBThreadPlan::GetDescription (lldb::SBStream &description) const +{ + if (m_opaque_sp) + { + m_opaque_sp->GetDescription(description.get(), eDescriptionLevelFull); + } + else + { + description.Printf("Empty SBThreadPlan"); + } + return true; +} + +void +SBThreadPlan::SetThreadPlan (const ThreadPlanSP& lldb_object_sp) +{ + m_opaque_sp = lldb_object_sp; +} + +void +SBThreadPlan::SetPlanComplete (bool success) +{ + if (m_opaque_sp) + m_opaque_sp->SetPlanComplete (success); +} + +bool +SBThreadPlan::IsPlanComplete() +{ + if (m_opaque_sp) + return m_opaque_sp->IsPlanComplete(); + else + return true; +} + +bool +SBThreadPlan::IsValid() +{ + if (m_opaque_sp) + return m_opaque_sp->ValidatePlan(nullptr); + else + return false; +} + + // This section allows an SBThreadPlan to push another of the common types of plans... + // + // FIXME, you should only be able to queue thread plans from inside the methods of a + // Scripted Thread Plan. Need a way to enforce that. + +SBThreadPlan +SBThreadPlan::QueueThreadPlanForStepOverRange (SBAddress &sb_start_address, + lldb::addr_t size) +{ + if (m_opaque_sp) + { + Address *start_address = sb_start_address.get(); + if (!start_address) + { + return SBThreadPlan(); + } + + AddressRange range (*start_address, size); + SymbolContext sc; + start_address->CalculateSymbolContext(&sc); + return SBThreadPlan (m_opaque_sp->GetThread().QueueThreadPlanForStepOverRange (false, + range, + sc, + eAllThreads)); + } + else + { + return SBThreadPlan(); + } +} + +SBThreadPlan +SBThreadPlan::QueueThreadPlanForStepInRange (SBAddress &sb_start_address, + lldb::addr_t size) +{ + if (m_opaque_sp) + { + Address *start_address = sb_start_address.get(); + if (!start_address) + { + return SBThreadPlan(); + } + + AddressRange range (*start_address, size); + SymbolContext sc; + start_address->CalculateSymbolContext(&sc); + return SBThreadPlan (m_opaque_sp->GetThread().QueueThreadPlanForStepInRange (false, + range, + sc, + NULL, + eAllThreads)); + } + else + { + return SBThreadPlan(); + } +} + +SBThreadPlan +SBThreadPlan::QueueThreadPlanForStepOut (uint32_t frame_idx_to_step_to, bool first_insn) +{ + if (m_opaque_sp) + { + SymbolContext sc; + sc = m_opaque_sp->GetThread().GetStackFrameAtIndex(0)->GetSymbolContext(lldb::eSymbolContextEverything); + return SBThreadPlan (m_opaque_sp->GetThread().QueueThreadPlanForStepOut (false, + &sc, + first_insn, + false, + eVoteYes, + eVoteNoOpinion, + frame_idx_to_step_to)); + } + else + { + return SBThreadPlan(); + } +} + +SBThreadPlan +SBThreadPlan::QueueThreadPlanForRunToAddress (SBAddress sb_address) +{ + if (m_opaque_sp) + { + Address *address = sb_address.get(); + if (!address) + return SBThreadPlan(); + + return SBThreadPlan (m_opaque_sp->GetThread().QueueThreadPlanForRunToAddress (false, + *address, + false)); + } + else + { + return SBThreadPlan(); + } +} + + diff --git a/contrib/llvm/tools/lldb/source/API/SBType.cpp b/contrib/llvm/tools/lldb/source/API/SBType.cpp index 064fb32..8a0f5d8 100644 --- a/contrib/llvm/tools/lldb/source/API/SBType.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBType.cpp @@ -156,6 +156,14 @@ SBType::IsPointerType() } bool +SBType::IsArrayType() +{ + if (!IsValid()) + return false; + return m_opaque_sp->GetClangASTType(true).IsArrayType(nullptr, nullptr, nullptr); +} + +bool SBType::IsReferenceType() { if (!IsValid()) @@ -204,6 +212,14 @@ SBType::GetDereferencedType() return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetDereferencedType()))); } +SBType +SBType::GetArrayElementType() +{ + if (!IsValid()) + return SBType(); + return SBType(TypeImplSP(new TypeImpl(m_opaque_sp->GetClangASTType(true).GetArrayElementType()))); +} + bool SBType::IsFunctionType () { @@ -220,7 +236,13 @@ SBType::IsPolymorphicClass () return m_opaque_sp->GetClangASTType(true).IsPolymorphicClass(); } - +bool +SBType::IsTypedefType () +{ + if (!IsValid()) + return false; + return m_opaque_sp->GetClangASTType(true).IsTypedefType(); +} lldb::SBType SBType::GetFunctionReturnType () @@ -252,6 +274,25 @@ SBType::GetFunctionArgumentTypes () return sb_type_list; } +uint32_t +SBType::GetNumberOfMemberFunctions () +{ + if (IsValid()) + { + return m_opaque_sp->GetClangASTType(true).GetNumMemberFunctions(); + } + return 0; +} + +lldb::SBTypeMemberFunction +SBType::GetMemberFunctionAtIndex (uint32_t idx) +{ + SBTypeMemberFunction sb_func_type; + if (IsValid()) + sb_func_type.reset(new TypeMemberFunctionImpl(m_opaque_sp->GetClangASTType(true).GetMemberFunctionAtIndex(idx))); + return sb_func_type; +} + lldb::SBType SBType::GetUnqualifiedType() { @@ -305,7 +346,7 @@ uint32_t SBType::GetNumberOfFields () { if (IsValid()) - return m_opaque_sp->GetClangASTType(false).GetNumFields(); + return m_opaque_sp->GetClangASTType(true).GetNumFields(); return 0; } @@ -430,6 +471,14 @@ SBType::IsTypeComplete() return m_opaque_sp->GetClangASTType(false).IsCompleteType(); } +uint32_t +SBType::GetTypeFlags () +{ + if (!IsValid()) + return 0; + return m_opaque_sp->GetClangASTType(true).GetTypeInfo(); +} + const char* SBType::GetName() { @@ -450,7 +499,7 @@ lldb::TypeClass SBType::GetTypeClass () { if (IsValid()) - return m_opaque_sp->GetClangASTType(false).GetTypeClass(); + return m_opaque_sp->GetClangASTType(true).GetTypeClass(); return lldb::eTypeClassInvalid; } @@ -684,3 +733,121 @@ SBTypeMember::ref () const { return *m_opaque_ap.get(); } + +SBTypeMemberFunction::SBTypeMemberFunction() : +m_opaque_sp() +{ +} + +SBTypeMemberFunction::~SBTypeMemberFunction() +{ +} + +SBTypeMemberFunction::SBTypeMemberFunction (const SBTypeMemberFunction& rhs) : + m_opaque_sp(rhs.m_opaque_sp) +{ +} + +lldb::SBTypeMemberFunction& +SBTypeMemberFunction::operator = (const lldb::SBTypeMemberFunction& rhs) +{ + if (this != &rhs) + m_opaque_sp = rhs.m_opaque_sp; + return *this; +} + +bool +SBTypeMemberFunction::IsValid() const +{ + return m_opaque_sp.get(); +} + +const char * +SBTypeMemberFunction::GetName () +{ + if (m_opaque_sp) + return m_opaque_sp->GetName().GetCString(); + return NULL; +} + +SBType +SBTypeMemberFunction::GetType () +{ + SBType sb_type; + if (m_opaque_sp) + { + sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetType()))); + } + return sb_type; +} + +lldb::SBType +SBTypeMemberFunction::GetReturnType () +{ + SBType sb_type; + if (m_opaque_sp) + { + sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetReturnType()))); + } + return sb_type; +} + +uint32_t +SBTypeMemberFunction::GetNumberOfArguments () +{ + if (m_opaque_sp) + return m_opaque_sp->GetNumArguments(); + return 0; +} + +lldb::SBType +SBTypeMemberFunction::GetArgumentTypeAtIndex (uint32_t i) +{ + SBType sb_type; + if (m_opaque_sp) + { + sb_type.SetSP(lldb::TypeImplSP(new TypeImpl(m_opaque_sp->GetArgumentAtIndex(i)))); + } + return sb_type; +} + +lldb::MemberFunctionKind +SBTypeMemberFunction::GetKind () +{ + if (m_opaque_sp) + return m_opaque_sp->GetKind(); + return lldb::eMemberFunctionKindUnknown; + +} + +bool +SBTypeMemberFunction::GetDescription (lldb::SBStream &description, + lldb::DescriptionLevel description_level) +{ + Stream &strm = description.ref(); + + if (m_opaque_sp) + return m_opaque_sp->GetDescription(strm); + + return false; +} + +void +SBTypeMemberFunction::reset(TypeMemberFunctionImpl *type_member_impl) +{ + m_opaque_sp.reset(type_member_impl); +} + +TypeMemberFunctionImpl & +SBTypeMemberFunction::ref () +{ + if (!m_opaque_sp) + m_opaque_sp.reset (new TypeMemberFunctionImpl()); + return *m_opaque_sp.get(); +} + +const TypeMemberFunctionImpl & +SBTypeMemberFunction::ref () const +{ + return *m_opaque_sp.get(); +} diff --git a/contrib/llvm/tools/lldb/source/API/SBTypeSummary.cpp b/contrib/llvm/tools/lldb/source/API/SBTypeSummary.cpp index aaa09c2..8a235bf 100644 --- a/contrib/llvm/tools/lldb/source/API/SBTypeSummary.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBTypeSummary.cpp @@ -20,6 +20,103 @@ using namespace lldb_private; #ifndef LLDB_DISABLE_PYTHON +SBTypeSummaryOptions::SBTypeSummaryOptions() +{ + m_opaque_ap.reset(new TypeSummaryOptions()); +} + +SBTypeSummaryOptions::SBTypeSummaryOptions (const lldb::SBTypeSummaryOptions &rhs) +{ + if (rhs.m_opaque_ap) + m_opaque_ap.reset(new TypeSummaryOptions(*rhs.m_opaque_ap.get())); + else + m_opaque_ap.reset(new TypeSummaryOptions()); +} + +SBTypeSummaryOptions::~SBTypeSummaryOptions () +{ +} + +bool +SBTypeSummaryOptions::IsValid() +{ + return m_opaque_ap.get(); +} + +lldb::LanguageType +SBTypeSummaryOptions::GetLanguage () +{ + if (IsValid()) + return m_opaque_ap->GetLanguage(); + return lldb::eLanguageTypeUnknown; +} + +lldb::TypeSummaryCapping +SBTypeSummaryOptions::GetCapping () +{ + if (IsValid()) + return m_opaque_ap->GetCapping(); + return eTypeSummaryCapped; +} + +void +SBTypeSummaryOptions::SetLanguage (lldb::LanguageType l) +{ + if (IsValid()) + m_opaque_ap->SetLanguage(l); +} + +void +SBTypeSummaryOptions::SetCapping (lldb::TypeSummaryCapping c) +{ + if (IsValid()) + m_opaque_ap->SetCapping(c); +} + +lldb_private::TypeSummaryOptions * +SBTypeSummaryOptions::operator->() +{ + return m_opaque_ap.get(); +} + +const lldb_private::TypeSummaryOptions * +SBTypeSummaryOptions::operator->() const +{ + return m_opaque_ap.get(); +} + +lldb_private::TypeSummaryOptions * +SBTypeSummaryOptions::get () +{ + return m_opaque_ap.get(); +} + +lldb_private::TypeSummaryOptions & +SBTypeSummaryOptions::ref() +{ + return *m_opaque_ap.get(); +} + +const lldb_private::TypeSummaryOptions & +SBTypeSummaryOptions::ref() const +{ + return *m_opaque_ap.get(); +} + +SBTypeSummaryOptions::SBTypeSummaryOptions (const lldb_private::TypeSummaryOptions *lldb_object_ptr) +{ + SetOptions(lldb_object_ptr); +} + +void +SBTypeSummaryOptions::SetOptions (const lldb_private::TypeSummaryOptions *lldb_object_ptr) +{ + if (lldb_object_ptr) + m_opaque_ap.reset(new TypeSummaryOptions(*lldb_object_ptr)); + else + m_opaque_ap.reset(new TypeSummaryOptions()); +} + SBTypeSummary::SBTypeSummary() : m_opaque_sp() { diff --git a/contrib/llvm/tools/lldb/source/API/SBValue.cpp b/contrib/llvm/tools/lldb/source/API/SBValue.cpp index 3a9621b..0d3d7ad 100644 --- a/contrib/llvm/tools/lldb/source/API/SBValue.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBValue.cpp @@ -543,6 +543,36 @@ SBValue::GetObjectDescription () return cstr; } +const char * +SBValue::GetTypeValidatorResult () +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + const char *cstr = NULL; + ValueLocker locker; + lldb::ValueObjectSP value_sp(GetSP(locker)); + if (value_sp) + { + const auto& validation(value_sp->GetValidationStatus()); + if (TypeValidatorResult::Failure == validation.first) + { + if (validation.second.empty()) + cstr = "unknown error"; + else + cstr = validation.second.c_str(); + } + } + if (log) + { + if (cstr) + log->Printf ("SBValue(%p)::GetTypeValidatorResult() => \"%s\"", + static_cast<void*>(value_sp.get()), cstr); + else + log->Printf ("SBValue(%p)::GetTypeValidatorResult() => NULL", + static_cast<void*>(value_sp.get())); + } + return cstr; +} + SBType SBValue::GetType() { @@ -610,6 +640,32 @@ SBValue::GetSummary () } return cstr; } + +const char * +SBValue::GetSummary (lldb::SBStream& stream, + lldb::SBTypeSummaryOptions& options) +{ + Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + ValueLocker locker; + lldb::ValueObjectSP value_sp(GetSP(locker)); + if (value_sp) + { + std::string buffer; + if (value_sp->GetSummaryAsCString(buffer,options.ref()) && !buffer.empty()) + stream.Printf("%s",buffer.c_str()); + } + const char* cstr = stream.GetData(); + if (log) + { + if (cstr) + log->Printf ("SBValue(%p)::GetSummary() => \"%s\"", + static_cast<void*>(value_sp.get()), cstr); + else + log->Printf ("SBValue(%p)::GetSummary() => NULL", + static_cast<void*>(value_sp.get())); + } + return cstr; +} #endif // LLDB_DISABLE_PYTHON const char * @@ -808,21 +864,11 @@ SBValue::CreateValueFromExpression (const char *name, const char *expression, SB if (value_sp) { ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); - Target* target = exe_ctx.GetTargetPtr(); - if (target) - { - options.ref().SetKeepInMemory(true); - target->EvaluateExpression (expression, - exe_ctx.GetFramePtr(), - new_value_sp, - options.ref()); - if (new_value_sp) - { - new_value_sp->SetName(ConstString(name)); - sb_value.SetSP(new_value_sp); - } - } + new_value_sp = ValueObject::CreateValueObjectFromExpression(name, expression, exe_ctx, options.ref()); + if (new_value_sp) + new_value_sp->SetName(ConstString(name)); } + sb_value.SetSP(new_value_sp); if (log) { if (new_value_sp) @@ -846,30 +892,11 @@ SBValue::CreateValueFromAddress(const char* name, lldb::addr_t address, SBType s lldb::TypeImplSP type_impl_sp (sb_type.GetSP()); if (value_sp && type_impl_sp) { - ClangASTType pointer_ast_type(type_impl_sp->GetClangASTType(false).GetPointerType ()); - if (pointer_ast_type) - { - lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(&address,sizeof(lldb::addr_t))); - - ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); - ValueObjectSP ptr_result_valobj_sp(ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), - pointer_ast_type, - ConstString(name), - buffer, - exe_ctx.GetByteOrder(), - exe_ctx.GetAddressByteSize())); - - if (ptr_result_valobj_sp) - { - ptr_result_valobj_sp->GetValue().SetValueType(Value::eValueTypeLoadAddress); - Error err; - new_value_sp = ptr_result_valobj_sp->Dereference(err); - if (new_value_sp) - new_value_sp->SetName(ConstString(name)); - } - sb_value.SetSP(new_value_sp); - } + ClangASTType ast_type(type_impl_sp->GetClangASTType(true)); + ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); + new_value_sp = ValueObject::CreateValueObjectFromAddress(name, address, exe_ctx, ast_type); } + sb_value.SetSP(new_value_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { @@ -894,15 +921,10 @@ SBValue::CreateValueFromData (const char* name, SBData data, SBType type) if (value_sp) { ExecutionContext exe_ctx (value_sp->GetExecutionContextRef()); - - new_value_sp = ValueObjectConstResult::Create (exe_ctx.GetBestExecutionContextScope(), - type.m_opaque_sp->GetClangASTType(false), - ConstString(name), - *data.m_opaque_sp, - LLDB_INVALID_ADDRESS); + new_value_sp = ValueObject::CreateValueObjectFromData(name, **data, exe_ctx, type.GetSP()->GetClangASTType(true)); new_value_sp->SetAddressTypeOfChildren(eAddressTypeLoad); - sb_value.SetSP(new_value_sp); } + sb_value.SetSP(new_value_sp); Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); if (log) { @@ -1836,3 +1858,16 @@ SBValue::WatchPointee (bool resolve_location, bool read, bool write, SBError &er sb_watchpoint = Dereference().Watch (resolve_location, read, write, error); return sb_watchpoint; } + +lldb::SBValue +SBValue::Persist () +{ + ValueLocker locker; + lldb::ValueObjectSP value_sp(GetSP(locker)); + SBValue persisted_sb; + if (value_sp) + { + persisted_sb.SetSP(value_sp->Persist()); + } + return persisted_sb; +} diff --git a/contrib/llvm/tools/lldb/source/API/SBValueList.cpp b/contrib/llvm/tools/lldb/source/API/SBValueList.cpp index 5069ed3..71fabe0 100644 --- a/contrib/llvm/tools/lldb/source/API/SBValueList.cpp +++ b/contrib/llvm/tools/lldb/source/API/SBValueList.cpp @@ -78,6 +78,21 @@ public: } return lldb::SBValue(); } + + lldb::SBValue + GetFirstValueByName (const char* name) const + { + if (name) + { + for (auto val : m_values) + { + if (val.IsValid() && val.GetName() && + strcmp(name,val.GetName()) == 0) + return val; + } + } + return lldb::SBValue(); + } private: std::vector<lldb::SBValue> m_values; @@ -261,6 +276,15 @@ SBValueList::FindValueObjectByUID (lldb::user_id_t uid) return sb_value; } +SBValue +SBValueList::GetFirstValueByName (const char* name) const +{ + SBValue sb_value; + if (m_opaque_ap.get()) + sb_value = m_opaque_ap->GetFirstValueByName(name); + return sb_value; +} + void * SBValueList::opaque_ptr () { |