Skip to content

Commit a578adc

Browse files
committed
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
1 parent 12d7500 commit a578adc

File tree

2 files changed

+26
-12
lines changed

2 files changed

+26
-12
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,17 +49,20 @@ def run_weak_var_check (self, weak_varname, present):
4949

5050
def do_test(self):
5151
hidden_dir = os.path.join(self.getBuildDir(), "hidden")
52-
52+
hidden_dylib = os.path.join(hidden_dir, "libdylib.dylib")
53+
5354
launch_info = lldb.SBLaunchInfo(None)
5455
launch_info.SetWorkingDirectory(self.getBuildDir())
5556
# We have to point to the hidden directory to pick up the
5657
# version of the dylib without the weak symbols:
5758
env_expr = self.platformContext.shlib_environment_var + "=" + hidden_dir
5859
launch_info.SetEnvironmentEntries([env_expr], True)
59-
60-
(self.target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self,
61-
"Set a breakpoint here", self.main_source_file,
62-
launch_info = launch_info)
60+
61+
(self.target, _, thread, _) = lldbutil.run_to_source_breakpoint(
62+
self, "Set a breakpoint here",
63+
self.main_source_file,
64+
launch_info = launch_info,
65+
extra_images = [hidden_dylib])
6366
# First we have to import the Dylib module so we get the type info
6467
# for the weak symbol. We need to add the source dir to the module
6568
# search paths, and then run @import to introduce it into the expression

lldb/packages/Python/lldbsuite/test/lldbutil.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -760,13 +760,18 @@ def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
760760
test.assertTrue(target, "Target: %s is not valid."%(exe_name))
761761
return target
762762

763-
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None, only_one_thread = True):
763+
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None,
764+
only_one_thread = True, extra_images = None):
764765

765766
# Launch the process, and do not stop at the entry point.
766767
if not launch_info:
767768
launch_info = lldb.SBLaunchInfo(None)
768769
launch_info.SetWorkingDirectory(test.get_process_working_directory())
769770

771+
if extra_images and lldb.remote_platform:
772+
environ = test.registerSharedLibrariesWithTarget(target, extra_images)
773+
launch_info.SetEnvironmentEntries(environ, True)
774+
770775
error = lldb.SBError()
771776
process = target.Launch(launch_info, error)
772777

@@ -791,7 +796,8 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
791796
exe_name = "a.out",
792797
bkpt_module = None,
793798
in_cwd = True,
794-
only_one_thread = True):
799+
only_one_thread = True,
800+
extra_images = None):
795801
"""Start up a target, using exe_name as the executable, and run it to
796802
a breakpoint set by name on bkpt_name restricted to bkpt_module.
797803
@@ -827,13 +833,15 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
827833

828834
test.assertTrue(breakpoint.GetNumLocations() > 0,
829835
"No locations found for name breakpoint: '%s'."%(bkpt_name))
830-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
836+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
837+
only_one_thread, extra_images)
831838

832839
def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
833840
launch_info = None, exe_name = "a.out",
834841
bkpt_module = None,
835842
in_cwd = True,
836-
only_one_thread = True):
843+
only_one_thread = True,
844+
extra_images = None):
837845
"""Start up a target, using exe_name as the executable, and run it to
838846
a breakpoint set by source regex bkpt_pattern.
839847
@@ -847,13 +855,15 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
847855
test.assertTrue(breakpoint.GetNumLocations() > 0,
848856
'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
849857
%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
850-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
858+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
859+
only_one_thread, extra_images)
851860

852861
def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
853862
launch_info = None, exe_name = "a.out",
854863
bkpt_module = None,
855864
in_cwd = True,
856-
only_one_thread = True):
865+
only_one_thread = True,
866+
extra_images = None):
857867
"""Start up a target, using exe_name as the executable, and run it to
858868
a breakpoint set by (source_spec, line_number(, column)).
859869
@@ -868,7 +878,8 @@ def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
868878
'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
869879
%(source_spec.GetFilename(), line_number, column,
870880
source_spec.GetDirectory()))
871-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info, only_one_thread)
881+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
882+
only_one_thread, extra_images)
872883

873884

874885
def continue_to_breakpoint(process, bkpt):

0 commit comments

Comments
 (0)