[Lldb-commits] [lldb] [lldb] Enable locate module callback for main executable (PR #160199)

via lldb-commits lldb-commits at lists.llvm.org
Mon Sep 22 13:58:03 PDT 2025


https://github.com/GeorgeHuyubo created https://github.com/llvm/llvm-project/pull/160199

Main executables were bypassing the locate module callback that shared 
libraries use, preventing custom symbol file location logic from working 
consistently. 

Fixed by modifying Platform::ResolveExecutable() to call 
CallLocateModuleCallbackIfSet() first, then fallback to the standard 
ModuleList::GetSharedModule() path if needed.

This ensures both main executables and shared libraries get the same 
callback treatment for symbol file resolution.

>From 8d5907bbc71c0155bbaee7eba5d81197ac7ae251 Mon Sep 17 00:00:00 2001
From: George Hu <hyubo at meta.com>
Date: Mon, 22 Sep 2025 13:42:31 -0700
Subject: [PATCH] Call locate module callback for main executable

---
 lldb/source/Target/Platform.cpp | 25 ++++++++++++++++++++-----
 1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/lldb/source/Target/Platform.cpp b/lldb/source/Target/Platform.cpp
index 8681adaf5ea76..1b2ac3aa94aef 100644
--- a/lldb/source/Target/Platform.cpp
+++ b/lldb/source/Target/Platform.cpp
@@ -750,12 +750,27 @@ Platform::ResolveExecutable(const ModuleSpec &module_spec,
 
   if (resolved_module_spec.GetArchitecture().IsValid() ||
       resolved_module_spec.GetUUID().IsValid()) {
-    Status error =
-        ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
-                                    module_search_paths_ptr, nullptr, nullptr);
+    // Call locate module callback first to give it a chance to find/register
+    // symbol file specs for the main executable, similar to how shared libraries
+    // are handled in Platform::GetRemoteSharedModule()
+    FileSpec symbol_file_spec;
+    CallLocateModuleCallbackIfSet(resolved_module_spec, exe_module_sp,
+                                  symbol_file_spec, nullptr);
 
-    if (exe_module_sp && exe_module_sp->GetObjectFile())
-      return error;
+    Status error;
+    if (!exe_module_sp) {
+      // If locate module callback didn't provide a module, fallback to standard path
+      error = ModuleList::GetSharedModule(resolved_module_spec, exe_module_sp,
+                                          module_search_paths_ptr, nullptr, nullptr);
+    }
+
+    if (exe_module_sp && exe_module_sp->GetObjectFile()) {
+      // Set the symbol file if locate module callback returned one
+      if (symbol_file_spec) {
+        exe_module_sp->SetSymbolFileFileSpec(symbol_file_spec);
+      }
+      return error; // Return the actual status from GetSharedModule (or success from callback)
+    }
     exe_module_sp.reset();
   }
   // No valid architecture was specified or the exact arch wasn't found.



More information about the lldb-commits mailing list