summaryrefslogtreecommitdiff
path: root/packages/Python/lldbsuite/test/lldbutil.py
diff options
context:
space:
mode:
Diffstat (limited to 'packages/Python/lldbsuite/test/lldbutil.py')
-rw-r--r--packages/Python/lldbsuite/test/lldbutil.py125
1 files changed, 95 insertions, 30 deletions
diff --git a/packages/Python/lldbsuite/test/lldbutil.py b/packages/Python/lldbsuite/test/lldbutil.py
index 58a1ead1ea0bd..90ac799f4897e 100644
--- a/packages/Python/lldbsuite/test/lldbutil.py
+++ b/packages/Python/lldbsuite/test/lldbutil.py
@@ -9,6 +9,7 @@ from __future__ import absolute_import
# System modules
import collections
+import errno
import os
import re
import sys
@@ -44,6 +45,14 @@ def which(program):
return exe_file
return None
+def mkdir_p(path):
+ try:
+ os.makedirs(path)
+ except OSError as e:
+ if e.errno != errno.EEXIST:
+ raise
+ if not os.path.isdir(path):
+ raise OSError(errno.ENOTDIR, "%s is not a directory"%path)
# ===================================================
# Disassembly for an SBFunction or an SBSymbol object
# ===================================================
@@ -334,7 +343,8 @@ def run_break_set_by_file_and_line(
If extra_options is not None, then we append it to the breakpoint set command.
- If num_expected_locations is -1 we check that we got AT LEAST one location, otherwise we check that num_expected_locations equals the number of locations.
+ If num_expected_locations is -1, we check that we got AT LEAST one location. If num_expected_locations is -2, we don't
+ check the actual number at all. Otherwise, we check that num_expected_locations equals the number of locations.
If loc_exact is true, we check that there is one location, and that location must be at the input file and line number."""
@@ -554,7 +564,7 @@ def check_breakpoint_result(
if num_locations == -1:
test.assertTrue(out_num_locations > 0,
"Expecting one or more locations, got none.")
- else:
+ elif num_locations != -2:
test.assertTrue(
num_locations == out_num_locations,
"Expecting %d locations, got %d." %
@@ -566,7 +576,7 @@ def check_breakpoint_result(
if 'file' in break_results:
out_file_name = break_results['file']
test.assertTrue(
- file_name == out_file_name,
+ file_name.endswith(out_file_name),
"Breakpoint file name '%s' doesn't match resultant name '%s'." %
(file_name,
out_file_name))
@@ -725,29 +735,18 @@ def get_crashed_threads(test, process):
threads.append(thread)
return threads
-def run_to_source_breakpoint(test, bkpt_pattern, source_spec, launch_info = None, exe_name = "a.out", in_cwd = True):
- """Start up a target, using exe_name as the executable, and run it to
- a breakpoint set by source regex bkpt_pattern.
- If you want to pass in launch arguments or environment variables, you can optionally pass in
- an SBLaunchInfo. If you do that, remember to set the working directory as well.
- If your executable isn't called a.out, you can pass that in. And if your executable isn't
- in the CWD, pass in the absolute path to the executable in exe_name, and set in_cwd to False.
- If the target isn't valid, the breakpoint isn't found, or hit, the
- function will cause a testsuite failure.
- If successful it returns a tuple with the target process and thread that hit the breakpoint."""
+# Helper functions for run_to_{source,name}_breakpoint:
+def run_to_breakpoint_make_target(test, exe_name, in_cwd):
if in_cwd:
- exe = os.path.join(os.getcwd(), exe_name)
+ exe = test.getBuildArtifact(exe_name)
# Create the target
target = test.dbg.CreateTarget(exe)
test.assertTrue(target, "Target: %s is not valid."%(exe_name))
+ return target
- # Set the breakpoints
- breakpoint = target.BreakpointCreateBySourceRegex(
- bkpt_pattern, source_spec)
- test.assertTrue(breakpoint.GetNumLocations() > 0,
- 'No locations found for source breakpoint: "%s"'%(bkpt_pattern))
+def run_to_breakpoint_do_run(test, target, bkpt, launch_info):
# Launch the process, and do not stop at the entry point.
if not launch_info:
@@ -757,15 +756,71 @@ def run_to_source_breakpoint(test, bkpt_pattern, source_spec, launch_info = None
error = lldb.SBError()
process = target.Launch(launch_info, error)
- test.assertTrue(process, "Could not create a valid process for %s: %s"%(exe_name, error.GetCString()))
+ test.assertTrue(process,
+ "Could not create a valid process for %s: %s"%(target.GetExecutable().GetFilename(),
+ error.GetCString()))
# Frame #0 should be at our breakpoint.
threads = get_threads_stopped_at_breakpoint(
- process, breakpoint)
+ process, bkpt)
test.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
thread = threads[0]
- return (target, process, thread, breakpoint)
+ 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):
+ """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.
+
+ If you want to pass in launch arguments or environment
+ variables, you can optionally pass in an SBLaunchInfo. If you
+ do that, remember to set the working directory as well.
+
+ If your executable isn't called a.out, you can pass that in.
+ And if your executable isn't in the CWD, pass in the absolute
+ path to the executable in exe_name, and set in_cwd to False.
+
+ If you need to restrict the breakpoint to a particular module,
+ pass the module name (a string not a FileSpec) in bkpt_module. If
+ nothing is passed in setting will be unrestricted.
+
+ If the target isn't valid, the breakpoint isn't found, or hit, the
+ function will cause a testsuite failure.
+
+ If successful it returns a tuple with the target process and
+ thread that hit the breakpoint, and the breakpoint that we set
+ for you.
+ """
+
+ target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
+
+ breakpoint = target.BreakpointCreateByName(bkpt_name, bkpt_module)
+
+
+ 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)
+
+def run_to_source_breakpoint(test, bkpt_pattern, source_spec,
+ launch_info = None, exe_name = "a.out",
+ bkpt_module = None,
+ in_cwd = True):
+ """Start up a target, using exe_name as the executable, and run it to
+ a breakpoint set by source regex bkpt_pattern.
+
+ The rest of the behavior is the same as run_to_name_breakpoint.
+ """
+
+ target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
+ # Set the breakpoints
+ breakpoint = target.BreakpointCreateBySourceRegex(
+ bkpt_pattern, source_spec, bkpt_module)
+ 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)
def continue_to_breakpoint(process, bkpt):
""" Continues the process, if it stops, returns the threads stopped at bkpt; otherwise, returns None"""
@@ -1195,11 +1250,11 @@ def join_remote_paths(*paths):
return os.path.join(*paths).replace(os.path.sep, '/')
-def append_to_process_working_directory(*paths):
+def append_to_process_working_directory(test, *paths):
remote = lldb.remote_platform
if remote:
return join_remote_paths(remote.GetWorkingDirectory(), *paths)
- return os.path.join(os.getcwd(), *paths)
+ return os.path.join(test.getBuildDir(), *paths)
# ==================================================
# Utility functions to get the correct signal number
@@ -1266,6 +1321,21 @@ def skip_if_library_missing(test, target, library):
target))
+def read_file_on_target(test, remote):
+ if lldb.remote_platform:
+ local = test.getBuildArtifact("file_from_target")
+ error = lldb.remote_platform.Get(lldb.SBFileSpec(remote, False),
+ lldb.SBFileSpec(local, True))
+ test.assertTrue(error.Success(), "Reading file {0} failed: {1}".format(remote, error))
+ else:
+ local = remote
+ with open(local, 'r') as f:
+ return f.read()
+
+def read_file_from_process_wd(test, name):
+ path = append_to_process_working_directory(test, name)
+ return read_file_on_target(test, path)
+
def wait_for_file_on_target(testcase, file_path, max_attempts=6):
for i in range(max_attempts):
err, retcode, msg = testcase.run_platform_command("ls %s" % file_path)
@@ -1280,9 +1350,4 @@ def wait_for_file_on_target(testcase, file_path, max_attempts=6):
"File %s not found even after %d attempts." %
(file_path, max_attempts))
- err, retcode, data = testcase.run_platform_command("cat %s" % (file_path))
-
- testcase.assertTrue(
- err.Success() and retcode == 0, "Failed to read file %s: %s, retcode: %d" %
- (file_path, err.GetCString(), retcode))
- return data
+ return read_file_on_target(testcase, file_path)