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: Inheritance</title> 16 17<meta name="description" content="STABS: Inheritance"> 18<meta name="keywords" content="STABS: Inheritance"> 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="Virtual-Base-Classes.html#Virtual-Base-Classes" rel="next" title="Virtual Base Classes"> 28<link href="Virtual-Methods.html#Virtual-Methods" rel="previous" title="Virtual Methods"> 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="Inheritance"></a> 63<div class="header"> 64<p> 65Next: <a href="Virtual-Base-Classes.html#Virtual-Base-Classes" accesskey="n" rel="next">Virtual Base Classes</a>, Previous: <a href="Virtual-Methods.html#Virtual-Methods" accesskey="p" rel="previous">Virtual Methods</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="Inheritance-1"></a> 69<h3 class="section">8.12 Inheritance</h3> 70 71<p>Stabs describing C<tt>++</tt> derived classes include additional sections that 72describe the inheritance hierarchy of the class. A derived class stab 73also encodes the number of base classes. For each base class it tells 74if the base class is virtual or not, and if the inheritance is private 75or public. It also gives the offset into the object of the portion of 76the object corresponding to each base class. 77</p> 78<p>This additional information is embedded in the class stab following the 79number of bytes in the struct. First the number of base classes 80appears bracketed by an exclamation point and a comma. 81</p> 82<p>Then for each base type there repeats a series: a virtual character, a 83visibility character, a number, a comma, another number, and a 84semi-colon. 85</p> 86<p>The virtual character is ‘<samp>1</samp>’ if the base class is virtual and 87‘<samp>0</samp>’ if not. The visibility character is ‘<samp>2</samp>’ if the derivation 88is public, ‘<samp>1</samp>’ if it is protected, and ‘<samp>0</samp>’ if it is private. 89Debuggers should ignore virtual or visibility characters they do not 90recognize, and assume a reasonable default (such as public and 91non-virtual) (GDB 4.11 does not, but this should be fixed in the next 92GDB release). 93</p> 94<p>The number following the virtual and visibility characters is the offset 95from the start of the object to the part of the object pertaining to the 96base class. 97</p> 98<p>After the comma, the second number is a type_descriptor for the base 99type. Finally a semi-colon ends the series, which repeats for each 100base class. 101</p> 102<p>The source below defines three base classes <code>A</code>, <code>B</code>, and 103<code>C</code> and the derived class <code>D</code>. 104</p> 105 106<div class="example"> 107<pre class="example">class A { 108public: 109 int Adat; 110 virtual int A_virt (int arg) { return arg; }; 111}; 112 113class B { 114public: 115 int B_dat; 116 virtual int B_virt (int arg) {return arg; }; 117}; 118 119class C { 120public: 121 int Cdat; 122 virtual int C_virt (int arg) {return arg; }; 123}; 124 125class D : A, virtual B, public C { 126public: 127 int Ddat; 128 virtual int A_virt (int arg ) { return arg+1; }; 129 virtual int B_virt (int arg) { return arg+2; }; 130 virtual int C_virt (int arg) { return arg+3; }; 131 virtual int D_virt (int arg) { return arg; }; 132}; 133</pre></div> 134 135<p>Class stabs similar to the ones described earlier are generated for 136each base class. 137</p> 138<div class="smallexample"> 139<pre class="smallexample">.stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32; 140 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0 141 142.stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1; 143 :i;2A*-2147483647;25;;;~%25;",128,0,0,0 144 145.stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1; 146 :i;2A*-2147483647;28;;;~%28;",128,0,0,0 147</pre></div> 148 149<p>In the stab describing derived class <code>D</code> below, the information about 150the derivation of this class is encoded as follows. 151</p> 152<div class="display"> 153<pre class="display">.stabs "derived_class_name:symbol_descriptors(struct tag&type)= 154 type_descriptor(struct)struct_bytes(32)!num_bases(3), 155 base_virtual(no)inheritance_public(no)base_offset(0), 156 base_class_type_ref(A); 157 base_virtual(yes)inheritance_public(no)base_offset(NIL), 158 base_class_type_ref(B); 159 base_virtual(no)inheritance_public(yes)base_offset(64), 160 base_class_type_ref(C); … 161</pre></div> 162 163<div class="smallexample"> 164<pre class="smallexample">.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat: 165 1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt: 166 :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647; 167 28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0 168</pre></div> 169 170<hr> 171<div class="header"> 172<p> 173Next: <a href="Virtual-Base-Classes.html#Virtual-Base-Classes" accesskey="n" rel="next">Virtual Base Classes</a>, Previous: <a href="Virtual-Methods.html#Virtual-Methods" accesskey="p" rel="previous">Virtual Methods</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> 174</div> 175 176 177 178</body> 179</html> 180