Virtual-Methods.html 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Copyright (C) 1992-2019 Free Software Foundation, Inc.
  4. Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
  5. and David MacKenzie.
  6. Permission is granted to copy, distribute and/or modify this document
  7. under the terms of the GNU Free Documentation License, Version 1.3 or
  8. any later version published by the Free Software Foundation; with no
  9. Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
  10. Texts. A copy of the license is included in the section entitled "GNU
  11. Free Documentation License". -->
  12. <!-- Created by GNU Texinfo 5.2, http://www.gnu.org/software/texinfo/ -->
  13. <head>
  14. <title>STABS: Virtual Methods</title>
  15. <meta name="description" content="STABS: Virtual Methods">
  16. <meta name="keywords" content="STABS: Virtual Methods">
  17. <meta name="resource-type" content="document">
  18. <meta name="distribution" content="global">
  19. <meta name="Generator" content="makeinfo">
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <link href="index.html#Top" rel="start" title="Top">
  22. <link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index">
  23. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  24. <link href="Cplusplus.html#Cplusplus" rel="up" title="Cplusplus">
  25. <link href="Inheritance.html#Inheritance" rel="next" title="Inheritance">
  26. <link href="Method-Modifiers.html#Method-Modifiers" rel="prev" title="Method Modifiers">
  27. <style type="text/css">
  28. <!--
  29. a.summary-letter {text-decoration: none}
  30. blockquote.smallquotation {font-size: smaller}
  31. div.display {margin-left: 3.2em}
  32. div.example {margin-left: 3.2em}
  33. div.indentedblock {margin-left: 3.2em}
  34. div.lisp {margin-left: 3.2em}
  35. div.smalldisplay {margin-left: 3.2em}
  36. div.smallexample {margin-left: 3.2em}
  37. div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
  38. div.smalllisp {margin-left: 3.2em}
  39. kbd {font-style:oblique}
  40. pre.display {font-family: inherit}
  41. pre.format {font-family: inherit}
  42. pre.menu-comment {font-family: serif}
  43. pre.menu-preformatted {font-family: serif}
  44. pre.smalldisplay {font-family: inherit; font-size: smaller}
  45. pre.smallexample {font-size: smaller}
  46. pre.smallformat {font-family: inherit; font-size: smaller}
  47. pre.smalllisp {font-size: smaller}
  48. span.nocodebreak {white-space:nowrap}
  49. span.nolinebreak {white-space:nowrap}
  50. span.roman {font-family:serif; 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" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
  57. <a name="Virtual-Methods"></a>
  58. <div class="header">
  59. <p>
  60. Next: <a href="Inheritance.html#Inheritance" accesskey="n" rel="next">Inheritance</a>, Previous: <a href="Method-Modifiers.html#Method-Modifiers" accesskey="p" rel="prev">Method Modifiers</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  61. </div>
  62. <hr>
  63. <a name="Virtual-Methods-1"></a>
  64. <h3 class="section">8.11 Virtual Methods</h3>
  65. <p>&lt;&lt; The following examples are based on a4.C &gt;&gt;
  66. </p>
  67. <p>The presence of virtual methods in a class definition adds additional
  68. data to the class description. The extra data is appended to the
  69. description of the virtual method and to the end of the class
  70. description. Consider the class definition below:
  71. </p>
  72. <div class="example">
  73. <pre class="example">class A {
  74. public:
  75. int Adat;
  76. virtual int A_virt (int arg) { return arg; };
  77. };
  78. </pre></div>
  79. <p>This results in the stab below describing class A. It defines a new
  80. type (20) which is an 8 byte structure. The first field of the class
  81. struct is &lsquo;<samp>Adat</samp>&rsquo;, an integer, starting at structure offset 0 and
  82. occupying 32 bits.
  83. </p>
  84. <p>The second field in the class struct is not explicitly defined by the
  85. C<tt>++</tt> class definition but is implied by the fact that the class
  86. contains a virtual method. This field is the vtable pointer. The
  87. name of the vtable pointer field starts with &lsquo;<samp>$vf</samp>&rsquo; and continues with a
  88. type reference to the class it is part of. In this example the type
  89. reference for class A is 20 so the name of its vtable pointer field is
  90. &lsquo;<samp>$vf20</samp>&rsquo;, followed by the usual colon.
  91. </p>
  92. <p>Next there is a type definition for the vtable pointer type (21).
  93. This is in turn defined as a pointer to another new type (22).
  94. </p>
  95. <p>Type 22 is the vtable itself, which is defined as an array, indexed by
  96. a range of integers between 0 and 1, and whose elements are of type
  97. 17. Type 17 was the vtable record type defined by the boilerplate C<tt>++</tt>
  98. type definitions, as shown earlier.
  99. </p>
  100. <p>The bit offset of the vtable pointer field is 32. The number of bits
  101. in the field are not specified when the field is a vtable pointer.
  102. </p>
  103. <p>Next is the method definition for the virtual member function <code>A_virt</code>.
  104. Its description starts out using the same format as the non-virtual
  105. member functions described above, except instead of a dot after the
  106. &lsquo;<samp>A</samp>&rsquo; there is an asterisk, indicating that the function is virtual.
  107. Since is is virtual some addition information is appended to the end
  108. of the method description.
  109. </p>
  110. <p>The first number represents the vtable index of the method. This is a
  111. 32 bit unsigned number with the high bit set, followed by a
  112. semi-colon.
  113. </p>
  114. <p>The second number is a type reference to the first base class in the
  115. inheritance hierarchy defining the virtual member function. In this
  116. case the class stab describes a base class so the virtual function is
  117. not overriding any other definition of the method. Therefore the
  118. reference is to the type number of the class that the stab is
  119. describing (20).
  120. </p>
  121. <p>This is followed by three semi-colons. One marks the end of the
  122. current sub-section, one marks the end of the method field, and the
  123. third marks the end of the struct definition.
  124. </p>
  125. <p>For classes containing virtual functions the very last section of the
  126. string part of the stab holds a type reference to the first base
  127. class. This is preceded by &lsquo;<samp>~%</samp>&rsquo; and followed by a final semi-colon.
  128. </p>
  129. <div class="display">
  130. <pre class="display">.stabs &quot;class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
  131. field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
  132. field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
  133. sym_desc(array)index_type_ref(range of int from 0 to 1);
  134. elem_type_ref(vtbl elem type),
  135. bit_offset(32);
  136. meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
  137. :arg_type(int),protection(public)normal(yes)virtual(yes)
  138. vtable_index(1);class_first_defining(A);;;~%first_base(A);&quot;,
  139. N_LSYM,NIL,NIL,NIL
  140. </pre></div>
  141. <div class="example">
  142. <pre class="example">.stabs &quot;A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
  143. A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;&quot;,128,0,0,0
  144. </pre></div>
  145. <hr>
  146. <div class="header">
  147. <p>
  148. Next: <a href="Inheritance.html#Inheritance" accesskey="n" rel="next">Inheritance</a>, Previous: <a href="Method-Modifiers.html#Method-Modifiers" accesskey="p" rel="prev">Method Modifiers</a>, Up: <a href="Cplusplus.html#Cplusplus" accesskey="u" rel="up">Cplusplus</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Symbol-Types-Index.html#Symbol-Types-Index" title="Index" rel="index">Index</a>]</p>
  149. </div>
  150. </body>
  151. </html>