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