summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Userland/DevTools/HackStudio/CMakeLists.txt2
-rw-r--r--Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp10
-rw-r--r--Userland/DevTools/Profiler/CMakeLists.txt2
-rw-r--r--Userland/DevTools/Profiler/DisassemblyModel.cpp10
-rw-r--r--Userland/DevTools/Profiler/Profile.cpp12
-rw-r--r--Userland/DevTools/Profiler/ProfileModel.cpp10
-rw-r--r--Userland/Libraries/LibSymbolication/Symbolication.cpp54
-rw-r--r--Userland/Libraries/LibSymbolication/Symbolication.h1
-rw-r--r--Userland/Utilities/bt.cpp10
9 files changed, 63 insertions, 48 deletions
diff --git a/Userland/DevTools/HackStudio/CMakeLists.txt b/Userland/DevTools/HackStudio/CMakeLists.txt
index a4e8040c19..062f37c36b 100644
--- a/Userland/DevTools/HackStudio/CMakeLists.txt
+++ b/Userland/DevTools/HackStudio/CMakeLists.txt
@@ -49,5 +49,5 @@ set(SOURCES
)
serenity_app(HackStudio ICON app-hack-studio)
-target_link_libraries(HackStudio LibWeb LibMarkdown LibGUI LibCpp LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell LibRegex)
+target_link_libraries(HackStudio LibWeb LibMarkdown LibGUI LibCpp LibGfx LibCore LibVT LibDebug LibX86 LibDiff LibShell LibSymbolication LibRegex)
add_dependencies(HackStudio CppLanguageServer)
diff --git a/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp b/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp
index da6ae10f78..d69b3664e9 100644
--- a/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp
+++ b/Userland/DevTools/HackStudio/Debugger/DisassemblyModel.cpp
@@ -9,6 +9,7 @@
#include <AK/StringBuilder.h>
#include <LibDebug/DebugSession.h>
#include <LibELF/Image.h>
+#include <LibSymbolication/Symbolication.h>
#include <LibX86/Disassembler.h>
#include <LibX86/ELFSymbolProvider.h>
#include <ctype.h>
@@ -30,14 +31,9 @@ DisassemblyModel::DisassemblyModel(const Debug::DebugSession& debug_session, con
OwnPtr<ELF::Image> kernel_elf;
const ELF::Image* elf = nullptr;
- // FIXME: Use /proc for this
-#if ARCH(I386)
- FlatPtr kernel_base = 0xc0000000;
-#else
- FlatPtr kernel_base = 0x2000000000;
-#endif
+ auto maybe_kernel_base = Symbolication::kernel_base();
- if (containing_function.value().address_low >= kernel_base) {
+ if (maybe_kernel_base.has_value() && containing_function.value().address_low >= maybe_kernel_base.value()) {
auto file_or_error = MappedFile::map("/boot/Kernel.debug");
if (file_or_error.is_error())
return;
diff --git a/Userland/DevTools/Profiler/CMakeLists.txt b/Userland/DevTools/Profiler/CMakeLists.txt
index 3b17cc360d..f08eebaa15 100644
--- a/Userland/DevTools/Profiler/CMakeLists.txt
+++ b/Userland/DevTools/Profiler/CMakeLists.txt
@@ -19,4 +19,4 @@ set(SOURCES
)
serenity_app(Profiler ICON app-profiler)
-target_link_libraries(Profiler LibGUI LibDesktop LibX86)
+target_link_libraries(Profiler LibGUI LibDesktop LibX86 LibSymbolication)
diff --git a/Userland/DevTools/Profiler/DisassemblyModel.cpp b/Userland/DevTools/Profiler/DisassemblyModel.cpp
index fdbdf1656a..f52241bb34 100644
--- a/Userland/DevTools/Profiler/DisassemblyModel.cpp
+++ b/Userland/DevTools/Profiler/DisassemblyModel.cpp
@@ -9,6 +9,7 @@
#include <AK/MappedFile.h>
#include <LibELF/Image.h>
#include <LibGUI/Painter.h>
+#include <LibSymbolication/Symbolication.h>
#include <LibX86/Disassembler.h>
#include <LibX86/ELFSymbolProvider.h>
#include <ctype.h>
@@ -40,13 +41,8 @@ DisassemblyModel::DisassemblyModel(Profile& profile, ProfileNode& node)
OwnPtr<ELF::Image> kernel_elf;
const ELF::Image* elf;
FlatPtr base_address = 0;
- // FIXME: Use /proc for this
-#if ARCH(I386)
- FlatPtr kernel_base = 0xc0000000;
-#else
- FlatPtr kernel_base = 0x2000000000;
-#endif
- if (m_node.address() >= kernel_base) {
+ auto maybe_kernel_base = Symbolication::kernel_base();
+ if (maybe_kernel_base.has_value() && m_node.address() >= maybe_kernel_base.value()) {
if (!m_kernel_file) {
auto file_or_error = MappedFile::map("/boot/Kernel.debug");
if (file_or_error.is_error())
diff --git a/Userland/DevTools/Profiler/Profile.cpp b/Userland/DevTools/Profiler/Profile.cpp
index 9bcb63a020..f4a7f630f4 100644
--- a/Userland/DevTools/Profiler/Profile.cpp
+++ b/Userland/DevTools/Profiler/Profile.cpp
@@ -16,6 +16,7 @@
#include <AK/RefPtr.h>
#include <LibCore/File.h>
#include <LibELF/Image.h>
+#include <LibSymbolication/Symbolication.h>
#include <sys/stat.h>
namespace Profiler {
@@ -301,12 +302,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
continue;
}
- // FIXME: Use /proc for this
-#if ARCH(I386)
- FlatPtr kernel_base = 0xc0000000;
-#else
- FlatPtr kernel_base = 0x2000000000;
-#endif
+ auto maybe_kernel_base = Symbolication::kernel_base();
auto* stack = perf_event.get_ptr("stack");
VERIFY(stack);
@@ -318,7 +314,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
FlyString object_name;
String symbol;
- if (ptr >= kernel_base) {
+ if (maybe_kernel_base.has_value() && ptr >= maybe_kernel_base.value()) {
if (kernel_elf) {
symbol = kernel_elf->symbolicate(ptr, &offset);
} else {
@@ -345,7 +341,7 @@ Result<NonnullOwnPtr<Profile>, String> Profile::load_from_perfcore_file(const St
continue;
FlatPtr innermost_frame_address = event.frames.at(1).address;
- event.in_kernel = innermost_frame_address >= kernel_base;
+ event.in_kernel = maybe_kernel_base.has_value() && innermost_frame_address >= maybe_kernel_base.value();
events.append(move(event));
}
diff --git a/Userland/DevTools/Profiler/ProfileModel.cpp b/Userland/DevTools/Profiler/ProfileModel.cpp
index eb0d311d75..fdb8c1dd9b 100644
--- a/Userland/DevTools/Profiler/ProfileModel.cpp
+++ b/Userland/DevTools/Profiler/ProfileModel.cpp
@@ -8,6 +8,7 @@
#include "Profile.h"
#include <AK/StringBuilder.h>
#include <LibGUI/FileIconProvider.h>
+#include <LibSymbolication/Symbolication.h>
#include <ctype.h>
#include <stdio.h>
@@ -105,13 +106,8 @@ GUI::Variant ProfileModel::data(const GUI::ModelIndex& index, GUI::ModelRole rol
if (node->is_root()) {
return GUI::FileIconProvider::icon_for_executable(node->process().executable);
}
- // FIXME: Use /proc for this
-#if ARCH(I386)
- FlatPtr kernel_base = 0xc0000000;
-#else
- FlatPtr kernel_base = 0x2000000000;
-#endif
- if (node->address() >= kernel_base)
+ auto maybe_kernel_base = Symbolication::kernel_base();
+ if (maybe_kernel_base.has_value() && node->address() >= maybe_kernel_base.value())
return m_kernel_frame_icon;
return m_user_frame_icon;
}
diff --git a/Userland/Libraries/LibSymbolication/Symbolication.cpp b/Userland/Libraries/LibSymbolication/Symbolication.cpp
index 40983c1988..4199790ecc 100644
--- a/Userland/Libraries/LibSymbolication/Symbolication.cpp
+++ b/Userland/Libraries/LibSymbolication/Symbolication.cpp
@@ -21,6 +21,42 @@ struct CachedELF {
static HashMap<String, OwnPtr<CachedELF>> s_cache;
+enum class KernelBaseState {
+ Uninitialized,
+ Valid,
+ Invalid,
+};
+
+static FlatPtr s_kernel_base;
+static KernelBaseState s_kernel_base_state = KernelBaseState::Uninitialized;
+
+Optional<FlatPtr> kernel_base()
+{
+ if (s_kernel_base_state == KernelBaseState::Uninitialized) {
+ auto file = Core::File::open("/proc/kernel_base", Core::OpenMode::ReadOnly);
+ if (file.is_error()) {
+ s_kernel_base_state = KernelBaseState::Invalid;
+ return {};
+ }
+ auto kernel_base_str = String { file.value()->read_all(), NoChomp };
+#if ARCH(I386)
+ using AddressType = u32;
+#else
+ using AddressType = u64;
+#endif
+ auto maybe_kernel_base = kernel_base_str.to_uint<AddressType>();
+ if (!maybe_kernel_base.has_value()) {
+ s_kernel_base_state = KernelBaseState::Invalid;
+ return {};
+ }
+ s_kernel_base = maybe_kernel_base.value();
+ s_kernel_base_state = KernelBaseState::Valid;
+ }
+ if (s_kernel_base_state == KernelBaseState::Invalid)
+ return {};
+ return s_kernel_base;
+}
+
Optional<Symbol> symbolicate(String const& path, FlatPtr address)
{
if (!s_cache.contains(path)) {
@@ -81,16 +117,14 @@ Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid)
Vector<FlatPtr> stack;
Vector<RegionWithSymbols> regions;
- regions.append(RegionWithSymbols {
- // FIXME: Use /proc for this
-#if ARCH(I386)
- .base = 0xc0000000,
-#else
- .base = 0x2000000000,
-#endif
- .size = 0x3fffffff,
- .path = "/boot/Kernel.debug",
- .is_relative = false });
+ if (auto maybe_kernel_base = kernel_base(); maybe_kernel_base.has_value()) {
+ regions.append(RegionWithSymbols {
+ .base = maybe_kernel_base.value(),
+ .size = 0x3fffffff,
+ .path = "/boot/Kernel.debug",
+ .is_relative = false,
+ });
+ }
{
auto stack_path = String::formatted("/proc/{}/stacks/{}", pid, tid);
diff --git a/Userland/Libraries/LibSymbolication/Symbolication.h b/Userland/Libraries/LibSymbolication/Symbolication.h
index 346dedd3a2..a5a128ecad 100644
--- a/Userland/Libraries/LibSymbolication/Symbolication.h
+++ b/Userland/Libraries/LibSymbolication/Symbolication.h
@@ -18,6 +18,7 @@ struct Symbol {
Vector<Debug::DebugInfo::SourcePosition> source_positions;
};
+Optional<FlatPtr> kernel_base();
Vector<Symbol> symbolicate_thread(pid_t pid, pid_t tid);
Optional<Symbol> symbolicate(String const& path, FlatPtr address);
diff --git a/Userland/Utilities/bt.cpp b/Userland/Utilities/bt.cpp
index 1963547f7c..b598343c95 100644
--- a/Userland/Utilities/bt.cpp
+++ b/Userland/Utilities/bt.cpp
@@ -9,6 +9,7 @@
#include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h>
#include <LibCore/EventLoop.h>
+#include <LibCore/File.h>
#include <LibSymbolication/Symbolication.h>
#include <unistd.h>
@@ -44,13 +45,8 @@ int main(int argc, char** argv)
auto frame_number = symbols.size() - 1;
for (auto& symbol : symbols) {
// Make kernel stack frames stand out.
- // FIXME: Use /proc for this
-#if ARCH(I386)
- FlatPtr kernel_base = 0xc0000000;
-#else
- FlatPtr kernel_base = 0x2000000000;
-#endif
- int color = symbol.address < kernel_base ? 35 : 31;
+ auto maybe_kernel_base = Symbolication::kernel_base();
+ int color = maybe_kernel_base.has_value() && symbol.address < maybe_kernel_base.value() ? 35 : 31;
out("{:3}: \033[{};1m{:p}\033[0m | ", frame_number, color, symbol.address);
if (!symbol.name.is_empty())
out("{} ", symbol.name);