mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 08:48:11 +00:00
LibELF+Utilities: Avoid truncating 64-bit values
This fixes displaying 64-bit addresses in readelf and also fixes showing backtraces from core dumps on x86_64.
This commit is contained in:
parent
36c3927169
commit
db1c5c4830
6 changed files with 37 additions and 36 deletions
|
@ -451,7 +451,7 @@ void DebugSession::update_loaded_libs()
|
||||||
if (file_or_error.is_error())
|
if (file_or_error.is_error())
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
|
|
||||||
FlatPtr base_address = entry.as_object().get("address").as_u32();
|
FlatPtr base_address = entry.as_object().get("address").to_addr();
|
||||||
auto debug_info = make<DebugInfo>(make<ELF::Image>(file_or_error.value()->bytes()), m_source_root, base_address);
|
auto debug_info = make<DebugInfo>(make<ELF::Image>(file_or_error.value()->bytes()), m_source_root, base_address);
|
||||||
auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(debug_info), base_address);
|
auto lib = make<LoadedLibrary>(lib_name, file_or_error.release_value(), move(debug_info), base_address);
|
||||||
m_loaded_libraries.set(lib_name, move(lib));
|
m_loaded_libraries.set(lib_name, move(lib));
|
||||||
|
|
|
@ -50,8 +50,8 @@ struct [[gnu::packed]] ThreadInfo {
|
||||||
|
|
||||||
struct [[gnu::packed]] MemoryRegionInfo {
|
struct [[gnu::packed]] MemoryRegionInfo {
|
||||||
NotesEntryHeader header;
|
NotesEntryHeader header;
|
||||||
uint32_t region_start;
|
uint64_t region_start;
|
||||||
uint32_t region_end;
|
uint64_t region_end;
|
||||||
uint16_t program_header_index;
|
uint16_t program_header_index;
|
||||||
char region_name[]; // Null terminated
|
char region_name[]; // Null terminated
|
||||||
|
|
||||||
|
|
|
@ -60,8 +60,8 @@ public:
|
||||||
StringView name() const { return m_dynamic.symbol_string_table_string(m_sym.st_name); }
|
StringView name() const { return m_dynamic.symbol_string_table_string(m_sym.st_name); }
|
||||||
const char* raw_name() const { return m_dynamic.raw_symbol_string_table_string(m_sym.st_name); }
|
const char* raw_name() const { return m_dynamic.raw_symbol_string_table_string(m_sym.st_name); }
|
||||||
unsigned section_index() const { return m_sym.st_shndx; }
|
unsigned section_index() const { return m_sym.st_shndx; }
|
||||||
unsigned value() const { return m_sym.st_value; }
|
FlatPtr value() const { return m_sym.st_value; }
|
||||||
unsigned size() const { return m_sym.st_size; }
|
size_t size() const { return m_sym.st_size; }
|
||||||
unsigned index() const { return m_index; }
|
unsigned index() const { return m_index; }
|
||||||
#if ARCH(I386)
|
#if ARCH(I386)
|
||||||
unsigned type() const
|
unsigned type() const
|
||||||
|
|
|
@ -332,7 +332,7 @@ Image::SortedSymbol* Image::find_sorted_symbol(FlatPtr address) const
|
||||||
return &m_sorted_symbols[index];
|
return &m_sorted_symbols[index];
|
||||||
}
|
}
|
||||||
|
|
||||||
Optional<Image::Symbol> Image::find_symbol(u32 address, u32* out_offset) const
|
Optional<Image::Symbol> Image::find_symbol(FlatPtr address, u32* out_offset) const
|
||||||
{
|
{
|
||||||
auto symbol_count = this->symbol_count();
|
auto symbol_count = this->symbol_count();
|
||||||
if (!symbol_count)
|
if (!symbol_count)
|
||||||
|
@ -358,7 +358,7 @@ NEVER_INLINE void Image::sort_symbols() const
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
String Image::symbolicate(u32 address, u32* out_offset) const
|
String Image::symbolicate(FlatPtr address, u32* out_offset) const
|
||||||
{
|
{
|
||||||
auto symbol_count = this->symbol_count();
|
auto symbol_count = this->symbol_count();
|
||||||
if (!symbol_count) {
|
if (!symbol_count) {
|
||||||
|
|
|
@ -51,8 +51,8 @@ public:
|
||||||
|
|
||||||
StringView name() const { return m_image.table_string(m_sym.st_name); }
|
StringView name() const { return m_image.table_string(m_sym.st_name); }
|
||||||
unsigned section_index() const { return m_sym.st_shndx; }
|
unsigned section_index() const { return m_sym.st_shndx; }
|
||||||
unsigned value() const { return m_sym.st_value; }
|
FlatPtr value() const { return m_sym.st_value; }
|
||||||
unsigned size() const { return m_sym.st_size; }
|
size_t size() const { return m_sym.st_size; }
|
||||||
unsigned index() const { return m_index; }
|
unsigned index() const { return m_index; }
|
||||||
#if ARCH(I386)
|
#if ARCH(I386)
|
||||||
unsigned type() const
|
unsigned type() const
|
||||||
|
@ -93,11 +93,11 @@ public:
|
||||||
unsigned index() const { return m_program_header_index; }
|
unsigned index() const { return m_program_header_index; }
|
||||||
u32 type() const { return m_program_header.p_type; }
|
u32 type() const { return m_program_header.p_type; }
|
||||||
u32 flags() const { return m_program_header.p_flags; }
|
u32 flags() const { return m_program_header.p_flags; }
|
||||||
u32 offset() const { return m_program_header.p_offset; }
|
size_t offset() const { return m_program_header.p_offset; }
|
||||||
VirtualAddress vaddr() const { return VirtualAddress(m_program_header.p_vaddr); }
|
VirtualAddress vaddr() const { return VirtualAddress(m_program_header.p_vaddr); }
|
||||||
u32 size_in_memory() const { return m_program_header.p_memsz; }
|
size_t size_in_memory() const { return m_program_header.p_memsz; }
|
||||||
u32 size_in_image() const { return m_program_header.p_filesz; }
|
size_t size_in_image() const { return m_program_header.p_filesz; }
|
||||||
u32 alignment() const { return m_program_header.p_align; }
|
size_t alignment() const { return m_program_header.p_align; }
|
||||||
bool is_readable() const { return flags() & PF_R; }
|
bool is_readable() const { return flags() & PF_R; }
|
||||||
bool is_writable() const { return flags() & PF_W; }
|
bool is_writable() const { return flags() & PF_W; }
|
||||||
bool is_executable() const { return flags() & PF_X; }
|
bool is_executable() const { return flags() & PF_X; }
|
||||||
|
@ -121,16 +121,16 @@ public:
|
||||||
~Section() { }
|
~Section() { }
|
||||||
|
|
||||||
StringView name() const { return m_image.section_header_table_string(m_section_header.sh_name); }
|
StringView name() const { return m_image.section_header_table_string(m_section_header.sh_name); }
|
||||||
unsigned type() const { return m_section_header.sh_type; }
|
u32 type() const { return m_section_header.sh_type; }
|
||||||
unsigned offset() const { return m_section_header.sh_offset; }
|
size_t offset() const { return m_section_header.sh_offset; }
|
||||||
unsigned size() const { return m_section_header.sh_size; }
|
size_t size() const { return m_section_header.sh_size; }
|
||||||
unsigned entry_size() const { return m_section_header.sh_entsize; }
|
size_t entry_size() const { return m_section_header.sh_entsize; }
|
||||||
unsigned entry_count() const { return !entry_size() ? 0 : size() / entry_size(); }
|
size_t entry_count() const { return !entry_size() ? 0 : size() / entry_size(); }
|
||||||
u32 address() const { return m_section_header.sh_addr; }
|
FlatPtr address() const { return m_section_header.sh_addr; }
|
||||||
const char* raw_data() const { return m_image.raw_data(m_section_header.sh_offset); }
|
const char* raw_data() const { return m_image.raw_data(m_section_header.sh_offset); }
|
||||||
ReadonlyBytes bytes() const { return { raw_data(), size() }; }
|
ReadonlyBytes bytes() const { return { raw_data(), size() }; }
|
||||||
Optional<RelocationSection> relocations() const;
|
Optional<RelocationSection> relocations() const;
|
||||||
u32 flags() const { return m_section_header.sh_flags; }
|
auto flags() const { return m_section_header.sh_flags; }
|
||||||
bool is_writable() const { return flags() & SHF_WRITE; }
|
bool is_writable() const { return flags() & SHF_WRITE; }
|
||||||
bool is_executable() const { return flags() & PF_X; }
|
bool is_executable() const { return flags() & PF_X; }
|
||||||
|
|
||||||
|
@ -147,7 +147,7 @@ public:
|
||||||
: Section(section.m_image, section.m_section_index)
|
: Section(section.m_image, section.m_section_index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
unsigned relocation_count() const { return entry_count(); }
|
size_t relocation_count() const { return entry_count(); }
|
||||||
Relocation relocation(unsigned index) const;
|
Relocation relocation(unsigned index) const;
|
||||||
|
|
||||||
template<VoidFunction<Image::Relocation&> F>
|
template<VoidFunction<Image::Relocation&> F>
|
||||||
|
@ -164,7 +164,7 @@ public:
|
||||||
|
|
||||||
~Relocation() { }
|
~Relocation() { }
|
||||||
|
|
||||||
unsigned offset() const { return m_rel.r_offset; }
|
size_t offset() const { return m_rel.r_offset; }
|
||||||
#if ARCH(I386)
|
#if ARCH(I386)
|
||||||
unsigned type() const
|
unsigned type() const
|
||||||
{
|
{
|
||||||
|
@ -230,9 +230,9 @@ public:
|
||||||
bool has_symbols() const { return symbol_count(); }
|
bool has_symbols() const { return symbol_count(); }
|
||||||
#ifndef KERNEL
|
#ifndef KERNEL
|
||||||
Optional<Symbol> find_demangled_function(const StringView& name) const;
|
Optional<Symbol> find_demangled_function(const StringView& name) const;
|
||||||
String symbolicate(u32 address, u32* offset = nullptr) const;
|
String symbolicate(FlatPtr address, u32* offset = nullptr) const;
|
||||||
#endif
|
#endif
|
||||||
Optional<Image::Symbol> find_symbol(u32 address, u32* offset = nullptr) const;
|
Optional<Image::Symbol> find_symbol(FlatPtr address, u32* offset = nullptr) const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char* raw_data(unsigned offset) const;
|
const char* raw_data(unsigned offset) const;
|
||||||
|
@ -252,7 +252,7 @@ private:
|
||||||
unsigned m_string_table_section_index { 0 };
|
unsigned m_string_table_section_index { 0 };
|
||||||
|
|
||||||
struct SortedSymbol {
|
struct SortedSymbol {
|
||||||
u32 address;
|
FlatPtr address;
|
||||||
StringView name;
|
StringView name;
|
||||||
String demangled_name;
|
String demangled_name;
|
||||||
Optional<Image::Symbol> symbol;
|
Optional<Image::Symbol> symbol;
|
||||||
|
|
|
@ -563,18 +563,19 @@ int main(int argc, char** argv)
|
||||||
outln("There are no program headers in this file.");
|
outln("There are no program headers in this file.");
|
||||||
} else {
|
} else {
|
||||||
outln("Program Headers:");
|
outln("Program Headers:");
|
||||||
outln(" Type Offset VirtAddr{} PhysAddr{} FileSiz MemSiz Flg Align", addr_padding, addr_padding);
|
outln(" Type Offset{} VirtAddr{} PhysAddr{} FileSiz{} MemSiz{} Flg Align",
|
||||||
|
addr_padding, addr_padding, addr_padding, addr_padding, addr_padding);
|
||||||
|
|
||||||
elf_image.for_each_program_header([](const ELF::Image::ProgramHeader& program_header) {
|
elf_image.for_each_program_header([](const ELF::Image::ProgramHeader& program_header) {
|
||||||
out(" ");
|
out(" ");
|
||||||
out("{:14} ", object_program_header_type_to_string(program_header.type()));
|
out("{:14} ", object_program_header_type_to_string(program_header.type()));
|
||||||
out("{:#08x} ", program_header.offset());
|
out("{:p} ", program_header.offset());
|
||||||
out("{:p} ", program_header.vaddr().as_ptr());
|
out("{:p} ", program_header.vaddr().as_ptr());
|
||||||
out("{:p} ", program_header.vaddr().as_ptr()); // FIXME: assumes PhysAddr = VirtAddr
|
out("{:p} ", program_header.vaddr().as_ptr()); // FIXME: assumes PhysAddr = VirtAddr
|
||||||
out("{:#08x} ", program_header.size_in_image());
|
out("{:p} ", program_header.size_in_image());
|
||||||
out("{:#08x} ", program_header.size_in_memory());
|
out("{:p} ", program_header.size_in_memory());
|
||||||
out("{:04x} ", program_header.flags());
|
out("{:04x} ", program_header.flags());
|
||||||
out("{:#08x}", program_header.alignment());
|
out("{:p}", program_header.alignment());
|
||||||
outln();
|
outln();
|
||||||
|
|
||||||
if (program_header.type() == PT_INTERP)
|
if (program_header.type() == PT_INTERP)
|
||||||
|
@ -642,11 +643,11 @@ int main(int argc, char** argv)
|
||||||
outln("Relocation section '{}' at offset {:#08x} contains zero entries:", object->relocation_section().name(), object->relocation_section().offset());
|
outln("Relocation section '{}' at offset {:#08x} contains zero entries:", object->relocation_section().name(), object->relocation_section().offset());
|
||||||
} else {
|
} else {
|
||||||
outln("Relocation section '{}' at offset {:#08x} contains {} entries:", object->relocation_section().name(), object->relocation_section().offset(), object->relocation_section().entry_count());
|
outln("Relocation section '{}' at offset {:#08x} contains {} entries:", object->relocation_section().name(), object->relocation_section().offset(), object->relocation_section().entry_count());
|
||||||
outln(" Offset Type Sym Value Sym Name");
|
outln(" Offset{} Type Sym Value{} Sym Name", addr_padding, addr_padding);
|
||||||
object->relocation_section().for_each_relocation([](const ELF::DynamicObject::Relocation& reloc) {
|
object->relocation_section().for_each_relocation([](const ELF::DynamicObject::Relocation& reloc) {
|
||||||
out(" {:#08x} ", reloc.offset());
|
out(" {:p} ", reloc.offset());
|
||||||
out(" {:17} ", object_relocation_type_to_string(reloc.type()));
|
out(" {:17} ", object_relocation_type_to_string(reloc.type()));
|
||||||
out(" {:#08x} ", reloc.symbol().value());
|
out(" {:p} ", reloc.symbol().value());
|
||||||
out(" {}", reloc.symbol().name());
|
out(" {}", reloc.symbol().name());
|
||||||
outln();
|
outln();
|
||||||
});
|
});
|
||||||
|
@ -657,11 +658,11 @@ int main(int argc, char** argv)
|
||||||
outln("Relocation section '{}' at offset {:#08x} contains zero entries:", object->plt_relocation_section().name(), object->plt_relocation_section().offset());
|
outln("Relocation section '{}' at offset {:#08x} contains zero entries:", object->plt_relocation_section().name(), object->plt_relocation_section().offset());
|
||||||
} else {
|
} else {
|
||||||
outln("Relocation section '{}' at offset {:#08x} contains {} entries:", object->plt_relocation_section().name(), object->plt_relocation_section().offset(), object->plt_relocation_section().entry_count());
|
outln("Relocation section '{}' at offset {:#08x} contains {} entries:", object->plt_relocation_section().name(), object->plt_relocation_section().offset(), object->plt_relocation_section().entry_count());
|
||||||
outln(" Offset Type Sym Value Sym Name");
|
outln(" Offset{} Type Sym Value{} Sym Name", addr_padding, addr_padding);
|
||||||
object->plt_relocation_section().for_each_relocation([](const ELF::DynamicObject::Relocation& reloc) {
|
object->plt_relocation_section().for_each_relocation([](const ELF::DynamicObject::Relocation& reloc) {
|
||||||
out(" {:#08x} ", reloc.offset());
|
out(" {:p} ", reloc.offset());
|
||||||
out(" {:17} ", object_relocation_type_to_string(reloc.type()));
|
out(" {:17} ", object_relocation_type_to_string(reloc.type()));
|
||||||
out(" {:#08x} ", reloc.symbol().value());
|
out(" {:p} ", reloc.symbol().value());
|
||||||
out(" {}", reloc.symbol().name());
|
out(" {}", reloc.symbol().name());
|
||||||
outln();
|
outln();
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue