Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 1 | """ |
| 2 | Test jumping to different places. |
| 3 | """ |
| 4 | |
Zachary Turner | 35d017f | 2015-10-23 17:04:29 +0000 | [diff] [blame] | 5 | from __future__ import print_function |
| 6 | |
Zachary Turner | 0a0490b | 2015-10-27 20:12:05 +0000 | [diff] [blame^] | 7 | import use_lldb_suite |
Zachary Turner | 77db4a8 | 2015-10-22 20:06:20 +0000 | [diff] [blame] | 8 | |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 9 | import os, time |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 10 | import lldb |
| 11 | from lldbtest import * |
| 12 | import lldbutil |
| 13 | |
| 14 | class ThreadJumpTestCase(TestBase): |
| 15 | |
Greg Clayton | 4570d3e | 2013-12-10 23:19:29 +0000 | [diff] [blame] | 16 | mydir = TestBase.compute_mydir(__file__) |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 17 | |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 18 | def test(self): |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 19 | """Test thread jump handling.""" |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 20 | self.build(dictionary=self.getBuildFlags()) |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 21 | exe = os.path.join(os.getcwd(), "a.out") |
| 22 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 23 | |
| 24 | # Find the line numbers for our breakpoints. |
| 25 | self.mark1 = line_number('main.cpp', '// 1st marker') |
| 26 | self.mark2 = line_number('main.cpp', '// 2nd marker') |
| 27 | self.mark3 = line_number('main.cpp', '// 3rd marker') |
| 28 | self.mark4 = line_number('main.cpp', '// 4th marker') |
| 29 | self.mark5 = line_number('other.cpp', '// other marker') |
| 30 | |
| 31 | lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.mark3, num_expected_locations=1) |
Sean Callanan | 05834cd | 2015-07-01 23:56:30 +0000 | [diff] [blame] | 32 | self.runCmd("run", RUN_SUCCEEDED) |
Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame] | 33 | |
| 34 | # The stop reason of the thread should be breakpoint 1. |
| 35 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 1", |
| 36 | substrs = ['stopped', |
| 37 | '* thread #1', |
| 38 | 'stop reason = breakpoint 1']) |
| 39 | |
| 40 | self.do_min_test(self.mark3, self.mark1, "i", "4"); # Try the int path, force it to return 'a' |
| 41 | self.do_min_test(self.mark3, self.mark2, "i", "5"); # Try the int path, force it to return 'b' |
| 42 | self.do_min_test(self.mark4, self.mark1, "j", "7"); # Try the double path, force it to return 'a' |
| 43 | self.do_min_test(self.mark4, self.mark2, "j", "8"); # Try the double path, force it to return 'b' |
| 44 | |
| 45 | # Try jumping to another function in a different file. |
| 46 | self.runCmd("thread jump --file other.cpp --line %i --force" % self.mark5) |
| 47 | self.expect("process status", |
| 48 | substrs = ["at other.cpp:%i" % self.mark5]) |
| 49 | |
| 50 | # Try jumping to another function (without forcing) |
| 51 | self.expect("j main.cpp:%i" % self.mark1, COMMAND_FAILED_AS_EXPECTED, error = True, |
| 52 | substrs = ["error"]) |
Tamas Berghammer | c8fd130 | 2015-09-30 10:12:40 +0000 | [diff] [blame] | 53 | |
| 54 | def do_min_test(self, start, jump, var, value): |
| 55 | self.runCmd("j %i" % start) # jump to the start marker |
| 56 | self.runCmd("thread step-in") # step into the min fn |
| 57 | self.runCmd("j %i" % jump) # jump to the branch we're interested in |
| 58 | self.runCmd("thread step-out") # return out |
| 59 | self.runCmd("thread step-over") # assign to the global |
| 60 | self.expect("expr %s" % var, substrs = [value]) # check it |