Skip to content

Commit 943faef

Browse files
committed
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
1 parent 1dc3c9a commit 943faef

File tree

18 files changed

+149
-206
lines changed

18 files changed

+149
-206
lines changed

lldb/include/lldb/Host/common/NativeProcessProtocol.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,10 @@ class NativeProcessProtocol {
133133
return GetArchitecture().GetByteOrder();
134134
}
135135

136+
uint32_t GetAddressByteSize() const {
137+
return GetArchitecture().GetAddressByteSize();
138+
}
139+
136140
virtual llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
137141
GetAuxvData() const = 0;
138142

lldb/include/lldb/Target/Process.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,8 +670,8 @@ class Process : public std::enable_shared_from_this<Process>,
670670
// The default action is to return an empty data buffer.
671671
//
672672
// \return
673-
// A data buffer containing the contents of the AUXV data.
674-
virtual const lldb::DataBufferSP GetAuxvData();
673+
// A data extractor containing the contents of the AUXV data.
674+
virtual DataExtractor GetAuxvData();
675675

676676
/// Sometimes processes know how to retrieve and load shared libraries. This
677677
/// is normally done by DynamicLoader plug-ins, but sometimes the connection

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/AuxVector.h

Lines changed: 0 additions & 108 deletions
This file was deleted.

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
add_lldb_library(lldbPluginDynamicLoaderPosixDYLD PLUGIN
2-
AuxVector.cpp
32
DYLDRendezvous.cpp
43
DynamicLoaderPOSIXDYLD.cpp
54

@@ -10,6 +9,7 @@ add_lldb_library(lldbPluginDynamicLoaderPosixDYLD PLUGIN
109
lldbSymbol
1110
lldbTarget
1211
lldbPluginProcessElfCore
12+
lldbPluginProcessUtility
1313
LINK_COMPONENTS
1414
Support
1515
)

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.cpp

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
// Main header include
1010
#include "DynamicLoaderPOSIXDYLD.h"
1111

12-
#include "AuxVector.h"
13-
1412
#include "lldb/Breakpoint/BreakpointLocation.h"
1513
#include "lldb/Core/Module.h"
1614
#include "lldb/Core/ModuleSpec.h"
@@ -90,8 +88,8 @@ void DynamicLoaderPOSIXDYLD::DidAttach() {
9088
if (log)
9189
log->Printf("DynamicLoaderPOSIXDYLD::%s() pid %" PRIu64, __FUNCTION__,
9290
m_process ? m_process->GetID() : LLDB_INVALID_PROCESS_ID);
91+
m_auxv = llvm::make_unique<AuxVector>(m_process->GetAuxvData());
9392

94-
m_auxv.reset(new AuxVector(m_process));
9593
if (log)
9694
log->Printf("DynamicLoaderPOSIXDYLD::%s pid %" PRIu64 " reloaded auxv data",
9795
__FUNCTION__,
@@ -182,7 +180,7 @@ void DynamicLoaderPOSIXDYLD::DidLaunch() {
182180
ModuleSP executable;
183181
addr_t load_offset;
184182

185-
m_auxv.reset(new AuxVector(m_process));
183+
m_auxv = llvm::make_unique<AuxVector>(m_process->GetAuxvData());
186184

187185
executable = GetTargetExecutable();
188186
load_offset = ComputeLoadOffset();
@@ -628,13 +626,13 @@ addr_t DynamicLoaderPOSIXDYLD::ComputeLoadOffset() {
628626
}
629627

630628
void DynamicLoaderPOSIXDYLD::EvalSpecialModulesStatus() {
631-
auto I = m_auxv->FindEntry(AuxVector::AUXV_AT_SYSINFO_EHDR);
632-
if (I != m_auxv->end() && I->value != 0)
633-
m_vdso_base = I->value;
629+
if (llvm::Optional<uint64_t> vdso_base =
630+
m_auxv->GetAuxValue(AuxVector::AUXV_AT_SYSINFO_EHDR))
631+
m_vdso_base = *vdso_base;
634632

635-
I = m_auxv->FindEntry(AuxVector::AUXV_AT_BASE);
636-
if (I != m_auxv->end() && I->value != 0)
637-
m_interpreter_base = I->value;
633+
if (llvm::Optional<uint64_t> interpreter_base =
634+
m_auxv->GetAuxValue(AuxVector::AUXV_AT_BASE))
635+
m_interpreter_base = *interpreter_base;
638636
}
639637

640638
addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() {
@@ -644,12 +642,12 @@ addr_t DynamicLoaderPOSIXDYLD::GetEntryPoint() {
644642
if (m_auxv == nullptr)
645643
return LLDB_INVALID_ADDRESS;
646644

647-
AuxVector::iterator I = m_auxv->FindEntry(AuxVector::AUXV_AT_ENTRY);
648-
649-
if (I == m_auxv->end())
645+
llvm::Optional<uint64_t> entry_point =
646+
m_auxv->GetAuxValue(AuxVector::AUXV_AT_ENTRY);
647+
if (!entry_point)
650648
return LLDB_INVALID_ADDRESS;
651649

652-
m_entry_point = static_cast<addr_t>(I->value);
650+
m_entry_point = static_cast<addr_t>(*entry_point);
653651

654652
const ArchSpec &arch = m_process->GetTarget().GetArchitecture();
655653

lldb/source/Plugins/DynamicLoader/POSIX-DYLD/DynamicLoaderPOSIXDYLD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <memory>
1414

1515
#include "DYLDRendezvous.h"
16+
#include "Plugins/Process/Utility/AuxVector.h"
1617
#include "lldb/Breakpoint/StoppointCallbackContext.h"
1718
#include "lldb/Core/ModuleList.h"
1819
#include "lldb/Target/DynamicLoader.h"

lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -876,7 +876,7 @@ bool ProcessFreeBSD::IsAThreadRunning() {
876876
return is_running;
877877
}
878878

879-
const DataBufferSP ProcessFreeBSD::GetAuxvData() {
879+
lldb_private::DataExtractor ProcessFreeBSD::GetAuxvData() {
880880
// If we're the local platform, we can ask the host for auxv data.
881881
PlatformSP platform_sp = GetTarget().GetPlatform();
882882
assert(platform_sp && platform_sp->IsHost());
@@ -890,7 +890,7 @@ const DataBufferSP ProcessFreeBSD::GetAuxvData() {
890890
buf_sp.reset();
891891
}
892892

893-
return buf_sp;
893+
return DataExtractor(buf_sp, GetByteOrder(), GetAddressByteSize());
894894
}
895895

896896
struct EmulatorBaton {

lldb/source/Plugins/Process/FreeBSD/ProcessFreeBSD.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class ProcessFreeBSD : public lldb_private::Process {
127127
size_t PutSTDIN(const char *buf, size_t len,
128128
lldb_private::Status &error) override;
129129

130-
const lldb::DataBufferSP GetAuxvData() override;
130+
const lldb_private::DataExtractor GetAuxvData() override;
131131

132132
// ProcessFreeBSD internal API.
133133

lldb/source/Plugins/Process/Linux/NativeProcessLinux.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2082,3 +2082,18 @@ Status NativeProcessLinux::StopProcessorTracingOnThread(lldb::user_id_t traceid,
20822082

20832083
return error;
20842084
}
2085+
2086+
llvm::Optional<uint64_t>
2087+
NativeProcessLinux::GetAuxValue(enum AuxVector::EntryType type) {
2088+
if (m_aux_vector == nullptr) {
2089+
auto buffer_or_error = GetAuxvData();
2090+
if (!buffer_or_error)
2091+
return llvm::None;
2092+
DataExtractor auxv_data(buffer_or_error.get()->getBufferStart(),
2093+
buffer_or_error.get()->getBufferSize(),
2094+
GetByteOrder(), GetAddressByteSize());
2095+
m_aux_vector = llvm::make_unique<AuxVector>(auxv_data);
2096+
}
2097+
2098+
return m_aux_vector->GetAuxValue(type);
2099+
}

lldb/source/Plugins/Process/Linux/NativeProcessLinux.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
#include <csignal>
1313
#include <unordered_set>
1414

15+
#include "Plugins/Process/Utility/AuxVector.h"
1516
#include "lldb/Host/Debug.h"
1617
#include "lldb/Host/HostThread.h"
1718
#include "lldb/Host/linux/Support.h"
@@ -102,6 +103,8 @@ class NativeProcessLinux : public NativeProcessProtocol {
102103
return getProcFile(GetID(), "auxv");
103104
}
104105

106+
llvm::Optional<uint64_t> GetAuxValue(enum AuxVector::EntryType type);
107+
105108
lldb::user_id_t StartTrace(const TraceOptions &config,
106109
Status &error) override;
107110

@@ -132,6 +135,7 @@ class NativeProcessLinux : public NativeProcessProtocol {
132135
private:
133136
MainLoop::SignalHandleUP m_sigchld_handle;
134137
ArchSpec m_arch;
138+
std::unique_ptr<AuxVector> m_aux_vector;
135139

136140
LazyBool m_supports_mem_region = eLazyBoolCalculate;
137141
std::vector<std::pair<MemoryRegionInfo, FileSpec>> m_mem_region_cache;

0 commit comments

Comments
 (0)