2 # Copyright (C) 2008-2017 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/>.
20 class CallerIs(gdb.Function):
21 """Check the calling function's name.
24 $_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.
40 super(CallerIs, self).__init__("_caller_is")
42 def invoke(self, name, nframes = 1):
44 raise ValueError("nframes must be >= 0")
45 frame = gdb.selected_frame()
51 return frame.name() == name.string()
53 class CallerMatches(gdb.Function):
54 """Compare the calling function's name with a regexp.
57 $_caller_matches(regex [, number_of_frames])
61 regex: The regular expression to compare the function's name with.
63 number_of_frames: How many stack frames to traverse back from the currently
64 selected frame to compare with. If the value is greater than the depth of
65 the stack from that point then the result is False.
69 True if the function's name at the specified frame matches regex.
73 super(CallerMatches, self).__init__("_caller_matches")
75 def invoke(self, name, nframes = 1):
77 raise ValueError("nframes must be >= 0")
78 frame = gdb.selected_frame()
84 return re.match(name.string(), frame.name()) is not None
86 class AnyCallerIs(gdb.Function):
87 """Check all calling function's names.
90 $_any_caller_is(name [, number_of_frames])
94 name: The name of the function to search for.
96 number_of_frames: How many stack frames to traverse back from the currently
97 selected frame to compare with. If the value is greater than the depth of
98 the stack from that point then the result is False.
102 True if any function's name is equal to name.
106 super(AnyCallerIs, self).__init__("_any_caller_is")
108 def invoke(self, name, nframes = 1):
110 raise ValueError("nframes must be >= 0")
111 frame = gdb.selected_frame()
113 if frame.name() == name.string():
115 frame = frame.older()
118 nframes = nframes - 1
121 class AnyCallerMatches(gdb.Function):
122 """Compare all calling function's names with a regexp.
125 $_any_caller_matches(regex [, number_of_frames])
129 regex: The regular expression to compare the function's name with.
131 number_of_frames: How many stack frames to traverse back from the currently
132 selected frame to compare with. If the value is greater than the depth of
133 the stack from that point then the result is False.
137 True if any function's name matches regex.
141 super(AnyCallerMatches, self).__init__("_any_caller_matches")
143 def invoke(self, name, nframes = 1):
145 raise ValueError("nframes must be >= 0")
146 frame = gdb.selected_frame()
147 name_re = re.compile(name.string())
149 if name_re.match(frame.name()) is not None:
151 frame = frame.older()
154 nframes = nframes - 1