Author: jingham Date: Thu Feb 1 13:35:50 2018 New Revision: 324010 URL: http://llvm.org/viewvc/llvm-project?rev=324010&view=rev Log: 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. Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/return-value/TestReturnValue.py lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py Modified: lldb/trunk/packages/Python/lldbsuite/test/functionalities/return-value/TestReturnValue.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/functionalities/return-value/TestReturnValue.py?rev=324010&r1=324009&r2=324010&view=diff ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/functionalities/return-value/TestReturnValue.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/functionalities/return-value/TestReturnValue.py Thu Feb 1 13:35:50 2018 @@ -41,27 +41,9 @@ class ReturnValueTestCase(TestBase): """Test getting return values from stepping out.""" self.build() exe = self.getBuildArtifact("a.out") - error = lldb.SBError() - - self.target = self.dbg.CreateTarget(exe) - self.assertTrue(self.target, VALID_TARGET) - - inner_sint_bkpt = self.target.BreakpointCreateByName("inner_sint", exe) - self.assertTrue(inner_sint_bkpt, VALID_BREAKPOINT) - - # Now launch the process, and do not stop at entry point. - self.process = self.target.LaunchSimple( - None, None, self.get_process_working_directory()) + (self.target, self.process, thread, inner_sint_bkpt) = lldbutil.run_to_name_breakpoint(self, "inner_sint", exe_name = exe) - self.assertTrue(self.process, PROCESS_IS_VALID) - - # The stop reason of the thread should be breakpoint. - self.assertTrue(self.process.GetState() == lldb.eStateStopped, - STOPPED_DUE_TO_BREAKPOINT) - - # Now finish, and make sure the return value is correct. - thread = lldbutil.get_stopped_thread( - self.process, lldb.eStopReasonBreakpoint) + error = lldb.SBError() # inner_sint returns the variable value, so capture that here: in_int = thread.GetFrameAtIndex(0).FindVariable( @@ -86,10 +68,8 @@ class ReturnValueTestCase(TestBase): # Run again and we will stop in inner_sint the second time outer_sint is called. # Then test stepping out two frames at once: - - self.process.Continue() - thread_list = lldbutil.get_threads_stopped_at_breakpoint( - self.process, inner_sint_bkpt) + + thread_list = lldbutil.continue_to_breakpoint(self.process, inner_sint_bkpt) self.assertTrue(len(thread_list) == 1) thread = thread_list[0] Modified: lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py URL: http://llvm.org/viewvc/llvm-project/lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py?rev=324010&r1=324009&r2=324010&view=diff ============================================================================== --- lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py (original) +++ lldb/trunk/packages/Python/lldbsuite/test/lldbutil.py Thu Feb 1 13:35:50 2018 @@ -734,39 +734,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 = 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", file: "%s", dir: "%s"'%(bkpt_pattern, source_spec.GetFilename(), source_spec.GetDirectory())) +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: @@ -776,15 +755,62 @@ def run_to_source_breakpoint(test, bkpt_ 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", + 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. + + 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. + """ + + 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())) + 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""" _______________________________________________ lldb-commits mailing list lldb-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/lldb-commits