From a5d89ca5dfa39312862928b542819f05fc40df91 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 4 Feb 2021 22:53:33 +0100 Subject: [PATCH] SymbolServer+bt: Symbolicate kernel addresses if /boot/Kernel available The /boot directory is only accessible to root by default, but anyone wanting access to kernel symbols for development can get them by making /boot/Kernel accessible to the "symbol" user. --- Userland/Services/SymbolServer/main.cpp | 8 ++++++++ Userland/Utilities/bt.cpp | 13 +++++++++++-- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/Userland/Services/SymbolServer/main.cpp b/Userland/Services/SymbolServer/main.cpp index 8d6e1a2f45..f975f3b37b 100644 --- a/Userland/Services/SymbolServer/main.cpp +++ b/Userland/Services/SymbolServer/main.cpp @@ -49,6 +49,14 @@ int main(int, char**) return 1; } + // NOTE: Developers can opt into kernel symbolication by making /boot/Kernel accessible to the "symbol" user. + if (access("/boot/Kernel", F_OK) == 0) { + if (unveil("/boot/Kernel", "r") < 0) { + perror("unveil"); + return 1; + } + } + if (unveil(nullptr, nullptr) < 0) { perror("unveil"); return 1; diff --git a/Userland/Utilities/bt.cpp b/Userland/Utilities/bt.cpp index ba0e906cff..55fbbd6921 100644 --- a/Userland/Utilities/bt.cpp +++ b/Userland/Utilities/bt.cpp @@ -70,11 +70,18 @@ int main(int argc, char** argv) FlatPtr base { 0 }; size_t size { 0 }; String path; + bool is_relative { true }; }; Vector stack; Vector regions; + regions.append(RegionWithSymbols { + .base = 0xc0000000, + .size = 0x3fffffff, + .path = "/boot/Kernel", + .is_relative = false }); + { // FIXME: Support multiple threads in the same process! auto stack_path = String::formatted("/proc/{}/stacks/{}", pid, pid); @@ -141,7 +148,6 @@ int main(int argc, char** argv) auto client = SymbolClient::Client::construct(); for (auto address : stack) { - const RegionWithSymbols* found_region = nullptr; for (auto& region : regions) { if (address >= region.base && address < (region.base + region.size)) { @@ -156,7 +162,10 @@ int main(int argc, char** argv) } Vector addresses; - addresses.append(address - found_region->base); + if (found_region->is_relative) + addresses.append(address - found_region->base); + else + addresses.append(address); auto symbols = client->symbolicate(found_region->path, addresses); if (symbols.is_empty()) {