]>
git.ipfire.org Git - thirdparty/binutils-gdb.git/blob - gdb/python/lib/gdb/function/caller_is.py
2 # Copyright (C) 2008-2024 Free Software Foundation, Inc.
4 # This program is free software; you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation; either version 3 of the License, or
7 # (at your option) any later version.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 class CallerIs(gdb
.Function
):
22 """Check the calling function's name.
24 Usage: $_caller_is (NAME [, NUMBER-OF-FRAMES])
28 NAME: The name of the function to search for.
30 NUMBER-OF-FRAMES: How many stack frames to traverse back from the currently
31 selected frame to compare with. If the value is greater than the depth of
32 the stack from that point then the result is False.
36 True if the function's name at the specified frame is equal to NAME."""
39 super(CallerIs
, self
).__init
__("_caller_is")
41 def invoke(self
, name
, nframes
=1):
43 raise ValueError("nframes must be >= 0")
44 frame
= gdb
.selected_frame()
50 return frame
.name() == name
.string()
53 class CallerMatches(gdb
.Function
):
54 """Compare the calling function's name with a regexp.
56 Usage: $_caller_matches (REGEX [, NUMBER-OF-FRAMES])
60 REGEX: The regular expression to compare the function's name with.
62 NUMBER-OF-FRAMES: How many stack frames to traverse back from the currently
63 selected frame to compare with. If the value is greater than the depth of
64 the stack from that point then the result is False.
68 True if the function's name at the specified frame matches REGEX."""
71 super(CallerMatches
, self
).__init
__("_caller_matches")
73 def invoke(self
, name
, nframes
=1):
75 raise ValueError("nframes must be >= 0")
76 frame
= gdb
.selected_frame()
82 return re
.match(name
.string(), frame
.name()) is not None
85 class AnyCallerIs(gdb
.Function
):
86 """Check all calling function's names.
88 Usage: $_any_caller_is (NAME [, NUMBER-OF-FRAMES])
92 NAME: The name of the function to search for.
94 NUMBER-OF-FRAMES: How many stack frames to traverse back from the currently
95 selected frame to compare with. If the value is greater than the depth of
96 the stack from that point then the result is False.
100 True if any function's name is equal to NAME."""
103 super(AnyCallerIs
, self
).__init
__("_any_caller_is")
105 def invoke(self
, name
, nframes
=1):
107 raise ValueError("nframes must be >= 0")
108 frame
= gdb
.selected_frame()
110 if frame
.name() == name
.string():
112 frame
= frame
.older()
115 nframes
= nframes
- 1
119 class AnyCallerMatches(gdb
.Function
):
120 """Compare all calling function's names with a regexp.
122 Usage: $_any_caller_matches (REGEX [, NUMBER-OF-FRAMES])
126 REGEX: The regular expression to compare the function's name with.
128 NUMBER-OF-FRAMES: How many stack frames to traverse back from the currently
129 selected frame to compare with. If the value is greater than the depth of
130 the stack from that point then the result is False.
134 True if any function's name matches REGEX."""
137 super(AnyCallerMatches
, self
).__init
__("_any_caller_matches")
139 def invoke(self
, name
, nframes
=1):
141 raise ValueError("nframes must be >= 0")
142 frame
= gdb
.selected_frame()
143 name_re
= re
.compile(name
.string())
145 if name_re
.match(frame
.name()) is not None:
147 frame
= frame
.older()
150 nframes
= nframes
- 1