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