summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/functionalities
diff options
context:
space:
mode:
authorJason Molenda <jmolenda@apple.com>2019-04-08 23:03:02 +0000
committerJason Molenda <jmolenda@apple.com>2019-04-08 23:03:02 +0000
commit1724a179e7ae2d0485f0fc8fee7ac3a18cc29152 (patch)
tree87bbd2f536267e1116e4243d67fe446449be3c35 /lldb/packages/Python/lldbsuite/test/functionalities
parente794752bdfb334b64b2d356e9c0444572ad19da1 (diff)
downloadbcm5719-llvm-1724a179e7ae2d0485f0fc8fee7ac3a18cc29152.tar.gz
bcm5719-llvm-1724a179e7ae2d0485f0fc8fee7ac3a18cc29152.zip
Rename Target::GetSharedModule to Target::GetOrCreateModule.
Add a flag to control whether the ModulesDidLoad notification is called when a module is added. If the notifications are disabled, the caller must call ModulesDidLoad after adding all the new modules, but postponing this notification until they're all batched up can allow for better efficiency than notifying one-by-one. Change the name of the ModuleList notifier functions that a subclass can implement to start with 'Notify' to make it clear what they are. Add a NotifyModulesRemoved. Add header documentation for the changed/updated methods. Added defaulted-value 'notify' argument to ModuleList Append, AppendIfNeeded, and Remove because callers working with a local ModuleList don't have an obvious idea of what notify means in this context. When the ModuleList is a part of the Target class, the notify behavior matters. DynamicLoaderDarwin has been updated so that libraries being added/removed are correctly batched up before notifications are sent. Added the TestModuleLoadedNotifys.py test to run on Darwin to test this. <rdar://problem/48293064> Differential Revision: https://reviews.llvm.org/D60172 llvm-svn: 357955
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/functionalities')
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/Makefile5
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py114
-rw-r--r--lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/main.cpp6
3 files changed, 125 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/Makefile b/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/Makefile
new file mode 100644
index 00000000000..8a7102e347a
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/Makefile
@@ -0,0 +1,5 @@
+LEVEL = ../../make
+
+CXX_SOURCES := main.cpp
+
+include $(LEVEL)/Makefile.rules
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py b/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
new file mode 100644
index 00000000000..e6614b0a957
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/TestModuleLoadedNotifys.py
@@ -0,0 +1,114 @@
+"""
+Test how many times newly loaded binaries are notified;
+they should be delivered in batches instead of one-by-one.
+"""
+
+from __future__ import print_function
+
+
+import os
+import time
+import re
+import lldb
+from lldbsuite.test.decorators import *
+from lldbsuite.test.lldbtest import *
+from lldbsuite.test import lldbutil
+
+class ModuleLoadedNotifysTestCase(TestBase):
+
+ mydir = TestBase.compute_mydir(__file__)
+ NO_DEBUG_INFO_TESTCASE = True
+
+ # DyanmicLoaderDarwin should batch up notifications about
+ # newly added/removed libraries. Other DynamicLoaders may
+ # not be written this way.
+ @skipUnlessDarwin
+
+ def setUp(self):
+ # Call super's setUp().
+ TestBase.setUp(self)
+ # Find the line number to break inside main().
+ self.line = line_number('main.cpp', '// breakpoint')
+
+ def test_launch_notifications(self):
+ """Test that lldb broadcasts newly loaded libraries in batches."""
+ self.build()
+ exe = self.getBuildArtifact("a.out")
+ self.dbg.SetAsync(False)
+
+ listener = self.dbg.GetListener()
+ listener.StartListeningForEventClass(
+ self.dbg,
+ lldb.SBTarget.GetBroadcasterClassName(),
+ lldb.SBTarget.eBroadcastBitModulesLoaded | lldb.SBTarget.eBroadcastBitModulesUnloaded)
+
+ # Create a target by the debugger.
+ target = self.dbg.CreateTarget(exe)
+ self.assertTrue(target, VALID_TARGET)
+
+ # break on main
+ breakpoint = target.BreakpointCreateByName('main', 'a.out')
+
+ event = lldb.SBEvent()
+ # CreateTarget() generated modules-loaded events; consume them & toss
+ while listener.GetNextEvent(event):
+ True
+
+ error = lldb.SBError()
+ process = target.Launch(listener,
+ None, # argv
+ None, # envp
+ None, # stdin_path
+ None, # stdout_path
+ None, # stderr_path
+ None, # working directory
+ 0, # launch flags
+ False, # Stop at entry
+ error) # error
+
+ self.assertTrue(
+ process.GetState() == lldb.eStateStopped,
+ PROCESS_STOPPED)
+
+ total_solibs_added = 0
+ total_solibs_removed = 0
+ total_modules_added_events = 0
+ total_modules_removed_events = 0
+ 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
+ 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:
+ solib_count = lldb.SBTarget.GetNumModulesFromEvent(event)
+ total_modules_removed_events += 1
+ total_solibs_removed += solib_count
+ if self.TraceOn():
+ # print all of the binaries that have been removed
+ removed_files = []
+ i = 0
+ while i < solib_count:
+ module = lldb.SBTarget.GetModuleAtIndexFromEvent(i, event)
+ removed_files.append(module.GetFileSpec().GetFilename())
+ i = i + 1
+ print("Unloaded files: %s" % (', '.join(removed_files)))
+
+
+ # This is testing that we get back a small number of events with the loaded
+ # 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.
+
+ avg_solibs_added_per_event = int(float(total_solibs_added) / float(total_modules_added_events))
+ self.assertGreater(avg_solibs_added_per_event, 1)
diff --git a/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/main.cpp b/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/main.cpp
new file mode 100644
index 00000000000..00130c93b88
--- /dev/null
+++ b/lldb/packages/Python/lldbsuite/test/functionalities/target-new-solib-notifications/main.cpp
@@ -0,0 +1,6 @@
+#include <stdio.h>
+int main ()
+{
+ puts("running"); // breakpoint here
+ return 0;
+}
OpenPOWER on IntegriCloud