From 54d28df97d85557042a5c215ad739a0341402926 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Thu, 4 Feb 2021 18:57:12 +0100 Subject: [PATCH] Kernel: Make /proc/PID/stacks/TID a JSON array The contents of these files are now raw JSON arrays. We no longer symbolicate the addresses. That's up to userspace from now on. --- Kernel/FileSystem/ProcFS.cpp | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Kernel/FileSystem/ProcFS.cpp b/Kernel/FileSystem/ProcFS.cpp index 485e299e8c..7646d5ce81 100644 --- a/Kernel/FileSystem/ProcFS.cpp +++ b/Kernel/FileSystem/ProcFS.cpp @@ -615,8 +615,16 @@ static bool procfs$tid_stack(InodeIdentifier identifier, KBufferBuilder& builder auto thread = Thread::from_tid(to_tid(identifier)); if (!thread) return false; - builder.appendf("Thread %d (%s):\n", thread->tid().value(), thread->name().characters()); - builder.append(thread->backtrace()); + + JsonArraySerializer array { builder }; + bool show_kernel_addresses = Process::current()->is_superuser(); + for (auto address : Processor::capture_stack_trace(*thread, 1024)) { + if (!show_kernel_addresses && !is_user_address(VirtualAddress { address })) + address = 0xdeadc0de; + array.add(JsonValue(address)); + } + + array.finish(); return true; }