1""" 2Tests stepping with scripted thread plans. 3""" 4 5import lldb 6import lldbsuite.test.lldbutil as lldbutil 7from lldbsuite.test.decorators import * 8from lldbsuite.test.lldbtest import * 9 10class StepScriptedTestCase(TestBase): 11 12 mydir = TestBase.compute_mydir(__file__) 13 14 NO_DEBUG_INFO_TESTCASE = True 15 16 def setUp(self): 17 TestBase.setUp(self) 18 self.main_source_file = lldb.SBFileSpec("main.c") 19 self.runCmd("command script import Steps.py") 20 21 @skipIfReproducer # Unexpected packet during replay 22 def test_standard_step_out(self): 23 """Tests stepping with the scripted thread plan laying over a standard 24 thread plan for stepping out.""" 25 self.build() 26 self.step_out_with_scripted_plan("Steps.StepOut") 27 28 @skipIfReproducer # Unexpected packet during replay 29 def test_scripted_step_out(self): 30 """Tests stepping with the scripted thread plan laying over an another 31 scripted thread plan for stepping out.""" 32 self.build() 33 self.step_out_with_scripted_plan("Steps.StepScripted") 34 35 def step_out_with_scripted_plan(self, name): 36 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 37 "Set a breakpoint here", 38 self.main_source_file) 39 40 frame = thread.GetFrameAtIndex(0) 41 self.assertEqual("foo", frame.GetFunctionName()) 42 43 err = thread.StepUsingScriptedThreadPlan(name) 44 self.assertTrue(err.Success(), err.GetCString()) 45 46 frame = thread.GetFrameAtIndex(0) 47 self.assertEqual("main", frame.GetFunctionName()) 48 49 50 def test_misspelled_plan_name(self): 51 """Test that we get a useful error if we misspell the plan class name""" 52 self.build() 53 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 54 "Set a breakpoint here", 55 self.main_source_file) 56 stop_id = process.GetStopID() 57 # Pass a non-existent class for the plan class: 58 err = thread.StepUsingScriptedThreadPlan("NoSuchModule.NoSuchPlan") 59 60 # Make sure we got a good error: 61 self.assertTrue(err.Fail(), "We got a failure state") 62 msg = err.GetCString() 63 self.assertTrue("NoSuchModule.NoSuchPlan" in msg, "Mentioned missing class") 64 65 # Make sure we didn't let the process run: 66 self.assertEqual(stop_id, process.GetStopID(), "Process didn't run") 67 68 @skipIfReproducer # Unexpected packet during replay 69 def test_checking_variable(self): 70 """Test that we can call SBValue API's from a scripted thread plan - using SBAPI's to step""" 71 self.do_test_checking_variable(False) 72 73 @skipIfReproducer # Unexpected packet during replay 74 def test_checking_variable_cli(self): 75 """Test that we can call SBValue API's from a scripted thread plan - using cli to step""" 76 self.do_test_checking_variable(True) 77 78 def do_test_checking_variable(self, use_cli): 79 self.build() 80 (target, process, thread, bkpt) = lldbutil.run_to_source_breakpoint(self, 81 "Set a breakpoint here", 82 self.main_source_file) 83 84 frame = thread.GetFrameAtIndex(0) 85 self.assertEqual("foo", frame.GetFunctionName()) 86 foo_val = frame.FindVariable("foo") 87 self.assertTrue(foo_val.GetError().Success(), "Got the foo variable") 88 self.assertEqual(foo_val.GetValueAsUnsigned(), 10, "foo starts at 10") 89 90 if use_cli: 91 result = lldb.SBCommandReturnObject() 92 self.dbg.GetCommandInterpreter().HandleCommand( 93 "thread step-scripted -C Steps.StepUntil -k variable_name -v foo", 94 result) 95 self.assertTrue(result.Succeeded()) 96 else: 97 args_data = lldb.SBStructuredData() 98 data = lldb.SBStream() 99 data.Print('{"variable_name" : "foo"}') 100 error = args_data.SetFromJSON(data) 101 self.assertTrue(error.Success(), "Made the args_data correctly") 102 103 err = thread.StepUsingScriptedThreadPlan("Steps.StepUntil", args_data, True) 104 self.assertTrue(err.Success(), err.GetCString()) 105 106 # We should not have exited: 107 self.assertEqual(process.GetState(), lldb.eStateStopped, "We are stopped") 108 109 # We should still be in foo: 110 self.assertEqual("foo", frame.GetFunctionName()) 111 112 # And foo should have changed: 113 self.assertTrue(foo_val.GetValueDidChange(), "Foo changed") 114