16std::optional<uint64_t>
22 DataExtractor auxv_data(buffer_or_error.get()->getBufferStart(),
23 buffer_or_error.get()->getBufferSize(),
36 llvm::ELF::Elf64_Dyn>();
40 llvm::ELF::Elf32_Dyn>();
46template <
typename ELF_EHDR,
typename ELF_PHDR,
typename ELF_DYN>
48 std::optional<uint64_t> maybe_phdr_addr =
50 std::optional<uint64_t> maybe_phdr_entry_size =
52 std::optional<uint64_t> maybe_phdr_num_entries =
54 if (!maybe_phdr_addr || !maybe_phdr_entry_size || !maybe_phdr_num_entries)
57 size_t phdr_entry_size = *maybe_phdr_entry_size;
58 size_t phdr_num_entries = *maybe_phdr_num_entries;
64 bool found_load_bias =
false;
66 uint64_t dynamic_section_size = 0;
67 bool found_dynamic_section =
false;
69 for (
size_t i = 0; i < phdr_num_entries; i++) {
72 sizeof(phdr_entry), bytes_read);
75 if (phdr_entry.p_type == llvm::ELF::PT_PHDR) {
76 load_bias = phdr_addr - phdr_entry.p_vaddr;
77 found_load_bias =
true;
80 if (phdr_entry.p_type == llvm::ELF::PT_DYNAMIC) {
81 dynamic_section_addr = phdr_entry.p_vaddr;
82 dynamic_section_size = phdr_entry.p_memsz;
83 found_dynamic_section =
true;
87 if (!found_load_bias || !found_dynamic_section)
91 dynamic_section_addr += load_bias;
92 ELF_DYN dynamic_entry;
93 size_t dynamic_num_entries = dynamic_section_size /
sizeof(dynamic_entry);
94 for (
size_t i = 0; i < dynamic_num_entries; i++) {
96 auto error =
ReadMemory(dynamic_section_addr + i *
sizeof(dynamic_entry),
97 &dynamic_entry,
sizeof(dynamic_entry), bytes_read);
102 if (dynamic_entry.d_tag == llvm::ELF::DT_DEBUG) {
103 return dynamic_section_addr + i *
sizeof(dynamic_entry) +
104 sizeof(dynamic_entry.d_tag);
112 llvm::ELF::Elf32_Ehdr, llvm::ELF::Elf32_Phdr, llvm::ELF::Elf32_Dyn>();
114 llvm::ELF::Elf64_Ehdr, llvm::ELF::Elf64_Phdr, llvm::ELF::Elf64_Dyn>();
117llvm::Expected<SVR4LibraryInfo>
122 ReadMemory(link_map_addr, &link_map,
sizeof(link_map), bytes_read);
123 if (!
error.Success())
124 return error.ToError();
128 link_map.
l_name, &name_buffer[0],
sizeof(name_buffer), bytes_read);
129 if (!string_or_error)
130 return string_or_error.takeError();
133 info.
name = string_or_error->str();
142llvm::Expected<std::vector<SVR4LibraryInfo>>
147 return llvm::createStringError(llvm::inconvertibleErrorCode(),
148 "Invalid shared library info address");
154 if (!status.Success())
155 return status.ToError();
157 return llvm::createStringError(llvm::inconvertibleErrorCode(),
158 "Invalid r_debug address");
163 if (!status.Success())
164 return status.ToError();
166 return llvm::createStringError(llvm::inconvertibleErrorCode(),
167 "Invalid link_map address");
169 std::vector<SVR4LibraryInfo> library_list;
171 llvm::Expected<SVR4LibraryInfo> info =
173 : ReadSVR4LibraryInfo<uint32_t>(link_map);
175 return info.takeError();
176 if (!info->name.empty() && info->base_addr != 0)
177 library_list.push_back(*info);
178 link_map = info->next;
static llvm::raw_ostream & error(Stream &strm)
EntryType
Constants describing the type of entry.
@ AUXV_AT_PHNUM
Number of program headers.
@ AUXV_AT_PHDR
Program headers.
@ AUXV_AT_PHENT
Size of program header.
llvm::Expected< SVR4LibraryInfo > ReadSVR4LibraryInfo(lldb::addr_t link_map_addr)
std::unique_ptr< AuxVector > m_aux_vector
llvm::Expected< std::vector< SVR4LibraryInfo > > GetLoadedSVR4Libraries() override
lldb::addr_t GetSharedLibraryInfoAddress() override
lldb::addr_t GetELFImageInfoAddress()
std::optional< uint64_t > GetAuxValue(enum AuxVector::EntryType type)
void NotifyDidExec() override
Notify the delegate that an exec occurred.
std::optional< lldb::addr_t > m_shared_library_info_addr
uint32_t GetAddressByteSize() const
lldb::ByteOrder GetByteOrder() const
llvm::Expected< llvm::StringRef > ReadCStringFromMemory(lldb::addr_t addr, char *buffer, size_t max_size, size_t &total_bytes_read)
Reads a null terminated string from memory.
virtual Status ReadMemory(lldb::addr_t addr, void *buf, size_t size, size_t &bytes_read)=0
virtual void NotifyDidExec()
Notify the delegate that an exec occurred.
virtual llvm::ErrorOr< std::unique_ptr< llvm::MemoryBuffer > > GetAuxvData() const =0
#define LLDB_INVALID_ADDRESS
A class that represents a running process on the host machine.