]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - packages/Python/lldbsuite/test/functionalities/breakpoint/auto_continue/TestBreakpointAutoContinue.py
Vendor import of lldb trunk r338536:
[FreeBSD/FreeBSD.git] / packages / Python / lldbsuite / test / functionalities / breakpoint / auto_continue / TestBreakpointAutoContinue.py
1 """
2 Test that the breakpoint auto-continue flag works correctly.
3 """
4
5 from __future__ import print_function
6
7
8 import os
9 import time
10 import re
11 import lldb
12 import lldbsuite.test.lldbutil as lldbutil
13 from lldbsuite.test.lldbtest import *
14
15
16 class BreakpointAutoContinue(TestBase):
17
18     mydir = TestBase.compute_mydir(__file__)
19
20     NO_DEBUG_INFO_TESTCASE = True
21
22     def test_breakpoint_auto_continue(self):
23         """Make sure the auto continue continues with no other complications"""
24         self.build()
25         self.simple_auto_continue()
26
27     def test_auto_continue_with_command(self):
28         """Add a command, make sure the command gets run"""
29         self.build()
30         self.auto_continue_with_command()
31
32     def test_auto_continue_on_location(self):
33         """Set auto-continue on a location and make sure only that location continues"""
34         self.build()
35         self.auto_continue_location()
36
37     def make_target_and_bkpt(self, additional_options=None, num_expected_loc=1,
38                              pattern="Set a breakpoint here"):
39         exe = self.getBuildArtifact("a.out")
40         self.target = self.dbg.CreateTarget(exe)
41         self.assertTrue(self.target.IsValid(), "Target is not valid")
42
43         extra_options_txt = "--auto-continue 1 "
44         if additional_options:
45             extra_options_txt += additional_options
46         bpno = lldbutil.run_break_set_by_source_regexp(self, pattern,
47                                             extra_options = extra_options_txt,
48                                             num_expected_locations = num_expected_loc)
49         return bpno
50
51     def launch_it (self, expected_state):
52         error = lldb.SBError()
53         launch_info = lldb.SBLaunchInfo(None)
54         launch_info.SetWorkingDirectory(self.get_process_working_directory())
55
56         process = self.target.Launch(launch_info, error)
57         self.assertTrue(error.Success(), "Launch failed.")
58
59         state = process.GetState()
60         self.assertEqual(state, expected_state, "Didn't get expected state")
61
62         return process
63
64     def setUp(self):
65         # Call super's setUp().
66         TestBase.setUp(self)
67
68     def simple_auto_continue(self):
69         bpno = self.make_target_and_bkpt()
70         process = self.launch_it(lldb.eStateExited)
71
72         bkpt = self.target.FindBreakpointByID(bpno)
73         self.assertEqual(bkpt.GetHitCount(), 2, "Should have run through the breakpoint twice")
74
75     def auto_continue_with_command(self):
76         bpno = self.make_target_and_bkpt("-N BKPT -C 'break modify --auto-continue 0 BKPT'")
77         process = self.launch_it(lldb.eStateStopped)
78         state = process.GetState()
79         self.assertEqual(state, lldb.eStateStopped, "Process should be stopped")
80         bkpt = self.target.FindBreakpointByID(bpno)
81         threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
82         self.assertEqual(len(threads), 1, "There was a thread stopped at our breakpoint")
83         self.assertEqual(bkpt.GetHitCount(), 2, "Should have hit the breakpoint twice")
84
85     def auto_continue_location(self):
86         bpno = self.make_target_and_bkpt(pattern="Set a[^ ]* breakpoint here", num_expected_loc=2)
87         bkpt = self.target.FindBreakpointByID(bpno)
88         bkpt.SetAutoContinue(False)
89
90         loc = lldb.SBBreakpointLocation()
91         for i in range(0,2):
92             func_name = bkpt.location[i].GetAddress().function.name
93             if func_name == "main":
94                 loc = bkpt.location[i]
95
96         self.assertTrue(loc.IsValid(), "Didn't find a location in main")
97         loc.SetAutoContinue(True)
98
99         process = self.launch_it(lldb.eStateStopped)
100
101         threads = lldbutil.get_threads_stopped_at_breakpoint(process, bkpt)
102         self.assertEqual(len(threads), 1, "Didn't get one thread stopped at our breakpoint")
103         func_name = threads[0].frame[0].function.name
104         self.assertEqual(func_name, "call_me")