@@ -99,7 +99,7 @@ bool ProcessElfCore::CanDebug(lldb::TargetSP target_sp,
9999ProcessElfCore::ProcessElfCore (lldb::TargetSP target_sp,
100100 lldb::ListenerSP listener_sp,
101101 const FileSpec &core_file)
102- : PostMortemProcess(target_sp, listener_sp, core_file) {}
102+ : PostMortemProcess(target_sp, listener_sp, core_file), m_uuids() {}
103103
104104// Destructor
105105ProcessElfCore::~ProcessElfCore () {
@@ -257,12 +257,12 @@ Status ProcessElfCore::DoLoadCore() {
257257 // the main executable using data we found in the core file notes.
258258 lldb::ModuleSP exe_module_sp = GetTarget ().GetExecutableModule ();
259259 if (!exe_module_sp) {
260- // The first entry in the NT_FILE might be our executable
261260 if (!m_nt_file_entries.empty ()) {
261+ llvm::StringRef executable_path = GetMainExecutablePath ();
262262 ModuleSpec exe_module_spec;
263263 exe_module_spec.GetArchitecture () = arch;
264- exe_module_spec.GetUUID () = m_nt_file_entries[ 0 ]. uuid ;
265- exe_module_spec.GetFileSpec ().SetFile (m_nt_file_entries[ 0 ]. path ,
264+ exe_module_spec.GetUUID () = FindModuleUUID (executable_path) ;
265+ exe_module_spec.GetFileSpec ().SetFile (executable_path ,
266266 FileSpec::Style::native);
267267 if (exe_module_spec.GetFileSpec ()) {
268268 exe_module_sp =
@@ -277,21 +277,38 @@ Status ProcessElfCore::DoLoadCore() {
277277
278278void ProcessElfCore::UpdateBuildIdForNTFileEntries () {
279279 Log *log = GetLog (LLDBLog::Process);
280+ m_uuids.clear ();
280281 for (NT_FILE_Entry &entry : m_nt_file_entries) {
281- entry.uuid = FindBuidIdInCoreMemory (entry.start );
282- if (log && entry.uuid .IsValid ())
283- LLDB_LOGF (log, " %s found UUID @ %16.16" PRIx64 " : %s \" %s\" " ,
284- __FUNCTION__, entry.start , entry.uuid .GetAsString ().c_str (),
285- entry.path .c_str ());
282+ UUID uuid = FindBuidIdInCoreMemory (entry.start );
283+ if (uuid.IsValid ()) {
284+ // Assert that either the path is not in the map or the UUID matches
285+ assert (m_uuids.count (entry.path ) == 0 || m_uuids[entry.path ] == uuid);
286+ m_uuids[entry.path ] = uuid;
287+ if (log)
288+ LLDB_LOGF (log, " %s found UUID @ %16.16" PRIx64 " : %s \" %s\" " ,
289+ __FUNCTION__, entry.start , uuid.GetAsString ().c_str (),
290+ entry.path .c_str ());
291+ }
286292 }
287293}
288294
295+ llvm::StringRef ProcessElfCore::GetMainExecutablePath () {
296+ if (m_nt_file_entries.empty ())
297+ return " " ;
298+
299+ // The first entry in the NT_FILE might be our executable
300+ llvm::StringRef executable_path = m_nt_file_entries[0 ].path ;
301+ // Prefer the NT_FILE entry matching m_executable_name as main executable.
302+ for (const NT_FILE_Entry &file_entry : m_nt_file_entries)
303+ if (llvm::StringRef (file_entry.path ).ends_with (" /" + m_executable_name)) {
304+ executable_path = file_entry.path ;
305+ break ;
306+ }
307+ return executable_path;
308+ }
309+
289310UUID ProcessElfCore::FindModuleUUID (const llvm::StringRef path) {
290- // Returns the gnu uuid from matched NT_FILE entry
291- for (NT_FILE_Entry &entry : m_nt_file_entries)
292- if (path == entry.path && entry.uuid .IsValid ())
293- return entry.uuid ;
294- return UUID ();
311+ return m_uuids[std::string (path)];
295312}
296313
297314lldb_private::DynamicLoader *ProcessElfCore::GetDynamicLoader () {
@@ -935,6 +952,7 @@ llvm::Error ProcessElfCore::parseLinuxNotes(llvm::ArrayRef<CoreNote> notes) {
935952 return status.ToError ();
936953 thread_data.name .assign (prpsinfo.pr_fname , strnlen (prpsinfo.pr_fname , sizeof (prpsinfo.pr_fname )));
937954 SetID (prpsinfo.pr_pid );
955+ m_executable_name = prpsinfo.pr_fname ;
938956 break ;
939957 }
940958 case ELF::NT_SIGINFO: {
0 commit comments