Xmethod API (Debugging with GDB)
Next: Writing an Xmethod, Previous: Xmethods In Python, Up: Python API [Contents][Index]
23.3.2.14 Xmethod API
The GDB Python API provides classes, interfaces and functions to implement, register and manipulate xmethods. See Xmethods In Python.
An xmethod matcher should be an instance of a class derived from XMethodMatcher defined in the module gdb.xmethod, or an object with similar interface and attributes. An instance of XMethodMatcher has the following attributes:
- Variable
- name
- The name of the matcher.
- Variable
- enabled
- A boolean value indicating whether the matcher is enabled or disabled.
- Variable: methods
A list of named methods managed by the matcher. Each object in the list is an instance of the class
XMethoddefined in the modulegdb.xmethod, or any object with the following attributes:nameName of the xmethod which should be unique for each xmethod managed by the matcher.
enabledA boolean value indicating whether the xmethod is enabled or disabled.
The class
XMethodis a convenience class with same attributes as above along with the following constructor:- Function: XMethod.__init__ (self, name)
Constructs an enabled xmethod with name
name.
The XMethodMatcher class has the following methods:
- Function
- XMethodMatcher.__init__ (self, name)
- Constructs an enabled xmethod matcher with name
name. Themethodsattribute is initialized toNone.
- Function
- XMethodMatcher.match (self, class_type, method_name)
- Derived classes should override this method. It should return a xmethod worker object (or a sequence of xmethod worker objects) matching the
class_typeandmethod_name.class_typeis agdb.Typeobject, andmethod_nameis a string value. If the matcher manages named methods as listed in itsmethodsattribute, then only those worker objects whose corresponding entries in themethodslist are enabled should be returned.
An xmethod worker should be an instance of a class derived from XMethodWorker defined in the module gdb.xmethod, or support the following interface:
- Function
- XMethodWorker.get_arg_types (self)
- This method returns a sequence of
gdb.Typeobjects corresponding to the arguments that the xmethod takes. It can return an empty sequence orNoneif the xmethod does not take any arguments. If the xmethod takes a single argument, then a singlegdb.Typeobject corresponding to it can be returned.
- Function
- XMethodWorker.get_result_type (self, *args)
- This method returns a
gdb.Typeobject representing the type of the result of invoking this xmethod. Theargsargument is the same tuple of arguments that would be passed to the__call__method of this worker.
- Function
- XMethodWorker.__call__ (self, *args)
- This is the method which does the work of the xmethod. The
argsarguments is the tuple of arguments to the xmethod. Each element in this tuple is a gdb.Value object. The first element is always thethispointer value.
For GDB to lookup xmethods, the xmethod matchers should be registered using the following function defined in the module gdb.xmethod:
- Function
- register_xmethod_matcher (locus, matcher, replace=False)
- The
matcheris registered withlocus, replacing an existing matcher with the same name asmatcherifreplaceisTrue.locuscan be agdb.Objfileobject (see Objfiles In Python), or agdb.Progspaceobject (see Progspaces In Python), orNone. If it isNone, thenmatcheris registered globally.
Next: Writing an Xmethod, Previous: Xmethods In Python, Up: Python API [Contents][Index]