1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-20 13:35:07 +00:00

Kernel: Generate a coredump file when a process crashes

When a process crashes, we generate a coredump file and write it in
/tmp/coredumps/.

The coredump file is an ELF file of type ET_CORE.
It contains a segment for every userspace memory region of the process,
and an additional PT_NOTE segment that contains the registers state for
each thread, and a additional data about memory regions
(e.g their name).
This commit is contained in:
Itamar 2020-11-06 10:09:51 +02:00 committed by Andreas Kling
parent efe4da57df
commit b4842d33bb
11 changed files with 427 additions and 1 deletions

View file

@ -32,6 +32,7 @@
#include <AK/Types.h>
#include <Kernel/API/Syscall.h>
#include <Kernel/Arch/i386/CPU.h>
#include <Kernel/CoreDump.h>
#include <Kernel/Devices/NullDevice.h>
#include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h>
@ -42,6 +43,7 @@
#include <Kernel/Module.h>
#include <Kernel/PerformanceEventBuffer.h>
#include <Kernel/Process.h>
#include <Kernel/RTC.h>
#include <Kernel/SharedBuffer.h>
#include <Kernel/StdLib.h>
#include <Kernel/TTY/TTY.h>
@ -468,6 +470,7 @@ void Process::crash(int signal, u32 eip, bool out_of_memory)
dump_backtrace();
}
m_termination_signal = signal;
set_dump_core(true);
dump_regions();
ASSERT(is_user_process());
die();
@ -584,6 +587,15 @@ void Process::finalize()
dbg() << "Finalizing process " << *this;
#endif
if (m_should_dump_core) {
dbgln("Generating coredump for pid: {}", m_pid.value());
auto coredump = CoreDump::create(*this);
if (!coredump) {
dbgln("Could not create coredump");
}
coredump->write();
}
if (m_perf_event_buffer) {
auto description_or_error = VFS::the().open(String::format("perfcore.%d", m_pid), O_CREAT | O_EXCL, 0400, current_directory(), UidAndGid { m_uid, m_gid });
if (!description_or_error.is_error()) {