1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-16 19:35:08 +00:00

LibDebug: Fix crash when debugging short lived programs

This commit is contained in:
Sahan Fernando 2020-12-10 12:15:23 +11:00 committed by Andreas Kling
parent 1851da9c93
commit 66f9a2d9ec

View file

@ -64,6 +64,11 @@ OwnPtr<DebugSession> 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> 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.