diff options
| author | Antonio Afonso <antonio.afonso@gmail.com> | 2019-06-11 20:16:13 +0000 |
|---|---|---|
| committer | Antonio Afonso <antonio.afonso@gmail.com> | 2019-06-11 20:16:13 +0000 |
| commit | 943faef1fafe2793cfaf9bf7741fe4215d3b0fe7 (patch) | |
| tree | 3964c21d1573a12769317960aaeb236d544ad4bd /lldb/source/Plugins/DynamicLoader | |
| parent | 1dc3c9aa8f7a68343a0ec1447c96e66b348a2608 (diff) | |
| download | bcm5719-llvm-943faef1fafe2793cfaf9bf7741fe4215d3b0fe7.tar.gz bcm5719-llvm-943faef1fafe2793cfaf9bf7741fe4215d3b0fe7.zip | |
Add support to read aux vector values
Summary:
This is the second patch to improve module loading in a series that started here (where I explain the motivation and solution): https://reviews.llvm.org/D62499
I need to read the aux vector to know where the r_debug map with the loaded libraries are.
The AuxVector class was made generic so it could be reused between the POSIX-DYLD plugin and NativeProcess*. The class itself ended up in the ProcessUtility plugin.
Reviewers: clayborg, xiaobai, labath, JDevlieghere
Reviewed By: clayborg, labath, JDevlieghere
Subscribers: emaste, JDevlieghere, mgorny, lldb-commits
Tags: #lldb
Differential Revision: https://reviews.llvm.org/D62500
llvm-svn: 363098
Diffstat (limited to 'lldb/source/Plugins/DynamicLoader')
5 files changed, 14 insertions, 264 deletions
diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp deleted file mode 100644 index 71d42c8fd99..00000000000 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp +++ /dev/null @@ -1,141 +0,0 @@ -//===-- AuxVector.cpp -------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "AuxVector.h" -#include "lldb/Target/Process.h" -#include "lldb/Utility/DataBufferHeap.h" -#include "lldb/Utility/DataExtractor.h" -#include "lldb/Utility/Log.h" - -using namespace lldb; -using namespace lldb_private; - -static bool GetMaxU64(DataExtractor &data, lldb::offset_t *offset_ptr, - uint64_t *value, unsigned int byte_size) { - lldb::offset_t saved_offset = *offset_ptr; - *value = data.GetMaxU64(offset_ptr, byte_size); - return *offset_ptr != saved_offset; -} - -static bool ParseAuxvEntry(DataExtractor &data, AuxVector::Entry &entry, - lldb::offset_t *offset_ptr, unsigned int byte_size) { - if (!GetMaxU64(data, offset_ptr, &entry.type, byte_size)) - return false; - - if (!GetMaxU64(data, offset_ptr, &entry.value, byte_size)) - return false; - - return true; -} - -DataBufferSP AuxVector::GetAuxvData() { - if (m_process) - return m_process->GetAuxvData(); - else - return DataBufferSP(); -} - -void AuxVector::ParseAuxv(DataExtractor &data) { - const unsigned int byte_size = m_process->GetAddressByteSize(); - lldb::offset_t offset = 0; - - for (;;) { - Entry entry; - - if (!ParseAuxvEntry(data, entry, &offset, byte_size)) - break; - - if (entry.type == AUXV_AT_NULL) - break; - - if (entry.type == AUXV_AT_IGNORE) - continue; - - m_auxv.push_back(entry); - } -} - -AuxVector::AuxVector(Process *process) : m_process(process) { - DataExtractor data; - Log *log(GetLogIfAnyCategoriesSet(LIBLLDB_LOG_DYNAMIC_LOADER)); - - data.SetData(GetAuxvData()); - data.SetByteOrder(m_process->GetByteOrder()); - data.SetAddressByteSize(m_process->GetAddressByteSize()); - - ParseAuxv(data); - - if (log) - DumpToLog(log); -} - -AuxVector::iterator AuxVector::FindEntry(EntryType type) const { - for (iterator I = begin(); I != end(); ++I) { - if (I->type == static_cast<uint64_t>(type)) - return I; - } - - return end(); -} - -void AuxVector::DumpToLog(Log *log) const { - if (!log) - return; - - log->PutCString("AuxVector: "); - for (iterator I = begin(); I != end(); ++I) { - log->Printf(" %s [%" PRIu64 "]: %" PRIx64, GetEntryName(*I), I->type, - I->value); - } -} - -const char *AuxVector::GetEntryName(EntryType type) { - const char *name = "AT_???"; - -#define ENTRY_NAME(_type) \ - _type: \ - name = &#_type[5] - switch (type) { - case ENTRY_NAME(AUXV_AT_NULL); break; - case ENTRY_NAME(AUXV_AT_IGNORE); break; - case ENTRY_NAME(AUXV_AT_EXECFD); break; - case ENTRY_NAME(AUXV_AT_PHDR); break; - case ENTRY_NAME(AUXV_AT_PHENT); break; - case ENTRY_NAME(AUXV_AT_PHNUM); break; - case ENTRY_NAME(AUXV_AT_PAGESZ); break; - case ENTRY_NAME(AUXV_AT_BASE); break; - case ENTRY_NAME(AUXV_AT_FLAGS); break; - case ENTRY_NAME(AUXV_AT_ENTRY); break; - case ENTRY_NAME(AUXV_AT_NOTELF); break; - case ENTRY_NAME(AUXV_AT_UID); break; - case ENTRY_NAME(AUXV_AT_EUID); break; - case ENTRY_NAME(AUXV_AT_GID); break; - case ENTRY_NAME(AUXV_AT_EGID); break; - case ENTRY_NAME(AUXV_AT_CLKTCK); break; - case ENTRY_NAME(AUXV_AT_PLATFORM); break; - case ENTRY_NAME(AUXV_AT_HWCAP); break; - case ENTRY_NAME(AUXV_AT_FPUCW); break; - case ENTRY_NAME(AUXV_AT_DCACHEBSIZE); break; - case ENTRY_NAME(AUXV_AT_ICACHEBSIZE); break; - case ENTRY_NAME(AUXV_AT_UCACHEBSIZE); break; - case ENTRY_NAME(AUXV_AT_IGNOREPPC); break; - case ENTRY_NAME(AUXV_AT_SECURE); break; - case ENTRY_NAME(AUXV_AT_BASE_PLATFORM); break; - case ENTRY_NAME(AUXV_AT_RANDOM); break; - case ENTRY_NAME(AUXV_AT_EXECFN); break; - case ENTRY_NAME(AUXV_AT_SYSINFO); break; - case ENTRY_NAME(AUXV_AT_SYSINFO_EHDR); break; - case ENTRY_NAME(AUXV_AT_L1I_CACHESHAPE); break; - case ENTRY_NAME(AUXV_AT_L1D_CACHESHAPE); break; - case ENTRY_NAME(AUXV_AT_L2_CACHESHAPE); break; - case ENTRY_NAME(AUXV_AT_L3_CACHESHAPE); break; - } -#undef ENTRY_NAME - - return name; -} diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h deleted file mode 100644 index cf32d9cd30f..00000000000 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h +++ /dev/null @@ -1,108 +0,0 @@ -//===-- AuxVector.h ---------------------------------------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#ifndef liblldb_AuxVector_H_ -#define liblldb_AuxVector_H_ - -#include <vector> - -#include "lldb/lldb-forward.h" - -namespace lldb_private { -class DataExtractor; -} - -/// \class AuxVector -/// Represents a processes auxiliary vector. -/// -/// When a process is loaded on Linux a vector of values is placed onto the -/// stack communicating operating system specific information. On -/// construction this class locates and parses this information and provides a -/// simple read-only interface to the entries found. -class AuxVector { - -public: - AuxVector(lldb_private::Process *process); - - struct Entry { - uint64_t type; - uint64_t value; - - Entry() : type(0), value(0) {} - }; - - /// Constants describing the type of entry. - /// On Linux, running "LD_SHOW_AUXV=1 ./executable" will spew AUX - /// information. Added AUXV prefix to avoid potential conflicts with system- - /// defined macros - enum EntryType { - AUXV_AT_NULL = 0, ///< End of auxv. - AUXV_AT_IGNORE = 1, ///< Ignore entry. - AUXV_AT_EXECFD = 2, ///< File descriptor of program. - AUXV_AT_PHDR = 3, ///< Program headers. - AUXV_AT_PHENT = 4, ///< Size of program header. - AUXV_AT_PHNUM = 5, ///< Number of program headers. - AUXV_AT_PAGESZ = 6, ///< Page size. - AUXV_AT_BASE = 7, ///< Interpreter base address. - AUXV_AT_FLAGS = 8, ///< Flags. - AUXV_AT_ENTRY = 9, ///< Program entry point. - AUXV_AT_NOTELF = 10, ///< Set if program is not an ELF. - AUXV_AT_UID = 11, ///< UID. - AUXV_AT_EUID = 12, ///< Effective UID. - AUXV_AT_GID = 13, ///< GID. - AUXV_AT_EGID = 14, ///< Effective GID. - AUXV_AT_CLKTCK = 17, ///< Clock frequency (e.g. times(2)). - AUXV_AT_PLATFORM = 15, ///< String identifying platform. - AUXV_AT_HWCAP = 16, ///< Machine dependent hints about processor capabilities. - AUXV_AT_FPUCW = 18, ///< Used FPU control word. - AUXV_AT_DCACHEBSIZE = 19, ///< Data cache block size. - AUXV_AT_ICACHEBSIZE = 20, ///< Instruction cache block size. - AUXV_AT_UCACHEBSIZE = 21, ///< Unified cache block size. - AUXV_AT_IGNOREPPC = 22, ///< Entry should be ignored. - AUXV_AT_SECURE = 23, ///< Boolean, was exec setuid-like? - AUXV_AT_BASE_PLATFORM = 24, ///< String identifying real platforms. - AUXV_AT_RANDOM = 25, ///< Address of 16 random bytes. - AUXV_AT_EXECFN = 31, ///< Filename of executable. - AUXV_AT_SYSINFO = 32, ///< Pointer to the global system page used for system - ///calls and other nice things. - AUXV_AT_SYSINFO_EHDR = 33, - AUXV_AT_L1I_CACHESHAPE = 34, ///< Shapes of the caches. - AUXV_AT_L1D_CACHESHAPE = 35, - AUXV_AT_L2_CACHESHAPE = 36, - AUXV_AT_L3_CACHESHAPE = 37, - }; - -private: - typedef std::vector<Entry> EntryVector; - -public: - typedef EntryVector::const_iterator iterator; - - iterator begin() const { return m_auxv.begin(); } - iterator end() const { return m_auxv.end(); } - - iterator FindEntry(EntryType type) const; - - static const char *GetEntryName(const Entry &entry) { - return GetEntryName(static_cast<EntryType>(entry.type)); - } - - static const char *GetEntryName(EntryType type); - - void DumpToLog(lldb_private::Log *log) const; - -private: - lldb_private::Process *m_process; - EntryVector m_auxv; - - lldb::DataBufferSP GetAuxvData(); - - void ParseAuxv(lldb_private::DataExtractor &data); -}; - -#endif diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt index 409ba92a0e1..c1e00b2dd44 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt @@ -1,5 +1,4 @@ add_lldb_library(lldbPluginDynamicLoaderPosixDYLD PLUGIN - AuxVector.cpp DYLDRendezvous.cpp DynamicLoaderPOSIXDYLD.cpp @@ -10,6 +9,7 @@ add_lldb_library(lldbPluginDynamicLoaderPosixDYLD PLUGIN lldbSymbol lldbTarget lldbPluginProcessElfCore + lldbPluginProcessUtility LINK_COMPONENTS Support ) diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp index 591a27f4492..b55660899d0 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp @@ -9,8 +9,6 @@ // Main header include #include "DynamicLoaderPOSIXDYLD.h" -#include "AuxVector.h" - #include "lldb/Breakpoint/BreakpointLocation.h" #include "lldb/Core/Module.h" #include "lldb/Core/ModuleSpec.h" @@ -90,8 +88,8 @@ void DynamicLoaderPOSIXDYLD::DidAttach() { if (log) log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__, m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID); + m_auxv = llvm::make_unique<AuxVector>(m_process->GetAuxvData()); - m_auxv.reset(new AuxVector(m_process)); if (log) log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data", __FUNCTION__, @@ -182,7 +180,7 @@ void DynamicLoaderPOSIXDYLD::DidLaunch() { ModuleSP executable; addr_t load_offset; - m_auxv.reset(new AuxVector(m_process)); + m_auxv = llvm::make_unique<AuxVector>(m_process->GetAuxvData()); executable = GetTargetExecutable(); load_offset = ComputeLoadOffset(); @@ -628,13 +626,13 @@ addr_t DynamicLoaderPOSIXDYLD::ComputeLoadOffset() { } void DynamicLoaderPOSIXDYLD::EvalSpecialModulesStatus() { - auto I = m_auxv->FindEntry(AuxVector::AUXV_AT_SYSINFO_EHDR); - if (I != m_auxv->end() && I->value != 0) - m_vdso_base = I->value; + if (llvm::Optional<uint64_t> vdso_base = + m_auxv->GetAuxValue(AuxVector::AUXV_AT_SYSINFO_EHDR)) + m_vdso_base = *vdso_base; - I = m_auxv->FindEntry(AuxVector::AUXV_AT_BASE); - if (I != m_auxv->end() && I->value != 0) - m_interpreter_base = I->value; + if (llvm::Optional<uint64_t> interpreter_base = + m_auxv->GetAuxValue(AuxVector::AUXV_AT_BASE)) + m_interpreter_base = *interpreter_base; } addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() { @@ -644,12 +642,12 @@ addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() { if (m_auxv == nullptr) return LLDB_INVALID_ADDRESS; - AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AUXV_AT_ENTRY); - - if (I == m_auxv->end()) + llvm::Optional<uint64_t> entry_point = + m_auxv->GetAuxValue(AuxVector::AUXV_AT_ENTRY); + if (!entry_point) return LLDB_INVALID_ADDRESS; - m_entry_point = static_cast<addr_t>(I->value); + m_entry_point = static_cast<addr_t>(*entry_point); const ArchSpec &arch = m_process->GetTarget().GetArchitecture(); diff --git a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h index d61f1563497..0630d1eb11d 100644 --- a/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h +++ b/lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h @@ -13,6 +13,7 @@ #include <memory> #include "DYLDRendezvous.h" +#include "Plugins/Process/Utility/AuxVector.h" #include "lldb/Breakpoint/StoppointCallbackContext.h" #include "lldb/Core/ModuleList.h" #include "lldb/Target/DynamicLoader.h" |

