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