<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <!-- 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". --> <!-- Created by GNU Texinfo 6.4, http://www.gnu.org/software/texinfo/ --> <head> <title>Inheritance (STABS)</title> <meta name="description" content="Inheritance (STABS)"> <meta name="keywords" content="Inheritance (STABS)"> <meta name="resource-type" content="document"> <meta name="distribution" content="global"> <meta name="Generator" content="makeinfo"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <link href="index.html#Top" rel="start" title="Top"> <link href="Symbol-Types-Index.html#Symbol-Types-Index" rel="index" title="Symbol Types Index"> <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents"> <link href="Cplusplus.html#Cplusplus" rel="up" title="Cplusplus"> <link href="Virtual-Base-Classes.html#Virtual-Base-Classes" rel="next" title="Virtual Base Classes"> <link href="Virtual-Methods.html#Virtual-Methods" rel="prev" title="Virtual Methods"> <style type="text/css"> <!-- a.summary-letter {text-decoration: none} blockquote.indentedblock {margin-right: 0em} blockquote.smallindentedblock {margin-right: 0em; font-size: smaller} blockquote.smallquotation {font-size: smaller} div.display {margin-left: 3.2em} div.example {margin-left: 3.2em} div.lisp {margin-left: 3.2em} div.smalldisplay {margin-left: 3.2em} div.smallexample {margin-left: 3.2em} div.smalllisp {margin-left: 3.2em} kbd {font-style: oblique} pre.display {font-family: inherit} pre.format {font-family: inherit} pre.menu-comment {font-family: serif} pre.menu-preformatted {font-family: serif} pre.smalldisplay {font-family: inherit; font-size: smaller} pre.smallexample {font-size: smaller} pre.smallformat {font-family: inherit; font-size: smaller} pre.smalllisp {font-size: smaller} span.nolinebreak {white-space: nowrap} span.roman {font-family: initial; font-weight: normal} span.sansserif {font-family: sans-serif; font-weight: normal} ul.no-bullet {list-style: none} --> </style> </head> <body lang="en"> <a name="Inheritance"></a> <div class="header"> <p> Next: <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="prev">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> </div> <hr> <a name="Inheritance-1"></a> <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> <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> <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> <p>The virtual character is ‘<samp>1</samp>’ if the base class is virtual and ‘<samp>0</samp>’ if not. The visibility character is ‘<samp>2</samp>’ if the derivation is public, ‘<samp>1</samp>’ if it is protected, and ‘<samp>0</samp>’ 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> <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> <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> <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>. </p> <div class="example"> <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></div> <p>Class stabs similar to the ones described earlier are generated for each base class. </p> <div class="smallexample"> <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></div> <p>In the stab describing derived class <code>D</code> below, the information about the derivation of this class is encoded as follows. </p> <div class="display"> <pre class="display">.stabs "derived_class_name:symbol_descriptors(struct tag&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); … </pre></div> <div class="smallexample"> <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></div> <hr> <div class="header"> <p> Next: <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="prev">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> </div> </body> </html>