Skip to content

[lldb] Clear up GetModuleSpecifications return value confusion - #188276

Merged
labath merged 1 commit into
llvm:mainfrom
labath:specs
Mar 25, 2026
Merged

labath merged 1 commit into
llvm:mainfrom
labath:specs

Conversation

@labath

@labath labath commented Mar 24, 2026 •

Copy link
Copy Markdown
Contributor

Some plugins were returning the number of specifications they have added, while others were returning the total final number. Particularly devious plugins (Minidump) were clearing the specification list altogether. This resulted in nondeterministic failures (depending on plugin ininitialization order) in TestSBModule.

This PR defines the problem away by having each plugin only return the specifications it is responsible for. If the caller wants to merge them, it is free to do so. This might be slighly less efficient, but this is hardly hot code.

I'm not touching the ObjectFile::GetModuleSpecifications function (the caller of all these functions) as the PR is big enough, although the same approach might be warranted there as well.

Fixes #178625.

Some plugins were returning the number of specifications they have
added, while others were returning the total final number. Particularly
devious plugins (Minidump) were clearing the specification list
altogether. This resulted in nondeterministic failures (depending on
plugin ininitialization order) in TestSBModule.

This PR defines the problem away by having each plugin only return the
specifications it is responsible for. If the caller wants to merge them,
it is free to do so. This *might* be slighly less efficient, but this is
hardly hot code.

I'm not touching the ObjectFile::GetModuleSpecifications function (the
caller of all these functions) as the PR is big enough, although the
same approach might be warranted there as well.
@labath
labath requested a review from JDevlieghere as a code owner March 24, 2026 16:22
@llvmbot llvmbot added the lldb label Mar 24, 2026
@llvmbot

llvmbot commented Mar 24, 2026

Copy link
Copy Markdown
Member

@llvm/pr-subscribers-lldb

Author: Pavel Labath (labath)

Changes

Some plugins were returning the number of specifications they have added, while others were returning the total final number. Particularly devious plugins (Minidump) were clearing the specification list altogether. This resulted in nondeterministic failures (depending on plugin ininitialization order) in TestSBModule.

This PR defines the problem away by having each plugin only return the specifications it is responsible for. If the caller wants to merge them, it is free to do so. This might be slighly less efficient, but this is hardly hot code.

I'm not touching the ObjectFile::GetModuleSpecifications function (the caller of all these functions) as the PR is big enough, although the same approach might be warranted there as well.


Patch is 45.27 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/188276.diff

