1""" 2Test jumping to different places. 3""" 4 5 6 7import lldb 8from lldbsuite.test.decorators import * 9from lldbsuite.test.lldbtest import * 10from lldbsuite.test import lldbutil 11 12 13class ThreadJumpTestCase(TestBase): 14 15 mydir = TestBase.compute_mydir(__file__) 16 17 def test(self): 18 """Test thread jump handling.""" 19 self.build(dictionary=self.getBuildFlags()) 20 exe = self.getBuildArtifact("a.out") 21 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) 22 23 # Find the line numbers for our breakpoints. 24 self.mark1 = line_number('main.cpp', '// 1st marker') 25 self.mark2 = line_number('main.cpp', '// 2nd marker') 26 self.mark3 = line_number('main.cpp', '// 3rd marker') 27 self.mark4 = line_number('main.cpp', '// 4th marker') 28 self.mark5 = line_number('other.cpp', '// other marker') 29 30 lldbutil.run_break_set_by_file_and_line( 31 self, "main.cpp", self.mark3, num_expected_locations=1) 32 self.runCmd("run", RUN_SUCCEEDED) 33 34 # The stop reason of the thread should be breakpoint 1. 35 self.expect( 36 "thread list", 37 STOPPED_DUE_TO_BREAKPOINT + " 1", 38 substrs=[ 39 'stopped', 40 'main.cpp:{}'.format( 41 self.mark3), 42 'stop reason = breakpoint 1']) 43 44 # Try the int path, force it to return 'a' 45 self.do_min_test(self.mark3, self.mark1, "i", "4") 46 # Try the int path, force it to return 'b' 47 self.do_min_test(self.mark3, self.mark2, "i", "5") 48 # Try the double path, force it to return 'a' 49 self.do_min_test(self.mark4, self.mark1, "j", "7") 50 # Expected to fail on powerpc64le architecture 51 if not self.isPPC64le(): 52 # Try the double path, force it to return 'b' 53 self.do_min_test(self.mark4, self.mark2, "j", "8") 54 55 # Try jumping to another function in a different file. 56 self.runCmd( 57 "thread jump --file other.cpp --line %i --force" % 58 self.mark5) 59 self.expect("process status", 60 substrs=["at other.cpp:%i" % self.mark5]) 61 62 # Try jumping to another function (without forcing) 63 self.expect( 64 "j main.cpp:%i" % 65 self.mark1, 66 COMMAND_FAILED_AS_EXPECTED, 67 error=True, 68 substrs=["error"]) 69 70 def do_min_test(self, start, jump, var, value): 71 # jump to the start marker 72 self.runCmd("j %i" % start) 73 self.runCmd("thread step-in") # step into the min fn 74 # jump to the branch we're interested in 75 self.runCmd("j %i" % jump) 76 self.runCmd("thread step-out") # return out 77 self.runCmd("thread step-over") # assign to the global 78 self.expect("expr %s" % var, substrs=[value]) # check it 79