Update copyright year range in header of all files managed by GDB
[binutils-gdb.git] / gdb / testsuite / gdb.python / py-finish-breakpoint.py
blob15e760621e7e5a856bc9e04fadaf258cbbcdbaa4
1 # Copyright (C) 2011-2023 Free Software Foundation, Inc.
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.
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.
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/>.
16 # This file is part of the GDB testsuite. It tests python Finish
17 # Breakpoints.
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
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
32 def out_of_scope(self):
33 print("MyFinishBreakpoint out of scope")
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")
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
52 class TestFinishBreakpoint(gdb.FinishBreakpoint):
53 def __init__(self, frame, count):
54 self.count = count
55 gdb.FinishBreakpoint.__init__(self, frame, internal=1)
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
66 def out_of_scope(self):
67 print("test didn't finish: %d" % self.count)
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
79 class SimpleFinishBreakpoint(gdb.FinishBreakpoint):
80 def __init__(self, frame):
81 gdb.FinishBreakpoint.__init__(self, frame)
83 print("SimpleFinishBreakpoint init")
85 def stop(self):
86 print("SimpleFinishBreakpoint stop")
87 return True
89 def out_of_scope(self):
90 print("SimpleFinishBreakpoint out of scope")
93 print("Python script imported")