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