32 Files Affected:

  • (modified) lldb/include/lldb/Expression/ObjectFileJIT.h (+5-6)
  • (modified) lldb/include/lldb/lldb-private-interfaces.h (+2-2)
  • (modified) lldb/source/Expression/ObjectFileJIT.cpp (+3-3)
  • (modified) lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp (+8-9)
  • (modified) lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h (+6-6)
  • (modified) lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp (+3-3)
  • (modified) lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp (+6-6)
  • (modified) lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp (+5-5)
  • (modified) lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp (+6-5)
  • (modified) lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp (+13-12)
  • (modified) lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.cpp (+6-6)
  • (modified) lldb/source/Plugins/ObjectFile/ELF/ObjectFileELF.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.cpp (+8-7)
  • (modified) lldb/source/Plugins/ObjectFile/JSON/ObjectFileJSON.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.cpp (+5-5)
  • (modified) lldb/source/Plugins/ObjectFile/Mach-O/ObjectFileMachO.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.cpp (+3-4)
  • (modified) lldb/source/Plugins/ObjectFile/Minidump/ObjectFileMinidump.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.cpp (+7-7)
  • (modified) lldb/source/Plugins/ObjectFile/PDB/ObjectFilePDB.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.cpp (+7-7)
  • (modified) lldb/source/Plugins/ObjectFile/PECOFF/ObjectFilePECOFF.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.cpp (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/XCOFF/ObjectFileXCOFF.h (+5-6)
  • (modified) lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.cpp (+7-8)
  • (modified) lldb/source/Plugins/ObjectFile/wasm/ObjectFileWasm.h (+5-6)
  • (modified) lldb/source/Symbol/ObjectFile.cpp (+12-7)
diff --git a/lldb/include/lldb/Expression/ObjectFileJIT.h b/lldb/include/lldb/Expression/ObjectFileJIT.h
index 0694a969ed8d1..124ae6a9e5042 100644
--- a/lldb/include/lldb/Expression/ObjectFileJIT.h
+++ b/lldb/include/lldb/Expression/ObjectFileJIT.h
@@ -58,12 +58,11 @@ class ObjectFileJIT : public ObjectFile {
       const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
 
-  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataExtractorSP &extractor_sp,
-                                        lldb::offset_t data_offset,
-                                        lldb::offset_t file_offset,
-                                        lldb::offset_t length,
-                                        lldb_private::ModuleSpecList &specs);
+  static ModuleSpecList
+  GetModuleSpecifications(const lldb_private::FileSpec &file,
+                          lldb::DataExtractorSP &extractor_sp,
+                          lldb::offset_t data_offset,
+                          lldb::offset_t file_offset, lldb::offset_t length);
 
   // LLVM RTTI support
   static char ID;
diff --git a/lldb/include/lldb/lldb-private-interfaces.h b/lldb/include/lldb/lldb-private-interfaces.h
index d70bce6f686c7..e618081cc2cd3 100644
--- a/lldb/include/lldb/lldb-private-interfaces.h
+++ b/lldb/include/lldb/lldb-private-interfaces.h
@@ -46,10 +46,10 @@ typedef ObjectContainer *(*ObjectContainerCreateInstance)(
 typedef ObjectContainer *(*ObjectContainerCreateMemoryInstance)(
     const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
     const lldb::ProcessSP &process_sp, lldb::addr_t offset);
-typedef size_t (*ObjectFileGetModuleSpecifications)(
+typedef ModuleSpecList (*ObjectFileGetModuleSpecifications)(
     const FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
-    lldb::offset_t length, ModuleSpecList &module_specs);
+    lldb::offset_t length);
 typedef ObjectFile *(*ObjectFileCreateInstance)(
     const lldb::ModuleSP &module_sp, lldb::DataExtractorSP extractor_sp,
     lldb::offset_t data_offset, const FileSpec *file,
diff --git a/lldb/source/Expression/ObjectFileJIT.cpp b/lldb/source/Expression/ObjectFileJIT.cpp
index 5f51617158197..ee4af0d0ceff9 100644
--- a/lldb/source/Expression/ObjectFileJIT.cpp
+++ b/lldb/source/Expression/ObjectFileJIT.cpp
@@ -60,12 +60,12 @@ ObjectFile *ObjectFileJIT::CreateMemoryInstance(const lldb::ModuleSP &module_sp,
   return nullptr;
 }
 
-size_t ObjectFileJIT::GetModuleSpecifications(
+ModuleSpecList ObjectFileJIT::GetModuleSpecifications(
     const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
-    lldb::offset_t length, lldb_private::ModuleSpecList &specs) {
+    lldb::offset_t length) {
   // JIT'ed object file can't be read from a file on disk
-  return 0;
+  return {};
 }
 
 ObjectFileJIT::ObjectFileJIT(const lldb::ModuleSP &module_sp,
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
index 32604a60841bb..64c16b352acfe 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.cpp
@@ -434,13 +434,13 @@ ObjectFileSP ObjectContainerBSDArchive::GetObjectFile(const FileSpec *file) {
   return ObjectFileSP();
 }
 
-size_t ObjectContainerBSDArchive::GetModuleSpecifications(
+ModuleSpecList ObjectContainerBSDArchive::GetModuleSpecifications(
     const FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
-    lldb::offset_t file_size, ModuleSpecList &specs) {
+    lldb::offset_t file_size) {
 
   if (!file || !extractor_sp)
-    return 0;
+    return {};
 
   DataExtractorSP data_extractor_sp =
       extractor_sp->GetSubsetExtractorSP(data_offset);
@@ -449,9 +449,8 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
   // contents for the archive and cache it
   ArchiveType archive_type = MagicBytesMatch(*data_extractor_sp);
   if (archive_type == ArchiveType::Invalid)
-    return 0;
+    return {};
 
-  const size_t initial_count = specs.GetSize();
   llvm::sys::TimePoint<> file_mod_time =
       FileSystem::Instance().GetModificationTime(file);
   ArchiveSP archive_sp(
@@ -469,6 +468,7 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
     }
   }
 
+  ModuleSpecList specs;
   if (archive_sp) {
     const size_t num_objects = archive_sp->GetNumObjects();
     for (size_t idx = 0; idx < num_objects; ++idx) {
@@ -512,11 +512,10 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
     }
   }
   const size_t end_count = specs.GetSize();
-  size_t num_specs_added = end_count - initial_count;
-  if (set_archive_arch && num_specs_added > 0) {
+  if (set_archive_arch && specs.GetSize() > 0) {
     // The archive was created but we didn't have an architecture so we need to
     // set it
-    for (size_t i = initial_count; i < end_count; ++i) {
+    for (size_t i = 0; i < end_count; ++i) {
       ModuleSpec module_spec;
       if (specs.GetModuleSpecAtIndex(i, module_spec)) {
         if (module_spec.GetArchitecture().IsValid()) {
@@ -526,5 +525,5 @@ size_t ObjectContainerBSDArchive::GetModuleSpecifications(
       }
     }
   }
-  return num_specs_added;
+  return specs;
 }
diff --git a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
index 82a23a458d58c..b92ee4653e7fa 100644
--- a/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
+++ b/lldb/source/Plugins/ObjectContainer/BSD-Archive/ObjectContainerBSDArchive.h
@@ -9,6 +9,7 @@
 #ifndef LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
 #define LLDB_SOURCE_PLUGINS_OBJECTCONTAINER_BSD_ARCHIVE_OBJECTCONTAINERBSDARCHIVE_H
 
+#include "lldb/Core/ModuleSpec.h"
 #include "lldb/Core/UniqueCStringMap.h"
 #include "lldb/Symbol/ObjectContainer.h"
 #include "lldb/Utility/ArchSpec.h"
@@ -54,12 +55,11 @@ class ObjectContainerBSDArchive : public lldb_private::ObjectContainer {
                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
                  lldb::offset_t offset, lldb::offset_t length);
 
-  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataExtractorSP &extractor_sp,
-                                        lldb::offset_t data_offset,
-                                        lldb::offset_t file_offset,
-                                        lldb::offset_t length,
-                                        lldb_private::ModuleSpecList &specs);
+  static lldb_private::ModuleSpecList
+  GetModuleSpecifications(const lldb_private::FileSpec &file,
+                          lldb::DataExtractorSP &extractor_sp,
+                          lldb::offset_t data_offset,
+                          lldb::offset_t file_offset, lldb::offset_t length);
 
   static ArchiveType
   MagicBytesMatch(const lldb_private::DataExtractor &extractor);
diff --git a/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp b/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp
index c25add2827fda..d4dee674a53c0 100644
--- a/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.cpp
@@ -43,11 +43,11 @@ ObjectContainer *ObjectContainerBigArchive::CreateInstance(
   return nullptr;
 }
 
-size_t ObjectContainerBigArchive::GetModuleSpecifications(
+ModuleSpecList ObjectContainerBigArchive::GetModuleSpecifications(
     const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
-    lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
-  return 0;
+    lldb::offset_t file_size) {
+  return {};
 }
 
 ObjectContainerBigArchive::ObjectContainerBigArchive(
diff --git a/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h b/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h
index a9f899af6b002..ae3d0c05359de 100644
--- a/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h
+++ b/lldb/source/Plugins/ObjectContainer/Big-Archive/ObjectContainerBigArchive.h
@@ -44,12 +44,11 @@ class ObjectContainerBigArchive : public lldb_private::ObjectContainer {
                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
                  lldb::offset_t offset, lldb::offset_t length);
 
-  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataExtractorSP &extractor_sp,
-                                        lldb::offset_t data_offset,
-                                        lldb::offset_t file_offset,
-                                        lldb::offset_t length,
-                                        lldb_private::ModuleSpecList &specs);
+  static lldb_private::ModuleSpecList
+  GetModuleSpecifications(const lldb_private::FileSpec &file,
+                          lldb::DataExtractorSP &extractor_sp,
+                          lldb::offset_t data_offset,
+                          lldb::offset_t file_offset, lldb::offset_t length);
 
   // Member Functions
   bool ParseHeader() override;
diff --git a/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp b/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
index 4f1405abf8b56..3e04a92ffe20f 100644
--- a/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.cpp
@@ -219,18 +219,18 @@ bool ObjectContainerMachOFileset::ParseHeader() {
   return ParseFileset(*m_extractor_sp, *header, m_entries, m_memory_addr);
 }
 
-size_t ObjectContainerMachOFileset::GetModuleSpecifications(
+ModuleSpecList ObjectContainerMachOFileset::GetModuleSpecifications(
     const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
-    lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
-  const size_t initial_count = specs.GetSize();
+    lldb::offset_t file_size) {
   if (!extractor_sp)
-    return initial_count;
+    return {};
 
   DataExtractorSP data_extractor_sp =
       extractor_sp->GetSubsetExtractorSP(data_offset);
   if (!data_extractor_sp)
-    return initial_count;
+    return {};
+  ModuleSpecList specs;
   if (MagicBytesMatch(*data_extractor_sp)) {
     std::vector<Entry> entries;
     if (ParseHeader(*data_extractor_sp, file, file_offset, entries)) {
@@ -244,7 +244,7 @@ size_t ObjectContainerMachOFileset::GetModuleSpecifications(
       }
     }
   }
-  return specs.GetSize() - initial_count;
+  return specs;
 }
 
 bool ObjectContainerMachOFileset::MagicBytesMatch(DataBufferSP data_sp,
diff --git a/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h b/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
index 1ba667394ae7e..b0de836056fdd 100644
--- a/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
+++ b/lldb/source/Plugins/ObjectContainer/Mach-O-Fileset/ObjectContainerMachOFileset.h
@@ -48,12 +48,11 @@ class ObjectContainerMachOFileset : public lldb_private::ObjectContainer {
       const lldb::ModuleSP &module_sp, lldb::WritableDataBufferSP data_sp,
       const lldb::ProcessSP &process_sp, lldb::addr_t header_addr);
 
-  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataExtractorSP &extractor_sp,
-                                        lldb::offset_t data_offset,
-                                        lldb::offset_t file_offset,
-                                        lldb::offset_t length,
-                                        lldb_private::ModuleSpecList &specs);
+  static ModuleSpecList
+  GetModuleSpecifications(const lldb_private::FileSpec &file,
+                          lldb::DataExtractorSP &extractor_sp,
+                          lldb::offset_t data_offset,
+                          lldb::offset_t file_offset, lldb::offset_t length);
 
   static bool MagicBytesMatch(const lldb_private::DataExtractor &data);
   static bool MagicBytesMatch(lldb::DataBufferSP data_sp,
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
index 0ff0a05e24455..6144a02bda6a2 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.cpp
@@ -188,14 +188,14 @@ ObjectContainerUniversalMachO::GetObjectFile(const FileSpec *file) {
   return ObjectFileSP();
 }
 
-size_t ObjectContainerUniversalMachO::GetModuleSpecifications(
+ModuleSpecList ObjectContainerUniversalMachO::GetModuleSpecifications(
     const lldb_private::FileSpec &file, lldb::DataExtractorSP &extractor_sp,
     lldb::offset_t data_offset, lldb::offset_t file_offset,
-    lldb::offset_t file_size, lldb_private::ModuleSpecList &specs) {
-  const size_t initial_count = specs.GetSize();
+    lldb::offset_t file_size) {
   if (!extractor_sp)
-    return initial_count;
+    return {};
 
+  ModuleSpecList specs;
   DataExtractorSP data_extractor_sp =
       extractor_sp->GetSubsetExtractorSP(data_offset);
   if (ObjectContainerUniversalMachO::MagicBytesMatch(*data_extractor_sp)) {
@@ -212,5 +212,5 @@ size_t ObjectContainerUniversalMachO::GetModuleSpecifications(
       }
     }
   }
-  return specs.GetSize() - initial_count;
+  return specs;
 }
diff --git a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
index b4d451f740ee4..6b91b81b1e4fe 100644
--- a/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
+++ b/lldb/source/Plugins/ObjectContainer/Universal-Mach-O/ObjectContainerUniversalMachO.h
@@ -39,12 +39,11 @@ class ObjectContainerUniversalMachO : public lldb_private::ObjectContainer {
                  lldb::offset_t data_offset, const lldb_private::FileSpec *file,
                  lldb::offset_t offset, lldb::offset_t length);
 
-  static size_t GetModuleSpecifications(const lldb_private::FileSpec &file,
-                                        lldb::DataExtractorSP &extractor_sp,
-                                        lldb::offset_t data_offset,
-                                        lldb::offset_t file_offset,
-                                        lldb::offset_t length,
-                                        lldb_private::ModuleSpecList &specs);
+  static lldb_private::ModuleSpecList
+  GetModuleSpecifications(const lldb_private::FileSpec &file,
+                          lldb::DataExtractorSP &extractor_sp,
+                          lldb::offset_t data_offset,
+                          lldb::offset_t file_offset, lldb::offset_t length);
 
   static bool MagicBytesMatch(const lldb_private::DataExtractor &data);
 
diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
index d3ec0ff1f81a1..bd1687e8a214c 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.cpp
@@ -101,11 +101,11 @@ ObjectFile *ObjectFileBreakpad::CreateMemoryInstance(
   return nullptr;
 }
 
-size_t ObjectFileBreakpad::GetModuleSpecifications(
+ModuleSpecList ObjectFileBreakpad::GetModuleSpecifications(
     const FileSpec &file, DataExtractorSP &extractor_sp, offset_t data_offset,
-    offset_t file_offset, offset_t length, ModuleSpecList &specs) {
+    offset_t file_offset, offset_t length) {
   if (!extractor_sp || !extractor_sp->HasData())
-    return 0;
+    return {};
   // If this is opearting on a VirtualDataExtractor, it can have
   // gaps between valid bytes in the DataBuffer. We extract an
   // ArrayRef of the raw bytes, and can segfault.
@@ -114,11 +114,12 @@ size_t ObjectFileBreakpad::GetModuleSpecifications(
   auto text = toStringRef(contiguous_extractor_sp->GetData());
   std::optional<Header> header = Header::parse(text);
   if (!header)
-    return 0;
+    return {};
   ModuleSpec spec(file, std::move(header->arch));
   spec.GetUUID() = std::move(header->uuid);
+  ModuleSpecList specs;
   specs.Append(spec);
-  return 1;
+  return specs;
 }
 
 ObjectFileBreakpad::ObjectFileBreakpad(const ModuleSP &module_sp,
diff --git a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
index c866aa73e0cdf..2a186aa5132b6 100644
--- a/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
+++ b/lldb/source/Plugins/ObjectFile/Breakpad/ObjectFileBreakpad.h
@@ -38,12 +38,11 @@ class ObjectFileBreakpad : public ObjectFile {
                                           const lldb::ProcessSP &process_sp,
                                           lldb::addr_t header_addr);
 
-  static size_t GetModuleSpecifications(const FileSpec &file,
-                                        lldb::DataExtractorSP &extractor_sp,
-                                        lldb::offset_t data_offset,
-                                        lldb::offset_t file_offset,
-                                        lldb::offset_t length,
-                                        ModuleSpecList &specs);
+  static ModuleSpecList
+  GetModuleSpecifications(const FileSpec &file,
+                          lldb::DataExtractorSP &extractor_sp,
+                          lldb::offset_t data_offset,
+                          lldb::offset_t file_offset, lldb::offset_t length);
 
   // PluginInterface protocol
   llvm::StringRef GetPluginName() override { return GetPluginNameStatic(); }
diff --git a/lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp b/lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp
index 123d1ccf229d8..3f24ba3fb1d2a 100644
--- a/lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp
+++ b/lldb/source/Plugins/ObjectFile/COFF/ObjectFileCOFF.cpp
@@ -113,11 +113,11 @@ lldb_private::ObjectFile *ObjectFileCOFF::CreateMemoryInstance(
   return nullptr;
 }
 
-size_t ObjectFileCOFF::GetModuleSpecifications(
+ModuleSpecList ObjectFileCOFF::GetModuleSpecifications(
     const FileSpec &file, DataExtractorSP &extractor_sp, offset_t data_offset,
-    offset_t file_offset, offset_t length, ModuleSpecList &specs) {
+    offset_t file_offset, offset_t length) {
   if (!extractor_sp || !extractor_sp->HasData())
-    return 0;
+    return {};
 
   // If this is opearting on a VirtualDataExtractor, it can have
   // gaps between valid bytes in the DataBuffer. We extract an
@@ -125,9 +125,9 @@ size_t ObjectFileCOFF::GetModuleSpecifications(
   DataExtractorSP contiguous_extractor_sp =
       extractor_sp->GetContiguousDataExtractorSP();
   if (!contiguous_extractor_sp)
-    return 0;
+    return {};
   if (!IsCOFFObjectFile(contiguous_extractor_sp->GetData()))
-    return 0;
+    return {};
 
   MemoryBufferRef buffer{toStringRef(contiguous_extractor_sp->GetData()),
                          file.GetFilename().GetStringRef()};
@@ -137,27 +137,28 @@ size_t ObjectFileCOFF::GetModuleSpecifications(
     LLDB_LOG_ERROR(log, binary.takeError(),
                    "Failed to create binary for file ({1}): {0}",
                    file.GetFilename());
-    return 0;
+    return {};
   }
 
   std::unique_ptr<COFFObjectFile> object =
       unique_dyn_cast<COFFObjectFile>(std::move(*binary));
+  ModuleSpecList specs;
   switch (static_cast<COFF::MachineTypes>(object->getMachine())) {
-  case COFF::IMAGE_FILE_MACHINE_I386:
     specs.Append(ModuleSpec(file, ArchSpec("i686-unknown-windows-msvc")));
-    return 1;...
[truncated]

@JDevlieghere JDevlieghere left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Welcome back!

This fixes #178625. LGTM.

@labath

labath commented Mar 25, 2026

Copy link
Copy Markdown
Contributor Author

Welcome back!

Thanks. I am back, but unfortunately I won't have much time for LLDB in the near future.

@labath
labath merged commit 08c94c0 into llvm:main Mar 25, 2026
10 checks passed
@labath
labath deleted the specs branch March 25, 2026 14:55
labath added a commit to labath/llvm-project that referenced this pull request Mar 26, 2026
…fications

For consistency with llvm#188276 (and better readability?).
labath added a commit that referenced this pull request Mar 27, 2026
…fications (#188509)

For consistency with #188276 (and better readability?).
Aadarsh-Keshri pushed a commit to Aadarsh-Keshri/llvm-project that referenced this pull request Mar 28, 2026
…188276)

Some plugins were returning the number of specifications they have
added, while others were returning the total final number. Particularly
devious plugins (Minidump) were clearing the specification list
altogether. This resulted in nondeterministic failures (depending on
plugin ininitialization order) in TestSBModule.

This PR defines the problem away by having each plugin only return the
specifications it is responsible for. If the caller wants to merge them,
it is free to do so. This *might* be slighly less efficient, but this is
hardly hot code.

I'm not touching the ObjectFile::GetModuleSpecifications function (the
caller of all these functions) as the PR is big enough, although the
same approach might be warranted there as well.

Fixes llvm#178625.
Aadarsh-Keshri pushed a commit to Aadarsh-Keshri/llvm-project that referenced this pull request Mar 28, 2026
…fications (llvm#188509)

For consistency with llvm#188276 (and better readability?).
fzou1 pushed a commit to fzou1/llvm-project that referenced this pull request Mar 30, 2026
…fications (llvm#188509)

For consistency with llvm#188276 (and better readability?).
DavidSpickett added a commit that referenced this pull request Sep 8, 2026
vadimkotov pushed a commit to vadimkotov/llvm-project that referenced this pull request Sep 8, 2026
aobolensk pushed a commit to aobolensk/llvm-project that referenced this pull request Sep 15, 2026
tru pushed a commit that referenced this pull request Sep 25, 2026
)

08c94c0 / #188276 accidentally removed
the "case:" for i386.

(cherry picked from commit 443d419)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[LLDB] The return value of ObjectFile::GetModuleSpecification is inconsistent across plugins

4 participants