1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 11:57:35 +00:00

bt: Enumerate all threads when symbolizing stacks in the bt utility.

Enumerate tid's from /proc/{pid}/stacks/ and use it to print the
backtrace for all active threads in the specified process.
This commit is contained in:
Brian Gianforcaro 2021-04-30 21:51:42 -07:00 committed by Linus Groh
parent f1c98dc5ea
commit ca213ab374

View file

@ -6,6 +6,7 @@
#include <AK/LexicalPath.h> #include <AK/LexicalPath.h>
#include <LibCore/ArgsParser.h> #include <LibCore/ArgsParser.h>
#include <LibCore/DirIterator.h>
#include <LibCore/EventLoop.h> #include <LibCore/EventLoop.h>
#include <LibCore/File.h> #include <LibCore/File.h>
#include <LibSymbolClient/Client.h> #include <LibSymbolClient/Client.h>
@ -54,8 +55,16 @@ int main(int argc, char** argv)
args_parser.parse(argc, argv); args_parser.parse(argc, argv);
Core::EventLoop loop; Core::EventLoop loop;
// FIXME: Support multiple threads in the same process! Core::DirIterator iterator(String::formatted("/proc/{}/stacks", pid), Core::DirIterator::SkipDots);
auto symbols = SymbolClient::symbolicate_thread(pid, pid); if (iterator.has_error()) {
warnln("Error: pid '{}' doesn't appear to exist.", pid);
return 1;
}
while (iterator.has_next()) {
pid_t tid = iterator.next_path().to_int().value();
outln("tid: {}", tid);
auto symbols = SymbolClient::symbolicate_thread(pid, tid);
for (auto& symbol : symbols) { for (auto& symbol : symbols) {
out("{:p} ", symbol.address); out("{:p} ", symbol.address);
if (!symbol.name.is_empty()) if (!symbol.name.is_empty())
@ -82,5 +91,7 @@ int main(int argc, char** argv)
} }
outln(""); outln("");
} }
outln("");
}
return 0; return 0;
} }