* mipsread.c (parse_symbol): Put stStaticProc symbols in minimal
[deliverable/binutils-gdb.git] / gdb / doc / stabs.texinfo
CommitLineData
e505224d
PB
1\input texinfo
2@setfilename stabs.info
3
4@ifinfo
5@format
6START-INFO-DIR-ENTRY
8a6d5d4f 7* Stabs:: The "stabs" debugging information format.
e505224d
PB
8END-INFO-DIR-ENTRY
9@end format
10@end ifinfo
11
12@ifinfo
8c59ee11 13This document describes the stabs debugging symbol tables.
e505224d 14
612dbd4c 15Copyright 1992 Free Software Foundation, Inc.
e505224d
PB
16Contributed by Cygnus Support. Written by Julia Menapace.
17
18Permission is granted to make and distribute verbatim copies of
19this manual provided the copyright notice and this permission notice
20are preserved on all copies.
21
22@ignore
23Permission is granted to process this file through Tex and print the
24results, provided the printed document carries copying permission
25notice identical to this one except for the removal of this paragraph
26(this paragraph not being relevant to the printed manual).
27
28@end ignore
29Permission is granted to copy or distribute modified versions of this
30manual under the terms of the GPL (for which purpose this text may be
31regarded as a program in the language TeX).
32@end ifinfo
33
139741da 34@setchapternewpage odd
e505224d
PB
35@settitle STABS
36@titlepage
139741da 37@title The ``stabs'' debug format
e505224d
PB
38@author Julia Menapace
39@author Cygnus Support
40@page
41@tex
42\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
43\xdef\manvers{\$Revision$} % For use in headers, footers too
44{\parskip=0pt
45\hfill Cygnus Support\par
46\hfill \manvers\par
47\hfill \TeX{}info \texinfoversion\par
48}
49@end tex
50
51@vskip 0pt plus 1filll
899bafeb
RP
52Copyright @copyright{} 1992 Free Software Foundation, Inc.
53Contributed by Cygnus Support.
e505224d
PB
54
55Permission is granted to make and distribute verbatim copies of
56this manual provided the copyright notice and this permission notice
57are preserved on all copies.
58
59@end titlepage
60
899bafeb
RP
61@ifinfo
62@node Top
63@top The "stabs" representation of debugging information
e505224d 64
6ae55c65 65This document describes the stabs debugging format.
e505224d
PB
66
67@menu
8eb5e289
DZ
68* Overview:: Overview of stabs
69* Program structure:: Encoding of the structure of the program
6897f9ec 70* Constants:: Constants
8eb5e289
DZ
71* Example:: A comprehensive example in C
72* Variables::
8c59ee11 73* Types:: Type definitions
8eb5e289
DZ
74* Symbol Tables:: Symbol information in symbol tables
75* Cplusplus:: Appendixes:
76* Example2.c:: Source code for extended example
77* Example2.s:: Assembly code for extended example
78* Stab Types:: Symbol types in a.out files
79* Symbol Descriptors:: Table of Symbol Descriptors
80* Type Descriptors:: Table of Symbol Descriptors
81* Expanded reference:: Reference information by stab type
82* Questions:: Questions and anomolies
83* xcoff-differences:: Differences between GNU stabs in a.out
139741da 84 and GNU stabs in xcoff
8eb5e289 85* Sun-differences:: Differences between GNU stabs and Sun
139741da 86 native stabs
807e8368 87* Stabs-in-elf:: Stabs in an ELF file.
e505224d 88@end menu
899bafeb 89@end ifinfo
e505224d
PB
90
91
899bafeb 92@node Overview
e505224d
PB
93@chapter Overview of stabs
94
139741da
RP
95@dfn{Stabs} refers to a format for information that describes a program
96to a debugger. This format was apparently invented by
97@c FIXME! <<name of inventor>> at
98the University of California at Berkeley, for the @code{pdx} Pascal
99debugger; the format has spread widely since then.
100
8c59ee11
JK
101This document is one of the few published sources of documentation on
102stabs. It is believed to be completely comprehensive for stabs used by
103C. The lists of symbol descriptors (@pxref{Symbol Descriptors}) and
104type descriptors (@pxref{Type Descriptors}) are believed to be completely
105comprehensive. There are known to be stabs for C++ and COBOL which are
106poorly documented here. Stabs specific to other languages (e.g. Pascal,
107Modula-2) are probably not as well documented as they should be.
108
109Other sources of information on stabs are @cite{dbx and dbxtool
110interfaces}, 2nd edition, by Sun, circa 1988, and @cite{AIX Version 3.2
111Files Reference}, Fourth Edition, September 1992, "dbx Stabstring
112Grammar" in the a.out section, page 2-31. This document is believed to
113incorporate the information from those two sources except where it
114explictly directs you to them for more information.
115
e505224d 116@menu
8eb5e289
DZ
117* Flow:: Overview of debugging information flow
118* Stabs Format:: Overview of stab format
119* C example:: A simple example in C source
120* Assembly code:: The simple example at the assembly level
e505224d
PB
121@end menu
122
899bafeb 123@node Flow
e505224d
PB
124@section Overview of debugging information flow
125
139741da
RP
126The GNU C compiler compiles C source in a @file{.c} file into assembly
127language in a @file{.s} file, which is translated by the assembler into
128a @file{.o} file, and then linked with other @file{.o} files and
129libraries to produce an executable file.
e505224d 130
139741da
RP
131With the @samp{-g} option, GCC puts additional debugging information in
132the @file{.s} file, which is slightly transformed by the assembler and
e505224d
PB
133linker, and carried through into the final executable. This debugging
134information describes features of the source file like line numbers,
135the types and scopes of variables, and functions, their parameters and
136their scopes.
137
138For some object file formats, the debugging information is
139741da 139encapsulated in assembler directives known collectively as `stab' (symbol
e505224d
PB
140table) directives, interspersed with the generated code. Stabs are
141the native format for debugging information in the a.out and xcoff
142object file formats. The GNU tools can also emit stabs in the coff
143and ecoff object file formats.
144
139741da
RP
145The assembler adds the information from stabs to the symbol information
146it places by default in the symbol table and the string table of the
147@file{.o} file it is building. The linker consolidates the @file{.o}
148files into one executable file, with one symbol table and one string
149table. Debuggers use the symbol and string tables in the executable as
150a source of debugging information about the program.
e505224d 151
8c59ee11 152@node Stabs Format
e505224d
PB
153@section Overview of stab format
154
155There are three overall formats for stab assembler directives
139741da
RP
156differentiated by the first word of the stab. The name of the directive
157describes what combination of four possible data fields will follow. It
158is either @code{.stabs} (string), @code{.stabn} (number), or
63cef7d7
JK
159@code{.stabd} (dot). IBM's xcoff uses @code{.stabx} (and some other
160directives such as @code{.file} and @code{.bi}) instead of
161@code{.stabs}, @code{.stabn} or @code{.stabd}.
e505224d
PB
162
163The overall format of each class of stab is:
164
165@example
139741da 166.stabs "@var{string}",@var{type},0,@var{desc},@var{value}
63cef7d7
JK
167.stabx "@var{string}",@var{value},@var{type},@var{sdb-type}
168.stabn @var{type},0,@var{desc},@var{value}
169.stabd @var{type},0,@var{desc}
e505224d
PB
170@end example
171
63cef7d7
JK
172@c what is the correct term for "current file location"? My AIX
173@c assembler manual calls it "the value of the current location counter".
174For @code{.stabn} and @code{.stabd}, there is no string (the
175@code{n_strx} field is zero, @pxref{Symbol Tables}). For @code{.stabd}
176the value field is implicit and has the value of the current file
177location. The @var{sdb-type} field to @code{.stabx} is unused for stabs
178and can always be set to 0.
e505224d 179
6897f9ec
JK
180The number in the type field gives some basic information about what
181type of stab this is (or whether it @emph{is} a stab, as opposed to an
182ordinary symbol). Each possible type number defines a different stab
183type. The stab type further defines the exact interpretation of, and
184possible values for, any remaining @code{"@var{string}"}, @var{desc}, or
3d4cf720
JK
185@var{value} fields present in the stab. @xref{Stab Types}, for a list
186in numeric order of the possible type field values for stab directives.
e505224d 187
139741da
RP
188For @code{.stabs} the @code{"@var{string}"} field holds the meat of the
189debugging information. The generally unstructured nature of this field
190is what makes stabs extensible. For some stab types the string field
191contains only a name. For other stab types the contents can be a great
192deal more complex.
e505224d 193
139741da 194The overall format is of the @code{"@var{string}"} field is:
e505224d
PB
195
196@example
46351197 197"@var{name}:@var{symbol-descriptor} @var{type-information}"
e505224d
PB
198@end example
199
139741da 200@var{name} is the name of the symbol represented by the stab.
6897f9ec 201@var{name} can be omitted, which means the stab represents an unnamed
8c59ee11 202object. For example, @samp{:t10=*2} defines type 10 as a pointer to
6897f9ec
JK
203type 2, but does not give the type a name. Omitting the @var{name}
204field is supported by AIX dbx and GDB after about version 4.8, but not
46351197
JK
205other debuggers. GCC sometimes uses a single space as the name instead
206of omitting the name altogether; apparently that is supported by most
207debuggers.
e505224d 208
139741da
RP
209The @var{symbol_descriptor} following the @samp{:} is an alphabetic
210character that tells more specifically what kind of symbol the stab
211represents. If the @var{symbol_descriptor} is omitted, but type
212information follows, then the stab represents a local variable. For a
8c59ee11 213list of symbol descriptors, see @ref{Symbol Descriptors,,Table C: Symbol
139741da 214descriptors}.
e505224d 215
6897f9ec
JK
216The @samp{c} symbol descriptor is an exception in that it is not
217followed by type information. @xref{Constants}.
218
139741da
RP
219Type information is either a @var{type_number}, or a
220@samp{@var{type_number}=}. The @var{type_number} alone is a type
221reference, referring directly to a type that has already been defined.
e505224d 222
139741da
RP
223The @samp{@var{type_number}=} is a type definition, where the number
224represents a new type which is about to be defined. The type definition
225may refer to other types by number, and those type numbers may be
226followed by @samp{=} and nested definitions.
e505224d
PB
227
228In a type definition, if the character that follows the equals sign is
139741da
RP
229non-numeric then it is a @var{type_descriptor}, and tells what kind of
230type is about to be defined. Any other values following the
231@var{type_descriptor} vary, depending on the @var{type_descriptor}. If
232a number follows the @samp{=} then the number is a @var{type_reference}.
233This is described more thoroughly in the section on types. @xref{Type
234Descriptors,,Table D: Type Descriptors}, for a list of
235@var{type_descriptor} values.
236
6897f9ec
JK
237There is an AIX extension for type attributes. Following the @samp{=}
238is any number of type attributes. Each one starts with @samp{@@} and
239ends with @samp{;}. Debuggers, including AIX's dbx, skip any type
8abe8194 240attributes they do not recognize. GDB 4.9 does not do this---it will
8c59ee11
JK
241ignore the entire symbol containing a type attribute. Hopefully this
242will be fixed in the next GDB release. Because of a conflict with C++
243(@pxref{Cplusplus}), new attributes should not be defined which begin
244with a digit, @samp{(}, or @samp{-}; GDB may be unable to distinguish
245those from the C++ type descriptor @samp{@@}. The attributes are:
6897f9ec
JK
246
247@table @code
248@item a@var{boundary}
8c59ee11 249@var{boundary} is an integer specifying the alignment. I assume it
6897f9ec
JK
250applies to all variables of this type.
251
252@item s@var{size}
8c59ee11 253Size in bits of a variable of this type.
6897f9ec
JK
254
255@item p@var{integer}
256Pointer class (for checking). Not sure what this means, or how
257@var{integer} is interpreted.
258
259@item P
260Indicate this is a packed type, meaning that structure fields or array
261elements are placed more closely in memory, to save memory at the
262expense of speed.
263@end table
264
b6963343
JK
265All this can make the @code{"@var{string}"} field quite long. All
266versions of GDB, and some versions of DBX, can handle arbitrarily long
267strings. But many versions of DBX cretinously limit the strings to
268about 80 characters, so compilers which must work with such DBX's need
269to split the @code{.stabs} directive into several @code{.stabs}
270directives. Each stab duplicates exactly all but the
6897f9ec 271@code{"@var{string}"} field. The @code{"@var{string}"} field of
b6963343
JK
272every stab except the last is marked as continued with a
273double-backslash at the end. Removing the backslashes and concatenating
274the @code{"@var{string}"} fields of each stab produces the original,
275long string.
e505224d 276
899bafeb 277@node C example
e505224d
PB
278@section A simple example in C source
279
280To get the flavor of how stabs describe source information for a C
281program, let's look at the simple program:
282
283@example
284main()
285@{
139741da 286 printf("Hello world");
e505224d
PB
287@}
288@end example
289
139741da
RP
290When compiled with @samp{-g}, the program above yields the following
291@file{.s} file. Line numbers have been added to make it easier to refer
292to parts of the @file{.s} file in the description of the stabs that
293follows.
e505224d 294
899bafeb 295@node Assembly code
e505224d
PB
296@section The simple example at the assembly level
297
298@example
2991 gcc2_compiled.:
3002 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
3013 .stabs "hello.c",100,0,0,Ltext0
3024 .text
3035 Ltext0:
3046 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
3057 .stabs "char:t2=r2;0;127;",128,0,0,0
3068 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
3079 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
30810 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
30911 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
31012 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
31113 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
31214 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
31315 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
31416 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
31517 .stabs "float:t12=r1;4;0;",128,0,0,0
31618 .stabs "double:t13=r1;8;0;",128,0,0,0
31719 .stabs "long double:t14=r1;8;0;",128,0,0,0
31820 .stabs "void:t15=15",128,0,0,0
139741da 31921 .align 4
e505224d 32022 LC0:
139741da
RP
32123 .ascii "Hello, world!\12\0"
32224 .align 4
32325 .global _main
32426 .proc 1
e505224d
PB
32527 _main:
32628 .stabn 68,0,4,LM1
32729 LM1:
139741da
RP
32830 !#PROLOGUE# 0
32931 save %sp,-136,%sp
33032 !#PROLOGUE# 1
33133 call ___main,0
33234 nop
e505224d
PB
33335 .stabn 68,0,5,LM2
33436 LM2:
33537 LBB2:
139741da
RP
33638 sethi %hi(LC0),%o1
33739 or %o1,%lo(LC0),%o0
33840 call _printf,0
33941 nop
e505224d
PB
34042 .stabn 68,0,6,LM3
34143 LM3:
34244 LBE2:
34345 .stabn 68,0,6,LM4
34446 LM4:
34547 L1:
139741da
RP
34648 ret
34749 restore
e505224d
PB
34850 .stabs "main:F1",36,0,0,_main
34951 .stabn 192,0,0,LBB2
35052 .stabn 224,0,0,LBE2
351@end example
352
139741da 353This simple ``hello world'' example demonstrates several of the stab
e505224d
PB
354types used to describe C language source files.
355
899bafeb 356@node Program structure
139741da 357@chapter Encoding for the structure of the program
e505224d
PB
358
359@menu
499a5faa 360* Main Program:: Indicate what the main program is
8eb5e289
DZ
361* Source Files:: The path and name of the source file
362* Line Numbers::
363* Procedures::
364* Block Structure::
e505224d
PB
365@end menu
366
499a5faa
JK
367@node Main Program
368@section Main Program
369
370Most languages allow the main program to have any name. The
371@code{N_MAIN} stab type is used for a stab telling the debugger what
372name is used in this program. Only the name is significant; it will be
373the name of a function which is the main program. Most C compilers do
374not use this stab; they expect the debugger to simply assume that the
375name is @samp{main}, but some C compilers emit an @code{N_MAIN} stab for
376the @samp{main} function.
377
63cef7d7
JK
378@node Source Files
379@section The path and name of the source files
e505224d 380
63cef7d7
JK
381Before any other stabs occur, there must be a stab specifying the source
382file. This information is contained in a symbol of stab type
383@code{N_SO}; the string contains the name of the file. The value of the
384symbol is the start address of portion of the text section corresponding
385to that file.
e505224d 386
ded6bcab
JK
387With the Sun Solaris2 compiler, the @code{desc} field contains a
388source-language code.
389
63cef7d7
JK
390Some compilers (for example, gcc2 and SunOS4 @file{/bin/cc}) also
391include the directory in which the source was compiled, in a second
392@code{N_SO} symbol preceding the one containing the file name. This
ded6bcab
JK
393symbol can be distinguished by the fact that it ends in a slash. Code
394from the cfront C++ compiler can have additional @code{N_SO} symbols for
395nonexistent source files after the @code{N_SO} for the real source file;
396these are believed to contain no useful information.
e505224d 397
63cef7d7
JK
398For example:
399
400@example
401.stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0 ; 100 is N_SO
402.stabs "hello.c",100,0,0,Ltext0
403 .text
404Ltext0:
405@end example
406
407Instead of @code{N_SO} symbols, XCOFF uses a @code{.file} assembler
408directive which assembles to a standard COFF @code{.file} symbol;
409explaining this in detail is outside the scope of this document.
410
411There are several different schemes for dealing with include files: the
412traditional @code{N_SOL} approach, Sun's @code{N_BINCL} scheme, and the
413XCOFF @code{C_BINCL} (which despite the similar name has little in
414common with @code{N_BINCL}).
415
416An @code{N_SOL} symbol specifies which include file subsequent symbols
417refer to. The string field is the name of the file and the value is the
418text address corresponding to the start of the previous include file and
419the start of this one. To specify the main source file again, use an
420@code{N_SOL} symbol with the name of the main source file.
421
422A @code{N_BINCL} symbol specifies the start of an include file. In an
423object file, only the name is significant. The Sun linker puts data
424into some of the other fields. The end of the include file is marked by
ded6bcab
JK
425a @code{N_EINCL} symbol (which has no name field). In an ojbect file,
426there is no significant data in the @code{N_EINCL} symbol; the Sun
427linker puts data into some of the fields. @code{N_BINCL} and
428@code{N_EINCL} can be nested. If the linker detects that two source
429files have identical stabs with a @code{N_BINCL} and @code{N_EINCL} pair
430(as will generally be the case for a header file), then it only puts out
431the stabs once. Each additional occurance is replaced by an
432@code{N_EXCL} symbol. I believe the Sun (SunOS4, not sure about
433Solaris) linker is the only one which supports this feature.
63cef7d7
JK
434
435For the start of an include file in XCOFF, use the @file{.bi} assembler
436directive which generates a @code{C_BINCL} symbol. A @file{.ei}
437directive, which generates a @code{C_EINCL} symbol, denotes the end of
438the include file. Both directives are followed by the name of the
439source file in quotes, which becomes the string for the symbol. The
440value of each symbol, produced automatically by the assembler and
441linker, is an offset into the executable which points to the beginning
442(inclusive, as you'd expect) and end (inclusive, as you would not
443expect) of the portion of the COFF linetable which corresponds to this
444include file. @code{C_BINCL} and @code{C_EINCL} do not nest.
445
446@node Line Numbers
e505224d
PB
447@section Line Numbers
448
63cef7d7
JK
449A @code{N_SLINE} symbol represents the start of a source line. The
450@var{desc} field contains the line number and the @var{value} field
f0f4b04e
JK
451contains the code address for the start of that source line. On most
452machines the address is absolute; for Sun's stabs-in-elf, it is relative
453to the function in which the @code{N_SLINE} symbol occurs.
e505224d 454
63cef7d7
JK
455GNU documents @code{N_DSLINE} and @code{N_BSLINE} symbols for line
456numbers in the data or bss segments, respectively. They are identical
457to @code{N_SLINE} but are relocated differently by the linker. They
458were intended to be used to describe the source location of a variable
459declaration, but I believe that gcc2 actually puts the line number in
460the desc field of the stab for the variable itself. GDB has been
461ignoring these symbols (unless they contain a string field) at least
462since GDB 3.5.
e505224d 463
63cef7d7
JK
464XCOFF uses COFF line numbers instead, which are outside the scope of
465this document, ammeliorated by adequate marking of include files
466(@pxref{Source Files}).
139741da 467
63cef7d7
JK
468For single source lines that generate discontiguous code, such as flow
469of control statements, there may be more than one line number entry for
470the same source line. In this case there is a line number entry at the
471start of each code range, each with the same line number.
e505224d 472
899bafeb 473@node Procedures
6897f9ec
JK
474@section Procedures
475
476All of the following stabs use the @samp{N_FUN} symbol type.
477
478A function is represented by a @samp{F} symbol descriptor for a global
479(extern) function, and @samp{f} for a static (local) function. The next
480@samp{N_SLINE} symbol can be used to find the line number of the start
481of the function. The value field is the address of the start of the
482function. The type information of the stab represents the return type
483of the function; thus @samp{foo:f5} means that foo is a function
484returning type 5.
485
ded6bcab
JK
486The type information of the stab is optionally followed by type
487information for each argument, with each argument preceded by @samp{;}.
488An argument type of 0 means that additional arguments are being passed,
489whose types and number may vary (@samp{...} in ANSI C). This extension
490is used by Sun's Solaris compiler. GDB has tolerated it (i.e. at least
491parsed the syntax, if not necessarily used the information) at least
492since version 4.8; I don't know whether all versions of dbx will
493tolerate it. The argument types given here are not merely redundant
494with the symbols for the arguments themselves (@pxref{Parameters}), they
495are the types of the arguments as they are passed, before any
496conversions might take place. For example, if a C function which is
497declared without a prototype takes a @code{float} argument, the value is
498passed as a @code{double} but then converted to a @code{float}.
499Debuggers need to use the types given in the arguments when printing
500values, but if calling the function they need to use the types given in
501the symbol defining the function.
502
503If the return type and types of arguments of a function which is defined
504in another source file are specified (i.e. a function prototype in ANSI
505C), traditionally compilers emit no stab; the only way for the debugger
506to find the information is if the source file where the function is
507defined was also compiled with debugging symbols. As an extension the
508Solaris compiler uses symbol descriptor @samp{P} followed by the return
509type of the function, followed by the arguments, each preceded by
510@samp{;}, as in a stab with symbol descriptor @samp{f} or @samp{F}.
511This use of symbol descriptor @samp{P} can be distinguished from its use
512for register parameters (@pxref{Parameters}) by the fact that it has
513symbol type @code{N_FUN}.
514
6897f9ec
JK
515The AIX documentation also defines symbol descriptor @samp{J} as an
516internal function. I assume this means a function nested within another
517function. It also says Symbol descriptor @samp{m} is a module in
518Modula-2 or extended Pascal.
519
520Procedures (functions which do not return values) are represented as
521functions returning the void type in C. I don't see why this couldn't
522be used for all languages (inventing a void type for this purpose if
523necessary), but the AIX documentation defines @samp{I}, @samp{P}, and
524@samp{Q} for internal, global, and static procedures, respectively.
525These symbol descriptors are unusual in that they are not followed by
526type information.
527
8c59ee11
JK
528For any of the above symbol descriptors, after the symbol descriptor and
529the type information, there is optionally a comma, followed by the name
530of the procedure, followed by a comma, followed by a name specifying the
531scope. The first name is local to the scope specified. I assume then
532that the name of the symbol (before the @samp{:}), if specified, is some
533sort of global name. I assume the name specifying the scope is the name
534of a function specifying that scope. This feature is an AIX extension,
535and this information is based on the manual; I haven't actually tried
536it.
6897f9ec
JK
537
538The stab representing a procedure is located immediately following the
539code of the procedure. This stab is in turn directly followed by a
540group of other stabs describing elements of the procedure. These other
541stabs describe the procedure's parameters, its block local variables and
542its block structure.
e505224d
PB
543
544@example
139741da
RP
54548 ret
54649 restore
e505224d
PB
547@end example
548
139741da
RP
549The @code{.stabs} entry after this code fragment shows the @var{name} of
550the procedure (@code{main}); the type descriptor @var{desc} (@code{F},
551for a global procedure); a reference to the predefined type @code{int}
552for the return type; and the starting @var{address} of the procedure.
553
554Here is an exploded summary (with whitespace introduced for clarity),
555followed by line 50 of our sample assembly output, which has this form:
556
e505224d 557@example
139741da
RP
558.stabs "@var{name}:
559 @var{desc} @r{(global proc @samp{F})}
560 @var{return_type_ref} @r{(int)}
561 ",N_FUN, NIL, NIL,
562 @var{address}
e505224d
PB
563@end example
564
565@example
56650 .stabs "main:F1",36,0,0,_main
567@end example
568
899bafeb 569@node Block Structure
e505224d
PB
570@section Block Structure
571
139741da 572The program's block structure is represented by the @code{N_LBRAC} (left
f0f4b04e
JK
573brace) and the @code{N_RBRAC} (right brace) stab types. The variables
574defined inside a block preceded the @code{N_LBRAC} symbol for most
575compilers, including GCC. Other compilers, such as the Convex, Acorn
576RISC machine, and Sun acc compilers, put the variables after the
577@code{N_LBRAC} symbol. The values of the @code{N_LBRAC} and
578@code{N_RBRAC} symbols are the start and end addresses of the code of
579the block, respectively. For most machines, they are relative to the
580starting address of this source file. For the Gould NP1, they are
581absolute. For Sun's stabs-in-elf, they are relative to the function in
582which they occur.
e505224d 583
139741da 584The @code{N_LBRAC} and @code{N_RBRAC} stabs that describe the block
f0f4b04e
JK
585scope of a procedure are located after the @code{N_FUN} stab that
586represents the procedure itself.
e505224d 587
f0f4b04e
JK
588Sun documents the @code{desc} field of @code{N_LBRAC} and
589@code{N_RBRAC} symbols as containing the nesting level of the block.
590However, dbx seems not to care, and GCC just always set @code{desc} to
591zero.
e505224d 592
6897f9ec
JK
593@node Constants
594@chapter Constants
595
596The @samp{c} symbol descriptor indicates that this stab represents a
597constant. This symbol descriptor is an exception to the general rule
598that symbol descriptors are followed by type information. Instead, it
599is followed by @samp{=} and one of the following:
600
601@table @code
b273dc0f 602@item b @var{value}
6897f9ec
JK
603Boolean constant. @var{value} is a numeric value; I assume it is 0 for
604false or 1 for true.
605
b273dc0f 606@item c @var{value}
6897f9ec
JK
607Character constant. @var{value} is the numeric value of the constant.
608
b273dc0f
JK
609@item e @var{type-information} , @var{value}
610Constant whose value can be represented as integral.
611@var{type-information} is the type of the constant, as it would appear
612after a symbol descriptor (@pxref{Stabs Format}). @var{value} is the
613numeric value of the constant. GDB 4.9 does not actually get the right
614value if @var{value} does not fit in a host @code{int}, but it does not
615do anything violent, and future debuggers could be extended to accept
616integers of any size (whether unsigned or not). This constant type is
617usually documented as being only for enumeration constants, but GDB has
618never imposed that restriction; I don't know about other debuggers.
619
620@item i @var{value}
621Integer constant. @var{value} is the numeric value. The type is some
622sort of generic integer type (for GDB, a host @code{int}); to specify
623the type explicitly, use @samp{e} instead.
624
625@item r @var{value}
6897f9ec
JK
626Real constant. @var{value} is the real value, which can be @samp{INF}
627(optionally preceded by a sign) for infinity, @samp{QNAN} for a quiet
628NaN (not-a-number), or @samp{SNAN} for a signalling NaN. If it is a
629normal number the format is that accepted by the C library function
630@code{atof}.
631
b273dc0f 632@item s @var{string}
6897f9ec
JK
633String constant. @var{string} is a string enclosed in either @samp{'}
634(in which case @samp{'} characters within the string are represented as
635@samp{\'} or @samp{"} (in which case @samp{"} characters within the
636string are represented as @samp{\"}).
637
b273dc0f 638@item S @var{type-information} , @var{elements} , @var{bits} , @var{pattern}
6897f9ec 639Set constant. @var{type-information} is the type of the constant, as it
8c59ee11 640would appear after a symbol descriptor (@pxref{Stabs Format}).
a03f27c3
JK
641@var{elements} is the number of elements in the set (Does this means
642how many bits of @var{pattern} are actually used, which would be
643redundant with the type, or perhaps the number of bits set in
644@var{pattern}? I don't get it), @var{bits} is the number of bits in the
645constant (meaning it specifies the length of @var{pattern}, I think),
646and @var{pattern} is a hexadecimal representation of the set. AIX
647documentation refers to a limit of 32 bytes, but I see no reason why
648this limit should exist. This form could probably be used for arbitrary
649constants, not just sets; the only catch is that @var{pattern} should be
650understood to be target, not host, byte order and format.
6897f9ec
JK
651@end table
652
653The boolean, character, string, and set constants are not supported by
654GDB 4.9, but it will ignore them. GDB 4.8 and earlier gave an error
655message and refused to read symbols from the file containing the
656constants.
657
658This information is followed by @samp{;}.
659
899bafeb 660@node Example
e505224d
PB
661@chapter A Comprehensive Example in C
662
139741da 663Now we'll examine a second program, @code{example2}, which builds on the
e505224d
PB
664first example to introduce the rest of the stab types, symbol
665descriptors, and type descriptors used in C.
139741da
RP
666@xref{Example2.c} for the complete @file{.c} source,
667and @pxref{Example2.s} for the @file{.s} assembly code.
e505224d
PB
668This description includes parts of those files.
669
670@section Flow of control and nested scopes
671
9cd64d11 672@table @strong
139741da
RP
673@item Directive:
674@code{.stabn}
675@item Types:
676@code{N_SLINE}, @code{N_LBRAC}, @code{N_RBRAC} (cont.)
677@end table
e505224d 678
899bafeb
RP
679Consider the body of @code{main}, from @file{example2.c}. It shows more
680about how @code{N_SLINE}, @code{N_RBRAC}, and @code{N_LBRAC} stabs are used.
e505224d
PB
681
682@example
68320 @{
68421 static float s_flap;
139741da
RP
68522 int times;
68623 for (times=0; times < s_g_repeat; times++)@{
68724 int inner;
68825 printf ("Hello world\n");
68926 @}
e505224d
PB
69027 @};
691@end example
692
899bafeb 693Here we have a single source line, the @samp{for} line, that generates
e505224d 694non-linear flow of control, and non-contiguous code. In this case, an
899bafeb 695@code{N_SLINE} stab with the same line number proceeds each block of
e505224d
PB
696non-contiguous code generated from the same source line.
697
139741da
RP
698The example also shows nested scopes. The @code{N_LBRAC} and
699@code{N_LBRAC} stabs that describe block structure are nested in the
700same order as the corresponding code blocks, those of the for loop
701inside those for the body of main.
e505224d 702
139741da
RP
703@noindent
704This is the label for the @code{N_LBRAC} (left brace) stab marking the
705start of @code{main}.
e505224d 706
139741da 707@example
e505224d 70857 LBB2:
139741da
RP
709@end example
710
711@noindent
712In the first code range for C source line 23, the @code{for} loop
713initialize and test, @code{N_SLINE} (68) records the line number:
e505224d 714
139741da
RP
715@example
716.stabn N_SLINE, NIL,
717 @var{line},
718 @var{address}
e505224d 719
e505224d
PB
72058 .stabn 68,0,23,LM2
72159 LM2:
139741da 72260 st %g0,[%fp-20]
e505224d 72361 L2:
139741da
RP
72462 sethi %hi(_s_g_repeat),%o0
72563 ld [%fp-20],%o1
72664 ld [%o0+%lo(_s_g_repeat)],%o0
72765 cmp %o1,%o0
72866 bge L3
72967 nop
e505224d 730
139741da 731@exdent label for the @code{N_LBRAC} (start block) marking the start of @code{for} loop
e505224d 732
e505224d
PB
73368 LBB3:
73469 .stabn 68,0,25,LM3
73570 LM3:
139741da
RP
73671 sethi %hi(LC0),%o1
73772 or %o1,%lo(LC0),%o0
73873 call _printf,0
73974 nop
e505224d
PB
74075 .stabn 68,0,26,LM4
74176 LM4:
e505224d 742
139741da 743@exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
e505224d 744
e505224d 74577 LBE3:
139741da 746@end example
e505224d 747
139741da
RP
748@noindent
749Now we come to the second code range for source line 23, the @code{for}
750loop increment and return. Once again, @code{N_SLINE} (68) records the
751source line number:
612dbd4c 752
139741da
RP
753@example
754.stabn, N_SLINE, NIL,
755 @var{line},
756 @var{address}
e505224d 757
e505224d
PB
75878 .stabn 68,0,23,LM5
75979 LM5:
76080 L4:
139741da
RP
76181 ld [%fp-20],%o0
76282 add %o0,1,%o1
76383 st %o1,[%fp-20]
76484 b,a L2
e505224d
PB
76585 L3:
76686 .stabn 68,0,27,LM6
76787 LM6:
e505224d 768
139741da 769@exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
e505224d 770
e505224d
PB
77188 LBE2:
77289 .stabn 68,0,27,LM7
77390 LM7:
77491 L1:
139741da
RP
77592 ret
77693 restore
e505224d
PB
77794 .stabs "main:F1",36,0,0,_main
77895 .stabs "argc:p1",160,0,0,68
77996 .stabs "argv:p20=*21=*2",160,0,0,72
78097 .stabs "s_flap:V12",40,0,0,_s_flap.0
78198 .stabs "times:1",128,0,0,-20
139741da
RP
782@end example
783
784@noindent
785Here is an illustration of stabs describing nested scopes. The scope
786nesting is reflected in the nested bracketing stabs (@code{N_LBRAC},
787192, appears here).
e505224d 788
139741da
RP
789@example
790.stabn N_LBRAC,NIL,NIL,
791 @var{block-start-address}
e505224d
PB
792
79399 .stabn 192,0,0,LBB2 ## begin proc label
794100 .stabs "inner:1",128,0,0,-24
795101 .stabn 192,0,0,LBB3 ## begin for label
139741da 796@end example
e505224d 797
139741da
RP
798@noindent
799@code{N_RBRAC} (224), ``right brace'' ends a lexical block (scope).
800
801@example
802.stabn N_RBRAC,NIL,NIL,
803 @var{block-end-address}
e505224d
PB
804
805102 .stabn 224,0,0,LBE3 ## end for label
806103 .stabn 224,0,0,LBE2 ## end proc label
807@end example
808
899bafeb 809@node Variables
e505224d
PB
810@chapter Variables
811
812@menu
8eb5e289 813* Automatic variables:: Variables allocated on the stack.
807e8368 814* Global Variables:: Variables used by more than one source file.
807e8368 815* Register variables:: Variables in registers.
8eb5e289 816* Common Blocks:: Variables statically allocated together.
24dcc707
JK
817* Statics:: Variables local to one source file.
818* Parameters:: Variables for arguments to functions.
e505224d
PB
819@end menu
820
899bafeb 821@node Automatic variables
e505224d
PB
822@section Locally scoped automatic variables
823
139741da
RP
824@table @strong
825@item Directive:
826@code{.stabs}
827@item Type:
828@code{N_LSYM}
829@item Symbol Descriptor:
830none
831@end table
e505224d 832
139741da
RP
833In addition to describing types, the @code{N_LSYM} stab type also
834describes locally scoped automatic variables. Refer again to the body
835of @code{main} in @file{example2.c}. It allocates two automatic
836variables: @samp{times} is scoped to the body of @code{main}, and
837@samp{inner} is scoped to the body of the @code{for} loop.
838@samp{s_flap} is locally scoped but not automatic, and will be discussed
839later.
e505224d
PB
840
841@example
84220 @{
84321 static float s_flap;
139741da
RP
84422 int times;
84523 for (times=0; times < s_g_repeat; times++)@{
84624 int inner;
84725 printf ("Hello world\n");
84826 @}
e505224d
PB
84927 @};
850@end example
851
139741da
RP
852The @code{N_LSYM} stab for an automatic variable is located just before the
853@code{N_LBRAC} stab describing the open brace of the block to which it is
e505224d
PB
854scoped.
855
856@example
139741da
RP
857@exdent @code{N_LSYM} (128): automatic variable, scoped locally to @code{main}
858
859.stabs "@var{name}:
8c59ee11 860 @var{type information}",
139741da
RP
861 N_LSYM, NIL, NIL,
862 @var{frame-pointer-offset}
e505224d
PB
863
86498 .stabs "times:1",128,0,0,-20
86599 .stabn 192,0,0,LBB2 ## begin `main' N_LBRAC
866
139741da
RP
867@exdent @code{N_LSYM} (128): automatic variable, scoped locally to the @code{for} loop
868
869.stabs "@var{name}:
8c59ee11 870 @var{type information}",
139741da
RP
871 N_LSYM, NIL, NIL,
872 @var{frame-pointer-offset}
e505224d
PB
873
874100 .stabs "inner:1",128,0,0,-24
875101 .stabn 192,0,0,LBB3 ## begin `for' loop N_LBRAC
876@end example
877
8c59ee11
JK
878The symbol descriptor is omitted for automatic variables. Since type
879information should being with a digit, @samp{-}, or @samp{(}, only
880digits, @samp{-}, and @samp{(} are precluded from being used for symbol
881descriptors by this fact. However, the Acorn RISC machine (ARM) is said
882to get this wrong: it puts out a mere type definition here, without the
883preceding @code{@var{typenumber}=}. This is a bad idea; there is no
884guarantee that type descriptors are distinct from symbol descriptors.
e505224d 885
899bafeb 886@node Global Variables
e505224d
PB
887@section Global Variables
888
139741da
RP
889@table @strong
890@item Directive:
891@code{.stabs}
892@item Type:
893@code{N_GSYM}
894@item Symbol Descriptor:
895@code{G}
896@end table
e505224d 897
139741da
RP
898Global variables are represented by the @code{N_GSYM} stab type. The symbol
899descriptor, following the colon in the string field, is @samp{G}. Following
900the @samp{G} is a type reference or type definition. In this example it is a
901type reference to the basic C type, @code{char}. The first source line in
902@file{example2.c},
e505224d
PB
903
904@example
9051 char g_foo = 'c';
906@end example
907
139741da
RP
908@noindent
909yields the following stab. The stab immediately precedes the code that
e505224d
PB
910allocates storage for the variable it describes.
911
912@example
139741da
RP
913@exdent @code{N_GSYM} (32): global symbol
914
915.stabs "@var{name}:
916 @var{descriptor}
917 @var{type-ref}",
918 N_GSYM, NIL, NIL, NIL
e505224d 919
e505224d 92021 .stabs "g_foo:G2",32,0,0,0
139741da
RP
92122 .global _g_foo
92223 .data
e505224d 92324 _g_foo:
139741da 92425 .byte 99
e505224d
PB
925@end example
926
139741da
RP
927The address of the variable represented by the @code{N_GSYM} is not contained
928in the @code{N_GSYM} stab. The debugger gets this information from the
e505224d
PB
929external symbol for the global variable.
930
899bafeb 931@node Register variables
6897f9ec 932@section Register variables
139741da 933
8c59ee11
JK
934@c According to an old version of this manual, AIX uses C_RPSYM instead
935@c of C_RSYM. I am skeptical; this should be verified.
6897f9ec
JK
936Register variables have their own stab type, @code{N_RSYM}, and their
937own symbol descriptor, @code{r}. The stab's value field contains the
938number of the register where the variable data will be stored.
e505224d 939
6897f9ec 940The value is the register number.
e505224d 941
6897f9ec 942AIX defines a separate symbol descriptor @samp{d} for floating point
807e8368
JK
943registers. This seems unnecessary---why not just just give floating
944point registers different register numbers? I have not verified whether
945the compiler actually uses @samp{d}.
e505224d 946
6897f9ec
JK
947If the register is explicitly allocated to a global variable, but not
948initialized, as in
e505224d
PB
949
950@example
6897f9ec 951register int g_bar asm ("%g5");
e505224d
PB
952@end example
953
6897f9ec
JK
954the stab may be emitted at the end of the object file, with
955the other bss symbols.
e505224d 956
807e8368
JK
957@node Common Blocks
958@section Common Blocks
959
960A common block is a statically allocated section of memory which can be
961referred to by several source files. It may contain several variables.
962I believe @sc{fortran} is the only language with this feature. A
963@code{N_BCOMM} stab begins a common block and an @code{N_ECOMM} stab
964ends it. The only thing which is significant about these two stabs is
965their name, which can be used to look up a normal (non-debugging) symbol
e0020f27
JK
966which gives the address of the common block. Then each stab between the
967@code{N_BCOMM} and the @code{N_ECOMM} specifies a member of that common
968block; its value is the offset within the common block of that variable.
969The @code{N_ECOML} stab type is documented for this purpose, but Sun's
11d19345
JK
970@sc{fortran} compiler uses @code{N_GSYM} instead. The test case I
971looked at had a common block local to a function and it used the
972@samp{V} symbol descriptor; I assume one would use @samp{S} if not local
973to a function (that is, if a common block @emph{can} be anything other
974than local to a function).
807e8368 975
24dcc707
JK
976@node Statics
977@section Static Variables
e505224d 978
24dcc707
JK
979Initialized static variables are represented by the @samp{S} and
980@samp{V} symbol descriptors. @samp{S} means file scope static, and
981@samp{V} means procedure scope static.
e505224d 982
24dcc707
JK
983In a.out files, @code{N_STSYM} means the data segment (although gcc
9842.4.5 has a bug in that it uses @code{N_FUN}, so neither dbx nor gdb can
985find the variables), @code{N_FUN} means the text segment, and
986@code{N_LCSYM} means the bss segment.
e505224d 987
38e1c8de 988In xcoff files, each symbol has a section number, so the stab type
24dcc707 989need not indicate the segment.
e505224d 990
38e1c8de
JK
991In ecoff files, the storage class is used to specify the section, so the
992stab type need not indicate the segment.
993
24dcc707
JK
994@c In ELF files, it apparently is a big mess. See kludge in dbxread.c
995@c in GDB. FIXME: Investigate where this kludge comes from.
996@c
997@c This is the place to mention N_ROSYM; I'd rather do so once I can
998@c coherently explain how this stuff works for stabs-in-elf.
999@c
1000For example, the source lines
e505224d
PB
1001
1002@example
24dcc707
JK
1003static const int var_const = 5;
1004static int var_init = 2;
1005static int var_noinit;
e505224d
PB
1006@end example
1007
24dcc707
JK
1008@noindent
1009yield the following stabs:
e505224d
PB
1010
1011@example
24dcc707
JK
1012.stabs "var_const:S1",36,0,0,_var_const ; @r{36 = N_FUN}
1013. . .
1014.stabs "var_init:S1",38,0,0,_var_init ; @r{38 = N_STSYM}
1015. . .
1016.stabs "var_noinit:S1",40,0,0,_var_noinit ; @r{40 = N_LCSYM}
e505224d
PB
1017@end example
1018
899bafeb 1019@node Parameters
907a9cab
JK
1020@section Parameters
1021
1022Parameters to a function are represented by a stab (or sometimes two,
1023see below) for each parameter. The stabs are in the order in which the
1024debugger should print the parameters (i.e. the order in which the
1025parameters are declared in the source file).
e505224d 1026
497e44a5 1027The symbol descriptor @samp{p} is used to refer to parameters which are
b82ea042
JK
1028in the arglist. Symbols have symbol type @samp{N_PSYM}. The value of
1029the symbol is the offset relative to the argument list.
1030
1031If the parameter is passed in a register, then the traditional way to do
497e44a5 1032this is to provide two symbols for each argument:
e505224d
PB
1033
1034@example
b82ea042
JK
1035.stabs "arg:p1" . . . ; N_PSYM
1036.stabs "arg:r1" . . . ; N_RSYM
e505224d
PB
1037@end example
1038
497e44a5
JK
1039Debuggers are expected to use the second one to find the value, and the
1040first one to know that it is an argument.
e505224d 1041
b82ea042
JK
1042Because this is kind of ugly, some compilers use symbol descriptor
1043@samp{P} or @samp{R} to indicate an argument which is in a register.
1044The symbol value is the register number. @samp{P} and @samp{R} mean the
1045same thing, the difference is that @samp{P} is a GNU invention and
1046@samp{R} is an IBM (xcoff) invention. As of version 4.9, GDB should
1047handle either one. Symbol type @samp{C_RPSYM} is used with @samp{R} and
1048@samp{N_RSYM} is used with @samp{P}.
1049
acf7d010
JK
1050According to the AIX documentation symbol descriptor @samp{D} is for a
1051parameter passed in a floating point register. This seems
1052unnecessary---why not just use @samp{R} with a register number which
23aed449 1053indicates that it's a floating point register? I haven't verified
6897f9ec
JK
1054whether the system actually does what the documentation indicates.
1055
a2a2eac8
JK
1056There is at least one case where GCC uses a @samp{p}/@samp{r} pair
1057rather than @samp{P}; this is where the argument is passed in the
1058argument list and then loaded into a register.
1059
c156f3c1
JK
1060On the sparc and hppa, for a @samp{P} symbol whose type is a structure
1061or union, the register contains the address of the structure. On the
1062sparc, this is also true of a @samp{p}/@samp{r} pair (using Sun cc) or a
1063@samp{p} symbol. However, if a (small) structure is really in a
1064register, @samp{r} is used. And, to top it all off, on the hppa it
1065might be a structure which was passed on the stack and loaded into a
1066register and for which there is a @samp{p}/@samp{r} pair! I believe
6897f9ec
JK
1067that symbol descriptor @samp{i} is supposed to deal with this case, (it
1068is said to mean "value parameter by reference, indirect access", I don't
1069know the source for this information) but I don't know details or what
1070compilers or debuggers use it, if any (not GDB or GCC). It is not clear
1071to me whether this case needs to be dealt with differently than
1072parameters passed by reference (see below).
c156f3c1 1073
b82ea042 1074There is another case similar to an argument in a register, which is an
98ef6f31
JK
1075argument which is actually stored as a local variable. Sometimes this
1076happens when the argument was passed in a register and then the compiler
1077stores it as a local variable. If possible, the compiler should claim
1078that it's in a register, but this isn't always done. Some compilers use
1079the pair of symbols approach described above ("arg:p" followed by
1080"arg:"); this includes gcc1 (not gcc2) on the sparc when passing a small
23aed449
JK
1081structure and gcc2 (sometimes) when the argument type is float and it is
1082passed as a double and converted to float by the prologue (in the latter
1083case the type of the "arg:p" symbol is double and the type of the "arg:"
1084symbol is float). GCC, at least on the 960, uses a single @samp{p}
1085symbol descriptor for an argument which is stored as a local variable
1086but uses @samp{N_LSYM} instead of @samp{N_PSYM}. In this case the value
1087of the symbol is an offset relative to the local variables for that
1088function, not relative to the arguments (on some machines those are the
1089same thing, but not on all).
e505224d 1090
6897f9ec
JK
1091If the parameter is passed by reference (e.g. Pascal VAR parameters),
1092then type symbol descriptor is @samp{v} if it is in the argument list,
1093or @samp{a} if it in a register. Other than the fact that these contain
1094the address of the parameter other than the parameter itself, they are
1095identical to @samp{p} and @samp{R}, respectively. I believe @samp{a} is
1096an AIX invention; @samp{v} is supported by all stabs-using systems as
1097far as I know.
1098
1099@c Is this paragraph correct? It is based on piecing together patchy
1100@c information and some guesswork
1101Conformant arrays refer to a feature of Modula-2, and perhaps other
1102languages, in which the size of an array parameter is not known to the
1103called function until run-time. Such parameters have two stabs, a
1104@samp{x} for the array itself, and a @samp{C}, which represents the size
1105of the array. The value of the @samp{x} stab is the offset in the
1106argument list where the address of the array is stored (it this right?
1107it is a guess); the value of the @samp{C} stab is the offset in the
1108argument list where the size of the array (in elements? in bytes?) is
1109stored.
1110
1111The following are also said to go with @samp{N_PSYM}:
a2a2eac8
JK
1112
1113@example
1114"name" -> "param_name:#type"
a2a2eac8 1115 -> pP (<<??>>)
8c59ee11 1116 -> pF FORTRAN function parameter
a2a2eac8
JK
1117 -> X (function result variable)
1118 -> b (based variable)
1119
1120value -> offset from the argument pointer (positive).
1121@end example
1122
497e44a5 1123As a simple example, the code
899bafeb 1124
497e44a5 1125@example
b82ea042
JK
1126main (argc, argv)
1127 int argc;
1128 char **argv;
1129@{
497e44a5
JK
1130@end example
1131
1132produces the stabs
899bafeb 1133
497e44a5 1134@example
b82ea042
JK
1135.stabs "main:F1",36,0,0,_main ; 36 is N_FUN
1136.stabs "argc:p1",160,0,0,68 ; 160 is N_PSYM
1137.stabs "argv:p20=*21=*2",160,0,0,72
e505224d
PB
1138@end example
1139
497e44a5 1140The type definition of argv is interesting because it contains several
a2a2eac8
JK
1141type definitions. Type 21 is pointer to type 2 (char) and argv (type 20) is
1142pointer to type 21.
e505224d 1143
8c59ee11 1144@node Types
3d4cf720 1145@chapter Type Definitions
e505224d 1146
612dbd4c 1147Now let's look at some variable definitions involving complex types.
e505224d
PB
1148This involves understanding better how types are described. In the
1149examples so far types have been described as references to previously
1150defined types or defined in terms of subranges of or pointers to
1151previously defined types. The section that follows will talk about
1152the various other type descriptors that may follow the = sign in a
1153type definition.
1154
1155@menu
8c59ee11
JK
1156* Builtin types:: Integers, floating point, void, etc.
1157* Miscellaneous Types:: Pointers, sets, files, etc.
1158* Cross-references:: Referring to a type not yet defined.
1159* Subranges:: A type with a specific range.
1160* Arrays:: An aggregate type of same-typed elements.
1161* Strings:: Like an array but also has a length.
1162* Enumerations:: Like an integer but the values have names.
1163* Structures:: An aggregate type of different-typed elements.
ded6bcab
JK
1164* Typedefs:: Giving a type a name.
1165* Unions:: Different types sharing storage.
8eb5e289 1166* Function Types::
e505224d
PB
1167@end menu
1168
8c59ee11
JK
1169@node Builtin types
1170@section Builtin types
e505224d 1171
8c59ee11
JK
1172Certain types are built in (@code{int}, @code{short}, @code{void},
1173@code{float}, etc.); the debugger recognizes these types and knows how
1174to handle them. Thus don't be surprised if some of the following ways
1175of specifying builtin types do not specify everything that a debugger
1176would need to know about the type---in some cases they merely specify
1177enough information to distinguish the type from other types.
1178
1179The traditional way to define builtin types is convolunted, so new ways
1180have been invented to describe them. Sun's ACC uses the @samp{b} and
1181@samp{R} type descriptors, and IBM uses negative type numbers. GDB can
1182accept all three, as of version 4.8; dbx just accepts the traditional
1183builtin types and perhaps one of the other two formats.
1184
1185@menu
1186* Traditional Builtin Types:: Put on your seatbelts and prepare for kludgery
1187* Builtin Type Descriptors:: Builtin types with special type descriptors
1188* Negative Type Numbers:: Builtin types using negative type numbers
1189@end menu
1190
1191@node Traditional Builtin Types
1192@subsection Traditional Builtin types
1193
1194Often types are defined as subranges of themselves. If the array bounds
1195can fit within an @code{int}, then they are given normally. For example:
1196
1197@example
1198.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0 ; 128 is N_LSYM
1199.stabs "char:t2=r2;0;127;",128,0,0,0
1200@end example
1201
1202Builtin types can also be described as subranges of @code{int}:
1203
1204@example
1205.stabs "unsigned short:t6=r1;0;65535;",128,0,0,0
1206@end example
1207
b273dc0f
JK
1208If the lower bound of a subrange is 0 and the upper bound is -1, it
1209means that the type is an unsigned integral type whose bounds are too
1210big to describe in an int. Traditionally this is only used for
1211@code{unsigned int} and @code{unsigned long}; GCC also sometimes uses it
1212for @code{long long} and @code{unsigned long long}, and the only way to
1213tell those types apart is to look at their names. On other machines GCC
1214puts out bounds in octal, with a leading 0. In this case a negative
1215bound consists of a number which is a 1 bit followed by a bunch of 0
1216bits, and a positive bound is one in which a bunch of bits are 1.
8c59ee11
JK
1217
1218@example
1219.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
1220.stabs "long long int:t7=r1;0;-1;",128,0,0,0
1221@end example
1222
b273dc0f
JK
1223If the lower bound of a subrange is 0 and the upper bound is negative,
1224it means that it is an unsigned integral type whose size in bytes is the
1225absolute value of the upper bound. I believe this is a Convex
1226convention for @code{unsigned long long}.
1227
1228If the lower bound of a subrange is negative and the upper bound is 0,
1229it means that the type is a signed integral type whose size in bytes is
1230the absolute value of the lower bound. I believe this is a Convex
1231convention for @code{long long}. To distinguish this from a legitimate
1232subrange, the type should be a subrange of itself. I'm not sure whether
1233this is the case for Convex.
1234
8c59ee11
JK
1235If the upper bound of a subrange is 0, it means that this is a floating
1236point type, and the lower bound of the subrange indicates the number of
1237bytes in the type:
1238
1239@example
1240.stabs "float:t12=r1;4;0;",128,0,0,0
1241.stabs "double:t13=r1;8;0;",128,0,0,0
1242@end example
1243
1244However, GCC writes @code{long double} the same way it writes
1245@code{double}; the only way to distinguish them is by the name:
1246
1247@example
1248.stabs "long double:t14=r1;8;0;",128,0,0,0
1249@end example
1250
1251Complex types are defined the same way as floating-point types; the only
1252way to distinguish a single-precision complex from a double-precision
1253floating-point type is by the name.
1254
1255The C @code{void} type is defined as itself:
1256
1257@example
1258.stabs "void:t15=15",128,0,0,0
1259@end example
1260
1261I'm not sure how a boolean type is represented.
1262
1263@node Builtin Type Descriptors
1264@subsection Defining Builtin Types using Builtin Type Descriptors
1265
1266There are various type descriptors to define builtin types:
1267
1268@table @code
1a8b5668
JK
1269@c FIXME: clean up description of width and offset, once we figure out
1270@c what they mean
8c59ee11
JK
1271@item b @var{signed} @var{char-flag} @var{width} ; @var{offset} ; @var{nbits} ;
1272Define an integral type. @var{signed} is @samp{u} for unsigned or
1273@samp{s} for signed. @var{char-flag} is @samp{c} which indicates this
1274is a character type, or is omitted. I assume this is to distinguish an
1275integral type from a character type of the same size, for example it
1276might make sense to set it for the C type @code{wchar_t} so the debugger
1277can print such variables differently (Solaris does not do this). Sun
1278sets it on the C types @code{signed char} and @code{unsigned char} which
1279arguably is wrong. @var{width} and @var{offset} appear to be for small
1280objects stored in larger ones, for example a @code{short} in an
1281@code{int} register. @var{width} is normally the number of bytes in the
1282type. @var{offset} seems to always be zero. @var{nbits} is the number
1283of bits in the type.
1284
1285Note that type descriptor @samp{b} used for builtin types conflicts with
1286its use for Pascal space types (@pxref{Miscellaneous Types}); they can
1287be distinguished because the character following the type descriptor
1288will be a digit, @samp{(}, or @samp{-} for a Pascal space type, or
1289@samp{u} or @samp{s} for a builtin type.
1290
1291@item w
1292Documented by AIX to define a wide character type, but their compiler
1293actually uses negative type numbers (@pxref{Negative Type Numbers}).
1294
1a8b5668
JK
1295@item R @var{fp_type} ; @var{bytes} ;
1296Define a floating point type. @var{fp_type} has one of the following values:
1297
1298@table @code
1299@item 1 (NF_SINGLE)
1300IEEE 32-bit (single precision) floating point format.
1301
1302@item 2 (NF_DOUBLE)
1303IEEE 64-bit (double precision) floating point format.
1304
1305@item 3 (NF_COMPLEX)
1306@item 4 (NF_COMPLEX16)
1307@item 5 (NF_COMPLEX32)
3d4cf720
JK
1308@c "GDB source" really means @file{include/aout/stab_gnu.h}, but trying
1309@c to put that here got an overfull hbox.
1310These are for complex numbers. A comment in the GDB source describes
1311them as Fortran complex, double complex, and complex*16, respectively,
1312but what does that mean? (i.e. Single precision? Double precison?).
1a8b5668
JK
1313
1314@item 6 (NF_LDOUBLE)
ded6bcab
JK
1315Long double. This should probably only be used for Sun format long
1316double, and new codes should be used for other floating point formats
1317(NF_DOUBLE can be used if a long double is really just an IEEE double,
1318of course).
1a8b5668
JK
1319@end table
1320
1321@var{bytes} is the number of bytes occupied by the type. This allows a
1322debugger to perform some operations with the type even if it doesn't
1323understand @var{fp_code}.
8c59ee11
JK
1324
1325@item g @var{type-information} ; @var{nbits}
1326Documented by AIX to define a floating type, but their compiler actually
1327uses negative type numbers (@pxref{Negative Type Numbers}).
1328
1329@item c @var{type-information} ; @var{nbits}
1330Documented by AIX to define a complex type, but their compiler actually
1331uses negative type numbers (@pxref{Negative Type Numbers}).
1332@end table
1333
1334The C @code{void} type is defined as a signed integral type 0 bits long:
1335@example
1336.stabs "void:t19=bs0;0;0",128,0,0,0
1337@end example
e9f687d5
JK
1338The Solaris compiler seems to omit the trailing semicolon in this case.
1339Getting sloppy in this way is not a swift move because if a type is
1340embedded in a more complex expression it is necessary to be able to tell
1341where it ends.
8c59ee11
JK
1342
1343I'm not sure how a boolean type is represented.
1344
1345@node Negative Type Numbers
1346@subsection Negative Type numbers
1347
1348Since the debugger knows about the builtin types anyway, the idea of
1349negative type numbers is simply to give a special type number which
1350indicates the built in type. There is no stab defining these types.
1351
1352I'm not sure whether anyone has tried to define what this means if
1353@code{int} can be other than 32 bits (or other types can be other than
1354their customary size). If @code{int} has exactly one size for each
1355architecture, then it can be handled easily enough, but if the size of
1356@code{int} can vary according the compiler options, then it gets hairy.
0e84d6ec
JK
1357The best way to do this would be to define separate negative type
1358numbers for 16-bit @code{int} and 32-bit @code{int}; therefore I have
1359indicated below the customary size (and other format information) for
1360each type. The information below is currently correct because AIX on
1361the RS6000 is the only system which uses these type numbers. If these
1362type numbers start to get used on other systems, I suspect the correct
1363thing to do is to define a new number in cases where a type does not
1364have the size and format indicated below (or avoid negative type numbers
1365in these cases).
8c59ee11 1366
b273dc0f
JK
1367Also note that part of the definition of the negative type number is
1368the name of the type. Types with identical size and format but
1369different names have different negative type numbers.
1370
8c59ee11
JK
1371@table @code
1372@item -1
1373@code{int}, 32 bit signed integral type.
1374
1375@item -2
1376@code{char}, 8 bit type holding a character. Both GDB and dbx on AIX
1377treat this as signed. GCC uses this type whether @code{char} is signed
1378or not, which seems like a bad idea. The AIX compiler (xlc) seems to
1379avoid this type; it uses -5 instead for @code{char}.
1380
1381@item -3
1382@code{short}, 16 bit signed integral type.
1383
1384@item -4
1385@code{long}, 32 bit signed integral type.
1386
1387@item -5
1388@code{unsigned char}, 8 bit unsigned integral type.
1389
1390@item -6
1391@code{signed char}, 8 bit signed integral type.
1392
1393@item -7
1394@code{unsigned short}, 16 bit unsigned integral type.
1395
1396@item -8
1397@code{unsigned int}, 32 bit unsigned integral type.
1398
1399@item -9
1400@code{unsigned}, 32 bit unsigned integral type.
1401
1402@item -10
1403@code{unsigned long}, 32 bit unsigned integral type.
1404
1405@item -11
1406@code{void}, type indicating the lack of a value.
1407
1408@item -12
1409@code{float}, IEEE single precision.
1410
1411@item -13
1412@code{double}, IEEE double precision.
1413
1414@item -14
b273dc0f
JK
1415@code{long double}, IEEE double precision. The compiler claims the size
1416will increase in a future release, and for binary compatibility you have
1417to avoid using @code{long double}. I hope when they increase it they
1418use a new negative type number.
8c59ee11
JK
1419
1420@item -15
b273dc0f 1421@code{integer}. 32 bit signed integral type.
8c59ee11
JK
1422
1423@item -16
455c8603
JK
1424@code{boolean}. 32 bit type. How is the truth value encoded? Is it
1425the least significant bit or is it a question of whether the whole value
1426is zero or non-zero?
8c59ee11
JK
1427
1428@item -17
b273dc0f 1429@code{short real}. IEEE single precision.
8c59ee11
JK
1430
1431@item -18
b273dc0f 1432@code{real}. IEEE double precision.
8c59ee11
JK
1433
1434@item -19
b273dc0f 1435@code{stringptr}. @xref{Strings}.
8c59ee11
JK
1436
1437@item -20
dcb9e869 1438@code{character}, 8 bit unsigned character type.
8c59ee11
JK
1439
1440@item -21
01c4b039
JK
1441@code{logical*1}, 8 bit type. This @sc{fortran} type has a split
1442personality in that it is used for boolean variables, but can also be
1443used for unsigned integers.
8c59ee11
JK
1444
1445@item -22
01c4b039
JK
1446@code{logical*2}, 16 bit type. This @sc{fortran} type has a split
1447personality in that it is used for boolean variables, but can also be
1448used for unsigned integers.
8c59ee11
JK
1449
1450@item -23
01c4b039
JK
1451@code{logical*4}, 32 bit type. This @sc{fortran} type has a split
1452personality in that it is used for boolean variables, but can also be
1453used for unsigned integers.
8c59ee11
JK
1454
1455@item -24
0e84d6ec
JK
1456@code{logical}, 32 bit type. This @sc{fortran} type has a split
1457personality in that it is used for boolean variables, but can also be
1458used for unsigned integers.
8c59ee11
JK
1459
1460@item -25
b273dc0f
JK
1461@code{complex}. A complex type consisting of two IEEE single-precision
1462floating point values.
8c59ee11
JK
1463
1464@item -26
b273dc0f
JK
1465@code{complex}. A complex type consisting of two IEEE double-precision
1466floating point values.
8c59ee11
JK
1467
1468@item -27
1469@code{integer*1}, 8 bit signed integral type.
1470
1471@item -28
1472@code{integer*2}, 16 bit signed integral type.
1473
1474@item -29
1475@code{integer*4}, 32 bit signed integral type.
1476
1477@item -30
dcb9e869
JK
1478@code{wchar}. Wide character, 16 bits wide, unsigned (what format?
1479Unicode?).
8c59ee11
JK
1480@end table
1481
1482@node Miscellaneous Types
1483@section Miscellaneous Types
1484
1485@table @code
1486@item b @var{type-information} ; @var{bytes}
1487Pascal space type. This is documented by IBM; what does it mean?
1488
1489Note that this use of the @samp{b} type descriptor can be distinguished
1490from its use for builtin integral types (@pxref{Builtin Type
1491Descriptors}) because the character following the type descriptor is
1492always a digit, @samp{(}, or @samp{-}.
1493
1494@item B @var{type-information}
1495A volatile-qualified version of @var{type-information}. This is a Sun
1496extension. A volatile-qualified type means that references and stores
1497to a variable of that type must not be optimized or cached; they must
1498occur as the user specifies them.
1499
1500@item d @var{type-information}
1501File of type @var{type-information}. As far as I know this is only used
1502by Pascal.
1503
1504@item k @var{type-information}
1505A const-qualified version of @var{type-information}. This is a Sun
1506extension. A const-qualified type means that a variable of this type
1507cannot be modified.
1508
1509@item M @var{type-information} ; @var{length}
1510Multiple instance type. The type seems to composed of @var{length}
1511repetitions of @var{type-information}, for example @code{character*3} is
1512represented by @samp{M-2;3}, where @samp{-2} is a reference to a
1513character type (@pxref{Negative Type Numbers}). I'm not sure how this
1514differs from an array. This appears to be a FORTRAN feature.
1515@var{length} is a bound, like those in range types, @xref{Subranges}.
1516
1517@item S @var{type-information}
1518Pascal set type. @var{type-information} must be a small type such as an
1519enumeration or a subrange, and the type is a bitmask whose length is
1520specified by the number of elements in @var{type-information}.
1521
1522@item * @var{type-information}
1523Pointer to @var{type-information}.
139741da 1524@end table
e505224d 1525
8c59ee11
JK
1526@node Cross-references
1527@section Cross-references to other types
1528
1529If a type is used before it is defined, one common way to deal with this
1530is just to use a type reference to a type which has not yet been
1531defined. The debugger is expected to be able to deal with this.
1532
1533Another way is with the @samp{x} type descriptor, which is followed by
1534@samp{s} for a structure tag, @samp{u} for a union tag, or @samp{e} for
1535a enumerator tag, followed by the name of the tag, followed by @samp{:}.
1536for example the following C declarations:
e505224d
PB
1537
1538@example
8c59ee11
JK
1539struct foo;
1540struct foo *bar;
e505224d
PB
1541@end example
1542
8c59ee11
JK
1543produce
1544
1545@example
1546.stabs "bar:G16=*17=xsfoo:",32,0,0,0
1547@end example
1548
1549Not all debuggers support the @samp{x} type descriptor, so on some
1550machines GCC does not use it. I believe that for the above example it
1551would just emit a reference to type 17 and never define it, but I
1552haven't verified that.
1553
1554Modula-2 imported types, at least on AIX, use the @samp{i} type
1555descriptor, which is followed by the name of the module from which the
1556type is imported, followed by @samp{:}, followed by the name of the
1557type. There is then optionally a comma followed by type information for
1558the type (This differs from merely naming the type (@pxref{Typedefs}) in
1559that it identifies the module; I don't understand whether the name of
1560the type given here is always just the same as the name we are giving
1561it, or whether this type descriptor is used with a nameless stab
1562(@pxref{Stabs Format}), or what). The symbol ends with @samp{;}.
e505224d 1563
8c59ee11
JK
1564@node Subranges
1565@section Subrange types
1566
1567The @samp{r} type descriptor defines a type as a subrange of another
1568type. It is followed by type information for the type which it is a
1569subrange of, a semicolon, an integral lower bound, a semicolon, an
1570integral upper bound, and a semicolon. The AIX documentation does not
63cef7d7
JK
1571specify the trailing semicolon, in an effort to specify array indexes
1572more cleanly, but a subrange which is not an array index has always
466bdeb2 1573included a trailing semicolon (@pxref{Arrays}).
8c59ee11 1574
8cfe3beb 1575Instead of an integer, either bound can be one of the following:
8c59ee11
JK
1576
1577@table @code
1578@item A @var{offset}
1579The bound is passed by reference on the stack at offset @var{offset}
1580from the argument list. @xref{Parameters}, for more information on such
1581offsets.
1582
1583@item T @var{offset}
1584The bound is passed by value on the stack at offset @var{offset} from
1585the argument list.
1586
1587@item a @var{register-number}
1588The bound is pased by reference in register number
1589@var{register-number}.
1590
1591@item t @var{register-number}
1592The bound is passed by value in register number @var{register-number}.
1593
1594@item J
1595There is no bound.
1596@end table
1597
1598Subranges are also used for builtin types, @xref{Traditional Builtin Types}.
1599
1600@node Arrays
1601@section Array types
1602
1603Arrays use the @samp{a} type descriptor. Following the type descriptor
63cef7d7
JK
1604is the type of the index and the type of the array elements. If the
1605index type is a range type, it will end in a semicolon; if it is not a
1606range type (for example, if it is a type reference), there does not
1607appear to be any way to tell where the types are separated. In an
1608effort to clean up this mess, IBM documents the two types as being
1609separated by a semicolon, and a range type as not ending in a semicolon
1610(but this is not right for range types which are not array indexes,
1611@pxref{Subranges}). I think probably the best solution is to specify
1612that a semicolon ends a range type, and that the index type and element
1613type of an array are separated by a semicolon, but that if the index
1614type is a range type, the extra semicolon can be omitted. GDB (at least
1615through version 4.9) doesn't support any kind of index type other than a
1616range anyway; I'm not sure about dbx.
6aa83a79 1617
ee59134e 1618It is well established, and widely used, that the type of the index,
3d4cf720
JK
1619unlike most types found in the stabs, is merely a type definition, not
1620type information (@pxref{Stabs Format}) (that is, it need not start with
1621@var{type-number}@code{=} if it is defining a new type). According to a
1622comment in GDB, this is also true of the type of the array elements; it
1623gives @samp{ar1;1;10;ar1;1;10;4} as a legitimate way to express a two
1624dimensional array. According to AIX documentation, the element type
1625must be type information. GDB accepts either.
ee59134e 1626
6aa83a79 1627The type of the index is often a range type, expressed as the letter r
8c59ee11
JK
1628and some parameters. It defines the size of the array. In the example
1629below, the range @code{r1;0;2;} defines an index type which is a
1630subrange of type 1 (integer), with a lower bound of 0 and an upper bound
1631of 2. This defines the valid range of subscripts of a three-element C
1632array.
e505224d 1633
8c59ee11 1634For example, the definition
e505224d
PB
1635
1636@example
8c59ee11
JK
1637char char_vec[3] = @{'a','b','c'@};
1638@end example
e505224d 1639
8c59ee11
JK
1640@noindent
1641produces the output
1642
1643@example
1644.stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
1645 .global _char_vec
1646 .align 4
1647_char_vec:
1648 .byte 97
1649 .byte 98
1650 .byte 99
1651@end example
1652
1653If an array is @dfn{packed}, it means that the elements are spaced more
1654closely than normal, saving memory at the expense of speed. For
1655example, an array of 3-byte objects might, if unpacked, have each
1656element aligned on a 4-byte boundary, but if packed, have no padding.
1657One way to specify that something is packed is with type attributes
1658(@pxref{Stabs Format}), in the case of arrays another is to use the
1659@samp{P} type descriptor instead of @samp{a}. Other than specifying a
1660packed array, @samp{P} is identical to @samp{a}.
1661
1662@c FIXME-what is it? A pointer?
1663An open array is represented by the @samp{A} type descriptor followed by
1664type information specifying the type of the array elements.
1665
1666@c FIXME: what is the format of this type? A pointer to a vector of pointers?
1667An N-dimensional dynamic array is represented by
1668
1669@example
1670D @var{dimensions} ; @var{type-information}
1671@end example
1672
1673@c Does dimensions really have this meaning? The AIX documentation
1674@c doesn't say.
1675@var{dimensions} is the number of dimensions; @var{type-information}
1676specifies the type of the array elements.
1677
1678@c FIXME: what is the format of this type? A pointer to some offsets in
1679@c another array?
1680A subarray of an N-dimensional array is represented by
1681
1682@example
1683E @var{dimensions} ; @var{type-information}
e505224d
PB
1684@end example
1685
8c59ee11
JK
1686@c Does dimensions really have this meaning? The AIX documentation
1687@c doesn't say.
1688@var{dimensions} is the number of dimensions; @var{type-information}
1689specifies the type of the array elements.
1690
1691@node Strings
1692@section Strings
1693
1694Some languages, like C or the original Pascal, do not have string types,
1695they just have related things like arrays of characters. But most
1696Pascals and various other languages have string types, which are
1697indicated as follows:
1698
1699@table @code
1700@item n @var{type-information} ; @var{bytes}
1701@var{bytes} is the maximum length. I'm not sure what
1702@var{type-information} is; I suspect that it means that this is a string
1703of @var{type-information} (thus allowing a string of integers, a string
1704of wide characters, etc., as well as a string of characters). Not sure
1705what the format of this type is. This is an AIX feature.
1706
1707@item z @var{type-information} ; @var{bytes}
1708Just like @samp{n} except that this is a gstring, not an ordinary
1709string. I don't know the difference.
1710
1711@item N
1712Pascal Stringptr. What is this? This is an AIX feature.
1713@end table
1714
899bafeb 1715@node Enumerations
e505224d
PB
1716@section Enumerations
1717
8c59ee11 1718Enumerations are defined with the @samp{e} type descriptor.
e505224d 1719
8c59ee11
JK
1720@c FIXME: Where does this information properly go? Perhaps it is
1721@c redundant with something we already explain.
e505224d
PB
1722The source line below declares an enumeration type. It is defined at
1723file scope between the bodies of main and s_proc in example2.c.
8c59ee11 1724The type definition is located after the N_RBRAC that marks the end of
e505224d 1725the previous procedure's block scope, and before the N_FUN that marks
8c59ee11
JK
1726the beginning of the next procedure's block scope. Therefore it does not
1727describe a block local symbol, but a file local one.
1728
1729The source line:
e505224d
PB
1730
1731@example
8c59ee11 1732enum e_places @{first,second=3,last@};
e505224d
PB
1733@end example
1734
899bafeb 1735@noindent
8c59ee11 1736generates the following stab
e505224d 1737
899bafeb 1738@example
8c59ee11 1739.stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
899bafeb 1740@end example
e505224d
PB
1741
1742The symbol descriptor (T) says that the stab describes a structure,
1743enumeration, or type tag. The type descriptor e, following the 22= of
1744the type definition narrows it down to an enumeration type. Following
1745the e is a list of the elements of the enumeration. The format is
1746name:value,. The list of elements ends with a ;.
1747
8c59ee11
JK
1748There is no standard way to specify the size of an enumeration type; it
1749is determined by the architecture (normally all enumerations types are
175032 bits). There should be a way to specify an enumeration type of
1751another size; type attributes would be one way to do this @xref{Stabs
1752Format}.
1753
1754@node Structures
1755@section Structures
e505224d 1756
139741da
RP
1757@table @strong
1758@item Directive:
1759@code{.stabs}
1760@item Type:
8c59ee11 1761@code{N_LSYM} or @code{C_DECL}
139741da
RP
1762@item Symbol Descriptor:
1763@code{T}
1764@item Type Descriptor:
1765@code{s}
1766@end table
e505224d
PB
1767
1768The following source code declares a structure tag and defines an
4d7f562d 1769instance of the structure in global scope. Then a typedef equates the
e505224d
PB
1770structure tag with a new type. A seperate stab is generated for the
1771structure tag, the structure typedef, and the structure instance. The
1772stabs for the tag and the typedef are emited when the definitions are
1773encountered. Since the structure elements are not initialized, the
1774stab and code for the structure variable itself is located at the end
1775of the program in .common.
1776
1777@example
17786 struct s_tag @{
17797 int s_int;
17808 float s_float;
17819 char s_char_vec[8];
178210 struct s_tag* s_next;
178311 @} g_an_s;
178412
178513 typedef struct s_tag s_typedef;
1786@end example
1787
1788The structure tag is an N_LSYM stab type because, like the enum, the
1789symbol is file scope. Like the enum, the symbol descriptor is T, for
1790enumeration, struct or tag type. The symbol descriptor s following
1791the 16= of the type definition narrows the symbol type to struct.
1792
1793Following the struct symbol descriptor is the number of bytes the
1794struct occupies, followed by a description of each structure element.
1795The structure element descriptions are of the form name:type, bit
1796offset from the start of the struct, and number of bits in the
1797element.
1798
1799
612dbd4c 1800@example
e505224d
PB
1801 <128> N_LSYM - type definition
1802 .stabs "name:sym_desc(struct tag) Type_def(16)=type_desc(struct type)
139741da 1803 struct_bytes
e505224d 1804 elem_name:type_ref(int),bit_offset,field_bits;
139741da 1805 elem_name:type_ref(float),bit_offset,field_bits;
6aa83a79
JG
1806 elem_name:type_def(17)=type_desc(array)
1807 index_type(range of int from 0 to 7);
1808 element_type(char),bit_offset,field_bits;;",
139741da 1809 N_LSYM,NIL,NIL,NIL
e505224d
PB
1810
181130 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
139741da 1812 s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
612dbd4c 1813@end example
e505224d
PB
1814
1815In this example, two of the structure elements are previously defined
1816types. For these, the type following the name: part of the element
1817description is a simple type reference. The other two structure
1818elements are new types. In this case there is a type definition
1819embedded after the name:. The type definition for the array element
1820looks just like a type definition for a standalone array. The s_next
1821field is a pointer to the same kind of structure that the field is an
1822element of. So the definition of structure type 16 contains an type
1823definition for an element which is a pointer to type 16.
1824
899bafeb 1825@node Typedefs
8c59ee11 1826@section Giving a type a name
e505224d 1827
8c59ee11 1828To give a type a name, use the @samp{t} symbol descriptor. For example,
e505224d 1829
899bafeb 1830@example
8c59ee11 1831.stabs "s_typedef:t16",128,0,0,0
899bafeb 1832@end example
e505224d 1833
8c59ee11
JK
1834specifies that @code{s_typedef} refers to type number 16. Such stabs
1835have symbol type @code{N_LSYM} or @code{C_DECL}.
e505224d 1836
466bdeb2 1837If instead, you are specifying the tag name for a structure, union, or
8c59ee11
JK
1838enumeration, use the @samp{T} symbol descriptor instead. I believe C is
1839the only language with this feature.
e505224d 1840
8c59ee11
JK
1841If the type is an opaque type (I believe this is a Modula-2 feature),
1842AIX provides a type descriptor to specify it. The type descriptor is
1843@samp{o} and is followed by a name. I don't know what the name
1844means---is it always the same as the name of the type, or is this type
1845descriptor used with a nameless stab (@pxref{Stabs Format})? There
1846optionally follows a comma followed by type information which defines
1847the type of this type. If omitted, a semicolon is used in place of the
1848comma and the type information, and, the type is much like a generic
1849pointer type---it has a known size but little else about it is
1850specified.
e505224d 1851
899bafeb 1852@node Unions
e505224d
PB
1853@section Unions
1854
612dbd4c 1855Next let's look at unions. In example2 this union type is declared
e505224d
PB
1856locally to a procedure and an instance of the union is defined.
1857
1858@example
185936 union u_tag @{
186037 int u_int;
186138 float u_float;
186239 char* u_char;
186340 @} an_u;
1864@end example
1865
1866This code generates a stab for the union tag and a stab for the union
1867variable. Both use the N_LSYM stab type. Since the union variable is
1868scoped locally to the procedure in which it is defined, its stab is
139741da 1869located immediately preceding the N_LBRAC for the procedure's block
e505224d
PB
1870start.
1871
139741da 1872The stab for the union tag, however is located preceding the code for
e505224d
PB
1873the procedure in which it is defined. The stab type is N_LSYM. This
1874would seem to imply that the union type is file scope, like the struct
1875type s_tag. This is not true. The contents and position of the stab
1876for u_type do not convey any infomation about its procedure local
1877scope.
1878
899bafeb 1879@display
e505224d
PB
1880 <128> N_LSYM - type
1881 .stabs "name:sym_desc(union tag)type_def(22)=type_desc(union)
1882 byte_size(4)
1883 elem_name:type_ref(int),bit_offset(0),bit_size(32);
1884 elem_name:type_ref(float),bit_offset(0),bit_size(32);
1885 elem_name:type_ref(ptr to char),bit_offset(0),bit_size(32);;"
1886 N_LSYM, NIL, NIL, NIL
899bafeb 1887@end display
e505224d 1888
5bc927fb
RP
1889@smallexample
1890105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
1891 128,0,0,0
1892@end smallexample
e505224d
PB
1893
1894The symbol descriptor, T, following the name: means that the stab
4d7f562d 1895describes an enumeration, struct or type tag. The type descriptor u,
e505224d
PB
1896following the 23= of the type definition, narrows it down to a union
1897type definition. Following the u is the number of bytes in the union.
1898After that is a list of union element descriptions. Their format is
1899name:type, bit offset into the union, and number of bytes for the
1900element;.
1901
1902The stab for the union variable follows. Notice that the frame
1903pointer offset for local variables is negative.
1904
899bafeb 1905@display
e505224d
PB
1906 <128> N_LSYM - local variable (with no symbol descriptor)
1907 .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset
899bafeb 1908@end display
e505224d 1909
899bafeb 1910@example
e505224d 1911130 .stabs "an_u:23",128,0,0,-20
899bafeb 1912@end example
e505224d 1913
a03f27c3 1914@node Function Types
e505224d
PB
1915@section Function types
1916
8c59ee11
JK
1917There are various types for function variables. These types are not
1918used in defining functions; see symbol descriptor @samp{f}; they are
1919used for things like pointers to functions.
e505224d 1920
8c59ee11
JK
1921The simple, traditional, type is type descriptor @samp{f} is followed by
1922type information for the return type of the function, followed by a
1923semicolon.
1924
1925This does not deal with functions the number and type of whose
1926parameters are part of their type, as found in Modula-2 or ANSI C. AIX
1927provides extensions to specify these, using the @samp{f}, @samp{F},
1928@samp{p}, and @samp{R} type descriptors.
1929
1930First comes the type descriptor. Then, if it is @samp{f} or @samp{F},
1931this is a function, and the type information for the return type of the
1932function follows, followed by a comma. Then comes the number of
1933parameters to the function and a semicolon. Then, for each parameter,
1934there is the name of the parameter followed by a colon (this is only
1935present for type descriptors @samp{R} and @samp{F} which represent
1936Pascal function or procedure parameters), type information for the
1937parameter, a comma, @samp{0} if passed by reference or @samp{1} if
1938passed by value, and a semicolon. The type definition ends with a
1939semicolon.
1940
1941For example,
e505224d
PB
1942
1943@example
8c59ee11 1944int (*g_pf)();
e505224d
PB
1945@end example
1946
8c59ee11
JK
1947@noindent
1948generates the following code:
e505224d 1949
899bafeb 1950@example
8c59ee11
JK
1951.stabs "g_pf:G24=*25=f1",32,0,0,0
1952 .common _g_pf,4,"bss"
899bafeb 1953@end example
e505224d 1954
8c59ee11
JK
1955The variable defines a new type, 24, which is a pointer to another new
1956type, 25, which is defined as a function returning int.
e505224d 1957
63cef7d7 1958@node Symbol Tables
e505224d
PB
1959@chapter Symbol information in symbol tables
1960
1961This section examines more closely the format of symbol table entries
1962and how stab assembler directives map to them. It also describes what
1963transformations the assembler and linker make on data from stabs.
1964
1965Each time the assembler encounters a stab in its input file it puts
1966each field of the stab into corresponding fields in a symbol table
1967entry of its output file. If the stab contains a string field, the
1968symbol table entry for that stab points to a string table entry
1969containing the string data from the stab. Assembler labels become
1970relocatable addresses. Symbol table entries in a.out have the format:
1971
1972@example
1973struct internal_nlist @{
139741da
RP
1974 unsigned long n_strx; /* index into string table of name */
1975 unsigned char n_type; /* type of symbol */
1976 unsigned char n_other; /* misc info (usually empty) */
1977 unsigned short n_desc; /* description field */
1978 bfd_vma n_value; /* value of symbol */
e505224d
PB
1979@};
1980@end example
1981
1982For .stabs directives, the n_strx field holds the character offset
1983from the start of the string table to the string table entry
1984containing the "string" field. For other classes of stabs (.stabn and
1985.stabd) this field is null.
1986
1987Symbol table entries with n_type fields containing a value greater or
1988equal to 0x20 originated as stabs generated by the compiler (with one
1989random exception). Those with n_type values less than 0x20 were
1990placed in the symbol table of the executable by the assembler or the
1991linker.
1992
1993The linker concatenates object files and does fixups of externally
1994defined symbols. You can see the transformations made on stab data by
1995the assembler and linker by examining the symbol table after each pass
1996of the build, first the assemble and then the link.
1997
1998To do this use nm with the -ap options. This dumps the symbol table,
1999including debugging information, unsorted. For stab entries the
2000columns are: value, other, desc, type, string. For assembler and
2001linker symbols, the columns are: value, type, string.
2002
2003There are a few important things to notice about symbol tables. Where
2004the value field of a stab contains a frame pointer offset, or a
2005register number, that value is unchanged by the rest of the build.
2006
2007Where the value field of a stab contains an assembly language label,
2008it is transformed by each build step. The assembler turns it into a
2009relocatable address and the linker turns it into an absolute address.
2010This source line defines a static variable at file scope:
2011
899bafeb 2012@example
e505224d 20133 static int s_g_repeat
899bafeb 2014@end example
e505224d 2015
899bafeb 2016@noindent
e505224d
PB
2017The following stab describes the symbol.
2018
899bafeb 2019@example
e505224d 202026 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
899bafeb 2021@end example
e505224d 2022
899bafeb 2023@noindent
e505224d 2024The assembler transforms the stab into this symbol table entry in the
899bafeb 2025@file{.o} file. The location is expressed as a data segment offset.
e505224d 2026
899bafeb 2027@example
e505224d 202821 00000084 - 00 0000 STSYM s_g_repeat:S1
899bafeb 2029@end example
e505224d 2030
899bafeb 2031@noindent
e505224d
PB
2032in the symbol table entry from the executable, the linker has made the
2033relocatable address absolute.
2034
899bafeb 2035@example
e505224d 203622 0000e00c - 00 0000 STSYM s_g_repeat:S1
899bafeb 2037@end example
e505224d
PB
2038
2039Stabs for global variables do not contain location information. In
2040this case the debugger finds location information in the assembler or
2041linker symbol table entry describing the variable. The source line:
2042
899bafeb 2043@example
e505224d 20441 char g_foo = 'c';
899bafeb 2045@end example
e505224d 2046
899bafeb 2047@noindent
e505224d
PB
2048generates the stab:
2049
899bafeb 2050@example
e505224d 205121 .stabs "g_foo:G2",32,0,0,0
899bafeb 2052@end example
e505224d
PB
2053
2054The variable is represented by the following two symbol table entries
2055in the object file. The first one originated as a stab. The second
2056one is an external symbol. The upper case D signifies that the n_type
2057field of the symbol table contains 7, N_DATA with local linkage (see
2058Table B). The value field following the file's line number is empty
2059for the stab entry. For the linker symbol it contains the
2060rellocatable address corresponding to the variable.
2061
899bafeb 2062@example
e505224d
PB
206319 00000000 - 00 0000 GSYM g_foo:G2
206420 00000080 D _g_foo
899bafeb 2065@end example
e505224d 2066
899bafeb 2067@noindent
e505224d
PB
2068These entries as transformed by the linker. The linker symbol table
2069entry now holds an absolute address.
2070
899bafeb 2071@example
e505224d 207221 00000000 - 00 0000 GSYM g_foo:G2
899bafeb 2073@dots{}
e505224d 2074215 0000e008 D _g_foo
899bafeb 2075@end example
e505224d 2076
8c59ee11 2077@node Cplusplus
612dbd4c 2078@chapter GNU C++ stabs
e505224d
PB
2079
2080@menu
8eb5e289
DZ
2081* Basic Cplusplus types::
2082* Simple classes::
2083* Class instance::
2084* Methods:: Method definition
2085* Protections::
2086* Method Modifiers::
2087* Virtual Methods::
2088* Inheritence::
2089* Virtual Base Classes::
2090* Static Members::
e505224d
PB
2091@end menu
2092
e505224d
PB
2093@subsection type descriptors added for C++ descriptions
2094
2095@table @code
2096@item #
2097method type (two ## if minimal debug)
2098
8c59ee11
JK
2099@item @@
2100Member (class and variable) type. It is followed by type information
2101for the offset basetype, a comma, and type information for the type of
2102the field being pointed to. (FIXME: this is acknowledged to be
2103gibberish. Can anyone say what really goes here?).
2104
2105Note that there is a conflict between this and type attributes
2106(@pxref{Stabs Format}); both use type descriptor @samp{@@}.
2107Fortunately, the @samp{@@} type descriptor used in this C++ sense always
2108will be followed by a digit, @samp{(}, or @samp{-}, and type attributes
2109never start with those things.
e505224d
PB
2110@end table
2111
b32ae57b 2112@node Basic Cplusplus types
e505224d
PB
2113@section Basic types for C++
2114
2115<< the examples that follow are based on a01.C >>
2116
2117
2118C++ adds two more builtin types to the set defined for C. These are
2119the unknown type and the vtable record type. The unknown type, type
212016, is defined in terms of itself like the void type.
2121
2122The vtable record type, type 17, is defined as a structure type and
2123then as a structure tag. The structure has four fields, delta, index,
2124pfn, and delta2. pfn is the function pointer.
2125
2126<< In boilerplate $vtbl_ptr_type, what are the fields delta,
2127index, and delta2 used for? >>
2128
2129This basic type is present in all C++ programs even if there are no
2130virtual methods defined.
2131
899bafeb 2132@display
e505224d 2133.stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8)
139741da
RP
2134 elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16);
2135 elem_name(index):type_ref(short int),bit_offset(16),field_bits(16);
2136 elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void),
2137 bit_offset(32),field_bits(32);
2138 elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;"
2139 N_LSYM, NIL, NIL
899bafeb 2140@end display
139741da 2141
899bafeb 2142@smallexample
e505224d 2143.stabs "$vtbl_ptr_type:t17=s8
139741da
RP
2144 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;"
2145 ,128,0,0,0
899bafeb 2146@end smallexample
e505224d 2147
899bafeb 2148@display
e505224d 2149.stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL
899bafeb 2150@end display
e505224d 2151
899bafeb 2152@example
e505224d 2153.stabs "$vtbl_ptr_type:T17",128,0,0,0
899bafeb 2154@end example
e505224d 2155
899bafeb 2156@node Simple classes
e505224d
PB
2157@section Simple class definition
2158
2159The stabs describing C++ language features are an extension of the
2160stabs describing C. Stabs representing C++ class types elaborate
2161extensively on the stab format used to describe structure types in C.
2162Stabs representing class type variables look just like stabs
2163representing C language variables.
2164
2165Consider the following very simple class definition.
2166
2167@example
2168class baseA @{
2169public:
139741da
RP
2170 int Adat;
2171 int Ameth(int in, char other);
e505224d
PB
2172@};
2173@end example
2174
2175The class baseA is represented by two stabs. The first stab describes
2176the class as a structure type. The second stab describes a structure
2177tag of the class type. Both stabs are of stab type N_LSYM. Since the
2178stab is not located between an N_FUN and a N_LBRAC stab this indicates
2179that the class is defined at file scope. If it were, then the N_LSYM
2180would signify a local variable.
2181
2182A stab describing a C++ class type is similar in format to a stab
2183describing a C struct, with each class member shown as a field in the
2184structure. The part of the struct format describing fields is
2185expanded to include extra information relevent to C++ class members.
2186In addition, if the class has multiple base classes or virtual
2187functions the struct format outside of the field parts is also
2188augmented.
2189
2190In this simple example the field part of the C++ class stab
2191representing member data looks just like the field part of a C struct
2192stab. The section on protections describes how its format is
2193sometimes extended for member data.
2194
2195The field part of a C++ class stab representing a member function
2196differs substantially from the field part of a C struct stab. It
2197still begins with `name:' but then goes on to define a new type number
2198for the member function, describe its return type, its argument types,
2199its protection level, any qualifiers applied to the method definition,
2200and whether the method is virtual or not. If the method is virtual
2201then the method description goes on to give the vtable index of the
2202method, and the type number of the first base class defining the
2203method.
2204
2205When the field name is a method name it is followed by two colons
2206rather than one. This is followed by a new type definition for the
2207method. This is a number followed by an equal sign and then the
2208symbol descriptor `##', indicating a method type. This is followed by
2209a type reference showing the return type of the method and a
2210semi-colon.
2211
2212The format of an overloaded operator method name differs from that
2213of other methods. It is "op$::XXXX." where XXXX is the operator name
612dbd4c
JG
2214such as + or +=. The name ends with a period, and any characters except
2215the period can occur in the XXXX string.
e505224d
PB
2216
2217The next part of the method description represents the arguments to
2218the method, preceeded by a colon and ending with a semi-colon. The
2219types of the arguments are expressed in the same way argument types
2220are expressed in C++ name mangling. In this example an int and a char
2221map to `ic'.
2222
2223This is followed by a number, a letter, and an asterisk or period,
2224followed by another semicolon. The number indicates the protections
2225that apply to the member function. Here the 2 means public. The
2226letter encodes any qualifier applied to the method definition. In
2227this case A means that it is a normal function definition. The dot
2228shows that the method is not virtual. The sections that follow
2229elaborate further on these fields and describe the additional
2230information present for virtual methods.
2231
2232
899bafeb 2233@display
e505224d 2234.stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
139741da 2235 field_name(Adat):type(int),bit_offset(0),field_bits(32);
e505224d 2236
139741da
RP
2237 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
2238 :arg_types(int char);
2239 protection(public)qualifier(normal)virtual(no);;"
2240 N_LSYM,NIL,NIL,NIL
899bafeb 2241@end display
e505224d 2242
899bafeb 2243@smallexample
e505224d
PB
2244.stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
2245
2246.stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
2247
2248.stabs "baseA:T20",128,0,0,0
899bafeb 2249@end smallexample
e505224d 2250
899bafeb 2251@node Class instance
e505224d
PB
2252@section Class instance
2253
2254As shown above, describing even a simple C++ class definition is
2255accomplished by massively extending the stab format used in C to
2256describe structure types. However, once the class is defined, C stabs
2257with no modifications can be used to describe class instances. The
2258following source:
2259
2260@example
2261main () @{
139741da 2262 baseA AbaseA;
e505224d
PB
2263@}
2264@end example
2265
899bafeb
RP
2266@noindent
2267yields the following stab describing the class instance. It looks no
e505224d
PB
2268different from a standard C stab describing a local variable.
2269
899bafeb 2270@display
e505224d 2271.stabs "name:type_ref(baseA)", N_LSYM, NIL, NIL, frame_ptr_offset
899bafeb 2272@end display
e505224d 2273
899bafeb 2274@example
e505224d 2275.stabs "AbaseA:20",128,0,0,-20
899bafeb 2276@end example
e505224d 2277
899bafeb 2278@node Methods
e505224d
PB
2279@section Method defintion
2280
2281The class definition shown above declares Ameth. The C++ source below
2282defines Ameth:
2283
2284@example
2285int
2286baseA::Ameth(int in, char other)
2287@{
139741da 2288 return in;
e505224d
PB
2289@};
2290@end example
2291
2292
2293This method definition yields three stabs following the code of the
2294method. One stab describes the method itself and following two
2295describe its parameters. Although there is only one formal argument
2296all methods have an implicit argument which is the `this' pointer.
2297The `this' pointer is a pointer to the object on which the method was
2298called. Note that the method name is mangled to encode the class name
2299and argument types. << Name mangling is not described by this
2300document - Is there already such a doc? >>
2301
612dbd4c 2302@example
e505224d 2303.stabs "name:symbol_desriptor(global function)return_type(int)",
139741da 2304 N_FUN, NIL, NIL, code_addr_of_method_start
e505224d
PB
2305
2306.stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic
612dbd4c 2307@end example
e505224d
PB
2308
2309Here is the stab for the `this' pointer implicit argument. The name
c2dc518b 2310of the `this' pointer is always `this.' Type 19, the `this' pointer is
e505224d
PB
2311defined as a pointer to type 20, baseA, but a stab defining baseA has
2312not yet been emited. Since the compiler knows it will be emited
2313shortly, here it just outputs a cross reference to the undefined
2314symbol, by prefixing the symbol name with xs.
2315
612dbd4c 2316@example
e505224d 2317.stabs "name:sym_desc(register param)type_def(19)=
139741da 2318 type_desc(ptr to)type_ref(baseA)=
e505224d
PB
2319 type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number
2320
c2dc518b 2321.stabs "this:P19=*20=xsbaseA:",64,0,0,8
612dbd4c 2322@end example
e505224d
PB
2323
2324The stab for the explicit integer argument looks just like a parameter
2325to a C function. The last field of the stab is the offset from the
2326argument pointer, which in most systems is the same as the frame
2327pointer.
2328
612dbd4c 2329@example
e505224d 2330.stabs "name:sym_desc(value parameter)type_ref(int)",
139741da 2331 N_PSYM,NIL,NIL,offset_from_arg_ptr
e505224d
PB
2332
2333.stabs "in:p1",160,0,0,72
612dbd4c 2334@end example
e505224d
PB
2335
2336<< The examples that follow are based on A1.C >>
2337
899bafeb 2338@node Protections
e505224d
PB
2339@section Protections
2340
2341
2342In the simple class definition shown above all member data and
2343functions were publicly accessable. The example that follows
2344contrasts public, protected and privately accessable fields and shows
2345how these protections are encoded in C++ stabs.
2346
2347Protections for class member data are signified by two characters
2348embeded in the stab defining the class type. These characters are
2349located after the name: part of the string. /0 means private, /1
2350means protected, and /2 means public. If these characters are omited
2351this means that the member is public. The following C++ source:
2352
2353@example
2354class all_data @{
139741da
RP
2355private:
2356 int priv_dat;
e505224d 2357protected:
139741da 2358 char prot_dat;
e505224d 2359public:
139741da 2360 float pub_dat;
e505224d
PB
2361@};
2362@end example
2363
899bafeb 2364@noindent
e505224d
PB
2365generates the following stab to describe the class type all_data.
2366
899bafeb 2367@display
e505224d 2368.stabs "class_name:sym_desc(type)type_def(19)=type_desc(struct)struct_bytes
139741da
RP
2369 data_name:/protection(private)type_ref(int),bit_offset,num_bits;
2370 data_name:/protection(protected)type_ref(char),bit_offset,num_bits;
2371 data_name:(/num omited, private)type_ref(float),bit_offset,num_bits;;"
2372 N_LSYM,NIL,NIL,NIL
899bafeb 2373@end display
e505224d 2374
899bafeb 2375@smallexample
e505224d 2376.stabs "all_data:t19=s12
139741da 2377 priv_dat:/01,0,32;prot_dat:/12,32,8;pub_dat:12,64,32;;",128,0,0,0
899bafeb 2378@end smallexample
e505224d
PB
2379
2380Protections for member functions are signified by one digit embeded in
2381the field part of the stab describing the method. The digit is 0 if
2382private, 1 if protected and 2 if public. Consider the C++ class
2383definition below:
2384
2385@example
2386class all_methods @{
2387private:
139741da 2388 int priv_meth(int in)@{return in;@};
e505224d 2389protected:
139741da 2390 char protMeth(char in)@{return in;@};
e505224d 2391public:
139741da 2392 float pubMeth(float in)@{return in;@};
e505224d
PB
2393@};
2394@end example
2395
2396It generates the following stab. The digit in question is to the left
2397of an `A' in each case. Notice also that in this case two symbol
2398descriptors apply to the class name struct tag and struct type.
2399
899bafeb 2400@display
e505224d 2401.stabs "class_name:sym_desc(struct tag&type)type_def(21)=
139741da
RP
2402 sym_desc(struct)struct_bytes(1)
2403 meth_name::type_def(22)=sym_desc(method)returning(int);
2404 :args(int);protection(private)modifier(normal)virtual(no);
2405 meth_name::type_def(23)=sym_desc(method)returning(char);
2406 :args(char);protection(protected)modifier(normal)virual(no);
2407 meth_name::type_def(24)=sym_desc(method)returning(float);
2408 :args(float);protection(public)modifier(normal)virtual(no);;",
2409 N_LSYM,NIL,NIL,NIL
899bafeb 2410@end display
139741da 2411
899bafeb 2412@smallexample
e505224d 2413.stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
139741da 2414 pubMeth::24=##12;:f;2A.;;",128,0,0,0
899bafeb 2415@end smallexample
e505224d 2416
899bafeb
RP
2417@node Method Modifiers
2418@section Method Modifiers (const, volatile, const volatile)
e505224d
PB
2419
2420<< based on a6.C >>
2421
2422In the class example described above all the methods have the normal
2423modifier. This method modifier information is located just after the
2424protection information for the method. This field has four possible
2425character values. Normal methods use A, const methods use B, volatile
2426methods use C, and const volatile methods use D. Consider the class
2427definition below:
2428
2429@example
2430class A @{
2431public:
139741da
RP
2432 int ConstMeth (int arg) const @{ return arg; @};
2433 char VolatileMeth (char arg) volatile @{ return arg; @};
2434 float ConstVolMeth (float arg) const volatile @{return arg; @};
e505224d
PB
2435@};
2436@end example
2437
2438This class is described by the following stab:
2439
899bafeb 2440@display
e505224d 2441.stabs "class(A):sym_desc(struct)type_def(20)=type_desc(struct)struct_bytes(1)
139741da
RP
2442 meth_name(ConstMeth)::type_def(21)sym_desc(method)
2443 returning(int);:arg(int);protection(public)modifier(const)virtual(no);
2444 meth_name(VolatileMeth)::type_def(22)=sym_desc(method)
2445 returning(char);:arg(char);protection(public)modifier(volatile)virt(no)
2446 meth_name(ConstVolMeth)::type_def(23)=sym_desc(method)
2447 returning(float);:arg(float);protection(public)modifer(const volatile)
2448 virtual(no);;", @dots{}
899bafeb 2449@end display
139741da 2450
899bafeb 2451@example
e505224d 2452.stabs "A:T20=s1ConstMeth::21=##1;:i;2B.;VolatileMeth::22=##2;:c;2C.;
139741da 2453 ConstVolMeth::23=##12;:f;2D.;;",128,0,0,0
612dbd4c 2454@end example
e505224d 2455
899bafeb 2456@node Virtual Methods
e505224d
PB
2457@section Virtual Methods
2458
2459<< The following examples are based on a4.C >>
2460
2461The presence of virtual methods in a class definition adds additional
2462data to the class description. The extra data is appended to the
2463description of the virtual method and to the end of the class
2464description. Consider the class definition below:
2465
2466@example
2467class A @{
2468public:
139741da
RP
2469 int Adat;
2470 virtual int A_virt (int arg) @{ return arg; @};
e505224d
PB
2471@};
2472@end example
2473
2474This results in the stab below describing class A. It defines a new
2475type (20) which is an 8 byte structure. The first field of the class
2476struct is Adat, an integer, starting at structure offset 0 and
2477occupying 32 bits.
2478
2479The second field in the class struct is not explicitly defined by the
2480C++ class definition but is implied by the fact that the class
2481contains a virtual method. This field is the vtable pointer. The
2482name of the vtable pointer field starts with $vf and continues with a
2483type reference to the class it is part of. In this example the type
2484reference for class A is 20 so the name of its vtable pointer field is
2485$vf20, followed by the usual colon.
2486
2487Next there is a type definition for the vtable pointer type (21).
2488This is in turn defined as a pointer to another new type (22).
2489
2490Type 22 is the vtable itself, which is defined as an array, indexed by
6aa83a79
JG
2491a range of integers between 0 and 1, and whose elements are of type
249217. Type 17 was the vtable record type defined by the boilerplate C++
2493type definitions, as shown earlier.
e505224d
PB
2494
2495The bit offset of the vtable pointer field is 32. The number of bits
2496in the field are not specified when the field is a vtable pointer.
2497
2498Next is the method definition for the virtual member function A_virt.
2499Its description starts out using the same format as the non-virtual
2500member functions described above, except instead of a dot after the
2501`A' there is an asterisk, indicating that the function is virtual.
2502Since is is virtual some addition information is appended to the end
2503of the method description.
2504
2505The first number represents the vtable index of the method. This is a
250632 bit unsigned number with the high bit set, followed by a
2507semi-colon.
2508
2509The second number is a type reference to the first base class in the
2510inheritence hierarchy defining the virtual member function. In this
2511case the class stab describes a base class so the virtual function is
2512not overriding any other definition of the method. Therefore the
2513reference is to the type number of the class that the stab is
2514describing (20).
2515
2516This is followed by three semi-colons. One marks the end of the
2517current sub-section, one marks the end of the method field, and the
2518third marks the end of the struct definition.
2519
2520For classes containing virtual functions the very last section of the
2521string part of the stab holds a type reference to the first base
2522class. This is preceeded by `~%' and followed by a final semi-colon.
2523
899bafeb 2524@display
e505224d 2525.stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
139741da
RP
2526 field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
2527 field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
6aa83a79
JG
2528 sym_desc(array)index_type_ref(range of int from 0 to 1);
2529 elem_type_ref(vtbl elem type),
139741da
RP
2530 bit_offset(32);
2531 meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
2532 :arg_type(int),protection(public)normal(yes)virtual(yes)
2533 vtable_index(1);class_first_defining(A);;;~%first_base(A);",
2534 N_LSYM,NIL,NIL,NIL
899bafeb 2535@end display
e505224d 2536
3d4cf720 2537@c FIXME: bogus line break.
899bafeb 2538@example
3d4cf720
JK
2539.stabs "A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2540 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
612dbd4c 2541@end example
e505224d 2542
2dd00294
JG
2543@node Inheritence
2544@section Inheritence
e505224d
PB
2545
2546Stabs describing C++ derived classes include additional sections that
2547describe the inheritence hierarchy of the class. A derived class stab
2548also encodes the number of base classes. For each base class it tells
2549if the base class is virtual or not, and if the inheritence is private
2550or public. It also gives the offset into the object of the portion of
2551the object corresponding to each base class.
2552
2553This additional information is embeded in the class stab following the
2554number of bytes in the struct. First the number of base classes
2555appears bracketed by an exclamation point and a comma.
2556
2557Then for each base type there repeats a series: two digits, a number,
2558a comma, another number, and a semi-colon.
2559
2560The first of the two digits is 1 if the base class is virtual and 0 if
2561not. The second digit is 2 if the derivation is public and 0 if not.
2562
2563The number following the first two digits is the offset from the start
2564of the object to the part of the object pertaining to the base class.
2565
2566After the comma, the second number is a type_descriptor for the base
2567type. Finally a semi-colon ends the series, which repeats for each
2568base class.
2569
2570The source below defines three base classes A, B, and C and the
2571derived class D.
2572
2573
2574@example
2575class A @{
2576public:
139741da
RP
2577 int Adat;
2578 virtual int A_virt (int arg) @{ return arg; @};
e505224d
PB
2579@};
2580
2581class B @{
2582public:
139741da
RP
2583 int B_dat;
2584 virtual int B_virt (int arg) @{return arg; @};
e505224d
PB
2585@};
2586
2587class C @{
2588public:
139741da
RP
2589 int Cdat;
2590 virtual int C_virt (int arg) @{return arg; @};
e505224d
PB
2591@};
2592
2593class D : A, virtual B, public C @{
2594public:
139741da
RP
2595 int Ddat;
2596 virtual int A_virt (int arg ) @{ return arg+1; @};
2597 virtual int B_virt (int arg) @{ return arg+2; @};
2598 virtual int C_virt (int arg) @{ return arg+3; @};
2599 virtual int D_virt (int arg) @{ return arg; @};
e505224d
PB
2600@};
2601@end example
2602
2603Class stabs similar to the ones described earlier are generated for
2604each base class.
2605
5bc927fb
RP
2606@c FIXME!!! the linebreaks in the following example probably make the
2607@c examples literally unusable, but I don't know any other way to get
2608@c them on the page.
63cef7d7
JK
2609@c One solution would be to put some of the type definitions into
2610@c separate stabs, even if that's not exactly what the compiler actually
2611@c emits.
899bafeb 2612@smallexample
5bc927fb
RP
2613.stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2614 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
e505224d 2615
5bc927fb
RP
2616.stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
2617 :i;2A*-2147483647;25;;;~%25;",128,0,0,0
e505224d 2618
5bc927fb
RP
2619.stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
2620 :i;2A*-2147483647;28;;;~%28;",128,0,0,0
899bafeb 2621@end smallexample
e505224d
PB
2622
2623In the stab describing derived class D below, the information about
2624the derivation of this class is encoded as follows.
2625
899bafeb 2626@display
e505224d 2627.stabs "derived_class_name:symbol_descriptors(struct tag&type)=
139741da
RP
2628 type_descriptor(struct)struct_bytes(32)!num_bases(3),
2629 base_virtual(no)inheritence_public(no)base_offset(0),
2630 base_class_type_ref(A);
2631 base_virtual(yes)inheritence_public(no)base_offset(NIL),
2632 base_class_type_ref(B);
2633 base_virtual(no)inheritence_public(yes)base_offset(64),
2634 base_class_type_ref(C); @dots{}
899bafeb 2635@end display
139741da 2636
5bc927fb 2637@c FIXME! fake linebreaks.
899bafeb 2638@smallexample
5bc927fb
RP
2639.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
2640 1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
2641 :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
2642 28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
899bafeb 2643@end smallexample
e505224d 2644
2dd00294 2645@node Virtual Base Classes
e505224d
PB
2646@section Virtual Base Classes
2647
2648A derived class object consists of a concatination in memory of the
2649data areas defined by each base class, starting with the leftmost and
2650ending with the rightmost in the list of base classes. The exception
2651to this rule is for virtual inheritence. In the example above, class
2652D inherits virtually from base class B. This means that an instance
2653of a D object will not contain it's own B part but merely a pointer to
2654a B part, known as a virtual base pointer.
2655
2656In a derived class stab, the base offset part of the derivation
2657information, described above, shows how the base class parts are
2658ordered. The base offset for a virtual base class is always given as
26590. Notice that the base offset for B is given as 0 even though B is
2660not the first base class. The first base class A starts at offset 0.
2661
2662The field information part of the stab for class D describes the field
2663which is the pointer to the virtual base class B. The vbase pointer
2664name is $vb followed by a type reference to the virtual base class.
2665Since the type id for B in this example is 25, the vbase pointer name
2666is $vb25.
2667
5bc927fb 2668@c FIXME!! fake linebreaks below
899bafeb 2669@smallexample
5bc927fb
RP
2670.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,
2671 160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;
2672 2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt:
2673 :32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
899bafeb 2674@end smallexample
e505224d
PB
2675
2676Following the name and a semicolon is a type reference describing the
2677type of the virtual base class pointer, in this case 24. Type 24 was
c2dc518b 2678defined earlier as the type of the B class `this` pointer. The
e505224d
PB
2679`this' pointer for a class is a pointer to the class type.
2680
899bafeb 2681@example
c2dc518b 2682.stabs "this:P24=*25=xsB:",64,0,0,8
899bafeb 2683@end example
e505224d
PB
2684
2685Finally the field offset part of the vbase pointer field description
2686shows that the vbase pointer is the first field in the D object,
2687before any data fields defined by the class. The layout of a D class
2688object is a follows, Adat at 0, the vtable pointer for A at 32, Cdat
2689at 64, the vtable pointer for C at 96, the virtual ase pointer for B
2690at 128, and Ddat at 160.
2691
2692
899bafeb 2693@node Static Members
e505224d
PB
2694@section Static Members
2695
446e5d80
JG
2696The data area for a class is a concatenation of the space used by the
2697data members of the class. If the class has virtual methods, a vtable
e505224d 2698pointer follows the class data. The field offset part of each field
446e5d80 2699description in the class stab shows this ordering.
e505224d 2700
446e5d80 2701<< How is this reflected in stabs? See Cygnus bug #677 for some info. >>
e505224d 2702
899bafeb 2703@node Example2.c
e505224d
PB
2704@appendix Example2.c - source code for extended example
2705
2706@example
27071 char g_foo = 'c';
27082 register int g_bar asm ("%g5");
27093 static int s_g_repeat = 2;
27104 int (*g_pf)();
27115
27126 struct s_tag @{
27137 int s_int;
27148 float s_float;
27159 char s_char_vec[8];
271610 struct s_tag* s_next;
271711 @} g_an_s;
271812
271913 typedef struct s_tag s_typedef;
272014
272115 char char_vec[3] = @{'a','b','c'@};
272216
272317 main (argc, argv)
272418 int argc;
272519 char* argv[];
272620 @{
272721 static float s_flap;
139741da
RP
272822 int times;
272923 for (times=0; times < s_g_repeat; times++)@{
273024 int inner;
273125 printf ("Hello world\n");
273226 @}
e505224d
PB
273327 @};
273428
273529 enum e_places @{first,second=3,last@};
273630
273731 static s_proc (s_arg, s_ptr_arg, char_vec)
273832 s_typedef s_arg;
273933 s_typedef* s_ptr_arg;
274034 char* char_vec;
274135 @{
274236 union u_tag @{
274337 int u_int;
274438 float u_float;
274539 char* u_char;
274640 @} an_u;
274741 @}
274842
274943
2750@end example
2751
899bafeb 2752@node Example2.s
e505224d
PB
2753@appendix Example2.s - assembly code for extended example
2754
2755@example
27561 gcc2_compiled.:
27572 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
27583 .stabs "example2.c",100,0,0,Ltext0
139741da 27594 .text
e505224d
PB
27605 Ltext0:
27616 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
27627 .stabs "char:t2=r2;0;127;",128,0,0,0
27638 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
27649 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
276510 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
276611 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
276712 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
276813 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
276914 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
277015 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
277116 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
277217 .stabs "float:t12=r1;4;0;",128,0,0,0
277318 .stabs "double:t13=r1;8;0;",128,0,0,0
277419 .stabs "long double:t14=r1;8;0;",128,0,0,0
277520 .stabs "void:t15=15",128,0,0,0
277621 .stabs "g_foo:G2",32,0,0,0
139741da
RP
277722 .global _g_foo
277823 .data
e505224d 277924 _g_foo:
139741da 278025 .byte 99
e505224d 278126 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
139741da 278227 .align 4
e505224d 278328 _s_g_repeat:
139741da 278429 .word 2
5bc927fb
RP
2785@c FIXME! fake linebreak in line 30
278630 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;s_char_vec:
2787 17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
e505224d
PB
278831 .stabs "s_typedef:t16",128,0,0,0
278932 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
139741da
RP
279033 .global _char_vec
279134 .align 4
e505224d 279235 _char_vec:
139741da
RP
279336 .byte 97
279437 .byte 98
279538 .byte 99
279639 .reserve _s_flap.0,4,"bss",4
279740 .text
279841 .align 4
e505224d 279942 LC0:
139741da
RP
280043 .ascii "Hello world\12\0"
280144 .align 4
280245 .global _main
280346 .proc 1
e505224d
PB
280447 _main:
280548 .stabn 68,0,20,LM1
280649 LM1:
139741da
RP
280750 !#PROLOGUE# 0
280851 save %sp,-144,%sp
280952 !#PROLOGUE# 1
281053 st %i0,[%fp+68]
281154 st %i1,[%fp+72]
281255 call ___main,0
281356 nop
e505224d
PB
281457 LBB2:
281558 .stabn 68,0,23,LM2
281659 LM2:
139741da 281760 st %g0,[%fp-20]
e505224d 281861 L2:
139741da
RP
281962 sethi %hi(_s_g_repeat),%o0
282063 ld [%fp-20],%o1
282164 ld [%o0+%lo(_s_g_repeat)],%o0
282265 cmp %o1,%o0
282366 bge L3
282467 nop
e505224d
PB
282568 LBB3:
282669 .stabn 68,0,25,LM3
282770 LM3:
139741da
RP
282871 sethi %hi(LC0),%o1
282972 or %o1,%lo(LC0),%o0
283073 call _printf,0
283174 nop
e505224d
PB
283275 .stabn 68,0,26,LM4
283376 LM4:
283477 LBE3:
283578 .stabn 68,0,23,LM5
283679 LM5:
283780 L4:
139741da
RP
283881 ld [%fp-20],%o0
283982 add %o0,1,%o1
284083 st %o1,[%fp-20]
284184 b,a L2
e505224d
PB
284285 L3:
284386 .stabn 68,0,27,LM6
284487 LM6:
284588 LBE2:
284689 .stabn 68,0,27,LM7
284790 LM7:
284891 L1:
139741da
RP
284992 ret
285093 restore
e505224d
PB
285194 .stabs "main:F1",36,0,0,_main
285295 .stabs "argc:p1",160,0,0,68
285396 .stabs "argv:p20=*21=*2",160,0,0,72
285497 .stabs "s_flap:V12",40,0,0,_s_flap.0
285598 .stabs "times:1",128,0,0,-20
285699 .stabn 192,0,0,LBB2
2857100 .stabs "inner:1",128,0,0,-24
2858101 .stabn 192,0,0,LBB3
2859102 .stabn 224,0,0,LBE3
2860103 .stabn 224,0,0,LBE2
2861104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
5bc927fb
RP
2862@c FIXME: fake linebreak in line 105
2863105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
2864128,0,0,0
139741da
RP
2865106 .align 4
2866107 .proc 1
e505224d
PB
2867108 _s_proc:
2868109 .stabn 68,0,35,LM8
2869110 LM8:
139741da
RP
2870111 !#PROLOGUE# 0
2871112 save %sp,-120,%sp
2872113 !#PROLOGUE# 1
2873114 mov %i0,%o0
2874115 st %i1,[%fp+72]
2875116 st %i2,[%fp+76]
e505224d
PB
2876117 LBB4:
2877118 .stabn 68,0,41,LM9
2878119 LM9:
2879120 LBE4:
2880121 .stabn 68,0,41,LM10
2881122 LM10:
2882123 L5:
139741da
RP
2883124 ret
2884125 restore
e505224d
PB
2885126 .stabs "s_proc:f1",36,0,0,_s_proc
2886127 .stabs "s_arg:p16",160,0,0,0
2887128 .stabs "s_ptr_arg:p18",160,0,0,72
2888129 .stabs "char_vec:p21",160,0,0,76
2889130 .stabs "an_u:23",128,0,0,-20
2890131 .stabn 192,0,0,LBB4
2891132 .stabn 224,0,0,LBE4
2892133 .stabs "g_bar:r1",64,0,0,5
2893134 .stabs "g_pf:G24=*25=f1",32,0,0,0
139741da 2894135 .common _g_pf,4,"bss"
e505224d 2895136 .stabs "g_an_s:G16",32,0,0,0
139741da 2896137 .common _g_an_s,20,"bss"
e505224d
PB
2897@end example
2898
3d4cf720
JK
2899@node Stab Types
2900@appendix Values for the Stab Type Field
e505224d 2901
3d4cf720
JK
2902These are all the possible values for the stab type field, for
2903@code{a.out} files. This does not apply to XCOFF.
e505224d 2904
3d4cf720
JK
2905The following types are used by the linker and assembler; there is
2906nothing stabs-specific about them. Since this document does not attempt
2907to describe aspects of object file format other than the debugging
2908format, no details are given.
e505224d 2909
3d4cf720
JK
2910@c Try to get most of these to fit on a single line.
2911@iftex
2912@tableindent=1.5in
2913@end iftex
e505224d 2914
3d4cf720
JK
2915@table @code
2916@item 0x0 N_UNDF
2917Undefined symbol
e505224d 2918
3d4cf720
JK
2919@item 0x2 N_ABS
2920File scope absolute symbol
e505224d 2921
3d4cf720
JK
2922@item 0x3 N_ABS | N_EXT
2923External absolute symbol
2924
2925@item 0x4 N_TEXT
2926File scope text symbol
2927
2928@item 0x5 N_TEXT | N_EXT
2929External text symbol
2930
2931@item 0x6 N_DATA
2932File scope data symbol
2933
2934@item 0x7 N_DATA | N_EXT
2935External data symbol
2936
2937@item 0x8 N_BSS
2938File scope BSS symbol
2939
2940@item 0x9 N_BSS | N_EXT
2941External BSS symbol
2942
2943@item 0x0c N_FN_SEQ
2944Same as N_FN, for Sequent compilers
2945
2946@item 0x0a N_INDR
2947Symbol is indirected to another symbol
2948
2949@item 0x12 N_COMM
2950Common sym -- visable after shared lib dynamic link
2951
2952@item 0x14 N_SETA
2953Absolute set element
2954
2955@item 0x16 N_SETT
2956Text segment set element
2957
2958@item 0x18 N_SETD
2959Data segment set element
2960
2961@item 0x1a N_SETB
2962BSS segment set element
2963
2964@item 0x1c N_SETV
2965Pointer to set vector
2966
2967@item 0x1e N_WARNING
2968Print a warning message during linking
2969
2970@item 0x1f N_FN
2971File name of a .o file
2972@end table
2973
2974The following symbol types indicate that this is a stab. This is the
2975full list of stab numbers, including stab types that are used in
2976languages other than C.
2977
2978@table @code
2979@item 0x20 N_GSYM
2980Global symbol, @xref{N_GSYM}.
2981
2982@item 0x22 N_FNAME
2983Function name (for BSD Fortran), @xref{N_FNAME}.
2984
24dcc707
JK
2985@item 0x24 N_FUN
2986Function name (@pxref{Procedures}) or text segment variable
2987(@pxref{Statics}).
3d4cf720 2988
24dcc707
JK
2989@item 0x26 N_STSYM
2990Data segment file-scope variable, @xref{Statics}.
3d4cf720 2991
24dcc707
JK
2992@item 0x28 N_LCSYM
2993BSS segment file-scope variable, @xref{Statics}.
3d4cf720 2994
499a5faa
JK
2995@item 0x2a N_MAIN
2996Name of main routine, @xref{Main Program}.
3d4cf720 2997
ded6bcab
JK
2998@c FIXME: discuss this in the main body of the text where we talk about
2999@c using N_FUN for variables.
3000@item 0x2c N_ROSYM
3001Read-only data symbol (Solaris2). Most systems use N_FUN for this.
3002
3d4cf720
JK
3003@item 0x30 N_PC
3004Global symbol (for Pascal), @xref{N_PC}.
3005
3006@item 0x32 N_NSYMS
3007Number of symbols (according to Ultrix V4.0), @xref{N_NSYMS}.
3008
3009@item 0x34 N_NOMAP
3010No DST map for sym (according to Ultrix V4.0), @xref{N_NOMAP}.
3011
ded6bcab
JK
3012@c FIXME: describe this solaris feature in the body of the text (see
3013@c comments in include/aout/stab.def).
3014@item 0x38 N_OBJ
3015Object file (Solaris2).
3016
3017@c See include/aout/stab.def for (a little) more info.
3018@item 0x3c N_OPT
3019Debugger options (Solaris2).
3020
3d4cf720
JK
3021@item 0x40 N_RSYM
3022Register variable, @xref{N_RSYM}.
3023
3024@item 0x42 N_M2C
3025Modula-2 compilation unit, @xref{N_M2C}.
3026
3027@item 0x44 N_SLINE
3028Line number in text segment, @xref{Line Numbers}.
3029
3030@item 0x46 N_DSLINE
3031Line number in data segment, @xref{Line Numbers}.
3032
3033@item 0x48 N_BSLINE
3034Line number in bss segment, @xref{Line Numbers}.
3035
3036@item 0x48 N_BROWS
3037Sun source code browser, path to .cb file, @xref{N_BROWS}.
3038
3039@item 0x4a N_DEFD
3040Gnu Modula2 definition module dependency, @xref{N_DEFD}.
3041
ded6bcab
JK
3042@item 0x4c N_FLINE
3043Function start/body/end line numbers (Solaris2).
3044
3d4cf720
JK
3045@item 0x50 N_EHDECL
3046Gnu C++ exception variable, @xref{N_EHDECL}.
3047
3048@item 0x50 N_MOD2
3049Modula2 info "for imc" (according to Ultrix V4.0), @xref{N_MOD2}.
3050
3051@item 0x54 N_CATCH
3052Gnu C++ "catch" clause, @xref{N_CATCH}.
3053
3054@item 0x60 N_SSYM
3055Structure of union element, @xref{N_SSYM}.
3056
ded6bcab
JK
3057@item 0x62 N_ENDM
3058Last stab for module (Solaris2).
3059
3d4cf720
JK
3060@item 0x64 N_SO
3061Path and name of source file , @xref{Source Files}.
3062
3063@item 0x80 N_LSYM
3064Automatic var in the stack or type definition, @xref{N_LSYM}, @xref{Typedefs}.
3065
3066@item 0x82 N_BINCL
3067Beginning of an include file (Sun only), @xref{Source Files}.
3068
3069@item 0x84 N_SOL
f0f4b04e 3070Name of include file, @xref{Source Files}.
3d4cf720
JK
3071
3072@item 0xa0 N_PSYM
3073Parameter variable, @xref{Parameters}.
3074
3075@item 0xa2 N_EINCL
3076End of an include file, @xref{Source Files}.
3077
3078@item 0xa4 N_ENTRY
3079Alternate entry point, @xref{N_ENTRY}.
3080
3081@item 0xc0 N_LBRAC
f0f4b04e 3082Beginning of a lexical block, @xref{Block Structure}.
3d4cf720
JK
3083
3084@item 0xc2 N_EXCL
3085Place holder for a deleted include file, @xref{Source Files}.
3086
3087@item 0xc4 N_SCOPE
3088Modula2 scope information (Sun linker), @xref{N_SCOPE}.
3089
3090@item 0xe0 N_RBRAC
f0f4b04e 3091End of a lexical block, @xref{Block Structure}.
3d4cf720
JK
3092
3093@item 0xe2 N_BCOMM
807e8368 3094Begin named common block, @xref{Common Blocks}.
3d4cf720
JK
3095
3096@item 0xe4 N_ECOMM
807e8368 3097End named common block, @xref{Common Blocks}.
3d4cf720
JK
3098
3099@item 0xe8 N_ECOML
807e8368 3100Member of a common block, @xref{Common Blocks}.
3d4cf720 3101
ded6bcab
JK
3102@c FIXME: How does this really work? Move it to main body of document.
3103@item 0xea N_WITH
3104Pascal @code{with} statement: type,,0,0,offset (Solaris2).
3105
3d4cf720 3106@item 0xf0 N_NBTEXT
ded6bcab 3107Gould non-base registers, @xref{Gould}.
3d4cf720
JK
3108
3109@item 0xf2 N_NBDATA
ded6bcab 3110Gould non-base registers, @xref{Gould}.
3d4cf720
JK
3111
3112@item 0xf4 N_NBBSS
ded6bcab 3113Gould non-base registers, @xref{Gould}.
3d4cf720
JK
3114
3115@item 0xf6 N_NBSTS
ded6bcab 3116Gould non-base registers, @xref{Gould}.
3d4cf720
JK
3117
3118@item 0xf8 N_NBLCS
ded6bcab 3119Gould non-base registers, @xref{Gould}.
3d4cf720
JK
3120@end table
3121
3122@c Restore the default table indent
3123@iftex
3124@tableindent=.8in
3125@end iftex
e505224d 3126
8c59ee11 3127@node Symbol Descriptors
3d4cf720 3128@appendix Table of Symbol Descriptors
e505224d 3129
ed9708e2 3130@c Please keep this alphabetical
497e44a5 3131@table @code
466bdeb2
JK
3132@c In TeX, this looks great, digit is in italics. But makeinfo insists
3133@c on putting it in `', not realizing that @var should override @code.
3134@c I don't know of any way to make makeinfo do the right thing. Seems
3135@c like a makeinfo bug to me.
3136@item @var{digit}
8c59ee11
JK
3137@itemx (
3138@itemx -
497e44a5
JK
3139Local variable, @xref{Automatic variables}.
3140
6897f9ec
JK
3141@item a
3142Parameter passed by reference in register, @xref{Parameters}.
3143
3144@item c
3145Constant, @xref{Constants}.
3146
ed9708e2 3147@item C
8c59ee11
JK
3148Conformant array bound (Pascal, maybe other languages),
3149@xref{Parameters}. Name of a caught exception (GNU C++). These can be
3150distinguished because the latter uses N_CATCH and the former uses
3151another symbol type.
6897f9ec
JK
3152
3153@item d
3154Floating point register variable, @xref{Register variables}.
3155
3156@item D
3157Parameter in floating point register, @xref{Parameters}.
ed9708e2 3158
497e44a5 3159@item f
24dcc707 3160File scope function, @xref{Procedures}.
497e44a5
JK
3161
3162@item F
3163Global function, @xref{Procedures}.
3164
497e44a5
JK
3165@item G
3166Global variable, @xref{Global Variables}.
3167
ed9708e2
JK
3168@item i
3169@xref{Parameters}.
3170
6897f9ec
JK
3171@item I
3172Internal (nested) procedure, @xref{Procedures}.
3173
3174@item J
3175Internal (nested) function, @xref{Procedures}.
3176
3177@item L
3178Label name (documented by AIX, no further information known).
3179
3180@item m
3181Module, @xref{Procedures}.
3182
ed9708e2 3183@item p
8c59ee11 3184Argument list parameter, @xref{Parameters}.
ed9708e2
JK
3185
3186@item pP
3187@xref{Parameters}.
3188
3189@item pF
8c59ee11 3190FORTRAN Function parameter, @xref{Parameters}.
ed9708e2
JK
3191
3192@item P
1a8b5668
JK
3193Unfortunately, three separate meanings have been independently invented
3194for this symbol descriptor. At least the GNU and Sun uses can be
3195distinguished by the symbol type. Global Procedure (AIX) (symbol type
3196used unknown), @xref{Procedures}. Register parameter (GNU) (symbol type
3197N_PSYM), @xref{Parameters}. Prototype of function referenced by this
3198file (Sun acc) (symbol type N_FUN).
6897f9ec
JK
3199
3200@item Q
3201Static Procedure, @xref{Procedures}.
3202
3203@item R
ed9708e2
JK
3204Register parameter @xref{Parameters}.
3205
497e44a5
JK
3206@item r
3207Register variable, @xref{Register variables}.
3208
3209@item S
24dcc707 3210File scope variable, @xref{Statics}.
497e44a5 3211
ed9708e2
JK
3212@item t
3213Type name, @xref{Typedefs}.
3214
3215@item T
8c59ee11 3216enumeration, struct or union tag, @xref{Typedefs}.
ed9708e2
JK
3217
3218@item v
8c59ee11 3219Parameter passed by reference, @xref{Parameters}.
ed9708e2 3220
497e44a5 3221@item V
24dcc707 3222Procedure scope static variable, @xref{Statics}.
497e44a5 3223
6897f9ec
JK
3224@item x
3225Conformant array, @xref{Parameters}.
3226
ed9708e2
JK
3227@item X
3228Function return variable, @xref{Parameters}.
497e44a5 3229@end table
e505224d 3230
899bafeb 3231@node Type Descriptors
3d4cf720 3232@appendix Table of Type Descriptors
e505224d 3233
6897f9ec 3234@table @code
8c59ee11
JK
3235@item @var{digit}
3236@itemx (
3237Type reference, @xref{Stabs Format}.
3238
3239@item -
3240Reference to builtin type, @xref{Negative Type Numbers}.
3241
3242@item #
3243Method (C++), @xref{Cplusplus}.
6897f9ec
JK
3244
3245@item *
8c59ee11
JK
3246Pointer, @xref{Miscellaneous Types}.
3247
3248@item &
3249Reference (C++).
6897f9ec
JK
3250
3251@item @@
8c59ee11
JK
3252Type Attributes (AIX), @xref{Stabs Format}. Member (class and variable)
3253type (GNU C++), @xref{Cplusplus}.
e505224d 3254
6897f9ec 3255@item a
8c59ee11
JK
3256Array, @xref{Arrays}.
3257
3258@item A
3259Open array, @xref{Arrays}.
3260
3261@item b
3262Pascal space type (AIX), @xref{Miscellaneous Types}. Builtin integer
3263type (Sun), @xref{Builtin Type Descriptors}.
3264
3265@item B
3266Volatile-qualified type, @xref{Miscellaneous Types}.
3267
3268@item c
3269Complex builtin type, @xref{Builtin Type Descriptors}.
3270
3271@item C
3272COBOL Picture type. See AIX documentation for details.
3273
3274@item d
3275File type, @xref{Miscellaneous Types}.
3276
3277@item D
3278N-dimensional dynamic array, @xref{Arrays}.
6897f9ec
JK
3279
3280@item e
8c59ee11
JK
3281Enumeration type, @xref{Enumerations}.
3282
3283@item E
3284N-dimensional subarray, @xref{Arrays}.
6897f9ec
JK
3285
3286@item f
a03f27c3
JK
3287Function type, @xref{Function Types}.
3288
3289@item F
3290Pascal function parameter, @xref{Function Types}
8c59ee11
JK
3291
3292@item g
3293Builtin floating point type, @xref{Builtin Type Descriptors}.
3294
3295@item G
3296COBOL Group. See AIX documentation for details.
3297
3298@item i
3299Imported type, @xref{Cross-references}.
3300
3301@item k
3302Const-qualified type, @xref{Miscellaneous Types}.
3303
3304@item K
3305COBOL File Descriptor. See AIX documentation for details.
3306
a03f27c3
JK
3307@item M
3308Multiple instance type, @xref{Miscellaneous Types}.
3309
8c59ee11
JK
3310@item n
3311String type, @xref{Strings}.
3312
3313@item N
3314Stringptr, @xref{Strings}.
3315
8c59ee11
JK
3316@item o
3317Opaque type, @xref{Typedefs}.
3318
a03f27c3
JK
3319@item p
3320Procedure, @xref{Function Types}.
3321
8c59ee11
JK
3322@item P
3323Packed array, @xref{Arrays}.
6897f9ec
JK
3324
3325@item r
8c59ee11
JK
3326Range type, @xref{Subranges}.
3327
3328@item R
a03f27c3
JK
3329Builtin floating type, @xref{Builtin Type Descriptors} (Sun). Pascal
3330subroutine parameter, @xref{Function Types} (AIX). Detecting this
3331conflict is possible with careful parsing (hint: a Pascal subroutine
3332parameter type will always contain a comma, and a builtin type
3333descriptor never will).
6897f9ec
JK
3334
3335@item s
8c59ee11
JK
3336Structure type, @xref{Structures}.
3337
3338@item S
3339Set type, @xref{Miscellaneous Types}.
6897f9ec
JK
3340
3341@item u
8c59ee11
JK
3342Union, @xref{Unions}.
3343
3344@item v
3345Variant record. This is a Pascal and Modula-2 feature which is like a
3346union within a struct in C. See AIX documentation for details.
3347
3348@item w
3349Wide character, @xref{Builtin Type Descriptors}.
3350
3351@item x
3352Cross-reference, @xref{Cross-references}.
6897f9ec 3353
8c59ee11
JK
3354@item z
3355gstring, @xref{Strings}.
6897f9ec 3356@end table
e505224d 3357
899bafeb 3358@node Expanded reference
e505224d
PB
3359@appendix Expanded reference by stab type.
3360
3d4cf720 3361@c FIXME: This appendix should go away, see N_PSYM or N_SO for an example.
8c59ee11 3362
3d4cf720
JK
3363For a full list of stab types, and cross-references to where they are
3364described, @xref{Stab Types}. This appendix just duplicates certain
3365information from the main body of this document; eventually the
3366information will all be in one place.
8c59ee11 3367
e505224d
PB
3368Format of an entry:
3369
3370The first line is the symbol type expressed in decimal, hexadecimal,
3371and as a #define (see devo/include/aout/stab.def).
3372
3373The second line describes the language constructs the symbol type
3374represents.
3375
3376The third line is the stab format with the significant stab fields
3377named and the rest NIL.
3378
3379Subsequent lines expand upon the meaning and possible values for each
3380significant stab field. # stands in for the type descriptor.
3381
3382Finally, any further information.
3383
899bafeb 3384@menu
8eb5e289
DZ
3385* N_GSYM:: Global variable
3386* N_FNAME:: Function name (BSD Fortran)
8eb5e289
DZ
3387* N_PC:: Pascal global symbol
3388* N_NSYMS:: Number of symbols
3389* N_NOMAP:: No DST map
3390* N_RSYM:: Register variable
3391* N_M2C:: Modula-2 compilation unit
3392* N_BROWS:: Path to .cb file for Sun source code browser
3393* N_DEFD:: GNU Modula2 definition module dependency
3394* N_EHDECL:: GNU C++ exception variable
3395* N_MOD2:: Modula2 information "for imc"
3396* N_CATCH:: GNU C++ "catch" clause
3397* N_SSYM:: Structure or union element
3398* N_LSYM:: Automatic variable
3399* N_ENTRY:: Alternate entry point
3400* N_SCOPE:: Modula2 scope information (Sun only)
3401* Gould:: non-base register symbols used on Gould systems
3402* N_LENG:: Length of preceding entry
899bafeb
RP
3403@end menu
3404
3405@node N_GSYM
139741da 3406@section 32 - 0x20 - N_GYSM
899bafeb
RP
3407
3408@display
e505224d
PB
3409Global variable.
3410
3411.stabs "name", N_GSYM, NIL, NIL, NIL
899bafeb 3412@end display
e505224d 3413
899bafeb 3414@example
e505224d 3415"name" -> "symbol_name:#type"
139741da 3416 # -> G
899bafeb 3417@end example
e505224d 3418
4d7f562d 3419Only the "name" field is significant. The location of the variable is
e505224d
PB
3420obtained from the corresponding external symbol.
3421
899bafeb
RP
3422@node N_FNAME
3423@section 34 - 0x22 - N_FNAME
e505224d
PB
3424Function name (for BSD Fortran)
3425
899bafeb 3426@display
e505224d 3427.stabs "name", N_FNAME, NIL, NIL, NIL
899bafeb 3428@end display
e505224d 3429
899bafeb 3430@example
e505224d 3431"name" -> "function_name"
899bafeb 3432@end example
e505224d
PB
3433
3434Only the "name" field is significant. The location of the symbol is
3435obtained from the corresponding extern symbol.
3436
899bafeb 3437@node N_PC
139741da 3438@section 48 - 0x30 - N_PC
e505224d
PB
3439Global symbol (for Pascal)
3440
899bafeb 3441@display
e505224d 3442.stabs "name", N_PC, NIL, NIL, value
899bafeb 3443@end display
e505224d 3444
899bafeb 3445@example
e505224d
PB
3446"name" -> "symbol_name" <<?>>
3447value -> supposedly the line number (stab.def is skeptical)
899bafeb 3448@end example
e505224d 3449
899bafeb 3450@display
e505224d
PB
3451stabdump.c says:
3452
3453global pascal symbol: name,,0,subtype,line
3454<< subtype? >>
899bafeb 3455@end display
e505224d 3456
899bafeb 3457@node N_NSYMS
139741da 3458@section 50 - 0x32 - N_NSYMS
e505224d
PB
3459Number of symbols (according to Ultrix V4.0)
3460
899bafeb 3461@display
139741da 3462 0, files,,funcs,lines (stab.def)
899bafeb 3463@end display
e505224d 3464
899bafeb
RP
3465@node N_NOMAP
3466@section 52 - 0x34 - N_NOMAP
e505224d
PB
3467no DST map for sym (according to Ultrix V4.0)
3468
899bafeb 3469@display
139741da 3470 name, ,0,type,ignored (stab.def)
899bafeb
RP
3471@end display
3472
3473@node N_RSYM
139741da 3474@section 64 - 0x40 - N_RSYM
e505224d
PB
3475 register variable
3476
899bafeb 3477@display
e505224d 3478.stabs "name:type",N_RSYM,0,RegSize,RegNumber (Sun doc)
899bafeb 3479@end display
e505224d 3480
899bafeb 3481@node N_M2C
139741da 3482@section 66 - 0x42 - N_M2C
e505224d
PB
3483Modula-2 compilation unit
3484
899bafeb 3485@display
e505224d 3486.stabs "name", N_M2C, 0, desc, value
899bafeb 3487@end display
e505224d 3488
899bafeb 3489@example
e505224d
PB
3490"name" -> "unit_name,unit_time_stamp[,code_time_stamp]
3491desc -> unit_number
3492value -> 0 (main unit)
139741da 3493 1 (any other unit)
899bafeb 3494@end example
e505224d 3495
899bafeb 3496@node N_BROWS
139741da 3497@section 72 - 0x48 - N_BROWS
e505224d
PB
3498Sun source code browser, path to .cb file
3499
3500<<?>>
3501"path to associated .cb file"
3502
3503Note: type field value overlaps with N_BSLINE
3504
899bafeb 3505@node N_DEFD
139741da 3506@section 74 - 0x4a - N_DEFD
612dbd4c 3507GNU Modula2 definition module dependency
e505224d
PB
3508
3509GNU Modula-2 definition module dependency. Value is the modification
3510time of the definition file. Other is non-zero if it is imported with
3511the GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
3512are enough empty fields?
3513
899bafeb
RP
3514@node N_EHDECL
3515@section 80 - 0x50 - N_EHDECL
612dbd4c 3516GNU C++ exception variable <<?>>
e505224d
PB
3517
3518"name is variable name"
3519
3520Note: conflicts with N_MOD2.
3521
899bafeb
RP
3522@node N_MOD2
3523@section 80 - 0x50 - N_MOD2
3524Modula2 info "for imc" (according to Ultrix V4.0)
e505224d
PB
3525
3526Note: conflicts with N_EHDECL <<?>>
3527
899bafeb
RP
3528@node N_CATCH
3529@section 84 - 0x54 - N_CATCH
3530GNU C++ "catch" clause
e505224d
PB
3531
3532GNU C++ `catch' clause. Value is its address. Desc is nonzero if
3533this entry is immediately followed by a CAUGHT stab saying what
3534exception was caught. Multiple CAUGHT stabs means that multiple
3535exceptions can be caught here. If Desc is 0, it means all exceptions
3536are caught here.
3537
899bafeb 3538@node N_SSYM
139741da 3539@section 96 - 0x60 - N_SSYM
e505224d
PB
3540Structure or union element
3541
899bafeb
RP
3542Value is offset in the structure.
3543
3544<<?looking at structs and unions in C I didn't see these>>
e505224d 3545
899bafeb 3546@node N_LSYM
139741da 3547@section 128 - 0x80 - N_LSYM
e505224d
PB
3548Automatic var in the stack (also used for type descriptors.)
3549
899bafeb 3550@display
e505224d 3551.stabs "name" N_LSYM, NIL, NIL, value
899bafeb 3552@end display
e505224d 3553
899bafeb
RP
3554@example
3555@exdent @emph{For stack based local variables:}
e505224d
PB
3556
3557"name" -> name of the variable
3558value -> offset from frame pointer (negative)
3559
899bafeb 3560@exdent @emph{For type descriptors:}
e505224d
PB
3561
3562"name" -> "name_of_the_type:#type"
139741da 3563 # -> t
e505224d 3564
139741da 3565type -> type_ref (or) type_def
e505224d
PB
3566
3567type_ref -> type_number
3568type_def -> type_number=type_desc etc.
899bafeb 3569@end example
e505224d
PB
3570
3571Type may be either a type reference or a type definition. A type
3572reference is a number that refers to a previously defined type. A
3573type definition is the number that will refer to this type, followed
3574by an equals sign, a type descriptor and the additional data that
3575defines the type. See the Table D for type descriptors and the
3576section on types for what data follows each type descriptor.
3577
899bafeb
RP
3578@node N_ENTRY
3579@section 164 - 0xa4 - N_ENTRY
e505224d
PB
3580
3581Alternate entry point.
3582Value is its address.
3583<<?>>
3584
899bafeb
RP
3585@node N_SCOPE
3586@section 196 - 0xc4 - N_SCOPE
e505224d
PB
3587
3588Modula2 scope information (Sun linker)
3589<<?>>
3590
899bafeb
RP
3591@node Gould
3592@section Non-base registers on Gould systems
ded6bcab
JK
3593
3594These are used on Gould systems for non-base registers syms.
3595
3596However, the following values are not the values used by Gould; they are
3597the values which GNU has been documenting for these values for a long
3598time, without actually checking what Gould uses. I include these values
3599only because perhaps some someone actually did something with the GNU
3600information (I hope not, why GNU knowingly assigned wrong values to
3601these in the header file is a complete mystery to me).
e505224d 3602
899bafeb 3603@example
139741da
RP
3604240 0xf0 N_NBTEXT ??
3605242 0xf2 N_NBDATA ??
3606244 0xf4 N_NBBSS ??
3607246 0xf6 N_NBSTS ??
3608248 0xf8 N_NBLCS ??
899bafeb 3609@end example
e505224d 3610
899bafeb
RP
3611@node N_LENG
3612@section - 0xfe - N_LENG
e505224d
PB
3613
3614Second symbol entry containing a length-value for the preceding entry.
3615The value is the length.
3616
899bafeb
RP
3617@node Questions
3618@appendix Questions and anomalies
e505224d
PB
3619
3620@itemize @bullet
3621@item
3622For GNU C stabs defining local and global variables (N_LSYM and
3623N_GSYM), the desc field is supposed to contain the source line number
3624on which the variable is defined. In reality the desc field is always
36250. (This behavour is defined in dbxout.c and putting a line number in
3626desc is controlled by #ifdef WINNING_GDB which defaults to false). Gdb
3627supposedly uses this information if you say 'list var'. In reality
3628var can be a variable defined in the program and gdb says `function
3629var not defined'
3630
3631@item
612dbd4c 3632In GNU C stabs there seems to be no way to differentiate tag types:
e505224d
PB
3633structures, unions, and enums (symbol descriptor T) and typedefs
3634(symbol descriptor t) defined at file scope from types defined locally
3635to a procedure or other more local scope. They all use the N_LSYM
3636stab type. Types defined at procedure scope are emited after the
139741da 3637N_RBRAC of the preceding function and before the code of the
e505224d
PB
3638procedure in which they are defined. This is exactly the same as
3639types defined in the source file between the two procedure bodies.
4d7f562d 3640GDB overcompensates by placing all types in block #1, the block for
e505224d 3641symbols of file scope. This is true for default, -ansi and
4d7f562d 3642-traditional compiler options. (Bugs gcc/1063, gdb/1066.)
e505224d
PB
3643
3644@item
3645What ends the procedure scope? Is it the proc block's N_RBRAC or the
3646next N_FUN? (I believe its the first.)
3647
3648@item
24dcc707 3649@c FIXME: This should go with the other stuff about global variables.
e505224d
PB
3650Global variable stabs don't have location information. This comes
3651from the external symbol for the same variable. The external symbol
3652has a leading underbar on the _name of the variable and the stab does
3653not. How do we know these two symbol table entries are talking about
24dcc707
JK
3654the same symbol when their names are different? (Answer: the debugger
3655knows that external symbols have leading underbars).
e505224d 3656
24dcc707
JK
3657@c FIXME: This is absurdly vague; there all kinds of differences, some
3658@c of which are the same between gnu & sun, and some of which aren't.
e505224d
PB
3659@item
3660Can gcc be configured to output stabs the way the Sun compiler
3661does, so that their native debugging tools work? <NO?> It doesn't by
3662default. GDB reads either format of stab. (gcc or SunC). How about
3663dbx?
3664@end itemize
3665
899bafeb 3666@node xcoff-differences
e505224d
PB
3667@appendix Differences between GNU stabs in a.out and GNU stabs in xcoff
3668
497e44a5
JK
3669@c FIXME: Merge *all* these into the main body of the document.
3670(The AIX/RS6000 native object file format is xcoff with stabs). This
3671appendix only covers those differences which are not covered in the main
3672body of this document.
e505224d
PB
3673
3674@itemize @bullet
e505224d 3675@item
5bc927fb 3676BSD a.out stab types correspond to AIX xcoff storage classes. In general the
e505224d
PB
3677mapping is N_STABTYPE becomes C_STABTYPE. Some stab types in a.out
3678are not supported in xcoff. See Table E. for full mappings.
3679
24dcc707
JK
3680@c FIXME: Get C_* types for the block, figure out whether it is always
3681@c used (I suspect not), explain clearly, and move to node Statics.
e505224d
PB
3682exception:
3683initialised static N_STSYM and un-initialized static N_LCSYM both map
3684to the C_STSYM storage class. But the destinction is preserved
3685because in xcoff N_STSYM and N_LCSYM must be emited in a named static
3686block. Begin the block with .bs s[RW] data_section_name for N_STSYM
3687or .bs s bss_section_name for N_LCSYM. End the block with .es
3688
24dcc707
JK
3689@c FIXME: I think they are trying to say something about whether the
3690@c assembler defaults the value to the location counter.
e505224d
PB
3691@item
3692If the xcoff stab is a N_FUN (C_FUN) then follow the string field with
3693,. instead of just ,
e505224d
PB
3694@end itemize
3695
e505224d
PB
3696(I think that's it for .s file differences. They could stand to be
3697better presented. This is just a list of what I have noticed so far.
3698There are a *lot* of differences in the information in the symbol
3699tables of the executable and object files.)
3700
3701Table E: mapping a.out stab types to xcoff storage classes
3702
3703@example
139741da 3704stab type storage class
e505224d 3705-------------------------------
139741da
RP
3706N_GSYM C_GSYM
3707N_FNAME unknown
3708N_FUN C_FUN
3709N_STSYM C_STSYM
3710N_LCSYM C_STSYM
3711N_MAIN unkown
3712N_PC unknown
3713N_RSYM C_RSYM
3714N_RPSYM (0x8e) C_RPSYM
3715N_M2C unknown
3716N_SLINE unknown
3717N_DSLINE unknown
3718N_BSLINE unknown
3719N_BROWSE unchanged
3720N_CATCH unknown
3721N_SSYM unknown
3722N_SO unknown
3723N_LSYM C_LSYM
3724N_DECL (0x8c) C_DECL
3725N_BINCL unknown
3726N_SOL unknown
3727N_PSYM C_PSYM
3728N_EINCL unknown
3729N_ENTRY C_ENTRY
3730N_LBRAC unknown
3731N_EXCL unknown
3732N_SCOPE unknown
3733N_RBRAC unknown
3734N_BCOMM C_BCOMM
3735N_ECOMM C_ECOMM
3736N_ECOML C_ECOML
3737
3738N_LENG unknown
e505224d
PB
3739@end example
3740
899bafeb 3741@node Sun-differences
e505224d
PB
3742@appendix Differences between GNU stabs and Sun native stabs.
3743
497e44a5
JK
3744@c FIXME: Merge all this stuff into the main body of the document.
3745
e505224d
PB
3746@itemize @bullet
3747@item
612dbd4c 3748GNU C stabs define *all* types, file or procedure scope, as
e505224d
PB
3749N_LSYM. Sun doc talks about using N_GSYM too.
3750
e505224d
PB
3751@item
3752Sun C stabs use type number pairs in the format (a,b) where a is a
3753number starting with 1 and incremented for each sub-source file in the
3754compilation. b is a number starting with 1 and incremented for each
612dbd4c 3755new type defined in the compilation. GNU C stabs use the type number
e505224d
PB
3756alone, with no source file number.
3757@end itemize
3758
807e8368 3759@node Stabs-in-elf
cc4fb848
FF
3760@appendix Using stabs with the ELF object file format.
3761
3762The ELF object file format allows tools to create object files with custom
3763sections containing any arbitrary data. To use stabs in ELF object files,
3764the tools create two custom sections, a ".stab" section which contains
3765an array of fixed length structures, one struct per stab, and a ".stabstr"
3766section containing all the variable length strings that are referenced by
5e27ed65
FF
3767stabs in the ".stab" section. The byte order of the stabs binary data
3768matches the byte order of the ELF file itself, as determined from the
3769EI_DATA field in the e_ident member of the ELF header.
cc4fb848
FF
3770
3771The first stab in the ".stab" section for each object file is a "synthetic
3772stab", generated entirely by the assembler, with no corresponding ".stab"
3773directive as input to the assembler. This stab contains the following
3774fields:
3775
3776@itemize @bullet
3777@item
3778Offset in the ".stabstr" section to the source filename.
3779
3780@item
3781N_UNDF
3782
3783@item
3784Unused field, always zero.
3785
3786@item
3787Count of upcoming symbols. I.E. the number of remaining stabs for this
3788object module.
3789
3790@item
3791Size of the string table fragment associated with this object module, in
3792bytes.
3793
3794@end itemize
3795
3796The ".stabstr" section always starts with a null byte (so that string
3797offsets of zero reference a null string), followed by random length strings,
3798each of which is null byte terminated.
3799
3800The ELF section header for the ".stab" section has it's sh_link member set
3801to the section number of the ".stabstr" section, and the ".stabstr" section
3802has it's ELF section header sh_type member set to SHT_STRTAB to mark it as
3803a string table.
3804
e505224d
PB
3805@contents
3806@bye
This page took 0.248235 seconds and 4 git commands to generate.