Added lldbutil.run_to_name_breakpoint and use it in one test.
Using the "run_to_{source,name}_breakpoint will allow us to remove
a lot of boiler-plate from the testsuite. We mostly use source
breakpoints, but some tests use by name ones so this was needed.
llvm-svn: 324010
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 45f23b5..6ed982e 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -734,11 +734,44 @@
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):
+# Helper functions for run_to_{source,name}_breakpoint:
+
+def run_to_breakpoint_make_target(test, exe_name, in_cwd):
+ if in_cwd:
+ 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
+
+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:
+ launch_info = lldb.SBLaunchInfo(None)
+ launch_info.SetWorkingDirectory(test.get_process_working_directory())
+
+ error = lldb.SBError()
+ process = target.Launch(launch_info, error)
+
+ 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, bkpt)
+
+ test.assertTrue(len(threads) == 1, "Expected 1 thread to stop at breakpoint, %d did."%(len(threads)))
+ thread = threads[0]
+ return (target, process, thread, bkpt)
+
+def run_to_name_breakpoint (test, bkpt_name, 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.
+ a breakpoint set by name on bkpt_name.
If you want to pass in launch arguments or environment
variables, you can optionally pass in an SBLaunchInfo. If you
@@ -755,36 +788,29 @@
thread that hit the breakpoint.
"""
- if in_cwd:
- exe = test.getBuildArtifact(exe_name)
-
- # Create the target
- target = test.dbg.CreateTarget(exe)
- test.assertTrue(target, "Target: %s is not valid."%(exe_name))
+ target = run_to_breakpoint_make_target(test, exe_name, in_cwd)
+ breakpoint = target.BreakpointCreateByName(bkpt_name)
+ 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",
+ 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)
test.assertTrue(breakpoint.GetNumLocations() > 0,
'No locations found for source breakpoint: "%s", file: "%s", dir: "%s"'%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory()))
-
- # 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())
-
- 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()))
-
- # Frame #0 should be at our breakpoint.
- threads = get_threads_stopped_at_breakpoint(
- process, breakpoint)
-
- 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 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"""