diff options
Diffstat (limited to 'source')
1182 files changed, 383863 insertions, 409297 deletions
diff --git a/source/API/CMakeLists.txt b/source/API/CMakeLists.txt index 2ed42cac062e..7e1e66bee3b2 100644 --- a/source/API/CMakeLists.txt +++ b/source/API/CMakeLists.txt @@ -6,6 +6,16 @@ endif() # for liblldb to link against include(${LLDB_PROJECT_ROOT}/cmake/LLDBDependencies.cmake) +option(LLDB_BUILD_FRAMEWORK "Build the Darwin LLDB.framework" Off) + +if(LLDB_BUILD_FRAMEWORK AND CMAKE_VERSION VERSION_LESS 3.7) + message(FATAL_ERROR "LLDB_BUILD_FRAMEWORK is not supported on CMake < 3.7") +endif() + +if (LLDB_BUILD_FRAMEWORK AND NOT APPLE) + message(FATAL_ERROR "LLDB.framework cannot be generated unless targeting Apple platforms.") +endif() + add_lldb_library(liblldb SHARED SBAddress.cpp SBAttachInfo.cpp @@ -47,6 +57,7 @@ add_lldb_library(liblldb SHARED SBSourceManager.cpp SBStream.cpp SBStringList.cpp + SBStructuredData.cpp SBSymbol.cpp SBSymbolContext.cpp SBSymbolContextList.cpp @@ -71,6 +82,14 @@ add_lldb_library(liblldb SHARED ${LLDB_WRAP_PYTHON} ) +if (LLVM_ENABLE_WERROR) + if (MSVC) + set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " /W0") + else() + set_property(SOURCE ${LLDB_WRAP_PYTHON} APPEND_STRING PROPERTY COMPILE_FLAGS " -w") + endif() +endif() + # This should not be part of LLDBDependencies.cmake, because we don't # want every single library taking a dependency on the script interpreters. target_link_libraries(liblldb PRIVATE @@ -88,16 +107,13 @@ if (NOT CMAKE_SYSTEM_NAME MATCHES "Windows") # If we're not exporting all symbols, we'll want to explicitly set # the exported symbols here. This prevents 'log enable --stack ...' # from working on some systems but limits the liblldb size. - MESSAGE("-- Symbols (liblldb): only exporting liblldb.exports symbols") + MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb namespace") add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb.exports) else() # Don't use an explicit export. Instead, tell the linker to # export all symbols. - MESSAGE("-- Symbols (liblldb): exporting all symbols") - # Darwin linker doesn't need this extra step. - if (NOT CMAKE_SYSTEM_NAME MATCHES "Darwin") - lldb_append_link_flags(liblldb "-Wl,--export-dynamic") - endif() + MESSAGE("-- Symbols (liblldb): exporting all symbols from the lldb and lldb_private namespaces") + add_llvm_symbol_exports(liblldb ${CMAKE_CURRENT_SOURCE_DIR}/liblldb-private.exports) endif() endif() @@ -117,5 +133,22 @@ endif() if (LLDB_WRAP_PYTHON) add_dependencies(liblldb swig_wrapper) endif() -target_link_libraries(liblldb ${cmake_2_8_12_PRIVATE} ${LLDB_SYSTEM_LIBS}) +target_link_libraries(liblldb PRIVATE ${LLDB_SYSTEM_LIBS}) + +if(LLDB_BUILD_FRAMEWORK) + file(GLOB public_headers ${LLDB_SOURCE_DIR}/include/lldb/API/*.h) + set_target_properties(liblldb PROPERTIES + OUTPUT_NAME LLDB + FRAMEWORK On + FRAMEWORK_VERSION ${LLDB_FRAMEWORK_VERSION} + LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR} + PUBLIC_HEADER "${public_headers}") + + add_custom_command(TARGET liblldb POST_BUILD + COMMAND ${CMAKE_COMMAND} -E make_directory $<TARGET_FILE_DIR:liblldb>/Versions/${LLDB_FRAMEWORK_VERSION} + COMMAND ${CMAKE_COMMAND} -E copy_directory ${LLDB_SOURCE_DIR}/include/lldb/API $<TARGET_FILE_DIR:liblldb>/Headers + COMMAND ${CMAKE_COMMAND} -E create_symlink Versions/Current/Headers ${CMAKE_BINARY_DIR}/${LLDB_FRAMEWORK_INSTALL_DIR}/LLDB.framework/Headers + COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_BINARY_DIR}/lib${LLVM_LIBDIR_SUFFIX}/clang/${LLDB_VERSION} $<TARGET_FILE_DIR:liblldb>/Resources/Clang + ) +endif() diff --git a/source/API/SBAddress.cpp b/source/API/SBAddress.cpp index 470ea5659f28..0ef374f47a92 100644 --- a/source/API/SBAddress.cpp +++ b/source/API/SBAddress.cpp @@ -18,312 +18,227 @@ #include "lldb/Symbol/LineEntry.h" #include "lldb/Target/Target.h" - using namespace lldb; using namespace lldb_private; +SBAddress::SBAddress() : m_opaque_ap(new Address()) {} -SBAddress::SBAddress () : - m_opaque_ap (new Address()) -{ -} - -SBAddress::SBAddress (const Address *lldb_object_ptr) : - m_opaque_ap (new Address()) -{ - if (lldb_object_ptr) - ref() = *lldb_object_ptr; +SBAddress::SBAddress(const Address *lldb_object_ptr) + : m_opaque_ap(new Address()) { + if (lldb_object_ptr) + ref() = *lldb_object_ptr; } -SBAddress::SBAddress (const SBAddress &rhs) : - m_opaque_ap (new Address()) -{ - if (rhs.IsValid()) - ref() = rhs.ref(); +SBAddress::SBAddress(const SBAddress &rhs) : m_opaque_ap(new Address()) { + if (rhs.IsValid()) + ref() = rhs.ref(); } - -SBAddress::SBAddress (lldb::SBSection section, lldb::addr_t offset) : - m_opaque_ap(new Address (section.GetSP(), offset)) -{ -} +SBAddress::SBAddress(lldb::SBSection section, lldb::addr_t offset) + : m_opaque_ap(new Address(section.GetSP(), 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(new Address()) -{ - SetLoadAddress (load_addr, target); +SBAddress::SBAddress(lldb::addr_t load_addr, lldb::SBTarget &target) + : m_opaque_ap(new Address()) { + SetLoadAddress(load_addr, target); } +SBAddress::~SBAddress() {} - -SBAddress::~SBAddress () -{ -} - -const SBAddress & -SBAddress::operator = (const SBAddress &rhs) -{ - if (this != &rhs) - { - if (rhs.IsValid()) - ref() = rhs.ref(); - else - m_opaque_ap.reset (new Address()); - } - return *this; +const SBAddress &SBAddress::operator=(const SBAddress &rhs) { + if (this != &rhs) { + if (rhs.IsValid()) + ref() = rhs.ref(); + else + m_opaque_ap.reset(new Address()); + } + return *this; } -bool -SBAddress::IsValid () const -{ - return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid(); +bool SBAddress::IsValid() const { + return m_opaque_ap.get() != NULL && m_opaque_ap->IsValid(); } -void -SBAddress::Clear () -{ - m_opaque_ap.reset (new Address()); -} +void SBAddress::Clear() { m_opaque_ap.reset(new Address()); } -void -SBAddress::SetAddress (lldb::SBSection section, lldb::addr_t offset) -{ - Address &addr = ref(); - addr.SetSection (section.GetSP()); - addr.SetOffset (offset); +void SBAddress::SetAddress(lldb::SBSection section, lldb::addr_t offset) { + Address &addr = ref(); + addr.SetSection(section.GetSP()); + addr.SetOffset(offset); } - -void -SBAddress::SetAddress (const Address *lldb_object_ptr) -{ - if (lldb_object_ptr) - ref() = *lldb_object_ptr; - else - m_opaque_ap.reset (new Address()); +void SBAddress::SetAddress(const Address *lldb_object_ptr) { + if (lldb_object_ptr) + ref() = *lldb_object_ptr; + else + m_opaque_ap.reset(new Address()); } -lldb::addr_t -SBAddress::GetFileAddress () const -{ - if (m_opaque_ap->IsValid()) - return m_opaque_ap->GetFileAddress(); - else - return LLDB_INVALID_ADDRESS; +lldb::addr_t SBAddress::GetFileAddress() const { + if (m_opaque_ap->IsValid()) + return m_opaque_ap->GetFileAddress(); + else + return LLDB_INVALID_ADDRESS; } -lldb::addr_t -SBAddress::GetLoadAddress (const SBTarget &target) const -{ - Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - lldb::addr_t addr = LLDB_INVALID_ADDRESS; - TargetSP target_sp (target.GetSP()); - if (target_sp) - { - if (m_opaque_ap->IsValid()) - { - std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); - addr = m_opaque_ap->GetLoadAddress (target_sp.get()); - } - } +lldb::addr_t SBAddress::GetLoadAddress(const SBTarget &target) const { + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - { - if (addr == LLDB_INVALID_ADDRESS) - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", - static_cast<void*>(target_sp.get())); - else - log->Printf ("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%" PRIx64, - static_cast<void*>(target_sp.get()), addr); + lldb::addr_t addr = LLDB_INVALID_ADDRESS; + TargetSP target_sp(target.GetSP()); + if (target_sp) { + if (m_opaque_ap->IsValid()) { + std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); + addr = m_opaque_ap->GetLoadAddress(target_sp.get()); } + } - return addr; -} - -void -SBAddress::SetLoadAddress (lldb::addr_t load_addr, lldb::SBTarget &target) -{ - // Create the address object if we don't already have one - ref(); - if (target.IsValid()) - *this = target.ResolveLoadAddress(load_addr); + if (log) { + if (addr == LLDB_INVALID_ADDRESS) + log->Printf( + "SBAddress::GetLoadAddress (SBTarget(%p)) => LLDB_INVALID_ADDRESS", + static_cast<void *>(target_sp.get())); else - m_opaque_ap->Clear(); - - // Check if we weren't were able to resolve a section offset address. - // If we weren't it is ok, the load address might be a location on the - // stack or heap, so we should just have an address with no section and - // a valid offset - if (!m_opaque_ap->IsValid()) - m_opaque_ap->SetOffset(load_addr); -} - -bool -SBAddress::OffsetAddress (addr_t offset) -{ - if (m_opaque_ap->IsValid()) - { - addr_t addr_offset = m_opaque_ap->GetOffset(); - if (addr_offset != LLDB_INVALID_ADDRESS) - { - m_opaque_ap->SetOffset(addr_offset + offset); - return true; - } + log->Printf("SBAddress::GetLoadAddress (SBTarget(%p)) => 0x%" PRIx64, + static_cast<void *>(target_sp.get()), addr); + } + + return addr; +} + +void SBAddress::SetLoadAddress(lldb::addr_t load_addr, lldb::SBTarget &target) { + // Create the address object if we don't already have one + ref(); + if (target.IsValid()) + *this = target.ResolveLoadAddress(load_addr); + else + m_opaque_ap->Clear(); + + // Check if we weren't were able to resolve a section offset address. + // If we weren't it is ok, the load address might be a location on the + // stack or heap, so we should just have an address with no section and + // a valid offset + if (!m_opaque_ap->IsValid()) + m_opaque_ap->SetOffset(load_addr); +} + +bool SBAddress::OffsetAddress(addr_t offset) { + if (m_opaque_ap->IsValid()) { + addr_t addr_offset = m_opaque_ap->GetOffset(); + if (addr_offset != LLDB_INVALID_ADDRESS) { + m_opaque_ap->SetOffset(addr_offset + offset); + return true; } - return false; + } + return false; } -lldb::SBSection -SBAddress::GetSection () -{ - lldb::SBSection sb_section; - if (m_opaque_ap->IsValid()) - sb_section.SetSP (m_opaque_ap->GetSection()); - return sb_section; +lldb::SBSection SBAddress::GetSection() { + lldb::SBSection sb_section; + if (m_opaque_ap->IsValid()) + sb_section.SetSP(m_opaque_ap->GetSection()); + return sb_section; } -lldb::addr_t -SBAddress::GetOffset () -{ - if (m_opaque_ap->IsValid()) - return m_opaque_ap->GetOffset(); - return 0; +lldb::addr_t SBAddress::GetOffset() { + if (m_opaque_ap->IsValid()) + return m_opaque_ap->GetOffset(); + return 0; } -Address * -SBAddress::operator->() -{ - return m_opaque_ap.get(); -} +Address *SBAddress::operator->() { return m_opaque_ap.get(); } -const Address * -SBAddress::operator->() const -{ - return m_opaque_ap.get(); -} +const Address *SBAddress::operator->() const { return m_opaque_ap.get(); } -Address & -SBAddress::ref () -{ - if (m_opaque_ap.get() == NULL) - m_opaque_ap.reset (new Address()); - return *m_opaque_ap; +Address &SBAddress::ref() { + if (m_opaque_ap.get() == NULL) + m_opaque_ap.reset(new Address()); + return *m_opaque_ap; } -const Address & -SBAddress::ref () const -{ - // This object should already have checked with "IsValid()" - // prior to calling this function. In case you didn't we will assert - // and die to let you know. - assert (m_opaque_ap.get()); - return *m_opaque_ap; +const Address &SBAddress::ref() const { + // This object should already have checked with "IsValid()" + // prior to calling this function. In case you didn't we will assert + // and die to let you know. + assert(m_opaque_ap.get()); + return *m_opaque_ap; } -Address * -SBAddress::get () -{ - return m_opaque_ap.get(); -} +Address *SBAddress::get() { return m_opaque_ap.get(); } -bool -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->IsValid()) - { - m_opaque_ap->Dump (&strm, - NULL, - Address::DumpStyleResolvedDescription, - Address::DumpStyleModuleWithFileAddress, - 4); - StreamString sstrm; -// m_opaque_ap->Dump (&sstrm, NULL, Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid, 4); -// if (sstrm.GetData()) -// strm.Printf (" (%s)", sstrm.GetData()); - } - else - strm.PutCString ("No value"); +bool 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->IsValid()) { + m_opaque_ap->Dump(&strm, NULL, Address::DumpStyleResolvedDescription, + Address::DumpStyleModuleWithFileAddress, 4); + StreamString sstrm; + // m_opaque_ap->Dump (&sstrm, NULL, + // Address::DumpStyleResolvedDescription, Address::DumpStyleInvalid, + // 4); + // if (sstrm.GetData()) + // strm.Printf (" (%s)", sstrm.GetData()); + } else + strm.PutCString("No value"); - return true; + return true; } -SBModule -SBAddress::GetModule () -{ - SBModule sb_module; - if (m_opaque_ap->IsValid()) - sb_module.SetSP (m_opaque_ap->GetModule()); - return sb_module; +SBModule SBAddress::GetModule() { + SBModule sb_module; + if (m_opaque_ap->IsValid()) + sb_module.SetSP(m_opaque_ap->GetModule()); + return sb_module; } -SBSymbolContext -SBAddress::GetSymbolContext (uint32_t resolve_scope) -{ - SBSymbolContext sb_sc; - if (m_opaque_ap->IsValid()) - m_opaque_ap->CalculateSymbolContext (&sb_sc.ref(), resolve_scope); - return sb_sc; +SBSymbolContext SBAddress::GetSymbolContext(uint32_t resolve_scope) { + SBSymbolContext sb_sc; + if (m_opaque_ap->IsValid()) + m_opaque_ap->CalculateSymbolContext(&sb_sc.ref(), resolve_scope); + return sb_sc; } -SBCompileUnit -SBAddress::GetCompileUnit () -{ - SBCompileUnit sb_comp_unit; - if (m_opaque_ap->IsValid()) - sb_comp_unit.reset(m_opaque_ap->CalculateSymbolContextCompileUnit()); - return sb_comp_unit; +SBCompileUnit SBAddress::GetCompileUnit() { + SBCompileUnit sb_comp_unit; + if (m_opaque_ap->IsValid()) + sb_comp_unit.reset(m_opaque_ap->CalculateSymbolContextCompileUnit()); + return sb_comp_unit; } -SBFunction -SBAddress::GetFunction () -{ - SBFunction sb_function; - if (m_opaque_ap->IsValid()) - sb_function.reset(m_opaque_ap->CalculateSymbolContextFunction()); - return sb_function; +SBFunction SBAddress::GetFunction() { + SBFunction sb_function; + if (m_opaque_ap->IsValid()) + sb_function.reset(m_opaque_ap->CalculateSymbolContextFunction()); + return sb_function; } -SBBlock -SBAddress::GetBlock () -{ - SBBlock sb_block; - if (m_opaque_ap->IsValid()) - sb_block.SetPtr(m_opaque_ap->CalculateSymbolContextBlock()); - return sb_block; +SBBlock SBAddress::GetBlock() { + SBBlock sb_block; + if (m_opaque_ap->IsValid()) + sb_block.SetPtr(m_opaque_ap->CalculateSymbolContextBlock()); + return sb_block; } -SBSymbol -SBAddress::GetSymbol () -{ - SBSymbol sb_symbol; - if (m_opaque_ap->IsValid()) - sb_symbol.reset(m_opaque_ap->CalculateSymbolContextSymbol()); - return sb_symbol; +SBSymbol SBAddress::GetSymbol() { + SBSymbol sb_symbol; + if (m_opaque_ap->IsValid()) + sb_symbol.reset(m_opaque_ap->CalculateSymbolContextSymbol()); + return sb_symbol; } -SBLineEntry -SBAddress::GetLineEntry () -{ - SBLineEntry sb_line_entry; - if (m_opaque_ap->IsValid()) - { - LineEntry line_entry; - if (m_opaque_ap->CalculateSymbolContextLineEntry (line_entry)) - sb_line_entry.SetLineEntry (line_entry); - } - return sb_line_entry; +SBLineEntry SBAddress::GetLineEntry() { + SBLineEntry sb_line_entry; + if (m_opaque_ap->IsValid()) { + LineEntry line_entry; + if (m_opaque_ap->CalculateSymbolContextLineEntry(line_entry)) + sb_line_entry.SetLineEntry(line_entry); + } + return sb_line_entry; } -AddressClass -SBAddress::GetAddressClass () -{ - if (m_opaque_ap->IsValid()) - return m_opaque_ap->GetAddressClass(); - return eAddressClassInvalid; +AddressClass SBAddress::GetAddressClass() { + if (m_opaque_ap->IsValid()) + return m_opaque_ap->GetAddressClass(); + return eAddressClassInvalid; } - diff --git a/source/API/SBAttachInfo.cpp b/source/API/SBAttachInfo.cpp index 0f2ab7afc9c2..e6500c468ec5 100644 --- a/source/API/SBAttachInfo.cpp +++ b/source/API/SBAttachInfo.cpp @@ -16,243 +16,152 @@ using namespace lldb; using namespace lldb_private; +SBAttachInfo::SBAttachInfo() : m_opaque_sp(new ProcessAttachInfo()) {} -SBAttachInfo::SBAttachInfo () : - m_opaque_sp (new ProcessAttachInfo()) -{ +SBAttachInfo::SBAttachInfo(lldb::pid_t pid) + : m_opaque_sp(new ProcessAttachInfo()) { + m_opaque_sp->SetProcessID(pid); } -SBAttachInfo::SBAttachInfo (lldb::pid_t pid) : - m_opaque_sp (new ProcessAttachInfo()) -{ - m_opaque_sp->SetProcessID (pid); +SBAttachInfo::SBAttachInfo(const char *path, bool wait_for) + : m_opaque_sp(new ProcessAttachInfo()) { + if (path && path[0]) + m_opaque_sp->GetExecutableFile().SetFile(path, false); + m_opaque_sp->SetWaitForLaunch(wait_for); } -SBAttachInfo::SBAttachInfo (const char *path, bool wait_for) : - m_opaque_sp (new ProcessAttachInfo()) -{ - if (path && path[0]) - m_opaque_sp->GetExecutableFile().SetFile(path, false); - m_opaque_sp->SetWaitForLaunch (wait_for); +SBAttachInfo::SBAttachInfo(const char *path, bool wait_for, bool async) + : m_opaque_sp(new ProcessAttachInfo()) { + if (path && path[0]) + m_opaque_sp->GetExecutableFile().SetFile(path, false); + m_opaque_sp->SetWaitForLaunch(wait_for); + m_opaque_sp->SetAsync(async); } -SBAttachInfo::SBAttachInfo (const char *path, bool wait_for, bool async) : - m_opaque_sp (new ProcessAttachInfo()) -{ - if (path && path[0]) - m_opaque_sp->GetExecutableFile().SetFile(path, false); - m_opaque_sp->SetWaitForLaunch (wait_for); - m_opaque_sp->SetAsync(async); +SBAttachInfo::SBAttachInfo(const SBAttachInfo &rhs) + : m_opaque_sp(new ProcessAttachInfo()) { + *m_opaque_sp = *rhs.m_opaque_sp; } -SBAttachInfo::SBAttachInfo (const SBAttachInfo &rhs) : - m_opaque_sp (new ProcessAttachInfo()) -{ - *m_opaque_sp = *rhs.m_opaque_sp; -} +SBAttachInfo::~SBAttachInfo() {} -SBAttachInfo::~SBAttachInfo() -{ -} +lldb_private::ProcessAttachInfo &SBAttachInfo::ref() { return *m_opaque_sp; } -lldb_private::ProcessAttachInfo & -SBAttachInfo::ref () -{ - return *m_opaque_sp; -} - -SBAttachInfo & -SBAttachInfo::operator = (const SBAttachInfo &rhs) -{ - if (this != &rhs) - *m_opaque_sp = *rhs.m_opaque_sp; - return *this; +SBAttachInfo &SBAttachInfo::operator=(const SBAttachInfo &rhs) { + if (this != &rhs) + *m_opaque_sp = *rhs.m_opaque_sp; + return *this; } -lldb::pid_t -SBAttachInfo::GetProcessID () -{ - return m_opaque_sp->GetProcessID(); -} +lldb::pid_t SBAttachInfo::GetProcessID() { return m_opaque_sp->GetProcessID(); } -void -SBAttachInfo::SetProcessID (lldb::pid_t pid) -{ - m_opaque_sp->SetProcessID (pid); +void SBAttachInfo::SetProcessID(lldb::pid_t pid) { + m_opaque_sp->SetProcessID(pid); } - -uint32_t -SBAttachInfo::GetResumeCount () -{ - return m_opaque_sp->GetResumeCount(); +uint32_t SBAttachInfo::GetResumeCount() { + return m_opaque_sp->GetResumeCount(); } -void -SBAttachInfo::SetResumeCount (uint32_t c) -{ - m_opaque_sp->SetResumeCount (c); +void SBAttachInfo::SetResumeCount(uint32_t c) { + m_opaque_sp->SetResumeCount(c); } -const char * -SBAttachInfo::GetProcessPluginName () -{ - return m_opaque_sp->GetProcessPluginName(); +const char *SBAttachInfo::GetProcessPluginName() { + return m_opaque_sp->GetProcessPluginName(); } -void -SBAttachInfo::SetProcessPluginName (const char *plugin_name) -{ - return m_opaque_sp->SetProcessPluginName (plugin_name); +void SBAttachInfo::SetProcessPluginName(const char *plugin_name) { + return m_opaque_sp->SetProcessPluginName(plugin_name); } -void -SBAttachInfo::SetExecutable (const char *path) -{ - if (path && path[0]) - m_opaque_sp->GetExecutableFile().SetFile(path, false); - else - m_opaque_sp->GetExecutableFile().Clear(); +void SBAttachInfo::SetExecutable(const char *path) { + if (path && path[0]) + m_opaque_sp->GetExecutableFile().SetFile(path, false); + else + m_opaque_sp->GetExecutableFile().Clear(); } -void -SBAttachInfo::SetExecutable (SBFileSpec exe_file) -{ - if (exe_file.IsValid()) - m_opaque_sp->GetExecutableFile() = exe_file.ref(); - else - m_opaque_sp->GetExecutableFile().Clear(); +void SBAttachInfo::SetExecutable(SBFileSpec exe_file) { + if (exe_file.IsValid()) + m_opaque_sp->GetExecutableFile() = exe_file.ref(); + else + m_opaque_sp->GetExecutableFile().Clear(); } -bool -SBAttachInfo::GetWaitForLaunch () -{ - return m_opaque_sp->GetWaitForLaunch(); +bool SBAttachInfo::GetWaitForLaunch() { + return m_opaque_sp->GetWaitForLaunch(); } -void -SBAttachInfo::SetWaitForLaunch (bool b) -{ - m_opaque_sp->SetWaitForLaunch (b); +void SBAttachInfo::SetWaitForLaunch(bool b) { + m_opaque_sp->SetWaitForLaunch(b); } -void -SBAttachInfo::SetWaitForLaunch (bool b, bool async) -{ - m_opaque_sp->SetWaitForLaunch (b); - m_opaque_sp->SetAsync(async); +void SBAttachInfo::SetWaitForLaunch(bool b, bool async) { + m_opaque_sp->SetWaitForLaunch(b); + m_opaque_sp->SetAsync(async); } -bool -SBAttachInfo::GetIgnoreExisting () -{ - return m_opaque_sp->GetIgnoreExisting(); +bool SBAttachInfo::GetIgnoreExisting() { + return m_opaque_sp->GetIgnoreExisting(); } -void -SBAttachInfo::SetIgnoreExisting (bool b) -{ - m_opaque_sp->SetIgnoreExisting (b); +void SBAttachInfo::SetIgnoreExisting(bool b) { + m_opaque_sp->SetIgnoreExisting(b); } -uint32_t -SBAttachInfo::GetUserID() -{ - return m_opaque_sp->GetUserID(); -} +uint32_t SBAttachInfo::GetUserID() { return m_opaque_sp->GetUserID(); } -uint32_t -SBAttachInfo::GetGroupID() -{ - return m_opaque_sp->GetGroupID(); -} +uint32_t SBAttachInfo::GetGroupID() { return m_opaque_sp->GetGroupID(); } -bool -SBAttachInfo::UserIDIsValid () -{ - return m_opaque_sp->UserIDIsValid(); -} +bool SBAttachInfo::UserIDIsValid() { return m_opaque_sp->UserIDIsValid(); } -bool -SBAttachInfo::GroupIDIsValid () -{ - return m_opaque_sp->GroupIDIsValid(); -} +bool SBAttachInfo::GroupIDIsValid() { return m_opaque_sp->GroupIDIsValid(); } -void -SBAttachInfo::SetUserID (uint32_t uid) -{ - m_opaque_sp->SetUserID (uid); -} +void SBAttachInfo::SetUserID(uint32_t uid) { m_opaque_sp->SetUserID(uid); } -void -SBAttachInfo::SetGroupID (uint32_t gid) -{ - m_opaque_sp->SetGroupID (gid); -} +void SBAttachInfo::SetGroupID(uint32_t gid) { m_opaque_sp->SetGroupID(gid); } -uint32_t -SBAttachInfo::GetEffectiveUserID() -{ - return m_opaque_sp->GetEffectiveUserID(); +uint32_t SBAttachInfo::GetEffectiveUserID() { + return m_opaque_sp->GetEffectiveUserID(); } -uint32_t -SBAttachInfo::GetEffectiveGroupID() -{ - return m_opaque_sp->GetEffectiveGroupID(); +uint32_t SBAttachInfo::GetEffectiveGroupID() { + return m_opaque_sp->GetEffectiveGroupID(); } -bool -SBAttachInfo::EffectiveUserIDIsValid () -{ - return m_opaque_sp->EffectiveUserIDIsValid(); +bool SBAttachInfo::EffectiveUserIDIsValid() { + return m_opaque_sp->EffectiveUserIDIsValid(); } -bool -SBAttachInfo::EffectiveGroupIDIsValid () -{ - return m_opaque_sp->EffectiveGroupIDIsValid (); +bool SBAttachInfo::EffectiveGroupIDIsValid() { + return m_opaque_sp->EffectiveGroupIDIsValid(); } -void -SBAttachInfo::SetEffectiveUserID (uint32_t uid) -{ - m_opaque_sp->SetEffectiveUserID(uid); +void SBAttachInfo::SetEffectiveUserID(uint32_t uid) { + m_opaque_sp->SetEffectiveUserID(uid); } -void -SBAttachInfo::SetEffectiveGroupID (uint32_t gid) -{ - m_opaque_sp->SetEffectiveGroupID(gid); +void SBAttachInfo::SetEffectiveGroupID(uint32_t gid) { + m_opaque_sp->SetEffectiveGroupID(gid); } -lldb::pid_t -SBAttachInfo::GetParentProcessID () -{ - return m_opaque_sp->GetParentProcessID(); +lldb::pid_t SBAttachInfo::GetParentProcessID() { + return m_opaque_sp->GetParentProcessID(); } -void -SBAttachInfo::SetParentProcessID (lldb::pid_t pid) -{ - m_opaque_sp->SetParentProcessID (pid); +void SBAttachInfo::SetParentProcessID(lldb::pid_t pid) { + m_opaque_sp->SetParentProcessID(pid); } -bool -SBAttachInfo::ParentProcessIDIsValid() -{ - return m_opaque_sp->ParentProcessIDIsValid(); +bool SBAttachInfo::ParentProcessIDIsValid() { + return m_opaque_sp->ParentProcessIDIsValid(); } -SBListener -SBAttachInfo::GetListener () -{ - return SBListener(m_opaque_sp->GetListener()); +SBListener SBAttachInfo::GetListener() { + return SBListener(m_opaque_sp->GetListener()); } -void -SBAttachInfo::SetListener (SBListener &listener) -{ - m_opaque_sp->SetListener(listener.GetSP()); +void SBAttachInfo::SetListener(SBListener &listener) { + m_opaque_sp->SetListener(listener.GetSP()); } diff --git a/source/API/SBBlock.cpp b/source/API/SBBlock.cpp index 03ee7343c9f5..471b7fbebb23 100644 --- a/source/API/SBBlock.cpp +++ b/source/API/SBBlock.cpp @@ -26,362 +26,272 @@ using namespace lldb; using namespace lldb_private; +SBBlock::SBBlock() : m_opaque_ptr(NULL) {} -SBBlock::SBBlock () : - m_opaque_ptr (NULL) -{ -} +SBBlock::SBBlock(lldb_private::Block *lldb_object_ptr) + : m_opaque_ptr(lldb_object_ptr) {} -SBBlock::SBBlock (lldb_private::Block *lldb_object_ptr) : - m_opaque_ptr (lldb_object_ptr) -{ -} +SBBlock::SBBlock(const SBBlock &rhs) : m_opaque_ptr(rhs.m_opaque_ptr) {} -SBBlock::SBBlock(const SBBlock &rhs) : - m_opaque_ptr (rhs.m_opaque_ptr) -{ +const SBBlock &SBBlock::operator=(const SBBlock &rhs) { + m_opaque_ptr = rhs.m_opaque_ptr; + return *this; } -const SBBlock & -SBBlock::operator = (const SBBlock &rhs) -{ - m_opaque_ptr = rhs.m_opaque_ptr; - return *this; -} +SBBlock::~SBBlock() { m_opaque_ptr = NULL; } -SBBlock::~SBBlock () -{ - m_opaque_ptr = NULL; -} +bool SBBlock::IsValid() const { return m_opaque_ptr != NULL; } -bool -SBBlock::IsValid () const -{ - return m_opaque_ptr != NULL; +bool SBBlock::IsInlined() const { + if (m_opaque_ptr) + return m_opaque_ptr->GetInlinedFunctionInfo() != NULL; + return false; } -bool -SBBlock::IsInlined () const -{ - if (m_opaque_ptr) - return m_opaque_ptr->GetInlinedFunctionInfo () != NULL; - return false; -} - -const char * -SBBlock::GetInlinedName () const -{ - if (m_opaque_ptr) - { - const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); - if (inlined_info) - { - Function *function = m_opaque_ptr->CalculateSymbolContextFunction(); - LanguageType language; - if (function) - language = function->GetLanguage(); - else - language = lldb::eLanguageTypeUnknown; - return inlined_info->GetName(language).AsCString (NULL); - } +const char *SBBlock::GetInlinedName() const { + if (m_opaque_ptr) { + const InlineFunctionInfo *inlined_info = + m_opaque_ptr->GetInlinedFunctionInfo(); + if (inlined_info) { + Function *function = m_opaque_ptr->CalculateSymbolContextFunction(); + LanguageType language; + if (function) + language = function->GetLanguage(); + else + language = lldb::eLanguageTypeUnknown; + return inlined_info->GetName(language).AsCString(NULL); } - return NULL; + } + return NULL; } -SBFileSpec -SBBlock::GetInlinedCallSiteFile () const -{ - SBFileSpec sb_file; - if (m_opaque_ptr) - { - const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); - if (inlined_info) - sb_file.SetFileSpec (inlined_info->GetCallSite().GetFile()); - } - return sb_file; +SBFileSpec SBBlock::GetInlinedCallSiteFile() const { + SBFileSpec sb_file; + if (m_opaque_ptr) { + const InlineFunctionInfo *inlined_info = + m_opaque_ptr->GetInlinedFunctionInfo(); + if (inlined_info) + sb_file.SetFileSpec(inlined_info->GetCallSite().GetFile()); + } + return sb_file; } -uint32_t -SBBlock::GetInlinedCallSiteLine () const -{ - if (m_opaque_ptr) - { - const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); - if (inlined_info) - return inlined_info->GetCallSite().GetLine(); - } - return 0; +uint32_t SBBlock::GetInlinedCallSiteLine() const { + if (m_opaque_ptr) { + const InlineFunctionInfo *inlined_info = + m_opaque_ptr->GetInlinedFunctionInfo(); + if (inlined_info) + return inlined_info->GetCallSite().GetLine(); + } + return 0; } -uint32_t -SBBlock::GetInlinedCallSiteColumn () const -{ - if (m_opaque_ptr) - { - const InlineFunctionInfo* inlined_info = m_opaque_ptr->GetInlinedFunctionInfo (); - if (inlined_info) - return inlined_info->GetCallSite().GetColumn(); - } - return 0; +uint32_t SBBlock::GetInlinedCallSiteColumn() const { + if (m_opaque_ptr) { + const InlineFunctionInfo *inlined_info = + m_opaque_ptr->GetInlinedFunctionInfo(); + if (inlined_info) + return inlined_info->GetCallSite().GetColumn(); + } + return 0; } -void -SBBlock::AppendVariables (bool can_create, bool get_parent_variables, lldb_private::VariableList *var_list) -{ - if (IsValid()) - { - bool show_inline = true; - m_opaque_ptr->AppendVariables (can_create, - get_parent_variables, - show_inline, - [](Variable*) { return true; }, - var_list); - } +void SBBlock::AppendVariables(bool can_create, bool get_parent_variables, + lldb_private::VariableList *var_list) { + if (IsValid()) { + bool show_inline = true; + m_opaque_ptr->AppendVariables(can_create, get_parent_variables, show_inline, + [](Variable *) { return true; }, var_list); + } } -SBBlock -SBBlock::GetParent () -{ - SBBlock sb_block; - if (m_opaque_ptr) - sb_block.m_opaque_ptr = m_opaque_ptr->GetParent(); - return sb_block; +SBBlock SBBlock::GetParent() { + SBBlock sb_block; + if (m_opaque_ptr) + sb_block.m_opaque_ptr = m_opaque_ptr->GetParent(); + return sb_block; } -lldb::SBBlock -SBBlock::GetContainingInlinedBlock () -{ - SBBlock sb_block; - if (m_opaque_ptr) - sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock (); - return sb_block; +lldb::SBBlock SBBlock::GetContainingInlinedBlock() { + SBBlock sb_block; + if (m_opaque_ptr) + sb_block.m_opaque_ptr = m_opaque_ptr->GetContainingInlinedBlock(); + return sb_block; } -SBBlock -SBBlock::GetSibling () -{ - SBBlock sb_block; - if (m_opaque_ptr) - sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling(); - return sb_block; +SBBlock SBBlock::GetSibling() { + SBBlock sb_block; + if (m_opaque_ptr) + sb_block.m_opaque_ptr = m_opaque_ptr->GetSibling(); + return sb_block; } -SBBlock -SBBlock::GetFirstChild () -{ - SBBlock sb_block; - if (m_opaque_ptr) - sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild(); - return sb_block; +SBBlock SBBlock::GetFirstChild() { + SBBlock sb_block; + if (m_opaque_ptr) + sb_block.m_opaque_ptr = m_opaque_ptr->GetFirstChild(); + return sb_block; } -lldb_private::Block * -SBBlock::GetPtr () -{ - return m_opaque_ptr; -} +lldb_private::Block *SBBlock::GetPtr() { return m_opaque_ptr; } -void -SBBlock::SetPtr (lldb_private::Block *block) -{ - m_opaque_ptr = block; -} +void SBBlock::SetPtr(lldb_private::Block *block) { m_opaque_ptr = block; } -bool -SBBlock::GetDescription (SBStream &description) -{ - Stream &strm = description.ref(); - - if (m_opaque_ptr) - { - lldb::user_id_t id = m_opaque_ptr->GetID(); - strm.Printf ("Block: {id: %" PRIu64 "} ", id); - if (IsInlined()) - { - strm.Printf (" (inlined, '%s') ", GetInlinedName()); - } - lldb_private::SymbolContext sc; - m_opaque_ptr->CalculateSymbolContext (&sc); - if (sc.function) - { - m_opaque_ptr->DumpAddressRanges (&strm, - sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); - } +bool SBBlock::GetDescription(SBStream &description) { + Stream &strm = description.ref(); + + if (m_opaque_ptr) { + lldb::user_id_t id = m_opaque_ptr->GetID(); + strm.Printf("Block: {id: %" PRIu64 "} ", id); + if (IsInlined()) { + strm.Printf(" (inlined, '%s') ", GetInlinedName()); } - else - strm.PutCString ("No value"); - - return true; + lldb_private::SymbolContext sc; + m_opaque_ptr->CalculateSymbolContext(&sc); + if (sc.function) { + m_opaque_ptr->DumpAddressRanges( + &strm, + sc.function->GetAddressRange().GetBaseAddress().GetFileAddress()); + } + } else + strm.PutCString("No value"); + + return true; } -uint32_t -SBBlock::GetNumRanges () -{ - if (m_opaque_ptr) - return m_opaque_ptr->GetNumRanges(); - return 0; +uint32_t SBBlock::GetNumRanges() { + if (m_opaque_ptr) + return m_opaque_ptr->GetNumRanges(); + return 0; } -lldb::SBAddress -SBBlock::GetRangeStartAddress (uint32_t idx) -{ - lldb::SBAddress sb_addr; - if (m_opaque_ptr) - { - AddressRange range; - if (m_opaque_ptr->GetRangeAtIndex(idx, range)) - { - sb_addr.ref() = range.GetBaseAddress(); - } +lldb::SBAddress SBBlock::GetRangeStartAddress(uint32_t idx) { + lldb::SBAddress sb_addr; + if (m_opaque_ptr) { + AddressRange range; + if (m_opaque_ptr->GetRangeAtIndex(idx, range)) { + sb_addr.ref() = range.GetBaseAddress(); } - return sb_addr; + } + return sb_addr; } -lldb::SBAddress -SBBlock::GetRangeEndAddress (uint32_t idx) -{ - lldb::SBAddress sb_addr; - if (m_opaque_ptr) - { - AddressRange range; - if (m_opaque_ptr->GetRangeAtIndex(idx, range)) - { - sb_addr.ref() = range.GetBaseAddress(); - sb_addr.ref().Slide(range.GetByteSize()); - } +lldb::SBAddress SBBlock::GetRangeEndAddress(uint32_t idx) { + lldb::SBAddress sb_addr; + if (m_opaque_ptr) { + AddressRange range; + if (m_opaque_ptr->GetRangeAtIndex(idx, range)) { + sb_addr.ref() = range.GetBaseAddress(); + sb_addr.ref().Slide(range.GetByteSize()); } - return sb_addr; + } + return sb_addr; } -uint32_t -SBBlock::GetRangeIndexForBlockAddress (lldb::SBAddress block_addr) -{ - if (m_opaque_ptr && block_addr.IsValid()) - { - return m_opaque_ptr->GetRangeIndexContainingAddress (block_addr.ref()); - } +uint32_t SBBlock::GetRangeIndexForBlockAddress(lldb::SBAddress block_addr) { + if (m_opaque_ptr && block_addr.IsValid()) { + return m_opaque_ptr->GetRangeIndexContainingAddress(block_addr.ref()); + } - return UINT32_MAX; + return UINT32_MAX; } - -lldb::SBValueList -SBBlock::GetVariables (lldb::SBFrame& frame, - bool arguments, - bool locals, - bool statics, - lldb::DynamicValueType use_dynamic) -{ - Block *block = GetPtr(); - SBValueList value_list; - if (block) - { - StackFrameSP frame_sp(frame.GetFrameSP()); - VariableListSP variable_list_sp (block->GetBlockVariableList (true)); - - if (variable_list_sp) - { - const size_t num_variables = variable_list_sp->GetSize(); - if (num_variables) - { - for (size_t i = 0; i < num_variables; ++i) - { - VariableSP variable_sp (variable_list_sp->GetVariableAtIndex(i)); - if (variable_sp) - { - bool add_variable = false; - switch (variable_sp->GetScope()) - { - case eValueTypeVariableGlobal: - case eValueTypeVariableStatic: - case eValueTypeVariableThreadLocal: - add_variable = statics; - break; - - case eValueTypeVariableArgument: - add_variable = arguments; - break; - - case eValueTypeVariableLocal: - add_variable = locals; - break; - - default: - break; - } - if (add_variable) - { - if (frame_sp) - { - lldb::ValueObjectSP valobj_sp(frame_sp->GetValueObjectForFrameVariable (variable_sp,eNoDynamicValues)); - SBValue value_sb; - value_sb.SetSP(valobj_sp, use_dynamic); - value_list.Append (value_sb); - } - } - } - } +lldb::SBValueList SBBlock::GetVariables(lldb::SBFrame &frame, bool arguments, + bool locals, bool statics, + lldb::DynamicValueType use_dynamic) { + Block *block = GetPtr(); + SBValueList value_list; + if (block) { + StackFrameSP frame_sp(frame.GetFrameSP()); + VariableListSP variable_list_sp(block->GetBlockVariableList(true)); + + if (variable_list_sp) { + const size_t num_variables = variable_list_sp->GetSize(); + if (num_variables) { + for (size_t i = 0; i < num_variables; ++i) { + VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i)); + if (variable_sp) { + bool add_variable = false; + switch (variable_sp->GetScope()) { + case eValueTypeVariableGlobal: + case eValueTypeVariableStatic: + case eValueTypeVariableThreadLocal: + add_variable = statics; + break; + + case eValueTypeVariableArgument: + add_variable = arguments; + break; + + case eValueTypeVariableLocal: + add_variable = locals; + break; + + default: + break; + } + if (add_variable) { + if (frame_sp) { + lldb::ValueObjectSP valobj_sp( + frame_sp->GetValueObjectForFrameVariable(variable_sp, + eNoDynamicValues)); + SBValue value_sb; + value_sb.SetSP(valobj_sp, use_dynamic); + value_list.Append(value_sb); + } } - } + } + } + } } - return value_list; + } + return value_list; } -lldb::SBValueList -SBBlock::GetVariables (lldb::SBTarget& target, - bool arguments, - bool locals, - bool statics) -{ - Block *block = GetPtr(); - - SBValueList value_list; - if (block) - { - TargetSP target_sp(target.GetSP()); - - VariableListSP variable_list_sp (block->GetBlockVariableList (true)); - - if (variable_list_sp) - { - const size_t num_variables = variable_list_sp->GetSize(); - if (num_variables) - { - for (size_t i = 0; i < num_variables; ++i) - { - VariableSP variable_sp (variable_list_sp->GetVariableAtIndex(i)); - if (variable_sp) - { - bool add_variable = false; - switch (variable_sp->GetScope()) - { - case eValueTypeVariableGlobal: - case eValueTypeVariableStatic: - case eValueTypeVariableThreadLocal: - add_variable = statics; - break; - - case eValueTypeVariableArgument: - add_variable = arguments; - break; - - case eValueTypeVariableLocal: - add_variable = locals; - break; - - default: - break; - } - if (add_variable) - { - if (target_sp) - value_list.Append (ValueObjectVariable::Create (target_sp.get(), variable_sp)); - } - } - } +lldb::SBValueList SBBlock::GetVariables(lldb::SBTarget &target, bool arguments, + bool locals, bool statics) { + Block *block = GetPtr(); + + SBValueList value_list; + if (block) { + TargetSP target_sp(target.GetSP()); + + VariableListSP variable_list_sp(block->GetBlockVariableList(true)); + + if (variable_list_sp) { + const size_t num_variables = variable_list_sp->GetSize(); + if (num_variables) { + for (size_t i = 0; i < num_variables; ++i) { + VariableSP variable_sp(variable_list_sp->GetVariableAtIndex(i)); + if (variable_sp) { + bool add_variable = false; + switch (variable_sp->GetScope()) { + case eValueTypeVariableGlobal: + case eValueTypeVariableStatic: + case eValueTypeVariableThreadLocal: + add_variable = statics; + break; + + case eValueTypeVariableArgument: + add_variable = arguments; + break; + + case eValueTypeVariableLocal: + add_variable = locals; + break; + + default: + break; } + if (add_variable) { + if (target_sp) + value_list.Append( + ValueObjectVariable::Create(target_sp.get(), variable_sp)); + } + } } - } - return value_list; + } + } + } + return value_list; } - diff --git a/source/API/SBBreakpoint.cpp b/source/API/SBBreakpoint.cpp index ec3a3de4a788..0eab2c2a363f 100644 --- a/source/API/SBBreakpoint.cpp +++ b/source/API/SBBreakpoint.cpp @@ -21,6 +21,7 @@ #include "lldb/API/SBThread.h" #include "lldb/Breakpoint/Breakpoint.h" +#include "lldb/Breakpoint/BreakpointIDList.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/Address.h" @@ -38,753 +39,818 @@ #include "lldb/lldb-enumerations.h" +#include "llvm/ADT/STLExtras.h" + using namespace lldb; using namespace lldb_private; -struct CallbackData -{ - SBBreakpoint::BreakpointHitCallback callback; - void *callback_baton; +struct CallbackData { + SBBreakpoint::BreakpointHitCallback callback; + void *callback_baton; }; -class SBBreakpointCallbackBaton : public Baton -{ +class SBBreakpointCallbackBaton : public TypedBaton<CallbackData> { public: - SBBreakpointCallbackBaton (SBBreakpoint::BreakpointHitCallback callback, void *baton) : - Baton (new CallbackData) - { - CallbackData *data = (CallbackData *)m_data; - data->callback = callback; - data->callback_baton = baton; - } - - ~SBBreakpointCallbackBaton() override - { - CallbackData *data = (CallbackData *)m_data; - - if (data) - { - delete data; - m_data = nullptr; - } - } + SBBreakpointCallbackBaton(SBBreakpoint::BreakpointHitCallback callback, + void *baton) + : TypedBaton(llvm::make_unique<CallbackData>()) { + getItem()->callback = callback; + getItem()->callback_baton = baton; + } }; -SBBreakpoint::SBBreakpoint () : - m_opaque_sp () -{ -} +SBBreakpoint::SBBreakpoint() : m_opaque_sp() {} -SBBreakpoint::SBBreakpoint (const SBBreakpoint& rhs) : - m_opaque_sp (rhs.m_opaque_sp) -{ -} +SBBreakpoint::SBBreakpoint(const SBBreakpoint &rhs) + : m_opaque_sp(rhs.m_opaque_sp) {} -SBBreakpoint::SBBreakpoint (const lldb::BreakpointSP &bp_sp) : - m_opaque_sp (bp_sp) -{ -} +SBBreakpoint::SBBreakpoint(const lldb::BreakpointSP &bp_sp) + : m_opaque_sp(bp_sp) {} SBBreakpoint::~SBBreakpoint() = default; -const SBBreakpoint & -SBBreakpoint::operator = (const SBBreakpoint& rhs) -{ - if (this != &rhs) - m_opaque_sp = rhs.m_opaque_sp; - return *this; +const SBBreakpoint &SBBreakpoint::operator=(const SBBreakpoint &rhs) { + if (this != &rhs) + m_opaque_sp = rhs.m_opaque_sp; + return *this; } -bool -SBBreakpoint::operator == (const lldb::SBBreakpoint& rhs) -{ - if (m_opaque_sp && rhs.m_opaque_sp) - return m_opaque_sp.get() == rhs.m_opaque_sp.get(); - return false; +bool SBBreakpoint::operator==(const lldb::SBBreakpoint &rhs) { + if (m_opaque_sp && rhs.m_opaque_sp) + return m_opaque_sp.get() == rhs.m_opaque_sp.get(); + return false; } -bool -SBBreakpoint::operator != (const lldb::SBBreakpoint& rhs) -{ - if (m_opaque_sp && rhs.m_opaque_sp) - return m_opaque_sp.get() != rhs.m_opaque_sp.get(); - return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp); +bool SBBreakpoint::operator!=(const lldb::SBBreakpoint &rhs) { + if (m_opaque_sp && rhs.m_opaque_sp) + return m_opaque_sp.get() != rhs.m_opaque_sp.get(); + return (m_opaque_sp && !rhs.m_opaque_sp) || (rhs.m_opaque_sp && !m_opaque_sp); } -break_id_t -SBBreakpoint::GetID () const -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +break_id_t SBBreakpoint::GetID() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - break_id_t break_id = LLDB_INVALID_BREAK_ID; - if (m_opaque_sp) - break_id = m_opaque_sp->GetID(); + break_id_t break_id = LLDB_INVALID_BREAK_ID; + if (m_opaque_sp) + break_id = m_opaque_sp->GetID(); - if (log) - { - if (break_id == LLDB_INVALID_BREAK_ID) - log->Printf ("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", - static_cast<void*>(m_opaque_sp.get())); - else - log->Printf ("SBBreakpoint(%p)::GetID () => %u", - static_cast<void*>(m_opaque_sp.get()), break_id); - } + if (log) { + if (break_id == LLDB_INVALID_BREAK_ID) + log->Printf("SBBreakpoint(%p)::GetID () => LLDB_INVALID_BREAK_ID", + static_cast<void *>(m_opaque_sp.get())); + else + log->Printf("SBBreakpoint(%p)::GetID () => %u", + static_cast<void *>(m_opaque_sp.get()), break_id); + } - return break_id; + return break_id; } -bool -SBBreakpoint::IsValid() const -{ - if (!m_opaque_sp) - return false; - else if (m_opaque_sp->GetTarget().GetBreakpointByID(m_opaque_sp->GetID())) - return true; - else - return false; +bool SBBreakpoint::IsValid() const { + if (!m_opaque_sp) + return false; + else if (m_opaque_sp->GetTarget().GetBreakpointByID(m_opaque_sp->GetID())) + return true; + else + return false; } -void -SBBreakpoint::ClearAllBreakpointSites () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->ClearAllBreakpointSites (); - } +void SBBreakpoint::ClearAllBreakpointSites() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->ClearAllBreakpointSites(); + } } -SBBreakpointLocation -SBBreakpoint::FindLocationByAddress (addr_t vm_addr) -{ - SBBreakpointLocation sb_bp_location; - - if (m_opaque_sp) - { - if (vm_addr != LLDB_INVALID_ADDRESS) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - Address address; - Target &target = m_opaque_sp->GetTarget(); - if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) - { - address.SetRawAddress (vm_addr); - } - sb_bp_location.SetLocation (m_opaque_sp->FindLocationByAddress (address)); - } - } - return sb_bp_location; -} - -break_id_t -SBBreakpoint::FindLocationIDByAddress (addr_t vm_addr) -{ - break_id_t break_id = LLDB_INVALID_BREAK_ID; - - if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - Address address; - Target &target = m_opaque_sp->GetTarget(); - if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) - { - address.SetRawAddress (vm_addr); - } - break_id = m_opaque_sp->FindLocationIDByAddress (address); - } - - return break_id; -} +SBBreakpointLocation SBBreakpoint::FindLocationByAddress(addr_t vm_addr) { + SBBreakpointLocation sb_bp_location; -SBBreakpointLocation -SBBreakpoint::FindLocationByID (break_id_t bp_loc_id) -{ - SBBreakpointLocation sb_bp_location; - - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - sb_bp_location.SetLocation (m_opaque_sp->FindLocationByID (bp_loc_id)); + if (m_opaque_sp) { + if (vm_addr != LLDB_INVALID_ADDRESS) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + Address address; + Target &target = m_opaque_sp->GetTarget(); + if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) { + address.SetRawAddress(vm_addr); + } + sb_bp_location.SetLocation(m_opaque_sp->FindLocationByAddress(address)); } - - return sb_bp_location; + } + return sb_bp_location; } -SBBreakpointLocation -SBBreakpoint::GetLocationAtIndex (uint32_t index) -{ - SBBreakpointLocation sb_bp_location; - - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - sb_bp_location.SetLocation (m_opaque_sp->GetLocationAtIndex (index)); +break_id_t SBBreakpoint::FindLocationIDByAddress(addr_t vm_addr) { + break_id_t break_id = LLDB_INVALID_BREAK_ID; + + if (m_opaque_sp && vm_addr != LLDB_INVALID_ADDRESS) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + Address address; + Target &target = m_opaque_sp->GetTarget(); + if (!target.GetSectionLoadList().ResolveLoadAddress(vm_addr, address)) { + address.SetRawAddress(vm_addr); } + break_id = m_opaque_sp->FindLocationIDByAddress(address); + } - return sb_bp_location; + return break_id; } -void -SBBreakpoint::SetEnabled (bool enable) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBBreakpoint(%p)::SetEnabled (enabled=%i)", - static_cast<void*>(m_opaque_sp.get()), enable); +SBBreakpointLocation SBBreakpoint::FindLocationByID(break_id_t bp_loc_id) { + SBBreakpointLocation sb_bp_location; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetEnabled (enable); - } -} + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + sb_bp_location.SetLocation(m_opaque_sp->FindLocationByID(bp_loc_id)); + } -bool -SBBreakpoint::IsEnabled () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->IsEnabled(); - } - else - return false; + return sb_bp_location; } -void -SBBreakpoint::SetOneShot (bool one_shot) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +SBBreakpointLocation SBBreakpoint::GetLocationAtIndex(uint32_t index) { + SBBreakpointLocation sb_bp_location; - if (log) - log->Printf ("SBBreakpoint(%p)::SetOneShot (one_shot=%i)", - static_cast<void*>(m_opaque_sp.get()), one_shot); + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + sb_bp_location.SetLocation(m_opaque_sp->GetLocationAtIndex(index)); + } - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetOneShot (one_shot); - } + return sb_bp_location; } -bool -SBBreakpoint::IsOneShot () const -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->IsOneShot(); - } - else - return false; +void SBBreakpoint::SetEnabled(bool enable) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf("SBBreakpoint(%p)::SetEnabled (enabled=%i)", + static_cast<void *>(m_opaque_sp.get()), enable); + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetEnabled(enable); + } } -bool -SBBreakpoint::IsInternal () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->IsInternal(); - } - else - return false; +bool SBBreakpoint::IsEnabled() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->IsEnabled(); + } else + return false; } -void -SBBreakpoint::SetIgnoreCount (uint32_t count) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +void SBBreakpoint::SetOneShot(bool one_shot) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", - static_cast<void*>(m_opaque_sp.get()), count); + if (log) + log->Printf("SBBreakpoint(%p)::SetOneShot (one_shot=%i)", + static_cast<void *>(m_opaque_sp.get()), one_shot); - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetIgnoreCount (count); - } + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetOneShot(one_shot); + } } -void -SBBreakpoint::SetCondition (const char *condition) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetCondition (condition); - } +bool SBBreakpoint::IsOneShot() const { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->IsOneShot(); + } else + return false; } -const char * -SBBreakpoint::GetCondition () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetConditionText (); - } - return nullptr; +bool SBBreakpoint::IsInternal() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->IsInternal(); + } else + return false; } -uint32_t -SBBreakpoint::GetHitCount () const -{ - uint32_t count = 0; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - count = m_opaque_sp->GetHitCount(); - } +void SBBreakpoint::SetIgnoreCount(uint32_t count) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf("SBBreakpoint(%p)::SetIgnoreCount (count=%u)", + static_cast<void *>(m_opaque_sp.get()), count); + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetIgnoreCount(count); + } +} + +void SBBreakpoint::SetCondition(const char *condition) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetCondition(condition); + } +} + +const char *SBBreakpoint::GetCondition() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetConditionText(); + } + return nullptr; +} + +uint32_t SBBreakpoint::GetHitCount() const { + uint32_t count = 0; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + count = m_opaque_sp->GetHitCount(); + } + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetHitCount () => %u", + static_cast<void *>(m_opaque_sp.get()), count); + + return count; +} + +uint32_t SBBreakpoint::GetIgnoreCount() const { + uint32_t count = 0; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + count = m_opaque_sp->GetIgnoreCount(); + } + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetIgnoreCount () => %u", + static_cast<void *>(m_opaque_sp.get()), count); + + return count; +} + +void SBBreakpoint::SetThreadID(tid_t tid) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetThreadID(tid); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")", + static_cast<void *>(m_opaque_sp.get()), tid); +} + +tid_t SBBreakpoint::GetThreadID() { + tid_t tid = LLDB_INVALID_THREAD_ID; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + tid = m_opaque_sp->GetThreadID(); + } + + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64, + static_cast<void *>(m_opaque_sp.get()), tid); + return tid; +} + +void SBBreakpoint::SetThreadIndex(uint32_t index) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::SetThreadIndex (%u)", + static_cast<void *>(m_opaque_sp.get()), index); + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex(index); + } +} + +uint32_t SBBreakpoint::GetThreadIndex() const { + uint32_t thread_idx = UINT32_MAX; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = + m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); + if (thread_spec != nullptr) + thread_idx = thread_spec->GetIndex(); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetThreadIndex () => %u", + static_cast<void *>(m_opaque_sp.get()), thread_idx); + + return thread_idx; +} + +void SBBreakpoint::SetThreadName(const char *thread_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::SetThreadName (%s)", + static_cast<void *>(m_opaque_sp.get()), thread_name); + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->GetOptions()->GetThreadSpec()->SetName(thread_name); + } +} + +const char *SBBreakpoint::GetThreadName() const { + const char *name = nullptr; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = + m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); + if (thread_spec != nullptr) + name = thread_spec->GetName(); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetThreadName () => %s", + static_cast<void *>(m_opaque_sp.get()), name); + + return name; +} + +void SBBreakpoint::SetQueueName(const char *queue_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::SetQueueName (%s)", + static_cast<void *>(m_opaque_sp.get()), queue_name); + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName(queue_name); + } +} + +const char *SBBreakpoint::GetQueueName() const { + const char *name = nullptr; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + const ThreadSpec *thread_spec = + m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); + if (thread_spec) + name = thread_spec->GetQueueName(); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetQueueName () => %s", + static_cast<void *>(m_opaque_sp.get()), name); + + return name; +} + +size_t SBBreakpoint::GetNumResolvedLocations() const { + size_t num_resolved = 0; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + num_resolved = m_opaque_sp->GetNumResolvedLocations(); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64, + static_cast<void *>(m_opaque_sp.get()), + static_cast<uint64_t>(num_resolved)); + return num_resolved; +} + +size_t SBBreakpoint::GetNumLocations() const { + size_t num_locs = 0; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + num_locs = m_opaque_sp->GetNumLocations(); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64, + static_cast<void *>(m_opaque_sp.get()), + static_cast<uint64_t>(num_locs)); + return num_locs; +} + +void SBBreakpoint::SetCommandLineCommands(SBStringList &commands) { + if (!m_opaque_sp) + return; + if (commands.GetSize() == 0) + return; + + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + std::unique_ptr<BreakpointOptions::CommandData> cmd_data_up( + new BreakpointOptions::CommandData(*commands, eScriptLanguageNone)); + + m_opaque_sp->GetOptions()->SetCommandDataCallback(cmd_data_up); +} + +bool SBBreakpoint::GetCommandLineCommands(SBStringList &commands) { + if (!m_opaque_sp) + return false; + StringList command_list; + bool has_commands = + m_opaque_sp->GetOptions()->GetCommandLineCallbacks(command_list); + if (has_commands) + commands.AppendList(command_list); + return has_commands; +} + +bool SBBreakpoint::GetDescription(SBStream &s) { + return GetDescription(s, true); +} + +bool SBBreakpoint::GetDescription(SBStream &s, bool include_locations) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID()); + m_opaque_sp->GetResolverDescription(s.get()); + m_opaque_sp->GetFilterDescription(s.get()); + if (include_locations) { + const size_t num_locations = m_opaque_sp->GetNumLocations(); + s.Printf(", locations = %" PRIu64, (uint64_t)num_locations); + } + return true; + } + s.Printf("No value"); + return false; +} + +bool SBBreakpoint::PrivateBreakpointHitCallback(void *baton, + StoppointCallbackContext *ctx, + lldb::user_id_t break_id, + lldb::user_id_t break_loc_id) { + ExecutionContext exe_ctx(ctx->exe_ctx_ref); + BreakpointSP bp_sp( + exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id)); + if (baton && bp_sp) { + CallbackData *data = (CallbackData *)baton; + lldb_private::Breakpoint *bp = bp_sp.get(); + if (bp && data->callback) { + Process *process = exe_ctx.GetProcessPtr(); + if (process) { + SBProcess sb_process(process->shared_from_this()); + SBThread sb_thread; + SBBreakpointLocation sb_location; + assert(bp_sp); + sb_location.SetLocation(bp_sp->FindLocationByID(break_loc_id)); + Thread *thread = exe_ctx.GetThreadPtr(); + if (thread) + sb_thread.SetThread(thread->shared_from_this()); + + return data->callback(data->callback_baton, sb_process, sb_thread, + sb_location); + } + } + } + return true; // Return true if we should stop at this breakpoint +} + +void SBBreakpoint::SetCallback(BreakpointHitCallback callback, void *baton) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) { + void *pointer = &callback; + log->Printf("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", + static_cast<void *>(m_opaque_sp.get()), + *static_cast<void **>(&pointer), static_cast<void *>(baton)); + } + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + BatonSP baton_sp(new SBBreakpointCallbackBaton(callback, baton)); + m_opaque_sp->SetCallback(SBBreakpoint::PrivateBreakpointHitCallback, + baton_sp, false); + } +} + +void SBBreakpoint::SetScriptCallbackFunction( + const char *callback_function_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf("SBBreakpoint(%p)::SetScriptCallbackFunction (callback=%s)", + static_cast<void *>(m_opaque_sp.get()), callback_function_name); + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + BreakpointOptions *bp_options = m_opaque_sp->GetOptions(); + m_opaque_sp->GetTarget() + .GetDebugger() + .GetCommandInterpreter() + .GetScriptInterpreter() + ->SetBreakpointCommandCallbackFunction(bp_options, + callback_function_name); + } +} + +SBError SBBreakpoint::SetScriptCallbackBody(const char *callback_body_text) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", + static_cast<void *>(m_opaque_sp.get()), callback_body_text); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetHitCount () => %u", - static_cast<void*>(m_opaque_sp.get()), count); + SBError sb_error; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + BreakpointOptions *bp_options = m_opaque_sp->GetOptions(); + Error error = + m_opaque_sp->GetTarget() + .GetDebugger() + .GetCommandInterpreter() + .GetScriptInterpreter() + ->SetBreakpointCommandCallback(bp_options, callback_body_text); + sb_error.SetError(error); + } else + sb_error.SetErrorString("invalid breakpoint"); - return count; + return sb_error; } -uint32_t -SBBreakpoint::GetIgnoreCount () const -{ - uint32_t count = 0; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - count = m_opaque_sp->GetIgnoreCount(); - } - - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetIgnoreCount () => %u", - static_cast<void*>(m_opaque_sp.get()), count); +bool SBBreakpoint::AddName(const char *new_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - return count; -} + if (log) + log->Printf("SBBreakpoint(%p)::AddName (name=%s)", + static_cast<void *>(m_opaque_sp.get()), new_name); -void -SBBreakpoint::SetThreadID (tid_t tid) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetThreadID (tid); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::SetThreadID (tid=0x%4.4" PRIx64 ")", - static_cast<void*>(m_opaque_sp.get()), tid); -} - -tid_t -SBBreakpoint::GetThreadID () -{ - tid_t tid = LLDB_INVALID_THREAD_ID; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - tid = m_opaque_sp->GetThreadID(); - } + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + 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); + } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetThreadID () => 0x%4.4" PRIx64, - static_cast<void*>(m_opaque_sp.get()), tid); - return tid; -} - -void -SBBreakpoint::SetThreadIndex (uint32_t index) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::SetThreadIndex (%u)", - static_cast<void*>(m_opaque_sp.get()), index); - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetOptions()->GetThreadSpec()->SetIndex (index); - } + return false; } -uint32_t -SBBreakpoint::GetThreadIndex() const -{ - uint32_t thread_idx = UINT32_MAX; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); - if (thread_spec != nullptr) - thread_idx = thread_spec->GetIndex(); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetThreadIndex () => %u", - static_cast<void*>(m_opaque_sp.get()), thread_idx); - - return thread_idx; -} - -void -SBBreakpoint::SetThreadName (const char *thread_name) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::SetThreadName (%s)", - static_cast<void*>(m_opaque_sp.get()), thread_name); - - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetOptions()->GetThreadSpec()->SetName (thread_name); - } -} +void SBBreakpoint::RemoveName(const char *name_to_remove) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); -const char * -SBBreakpoint::GetThreadName () const -{ - const char *name = nullptr; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); - if (thread_spec != nullptr) - name = thread_spec->GetName(); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetThreadName () => %s", - static_cast<void*>(m_opaque_sp.get()), name); - - return name; -} - -void -SBBreakpoint::SetQueueName (const char *queue_name) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::SetQueueName (%s)", - static_cast<void*>(m_opaque_sp.get()), queue_name); - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetOptions()->GetThreadSpec()->SetQueueName (queue_name); - } -} + if (log) + log->Printf("SBBreakpoint(%p)::RemoveName (name=%s)", + static_cast<void *>(m_opaque_sp.get()), name_to_remove); -const char * -SBBreakpoint::GetQueueName () const -{ - const char *name = nullptr; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - const ThreadSpec *thread_spec = m_opaque_sp->GetOptions()->GetThreadSpecNoCreate(); - if (thread_spec) - name = thread_spec->GetQueueName(); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetQueueName () => %s", - static_cast<void*>(m_opaque_sp.get()), name); - - return name; -} - -size_t -SBBreakpoint::GetNumResolvedLocations() const -{ - size_t num_resolved = 0; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - num_resolved = m_opaque_sp->GetNumResolvedLocations(); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetNumResolvedLocations () => %" PRIu64, - static_cast<void*>(m_opaque_sp.get()), - static_cast<uint64_t>(num_resolved)); - return num_resolved; -} - -size_t -SBBreakpoint::GetNumLocations() const -{ - size_t num_locs = 0; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - num_locs = m_opaque_sp->GetNumLocations(); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::GetNumLocations () => %" PRIu64, - static_cast<void*>(m_opaque_sp.get()), - static_cast<uint64_t>(num_locs)); - return num_locs; -} - -bool -SBBreakpoint::GetDescription (SBStream &s) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - s.Printf("SBBreakpoint: id = %i, ", m_opaque_sp->GetID()); - m_opaque_sp->GetResolverDescription (s.get()); - m_opaque_sp->GetFilterDescription (s.get()); - const size_t num_locations = m_opaque_sp->GetNumLocations (); - s.Printf(", locations = %" PRIu64, (uint64_t)num_locations); - return true; - } - s.Printf ("No value"); - return false; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->RemoveName(name_to_remove); + } } -bool -SBBreakpoint::PrivateBreakpointHitCallback(void *baton, - StoppointCallbackContext *ctx, - lldb::user_id_t break_id, - lldb::user_id_t break_loc_id) -{ - ExecutionContext exe_ctx (ctx->exe_ctx_ref); - BreakpointSP bp_sp(exe_ctx.GetTargetRef().GetBreakpointList().FindBreakpointByID(break_id)); - if (baton && bp_sp) - { - CallbackData *data = (CallbackData *)baton; - lldb_private::Breakpoint *bp = bp_sp.get(); - if (bp && data->callback) - { - Process *process = exe_ctx.GetProcessPtr(); - if (process) - { - SBProcess sb_process (process->shared_from_this()); - SBThread sb_thread; - SBBreakpointLocation sb_location; - assert (bp_sp); - sb_location.SetLocation (bp_sp->FindLocationByID (break_loc_id)); - Thread *thread = exe_ctx.GetThreadPtr(); - if (thread) - sb_thread.SetThread(thread->shared_from_this()); - - return data->callback (data->callback_baton, - sb_process, - sb_thread, - sb_location); - } - } - } - return true; // Return true if we should stop at this breakpoint -} +bool SBBreakpoint::MatchesName(const char *name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); -void -SBBreakpoint::SetCallback (BreakpointHitCallback callback, void *baton) -{ - 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 (log) - { - void *pointer = &callback; - log->Printf ("SBBreakpoint(%p)::SetCallback (callback=%p, baton=%p)", - static_cast<void*>(m_opaque_sp.get()), - *static_cast<void**>(&pointer), static_cast<void*>(baton)); - } + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->MatchesName(name); + } - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - BatonSP baton_sp(new SBBreakpointCallbackBaton (callback, baton)); - m_opaque_sp->SetCallback (SBBreakpoint::PrivateBreakpointHitCallback, baton_sp, false); - } + return false; } -void -SBBreakpoint::SetScriptCallbackFunction (const char *callback_function_name) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +void SBBreakpoint::GetNames(SBStringList &names) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBreakpoint(%p)::SetScriptCallbackFunction (callback=%s)", - static_cast<void*>(m_opaque_sp.get()), - callback_function_name); + if (log) + log->Printf("SBBreakpoint(%p)::GetNames ()", + static_cast<void *>(m_opaque_sp.get())); - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - BreakpointOptions *bp_options = m_opaque_sp->GetOptions(); - m_opaque_sp->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options, - callback_function_name); + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + 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()); } + } } -SBError -SBBreakpoint::SetScriptCallbackBody (const char *callback_body_text) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", - static_cast<void*>(m_opaque_sp.get()), callback_body_text); - - SBError sb_error; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - BreakpointOptions *bp_options = m_opaque_sp->GetOptions(); - Error error = m_opaque_sp->GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, - callback_body_text); - sb_error.SetError(error); - } - else - sb_error.SetErrorString("invalid breakpoint"); - - return sb_error; +lldb_private::Breakpoint *SBBreakpoint::operator->() const { + return m_opaque_sp.get(); } -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); +lldb_private::Breakpoint *SBBreakpoint::get() const { + return m_opaque_sp.get(); +} - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(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); - } +lldb::BreakpointSP &SBBreakpoint::operator*() { return m_opaque_sp; } - return false; +const lldb::BreakpointSP &SBBreakpoint::operator*() const { + return m_opaque_sp; } -void -SBBreakpoint::RemoveName (const char *name_to_remove) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +bool SBBreakpoint::EventIsBreakpointEvent(const lldb::SBEvent &event) { + return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != + nullptr; +} - if (log) - log->Printf ("SBBreakpoint(%p)::RemoveName (name=%s)", - static_cast<void*>(m_opaque_sp.get()), - name_to_remove); +BreakpointEventType +SBBreakpoint::GetBreakpointEventTypeFromEvent(const SBEvent &event) { + if (event.IsValid()) + return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent( + event.GetSP()); + return eBreakpointEventTypeInvalidType; +} - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->RemoveName(name_to_remove); - } +SBBreakpoint SBBreakpoint::GetBreakpointFromEvent(const lldb::SBEvent &event) { + SBBreakpoint sb_breakpoint; + if (event.IsValid()) + sb_breakpoint.m_opaque_sp = + Breakpoint::BreakpointEventData::GetBreakpointFromEvent(event.GetSP()); + return sb_breakpoint; } -bool -SBBreakpoint::MatchesName (const char *name) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +SBBreakpointLocation +SBBreakpoint::GetBreakpointLocationAtIndexFromEvent(const lldb::SBEvent &event, + uint32_t loc_idx) { + SBBreakpointLocation sb_breakpoint_loc; + if (event.IsValid()) + sb_breakpoint_loc.SetLocation( + Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent( + event.GetSP(), loc_idx)); + return sb_breakpoint_loc; +} - if (log) - log->Printf ("SBBreakpoint(%p)::MatchesName (name=%s)", - static_cast<void*>(m_opaque_sp.get()), - name); +uint32_t +SBBreakpoint::GetNumBreakpointLocationsFromEvent(const lldb::SBEvent &event) { + uint32_t num_locations = 0; + if (event.IsValid()) + num_locations = + (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent( + event.GetSP())); + return num_locations; +} - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->MatchesName(name); - } +// This is simple collection of breakpoint id's and their target. +class SBBreakpointListImpl { +public: + SBBreakpointListImpl(lldb::TargetSP target_sp) : m_target_wp() { + if (target_sp && target_sp->IsValid()) + m_target_wp = target_sp; + } + + ~SBBreakpointListImpl() = default; + + size_t GetSize() { return m_break_ids.size(); } + + BreakpointSP GetBreakpointAtIndex(size_t idx) { + if (idx >= m_break_ids.size()) + return BreakpointSP(); + TargetSP target_sp = m_target_wp.lock(); + if (!target_sp) + return BreakpointSP(); + lldb::break_id_t bp_id = m_break_ids[idx]; + return target_sp->GetBreakpointList().FindBreakpointByID(bp_id); + } + + BreakpointSP FindBreakpointByID(lldb::break_id_t desired_id) { + TargetSP target_sp = m_target_wp.lock(); + if (!target_sp) + return BreakpointSP(); + + for (lldb::break_id_t &break_id : m_break_ids) { + if (break_id == desired_id) + return target_sp->GetBreakpointList().FindBreakpointByID(break_id); + } + return BreakpointSP(); + } + + bool Append(Breakpoint &bkpt) { + TargetSP target_sp = m_target_wp.lock(); + if (!target_sp) + return false; + if (bkpt.GetTargetSP() != target_sp) + return false; + m_break_ids.push_back(bkpt.GetID()); + return true; + } + + bool AppendIfUnique(Breakpoint &bkpt) { + TargetSP target_sp = m_target_wp.lock(); + if (!target_sp) + return false; + if (bkpt.GetTargetSP() != target_sp) + return false; + lldb::break_id_t bp_id = bkpt.GetID(); + if (find(m_break_ids.begin(), m_break_ids.end(), bp_id) == + m_break_ids.end()) + return false; + + m_break_ids.push_back(bkpt.GetID()); + return true; + } + + bool AppendByID(lldb::break_id_t id) { + TargetSP target_sp = m_target_wp.lock(); + if (!target_sp) + return false; + if (id == LLDB_INVALID_BREAK_ID) + return false; + m_break_ids.push_back(id); + return true; + } + + void Clear() { m_break_ids.clear(); } + + void CopyToBreakpointIDList(lldb_private::BreakpointIDList &bp_list) { + for (lldb::break_id_t id : m_break_ids) { + bp_list.AddBreakpointID(BreakpointID(id)); + } + } + + TargetSP GetTarget() { return m_target_wp.lock(); } + +private: + std::vector<lldb::break_id_t> m_break_ids; + TargetWP m_target_wp; +}; - return false; -} +SBBreakpointList::SBBreakpointList(SBTarget &target) + : m_opaque_sp(new SBBreakpointListImpl(target.GetSP())) {} -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) - { - std::lock_guard<std::recursive_mutex> guard(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()); - } - } -} +SBBreakpointList::~SBBreakpointList() {} -lldb_private::Breakpoint * -SBBreakpoint::operator->() const -{ - return m_opaque_sp.get(); +size_t SBBreakpointList::GetSize() const { + if (!m_opaque_sp) + return 0; + else + return m_opaque_sp->GetSize(); } -lldb_private::Breakpoint * -SBBreakpoint::get() const -{ - return m_opaque_sp.get(); -} +SBBreakpoint SBBreakpointList::GetBreakpointAtIndex(size_t idx) { + if (!m_opaque_sp) + return SBBreakpoint(); -lldb::BreakpointSP & -SBBreakpoint::operator *() -{ - return m_opaque_sp; + BreakpointSP bkpt_sp = m_opaque_sp->GetBreakpointAtIndex(idx); + return SBBreakpoint(bkpt_sp); } -const lldb::BreakpointSP & -SBBreakpoint::operator *() const -{ - return m_opaque_sp; +SBBreakpoint SBBreakpointList::FindBreakpointByID(lldb::break_id_t id) { + if (!m_opaque_sp) + return SBBreakpoint(); + BreakpointSP bkpt_sp = m_opaque_sp->FindBreakpointByID(id); + return SBBreakpoint(bkpt_sp); } -bool -SBBreakpoint::EventIsBreakpointEvent (const lldb::SBEvent &event) -{ - return Breakpoint::BreakpointEventData::GetEventDataFromEvent(event.get()) != nullptr; +void SBBreakpointList::Append(const SBBreakpoint &sb_bkpt) { + if (!sb_bkpt.IsValid()) + return; + if (!m_opaque_sp) + return; + m_opaque_sp->Append(*sb_bkpt.get()); } -BreakpointEventType -SBBreakpoint::GetBreakpointEventTypeFromEvent (const SBEvent& event) -{ - if (event.IsValid()) - return Breakpoint::BreakpointEventData::GetBreakpointEventTypeFromEvent (event.GetSP()); - return eBreakpointEventTypeInvalidType; +void SBBreakpointList::AppendByID(lldb::break_id_t id) { + if (!m_opaque_sp) + return; + m_opaque_sp->AppendByID(id); } -SBBreakpoint -SBBreakpoint::GetBreakpointFromEvent (const lldb::SBEvent& event) -{ - SBBreakpoint sb_breakpoint; - if (event.IsValid()) - sb_breakpoint.m_opaque_sp = Breakpoint::BreakpointEventData::GetBreakpointFromEvent (event.GetSP()); - return sb_breakpoint; +bool SBBreakpointList::AppendIfUnique(const SBBreakpoint &sb_bkpt) { + if (!sb_bkpt.IsValid()) + return false; + if (!m_opaque_sp) + return false; + return m_opaque_sp->AppendIfUnique(*sb_bkpt.get()); } -SBBreakpointLocation -SBBreakpoint::GetBreakpointLocationAtIndexFromEvent (const lldb::SBEvent& event, uint32_t loc_idx) -{ - SBBreakpointLocation sb_breakpoint_loc; - if (event.IsValid()) - sb_breakpoint_loc.SetLocation (Breakpoint::BreakpointEventData::GetBreakpointLocationAtIndexFromEvent (event.GetSP(), loc_idx)); - return sb_breakpoint_loc; +void SBBreakpointList::Clear() { + if (m_opaque_sp) + m_opaque_sp->Clear(); } -uint32_t -SBBreakpoint::GetNumBreakpointLocationsFromEvent (const lldb::SBEvent &event) -{ - uint32_t num_locations = 0; - if (event.IsValid()) - num_locations = (Breakpoint::BreakpointEventData::GetNumBreakpointLocationsFromEvent (event.GetSP())); - return num_locations; +void SBBreakpointList::CopyToBreakpointIDList( + lldb_private::BreakpointIDList &bp_id_list) { + if (m_opaque_sp) + m_opaque_sp->CopyToBreakpointIDList(bp_id_list); } diff --git a/source/API/SBBreakpointLocation.cpp b/source/API/SBBreakpointLocation.cpp index 631a32bc9dda..c7fac7688f83 100644 --- a/source/API/SBBreakpointLocation.cpp +++ b/source/API/SBBreakpointLocation.cpp @@ -8,13 +8,11 @@ //===----------------------------------------------------------------------===// #include "lldb/API/SBBreakpointLocation.h" -#include "lldb/API/SBDefines.h" #include "lldb/API/SBAddress.h" #include "lldb/API/SBDebugger.h" +#include "lldb/API/SBDefines.h" #include "lldb/API/SBStream.h" -#include "lldb/lldb-types.h" -#include "lldb/lldb-defines.h" #include "lldb/Breakpoint/Breakpoint.h" #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Debugger.h" @@ -23,347 +21,296 @@ #include "lldb/Core/StreamFile.h" #include "lldb/Interpreter/CommandInterpreter.h" #include "lldb/Interpreter/ScriptInterpreter.h" -#include "lldb/Target/ThreadSpec.h" #include "lldb/Target/Target.h" #include "lldb/Target/ThreadSpec.h" +#include "lldb/Target/ThreadSpec.h" +#include "lldb/lldb-defines.h" +#include "lldb/lldb-types.h" using namespace lldb; using namespace lldb_private; - -SBBreakpointLocation::SBBreakpointLocation () : - m_opaque_sp () -{ +SBBreakpointLocation::SBBreakpointLocation() : m_opaque_sp() {} + +SBBreakpointLocation::SBBreakpointLocation( + const lldb::BreakpointLocationSP &break_loc_sp) + : m_opaque_sp(break_loc_sp) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) { + SBStream sstr; + GetDescription(sstr, lldb::eDescriptionLevelBrief); + log->Printf("SBBreakpointLocation::SBBreakpointLocaiton (const " + "lldb::BreakpointLocationsSP &break_loc_sp" + "=%p) => this.sp = %p (%s)", + static_cast<void *>(break_loc_sp.get()), + static_cast<void *>(m_opaque_sp.get()), sstr.GetData()); + } } -SBBreakpointLocation::SBBreakpointLocation (const lldb::BreakpointLocationSP &break_loc_sp) : - m_opaque_sp (break_loc_sp) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - { - SBStream sstr; - GetDescription (sstr, lldb::eDescriptionLevelBrief); - log->Printf ("SBBreakpointLocation::SBBreakpointLocaiton (const lldb::BreakpointLocationsSP &break_loc_sp" - "=%p) => this.sp = %p (%s)", - static_cast<void*>(break_loc_sp.get()), - static_cast<void*>(m_opaque_sp.get()), sstr.GetData()); - } -} +SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) + : m_opaque_sp(rhs.m_opaque_sp) {} -SBBreakpointLocation::SBBreakpointLocation(const SBBreakpointLocation &rhs) : - m_opaque_sp (rhs.m_opaque_sp) -{ +const SBBreakpointLocation &SBBreakpointLocation:: +operator=(const SBBreakpointLocation &rhs) { + if (this != &rhs) + m_opaque_sp = rhs.m_opaque_sp; + return *this; } -const SBBreakpointLocation & -SBBreakpointLocation::operator = (const SBBreakpointLocation &rhs) -{ - if (this != &rhs) - m_opaque_sp = rhs.m_opaque_sp; - return *this; -} +SBBreakpointLocation::~SBBreakpointLocation() {} +bool SBBreakpointLocation::IsValid() const { return m_opaque_sp.get() != NULL; } -SBBreakpointLocation::~SBBreakpointLocation () -{ +SBAddress SBBreakpointLocation::GetAddress() { + if (m_opaque_sp) + return SBAddress(&m_opaque_sp->GetAddress()); + else + return SBAddress(); } -bool -SBBreakpointLocation::IsValid() const -{ - return m_opaque_sp.get() != NULL; -} - -SBAddress -SBBreakpointLocation::GetAddress () -{ - if (m_opaque_sp) - return SBAddress(&m_opaque_sp->GetAddress()); - else - return SBAddress(); -} +addr_t SBBreakpointLocation::GetLoadAddress() { + addr_t ret_addr = LLDB_INVALID_ADDRESS; -addr_t -SBBreakpointLocation::GetLoadAddress () -{ - addr_t ret_addr = LLDB_INVALID_ADDRESS; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + ret_addr = m_opaque_sp->GetLoadAddress(); + } - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - ret_addr = m_opaque_sp->GetLoadAddress(); - } - - return ret_addr; + return ret_addr; } -void -SBBreakpointLocation::SetEnabled (bool enabled) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetEnabled (enabled); - } +void SBBreakpointLocation::SetEnabled(bool enabled) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetEnabled(enabled); + } } -bool -SBBreakpointLocation::IsEnabled () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->IsEnabled(); - } - else - return false; +bool SBBreakpointLocation::IsEnabled() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->IsEnabled(); + } else + return false; } -uint32_t -SBBreakpointLocation::GetIgnoreCount () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetIgnoreCount(); - } - else - return 0; +uint32_t SBBreakpointLocation::GetIgnoreCount() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetIgnoreCount(); + } else + return 0; } -void -SBBreakpointLocation::SetIgnoreCount (uint32_t n) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetIgnoreCount (n); - } +void SBBreakpointLocation::SetIgnoreCount(uint32_t n) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetIgnoreCount(n); + } } -void -SBBreakpointLocation::SetCondition (const char *condition) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetCondition (condition); - } +void SBBreakpointLocation::SetCondition(const char *condition) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetCondition(condition); + } } -const char * -SBBreakpointLocation::GetCondition () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetConditionText (); - } - return NULL; +const char *SBBreakpointLocation::GetCondition() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetConditionText(); + } + return NULL; } -void -SBBreakpointLocation::SetScriptCallbackFunction (const char *callback_function_name) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)", - static_cast<void*>(m_opaque_sp.get()), - callback_function_name); - - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); - m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallbackFunction (bp_options, - callback_function_name); - } +void SBBreakpointLocation::SetScriptCallbackFunction( + const char *callback_function_name) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf( + "SBBreakpointLocation(%p)::SetScriptCallbackFunction (callback=%s)", + static_cast<void *>(m_opaque_sp.get()), callback_function_name); + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); + m_opaque_sp->GetBreakpoint() + .GetTarget() + .GetDebugger() + .GetCommandInterpreter() + .GetScriptInterpreter() + ->SetBreakpointCommandCallbackFunction(bp_options, + callback_function_name); + } } SBError -SBBreakpointLocation::SetScriptCallbackBody (const char *callback_body_text) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", - static_cast<void*>(m_opaque_sp.get()), callback_body_text); - - SBError sb_error; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); - Error error = m_opaque_sp->GetBreakpoint().GetTarget().GetDebugger().GetCommandInterpreter().GetScriptInterpreter()->SetBreakpointCommandCallback (bp_options, - callback_body_text); - sb_error.SetError(error); - } - else - sb_error.SetErrorString("invalid breakpoint"); - - return sb_error; +SBBreakpointLocation::SetScriptCallbackBody(const char *callback_body_text) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf("SBBreakpoint(%p)::SetScriptCallbackBody: callback body:\n%s)", + static_cast<void *>(m_opaque_sp.get()), callback_body_text); + + SBError sb_error; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + BreakpointOptions *bp_options = m_opaque_sp->GetLocationOptions(); + Error error = + m_opaque_sp->GetBreakpoint() + .GetTarget() + .GetDebugger() + .GetCommandInterpreter() + .GetScriptInterpreter() + ->SetBreakpointCommandCallback(bp_options, callback_body_text); + sb_error.SetError(error); + } else + sb_error.SetErrorString("invalid breakpoint"); + + return sb_error; } -void -SBBreakpointLocation::SetThreadID (tid_t thread_id) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetThreadID (thread_id); - } +void SBBreakpointLocation::SetThreadID(tid_t thread_id) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetThreadID(thread_id); + } } -tid_t -SBBreakpointLocation::GetThreadID () -{ - tid_t tid = LLDB_INVALID_THREAD_ID; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetThreadID(); - } - return tid; +tid_t SBBreakpointLocation::GetThreadID() { + tid_t tid = LLDB_INVALID_THREAD_ID; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetThreadID(); + } + return tid; } -void -SBBreakpointLocation::SetThreadIndex (uint32_t index) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetThreadIndex (index); - } +void SBBreakpointLocation::SetThreadIndex(uint32_t index) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetThreadIndex(index); + } } -uint32_t -SBBreakpointLocation::GetThreadIndex() const -{ - uint32_t thread_idx = UINT32_MAX; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetThreadIndex(); - } - return thread_idx; -} - - -void -SBBreakpointLocation::SetThreadName (const char *thread_name) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetThreadName (thread_name); - } +uint32_t SBBreakpointLocation::GetThreadIndex() const { + uint32_t thread_idx = UINT32_MAX; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetThreadIndex(); + } + return thread_idx; } -const char * -SBBreakpointLocation::GetThreadName () const -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetThreadName(); - } - return NULL; +void SBBreakpointLocation::SetThreadName(const char *thread_name) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetThreadName(thread_name); + } } -void -SBBreakpointLocation::SetQueueName (const char *queue_name) -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->SetQueueName (queue_name); - } +const char *SBBreakpointLocation::GetThreadName() const { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetThreadName(); + } + return NULL; } -const char * -SBBreakpointLocation::GetQueueName () const -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetQueueName (); - } - return NULL; +void SBBreakpointLocation::SetQueueName(const char *queue_name) { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->SetQueueName(queue_name); + } } -bool -SBBreakpointLocation::IsResolved () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->IsResolved(); - } - return false; +const char *SBBreakpointLocation::GetQueueName() const { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->GetQueueName(); + } + return NULL; } -void -SBBreakpointLocation::SetLocation (const lldb::BreakpointLocationSP &break_loc_sp) -{ - // Uninstall the callbacks? - m_opaque_sp = break_loc_sp; +bool SBBreakpointLocation::IsResolved() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->IsResolved(); + } + return false; } -bool -SBBreakpointLocation::GetDescription (SBStream &description, DescriptionLevel level) -{ - Stream &strm = description.ref(); - - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - m_opaque_sp->GetDescription (&strm, level); - strm.EOL(); - } - else - strm.PutCString ("No value"); - - return true; +void SBBreakpointLocation::SetLocation( + const lldb::BreakpointLocationSP &break_loc_sp) { + // Uninstall the callbacks? + m_opaque_sp = break_loc_sp; } -break_id_t -SBBreakpointLocation::GetID () -{ - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - return m_opaque_sp->GetID (); - } - else - return LLDB_INVALID_BREAK_ID; +bool SBBreakpointLocation::GetDescription(SBStream &description, + DescriptionLevel level) { + Stream &strm = description.ref(); + + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + m_opaque_sp->GetDescription(&strm, level); + strm.EOL(); + } else + strm.PutCString("No value"); + + return true; } -SBBreakpoint -SBBreakpointLocation::GetBreakpoint () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - //if (log) - // log->Printf ("SBBreakpointLocation::GetBreakpoint ()"); - - SBBreakpoint sb_bp; - if (m_opaque_sp) - { - std::lock_guard<std::recursive_mutex> guard(m_opaque_sp->GetTarget().GetAPIMutex()); - *sb_bp = m_opaque_sp->GetBreakpoint ().shared_from_this(); - } - - if (log) - { - SBStream sstr; - sb_bp.GetDescription (sstr); - log->Printf ("SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s", - static_cast<void*>(m_opaque_sp.get()), - static_cast<void*>(sb_bp.get()), sstr.GetData()); - } - return sb_bp; +break_id_t SBBreakpointLocation::GetID() { + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + return m_opaque_sp->GetID(); + } else + return LLDB_INVALID_BREAK_ID; } +SBBreakpoint SBBreakpointLocation::GetBreakpoint() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + // if (log) + // log->Printf ("SBBreakpointLocation::GetBreakpoint ()"); + + SBBreakpoint sb_bp; + if (m_opaque_sp) { + std::lock_guard<std::recursive_mutex> guard( + m_opaque_sp->GetTarget().GetAPIMutex()); + *sb_bp = m_opaque_sp->GetBreakpoint().shared_from_this(); + } + + if (log) { + SBStream sstr; + sb_bp.GetDescription(sstr); + log->Printf( + "SBBreakpointLocation(%p)::GetBreakpoint () => SBBreakpoint(%p) %s", + static_cast<void *>(m_opaque_sp.get()), + static_cast<void *>(sb_bp.get()), sstr.GetData()); + } + return sb_bp; +} diff --git a/source/API/SBBroadcaster.cpp b/source/API/SBBroadcaster.cpp index 4b751adc295f..5189dd7bb271 100644 --- a/source/API/SBBroadcaster.cpp +++ b/source/API/SBBroadcaster.cpp @@ -11,192 +11,151 @@ #include "lldb/Core/Log.h" #include "lldb/API/SBBroadcaster.h" -#include "lldb/API/SBListener.h" #include "lldb/API/SBEvent.h" +#include "lldb/API/SBListener.h" using namespace lldb; using namespace lldb_private; +SBBroadcaster::SBBroadcaster() : m_opaque_sp(), m_opaque_ptr(NULL) {} -SBBroadcaster::SBBroadcaster () : - m_opaque_sp (), - m_opaque_ptr (NULL) -{ -} - -SBBroadcaster::SBBroadcaster (const char *name) : - m_opaque_sp (new Broadcaster (NULL, name)), - m_opaque_ptr (NULL) -{ - m_opaque_ptr = m_opaque_sp.get(); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE)); +SBBroadcaster::SBBroadcaster(const char *name) + : m_opaque_sp(new Broadcaster(NULL, name)), m_opaque_ptr(NULL) { + m_opaque_ptr = m_opaque_sp.get(); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API | + LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf ("SBBroadcaster::SBBroadcaster (name=\"%s\") => SBBroadcaster(%p)", - name, static_cast<void*>(m_opaque_ptr)); + if (log) + log->Printf( + "SBBroadcaster::SBBroadcaster (name=\"%s\") => SBBroadcaster(%p)", name, + static_cast<void *>(m_opaque_ptr)); } -SBBroadcaster::SBBroadcaster (lldb_private::Broadcaster *broadcaster, bool owns) : - m_opaque_sp (owns ? broadcaster : NULL), - m_opaque_ptr (broadcaster) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API | LIBLLDB_LOG_VERBOSE)); +SBBroadcaster::SBBroadcaster(lldb_private::Broadcaster *broadcaster, bool owns) + : m_opaque_sp(owns ? broadcaster : NULL), m_opaque_ptr(broadcaster) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API | + LIBLLDB_LOG_VERBOSE)); - if (log) - log->Printf ("SBBroadcaster::SBBroadcaster (broadcaster=%p, bool owns=%i) => SBBroadcaster(%p)", - static_cast<void*>(broadcaster), owns, - static_cast<void*>(m_opaque_ptr)); + if (log) + log->Printf("SBBroadcaster::SBBroadcaster (broadcaster=%p, bool owns=%i) " + "=> SBBroadcaster(%p)", + static_cast<void *>(broadcaster), owns, + static_cast<void *>(m_opaque_ptr)); } -SBBroadcaster::SBBroadcaster (const SBBroadcaster &rhs) : - m_opaque_sp (rhs.m_opaque_sp), - m_opaque_ptr (rhs.m_opaque_ptr) -{ -} +SBBroadcaster::SBBroadcaster(const SBBroadcaster &rhs) + : m_opaque_sp(rhs.m_opaque_sp), m_opaque_ptr(rhs.m_opaque_ptr) {} -const SBBroadcaster & -SBBroadcaster::operator = (const SBBroadcaster &rhs) -{ - if (this != &rhs) - { - m_opaque_sp = rhs.m_opaque_sp; - m_opaque_ptr = rhs.m_opaque_ptr; - } - return *this; +const SBBroadcaster &SBBroadcaster::operator=(const SBBroadcaster &rhs) { + if (this != &rhs) { + m_opaque_sp = rhs.m_opaque_sp; + m_opaque_ptr = rhs.m_opaque_ptr; + } + return *this; } -SBBroadcaster::~SBBroadcaster() -{ - reset (NULL, false); -} +SBBroadcaster::~SBBroadcaster() { reset(NULL, false); } -void -SBBroadcaster::BroadcastEventByType (uint32_t event_type, bool unique) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +void SBBroadcaster::BroadcastEventByType(uint32_t event_type, bool unique) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBroadcaster(%p)::BroadcastEventByType (event_type=0x%8.8x, unique=%i)", - static_cast<void*>(m_opaque_ptr), event_type, unique); + if (log) + log->Printf("SBBroadcaster(%p)::BroadcastEventByType (event_type=0x%8.8x, " + "unique=%i)", + static_cast<void *>(m_opaque_ptr), event_type, unique); - if (m_opaque_ptr == NULL) - return; + if (m_opaque_ptr == NULL) + return; - if (unique) - m_opaque_ptr->BroadcastEventIfUnique (event_type); - else - m_opaque_ptr->BroadcastEvent (event_type); + if (unique) + m_opaque_ptr->BroadcastEventIfUnique(event_type); + else + m_opaque_ptr->BroadcastEvent(event_type); } -void -SBBroadcaster::BroadcastEvent (const SBEvent &event, bool unique) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +void SBBroadcaster::BroadcastEvent(const SBEvent &event, bool unique) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBroadcaster(%p)::BroadcastEventByType (SBEvent(%p), unique=%i)", - static_cast<void*>(m_opaque_ptr), - static_cast<void*>(event.get()), unique); + if (log) + log->Printf( + "SBBroadcaster(%p)::BroadcastEventByType (SBEvent(%p), unique=%i)", + static_cast<void *>(m_opaque_ptr), static_cast<void *>(event.get()), + unique); - if (m_opaque_ptr == NULL) - return; + if (m_opaque_ptr == NULL) + return; - EventSP event_sp = event.GetSP (); - if (unique) - m_opaque_ptr->BroadcastEventIfUnique (event_sp); - else - m_opaque_ptr->BroadcastEvent (event_sp); + EventSP event_sp = event.GetSP(); + if (unique) + m_opaque_ptr->BroadcastEventIfUnique(event_sp); + else + m_opaque_ptr->BroadcastEvent(event_sp); } -void -SBBroadcaster::AddInitialEventsToListener (const SBListener &listener, uint32_t requested_events) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBBroadcaster(%p)::AddInitialEventsToListener (SBListener(%p), event_mask=0x%8.8x)", - static_cast<void*>(m_opaque_ptr), - static_cast<void*>(listener.get()), requested_events); - if (m_opaque_ptr) - m_opaque_ptr->AddInitialEventsToListener (listener.m_opaque_sp, requested_events); +void SBBroadcaster::AddInitialEventsToListener(const SBListener &listener, + uint32_t requested_events) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBBroadcaster(%p)::AddInitialEventsToListener " + "(SBListener(%p), event_mask=0x%8.8x)", + static_cast<void *>(m_opaque_ptr), + static_cast<void *>(listener.get()), requested_events); + if (m_opaque_ptr) + m_opaque_ptr->AddInitialEventsToListener(listener.m_opaque_sp, + requested_events); } -uint32_t -SBBroadcaster::AddListener (const SBListener &listener, uint32_t event_mask) -{ - if (m_opaque_ptr) - return m_opaque_ptr->AddListener (listener.m_opaque_sp, event_mask); - return 0; +uint32_t SBBroadcaster::AddListener(const SBListener &listener, + uint32_t event_mask) { + if (m_opaque_ptr) + return m_opaque_ptr->AddListener(listener.m_opaque_sp, event_mask); + return 0; } -const char * -SBBroadcaster::GetName () const -{ - if (m_opaque_ptr) - return m_opaque_ptr->GetBroadcasterName().GetCString(); - return NULL; +const char *SBBroadcaster::GetName() const { + if (m_opaque_ptr) + return m_opaque_ptr->GetBroadcasterName().GetCString(); + return NULL; } -bool -SBBroadcaster::EventTypeHasListeners (uint32_t event_type) -{ - if (m_opaque_ptr) - return m_opaque_ptr->EventTypeHasListeners (event_type); - return false; +bool SBBroadcaster::EventTypeHasListeners(uint32_t event_type) { + if (m_opaque_ptr) + return m_opaque_ptr->EventTypeHasListeners(event_type); + return false; } -bool -SBBroadcaster::RemoveListener (const SBListener &listener, uint32_t event_mask) -{ - if (m_opaque_ptr) - return m_opaque_ptr->RemoveListener (listener.m_opaque_sp, event_mask); - return false; +bool SBBroadcaster::RemoveListener(const SBListener &listener, + uint32_t event_mask) { + if (m_opaque_ptr) + return m_opaque_ptr->RemoveListener(listener.m_opaque_sp, event_mask); + return false; } -Broadcaster * -SBBroadcaster::get () const -{ - return m_opaque_ptr; -} +Broadcaster *SBBroadcaster::get() const { return m_opaque_ptr; } -void -SBBroadcaster::reset (Broadcaster *broadcaster, bool owns) -{ - if (owns) - m_opaque_sp.reset (broadcaster); - else - m_opaque_sp.reset (); - m_opaque_ptr = broadcaster; +void SBBroadcaster::reset(Broadcaster *broadcaster, bool owns) { + if (owns) + m_opaque_sp.reset(broadcaster); + else + m_opaque_sp.reset(); + m_opaque_ptr = broadcaster; } +bool SBBroadcaster::IsValid() const { return m_opaque_ptr != NULL; } -bool -SBBroadcaster::IsValid () const -{ - return m_opaque_ptr != NULL; -} - -void -SBBroadcaster::Clear () -{ - m_opaque_sp.reset(); - m_opaque_ptr = NULL; +void SBBroadcaster::Clear() { + m_opaque_sp.reset(); + m_opaque_ptr = NULL; } -bool -SBBroadcaster::operator == (const SBBroadcaster &rhs) const -{ - return m_opaque_ptr == rhs.m_opaque_ptr; - +bool SBBroadcaster::operator==(const SBBroadcaster &rhs) const { + return m_opaque_ptr == rhs.m_opaque_ptr; } -bool -SBBroadcaster::operator != (const SBBroadcaster &rhs) const -{ - return m_opaque_ptr != rhs.m_opaque_ptr; +bool SBBroadcaster::operator!=(const SBBroadcaster &rhs) const { + return m_opaque_ptr != rhs.m_opaque_ptr; } -bool -SBBroadcaster::operator < (const SBBroadcaster &rhs) const -{ - return m_opaque_ptr < rhs.m_opaque_ptr; +bool SBBroadcaster::operator<(const SBBroadcaster &rhs) const { + return m_opaque_ptr < rhs.m_opaque_ptr; } diff --git a/source/API/SBCommandInterpreter.cpp b/source/API/SBCommandInterpreter.cpp index dfa1709a3491..aa4953999b84 100644 --- a/source/API/SBCommandInterpreter.cpp +++ b/source/API/SBCommandInterpreter.cpp @@ -20,672 +20,597 @@ #include "lldb/Target/Target.h" #include "lldb/API/SBBroadcaster.h" -#include "lldb/API/SBCommandReturnObject.h" #include "lldb/API/SBCommandInterpreter.h" +#include "lldb/API/SBCommandReturnObject.h" #include "lldb/API/SBEvent.h" #include "lldb/API/SBExecutionContext.h" -#include "lldb/API/SBProcess.h" -#include "lldb/API/SBTarget.h" #include "lldb/API/SBListener.h" +#include "lldb/API/SBProcess.h" #include "lldb/API/SBStream.h" #include "lldb/API/SBStringList.h" +#include "lldb/API/SBTarget.h" using namespace lldb; using namespace lldb_private; -SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() -{ - m_opaque_up.reset(new CommandInterpreterRunOptions()); +SBCommandInterpreterRunOptions::SBCommandInterpreterRunOptions() { + m_opaque_up.reset(new CommandInterpreterRunOptions()); } SBCommandInterpreterRunOptions::~SBCommandInterpreterRunOptions() = default; -bool -SBCommandInterpreterRunOptions::GetStopOnContinue () const -{ - return m_opaque_up->GetStopOnContinue(); +bool SBCommandInterpreterRunOptions::GetStopOnContinue() const { + return m_opaque_up->GetStopOnContinue(); } -void -SBCommandInterpreterRunOptions::SetStopOnContinue (bool stop_on_continue) -{ - m_opaque_up->SetStopOnContinue(stop_on_continue); +void SBCommandInterpreterRunOptions::SetStopOnContinue(bool stop_on_continue) { + m_opaque_up->SetStopOnContinue(stop_on_continue); } -bool -SBCommandInterpreterRunOptions::GetStopOnError () const -{ - return m_opaque_up->GetStopOnError(); +bool SBCommandInterpreterRunOptions::GetStopOnError() const { + return m_opaque_up->GetStopOnError(); } -void -SBCommandInterpreterRunOptions::SetStopOnError (bool stop_on_error) -{ - m_opaque_up->SetStopOnError(stop_on_error); +void SBCommandInterpreterRunOptions::SetStopOnError(bool stop_on_error) { + m_opaque_up->SetStopOnError(stop_on_error); } -bool -SBCommandInterpreterRunOptions::GetStopOnCrash () const -{ - return m_opaque_up->GetStopOnCrash(); +bool SBCommandInterpreterRunOptions::GetStopOnCrash() const { + return m_opaque_up->GetStopOnCrash(); } -void -SBCommandInterpreterRunOptions::SetStopOnCrash (bool stop_on_crash) -{ - m_opaque_up->SetStopOnCrash(stop_on_crash); +void SBCommandInterpreterRunOptions::SetStopOnCrash(bool stop_on_crash) { + m_opaque_up->SetStopOnCrash(stop_on_crash); } -bool -SBCommandInterpreterRunOptions::GetEchoCommands () const -{ - return m_opaque_up->GetEchoCommands(); +bool SBCommandInterpreterRunOptions::GetEchoCommands() const { + return m_opaque_up->GetEchoCommands(); } -void -SBCommandInterpreterRunOptions::SetEchoCommands (bool echo_commands) -{ - m_opaque_up->SetEchoCommands(echo_commands); +void SBCommandInterpreterRunOptions::SetEchoCommands(bool echo_commands) { + m_opaque_up->SetEchoCommands(echo_commands); } -bool -SBCommandInterpreterRunOptions::GetPrintResults () const -{ - return m_opaque_up->GetPrintResults(); +bool SBCommandInterpreterRunOptions::GetPrintResults() const { + return m_opaque_up->GetPrintResults(); } -void -SBCommandInterpreterRunOptions::SetPrintResults (bool print_results) -{ - m_opaque_up->SetPrintResults(print_results); +void SBCommandInterpreterRunOptions::SetPrintResults(bool print_results) { + m_opaque_up->SetPrintResults(print_results); } -bool -SBCommandInterpreterRunOptions::GetAddToHistory () const -{ - return m_opaque_up->GetAddToHistory(); +bool SBCommandInterpreterRunOptions::GetAddToHistory() const { + return m_opaque_up->GetAddToHistory(); } -void -SBCommandInterpreterRunOptions::SetAddToHistory (bool add_to_history) -{ - m_opaque_up->SetAddToHistory(add_to_history); +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(); +SBCommandInterpreterRunOptions::get() const { + return m_opaque_up.get(); } lldb_private::CommandInterpreterRunOptions & -SBCommandInterpreterRunOptions::ref () const -{ - return *m_opaque_up.get(); +SBCommandInterpreterRunOptions::ref() const { + return *m_opaque_up.get(); } -class CommandPluginInterfaceImplementation : public CommandObjectParsed -{ +class CommandPluginInterfaceImplementation : public CommandObjectParsed { public: - CommandPluginInterfaceImplementation(CommandInterpreter &interpreter, - const char *name, - lldb::SBCommandPluginInterface* backend, - const char *help = nullptr, - const char *syntax = nullptr, - uint32_t flags = 0) : - CommandObjectParsed (interpreter, name, help, syntax, flags), - m_backend(backend) {} - - bool - IsRemovable() const override - { - return true; - } - + CommandPluginInterfaceImplementation(CommandInterpreter &interpreter, + const char *name, + lldb::SBCommandPluginInterface *backend, + const char *help = nullptr, + const char *syntax = nullptr, + uint32_t flags = 0) + : CommandObjectParsed(interpreter, name, help, syntax, flags), + m_backend(backend) {} + + bool IsRemovable() const override { return true; } + protected: - bool - DoExecute(Args& command, CommandReturnObject &result) override - { - SBCommandReturnObject sb_return(&result); - SBCommandInterpreter sb_interpreter(&m_interpreter); - SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); - bool ret = m_backend->DoExecute (debugger_sb,(char**)command.GetArgumentVector(), sb_return); - sb_return.Release(); - return ret; - } - lldb::SBCommandPluginInterface* m_backend; + bool DoExecute(Args &command, CommandReturnObject &result) override { + SBCommandReturnObject sb_return(&result); + SBCommandInterpreter sb_interpreter(&m_interpreter); + SBDebugger debugger_sb(m_interpreter.GetDebugger().shared_from_this()); + bool ret = m_backend->DoExecute( + debugger_sb, (char **)command.GetArgumentVector(), sb_return); + sb_return.Release(); + return ret; + } + std::shared_ptr<lldb::SBCommandPluginInterface> m_backend; }; -SBCommandInterpreter::SBCommandInterpreter (CommandInterpreter *interpreter) : - m_opaque_ptr (interpreter) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +SBCommandInterpreter::SBCommandInterpreter(CommandInterpreter *interpreter) + : m_opaque_ptr(interpreter) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)" - " => SBCommandInterpreter(%p)", - static_cast<void*>(interpreter), - static_cast<void*>(m_opaque_ptr)); + if (log) + log->Printf("SBCommandInterpreter::SBCommandInterpreter (interpreter=%p)" + " => SBCommandInterpreter(%p)", + static_cast<void *>(interpreter), + static_cast<void *>(m_opaque_ptr)); } -SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) : - m_opaque_ptr (rhs.m_opaque_ptr) -{ -} +SBCommandInterpreter::SBCommandInterpreter(const SBCommandInterpreter &rhs) + : m_opaque_ptr(rhs.m_opaque_ptr) {} SBCommandInterpreter::~SBCommandInterpreter() = default; -const SBCommandInterpreter & -SBCommandInterpreter::operator = (const SBCommandInterpreter &rhs) -{ - m_opaque_ptr = rhs.m_opaque_ptr; - return *this; +const SBCommandInterpreter &SBCommandInterpreter:: +operator=(const SBCommandInterpreter &rhs) { + m_opaque_ptr = rhs.m_opaque_ptr; + return *this; } -bool -SBCommandInterpreter::IsValid() const -{ - return m_opaque_ptr != nullptr; -} - -bool -SBCommandInterpreter::CommandExists(const char *cmd) -{ - return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd) : false); -} +bool SBCommandInterpreter::IsValid() const { return m_opaque_ptr != nullptr; } -bool -SBCommandInterpreter::AliasExists (const char *cmd) -{ - return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd) : false); +bool SBCommandInterpreter::CommandExists(const char *cmd) { + return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->CommandExists(cmd) + : false); } -bool -SBCommandInterpreter::IsActive() -{ - return (IsValid() ? m_opaque_ptr->IsActive() : false); +bool SBCommandInterpreter::AliasExists(const char *cmd) { + return (((cmd != nullptr) && IsValid()) ? m_opaque_ptr->AliasExists(cmd) + : false); } -const char * -SBCommandInterpreter::GetIOHandlerControlSequence(char ch) -{ - return (IsValid() ? m_opaque_ptr->GetDebugger().GetTopIOHandlerControlSequence(ch).GetCString() : nullptr); +bool SBCommandInterpreter::IsActive() { + return (IsValid() ? m_opaque_ptr->IsActive() : false); } -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); +const char *SBCommandInterpreter::GetIOHandlerControlSequence(char ch) { + return (IsValid() + ? m_opaque_ptr->GetDebugger() + .GetTopIOHandlerControlSequence(ch) + .GetCString() + : nullptr); } 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) - log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p), add_to_history=%i)", - 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; +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) + log->Printf("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", " + "SBCommandReturnObject(%p), add_to_history=%i)", + 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 && IsValid()) { + result.ref().SetInteractive(false); + m_opaque_ptr->HandleCommand(command_line, + add_to_history ? eLazyBoolYes : eLazyBoolNo, + result.ref(), ctx_ptr); + } else { + result->AppendError( + "SBCommandInterpreter or the command line is not valid"); + result->SetStatus(eReturnStatusFailed); + } + + // We need to get the value again, in case the command disabled the log! + log = lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API); + if (log) { + SBStream sstr; + result.GetDescription(sstr); + log->Printf("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", " + "SBCommandReturnObject(%p): %s, add_to_history=%i) => %i", + static_cast<void *>(m_opaque_ptr), command_line, + static_cast<void *>(result.get()), sstr.GetData(), + add_to_history, result.GetStatus()); + } + + 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 (!IsValid()) { + 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, const char *last_char, + int match_start_point, int max_return_elements, SBStringList &matches) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + int num_completions = 0; + + // Sanity check the arguments that are passed in: + // cursor & last_char have to be within the current_line. + if (current_line == nullptr || cursor == nullptr || last_char == nullptr) + return 0; + + if (cursor < current_line || last_char < current_line) + return 0; + + size_t current_line_size = strlen(current_line); + if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) || + last_char - current_line > static_cast<ptrdiff_t>(current_line_size)) + return 0; + + if (log) + log->Printf("SBCommandInterpreter(%p)::HandleCompletion " + "(current_line=\"%s\", cursor at: %" PRId64 + ", last char at: %" PRId64 + ", match_start_point: %d, max_return_elements: %d)", + static_cast<void *>(m_opaque_ptr), current_line, + static_cast<uint64_t>(cursor - current_line), + static_cast<uint64_t>(last_char - current_line), + match_start_point, max_return_elements); + + if (IsValid()) { + lldb_private::StringList lldb_matches; + num_completions = m_opaque_ptr->HandleCompletion( + current_line, cursor, last_char, match_start_point, max_return_elements, + lldb_matches); + + SBStringList temp_list(&lldb_matches); + matches.AppendList(temp_list); + } + if (log) + log->Printf( + "SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", + static_cast<void *>(m_opaque_ptr), num_completions); + + return num_completions; +} + +int SBCommandInterpreter::HandleCompletion(const char *current_line, + uint32_t cursor_pos, + int match_start_point, + int max_return_elements, + lldb::SBStringList &matches) { + const char *cursor = current_line + cursor_pos; + const char *last_char = current_line + strlen(current_line); + return HandleCompletion(current_line, cursor, last_char, match_start_point, + max_return_elements, matches); +} + +bool SBCommandInterpreter::HasCommands() { + return (IsValid() ? m_opaque_ptr->HasCommands() : false); +} + +bool SBCommandInterpreter::HasAliases() { + return (IsValid() ? m_opaque_ptr->HasAliases() : false); +} + +bool SBCommandInterpreter::HasAliasOptions() { + return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false); +} + +SBProcess SBCommandInterpreter::GetProcess() { + SBProcess sb_process; + ProcessSP process_sp; + if (IsValid()) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + if (target_sp) { + std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); + process_sp = target_sp->GetProcessSP(); + sb_process.SetSP(process_sp); } - else - ctx_ptr = nullptr; - + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - result.Clear(); - if (command_line && IsValid()) - { - result.ref().SetInteractive(false); - m_opaque_ptr->HandleCommand (command_line, add_to_history ? eLazyBoolYes : eLazyBoolNo, result.ref(), ctx_ptr); - } - else - { - result->AppendError ("SBCommandInterpreter or the command line is not valid"); - result->SetStatus (eReturnStatusFailed); - } + if (log) + log->Printf("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", + static_cast<void *>(m_opaque_ptr), + static_cast<void *>(process_sp.get())); - // We need to get the value again, in case the command disabled the log! - log = lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API); - if (log) - { - SBStream sstr; - result.GetDescription (sstr); - log->Printf ("SBCommandInterpreter(%p)::HandleCommand (command=\"%s\", SBCommandReturnObject(%p): %s, add_to_history=%i) => %i", - static_cast<void*>(m_opaque_ptr), command_line, - static_cast<void*>(result.get()), sstr.GetData(), - add_to_history, result.GetStatus()); - } - - return result.GetStatus(); + return sb_process; } -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 (!IsValid()) - { - 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, - const char *last_char, - int match_start_point, - int max_return_elements, - SBStringList &matches) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - int num_completions = 0; - - // Sanity check the arguments that are passed in: - // cursor & last_char have to be within the current_line. - if (current_line == nullptr || cursor == nullptr || last_char == nullptr) - return 0; - - if (cursor < current_line || last_char < current_line) - return 0; - - size_t current_line_size = strlen (current_line); - if (cursor - current_line > static_cast<ptrdiff_t>(current_line_size) || - last_char - current_line > static_cast<ptrdiff_t>(current_line_size)) - return 0; - - if (log) - log->Printf ("SBCommandInterpreter(%p)::HandleCompletion (current_line=\"%s\", cursor at: %" PRId64 ", last char at: %" PRId64 ", match_start_point: %d, max_return_elements: %d)", - static_cast<void*>(m_opaque_ptr), current_line, - static_cast<uint64_t>(cursor - current_line), - static_cast<uint64_t>(last_char - current_line), - match_start_point, max_return_elements); - - if (IsValid()) - { - lldb_private::StringList lldb_matches; - num_completions = m_opaque_ptr->HandleCompletion(current_line, cursor, last_char, match_start_point, - max_return_elements, lldb_matches); - - SBStringList temp_list (&lldb_matches); - matches.AppendList (temp_list); - } - if (log) - log->Printf ("SBCommandInterpreter(%p)::HandleCompletion - Found %d completions.", - static_cast<void*>(m_opaque_ptr), num_completions); - - return num_completions; -} - -int -SBCommandInterpreter::HandleCompletion (const char *current_line, - uint32_t cursor_pos, - int match_start_point, - int max_return_elements, - lldb::SBStringList &matches) -{ - const char *cursor = current_line + cursor_pos; - const char *last_char = current_line + strlen (current_line); - return HandleCompletion (current_line, cursor, last_char, match_start_point, max_return_elements, matches); -} - -bool -SBCommandInterpreter::HasCommands() -{ - return (IsValid() ? m_opaque_ptr->HasCommands() : false); -} - -bool -SBCommandInterpreter::HasAliases() -{ - return (IsValid() ? m_opaque_ptr->HasAliases() : false); -} - -bool -SBCommandInterpreter::HasAliasOptions() -{ - return (IsValid() ? m_opaque_ptr->HasAliasOptions() : false); -} - -SBProcess -SBCommandInterpreter::GetProcess () -{ - SBProcess sb_process; - ProcessSP process_sp; - if (IsValid()) - { - TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); - if (target_sp) - { - std::lock_guard<std::recursive_mutex> guard(target_sp->GetAPIMutex()); - process_sp = target_sp->GetProcessSP(); - sb_process.SetSP(process_sp); - } - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +SBDebugger SBCommandInterpreter::GetDebugger() { + SBDebugger sb_debugger; + if (IsValid()) + sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommandInterpreter(%p)::GetProcess () => SBProcess(%p)", - static_cast<void*>(m_opaque_ptr), - static_cast<void*>(process_sp.get())); + if (log) + log->Printf("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)", + static_cast<void *>(m_opaque_ptr), + static_cast<void *>(sb_debugger.get())); - return sb_process; + return sb_debugger; } -SBDebugger -SBCommandInterpreter::GetDebugger () -{ - SBDebugger sb_debugger; - if (IsValid()) - sb_debugger.reset(m_opaque_ptr->GetDebugger().shared_from_this()); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBCommandInterpreter(%p)::GetDebugger () => SBDebugger(%p)", - static_cast<void*>(m_opaque_ptr), - static_cast<void*>(sb_debugger.get())); - - return sb_debugger; +bool SBCommandInterpreter::GetPromptOnQuit() { + return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false); } -bool -SBCommandInterpreter::GetPromptOnQuit() -{ - return (IsValid() ? m_opaque_ptr->GetPromptOnQuit() : false); +void SBCommandInterpreter::SetPromptOnQuit(bool b) { + if (IsValid()) + m_opaque_ptr->SetPromptOnQuit(b); } -void -SBCommandInterpreter::SetPromptOnQuit (bool b) -{ - if (IsValid()) - m_opaque_ptr->SetPromptOnQuit(b); +void SBCommandInterpreter::ResolveCommand(const char *command_line, + SBCommandReturnObject &result) { + result.Clear(); + if (command_line && IsValid()) { + m_opaque_ptr->ResolveCommand(command_line, result.ref()); + } else { + result->AppendError( + "SBCommandInterpreter or the command line is not valid"); + result->SetStatus(eReturnStatusFailed); + } } -void -SBCommandInterpreter::ResolveCommand(const char *command_line, SBCommandReturnObject &result) -{ - result.Clear(); - if (command_line && IsValid()) - { - m_opaque_ptr->ResolveCommand(command_line, result.ref()); - } - else - { - result->AppendError("SBCommandInterpreter or the command line is not valid"); - result->SetStatus(eReturnStatusFailed); - } -} +CommandInterpreter *SBCommandInterpreter::get() { return m_opaque_ptr; } -CommandInterpreter * -SBCommandInterpreter::get () -{ - return m_opaque_ptr; +CommandInterpreter &SBCommandInterpreter::ref() { + assert(m_opaque_ptr); + return *m_opaque_ptr; } -CommandInterpreter & -SBCommandInterpreter::ref () -{ - assert (m_opaque_ptr); - return *m_opaque_ptr; +void SBCommandInterpreter::reset( + lldb_private::CommandInterpreter *interpreter) { + m_opaque_ptr = interpreter; } -void -SBCommandInterpreter::reset (lldb_private::CommandInterpreter *interpreter) -{ - m_opaque_ptr = interpreter; +void SBCommandInterpreter::SourceInitFileInHomeDirectory( + SBCommandReturnObject &result) { + result.Clear(); + if (IsValid()) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + std::unique_lock<std::recursive_mutex> lock; + if (target_sp) + lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); + m_opaque_ptr->SourceInitFile(false, result.ref()); + } else { + result->AppendError("SBCommandInterpreter is not valid"); + result->SetStatus(eReturnStatusFailed); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + if (log) + log->Printf("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory " + "(&SBCommandReturnObject(%p))", + static_cast<void *>(m_opaque_ptr), + static_cast<void *>(result.get())); } -void -SBCommandInterpreter::SourceInitFileInHomeDirectory (SBCommandReturnObject &result) -{ - result.Clear(); - if (IsValid()) - { - TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); - std::unique_lock<std::recursive_mutex> lock; - if (target_sp) - lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); - m_opaque_ptr->SourceInitFile (false, result.ref()); - } - else - { - result->AppendError ("SBCommandInterpreter is not valid"); - result->SetStatus (eReturnStatusFailed); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInHomeDirectory (&SBCommandReturnObject(%p))", - static_cast<void*>(m_opaque_ptr), - static_cast<void*>(result.get())); -} - -void -SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory (SBCommandReturnObject &result) -{ - result.Clear(); - if (IsValid()) - { - TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); - std::unique_lock<std::recursive_mutex> lock; - if (target_sp) - lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); - m_opaque_ptr->SourceInitFile (true, result.ref()); - } - else - { - result->AppendError ("SBCommandInterpreter is not valid"); - result->SetStatus (eReturnStatusFailed); - } - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +void SBCommandInterpreter::SourceInitFileInCurrentWorkingDirectory( + SBCommandReturnObject &result) { + result.Clear(); + if (IsValid()) { + TargetSP target_sp(m_opaque_ptr->GetDebugger().GetSelectedTarget()); + std::unique_lock<std::recursive_mutex> lock; + if (target_sp) + lock = std::unique_lock<std::recursive_mutex>(target_sp->GetAPIMutex()); + m_opaque_ptr->SourceInitFile(true, result.ref()); + } else { + result->AppendError("SBCommandInterpreter is not valid"); + result->SetStatus(eReturnStatusFailed); + } + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory (&SBCommandReturnObject(%p))", - static_cast<void*>(m_opaque_ptr), - static_cast<void*>(result.get())); + if (log) + log->Printf( + "SBCommandInterpreter(%p)::SourceInitFileInCurrentWorkingDirectory " + "(&SBCommandReturnObject(%p))", + static_cast<void *>(m_opaque_ptr), static_cast<void *>(result.get())); } -SBBroadcaster -SBCommandInterpreter::GetBroadcaster () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +SBBroadcaster SBCommandInterpreter::GetBroadcaster() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - SBBroadcaster broadcaster (m_opaque_ptr, false); + SBBroadcaster broadcaster(m_opaque_ptr, false); - if (log) - log->Printf ("SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)", - static_cast<void*>(m_opaque_ptr), static_cast<void*>(broadcaster.get())); + if (log) + log->Printf( + "SBCommandInterpreter(%p)::GetBroadcaster() => SBBroadcaster(%p)", + static_cast<void *>(m_opaque_ptr), + static_cast<void *>(broadcaster.get())); - return broadcaster; + return broadcaster; } -const char * -SBCommandInterpreter::GetBroadcasterClass () -{ - return CommandInterpreter::GetStaticBroadcasterClass().AsCString(); +const char *SBCommandInterpreter::GetBroadcasterClass() { + return CommandInterpreter::GetStaticBroadcasterClass().AsCString(); } -const char * -SBCommandInterpreter::GetArgumentTypeAsCString (const lldb::CommandArgumentType arg_type) -{ - return CommandObject::GetArgumentTypeAsCString (arg_type); +const char *SBCommandInterpreter::GetArgumentTypeAsCString( + const lldb::CommandArgumentType arg_type) { + return CommandObject::GetArgumentTypeAsCString(arg_type); } -const char * -SBCommandInterpreter::GetArgumentDescriptionAsCString (const lldb::CommandArgumentType arg_type) -{ - return CommandObject::GetArgumentDescriptionAsCString (arg_type); +const char *SBCommandInterpreter::GetArgumentDescriptionAsCString( + const lldb::CommandArgumentType arg_type) { + return CommandObject::GetArgumentDescriptionAsCString(arg_type); } - -bool -SBCommandInterpreter::EventIsCommandInterpreterEvent (const lldb::SBEvent &event) -{ - return event.GetBroadcasterClass() == SBCommandInterpreter::GetBroadcasterClass(); + +bool SBCommandInterpreter::EventIsCommandInterpreterEvent( + const lldb::SBEvent &event) { + return event.GetBroadcasterClass() == + SBCommandInterpreter::GetBroadcasterClass(); +} + +bool SBCommandInterpreter::SetCommandOverrideCallback( + const char *command_name, lldb::CommandOverrideCallback callback, + void *baton) { + if (command_name && command_name[0] && IsValid()) { + llvm::StringRef command_name_str = command_name; + CommandObject *cmd_obj = + m_opaque_ptr->GetCommandObjectForCommand(command_name_str); + if (cmd_obj) { + assert(command_name_str.empty()); + cmd_obj->SetOverrideCallback(callback, baton); + return true; + } + } + return false; } -bool -SBCommandInterpreter::SetCommandOverrideCallback (const char *command_name, - lldb::CommandOverrideCallback callback, - void *baton) -{ - if (command_name && command_name[0] && IsValid()) - { - std::string command_name_str (command_name); - CommandObject *cmd_obj = m_opaque_ptr->GetCommandObjectForCommand(command_name_str); - if (cmd_obj) - { - assert(command_name_str.empty()); - cmd_obj->SetOverrideCallback (callback, baton); - return true; - } - } - return false; +lldb::SBCommand SBCommandInterpreter::AddMultiwordCommand(const char *name, + const char *help) { + CommandObjectMultiword *new_command = + new CommandObjectMultiword(*m_opaque_ptr, name, help); + new_command->SetRemovable(true); + lldb::CommandObjectSP new_command_sp(new_command); + if (new_command_sp && + m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); } -lldb::SBCommand -SBCommandInterpreter::AddMultiwordCommand (const char* name, const char* help) -{ - CommandObjectMultiword *new_command = new CommandObjectMultiword(*m_opaque_ptr, name, help); - new_command->SetRemovable (true); - lldb::CommandObjectSP new_command_sp(new_command); - if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) - return lldb::SBCommand(new_command_sp); - return lldb::SBCommand(); +lldb::SBCommand SBCommandInterpreter::AddCommand( + const char *name, lldb::SBCommandPluginInterface *impl, const char *help) { + lldb::CommandObjectSP new_command_sp; + new_command_sp.reset(new CommandPluginInterfaceImplementation( + *m_opaque_ptr, name, impl, help)); + + if (new_command_sp && + m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); } lldb::SBCommand -SBCommandInterpreter::AddCommand (const char* name, lldb::SBCommandPluginInterface* impl, const char* help) -{ - lldb::CommandObjectSP new_command_sp; - new_command_sp.reset(new CommandPluginInterfaceImplementation(*m_opaque_ptr,name, impl, help)); +SBCommandInterpreter::AddCommand(const char *name, + lldb::SBCommandPluginInterface *impl, + const char *help, const char *syntax) { + lldb::CommandObjectSP new_command_sp; + new_command_sp.reset(new CommandPluginInterfaceImplementation( + *m_opaque_ptr, name, impl, help, syntax)); - if (new_command_sp && m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) - return lldb::SBCommand(new_command_sp); - return lldb::SBCommand(); + if (new_command_sp && + m_opaque_ptr->AddUserCommand(name, new_command_sp, true)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); } SBCommand::SBCommand() = default; -SBCommand::SBCommand (lldb::CommandObjectSP cmd_sp) : m_opaque_sp (cmd_sp) -{} +SBCommand::SBCommand(lldb::CommandObjectSP cmd_sp) : m_opaque_sp(cmd_sp) {} -bool -SBCommand::IsValid() -{ - return m_opaque_sp.get() != nullptr; -} +bool SBCommand::IsValid() { return m_opaque_sp.get() != nullptr; } -const char* -SBCommand::GetName() -{ - return (IsValid() ? m_opaque_sp->GetCommandName() : nullptr); +const char *SBCommand::GetName() { + return (IsValid() ? ConstString(m_opaque_sp->GetCommandName()).AsCString() : nullptr); } -const char* -SBCommand::GetHelp() -{ - return (IsValid() ? m_opaque_sp->GetHelp() : nullptr); +const char *SBCommand::GetHelp() { + return (IsValid() ? ConstString(m_opaque_sp->GetHelp()).AsCString() + : nullptr); } -const char* -SBCommand::GetHelpLong() -{ - return (IsValid() ? m_opaque_sp->GetHelpLong() : nullptr); +const char *SBCommand::GetHelpLong() { + return (IsValid() ? ConstString(m_opaque_sp->GetHelpLong()).AsCString() + : nullptr); } -void -SBCommand::SetHelp (const char* help) -{ - if (IsValid()) - m_opaque_sp->SetHelp(help); +void SBCommand::SetHelp(const char *help) { + if (IsValid()) + m_opaque_sp->SetHelp(help); } -void -SBCommand::SetHelpLong (const char* help) -{ - if (IsValid()) - m_opaque_sp->SetHelpLong(help); +void SBCommand::SetHelpLong(const char *help) { + if (IsValid()) + m_opaque_sp->SetHelpLong(help); } -lldb::SBCommand -SBCommand::AddMultiwordCommand (const char* name, const char* help) -{ - if (!IsValid ()) - return lldb::SBCommand(); - if (!m_opaque_sp->IsMultiwordObject()) - return lldb::SBCommand(); - CommandObjectMultiword *new_command = new CommandObjectMultiword(m_opaque_sp->GetCommandInterpreter(),name,help); - new_command->SetRemovable (true); - lldb::CommandObjectSP new_command_sp(new_command); - if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) - return lldb::SBCommand(new_command_sp); +lldb::SBCommand SBCommand::AddMultiwordCommand(const char *name, + const char *help) { + if (!IsValid()) return lldb::SBCommand(); -} - -lldb::SBCommand -SBCommand::AddCommand (const char* name, lldb::SBCommandPluginInterface *impl, const char* help) -{ - if (!IsValid ()) - return lldb::SBCommand(); - if (!m_opaque_sp->IsMultiwordObject()) - return lldb::SBCommand(); - lldb::CommandObjectSP new_command_sp; - new_command_sp.reset(new CommandPluginInterfaceImplementation(m_opaque_sp->GetCommandInterpreter(),name,impl,help)); - if (new_command_sp && m_opaque_sp->LoadSubCommand(name,new_command_sp)) - return lldb::SBCommand(new_command_sp); + if (!m_opaque_sp->IsMultiwordObject()) + return lldb::SBCommand(); + CommandObjectMultiword *new_command = new CommandObjectMultiword( + m_opaque_sp->GetCommandInterpreter(), name, help); + new_command->SetRemovable(true); + lldb::CommandObjectSP new_command_sp(new_command); + if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); +} + +lldb::SBCommand SBCommand::AddCommand(const char *name, + lldb::SBCommandPluginInterface *impl, + const char *help) { + if (!IsValid()) + return lldb::SBCommand(); + if (!m_opaque_sp->IsMultiwordObject()) + return lldb::SBCommand(); + lldb::CommandObjectSP new_command_sp; + new_command_sp.reset(new CommandPluginInterfaceImplementation( + m_opaque_sp->GetCommandInterpreter(), name, impl, help)); + if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); +} + +lldb::SBCommand SBCommand::AddCommand(const char *name, + lldb::SBCommandPluginInterface *impl, + const char *help, const char *syntax) { + if (!IsValid()) + return lldb::SBCommand(); + if (!m_opaque_sp->IsMultiwordObject()) return lldb::SBCommand(); + lldb::CommandObjectSP new_command_sp; + new_command_sp.reset(new CommandPluginInterfaceImplementation( + m_opaque_sp->GetCommandInterpreter(), name, impl, help, syntax)); + if (new_command_sp && m_opaque_sp->LoadSubCommand(name, new_command_sp)) + return lldb::SBCommand(new_command_sp); + return lldb::SBCommand(); } -uint32_t -SBCommand::GetFlags () -{ - return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0); +uint32_t SBCommand::GetFlags() { + return (IsValid() ? m_opaque_sp->GetFlags().Get() : 0); } -void -SBCommand::SetFlags (uint32_t flags) -{ - if (IsValid()) - m_opaque_sp->GetFlags().Set(flags); +void SBCommand::SetFlags(uint32_t flags) { + if (IsValid()) + m_opaque_sp->GetFlags().Set(flags); } diff --git a/source/API/SBCommandReturnObject.cpp b/source/API/SBCommandReturnObject.cpp index a7bc31da8a89..41d5147af707 100644 --- a/source/API/SBCommandReturnObject.cpp +++ b/source/API/SBCommandReturnObject.cpp @@ -22,333 +22,259 @@ using namespace lldb; using namespace lldb_private; -SBCommandReturnObject::SBCommandReturnObject () : - m_opaque_ap (new CommandReturnObject ()) -{ -} +SBCommandReturnObject::SBCommandReturnObject() + : m_opaque_ap(new CommandReturnObject()) {} -SBCommandReturnObject::SBCommandReturnObject (const SBCommandReturnObject &rhs): - m_opaque_ap () -{ - if (rhs.m_opaque_ap) - m_opaque_ap.reset (new CommandReturnObject (*rhs.m_opaque_ap)); +SBCommandReturnObject::SBCommandReturnObject(const SBCommandReturnObject &rhs) + : m_opaque_ap() { + if (rhs.m_opaque_ap) + m_opaque_ap.reset(new CommandReturnObject(*rhs.m_opaque_ap)); } -SBCommandReturnObject::SBCommandReturnObject (CommandReturnObject *ptr) : - m_opaque_ap (ptr) -{ -} +SBCommandReturnObject::SBCommandReturnObject(CommandReturnObject *ptr) + : m_opaque_ap(ptr) {} SBCommandReturnObject::~SBCommandReturnObject() = default; -CommandReturnObject * -SBCommandReturnObject::Release () -{ - return m_opaque_ap.release(); +CommandReturnObject *SBCommandReturnObject::Release() { + return m_opaque_ap.release(); } -const SBCommandReturnObject & -SBCommandReturnObject::operator = (const SBCommandReturnObject &rhs) -{ - if (this != &rhs) - { - if (rhs.m_opaque_ap) - m_opaque_ap.reset (new CommandReturnObject (*rhs.m_opaque_ap)); - else - m_opaque_ap.reset(); - } - return *this; +const SBCommandReturnObject &SBCommandReturnObject:: +operator=(const SBCommandReturnObject &rhs) { + if (this != &rhs) { + if (rhs.m_opaque_ap) + m_opaque_ap.reset(new CommandReturnObject(*rhs.m_opaque_ap)); + else + m_opaque_ap.reset(); + } + return *this; } -bool -SBCommandReturnObject::IsValid() const -{ - return m_opaque_ap.get() != nullptr; +bool SBCommandReturnObject::IsValid() const { + return m_opaque_ap.get() != nullptr; } -const char * -SBCommandReturnObject::GetOutput () -{ - Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (m_opaque_ap) - { - if (log) - log->Printf ("SBCommandReturnObject(%p)::GetOutput () => \"%s\"", - static_cast<void*>(m_opaque_ap.get()), - m_opaque_ap->GetOutputData()); +const char *SBCommandReturnObject::GetOutput() { + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - return m_opaque_ap->GetOutputData(); - } + if (m_opaque_ap) { + llvm::StringRef output = m_opaque_ap->GetOutputData(); + ConstString result(output.empty() ? llvm::StringRef("") : output); if (log) - log->Printf ("SBCommandReturnObject(%p)::GetOutput () => nullptr", - static_cast<void*>(m_opaque_ap.get())); + log->Printf("SBCommandReturnObject(%p)::GetOutput () => \"%s\"", + static_cast<void *>(m_opaque_ap.get()), result.AsCString()); - return nullptr; -} + return result.AsCString(); + } -const char * -SBCommandReturnObject::GetError () -{ - Log *log(GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + if (log) + log->Printf("SBCommandReturnObject(%p)::GetOutput () => nullptr", + static_cast<void *>(m_opaque_ap.get())); - if (m_opaque_ap) - { - if (log) - log->Printf ("SBCommandReturnObject(%p)::GetError () => \"%s\"", - static_cast<void*>(m_opaque_ap.get()), - m_opaque_ap->GetErrorData()); + return nullptr; +} - return m_opaque_ap->GetErrorData(); - } +const char *SBCommandReturnObject::GetError() { + Log *log(GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (m_opaque_ap) { + llvm::StringRef output = m_opaque_ap->GetErrorData(); + ConstString result(output.empty() ? llvm::StringRef("") : output); if (log) - log->Printf ("SBCommandReturnObject(%p)::GetError () => nullptr", - static_cast<void*>(m_opaque_ap.get())); + log->Printf("SBCommandReturnObject(%p)::GetError () => \"%s\"", + static_cast<void *>(m_opaque_ap.get()), result.AsCString()); - return nullptr; + return result.AsCString(); + } + + if (log) + log->Printf("SBCommandReturnObject(%p)::GetError () => nullptr", + static_cast<void *>(m_opaque_ap.get())); + + return nullptr; } -size_t -SBCommandReturnObject::GetOutputSize() -{ - return (m_opaque_ap ? strlen(m_opaque_ap->GetOutputData()) : 0); +size_t SBCommandReturnObject::GetOutputSize() { + return (m_opaque_ap ? m_opaque_ap->GetOutputData().size() : 0); } -size_t -SBCommandReturnObject::GetErrorSize() -{ - return (m_opaque_ap ? strlen(m_opaque_ap->GetErrorData()) : 0); +size_t SBCommandReturnObject::GetErrorSize() { + return (m_opaque_ap ? m_opaque_ap->GetErrorData().size() : 0); } -size_t -SBCommandReturnObject::PutOutput (FILE *fh) -{ - if (fh) - { - size_t num_bytes = GetOutputSize (); - if (num_bytes) - return ::fprintf (fh, "%s", GetOutput()); - } - return 0; +size_t SBCommandReturnObject::PutOutput(FILE *fh) { + if (fh) { + size_t num_bytes = GetOutputSize(); + if (num_bytes) + return ::fprintf(fh, "%s", GetOutput()); + } + return 0; } -size_t -SBCommandReturnObject::PutError (FILE *fh) -{ - if (fh) - { - size_t num_bytes = GetErrorSize (); - if (num_bytes) - return ::fprintf (fh, "%s", GetError()); - } - return 0; +size_t SBCommandReturnObject::PutError(FILE *fh) { + if (fh) { + size_t num_bytes = GetErrorSize(); + if (num_bytes) + return ::fprintf(fh, "%s", GetError()); + } + return 0; } -void -SBCommandReturnObject::Clear() -{ - if (m_opaque_ap) - m_opaque_ap->Clear(); +void SBCommandReturnObject::Clear() { + if (m_opaque_ap) + m_opaque_ap->Clear(); } -lldb::ReturnStatus -SBCommandReturnObject::GetStatus() -{ - return (m_opaque_ap ? m_opaque_ap->GetStatus() : lldb::eReturnStatusInvalid); +lldb::ReturnStatus SBCommandReturnObject::GetStatus() { + return (m_opaque_ap ? m_opaque_ap->GetStatus() : lldb::eReturnStatusInvalid); } -void -SBCommandReturnObject::SetStatus(lldb::ReturnStatus status) -{ - if (m_opaque_ap) - m_opaque_ap->SetStatus(status); +void SBCommandReturnObject::SetStatus(lldb::ReturnStatus status) { + if (m_opaque_ap) + m_opaque_ap->SetStatus(status); } -bool -SBCommandReturnObject::Succeeded() -{ - return (m_opaque_ap ? m_opaque_ap->Succeeded() : false); +bool SBCommandReturnObject::Succeeded() { + return (m_opaque_ap ? m_opaque_ap->Succeeded() : false); } -bool -SBCommandReturnObject::HasResult() -{ - return (m_opaque_ap ? m_opaque_ap->HasResult() : false); +bool SBCommandReturnObject::HasResult() { + return (m_opaque_ap ? m_opaque_ap->HasResult() : false); } -void -SBCommandReturnObject::AppendMessage (const char *message) -{ - if (m_opaque_ap) - m_opaque_ap->AppendMessage (message); +void SBCommandReturnObject::AppendMessage(const char *message) { + if (m_opaque_ap) + m_opaque_ap->AppendMessage(message); } -void -SBCommandReturnObject::AppendWarning (const char *message) -{ - if (m_opaque_ap) - m_opaque_ap->AppendWarning (message); +void SBCommandReturnObject::AppendWarning(const char *message) { + if (m_opaque_ap) + m_opaque_ap->AppendWarning(message); } -CommandReturnObject * -SBCommandReturnObject::operator ->() const -{ - return m_opaque_ap.get(); +CommandReturnObject *SBCommandReturnObject::operator->() const { + return m_opaque_ap.get(); } -CommandReturnObject * -SBCommandReturnObject::get() const -{ - return m_opaque_ap.get(); +CommandReturnObject *SBCommandReturnObject::get() const { + return m_opaque_ap.get(); } -CommandReturnObject & -SBCommandReturnObject::operator *() const -{ - assert(m_opaque_ap.get()); - return *(m_opaque_ap.get()); +CommandReturnObject &SBCommandReturnObject::operator*() const { + assert(m_opaque_ap.get()); + return *(m_opaque_ap.get()); } -CommandReturnObject & -SBCommandReturnObject::ref() const -{ - assert(m_opaque_ap.get()); - return *(m_opaque_ap.get()); +CommandReturnObject &SBCommandReturnObject::ref() const { + assert(m_opaque_ap.get()); + return *(m_opaque_ap.get()); } -void -SBCommandReturnObject::SetLLDBObjectPtr (CommandReturnObject *ptr) -{ - if (m_opaque_ap) - m_opaque_ap.reset (ptr); +void SBCommandReturnObject::SetLLDBObjectPtr(CommandReturnObject *ptr) { + if (m_opaque_ap) + m_opaque_ap.reset(ptr); } -bool -SBCommandReturnObject::GetDescription (SBStream &description) -{ - Stream &strm = description.ref(); +bool SBCommandReturnObject::GetDescription(SBStream &description) { + Stream &strm = description.ref(); - if (m_opaque_ap) - { - description.Printf ("Status: "); - lldb::ReturnStatus status = m_opaque_ap->GetStatus(); - if (status == lldb::eReturnStatusStarted) - strm.PutCString ("Started"); - else if (status == lldb::eReturnStatusInvalid) - strm.PutCString ("Invalid"); - else if (m_opaque_ap->Succeeded()) - strm.PutCString ("Success"); - else - strm.PutCString ("Fail"); + if (m_opaque_ap) { + description.Printf("Status: "); + lldb::ReturnStatus status = m_opaque_ap->GetStatus(); + if (status == lldb::eReturnStatusStarted) + strm.PutCString("Started"); + else if (status == lldb::eReturnStatusInvalid) + strm.PutCString("Invalid"); + else if (m_opaque_ap->Succeeded()) + strm.PutCString("Success"); + else + strm.PutCString("Fail"); - if (GetOutputSize() > 0) - strm.Printf ("\nOutput Message:\n%s", GetOutput()); + if (GetOutputSize() > 0) + strm.Printf("\nOutput Message:\n%s", GetOutput()); - if (GetErrorSize() > 0) - strm.Printf ("\nError Message:\n%s", GetError()); - } - else - strm.PutCString ("No value"); - - return true; -} - -void -SBCommandReturnObject::SetImmediateOutputFile(FILE *fh) -{ - SetImmediateOutputFile(fh, false); -} - -void -SBCommandReturnObject::SetImmediateErrorFile(FILE *fh) -{ - SetImmediateErrorFile(fh, false); -} - -void -SBCommandReturnObject::SetImmediateOutputFile(FILE *fh, bool transfer_ownership) -{ - if (m_opaque_ap) - m_opaque_ap->SetImmediateOutputFile(fh, transfer_ownership); -} - -void -SBCommandReturnObject::SetImmediateErrorFile(FILE *fh, bool transfer_ownership) -{ - if (m_opaque_ap) - m_opaque_ap->SetImmediateErrorFile(fh, transfer_ownership); -} - -void -SBCommandReturnObject::PutCString(const char* string, int len) -{ - if (m_opaque_ap) - { - if (len == 0 || string == nullptr || *string == 0) - { - return; - } - else if (len > 0) - { - std::string buffer(string, len); - m_opaque_ap->AppendMessage(buffer.c_str()); - } - else - m_opaque_ap->AppendMessage(string); - } -} - -const char * -SBCommandReturnObject::GetOutput (bool only_if_no_immediate) -{ - if (!m_opaque_ap) - return nullptr; - if (!only_if_no_immediate || m_opaque_ap->GetImmediateOutputStream().get() == nullptr) - return GetOutput(); - return nullptr; + if (GetErrorSize() > 0) + strm.Printf("\nError Message:\n%s", GetError()); + } else + strm.PutCString("No value"); + + return true; +} + +void SBCommandReturnObject::SetImmediateOutputFile(FILE *fh) { + SetImmediateOutputFile(fh, false); } -const char * -SBCommandReturnObject::GetError (bool only_if_no_immediate) -{ - if (!m_opaque_ap) - return nullptr; - if (!only_if_no_immediate || m_opaque_ap->GetImmediateErrorStream().get() == nullptr) - return GetError(); +void SBCommandReturnObject::SetImmediateErrorFile(FILE *fh) { + SetImmediateErrorFile(fh, false); +} + +void SBCommandReturnObject::SetImmediateOutputFile(FILE *fh, + bool transfer_ownership) { + if (m_opaque_ap) + m_opaque_ap->SetImmediateOutputFile(fh, transfer_ownership); +} + +void SBCommandReturnObject::SetImmediateErrorFile(FILE *fh, + bool transfer_ownership) { + if (m_opaque_ap) + m_opaque_ap->SetImmediateErrorFile(fh, transfer_ownership); +} + +void SBCommandReturnObject::PutCString(const char *string, int len) { + if (m_opaque_ap) { + if (len == 0 || string == nullptr || *string == 0) { + return; + } else if (len > 0) { + std::string buffer(string, len); + m_opaque_ap->AppendMessage(buffer.c_str()); + } else + m_opaque_ap->AppendMessage(string); + } +} + +const char *SBCommandReturnObject::GetOutput(bool only_if_no_immediate) { + if (!m_opaque_ap) return nullptr; + if (!only_if_no_immediate || + m_opaque_ap->GetImmediateOutputStream().get() == nullptr) + return GetOutput(); + return nullptr; } -size_t -SBCommandReturnObject::Printf(const char* format, ...) -{ - if (m_opaque_ap) - { - va_list args; - va_start (args, format); - size_t result = m_opaque_ap->GetOutputStream().PrintfVarArg(format, args); - va_end (args); - return result; - } - return 0; -} - -void -SBCommandReturnObject::SetError (lldb::SBError &error, const char *fallback_error_cstr) -{ - if (m_opaque_ap) - { - if (error.IsValid()) - m_opaque_ap->SetError(error.ref(), fallback_error_cstr); - else if (fallback_error_cstr) - m_opaque_ap->SetError(Error(), fallback_error_cstr); - } -} - -void -SBCommandReturnObject::SetError (const char *error_cstr) -{ - if (m_opaque_ap && error_cstr) - m_opaque_ap->SetError(error_cstr); +const char *SBCommandReturnObject::GetError(bool only_if_no_immediate) { + if (!m_opaque_ap) + return nullptr; + if (!only_if_no_immediate || + m_opaque_ap->GetImmediateErrorStream().get() == nullptr) + return GetError(); + return nullptr; +} + +size_t SBCommandReturnObject::Printf(const char *format, ...) { + if (m_opaque_ap) { + va_list args; + va_start(args, format); + size_t result = m_opaque_ap->GetOutputStream().PrintfVarArg(format, args); + va_end(args); + return result; + } + return 0; +} + +void SBCommandReturnObject::SetError(lldb::SBError &error, + const char *fallback_error_cstr) { + if (m_opaque_ap) { + if (error.IsValid()) + m_opaque_ap->SetError(error.ref(), fallback_error_cstr); + else if (fallback_error_cstr) + m_opaque_ap->SetError(Error(), fallback_error_cstr); + } +} + +void SBCommandReturnObject::SetError(const char *error_cstr) { + if (m_opaque_ap && error_cstr) + m_opaque_ap->SetError(error_cstr); } diff --git a/source/API/SBCommunication.cpp b/source/API/SBCommunication.cpp index 956b6cfcdd31..9519c02f7e22 100644 --- a/source/API/SBCommunication.cpp +++ b/source/API/SBCommunication.cpp @@ -16,270 +16,229 @@ using namespace lldb; using namespace lldb_private; +SBCommunication::SBCommunication() : m_opaque(NULL), m_opaque_owned(false) {} +SBCommunication::SBCommunication(const char *broadcaster_name) + : m_opaque(new Communication(broadcaster_name)), m_opaque_owned(true) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); -SBCommunication::SBCommunication() : - m_opaque (NULL), - m_opaque_owned (false) -{ + if (log) + log->Printf("SBCommunication::SBCommunication (broadcaster_name=\"%s\") => " + "SBCommunication(%p)", + broadcaster_name, static_cast<void *>(m_opaque)); } -SBCommunication::SBCommunication(const char * broadcaster_name) : - m_opaque (new Communication (broadcaster_name)), - m_opaque_owned (true) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - if (log) - log->Printf ("SBCommunication::SBCommunication (broadcaster_name=\"%s\") => " - "SBCommunication(%p)", broadcaster_name, - static_cast<void*>(m_opaque)); +SBCommunication::~SBCommunication() { + if (m_opaque && m_opaque_owned) + delete m_opaque; + m_opaque = NULL; + m_opaque_owned = false; } -SBCommunication::~SBCommunication() -{ - if (m_opaque && m_opaque_owned) - delete m_opaque; - m_opaque = NULL; - m_opaque_owned = false; -} +bool SBCommunication::IsValid() const { return m_opaque != NULL; } -bool -SBCommunication::IsValid () const -{ - return m_opaque != NULL; +bool SBCommunication::GetCloseOnEOF() { + if (m_opaque) + return m_opaque->GetCloseOnEOF(); + return false; } -bool -SBCommunication::GetCloseOnEOF () -{ - if (m_opaque) - return m_opaque->GetCloseOnEOF (); - return false; +void SBCommunication::SetCloseOnEOF(bool b) { + if (m_opaque) + m_opaque->SetCloseOnEOF(b); } -void -SBCommunication::SetCloseOnEOF (bool b) -{ - if (m_opaque) - m_opaque->SetCloseOnEOF (b); +ConnectionStatus SBCommunication::Connect(const char *url) { + if (m_opaque) { + if (!m_opaque->HasConnection()) + m_opaque->SetConnection(Connection::CreateDefaultConnection(url)); + return m_opaque->Connect(url, NULL); + } + return eConnectionStatusNoConnection; } -ConnectionStatus -SBCommunication::Connect (const char *url) -{ - if (m_opaque) - { - if (!m_opaque->HasConnection ()) - m_opaque->SetConnection(Connection::CreateDefaultConnection(url)); - return m_opaque->Connect (url, NULL); - } - return eConnectionStatusNoConnection; -} +ConnectionStatus SBCommunication::AdoptFileDesriptor(int fd, bool owns_fd) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); -ConnectionStatus -SBCommunication::AdoptFileDesriptor (int fd, bool owns_fd) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - ConnectionStatus status = eConnectionStatusNoConnection; - if (m_opaque) - { - if (m_opaque->HasConnection ()) - { - if (m_opaque->IsConnected()) - m_opaque->Disconnect(); - } - m_opaque->SetConnection (new ConnectionFileDescriptor (fd, owns_fd)); - if (m_opaque->IsConnected()) - status = eConnectionStatusSuccess; - else - status = eConnectionStatusLostConnection; + ConnectionStatus status = eConnectionStatusNoConnection; + if (m_opaque) { + if (m_opaque->HasConnection()) { + if (m_opaque->IsConnected()) + m_opaque->Disconnect(); } + m_opaque->SetConnection(new ConnectionFileDescriptor(fd, owns_fd)); + if (m_opaque->IsConnected()) + status = eConnectionStatusSuccess; + else + status = eConnectionStatusLostConnection; + } - if (log) - log->Printf ("SBCommunication(%p)::AdoptFileDescriptor (fd=%d, ownd_fd=%i) => %s", - static_cast<void*>(m_opaque), fd, owns_fd, - Communication::ConnectionStatusAsCString (status)); - - return status; -} - - -ConnectionStatus -SBCommunication::Disconnect () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - ConnectionStatus status= eConnectionStatusNoConnection; - if (m_opaque) - status = m_opaque->Disconnect (); - - if (log) - log->Printf ("SBCommunication(%p)::Disconnect () => %s", - static_cast<void*>(m_opaque), - Communication::ConnectionStatusAsCString (status)); - - return status; + if (log) + log->Printf( + "SBCommunication(%p)::AdoptFileDescriptor (fd=%d, ownd_fd=%i) => %s", + static_cast<void *>(m_opaque), fd, owns_fd, + Communication::ConnectionStatusAsCString(status)); + + return status; } -bool -SBCommunication::IsConnected () const -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - bool result = false; - if (m_opaque) - result = m_opaque->IsConnected (); +ConnectionStatus SBCommunication::Disconnect() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + ConnectionStatus status = eConnectionStatusNoConnection; + if (m_opaque) + status = m_opaque->Disconnect(); - if (log) - log->Printf ("SBCommunication(%p)::IsConnected () => %i", - static_cast<void*>(m_opaque), result); + if (log) + log->Printf("SBCommunication(%p)::Disconnect () => %s", + static_cast<void *>(m_opaque), + Communication::ConnectionStatusAsCString(status)); + + return status; +} + +bool SBCommunication::IsConnected() const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + bool result = false; + if (m_opaque) + result = m_opaque->IsConnected(); - return false; + if (log) + log->Printf("SBCommunication(%p)::IsConnected () => %i", + static_cast<void *>(m_opaque), result); + + return false; } -size_t -SBCommunication::Read (void *dst, size_t dst_len, uint32_t timeout_usec, ConnectionStatus &status) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommunication(%p)::Read (dst=%p, dst_len=%" PRIu64 ", timeout_usec=%u, &status)...", - static_cast<void*>(m_opaque), static_cast<void*>(dst), - static_cast<uint64_t>(dst_len), timeout_usec); - size_t bytes_read = 0; - if (m_opaque) - bytes_read = m_opaque->Read (dst, dst_len, timeout_usec, status, NULL); - else - status = eConnectionStatusNoConnection; - - if (log) - log->Printf ("SBCommunication(%p)::Read (dst=%p, dst_len=%" PRIu64 ", timeout_usec=%u, &status=%s) => %" PRIu64, - static_cast<void*>(m_opaque), static_cast<void*>(dst), - static_cast<uint64_t>(dst_len), timeout_usec, - Communication::ConnectionStatusAsCString (status), - static_cast<uint64_t>(bytes_read)); - return bytes_read; +size_t SBCommunication::Read(void *dst, size_t dst_len, uint32_t timeout_usec, + ConnectionStatus &status) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBCommunication(%p)::Read (dst=%p, dst_len=%" PRIu64 + ", timeout_usec=%u, &status)...", + static_cast<void *>(m_opaque), static_cast<void *>(dst), + static_cast<uint64_t>(dst_len), timeout_usec); + size_t bytes_read = 0; + Timeout<std::micro> timeout = timeout_usec == UINT32_MAX + ? Timeout<std::micro>(llvm::None) + : std::chrono::microseconds(timeout_usec); + if (m_opaque) + bytes_read = m_opaque->Read(dst, dst_len, timeout, status, NULL); + else + status = eConnectionStatusNoConnection; + + if (log) + log->Printf("SBCommunication(%p)::Read (dst=%p, dst_len=%" PRIu64 + ", timeout_usec=%u, &status=%s) => %" PRIu64, + static_cast<void *>(m_opaque), static_cast<void *>(dst), + static_cast<uint64_t>(dst_len), timeout_usec, + Communication::ConnectionStatusAsCString(status), + static_cast<uint64_t>(bytes_read)); + return bytes_read; } +size_t SBCommunication::Write(const void *src, size_t src_len, + ConnectionStatus &status) { + size_t bytes_written = 0; + if (m_opaque) + bytes_written = m_opaque->Write(src, src_len, status, NULL); + else + status = eConnectionStatusNoConnection; -size_t -SBCommunication::Write (const void *src, size_t src_len, ConnectionStatus &status) -{ - size_t bytes_written = 0; - if (m_opaque) - bytes_written = m_opaque->Write (src, src_len, status, NULL); - else - status = eConnectionStatusNoConnection; + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBCommunication(%p)::Write (src=%p, src_len=%" PRIu64 + ", &status=%s) => %" PRIu64, + static_cast<void *>(m_opaque), static_cast<const void *>(src), + static_cast<uint64_t>(src_len), + Communication::ConnectionStatusAsCString(status), + static_cast<uint64_t>(bytes_written)); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommunication(%p)::Write (src=%p, src_len=%" PRIu64 ", &status=%s) => %" PRIu64, - static_cast<void*>(m_opaque), static_cast<const void*>(src), - static_cast<uint64_t>(src_len), - Communication::ConnectionStatusAsCString (status), - static_cast<uint64_t>(bytes_written)); - - return 0; + return 0; } -bool -SBCommunication::ReadThreadStart () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); +bool SBCommunication::ReadThreadStart() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - bool success = false; - if (m_opaque) - success = m_opaque->StartReadThread (); + bool success = false; + if (m_opaque) + success = m_opaque->StartReadThread(); - if (log) - log->Printf ("SBCommunication(%p)::ReadThreadStart () => %i", - static_cast<void*>(m_opaque), success); + if (log) + log->Printf("SBCommunication(%p)::ReadThreadStart () => %i", + static_cast<void *>(m_opaque), success); - return success; + return success; } +bool SBCommunication::ReadThreadStop() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBCommunication(%p)::ReadThreadStop ()...", + static_cast<void *>(m_opaque)); -bool -SBCommunication::ReadThreadStop () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommunication(%p)::ReadThreadStop ()...", - static_cast<void*>(m_opaque)); - - bool success = false; - if (m_opaque) - success = m_opaque->StopReadThread (); + bool success = false; + if (m_opaque) + success = m_opaque->StopReadThread(); - if (log) - log->Printf ("SBCommunication(%p)::ReadThreadStop () => %i", - static_cast<void*>(m_opaque), success); + if (log) + log->Printf("SBCommunication(%p)::ReadThreadStop () => %i", + static_cast<void *>(m_opaque), success); - return success; + return success; } -bool -SBCommunication::ReadThreadIsRunning () -{ - bool result = false; - if (m_opaque) - result = m_opaque->ReadThreadIsRunning (); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommunication(%p)::ReadThreadIsRunning () => %i", - static_cast<void*>(m_opaque), result); - return result; +bool SBCommunication::ReadThreadIsRunning() { + bool result = false; + if (m_opaque) + result = m_opaque->ReadThreadIsRunning(); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (log) + log->Printf("SBCommunication(%p)::ReadThreadIsRunning () => %i", + static_cast<void *>(m_opaque), result); + return result; } -bool -SBCommunication::SetReadThreadBytesReceivedCallback -( - ReadThreadBytesReceived callback, - void *callback_baton -) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - bool result = false; - if (m_opaque) - { - m_opaque->SetReadThreadBytesReceivedCallback (callback, callback_baton); - result = true; - } +bool SBCommunication::SetReadThreadBytesReceivedCallback( + ReadThreadBytesReceived callback, void *callback_baton) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + + bool result = false; + if (m_opaque) { + m_opaque->SetReadThreadBytesReceivedCallback(callback, callback_baton); + result = true; + } - if (log) - log->Printf ("SBCommunication(%p)::SetReadThreadBytesReceivedCallback (callback=%p, baton=%p) => %i", - static_cast<void*>(m_opaque), - reinterpret_cast<void*>(reinterpret_cast<intptr_t>(callback)), - static_cast<void*>(callback_baton), result); + if (log) + log->Printf("SBCommunication(%p)::SetReadThreadBytesReceivedCallback " + "(callback=%p, baton=%p) => %i", + static_cast<void *>(m_opaque), + reinterpret_cast<void *>(reinterpret_cast<intptr_t>(callback)), + static_cast<void *>(callback_baton), result); - return result; + return result; } -SBBroadcaster -SBCommunication::GetBroadcaster () -{ - SBBroadcaster broadcaster (m_opaque, false); +SBBroadcaster SBCommunication::GetBroadcaster() { + SBBroadcaster broadcaster(m_opaque, false); - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - log->Printf ("SBCommunication(%p)::GetBroadcaster () => SBBroadcaster (%p)", - static_cast<void*>(m_opaque), - static_cast<void*>(broadcaster.get())); + if (log) + log->Printf("SBCommunication(%p)::GetBroadcaster () => SBBroadcaster (%p)", + static_cast<void *>(m_opaque), + static_cast<void *>(broadcaster.get())); - return broadcaster; + return broadcaster; } -const char * -SBCommunication::GetBroadcasterClass () -{ - return Communication::GetStaticBroadcasterClass().AsCString(); +const char *SBCommunication::GetBroadcasterClass() { + return Communication::GetStaticBroadcasterClass().AsCString(); } // -//void -//SBCommunication::CreateIfNeeded () +// void +// SBCommunication::CreateIfNeeded () //{ // if (m_opaque == NULL) // { diff --git a/source/API/SBCompileUnit.cpp b/source/API/SBCompileUnit.cpp index 5d904ce56300..12aed5911de7 100644 --- a/source/API/SBCompileUnit.cpp +++ b/source/API/SBCompileUnit.cpp @@ -21,275 +21,203 @@ using namespace lldb; using namespace lldb_private; +SBCompileUnit::SBCompileUnit() : m_opaque_ptr(NULL) {} -SBCompileUnit::SBCompileUnit () : - m_opaque_ptr (NULL) -{ -} - -SBCompileUnit::SBCompileUnit (lldb_private::CompileUnit *lldb_object_ptr) : - m_opaque_ptr (lldb_object_ptr) -{ -} +SBCompileUnit::SBCompileUnit(lldb_private::CompileUnit *lldb_object_ptr) + : m_opaque_ptr(lldb_object_ptr) {} -SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) : - m_opaque_ptr (rhs.m_opaque_ptr) -{ -} +SBCompileUnit::SBCompileUnit(const SBCompileUnit &rhs) + : m_opaque_ptr(rhs.m_opaque_ptr) {} -const SBCompileUnit & -SBCompileUnit::operator = (const SBCompileUnit &rhs) -{ - m_opaque_ptr = rhs.m_opaque_ptr; - return *this; +const SBCompileUnit &SBCompileUnit::operator=(const SBCompileUnit &rhs) { + m_opaque_ptr = rhs.m_opaque_ptr; + return *this; } +SBCompileUnit::~SBCompileUnit() { m_opaque_ptr = NULL; } -SBCompileUnit::~SBCompileUnit () -{ - m_opaque_ptr = NULL; +SBFileSpec SBCompileUnit::GetFileSpec() const { + SBFileSpec file_spec; + if (m_opaque_ptr) + file_spec.SetFileSpec(*m_opaque_ptr); + return file_spec; } -SBFileSpec -SBCompileUnit::GetFileSpec () const -{ - SBFileSpec file_spec; - if (m_opaque_ptr) - file_spec.SetFileSpec(*m_opaque_ptr); - return file_spec; +uint32_t SBCompileUnit::GetNumLineEntries() const { + if (m_opaque_ptr) { + LineTable *line_table = m_opaque_ptr->GetLineTable(); + if (line_table) + return line_table->GetSize(); + } + return 0; } -uint32_t -SBCompileUnit::GetNumLineEntries () const -{ - if (m_opaque_ptr) - { - LineTable *line_table = m_opaque_ptr->GetLineTable (); - if (line_table) - return line_table->GetSize(); - } - return 0; -} +SBLineEntry SBCompileUnit::GetLineEntryAtIndex(uint32_t idx) const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); -SBLineEntry -SBCompileUnit::GetLineEntryAtIndex (uint32_t idx) const -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - SBLineEntry sb_line_entry; - if (m_opaque_ptr) - { - LineTable *line_table = m_opaque_ptr->GetLineTable (); - if (line_table) - { - LineEntry line_entry; - if (line_table->GetLineEntryAtIndex(idx, line_entry)) - sb_line_entry.SetLineEntry(line_entry); - } + SBLineEntry sb_line_entry; + if (m_opaque_ptr) { + LineTable *line_table = m_opaque_ptr->GetLineTable(); + if (line_table) { + LineEntry line_entry; + if (line_table->GetLineEntryAtIndex(idx, line_entry)) + sb_line_entry.SetLineEntry(line_entry); } + } - if (log) - { - SBStream sstr; - sb_line_entry.GetDescription (sstr); - log->Printf ("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => SBLineEntry(%p): '%s'", - static_cast<void*>(m_opaque_ptr), idx, - static_cast<void*>(sb_line_entry.get()), sstr.GetData()); - } + if (log) { + SBStream sstr; + sb_line_entry.GetDescription(sstr); + log->Printf("SBCompileUnit(%p)::GetLineEntryAtIndex (idx=%u) => " + "SBLineEntry(%p): '%s'", + static_cast<void *>(m_opaque_ptr), idx, + static_cast<void *>(sb_line_entry.get()), sstr.GetData()); + } - return sb_line_entry; + return sb_line_entry; } -uint32_t -SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec) const -{ - const bool exact = true; - return FindLineEntryIndex (start_idx, line, inline_file_spec, exact); +uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, + SBFileSpec *inline_file_spec) const { + const bool exact = true; + return FindLineEntryIndex(start_idx, line, inline_file_spec, exact); } -uint32_t -SBCompileUnit::FindLineEntryIndex (uint32_t start_idx, uint32_t line, SBFileSpec *inline_file_spec, bool exact) const -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - uint32_t index = UINT32_MAX; - if (m_opaque_ptr) - { - FileSpec file_spec; - if (inline_file_spec && inline_file_spec->IsValid()) - file_spec = inline_file_spec->ref(); - else - file_spec = *m_opaque_ptr; - - index = m_opaque_ptr->FindLineEntry (start_idx, - line, - inline_file_spec ? inline_file_spec->get() : NULL, - exact, - NULL); - } +uint32_t SBCompileUnit::FindLineEntryIndex(uint32_t start_idx, uint32_t line, + SBFileSpec *inline_file_spec, + bool exact) const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); - if (log) - { - SBStream sstr; - if (index == UINT32_MAX) - { - log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => NOT FOUND", - static_cast<void*>(m_opaque_ptr), start_idx, line, - inline_file_spec - ? static_cast<const void*>(inline_file_spec->get()) - : NULL); - } - else - { - log->Printf ("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, line=%u, SBFileSpec(%p)) => %u", - static_cast<void*>(m_opaque_ptr), start_idx, line, - inline_file_spec - ? static_cast<const void*>(inline_file_spec->get()) - : NULL, - index); - } + uint32_t index = UINT32_MAX; + if (m_opaque_ptr) { + FileSpec file_spec; + if (inline_file_spec && inline_file_spec->IsValid()) + file_spec = inline_file_spec->ref(); + else + file_spec = *m_opaque_ptr; + + index = m_opaque_ptr->FindLineEntry( + start_idx, line, inline_file_spec ? inline_file_spec->get() : NULL, + exact, NULL); + } + + if (log) { + SBStream sstr; + if (index == UINT32_MAX) { + log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, " + "line=%u, SBFileSpec(%p)) => NOT FOUND", + static_cast<void *>(m_opaque_ptr), start_idx, line, + inline_file_spec + ? static_cast<const void *>(inline_file_spec->get()) + : NULL); + } else { + log->Printf("SBCompileUnit(%p)::FindLineEntryIndex (start_idx=%u, " + "line=%u, SBFileSpec(%p)) => %u", + static_cast<void *>(m_opaque_ptr), start_idx, line, + inline_file_spec + ? static_cast<const void *>(inline_file_spec->get()) + : NULL, + index); } + } - return index; + return index; } -uint32_t -SBCompileUnit::GetNumSupportFiles () const -{ - if (m_opaque_ptr) - { - FileSpecList& support_files = m_opaque_ptr->GetSupportFiles (); - return support_files.GetSize(); - } - return 0; +uint32_t SBCompileUnit::GetNumSupportFiles() const { + if (m_opaque_ptr) { + FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); + return support_files.GetSize(); + } + return 0; } +lldb::SBTypeList SBCompileUnit::GetTypes(uint32_t type_mask) { + SBTypeList sb_type_list; - -lldb::SBTypeList -SBCompileUnit::GetTypes (uint32_t type_mask) -{ - SBTypeList sb_type_list; - - if (m_opaque_ptr) - { - ModuleSP module_sp (m_opaque_ptr->GetModule()); - if (module_sp) - { - SymbolVendor* vendor = module_sp->GetSymbolVendor(); - if (vendor) - { - TypeList type_list; - vendor->GetTypes (m_opaque_ptr, type_mask, type_list); - sb_type_list.m_opaque_ap->Append(type_list); - } - } + if (m_opaque_ptr) { + ModuleSP module_sp(m_opaque_ptr->GetModule()); + if (module_sp) { + SymbolVendor *vendor = module_sp->GetSymbolVendor(); + if (vendor) { + TypeList type_list; + vendor->GetTypes(m_opaque_ptr, type_mask, type_list); + sb_type_list.m_opaque_ap->Append(type_list); + } } - return sb_type_list; + } + return sb_type_list; } +SBFileSpec SBCompileUnit::GetSupportFileAtIndex(uint32_t idx) const { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + SBFileSpec sb_file_spec; + if (m_opaque_ptr) { + FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); + FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); + sb_file_spec.SetFileSpec(file_spec); + } + if (log) { + SBStream sstr; + sb_file_spec.GetDescription(sstr); + log->Printf("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => " + "SBFileSpec(%p): '%s'", + static_cast<void *>(m_opaque_ptr), idx, + static_cast<const void *>(sb_file_spec.get()), sstr.GetData()); + } -SBFileSpec -SBCompileUnit::GetSupportFileAtIndex (uint32_t idx) const -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - - SBFileSpec sb_file_spec; - if (m_opaque_ptr) - { - FileSpecList &support_files = m_opaque_ptr->GetSupportFiles (); - FileSpec file_spec = support_files.GetFileSpecAtIndex(idx); - sb_file_spec.SetFileSpec(file_spec); - } - - if (log) - { - SBStream sstr; - sb_file_spec.GetDescription (sstr); - log->Printf ("SBCompileUnit(%p)::GetGetFileSpecAtIndex (idx=%u) => SBFileSpec(%p): '%s'", - static_cast<void*>(m_opaque_ptr), idx, - static_cast<const void*>(sb_file_spec.get()), - sstr.GetData()); - } - - return sb_file_spec; + return sb_file_spec; } -uint32_t -SBCompileUnit::FindSupportFileIndex (uint32_t start_idx, const SBFileSpec &sb_file, bool full) -{ - if (m_opaque_ptr) - { - FileSpecList &support_files = m_opaque_ptr->GetSupportFiles (); - return support_files.FindFileIndex(start_idx, sb_file.ref(), full); - } - return 0; +uint32_t SBCompileUnit::FindSupportFileIndex(uint32_t start_idx, + const SBFileSpec &sb_file, + bool full) { + if (m_opaque_ptr) { + FileSpecList &support_files = m_opaque_ptr->GetSupportFiles(); + return support_files.FindFileIndex(start_idx, sb_file.ref(), full); + } + return 0; } -lldb::LanguageType -SBCompileUnit::GetLanguage () -{ - if (m_opaque_ptr) - return m_opaque_ptr->GetLanguage(); - return lldb::eLanguageTypeUnknown; +lldb::LanguageType SBCompileUnit::GetLanguage() { + if (m_opaque_ptr) + return m_opaque_ptr->GetLanguage(); + return lldb::eLanguageTypeUnknown; } -bool -SBCompileUnit::IsValid () const -{ - return m_opaque_ptr != NULL; -} +bool SBCompileUnit::IsValid() const { return m_opaque_ptr != NULL; } -bool -SBCompileUnit::operator == (const SBCompileUnit &rhs) const -{ - return m_opaque_ptr == rhs.m_opaque_ptr; +bool SBCompileUnit::operator==(const SBCompileUnit &rhs) const { + return m_opaque_ptr == rhs.m_opaque_ptr; } -bool -SBCompileUnit::operator != (const SBCompileUnit &rhs) const -{ - return m_opaque_ptr != rhs.m_opaque_ptr; +bool SBCompileUnit::operator!=(const SBCompileUnit &rhs) const { + return m_opaque_ptr != rhs.m_opaque_ptr; } -const lldb_private::CompileUnit * -SBCompileUnit::operator->() const -{ - return m_opaque_ptr; +const lldb_private::CompileUnit *SBCompileUnit::operator->() const { + return m_opaque_ptr; } -const lldb_private::CompileUnit & -SBCompileUnit::operator*() const -{ - return *m_opaque_ptr; +const lldb_private::CompileUnit &SBCompileUnit::operator*() const { + return *m_opaque_ptr; } -lldb_private::CompileUnit * -SBCompileUnit::get () -{ - return m_opaque_ptr; -} +lldb_private::CompileUnit *SBCompileUnit::get() { return m_opaque_ptr; } -void -SBCompileUnit::reset (lldb_private::CompileUnit *lldb_object_ptr) -{ - m_opaque_ptr = lldb_object_ptr; +void SBCompileUnit::reset(lldb_private::CompileUnit *lldb_object_ptr) { + m_opaque_ptr = lldb_object_ptr; } - -bool -SBCompileUnit::GetDescription (SBStream &description) -{ - Stream &strm = description.ref(); +bool SBCompileUnit::GetDescription(SBStream &description) { + Stream &strm = description.ref(); - if (m_opaque_ptr) - { - m_opaque_ptr->Dump (&strm, false); - } - else - strm.PutCString ("No value"); - - return true; + if (m_opaque_ptr) { + m_opaque_ptr->Dump(&strm, false); + } else + strm.PutCString("No value"); + + return true; } diff --git a/source/API/SBData.cpp b/source/API/SBData.cpp index a58585295a21..d905d3f272f3 100644 --- a/source/API/SBData.cpp +++ b/source/API/SBData.cpp @@ -18,788 +18,682 @@ #include "lldb/Core/Log.h" #include "lldb/Core/Stream.h" - using namespace lldb; using namespace lldb_private; -SBData::SBData () : - m_opaque_sp(new DataExtractor()) -{ -} +SBData::SBData() : m_opaque_sp(new DataExtractor()) {} -SBData::SBData (const lldb::DataExtractorSP& data_sp) : - m_opaque_sp (data_sp) -{ -} +SBData::SBData(const lldb::DataExtractorSP &data_sp) : m_opaque_sp(data_sp) {} -SBData::SBData(const SBData &rhs) : - m_opaque_sp (rhs.m_opaque_sp) -{ -} +SBData::SBData(const SBData &rhs) : m_opaque_sp(rhs.m_opaque_sp) {} -const SBData & -SBData::operator = (const SBData &rhs) -{ - if (this != &rhs) - m_opaque_sp = rhs.m_opaque_sp; - return *this; +const SBData &SBData::operator=(const SBData &rhs) { + if (this != &rhs) + m_opaque_sp = rhs.m_opaque_sp; + return *this; } -SBData::~SBData () -{ -} +SBData::~SBData() {} -void -SBData::SetOpaque (const lldb::DataExtractorSP &data_sp) -{ - m_opaque_sp = data_sp; +void SBData::SetOpaque(const lldb::DataExtractorSP &data_sp) { + m_opaque_sp = data_sp; } -lldb_private::DataExtractor * -SBData::get() const -{ - return m_opaque_sp.get(); +lldb_private::DataExtractor *SBData::get() const { return m_opaque_sp.get(); } + +lldb_private::DataExtractor *SBData::operator->() const { + return m_opaque_sp.operator->(); } -lldb_private::DataExtractor * -SBData::operator->() const -{ - return m_opaque_sp.operator->(); -} +lldb::DataExtractorSP &SBData::operator*() { return m_opaque_sp; } -lldb::DataExtractorSP & -SBData::operator*() -{ - return m_opaque_sp; -} +const lldb::DataExtractorSP &SBData::operator*() const { return m_opaque_sp; } + +bool SBData::IsValid() { return m_opaque_sp.get() != NULL; } + +uint8_t SBData::GetAddressByteSize() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + uint8_t value = 0; + if (m_opaque_sp.get()) + value = m_opaque_sp->GetAddressByteSize(); + if (log) + log->Printf("SBData::GetAddressByteSize () => " + "(%i)", + value); + return value; +} + +void SBData::SetAddressByteSize(uint8_t addr_byte_size) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (m_opaque_sp.get()) + m_opaque_sp->SetAddressByteSize(addr_byte_size); + if (log) + log->Printf("SBData::SetAddressByteSize (%i)", addr_byte_size); +} + +void SBData::Clear() { + if (m_opaque_sp.get()) + m_opaque_sp->Clear(); +} + +size_t SBData::GetByteSize() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + size_t value = 0; + if (m_opaque_sp.get()) + value = m_opaque_sp->GetByteSize(); + if (log) + log->Printf("SBData::GetByteSize () => " + "( %" PRIu64 " )", + (uint64_t)value); + return value; +} + +lldb::ByteOrder SBData::GetByteOrder() { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + lldb::ByteOrder value = eByteOrderInvalid; + if (m_opaque_sp.get()) + value = m_opaque_sp->GetByteOrder(); + if (log) + log->Printf("SBData::GetByteOrder () => " + "(%i)", + value); + return value; +} + +void SBData::SetByteOrder(lldb::ByteOrder endian) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (m_opaque_sp.get()) + m_opaque_sp->SetByteOrder(endian); + if (log) + log->Printf("SBData::GetByteOrder (%i)", endian); +} + +float SBData::GetFloat(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + float value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetFloat(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetFloat (error=%p,offset=%" PRIu64 ") => (%f)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +double SBData::GetDouble(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + double value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetDouble(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetDouble (error=%p,offset=%" PRIu64 ") => " + "(%f)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +long double SBData::GetLongDouble(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + long double value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetLongDouble(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetLongDouble (error=%p,offset=%" PRIu64 ") => " + "(%Lf)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +lldb::addr_t SBData::GetAddress(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + lldb::addr_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetAddress(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetAddress (error=%p,offset=%" PRIu64 ") => " + "(%p)", + static_cast<void *>(error.get()), offset, + reinterpret_cast<void *>(value)); + return value; +} + +uint8_t SBData::GetUnsignedInt8(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + uint8_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetU8(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetUnsignedInt8 (error=%p,offset=%" PRIu64 ") => " + "(%c)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +uint16_t SBData::GetUnsignedInt16(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + uint16_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetU16(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetUnsignedInt16 (error=%p,offset=%" PRIu64 ") => " + "(%hd)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +uint32_t SBData::GetUnsignedInt32(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + uint32_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetU32(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetUnsignedInt32 (error=%p,offset=%" PRIu64 ") => " + "(%d)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +uint64_t SBData::GetUnsignedInt64(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + uint64_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetU64(&offset); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetUnsignedInt64 (error=%p,offset=%" PRIu64 ") => " + "(%" PRId64 ")", + static_cast<void *>(error.get()), offset, value); + return value; +} + +int8_t SBData::GetSignedInt8(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + int8_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = (int8_t)m_opaque_sp->GetMaxS64(&offset, 1); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetSignedInt8 (error=%p,offset=%" PRIu64 ") => " + "(%c)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +int16_t SBData::GetSignedInt16(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + int16_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = (int16_t)m_opaque_sp->GetMaxS64(&offset, 2); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetSignedInt16 (error=%p,offset=%" PRIu64 ") => " + "(%hd)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +int32_t SBData::GetSignedInt32(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + int32_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = (int32_t)m_opaque_sp->GetMaxS64(&offset, 4); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetSignedInt32 (error=%p,offset=%" PRIu64 ") => " + "(%d)", + static_cast<void *>(error.get()), offset, value); + return value; +} + +int64_t SBData::GetSignedInt64(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + int64_t value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = (int64_t)m_opaque_sp->GetMaxS64(&offset, 8); + if (offset == old_offset) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetSignedInt64 (error=%p,offset=%" PRIu64 ") => " + "(%" PRId64 ")", + static_cast<void *>(error.get()), offset, value); + return value; +} + +const char *SBData::GetString(lldb::SBError &error, lldb::offset_t offset) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + const char *value = 0; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + value = m_opaque_sp->GetCStr(&offset); + if (offset == old_offset || (value == NULL)) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::GetString (error=%p,offset=%" PRIu64 ") => (%p)", + static_cast<void *>(error.get()), offset, + static_cast<const void *>(value)); + return value; +} + +bool SBData::GetDescription(lldb::SBStream &description, + lldb::addr_t base_addr) { + Stream &strm = description.ref(); + + if (m_opaque_sp) { + m_opaque_sp->Dump(&strm, 0, lldb::eFormatBytesWithASCII, 1, + m_opaque_sp->GetByteSize(), 16, base_addr, 0, 0); + } else + strm.PutCString("No value"); + + return true; +} + +size_t SBData::ReadRawData(lldb::SBError &error, lldb::offset_t offset, + void *buf, size_t size) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + void *ok = NULL; + if (!m_opaque_sp.get()) { + error.SetErrorString("no value to read from"); + } else { + uint32_t old_offset = offset; + ok = m_opaque_sp->GetU8(&offset, buf, size); + if ((offset == old_offset) || (ok == NULL)) + error.SetErrorString("unable to read data"); + } + if (log) + log->Printf("SBData::ReadRawData (error=%p,offset=%" PRIu64 + ",buf=%p,size=%" PRIu64 ") => " + "(%p)", + static_cast<void *>(error.get()), offset, + static_cast<void *>(buf), static_cast<uint64_t>(size), + static_cast<void *>(ok)); + return ok ? size : 0; +} + +void SBData::SetData(lldb::SBError &error, const void *buf, size_t size, + lldb::ByteOrder endian, uint8_t addr_size) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + if (!m_opaque_sp.get()) + m_opaque_sp.reset(new DataExtractor(buf, size, endian, addr_size)); + else + m_opaque_sp->SetData(buf, size, endian); + if (log) + log->Printf("SBData::SetData (error=%p,buf=%p,size=%" PRIu64 + ",endian=%d,addr_size=%c) => " + "(%p)", + static_cast<void *>(error.get()), + static_cast<const void *>(buf), static_cast<uint64_t>(size), + endian, addr_size, static_cast<void *>(m_opaque_sp.get())); +} + +bool SBData::Append(const SBData &rhs) { + Log *log(lldb_private::GetLogIfAllCategoriesSet(LIBLLDB_LOG_API)); + bool value = false; + if (m_opaque_sp.get() && rhs.m_opaque_sp.get()) + value = m_opaque_sp.get()->Append(*rhs.m_opaque_sp); + if (log) + log->Printf("SBData::Append (rhs=%p) => (%s)", + static_cast<void *>(rhs.get()), value ? "true" : "false"); + return value; +} + +lldb::SBData SBData::CreateDataFromCString(lldb::ByteOrder endian, + uint32_t addr_byte_size, + const char *data) { + if (!data || !data[0]) + return SBData(); + + uint32_t data_len = strlen(data); + + lldb::DataBufferSP buffer_sp(new DataBufferHeap(data, data_len)); + lldb::DataExtractorSP data_sp( + new DataExtractor(buffer_sp, endian, addr_byte_size)); -const lldb::DataExtractorSP & -SBData::operator*() const -{ - return m_opaque_sp; + SBData ret(data_sp); + + return ret; } -bool -SBData::IsValid() -{ - return m_opaque_sp.get() != NULL; +lldb::SBData SBData::CreateDataFromUInt64Array(lldb::ByteOrder endian, + uint32_t addr_byte_size, + uint64_t *array, + size_t array_len) { + if (!array || array_len == 0) + return SBData(); + + size_t data_len = array_len * sizeof(uint64_t); + + lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); + lldb::DataExtractorSP data_sp( + new DataExtractor(buffer_sp, endian, addr_byte_size)); + + SBData ret(data_sp); + + return ret; } -uint8_t -SBData::GetAddressByteSize () -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - uint8_t value = 0; - if (m_opaque_sp.get()) - value = m_opaque_sp->GetAddressByteSize(); - if (log) - log->Printf ("SBData::GetAddressByteSize () => " - "(%i)", value); - return value; +lldb::SBData SBData::CreateDataFromUInt32Array(lldb::ByteOrder endian, + uint32_t addr_byte_size, + uint32_t *array, + size_t array_len) { + if (!array || array_len == 0) + return SBData(); + + size_t data_len = array_len * sizeof(uint32_t); + + lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); + lldb::DataExtractorSP data_sp( + new DataExtractor(buffer_sp, endian, addr_byte_size)); + + SBData ret(data_sp); + + return ret; } -void -SBData::SetAddressByteSize (uint8_t addr_byte_size) -{ - Log *log(lldb_private::GetLogIfAllCategoriesSet (LIBLLDB_LOG_API)); - if (m_opaque_sp.get()) - m_opaque_sp->SetAddressByteSize(addr_byte_size); - if (log) - log->Printf ("SBData::SetAddressByteSize (%i)", addr_byte_size); +lldb::SBData SBData::CreateDataFromSInt64Array(lldb::ByteOrder endian, + uint32_t addr_byte_size, + int64_t *array, + size_t array_len) { + if (!array || array_len == 0) + return SBData(); + + size_t data_len = array_len * sizeof(int64_t); + + lldb::DataBufferSP buffer_sp(new DataBufferHeap(array, data_len)); + lldb::DataExtractorSP data_sp( + new DataExtractor(buffer_sp, endian, addr_byte_size)); + + SBData ret(data_sp); + + return ret; } -void -SBData::Clear () -{ - if (m_opaque_sp.get()) - m_opaque_sp->Clear(); |