hc
2023-11-06 15ade055295d13f95d49e3d99b09f3bbfb4a43e7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1988-2021 Free Software Foundation, Inc.
 
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with the
Invariant Sections being "Free Software" and "Free Software Needs
Free Documentation", with the Front-Cover Texts being "A GNU Manual,"
and with the Back-Cover Texts as in (a) below.
 
(a) The FSF's Back-Cover Text is: "You are free to copy and modify
this GNU Manual.  Buying copies from GNU Press supports the FSF in
developing GNU and promoting software freedom." -->
<!-- Created by GNU Texinfo 5.1, http://www.gnu.org/software/texinfo/ -->
<head>
<title>Debugging with GDB: Xmethod API</title>
 
<meta name="description" content="Debugging with GDB: Xmethod API">
<meta name="keywords" content="Debugging with GDB: Xmethod API">
<meta name="resource-type" content="document">
<meta name="distribution" content="global">
<meta name="Generator" content="makeinfo">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link href="index.html#Top" rel="start" title="Top">
<link href="Concept-Index.html#Concept-Index" rel="index" title="Concept Index">
<link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
<link href="Python-API.html#Python-API" rel="up" title="Python API">
<link href="Writing-an-Xmethod.html#Writing-an-Xmethod" rel="next" title="Writing an Xmethod">
<link href="Xmethods-In-Python.html#Xmethods-In-Python" rel="previous" title="Xmethods In Python">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
div.smalllisp {margin-left: 3.2em}
kbd {font-style:oblique}
pre.display {font-family: inherit}
pre.format {font-family: inherit}
pre.menu-comment {font-family: serif}
pre.menu-preformatted {font-family: serif}
pre.smalldisplay {font-family: inherit; font-size: smaller}
pre.smallexample {font-size: smaller}
pre.smallformat {font-family: inherit; font-size: smaller}
pre.smalllisp {font-size: smaller}
span.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
 
 
</head>
 
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Xmethod-API"></a>
<div class="header">
<p>
Next: <a href="Writing-an-Xmethod.html#Writing-an-Xmethod" accesskey="n" rel="next">Writing an Xmethod</a>, Previous: <a href="Xmethods-In-Python.html#Xmethods-In-Python" accesskey="p" rel="previous">Xmethods In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
<hr>
<a name="Xmethod-API-1"></a>
<h4 class="subsubsection">23.2.2.14 Xmethod API</h4>
<a name="index-xmethod-API"></a>
 
<p>The <small>GDB</small> Python API provides classes, interfaces and functions
to implement, register and manipulate xmethods.
See <a href="Xmethods-In-Python.html#Xmethods-In-Python">Xmethods In Python</a>.
</p>
<p>An xmethod matcher should be an instance of a class derived from
<code>XMethodMatcher</code> defined in the module <code>gdb.xmethod</code>, or an
object with similar interface and attributes.  An instance of
<code>XMethodMatcher</code> has the following attributes:
</p>
<dl>
<dt><a name="index-name"></a>Variable: <strong>name</strong></dt>
<dd><p>The name of the matcher.
</p></dd></dl>
 
<dl>
<dt><a name="index-enabled"></a>Variable: <strong>enabled</strong></dt>
<dd><p>A boolean value indicating whether the matcher is enabled or disabled.
</p></dd></dl>
 
<dl>
<dt><a name="index-methods"></a>Variable: <strong>methods</strong></dt>
<dd><p>A list of named methods managed by the matcher.  Each object in the list
is an instance of the class <code>XMethod</code> defined in the module
<code>gdb.xmethod</code>, or any object with the following attributes:
</p>
<dl compact="compact">
<dt><code>name</code></dt>
<dd><p>Name of the xmethod which should be unique for each xmethod
managed by the matcher.
</p>
</dd>
<dt><code>enabled</code></dt>
<dd><p>A boolean value indicating whether the xmethod is enabled or
disabled.
</p>
</dd>
</dl>
 
<p>The class <code>XMethod</code> is a convenience class with same
attributes as above along with the following constructor:
</p>
<dl>
<dt><a name="index-XMethod_002e_005f_005finit_005f_005f"></a>Function: <strong>XMethod.__init__</strong> <em>(self, name)</em></dt>
<dd><p>Constructs an enabled xmethod with name <var>name</var>.
</p></dd></dl>
</dd></dl>
 
