toolchain/share/doc/stabs/Inheritance.html

147 lines
6.4 KiB
HTML
Raw Permalink Normal View History

2024-01-10 05:24:32 +00:00
<html lang="en">
<head>
<title>Inheritance - 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="Virtual-Methods.html#Virtual-Methods" title="Virtual Methods">
<link rel="next" href="Virtual-Base-Classes.html#Virtual-Base-Classes" title="Virtual Base Classes">
<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="Inheritance"></a>
<p>
Next:&nbsp;<a rel="next" accesskey="n" href="Virtual-Base-Classes.html#Virtual-Base-Classes">Virtual Base Classes</a>,
Previous:&nbsp;<a rel="previous" accesskey="p" href="Virtual-Methods.html#Virtual-Methods">Virtual Methods</a>,
Up:&nbsp;<a rel="up" accesskey="u" href="Cplusplus.html#Cplusplus">Cplusplus</a>
<hr>
</div>
<h3 class="section">8.12 Inheritance</h3>
<p>Stabs describing C<tt>++</tt> derived classes include additional sections that
describe the inheritance hierarchy of the class. A derived class stab
also encodes the number of base classes. For each base class it tells
if the base class is virtual or not, and if the inheritance is private
or public. It also gives the offset into the object of the portion of
the object corresponding to each base class.
<p>This additional information is embedded in the class stab following the
number of bytes in the struct. First the number of base classes
appears bracketed by an exclamation point and a comma.
<p>Then for each base type there repeats a series: a virtual character, a
visibility character, a number, a comma, another number, and a
semi-colon.
<p>The virtual character is &lsquo;<samp><span class="samp">1</span></samp>&rsquo; if the base class is virtual and
&lsquo;<samp><span class="samp">0</span></samp>&rsquo; if not. The visibility character is &lsquo;<samp><span class="samp">2</span></samp>&rsquo; if the derivation
is public, &lsquo;<samp><span class="samp">1</span></samp>&rsquo; if it is protected, and &lsquo;<samp><span class="samp">0</span></samp>&rsquo; if it is private.
Debuggers should ignore virtual or visibility characters they do not
recognize, and assume a reasonable default (such as public and
non-virtual) (GDB 4.11 does not, but this should be fixed in the next
GDB release).
<p>The number following the virtual and visibility characters is the offset
from the start of the object to the part of the object pertaining to the
base class.
<p>After the comma, the second number is a type_descriptor for the base
type. Finally a semi-colon ends the series, which repeats for each
base class.
<p>The source below defines three base classes <code>A</code>, <code>B</code>, and
<code>C</code> and the derived class <code>D</code>.
<pre class="example"> class A {
public:
int Adat;
virtual int A_virt (int arg) { return arg; };
};
class B {
public:
int B_dat;
virtual int B_virt (int arg) {return arg; };
};
class C {
public:
int Cdat;
virtual int C_virt (int arg) {return arg; };
};
class D : A, virtual B, public C {
public:
int Ddat;
virtual int A_virt (int arg ) { return arg+1; };
virtual int B_virt (int arg) { return arg+2; };
virtual int C_virt (int arg) { return arg+3; };
virtual int D_virt (int arg) { return arg; };
};
</pre>
<p>Class stabs similar to the ones described earlier are generated for
each base class.
<!-- FIXME!!! the linebreaks in the following example probably make the -->
<!-- examples literally unusable, but I don't know any other way to get -->
<!-- them on the page. -->
<!-- One solution would be to put some of the type definitions into -->
<!-- separate stabs, even if that's not exactly what the compiler actually -->
<!-- emits. -->
<pre class="smallexample"> .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
.stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
:i;2A*-2147483647;25;;;~%25;",128,0,0,0
.stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
:i;2A*-2147483647;28;;;~%28;",128,0,0,0
</pre>
<p>In the stab describing derived class <code>D</code> below, the information about
the derivation of this class is encoded as follows.
<pre class="display"> .stabs "derived_class_name:symbol_descriptors(struct tag&amp;type)=
type_descriptor(struct)struct_bytes(32)!num_bases(3),
base_virtual(no)inheritance_public(no)base_offset(0),
base_class_type_ref(A);
base_virtual(yes)inheritance_public(no)base_offset(NIL),
base_class_type_ref(B);
base_virtual(no)inheritance_public(yes)base_offset(64),
base_class_type_ref(C); <small class="dots">...</small>
</pre>
<!-- FIXME! fake linebreaks. -->
<pre class="smallexample"> .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
:32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
</pre>
</body></html>