blob: 8454516834b390bb2a1a144711468923aa59d67a [file] [log] [blame]
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<!-- Copyright (C) 1992-2015 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 5.2, http://www.gnu.org/software/texinfo/ -->
<head>
<title>STABS: Structures</title>
<meta name="description" content="STABS: Structures">
<meta name="keywords" content="STABS: Structures">
<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="Types.html#Types" rel="up" title="Types">
<link href="Typedefs.html#Typedefs" rel="next" title="Typedefs">
<link href="Enumerations.html#Enumerations" rel="prev" title="Enumerations">
<style type="text/css">
<!--
a.summary-letter {text-decoration: none}
blockquote.smallquotation {font-size: smaller}
div.display {margin-left: 3.2em}
div.example {margin-left: 3.2em}
div.indentedblock {margin-left: 3.2em}
div.lisp {margin-left: 3.2em}
div.smalldisplay {margin-left: 3.2em}
div.smallexample {margin-left: 3.2em}
div.smallindentedblock {margin-left: 3.2em; font-size: smaller}
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.nocodebreak {white-space:nowrap}
span.nolinebreak {white-space:nowrap}
span.roman {font-family:serif; font-weight:normal}
span.sansserif {font-family:sans-serif; font-weight:normal}
ul.no-bullet {list-style: none}
-->
</style>
</head>
<body lang="en" bgcolor="#FFFFFF" text="#000000" link="#0000FF" vlink="#800080" alink="#FF0000">
<a name="Structures"></a>
<div class="header">
<p>
Next: <a href="Typedefs.html#Typedefs" accesskey="n" rel="next">Typedefs</a>, Previous: <a href="Enumerations.html#Enumerations" accesskey="p" rel="prev">Enumerations</a>, Up: <a href="Types.html#Types" accesskey="u" rel="up">Types</a> &nbsp; [<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="Structures-1"></a>
<h3 class="section">5.8 Structures</h3>
<p>The encoding of structures in stabs can be shown with an example.
</p>
<p>The following source code declares a structure tag and defines an
instance of the structure in global scope. Then a <code>typedef</code> equates the
structure tag with a new type. Separate stabs are generated for the
structure tag, the structure <code>typedef</code>, and the structure instance. The
stabs for the tag and the <code>typedef</code> are emitted when the definitions are
encountered. Since the structure elements are not initialized, the
stab and code for the structure variable itself is located at the end
of the program in the bss section.
</p>
<div class="example">
<pre class="example">struct s_tag {
int s_int;
float s_float;
char s_char_vec[8];
struct s_tag* s_next;
} g_an_s;
typedef struct s_tag s_typedef;
</pre></div>
<p>The structure tag has an <code>N_LSYM</code> stab type because, like the
enumeration, the symbol has file scope. Like the enumeration, the
symbol descriptor is &lsquo;<samp>T</samp>&rsquo;, for enumeration, structure, or tag type.
The type descriptor &lsquo;<samp>s</samp>&rsquo; following the &lsquo;<samp>16=</samp>&rsquo; of the type
definition narrows the symbol type to structure.
</p>
<p>Following the &lsquo;<samp>s</samp>&rsquo; type descriptor is the number of bytes the
structure occupies, followed by a description of each structure element.
The structure element descriptions are of the form
&lsquo;<samp><var>name</var>:<var>type</var>, <var>bit offset from the start of the
struct</var>, <var>number of bits in the element</var></samp>&rsquo;.
</p>
<div class="example">
<pre class="example"># <span class="roman">128 is N_LSYM</span>
.stabs &quot;s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;&quot;,128,0,0,0
</pre></div>
<p>In this example, the first two structure elements are previously defined
types. For these, the type following the &lsquo;<samp><var>name</var>:</samp>&rsquo; part of the
element description is a simple type reference. The other two structure
elements are new types. In this case there is a type definition
embedded after the &lsquo;<samp><var>name</var>:</samp>&rsquo;. The type definition for the
array element looks just like a type definition for a stand-alone array.
The <code>s_next</code> field is a pointer to the same kind of structure that
the field is an element of. So the definition of structure type 16
contains a type definition for an element which is a pointer to type 16.
</p>
<p>If a field is a static member (this is a C<tt>++</tt> feature in which a single
variable appears to be a field of every structure of a given type) it
still starts out with the field name, a colon, and the type, but then
instead of a comma, bit position, comma, and bit size, there is a colon
followed by the name of the variable which each such field refers to.
</p>
<p>If the structure has methods (a C<tt>++</tt> feature), they follow the non-method
fields; see <a href="Cplusplus.html#Cplusplus">Cplusplus</a>.
</p>
<hr>
<div class="header">
<p>
Next: <a href="Typedefs.html#Typedefs" accesskey="n" rel="next">Typedefs</a>, Previous: <a href="Enumerations.html#Enumerations" accesskey="p" rel="prev">Enumerations</a>, Up: <a href="Types.html#Types" accesskey="u" rel="up">Types</a> &nbsp; [<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>