toolchain/share/doc/stabs/Virtual-Methods.html

128 lines
6.1 KiB
HTML

<html lang="en">
<head>
<title>Virtual Methods - STABS</title>
<meta http-equiv="Content-Type" content="text/html">
<meta name="description" content="STABS">
<meta name="generator" content="makeinfo 4.13">
<link title="Top" rel="start" href="index.html#Top">
<link rel="up" href="Cplusplus.html#Cplusplus" title="Cplusplus">
<link rel="prev" href="Method-Modifiers.html#Method-Modifiers" title="Method Modifiers">
<link rel="next" href="Inheritance.html#Inheritance" title="Inheritance">
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
<!--
Copyright (C) 1992-2019 Free Software Foundation, Inc.
Contributed by Cygnus Support. Written by Julia Menapace, Jim Kingdon,
and David MacKenzie.
Permission is granted to copy, distribute and/or modify this document
under the terms of the GNU Free Documentation License, Version 1.3 or
any later version published by the Free Software Foundation; with no
Invariant Sections, with no Front-Cover Texts, and with no Back-Cover
Texts. A copy of the license is included in the section entitled ``GNU
Free Documentation License''.-->
<meta http-equiv="Content-Style-Type" content="text/css">
<style type="text/css"><!--
pre.display { font-family:inherit }
pre.format { font-family:inherit }
pre.smalldisplay { font-family:inherit; font-size:smaller }
pre.smallformat { font-family:inherit; font-size:smaller }
pre.smallexample { font-size:smaller }
pre.smalllisp { font-size:smaller }
span.sc { font-variant:small-caps }
span.roman { font-family:serif; font-weight:normal; }
span.sansserif { font-family:sans-serif; font-weight:normal; }
--></style>
</head>
<body>
<div class="node">
<a name="Virtual-Methods"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Inheritance.html#Inheritance">Inheritance</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Method-Modifiers.html#Method-Modifiers">Method Modifiers</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Cplusplus.html#Cplusplus">Cplusplus</a>
<hr>
</div>
<h3 class="section">8.11 Virtual Methods</h3>
<p>&lt;&lt; The following examples are based on a4.C &gt;&gt;
<p>The presence of virtual methods in a class definition adds additional
data to the class description. The extra data is appended to the
description of the virtual method and to the end of the class
description. Consider the class definition below:
<pre class="example"> class A {
public:
int Adat;
virtual int A_virt (int arg) { return arg; };
};
</pre>
<p>This results in the stab below describing class A. It defines a new
type (20) which is an 8 byte structure. The first field of the class
struct is &lsquo;<samp><span class="samp">Adat</span></samp>&rsquo;, an integer, starting at structure offset 0 and
occupying 32 bits.
<p>The second field in the class struct is not explicitly defined by the
C<tt>++</tt> class definition but is implied by the fact that the class
contains a virtual method. This field is the vtable pointer. The
name of the vtable pointer field starts with &lsquo;<samp><span class="samp">$vf</span></samp>&rsquo; and continues with a
type reference to the class it is part of. In this example the type
reference for class A is 20 so the name of its vtable pointer field is
&lsquo;<samp><span class="samp">$vf20</span></samp>&rsquo;, followed by the usual colon.
<p>Next there is a type definition for the vtable pointer type (21).
This is in turn defined as a pointer to another new type (22).
<p>Type 22 is the vtable itself, which is defined as an array, indexed by
a range of integers between 0 and 1, and whose elements are of type
17. Type 17 was the vtable record type defined by the boilerplate C<tt>++</tt>
type definitions, as shown earlier.
<p>The bit offset of the vtable pointer field is 32. The number of bits
in the field are not specified when the field is a vtable pointer.
<p>Next is the method definition for the virtual member function <code>A_virt</code>.
Its description starts out using the same format as the non-virtual
member functions described above, except instead of a dot after the
&lsquo;<samp><span class="samp">A</span></samp>&rsquo; there is an asterisk, indicating that the function is virtual.
Since is is virtual some addition information is appended to the end
of the method description.
<p>The first number represents the vtable index of the method. This is a
32 bit unsigned number with the high bit set, followed by a
semi-colon.
<p>The second number is a type reference to the first base class in the
inheritance hierarchy defining the virtual member function. In this
case the class stab describes a base class so the virtual function is
not overriding any other definition of the method. Therefore the
reference is to the type number of the class that the stab is
describing (20).
<p>This is followed by three semi-colons. One marks the end of the
current sub-section, one marks the end of the method field, and the
third marks the end of the struct definition.
<p>For classes containing virtual functions the very last section of the
string part of the stab holds a type reference to the first base
class. This is preceded by &lsquo;<samp><span class="samp">~%</span></samp>&rsquo; and followed by a final semi-colon.
<pre class="display"> .stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
sym_desc(array)index_type_ref(range of int from 0 to 1);
elem_type_ref(vtbl elem type),
bit_offset(32);
meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
:arg_type(int),protection(public)normal(yes)virtual(yes)
vtable_index(1);class_first_defining(A);;;~%first_base(A);",
N_LSYM,NIL,NIL,NIL
</pre>
<!-- FIXME: bogus line break. -->
<pre class="example"> .stabs "A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
</pre>
</body></html>