169 self, name, class_matcher, method_matcher, method_function, *arg_types
173 name: Name of the xmethod matcher.
174 class_matcher: A regular expression used to match the name of the
175 class whose method this xmethod is implementing/replacing.
176 method_matcher: A regular expression used to match the name of the
177 method this xmethod is implementing/replacing.
178 method_function: A Python callable which would be called via the
179 'invoke' method of the worker returned by the objects of this
180 class. This callable should accept the object (*this) as the
181 first argument followed by the rest of the arguments to the
182 method. All arguments to this function should be gdb.Value
184 arg_types: The gdb.Type objects corresponding to the arguments that
185 this xmethod takes. It can be None, or an empty sequence,
186 or a single gdb.Type object, or a sequence of gdb.Type objects.
188 XMethodMatcher.__init__(self, name)
189 assert callable(method_function), (
190 "The 'method_function' argument to 'SimpleXMethodMatcher' "
191 "__init__ method should be a callable."
198 def match(self, class_type, method_name):
199 cm = re.match(self.
_class_matcher, str(class_type.unqualified().tag))
213 if not hasattr(matcher,
"match"):
214 return TypeError(
"Xmethod matcher is missing method: match")
215 if not hasattr(matcher,
"name"):
216 return TypeError(
"Xmethod matcher is missing attribute: name")
217 if not hasattr(matcher,
"enabled"):
218 return TypeError(
"Xmethod matcher is missing attribute: enabled")
219 if not isinstance(matcher.name, str):
220 return TypeError(
"Attribute 'name' of xmethod matcher is not a " "string")
221 if matcher.name.find(
";") >= 0:
222 return ValueError(
"Xmethod matcher name cannot contain ';' in it")
232 for i
in range(0, len(locus.xmethods)):
233 if locus.xmethods[i].name == name:
239 """Registers a xmethod matcher MATCHER with a LOCUS.
242 locus: The locus in which the xmethods should be registered.
243 It can be 'None' to indicate that the xmethods should be
244 registered globally. Or, it could be a gdb.Objfile or a
245 gdb.Progspace object in which the xmethods should be
247 matcher: The xmethod matcher to register with the LOCUS. It
248 should be an instance of 'XMethodMatcher' class.
249 replace: If True, replace any existing xmethod matcher with the
250 same name in the locus. Otherwise, if a matcher with the same name
251 exists in the locus, raise an exception.
259 locus_name =
"global"
261 locus_name = locus.filename
265 del locus.xmethods[index]
268 "Xmethod matcher already registered with "
269 "%s: %s" % (locus_name, matcher.name)
271 if gdb.parameter(
"verbose"):
272 gdb.write(
"Registering xmethod matcher '%s' with %s' ...\n")
273 locus.xmethods.insert(0, matcher)