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:
A list of named methods managed by the matcher. Each object in the list is an instance of the class
XMethoddefined in the module
gdb.xmethod, or any object with the following attributes:
- Name of the xmethod which should be unique for each xmethod managed by the matcher.
- A boolean value indicating whether the xmethod is enabled or disabled.
XMethodis a convenience class with same attributes as above along with the following constructor:
XMethodMatcher class has the following methods:
Constructs an enabled xmethod matcher with name name. The
methodsattribute is initialized to
Derived classes should override this method. It should return a xmethod worker object (or a sequence of xmethod worker objects) matching the class_type and method_name. class_type is a
gdb.Typeobject, and method_name is a string value. If the matcher manages named methods as listed in its
methodsattribute, then only those worker objects whose corresponding entries in the
methodslist are enabled should be returned.
An xmethod worker should be an instance of a class derived from
XMethodWorker defined in the module
or support the following interface:
This method returns a sequence of
gdb.Typeobjects corresponding to the arguments that the xmethod takes. It can return an empty sequence or
Noneif the xmethod does not take any arguments. If the xmethod takes a single argument, then a single
gdb.Typeobject corresponding to it can be returned.
This method returns a
gdb.Typeobject representing the type of the result of invoking this xmethod. The args argument is the same tuple of arguments that would be passed to the
__call__method of this worker.
This is the method which does the work of the xmethod. The args arguments is the tuple of arguments to the xmethod. Each element in this tuple is a gdb.Value object. The first element is always the
For gdb to lookup xmethods, the xmethod matchers
should be registered using the following function defined in the module
matcheris registered with
locus, replacing an existing matcher with the same name as
locuscan be a
gdb.Objfileobject (see Objfiles In Python), or a
gdb.Progspaceobject (see Progspaces In Python), or
None. If it is
matcheris registered globally.