Skip to content

Commit a075518

Browse files
committed
Merge commit 'refs/am/changes/de2f97ccec13e94e1c602bc4abf14c4c46265a6c_swift/master' into HEAD
Conflicts: lldb/packages/Python/lldbsuite/test/lldbutil.py
2 parents d8f0c65 + de2f97c commit a075518

File tree

3 files changed

+56
-59
lines changed

3 files changed

+56
-59
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: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -767,12 +767,18 @@ def run_to_breakpoint_make_target(test, exe_name = "a.out", in_cwd = True):
767767

768768
return target
769769

770-
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
770+
def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None,
771+
only_one_thread = True, extra_images = None):
772+
771773
# Launch the process, and do not stop at the entry point.
772774
if not launch_info:
773775
launch_info = target.GetLaunchInfo()
774776
launch_info.SetWorkingDirectory(test.get_process_working_directory())
775777

778+
if extra_images and lldb.remote_platform:
779+
environ = test.registerSharedLibrariesWithTarget(target, extra_images)
780+
launch_info.SetEnvironmentEntries(environ, True)
781+
776782
error = lldb.SBError()
777783
process = target.Launch(launch_info, error)
778784

@@ -784,18 +790,21 @@ def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
784790
threads = get_threads_stopped_at_breakpoint(
785791
process, bkpt)
786792

787-
buf = '\n'
788-
for i in range(launch_info.GetNumEnvironmentEntries()):
789-
buf += 'Env: ' + launch_info.GetEnvironmentEntryAtIndex(i) + '\n'
793+
num_threads = len(threads)
794+
if only_one_thread:
795+
test.assertEqual(num_threads, 1, "Expected 1 thread to stop at breakpoint, %d did."%(num_threads))
796+
else:
797+
test.assertGreater(num_threads, 0, "No threads stopped at breakpoint")
790798

791-
test.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did. Launch info: %s"%(len(threads), buf))
792799
thread = threads[0]
793800
return (target, process, thread, bkpt)
794801

795802
def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
796803
exe_name = "a.out",
797804
bkpt_module = None,
798-
in_cwd = True):
805+
in_cwd = True,
806+
only_one_thread = True,
807+
extra_images = None):
799808
"""Start up a target, using exe_name as the executable, and run it to
800809
a breakpoint set by name on bkpt_name restricted to bkpt_module.
801810
@@ -817,6 +826,11 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
817826
If successful it returns a tuple with the target process and
818827
thread that hit the breakpoint, and the breakpoint that we set
819828
for you.
829+
830+
If only_one_thread is true, we require that there be only one
831+
thread stopped at the breakpoint. Otherwise we only require one
832+
or more threads stop there. If there are more than one, we return
833+
the first thread that stopped.
820834
"""
821835

822836
target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
@@ -826,12 +840,15 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
826840

827841
test.assertTrue(breakpoint.GetNumLocations() > 0,
828842
"No locations found for name breakpoint: '%s'."%(bkpt_name))
829-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
843+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
844+
only_one_thread, extra_images)
830845

831846
def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
832847
launch_info = None, exe_name = "a.out",
833848
bkpt_module = None,
834-
in_cwd = True):
849+
in_cwd = True,
850+
only_one_thread = True,
851+
extra_images = None):
835852
"""Start up a target, using exe_name as the executable, and run it to
836853
a breakpoint set by source regex bkpt_pattern.
837854
@@ -845,12 +862,15 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
845862
test.assertTrue(breakpoint.GetNumLocations() > 0,
846863
'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'
847864
%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
848-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
865+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
866+
only_one_thread, extra_images)
849867

850868
def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
851869
launch_info = None, exe_name = "a.out",
852870
bkpt_module = None,
853-
in_cwd = True):
871+
in_cwd = True,
872+
only_one_thread = True,
873+
extra_images = None):
854874
"""Start up a target, using exe_name as the executable, and run it to
855875
a breakpoint set by (source_spec, line_number(, column)).
856876
@@ -865,7 +885,8 @@ def run_to_line_breakpoint(test, source_spec, line_number, column = 0,
865885
'No locations found for line breakpoint: "%s:%d(:%d)", dir: "%s"'
866886
%(source_spec.GetFilename(), line_number, column,
867887
source_spec.GetDirectory()))
868-
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info)
888+
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
889+
only_one_thread, extra_images)
869890

870891

871892
def continue_to_breakpoint(process, bkpt):

0 commit comments

Comments
 (0)