summaryrefslogtreecommitdiffstats
path: root/lldb/packages/Python/lldbsuite/test/lldbutil.py
diff options
context:
space:
mode:
authorJim Ingham <jingham@apple.com>2017-07-06 02:18:16 +0000
committerJim Ingham <jingham@apple.com>2017-07-06 02:18:16 +0000
commita15e7f296babc33d7565dc6c224a818a9597796b (patch)
treee6c4bc1fdc59886148171e58f9bb3a522200e731 /lldb/packages/Python/lldbsuite/test/lldbutil.py
parent35adb43950dc9be4e0efb0cc36f87e5be43cfff4 (diff)
downloadbcm5719-llvm-a15e7f296babc33d7565dc6c224a818a9597796b.tar.gz
bcm5719-llvm-a15e7f296babc33d7565dc6c224a818a9597796b.zip
Add a lldbutils routine that gathers up the boiler-plate
to make a target, set a source regex breakpoint, run to the breakpoint and find the thread that hit the breakpoint. Start the process of replacing the boiler plate with this routine. llvm-svn: 307234
Diffstat (limited to 'lldb/packages/Python/lldbsuite/test/lldbutil.py')
-rw-r--r--lldb/packages/Python/lldbsuite/test/lldbutil.py41
1 files changed, 41 insertions, 0 deletions
diff --git a/lldb/packages/Python/lldbsuite/test/lldbutil.py b/lldb/packages/Python/lldbsuite/test/lldbutil.py
index 7732dbe6dff..58a1ead1ea0 100644
--- a/lldb/packages/Python/lldbsuite/test/lldbutil.py
+++ b/lldb/packages/Python/lldbsuite/test/lldbutil.py
@@ -725,6 +725,47 @@ 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."""
+
+ if in_cwd:
+ exe = os.path.join(os.getcwd(), exe_name)
+
+ # Create the target
+ target = test.dbg.CreateTarget(exe)
+ test.assertTrue(target, "Target: %s is not valid."%(exe_name))
+
+ # Set the breakpoints
+ breakpoint = target.BreakpointCreateBySourceRegex(
+ bkpt_pattern, source_spec)
+ test.assertTrue(breakpoint.GetNumLocations() > 0,
+ 'No locations found for source breakpoint: "%s"'%(bkpt_pattern))
+
+ # 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)
def continue_to_breakpoint(process, bkpt):
""" Continues the process, if it stops, returns the threads stopped at bkpt; otherwise, returns None"""
OpenPOWER on IntegriCloud