Skip to content

Cherry pick testsuite improvements #610

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def setUp(self):
# Call super's setUp().
TestBase.setUp(self)
# Find the line number for our breakpoint.
self.breakpoint = line_number('main.cpp', '// Set breakpoint here')
self.bkpt_string = '// Set breakpoint here'
self.breakpoint = line_number('main.cpp', self.bkpt_string)

if "gcc" in self.getCompiler() or self.isIntelCompiler():
self.step_out_destination = line_number(
'main.cpp', '// Expect to stop here after step-out (icc and gcc)')
Expand Down Expand Up @@ -129,56 +131,27 @@ def step_out_with_python(self):

def step_out_test(self, step_out_func):
"""Test single thread step out of a function."""
exe = self.getBuildArtifact("a.out")
self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)

# This should create a breakpoint in the main thread.
lldbutil.run_break_set_by_file_and_line(
self, "main.cpp", self.breakpoint, num_expected_locations=1)

# The breakpoint list should show 1 location.
self.expect(
"breakpoint list -f",
"Breakpoint location shown correctly",
substrs=[
"1: file = 'main.cpp', line = %d, exact_match = 0, locations = 1" %
self.breakpoint])
(self.inferior_target, self.inferior_process, thread, bkpt) = lldbutil.run_to_source_breakpoint(
self, self.bkpt_string, lldb.SBFileSpec('main.cpp'), only_one_thread = False)

# Run the program.
self.runCmd("run", RUN_SUCCEEDED)

# Get the target process
self.inferior_target = self.dbg.GetSelectedTarget()
self.inferior_process = self.inferior_target.GetProcess()

# Get the number of threads, ensure we see all three.
num_threads = self.inferior_process.GetNumThreads()
self.assertEqual(
num_threads,
3,
'Number of expected threads and actual threads do not match.')
# We hit the breakpoint on at least one thread. If we hit it on both threads
# simultaneously, we can try the step out. Otherwise, suspend the thread
# that hit the breakpoint, and continue till the second thread hits
# the breakpoint:

(breakpoint_threads, other_threads) = ([], [])
lldbutil.sort_stopped_threads(self.inferior_process,
breakpoint_threads=breakpoint_threads,
other_threads=other_threads)

while len(breakpoint_threads) < 2:
self.runCmd("thread continue %s" %
" ".join([str(x.GetIndexID()) for x in other_threads]))
lldbutil.sort_stopped_threads(
self.inferior_process,
breakpoint_threads=breakpoint_threads,
other_threads=other_threads)
if len(breakpoint_threads) == 1:
success = thread.Suspend()
self.assertTrue(success, "Couldn't suspend a thread")
bkpt_threads = lldbutil.continue_to_breakpoint(bkpt)
self.assertEqual(len(bkpt_threads), 1, "Second thread stopped")
success = thread.Resume()
self.assertTrue(success, "Couldn't resume a thread")

self.step_out_thread = breakpoint_threads[0]

# Step out of thread stopped at breakpoint
step_out_func()

# Run to completion
self.runCmd("continue")

# At this point, the inferior process should have exited.
self.assertTrue(self.inferior_process.GetState() ==
lldb.eStateExited, PROCESS_EXITED)
40 changes: 32 additions & 8 deletions lldb/packages/Python/lldbsuite/test/lldbutil.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
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)

Expand All @@ -778,14 +783,21 @@ def run_to_breakpoint_do_run(test, target, bkpt, launch_info = None):
threads = get_threads_stopped_at_breakpoint(
process, bkpt)

test.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
num_threads = len(threads)
if only_one_thread:
test.assertEqual(num_threads, 1, "Expected 1 thread to stop at breakpoint, %d did."%(num_threads))
else:
test.assertGreater(num_threads, 0, "No threads stopped at breakpoint")

thread = threads[0]
return (target, process, thread, bkpt)

def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
exe_name = "a.out",
bkpt_module = None,
in_cwd = True):
in_cwd = 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.

Expand All @@ -807,6 +819,11 @@ def run_to_name_breakpoint (test, bkpt_name, launch_info = None,
If successful it returns a tuple with the target process and
thread that hit the breakpoint, and the breakpoint that we set
for you.

If only_one_thread is true, we require that there be only one
thread stopped at the breakpoint. Otherwise we only require one
or more threads stop there. If there are more than one, we return
the first thread that stopped.
"""

target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
Expand All @@ -816,12 +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)
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):
in_cwd = 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.

Expand All @@ -835,12 +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)
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):
in_cwd = 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)).

Expand All @@ -855,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)
return run_to_breakpoint_do_run(test, target, breakpoint, launch_info,
only_one_thread, extra_images)


def continue_to_breakpoint(process, bkpt):
Expand Down