2 @setfilename stabs.info
9 * Stabs:: The "stabs" debugging information format.
15 This document describes the stabs debugging symbol tables.
17 Copyright 1992, 1993 Free Software Foundation, Inc.
18 Contributed by Cygnus Support. Written by Julia Menapace.
20 Permission is granted to make and distribute verbatim copies of
21 this manual provided the copyright notice and this permission notice
22 are preserved on all copies.
25 Permission is granted to process this file through Tex and print the
26 results, provided the printed document carries copying permission
27 notice identical to this one except for the removal of this paragraph
28 (this paragraph not being relevant to the printed manual).
31 Permission is granted to copy or distribute modified versions of this
32 manual under the terms of the GPL (for which purpose this text may be
33 regarded as a program in the language TeX).
36 @setchapternewpage odd
39 @title The ``stabs'' debug format
40 @author Julia Menapace, Jim Kingdon, David MacKenzie
41 @author Cygnus Support
44 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
45 \xdef\manvers{\$Revision$} % For use in headers, footers too
47 \hfill Cygnus Support\par
49 \hfill \TeX{}info \texinfoversion\par
53 @vskip 0pt plus 1filll
54 Copyright @copyright{} 1992, 1993 Free Software Foundation, Inc.
55 Contributed by Cygnus Support.
57 Permission is granted to make and distribute verbatim copies of
58 this manual provided the copyright notice and this permission notice
59 are preserved on all copies.
65 @top The "stabs" representation of debugging information
67 This document describes the stabs debugging format.
70 * Overview:: Overview of stabs
71 * Program structure:: Encoding of the structure of the program
72 * Constants:: Constants
73 * Example:: A comprehensive example in C
75 * Types:: Type definitions
76 * Symbol Tables:: Symbol information in symbol tables
77 * Cplusplus:: Appendixes:
78 * Example2.c:: Source code for extended example
79 * Example2.s:: Assembly code for extended example
80 * Stab Types:: Symbol types in a.out files
81 * Symbol Descriptors:: Table of Symbol Descriptors
82 * Type Descriptors:: Table of Symbol Descriptors
83 * Expanded reference:: Reference information by stab type
84 * Questions:: Questions and anomolies
85 * XCOFF-differences:: Differences between GNU stabs in a.out
86 and GNU stabs in XCOFF
87 * Sun-differences:: Differences between GNU stabs and Sun
89 * Stabs-in-ELF:: Stabs in an ELF file.
95 @chapter Overview of stabs
97 @dfn{Stabs} refers to a format for information that describes a program
98 to a debugger. This format was apparently invented by
99 @c FIXME! <<name of inventor>> at
100 the University of California at Berkeley, for the @code{pdx} Pascal
101 debugger; the format has spread widely since then.
103 This document is one of the few published sources of documentation on
104 stabs. It is believed to be comprehensive for stabs used by C. The
105 lists of symbol descriptors (@pxref{Symbol Descriptors}) and type
106 descriptors (@pxref{Type Descriptors}) are believed to be completely
107 comprehensive. Stabs for COBOL-specific features and for variant
108 records (used by Pascal and Modula-2) are poorly documented here.
110 Other sources of information on stabs are @cite{Dbx and Dbxtool
111 Interfaces}, 2nd edition, by Sun, 1988, and @cite{AIX Version 3.2 Files
112 Reference}, Fourth Edition, September 1992, "dbx Stabstring Grammar" in
113 the a.out section, page 2-31. This document is believed to incorporate
114 the information from those two sources except where it explictly directs
115 you to them for more information.
118 * Flow:: Overview of debugging information flow
119 * Stabs Format:: Overview of stab format
120 * String Field:: The @code{.stabs} @var{string} field
121 * C example:: A simple example in C source
122 * Assembly code:: The simple example at the assembly level
126 @section Overview of debugging information flow
128 The GNU C compiler compiles C source in a @file{.c} file into assembly
129 language in a @file{.s} file, which the assembler translates into
130 a @file{.o} file, which the linker combines with other @file{.o} files and
131 libraries to produce an executable file.
133 With the @samp{-g} option, GCC puts in the @file{.s} file additional
134 debugging information, which is slightly transformed by the assembler
135 and linker, and carried through into the final executable. This
136 debugging information describes features of the source file like line
137 numbers, the types and scopes of variables, and function names,
138 parameters, and scopes.
140 For some object file formats, the debugging information is encapsulated
141 in assembler directives known collectively as @dfn{stab} (symbol table)
142 directives, which are interspersed with the generated code. Stabs are
143 the native format for debugging information in the a.out and XCOFF
144 object file formats. The GNU tools can also emit stabs in the COFF and
145 ECOFF object file formats.
147 The assembler adds the information from stabs to the symbol information
148 it places by default in the symbol table and the string table of the
149 @file{.o} file it is building. The linker consolidates the @file{.o}
150 files into one executable file, with one symbol table and one string
151 table. Debuggers use the symbol and string tables in the executable as
152 a source of debugging information about the program.
155 @section Overview of stab format
157 There are three overall formats for stab assembler directives,
158 differentiated by the first word of the stab. The name of the directive
159 describes which combination of four possible data fields follows. It is
160 either @code{.stabs} (string), @code{.stabn} (number), or @code{.stabd}
161 (dot). IBM's XCOFF assembler uses @code{.stabx} (and some other
162 directives such as @code{.file} and @code{.bi}) instead of
163 @code{.stabs}, @code{.stabn} or @code{.stabd}.
165 The overall format of each class of stab is:
168 .stabs "@var{string}",@var{type},0,@var{desc},@var{value}
169 .stabn @var{type},0,@var{desc},@var{value}
170 .stabd @var{type},0,@var{desc}
171 .stabx "@var{string}",@var{value},@var{type},@var{sdb-type}
174 @c what is the correct term for "current file location"? My AIX
175 @c assembler manual calls it "the value of the current location counter".
176 For @code{.stabn} and @code{.stabd}, there is no @var{string} (the
177 @code{n_strx} field is zero; see @xref{Symbol Tables}). For
178 @code{.stabd}, the @var{value} field is implicit and has the value of
179 the current file location. For @code{.stabx}, the @var{sdb-type} field
180 is unused for stabs and can always be set to 0.
182 The number in the @var{type} field gives some basic information about
183 which type of stab this is (or whether it @emph{is} a stab, as opposed
184 to an ordinary symbol). Each valid type number defines a different stab
185 type. Further, the stab type defines the exact interpretation of, and
186 possible values for, any remaining @var{string}, @var{desc}, or
187 @var{value} fields present in the stab. @xref{Stab Types}, for a list
188 in numeric order of the valid type field values for stab directives.
191 @section The @code{.stabs} @var{string} field
193 For @code{.stabs} the @var{string} field holds the meat of the
194 debugging information. The generally unstructured nature of this field
195 is what makes stabs extensible. For some stab types the string field
196 contains only a name. For other stab types the contents can be a great
199 The overall format is of the @var{string} field is:
202 "@var{name}:@var{symbol-descriptor} @var{type-information}"
205 @var{name} is the name of the symbol represented by the stab.
206 @var{name} can be omitted, which means the stab represents an unnamed
207 object. For example, @samp{:t10=*2} defines type 10 as a pointer to
208 type 2, but does not give the type a name. Omitting the @var{name}
209 field is supported by AIX dbx and GDB after about version 4.8, but not
210 other debuggers. GCC sometimes uses a single space as the name instead
211 of omitting the name altogether; apparently that is supported by most
214 The @var{symbol_descriptor} following the @samp{:} is an alphabetic
215 character that tells more specifically what kind of symbol the stab
216 represents. If the @var{symbol_descriptor} is omitted, but type
217 information follows, then the stab represents a local variable. For a
218 list of symbol descriptors, see @ref{Symbol Descriptors}. The @samp{c}
219 symbol descriptor is an exception in that it is not followed by type
220 information. @xref{Constants}.
222 @var{type-information} is either a @var{type_number}, or
223 @samp{@var{type_number}=}. The @var{type_number} alone is a type
224 reference, referring directly to a type that has already been defined.
226 The @samp{@var{type_number}=} form is a type definition, where the
227 number represents a new type which is about to be defined. The type
228 definition may refer to other types by number, and those type numbers
229 may be followed by @samp{=} and nested definitions.
231 In a type definition, if the character that follows the equals sign is
232 non-numeric then it is a @var{type_descriptor}, and tells what kind of
233 type is about to be defined. Any other values following the
234 @var{type_descriptor} vary, depending on the @var{type_descriptor}. If
235 a number follows the @samp{=} then the number is a @var{type_reference}.
236 For a full description of types, @ref{Types}. @xref{Type
237 Descriptors}, for a list of
238 @var{type_descriptor} values.
240 There is an AIX extension for type attributes. Following the @samp{=}
241 is any number of type attributes. Each one starts with @samp{@@} and
242 ends with @samp{;}. Debuggers, including AIX's dbx and GDB 4.10, skip
243 any type attributes they do not recognize. GDB 4.9 and other versions
244 of dbx may not do this. Because of a conflict with C++
245 (@pxref{Cplusplus}), new attributes should not be defined which begin
246 with a digit, @samp{(}, or @samp{-}; GDB may be unable to distinguish
247 those from the C++ type descriptor @samp{@@}. The attributes are:
250 @item a@var{boundary}
251 @var{boundary} is an integer specifying the alignment. I assume it
252 applies to all variables of this type.
255 Size in bits of a variable of this type.
258 Pointer class (for checking). Not sure what this means, or how
259 @var{integer} is interpreted.
262 Indicate this is a packed type, meaning that structure fields or array
263 elements are placed more closely in memory, to save memory at the
267 All this can make the @var{string} field quite long. All
268 versions of GDB, and some versions of dbx, can handle arbitrarily long
269 strings. But many versions of dbx cretinously limit the strings to
270 about 80 characters, so compilers which must work with such dbx's need
271 to split the @code{.stabs} directive into several @code{.stabs}
272 directives. Each stab duplicates exactly all but the
273 @var{string} field. The @var{string} field of
274 every stab except the last is marked as continued with a
275 double-backslash at the end. Removing the backslashes and concatenating
276 the @var{string} fields of each stab produces the original,
280 @section A simple example in C source
282 To get the flavor of how stabs describe source information for a C
283 program, let's look at the simple program:
288 printf("Hello world");
292 When compiled with @samp{-g}, the program above yields the following
293 @file{.s} file. Line numbers have been added to make it easier to refer
294 to parts of the @file{.s} file in the description of the stabs that
298 @section The simple example at the assembly level
300 This simple ``hello world'' example demonstrates several of the stab
301 types used to describe C language source files.
305 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
306 3 .stabs "hello.c",100,0,0,Ltext0
309 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
310 7 .stabs "char:t2=r2;0;127;",128,0,0,0
311 8 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
312 9 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
313 10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
314 11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
315 12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
316 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
317 14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
318 15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
319 16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
320 17 .stabs "float:t12=r1;4;0;",128,0,0,0
321 18 .stabs "double:t13=r1;8;0;",128,0,0,0
322 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
323 20 .stabs "void:t15=15",128,0,0,0
326 23 .ascii "Hello, world!\12\0"
341 38 sethi %hi(LC0),%o1
342 39 or %o1,%lo(LC0),%o0
353 50 .stabs "main:F1",36,0,0,_main
354 51 .stabn 192,0,0,LBB2
355 52 .stabn 224,0,0,LBE2
358 @node Program structure
359 @chapter Encoding for the structure of the program
362 * Main Program:: Indicate what the main program is
363 * Source Files:: The path and name of the source file
364 * Include Files:: Names of include files
371 @section Main Program
373 Most languages allow the main program to have any name. The
374 @code{N_MAIN} stab type is used for a stab telling the debugger what
375 name is used in this program. Only the name is significant; it will be
376 the name of a function which is the main program. Most C compilers do
377 not use this stab; they expect the debugger to simply assume that the
378 name is @samp{main}, but some C compilers emit an @code{N_MAIN} stab for
379 the @samp{main} function.
382 @section Paths and names of the source files
384 Before any other stabs occur, there must be a stab specifying the source
385 file. This information is contained in a symbol of stab type
386 @code{N_SO}; the string contains the name of the file. The value of the
387 symbol is the start address of portion of the text section corresponding
390 With the Sun Solaris2 compiler, the @code{desc} field contains a
391 source-language code.
393 Some compilers (for example, GCC2 and SunOS4 @file{/bin/cc}) also
394 include the directory in which the source was compiled, in a second
395 @code{N_SO} symbol preceding the one containing the file name. This
396 symbol can be distinguished by the fact that it ends in a slash. Code
397 from the cfront C++ compiler can have additional @code{N_SO} symbols for
398 nonexistent source files after the @code{N_SO} for the real source file;
399 these are believed to contain no useful information.
404 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0 # @r{100 is N_SO}
405 .stabs "hello.c",100,0,0,Ltext0
410 Instead of @code{N_SO} symbols, XCOFF uses a @code{.file} assembler
411 directive which assembles to a standard COFF @code{.file} symbol;
412 explaining this in detail is outside the scope of this document.
415 @section Names of include files
417 There are several different schemes for dealing with include files: the
418 traditional @code{N_SOL} approach, Sun's @code{N_BINCL} approach, and the
419 XCOFF @code{C_BINCL} approach (which despite the similar name has little in
420 common with @code{N_BINCL}).
422 An @code{N_SOL} symbol specifies which include file subsequent symbols
423 refer to. The string field is the name of the file and the value is the
424 text address corresponding to the start of the previous include file and
425 the start of this one. To specify the main source file again, use an
426 @code{N_SOL} symbol with the name of the main source file.
428 A @code{N_BINCL} symbol specifies the start of an include file. In an
429 object file, only the name is significant. The Sun linker puts data
430 into some of the other fields. The end of the include file is marked by
431 a @code{N_EINCL} symbol (which has no name field). In an ojbect file,
432 there is no significant data in the @code{N_EINCL} symbol; the Sun
433 linker puts data into some of the fields. @code{N_BINCL} and
434 @code{N_EINCL} can be nested. If the linker detects that two source
435 files have identical stabs with a @code{N_BINCL} and @code{N_EINCL} pair
436 (as will generally be the case for a header file), then it only puts out
437 the stabs once. Each additional occurance is replaced by an
438 @code{N_EXCL} symbol. I believe the Sun (SunOS4, not sure about
439 Solaris) linker is the only one which supports this feature.
441 For the start of an include file in XCOFF, use the @file{.bi} assembler
442 directive, which generates a @code{C_BINCL} symbol. A @file{.ei}
443 directive, which generates a @code{C_EINCL} symbol, denotes the end of
444 the include file. Both directives are followed by the name of the
445 source file in quotes, which becomes the string for the symbol. The
446 value of each symbol, produced automatically by the assembler and
447 linker, is an offset into the executable which points to the beginning
448 (inclusive, as you'd expect) and end (inclusive, as you would not
449 expect) of the portion of the COFF linetable which corresponds to this
450 include file. @code{C_BINCL} and @code{C_EINCL} do not nest.
453 @section Line Numbers
455 A @code{N_SLINE} symbol represents the start of a source line. The
456 @var{desc} field contains the line number and the @var{value} field
457 contains the code address for the start of that source line. On most
458 machines the address is absolute; for Sun's stabs-in-ELF, it is relative
459 to the function in which the @code{N_SLINE} symbol occurs.
461 GNU documents @code{N_DSLINE} and @code{N_BSLINE} symbols for line
462 numbers in the data or bss segments, respectively. They are identical
463 to @code{N_SLINE} but are relocated differently by the linker. They
464 were intended to be used to describe the source location of a variable
465 declaration, but I believe that GCC2 actually puts the line number in
466 the desc field of the stab for the variable itself. GDB has been
467 ignoring these symbols (unless they contain a string field) at least
470 XCOFF uses COFF line numbers instead, which are outside the scope of
471 this document, ammeliorated by adequate marking of include files
472 (@pxref{Include Files}).
474 For single source lines that generate discontiguous code, such as flow
475 of control statements, there may be more than one line number entry for
476 the same source line. In this case there is a line number entry at the
477 start of each code range, each with the same line number.
482 All of the following stabs use the @code{N_FUN} symbol type.
484 A function is represented by an @samp{F} symbol descriptor for a global
485 (extern) function, and @samp{f} for a static (local) function. The next
486 @code{N_SLINE} symbol can be used to find the line number of the start
487 of the function. The value field is the address of the start of the
488 function (absolute for @code{a.out}; relative to the start of the file
489 for Sun's stabs-in-ELF). The type information of the stab represents
490 the return type of the function; thus @samp{foo:f5} means that foo is a
491 function returning type 5.
493 The type information of the stab is optionally followed by type
494 information for each argument, with each argument preceded by @samp{;}.
495 An argument type of 0 means that additional arguments are being passed,
496 whose types and number may vary (@samp{...} in ANSI C). This extension
497 is used by Sun's Solaris compiler. GDB has tolerated it (i.e., at least
498 parsed the syntax, if not necessarily used the information) at least
499 since version 4.8; I don't know whether all versions of dbx will
500 tolerate it. The argument types given here are not redundant
501 with the symbols for the arguments themselves (@pxref{Parameters}), they
502 are the types of the arguments as they are passed, before any
503 conversions might take place. For example, if a C function which is
504 declared without a prototype takes a @code{float} argument, the value is
505 passed as a @code{double} but then converted to a @code{float}.
506 Debuggers need to use the types given in the arguments when printing
507 values, but if calling the function they need to use the types given in
508 the symbol defining the function.
510 If the return type and types of arguments of a function which is defined
511 in another source file are specified (i.e., a function prototype in ANSI
512 C), traditionally compilers emit no stab; the only way for the debugger
513 to find the information is if the source file where the function is
514 defined was also compiled with debugging symbols. As an extension the
515 Solaris compiler uses symbol descriptor @samp{P} followed by the return
516 type of the function, followed by the arguments, each preceded by
517 @samp{;}, as in a stab with symbol descriptor @samp{f} or @samp{F}.
518 This use of symbol descriptor @samp{P} can be distinguished from its use
519 for register parameters (@pxref{Parameters}) by the fact that it has
520 symbol type @code{N_FUN}.
522 The AIX documentation also defines symbol descriptor @samp{J} as an
523 internal function. I assume this means a function nested within another
524 function. It also says symbol descriptor @samp{m} is a module in
525 Modula-2 or extended Pascal.
527 Procedures (functions which do not return values) are represented as
528 functions returning the @code{void} type in C. I don't see why this couldn't
529 be used for all languages (inventing a @code{void} type for this purpose if
530 necessary), but the AIX documentation defines @samp{I}, @samp{P}, and
531 @samp{Q} for internal, global, and static procedures, respectively.
532 These symbol descriptors are unusual in that they are not followed by
535 For any of the above symbol descriptors, after the symbol descriptor and
536 the type information, there is optionally a comma, followed by the name
537 of the procedure, followed by a comma, followed by a name specifying the
538 scope. The first name is local to the scope specified, and seems to be
539 redundant with the name of the symbol (before the @samp{:}). The name
540 specifying the scope is the name of a procedure specifying that scope.
541 This feature is used by GCC, and presumably Pascal, Modula-2, etc.,
542 compilers, for nested functions.
544 If procedures are nested more than one level deep, only the immediately
545 containing scope is specified, for example:
557 return baz (x + 2 * y);
559 return x + bar (3 * x);
567 .stabs "baz:f1,baz,bar",36,0,0,_baz.15 # @r{36 is N_FUN}
568 .stabs "bar:f1,bar,foo",36,0,0,_bar.12
569 .stabs "foo:F1",36,0,0,_foo
572 The stab representing a procedure is located immediately following the
573 code of the procedure. This stab is in turn directly followed by a
574 group of other stabs describing elements of the procedure. These other
575 stabs describe the procedure's parameters, its block local variables, and
578 Going back to our ``hello world'' example program,
586 The @code{.stabs} entry after this code fragment shows the @var{name} of
587 the procedure (@code{main}); the type descriptor @var{desc} (@code{F},
588 for a global procedure); a reference to the predefined type @code{int}
589 for the return type; and the starting @var{address} of the procedure.
591 Here is an exploded summary (with whitespace introduced for clarity),
592 followed by line 50 of our sample assembly output, which has this form:
596 @var{desc} @r{(global proc @samp{F})}
597 @var{return_type_ref} @r{(int)}
603 50 .stabs "main:F1",36,0,0,_main
606 @node Block Structure
607 @section Block Structure
609 The program's block structure is represented by the @code{N_LBRAC} (left
610 brace) and the @code{N_RBRAC} (right brace) stab types. The variables
611 defined inside a block precede the @code{N_LBRAC} symbol for most
612 compilers, including GCC. Other compilers, such as the Convex, Acorn
613 RISC machine, and Sun @code{acc} compilers, put the variables after the
614 @code{N_LBRAC} symbol. The values of the @code{N_LBRAC} and
615 @code{N_RBRAC} symbols are the start and end addresses of the code of
616 the block, respectively. For most machines, they are relative to the
617 starting address of this source file. For the Gould NP1, they are
618 absolute. For Sun's stabs-in-ELF, they are relative to the function in
621 The @code{N_LBRAC} and @code{N_RBRAC} stabs that describe the block
622 scope of a procedure are located after the @code{N_FUN} stab that
623 represents the procedure itself.
625 Sun documents the @code{desc} field of @code{N_LBRAC} and
626 @code{N_RBRAC} symbols as containing the nesting level of the block.
627 However, dbx seems not to care, and GCC always sets @code{desc} to
633 The @samp{c} symbol descriptor indicates that this stab represents a
634 constant. This symbol descriptor is an exception to the general rule
635 that symbol descriptors are followed by type information. Instead, it
636 is followed by @samp{=} and one of the following:
640 Boolean constant. @var{value} is a numeric value; I assume it is 0 for
644 Character constant. @var{value} is the numeric value of the constant.
646 @item e @var{type-information} , @var{value}
647 Constant whose value can be represented as integral.
648 @var{type-information} is the type of the constant, as it would appear
649 after a symbol descriptor (@pxref{String Field}). @var{value} is the
650 numeric value of the constant. GDB 4.9 does not actually get the right
651 value if @var{value} does not fit in a host @code{int}, but it does not
652 do anything violent, and future debuggers could be extended to accept
653 integers of any size (whether unsigned or not). This constant type is
654 usually documented as being only for enumeration constants, but GDB has
655 never imposed that restriction; I don't know about other debuggers.
658 Integer constant. @var{value} is the numeric value. The type is some
659 sort of generic integer type (for GDB, a host @code{int}); to specify
660 the type explicitly, use @samp{e} instead.
663 Real constant. @var{value} is the real value, which can be @samp{INF}
664 (optionally preceded by a sign) for infinity, @samp{QNAN} for a quiet
665 NaN (not-a-number), or @samp{SNAN} for a signalling NaN. If it is a
666 normal number the format is that accepted by the C library function
670 String constant. @var{string} is a string enclosed in either @samp{'}
671 (in which case @samp{'} characters within the string are represented as
672 @samp{\'} or @samp{"} (in which case @samp{"} characters within the
673 string are represented as @samp{\"}).
675 @item S @var{type-information} , @var{elements} , @var{bits} , @var{pattern}
676 Set constant. @var{type-information} is the type of the constant, as it
677 would appear after a symbol descriptor (@pxref{String Field}).
678 @var{elements} is the number of elements in the set (Does this means
679 how many bits of @var{pattern} are actually used, which would be
680 redundant with the type, or perhaps the number of bits set in
681 @var{pattern}? I don't get it), @var{bits} is the number of bits in the
682 constant (meaning it specifies the length of @var{pattern}, I think),
683 and @var{pattern} is a hexadecimal representation of the set. AIX
684 documentation refers to a limit of 32 bytes, but I see no reason why
685 this limit should exist. This form could probably be used for arbitrary
686 constants, not just sets; the only catch is that @var{pattern} should be
687 understood to be target, not host, byte order and format.
690 The boolean, character, string, and set constants are not supported by
691 GDB 4.9, but it will ignore them. GDB 4.8 and earlier gave an error
692 message and refused to read symbols from the file containing the
695 This information is followed by @samp{;}.
698 @chapter A Comprehensive Example in C
700 To describe the other stab types,
701 we'll examine a second program, @code{example2}, which builds on the
702 first example to introduce the rest of the stab types, symbol
703 descriptors, and type descriptors used in C.
704 @xref{Example2.c} for the complete @file{.c} source,
705 and @pxref{Example2.s} for the @file{.s} assembly code.
706 This description includes parts of those files.
708 @section Flow of control and nested scopes
714 @code{N_SLINE}, @code{N_LBRAC}, @code{N_RBRAC} (cont.)
717 Consider the body of @code{main}, from @file{example2.c}. It shows more
718 about how @code{N_SLINE}, @code{N_RBRAC}, and @code{N_LBRAC} stabs are used.
722 21 static float s_flap;
724 23 for (times=0; times < s_g_repeat; times++)@{
726 25 printf ("Hello world\n");
731 Here we have a single source line, the @code{for} line, that generates
732 non-linear flow of control, and non-contiguous code. In this case, an
733 @code{N_SLINE} stab with the same line number proceeds each block of
734 non-contiguous code generated from the same source line.
736 The example also shows nested scopes. The @code{N_LBRAC} and
737 @code{N_LBRAC} stabs that describe block structure are nested in the
738 same order as the corresponding code blocks, those of the for loop
739 inside those for the body of main.
742 This is the label for the @code{N_LBRAC} (left brace) stab marking the
743 start of @code{main}.
750 In the first code range for C source line 23, the @code{for} loop
751 initialize and test, @code{N_SLINE} (68) records the line number:
758 58 .stabn 68,0,23,LM2
762 62 sethi %hi(_s_g_repeat),%o0
764 64 ld [%o0+%lo(_s_g_repeat)],%o0
769 @exdent label for the @code{N_LBRAC} (start block) marking the start of @code{for} loop
772 69 .stabn 68,0,25,LM3
774 71 sethi %hi(LC0),%o1
775 72 or %o1,%lo(LC0),%o0
778 75 .stabn 68,0,26,LM4
781 @exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
787 Now we come to the second code range for source line 23, the @code{for}
788 loop increment and return. Once again, @code{N_SLINE} (68) records the
792 .stabn, N_SLINE, NIL,
796 78 .stabn 68,0,23,LM5
804 86 .stabn 68,0,27,LM6
807 @exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
810 89 .stabn 68,0,27,LM7
815 94 .stabs "main:F1",36,0,0,_main
816 95 .stabs "argc:p1",160,0,0,68
817 96 .stabs "argv:p20=*21=*2",160,0,0,72
818 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
819 98 .stabs "times:1",128,0,0,-20
823 Here is an illustration of stabs describing nested scopes. The scope
824 nesting is reflected in the nested bracketing stabs (@code{N_LBRAC},
828 .stabn N_LBRAC,NIL,NIL,
829 @var{block-start-address}
831 99 .stabn 192,0,0,LBB2 ## begin proc label
832 100 .stabs "inner:1",128,0,0,-24
833 101 .stabn 192,0,0,LBB3 ## begin for label
837 @code{N_RBRAC} (224), ``right brace'' ends a lexical block (scope).
840 .stabn N_RBRAC,NIL,NIL,
841 @var{block-end-address}
843 102 .stabn 224,0,0,LBE3 ## end for label
844 103 .stabn 224,0,0,LBE2 ## end proc label
851 * Stack Variables:: Variables allocated on the stack.
852 * Global Variables:: Variables used by more than one source file.
853 * Register variables:: Variables in registers.
854 * Common Blocks:: Variables statically allocated together.
855 * Statics:: Variables local to one source file.
856 * Parameters:: Variables for arguments to functions.
859 @node Stack Variables
860 @section Automatic Variables Allocated on the Stack
862 If a variable is declared whose scope is local to a function and whose
863 lifetime is only as long as that function executes (C calls such
864 variables automatic), they can be allocated in a register
865 (@pxref{Register variables}) or on the stack.
867 For variables allocated on the stack, each variable has a stab with the
868 symbol descriptor omitted. Since type information should being with a
869 digit, @samp{-}, or @samp{(}, only digits, @samp{-}, and @samp{(} are
870 precluded from being used for symbol descriptors by this fact. However,
871 the Acorn RISC machine (ARM) is said to get this wrong: it puts out a
872 mere type definition here, without the preceding
873 @code{@var{typenumber}=}. This is a bad idea; there is no guarantee
874 that type descriptors are distinct from symbol descriptors.
876 These stabs have the @code{N_LSYM} stab type. The value of the stab is
877 the offset of the variable within the local variables. On most machines
878 this is an offset from the frame pointer and is negative. The location
879 of the stab specifies what block it is defined in; see @ref{Block
882 For example, the following C code
892 produces the following stabs
895 .stabs "main:F1",36,0,0,_main # @r{36 is N_FUN}
896 .stabs "x:1",128,0,0,-12 # @r{128 is N_LSYM}
897 .stabn 192,0,0,LBB2 # @r{192 is N_LBRAC}
898 .stabn 224,0,0,LBE2 # @r{224 is N_RBRAC}
901 @xref{Procedures} for more information on the first stab, and @ref{Block
902 Structure} for more information on the @code{N_LBRAC} and @code{N_RBRAC}
905 @node Global Variables
906 @section Global Variables
908 A variable whose scope which is not specific to just one source file is
909 represented by the @samp{G} symbol descriptor. These stabs use the
910 @code{N_GSYM} stab type. The type information for the stab
911 (@pxref{String Field}) gives the type of the variable.
913 For example, the following source code:
920 yields the following assembly code:
923 .stabs "g_foo:G2",32,0,0,0 # @r{32 is N_GSYM}
930 The address of the variable represented by the @code{N_GSYM} is not
931 contained in the @code{N_GSYM} stab. The debugger gets this information
932 from the external symbol for the global variable. In the example above,
933 the @code{.global _g_foo} and @code{_g_foo:} lines tell the assembler to
934 produce an external symbol.
936 @node Register variables
937 @section Register variables
939 @c According to an old version of this manual, AIX uses C_RPSYM instead
940 @c of C_RSYM. I am skeptical; this should be verified.
941 Register variables have their own stab type, @code{N_RSYM}, and their
942 own symbol descriptor, @samp{r}. The stab's value field contains the
943 number of the register where the variable data will be stored.
945 The value is the register number.
947 AIX defines a separate symbol descriptor @samp{d} for floating point
948 registers. This seems unnecessary; why not just just give floating
949 point registers different register numbers? I have not verified whether
950 the compiler actually uses @samp{d}.
952 If the register is explicitly allocated to a global variable, but not
956 register int g_bar asm ("%g5");
959 the stab may be emitted at the end of the object file, with
960 the other bss symbols.
963 @section Common Blocks
965 A common block is a statically allocated section of memory which can be
966 referred to by several source files. It may contain several variables.
967 I believe Fortran is the only language with this feature. A
968 @code{N_BCOMM} stab begins a common block and an @code{N_ECOMM} stab
969 ends it. The only thing which is significant about these two stabs is
970 their name, which can be used to look up a normal (non-debugging) symbol
971 which gives the address of the common block. Then each stab between the
972 @code{N_BCOMM} and the @code{N_ECOMM} specifies a member of that common
973 block; its value is the offset within the common block of that variable.
974 The @code{N_ECOML} stab type is documented for this purpose, but Sun's
975 Fortran compiler uses @code{N_GSYM} instead. The test case I
976 looked at had a common block local to a function and it used the
977 @samp{V} symbol descriptor; I assume one would use @samp{S} if not local
978 to a function (that is, if a common block @emph{can} be anything other
979 than local to a function).
982 @section Static Variables
984 Initialized static variables are represented by the @samp{S} and
985 @samp{V} symbol descriptors. @samp{S} means file scope static, and
986 @samp{V} means procedure scope static.
988 @c This is probably not worth mentioning; it is only true on the sparc
989 @c for `double' variables which although declared const are actually in
990 @c the data segment (the text segment can't guarantee 8 byte alignment).
992 @c 2.4.5 has a bug in that it uses @code{N_FUN}, so neither dbx nor GDB can
993 @c find the variables)
994 In a.out files, @code{N_STSYM} means the data segment, @code{N_FUN}
995 means the text segment, and @code{N_LCSYM} means the bss segment.
997 In XCOFF files, each symbol has a section number, so the stab type
998 need not indicate the segment.
1000 In ECOFF files, the storage class is used to specify the section, so the
1001 stab type need not indicate the segment.
1003 @c In ELF files, it apparently is a big mess. See kludge in dbxread.c
1004 @c in GDB. FIXME: Investigate where this kludge comes from.
1006 @c This is the place to mention N_ROSYM; I'd rather do so once I can
1007 @c coherently explain how this stuff works for stabs-in-ELF.
1009 For example, the source lines
1012 static const int var_const = 5;
1013 static int var_init = 2;
1014 static int var_noinit;
1018 yield the following stabs:
1021 .stabs "var_const:S1",36,0,0,_var_const # @r{36 is N_FUN}
1023 .stabs "var_init:S1",38,0,0,_var_init # @r{38 is N_STSYM}
1025 .stabs "var_noinit:S1",40,0,0,_var_noinit # @r{40 is N_LCSYM}
1031 Parameters to a function are represented by a stab (or sometimes two,
1032 see below) for each parameter. The stabs are in the order in which the
1033 debugger should print the parameters (i.e., the order in which the
1034 parameters are declared in the source file). The exact form of the stab
1035 depends on how the parameter is being passed.
1037 Parameters passed on the stack use the symbol descriptor @samp{p}, and
1038 the @code{N_PSYM} symbol type. The value of the symbol is an offset
1039 used to locate the parameter on the stack; its exact meaning is
1040 machine-dependent but on most machines it is an offset from the frame
1043 If the parameter is passed in a register, then the traditional way to do
1044 this is to provide two symbols for each argument:
1047 .stabs "arg:p1" . . . ; N_PSYM
1048 .stabs "arg:r1" . . . ; N_RSYM
1051 Debuggers are expected to use the second one to find the value, and the
1052 first one to know that it is an argument.
1054 Because this is kind of ugly, some compilers use symbol descriptor
1055 @samp{P} or @samp{R} to indicate an argument which is in a register.
1056 The symbol value is the register number. @samp{P} and @samp{R} mean the
1057 same thing, the difference is that @samp{P} is a GNU invention and
1058 @samp{R} is an IBM (XCOFF) invention. As of version 4.9, GDB should
1059 handle either one. Symbol type @code{C_RPSYM} is used with @samp{R} and
1060 @code{N_RSYM} is used with @samp{P}.
1062 According to the AIX documentation symbol descriptor @samp{D} is for a
1063 parameter passed in a floating point register. This seems
1064 unnecessary---why not just use @samp{R} with a register number which
1065 indicates that it's a floating point register? I haven't verified
1066 whether the system actually does what the documentation indicates.
1068 There is at least one case where GCC uses a @samp{p} and @samp{r} pair
1069 rather than @samp{P}; this is where the argument is passed in the
1070 argument list and then loaded into a register.
1072 On the sparc and hppa, for a @samp{P} symbol whose type is a structure
1073 or union, the register contains the address of the structure. On the
1074 sparc, this is also true of a @samp{p} and @samp{r} pair (using Sun cc) or a
1075 @samp{p} symbol. However, if a (small) structure is really in a
1076 register, @samp{r} is used. And, to top it all off, on the hppa it
1077 might be a structure which was passed on the stack and loaded into a
1078 register and for which there is a @samp{p} and @samp{r} pair! I believe
1079 that symbol descriptor @samp{i} is supposed to deal with this case, (it
1080 is said to mean "value parameter by reference, indirect access", I don't
1081 know the source for this information) but I don't know details or what
1082 compilers or debuggers use it, if any (not GDB or GCC). It is not clear
1083 to me whether this case needs to be dealt with differently than
1084 parameters passed by reference (see below).
1086 There is another case similar to an argument in a register, which is an
1087 argument which is actually stored as a local variable. Sometimes this
1088 happens when the argument was passed in a register and then the compiler
1089 stores it as a local variable. If possible, the compiler should claim
1090 that it's in a register, but this isn't always done. Some compilers use
1091 the pair of symbols approach described above (@samp{@var{arg}:p}
1092 followed by @samp{@var{arg}:}); this includes GCC1 (not GCC2) on the
1093 sparc when passing a small structure and GCC2 (sometimes) when the
1094 argument type is float and it is passed as a double and converted to
1095 float by the prologue (in the latter case the type of the
1096 @samp{@var{arg}:p} symbol is double and the type of the
1097 @samp{@var{arg}:} symbol is float). GCC, at least on the 960, uses a
1098 single @samp{p} symbol descriptor for an argument which is stored as a
1099 local variable but uses @code{N_LSYM} instead of @code{N_PSYM}. In this
1100 case the value of the symbol is an offset relative to the local
1101 variables for that function, not relative to the arguments (on some
1102 machines those are the same thing, but not on all).
1104 If the parameter is passed by reference (e.g., Pascal VAR parameters),
1105 then type symbol descriptor is @samp{v} if it is in the argument list,
1106 or @samp{a} if it in a register. Other than the fact that these contain
1107 the address of the parameter other than the parameter itself, they are
1108 identical to @samp{p} and @samp{R}, respectively. I believe @samp{a} is
1109 an AIX invention; @samp{v} is supported by all stabs-using systems as
1112 @c Is this paragraph correct? It is based on piecing together patchy
1113 @c information and some guesswork
1114 Conformant arrays refer to a feature of Modula-2, and perhaps other
1115 languages, in which the size of an array parameter is not known to the
1116 called function until run-time. Such parameters have two stabs, a
1117 @samp{x} for the array itself, and a @samp{C}, which represents the size
1118 of the array. The value of the @samp{x} stab is the offset in the
1119 argument list where the address of the array is stored (it this right?
1120 it is a guess); the value of the @samp{C} stab is the offset in the
1121 argument list where the size of the array (in elements? in bytes?) is
1124 The following are also said to go with @code{N_PSYM}:
1127 "name" -> "param_name:#type"
1129 -> pF Fortran function parameter
1130 -> X (function result variable)
1131 -> b (based variable)
1133 value -> offset from the argument pointer (positive).
1136 As a simple example, the code
1148 .stabs "main:F1",36,0,0,_main # @r{36 is N_FUN}
1149 .stabs "argc:p1",160,0,0,68 # @r{160 is N_PSYM}
1150 .stabs "argv:p20=*21=*2",160,0,0,72
1153 The type definition of argv is interesting because it contains several
1154 type definitions. Type 21 is pointer to type 2 (char) and argv (type 20) is
1158 @chapter Defining Types
1160 Now let's look at some variable definitions involving complex types.
1161 This involves understanding better how types are described. In the
1162 examples so far types have been described as references to previously
1163 defined types or defined in terms of subranges of or pointers to
1164 previously defined types. The section that follows discusses
1165 the other type descriptors that may follow the @samp{=} sign in a
1169 * Builtin types:: Integers, floating point, void, etc.
1170 * Miscellaneous Types:: Pointers, sets, files, etc.
1171 * Cross-references:: Referring to a type not yet defined.
1172 * Subranges:: A type with a specific range.
1173 * Arrays:: An aggregate type of same-typed elements.
1174 * Strings:: Like an array but also has a length.
1175 * Enumerations:: Like an integer but the values have names.
1176 * Structures:: An aggregate type of different-typed elements.
1177 * Typedefs:: Giving a type a name.
1178 * Unions:: Different types sharing storage.
1183 @section Builtin types
1185 Certain types are built in (@code{int}, @code{short}, @code{void},
1186 @code{float}, etc.); the debugger recognizes these types and knows how
1187 to handle them. Thus don't be surprised if some of the following ways
1188 of specifying builtin types do not specify everything that a debugger
1189 would need to know about the type---in some cases they merely specify
1190 enough information to distinguish the type from other types.
1192 The traditional way to define builtin types is convolunted, so new ways
1193 have been invented to describe them. Sun's @code{acc} uses special
1194 builtin type descriptors (@samp{b} and @samp{R}), and IBM uses negative
1195 type numbers. GDB can accept all three, as of version 4.8; dbx just
1196 accepts the traditional builtin types and perhaps one of the other two
1197 formats. The following sections describe each of these formats.
1200 * Traditional Builtin Types:: Put on your seatbelts and prepare for kludgery
1201 * Builtin Type Descriptors:: Builtin types with special type descriptors
1202 * Negative Type Numbers:: Builtin types using negative type numbers
1205 @node Traditional Builtin Types
1206 @subsection Traditional Builtin types
1208 Often types are defined as subranges of themselves. If the array bounds
1209 can fit within an @code{int}, then they are given normally. For example:
1212 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0 # @r{128 is N_LSYM}
1213 .stabs "char:t2=r2;0;127;",128,0,0,0
1216 Builtin types can also be described as subranges of @code{int}:
1219 .stabs "unsigned short:t6=r1;0;65535;",128,0,0,0
1222 If the lower bound of a subrange is 0 and the upper bound is -1, it
1223 means that the type is an unsigned integral type whose bounds are too
1224 big to describe in an int. Traditionally this is only used for
1225 @code{unsigned int} and @code{unsigned long}. For larger types, GCC
1226 2.4.5 puts out bounds in octal, with a leading 0. In this case a
1227 negative bound consists of a number which is a 1 bit followed by a bunch
1228 of 0 bits, and a positive bound is one in which a bunch of bits are 1.
1229 All known versions of dbx and GDB version 4 accept this, but GDB 3.5
1230 refuses to read the whole file containing such symbols. So GCC 2.3.3
1231 did not output the proper size for these types.
1233 @c FIXME: Update this for the 2.4.5 output, not 2.3.3
1235 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
1236 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
1239 If the lower bound of a subrange is 0 and the upper bound is negative,
1240 it means that it is an unsigned integral type whose size in bytes is the
1241 absolute value of the upper bound. I believe this is a Convex
1242 convention for @code{unsigned long long}.
1244 If the lower bound of a subrange is negative and the upper bound is 0,
1245 it means that the type is a signed integral type whose size in bytes is
1246 the absolute value of the lower bound. I believe this is a Convex
1247 convention for @code{long long}. To distinguish this from a legitimate
1248 subrange, the type should be a subrange of itself. I'm not sure whether
1249 this is the case for Convex.
1251 If the upper bound of a subrange is 0, it means that this is a floating
1252 point type, and the lower bound of the subrange indicates the number of
1256 .stabs "float:t12=r1;4;0;",128,0,0,0
1257 .stabs "double:t13=r1;8;0;",128,0,0,0
1260 However, GCC writes @code{long double} the same way it writes
1261 @code{double}, so there is no way to distinguish.
1264 .stabs "long double:t14=r1;8;0;",128,0,0,0
1267 Complex types are defined the same way as floating-point types; there is
1268 no way to distinguish a single-precision complex from a double-precision
1269 floating-point type.
1271 The C @code{void} type is defined as itself:
1274 .stabs "void:t15=15",128,0,0,0
1277 I'm not sure how a boolean type is represented.
1279 @node Builtin Type Descriptors
1280 @subsection Defining Builtin Types using Builtin Type Descriptors
1282 There are various type descriptors to define builtin types:
1285 @c FIXME: clean up description of width and offset, once we figure out
1287 @item b @var{signed} @var{char-flag} @var{width} ; @var{offset} ; @var{nbits} ;
1288 Define an integral type. @var{signed} is @samp{u} for unsigned or
1289 @samp{s} for signed. @var{char-flag} is @samp{c} which indicates this
1290 is a character type, or is omitted. I assume this is to distinguish an
1291 integral type from a character type of the same size, for example it
1292 might make sense to set it for the C type @code{wchar_t} so the debugger
1293 can print such variables differently (Solaris does not do this). Sun
1294 sets it on the C types @code{signed char} and @code{unsigned char} which
1295 arguably is wrong. @var{width} and @var{offset} appear to be for small
1296 objects stored in larger ones, for example a @code{short} in an
1297 @code{int} register. @var{width} is normally the number of bytes in the
1298 type. @var{offset} seems to always be zero. @var{nbits} is the number
1299 of bits in the type.
1301 Note that type descriptor @samp{b} used for builtin types conflicts with
1302 its use for Pascal space types (@pxref{Miscellaneous Types}); they can
1303 be distinguished because the character following the type descriptor
1304 will be a digit, @samp{(}, or @samp{-} for a Pascal space type, or
1305 @samp{u} or @samp{s} for a builtin type.
1308 Documented by AIX to define a wide character type, but their compiler
1309 actually uses negative type numbers (@pxref{Negative Type Numbers}).
1311 @item R @var{fp_type} ; @var{bytes} ;
1312 Define a floating point type. @var{fp_type} has one of the following values:
1316 IEEE 32-bit (single precision) floating point format.
1319 IEEE 64-bit (double precision) floating point format.
1321 @item 3 (NF_COMPLEX)
1322 @item 4 (NF_COMPLEX16)
1323 @item 5 (NF_COMPLEX32)
1324 @c "GDB source" really means @file{include/aout/stab_gnu.h}, but trying
1325 @c to put that here got an overfull hbox.
1326 These are for complex numbers. A comment in the GDB source describes
1327 them as Fortran complex, double complex, and complex*16, respectively,
1328 but what does that mean? (i.e., Single precision? Double precison?).
1330 @item 6 (NF_LDOUBLE)
1331 Long double. This should probably only be used for Sun format long
1332 double, and new codes should be used for other floating point formats
1333 (@code{NF_DOUBLE} can be used if a long double is really just an IEEE double,
1337 @var{bytes} is the number of bytes occupied by the type. This allows a
1338 debugger to perform some operations with the type even if it doesn't
1339 understand @var{fp_code}.
1341 @item g @var{type-information} ; @var{nbits}
1342 Documented by AIX to define a floating type, but their compiler actually
1343 uses negative type numbers (@pxref{Negative Type Numbers}).
1345 @item c @var{type-information} ; @var{nbits}
1346 Documented by AIX to define a complex type, but their compiler actually
1347 uses negative type numbers (@pxref{Negative Type Numbers}).
1350 The C @code{void} type is defined as a signed integral type 0 bits long:
1352 .stabs "void:t19=bs0;0;0",128,0,0,0
1354 The Solaris compiler seems to omit the trailing semicolon in this case.
1355 Getting sloppy in this way is not a swift move because if a type is
1356 embedded in a more complex expression it is necessary to be able to tell
1359 I'm not sure how a boolean type is represented.
1361 @node Negative Type Numbers
1362 @subsection Negative Type numbers
1364 Since the debugger knows about the builtin types anyway, the idea of
1365 negative type numbers is simply to give a special type number which
1366 indicates the built in type. There is no stab defining these types.
1368 I'm not sure whether anyone has tried to define what this means if
1369 @code{int} can be other than 32 bits (or other types can be other than
1370 their customary size). If @code{int} has exactly one size for each
1371 architecture, then it can be handled easily enough, but if the size of
1372 @code{int} can vary according the compiler options, then it gets hairy.
1373 The best way to do this would be to define separate negative type
1374 numbers for 16-bit @code{int} and 32-bit @code{int}; therefore I have
1375 indicated below the customary size (and other format information) for
1376 each type. The information below is currently correct because AIX on
1377 the RS6000 is the only system which uses these type numbers. If these
1378 type numbers start to get used on other systems, I suspect the correct
1379 thing to do is to define a new number in cases where a type does not
1380 have the size and format indicated below (or avoid negative type numbers
1383 Also note that part of the definition of the negative type number is
1384 the name of the type. Types with identical size and format but
1385 different names have different negative type numbers.
1389 @code{int}, 32 bit signed integral type.
1392 @code{char}, 8 bit type holding a character. Both GDB and dbx on AIX
1393 treat this as signed. GCC uses this type whether @code{char} is signed
1394 or not, which seems like a bad idea. The AIX compiler (xlc) seems to
1395 avoid this type; it uses -5 instead for @code{char}.
1398 @code{short}, 16 bit signed integral type.
1401 @code{long}, 32 bit signed integral type.
1404 @code{unsigned char}, 8 bit unsigned integral type.
1407 @code{signed char}, 8 bit signed integral type.
1410 @code{unsigned short}, 16 bit unsigned integral type.
1413 @code{unsigned int}, 32 bit unsigned integral type.
1416 @code{unsigned}, 32 bit unsigned integral type.
1419 @code{unsigned long}, 32 bit unsigned integral type.
1422 @code{void}, type indicating the lack of a value.
1425 @code{float}, IEEE single precision.
1428 @code{double}, IEEE double precision.
1431 @code{long double}, IEEE double precision. The compiler claims the size
1432 will increase in a future release, and for binary compatibility you have
1433 to avoid using @code{long double}. I hope when they increase it they
1434 use a new negative type number.
1437 @code{integer}. 32 bit signed integral type.
1440 @code{boolean}. 32 bit type. How is the truth value encoded? Is it
1441 the least significant bit or is it a question of whether the whole value
1442 is zero or non-zero?
1445 @code{short real}. IEEE single precision.
1448 @code{real}. IEEE double precision.
1451 @code{stringptr}. @xref{Strings}.
1454 @code{character}, 8 bit unsigned character type.
1457 @code{logical*1}, 8 bit type. This Fortran type has a split
1458 personality in that it is used for boolean variables, but can also be
1459 used for unsigned integers. 0 is false, 1 is true, and other values are
1463 @code{logical*2}, 16 bit type. This Fortran type has a split
1464 personality in that it is used for boolean variables, but can also be
1465 used for unsigned integers. 0 is false, 1 is true, and other values are
1469 @code{logical*4}, 32 bit type. This Fortran type has a split
1470 personality in that it is used for boolean variables, but can also be
1471 used for unsigned integers. 0 is false, 1 is true, and other values are
1475 @code{logical}, 32 bit type. This Fortran type has a split
1476 personality in that it is used for boolean variables, but can also be
1477 used for unsigned integers. 0 is false, 1 is true, and other values are
1481 @code{complex}. A complex type consisting of two IEEE single-precision
1482 floating point values.
1485 @code{complex}. A complex type consisting of two IEEE double-precision
1486 floating point values.
1489 @code{integer*1}, 8 bit signed integral type.
1492 @code{integer*2}, 16 bit signed integral type.
1495 @code{integer*4}, 32 bit signed integral type.
1498 @code{wchar}. Wide character, 16 bits wide, unsigned (what format?
1502 @node Miscellaneous Types
1503 @section Miscellaneous Types
1506 @item b @var{type-information} ; @var{bytes}
1507 Pascal space type. This is documented by IBM; what does it mean?
1509 Note that this use of the @samp{b} type descriptor can be distinguished
1510 from its use for builtin integral types (@pxref{Builtin Type
1511 Descriptors}) because the character following the type descriptor is
1512 always a digit, @samp{(}, or @samp{-}.
1514 @item B @var{type-information}
1515 A volatile-qualified version of @var{type-information}. This is a Sun
1516 extension. A volatile-qualified type means that references and stores
1517 to a variable of that type must not be optimized or cached; they must
1518 occur as the user specifies them.
1520 @item d @var{type-information}
1521 File of type @var{type-information}. As far as I know this is only used
1524 @item k @var{type-information}
1525 A const-qualified version of @var{type-information}. This is a Sun
1526 extension. A const-qualified type means that a variable of this type
1529 @item M @var{type-information} ; @var{length}
1530 Multiple instance type. The type seems to composed of @var{length}
1531 repetitions of @var{type-information}, for example @code{character*3} is
1532 represented by @samp{M-2;3}, where @samp{-2} is a reference to a
1533 character type (@pxref{Negative Type Numbers}). I'm not sure how this
1534 differs from an array. This appears to be a Fortran feature.
1535 @var{length} is a bound, like those in range types; see @ref{Subranges}.
1537 @item S @var{type-information}
1538 Pascal set type. @var{type-information} must be a small type such as an
1539 enumeration or a subrange, and the type is a bitmask whose length is
1540 specified by the number of elements in @var{type-information}.
1542 @item * @var{type-information}
1543 Pointer to @var{type-information}.
1546 @node Cross-references
1547 @section Cross-references to other types
1549 If a type is used before it is defined, one common way to deal with this
1550 is just to use a type reference to a type which has not yet been
1551 defined. The debugger is expected to be able to deal with this.
1553 Another way is with the @samp{x} type descriptor, which is followed by
1554 @samp{s} for a structure tag, @samp{u} for a union tag, or @samp{e} for
1555 a enumerator tag, followed by the name of the tag, followed by @samp{:}.
1556 for example the following C declarations:
1566 .stabs "bar:G16=*17=xsfoo:",32,0,0,0
1569 Not all debuggers support the @samp{x} type descriptor, so on some
1570 machines GCC does not use it. I believe that for the above example it
1571 would just emit a reference to type 17 and never define it, but I
1572 haven't verified that.
1574 Modula-2 imported types, at least on AIX, use the @samp{i} type
1575 descriptor, which is followed by the name of the module from which the
1576 type is imported, followed by @samp{:}, followed by the name of the
1577 type. There is then optionally a comma followed by type information for
1578 the type (This differs from merely naming the type (@pxref{Typedefs}) in
1579 that it identifies the module; I don't understand whether the name of
1580 the type given here is always just the same as the name we are giving
1581 it, or whether this type descriptor is used with a nameless stab
1582 (@pxref{String Field}), or what). The symbol ends with @samp{;}.
1585 @section Subrange types
1587 The @samp{r} type descriptor defines a type as a subrange of another
1588 type. It is followed by type information for the type which it is a
1589 subrange of, a semicolon, an integral lower bound, a semicolon, an
1590 integral upper bound, and a semicolon. The AIX documentation does not
1591 specify the trailing semicolon, in an effort to specify array indexes
1592 more cleanly, but a subrange which is not an array index has always
1593 included a trailing semicolon (@pxref{Arrays}).
1595 Instead of an integer, either bound can be one of the following:
1598 @item A @var{offset}
1599 The bound is passed by reference on the stack at offset @var{offset}
1600 from the argument list. @xref{Parameters}, for more information on such
1603 @item T @var{offset}
1604 The bound is passed by value on the stack at offset @var{offset} from
1607 @item a @var{register-number}
1608 The bound is pased by reference in register number
1609 @var{register-number}.
1611 @item t @var{register-number}
1612 The bound is passed by value in register number @var{register-number}.
1618 Subranges are also used for builtin types; see @ref{Traditional Builtin Types}.
1621 @section Array types
1623 Arrays use the @samp{a} type descriptor. Following the type descriptor
1624 is the type of the index and the type of the array elements. If the
1625 index type is a range type, it will end in a semicolon; if it is not a
1626 range type (for example, if it is a type reference), there does not
1627 appear to be any way to tell where the types are separated. In an
1628 effort to clean up this mess, IBM documents the two types as being
1629 separated by a semicolon, and a range type as not ending in a semicolon
1630 (but this is not right for range types which are not array indexes,
1631 @pxref{Subranges}). I think probably the best solution is to specify
1632 that a semicolon ends a range type, and that the index type and element
1633 type of an array are separated by a semicolon, but that if the index
1634 type is a range type, the extra semicolon can be omitted. GDB (at least
1635 through version 4.9) doesn't support any kind of index type other than a
1636 range anyway; I'm not sure about dbx.
1638 It is well established, and widely used, that the type of the index,
1639 unlike most types found in the stabs, is merely a type definition, not
1640 type information (@pxref{String Field}) (that is, it need not start with
1641 @var{type-number}@code{=} if it is defining a new type). According to a
1642 comment in GDB, this is also true of the type of the array elements; it
1643 gives @samp{ar1;1;10;ar1;1;10;4} as a legitimate way to express a two
1644 dimensional array. According to AIX documentation, the element type
1645 must be type information. GDB accepts either.
1647 The type of the index is often a range type, expressed as the letter r
1648 and some parameters. It defines the size of the array. In the example
1649 below, the range @code{r1;0;2;} defines an index type which is a
1650 subrange of type 1 (integer), with a lower bound of 0 and an upper bound
1651 of 2. This defines the valid range of subscripts of a three-element C
1654 For example, the definition
1657 char char_vec[3] = @{'a','b','c'@};
1664 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
1673 If an array is @dfn{packed}, it means that the elements are spaced more
1674 closely than normal, saving memory at the expense of speed. For
1675 example, an array of 3-byte objects might, if unpacked, have each
1676 element aligned on a 4-byte boundary, but if packed, have no padding.
1677 One way to specify that something is packed is with type attributes
1678 (@pxref{String Field}), in the case of arrays another is to use the
1679 @samp{P} type descriptor instead of @samp{a}. Other than specifying a
1680 packed array, @samp{P} is identical to @samp{a}.
1682 @c FIXME-what is it? A pointer?
1683 An open array is represented by the @samp{A} type descriptor followed by
1684 type information specifying the type of the array elements.
1686 @c FIXME: what is the format of this type? A pointer to a vector of pointers?
1687 An N-dimensional dynamic array is represented by
1690 D @var{dimensions} ; @var{type-information}
1693 @c Does dimensions really have this meaning? The AIX documentation
1695 @var{dimensions} is the number of dimensions; @var{type-information}
1696 specifies the type of the array elements.
1698 @c FIXME: what is the format of this type? A pointer to some offsets in
1700 A subarray of an N-dimensional array is represented by
1703 E @var{dimensions} ; @var{type-information}
1706 @c Does dimensions really have this meaning? The AIX documentation
1708 @var{dimensions} is the number of dimensions; @var{type-information}
1709 specifies the type of the array elements.
1714 Some languages, like C or the original Pascal, do not have string types,
1715 they just have related things like arrays of characters. But most
1716 Pascals and various other languages have string types, which are
1717 indicated as follows:
1720 @item n @var{type-information} ; @var{bytes}
1721 @var{bytes} is the maximum length. I'm not sure what
1722 @var{type-information} is; I suspect that it means that this is a string
1723 of @var{type-information} (thus allowing a string of integers, a string
1724 of wide characters, etc., as well as a string of characters). Not sure
1725 what the format of this type is. This is an AIX feature.
1727 @item z @var{type-information} ; @var{bytes}
1728 Just like @samp{n} except that this is a gstring, not an ordinary
1729 string. I don't know the difference.
1732 Pascal Stringptr. What is this? This is an AIX feature.
1736 @section Enumerations
1738 Enumerations are defined with the @samp{e} type descriptor.
1740 @c FIXME: Where does this information properly go? Perhaps it is
1741 @c redundant with something we already explain.
1742 The source line below declares an enumeration type. It is defined at
1743 file scope between the bodies of main and @code{s_proc} in @file{example2.c}.
1744 The type definition is located after the @code{N_RBRAC} that marks the end of
1745 the previous procedure's block scope, and before the @code{N_FUN} that marks
1746 the beginning of the next procedure's block scope. Therefore it does not
1747 describe a block local symbol, but a file local one.
1752 enum e_places @{first,second=3,last@};
1756 generates the following stab
1759 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
1762 The symbol descriptor (T) says that the stab describes a structure,
1763 enumeration, or union tag. The type descriptor e, following the 22= of
1764 the type definition narrows it down to an enumeration type. Following
1765 the e is a list of the elements of the enumeration. The format is
1766 @var{name:value,}. The list of elements ends with a @samp{;}.
1768 There is no standard way to specify the size of an enumeration type; it
1769 is determined by the architecture (normally all enumerations types are
1770 32 bits). There should be a way to specify an enumeration type of
1771 another size; type attributes would be one way to do this @xref{Stabs
1781 @code{N_LSYM} or @code{C_DECL}
1782 @item Symbol Descriptor:
1784 @item Type Descriptor:
1788 The following source code declares a structure tag and defines an
1789 instance of the structure in global scope. Then a typedef equates the
1790 structure tag with a new type. A seperate stab is generated for the
1791 structure tag, the structure typedef, and the structure instance. The
1792 stabs for the tag and the typedef are emited when the definitions are
1793 encountered. Since the structure elements are not initialized, the
1794 stab and code for the structure variable itself is located at the end
1795 of the program in .common.
1801 9 char s_char_vec[8];
1802 10 struct s_tag* s_next;
1805 13 typedef struct s_tag s_typedef;
1808 The structure tag is an @code{N_LSYM} stab type because, like the enum, the
1809 symbol is file scope. Like the enum, the symbol descriptor is @samp{T}, for
1810 enumeration, struct or tag type. The symbol descriptor @samp{s} following
1811 the @samp{16=} of the type definition narrows the symbol type to struct.
1813 Following the struct symbol descriptor is the number of bytes the struct
1814 occupies, followed by a description of each structure element. The
1815 structure element descriptions are of the form
1816 @var{name:type, bit offset from the start of the struct,
1817 number of bits in the element}.
1821 <128> N_LSYM - type definition
1822 .stabs "name:sym_desc(struct tag) Type_def(16)=type_desc(struct type)
1824 elem_name:type_ref(int),bit_offset,field_bits;
1825 elem_name:type_ref(float),bit_offset,field_bits;
1826 elem_name:type_def(17)=type_desc(array)
1827 index_type(range of int from 0 to 7);
1828 element_type(char),bit_offset,field_bits;;",
1831 30 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
1832 s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
1835 In this example, two of the structure elements are previously defined
1836 types. For these, the type following the name: part of the element
1837 description is a simple type reference. The other two structure
1838 elements are new types. In this case there is a type definition
1839 embedded after the name:. The type definition for the array element
1840 looks just like a type definition for a standalone array. The @code{s_next}
1841 field is a pointer to the same kind of structure that the field is an
1842 element of. So the definition of structure type 16 contains an type
1843 definition for an element which is a pointer to type 16.
1846 @section Giving a Type a Name
1848 To give a type a name, use the @samp{t} symbol descriptor. The type
1849 specified by the type information (@pxref{String Field}) for the stab.
1853 .stabs "s_typedef:t16",128,0,0,0
1856 specifies that @code{s_typedef} refers to type number 16. Such stabs
1857 have symbol type @code{N_LSYM} or @code{C_DECL}.
1859 If instead, you are specifying the tag name for a structure, union, or
1860 enumeration, use the @samp{T} symbol descriptor instead. I believe C is
1861 the only language with this feature.
1863 If the type is an opaque type (I believe this is a Modula-2 feature),
1864 AIX provides a type descriptor to specify it. The type descriptor is
1865 @samp{o} and is followed by a name. I don't know what the name
1866 means---is it always the same as the name of the type, or is this type
1867 descriptor used with a nameless stab (@pxref{String Field})? There
1868 optionally follows a comma followed by type information which defines
1869 the type of this type. If omitted, a semicolon is used in place of the
1870 comma and the type information, and the type is much like a generic
1871 pointer type---it has a known size but little else about it is
1877 Next let's look at unions. In example2 this union type is declared
1878 locally to a procedure and an instance of the union is defined.
1888 This code generates a stab for the union tag and a stab for the union
1889 variable. Both use the @code{N_LSYM} stab type. Since the union variable is
1890 scoped locally to the procedure in which it is defined, its stab is
1891 located immediately preceding the @code{N_LBRAC} for the procedure's block
1894 The stab for the union tag, however is located preceding the code for
1895 the procedure in which it is defined. The stab type is @code{N_LSYM}. This
1896 would seem to imply that the union type is file scope, like the struct
1897 type @code{s_tag}. This is not true. The contents and position of the stab
1898 for @code{u_type} do not convey any infomation about its procedure local
1903 .stabs "name:sym_desc(union tag)type_def(22)=type_desc(union)
1905 elem_name:type_ref(int),bit_offset(0),bit_size(32);
1906 elem_name:type_ref(float),bit_offset(0),bit_size(32);
1907 elem_name:type_ref(ptr to char),bit_offset(0),bit_size(32);;"
1908 N_LSYM, NIL, NIL, NIL
1912 105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
1916 The symbol descriptor, @samp{T}, following the @samp{name:} means that the stab
1917 describes an enumeration, struct or union tag. The type descriptor @samp{u},
1918 following the @samp{23=} of the type definition, narrows it down to a union
1919 type definition. Following the @samp{u} is the number of bytes in the union.
1920 After that is a list of union element descriptions. Their format is
1921 @var{name:type, bit offset into the union, number of bytes for the
1924 The stab for the union variable follows.
1927 <128> N_LSYM - local variable (with no symbol descriptor)
1928 .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset
1932 130 .stabs "an_u:23",128,0,0,-20
1935 @node Function Types
1936 @section Function types
1938 There are various types for function variables. These types are not
1939 used in defining functions; see symbol descriptor @samp{f}; they are
1940 used for things like pointers to functions.
1942 The simple, traditional, type is type descriptor @samp{f} is followed by
1943 type information for the return type of the function, followed by a
1946 This does not deal with functions the number and type of whose
1947 parameters are part of their type, as found in Modula-2 or ANSI C. AIX
1948 provides extensions to specify these, using the @samp{f}, @samp{F},
1949 @samp{p}, and @samp{R} type descriptors.
1951 First comes the type descriptor. Then, if it is @samp{f} or @samp{F},
1952 this is a function, and the type information for the return type of the
1953 function follows, followed by a comma. Then comes the number of
1954 parameters to the function and a semicolon. Then, for each parameter,
1955 there is the name of the parameter followed by a colon (this is only
1956 present for type descriptors @samp{R} and @samp{F} which represent
1957 Pascal function or procedure parameters), type information for the
1958 parameter, a comma, @samp{0} if passed by reference or @samp{1} if
1959 passed by value, and a semicolon. The type definition ends with a
1969 generates the following code:
1972 .stabs "g_pf:G24=*25=f1",32,0,0,0
1973 .common _g_pf,4,"bss"
1976 The variable defines a new type, 24, which is a pointer to another new
1977 type, 25, which is defined as a function returning int.
1980 @chapter Symbol information in symbol tables
1982 This chapter describes the format of symbol table entries
1983 and how stab assembler directives map to them. It also describes the
1984 transformations that the assembler and linker make on data from stabs.
1986 Each time the assembler encounters a stab in its input file it puts
1987 each field of the stab into corresponding fields in a symbol table
1988 entry of its output file. If the stab contains a string field, the
1989 symbol table entry for that stab points to a string table entry
1990 containing the string data from the stab. Assembler labels become
1991 relocatable addresses. Symbol table entries in a.out have the format:
1993 @c FIXME: should refer to external, not internal.
1995 struct internal_nlist @{
1996 unsigned long n_strx; /* index into string table of name */
1997 unsigned char n_type; /* type of symbol */
1998 unsigned char n_other; /* misc info (usually empty) */
1999 unsigned short n_desc; /* description field */
2000 bfd_vma n_value; /* value of symbol */
2004 For @code{.stabs} directives, the @code{n_strx} field holds the offset
2006 from the start of the string table to the string table entry
2007 containing the @var{string} field. For other classes of stabs (@code{.stabn} and
2008 @code{.stabd}) this field is zero.
2010 Symbol table entries with @code{n_type} fields containing a value greater or
2011 equal to 0x20 originated as stabs generated by the compiler (with one
2012 random exception). Those with n_type values less than 0x20 were
2013 placed in the symbol table of the executable by the assembler or the
2016 The linker concatenates object files and does fixups of externally
2017 defined symbols. You can see the transformations made on stab data by
2018 the assembler and linker by examining the symbol table after each pass
2019 of the build, first the assemble and then the link.
2021 To do this, use @samp{nm -ap}. This dumps the symbol table, including
2022 debugging information, unsorted. For stab entries the columns are:
2023 @var{value}, @var{other}, @var{desc}, @var{type}, @var{string}. For
2024 assembler and linker symbols, the columns are: @var{value}, @var{type},
2027 There are a few important things to notice about symbol tables. Where
2028 the @var{value} field of a stab contains a frame pointer offset, or a
2029 register number, that value is unchanged by the rest of the build.
2031 Where the @var{value} field of a stab contains an assembly language label,
2032 it is transformed by each build step. The assembler turns it into a
2033 relocatable address and the linker turns it into an absolute address.
2034 This source line defines a static variable at file scope:
2037 3 static int s_g_repeat
2041 The following stab describes the symbol:
2044 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
2048 The assembler transforms the stab into this symbol table entry in the
2049 @file{.o} file. The location is expressed as a data segment offset.
2052 21 00000084 - 00 0000 STSYM s_g_repeat:S1
2056 in the symbol table entry from the executable, the linker has made the
2057 relocatable address absolute.
2060 22 0000e00c - 00 0000 STSYM s_g_repeat:S1
2063 Stabs for global variables do not contain location information. In
2064 this case the debugger finds location information in the assembler or
2065 linker symbol table entry describing the variable. The source line:
2075 21 .stabs "g_foo:G2",32,0,0,0
2078 The variable is represented by the following two symbol table entries
2079 in the object file. The first one originated as a stab. The second
2080 one is an external symbol. The upper case @samp{D} signifies that the @code{n_type}
2081 field of the symbol table contains 7, @code{N_DATA} with local linkage.
2082 The value field following the file's line number is empty
2083 for the stab entry. For the linker symbol it contains the
2084 relocatable address corresponding to the variable.
2087 19 00000000 - 00 0000 GSYM g_foo:G2
2088 20 00000080 D _g_foo
2092 These entries as transformed by the linker. The linker symbol table
2093 entry now holds an absolute address.
2096 21 00000000 - 00 0000 GSYM g_foo:G2
2098 215 0000e008 D _g_foo
2102 @chapter GNU C++ stabs
2105 * Basic Cplusplus types::
2108 * Methods:: Method definition
2110 * Method Modifiers::
2113 * Virtual Base Classes::
2117 Type descriptors added for C++ descriptions:
2121 method type (@code{##} if minimal debug)
2124 Member (class and variable) type. It is followed by type information
2125 for the offset basetype, a comma, and type information for the type of
2126 the field being pointed to. (FIXME: this is acknowledged to be
2127 gibberish. Can anyone say what really goes here?).
2129 Note that there is a conflict between this and type attributes
2130 (@pxref{String Field}); both use type descriptor @samp{@@}.
2131 Fortunately, the @samp{@@} type descriptor used in this C++ sense always
2132 will be followed by a digit, @samp{(}, or @samp{-}, and type attributes
2133 never start with those things.
2136 @node Basic Cplusplus types
2137 @section Basic types for C++
2139 << the examples that follow are based on a01.C >>
2142 C++ adds two more builtin types to the set defined for C. These are
2143 the unknown type and the vtable record type. The unknown type, type
2144 16, is defined in terms of itself like the void type.
2146 The vtable record type, type 17, is defined as a structure type and
2147 then as a structure tag. The structure has four fields: delta, index,
2148 pfn, and delta2. pfn is the function pointer.
2150 << In boilerplate $vtbl_ptr_type, what are the fields delta,
2151 index, and delta2 used for? >>
2153 This basic type is present in all C++ programs even if there are no
2154 virtual methods defined.
2157 .stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8)
2158 elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16);
2159 elem_name(index):type_ref(short int),bit_offset(16),field_bits(16);
2160 elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void),
2161 bit_offset(32),field_bits(32);
2162 elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;"
2167 .stabs "$vtbl_ptr_type:t17=s8
2168 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;"
2173 .stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL
2177 .stabs "$vtbl_ptr_type:T17",128,0,0,0
2180 @node Simple classes
2181 @section Simple class definition
2183 The stabs describing C++ language features are an extension of the
2184 stabs describing C. Stabs representing C++ class types elaborate
2185 extensively on the stab format used to describe structure types in C.
2186 Stabs representing class type variables look just like stabs
2187 representing C language variables.
2189 Consider the following very simple class definition.
2195 int Ameth(int in, char other);
2199 The class @code{baseA} is represented by two stabs. The first stab describes
2200 the class as a structure type. The second stab describes a structure
2201 tag of the class type. Both stabs are of stab type @code{N_LSYM}. Since the
2202 stab is not located between an @code{N_FUN} and a @code{N_LBRAC} stab this indicates
2203 that the class is defined at file scope. If it were, then the @code{N_LSYM}
2204 would signify a local variable.
2206 A stab describing a C++ class type is similar in format to a stab
2207 describing a C struct, with each class member shown as a field in the
2208 structure. The part of the struct format describing fields is
2209 expanded to include extra information relevent to C++ class members.
2210 In addition, if the class has multiple base classes or virtual
2211 functions the struct format outside of the field parts is also
2214 In this simple example the field part of the C++ class stab
2215 representing member data looks just like the field part of a C struct
2216 stab. The section on protections describes how its format is
2217 sometimes extended for member data.
2219 The field part of a C++ class stab representing a member function
2220 differs substantially from the field part of a C struct stab. It
2221 still begins with @samp{name:} but then goes on to define a new type number
2222 for the member function, describe its return type, its argument types,
2223 its protection level, any qualifiers applied to the method definition,
2224 and whether the method is virtual or not. If the method is virtual
2225 then the method description goes on to give the vtable index of the
2226 method, and the type number of the first base class defining the
2229 When the field name is a method name it is followed by two colons rather
2230 than one. This is followed by a new type definition for the method.
2231 This is a number followed by an equal sign and the type descriptor
2232 @samp{#}, indicating a method type, and a second @samp{#}, indicating
2233 that this is the @dfn{minimal} type of method definition used by GCC2,
2234 not larger method definitions used by earlier versions of GCC. This is
2235 followed by a type reference showing the return type of the method and a
2238 The format of an overloaded operator method name differs from that of
2239 other methods. It is @samp{op$::@var{operator-name}.} where
2240 @var{operator-name} is the operator name such as @samp{+} or @samp{+=}.
2241 The name ends with a period, and any characters except the period can
2242 occur in the @var{operator-name} string.
2244 The next part of the method description represents the arguments to the
2245 method, preceeded by a colon and ending with a semi-colon. The types of
2246 the arguments are expressed in the same way argument types are expressed
2247 in C++ name mangling. In this example an @code{int} and a @code{char}
2250 This is followed by a number, a letter, and an asterisk or period,
2251 followed by another semicolon. The number indicates the protections
2252 that apply to the member function. Here the 2 means public. The
2253 letter encodes any qualifier applied to the method definition. In
2254 this case, @samp{A} means that it is a normal function definition. The dot
2255 shows that the method is not virtual. The sections that follow
2256 elaborate further on these fields and describe the additional
2257 information present for virtual methods.
2261 .stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
2262 field_name(Adat):type(int),bit_offset(0),field_bits(32);
2264 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
2265 :arg_types(int char);
2266 protection(public)qualifier(normal)virtual(no);;"
2271 .stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
2273 .stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
2275 .stabs "baseA:T20",128,0,0,0
2278 @node Class instance
2279 @section Class instance
2281 As shown above, describing even a simple C++ class definition is
2282 accomplished by massively extending the stab format used in C to
2283 describe structure types. However, once the class is defined, C stabs
2284 with no modifications can be used to describe class instances. The
2294 yields the following stab describing the class instance. It looks no
2295 different from a standard C stab describing a local variable.
2298 .stabs "name:type_ref(baseA)", N_LSYM, NIL, NIL, frame_ptr_offset
2302 .stabs "AbaseA:20",128,0,0,-20
2306 @section Method defintion
2308 The class definition shown above declares Ameth. The C++ source below
2313 baseA::Ameth(int in, char other)
2320 This method definition yields three stabs following the code of the
2321 method. One stab describes the method itself and following two describe
2322 its parameters. Although there is only one formal argument all methods
2323 have an implicit argument which is the @code{this} pointer. The @code{this}
2324 pointer is a pointer to the object on which the method was called. Note
2325 that the method name is mangled to encode the class name and argument
2326 types. Name mangling is described in the @sc{arm} (@cite{The Annotated
2327 C++ Reference Manual}, by Ellis and Stroustrup, @sc{isbn}
2328 0-201-51459-1); @file{gpcompare.texi} in Cygnus GCC distributions
2329 describes the differences between GNU mangling and @sc{arm}
2331 @c FIXME: Use @xref, especially if this is generally installed in the
2333 @c FIXME: This information should be in a net release, either of GCC or
2334 @c GDB. But gpcompare.texi doesn't seem to be in the FSF GCC.
2337 .stabs "name:symbol_desriptor(global function)return_type(int)",
2338 N_FUN, NIL, NIL, code_addr_of_method_start
2340 .stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic
2343 Here is the stab for the @code{this} pointer implicit argument. The
2344 name of the @code{this} pointer is always @code{this}. Type 19, the
2345 @code{this} pointer is defined as a pointer to type 20, @code{baseA},
2346 but a stab defining @code{baseA} has not yet been emited. Since the
2347 compiler knows it will be emited shortly, here it just outputs a cross
2348 reference to the undefined symbol, by prefixing the symbol name with
2352 .stabs "name:sym_desc(register param)type_def(19)=
2353 type_desc(ptr to)type_ref(baseA)=
2354 type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number
2356 .stabs "this:P19=*20=xsbaseA:",64,0,0,8
2359 The stab for the explicit integer argument looks just like a parameter
2360 to a C function. The last field of the stab is the offset from the
2361 argument pointer, which in most systems is the same as the frame
2365 .stabs "name:sym_desc(value parameter)type_ref(int)",
2366 N_PSYM,NIL,NIL,offset_from_arg_ptr
2368 .stabs "in:p1",160,0,0,72
2371 << The examples that follow are based on A1.C >>
2374 @section Protections
2377 In the simple class definition shown above all member data and
2378 functions were publicly accessable. The example that follows
2379 contrasts public, protected and privately accessable fields and shows
2380 how these protections are encoded in C++ stabs.
2382 @c FIXME: What does "part of the string" mean?
2383 Protections for class member data are signified by two characters
2384 embedded in the stab defining the class type. These characters are
2385 located after the name: part of the string. @samp{/0} means private,
2386 @samp{/1} means protected, and @samp{/2} means public. If these
2387 characters are omited this means that the member is public. The
2388 following C++ source:
2402 generates the following stab to describe the class type all_data.
2405 .stabs "class_name:sym_desc(type)type_def(19)=type_desc(struct)struct_bytes
2406 data_name:/protection(private)type_ref(int),bit_offset,num_bits;
2407 data_name:/protection(protected)type_ref(char),bit_offset,num_bits;
2408 data_name:(/num omited, private)type_ref(float),bit_offset,num_bits;;"
2413 .stabs "all_data:t19=s12
2414 priv_dat:/01,0,32;prot_dat:/12,32,8;pub_dat:12,64,32;;",128,0,0,0
2417 Protections for member functions are signified by one digit embeded in
2418 the field part of the stab describing the method. The digit is 0 if
2419 private, 1 if protected and 2 if public. Consider the C++ class
2423 class all_methods @{
2425 int priv_meth(int in)@{return in;@};
2427 char protMeth(char in)@{return in;@};
2429 float pubMeth(float in)@{return in;@};
2433 It generates the following stab. The digit in question is to the left
2434 of an @samp{A} in each case. Notice also that in this case two symbol
2435 descriptors apply to the class name struct tag and struct type.
2438 .stabs "class_name:sym_desc(struct tag&type)type_def(21)=
2439 sym_desc(struct)struct_bytes(1)
2440 meth_name::type_def(22)=sym_desc(method)returning(int);
2441 :args(int);protection(private)modifier(normal)virtual(no);
2442 meth_name::type_def(23)=sym_desc(method)returning(char);
2443 :args(char);protection(protected)modifier(normal)virual(no);
2444 meth_name::type_def(24)=sym_desc(method)returning(float);
2445 :args(float);protection(public)modifier(normal)virtual(no);;",
2450 .stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
2451 pubMeth::24=##12;:f;2A.;;",128,0,0,0
2454 @node Method Modifiers
2455 @section Method Modifiers (const, volatile, const volatile)
2459 In the class example described above all the methods have the normal
2460 modifier. This method modifier information is located just after the
2461 protection information for the method. This field has four possible
2462 character values. Normal methods use @samp{A}, const methods use
2463 @samp{B}, volatile methods use @samp{C}, and const volatile methods use
2464 @samp{D}. Consider the class definition below:
2469 int ConstMeth (int arg) const @{ return arg; @};
2470 char VolatileMeth (char arg) volatile @{ return arg; @};
2471 float ConstVolMeth (float arg) const volatile @{return arg; @};
2475 This class is described by the following stab:
2478 .stabs "class(A):sym_desc(struct)type_def(20)=type_desc(struct)struct_bytes(1)
2479 meth_name(ConstMeth)::type_def(21)sym_desc(method)
2480 returning(int);:arg(int);protection(public)modifier(const)virtual(no);
2481 meth_name(VolatileMeth)::type_def(22)=sym_desc(method)
2482 returning(char);:arg(char);protection(public)modifier(volatile)virt(no)
2483 meth_name(ConstVolMeth)::type_def(23)=sym_desc(method)
2484 returning(float);:arg(float);protection(public)modifer(const volatile)
2485 virtual(no);;", @dots{}
2489 .stabs "A:T20=s1ConstMeth::21=##1;:i;2B.;VolatileMeth::22=##2;:c;2C.;
2490 ConstVolMeth::23=##12;:f;2D.;;",128,0,0,0
2493 @node Virtual Methods
2494 @section Virtual Methods
2496 << The following examples are based on a4.C >>
2498 The presence of virtual methods in a class definition adds additional
2499 data to the class description. The extra data is appended to the
2500 description of the virtual method and to the end of the class
2501 description. Consider the class definition below:
2507 virtual int A_virt (int arg) @{ return arg; @};
2511 This results in the stab below describing class A. It defines a new
2512 type (20) which is an 8 byte structure. The first field of the class
2513 struct is @samp{Adat}, an integer, starting at structure offset 0 and
2516 The second field in the class struct is not explicitly defined by the
2517 C++ class definition but is implied by the fact that the class
2518 contains a virtual method. This field is the vtable pointer. The
2519 name of the vtable pointer field starts with @samp{$vf} and continues with a
2520 type reference to the class it is part of. In this example the type
2521 reference for class A is 20 so the name of its vtable pointer field is
2522 @samp{$vf20}, followed by the usual colon.
2524 Next there is a type definition for the vtable pointer type (21).
2525 This is in turn defined as a pointer to another new type (22).
2527 Type 22 is the vtable itself, which is defined as an array, indexed by
2528 a range of integers between 0 and 1, and whose elements are of type
2529 17. Type 17 was the vtable record type defined by the boilerplate C++
2530 type definitions, as shown earlier.
2532 The bit offset of the vtable pointer field is 32. The number of bits
2533 in the field are not specified when the field is a vtable pointer.
2535 Next is the method definition for the virtual member function @code{A_virt}.
2536 Its description starts out using the same format as the non-virtual
2537 member functions described above, except instead of a dot after the
2538 @samp{A} there is an asterisk, indicating that the function is virtual.
2539 Since is is virtual some addition information is appended to the end
2540 of the method description.
2542 The first number represents the vtable index of the method. This is a
2543 32 bit unsigned number with the high bit set, followed by a
2546 The second number is a type reference to the first base class in the
2547 inheritence hierarchy defining the virtual member function. In this
2548 case the class stab describes a base class so the virtual function is
2549 not overriding any other definition of the method. Therefore the
2550 reference is to the type number of the class that the stab is
2553 This is followed by three semi-colons. One marks the end of the
2554 current sub-section, one marks the end of the method field, and the
2555 third marks the end of the struct definition.
2557 For classes containing virtual functions the very last section of the
2558 string part of the stab holds a type reference to the first base
2559 class. This is preceeded by @samp{~%} and followed by a final semi-colon.
2562 .stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
2563 field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
2564 field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
2565 sym_desc(array)index_type_ref(range of int from 0 to 1);
2566 elem_type_ref(vtbl elem type),
2568 meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
2569 :arg_type(int),protection(public)normal(yes)virtual(yes)
2570 vtable_index(1);class_first_defining(A);;;~%first_base(A);",
2574 @c FIXME: bogus line break.
2576 .stabs "A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2577 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
2581 @section Inheritence
2583 Stabs describing C++ derived classes include additional sections that
2584 describe the inheritence hierarchy of the class. A derived class stab
2585 also encodes the number of base classes. For each base class it tells
2586 if the base class is virtual or not, and if the inheritence is private
2587 or public. It also gives the offset into the object of the portion of
2588 the object corresponding to each base class.
2590 This additional information is embeded in the class stab following the
2591 number of bytes in the struct. First the number of base classes
2592 appears bracketed by an exclamation point and a comma.
2594 Then for each base type there repeats a series: two digits, a number,
2595 a comma, another number, and a semi-colon.
2597 The first of the two digits is 1 if the base class is virtual and 0 if
2598 not. The second digit is 2 if the derivation is public and 0 if not.
2600 The number following the first two digits is the offset from the start
2601 of the object to the part of the object pertaining to the base class.
2603 After the comma, the second number is a type_descriptor for the base
2604 type. Finally a semi-colon ends the series, which repeats for each
2607 The source below defines three base classes @code{A}, @code{B}, and
2608 @code{C} and the derived class @code{D}.
2615 virtual int A_virt (int arg) @{ return arg; @};
2621 virtual int B_virt (int arg) @{return arg; @};
2627 virtual int C_virt (int arg) @{return arg; @};
2630 class D : A, virtual B, public C @{
2633 virtual int A_virt (int arg ) @{ return arg+1; @};
2634 virtual int B_virt (int arg) @{ return arg+2; @};
2635 virtual int C_virt (int arg) @{ return arg+3; @};
2636 virtual int D_virt (int arg) @{ return arg; @};
2640 Class stabs similar to the ones described earlier are generated for
2643 @c FIXME!!! the linebreaks in the following example probably make the
2644 @c examples literally unusable, but I don't know any other way to get
2645 @c them on the page.
2646 @c One solution would be to put some of the type definitions into
2647 @c separate stabs, even if that's not exactly what the compiler actually
2650 .stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2651 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
2653 .stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
2654 :i;2A*-2147483647;25;;;~%25;",128,0,0,0
2656 .stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
2657 :i;2A*-2147483647;28;;;~%28;",128,0,0,0
2660 In the stab describing derived class @code{D} below, the information about
2661 the derivation of this class is encoded as follows.
2664 .stabs "derived_class_name:symbol_descriptors(struct tag&type)=
2665 type_descriptor(struct)struct_bytes(32)!num_bases(3),
2666 base_virtual(no)inheritence_public(no)base_offset(0),
2667 base_class_type_ref(A);
2668 base_virtual(yes)inheritence_public(no)base_offset(NIL),
2669 base_class_type_ref(B);
2670 base_virtual(no)inheritence_public(yes)base_offset(64),
2671 base_class_type_ref(C); @dots{}
2674 @c FIXME! fake linebreaks.
2676 .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
2677 1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
2678 :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
2679 28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
2682 @node Virtual Base Classes
2683 @section Virtual Base Classes
2685 A derived class object consists of a concatination in memory of the data
2686 areas defined by each base class, starting with the leftmost and ending
2687 with the rightmost in the list of base classes. The exception to this
2688 rule is for virtual inheritence. In the example above, class @code{D}
2689 inherits virtually from base class @code{B}. This means that an
2690 instance of a @code{D} object will not contain its own @code{B} part but
2691 merely a pointer to a @code{B} part, known as a virtual base pointer.
2693 In a derived class stab, the base offset part of the derivation
2694 information, described above, shows how the base class parts are
2695 ordered. The base offset for a virtual base class is always given as 0.
2696 Notice that the base offset for @code{B} is given as 0 even though
2697 @code{B} is not the first base class. The first base class @code{A}
2700 The field information part of the stab for class @code{D} describes the field
2701 which is the pointer to the virtual base class @code{B}. The vbase pointer
2702 name is @samp{$vb} followed by a type reference to the virtual base class.
2703 Since the type id for @code{B} in this example is 25, the vbase pointer name
2706 @c FIXME!! fake linebreaks below
2708 .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,
2709 160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;
2710 2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt:
2711 :32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
2714 Following the name and a semicolon is a type reference describing the
2715 type of the virtual base class pointer, in this case 24. Type 24 was
2716 defined earlier as the type of the @code{B} class @code{this} pointer. The
2717 @code{this} pointer for a class is a pointer to the class type.
2720 .stabs "this:P24=*25=xsB:",64,0,0,8
2723 Finally the field offset part of the vbase pointer field description
2724 shows that the vbase pointer is the first field in the @code{D} object,
2725 before any data fields defined by the class. The layout of a @code{D}
2726 class object is a follows, @code{Adat} at 0, the vtable pointer for
2727 @code{A} at 32, @code{Cdat} at 64, the vtable pointer for C at 96, the
2728 virtual base pointer for @code{B} at 128, and @code{Ddat} at 160.
2731 @node Static Members
2732 @section Static Members
2734 The data area for a class is a concatenation of the space used by the
2735 data members of the class. If the class has virtual methods, a vtable
2736 pointer follows the class data. The field offset part of each field
2737 description in the class stab shows this ordering.
2739 << How is this reflected in stabs? See Cygnus bug #677 for some info. >>
2742 @appendix Source code for extended example
2746 2 register int g_bar asm ("%g5");
2747 3 static int s_g_repeat = 2;
2753 9 char s_char_vec[8];
2754 10 struct s_tag* s_next;
2757 13 typedef struct s_tag s_typedef;
2759 15 char char_vec[3] = @{'a','b','c'@};
2761 17 main (argc, argv)
2765 21 static float s_flap;
2767 23 for (times=0; times < s_g_repeat; times++)@{
2769 25 printf ("Hello world\n");
2773 29 enum e_places @{first,second=3,last@};
2775 31 static s_proc (s_arg, s_ptr_arg, char_vec)
2777 33 s_typedef* s_ptr_arg;
2791 @appendix Assembly code for extended example
2795 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
2796 3 .stabs "example2.c",100,0,0,Ltext0
2799 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
2800 7 .stabs "char:t2=r2;0;127;",128,0,0,0
2801 8 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
2802 9 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
2803 10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
2804 11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
2805 12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
2806 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
2807 14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
2808 15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
2809 16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
2810 17 .stabs "float:t12=r1;4;0;",128,0,0,0
2811 18 .stabs "double:t13=r1;8;0;",128,0,0,0
2812 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
2813 20 .stabs "void:t15=15",128,0,0,0
2814 21 .stabs "g_foo:G2",32,0,0,0
2819 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
2823 @c FIXME! fake linebreak in line 30
2824 30 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;s_char_vec:
2825 17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
2826 31 .stabs "s_typedef:t16",128,0,0,0
2827 32 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
2828 33 .global _char_vec
2834 39 .reserve _s_flap.0,4,"bss",4
2838 43 .ascii "Hello world\12\0"
2843 48 .stabn 68,0,20,LM1
2846 51 save %sp,-144,%sp
2853 58 .stabn 68,0,23,LM2
2857 62 sethi %hi(_s_g_repeat),%o0
2859 64 ld [%o0+%lo(_s_g_repeat)],%o0
2864 69 .stabn 68,0,25,LM3
2866 71 sethi %hi(LC0),%o1
2867 72 or %o1,%lo(LC0),%o0
2870 75 .stabn 68,0,26,LM4
2873 78 .stabn 68,0,23,LM5
2881 86 .stabn 68,0,27,LM6
2884 89 .stabn 68,0,27,LM7
2889 94 .stabs "main:F1",36,0,0,_main
2890 95 .stabs "argc:p1",160,0,0,68
2891 96 .stabs "argv:p20=*21=*2",160,0,0,72
2892 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
2893 98 .stabs "times:1",128,0,0,-20
2894 99 .stabn 192,0,0,LBB2
2895 100 .stabs "inner:1",128,0,0,-24
2896 101 .stabn 192,0,0,LBB3
2897 102 .stabn 224,0,0,LBE3
2898 103 .stabn 224,0,0,LBE2
2899 104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
2900 @c FIXME: fake linebreak in line 105
2901 105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
2906 109 .stabn 68,0,35,LM8
2909 112 save %sp,-120,%sp
2915 118 .stabn 68,0,41,LM9
2918 121 .stabn 68,0,41,LM10
2923 126 .stabs "s_proc:f1",36,0,0,_s_proc
2924 127 .stabs "s_arg:p16",160,0,0,0
2925 128 .stabs "s_ptr_arg:p18",160,0,0,72
2926 129 .stabs "char_vec:p21",160,0,0,76
2927 130 .stabs "an_u:23",128,0,0,-20
2928 131 .stabn 192,0,0,LBB4
2929 132 .stabn 224,0,0,LBE4
2930 133 .stabs "g_bar:r1",64,0,0,5
2931 134 .stabs "g_pf:G24=*25=f1",32,0,0,0
2932 135 .common _g_pf,4,"bss"
2933 136 .stabs "g_an_s:G16",32,0,0,0
2934 137 .common _g_an_s,20,"bss"
2938 @appendix Table of stab types
2940 The following are all the possible values for the stab type field, for
2941 @code{a.out} files, in numeric order. This does not apply to XCOFF.
2943 The symbolic names are defined in the file @file{include/aout/stabs.def}.
2946 * Non-stab symbol types:: Types from 0 to 0x1f
2947 * Stab symbol types:: Types from 0x20 to 0xff
2950 @node Non-stab symbol types
2951 @appendixsec Non-stab symbol types
2953 The following types are used by the linker and assembler, not by stab
2954 directives. Since this document does not attempt to describe aspects of
2955 object file format other than the debugging format, no details are
2958 @c Try to get most of these to fit on a single line.
2968 File scope absolute symbol
2970 @item 0x3 N_ABS | N_EXT
2971 External absolute symbol
2974 File scope text symbol
2976 @item 0x5 N_TEXT | N_EXT
2977 External text symbol
2980 File scope data symbol
2982 @item 0x7 N_DATA | N_EXT
2983 External data symbol
2986 File scope BSS symbol
2988 @item 0x9 N_BSS | N_EXT
2992 Same as @code{N_FN}, for Sequent compilers
2995 Symbol is indirected to another symbol
2998 Common---visible after shared library dynamic link
3001 Absolute set element
3004 Text segment set element
3007 Data segment set element
3010 BSS segment set element
3013 Pointer to set vector
3015 @item 0x1e N_WARNING
3016 Print a warning message during linking
3019 File name of a @file{.o} file
3022 @node Stab symbol types
3023 @appendixsec Stab symbol types
3025 The following symbol types indicate that this is a stab. This is the
3026 full list of stab numbers, including stab types that are used in
3027 languages other than C.
3031 Global symbol; see @ref{N_GSYM}.
3034 Function name (for BSD Fortran); see @ref{N_FNAME}.
3037 Function name (@pxref{Procedures}) or text segment variable
3041 Data segment file-scope variable; see @ref{Statics}.
3044 BSS segment file-scope variable; see @ref{Statics}.
3047 Name of main routine; see @ref{Main Program}.
3049 @c FIXME: discuss this in the Statics node where we talk about
3050 @c the fact that the n_type indicates the section.
3052 Variable in @code{.rodata} section; see @ref{Statics}.
3055 Global symbol (for Pascal); see @ref{N_PC}.
3058 Number of symbols (according to Ultrix V4.0); see @ref{N_NSYMS}.
3061 No DST map; see @ref{N_NOMAP}.
3063 @c FIXME: describe this solaris feature in the body of the text (see
3064 @c comments in include/aout/stab.def).
3066 Object file (Solaris2).
3068 @c See include/aout/stab.def for (a little) more info.
3070 Debugger options (Solaris2).
3073 Register variable; see @ref{N_RSYM}.
3076 Modula-2 compilation unit; see @ref{N_M2C}.
3079 Line number in text segment; see @ref{Line Numbers}.
3082 Line number in data segment; see @ref{Line Numbers}.
3085 Line number in bss segment; see @ref{Line Numbers}.
3088 Sun source code browser, path to @file{.cb} file; see @ref{N_BROWS}.
3091 GNU Modula2 definition module dependency; see @ref{N_DEFD}.
3094 Function start/body/end line numbers (Solaris2).
3097 GNU C++ exception variable; see @ref{N_EHDECL}.
3100 Modula2 info "for imc" (according to Ultrix V4.0); see @ref{N_MOD2}.
3103 GNU C++ @code{catch} clause; see @ref{N_CATCH}.
3106 Structure of union element; see @ref{N_SSYM}.
3109 Last stab for module (Solaris2).
3112 Path and name of source file; see @ref{Source Files}.
3115 Stack variable (@pxref{Stack Variables}) or type (@pxref{Typedefs}).
3118 Beginning of an include file (Sun only); see @ref{Include Files}.
3121 Name of include file; see @ref{Include Files}.
3124 Parameter variable; see @ref{Parameters}.
3127 End of an include file; see @ref{Include Files}.
3130 Alternate entry point; see @ref{N_ENTRY}.
3133 Beginning of a lexical block; see @ref{Block Structure}.
3136 Place holder for a deleted include file; see @ref{Include Files}.
3139 Modula2 scope information (Sun linker); see @ref{N_SCOPE}.
3142 End of a lexical block; see @ref{Block Structure}.
3145 Begin named common block; see @ref{Common Blocks}.
3148 End named common block; see @ref{Common Blocks}.
3151 Member of a common block; see @ref{Common Blocks}.
3153 @c FIXME: How does this really work? Move it to main body of document.
3155 Pascal @code{with} statement: type,,0,0,offset (Solaris2).
3158 Gould non-base registers; see @ref{Gould}.
3161 Gould non-base registers; see @ref{Gould}.
3164 Gould non-base registers; see @ref{Gould}.
3167 Gould non-base registers; see @ref{Gould}.
3170 Gould non-base registers; see @ref{Gould}.
3173 @c Restore the default table indent
3178 @node Symbol Descriptors
3179 @appendix Table of Symbol Descriptors
3181 These tell in the @code{.stabs} @var{string} field what kind of symbol
3182 the stab represents. They follow the colon which follows the symbol
3183 name. @xref{String Field}, for more information about their use.
3185 @c Please keep this alphabetical
3187 @c In TeX, this looks great, digit is in italics. But makeinfo insists
3188 @c on putting it in `', not realizing that @var should override @code.
3189 @c I don't know of any way to make makeinfo do the right thing. Seems
3190 @c like a makeinfo bug to me.
3194 Variable on the stack; see @ref{Stack Variables}.
3197 Parameter passed by reference in register; see @ref{Parameters}.
3200 Constant; see @ref{Constants}.
3203 Conformant array bound (Pascal, maybe other languages),
3204 @xref{Parameters}. Name of a caught exception (GNU C++). These can be
3205 distinguished because the latter uses N_CATCH and the former uses
3206 another symbol type.
3209 Floating point register variable; see @ref{Register variables}.
3212 Parameter in floating point register; see @ref{Parameters}.
3215 File scope function; see @ref{Procedures}.
3218 Global function; see @ref{Procedures}.
3221 Global variable; see @ref{Global Variables}.
3227 Internal (nested) procedure; see @ref{Procedures}.
3230 Internal (nested) function; see @ref{Procedures}.
3233 Label name (documented by AIX, no further information known).
3236 Module; see @ref{Procedures}.
3239 Argument list parameter; see @ref{Parameters}.
3245 Fortran Function parameter; see @ref{Parameters}.
3248 Unfortunately, three separate meanings have been independently invented
3249 for this symbol descriptor. At least the GNU and Sun uses can be
3250 distinguished by the symbol type. Global Procedure (AIX) (symbol type
3251 used unknown); see @ref{Procedures}. Register parameter (GNU) (symbol type
3252 N_PSYM); see @ref{Parameters}. Prototype of function referenced by this
3253 file (Sun acc) (symbol type N_FUN).
3256 Static Procedure; see @ref{Procedures}.
3259 Register parameter @xref{Parameters}.
3262 Register variable; see @ref{Register variables}.
3265 File scope variable; see @ref{Statics}.
3268 Type name; see @ref{Typedefs}.
3271 enumeration, struct or union tag; see @ref{Typedefs}.
3274 Parameter passed by reference; see @ref{Parameters}.
3277 Procedure scope static variable; see @ref{Statics}.
3280 Conformant array; see @ref{Parameters}.
3283 Function return variable; see @ref{Parameters}.
3286 @node Type Descriptors
3287 @appendix Table of Type Descriptors
3289 These tell in the @code{.stabs} @var{string} field what kind of type is being
3290 defined. They follow the type number and an equals sign.
3291 @xref{Overview}, for more information about their use.
3296 Type reference; see @ref{String Field}.
3299 Reference to builtin type; see @ref{Negative Type Numbers}.
3302 Method (C++); see @ref{Cplusplus}.
3305 Pointer; see @ref{Miscellaneous Types}.
3311 Type Attributes (AIX); see @ref{String Field}. Member (class and variable)
3312 type (GNU C++); see @ref{Cplusplus}.
3315 Array; see @ref{Arrays}.
3318 Open array; see @ref{Arrays}.
3321 Pascal space type (AIX); see @ref{Miscellaneous Types}. Builtin integer
3322 type (Sun); see @ref{Builtin Type Descriptors}.
3325 Volatile-qualified type; see @ref{Miscellaneous Types}.
3328 Complex builtin type; see @ref{Builtin Type Descriptors}.
3331 COBOL Picture type. See AIX documentation for details.
3334 File type; see @ref{Miscellaneous Types}.
3337 N-dimensional dynamic array; see @ref{Arrays}.
3340 Enumeration type; see @ref{Enumerations}.
3343 N-dimensional subarray; see @ref{Arrays}.
3346 Function type; see @ref{Function Types}.
3349 Pascal function parameter; see @ref{Function Types}
3352 Builtin floating point type; see @ref{Builtin Type Descriptors}.
3355 COBOL Group. See AIX documentation for details.
3358 Imported type; see @ref{Cross-references}.
3361 Const-qualified type; see @ref{Miscellaneous Types}.
3364 COBOL File Descriptor. See AIX documentation for details.
3367 Multiple instance type; see @ref{Miscellaneous Types}.
3370 String type; see @ref{Strings}.
3373 Stringptr; see @ref{Strings}.
3376 Opaque type; see @ref{Typedefs}.
3379 Procedure; see @ref{Function Types}.
3382 Packed array; see @ref{Arrays}.
3385 Range type; see @ref{Subranges}.
3388 Builtin floating type; see @ref{Builtin Type Descriptors} (Sun). Pascal
3389 subroutine parameter; see @ref{Function Types} (AIX). Detecting this
3390 conflict is possible with careful parsing (hint: a Pascal subroutine
3391 parameter type will always contain a comma, and a builtin type
3392 descriptor never will).
3395 Structure type; see @ref{Structures}.
3398 Set type; see @ref{Miscellaneous Types}.
3401 Union; see @ref{Unions}.
3404 Variant record. This is a Pascal and Modula-2 feature which is like a
3405 union within a struct in C. See AIX documentation for details.
3408 Wide character; see @ref{Builtin Type Descriptors}.
3411 Cross-reference; see @ref{Cross-references}.
3414 gstring; see @ref{Strings}.
3417 @node Expanded reference
3418 @appendix Expanded reference by stab type
3420 @c FIXME: This appendix should go away, see N_PSYM or N_SO for an example.
3422 For a full list of stab types, and cross-references to where they are
3423 described, see @ref{Stab Types}. This appendix just duplicates certain
3424 information from the main body of this document; eventually the
3425 information will all be in one place.
3429 The first line is the symbol type expressed in decimal, hexadecimal,
3430 and as a #define (see devo/include/aout/stab.def).
3432 The second line describes the language constructs the symbol type
3435 The third line is the stab format with the significant stab fields
3436 named and the rest NIL.
3438 Subsequent lines expand upon the meaning and possible values for each
3439 significant stab field. # stands in for the type descriptor.
3441 Finally, any further information.
3444 * N_GSYM:: Global variable
3445 * N_FNAME:: Function name (BSD Fortran)
3446 * N_PC:: Pascal global symbol
3447 * N_NSYMS:: Number of symbols
3448 * N_NOMAP:: No DST map
3449 * N_RSYM:: Register variable
3450 * N_M2C:: Modula-2 compilation unit
3451 * N_BROWS:: Path to .cb file for Sun source code browser
3452 * N_DEFD:: GNU Modula2 definition module dependency
3453 * N_EHDECL:: GNU C++ exception variable
3454 * N_MOD2:: Modula2 information "for imc"
3455 * N_CATCH:: GNU C++ "catch" clause
3456 * N_SSYM:: Structure or union element
3457 * N_ENTRY:: Alternate entry point
3458 * N_SCOPE:: Modula2 scope information (Sun only)
3459 * Gould:: non-base register symbols used on Gould systems
3460 * N_LENG:: Length of preceding entry
3464 @section 32 - 0x20 - N_GYSM
3469 .stabs "name", N_GSYM, NIL, NIL, NIL
3473 "name" -> "symbol_name:#type"
3477 Only the @var{name} field is significant. The location of the variable is
3478 obtained from the corresponding external symbol.
3481 @section 34 - 0x22 - N_FNAME
3482 Function name (for BSD Fortran)
3485 .stabs "name", N_FNAME, NIL, NIL, NIL
3489 "name" -> "function_name"
3492 Only the "name" field is significant. The location of the symbol is
3493 obtained from the corresponding extern symbol.
3496 @section 48 - 0x30 - N_PC
3497 Global symbol (for Pascal)
3500 .stabs "name", N_PC, NIL, NIL, value
3504 "name" -> "symbol_name" <<?>>
3505 value -> supposedly the line number (stab.def is skeptical)
3509 @file{stabdump.c} says:
3511 global pascal symbol: name,,0,subtype,line
3516 @section 50 - 0x32 - N_NSYMS
3517 Number of symbols (according to Ultrix V4.0)
3520 0, files,,funcs,lines (stab.def)
3524 @section 52 - 0x34 - N_NOMAP
3525 No DST map for symbol (according to Ultrix V4.0). I think this means a
3526 variable has been optimized out.
3529 name, ,0,type,ignored (stab.def)
3533 @section 64 - 0x40 - N_RSYM
3537 .stabs "name:type",N_RSYM,0,RegSize,RegNumber (Sun doc)
3541 @section 66 - 0x42 - N_M2C
3542 Modula-2 compilation unit
3545 .stabs "name", N_M2C, 0, desc, value
3549 "name" -> "unit_name,unit_time_stamp[,code_time_stamp]
3551 value -> 0 (main unit)
3556 @section 72 - 0x48 - N_BROWS
3557 Sun source code browser, path to @file{.cb} file
3560 "path to associated .cb file"
3562 Note: type field value overlaps with N_BSLINE
3565 @section 74 - 0x4a - N_DEFD
3566 GNU Modula2 definition module dependency
3568 GNU Modula-2 definition module dependency. Value is the modification
3569 time of the definition file. Other is non-zero if it is imported with
3570 the GNU M2 keyword @code{%INITIALIZE}. Perhaps @code{N_M2C} can be used
3571 if there are enough empty fields?
3574 @section 80 - 0x50 - N_EHDECL
3575 GNU C++ exception variable <<?>>
3577 "name is variable name"
3579 Note: conflicts with N_MOD2.
3582 @section 80 - 0x50 - N_MOD2
3583 Modula2 info "for imc" (according to Ultrix V4.0)
3585 Note: conflicts with N_EHDECL <<?>>
3588 @section 84 - 0x54 - N_CATCH
3589 GNU C++ @code{catch} clause
3591 GNU C++ @code{catch} clause. Value is its address. Desc is nonzero if
3592 this entry is immediately followed by a CAUGHT stab saying what
3593 exception was caught. Multiple CAUGHT stabs means that multiple
3594 exceptions can be caught here. If Desc is 0, it means all exceptions
3598 @section 96 - 0x60 - N_SSYM
3599 Structure or union element
3601 Value is offset in the structure.
3603 <<?looking at structs and unions in C I didn't see these>>
3606 @section 164 - 0xa4 - N_ENTRY
3608 Alternate entry point.
3609 Value is its address.
3613 @section 196 - 0xc4 - N_SCOPE
3615 Modula2 scope information (Sun linker)
3619 @section Non-base registers on Gould systems
3621 These are used on Gould systems for non-base registers syms.
3623 However, the following values are not the values used by Gould; they are
3624 the values which GNU has been documenting for these values for a long
3625 time, without actually checking what Gould uses. I include these values
3626 only because perhaps some someone actually did something with the GNU
3627 information (I hope not, why GNU knowingly assigned wrong values to
3628 these in the header file is a complete mystery to me).
3631 240 0xf0 N_NBTEXT ??
3632 242 0xf2 N_NBDATA ??
3639 @section - 0xfe - N_LENG
3641 Second symbol entry containing a length-value for the preceding entry.
3642 The value is the length.
3645 @appendix Questions and anomalies
3649 @c I think this is changed in GCC 2.4.5 to put the line number there.
3650 For GNU C stabs defining local and global variables (@code{N_LSYM} and
3651 @code{N_GSYM}), the @var{desc} field is supposed to contain the source
3652 line number on which the variable is defined. In reality the @var{desc}
3653 field is always 0. (This behavior is defined in @file{dbxout.c} and
3654 putting a line number in @var{desc} is controlled by @samp{#ifdef
3655 WINNING_GDB}, which defaults to false). GDB supposedly uses this
3656 information if you say @samp{list @var{var}}. In reality, @var{var} can
3657 be a variable defined in the program and GDB says @samp{function
3658 @var{var} not defined}.
3661 In GNU C stabs, there seems to be no way to differentiate tag types:
3662 structures, unions, and enums (symbol descriptor @samp{T}) and typedefs
3663 (symbol descriptor @samp{t}) defined at file scope from types defined locally
3664 to a procedure or other more local scope. They all use the @code{N_LSYM}
3665 stab type. Types defined at procedure scope are emited after the
3666 @code{N_RBRAC} of the preceding function and before the code of the
3667 procedure in which they are defined. This is exactly the same as
3668 types defined in the source file between the two procedure bodies.
3669 GDB overcompensates by placing all types in block #1, the block for
3670 symbols of file scope. This is true for default, @samp{-ansi} and
3671 @samp{-traditional} compiler options. (Bugs gcc/1063, gdb/1066.)
3674 What ends the procedure scope? Is it the proc block's @code{N_RBRAC} or the
3675 next @code{N_FUN}? (I believe its the first.)
3678 @c FIXME: This should go with the other stuff about global variables.
3679 Global variable stabs don't have location information. This comes
3680 from the external symbol for the same variable. The external symbol
3681 has a leading underbar on the _name of the variable and the stab does
3682 not. How do we know these two symbol table entries are talking about
3683 the same symbol when their names are different? (Answer: the debugger
3684 knows that external symbols have leading underbars).
3686 @c FIXME: This is absurdly vague; there all kinds of differences, some
3687 @c of which are the same between gnu & sun, and some of which aren't.
3688 @c In particular, I'm pretty sure GCC works with Sun dbx by default.
3690 @c Can GCC be configured to output stabs the way the Sun compiler
3691 @c does, so that their native debugging tools work? <NO?> It doesn't by
3692 @c default. GDB reads either format of stab. (GCC or SunC). How about
3696 @node XCOFF-differences
3697 @appendix Differences between GNU stabs in a.out and GNU stabs in XCOFF
3699 @c FIXME: Merge *all* these into the main body of the document.
3700 The AIX/RS6000 native object file format is XCOFF with stabs. This
3701 appendix only covers those differences which are not covered in the main
3702 body of this document.
3706 BSD a.out stab types correspond to AIX XCOFF storage classes. In general
3707 the mapping is @code{N_@var{stabtype}} becomes @code{C_@var{stabtype}}.
3708 Some stab types in a.out are not supported in XCOFF; most of these use
3711 @c FIXME: Get C_* types for the block, figure out whether it is always
3712 @c used (I suspect not), explain clearly, and move to node Statics.
3713 Exception: initialised static @code{N_STSYM} and un-initialized static
3714 @code{N_LCSYM} both map to the @code{C_STSYM} storage class. But the
3715 destinction is preserved because in XCOFF @code{N_STSYM} and
3716 @code{N_LCSYM} must be emited in a named static block. Begin the block
3717 with @samp{.bs s[RW] data_section_name} for @code{N_STSYM} or @samp{.bs
3718 s bss_section_name} for @code{N_LCSYM}. End the block with @samp{.es}.
3720 @c FIXME: I think they are trying to say something about whether the
3721 @c assembler defaults the value to the location counter.
3723 If the XCOFF stab is a @code{N_FUN} (@code{C_FUN}) then follow the
3724 string field with @samp{,.} instead of just @samp{,}.
3727 I think that's it for @file{.s} file differences. They could stand to be
3728 better presented. This is just a list of what I have noticed so far.
3729 There are a @emph{lot} of differences in the information in the symbol
3730 tables of the executable and object files.
3732 Mapping of a.out stab types to XCOFF storage classes:
3735 stab type storage class
3736 -------------------------------
3772 @node Sun-differences
3773 @appendix Differences between GNU stabs and Sun native stabs
3775 @c FIXME: Merge all this stuff into the main body of the document.
3779 GNU C stabs define @emph{all} types, file or procedure scope, as
3780 @code{N_LSYM}. Sun doc talks about using @code{N_GSYM} too.
3783 Sun C stabs use type number pairs in the format (@var{a},@var{b}) where
3784 @var{a} is a number starting with 1 and incremented for each sub-source
3785 file in the compilation. @var{b} is a number starting with 1 and
3786 incremented for each new type defined in the compilation. GNU C stabs
3787 use the type number alone, with no source file number.
3791 @appendix Using stabs with the ELF object file format
3793 The ELF object file format allows tools to create object files with
3794 custom sections containing any arbitrary data. To use stabs in ELF
3795 object files, the tools create two custom sections, a section named
3796 @code{.stab} which contains an array of fixed length structures, one
3797 struct per stab, and a section named @code{.stabstr} containing all the
3798 variable length strings that are referenced by stabs in the @code{.stab}
3799 section. The byte order of the stabs binary data matches the byte order
3800 of the ELF file itself, as determined from the @code{EI_DATA} field in
3801 the @code{e_ident} member of the ELF header.
3803 @c Is "source file" the right term for this concept? We don't mean that
3804 @c there is a separate one for include files (but "object file" or
3805 @c "object module" isn't quite right either; the output from ld -r is a
3806 @c single object file but contains many source files).
3807 The first stab in the @code{.stab} section for each source file is
3808 synthetic, generated entirely by the assembler, with no corresponding
3809 @code{.stab} directive as input to the assembler. This stab contains
3810 the following fields:
3814 Offset in the @code{.stabstr} section to the source filename.
3820 Unused field, always zero.
3823 Count of upcoming symbols, i.e., the number of remaining stabs for this
3827 Size of the string table fragment associated with this source file, in
3831 The @code{.stabstr} section always starts with a null byte (so that string
3832 offsets of zero reference a null string), followed by random length strings,
3833 each of which is null byte terminated.
3835 The ELF section header for the @code{.stab} section has its
3836 @code{sh_link} member set to the section number of the @code{.stabstr}
3837 section, and the @code{.stabstr} section has its ELF section
3838 header @code{sh_type} member set to @code{SHT_STRTAB} to mark it as a
3841 Because the linker does not process the @code{.stab} section in any
3842 special way, none of the addresses in the @code{n_value} field of the
3843 stabs are relocated by the linker. Instead they are relative to the
3844 source file (or some entity smaller than a source file, like a
3845 function). To find the address of each section corresponding to a given
3846 source file, the (compiler? assembler?) puts out symbols giving the
3847 address of each section for a given source file. Since these are normal
3848 ELF symbols, the linker can relocate them correctly. They are
3849 named @code{Bbss.bss} for the bss section, @code{Ddata.data} for
3850 the data section, and @code{Drodata.rodata} for the rodata section. I
3851 haven't yet figured out how the debugger gets the address for the text