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: Structures</title>
16
17<meta name="description" content="STABS: Structures">
18<meta name="keywords" content="STABS: Structures">
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="Types.html#Types" rel="up" title="Types">
27<link href="Typedefs.html#Typedefs" rel="next" title="Typedefs">
28<link href="Enumerations.html#Enumerations" rel="previous" title="Enumerations">
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="Structures"></a>
63<div class="header">
64<p>
65Next: <a href="Typedefs.html#Typedefs" accesskey="n" rel="next">Typedefs</a>, Previous: <a href="Enumerations.html#Enumerations" accesskey="p" rel="previous">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>
66</div>
67<hr>
68<a name="Structures-1"></a>
69<h3 class="section">5.8 Structures</h3>
70
71<p>The encoding of structures in stabs can be shown with an example.
72</p>
73<p>The following source code declares a structure tag and defines an
74instance of the structure in global scope. Then a <code>typedef</code> equates the
75structure tag with a new type.  Separate stabs are generated for the
76structure tag, the structure <code>typedef</code>, and the structure instance.  The
77stabs for the tag and the <code>typedef</code> are emitted when the definitions are
78encountered.  Since the structure elements are not initialized, the
79stab and code for the structure variable itself is located at the end
80of the program in the bss section.
81</p>
82<div class="example">
83<pre class="example">struct s_tag {
84  int   s_int;
85  float s_float;
86  char  s_char_vec[8];
87  struct s_tag* s_next;
88} g_an_s;
89
90typedef struct s_tag s_typedef;
91</pre></div>
92
93<p>The structure tag has an <code>N_LSYM</code> stab type because, like the
94enumeration, the symbol has file scope.  Like the enumeration, the
95symbol descriptor is &lsquo;<samp>T</samp>&rsquo;, for enumeration, structure, or tag type.
96The type descriptor &lsquo;<samp>s</samp>&rsquo; following the &lsquo;<samp>16=</samp>&rsquo; of the type
97definition narrows the symbol type to structure.
98</p>
99<p>Following the &lsquo;<samp>s</samp>&rsquo; type descriptor is the number of bytes the
100structure occupies, followed by a description of each structure element.
101The structure element descriptions are of the form
102&lsquo;<samp><var>name</var>:<var>type</var>, <var>bit offset from the start of the
103struct</var>, <var>number of bits in the element</var></samp>&rsquo;.
104</p>
105<div class="example">
106<pre class="example"># <span class="roman">128 is N_LSYM</span>
107.stabs &quot;s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
108        s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;&quot;,128,0,0,0
109</pre></div>
110
111<p>In this example, the first two structure elements are previously defined
112types.  For these, the type following the &lsquo;<samp><var>name</var>:</samp>&rsquo; part of the
113element description is a simple type reference.  The other two structure
114elements are new types.  In this case there is a type definition
115embedded after the &lsquo;<samp><var>name</var>:</samp>&rsquo;.  The type definition for the
116array element looks just like a type definition for a stand-alone array.
117The <code>s_next</code> field is a pointer to the same kind of structure that
118the field is an element of.  So the definition of structure type 16
119contains a type definition for an element which is a pointer to type 16.
120</p>
121<p>If a field is a static member (this is a C<tt>++</tt> feature in which a single
122variable appears to be a field of every structure of a given type) it
123still starts out with the field name, a colon, and the type, but then
124instead of a comma, bit position, comma, and bit size, there is a colon
125followed by the name of the variable which each such field refers to.
126</p>
127<p>If the structure has methods (a C<tt>++</tt> feature), they follow the non-method
128fields; see <a href="Cplusplus.html#Cplusplus">Cplusplus</a>.
129</p>
130<hr>
131<div class="header">
132<p>
133Next: <a href="Typedefs.html#Typedefs" accesskey="n" rel="next">Typedefs</a>, Previous: <a href="Enumerations.html#Enumerations" accesskey="p" rel="previous">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>
134</div>
135
136
137
138</body>
139</html>
140