From 5dd555fe2fc407b035ea994474eb19bd633038bb Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 4 Feb 2021 23:18:25 +0100 Subject: [PATCH] SystemMonitor: Use SymbolServer to symbolicate thread stacks --- .../Applications/SystemMonitor/CMakeLists.txt | 2 +- .../SystemMonitor/ThreadStackWidget.cpp | 21 ++++++++++++------- Userland/Applications/SystemMonitor/main.cpp | 7 ++++++- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/Userland/Applications/SystemMonitor/CMakeLists.txt b/Userland/Applications/SystemMonitor/CMakeLists.txt index ee2e4d2323..1ee651f1be 100644 --- a/Userland/Applications/SystemMonitor/CMakeLists.txt +++ b/Userland/Applications/SystemMonitor/CMakeLists.txt @@ -13,4 +13,4 @@ set(SOURCES ) serenity_app(SystemMonitor ICON app-system-monitor) -target_link_libraries(SystemMonitor LibGUI LibPCIDB) +target_link_libraries(SystemMonitor LibGUI LibSymbolClient LibPCIDB) diff --git a/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp b/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp index 01e37791a0..d7aa93d589 100644 --- a/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp +++ b/Userland/Applications/SystemMonitor/ThreadStackWidget.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018-2020, Andreas Kling + * Copyright (c) 2018-2021, Andreas Kling * All rights reserved. * * Redistribution and use in source and binary forms, with or without @@ -29,6 +29,7 @@ #include #include #include +#include ThreadStackWidget::ThreadStackWidget() { @@ -55,14 +56,18 @@ void ThreadStackWidget::set_ids(pid_t pid, pid_t tid) void ThreadStackWidget::refresh() { - auto file = Core::File::construct(String::formatted("/proc/{}/stacks/{}", m_pid, m_tid)); - if (!file->open(Core::IODevice::ReadOnly)) { - m_stack_editor->set_text(String::formatted("Unable to open {}", file->filename())); - return; + auto symbols = SymbolClient::symbolicate_thread(m_pid, m_tid); + + StringBuilder builder; + + for (auto& symbol : symbols) { + builder.appendff("{:p}", symbol.address); + if (!symbol.name.is_empty()) + builder.appendff(" {}", symbol.name); + builder.append('\n'); } - auto new_text = file->read_all(); - if (m_stack_editor->text() != new_text) { - m_stack_editor->set_text(new_text); + if (m_stack_editor->text() != builder.string_view()) { + m_stack_editor->set_text(builder.string_view()); } } diff --git a/Userland/Applications/SystemMonitor/main.cpp b/Userland/Applications/SystemMonitor/main.cpp index a53823a7fb..c845b0c92b 100644 --- a/Userland/Applications/SystemMonitor/main.cpp +++ b/Userland/Applications/SystemMonitor/main.cpp @@ -112,7 +112,7 @@ int main(int argc, char** argv) auto app = GUI::Application::construct(argc, argv); - if (pledge("stdio proc recvfd sendfd accept rpath exec", nullptr) < 0) { + if (pledge("stdio proc recvfd sendfd accept rpath exec unix", nullptr) < 0) { perror("pledge"); return 1; } @@ -137,6 +137,11 @@ int main(int argc, char** argv) return 1; } + if (unveil("/tmp/portal/symbol", "rw") < 0) { + perror("unveil"); + return 1; + } + if (unveil("/bin", "r") < 0) { perror("unveil"); return 1;