<p>The <code>XMethodMatcher</code> class has the following methods:
</p>
<dl>
<dt><a name="index-XMethodMatcher_002e_005f_005finit_005f_005f"></a>Function: <strong>XMethodMatcher.__init__</strong> <em>(self, name)</em></dt>
<dd><p>Constructs an enabled xmethod matcher with name <var>name</var>.  The
<code>methods</code> attribute is initialized to <code>None</code>.
</p></dd></dl>
 
<dl>
<dt><a name="index-XMethodMatcher_002ematch"></a>Function: <strong>XMethodMatcher.match</strong> <em>(self, class_type, method_name)</em></dt>
<dd><p>Derived classes should override this method.  It should return a
xmethod worker object (or a sequence of xmethod worker
objects) matching the <var>class_type</var> and <var>method_name</var>.
<var>class_type</var> is a <code>gdb.Type</code> object, and <var>method_name</var>
is a string value.  If the matcher manages named methods as listed in
its <code>methods</code> attribute, then only those worker objects whose
corresponding entries in the <code>methods</code> list are enabled should be
returned.
</p></dd></dl>
 
<p>An xmethod worker should be an instance of a class derived from
<code>XMethodWorker</code> defined in the module <code>gdb.xmethod</code>,
or support the following interface:
</p>
<dl>
<dt><a name="index-XMethodWorker_002eget_005farg_005ftypes"></a>Function: <strong>XMethodWorker.get_arg_types</strong> <em>(self)</em></dt>
<dd><p>This method returns a sequence of <code>gdb.Type</code> objects corresponding
to the arguments that the xmethod takes.  It can return an empty
sequence or <code>None</code> if the xmethod does not take any arguments.
If the xmethod takes a single argument, then a single
<code>gdb.Type</code> object corresponding to it can be returned.
</p></dd></dl>
 
<dl>
<dt><a name="index-XMethodWorker_002eget_005fresult_005ftype"></a>Function: <strong>XMethodWorker.get_result_type</strong> <em>(self, *args)</em></dt>
<dd><p>This method returns a <code>gdb.Type</code> object representing the type
of the result of invoking this xmethod.
The <var>args</var> argument is the same tuple of arguments that would be
passed to the <code>__call__</code> method of this worker.
</p></dd></dl>
 
<dl>
<dt><a name="index-XMethodWorker_002e_005f_005fcall_005f_005f"></a>Function: <strong>XMethodWorker.__call__</strong> <em>(self, *args)</em></dt>
<dd><p>This is the method which does the <em>work</em> of the xmethod.  The
<var>args</var> 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 <code>this</code> pointer value.
</p></dd></dl>
 
<p>For <small>GDB</small> to lookup xmethods, the xmethod matchers
should be registered using the following function defined in the module
<code>gdb.xmethod</code>:
</p>
<dl>
<dt><a name="index-register_005fxmethod_005fmatcher"></a>Function: <strong>register_xmethod_matcher</strong> <em>(locus, matcher, replace=False)</em></dt>
<dd><p>The <code>matcher</code> is registered with <code>locus</code>, replacing an
existing matcher with the same name as <code>matcher</code> if
<code>replace</code> is <code>True</code>.  <code>locus</code> can be a
<code>gdb.Objfile</code> object (see <a href="Objfiles-In-Python.html#Objfiles-In-Python">Objfiles In Python</a>), or a
<code>gdb.Progspace</code> object (see <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>), or
<code>None</code>.  If it is <code>None</code>, then <code>matcher</code> is registered
globally.
</p></dd></dl>
 
<hr>
<div class="header">
<p>
Next: <a href="Writing-an-Xmethod.html#Writing-an-Xmethod" accesskey="n" rel="next">Writing an Xmethod</a>, Previous: <a href="Xmethods-In-Python.html#Xmethods-In-Python" accesskey="p" rel="previous">Xmethods In Python</a>, Up: <a href="Python-API.html#Python-API" accesskey="u" rel="up">Python API</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Concept-Index.html#Concept-Index" title="Index" rel="index">Index</a>]</p>
</div>
 
 
 
</body>
</html>