1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-19 23:25:08 +00:00

Kernel: Symbolicate userspace backtraces using ELFLoader.

Stash away the ELFLoader used to load an executable in Process so we can use
it for symbolicating userspace addresses later on. This will make debugging
userspace programs a lot nicer. :^)
This commit is contained in:
Andreas Kling 2019-05-16 17:18:25 +02:00
parent e20aecefba
commit 174639b7f0
6 changed files with 56 additions and 11 deletions

View file

@ -327,19 +327,20 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
bool success = region->page_in();
ASSERT(success);
}
OwnPtr<ELFLoader> loader;
{
// Okay, here comes the sleight of hand, pay close attention..
auto old_regions = move(m_regions);
m_regions.append(*region);
ELFLoader loader(region->laddr().as_ptr());
loader.map_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable, const String& name) {
loader = make<ELFLoader>(region->laddr().as_ptr());
loader->map_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, size_t offset_in_image, bool is_readable, bool is_writable, const String& name) {
ASSERT(size);
ASSERT(alignment == PAGE_SIZE);
size = ceil_div(size, PAGE_SIZE) * PAGE_SIZE;
(void) allocate_region_with_vmo(laddr, size, vmo.copy_ref(), offset_in_image, String(name), is_readable, is_writable);
return laddr.as_ptr();
};
loader.alloc_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) {
loader->alloc_section_hook = [&] (LinearAddress laddr, size_t size, size_t alignment, bool is_readable, bool is_writable, const String& name) {
ASSERT(size);
ASSERT(alignment == PAGE_SIZE);
size += laddr.get() & 0xfff;
@ -348,8 +349,8 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
(void) allocate_region(laddr, size, String(name), is_readable, is_writable);
return laddr.as_ptr();
};
bool success = loader.load();
if (!success || !loader.entry().get()) {
bool success = loader->load();
if (!success || !loader->entry().get()) {
m_page_directory = move(old_page_directory);
// FIXME: RAII this somehow instead.
ASSERT(&current->process() == this);
@ -359,9 +360,11 @@ int Process::do_exec(String path, Vector<String> arguments, Vector<String> envir
return -ENOEXEC;
}
entry_eip = loader.entry().get();
entry_eip = loader->entry().get();
}
m_elf_loader = move(loader);
current->m_kernel_stack_for_signal_handler_region = nullptr;
current->m_signal_stack_user_region = nullptr;
current->set_default_signal_dispositions();