mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 13:28:11 +00:00
LibELF: Remove ELF::Loader and move everyone to ELF::Image
This commit gets rid of ELF::Loader entirely since its very ambiguous purpose was actually to load executables for the kernel, and that is now handled by the kernel itself. This patch includes some drive-by cleanup in LibDebug and CrashDaemon enabled by the fact that we no longer need to keep the ref-counted ELF::Loader around.
This commit is contained in:
parent
7551a66f73
commit
1e4c010643
24 changed files with 178 additions and 318 deletions
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <AK/Demangle.h>
|
||||
#include <AK/Memory.h>
|
||||
#include <AK/QuickSort.h>
|
||||
#include <AK/StringBuilder.h>
|
||||
#include <AK/StringView.h>
|
||||
#include <LibELF/Image.h>
|
||||
|
@ -323,4 +324,84 @@ Optional<Image::Symbol> Image::find_demangled_function(const String& name) const
|
|||
return found;
|
||||
}
|
||||
|
||||
Optional<Image::Symbol> Image::find_symbol(u32 address, u32* out_offset) const
|
||||
{
|
||||
auto symbol_count = this->symbol_count();
|
||||
if (!symbol_count)
|
||||
return {};
|
||||
|
||||
SortedSymbol* sorted_symbols = nullptr;
|
||||
if (m_sorted_symbols.is_empty()) {
|
||||
m_sorted_symbols.ensure_capacity(symbol_count);
|
||||
for_each_symbol([this](auto& symbol) {
|
||||
m_sorted_symbols.append({ symbol.value(), symbol.name(), {}, symbol });
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
quick_sort(m_sorted_symbols, [](auto& a, auto& b) {
|
||||
return a.address < b.address;
|
||||
});
|
||||
}
|
||||
sorted_symbols = m_sorted_symbols.data();
|
||||
|
||||
for (size_t i = 0; i < symbol_count; ++i) {
|
||||
if (sorted_symbols[i].address > address) {
|
||||
if (i == 0)
|
||||
return {};
|
||||
auto& symbol = sorted_symbols[i - 1];
|
||||
if (out_offset)
|
||||
*out_offset = address - symbol.address;
|
||||
return symbol.symbol;
|
||||
}
|
||||
}
|
||||
return {};
|
||||
}
|
||||
|
||||
String Image::symbolicate(u32 address, u32* out_offset) const
|
||||
{
|
||||
auto symbol_count = this->symbol_count();
|
||||
if (!symbol_count) {
|
||||
if (out_offset)
|
||||
*out_offset = 0;
|
||||
return "??";
|
||||
}
|
||||
SortedSymbol* sorted_symbols = nullptr;
|
||||
|
||||
if (m_sorted_symbols.is_empty()) {
|
||||
m_sorted_symbols.ensure_capacity(symbol_count);
|
||||
for_each_symbol([this](auto& symbol) {
|
||||
m_sorted_symbols.append({ symbol.value(), symbol.name(), {}, {} });
|
||||
return IterationDecision::Continue;
|
||||
});
|
||||
quick_sort(m_sorted_symbols, [](auto& a, auto& b) {
|
||||
return a.address < b.address;
|
||||
});
|
||||
}
|
||||
sorted_symbols = m_sorted_symbols.data();
|
||||
|
||||
for (size_t i = 0; i < symbol_count; ++i) {
|
||||
if (sorted_symbols[i].address > address) {
|
||||
if (i == 0) {
|
||||
if (out_offset)
|
||||
*out_offset = 0;
|
||||
return "!!";
|
||||
}
|
||||
auto& symbol = sorted_symbols[i - 1];
|
||||
|
||||
auto& demangled_name = symbol.demangled_name;
|
||||
if (demangled_name.is_null()) {
|
||||
demangled_name = demangle(symbol.name);
|
||||
}
|
||||
|
||||
if (out_offset) {
|
||||
*out_offset = address - symbol.address;
|
||||
return demangled_name;
|
||||
}
|
||||
return String::format("%s +%u", demangled_name.characters(), address - symbol.address);
|
||||
}
|
||||
}
|
||||
if (out_offset)
|
||||
*out_offset = 0;
|
||||
return "??";
|
||||
}
|
||||
|
||||
} // end namespace ELF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue