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