Everywhere: Core dump => Coredump

We all know what a coredump is, and it feels more natural to refer to
it as a coredump (most code already does), so let's be consistent.
This commit is contained in:
Andreas Kling 2021-08-22 14:51:04 +02:00
parent a930877f31
commit bcd2025311
Notes: sideshowbarker 2024-07-18 05:22:42 +09:00
21 changed files with 73 additions and 72 deletions

View file

@ -48,7 +48,7 @@ set(KERNEL_SOURCES
CMOS.cpp
CommandLine.cpp
ConsoleDevice.cpp
CoreDump.cpp
Coredump.cpp
Devices/AsyncDeviceRequest.cpp
Devices/BlockDevice.cpp
Devices/CharacterDevice.cpp

View file

@ -9,7 +9,7 @@
#include <AK/ByteBuffer.h>
#include <AK/JsonObjectSerializer.h>
#include <Kernel/CoreDump.h>
#include <Kernel/Coredump.h>
#include <Kernel/FileSystem/Custody.h>
#include <Kernel/FileSystem/FileDescription.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
@ -19,41 +19,41 @@
#include <Kernel/Process.h>
#include <Kernel/RTC.h>
#include <LibC/elf.h>
#include <LibELF/CoreDump.h>
#include <LibELF/Core.h>
namespace Kernel {
OwnPtr<CoreDump> CoreDump::create(NonnullRefPtr<Process> process, const String& output_path)
OwnPtr<Coredump> Coredump::create(NonnullRefPtr<Process> process, const String& output_path)
{
if (!process->is_dumpable()) {
dbgln("Refusing to generate CoreDump for non-dumpable process {}", process->pid().value());
dbgln("Refusing to generate coredump for non-dumpable process {}", process->pid().value());
return {};
}
auto fd = create_target_file(process, output_path);
if (!fd)
return {};
return adopt_own_if_nonnull(new (nothrow) CoreDump(move(process), fd.release_nonnull()));
return adopt_own_if_nonnull(new (nothrow) Coredump(move(process), fd.release_nonnull()));
}
CoreDump::CoreDump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription>&& fd)
Coredump::Coredump(NonnullRefPtr<Process> process, NonnullRefPtr<FileDescription>&& fd)
: m_process(move(process))
, m_fd(move(fd))
, m_num_program_headers(m_process->address_space().region_count() + 1) // +1 for NOTE segment
{
}
RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, const String& output_path)
RefPtr<FileDescription> Coredump::create_target_file(const Process& process, const String& output_path)
{
auto output_directory = KLexicalPath::dirname(output_path);
auto dump_directory = VirtualFileSystem::the().open_directory(output_directory, VirtualFileSystem::the().root_custody());
if (dump_directory.is_error()) {
dbgln("Can't find directory '{}' for core dump", output_directory);
dbgln("Can't find directory '{}' for coredump", output_directory);
return nullptr;
}
auto dump_directory_metadata = dump_directory.value()->inode().metadata();
if (dump_directory_metadata.uid != 0 || dump_directory_metadata.gid != 0 || dump_directory_metadata.mode != 040777) {
dbgln("Refusing to put core dump in sketchy directory '{}'", output_directory);
dbgln("Refusing to put coredump in sketchy directory '{}'", output_directory);
return nullptr;
}
auto fd_or_error = VirtualFileSystem::the().open(
@ -64,14 +64,14 @@ RefPtr<FileDescription> CoreDump::create_target_file(const Process& process, con
UidAndGid { process.uid(), process.gid() });
if (fd_or_error.is_error()) {
dbgln("Failed to open core dump '{}' for writing", output_path);
dbgln("Failed to open coredump '{}' for writing", output_path);
return nullptr;
}
return fd_or_error.value();
}
KResult CoreDump::write_elf_header()
KResult Coredump::write_elf_header()
{
ElfW(Ehdr) elf_file_header;
elf_file_header.e_ident[EI_MAG0] = 0x7f;
@ -117,7 +117,7 @@ KResult CoreDump::write_elf_header()
return KSuccess;
}
KResult CoreDump::write_program_headers(size_t notes_size)
KResult Coredump::write_program_headers(size_t notes_size)
{
size_t offset = sizeof(ElfW(Ehdr)) + m_num_program_headers * sizeof(ElfW(Phdr));
for (auto& region : m_process->address_space().regions()) {
@ -159,7 +159,7 @@ KResult CoreDump::write_program_headers(size_t notes_size)
return KSuccess;
}
KResult CoreDump::write_regions()
KResult Coredump::write_regions()
{
for (auto& region : m_process->address_space().regions()) {
if (region->is_kernel())
@ -190,7 +190,7 @@ KResult CoreDump::write_regions()
return KSuccess;
}
KResult CoreDump::write_notes_segment(ByteBuffer& notes_segment)
KResult Coredump::write_notes_segment(ByteBuffer& notes_segment)
{
auto result = m_fd->write(UserOrKernelBuffer::for_kernel_buffer(notes_segment.data()), notes_segment.size());
if (result.is_error())
@ -198,7 +198,7 @@ KResult CoreDump::write_notes_segment(ByteBuffer& notes_segment)
return KSuccess;
}
ByteBuffer CoreDump::create_notes_process_data() const
ByteBuffer Coredump::create_notes_process_data() const
{
ByteBuffer process_data;
@ -232,7 +232,7 @@ ByteBuffer CoreDump::create_notes_process_data() const
return process_data;
}
ByteBuffer CoreDump::create_notes_threads_data() const
ByteBuffer Coredump::create_notes_threads_data() const
{
ByteBuffer threads_data;
@ -253,7 +253,7 @@ ByteBuffer CoreDump::create_notes_threads_data() const
return threads_data;
}
ByteBuffer CoreDump::create_notes_regions_data() const
ByteBuffer Coredump::create_notes_regions_data() const
{
ByteBuffer regions_data;
size_t region_index = 0;
@ -282,7 +282,7 @@ ByteBuffer CoreDump::create_notes_regions_data() const
return regions_data;
}
ByteBuffer CoreDump::create_notes_metadata_data() const
ByteBuffer Coredump::create_notes_metadata_data() const
{
ByteBuffer metadata_data;
@ -303,7 +303,7 @@ ByteBuffer CoreDump::create_notes_metadata_data() const
return metadata_data;
}
ByteBuffer CoreDump::create_notes_segment_data() const
ByteBuffer Coredump::create_notes_segment_data() const
{
ByteBuffer notes_buffer;
@ -319,7 +319,7 @@ ByteBuffer CoreDump::create_notes_segment_data() const
return notes_buffer;
}
KResult CoreDump::write()
KResult Coredump::write()
{
SpinlockLocker lock(m_process->address_space().get_lock());
ProcessPagingScope scope(m_process);

View file

@ -13,15 +13,15 @@
namespace Kernel {
class CoreDump {
class Coredump {
public:
static OwnPtr<CoreDump> create(NonnullRefPtr<Process>, const String& output_path);
static OwnPtr<Coredump> create(NonnullRefPtr<Process>, const String& output_path);
~CoreDump() = default;
~Coredump() = default;
[[nodiscard]] KResult write();
private:
CoreDump(NonnullRefPtr<Process>, NonnullRefPtr<FileDescription>&&);
Coredump(NonnullRefPtr<Process>, NonnullRefPtr<FileDescription>&&);
static RefPtr<FileDescription> create_target_file(const Process&, const String& output_path);
[[nodiscard]] KResult write_elf_header();

View file

@ -12,7 +12,7 @@ namespace Kernel {
class BlockDevice;
class CharacterDevice;
class CoreDump;
class Coredump;
class Custody;
class DevFSDeviceInode;
class DevFSDirectoryInode;

View file

@ -11,7 +11,7 @@
#include <AK/Types.h>
#include <Kernel/API/Syscall.h>
#include <Kernel/Arch/x86/InterruptDisabler.h>
#include <Kernel/CoreDump.h>
#include <Kernel/Coredump.h>
#include <Kernel/Debug.h>
#ifdef ENABLE_KERNEL_COVERAGE_COLLECTION
# include <Kernel/Devices/KCOVDevice.h>
@ -406,7 +406,7 @@ void Process::crash(int signal, FlatPtr ip, bool out_of_memory)
ProtectedDataMutationScope scope { *this };
m_protected_values.termination_signal = signal;
}
set_dump_core(!out_of_memory);
set_should_generate_coredump(!out_of_memory);
address_space().dump_regions();
VERIFY(is_user_process());
die();
@ -561,10 +561,10 @@ KResultOr<NonnullOwnPtr<KString>> Process::get_syscall_path_argument(Syscall::St
bool Process::dump_core()
{
VERIFY(is_dumpable());
VERIFY(should_core_dump());
VERIFY(should_generate_coredump());
dbgln("Generating coredump for pid: {}", pid().value());
auto coredump_path = String::formatted("/tmp/coredump/{}_{}_{}", name(), pid().value(), kgettimeofday().to_truncated_seconds());
auto coredump = CoreDump::create(*this, coredump_path);
auto coredump = Coredump::create(*this, coredump_path);
if (!coredump)
return false;
return !coredump->write().is_error();
@ -615,7 +615,7 @@ void Process::finalize()
dbgln_if(PROCESS_DEBUG, "Finalizing process {}", *this);
if (is_dumpable()) {
if (m_should_dump_core)
if (m_should_generate_coredump)
dump_core();
if (m_perf_event_buffer) {
dump_perfcore();

View file

@ -118,7 +118,7 @@ public:
MAKE_ALIGNED_ALLOCATED(Process, PAGE_SIZE);
friend class Thread;
friend class CoreDump;
friend class Coredump;
friend class ProcFSProcessFileDescriptions;
// Helper class to temporarily unprotect a process's protected data so you can write to it.
@ -190,8 +190,9 @@ public:
bool is_profiling() const { return m_profiling; }
void set_profiling(bool profiling) { m_profiling = profiling; }
bool should_core_dump() const { return m_should_dump_core; }
void set_dump_core(bool dump_core) { m_should_dump_core = dump_core; }
bool should_generate_coredump() const { return m_should_generate_coredump; }
void set_should_generate_coredump(bool b) { m_should_generate_coredump = b; }
bool is_dying() const { return m_state.load(AK::MemoryOrder::memory_order_acquire) != State::Running; }
bool is_dead() const { return m_state.load(AK::MemoryOrder::memory_order_acquire) == State::Dead; }
@ -498,7 +499,7 @@ public:
KResult set_coredump_property(NonnullOwnPtr<KString> key, NonnullOwnPtr<KString> value);
KResult try_set_coredump_property(StringView key, StringView value);
const NonnullRefPtrVector<Thread>& threads_for_coredump(Badge<CoreDump>) const { return m_threads_for_coredump; }
const NonnullRefPtrVector<Thread>& threads_for_coredump(Badge<Coredump>) const { return m_threads_for_coredump; }
PerformanceEventBuffer* perf_events() { return m_perf_event_buffer; }
@ -754,7 +755,7 @@ private:
Atomic<State> m_state { State::Running };
bool m_profiling { false };
Atomic<bool, AK::MemoryOrder::memory_order_relaxed> m_is_stopped { false };
bool m_should_dump_core { false };
bool m_should_generate_coredump { false };
RefPtr<Custody> m_executable;
RefPtr<Custody> m_cwd;

View file

@ -4,7 +4,7 @@
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <Kernel/CoreDump.h>
#include <Kernel/Coredump.h>
#include <Kernel/FileSystem/VirtualFileSystem.h>
#include <Kernel/PerformanceManager.h>
#include <Kernel/Process.h>

View file

@ -890,7 +890,7 @@ DispatchSignalResult Thread::dispatch_signal(u8 signal)
set_state(Stopped, signal);
return DispatchSignalResult::Yield;
case DefaultSignalAction::DumpCore:
process.set_dump_core(true);
process.set_should_generate_coredump(true);
process.for_each_thread([](auto& thread) {
thread.set_dump_backtrace_on_finalization();
});

View file

@ -13,4 +13,4 @@ set(SOURCES
)
serenity_app(CrashReporter ICON app-crash-reporter)
target_link_libraries(CrashReporter LibCore LibCoreDump LibDesktop LibGUI)
target_link_libraries(CrashReporter LibCore LibCoredump LibDesktop LibGUI)

View file

@ -11,11 +11,11 @@
#include <Applications/CrashReporter/CrashReporterWindowGML.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/File.h>
#include <LibCoreDump/Backtrace.h>
#include <LibCoreDump/Reader.h>
#include <LibCoredump/Backtrace.h>
#include <LibCoredump/Reader.h>
#include <LibDesktop/AppFile.h>
#include <LibDesktop/Launcher.h>
#include <LibELF/CoreDump.h>
#include <LibELF/Core.h>
#include <LibGUI/Application.h>
#include <LibGUI/BoxLayout.h>
#include <LibGUI/Button.h>
@ -36,9 +36,9 @@ struct TitleAndText {
String text;
};
static TitleAndText build_backtrace(const CoreDump::Reader& coredump, const ELF::Core::ThreadInfo& thread_info, size_t thread_index)
static TitleAndText build_backtrace(Coredump::Reader const& coredump, ELF::Core::ThreadInfo const& thread_info, size_t thread_index)
{
CoreDump::Backtrace backtrace(coredump, thread_info);
Coredump::Backtrace backtrace(coredump, thread_info);
auto metadata = coredump.metadata();
StringBuilder builder;
@ -129,7 +129,7 @@ int main(int argc, char** argv)
u8 termination_signal { 0 };
{
auto coredump = CoreDump::Reader::create(coredump_path);
auto coredump = Coredump::Reader::create(coredump_path);
if (!coredump) {
warnln("Could not open coredump '{}'", coredump_path);
return 1;

View file

@ -5,7 +5,7 @@ add_subdirectory(LibCards)
add_subdirectory(LibChess)
add_subdirectory(LibCompress)
add_subdirectory(LibCore)
add_subdirectory(LibCoreDump)
add_subdirectory(LibCoredump)
add_subdirectory(LibCpp)
add_subdirectory(LibCrypt)
add_subdirectory(LibCrypto)

View file

@ -1,7 +0,0 @@
set(SOURCES
Backtrace.cpp
Reader.cpp
)
serenity_lib(LibCoreDump coredump)
target_link_libraries(LibCoreDump LibC LibCompress LibCore LibDebug)

View file

@ -10,12 +10,12 @@
#include <AK/StringBuilder.h>
#include <AK/Types.h>
#include <LibCore/File.h>
#include <LibCoreDump/Backtrace.h>
#include <LibCoreDump/Reader.h>
#include <LibELF/CoreDump.h>
#include <LibCoredump/Backtrace.h>
#include <LibCoredump/Reader.h>
#include <LibELF/Core.h>
#include <LibELF/Image.h>
namespace CoreDump {
namespace Coredump {
ELFObjectInfo const* Backtrace::object_info_for_region(ELF::Core::MemoryRegionInfo const& region)
{

View file

@ -7,11 +7,11 @@
#pragma once
#include <AK/Types.h>
#include <LibCoreDump/Reader.h>
#include <LibCoredump/Reader.h>
#include <LibDebug/DebugInfo.h>
#include <LibELF/CoreDump.h>
#include <LibELF/Core.h>
namespace CoreDump {
namespace Coredump {
struct ELFObjectInfo {
ELFObjectInfo(NonnullRefPtr<MappedFile> file, NonnullOwnPtr<Debug::DebugInfo>&& debug_info, NonnullOwnPtr<ELF::Image> image)

View file

@ -0,0 +1,7 @@
set(SOURCES
Backtrace.cpp
Reader.cpp
)
serenity_lib(LibCoredump Coredump)
target_link_libraries(LibCoredump LibC LibCompress LibCore LibDebug)

View file

@ -6,7 +6,7 @@
#pragma once
namespace CoreDump {
namespace Coredump {
class Backtrace;
class Reader;

View file

@ -7,11 +7,11 @@
#include <AK/JsonObject.h>
#include <AK/JsonValue.h>
#include <LibCompress/Gzip.h>
#include <LibCoreDump/Reader.h>
#include <LibCoredump/Reader.h>
#include <signal_numbers.h>
#include <string.h>
namespace CoreDump {
namespace Coredump {
OwnPtr<Reader> Reader::create(const String& path)
{
@ -40,10 +40,10 @@ Reader::Reader(ReadonlyBytes coredump_bytes)
ByteBuffer Reader::decompress_coredump(const ReadonlyBytes& raw_coredump)
{
if (!Compress::GzipDecompressor::is_likely_compressed(raw_coredump))
return ByteBuffer::copy(raw_coredump); // handle old format core dumps (uncompressed)
return ByteBuffer::copy(raw_coredump); // handle old format coredumps (uncompressed)
auto decompressed_coredump = Compress::GzipDecompressor::decompress_all(raw_coredump);
if (!decompressed_coredump.has_value())
return ByteBuffer::copy(raw_coredump); // if we didn't manage to decompress it, try and parse it as decompressed core dump
return ByteBuffer::copy(raw_coredump); // if we didn't manage to decompress it, try and parse it as decompressed coredump
return decompressed_coredump.value();
}

View file

@ -10,10 +10,10 @@
#include <AK/MappedFile.h>
#include <AK/Noncopyable.h>
#include <AK/OwnPtr.h>
#include <LibELF/CoreDump.h>
#include <LibELF/Core.h>
#include <LibELF/Image.h>
namespace CoreDump {
namespace Coredump {
class Reader {
AK_MAKE_NONCOPYABLE(Reader);

View file

@ -9,4 +9,4 @@ set(SOURCES
)
serenity_bin(CrashDaemon)
target_link_libraries(CrashDaemon LibC LibCompress LibCore LibCoreDump)
target_link_libraries(CrashDaemon LibC LibCompress LibCore LibCoredump)

View file

@ -10,8 +10,8 @@
#include <LibCompress/Gzip.h>
#include <LibCore/File.h>
#include <LibCore/FileWatcher.h>
#include <LibCoreDump/Backtrace.h>
#include <LibCoreDump/Reader.h>
#include <LibCoredump/Backtrace.h>
#include <LibCoredump/Reader.h>
#include <serenity.h>
#include <spawn.h>
#include <sys/stat.h>
@ -62,7 +62,7 @@ static bool compress_coredump(const String& coredump_path)
static void print_backtrace(const String& coredump_path)
{
auto coredump = CoreDump::Reader::create(coredump_path);
auto coredump = Coredump::Reader::create(coredump_path);
if (!coredump) {
dbgln("Could not open coredump '{}'", coredump_path);
return;
@ -70,7 +70,7 @@ static void print_backtrace(const String& coredump_path)
size_t thread_index = 0;
coredump->for_each_thread_info([&](auto& thread_info) {
CoreDump::Backtrace backtrace(*coredump, thread_info);
Coredump::Backtrace backtrace(*coredump, thread_info);
if (thread_index > 0)
dbgln();
dbgln("--- Backtrace for thread #{} (TID {}) ---", thread_index, thread_info.tid);