Richard Mitton | f86248d | 2013-09-12 02:20:34 +0000 | [diff] [blame^] | 1 | """ |
| 2 | Test jumping to different places. |
| 3 | """ |
| 4 | |
| 5 | import os, time |
| 6 | import unittest2 |
| 7 | import lldb |
| 8 | from lldbtest import * |
| 9 | import lldbutil |
| 10 | |
| 11 | class ThreadJumpTestCase(TestBase): |
| 12 | |
| 13 | mydir = os.path.join("functionalities", "thread", "jump") |
| 14 | |
| 15 | @unittest2.skipUnless(sys.platform.startswith("darwin"), "requires Darwin") |
| 16 | @dsym_test |
| 17 | def test_with_dsym(self): |
| 18 | """Test thread jump handling.""" |
| 19 | self.buildDsym(dictionary=self.getBuildFlags()) |
| 20 | self.thread_jump_test() |
| 21 | |
| 22 | @dwarf_test |
| 23 | def test_with_dwarf(self): |
| 24 | """Test thread jump handling.""" |
| 25 | self.buildDwarf(dictionary=self.getBuildFlags()) |
| 26 | self.thread_jump_test() |
| 27 | |
| 28 | def do_min_test(self, start, jump, var, value): |
| 29 | self.runCmd("j %i" % start) # jump to the start marker |
| 30 | self.runCmd("thread step-in") # step into the min fn |
| 31 | self.runCmd("j %i" % jump) # jump to the branch we're interested in |
| 32 | self.runCmd("thread step-out") # return out |
| 33 | self.runCmd("thread step-over") # assign to the global |
| 34 | self.expect("expr %s" % var, substrs = [value]) # check it |
| 35 | |
| 36 | def thread_jump_test(self): |
| 37 | """Test thread exit handling.""" |
| 38 | exe = os.path.join(os.getcwd(), "a.out") |
| 39 | self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET) |
| 40 | |
| 41 | # Find the line numbers for our breakpoints. |
| 42 | self.mark1 = line_number('main.cpp', '// 1st marker') |
| 43 | self.mark2 = line_number('main.cpp', '// 2nd marker') |
| 44 | self.mark3 = line_number('main.cpp', '// 3rd marker') |
| 45 | self.mark4 = line_number('main.cpp', '// 4th marker') |
| 46 | self.mark5 = line_number('other.cpp', '// other marker') |
| 47 | |
| 48 | lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.mark3, num_expected_locations=1) |
| 49 | self.runCmd("run", RUN_SUCCEEDED) |
| 50 | |
| 51 | # The stop reason of the thread should be breakpoint 1. |
| 52 | self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 1", |
| 53 | substrs = ['stopped', |
| 54 | '* thread #1', |
| 55 | 'stop reason = breakpoint 1']) |
| 56 | |
| 57 | self.do_min_test(self.mark3, self.mark1, "i", "4"); # Try the int path, force it to return 'a' |
| 58 | self.do_min_test(self.mark3, self.mark2, "i", "5"); # Try the int path, force it to return 'b' |
| 59 | self.do_min_test(self.mark4, self.mark1, "j", "7"); # Try the double path, force it to return 'a' |
| 60 | self.do_min_test(self.mark4, self.mark2, "j", "8"); # Try the double path, force it to return 'b' |
| 61 | |
| 62 | # Try jumping to another function in a different file. |
| 63 | self.runCmd("thread jump --file other.cpp --line %i --force" % self.mark5) |
| 64 | self.expect("process status", |
| 65 | substrs = ["at other.cpp:%i" % self.mark5]) |
| 66 | |
| 67 | # Try jumping to another function (without forcing) |
| 68 | self.expect("j main.cpp:%i" % self.mark1, COMMAND_FAILED_AS_EXPECTED, error = True, |
| 69 | substrs = ["error"]) |
| 70 | |
| 71 | if __name__ == '__main__': |
| 72 | import atexit |
| 73 | lldb.SBDebugger.Initialize() |
| 74 | atexit.register(lambda: lldb.SBDebugger.Terminate()) |
| 75 | unittest2.main() |