diff --git a/Userland/functrace.cpp b/Userland/functrace.cpp index cdb37dbc56..877a7aa601 100644 --- a/Userland/functrace.cpp +++ b/Userland/functrace.cpp @@ -32,6 +32,7 @@ #include #include #include +#include #include #include #include @@ -69,6 +70,23 @@ void print_function_call(String function_name, size_t depth) printf("=> %s\n", function_name.characters()); } +void print_syscall(PtraceRegisters& regs, size_t depth) +{ + for (size_t i = 0; i < depth; ++i) { + printf(" "); + } + const char* begin_color = "\033[34;1m"; + const char* end_color = "\033[0m"; + printf("=> %sSC_%s(0x%x, 0x%x, 0x%x)%s\n", + begin_color, + Syscall::to_string( + (Syscall::Function)regs.eax), + regs.edx, + regs.ecx, + regs.ebx, + end_color); +} + NonnullOwnPtr> instrument_code() { (void)demangle("foo"); // Required for linked with __cxa_demangle @@ -134,18 +152,23 @@ int main(int argc, char** argv) return DebugSession::DebugDecision::Detach; } + if (reason == DebugSession::DebugBreakReason::Syscall) { + print_syscall(regs.value(), depth + 1); + return DebugSession::DebugDecision::ContinueBreakAtSyscall; + } + if (new_function) { auto function_name = g_debug_session->elf().symbolicate(regs.value().eip); print_function_call(function_name, depth); new_function = false; - return DebugSession::Continue; + return DebugSession::ContinueBreakAtSyscall; } auto instruction = instrumented->get((void*)regs.value().eip).value(); if (instruction.mnemonic() == "RET") { if (depth != 0) --depth; - return DebugSession::Continue; + return DebugSession::ContinueBreakAtSyscall; } // FIXME: we could miss some leaf functions that were called with a jump