You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Xmethod-API.html 8.9KB

3 jaren geleden
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  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 6.5, http://www.gnu.org/software/texinfo/ -->
  14. <head>
  15. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  16. <title>Xmethod API (Debugging with GDB)</title>
  17. <meta name="description" content="Xmethod API (Debugging with GDB)">
  18. <meta name="keywords" content="Xmethod API (Debugging with GDB)">
  19. <meta name="resource-type" content="document">
  20. <meta name="distribution" content="global">
  21. <meta name="Generator" content="makeinfo">
  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="prev" title="Xmethods In Python">
  28. <style type="text/css">
  29. <!--
  30. a.summary-letter {text-decoration: none}
  31. blockquote.indentedblock {margin-right: 0em}
  32. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  33. blockquote.smallquotation {font-size: smaller}
  34. div.display {margin-left: 3.2em}
  35. div.example {margin-left: 3.2em}
  36. div.lisp {margin-left: 3.2em}
  37. div.smalldisplay {margin-left: 3.2em}
  38. div.smallexample {margin-left: 3.2em}
  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.nolinebreak {white-space: nowrap}
  50. span.roman {font-family: initial; font-weight: normal}
  51. span.sansserif {font-family: sans-serif; font-weight: normal}
  52. ul.no-bullet {list-style: none}
  53. -->
  54. </style>
  55. </head>
  56. <body lang="en">
  57. <a name="Xmethod-API"></a>
  58. <div class="header">
  59. <p>
  60. 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="prev">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>
  61. </div>
  62. <hr>
  63. <a name="Xmethod-API-1"></a>
  64. <h4 class="subsubsection">23.2.2.14 Xmethod API</h4>
  65. <a name="index-xmethod-API"></a>
  66. <p>The <small>GDB</small> Python API provides classes, interfaces and functions
  67. to implement, register and manipulate xmethods.
  68. See <a href="Xmethods-In-Python.html#Xmethods-In-Python">Xmethods In Python</a>.
  69. </p>
  70. <p>An xmethod matcher should be an instance of a class derived from
  71. <code>XMethodMatcher</code> defined in the module <code>gdb.xmethod</code>, or an
  72. object with similar interface and attributes. An instance of
  73. <code>XMethodMatcher</code> has the following attributes:
  74. </p>
  75. <dl>
  76. <dt><a name="index-name"></a>Variable: <strong>name</strong></dt>
  77. <dd><p>The name of the matcher.
  78. </p></dd></dl>
  79. <dl>
  80. <dt><a name="index-enabled"></a>Variable: <strong>enabled</strong></dt>
  81. <dd><p>A boolean value indicating whether the matcher is enabled or disabled.
  82. </p></dd></dl>
  83. <dl>
  84. <dt><a name="index-methods"></a>Variable: <strong>methods</strong></dt>
  85. <dd><p>A list of named methods managed by the matcher. Each object in the list
  86. is an instance of the class <code>XMethod</code> defined in the module
  87. <code>gdb.xmethod</code>, or any object with the following attributes:
  88. </p>
  89. <dl compact="compact">
  90. <dt><code>name</code></dt>
  91. <dd><p>Name of the xmethod which should be unique for each xmethod
  92. managed by the matcher.
  93. </p>
  94. </dd>
  95. <dt><code>enabled</code></dt>
  96. <dd><p>A boolean value indicating whether the xmethod is enabled or
  97. disabled.
  98. </p>
  99. </dd>
  100. </dl>
  101. <p>The class <code>XMethod</code> is a convenience class with same
  102. attributes as above along with the following constructor:
  103. </p>
  104. <dl>
  105. <dt><a name="index-XMethod_002e_005f_005finit_005f_005f"></a>Function: <strong>XMethod.__init__</strong> <em>(self, name)</em></dt>
  106. <dd><p>Constructs an enabled xmethod with name <var>name</var>.
  107. </p></dd></dl>
  108. </dd></dl>
  109. <p>The <code>XMethodMatcher</code> class has the following methods:
  110. </p>
  111. <dl>
  112. <dt><a name="index-XMethodMatcher_002e_005f_005finit_005f_005f"></a>Function: <strong>XMethodMatcher.__init__</strong> <em>(self, name)</em></dt>
  113. <dd><p>Constructs an enabled xmethod matcher with name <var>name</var>. The
  114. <code>methods</code> attribute is initialized to <code>None</code>.
  115. </p></dd></dl>
  116. <dl>
  117. <dt><a name="index-XMethodMatcher_002ematch"></a>Function: <strong>XMethodMatcher.match</strong> <em>(self, class_type, method_name)</em></dt>
  118. <dd><p>Derived classes should override this method. It should return a
  119. xmethod worker object (or a sequence of xmethod worker
  120. objects) matching the <var>class_type</var> and <var>method_name</var>.
  121. <var>class_type</var> is a <code>gdb.Type</code> object, and <var>method_name</var>
  122. is a string value. If the matcher manages named methods as listed in
  123. its <code>methods</code> attribute, then only those worker objects whose
  124. corresponding entries in the <code>methods</code> list are enabled should be
  125. returned.
  126. </p></dd></dl>
  127. <p>An xmethod worker should be an instance of a class derived from
  128. <code>XMethodWorker</code> defined in the module <code>gdb.xmethod</code>,
  129. or support the following interface:
  130. </p>
  131. <dl>
  132. <dt><a name="index-XMethodWorker_002eget_005farg_005ftypes"></a>Function: <strong>XMethodWorker.get_arg_types</strong> <em>(self)</em></dt>
  133. <dd><p>This method returns a sequence of <code>gdb.Type</code> objects corresponding
  134. to the arguments that the xmethod takes. It can return an empty
  135. sequence or <code>None</code> if the xmethod does not take any arguments.
  136. If the xmethod takes a single argument, then a single
  137. <code>gdb.Type</code> object corresponding to it can be returned.
  138. </p></dd></dl>
  139. <dl>
  140. <dt><a name="index-XMethodWorker_002eget_005fresult_005ftype"></a>Function: <strong>XMethodWorker.get_result_type</strong> <em>(self, *args)</em></dt>
  141. <dd><p>This method returns a <code>gdb.Type</code> object representing the type
  142. of the result of invoking this xmethod.
  143. The <var>args</var> argument is the same tuple of arguments that would be
  144. passed to the <code>__call__</code> method of this worker.
  145. </p></dd></dl>
  146. <dl>
  147. <dt><a name="index-XMethodWorker_002e_005f_005fcall_005f_005f"></a>Function: <strong>XMethodWorker.__call__</strong> <em>(self, *args)</em></dt>
  148. <dd><p>This is the method which does the <em>work</em> of the xmethod. The
  149. <var>args</var> arguments is the tuple of arguments to the xmethod. Each
  150. element in this tuple is a gdb.Value object. The first element is
  151. always the <code>this</code> pointer value.
  152. </p></dd></dl>
  153. <p>For <small>GDB</small> to lookup xmethods, the xmethod matchers
  154. should be registered using the following function defined in the module
  155. <code>gdb.xmethod</code>:
  156. </p>
  157. <dl>
  158. <dt><a name="index-register_005fxmethod_005fmatcher"></a>Function: <strong>register_xmethod_matcher</strong> <em>(locus, matcher, replace=False)</em></dt>
  159. <dd><p>The <code>matcher</code> is registered with <code>locus</code>, replacing an
  160. existing matcher with the same name as <code>matcher</code> if
  161. <code>replace</code> is <code>True</code>. <code>locus</code> can be a
  162. <code>gdb.Objfile</code> object (see <a href="Objfiles-In-Python.html#Objfiles-In-Python">Objfiles In Python</a>), or a
  163. <code>gdb.Progspace</code> object (see <a href="Progspaces-In-Python.html#Progspaces-In-Python">Progspaces In Python</a>), or
  164. <code>None</code>. If it is <code>None</code>, then <code>matcher</code> is registered
  165. globally.
  166. </p></dd></dl>
  167. <hr>
  168. <div class="header">
  169. <p>
  170. 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="prev">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>
  171. </div>
  172. </body>
  173. </html>