Skip to content

Commit de2f97c

Browse files
committed
Merge commit 'refs/am/changes/52a408f2f102bc00b5c8a3d8a18909847f9bc7f3_swift/swift-5.2-branch' into HEAD
Conflicts: lldb/packages/Python/lldbsuite/test/lldbutil.py
2 parents 07ee53b + 52a408f commit de2f97c

File tree

3 files changed

+57
-56
lines changed

3 files changed

+57
-56
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/functionalities/thread/step_out/TestThreadStepOut.py

Lines changed: 16 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,9 @@ def setUp(self):
6868
# Call super's setUp().
6969
TestBase.setUp(self)
7070
# Find the line number for our breakpoint.
71-
self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
71+
self.bkpt_string = '// Set breakpoint here'
72+
self.breakpoint = line_number('main.cpp', self.bkpt_string)
73+
7274
if "gcc" in self.getCompiler() or self.isIntelCompiler():
7375
self.step_out_destination = line_number(
7476
'main.cpp', '// Expect to stop here after step-out (icc and gcc)')
@@ -129,56 +131,27 @@ def step_out_with_python(self):
129131

130132
def step_out_test(self, step_out_func):
131133
"""Test single thread step out of a function."""
132-
exe = self.getBuildArtifact("a.out")
133-
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
134-
135-
# This should create a breakpoint in the main thread.
136-
lldbutil.run_break_set_by_file_and_line(
137-
self, "main.cpp", self.breakpoint, num_expected_locations=1)
138-
139-
# The breakpoint list should show 1 location.
140-
self.expect(
141-
"breakpoint list -f",
142-
"Breakpoint location shown correctly",
143-
substrs=[
144-
"1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
145-
self.breakpoint])
134+
(self.inferior_target, self.inferior_process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
135+
self, self.bkpt_string, lldb.SBFileSpec('main.cpp'), only_one_thread = False)
146136

147-
# Run the program.
148-
self.runCmd("run", RUN_SUCCEEDED)
149-
150-
# Get the target process
151-
self.inferior_target = self.dbg.GetSelectedTarget()
152-
self.inferior_process = self.inferior_target.GetProcess()
153-
154-
# Get the number of threads, ensure we see all three.
155-
num_threads = self.inferior_process.GetNumThreads()
156-
self.assertEqual(
157-
num_threads,
158-
3,
159-
'Number of expected threads and actual threads do not match.')
137+
# We hit the breakpoint on at least one thread. If we hit it on both threads
138+
# simultaneously, we can try the step out. Otherwise, suspend the thread
139+
# that hit the breakpoint, and continue till the second thread hits
140+
# the breakpoint:
160141

161142
(breakpoint_threads, other_threads) = ([], [])
162143
lldbutil.sort_stopped_threads(self.inferior_process,
163144
breakpoint_threads=breakpoint_threads,
164145
other_threads=other_threads)
165-
166-
while len(breakpoint_threads) < 2:
167-
self.runCmd("thread continue %s" %
168-
" ".join([str(x.GetIndexID()) for x in other_threads]))
169-
lldbutil.sort_stopped_threads(
170-
self.inferior_process,
171-
breakpoint_threads=breakpoint_threads,
172-
other_threads=other_threads)
146+
if len(breakpoint_threads) == 1:
147+
success = thread.Suspend()
148+
self.assertTrue(success, "Couldn't suspend a thread")
149+
bkpt_threads = lldbutil.continue_to_breakpoint(bkpt)
150+
self.assertEqual(len(bkpt_threads), 1, "Second thread stopped")
151+
success = thread.Resume()
152+
self.assertTrue(success, "Couldn't resume a thread")
173153

174154
self.step_out_thread = breakpoint_threads[0]
175155

176156
# Step out of thread stopped at breakpoint
177157
step_out_func()
178-
179-
# Run to completion
180-
self.runCmd("continue")
181-
182-
# At this point, the inferior process should have exited.
183-
self.assertTrue(self.inferior_process.GetState() ==
184-
lldb.eStateExited, PROCESS_EXITED)

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

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

764-
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
764+
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None,
765+
only_one_thread = True, extra_images = None):
766+
765767
# Launch the process, and do not stop at the entry point.
766768
if not launch_info:
767769
launch_info = lldb.SBLaunchInfo(None)
768770
launch_info.SetWorkingDirectory(test.get_process_working_directory())
769771

772+
if extra_images and lldb.remote_platform:
773+
environ = test.registerSharedLibrariesWithTarget(target, extra_images)
774+
launch_info.SetEnvironmentEntries(environ, True)
775+
770776
error = lldb.SBError()
771777
process = target.Launch(launch_info, error)
772778

@@ -778,14 +784,21 @@ def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
778784
threads = get_threads_stopped_at_breakpoint(
779785
process, bkpt)
780786

781-
test.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
787+
num_threads = len(threads)
788+
if only_one_thread:
789+
test.assertEqual(num_threads, 1, "Expected 1 thread to stop at breakpoint, %d did."%(num_threads))
790+
else:
791+
test.assertGreater(num_threads, 0, "No threads stopped at breakpoint")
792+
782793
thread = threads[0]
783794
return (target, process, thread, bkpt)
784795

785796
def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
786797
exe_name = "a.out",
787798
bkpt_module = None,
788-
in_cwd = True):
799+
in_cwd = True,
800+
only_one_thread = True,
801+
extra_images = None):
789802
"""Start up a target, using exe_name as the executable, and run it to
790803
a breakpoint set by name on bkpt_name restricted to bkpt_module.
791804
@@ -807,6 +820,11 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
807820
If successful it returns a tuple with the target process and
808821
thread that hit the breakpoint, and the breakpoint that we set
809822
for you.
823+
824+
If only_one_thread is true, we require that there be only one
825+
thread stopped at the breakpoint. Otherwise we only require one
826+
or more threads stop there. If there are more than one, we return
827+
the first thread that stopped.
810828
"""
811829

812830
target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
@@ -816,12 +834,15 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
816834

817835
test.assertTrue(breakpoint.GetNumLocations() > 0,
818836
"No locations found for name breakpoint: '%s'."%(bkpt_name))
819-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
837+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
838+
only_one_thread, extra_images)
820839

821840
def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
822841
launch_info = None, exe_name = "a.out",
823842
bkpt_module = None,
824-
in_cwd = True):
843+
in_cwd = True,
844+
only_one_thread = True,
845+
extra_images = None):
825846
"""Start up a target, using exe_name as the executable, and run it to
826847
a breakpoint set by source regex bkpt_pattern.
827848
@@ -835,12 +856,15 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
835856
test.assertTrue(breakpoint.GetNumLocations() > 0,
836857
'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
837858
%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
838-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
859+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
860+
only_one_thread, extra_images)
839861

840862
def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
841863
launch_info = None, exe_name = "a.out",
842864
bkpt_module = None,
843-
in_cwd = True):
865+
in_cwd = True,
866+
only_one_thread = True,
867+
extra_images = None):
844868
"""Start up a target, using exe_name as the executable, and run it to
845869
a breakpoint set by (source_spec, line_number(, column)).
846870
@@ -855,7 +879,8 @@ def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
855879
'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
856880
%(source_spec.GetFilename(), line_number, column,
857881
source_spec.GetDirectory()))
858-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
882+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
883+
only_one_thread, extra_images)
859884

860885

861886
def continue_to_breakpoint(process, bkpt):

0 commit comments

Comments
 (0)