JDevlieghere created this revision.
JDevlieghere added reviewers: friss, labath, jingham, vsk.
Herald added a subscriber: abidh.

The reproducer intentionally leak every object allocated during replay, which 
means that modules never get orphaned. If this were to happen for another 
reason, we might not be testing what we think we are. Assert that there are no 
targets left at the end of a test and that the global module cache is empty in 
the non-reproducer scenario.


Repository:
  rLLDB LLDB

https://reviews.llvm.org/D81612

Files:
  lldb/bindings/interface/SBModule.i
  lldb/include/lldb/API/SBModule.h
  lldb/packages/Python/lldbsuite/test/lldbtest.py
  lldb/source/API/SBModule.cpp


Index: lldb/source/API/SBModule.cpp
===================================================================
--- lldb/source/API/SBModule.cpp
+++ lldb/source/API/SBModule.cpp
@@ -683,6 +683,13 @@
   return LLDB_RECORD_RESULT(sb_addr);
 }
 
+uint32_t SBModule::GetNumberAllocatedModules() {
+  LLDB_RECORD_STATIC_METHOD_NO_ARGS(uint32_t, SBModule,
+                                    GetNumberAllocatedModules);
+
+  return Module::GetNumberAllocatedModules();
+}
+
 namespace lldb_private {
 namespace repro {
 
@@ -757,6 +764,8 @@
                              GetObjectFileHeaderAddress, ());
   LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBModule,
                              GetObjectFileEntryPointAddress, ());
+  LLDB_REGISTER_STATIC_METHOD(uint32_t, SBModule, GetNumberAllocatedModules,
+                              ());
 }
 
 }
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2022,6 +2022,14 @@
         for target in targets:
             self.dbg.DeleteTarget(target)
 
+        # Modules are not orphaned during reproducer replay because they're
+        # leaked on purpose.
+        if not configuration.is_reproducer():
+            # Assert that all targets are deleted.
+            self.assertEqual(self.dbg.GetNumTargets(), 0)
+            # Assert that the global module cache is empty.
+            self.assertEqual(lldb.SBModule.GetNumberAllocatedModules(), 0)
+
         # Do this last, to make sure it's in reverse order from how we setup.
         Base.tearDown(self)
 
Index: lldb/include/lldb/API/SBModule.h
===================================================================
--- lldb/include/lldb/API/SBModule.h
+++ lldb/include/lldb/API/SBModule.h
@@ -288,6 +288,9 @@
   lldb::SBAddress GetObjectFileHeaderAddress() const;
   lldb::SBAddress GetObjectFileEntryPointAddress() const;
 
+  /// Get the number of global modules.
+  static uint32_t GetNumberAllocatedModules();
+
 private:
   friend class SBAddress;
   friend class SBFrame;
Index: lldb/bindings/interface/SBModule.i
===================================================================
--- lldb/bindings/interface/SBModule.i
+++ lldb/bindings/interface/SBModule.i
@@ -344,6 +344,9 @@
     lldb::SBAddress
     GetObjectFileEntryPointAddress() const;
 
+    static uint32_t
+    GetNumberAllocatedModules();
+
     STRING_EXTENSION(SBModule)
 
 #ifdef SWIGPYTHON


Index: lldb/source/API/SBModule.cpp
===================================================================
--- lldb/source/API/SBModule.cpp
+++ lldb/source/API/SBModule.cpp
@@ -683,6 +683,13 @@
   return LLDB_RECORD_RESULT(sb_addr);
 }
 
+uint32_t SBModule::GetNumberAllocatedModules() {
+  LLDB_RECORD_STATIC_METHOD_NO_ARGS(uint32_t, SBModule,
+                                    GetNumberAllocatedModules);
+
+  return Module::GetNumberAllocatedModules();
+}
+
 namespace lldb_private {
 namespace repro {
 
@@ -757,6 +764,8 @@
                              GetObjectFileHeaderAddress, ());
   LLDB_REGISTER_METHOD_CONST(lldb::SBAddress, SBModule,
                              GetObjectFileEntryPointAddress, ());
+  LLDB_REGISTER_STATIC_METHOD(uint32_t, SBModule, GetNumberAllocatedModules,
+                              ());
 }
 
 }
Index: lldb/packages/Python/lldbsuite/test/lldbtest.py
===================================================================
--- lldb/packages/Python/lldbsuite/test/lldbtest.py
+++ lldb/packages/Python/lldbsuite/test/lldbtest.py
@@ -2022,6 +2022,14 @@
         for target in targets:
             self.dbg.DeleteTarget(target)
 
+        # Modules are not orphaned during reproducer replay because they're
+        # leaked on purpose.
+        if not configuration.is_reproducer():
+            # Assert that all targets are deleted.
+            self.assertEqual(self.dbg.GetNumTargets(), 0)
+            # Assert that the global module cache is empty.
+            self.assertEqual(lldb.SBModule.GetNumberAllocatedModules(), 0)
+
         # Do this last, to make sure it's in reverse order from how we setup.
         Base.tearDown(self)
 
Index: lldb/include/lldb/API/SBModule.h
===================================================================
--- lldb/include/lldb/API/SBModule.h
+++ lldb/include/lldb/API/SBModule.h
@@ -288,6 +288,9 @@
   lldb::SBAddress GetObjectFileHeaderAddress() const;
   lldb::SBAddress GetObjectFileEntryPointAddress() const;
 
+  /// Get the number of global modules.
+  static uint32_t GetNumberAllocatedModules();
+
 private:
   friend class SBAddress;
   friend class SBFrame;
Index: lldb/bindings/interface/SBModule.i
===================================================================
--- lldb/bindings/interface/SBModule.i
+++ lldb/bindings/interface/SBModule.i
@@ -344,6 +344,9 @@
     lldb::SBAddress
     GetObjectFileEntryPointAddress() const;
 
+    static uint32_t
+    GetNumberAllocatedModules();
+
     STRING_EXTENSION(SBModule)
 
 #ifdef SWIGPYTHON
_______________________________________________
lldb-commits mailing list
lldb-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits

Reply via email to