From a79d8d8ae54a1a1dc971df8c24754f2a52feb142 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 27 Jul 2019 12:01:14 +0200 Subject: [PATCH] Kernel: Add (expensive) but valuable userspace symbols to stacks. This is expensive because we have to page in the entire executable for every process up front for this to work. This is due to the page fault code not being strong enough to run while another process is active. Note that we already had userspace symbols in *crash* stacks. This patch adds them generally, so they show up in /proc, Process Manager, etc. There's room for improvement here, but the debugging benefits way overshadow the performance penalty right now. :^) --- Kernel/Makefile | 1 + Kernel/Process.cpp | 5 +++++ Kernel/Thread.cpp | 8 +++++++- 3 files changed, 13 insertions(+), 1 deletion(-) diff --git a/Kernel/Makefile b/Kernel/Makefile index 62f8b1276b..c302147db7 100644 --- a/Kernel/Makefile +++ b/Kernel/Makefile @@ -105,6 +105,7 @@ CXXFLAGS += -nostdlib -nostdinc -nostdinc++ CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/ CXXFLAGS += -I../Toolchain/Local/i686-pc-serenity/include/c++/8.3.0/i686-pc-serenity/ DEFINES += -DKERNEL +DEFINES += -DEXPENSIVE_USERSPACE_STACKS LDFLAGS += -Ttext 0x10000 -Wl,-T linker.ld -nostdlib all: $(KERNEL) kernel.map diff --git a/Kernel/Process.cpp b/Kernel/Process.cpp index 3e65b7b0b3..34439560eb 100644 --- a/Kernel/Process.cpp +++ b/Kernel/Process.cpp @@ -350,6 +350,11 @@ int Process::do_exec(String path, Vector arguments, Vector envir bool success = region->page_in(); ASSERT(success); } + +#ifdef EXPENSIVE_USERSPACE_STACKS + region->page_in(); +#endif + OwnPtr loader; { // Okay, here comes the sleight of hand, pay close attention.. diff --git a/Kernel/Thread.cpp b/Kernel/Thread.cpp index 71194807c1..e2370135e0 100644 --- a/Kernel/Thread.cpp +++ b/Kernel/Thread.cpp @@ -1,3 +1,4 @@ +#include #include #include #include @@ -570,7 +571,12 @@ String Thread::backtrace(ProcessInspectionHandle&) const if (!symbol.address) break; if (!symbol.ksym) { - builder.appendf("%p\n", symbol.address); +#ifdef EXPENSIVE_USERSPACE_STACKS + if (!Scheduler::is_active() && process.elf_loader() && process.elf_loader()->has_symbols()) + builder.appendf("%p %s\n", symbol.address, process.elf_loader()->symbolicate(symbol.address).characters()); + else +#endif + builder.appendf("%p\n", symbol.address); continue; } unsigned offset = symbol.address - symbol.ksym->address;