From 5c68929aa1724867eec6b65c0ae50dc8a8d4c589 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Mon, 22 Apr 2019 18:44:45 +0200 Subject: Kernel: Add a systrace() syscall and implement /bin/strace using it. Calling systrace(pid) gives you a file descriptor with a stream of the syscalls made by a peer process. The process must be owned by the same UID who calls systrace(). :^) --- Userland/strace.cpp | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Userland/strace.cpp (limited to 'Userland/strace.cpp') diff --git a/Userland/strace.cpp b/Userland/strace.cpp new file mode 100644 index 0000000000..374ac1cf80 --- /dev/null +++ b/Userland/strace.cpp @@ -0,0 +1,40 @@ +#include +#include +#include +#include +#include +#include + +int main(int argc, char** argv) +{ + if (argc < 2) + return 1; + + int pid = atoi(argv[1]); + int fd = systrace(pid); + if (fd < 0) { + perror("systrace"); + return 1; + } + + for (;;) { + dword call[5]; + int nread = read(fd, &call, sizeof(call)); + if (nread == 0) + break; + if (nread < 0) { + perror("read"); + return 1; + } + ASSERT(nread == sizeof(call)); + printf("%s(%#x, %#x, %#x) = %#x\n", Syscall::to_string((Syscall::Function)call[0]), call[1], call[2], call[3], call[4]); + } + + int rc = close(fd); + if (rc < 0) { + perror("close"); + return 1; + } + + return 0; +} -- cgit v1.2.3