[Lldb-commits] [lldb] [lldb][Process/FreeBSDKernelCore] Rework plugin destruction (PR #188426)

via lldb-commits lldb-commits at lists.llvm.org
Wed Mar 25 00:43:16 PDT 2026


llvmbot wrote:


<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-lldb

Author: Minsoo Choo (mchoo7)

<details>
<summary>Changes</summary>

Destroy the plugin classes similar to `ProcessElfCore`, another process plugin derived from `PostMortemProcess` class. After clearing thread list, invoke `Finalize()` to cleanup resources properly. `Finalize()` will call `DoDestroy()` which releases `m_kvm` via `kvm_close()`.

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


1 Files Affected:

- (modified) lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp (+14-3) 


``````````diff
diff --git a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
index da8e22caaa80f..1dbf35f660806 100644
--- a/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
+++ b/lldb/source/Plugins/Process/FreeBSD-Kernel-Core/ProcessFreeBSDKernelCore.cpp
@@ -67,8 +67,13 @@ ProcessFreeBSDKernelCore::ProcessFreeBSDKernelCore(lldb::TargetSP target_sp,
     : PostMortemProcess(target_sp, listener_sp, core_file), m_kvm(kvm) {}
 
 ProcessFreeBSDKernelCore::~ProcessFreeBSDKernelCore() {
-  if (m_kvm)
-    kvm_close(m_kvm);
+  m_thread_list.Clear();
+
+  // We need to call finalize on the process before destroying ourselves to
+  // make sure all of the broadcaster cleanup goes as planned. If we destruct
+  // this class, then Process::~Process() might have problems trying to fully
+  // destroy the broadcaster.
+  Finalize(true /* destructing */);
 }
 
 lldb::ProcessSP ProcessFreeBSDKernelCore::CreateInstance(
@@ -126,7 +131,13 @@ DynamicLoader *ProcessFreeBSDKernelCore::GetDynamicLoader() {
   return m_dyld_up.get();
 }
 
-Status ProcessFreeBSDKernelCore::DoDestroy() { return Status(); }
+Status ProcessFreeBSDKernelCore::DoDestroy() {
+  if (!m_kvm)
+    return Status::FromErrorString("kvm file descriptor is not set.");
+
+  kvm_close(m_kvm);
+  return Status();
+}
 
 void ProcessFreeBSDKernelCore::RefreshStateAfterStop() {
   if (!m_printed_unread_message) {

``````````

</details>


https://github.com/llvm/llvm-project/pull/188426


More information about the lldb-commits mailing list