[Lldb-commits] [lldb] [lldb] Make ELF files able to load section headers from memory. (PR #129166)
via lldb-commits
lldb-commits at lists.llvm.org
Thu Feb 27 16:58:36 PST 2025
github-actions[bot] wrote:
<!--LLVM CODE FORMAT COMMENT: {clang-format}-->
:warning: C/C++ code formatter, clang-format found issues in your code. :warning:
<details>
<summary>
You can test this locally with the following command:
</summary>
``````````bash
git-clang-format --diff 1199bbb396fb9554401ad5ae1816b6648bab76a9 d653c41231ab7dd2ee649ea6ebef3d12aed4d4b9 --extensions cpp,h -- lldb/source/Plugins/ObjectFile/ELF/ELFHeader.h lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
``````````
</details>
<details>
<summary>
View the diff from clang-format here.
</summary>
``````````diff
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
index ba96f9fad6..5e488b2963 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp
@@ -557,8 +557,9 @@ static bool GetOsFromOSABI(unsigned char osabi_byte,
}
/// Read the bytes for the section headers from the ELF object file data.
-static DataExtractor GetSectionHeadersFromELFData(
- const elf::ELFHeader &header, const DataExtractor &object_data) {
+static DataExtractor
+GetSectionHeadersFromELFData(const elf::ELFHeader &header,
+ const DataExtractor &object_data) {
DataExtractor sh_data;
const elf_off sh_offset = header.e_shoff;
const size_t sh_size = header.GetSectionHeaderByteSize();
@@ -568,14 +569,14 @@ static DataExtractor GetSectionHeadersFromELFData(
/// Read the section data bytes for the section from the ELF object file data.
bool ObjectFileELF::GetSectionContentsFromELFData(
- const elf::ELFSectionHeader &sh, const DataExtractor &object_data,
- lldb_private::DataExtractor §ion_data) {
+ const elf::ELFSectionHeader &sh, const DataExtractor &object_data,
+ lldb_private::DataExtractor §ion_data) {
if (sh.sh_type == SHT_NOBITS || sh.sh_size == 0) {
section_data.Clear();
return false;
}
- return section_data.SetData(object_data,
- sh.sh_offset, sh.sh_size) == sh.sh_size;
+ return section_data.SetData(object_data, sh.sh_offset, sh.sh_size) ==
+ sh.sh_size;
}
size_t ObjectFileELF::GetModuleSpecifications(
@@ -1385,14 +1386,11 @@ void ObjectFileELF::ParseARMAttributes(DataExtractor &data,
}
// GetSectionHeaderInfo
-size_t ObjectFileELF::GetSectionHeaderInfo(const elf::ELFHeader &header,
- const DataExtractor &sh_data,
- SectionHeaderColl §ion_headers,
- ReadSectionDataCallback read_sect,
- lldb_private::UUID &uuid,
- std::string &gnu_debuglink_file,
- uint32_t &gnu_debuglink_crc,
- ArchSpec &arch_spec) {
+size_t ObjectFileELF::GetSectionHeaderInfo(
+ const elf::ELFHeader &header, const DataExtractor &sh_data,
+ SectionHeaderColl §ion_headers, ReadSectionDataCallback read_sect,
+ lldb_private::UUID &uuid, std::string &gnu_debuglink_file,
+ uint32_t &gnu_debuglink_crc, ArchSpec &arch_spec) {
// Don't reparse the section headers if we already did that.
if (!section_headers.empty())
return section_headers.size();
@@ -1594,8 +1592,7 @@ size_t ObjectFileELF::GetSectionHeaderInfo(const elf::ELFHeader &header,
if (arch_spec.GetMachine() == llvm::Triple::arm ||
arch_spec.GetMachine() == llvm::Triple::thumb) {
DataExtractor data;
- if (sheader.sh_type == SHT_ARM_ATTRIBUTES &&
- read_sect(sheader, data))
+ if (sheader.sh_type == SHT_ARM_ATTRIBUTES && read_sect(sheader, data))
ParseARMAttributes(data, arch_spec);
}
@@ -1662,7 +1659,8 @@ size_t ObjectFileELF::ParseSectionHeaders() {
if (ProcessSP process_sp = m_process_wp.lock()) {
const addr_t addr = m_memory_addr + m_header.e_shoff;
if (DataBufferSP data_sp = ReadMemory(process_sp, addr, sh_size))
- sh_data = DataExtractor(data_sp, GetByteOrder(), GetAddressByteSize());
+ sh_data =
+ DataExtractor(data_sp, GetByteOrder(), GetAddressByteSize());
}
}
}
@@ -3862,7 +3860,8 @@ DataExtractor ObjectFileELF::GetSectionData(const elf::ELFSectionHeader &sh) {
// the process.
if (ProcessSP process_sp = m_process_wp.lock()) {
const addr_t data_addr = m_memory_addr + sh.sh_offset;
- if (DataBufferSP data_sp = ReadMemory(process_sp, data_addr, sh.sh_size)) {
+ if (DataBufferSP data_sp =
+ ReadMemory(process_sp, data_addr, sh.sh_size)) {
data = DataExtractor(data_sp, GetByteOrder(), GetAddressByteSize());
if (data.GetByteSize() == sh.sh_size)
return data;
diff --git a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
index 039909f7d3..bf881b0ceb 100644
--- a/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
+++ b/lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h
@@ -293,18 +293,17 @@ private:
///
/// \return True if we are able to read all of the section data from
/// \a object_data. False otherwise.
- static bool GetSectionContentsFromELFData(
- const elf::ELFSectionHeader &sh,
- const lldb_private::DataExtractor &object_data,
- lldb_private::DataExtractor §ion_data);
+ static bool
+ GetSectionContentsFromELFData(const elf::ELFSectionHeader &sh,
+ const lldb_private::DataExtractor &object_data,
+ lldb_private::DataExtractor §ion_data);
/// Callback that can be used to read the data for a section.
///
/// \return True if the section has a size and all bytes can be read,
/// False otherwise.
- using ReadSectionDataCallback =
- std::function<bool(const elf::ELFSectionHeader &sh,
- lldb_private::DataExtractor &data)>;
+ using ReadSectionDataCallback = std::function<bool(
+ const elf::ELFSectionHeader &sh, lldb_private::DataExtractor &data)>;
/// Parses the elf section headers and returns the uuid, debug link name,
/// crc, archspec.
``````````
</details>
https://github.com/llvm/llvm-project/pull/129166
More information about the lldb-commits
mailing list