Skip to content

[lldb][Process/FreeBSDKernelCore] Rework DoLoadCore()#186626

Open
mchoo7 wants to merge 1 commit intollvm:mainfrom
mchoo7:core
Open

[lldb][Process/FreeBSDKernelCore] Rework DoLoadCore()#186626
mchoo7 wants to merge 1 commit intollvm:mainfrom
mchoo7:core

Conversation

@mchoo7
Copy link
Contributor

@mchoo7 mchoo7 commented Mar 14, 2026

Currently ProcessFreeBSDKernelCore is initialized and loads core at the same time by invoking kvm_open2() only once. But to implement minidump2elf based variant which inherits from ProcessElfCore, detecting and loading core file should be handled separately. Thus separate initialization and core load although the outcome is the same.

Signed-off-by: Minsoo Choo <minsoochoo0122@proton.me>
@llvmbot llvmbot added the lldb label Mar 14, 2026
@mchoo7 mchoo7 requested review from aokblast, emaste and jrtc27 March 14, 2026 23:03
@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2026

@llvm/pr-subscribers-lldb

Author: Minsoo Choo (mchoo7)

Changes

Currently ProcessFreeBSDKernelCore is initialized and loads core at the same time by invoking kvm_open2() only once. But to implement minidump2elf based variant which inherits from ProcessElfCore, detecting and loading core file should be handled separately. Thus separate initialization and core load although the outcome is the same.


Full diff: https://github.com/llvm/llvm-project/pull/186626.diff

2 Files Affected:

  • (modified) lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp (+20-5)
  • (modified) lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h (+1-1)
diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
index d1a4a1ebc47d7..ad94c86e5499a 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
@@ -62,9 +62,8 @@ static PluginProperties &GetGlobalPluginProperties() {
 
 ProcessFreeBSDKernelCore::ProcessFreeBSDKernelCore(lldb::TargetSP target_sp,
                                                    ListenerSP listener_sp,
-                                                   kvm_t *kvm,
                                                    const FileSpec &core_file)
-    : PostMortemProcess(target_sp, listener_sp, core_file), m_kvm(kvm) {}
+    : PostMortemProcess(target_sp, listener_sp, core_file) {}
 
 ProcessFreeBSDKernelCore::~ProcessFreeBSDKernelCore() {
   if (m_kvm)
@@ -79,9 +78,11 @@ lldb::ProcessSP ProcessFreeBSDKernelCore::CreateInstance(
     kvm_t *kvm =
         kvm_open2(executable->GetFileSpec().GetPath().c_str(),
                   crash_file->GetPath().c_str(), O_RDONLY, nullptr, nullptr);
-    if (kvm)
+    if (kvm) {
+      kvm_close(kvm);
       return std::make_shared<ProcessFreeBSDKernelCore>(target_sp, listener_sp,
-                                                        kvm, *crash_file);
+                                                        *crash_file);
+    }
   }
   return nullptr;
 }
@@ -113,7 +114,21 @@ bool ProcessFreeBSDKernelCore::CanDebug(lldb::TargetSP target_sp,
 }
 
 Status ProcessFreeBSDKernelCore::DoLoadCore() {
-  // The core is already loaded by CreateInstance().
+  ModuleSP executable = GetTarget().GetExecutableModule();
+  if (!executable)
+    return Status::FromErrorString(
+        "ProcessFreeBSDKernelCore: no executable module set on target");
+
+  m_kvm = kvm_open2(executable->GetFileSpec().GetPath().c_str(),
+                    GetCoreFile().GetPath().c_str(), O_RDWR, nullptr, nullptr);
+
+  if (!m_kvm)
+    return Status::FromErrorStringWithFormat(
+        "ProcessFreeBSDKernelCore: kvm_open2 failed for core '%s' "
+        "with kernel '%s'",
+        GetCoreFile().GetPath().c_str(),
+        executable->GetFileSpec().GetPath().c_str());
+
   SetKernelDisplacement();
 
   return Status();
diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h
index d82e55ea74bd9..77cb747fc95c1 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.h
@@ -17,7 +17,7 @@
 class ProcessFreeBSDKernelCore : public lldb_private::PostMortemProcess {
 public:
   ProcessFreeBSDKernelCore(lldb::TargetSP target_sp, lldb::ListenerSP listener,
-                           kvm_t *kvm, const lldb_private::FileSpec &core_file);
+                           const lldb_private::FileSpec &core_file);
 
   ~ProcessFreeBSDKernelCore();
 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants