Xmethods-In-Python.html 7.0 KB

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