mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 05:07:45 +00:00
functrace: Log syscalls
This commit is contained in:
parent
af338a34c0
commit
ef6dc61291
1 changed files with 25 additions and 2 deletions
|
@ -32,6 +32,7 @@
|
||||||
#include <AK/NonnullOwnPtr.h>
|
#include <AK/NonnullOwnPtr.h>
|
||||||
#include <AK/StringBuilder.h>
|
#include <AK/StringBuilder.h>
|
||||||
#include <AK/kmalloc.h>
|
#include <AK/kmalloc.h>
|
||||||
|
#include <Kernel/Syscall.h>
|
||||||
#include <LibC/sys/arch/i386/regs.h>
|
#include <LibC/sys/arch/i386/regs.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibDebug/DebugSession.h>
|
#include <LibDebug/DebugSession.h>
|
||||||
|
@ -69,6 +70,23 @@ void print_function_call(String function_name, size_t depth)
|
||||||
printf("=> %s\n", function_name.characters());
|
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<HashMap<void*, X86::Instruction>> instrument_code()
|
NonnullOwnPtr<HashMap<void*, X86::Instruction>> instrument_code()
|
||||||
{
|
{
|
||||||
(void)demangle("foo"); // Required for linked with __cxa_demangle
|
(void)demangle("foo"); // Required for linked with __cxa_demangle
|
||||||
|
@ -134,18 +152,23 @@ int main(int argc, char** argv)
|
||||||
return DebugSession::DebugDecision::Detach;
|
return DebugSession::DebugDecision::Detach;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (reason == DebugSession::DebugBreakReason::Syscall) {
|
||||||
|
print_syscall(regs.value(), depth + 1);
|
||||||
|
return DebugSession::DebugDecision::ContinueBreakAtSyscall;
|
||||||
|
}
|
||||||
|
|
||||||
if (new_function) {
|
if (new_function) {
|
||||||
auto function_name = g_debug_session->elf().symbolicate(regs.value().eip);
|
auto function_name = g_debug_session->elf().symbolicate(regs.value().eip);
|
||||||
print_function_call(function_name, depth);
|
print_function_call(function_name, depth);
|
||||||
new_function = false;
|
new_function = false;
|
||||||
return DebugSession::Continue;
|
return DebugSession::ContinueBreakAtSyscall;
|
||||||
}
|
}
|
||||||
auto instruction = instrumented->get((void*)regs.value().eip).value();
|
auto instruction = instrumented->get((void*)regs.value().eip).value();
|
||||||
|
|
||||||
if (instruction.mnemonic() == "RET") {
|
if (instruction.mnemonic() == "RET") {
|
||||||
if (depth != 0)
|
if (depth != 0)
|
||||||
--depth;
|
--depth;
|
||||||
return DebugSession::Continue;
|
return DebugSession::ContinueBreakAtSyscall;
|
||||||
}
|
}
|
||||||
|
|
||||||
// FIXME: we could miss some leaf functions that were called with a jump
|
// FIXME: we could miss some leaf functions that were called with a jump
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue