7791079b1f42377acea488e7cdf837d24343dcbd
[deliverable/binutils-gdb.git] / gdb / testsuite / gdb.python / py-finish-breakpoint.py
1 # Copyright (C) 2011-2021 Free Software Foundation, Inc.
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 3 of the License, or
6 # (at your option) any later version.
7 #
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
12 #
13 # You should have received a copy of the GNU General Public License
14 # along with this program. If not, see <http://www.gnu.org/licenses/>.
15
16 # This file is part of the GDB testsuite. It tests python Finish
17 # Breakpoints.
18
19
20 class MyFinishBreakpoint(gdb.FinishBreakpoint):
21 def __init__(self, val, frame):
22 gdb.FinishBreakpoint.__init__(self, frame)
23 print("MyFinishBreakpoint init")
24 self.val = val
25
26 def stop(self):
27 print("MyFinishBreakpoint stop with %d" % int(self.val.dereference()))
28 print("return_value is: %d" % int(self.return_value))
29 gdb.execute("where 1")
30 return True
31
32 def out_of_scope(self):
33 print("MyFinishBreakpoint out of scope")
34
35
36 class TestBreakpoint(gdb.Breakpoint):
37 def __init__(self):
38 gdb.Breakpoint.__init__(self, spec="test_1", internal=1)
39 self.silent = True
40 self.count = 0
41 print("TestBreakpoint init")
42
43 def stop(self):
44 self.count += 1
45 try:
46 TestFinishBreakpoint(gdb.newest_frame(), self.count)
47 except ValueError as e:
48 print(e)
49 return False
50
51
52 class TestFinishBreakpoint(gdb.FinishBreakpoint):
53 def __init__(self, frame, count):
54 self.count = count
55 gdb.FinishBreakpoint.__init__(self, frame, internal=1)
56
57 def stop(self):
58 print("-->", self.number)
59 if self.count == 3:
60 print("test stop: %d" % self.count)
61 return True
62 else:
63 print("test don't stop: %d" % self.count)
64 return False
65
66 def out_of_scope(self):
67 print("test didn't finish: %d" % self.count)
68
69
70 class TestExplicitBreakpoint(gdb.Breakpoint):
71 def stop(self):
72 try:
73 SimpleFinishBreakpoint(gdb.newest_frame())
74 except ValueError as e:
75 print(e)
76 return False
77
78
79 class SimpleFinishBreakpoint(gdb.FinishBreakpoint):
80 def __init__(self, frame):
81 gdb.FinishBreakpoint.__init__(self, frame)
82
83 print("SimpleFinishBreakpoint init")
84
85 def stop(self):
86 print("SimpleFinishBreakpoint stop")
87 return True
88
89 def out_of_scope(self):
90 print("SimpleFinishBreakpoint out of scope")
91
92
93 print("Python script imported")
This page took 0.031128 seconds and 3 git commands to generate.