Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

131 Zeilen
6.9KB

  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>Xmethods In Python (Debugging with GDB)</title>
  17. <meta name="description" content="Xmethods In Python (Debugging with GDB)">
  18. <meta name="keywords" content="Xmethods In Python (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="Xmethod-API.html#Xmethod-API" rel="next" title="Xmethod API">
  27. <link href="Unwinding-Frames-in-Python.html#Unwinding-Frames-in-Python" rel="prev" title="Unwinding Frames 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="Xmethods-In-Python"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Xmethod-API.html#Xmethod-API" accesskey="n" rel="next">Xmethod API</a>, Previous: <a href="Unwinding-Frames-in-Python.html#Unwinding-Frames-in-Python" accesskey="p" rel="prev">Unwinding Frames 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="Xmethods-In-Python-1"></a>
  64. <h4 class="subsubsection">23.2.2.13 Xmethods In Python</h4>
  65. <a name="index-xmethods-in-Python"></a>
  66. <p><em>Xmethods</em> are additional methods or replacements for existing
  67. methods of a C<tt>++</tt> class. This feature is useful for those cases
  68. where a method defined in C<tt>++</tt> source code could be inlined or
  69. optimized out by the compiler, making it unavailable to <small>GDB</small>.
  70. For such cases, one can define an xmethod to serve as a replacement
  71. for the method defined in the C<tt>++</tt> source code. <small>GDB</small> will
  72. then invoke the xmethod, instead of the C<tt>++</tt> method, to
  73. evaluate expressions. One can also use xmethods when debugging
  74. with core files. Moreover, when debugging live programs, invoking an
  75. xmethod need not involve running the inferior (which can potentially
  76. perturb its state). Hence, even if the C<tt>++</tt> method is available, it
  77. is better to use its replacement xmethod if one is defined.
  78. </p>
  79. <p>The xmethods feature in Python is available via the concepts of an
  80. <em>xmethod matcher</em> and an <em>xmethod worker</em>. To
  81. implement an xmethod, one has to implement a matcher and a
  82. corresponding worker for it (more than one worker can be
  83. implemented, each catering to a different overloaded instance of the
  84. method). Internally, <small>GDB</small> invokes the <code>match</code> method of a
  85. matcher to match the class type and method name. On a match, the
  86. <code>match</code> method returns a list of matching <em>worker</em> objects.
  87. Each worker object typically corresponds to an overloaded instance of
  88. the xmethod. They implement a <code>get_arg_types</code> method which
  89. returns a sequence of types corresponding to the arguments the xmethod
  90. requires. <small>GDB</small> uses this sequence of types to perform
  91. overload resolution and picks a winning xmethod worker. A winner
  92. is also selected from among the methods <small>GDB</small> finds in the
  93. C<tt>++</tt> source code. Next, the winning xmethod worker and the
  94. winning C<tt>++</tt> method are compared to select an overall winner. In
  95. case of a tie between a xmethod worker and a C<tt>++</tt> method, the
  96. xmethod worker is selected as the winner. That is, if a winning
  97. xmethod worker is found to be equivalent to the winning C<tt>++</tt>
  98. method, then the xmethod worker is treated as a replacement for
  99. the C<tt>++</tt> method. <small>GDB</small> uses the overall winner to invoke the
  100. method. If the winning xmethod worker is the overall winner, then
  101. the corresponding xmethod is invoked via the <code>__call__</code> method
  102. of the worker object.
  103. </p>
  104. <p>If one wants to implement an xmethod as a replacement for an
  105. existing C<tt>++</tt> method, then they have to implement an equivalent
  106. xmethod which has exactly the same name and takes arguments of
  107. exactly the same type as the C<tt>++</tt> method. If the user wants to
  108. invoke the C<tt>++</tt> method even though a replacement xmethod is
  109. available for that method, then they can disable the xmethod.
  110. </p>
  111. <p>See <a href="Xmethod-API.html#Xmethod-API">Xmethod API</a>, for API to implement xmethods in Python.
  112. See <a href="Writing-an-Xmethod.html#Writing-an-Xmethod">Writing an Xmethod</a>, for implementing xmethods in Python.
  113. </p>
  114. <hr>
  115. <div class="header">
  116. <p>
  117. Next: <a href="Xmethod-API.html#Xmethod-API" accesskey="n" rel="next">Xmethod API</a>, Previous: <a href="Unwinding-Frames-in-Python.html#Unwinding-Frames-in-Python" accesskey="p" rel="prev">Unwinding Frames 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>
  118. </div>
  119. </body>
  120. </html>