From 66f9a2d9ecb8d628d9db8f684839dba5a7e1434f Mon Sep 17 00:00:00 2001 From: Sahan Fernando Date: Thu, 10 Dec 2020 12:15:23 +1100 Subject: [PATCH] LibDebug: Fix crash when debugging short lived programs --- Libraries/LibDebug/DebugSession.cpp | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/Libraries/LibDebug/DebugSession.cpp b/Libraries/LibDebug/DebugSession.cpp index f6e82e140c..194ea09a9c 100644 --- a/Libraries/LibDebug/DebugSession.cpp +++ b/Libraries/LibDebug/DebugSession.cpp @@ -64,6 +64,11 @@ OwnPtr DebugSession::exec_and_attach(const String& command) { int pid = fork(); + if (pid < 0) { + perror("fork"); + exit(1); + } + if (!pid) { if (ptrace(PT_TRACE_ME, 0, 0, 0) < 0) { perror("PT_TRACE_ME"); @@ -93,16 +98,6 @@ OwnPtr DebugSession::exec_and_attach(const String& command) return nullptr; } - if (waitpid(pid, nullptr, WSTOPPED) != pid) { - perror("waitpid"); - return nullptr; - } - - if (ptrace(PT_CONTINUE, pid, 0, 0) < 0) { - perror("continue"); - return nullptr; - } - // We want to continue until the exit from the 'execve' sycsall. // This ensures that when we start debugging the process // it executes the target image, and not the forked image of the tracing process.