[Lldb-commits] [lldb] r363098 - Add support to read aux vector values
Antonio Afonso via lldb-commits
lldb-commits at lists.llvm.org
Tue Jun 11 13:16:13 PDT 2019
Author: aadsm
Date: Tue Jun 11 13:16:13 2019
New Revision: 363098
URL: http://llvm.org/viewvc/llvm-project?rev=363098&view=rev
Log:
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
Added:
lldb/trunk/source/Plugins/Process/Utility/AuxVector.cpp
lldb/trunk/source/Plugins/Process/Utility/AuxVector.h
Removed:
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h
Modified:
lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
lldb/trunk/include/lldb/Target/Process.h
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt
lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.h
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
lldb/trunk/source/Target/Process.cpp
Modified: lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h (original)
+++ lldb/trunk/include/lldb/Host/common/NativeProcessProtocol.h Tue Jun 11 13:16:13 2019
@@ -133,6 +133,10 @@ public:
return GetArchitecture().GetByteOrder();
}
+ uint32_t GetAddressByteSize() const {
+ return GetArchitecture().GetAddressByteSize();
+ }
+
virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
GetAuxvData() const = 0;
Modified: lldb/trunk/include/lldb/Target/Process.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/include/lldb/Target/Process.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/include/lldb/Target/Process.h (original)
+++ lldb/trunk/include/lldb/Target/Process.h Tue Jun 11 13:16:13 2019
@@ -670,8 +670,8 @@ public:
// The default action is to return an empty data buffer.
//
// \return
- // A data buffer containing the contents of the AUXV data.
- virtual const lldb::DataBufferSP GetAuxvData();
+ // A data extractor containing the contents of the AUXV data.
+ virtual DataExtractor GetAuxvData();
/// Sometimes processes know how to retrieve and load shared libraries. This
/// is normally done by DynamicLoader plug-ins, but sometimes the connection
Removed: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp?rev=363097&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.cpp (removed)
@@ -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;
-}
Removed: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h?rev=363097&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h (removed)
@@ -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
Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt Tue Jun 11 13:16:13 2019
@@ -1,5 +1,4 @@
add_lldb_library(lldbPluginDynamicLoaderPosixDYLD PLUGIN
- AuxVector.cpp
DYLDRendezvous.cpp
DynamicLoaderPOSIXDYLD.cpp
@@ -10,6 +9,7 @@ add_lldb_library(lldbPluginDynamicLoader
lldbSymbol
lldbTarget
lldbPluginProcessElfCore
+ lldbPluginProcessUtility
LINK_COMPONENTS
Support
)
Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp Tue Jun 11 13:16:13 2019
@@ -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::ComputeLo
}
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;
-
- 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> vdso_base =
+ m_auxv->GetAuxValue(AuxVector::AUXV_AT_SYSINFO_EHDR))
+ m_vdso_base = *vdso_base;
+
+ 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::GetEntryP
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();
Modified: lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h (original)
+++ lldb/trunk/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h Tue Jun 11 13:16:13 2019
@@ -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"
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp Tue Jun 11 13:16:13 2019
@@ -876,7 +876,7 @@ bool ProcessFreeBSD::IsAThreadRunning()
return is_running;
}
-const DataBufferSP ProcessFreeBSD::GetAuxvData() {
+lldb_private::DataExtractor ProcessFreeBSD::GetAuxvData() {
// If we're the local platform, we can ask the host for auxv data.
PlatformSP platform_sp = GetTarget().GetPlatform();
assert(platform_sp && platform_sp->IsHost());
@@ -890,7 +890,7 @@ const DataBufferSP ProcessFreeBSD::GetAu
buf_sp.reset();
}
- return buf_sp;
+ return DataExtractor(buf_sp, GetByteOrder(), GetAddressByteSize());
}
struct EmulatorBaton {
Modified: lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h (original)
+++ lldb/trunk/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h Tue Jun 11 13:16:13 2019
@@ -127,7 +127,7 @@ public:
size_t PutSTDIN(const char *buf, size_t len,
lldb_private::Status &error) override;
- const lldb::DataBufferSP GetAuxvData() override;
+ const lldb_private::DataExtractor GetAuxvData() override;
// ProcessFreeBSD internal API.
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.cpp Tue Jun 11 13:16:13 2019
@@ -2082,3 +2082,18 @@ Status NativeProcessLinux::StopProcessor
return error;
}
+
+llvm::Optional<uint64_t>
+NativeProcessLinux::GetAuxValue(enum AuxVector::EntryType type) {
+ if (m_aux_vector == nullptr) {
+ auto buffer_or_error = GetAuxvData();
+ if (!buffer_or_error)
+ return llvm::None;
+ DataExtractor auxv_data(buffer_or_error.get()->getBufferStart(),
+ buffer_or_error.get()->getBufferSize(),
+ GetByteOrder(), GetAddressByteSize());
+ m_aux_vector = llvm::make_unique<AuxVector>(auxv_data);
+ }
+
+ return m_aux_vector->GetAuxValue(type);
+}
Modified: lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h (original)
+++ lldb/trunk/source/Plugins/Process/Linux/NativeProcessLinux.h Tue Jun 11 13:16:13 2019
@@ -12,6 +12,7 @@
#include <csignal>
#include <unordered_set>
+#include "Plugins/Process/Utility/AuxVector.h"
#include "lldb/Host/Debug.h"
#include "lldb/Host/HostThread.h"
#include "lldb/Host/linux/Support.h"
@@ -102,6 +103,8 @@ public:
return getProcFile(GetID(), "auxv");
}
+ llvm::Optional<uint64_t> GetAuxValue(enum AuxVector::EntryType type);
+
lldb::user_id_t StartTrace(const TraceOptions &config,
Status &error) override;
@@ -132,6 +135,7 @@ protected:
private:
MainLoop::SignalHandleUP m_sigchld_handle;
ArchSpec m_arch;
+ std::unique_ptr<AuxVector> m_aux_vector;
LazyBool m_supports_mem_region = eLazyBoolCalculate;
std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;
Added: lldb/trunk/source/Plugins/Process/Utility/AuxVector.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/AuxVector.cpp?rev=363098&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/AuxVector.cpp (added)
+++ lldb/trunk/source/Plugins/Process/Utility/AuxVector.cpp Tue Jun 11 13:16:13 2019
@@ -0,0 +1,96 @@
+//===-- 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"
+
+AuxVector::AuxVector(const lldb_private::DataExtractor &data) {
+ ParseAuxv(data);
+}
+
+void AuxVector::ParseAuxv(const lldb_private::DataExtractor &data) {
+ lldb::offset_t offset = 0;
+ const size_t value_type_size = data.GetAddressByteSize() * 2;
+ while (data.ValidOffsetForDataOfSize(offset, value_type_size)) {
+ // We're not reading an address but an int that could be 32 or 64 bit
+ // depending on the address size, which is what GetAddress does.
+ const uint64_t type = data.GetAddress(&offset);
+ const uint64_t value = data.GetAddress(&offset);
+ if (type == AUXV_AT_NULL)
+ break;
+ if (type == AUXV_AT_IGNORE)
+ continue;
+
+ m_auxv_entries[type] = value;
+ }
+}
+
+llvm::Optional<uint64_t>
+AuxVector::GetAuxValue(enum EntryType entry_type) const {
+ auto it = m_auxv_entries.find(static_cast<uint64_t>(entry_type));
+ if (it != m_auxv_entries.end())
+ return it->second;
+ return llvm::None;
+}
+
+void AuxVector::DumpToLog(lldb_private::Log *log) const {
+ if (!log)
+ return;
+
+ log->PutCString("AuxVector: ");
+ for (auto entry : m_auxv_entries) {
+ log->Printf(" %s [%" PRIu64 "]: %" PRIx64,
+ GetEntryName(static_cast<EntryType>(entry.first)), entry.first,
+ entry.second);
+ }
+}
+
+const char *AuxVector::GetEntryName(EntryType type) const {
+ 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;
+}
Added: lldb/trunk/source/Plugins/Process/Utility/AuxVector.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/AuxVector.h?rev=363098&view=auto
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/AuxVector.h (added)
+++ lldb/trunk/source/Plugins/Process/Utility/AuxVector.h Tue Jun 11 13:16:13 2019
@@ -0,0 +1,73 @@
+//===-- 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 "lldb/Utility/DataExtractor.h"
+#include "lldb/Utility/Log.h"
+#include <unordered_map>
+
+class AuxVector {
+
+public:
+ AuxVector(const lldb_private::DataExtractor &data);
+
+ /// 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,
+ };
+
+ llvm::Optional<uint64_t> GetAuxValue(enum EntryType entry_type) const;
+ void DumpToLog(lldb_private::Log *log) const;
+ const char *GetEntryName(EntryType type) const;
+
+private:
+ void ParseAuxv(const lldb_private::DataExtractor &data);
+
+ std::unordered_map<uint64_t, uint64_t> m_auxv_entries;
+};
+
+#endif
Modified: lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt (original)
+++ lldb/trunk/source/Plugins/Process/Utility/CMakeLists.txt Tue Jun 11 13:16:13 2019
@@ -1,4 +1,5 @@
add_lldb_library(lldbPluginProcessUtility PLUGIN
+ AuxVector.cpp
DynamicRegisterInfo.cpp
FreeBSDSignals.cpp
GDBRemoteSignals.cpp
Modified: lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp (original)
+++ lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.cpp Tue Jun 11 13:16:13 2019
@@ -894,11 +894,11 @@ ArchSpec ProcessElfCore::GetArchitecture
return arch;
}
-const lldb::DataBufferSP ProcessElfCore::GetAuxvData() {
+DataExtractor ProcessElfCore::GetAuxvData() {
const uint8_t *start = m_auxv.GetDataStart();
size_t len = m_auxv.GetByteSize();
lldb::DataBufferSP buffer(new lldb_private::DataBufferHeap(start, len));
- return buffer;
+ return DataExtractor(buffer, GetByteOrder(), GetAddressByteSize());
}
bool ProcessElfCore::GetProcessInfo(ProcessInstanceInfo &info) {
Modified: lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.h (original)
+++ lldb/trunk/source/Plugins/Process/elf-core/ProcessElfCore.h Tue Jun 11 13:16:13 2019
@@ -97,7 +97,7 @@ public:
lldb_private::ArchSpec GetArchitecture();
// Returns AUXV structure found in the core file
- const lldb::DataBufferSP GetAuxvData() override;
+ lldb_private::DataExtractor GetAuxvData() override;
bool GetProcessInfo(lldb_private::ProcessInstanceInfo &info) override;
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.cpp Tue Jun 11 13:16:13 2019
@@ -4046,7 +4046,7 @@ Status ProcessGDBRemote::SendEventData(c
return error;
}
-const DataBufferSP ProcessGDBRemote::GetAuxvData() {
+DataExtractor ProcessGDBRemote::GetAuxvData() {
DataBufferSP buf;
if (m_gdb_comm.GetQXferAuxvReadSupported()) {
std::string response_string;
@@ -4056,7 +4056,7 @@ const DataBufferSP ProcessGDBRemote::Get
buf = std::make_shared<DataBufferHeap>(response_string.c_str(),
response_string.length());
}
- return buf;
+ return DataExtractor(buf, GetByteOrder(), GetAddressByteSize());
}
StructuredData::ObjectSP
Modified: lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h (original)
+++ lldb/trunk/source/Plugins/Process/gdb-remote/ProcessGDBRemote.h Tue Jun 11 13:16:13 2019
@@ -324,7 +324,7 @@ protected:
bool ParsePythonTargetDefinition(const FileSpec &target_definition_fspec);
- const lldb::DataBufferSP GetAuxvData() override;
+ DataExtractor GetAuxvData() override;
StructuredData::ObjectSP GetExtendedInfoForThread(lldb::tid_t tid);
Modified: lldb/trunk/source/Target/Process.cpp
URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/source/Target/Process.cpp?rev=363098&r1=363097&r2=363098&view=diff
==============================================================================
--- lldb/trunk/source/Target/Process.cpp (original)
+++ lldb/trunk/source/Target/Process.cpp Tue Jun 11 13:16:13 2019
@@ -2708,7 +2708,7 @@ DynamicLoader *Process::GetDynamicLoader
return m_dyld_up.get();
}
-const lldb::DataBufferSP Process::GetAuxvData() { return DataBufferSP(); }
+DataExtractor Process::GetAuxvData() { return DataExtractor(); }
JITLoaderList &Process::GetJITLoaders() {
if (!m_jit_loaders_up) {
More information about the lldb-commits
mailing list