================
@@ -377,18 +376,45 @@ bool 
ProcessElfCore::GetMainExecutableModuleSpec(ModuleSpec &exe_spec) {
   if (!exe_spec.GetFileSpec() && !m_executable_name.empty())
     exe_spec.GetFileSpec() = CreateFileSpecFromPath(m_executable_name);
 
+  // Try and find the UUID after the module spec was filled in.
+  FindModuleUUID(exe_spec);
+
   // We succeeded if we got a path.
   return (bool)exe_spec.GetFileSpec();
 }
 
-UUID ProcessElfCore::FindModuleUUID(const llvm::StringRef path) {
-  // Lookup the UUID for the given path in the map.
-  // Note that this could be called by multiple threads so make sure
-  // we access the map in a thread safe way (i.e. don't use operator[]).
-  auto it = m_uuids.find(std::string(path));
-  if (it != m_uuids.end())
-    return it->second;
-  return UUID();
+bool ProcessElfCore::FindModuleUUID(ModuleSpec &spec) {
+  if (!spec.GetUUID().IsValid()) {
+    // Lookup the UUID for the given path in the map.
+    // Note that this could be called by multiple threads so make sure
+    // we access the map in a thread safe way (i.e. don't use operator[]).
+    std::string path;
+    // Sometimes the path to a file or shared library from the dynamic loader,
+    // one of the main clients of this function, is a symlink. The information
+    // in the NT_FILE note contains resolved paths and might not match. The
+    // best way for us to find a module is by load address, so use this trick
+    // if the load address is set in the module specification.
+    if (std::optional<lldb::addr_t> load_addr = spec.GetLoadAddress()) {
+      if (std::optional<NT_FILE_Entry> nt = 
+              GetNTFileEntryContainingAddress(*load_addr))
+        path = nt->path;
+    }
+    // If we didn't find a file spec from the load address, fall back to using
+    // the file spec.
+    if (path.empty())
+      path = spec.GetFileSpec().GetPath();
+
+    auto it = m_uuids.find(path);
----------------
Jlalond wrote:

So we're changing the behavior to only evaluate the entry from the NTFile, so 
if we do have a load address we'll only ever evaluate the NT_file.

Should we instead try to inspect the in-memory version, check if it has a UUID 
and then fall back to the file? Is there going to be a guarauntee the UUID will 
be in memory but not in file? I think doing both makes sense

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

Reply via email to