https://github.com/JDevlieghere updated 
https://github.com/llvm/llvm-project/pull/214633

>From 6859eb11d87524c9959a5bcd905cc4e506c4da75 Mon Sep 17 00:00:00 2001
From: Jonas Devlieghere <[email protected]>
Date: Thu, 6 Aug 2026 21:39:24 -0700
Subject: [PATCH] [lldb] Take the kernel dSYM search paths as a parameter

PlatformDarwinKernel::GetSharedModuleKernel unconditionally dereferenced
the process to get the search paths. Obtain the paths from the target
and pass that instead.
---
 .../Platform/MacOSX/PlatformDarwinKernel.cpp  | 14 +++++---
 .../Platform/MacOSX/PlatformDarwinKernel.h    | 11 +++---
 .../test/API/macosx/load-kext/TestLoadKext.py | 35 +++++++++++++++++++
 3 files changed, 50 insertions(+), 10 deletions(-)

diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
index 22fbfcb817570..f4603e0d8ec64 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.cpp
@@ -731,8 +731,13 @@ Status PlatformDarwinKernel::GetSharedModule(
     // DynamicLoaderDarwinKernel uses the magic name mach_kernel,
     // UUID search can get here with no name - and it may be a kernel.
     if (kext_bundle_id == "mach_kernel" || kext_bundle_id.empty()) {
-      error = GetSharedModuleKernel(module_spec, process, module_sp,
-                                    old_modules, did_create_ptr);
+      // A kernel's dSYM is searched for with the target's paths when there is 
a
+      // target to take them from, and the global defaults otherwise.
+      FileSpecList search_paths = Target::GetDefaultDebugFileSearchPaths();
+      if (TargetSP target_sp = module_spec.GetTargetSP())
+        search_paths = target_sp->GetDebugFileSearchPaths();
+      error = GetSharedModuleKernel(module_spec, process, search_paths,
+                                    module_sp, old_modules, did_create_ptr);
       if (error.Success() && module_sp) {
         return error;
       }
@@ -786,7 +791,8 @@ Status PlatformDarwinKernel::GetSharedModuleKext(
 }
 
 Status PlatformDarwinKernel::GetSharedModuleKernel(
-    const ModuleSpec &module_spec, Process *process, ModuleSP &module_sp,
+    const ModuleSpec &module_spec, Process *process,
+    const FileSpecList &search_paths, ModuleSP &module_sp,
     llvm::SmallVectorImpl<ModuleSP> *old_modules, bool *did_create_ptr) {
   assert(module_sp.get() == nullptr);
   UpdateKextandKernelsLocalScan();
@@ -805,8 +811,6 @@ Status PlatformDarwinKernel::GetSharedModuleKernel(
         // way it ends up in the index), but it might be a
         // .dSYM.yaa that needs to be expanded, don't just
         // append ".dSYM" to the filename for the SymbolFile.
-        FileSpecList search_paths =
-            process->GetTarget().GetDebugFileSearchPaths();
         FileSpec dsym_fspec = PluginManager::LocateExecutableSymbolFile(
             kern_spec, search_paths, module_sp->GetSymbolLocatorStatistics());
         if (FileSystem::Instance().Exists(dsym_fspec))
diff --git a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h 
b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
index b5cf701a76b4d..e265e72382d21 100644
--- a/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
+++ b/lldb/source/Plugins/Platform/MacOSX/PlatformDarwinKernel.h
@@ -144,11 +144,12 @@ class PlatformDarwinKernel : public PlatformDarwin {
                              llvm::SmallVectorImpl<lldb::ModuleSP> 
*old_modules,
                              bool *did_create_ptr);
 
-  Status
-  GetSharedModuleKernel(const ModuleSpec &module_spec, Process *process,
-                        lldb::ModuleSP &module_sp,
-                        llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules,
-                        bool *did_create_ptr);
+  /// \param search_paths Where to look for a kernel's dSYM. The caller 
supplies
+  ///   these because there is not always a process to take them from.
+  Status GetSharedModuleKernel(
+      const ModuleSpec &module_spec, Process *process,
+      const FileSpecList &search_paths, lldb::ModuleSP &module_sp,
+      llvm::SmallVectorImpl<lldb::ModuleSP> *old_modules, bool 
*did_create_ptr);
 
   Status ExamineKextForMatchingUUID(const FileSpec &kext_bundle_path,
                                     const UUID &uuid, const ArchSpec &arch,
diff --git a/lldb/test/API/macosx/load-kext/TestLoadKext.py 
b/lldb/test/API/macosx/load-kext/TestLoadKext.py
index fa4387d18e5cb..841865b9fee1b 100644
--- a/lldb/test/API/macosx/load-kext/TestLoadKext.py
+++ b/lldb/test/API/macosx/load-kext/TestLoadKext.py
@@ -25,3 +25,38 @@ def test_load_kext(self):
         self.assertEqual(target.GetNumModules(), 1)
         mod = target.GetModuleAtIndex(0)
         self.assertEqual(mod.GetFileSpec().GetFilename(), "mykext")
+
+    @skipUnlessDarwin
+    def test_kernel_lookup_by_uuid_without_a_process(self):
+        """Search the darwin-kernel platform for a kernel before there is a
+        process to search on behalf of."""
+
+        import os
+
+        # PlatformDarwinKernel only indexes a kernel binary that has a .dSYM
+        # sibling, and only that branch goes looking for a symbol file.
+        kernel_dir = self.getBuildArtifact("kernels")
+        lldbutil.mkdir_p(kernel_dir)
+        kernel = os.path.join(kernel_dir, "kernel.test")
+        self.yaml2obj("mykext.yaml", kernel)
+        lldbutil.mkdir_p(kernel + ".dSYM")
+
+        self.runCmd(
+            "settings set platform.plugin.darwin-kernel.kext-directories " + 
kernel_dir
+        )
+        self.runCmd("platform select darwin-kernel")
+
+        def cleanup():
+            self.runCmd("platform select host")
+            self.runCmd("settings clear 
platform.plugin.darwin-kernel.kext-directories")
+
+        self.addTearDownHook(cleanup)
+
+        target = self.dbg.CreateTarget("")
+        self.assertTrue(target.IsValid())
+
+        # A UUID with no file name reaches the kernel branch of
+        # PlatformDarwinKernel::GetSharedModule, which matches the binary above
+        # and then searches for its symbols. There is no process here, and the
+        # search must not need one.
+        target.AddModule(None, None, "17A97B33-09B7-3195-9408-DBD965D578A5")

_______________________________________________
lldb-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to