From 529a8664f44a092ac2230ccbfa39032222c8a03d Mon Sep 17 00:00:00 2001 From: Brian Gianforcaro Date: Sat, 22 May 2021 17:11:39 -0700 Subject: [PATCH] Userland: Tweak the visual display of the `bt` utility This patch adds a few minor visual features to the `bt` utility: - Number each frame of the back trace. - Color the address based on if it's in kernel or user space. - Add a "frames:" heading to visually seperate the thread id. - Rename "tid: " -> "thread: " as it's more visually appealing since it aligns vertically with "frames:" - Add a visual " | " seperate between the address and symbol name. --- Userland/Utilities/bt.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Userland/Utilities/bt.cpp b/Userland/Utilities/bt.cpp index 957e407197..993d79d7e0 100644 --- a/Userland/Utilities/bt.cpp +++ b/Userland/Utilities/bt.cpp @@ -37,10 +37,14 @@ int main(int argc, char** argv) while (iterator.has_next()) { pid_t tid = iterator.next_path().to_int().value(); - outln("tid: {}", tid); + outln("thread: {}", tid); + outln("frames:"); auto symbols = Symbolication::symbolicate_thread(pid, tid); + auto frame_number = symbols.size() - 1; for (auto& symbol : symbols) { - out("{:p} ", symbol.address); + // Make kernel stack frames stand out. + int color = symbol.address < 0xc0000000 ? 35 : 31; + out("{:3}: \033[{};1m{:p}\033[0m | ", frame_number, color, symbol.address); if (!symbol.name.is_empty()) out("{} ", symbol.name); if (!symbol.filename.is_empty()) { @@ -64,6 +68,7 @@ int main(int argc, char** argv) out(")"); } outln(""); + frame_number--; } outln(""); }