]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/thread/step_until/TestStepUntil.py
Vendor import of lldb trunk r338536:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / thread / step_until / TestStepUntil.py
1 """Test stepping over vrs. hitting breakpoints & subsequent stepping in various forms."""
2
3 from __future__ import print_function
4
5
6 import os
7 import time
8 import lldb
9 from lldbsuite.test.decorators import *
10 from lldbsuite.test.lldbtest import *
11 from lldbsuite.test import lldbutil
12
13
14 class StepUntilTestCase(TestBase):
15
16     mydir = TestBase.compute_mydir(__file__)
17
18     def setUp(self):
19         # Call super's setUp().
20         TestBase.setUp(self)
21         # Find the line numbers that we will step to in main:
22         self.main_source = "main.c"
23         self.less_than_two = line_number('main.c', 'Less than 2')
24         self.greater_than_two = line_number('main.c', 'Greater than or equal to 2.')
25         self.back_out_in_main = line_number('main.c', 'Back out in main')
26
27     def do_until (self, args, until_lines, expected_linenum):
28         self.build()
29         exe = self.getBuildArtifact("a.out")
30
31         target = self.dbg.CreateTarget(exe)
32         self.assertTrue(target, VALID_TARGET)
33
34         main_source_spec = lldb.SBFileSpec(self.main_source)
35         break_before = target.BreakpointCreateBySourceRegex(
36             'At the start',
37             main_source_spec)
38         self.assertTrue(break_before, VALID_BREAKPOINT)
39
40         # Now launch the process, and do not stop at entry point.
41         process = target.LaunchSimple(
42             args, None, self.get_process_working_directory())
43
44         self.assertTrue(process, PROCESS_IS_VALID)
45
46         # The stop reason of the thread should be breakpoint.
47         threads = lldbutil.get_threads_stopped_at_breakpoint(
48             process, break_before)
49
50         if len(threads) != 1:
51             self.fail("Failed to stop at first breakpoint in main.")
52
53         thread = threads[0]
54         return thread
55
56         thread = self.common_setup(None)
57
58         cmd_interp = self.dbg.GetCommandInterpreter()
59         ret_obj = lldb.SBCommandReturnObject()
60
61         cmd_line = "thread until"
62         for line_num in until_lines:
63             cmd_line += " %d"%(line_num)
64
65         cmd_interp.HandleCommand(cmd_line, ret_obj)
66         self.assertTrue(ret_obj.Succeeded(), "'%s' failed: %s."%(cmd_line, ret_obj.GetError()))
67
68         frame = thread.frames[0]
69         line = frame.GetLineEntry().GetLine()
70         self.assertEqual(line, expected_linenum, 'Did not get the expected stop line number')
71
72     def test_hitting_one (self):
73         """Test thread step until - targeting one line and hitting it."""
74         self.do_until(None, [self.less_than_two], self.less_than_two)
75
76     def test_targetting_two_hitting_first (self):
77         """Test thread step until - targeting two lines and hitting one."""
78         self.do_until(["foo", "bar", "baz"], [self.less_than_two, self.greater_than_two], self.greater_than_two)
79
80     def test_targetting_two_hitting_second (self):
81         """Test thread step until - targeting two lines and hitting the other one."""
82         self.do_until(None, [self.less_than_two, self.greater_than_two], self.less_than_two)
83
84     def test_missing_one (self):
85         """Test thread step until - targeting one line and missing it."""
86         self.do_until(["foo", "bar", "baz"], [self.less_than_two], self.back_out_in_main)
87
88
89