[Lldb-commits] [PATCH] D123128: don't extra notify ModulesDidLoad() from LoadModuleAtAddress()

Luboš Luňák via Phabricator via lldb-commits lldb-commits at lists.llvm.org
Sun Apr 10 04:56:07 PDT 2022


llunak updated this revision to Diff 421782.
llunak edited the summary of this revision.
llunak added a comment.

Changed to always disable notify and added a comment about that to LoadModuleAtAddress().


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D123128/new/

https://reviews.llvm.org/D123128

Files:
  lldb/include/lldb/Target/DynamicLoader.h
  lldb/source/Core/DynamicLoader.cpp
  lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py


Index: lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
===================================================================
--- lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
+++ lldb/test/API/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
@@ -16,10 +16,10 @@
     mydir = TestBase.compute_mydir(__file__)
     NO_DEBUG_INFO_TESTCASE = True
 
-    # DynamicLoaderDarwin should batch up notifications about
-    # newly added/removed libraries.  Other DynamicLoaders may
+    # At least DynamicLoaderDarwin and DynamicLoaderPOSIXDYLD should batch up
+    # notifications about newly added/removed libraries.  Other DynamicLoaders may
     # not be written this way.
-    @skipUnlessDarwin
+    @skipUnlessPlatform(["linux"]+lldbplatformutil.getDarwinOSTriples())
 
     def setUp(self):
         # Call super's setUp().
@@ -72,20 +72,24 @@
         total_solibs_removed = 0
         total_modules_added_events = 0
         total_modules_removed_events = 0
+        already_loaded_modules = []
         while listener.GetNextEvent(event):
             if lldb.SBTarget.EventIsTargetEvent(event):
                 if event.GetType() == lldb.SBTarget.eBroadcastBitModulesLoaded:
                     solib_count = lldb.SBTarget.GetNumModulesFromEvent(event)
                     total_modules_added_events += 1
                     total_solibs_added += solib_count
+                    added_files = []
+                    i = 0
+                    while i < solib_count:
+                        module = lldb.SBTarget.GetModuleAtIndexFromEvent(i, event)
+                        self.assertTrue(module not in already_loaded_modules)
+                        already_loaded_modules.append(module)
+                        if self.TraceOn():
+                            added_files.append(module.GetFileSpec().GetFilename())
+                        i = i + 1
                     if self.TraceOn():
                         # print all of the binaries that have been added
-                        added_files = []
-                        i = 0
-                        while i < solib_count:
-                            module = lldb.SBTarget.GetModuleAtIndexFromEvent(i, event)
-                            added_files.append(module.GetFileSpec().GetFilename())
-                            i = i + 1
                         print("Loaded files: %s" % (', '.join(added_files)))
 
                 if event.GetType() == lldb.SBTarget.eBroadcastBitModulesUnloaded:
@@ -107,6 +111,7 @@
         # binaries in batches.  Check that we got back more than 1 solib per event.  
         # In practice on Darwin today, we get back two events for a do-nothing c 
         # program: a.out and dyld, and then all the rest of the system libraries.
+        # On Linux we get events for ld.so, [vdso], the binary and then all libraries.
 
-        avg_solibs_added_per_event = int(float(total_solibs_added) / float(total_modules_added_events))
+        avg_solibs_added_per_event = round(float(total_solibs_added) / float(total_modules_added_events))
         self.assertGreater(avg_solibs_added_per_event, 1)
Index: lldb/source/Core/DynamicLoader.cpp
===================================================================
--- lldb/source/Core/DynamicLoader.cpp
+++ lldb/source/Core/DynamicLoader.cpp
@@ -152,8 +152,7 @@
   if (ModuleSP module_sp = target.GetImages().FindFirstModule(module_spec))
     return module_sp;
 
-  if (ModuleSP module_sp = target.GetOrCreateModule(module_spec,
-                                                    /*notify=*/true))
+  if (ModuleSP module_sp = target.GetOrCreateModule(module_spec, false))
     return module_sp;
 
   return nullptr;
Index: lldb/include/lldb/Target/DynamicLoader.h
===================================================================
--- lldb/include/lldb/Target/DynamicLoader.h
+++ lldb/include/lldb/Target/DynamicLoader.h
@@ -203,6 +203,8 @@
 
   /// Locates or creates a module given by \p file and updates/loads the
   /// resulting module at the virtual base address \p base_addr.
+  /// Note that this calls Target::GetOrCreateModule with notify being false,
+  /// so it is necessary to call Target::ModulesDidLoad afterwards.
   virtual lldb::ModuleSP LoadModuleAtAddress(const lldb_private::FileSpec &file,
                                              lldb::addr_t link_map_addr,
                                              lldb::addr_t base_addr,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D123128.421782.patch
Type: text/x-patch
Size: 4517 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/lldb-commits/attachments/20220410/1365a2dc/attachment.bin>


More information about the lldb-commits mailing list