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