Xmethod-API.html 9.0 KB

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