blob: a9b06863a72b4d78dace76e5d0c9b65c92150051 [file] [log] [blame]
Richard Mittonf86248d2013-09-12 02:20:34 +00001"""
2Test jumping to different places.
3"""
4
Zachary Turner77db4a82015-10-22 20:06:20 +00005import lldb_shared
6
Richard Mittonf86248d2013-09-12 02:20:34 +00007import os, time
Richard Mittonf86248d2013-09-12 02:20:34 +00008import lldb
9from lldbtest import *
10import lldbutil
11
12class ThreadJumpTestCase(TestBase):
13
Greg Clayton4570d3e2013-12-10 23:19:29 +000014 mydir = TestBase.compute_mydir(__file__)
Richard Mittonf86248d2013-09-12 02:20:34 +000015
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000016 def test(self):
Richard Mittonf86248d2013-09-12 02:20:34 +000017 """Test thread jump handling."""
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000018 self.build(dictionary=self.getBuildFlags())
Richard Mittonf86248d2013-09-12 02:20:34 +000019 exe = os.path.join(os.getcwd(), "a.out")
20 self.runCmd("file " + exe, CURRENT_EXECUTABLE_SET)
21
22 # Find the line numbers for our breakpoints.
23 self.mark1 = line_number('main.cpp', '// 1st marker')
24 self.mark2 = line_number('main.cpp', '// 2nd marker')
25 self.mark3 = line_number('main.cpp', '// 3rd marker')
26 self.mark4 = line_number('main.cpp', '// 4th marker')
27 self.mark5 = line_number('other.cpp', '// other marker')
28
29 lldbutil.run_break_set_by_file_and_line (self, "main.cpp", self.mark3, num_expected_locations=1)
Sean Callanan05834cd2015-07-01 23:56:30 +000030 self.runCmd("run", RUN_SUCCEEDED)
Richard Mittonf86248d2013-09-12 02:20:34 +000031
32 # The stop reason of the thread should be breakpoint 1.
33 self.expect("thread list", STOPPED_DUE_TO_BREAKPOINT + " 1",
34 substrs = ['stopped',
35 '* thread #1',
36 'stop reason = breakpoint 1'])
37
38 self.do_min_test(self.mark3, self.mark1, "i", "4"); # Try the int path, force it to return 'a'
39 self.do_min_test(self.mark3, self.mark2, "i", "5"); # Try the int path, force it to return 'b'
40 self.do_min_test(self.mark4, self.mark1, "j", "7"); # Try the double path, force it to return 'a'
41 self.do_min_test(self.mark4, self.mark2, "j", "8"); # Try the double path, force it to return 'b'
42
43 # Try jumping to another function in a different file.
44 self.runCmd("thread jump --file other.cpp --line %i --force" % self.mark5)
45 self.expect("process status",
46 substrs = ["at other.cpp:%i" % self.mark5])
47
48 # Try jumping to another function (without forcing)
49 self.expect("j main.cpp:%i" % self.mark1, COMMAND_FAILED_AS_EXPECTED, error = True,
50 substrs = ["error"])
Tamas Berghammerc8fd1302015-09-30 10:12:40 +000051
52 def do_min_test(self, start, jump, var, value):
53 self.runCmd("j %i" % start) # jump to the start marker
54 self.runCmd("thread step-in") # step into the min fn
55 self.runCmd("j %i" % jump) # jump to the branch we're interested in
56 self.runCmd("thread step-out") # return out
57 self.runCmd("thread step-over") # assign to the global
58 self.expect("expr %s" % var, substrs = [value]) # check it