1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:37:43 +00:00

LibELF: Replace kprintf's in ELFImage.cpp with dbgprintf

This lets us use the class in userspace
This commit is contained in:
Andrew Kaster 2019-12-29 01:20:38 -05:00 committed by Andreas Kling
parent c24fe710d7
commit 21161342ef

View file

@ -45,43 +45,43 @@ unsigned ELFImage::symbol_count() const
void ELFImage::dump() const void ELFImage::dump() const
{ {
kprintf("ELFImage{%p} {\n", this); dbgprintf("ELFImage{%p} {\n", this);
kprintf(" is_valid: %u\n", is_valid()); dbgprintf(" is_valid: %u\n", is_valid());
if (!is_valid()) { if (!is_valid()) {
kprintf("}\n"); dbgprintf("}\n");
return; return;
} }
kprintf(" type: %s\n", object_file_type_to_string(header().e_type)); dbgprintf(" type: %s\n", object_file_type_to_string(header().e_type));
kprintf(" machine: %u\n", header().e_machine); dbgprintf(" machine: %u\n", header().e_machine);
kprintf(" entry: %x\n", header().e_entry); dbgprintf(" entry: %x\n", header().e_entry);
kprintf(" shoff: %u\n", header().e_shoff); dbgprintf(" shoff: %u\n", header().e_shoff);
kprintf(" shnum: %u\n", header().e_shnum); dbgprintf(" shnum: %u\n", header().e_shnum);
kprintf(" shstrndx: %u\n", header().e_shstrndx); dbgprintf(" shstrndx: %u\n", header().e_shstrndx);
for (unsigned i = 0; i < header().e_shnum; ++i) { for (unsigned i = 0; i < header().e_shnum; ++i) {
auto& section = this->section(i); auto& section = this->section(i);
kprintf(" Section %u: {\n", i); dbgprintf(" Section %u: {\n", i);
kprintf(" name: %s\n", section.name()); dbgprintf(" name: %s\n", section.name());
kprintf(" type: %x\n", section.type()); dbgprintf(" type: %x\n", section.type());
kprintf(" offset: %x\n", section.offset()); dbgprintf(" offset: %x\n", section.offset());
kprintf(" size: %u\n", section.size()); dbgprintf(" size: %u\n", section.size());
kprintf(" \n"); dbgprintf(" \n");
kprintf(" }\n"); dbgprintf(" }\n");
} }
kprintf("Symbol count: %u (table is %u)\n", symbol_count(), m_symbol_table_section_index); dbgprintf("Symbol count: %u (table is %u)\n", symbol_count(), m_symbol_table_section_index);
for (unsigned i = 1; i < symbol_count(); ++i) { for (unsigned i = 1; i < symbol_count(); ++i) {
auto& sym = symbol(i); auto& sym = symbol(i);
kprintf("Symbol @%u:\n", i); dbgprintf("Symbol @%u:\n", i);
kprintf(" Name: %s\n", sym.name()); dbgprintf(" Name: %s\n", sym.name());
kprintf(" In section: %s\n", section_index_to_string(sym.section_index())); dbgprintf(" In section: %s\n", section_index_to_string(sym.section_index()));
kprintf(" Value: %x\n", sym.value()); dbgprintf(" Value: %x\n", sym.value());
kprintf(" Size: %u\n", sym.size()); dbgprintf(" Size: %u\n", sym.size());
} }
kprintf("}\n"); dbgprintf("}\n");
} }
unsigned ELFImage::section_count() const unsigned ELFImage::section_count() const
@ -98,7 +98,7 @@ bool ELFImage::parse()
{ {
// We only support i386. // We only support i386.
if (header().e_machine != 3) { if (header().e_machine != 3) {
kprintf("ELFImage::parse(): e_machine=%u not supported!\n", header().e_machine); dbgprintf("ELFImage::parse(): e_machine=%u not supported!\n", header().e_machine);
return false; return false;
} }
@ -195,14 +195,14 @@ const ELFImage::RelocationSection ELFImage::Section::relocations() const
sprintf(relocation_sectionName, ".rel%s", name()); sprintf(relocation_sectionName, ".rel%s", name());
#ifdef ELFIMAGE_DEBUG #ifdef ELFIMAGE_DEBUG
kprintf("looking for '%s'\n", relocation_sectionName); dbgprintf("looking for '%s'\n", relocation_sectionName);
#endif #endif
auto relocation_section = m_image.lookup_section(relocation_sectionName); auto relocation_section = m_image.lookup_section(relocation_sectionName);
if (relocation_section.type() != SHT_REL) if (relocation_section.type() != SHT_REL)
return static_cast<const RelocationSection>(m_image.section(0)); return static_cast<const RelocationSection>(m_image.section(0));
#ifdef ELFIMAGE_DEBUG #ifdef ELFIMAGE_DEBUG
kprintf("Found relocations for %s in %s\n", name(), relocation_section.name()); dbgprintf("Found relocations for %s in %s\n", name(), relocation_section.name());
#endif #endif
return static_cast<const RelocationSection>(relocation_section); return static_cast<const RelocationSection>(relocation_section);
} }