2 @setfilename stabs.info
7 * Stabs: (stabs). The "stabs" debugging information format.
13 This document describes the stabs debugging symbol tables.
15 Copyright 1992 Free Software Foundation, Inc.
16 Contributed by Cygnus Support. Written by Julia Menapace.
18 Permission is granted to make and distribute verbatim copies of
19 this manual provided the copyright notice and this permission notice
20 are preserved on all copies.
23 Permission is granted to process this file through Tex and print the
24 results, provided the printed document carries copying permission
25 notice identical to this one except for the removal of this paragraph
26 (this paragraph not being relevant to the printed manual).
29 Permission is granted to copy or distribute modified versions of this
30 manual under the terms of the GPL (for which purpose this text may be
31 regarded as a program in the language TeX).
34 @setchapternewpage odd
37 @title The ``stabs'' debug format
38 @author Julia Menapace
39 @author Cygnus Support
42 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
43 \xdef\manvers{\$Revision$} % For use in headers, footers too
45 \hfill Cygnus Support\par
47 \hfill \TeX{}info \texinfoversion\par
51 @vskip 0pt plus 1filll
52 Copyright @copyright{} 1992 Free Software Foundation, Inc.
53 Contributed by Cygnus Support.
55 Permission is granted to make and distribute verbatim copies of
56 this manual provided the copyright notice and this permission notice
57 are preserved on all copies.
63 @top The "stabs" representation of debugging information
65 This document describes the GNU stabs debugging format in a.out files.
68 * Overview:: Overview of stabs
69 * Program structure:: Encoding of the structure of the program
70 * Constants:: Constants
71 * Example:: A comprehensive example in C
73 * Types:: Type definitions
74 * Symbol tables:: Symbol information in symbol tables
78 * Example2.c:: Source code for extended example
79 * Example2.s:: Assembly code for extended example
80 * Stab types:: Table A: Symbol types from stabs
81 * Assembler types:: Table B: Symbol types from assembler and linker
82 * Symbol Descriptors:: Table C
83 * Type Descriptors:: Table D
84 * Expanded reference:: Reference information by stab type
85 * Questions:: Questions and anomolies
86 * xcoff-differences:: Differences between GNU stabs in a.out
87 and GNU stabs in xcoff
88 * Sun-differences:: Differences between GNU stabs and Sun
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 completely comprehensive for stabs used by
105 C. The lists of symbol descriptors (@pxref{Symbol Descriptors}) and
106 type descriptors (@pxref{Type Descriptors}) are believed to be completely
107 comprehensive. There are known to be stabs for C++ and COBOL which are
108 poorly documented here. Stabs specific to other languages (e.g. Pascal,
109 Modula-2) are probably not as well documented as they should be.
111 Other sources of information on stabs are @cite{dbx and dbxtool
112 interfaces}, 2nd edition, by Sun, circa 1988, and @cite{AIX Version 3.2
113 Files Reference}, Fourth Edition, September 1992, "dbx Stabstring
114 Grammar" in the a.out section, page 2-31. This document is believed to
115 incorporate the information from those two sources except where it
116 explictly directs you to them for more information.
119 * Flow:: Overview of debugging information flow
120 * Stabs Format:: Overview of stab format
121 * C example:: A simple example in C source
122 * Assembly code:: The simple example at the assembly level
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 is translated by the assembler into
130 a @file{.o} file, and then linked with other @file{.o} files and
131 libraries to produce an executable file.
133 With the @samp{-g} option, GCC puts additional debugging information in
134 the @file{.s} file, which is slightly transformed by the assembler and
135 linker, and carried through into the final executable. This debugging
136 information describes features of the source file like line numbers,
137 the types and scopes of variables, and functions, their parameters and
140 For some object file formats, the debugging information is
141 encapsulated in assembler directives known collectively as `stab' (symbol
142 table) directives, 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
145 and 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 what combination of four possible data fields will follow. It
160 is either @code{.stabs} (string), @code{.stabn} (number), or
163 The overall format of each class of stab is:
166 .stabs "@var{string}",@var{type},0,@var{desc},@var{value}
167 .stabn @var{type},0,@var{desc},@var{value}
168 .stabd @var{type},0,@var{desc}
171 In general, in @code{.stabs} the @var{string} field contains name and type
172 information. For @code{.stabd} the value field is implicit and has the value
173 of the current file location. Otherwise the value field often
174 contains a relocatable address, frame pointer offset, or register
175 number, that maps to the source code element described by the stab.
177 The number in the type field gives some basic information about what
178 type of stab this is (or whether it @emph{is} a stab, as opposed to an
179 ordinary symbol). Each possible type number defines a different stab
180 type. The stab type further defines the exact interpretation of, and
181 possible values for, any remaining @code{"@var{string}"}, @var{desc}, or
182 @var{value} fields present in the stab. Table A (@pxref{Stab
183 types,,Table A: Symbol types from stabs}) lists in numeric order the
184 possible type field values for stab directives. The reference section
185 that follows Table A describes the meaning of the fields for each stab
186 type in detail. The examples that follow this overview introduce the
187 stab types in terms of the source code elements they describe.
189 For @code{.stabs} the @code{"@var{string}"} field holds the meat of the
190 debugging information. The generally unstructured nature of this field
191 is what makes stabs extensible. For some stab types the string field
192 contains only a name. For other stab types the contents can be a great
195 The overall format is of the @code{"@var{string}"} field is:
198 "@var{name}@r{[}:@var{symbol_descriptor}@r{]}
199 @r{[}@var{type_number}@r{[}=@var{type_descriptor} @r{@dots{}]]}"
202 @var{name} is the name of the symbol represented by the stab.
203 @var{name} can be omitted, which means the stab represents an unnamed
204 object. For example, @samp{:t10=*2} defines type 10 as a pointer to
205 type 2, but does not give the type a name. Omitting the @var{name}
206 field is supported by AIX dbx and GDB after about version 4.8, but not
209 The @var{symbol_descriptor} following the @samp{:} is an alphabetic
210 character that tells more specifically what kind of symbol the stab
211 represents. If the @var{symbol_descriptor} is omitted, but type
212 information follows, then the stab represents a local variable. For a
213 list of symbol descriptors, see @ref{Symbol Descriptors,,Table C: Symbol
216 The @samp{c} symbol descriptor is an exception in that it is not
217 followed by type information. @xref{Constants}.
219 Type information is either a @var{type_number}, or a
220 @samp{@var{type_number}=}. The @var{type_number} alone is a type
221 reference, referring directly to a type that has already been defined.
223 The @samp{@var{type_number}=} is a type definition, where the number
224 represents a new type which is about to be defined. The type definition
225 may refer to other types by number, and those type numbers may be
226 followed by @samp{=} and nested definitions.
228 In a type definition, if the character that follows the equals sign is
229 non-numeric then it is a @var{type_descriptor}, and tells what kind of
230 type is about to be defined. Any other values following the
231 @var{type_descriptor} vary, depending on the @var{type_descriptor}. If
232 a number follows the @samp{=} then the number is a @var{type_reference}.
233 This is described more thoroughly in the section on types. @xref{Type
234 Descriptors,,Table D: Type Descriptors}, for a list of
235 @var{type_descriptor} values.
237 There is an AIX extension for type attributes. Following the @samp{=}
238 is any number of type attributes. Each one starts with @samp{@@} and
239 ends with @samp{;}. Debuggers, including AIX's dbx, skip any type
240 attributes they do not recognize. GDB 4.9 does not do this--it will
241 ignore the entire symbol containing a type attribute. Hopefully this
242 will be fixed in the next GDB release. Because of a conflict with C++
243 (@pxref{Cplusplus}), new attributes should not be defined which begin
244 with a digit, @samp{(}, or @samp{-}; GDB may be unable to distinguish
245 those from the C++ type descriptor @samp{@@}. The attributes are:
248 @item a@var{boundary}
249 @var{boundary} is an integer specifying the alignment. I assume it
250 applies to all variables of this type.
253 Size in bits of a variable of this type.
256 Pointer class (for checking). Not sure what this means, or how
257 @var{integer} is interpreted.
260 Indicate this is a packed type, meaning that structure fields or array
261 elements are placed more closely in memory, to save memory at the
265 All this can make the @code{"@var{string}"} field quite long. All
266 versions of GDB, and some versions of DBX, can handle arbitrarily long
267 strings. But many versions of DBX cretinously limit the strings to
268 about 80 characters, so compilers which must work with such DBX's need
269 to split the @code{.stabs} directive into several @code{.stabs}
270 directives. Each stab duplicates exactly all but the
271 @code{"@var{string}"} field. The @code{"@var{string}"} field of
272 every stab except the last is marked as continued with a
273 double-backslash at the end. Removing the backslashes and concatenating
274 the @code{"@var{string}"} fields of each stab produces the original,
278 @section A simple example in C source
280 To get the flavor of how stabs describe source information for a C
281 program, let's look at the simple program:
286 printf("Hello world");
290 When compiled with @samp{-g}, the program above yields the following
291 @file{.s} file. Line numbers have been added to make it easier to refer
292 to parts of the @file{.s} file in the description of the stabs that
296 @section The simple example at the assembly level
300 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
301 3 .stabs "hello.c",100,0,0,Ltext0
304 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
305 7 .stabs "char:t2=r2;0;127;",128,0,0,0
306 8 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
307 9 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
308 10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
309 11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
310 12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
311 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
312 14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
313 15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
314 16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
315 17 .stabs "float:t12=r1;4;0;",128,0,0,0
316 18 .stabs "double:t13=r1;8;0;",128,0,0,0
317 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
318 20 .stabs "void:t15=15",128,0,0,0
321 23 .ascii "Hello, world!\12\0"
336 38 sethi %hi(LC0),%o1
337 39 or %o1,%lo(LC0),%o0
348 50 .stabs "main:F1",36,0,0,_main
349 51 .stabn 192,0,0,LBB2
350 52 .stabn 224,0,0,LBE2
353 This simple ``hello world'' example demonstrates several of the stab
354 types used to describe C language source files.
356 @node Program structure
357 @chapter Encoding for the structure of the program
360 * Source file:: The path and name of the source file
367 @section The path and name of the source file
376 The first stabs in the .s file contain the name and path of the source
377 file that was compiled to produce the .s file. This information is
378 contained in two records of stab type N_SO (100).
381 .stabs "path_name", N_SO, NIL, NIL, Code_address_of_program_start
382 .stabs "file_name:", N_SO, NIL, NIL, Code_address_of_program_start
386 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
387 3 .stabs "hello.c",100,0,0,Ltext0
393 @section Line Numbers
402 The start of source lines is represented by the @code{N_SLINE} (68) stab
406 .stabn N_SLINE, NIL, @var{line}, @var{address}
409 @var{line} is a source line number; @var{address} represents the code
410 address for the start of that source line.
422 All of the following stabs use the @samp{N_FUN} symbol type.
424 A function is represented by a @samp{F} symbol descriptor for a global
425 (extern) function, and @samp{f} for a static (local) function. The next
426 @samp{N_SLINE} symbol can be used to find the line number of the start
427 of the function. The value field is the address of the start of the
428 function. The type information of the stab represents the return type
429 of the function; thus @samp{foo:f5} means that foo is a function
432 The AIX documentation also defines symbol descriptor @samp{J} as an
433 internal function. I assume this means a function nested within another
434 function. It also says Symbol descriptor @samp{m} is a module in
435 Modula-2 or extended Pascal.
437 Procedures (functions which do not return values) are represented as
438 functions returning the void type in C. I don't see why this couldn't
439 be used for all languages (inventing a void type for this purpose if
440 necessary), but the AIX documentation defines @samp{I}, @samp{P}, and
441 @samp{Q} for internal, global, and static procedures, respectively.
442 These symbol descriptors are unusual in that they are not followed by
445 For any of the above symbol descriptors, after the symbol descriptor and
446 the type information, there is optionally a comma, followed by the name
447 of the procedure, followed by a comma, followed by a name specifying the
448 scope. The first name is local to the scope specified. I assume then
449 that the name of the symbol (before the @samp{:}), if specified, is some
450 sort of global name. I assume the name specifying the scope is the name
451 of a function specifying that scope. This feature is an AIX extension,
452 and this information is based on the manual; I haven't actually tried
455 The stab representing a procedure is located immediately following the
456 code of the procedure. This stab is in turn directly followed by a
457 group of other stabs describing elements of the procedure. These other
458 stabs describe the procedure's parameters, its block local variables and
466 The @code{.stabs} entry after this code fragment shows the @var{name} of
467 the procedure (@code{main}); the type descriptor @var{desc} (@code{F},
468 for a global procedure); a reference to the predefined type @code{int}
469 for the return type; and the starting @var{address} of the procedure.
471 Here is an exploded summary (with whitespace introduced for clarity),
472 followed by line 50 of our sample assembly output, which has this form:
476 @var{desc} @r{(global proc @samp{F})}
477 @var{return_type_ref} @r{(int)}
483 50 .stabs "main:F1",36,0,0,_main
486 @node Block Structure
487 @section Block Structure
493 @code{N_LBRAC}, @code{N_RBRAC}
496 The program's block structure is represented by the @code{N_LBRAC} (left
497 brace) and the @code{N_RBRAC} (right brace) stab types. The following code
498 range, which is the body of @code{main}, is labeled with @samp{LBB2:} at the
499 beginning and @samp{LBE2:} at the end.
503 38 sethi %hi(LC0),%o1
504 39 or %o1,%lo(LC0),%o0
512 The @code{N_LBRAC} and @code{N_RBRAC} stabs that describe the block
513 scope of the procedure are located after the @code{N_FUNC} stab that
514 represents the procedure itself. The @code{N_LBRAC} uses the
515 @code{LBB2} label as the code address in its value field, and the
516 @code{N_RBRAC} uses @code{LBE2}.
519 50 .stabs "main:F1",36,0,0,_main
523 .stabn N_LBRAC, NIL, NIL, @var{left-brace-address}
524 .stabn N_RBRAC, NIL, NIL, @var{right-brace-address}
528 51 .stabn 192,0,0,LBB2
529 52 .stabn 224,0,0,LBE2
535 The @samp{c} symbol descriptor indicates that this stab represents a
536 constant. This symbol descriptor is an exception to the general rule
537 that symbol descriptors are followed by type information. Instead, it
538 is followed by @samp{=} and one of the following:
542 Boolean constant. @var{value} is a numeric value; I assume it is 0 for
546 Character constant. @var{value} is the numeric value of the constant.
548 @item e@var{type-information},@var{value}
549 Enumeration constant. @var{type-information} is the type of the
550 constant, as it would appear after a symbol descriptor
551 (@pxref{Stabs Format}). @var{value} is the numeric value of the constant.
554 Integer constant. @var{value} is the numeric value.
557 Real constant. @var{value} is the real value, which can be @samp{INF}
558 (optionally preceded by a sign) for infinity, @samp{QNAN} for a quiet
559 NaN (not-a-number), or @samp{SNAN} for a signalling NaN. If it is a
560 normal number the format is that accepted by the C library function
564 String constant. @var{string} is a string enclosed in either @samp{'}
565 (in which case @samp{'} characters within the string are represented as
566 @samp{\'} or @samp{"} (in which case @samp{"} characters within the
567 string are represented as @samp{\"}).
569 @item S@var{type-information},@var{elements},@var{bits},@var{pattern}
570 Set constant. @var{type-information} is the type of the constant, as it
571 would appear after a symbol descriptor (@pxref{Stabs Format}).
572 @var{elements} is the number of elements in the set (is this just the
573 number of bits set in @var{pattern}? Or redundant with the type? I
574 don't get it), @var{bits} is the number of bits in the constant (meaning
575 it specifies the length of @var{pattern}, I think), and @var{pattern} is
576 a hexadecimal representation of the set. AIX documentation refers to a
577 limit of 32 bytes, but I see no reason why this limit should exist.
580 The boolean, character, string, and set constants are not supported by
581 GDB 4.9, but it will ignore them. GDB 4.8 and earlier gave an error
582 message and refused to read symbols from the file containing the
585 This information is followed by @samp{;}.
588 @chapter A Comprehensive Example in C
590 Now we'll examine a second program, @code{example2}, which builds on the
591 first example to introduce the rest of the stab types, symbol
592 descriptors, and type descriptors used in C.
593 @xref{Example2.c} for the complete @file{.c} source,
594 and @pxref{Example2.s} for the @file{.s} assembly code.
595 This description includes parts of those files.
597 @section Flow of control and nested scopes
603 @code{N_SLINE}, @code{N_LBRAC}, @code{N_RBRAC} (cont.)
606 Consider the body of @code{main}, from @file{example2.c}. It shows more
607 about how @code{N_SLINE}, @code{N_RBRAC}, and @code{N_LBRAC} stabs are used.
611 21 static float s_flap;
613 23 for (times=0; times < s_g_repeat; times++)@{
615 25 printf ("Hello world\n");
620 Here we have a single source line, the @samp{for} line, that generates
621 non-linear flow of control, and non-contiguous code. In this case, an
622 @code{N_SLINE} stab with the same line number proceeds each block of
623 non-contiguous code generated from the same source line.
625 The example also shows nested scopes. The @code{N_LBRAC} and
626 @code{N_LBRAC} stabs that describe block structure are nested in the
627 same order as the corresponding code blocks, those of the for loop
628 inside those for the body of main.
631 This is the label for the @code{N_LBRAC} (left brace) stab marking the
632 start of @code{main}.
639 In the first code range for C source line 23, the @code{for} loop
640 initialize and test, @code{N_SLINE} (68) records the line number:
647 58 .stabn 68,0,23,LM2
651 62 sethi %hi(_s_g_repeat),%o0
653 64 ld [%o0+%lo(_s_g_repeat)],%o0
658 @exdent label for the @code{N_LBRAC} (start block) marking the start of @code{for} loop
661 69 .stabn 68,0,25,LM3
663 71 sethi %hi(LC0),%o1
664 72 or %o1,%lo(LC0),%o0
667 75 .stabn 68,0,26,LM4
670 @exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
676 Now we come to the second code range for source line 23, the @code{for}
677 loop increment and return. Once again, @code{N_SLINE} (68) records the
681 .stabn, N_SLINE, NIL,
685 78 .stabn 68,0,23,LM5
693 86 .stabn 68,0,27,LM6
696 @exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
699 89 .stabn 68,0,27,LM7
704 94 .stabs "main:F1",36,0,0,_main
705 95 .stabs "argc:p1",160,0,0,68
706 96 .stabs "argv:p20=*21=*2",160,0,0,72
707 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
708 98 .stabs "times:1",128,0,0,-20
712 Here is an illustration of stabs describing nested scopes. The scope
713 nesting is reflected in the nested bracketing stabs (@code{N_LBRAC},
717 .stabn N_LBRAC,NIL,NIL,
718 @var{block-start-address}
720 99 .stabn 192,0,0,LBB2 ## begin proc label
721 100 .stabs "inner:1",128,0,0,-24
722 101 .stabn 192,0,0,LBB3 ## begin for label
726 @code{N_RBRAC} (224), ``right brace'' ends a lexical block (scope).
729 .stabn N_RBRAC,NIL,NIL,
730 @var{block-end-address}
732 102 .stabn 224,0,0,LBE3 ## end for label
733 103 .stabn 224,0,0,LBE2 ## end proc label
740 * Automatic variables:: locally scoped
742 * Register variables::
743 * Initialized statics::
744 * Un-initialized statics::
748 @node Automatic variables
749 @section Locally scoped automatic variables
756 @item Symbol Descriptor:
760 In addition to describing types, the @code{N_LSYM} stab type also
761 describes locally scoped automatic variables. Refer again to the body
762 of @code{main} in @file{example2.c}. It allocates two automatic
763 variables: @samp{times} is scoped to the body of @code{main}, and
764 @samp{inner} is scoped to the body of the @code{for} loop.
765 @samp{s_flap} is locally scoped but not automatic, and will be discussed
770 21 static float s_flap;
772 23 for (times=0; times < s_g_repeat; times++)@{
774 25 printf ("Hello world\n");
779 The @code{N_LSYM} stab for an automatic variable is located just before the
780 @code{N_LBRAC} stab describing the open brace of the block to which it is
784 @exdent @code{N_LSYM} (128): automatic variable, scoped locally to @code{main}
787 @var{type information}",
789 @var{frame-pointer-offset}
791 98 .stabs "times:1",128,0,0,-20
792 99 .stabn 192,0,0,LBB2 ## begin `main' N_LBRAC
794 @exdent @code{N_LSYM} (128): automatic variable, scoped locally to the @code{for} loop
797 @var{type information}",
799 @var{frame-pointer-offset}
801 100 .stabs "inner:1",128,0,0,-24
802 101 .stabn 192,0,0,LBB3 ## begin `for' loop N_LBRAC
805 The symbol descriptor is omitted for automatic variables. Since type
806 information should being with a digit, @samp{-}, or @samp{(}, only
807 digits, @samp{-}, and @samp{(} are precluded from being used for symbol
808 descriptors by this fact. However, the Acorn RISC machine (ARM) is said
809 to get this wrong: it puts out a mere type definition here, without the
810 preceding @code{@var{typenumber}=}. This is a bad idea; there is no
811 guarantee that type descriptors are distinct from symbol descriptors.
813 @node Global Variables
814 @section Global Variables
821 @item Symbol Descriptor:
825 Global variables are represented by the @code{N_GSYM} stab type. The symbol
826 descriptor, following the colon in the string field, is @samp{G}. Following
827 the @samp{G} is a type reference or type definition. In this example it is a
828 type reference to the basic C type, @code{char}. The first source line in
836 yields the following stab. The stab immediately precedes the code that
837 allocates storage for the variable it describes.
840 @exdent @code{N_GSYM} (32): global symbol
845 N_GSYM, NIL, NIL, NIL
847 21 .stabs "g_foo:G2",32,0,0,0
854 The address of the variable represented by the @code{N_GSYM} is not contained
855 in the @code{N_GSYM} stab. The debugger gets this information from the
856 external symbol for the global variable.
858 @node Register variables
859 @section Register variables
861 @c According to an old version of this manual, AIX uses C_RPSYM instead
862 @c of C_RSYM. I am skeptical; this should be verified.
863 Register variables have their own stab type, @code{N_RSYM}, and their
864 own symbol descriptor, @code{r}. The stab's value field contains the
865 number of the register where the variable data will be stored.
867 The value is the register number.
869 AIX defines a separate symbol descriptor @samp{d} for floating point
870 registers. This seems incredibly stupid--why not just just give
871 floating point registers different register numbers? I have not
872 verified whether the compiler actually uses @samp{d}.
874 If the register is explicitly allocated to a global variable, but not
878 register int g_bar asm ("%g5");
881 the stab may be emitted at the end of the object file, with
882 the other bss symbols.
884 @node Initialized statics
885 @section Initialized static variables
892 @item Symbol Descriptors:
893 @code{S} (file scope), @code{V} (procedure scope)
896 Initialized static variables are represented by the @code{N_STSYM} stab
897 type. The symbol descriptor part of the string field shows if the
898 variable is file scope static (@samp{S}) or procedure scope static
899 (@samp{V}). The source line
902 3 static int s_g_repeat = 2;
906 yields the following code. The stab is located immediately preceding
907 the storage for the variable it represents. Since the variable in
908 this example is file scope static the symbol descriptor is @samp{S}.
911 @exdent @code{N_STSYM} (38): initialized static variable (data seg w/internal linkage)
919 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
926 @node Un-initialized statics
927 @section Un-initialized static variables
934 @item Symbol Descriptors:
935 @code{S} (file scope), @code{V} (procedure scope)
938 Un-initialized static variables are represented by the @code{N_LCSYM}
939 stab type. The symbol descriptor part of the string shows if the
940 variable is file scope static (@samp{S}) or procedure scope static
941 (@samp{V}). In this example it is procedure scope static. The source
942 line allocating @code{s_flap} immediately follows the open brace for the
943 procedure @code{main}.
947 21 static float s_flap;
950 The code that reserves storage for the variable @code{s_flap} precedes the
951 body of body of @code{main}.
954 39 .reserve _s_flap.0,4,"bss",4
957 But since @code{s_flap} is scoped locally to @code{main}, its stab is
958 located with the other stabs representing symbols local to @code{main}.
959 The stab for @code{s_flap} is located just before the @code{N_LBRAC} for
963 @exdent @code{N_LCSYM} (40): uninitialized static var (BSS seg w/internal linkage)
971 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
972 98 .stabs "times:1",128,0,0,-20
973 99 .stabn 192,0,0,LBB2 # N_LBRAC for main.
976 @c ............................................................
981 The symbol descriptor @samp{p} is used to refer to parameters which are
982 in the arglist. Symbols have symbol type @samp{N_PSYM}. The value of
983 the symbol is the offset relative to the argument list.
985 If the parameter is passed in a register, then the traditional way to do
986 this is to provide two symbols for each argument:
989 .stabs "arg:p1" . . . ; N_PSYM
990 .stabs "arg:r1" . . . ; N_RSYM
993 Debuggers are expected to use the second one to find the value, and the
994 first one to know that it is an argument.
996 Because this is kind of ugly, some compilers use symbol descriptor
997 @samp{P} or @samp{R} to indicate an argument which is in a register.
998 The symbol value is the register number. @samp{P} and @samp{R} mean the
999 same thing, the difference is that @samp{P} is a GNU invention and
1000 @samp{R} is an IBM (xcoff) invention. As of version 4.9, GDB should
1001 handle either one. Symbol type @samp{C_RPSYM} is used with @samp{R} and
1002 @samp{N_RSYM} is used with @samp{P}.
1004 AIX, according to the documentation, uses @samp{D} for a parameter
1005 passed in a floating point register. This strikes me as incredibly
1006 bogus---why doesn't it just use @samp{R} with a register number which
1007 indicates that it's a floating point register? I haven't verified
1008 whether the system actually does what the documentation indicates.
1010 There is at least one case where GCC uses a @samp{p}/@samp{r} pair
1011 rather than @samp{P}; this is where the argument is passed in the
1012 argument list and then loaded into a register.
1014 On the sparc and hppa, for a @samp{P} symbol whose type is a structure
1015 or union, the register contains the address of the structure. On the
1016 sparc, this is also true of a @samp{p}/@samp{r} pair (using Sun cc) or a
1017 @samp{p} symbol. However, if a (small) structure is really in a
1018 register, @samp{r} is used. And, to top it all off, on the hppa it
1019 might be a structure which was passed on the stack and loaded into a
1020 register and for which there is a @samp{p}/@samp{r} pair! I believe
1021 that symbol descriptor @samp{i} is supposed to deal with this case, (it
1022 is said to mean "value parameter by reference, indirect access", I don't
1023 know the source for this information) but I don't know details or what
1024 compilers or debuggers use it, if any (not GDB or GCC). It is not clear
1025 to me whether this case needs to be dealt with differently than
1026 parameters passed by reference (see below).
1028 There is another case similar to an argument in a register, which is an
1029 argument which is actually stored as a local variable. Sometimes this
1030 happens when the argument was passed in a register and then the compiler
1031 stores it as a local variable. If possible, the compiler should claim
1032 that it's in a register, but this isn't always done. Some compilers use
1033 the pair of symbols approach described above ("arg:p" followed by
1034 "arg:"); this includes gcc1 (not gcc2) on the sparc when passing a small
1035 structure and gcc2 (sometimes) when the argument type is float and it is
1036 passed as a double and converted to float by the prologue (in the latter
1037 case the type of the "arg:p" symbol is double and the type of the "arg:"
1038 symbol is float). GCC, at least on the 960, uses a single @samp{p}
1039 symbol descriptor for an argument which is stored as a local variable
1040 but uses @samp{N_LSYM} instead of @samp{N_PSYM}. In this case the value
1041 of the symbol is an offset relative to the local variables for that
1042 function, not relative to the arguments (on some machines those are the
1043 same thing, but not on all).
1045 If the parameter is passed by reference (e.g. Pascal VAR parameters),
1046 then type symbol descriptor is @samp{v} if it is in the argument list,
1047 or @samp{a} if it in a register. Other than the fact that these contain
1048 the address of the parameter other than the parameter itself, they are
1049 identical to @samp{p} and @samp{R}, respectively. I believe @samp{a} is
1050 an AIX invention; @samp{v} is supported by all stabs-using systems as
1053 @c Is this paragraph correct? It is based on piecing together patchy
1054 @c information and some guesswork
1055 Conformant arrays refer to a feature of Modula-2, and perhaps other
1056 languages, in which the size of an array parameter is not known to the
1057 called function until run-time. Such parameters have two stabs, a
1058 @samp{x} for the array itself, and a @samp{C}, which represents the size
1059 of the array. The value of the @samp{x} stab is the offset in the
1060 argument list where the address of the array is stored (it this right?
1061 it is a guess); the value of the @samp{C} stab is the offset in the
1062 argument list where the size of the array (in elements? in bytes?) is
1065 The following are also said to go with @samp{N_PSYM}:
1068 "name" -> "param_name:#type"
1070 -> pF FORTRAN function parameter
1071 -> X (function result variable)
1072 -> b (based variable)
1074 value -> offset from the argument pointer (positive).
1077 As a simple example, the code
1089 .stabs "main:F1",36,0,0,_main ; 36 is N_FUN
1090 .stabs "argc:p1",160,0,0,68 ; 160 is N_PSYM
1091 .stabs "argv:p20=*21=*2",160,0,0,72
1094 The type definition of argv is interesting because it contains several
1095 type definitions. Type 21 is pointer to type 2 (char) and argv (type 20) is
1099 @chapter Type definitions
1101 Now let's look at some variable definitions involving complex types.
1102 This involves understanding better how types are described. In the
1103 examples so far types have been described as references to previously
1104 defined types or defined in terms of subranges of or pointers to
1105 previously defined types. The section that follows will talk about
1106 the various other type descriptors that may follow the = sign in a
1110 * Builtin types:: Integers, floating point, void, etc.
1111 * Miscellaneous Types:: Pointers, sets, files, etc.
1112 * Cross-references:: Referring to a type not yet defined.
1113 * Subranges:: A type with a specific range.
1114 * Arrays:: An aggregate type of same-typed elements.
1115 * Strings:: Like an array but also has a length.
1116 * Enumerations:: Like an integer but the values have names.
1117 * Structures:: An aggregate type of different-typed elements.
1118 * Typedefs:: Giving a type a name
1124 @section Builtin types
1126 Certain types are built in (@code{int}, @code{short}, @code{void},
1127 @code{float}, etc.); the debugger recognizes these types and knows how
1128 to handle them. Thus don't be surprised if some of the following ways
1129 of specifying builtin types do not specify everything that a debugger
1130 would need to know about the type---in some cases they merely specify
1131 enough information to distinguish the type from other types.
1133 The traditional way to define builtin types is convolunted, so new ways
1134 have been invented to describe them. Sun's ACC uses the @samp{b} and
1135 @samp{R} type descriptors, and IBM uses negative type numbers. GDB can
1136 accept all three, as of version 4.8; dbx just accepts the traditional
1137 builtin types and perhaps one of the other two formats.
1140 * Traditional Builtin Types:: Put on your seatbelts and prepare for kludgery
1141 * Builtin Type Descriptors:: Builtin types with special type descriptors
1142 * Negative Type Numbers:: Builtin types using negative type numbers
1145 @node Traditional Builtin Types
1146 @subsection Traditional Builtin types
1148 Often types are defined as subranges of themselves. If the array bounds
1149 can fit within an @code{int}, then they are given normally. For example:
1152 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0 ; 128 is N_LSYM
1153 .stabs "char:t2=r2;0;127;",128,0,0,0
1156 Builtin types can also be described as subranges of @code{int}:
1159 .stabs "unsigned short:t6=r1;0;65535;",128,0,0,0
1162 If the upper bound of a subrange is -1, it means that the type is an
1163 integral type whose bounds are too big to describe in an int.
1164 Traditionally this is only used for @code{unsigned int} and
1165 @code{unsigned long}; GCC also uses it for @code{long long} and
1166 @code{unsigned long long}, and the only way to tell those types apart is
1167 to look at their names. On other machines GCC puts out bounds in octal,
1168 with a leading 0. In this case a negative bound consists of a number
1169 which is a 1 bit followed by a bunch of 0 bits, and a positive bound is
1170 one in which a bunch of bits are 1.
1173 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
1174 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
1177 If the upper bound of a subrange is 0, it means that this is a floating
1178 point type, and the lower bound of the subrange indicates the number of
1182 .stabs "float:t12=r1;4;0;",128,0,0,0
1183 .stabs "double:t13=r1;8;0;",128,0,0,0
1186 However, GCC writes @code{long double} the same way it writes
1187 @code{double}; the only way to distinguish them is by the name:
1190 .stabs "long double:t14=r1;8;0;",128,0,0,0
1193 Complex types are defined the same way as floating-point types; the only
1194 way to distinguish a single-precision complex from a double-precision
1195 floating-point type is by the name.
1197 The C @code{void} type is defined as itself:
1200 .stabs "void:t15=15",128,0,0,0
1203 I'm not sure how a boolean type is represented.
1205 @node Builtin Type Descriptors
1206 @subsection Defining Builtin Types using Builtin Type Descriptors
1208 There are various type descriptors to define builtin types:
1211 @c FIXME: clean up description of width and offset, once we figure out
1213 @item b @var{signed} @var{char-flag} @var{width} ; @var{offset} ; @var{nbits} ;
1214 Define an integral type. @var{signed} is @samp{u} for unsigned or
1215 @samp{s} for signed. @var{char-flag} is @samp{c} which indicates this
1216 is a character type, or is omitted. I assume this is to distinguish an
1217 integral type from a character type of the same size, for example it
1218 might make sense to set it for the C type @code{wchar_t} so the debugger
1219 can print such variables differently (Solaris does not do this). Sun
1220 sets it on the C types @code{signed char} and @code{unsigned char} which
1221 arguably is wrong. @var{width} and @var{offset} appear to be for small
1222 objects stored in larger ones, for example a @code{short} in an
1223 @code{int} register. @var{width} is normally the number of bytes in the
1224 type. @var{offset} seems to always be zero. @var{nbits} is the number
1225 of bits in the type.
1227 Note that type descriptor @samp{b} used for builtin types conflicts with
1228 its use for Pascal space types (@pxref{Miscellaneous Types}); they can
1229 be distinguished because the character following the type descriptor
1230 will be a digit, @samp{(}, or @samp{-} for a Pascal space type, or
1231 @samp{u} or @samp{s} for a builtin type.
1234 Documented by AIX to define a wide character type, but their compiler
1235 actually uses negative type numbers (@pxref{Negative Type Numbers}).
1237 @item R @var{fp_type} ; @var{bytes} ;
1238 Define a floating point type. @var{fp_type} has one of the following values:
1242 IEEE 32-bit (single precision) floating point format.
1245 IEEE 64-bit (double precision) floating point format.
1247 @item 3 (NF_COMPLEX)
1248 @item 4 (NF_COMPLEX16)
1249 @item 5 (NF_COMPLEX32)
1250 These are for complex numbers. A comment in
1251 @file{include/aout/stab_gnu.h} describes them as Fortran complex, double
1252 complex, and complex*16, respectively, but what does that mean? (i.e.
1253 Single precision? Double precison?).
1255 @item 6 (NF_LDOUBLE)
1256 Long double. It would be cleaner to define a different code for every
1257 possible format of long double.
1260 @var{bytes} is the number of bytes occupied by the type. This allows a
1261 debugger to perform some operations with the type even if it doesn't
1262 understand @var{fp_code}.
1264 @item g @var{type-information} ; @var{nbits}
1265 Documented by AIX to define a floating type, but their compiler actually
1266 uses negative type numbers (@pxref{Negative Type Numbers}).
1268 @item c @var{type-information} ; @var{nbits}
1269 Documented by AIX to define a complex type, but their compiler actually
1270 uses negative type numbers (@pxref{Negative Type Numbers}).
1273 The C @code{void} type is defined as a signed integral type 0 bits long:
1275 .stabs "void:t19=bs0;0;0",128,0,0,0
1278 I'm not sure how a boolean type is represented.
1280 @node Negative Type Numbers
1281 @subsection Negative Type numbers
1283 Since the debugger knows about the builtin types anyway, the idea of
1284 negative type numbers is simply to give a special type number which
1285 indicates the built in type. There is no stab defining these types.
1287 I'm not sure whether anyone has tried to define what this means if
1288 @code{int} can be other than 32 bits (or other types can be other than
1289 their customary size). If @code{int} has exactly one size for each
1290 architecture, then it can be handled easily enough, but if the size of
1291 @code{int} can vary according the compiler options, then it gets hairy.
1292 I guess the consistent way to do this would be to define separate
1293 negative type numbers for 16-bit @code{int} and 32-bit @code{int};
1294 therefore I have indicated below the customary size (and other format
1295 information) for each type. The information below is currently correct
1296 because AIX on the RS6000 is the only system which uses these type
1297 numbers. If these type numbers start to get used on other systems, I
1298 suspect the correct thing to do is to define a new number in cases where
1299 a type does not have the size and format indicated below.
1303 @code{int}, 32 bit signed integral type.
1306 @code{char}, 8 bit type holding a character. Both GDB and dbx on AIX
1307 treat this as signed. GCC uses this type whether @code{char} is signed
1308 or not, which seems like a bad idea. The AIX compiler (xlc) seems to
1309 avoid this type; it uses -5 instead for @code{char}.
1312 @code{short}, 16 bit signed integral type.
1315 @code{long}, 32 bit signed integral type.
1318 @code{unsigned char}, 8 bit unsigned integral type.
1321 @code{signed char}, 8 bit signed integral type.
1324 @code{unsigned short}, 16 bit unsigned integral type.
1327 @code{unsigned int}, 32 bit unsigned integral type.
1330 @code{unsigned}, 32 bit unsigned integral type.
1333 @code{unsigned long}, 32 bit unsigned integral type.
1336 @code{void}, type indicating the lack of a value.
1339 @code{float}, IEEE single precision.
1342 @code{double}, IEEE double precision.
1345 @code{long double}, IEEE extended, RS6000 format.
1348 @code{integer}. Pascal, I assume. 32 bit signed integral type.
1351 Boolean. Only one bit is used, not sure about the actual size of the
1355 @code{short real}. Pascal, I assume. IEEE single precision.
1358 @code{real}. Pascal, I assume. IEEE double precision.
1361 A Pascal Stringptr. @xref{Strings}.
1364 @code{character}, 8 bit unsigned type.
1367 @code{logical*1}, 8 bit unsigned integral type.
1370 @code{logical*2}, 16 bit unsigned integral type.
1373 @code{logical*4}, 32 bit unsigned integral type.
1376 @code{logical}, 32 bit unsigned integral type.
1379 A complex type consisting of two IEEE single-precision floating point values.
1382 A complex type consisting of two IEEE double-precision floating point values.
1385 @code{integer*1}, 8 bit signed integral type.
1388 @code{integer*2}, 16 bit signed integral type.
1391 @code{integer*4}, 32 bit signed integral type.
1394 Wide character. AIX appears not to use this for the C type
1395 @code{wchar_t}; instead it uses an integral type of the appropriate
1399 @node Miscellaneous Types
1400 @section Miscellaneous Types
1403 @item b @var{type-information} ; @var{bytes}
1404 Pascal space type. This is documented by IBM; what does it mean?
1406 Note that this use of the @samp{b} type descriptor can be distinguished
1407 from its use for builtin integral types (@pxref{Builtin Type
1408 Descriptors}) because the character following the type descriptor is
1409 always a digit, @samp{(}, or @samp{-}.
1411 @item B @var{type-information}
1412 A volatile-qualified version of @var{type-information}. This is a Sun
1413 extension. A volatile-qualified type means that references and stores
1414 to a variable of that type must not be optimized or cached; they must
1415 occur as the user specifies them.
1417 @item d @var{type-information}
1418 File of type @var{type-information}. As far as I know this is only used
1421 @item k @var{type-information}
1422 A const-qualified version of @var{type-information}. This is a Sun
1423 extension. A const-qualified type means that a variable of this type
1426 @item M @var{type-information} ; @var{length}
1427 Multiple instance type. The type seems to composed of @var{length}
1428 repetitions of @var{type-information}, for example @code{character*3} is
1429 represented by @samp{M-2;3}, where @samp{-2} is a reference to a
1430 character type (@pxref{Negative Type Numbers}). I'm not sure how this
1431 differs from an array. This appears to be a FORTRAN feature.
1432 @var{length} is a bound, like those in range types, @xref{Subranges}.
1434 @item S @var{type-information}
1435 Pascal set type. @var{type-information} must be a small type such as an
1436 enumeration or a subrange, and the type is a bitmask whose length is
1437 specified by the number of elements in @var{type-information}.
1439 @item * @var{type-information}
1440 Pointer to @var{type-information}.
1443 @node Cross-references
1444 @section Cross-references to other types
1446 If a type is used before it is defined, one common way to deal with this
1447 is just to use a type reference to a type which has not yet been
1448 defined. The debugger is expected to be able to deal with this.
1450 Another way is with the @samp{x} type descriptor, which is followed by
1451 @samp{s} for a structure tag, @samp{u} for a union tag, or @samp{e} for
1452 a enumerator tag, followed by the name of the tag, followed by @samp{:}.
1453 for example the following C declarations:
1463 .stabs "bar:G16=*17=xsfoo:",32,0,0,0
1466 Not all debuggers support the @samp{x} type descriptor, so on some
1467 machines GCC does not use it. I believe that for the above example it
1468 would just emit a reference to type 17 and never define it, but I
1469 haven't verified that.
1471 Modula-2 imported types, at least on AIX, use the @samp{i} type
1472 descriptor, which is followed by the name of the module from which the
1473 type is imported, followed by @samp{:}, followed by the name of the
1474 type. There is then optionally a comma followed by type information for
1475 the type (This differs from merely naming the type (@pxref{Typedefs}) in
1476 that it identifies the module; I don't understand whether the name of
1477 the type given here is always just the same as the name we are giving
1478 it, or whether this type descriptor is used with a nameless stab
1479 (@pxref{Stabs Format}), or what). The symbol ends with @samp{;}.
1482 @section Subrange types
1484 The @samp{r} type descriptor defines a type as a subrange of another
1485 type. It is followed by type information for the type which it is a
1486 subrange of, a semicolon, an integral lower bound, a semicolon, an
1487 integral upper bound, and a semicolon. The AIX documentation does not
1488 specify the trailing semicolon; I believe it is confused.
1490 AIX allows the bounds to be one of the following instead of an integer:
1493 @item A @var{offset}
1494 The bound is passed by reference on the stack at offset @var{offset}
1495 from the argument list. @xref{Parameters}, for more information on such
1498 @item T @var{offset}
1499 The bound is passed by value on the stack at offset @var{offset} from
1502 @item a @var{register-number}
1503 The bound is pased by reference in register number
1504 @var{register-number}.
1506 @item t @var{register-number}
1507 The bound is passed by value in register number @var{register-number}.
1513 Subranges are also used for builtin types, @xref{Traditional Builtin Types}.
1516 @section Array types
1518 Arrays use the @samp{a} type descriptor. Following the type descriptor
1519 is the type of the index and the type of the array elements. The two
1520 types types are not separated by any sort of delimiter; if the type of
1521 the index does not end in a semicolon I don't know what is supposed to
1522 happen. IBM documents a semicolon between the two types. For the
1523 common case (a range type), this ends up as being the same since IBM
1524 documents a range type as not ending in a semicolon, but the latter does
1525 not accord with common practice, in which range types do end with
1528 The type of the index is often a range type, expressed as the letter r
1529 and some parameters. It defines the size of the array. In the example
1530 below, the range @code{r1;0;2;} defines an index type which is a
1531 subrange of type 1 (integer), with a lower bound of 0 and an upper bound
1532 of 2. This defines the valid range of subscripts of a three-element C
1535 For example, the definition
1538 char char_vec[3] = @{'a','b','c'@};
1545 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
1554 If an array is @dfn{packed}, it means that the elements are spaced more
1555 closely than normal, saving memory at the expense of speed. For
1556 example, an array of 3-byte objects might, if unpacked, have each
1557 element aligned on a 4-byte boundary, but if packed, have no padding.
1558 One way to specify that something is packed is with type attributes
1559 (@pxref{Stabs Format}), in the case of arrays another is to use the
1560 @samp{P} type descriptor instead of @samp{a}. Other than specifying a
1561 packed array, @samp{P} is identical to @samp{a}.
1563 @c FIXME-what is it? A pointer?
1564 An open array is represented by the @samp{A} type descriptor followed by
1565 type information specifying the type of the array elements.
1567 @c FIXME: what is the format of this type? A pointer to a vector of pointers?
1568 An N-dimensional dynamic array is represented by
1571 D @var{dimensions} ; @var{type-information}
1574 @c Does dimensions really have this meaning? The AIX documentation
1576 @var{dimensions} is the number of dimensions; @var{type-information}
1577 specifies the type of the array elements.
1579 @c FIXME: what is the format of this type? A pointer to some offsets in
1581 A subarray of an N-dimensional array is represented by
1584 E @var{dimensions} ; @var{type-information}
1587 @c Does dimensions really have this meaning? The AIX documentation
1589 @var{dimensions} is the number of dimensions; @var{type-information}
1590 specifies the type of the array elements.
1595 Some languages, like C or the original Pascal, do not have string types,
1596 they just have related things like arrays of characters. But most
1597 Pascals and various other languages have string types, which are
1598 indicated as follows:
1601 @item n @var{type-information} ; @var{bytes}
1602 @var{bytes} is the maximum length. I'm not sure what
1603 @var{type-information} is; I suspect that it means that this is a string
1604 of @var{type-information} (thus allowing a string of integers, a string
1605 of wide characters, etc., as well as a string of characters). Not sure
1606 what the format of this type is. This is an AIX feature.
1608 @item z @var{type-information} ; @var{bytes}
1609 Just like @samp{n} except that this is a gstring, not an ordinary
1610 string. I don't know the difference.
1613 Pascal Stringptr. What is this? This is an AIX feature.
1617 @section Enumerations
1619 Enumerations are defined with the @samp{e} type descriptor.
1621 @c FIXME: Where does this information properly go? Perhaps it is
1622 @c redundant with something we already explain.
1623 The source line below declares an enumeration type. It is defined at
1624 file scope between the bodies of main and s_proc in example2.c.
1625 The type definition is located after the N_RBRAC that marks the end of
1626 the previous procedure's block scope, and before the N_FUN that marks
1627 the beginning of the next procedure's block scope. Therefore it does not
1628 describe a block local symbol, but a file local one.
1633 enum e_places @{first,second=3,last@};
1637 generates the following stab
1640 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
1643 The symbol descriptor (T) says that the stab describes a structure,
1644 enumeration, or type tag. The type descriptor e, following the 22= of
1645 the type definition narrows it down to an enumeration type. Following
1646 the e is a list of the elements of the enumeration. The format is
1647 name:value,. The list of elements ends with a ;.
1649 There is no standard way to specify the size of an enumeration type; it
1650 is determined by the architecture (normally all enumerations types are
1651 32 bits). There should be a way to specify an enumeration type of
1652 another size; type attributes would be one way to do this @xref{Stabs
1662 @code{N_LSYM} or @code{C_DECL}
1663 @item Symbol Descriptor:
1665 @item Type Descriptor:
1669 The following source code declares a structure tag and defines an
1670 instance of the structure in global scope. Then a typedef equates the
1671 structure tag with a new type. A seperate stab is generated for the
1672 structure tag, the structure typedef, and the structure instance. The
1673 stabs for the tag and the typedef are emited when the definitions are
1674 encountered. Since the structure elements are not initialized, the
1675 stab and code for the structure variable itself is located at the end
1676 of the program in .common.
1682 9 char s_char_vec[8];
1683 10 struct s_tag* s_next;
1686 13 typedef struct s_tag s_typedef;
1689 The structure tag is an N_LSYM stab type because, like the enum, the
1690 symbol is file scope. Like the enum, the symbol descriptor is T, for
1691 enumeration, struct or tag type. The symbol descriptor s following
1692 the 16= of the type definition narrows the symbol type to struct.
1694 Following the struct symbol descriptor is the number of bytes the
1695 struct occupies, followed by a description of each structure element.
1696 The structure element descriptions are of the form name:type, bit
1697 offset from the start of the struct, and number of bits in the
1702 <128> N_LSYM - type definition
1703 .stabs "name:sym_desc(struct tag) Type_def(16)=type_desc(struct type)
1705 elem_name:type_ref(int),bit_offset,field_bits;
1706 elem_name:type_ref(float),bit_offset,field_bits;
1707 elem_name:type_def(17)=type_desc(array)
1708 index_type(range of int from 0 to 7);
1709 element_type(char),bit_offset,field_bits;;",
1712 30 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
1713 s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
1716 In this example, two of the structure elements are previously defined
1717 types. For these, the type following the name: part of the element
1718 description is a simple type reference. The other two structure
1719 elements are new types. In this case there is a type definition
1720 embedded after the name:. The type definition for the array element
1721 looks just like a type definition for a standalone array. The s_next
1722 field is a pointer to the same kind of structure that the field is an
1723 element of. So the definition of structure type 16 contains an type
1724 definition for an element which is a pointer to type 16.
1727 @section Giving a type a name
1729 To give a type a name, use the @samp{t} symbol descriptor. For example,
1732 .stabs "s_typedef:t16",128,0,0,0
1735 specifies that @code{s_typedef} refers to type number 16. Such stabs
1736 have symbol type @code{N_LSYM} or @code{C_DECL}.
1738 If instead, you are giving a name to a tag for a structure, union, or
1739 enumeration, use the @samp{T} symbol descriptor instead. I believe C is
1740 the only language with this feature.
1742 If the type is an opaque type (I believe this is a Modula-2 feature),
1743 AIX provides a type descriptor to specify it. The type descriptor is
1744 @samp{o} and is followed by a name. I don't know what the name
1745 means---is it always the same as the name of the type, or is this type
1746 descriptor used with a nameless stab (@pxref{Stabs Format})? There
1747 optionally follows a comma followed by type information which defines
1748 the type of this type. If omitted, a semicolon is used in place of the
1749 comma and the type information, and, the type is much like a generic
1750 pointer type---it has a known size but little else about it is
1756 Next let's look at unions. In example2 this union type is declared
1757 locally to a procedure and an instance of the union is defined.
1767 This code generates a stab for the union tag and a stab for the union
1768 variable. Both use the N_LSYM stab type. Since the union variable is
1769 scoped locally to the procedure in which it is defined, its stab is
1770 located immediately preceding the N_LBRAC for the procedure's block
1773 The stab for the union tag, however is located preceding the code for
1774 the procedure in which it is defined. The stab type is N_LSYM. This
1775 would seem to imply that the union type is file scope, like the struct
1776 type s_tag. This is not true. The contents and position of the stab
1777 for u_type do not convey any infomation about its procedure local
1782 .stabs "name:sym_desc(union tag)type_def(22)=type_desc(union)
1784 elem_name:type_ref(int),bit_offset(0),bit_size(32);
1785 elem_name:type_ref(float),bit_offset(0),bit_size(32);
1786 elem_name:type_ref(ptr to char),bit_offset(0),bit_size(32);;"
1787 N_LSYM, NIL, NIL, NIL
1791 105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
1795 The symbol descriptor, T, following the name: means that the stab
1796 describes an enumeration, struct or type tag. The type descriptor u,
1797 following the 23= of the type definition, narrows it down to a union
1798 type definition. Following the u is the number of bytes in the union.
1799 After that is a list of union element descriptions. Their format is
1800 name:type, bit offset into the union, and number of bytes for the
1803 The stab for the union variable follows. Notice that the frame
1804 pointer offset for local variables is negative.
1807 <128> N_LSYM - local variable (with no symbol descriptor)
1808 .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset
1812 130 .stabs "an_u:23",128,0,0,-20
1815 @node Function types
1816 @section Function types
1818 There are various types for function variables. These types are not
1819 used in defining functions; see symbol descriptor @samp{f}; they are
1820 used for things like pointers to functions.
1822 The simple, traditional, type is type descriptor @samp{f} is followed by
1823 type information for the return type of the function, followed by a
1826 This does not deal with functions the number and type of whose
1827 parameters are part of their type, as found in Modula-2 or ANSI C. AIX
1828 provides extensions to specify these, using the @samp{f}, @samp{F},
1829 @samp{p}, and @samp{R} type descriptors.
1831 First comes the type descriptor. Then, if it is @samp{f} or @samp{F},
1832 this is a function, and the type information for the return type of the
1833 function follows, followed by a comma. Then comes the number of
1834 parameters to the function and a semicolon. Then, for each parameter,
1835 there is the name of the parameter followed by a colon (this is only
1836 present for type descriptors @samp{R} and @samp{F} which represent
1837 Pascal function or procedure parameters), type information for the
1838 parameter, a comma, @samp{0} if passed by reference or @samp{1} if
1839 passed by value, and a semicolon. The type definition ends with a
1849 generates the following code:
1852 .stabs "g_pf:G24=*25=f1",32,0,0,0
1853 .common _g_pf,4,"bss"
1856 The variable defines a new type, 24, which is a pointer to another new
1857 type, 25, which is defined as a function returning int.
1860 @chapter Symbol information in symbol tables
1862 This section examines more closely the format of symbol table entries
1863 and how stab assembler directives map to them. It also describes what
1864 transformations the assembler and linker make on data from stabs.
1866 Each time the assembler encounters a stab in its input file it puts
1867 each field of the stab into corresponding fields in a symbol table
1868 entry of its output file. If the stab contains a string field, the
1869 symbol table entry for that stab points to a string table entry
1870 containing the string data from the stab. Assembler labels become
1871 relocatable addresses. Symbol table entries in a.out have the format:
1874 struct internal_nlist @{
1875 unsigned long n_strx; /* index into string table of name */
1876 unsigned char n_type; /* type of symbol */
1877 unsigned char n_other; /* misc info (usually empty) */
1878 unsigned short n_desc; /* description field */
1879 bfd_vma n_value; /* value of symbol */
1883 For .stabs directives, the n_strx field holds the character offset
1884 from the start of the string table to the string table entry
1885 containing the "string" field. For other classes of stabs (.stabn and
1886 .stabd) this field is null.
1888 Symbol table entries with n_type fields containing a value greater or
1889 equal to 0x20 originated as stabs generated by the compiler (with one
1890 random exception). Those with n_type values less than 0x20 were
1891 placed in the symbol table of the executable by the assembler or the
1894 The linker concatenates object files and does fixups of externally
1895 defined symbols. You can see the transformations made on stab data by
1896 the assembler and linker by examining the symbol table after each pass
1897 of the build, first the assemble and then the link.
1899 To do this use nm with the -ap options. This dumps the symbol table,
1900 including debugging information, unsorted. For stab entries the
1901 columns are: value, other, desc, type, string. For assembler and
1902 linker symbols, the columns are: value, type, string.
1904 There are a few important things to notice about symbol tables. Where
1905 the value field of a stab contains a frame pointer offset, or a
1906 register number, that value is unchanged by the rest of the build.
1908 Where the value field of a stab contains an assembly language label,
1909 it is transformed by each build step. The assembler turns it into a
1910 relocatable address and the linker turns it into an absolute address.
1911 This source line defines a static variable at file scope:
1914 3 static int s_g_repeat
1918 The following stab describes the symbol.
1921 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
1925 The assembler transforms the stab into this symbol table entry in the
1926 @file{.o} file. The location is expressed as a data segment offset.
1929 21 00000084 - 00 0000 STSYM s_g_repeat:S1
1933 in the symbol table entry from the executable, the linker has made the
1934 relocatable address absolute.
1937 22 0000e00c - 00 0000 STSYM s_g_repeat:S1
1940 Stabs for global variables do not contain location information. In
1941 this case the debugger finds location information in the assembler or
1942 linker symbol table entry describing the variable. The source line:
1952 21 .stabs "g_foo:G2",32,0,0,0
1955 The variable is represented by the following two symbol table entries
1956 in the object file. The first one originated as a stab. The second
1957 one is an external symbol. The upper case D signifies that the n_type
1958 field of the symbol table contains 7, N_DATA with local linkage (see
1959 Table B). The value field following the file's line number is empty
1960 for the stab entry. For the linker symbol it contains the
1961 rellocatable address corresponding to the variable.
1964 19 00000000 - 00 0000 GSYM g_foo:G2
1965 20 00000080 D _g_foo
1969 These entries as transformed by the linker. The linker symbol table
1970 entry now holds an absolute address.
1973 21 00000000 - 00 0000 GSYM g_foo:G2
1975 215 0000e008 D _g_foo
1979 @chapter GNU C++ stabs
1982 * Basic Cplusplus types::
1985 * Methods:: Method definition
1987 * Method Modifiers:: (const, volatile, const volatile)
1990 * Virtual Base Classes::
1994 @subsection type descriptors added for C++ descriptions
1998 method type (two ## if minimal debug)
2001 Member (class and variable) type. It is followed by type information
2002 for the offset basetype, a comma, and type information for the type of
2003 the field being pointed to. (FIXME: this is acknowledged to be
2004 gibberish. Can anyone say what really goes here?).
2006 Note that there is a conflict between this and type attributes
2007 (@pxref{Stabs Format}); both use type descriptor @samp{@@}.
2008 Fortunately, the @samp{@@} type descriptor used in this C++ sense always
2009 will be followed by a digit, @samp{(}, or @samp{-}, and type attributes
2010 never start with those things.
2013 @node Basic Cplusplus types
2014 @section Basic types for C++
2016 << the examples that follow are based on a01.C >>
2019 C++ adds two more builtin types to the set defined for C. These are
2020 the unknown type and the vtable record type. The unknown type, type
2021 16, is defined in terms of itself like the void type.
2023 The vtable record type, type 17, is defined as a structure type and
2024 then as a structure tag. The structure has four fields, delta, index,
2025 pfn, and delta2. pfn is the function pointer.
2027 << In boilerplate $vtbl_ptr_type, what are the fields delta,
2028 index, and delta2 used for? >>
2030 This basic type is present in all C++ programs even if there are no
2031 virtual methods defined.
2034 .stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8)
2035 elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16);
2036 elem_name(index):type_ref(short int),bit_offset(16),field_bits(16);
2037 elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void),
2038 bit_offset(32),field_bits(32);
2039 elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;"
2044 .stabs "$vtbl_ptr_type:t17=s8
2045 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;"
2050 .stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL
2054 .stabs "$vtbl_ptr_type:T17",128,0,0,0
2057 @node Simple classes
2058 @section Simple class definition
2060 The stabs describing C++ language features are an extension of the
2061 stabs describing C. Stabs representing C++ class types elaborate
2062 extensively on the stab format used to describe structure types in C.
2063 Stabs representing class type variables look just like stabs
2064 representing C language variables.
2066 Consider the following very simple class definition.
2072 int Ameth(int in, char other);
2076 The class baseA is represented by two stabs. The first stab describes
2077 the class as a structure type. The second stab describes a structure
2078 tag of the class type. Both stabs are of stab type N_LSYM. Since the
2079 stab is not located between an N_FUN and a N_LBRAC stab this indicates
2080 that the class is defined at file scope. If it were, then the N_LSYM
2081 would signify a local variable.
2083 A stab describing a C++ class type is similar in format to a stab
2084 describing a C struct, with each class member shown as a field in the
2085 structure. The part of the struct format describing fields is
2086 expanded to include extra information relevent to C++ class members.
2087 In addition, if the class has multiple base classes or virtual
2088 functions the struct format outside of the field parts is also
2091 In this simple example the field part of the C++ class stab
2092 representing member data looks just like the field part of a C struct
2093 stab. The section on protections describes how its format is
2094 sometimes extended for member data.
2096 The field part of a C++ class stab representing a member function
2097 differs substantially from the field part of a C struct stab. It
2098 still begins with `name:' but then goes on to define a new type number
2099 for the member function, describe its return type, its argument types,
2100 its protection level, any qualifiers applied to the method definition,
2101 and whether the method is virtual or not. If the method is virtual
2102 then the method description goes on to give the vtable index of the
2103 method, and the type number of the first base class defining the
2106 When the field name is a method name it is followed by two colons
2107 rather than one. This is followed by a new type definition for the
2108 method. This is a number followed by an equal sign and then the
2109 symbol descriptor `##', indicating a method type. This is followed by
2110 a type reference showing the return type of the method and a
2113 The format of an overloaded operator method name differs from that
2114 of other methods. It is "op$::XXXX." where XXXX is the operator name
2115 such as + or +=. The name ends with a period, and any characters except
2116 the period can occur in the XXXX string.
2118 The next part of the method description represents the arguments to
2119 the method, preceeded by a colon and ending with a semi-colon. The
2120 types of the arguments are expressed in the same way argument types
2121 are expressed in C++ name mangling. In this example an int and a char
2124 This is followed by a number, a letter, and an asterisk or period,
2125 followed by another semicolon. The number indicates the protections
2126 that apply to the member function. Here the 2 means public. The
2127 letter encodes any qualifier applied to the method definition. In
2128 this case A means that it is a normal function definition. The dot
2129 shows that the method is not virtual. The sections that follow
2130 elaborate further on these fields and describe the additional
2131 information present for virtual methods.
2135 .stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
2136 field_name(Adat):type(int),bit_offset(0),field_bits(32);
2138 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
2139 :arg_types(int char);
2140 protection(public)qualifier(normal)virtual(no);;"
2145 .stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
2147 .stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
2149 .stabs "baseA:T20",128,0,0,0
2152 @node Class instance
2153 @section Class instance
2155 As shown above, describing even a simple C++ class definition is
2156 accomplished by massively extending the stab format used in C to
2157 describe structure types. However, once the class is defined, C stabs
2158 with no modifications can be used to describe class instances. The
2168 yields the following stab describing the class instance. It looks no
2169 different from a standard C stab describing a local variable.
2172 .stabs "name:type_ref(baseA)", N_LSYM, NIL, NIL, frame_ptr_offset
2176 .stabs "AbaseA:20",128,0,0,-20
2180 @section Method defintion
2182 The class definition shown above declares Ameth. The C++ source below
2187 baseA::Ameth(int in, char other)
2194 This method definition yields three stabs following the code of the
2195 method. One stab describes the method itself and following two
2196 describe its parameters. Although there is only one formal argument
2197 all methods have an implicit argument which is the `this' pointer.
2198 The `this' pointer is a pointer to the object on which the method was
2199 called. Note that the method name is mangled to encode the class name
2200 and argument types. << Name mangling is not described by this
2201 document - Is there already such a doc? >>
2204 .stabs "name:symbol_desriptor(global function)return_type(int)",
2205 N_FUN, NIL, NIL, code_addr_of_method_start
2207 .stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic
2210 Here is the stab for the `this' pointer implicit argument. The name
2211 of the `this' pointer is always `this.' Type 19, the `this' pointer is
2212 defined as a pointer to type 20, baseA, but a stab defining baseA has
2213 not yet been emited. Since the compiler knows it will be emited
2214 shortly, here it just outputs a cross reference to the undefined
2215 symbol, by prefixing the symbol name with xs.
2218 .stabs "name:sym_desc(register param)type_def(19)=
2219 type_desc(ptr to)type_ref(baseA)=
2220 type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number
2222 .stabs "this:P19=*20=xsbaseA:",64,0,0,8
2225 The stab for the explicit integer argument looks just like a parameter
2226 to a C function. The last field of the stab is the offset from the
2227 argument pointer, which in most systems is the same as the frame
2231 .stabs "name:sym_desc(value parameter)type_ref(int)",
2232 N_PSYM,NIL,NIL,offset_from_arg_ptr
2234 .stabs "in:p1",160,0,0,72
2237 << The examples that follow are based on A1.C >>
2240 @section Protections
2243 In the simple class definition shown above all member data and
2244 functions were publicly accessable. The example that follows
2245 contrasts public, protected and privately accessable fields and shows
2246 how these protections are encoded in C++ stabs.
2248 Protections for class member data are signified by two characters
2249 embeded in the stab defining the class type. These characters are
2250 located after the name: part of the string. /0 means private, /1
2251 means protected, and /2 means public. If these characters are omited
2252 this means that the member is public. The following C++ source:
2266 generates the following stab to describe the class type all_data.
2269 .stabs "class_name:sym_desc(type)type_def(19)=type_desc(struct)struct_bytes
2270 data_name:/protection(private)type_ref(int),bit_offset,num_bits;
2271 data_name:/protection(protected)type_ref(char),bit_offset,num_bits;
2272 data_name:(/num omited, private)type_ref(float),bit_offset,num_bits;;"
2277 .stabs "all_data:t19=s12
2278 priv_dat:/01,0,32;prot_dat:/12,32,8;pub_dat:12,64,32;;",128,0,0,0
2281 Protections for member functions are signified by one digit embeded in
2282 the field part of the stab describing the method. The digit is 0 if
2283 private, 1 if protected and 2 if public. Consider the C++ class
2287 class all_methods @{
2289 int priv_meth(int in)@{return in;@};
2291 char protMeth(char in)@{return in;@};
2293 float pubMeth(float in)@{return in;@};
2297 It generates the following stab. The digit in question is to the left
2298 of an `A' in each case. Notice also that in this case two symbol
2299 descriptors apply to the class name struct tag and struct type.
2302 .stabs "class_name:sym_desc(struct tag&type)type_def(21)=
2303 sym_desc(struct)struct_bytes(1)
2304 meth_name::type_def(22)=sym_desc(method)returning(int);
2305 :args(int);protection(private)modifier(normal)virtual(no);
2306 meth_name::type_def(23)=sym_desc(method)returning(char);
2307 :args(char);protection(protected)modifier(normal)virual(no);
2308 meth_name::type_def(24)=sym_desc(method)returning(float);
2309 :args(float);protection(public)modifier(normal)virtual(no);;",
2314 .stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
2315 pubMeth::24=##12;:f;2A.;;",128,0,0,0
2318 @node Method Modifiers
2319 @section Method Modifiers (const, volatile, const volatile)
2323 In the class example described above all the methods have the normal
2324 modifier. This method modifier information is located just after the
2325 protection information for the method. This field has four possible
2326 character values. Normal methods use A, const methods use B, volatile
2327 methods use C, and const volatile methods use D. Consider the class
2333 int ConstMeth (int arg) const @{ return arg; @};
2334 char VolatileMeth (char arg) volatile @{ return arg; @};
2335 float ConstVolMeth (float arg) const volatile @{return arg; @};
2339 This class is described by the following stab:
2342 .stabs "class(A):sym_desc(struct)type_def(20)=type_desc(struct)struct_bytes(1)
2343 meth_name(ConstMeth)::type_def(21)sym_desc(method)
2344 returning(int);:arg(int);protection(public)modifier(const)virtual(no);
2345 meth_name(VolatileMeth)::type_def(22)=sym_desc(method)
2346 returning(char);:arg(char);protection(public)modifier(volatile)virt(no)
2347 meth_name(ConstVolMeth)::type_def(23)=sym_desc(method)
2348 returning(float);:arg(float);protection(public)modifer(const volatile)
2349 virtual(no);;", @dots{}
2353 .stabs "A:T20=s1ConstMeth::21=##1;:i;2B.;VolatileMeth::22=##2;:c;2C.;
2354 ConstVolMeth::23=##12;:f;2D.;;",128,0,0,0
2357 @node Virtual Methods
2358 @section Virtual Methods
2360 << The following examples are based on a4.C >>
2362 The presence of virtual methods in a class definition adds additional
2363 data to the class description. The extra data is appended to the
2364 description of the virtual method and to the end of the class
2365 description. Consider the class definition below:
2371 virtual int A_virt (int arg) @{ return arg; @};
2375 This results in the stab below describing class A. It defines a new
2376 type (20) which is an 8 byte structure. The first field of the class
2377 struct is Adat, an integer, starting at structure offset 0 and
2380 The second field in the class struct is not explicitly defined by the
2381 C++ class definition but is implied by the fact that the class
2382 contains a virtual method. This field is the vtable pointer. The
2383 name of the vtable pointer field starts with $vf and continues with a
2384 type reference to the class it is part of. In this example the type
2385 reference for class A is 20 so the name of its vtable pointer field is
2386 $vf20, followed by the usual colon.
2388 Next there is a type definition for the vtable pointer type (21).
2389 This is in turn defined as a pointer to another new type (22).
2391 Type 22 is the vtable itself, which is defined as an array, indexed by
2392 a range of integers between 0 and 1, and whose elements are of type
2393 17. Type 17 was the vtable record type defined by the boilerplate C++
2394 type definitions, as shown earlier.
2396 The bit offset of the vtable pointer field is 32. The number of bits
2397 in the field are not specified when the field is a vtable pointer.
2399 Next is the method definition for the virtual member function A_virt.
2400 Its description starts out using the same format as the non-virtual
2401 member functions described above, except instead of a dot after the
2402 `A' there is an asterisk, indicating that the function is virtual.
2403 Since is is virtual some addition information is appended to the end
2404 of the method description.
2406 The first number represents the vtable index of the method. This is a
2407 32 bit unsigned number with the high bit set, followed by a
2410 The second number is a type reference to the first base class in the
2411 inheritence hierarchy defining the virtual member function. In this
2412 case the class stab describes a base class so the virtual function is
2413 not overriding any other definition of the method. Therefore the
2414 reference is to the type number of the class that the stab is
2417 This is followed by three semi-colons. One marks the end of the
2418 current sub-section, one marks the end of the method field, and the
2419 third marks the end of the struct definition.
2421 For classes containing virtual functions the very last section of the
2422 string part of the stab holds a type reference to the first base
2423 class. This is preceeded by `~%' and followed by a final semi-colon.
2426 .stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
2427 field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
2428 field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
2429 sym_desc(array)index_type_ref(range of int from 0 to 1);
2430 elem_type_ref(vtbl elem type),
2432 meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
2433 :arg_type(int),protection(public)normal(yes)virtual(yes)
2434 vtable_index(1);class_first_defining(A);;;~%first_base(A);",
2439 .stabs "A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
2443 @section Inheritence
2445 Stabs describing C++ derived classes include additional sections that
2446 describe the inheritence hierarchy of the class. A derived class stab
2447 also encodes the number of base classes. For each base class it tells
2448 if the base class is virtual or not, and if the inheritence is private
2449 or public. It also gives the offset into the object of the portion of
2450 the object corresponding to each base class.
2452 This additional information is embeded in the class stab following the
2453 number of bytes in the struct. First the number of base classes
2454 appears bracketed by an exclamation point and a comma.
2456 Then for each base type there repeats a series: two digits, a number,
2457 a comma, another number, and a semi-colon.
2459 The first of the two digits is 1 if the base class is virtual and 0 if
2460 not. The second digit is 2 if the derivation is public and 0 if not.
2462 The number following the first two digits is the offset from the start
2463 of the object to the part of the object pertaining to the base class.
2465 After the comma, the second number is a type_descriptor for the base
2466 type. Finally a semi-colon ends the series, which repeats for each
2469 The source below defines three base classes A, B, and C and the
2477 virtual int A_virt (int arg) @{ return arg; @};
2483 virtual int B_virt (int arg) @{return arg; @};
2489 virtual int C_virt (int arg) @{return arg; @};
2492 class D : A, virtual B, public C @{
2495 virtual int A_virt (int arg ) @{ return arg+1; @};
2496 virtual int B_virt (int arg) @{ return arg+2; @};
2497 virtual int C_virt (int arg) @{ return arg+3; @};
2498 virtual int D_virt (int arg) @{ return arg; @};
2502 Class stabs similar to the ones described earlier are generated for
2505 @c FIXME!!! the linebreaks in the following example probably make the
2506 @c examples literally unusable, but I don't know any other way to get
2507 @c them on the page.
2509 .stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2510 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
2512 .stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
2513 :i;2A*-2147483647;25;;;~%25;",128,0,0,0
2515 .stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
2516 :i;2A*-2147483647;28;;;~%28;",128,0,0,0
2519 In the stab describing derived class D below, the information about
2520 the derivation of this class is encoded as follows.
2523 .stabs "derived_class_name:symbol_descriptors(struct tag&type)=
2524 type_descriptor(struct)struct_bytes(32)!num_bases(3),
2525 base_virtual(no)inheritence_public(no)base_offset(0),
2526 base_class_type_ref(A);
2527 base_virtual(yes)inheritence_public(no)base_offset(NIL),
2528 base_class_type_ref(B);
2529 base_virtual(no)inheritence_public(yes)base_offset(64),
2530 base_class_type_ref(C); @dots{}
2533 @c FIXME! fake linebreaks.
2535 .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
2536 1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
2537 :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
2538 28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
2541 @node Virtual Base Classes
2542 @section Virtual Base Classes
2544 A derived class object consists of a concatination in memory of the
2545 data areas defined by each base class, starting with the leftmost and
2546 ending with the rightmost in the list of base classes. The exception
2547 to this rule is for virtual inheritence. In the example above, class
2548 D inherits virtually from base class B. This means that an instance
2549 of a D object will not contain it's own B part but merely a pointer to
2550 a B part, known as a virtual base pointer.
2552 In a derived class stab, the base offset part of the derivation
2553 information, described above, shows how the base class parts are
2554 ordered. The base offset for a virtual base class is always given as
2555 0. Notice that the base offset for B is given as 0 even though B is
2556 not the first base class. The first base class A starts at offset 0.
2558 The field information part of the stab for class D describes the field
2559 which is the pointer to the virtual base class B. The vbase pointer
2560 name is $vb followed by a type reference to the virtual base class.
2561 Since the type id for B in this example is 25, the vbase pointer name
2564 @c FIXME!! fake linebreaks below
2566 .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,
2567 160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;
2568 2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt:
2569 :32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
2572 Following the name and a semicolon is a type reference describing the
2573 type of the virtual base class pointer, in this case 24. Type 24 was
2574 defined earlier as the type of the B class `this` pointer. The
2575 `this' pointer for a class is a pointer to the class type.
2578 .stabs "this:P24=*25=xsB:",64,0,0,8
2581 Finally the field offset part of the vbase pointer field description
2582 shows that the vbase pointer is the first field in the D object,
2583 before any data fields defined by the class. The layout of a D class
2584 object is a follows, Adat at 0, the vtable pointer for A at 32, Cdat
2585 at 64, the vtable pointer for C at 96, the virtual ase pointer for B
2586 at 128, and Ddat at 160.
2589 @node Static Members
2590 @section Static Members
2592 The data area for a class is a concatenation of the space used by the
2593 data members of the class. If the class has virtual methods, a vtable
2594 pointer follows the class data. The field offset part of each field
2595 description in the class stab shows this ordering.
2597 << How is this reflected in stabs? See Cygnus bug #677 for some info. >>
2600 @appendix Example2.c - source code for extended example
2604 2 register int g_bar asm ("%g5");
2605 3 static int s_g_repeat = 2;
2611 9 char s_char_vec[8];
2612 10 struct s_tag* s_next;
2615 13 typedef struct s_tag s_typedef;
2617 15 char char_vec[3] = @{'a','b','c'@};
2619 17 main (argc, argv)
2623 21 static float s_flap;
2625 23 for (times=0; times < s_g_repeat; times++)@{
2627 25 printf ("Hello world\n");
2631 29 enum e_places @{first,second=3,last@};
2633 31 static s_proc (s_arg, s_ptr_arg, char_vec)
2635 33 s_typedef* s_ptr_arg;
2649 @appendix Example2.s - assembly code for extended example
2653 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
2654 3 .stabs "example2.c",100,0,0,Ltext0
2657 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
2658 7 .stabs "char:t2=r2;0;127;",128,0,0,0
2659 8 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
2660 9 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
2661 10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
2662 11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
2663 12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
2664 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
2665 14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
2666 15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
2667 16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
2668 17 .stabs "float:t12=r1;4;0;",128,0,0,0
2669 18 .stabs "double:t13=r1;8;0;",128,0,0,0
2670 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
2671 20 .stabs "void:t15=15",128,0,0,0
2672 21 .stabs "g_foo:G2",32,0,0,0
2677 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
2681 @c FIXME! fake linebreak in line 30
2682 30 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;s_char_vec:
2683 17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
2684 31 .stabs "s_typedef:t16",128,0,0,0
2685 32 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
2686 33 .global _char_vec
2692 39 .reserve _s_flap.0,4,"bss",4
2696 43 .ascii "Hello world\12\0"
2701 48 .stabn 68,0,20,LM1
2704 51 save %sp,-144,%sp
2711 58 .stabn 68,0,23,LM2
2715 62 sethi %hi(_s_g_repeat),%o0
2717 64 ld [%o0+%lo(_s_g_repeat)],%o0
2722 69 .stabn 68,0,25,LM3
2724 71 sethi %hi(LC0),%o1
2725 72 or %o1,%lo(LC0),%o0
2728 75 .stabn 68,0,26,LM4
2731 78 .stabn 68,0,23,LM5
2739 86 .stabn 68,0,27,LM6
2742 89 .stabn 68,0,27,LM7
2747 94 .stabs "main:F1",36,0,0,_main
2748 95 .stabs "argc:p1",160,0,0,68
2749 96 .stabs "argv:p20=*21=*2",160,0,0,72
2750 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
2751 98 .stabs "times:1",128,0,0,-20
2752 99 .stabn 192,0,0,LBB2
2753 100 .stabs "inner:1",128,0,0,-24
2754 101 .stabn 192,0,0,LBB3
2755 102 .stabn 224,0,0,LBE3
2756 103 .stabn 224,0,0,LBE2
2757 104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
2758 @c FIXME: fake linebreak in line 105
2759 105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
2764 109 .stabn 68,0,35,LM8
2767 112 save %sp,-120,%sp
2773 118 .stabn 68,0,41,LM9
2776 121 .stabn 68,0,41,LM10
2781 126 .stabs "s_proc:f1",36,0,0,_s_proc
2782 127 .stabs "s_arg:p16",160,0,0,0
2783 128 .stabs "s_ptr_arg:p18",160,0,0,72
2784 129 .stabs "char_vec:p21",160,0,0,76
2785 130 .stabs "an_u:23",128,0,0,-20
2786 131 .stabn 192,0,0,LBB4
2787 132 .stabn 224,0,0,LBE4
2788 133 .stabs "g_bar:r1",64,0,0,5
2789 134 .stabs "g_pf:G24=*25=f1",32,0,0,0
2790 135 .common _g_pf,4,"bss"
2791 136 .stabs "g_an_s:G16",32,0,0,0
2792 137 .common _g_an_s,20,"bss"
2796 @appendix Table A: Symbol types from stabs
2798 Table A lists stab types sorted by type number. Stab type numbers are
2799 32 and greater. This is the full list of stab numbers, including stab
2800 types that are used in languages other than C.
2802 The #define names for these stab types are defined in:
2803 devo/include/aout/stab.def
2806 type type #define used to describe
2807 dec hex name source program feature
2808 ------------------------------------------------
2809 32 0x20 N_GYSM global symbol
2810 34 0X22 N_FNAME function name (for BSD Fortran)
2811 36 0x24 N_FUN function name or text segment variable for C
2812 38 0x26 N_STSYM static symbol (data segment w/internal linkage)
2813 40 0x28 N_LCSYM .lcomm symbol(BSS-seg variable w/internal linkage)
2814 42 0x2a N_MAIN Name of main routine (not used in C)
2815 48 0x30 N_PC global symbol (for Pascal)
2816 50 0x32 N_NSYMS number of symbols (according to Ultrix V4.0)
2817 52 0x34 N_NOMAP no DST map for sym (according to Ultrix V4.0)
2818 64 0x40 N_RSYM register variable
2819 66 0x42 N_M2C Modula-2 compilation unit
2820 68 0x44 N_SLINE line number in text segment
2821 70 0x46 N_DSLINE line number in data segment
2823 72 0x48 N_BSLINE line number in bss segment
2824 72 0x48 N_BROWS Sun source code browser, path to .cb file
2826 74 0x4a N_DEFD GNU Modula2 definition module dependency
2828 80 0x50 N_EHDECL GNU C++ exception variable
2829 80 0x50 N_MOD2 Modula2 info "for imc" (according to Ultrix V4.0)
2831 84 0x54 N_CATCH GNU C++ "catch" clause
2832 96 0x60 N_SSYM structure of union element
2833 100 0x64 N_SO path and name of source file
2834 128 0x80 N_LSYM automatic var in the stack
2835 (also used for type desc.)
2836 130 0x82 N_BINCL beginning of an include file (Sun only)
2837 132 0x84 N_SOL Name of sub-source (#include) file.
2838 160 0xa0 N_PSYM parameter variable
2839 162 0xa2 N_EINCL end of an include file
2840 164 0xa4 N_ENTRY alternate entry point
2841 192 0xc0 N_LBRAC beginning of a lexical block
2842 194 0xc2 N_EXCL place holder for a deleted include file
2843 196 0xc4 N_SCOPE modula2 scope information (Sun linker)
2844 224 0xe0 N_RBRAC end of a lexical block
2845 226 0xe2 N_BCOMM begin named common block
2846 228 0xe4 N_ECOMM end named common block
2847 232 0xe8 N_ECOML end common (local name)
2849 << used on Gould systems for non-base registers syms >>
2850 240 0xf0 N_NBTEXT ??
2851 242 0xf2 N_NBDATA ??
2857 @node Assembler types
2858 @appendix Table B: Symbol types from assembler and linker
2860 Table B shows the types of symbol table entries that hold assembler
2863 The #define names for these n_types values are defined in
2864 /include/aout/aout64.h
2868 n_type n_type name used to describe
2869 ------------------------------------------
2870 1 0x0 N_UNDF undefined symbol
2871 2 0x2 N_ABS absolute symbol -- defined at a particular address
2872 3 0x3 extern " (vs. file scope)
2873 4 0x4 N_TEXT text symbol -- defined at offset in text segment
2874 5 0x5 extern " (vs. file scope)
2875 6 0x6 N_DATA data symbol -- defined at offset in data segment
2876 7 0x7 extern " (vs. file scope)
2877 8 0x8 N_BSS BSS symbol -- defined at offset in zero'd segment
2878 9 extern " (vs. file scope)
2880 12 0x0C N_FN_SEQ func name for Sequent compilers (stab exception)
2882 49 0x12 N_COMM common sym -- visable after shared lib dynamic link
2883 31 0x1f N_FN file name of a .o file
2886 @node Symbol Descriptors
2887 @appendix Table C: Symbol descriptors
2889 @c Please keep this alphabetical
2894 Local variable, @xref{Automatic variables}.
2897 Parameter passed by reference in register, @xref{Parameters}.
2900 Constant, @xref{Constants}.
2903 Conformant array bound (Pascal, maybe other languages),
2904 @xref{Parameters}. Name of a caught exception (GNU C++). These can be
2905 distinguished because the latter uses N_CATCH and the former uses
2906 another symbol type.
2909 Floating point register variable, @xref{Register variables}.
2912 Parameter in floating point register, @xref{Parameters}.
2915 Static function, @xref{Procedures}.
2918 Global function, @xref{Procedures}.
2921 Global variable, @xref{Global Variables}.
2927 Internal (nested) procedure, @xref{Procedures}.
2930 Internal (nested) function, @xref{Procedures}.
2933 Label name (documented by AIX, no further information known).
2936 Module, @xref{Procedures}.
2939 Argument list parameter, @xref{Parameters}.
2945 FORTRAN Function parameter, @xref{Parameters}.
2948 Unfortunately, three separate meanings have been independently invented
2949 for this symbol descriptor. At least the GNU and Sun uses can be
2950 distinguished by the symbol type. Global Procedure (AIX) (symbol type
2951 used unknown), @xref{Procedures}. Register parameter (GNU) (symbol type
2952 N_PSYM), @xref{Parameters}. Prototype of function referenced by this
2953 file (Sun acc) (symbol type N_FUN).
2956 Static Procedure, @xref{Procedures}.
2959 Register parameter @xref{Parameters}.
2962 Register variable, @xref{Register variables}.
2965 Static file scope variable @xref{Initialized statics},
2966 @xref{Un-initialized statics}.
2969 Type name, @xref{Typedefs}.
2972 enumeration, struct or union tag, @xref{Typedefs}.
2975 Parameter passed by reference, @xref{Parameters}.
2978 Static procedure scope variable @xref{Initialized statics},
2979 @xref{Un-initialized statics}.
2982 Conformant array, @xref{Parameters}.
2985 Function return variable, @xref{Parameters}.
2988 @node Type Descriptors
2989 @appendix Table D: Type Descriptors
2994 Type reference, @xref{Stabs Format}.
2997 Reference to builtin type, @xref{Negative Type Numbers}.
3000 Method (C++), @xref{Cplusplus}.
3003 Pointer, @xref{Miscellaneous Types}.
3009 Type Attributes (AIX), @xref{Stabs Format}. Member (class and variable)
3010 type (GNU C++), @xref{Cplusplus}.
3013 Array, @xref{Arrays}.
3016 Open array, @xref{Arrays}.
3019 Pascal space type (AIX), @xref{Miscellaneous Types}. Builtin integer
3020 type (Sun), @xref{Builtin Type Descriptors}.
3023 Volatile-qualified type, @xref{Miscellaneous Types}.
3026 Complex builtin type, @xref{Builtin Type Descriptors}.
3029 COBOL Picture type. See AIX documentation for details.
3032 File type, @xref{Miscellaneous Types}.
3035 N-dimensional dynamic array, @xref{Arrays}.
3038 Enumeration type, @xref{Enumerations}.
3041 N-dimensional subarray, @xref{Arrays}.
3044 Function type, @xref{Function types}.
3047 Builtin floating point type, @xref{Builtin Type Descriptors}.
3050 COBOL Group. See AIX documentation for details.
3053 Imported type, @xref{Cross-references}.
3056 Const-qualified type, @xref{Miscellaneous Types}.
3059 COBOL File Descriptor. See AIX documentation for details.
3062 String type, @xref{Strings}.
3065 Stringptr, @xref{Strings}.
3068 Multiple instance type, @xref{Miscellaneous Types}.
3071 Opaque type, @xref{Typedefs}.
3074 Packed array, @xref{Arrays}.
3077 Range type, @xref{Subranges}.
3080 Builtin floating type, @xref{Builtin Type Descriptors}.
3083 Structure type, @xref{Structures}.
3086 Set type, @xref{Miscellaneous Types}.
3089 Union, @xref{Unions}.
3092 Variant record. This is a Pascal and Modula-2 feature which is like a
3093 union within a struct in C. See AIX documentation for details.
3096 Wide character, @xref{Builtin Type Descriptors}.
3099 Cross-reference, @xref{Cross-references}.
3102 gstring, @xref{Strings}.
3105 @node Expanded reference
3106 @appendix Expanded reference by stab type.
3108 @c FIXME: For most types this should be much shorter and much sweeter,
3109 @c see N_PSYM for an example. For stuff like N_SO where the stab type
3110 @c really is the important thing, the information can stay here.
3112 @c FIXME: It probably should be merged with Tables A and B.
3116 The first line is the symbol type expressed in decimal, hexadecimal,
3117 and as a #define (see devo/include/aout/stab.def).
3119 The second line describes the language constructs the symbol type
3122 The third line is the stab format with the significant stab fields
3123 named and the rest NIL.
3125 Subsequent lines expand upon the meaning and possible values for each
3126 significant stab field. # stands in for the type descriptor.
3128 Finally, any further information.
3131 * N_GSYM:: Global variable
3132 * N_FNAME:: Function name (BSD Fortran)
3133 * N_FUN:: C Function name or text segment variable
3134 * N_STSYM:: Initialized static symbol
3135 * N_LCSYM:: Uninitialized static symbol
3136 * N_MAIN:: Name of main routine (not for C)
3137 * N_PC:: Pascal global symbol
3138 * N_NSYMS:: Number of symbols
3139 * N_NOMAP:: No DST map
3140 * N_RSYM:: Register variable
3141 * N_M2C:: Modula-2 compilation unit
3142 * N_SLINE:: Line number in text segment
3143 * N_DSLINE:: Line number in data segment
3144 * N_BSLINE:: Line number in bss segment
3145 * N_BROWS:: Path to .cb file for Sun source code browser
3146 * N_DEFD:: GNU Modula2 definition module dependency
3147 * N_EHDECL:: GNU C++ exception variable
3148 * N_MOD2:: Modula2 information "for imc"
3149 * N_CATCH:: GNU C++ "catch" clause
3150 * N_SSYM:: Structure or union element
3151 * N_SO:: Source file containing main
3152 * N_LSYM:: Automatic variable
3153 * N_BINCL:: Beginning of include file (Sun only)
3154 * N_SOL:: Name of include file
3155 * N_PSYM:: Parameter variable
3156 * N_EINCL:: End of include file
3157 * N_ENTRY:: Alternate entry point
3158 * N_LBRAC:: Beginning of lexical block
3159 * N_EXCL:: Deleted include file
3160 * N_SCOPE:: Modula2 scope information (Sun only)
3161 * N_RBRAC:: End of lexical block
3162 * N_BCOMM:: Begin named common block
3163 * N_ECOMM:: End named common block
3164 * N_ECOML:: End common
3165 * Gould:: non-base register symbols used on Gould systems
3166 * N_LENG:: Length of preceding entry
3170 @section 32 - 0x20 - N_GYSM
3175 .stabs "name", N_GSYM, NIL, NIL, NIL
3179 "name" -> "symbol_name:#type"
3183 Only the "name" field is significant. The location of the variable is
3184 obtained from the corresponding external symbol.
3187 @section 34 - 0x22 - N_FNAME
3188 Function name (for BSD Fortran)
3191 .stabs "name", N_FNAME, NIL, NIL, NIL
3195 "name" -> "function_name"
3198 Only the "name" field is significant. The location of the symbol is
3199 obtained from the corresponding extern symbol.
3202 @section 36 - 0x24 - N_FUN
3204 Function name (@pxref{Procedures}) or text segment variable
3205 (@pxref{Variables}).
3207 @exdent @emph{For functions:}
3208 "name" -> "proc_name:#return_type"
3209 # -> F (global function)
3211 desc -> line num for proc start. (GCC doesn't set and DBX doesn't miss it.)
3212 value -> Code address of proc start.
3214 @exdent @emph{For text segment variables:}
3215 <<How to create one?>>
3219 @section 38 - 0x26 - N_STSYM
3220 Initialized static symbol (data segment w/internal linkage).
3223 .stabs "name", N_STSYM, NIL, NIL, value
3227 "name" -> "symbol_name#type"
3228 # -> S (scope global to compilation unit)
3229 -> V (scope local to a procedure)
3230 value -> Data Address
3234 @section 40 - 0x28 - N_LCSYM
3235 Unitialized static (.lcomm) symbol(BSS segment w/internal linkage).
3238 .stabs "name", N_LCLSYM, NIL, NIL, value
3242 "name" -> "symbol_name#type"
3243 # -> S (scope global to compilation unit)
3244 -> V (scope local to procedure)
3245 value -> BSS Address
3249 @section 42 - 0x2a - N_MAIN
3250 Name of main routine (not used in C)
3253 .stabs "name", N_MAIN, NIL, NIL, NIL
3257 "name" -> "name_of_main_routine"
3261 @section 48 - 0x30 - N_PC
3262 Global symbol (for Pascal)
3265 .stabs "name", N_PC, NIL, NIL, value
3269 "name" -> "symbol_name" <<?>>
3270 value -> supposedly the line number (stab.def is skeptical)
3276 global pascal symbol: name,,0,subtype,line
3281 @section 50 - 0x32 - N_NSYMS
3282 Number of symbols (according to Ultrix V4.0)
3285 0, files,,funcs,lines (stab.def)
3289 @section 52 - 0x34 - N_NOMAP
3290 no DST map for sym (according to Ultrix V4.0)
3293 name, ,0,type,ignored (stab.def)
3297 @section 64 - 0x40 - N_RSYM
3301 .stabs "name:type",N_RSYM,0,RegSize,RegNumber (Sun doc)
3305 @section 66 - 0x42 - N_M2C
3306 Modula-2 compilation unit
3309 .stabs "name", N_M2C, 0, desc, value
3313 "name" -> "unit_name,unit_time_stamp[,code_time_stamp]
3315 value -> 0 (main unit)
3320 @section 68 - 0x44 - N_SLINE
3321 Line number in text segment
3324 .stabn N_SLINE, 0, desc, value
3329 value -> code_address (relocatable addr where the corresponding code starts)
3332 For single source lines that generate discontiguous code, such as flow
3333 of control statements, there may be more than one N_SLINE stab for the
3334 same source line. In this case there is a stab at the start of each
3335 code range, each with the same line number.
3338 @section 70 - 0x46 - N_DSLINE
3339 Line number in data segment
3342 .stabn N_DSLINE, 0, desc, value
3347 value -> data_address (relocatable addr where the corresponding code
3351 See comment for N_SLINE above.
3354 @section 72 - 0x48 - N_BSLINE
3355 Line number in bss segment
3358 .stabn N_BSLINE, 0, desc, value
3363 value -> bss_address (relocatable addr where the corresponding code
3367 See comment for N_SLINE above.
3370 @section 72 - 0x48 - N_BROWS
3371 Sun source code browser, path to .cb file
3374 "path to associated .cb file"
3376 Note: type field value overlaps with N_BSLINE
3379 @section 74 - 0x4a - N_DEFD
3380 GNU Modula2 definition module dependency
3382 GNU Modula-2 definition module dependency. Value is the modification
3383 time of the definition file. Other is non-zero if it is imported with
3384 the GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
3385 are enough empty fields?
3388 @section 80 - 0x50 - N_EHDECL
3389 GNU C++ exception variable <<?>>
3391 "name is variable name"
3393 Note: conflicts with N_MOD2.
3396 @section 80 - 0x50 - N_MOD2
3397 Modula2 info "for imc" (according to Ultrix V4.0)
3399 Note: conflicts with N_EHDECL <<?>>
3402 @section 84 - 0x54 - N_CATCH
3403 GNU C++ "catch" clause
3405 GNU C++ `catch' clause. Value is its address. Desc is nonzero if
3406 this entry is immediately followed by a CAUGHT stab saying what
3407 exception was caught. Multiple CAUGHT stabs means that multiple
3408 exceptions can be caught here. If Desc is 0, it means all exceptions
3412 @section 96 - 0x60 - N_SSYM
3413 Structure or union element
3415 Value is offset in the structure.
3417 <<?looking at structs and unions in C I didn't see these>>
3420 @section 100 - 0x64 - N_SO
3421 Path and name of source file containing main routine
3424 .stabs "name", N_SO, NIL, NIL, value
3428 "name" -> /source/directory/
3431 value -> the starting text address of the compilation.
3434 These are found two in a row. The name field of the first N_SO contains
3435 the directory that the source file is relative to. The name field of
3436 the second N_SO contains the name of the source file itself.
3438 Only some compilers (e.g. gcc2, Sun cc) include the directory; this
3439 symbol can be distinguished by the fact that it ends in a slash.
3440 According to a comment in GDB's partial-stab.h, other compilers
3441 (especially unnamed C++ compilers) put out useless N_SO's for
3442 nonexistent source files (after the N_SO for the real source file).
3445 @section 128 - 0x80 - N_LSYM
3446 Automatic var in the stack (also used for type descriptors.)
3449 .stabs "name" N_LSYM, NIL, NIL, value
3453 @exdent @emph{For stack based local variables:}
3455 "name" -> name of the variable
3456 value -> offset from frame pointer (negative)
3458 @exdent @emph{For type descriptors:}
3460 "name" -> "name_of_the_type:#type"
3463 type -> type_ref (or) type_def
3465 type_ref -> type_number
3466 type_def -> type_number=type_desc etc.
3469 Type may be either a type reference or a type definition. A type
3470 reference is a number that refers to a previously defined type. A
3471 type definition is the number that will refer to this type, followed
3472 by an equals sign, a type descriptor and the additional data that
3473 defines the type. See the Table D for type descriptors and the
3474 section on types for what data follows each type descriptor.
3477 @section 130 - 0x82 - N_BINCL
3479 Beginning of an include file (Sun only)
3481 Beginning of an include file. Only Sun uses this. In an object file,
3482 only the name is significant. The Sun linker puts data into some of
3486 @section 132 - 0x84 - N_SOL
3488 Name of a sub-source file (#include file). Value is starting address
3493 @section 160 - 0xa0 - N_PSYM
3495 Parameter variable. @xref{Parameters}.
3498 @section 162 - 0xa2 - N_EINCL
3500 End of an include file. This and N_BINCL act as brackets around the
3501 file's output. In an ojbect file, there is no significant data in
3502 this entry. The Sun linker puts data into some of the fields.
3506 @section 164 - 0xa4 - N_ENTRY
3508 Alternate entry point.
3509 Value is its address.
3513 @section 192 - 0xc0 - N_LBRAC
3515 Beginning of a lexical block (left brace). The variable defined
3516 inside the block precede the N_LBRAC symbol. Or can they follow as
3517 well as long as a new N_FUNC was not encountered. <<?>>
3520 .stabn N_LBRAC, NIL, NIL, value
3524 value -> code address of block start.
3528 @section 194 - 0xc2 - N_EXCL
3530 Place holder for a deleted include file. Replaces a N_BINCL and
3531 everything up to the corresponding N_EINCL. The Sun linker generates
3532 these when it finds multiple indentical copies of the symbols from an
3533 included file. This appears only in output from the Sun linker.
3537 @section 196 - 0xc4 - N_SCOPE
3539 Modula2 scope information (Sun linker)
3543 @section 224 - 0xe0 - N_RBRAC
3545 End of a lexical block (right brace)
3548 .stabn N_RBRAC, NIL, NIL, value
3552 value -> code address of the end of the block.
3556 @section 226 - 0xe2 - N_BCOMM
3558 Begin named common block.
3560 Only the name is significant.
3564 @section 228 - 0xe4 - N_ECOMM
3566 End named common block.
3568 Only the name is significant and it should match the N_BCOMM
3572 @section 232 - 0xe8 - N_ECOML
3574 End common (local name)
3580 @section Non-base registers on Gould systems
3581 << used on Gould systems for non-base registers syms, values assigned
3582 at random, need real info from Gould. >>
3586 240 0xf0 N_NBTEXT ??
3587 242 0xf2 N_NBDATA ??
3594 @section - 0xfe - N_LENG
3596 Second symbol entry containing a length-value for the preceding entry.
3597 The value is the length.
3600 @appendix Questions and anomalies
3604 For GNU C stabs defining local and global variables (N_LSYM and
3605 N_GSYM), the desc field is supposed to contain the source line number
3606 on which the variable is defined. In reality the desc field is always
3607 0. (This behavour is defined in dbxout.c and putting a line number in
3608 desc is controlled by #ifdef WINNING_GDB which defaults to false). Gdb
3609 supposedly uses this information if you say 'list var'. In reality
3610 var can be a variable defined in the program and gdb says `function
3614 In GNU C stabs there seems to be no way to differentiate tag types:
3615 structures, unions, and enums (symbol descriptor T) and typedefs
3616 (symbol descriptor t) defined at file scope from types defined locally
3617 to a procedure or other more local scope. They all use the N_LSYM
3618 stab type. Types defined at procedure scope are emited after the
3619 N_RBRAC of the preceding function and before the code of the
3620 procedure in which they are defined. This is exactly the same as
3621 types defined in the source file between the two procedure bodies.
3622 GDB overcompensates by placing all types in block #1, the block for
3623 symbols of file scope. This is true for default, -ansi and
3624 -traditional compiler options. (Bugs gcc/1063, gdb/1066.)
3627 What ends the procedure scope? Is it the proc block's N_RBRAC or the
3628 next N_FUN? (I believe its the first.)
3631 The comment in xcoff.h says DBX_STATIC_CONST_VAR_CODE is used for
3632 static const variables. DBX_STATIC_CONST_VAR_CODE is set to N_FUN by
3633 default, in dbxout.c. If included, xcoff.h redefines it to N_STSYM.
3634 But testing the default behaviour, my Sun4 native example shows
3635 N_STSYM not N_FUN is used to describe file static initialized
3636 variables. (the code tests for TREE_READONLY(decl) &&
3637 !TREE_THIS_VOLATILE(decl) and if true uses DBX_STATIC_CONST_VAR_CODE).
3640 Global variable stabs don't have location information. This comes
3641 from the external symbol for the same variable. The external symbol
3642 has a leading underbar on the _name of the variable and the stab does
3643 not. How do we know these two symbol table entries are talking about
3644 the same symbol when their names are different?
3647 Can gcc be configured to output stabs the way the Sun compiler
3648 does, so that their native debugging tools work? <NO?> It doesn't by
3649 default. GDB reads either format of stab. (gcc or SunC). How about
3653 @node xcoff-differences
3654 @appendix Differences between GNU stabs in a.out and GNU stabs in xcoff
3656 @c FIXME: Merge *all* these into the main body of the document.
3657 (The AIX/RS6000 native object file format is xcoff with stabs). This
3658 appendix only covers those differences which are not covered in the main
3659 body of this document.
3663 Instead of .stabs, xcoff uses .stabx.
3666 The data fields of an xcoff .stabx are in a different order than an
3667 a.out .stabs. The order is: string, value, type, sdb-type. The desc
3668 and null fields present in a.out stabs are missing in xcoff stabs. For
3669 N_GSYM the value field is the name of the symbol. sdb-type is unused
3670 with stabs; it can always be set to 0.
3673 BSD a.out stab types correspond to AIX xcoff storage classes. In general the
3674 mapping is N_STABTYPE becomes C_STABTYPE. Some stab types in a.out
3675 are not supported in xcoff. See Table E. for full mappings.
3678 initialised static N_STSYM and un-initialized static N_LCSYM both map
3679 to the C_STSYM storage class. But the destinction is preserved
3680 because in xcoff N_STSYM and N_LCSYM must be emited in a named static
3681 block. Begin the block with .bs s[RW] data_section_name for N_STSYM
3682 or .bs s bss_section_name for N_LCSYM. End the block with .es
3685 xcoff uses a .file stab type to represent the source file name. There
3686 is no stab for the path to the source file.
3689 xcoff uses a .line stab type to represent source lines. The format
3690 is: .line line_number.
3693 xcoff emits line numbers relative to the start of the current
3694 function. The start of a function is marked by .bf. If a function
3695 includes lines from a seperate file, then those line numbers are
3696 absolute line numbers in the <<sub-?>> file being compiled.
3699 The start of current include file is marked with: .bi "filename" and
3700 the end marked with .ei "filename"
3703 If the xcoff stab is a N_FUN (C_FUN) then follow the string field with
3704 ,. instead of just ,
3708 (I think that's it for .s file differences. They could stand to be
3709 better presented. This is just a list of what I have noticed so far.
3710 There are a *lot* of differences in the information in the symbol
3711 tables of the executable and object files.)
3713 Table E: mapping a.out stab types to xcoff storage classes
3716 stab type storage class
3717 -------------------------------
3726 N_RPSYM (0x8e) C_RPSYM
3736 N_DECL (0x8c) C_DECL
3753 @node Sun-differences
3754 @appendix Differences between GNU stabs and Sun native stabs.
3756 @c FIXME: Merge all this stuff into the main body of the document.
3760 GNU C stabs define *all* types, file or procedure scope, as
3761 N_LSYM. Sun doc talks about using N_GSYM too.
3764 Stabs describing block scopes, N_LBRAC and N_RBRAC are supposed to
3765 contain the nesting level of the block in the desc field, re Sun doc.
3766 GNU stabs always have 0 in that field. dbx seems not to care.
3769 Sun C stabs use type number pairs in the format (a,b) where a is a
3770 number starting with 1 and incremented for each sub-source file in the
3771 compilation. b is a number starting with 1 and incremented for each
3772 new type defined in the compilation. GNU C stabs use the type number
3773 alone, with no source file number.