From ed4f4290d7d3c4cd36120b5f5e828e89397c9b7c Mon Sep 17 00:00:00 2001 From: asou Date: Thu, 1 Aug 2024 01:43:08 +0000 Subject: [PATCH] Possible to read the core file of a process. --- .../Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp b/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp index 57724ca9efb..e6b0a3626f4 100644 --- a/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp +++ b/gnu/llvm/lldb/source/Plugins/Process/OpenBSDKernel/ProcessOpenBSDKernel.cpp @@ -19,6 +19,7 @@ #define _KERNEL #include #include +#include #undef _KERNEL #endif @@ -60,6 +61,14 @@ lldb::ProcessSP ProcessOpenBSDKernel::CreateInstance(lldb::TargetSP target_sp, ModuleSP executable = target_sp->GetExecutableModule(); if (crash_file && !can_connect && executable) { #if defined(__OpenBSD__) + char buf[4]; + FILE *fp = fopen(crash_file->GetPath().c_str(), "r"); + if (fp == NULL) + return nullptr; + size_t r = fread(buf, 1, sizeof(buf), fp); + fclose(fp); + if (r != sizeof(buf) || memcmp(buf, ELFMAG, sizeof(buf)) == 0) + return nullptr; kvm_t *kvm = kvm_open(executable->GetFileSpec().GetPath().c_str(), crash_file->GetPath().c_str(), nullptr, O_RDONLY, nullptr); -- 2.20.1