[Lldb-commits] [lldb] a578adc - dotest: Add a way for the run_to_* helpers to register dylibs

Fred Riss via lldb-commits lldb-commits at lists.llvm.org
Fri Nov 15 15:36:24 PST 2019


Author: Fred Riss
Date: 2019-11-15T15:17:27-08:00
New Revision: a578adc1bc8e17b147ed5ef4794cd6f3f82b584b

URL: https://github.com/llvm/llvm-project/commit/a578adc1bc8e17b147ed5ef4794cd6f3f82b584b
DIFF: https://github.com/llvm/llvm-project/commit/a578adc1bc8e17b147ed5ef4794cd6f3f82b584b.diff

LOG: dotest: Add a way for the run_to_* helpers to register dylibs

Summary:
To run the testsuite remotely the executable needs to be uploaded to
the target system. The Target takes care of this by default.

When the test uses additional shared libraries, those won't be handled
by default and need to be registered with the target using
test.registerSharedLibrariesWithTarget(target, dylib).

Calling this API requires a target, so it doesn't mesh well with the
run_to_* helpers that we've been advertising as the right way to write
tests.

This patch adds an extra_images argument to all the helpers and does
the registration automatically when running a remote
testsuite. TestWeakSymbols.py was converted to use this new scheme.

Reviewers: jingham

Subscribers: lldb-commits

Tags: #lldb

Differential Revision: https://reviews.llvm.org/D70134

Added: 
    

Modified: 
    lldb/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py
    lldb/packages/Python/lldbsuite/test/lldbutil.py

Removed: 
    


################################################################################
diff  --git a/lldb/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py b/lldb/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py
index 2999cba7d99d..2b097e81ddfa 100644
--- a/lldb/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py
+++ b/lldb/packages/Python/lldbsuite/test/commands/expression/weak_symbols/TestWeakSymbols.py
@@ -49,17 +49,20 @@ def run_weak_var_check (self, weak_varname, present):
         
     def do_test(self):
         hidden_dir = os.path.join(self.getBuildDir(), "hidden")
-        
+        hidden_dylib = os.path.join(hidden_dir, "libdylib.dylib")
+
         launch_info = lldb.SBLaunchInfo(None)
         launch_info.SetWorkingDirectory(self.getBuildDir())
         # We have to point to the hidden directory to pick up the
         # version of the dylib without the weak symbols:
         env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir
         launch_info.SetEnvironmentEntries([env_expr], True)
-        
-        (self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
-                                                                            "Set a breakpoint here", self.main_source_file,
-                                                                            launch_info = launch_info)
+
+        (self.target, _, thread, _) = lldbutil.run_to_source_breakpoint(
+                                              self, "Set a breakpoint here",
+                                              self.main_source_file,
+                                              launch_info = launch_info,
+                                              extra_images = [hidden_dylib])
         # First we have to import the Dylib module so we get the type info
         # for the weak symbol.  We need to add the source dir to the module
         # search paths, and then run @import to introduce it into the expression

diff  --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 5100dd596d0d..05d0c9f9d3e9 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -760,13 +760,18 @@ def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
     test.assertTrue(target, "Target: %s is not valid."%(exe_name))
     return target
 
-def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None, only_one_thread = True):
+def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None,
+                             only_one_thread = True, extra_images = None):
 
     # Launch the process, and do not stop at the entry point.
     if not launch_info:
         launch_info = lldb.SBLaunchInfo(None)
         launch_info.SetWorkingDirectory(test.get_process_working_directory())
 
+    if extra_images and lldb.remote_platform:
+        environ = test.registerSharedLibrariesWithTarget(target, extra_images)
+        launch_info.SetEnvironmentEntries(environ, True)
+
     error = lldb.SBError()
     process = target.Launch(launch_info, error)
 
@@ -791,7 +796,8 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
                             exe_name = "a.out",
                             bkpt_module = None,
                             in_cwd = True,
-                            only_one_thread = True):
+                            only_one_thread = True,
+                            extra_images = None):
     """Start up a target, using exe_name as the executable, and run it to
        a breakpoint set by name on bkpt_name restricted to bkpt_module.
 
@@ -827,13 +833,15 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
 
     test.assertTrue(breakpoint.GetNumLocations() > 0,
                     "No locations found for name breakpoint: '%s'."%(bkpt_name))
-    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
+    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
+                                    only_one_thread, extra_images)
 
 def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
                              launch_info = None, exe_name = "a.out",
                              bkpt_module = None,
                              in_cwd = True,
-                             only_one_thread = True):
+                             only_one_thread = True,
+                             extra_images = None):
     """Start up a target, using exe_name as the executable, and run it to
        a breakpoint set by source regex bkpt_pattern.
 
@@ -847,13 +855,15 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
     test.assertTrue(breakpoint.GetNumLocations() > 0,
         'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
         %(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
-    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
+    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
+                                    only_one_thread, extra_images)
 
 def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
                            launch_info = None, exe_name = "a.out",
                            bkpt_module = None,
                            in_cwd = True,
-                           only_one_thread = True):
+                           only_one_thread = True,
+                           extra_images = None):
     """Start up a target, using exe_name as the executable, and run it to
        a breakpoint set by (source_spec, line_number(, column)).
 
@@ -868,7 +878,8 @@ def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
         'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
         %(source_spec.GetFilename(), line_number, column,
           source_spec.GetDirectory()))
-    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
+    return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
+                                    only_one_thread, extra_images)
 
 
 def continue_to_breakpoint(process, bkpt):


        


More information about the lldb-commits mailing list