* c-typeprint.c (c_type_print_base): Don't print typedef'd names
[deliverable/binutils-gdb.git] / gdb / doc / stabs.texinfo
CommitLineData
e505224d
PB
1\input texinfo
2@setfilename stabs.info
3
4@ifinfo
5@format
6START-INFO-DIR-ENTRY
139741da 7* Stabs: (stabs). The "stabs" debugging information format.
e505224d
PB
8END-INFO-DIR-ENTRY
9@end format
10@end ifinfo
11
12@ifinfo
8c59ee11 13This document describes the stabs debugging symbol tables.
e505224d 14
612dbd4c 15Copyright 1992 Free Software Foundation, Inc.
e505224d
PB
16Contributed by Cygnus Support. Written by Julia Menapace.
17
18Permission is granted to make and distribute verbatim copies of
19this manual provided the copyright notice and this permission notice
20are preserved on all copies.
21
22@ignore
23Permission is granted to process this file through Tex and print the
24results, provided the printed document carries copying permission
25notice identical to this one except for the removal of this paragraph
26(this paragraph not being relevant to the printed manual).
27
28@end ignore
29Permission is granted to copy or distribute modified versions of this
30manual under the terms of the GPL (for which purpose this text may be
31regarded as a program in the language TeX).
32@end ifinfo
33
139741da 34@setchapternewpage odd
e505224d
PB
35@settitle STABS
36@titlepage
139741da 37@title The ``stabs'' debug format
e505224d
PB
38@author Julia Menapace
39@author Cygnus Support
40@page
41@tex
42\def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
43\xdef\manvers{\$Revision$} % For use in headers, footers too
44{\parskip=0pt
45\hfill Cygnus Support\par
46\hfill \manvers\par
47\hfill \TeX{}info \texinfoversion\par
48}
49@end tex
50
51@vskip 0pt plus 1filll
899bafeb
RP
52Copyright @copyright{} 1992 Free Software Foundation, Inc.
53Contributed by Cygnus Support.
e505224d
PB
54
55Permission is granted to make and distribute verbatim copies of
56this manual provided the copyright notice and this permission notice
57are preserved on all copies.
58
59@end titlepage
60
899bafeb
RP
61@ifinfo
62@node Top
63@top The "stabs" representation of debugging information
e505224d 64
612dbd4c 65This document describes the GNU stabs debugging format in a.out files.
e505224d
PB
66
67@menu
139741da
RP
68* Overview:: Overview of stabs
69* Program structure:: Encoding of the structure of the program
6897f9ec 70* Constants:: Constants
139741da 71* Example:: A comprehensive example in C
e505224d 72* Variables::
8c59ee11 73* Types:: Type definitions
139741da 74* Symbol tables:: Symbol information in symbol tables
8c59ee11 75* Cplusplus::
e505224d
PB
76
77Appendixes:
139741da
RP
78* Example2.c:: Source code for extended example
79* Example2.s:: Assembly code for extended example
8c59ee11
JK
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
139741da
RP
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
89 native stabs
e505224d 90@end menu
899bafeb 91@end ifinfo
e505224d
PB
92
93
899bafeb 94@node Overview
e505224d
PB
95@chapter Overview of stabs
96
139741da
RP
97@dfn{Stabs} refers to a format for information that describes a program
98to a debugger. This format was apparently invented by
99@c FIXME! <<name of inventor>> at
100the University of California at Berkeley, for the @code{pdx} Pascal
101debugger; the format has spread widely since then.
102
8c59ee11
JK
103This document is one of the few published sources of documentation on
104stabs. It is believed to be completely comprehensive for stabs used by
105C. The lists of symbol descriptors (@pxref{Symbol Descriptors}) and
106type descriptors (@pxref{Type Descriptors}) are believed to be completely
107comprehensive. There are known to be stabs for C++ and COBOL which are
108poorly documented here. Stabs specific to other languages (e.g. Pascal,
109Modula-2) are probably not as well documented as they should be.
110
111Other sources of information on stabs are @cite{dbx and dbxtool
112interfaces}, 2nd edition, by Sun, circa 1988, and @cite{AIX Version 3.2
113Files Reference}, Fourth Edition, September 1992, "dbx Stabstring
114Grammar" in the a.out section, page 2-31. This document is believed to
115incorporate the information from those two sources except where it
116explictly directs you to them for more information.
117
e505224d
PB
118@menu
119* Flow:: Overview of debugging information flow
8c59ee11 120* Stabs Format:: Overview of stab format
e505224d
PB
121* C example:: A simple example in C source
122* Assembly code:: The simple example at the assembly level
123@end menu
124
899bafeb 125@node Flow
e505224d
PB
126@section Overview of debugging information flow
127
139741da
RP
128The GNU C compiler compiles C source in a @file{.c} file into assembly
129language in a @file{.s} file, which is translated by the assembler into
130a @file{.o} file, and then linked with other @file{.o} files and
131libraries to produce an executable file.
e505224d 132
139741da
RP
133With the @samp{-g} option, GCC puts additional debugging information in
134the @file{.s} file, which is slightly transformed by the assembler and
e505224d
PB
135linker, and carried through into the final executable. This debugging
136information describes features of the source file like line numbers,
137the types and scopes of variables, and functions, their parameters and
138their scopes.
139
140For some object file formats, the debugging information is
139741da 141encapsulated in assembler directives known collectively as `stab' (symbol
e505224d
PB
142table) directives, interspersed with the generated code. Stabs are
143the native format for debugging information in the a.out and xcoff
144object file formats. The GNU tools can also emit stabs in the coff
145and ecoff object file formats.
146
139741da
RP
147The assembler adds the information from stabs to the symbol information
148it places by default in the symbol table and the string table of the
149@file{.o} file it is building. The linker consolidates the @file{.o}
150files into one executable file, with one symbol table and one string
151table. Debuggers use the symbol and string tables in the executable as
152a source of debugging information about the program.
e505224d 153
8c59ee11 154@node Stabs Format
e505224d
PB
155@section Overview of stab format
156
157There are three overall formats for stab assembler directives
139741da
RP
158differentiated by the first word of the stab. The name of the directive
159describes what combination of four possible data fields will follow. It
160is either @code{.stabs} (string), @code{.stabn} (number), or
161@code{.stabd} (dot).
e505224d
PB
162
163The overall format of each class of stab is:
164
165@example
139741da
RP
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}
e505224d
PB
169@end example
170
139741da
RP
171In general, in @code{.stabs} the @var{string} field contains name and type
172information. For @code{.stabd} the value field is implicit and has the value
e505224d
PB
173of the current file location. Otherwise the value field often
174contains a relocatable address, frame pointer offset, or register
175number, that maps to the source code element described by the stab.
176
6897f9ec
JK
177The number in the type field gives some basic information about what
178type of stab this is (or whether it @emph{is} a stab, as opposed to an
179ordinary symbol). Each possible type number defines a different stab
180type. The stab type further defines the exact interpretation of, and
181possible values for, any remaining @code{"@var{string}"}, @var{desc}, or
139741da 182@var{value} fields present in the stab. Table A (@pxref{Stab
6897f9ec
JK
183types,,Table A: Symbol types from stabs}) lists in numeric order the
184possible type field values for stab directives. The reference section
185that follows Table A describes the meaning of the fields for each stab
186type in detail. The examples that follow this overview introduce the
187stab types in terms of the source code elements they describe.
e505224d 188
139741da
RP
189For @code{.stabs} the @code{"@var{string}"} field holds the meat of the
190debugging information. The generally unstructured nature of this field
191is what makes stabs extensible. For some stab types the string field
192contains only a name. For other stab types the contents can be a great
193deal more complex.
e505224d 194
139741da 195The overall format is of the @code{"@var{string}"} field is:
e505224d
PB
196
197@example
139741da
RP
198"@var{name}@r{[}:@var{symbol_descriptor}@r{]}
199 @r{[}@var{type_number}@r{[}=@var{type_descriptor} @r{@dots{}]]}"
e505224d
PB
200@end example
201
139741da 202@var{name} is the name of the symbol represented by the stab.
6897f9ec 203@var{name} can be omitted, which means the stab represents an unnamed
8c59ee11 204object. For example, @samp{:t10=*2} defines type 10 as a pointer to
6897f9ec
JK
205type 2, but does not give the type a name. Omitting the @var{name}
206field is supported by AIX dbx and GDB after about version 4.8, but not
207other debuggers.
e505224d 208
139741da
RP
209The @var{symbol_descriptor} following the @samp{:} is an alphabetic
210character that tells more specifically what kind of symbol the stab
211represents. If the @var{symbol_descriptor} is omitted, but type
212information follows, then the stab represents a local variable. For a
8c59ee11 213list of symbol descriptors, see @ref{Symbol Descriptors,,Table C: Symbol
139741da 214descriptors}.
e505224d 215
6897f9ec
JK
216The @samp{c} symbol descriptor is an exception in that it is not
217followed by type information. @xref{Constants}.
218
139741da
RP
219Type information is either a @var{type_number}, or a
220@samp{@var{type_number}=}. The @var{type_number} alone is a type
221reference, referring directly to a type that has already been defined.
e505224d 222
139741da
RP
223The @samp{@var{type_number}=} is a type definition, where the number
224represents a new type which is about to be defined. The type definition
225may refer to other types by number, and those type numbers may be
226followed by @samp{=} and nested definitions.
e505224d
PB
227
228In a type definition, if the character that follows the equals sign is
139741da
RP
229non-numeric then it is a @var{type_descriptor}, and tells what kind of
230type is about to be defined. Any other values following the
231@var{type_descriptor} vary, depending on the @var{type_descriptor}. If
232a number follows the @samp{=} then the number is a @var{type_reference}.
233This is described more thoroughly in the section on types. @xref{Type
234Descriptors,,Table D: Type Descriptors}, for a list of
235@var{type_descriptor} values.
236
6897f9ec
JK
237There is an AIX extension for type attributes. Following the @samp{=}
238is any number of type attributes. Each one starts with @samp{@@} and
239ends with @samp{;}. Debuggers, including AIX's dbx, skip any type
8c59ee11
JK
240attributes they do not recognize. GDB 4.9 does not do this--it will
241ignore the entire symbol containing a type attribute. Hopefully this
242will be fixed in the next GDB release. Because of a conflict with C++
243(@pxref{Cplusplus}), new attributes should not be defined which begin
244with a digit, @samp{(}, or @samp{-}; GDB may be unable to distinguish
245those from the C++ type descriptor @samp{@@}. The attributes are:
6897f9ec
JK
246
247@table @code
248@item a@var{boundary}
8c59ee11 249@var{boundary} is an integer specifying the alignment. I assume it
6897f9ec
JK
250applies to all variables of this type.
251
252@item s@var{size}
8c59ee11 253Size in bits of a variable of this type.
6897f9ec
JK
254
255@item p@var{integer}
256Pointer class (for checking). Not sure what this means, or how
257@var{integer} is interpreted.
258
259@item P
260Indicate this is a packed type, meaning that structure fields or array
261elements are placed more closely in memory, to save memory at the
262expense of speed.
263@end table
264
b6963343
JK
265All this can make the @code{"@var{string}"} field quite long. All
266versions of GDB, and some versions of DBX, can handle arbitrarily long
267strings. But many versions of DBX cretinously limit the strings to
268about 80 characters, so compilers which must work with such DBX's need
269to split the @code{.stabs} directive into several @code{.stabs}
270directives. Each stab duplicates exactly all but the
6897f9ec 271@code{"@var{string}"} field. The @code{"@var{string}"} field of
b6963343
JK
272every stab except the last is marked as continued with a
273double-backslash at the end. Removing the backslashes and concatenating
274the @code{"@var{string}"} fields of each stab produces the original,
275long string.
e505224d 276
899bafeb 277@node C example
e505224d
PB
278@section A simple example in C source
279
280To get the flavor of how stabs describe source information for a C
281program, let's look at the simple program:
282
283@example
284main()
285@{
139741da 286 printf("Hello world");
e505224d
PB
287@}
288@end example
289
139741da
RP
290When 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
292to parts of the @file{.s} file in the description of the stabs that
293follows.
e505224d 294
899bafeb 295@node Assembly code
e505224d
PB
296@section The simple example at the assembly level
297
298@example
2991 gcc2_compiled.:
3002 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
3013 .stabs "hello.c",100,0,0,Ltext0
3024 .text
3035 Ltext0:
3046 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
3057 .stabs "char:t2=r2;0;127;",128,0,0,0
3068 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
3079 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
30810 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
30911 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
31012 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
31113 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
31214 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
31315 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
31416 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
31517 .stabs "float:t12=r1;4;0;",128,0,0,0
31618 .stabs "double:t13=r1;8;0;",128,0,0,0
31719 .stabs "long double:t14=r1;8;0;",128,0,0,0
31820 .stabs "void:t15=15",128,0,0,0
139741da 31921 .align 4
e505224d 32022 LC0:
139741da
RP
32123 .ascii "Hello, world!\12\0"
32224 .align 4
32325 .global _main
32426 .proc 1
e505224d
PB
32527 _main:
32628 .stabn 68,0,4,LM1
32729 LM1:
139741da
RP
32830 !#PROLOGUE# 0
32931 save %sp,-136,%sp
33032 !#PROLOGUE# 1
33133 call ___main,0
33234 nop
e505224d
PB
33335 .stabn 68,0,5,LM2
33436 LM2:
33537 LBB2:
139741da
RP
33638 sethi %hi(LC0),%o1
33739 or %o1,%lo(LC0),%o0
33840 call _printf,0
33941 nop
e505224d
PB
34042 .stabn 68,0,6,LM3
34143 LM3:
34244 LBE2:
34345 .stabn 68,0,6,LM4
34446 LM4:
34547 L1:
139741da
RP
34648 ret
34749 restore
e505224d
PB
34850 .stabs "main:F1",36,0,0,_main
34951 .stabn 192,0,0,LBB2
35052 .stabn 224,0,0,LBE2
351@end example
352
139741da 353This simple ``hello world'' example demonstrates several of the stab
e505224d
PB
354types used to describe C language source files.
355
899bafeb 356@node Program structure
139741da 357@chapter Encoding for the structure of the program
e505224d
PB
358
359@menu
360* Source file:: The path and name of the source file
361* Line numbers::
362* Procedures::
8d0dca57 363* Block Structure::
e505224d
PB
364@end menu
365
899bafeb 366@node Source file
e505224d
PB
367@section The path and name of the source file
368
139741da
RP
369@table @strong
370@item Directive:
371@code{.stabs}
372@item Type:
373@code{N_SO}
374@end table
e505224d
PB
375
376The first stabs in the .s file contain the name and path of the source
377file that was compiled to produce the .s file. This information is
378contained in two records of stab type N_SO (100).
379
380@example
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
383@end example
384
385@example
3862 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
3873 .stabs "hello.c",100,0,0,Ltext0
139741da 3884 .text
e505224d
PB
3895 Ltext0:
390@end example
391
899bafeb 392@node Line numbers
e505224d
PB
393@section Line Numbers
394
139741da
RP
395@table @strong
396@item Directive:
397@code{.stabn}
398@item Type:
399@code{N_SLINE}
400@end table
e505224d 401
139741da 402The start of source lines is represented by the @code{N_SLINE} (68) stab
e505224d
PB
403type.
404
405@example
139741da 406.stabn N_SLINE, NIL, @var{line}, @var{address}
e505224d
PB
407@end example
408
139741da
RP
409@var{line} is a source line number; @var{address} represents the code
410address for the start of that source line.
411
e505224d
PB
412@example
41327 _main:
41428 .stabn 68,0,4,LM1
41529 LM1:
139741da 41630 !#PROLOGUE# 0
e505224d
PB
417@end example
418
899bafeb 419@node Procedures
6897f9ec
JK
420@section Procedures
421
422All of the following stabs use the @samp{N_FUN} symbol type.
423
424A 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
427of the function. The value field is the address of the start of the
428function. The type information of the stab represents the return type
429of the function; thus @samp{foo:f5} means that foo is a function
430returning type 5.
431
432The AIX documentation also defines symbol descriptor @samp{J} as an
433internal function. I assume this means a function nested within another
434function. It also says Symbol descriptor @samp{m} is a module in
435Modula-2 or extended Pascal.
436
437Procedures (functions which do not return values) are represented as
438functions returning the void type in C. I don't see why this couldn't
439be used for all languages (inventing a void type for this purpose if
440necessary), but the AIX documentation defines @samp{I}, @samp{P}, and
441@samp{Q} for internal, global, and static procedures, respectively.
442These symbol descriptors are unusual in that they are not followed by
443type information.
444
8c59ee11
JK
445For any of the above symbol descriptors, after the symbol descriptor and
446the type information, there is optionally a comma, followed by the name
447of the procedure, followed by a comma, followed by a name specifying the
448scope. The first name is local to the scope specified. I assume then
449that the name of the symbol (before the @samp{:}), if specified, is some
450sort of global name. I assume the name specifying the scope is the name
451of a function specifying that scope. This feature is an AIX extension,
452and this information is based on the manual; I haven't actually tried
453it.
6897f9ec
JK
454
455The stab representing a procedure is located immediately following the
456code of the procedure. This stab is in turn directly followed by a
457group of other stabs describing elements of the procedure. These other
458stabs describe the procedure's parameters, its block local variables and
459its block structure.
e505224d
PB
460
461@example
139741da
RP
46248 ret
46349 restore
e505224d
PB
464@end example
465
139741da
RP
466The @code{.stabs} entry after this code fragment shows the @var{name} of
467the procedure (@code{main}); the type descriptor @var{desc} (@code{F},
468for a global procedure); a reference to the predefined type @code{int}
469for the return type; and the starting @var{address} of the procedure.
470
471Here is an exploded summary (with whitespace introduced for clarity),
472followed by line 50 of our sample assembly output, which has this form:
473
e505224d 474@example
139741da
RP
475.stabs "@var{name}:
476 @var{desc} @r{(global proc @samp{F})}
477 @var{return_type_ref} @r{(int)}
478 ",N_FUN, NIL, NIL,
479 @var{address}
e505224d
PB
480@end example
481
482@example
48350 .stabs "main:F1",36,0,0,_main
484@end example
485
899bafeb 486@node Block Structure
e505224d
PB
487@section Block Structure
488
139741da
RP
489@table @strong
490@item Directive:
491@code{.stabn}
492@item Types:
493@code{N_LBRAC}, @code{N_RBRAC}
494@end table
e505224d 495
139741da
RP
496The program's block structure is represented by the @code{N_LBRAC} (left
497brace) and the @code{N_RBRAC} (right brace) stab types. The following code
498range, which is the body of @code{main}, is labeled with @samp{LBB2:} at the
499beginning and @samp{LBE2:} at the end.
e505224d
PB
500
501@example
50237 LBB2:
139741da
RP
50338 sethi %hi(LC0),%o1
50439 or %o1,%lo(LC0),%o0
50540 call _printf,0
50641 nop
e505224d
PB
50742 .stabn 68,0,6,LM3
50843 LM3:
50944 LBE2:
510@end example
511
139741da
RP
512The @code{N_LBRAC} and @code{N_RBRAC} stabs that describe the block
513scope of the procedure are located after the @code{N_FUNC} stab that
514represents 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}.
e505224d
PB
517
518@example
51950 .stabs "main:F1",36,0,0,_main
520@end example
521
522@example
139741da
RP
523 .stabn N_LBRAC, NIL, NIL, @var{left-brace-address}
524 .stabn N_RBRAC, NIL, NIL, @var{right-brace-address}
e505224d
PB
525@end example
526
527@example
52851 .stabn 192,0,0,LBB2
52952 .stabn 224,0,0,LBE2
530@end example
531
6897f9ec
JK
532@node Constants
533@chapter Constants
534
535The @samp{c} symbol descriptor indicates that this stab represents a
536constant. This symbol descriptor is an exception to the general rule
537that symbol descriptors are followed by type information. Instead, it
538is followed by @samp{=} and one of the following:
539
540@table @code
b273dc0f 541@item b @var{value}
6897f9ec
JK
542Boolean constant. @var{value} is a numeric value; I assume it is 0 for
543false or 1 for true.
544
b273dc0f 545@item c @var{value}
6897f9ec
JK
546Character constant. @var{value} is the numeric value of the constant.
547
b273dc0f
JK
548@item e @var{type-information} , @var{value}
549Constant whose value can be represented as integral.
550@var{type-information} is the type of the constant, as it would appear
551after a symbol descriptor (@pxref{Stabs Format}). @var{value} is the
552numeric value of the constant. GDB 4.9 does not actually get the right
553value if @var{value} does not fit in a host @code{int}, but it does not
554do anything violent, and future debuggers could be extended to accept
555integers of any size (whether unsigned or not). This constant type is
556usually documented as being only for enumeration constants, but GDB has
557never imposed that restriction; I don't know about other debuggers.
558
559@item i @var{value}
560Integer constant. @var{value} is the numeric value. The type is some
561sort of generic integer type (for GDB, a host @code{int}); to specify
562the type explicitly, use @samp{e} instead.
563
564@item r @var{value}
6897f9ec
JK
565Real constant. @var{value} is the real value, which can be @samp{INF}
566(optionally preceded by a sign) for infinity, @samp{QNAN} for a quiet
567NaN (not-a-number), or @samp{SNAN} for a signalling NaN. If it is a
568normal number the format is that accepted by the C library function
569@code{atof}.
570
b273dc0f 571@item s @var{string}
6897f9ec
JK
572String constant. @var{string} is a string enclosed in either @samp{'}
573(in which case @samp{'} characters within the string are represented as
574@samp{\'} or @samp{"} (in which case @samp{"} characters within the
575string are represented as @samp{\"}).
576
b273dc0f 577@item S @var{type-information} , @var{elements} , @var{bits} , @var{pattern}
6897f9ec 578Set constant. @var{type-information} is the type of the constant, as it
8c59ee11 579would appear after a symbol descriptor (@pxref{Stabs Format}).
6897f9ec
JK
580@var{elements} is the number of elements in the set (is this just the
581number of bits set in @var{pattern}? Or redundant with the type? I
582don't get it), @var{bits} is the number of bits in the constant (meaning
583it specifies the length of @var{pattern}, I think), and @var{pattern} is
584a hexadecimal representation of the set. AIX documentation refers to a
585limit of 32 bytes, but I see no reason why this limit should exist.
b273dc0f
JK
586This form could probably be used for arbitrary constants, not just sets;
587the only catch is that @var{pattern} should be understood to be target,
588not host, byte order and format.
6897f9ec
JK
589@end table
590
591The boolean, character, string, and set constants are not supported by
592GDB 4.9, but it will ignore them. GDB 4.8 and earlier gave an error
593message and refused to read symbols from the file containing the
594constants.
595
596This information is followed by @samp{;}.
597
899bafeb 598@node Example
e505224d
PB
599@chapter A Comprehensive Example in C
600
139741da 601Now we'll examine a second program, @code{example2}, which builds on the
e505224d
PB
602first example to introduce the rest of the stab types, symbol
603descriptors, and type descriptors used in C.
139741da
RP
604@xref{Example2.c} for the complete @file{.c} source,
605and @pxref{Example2.s} for the @file{.s} assembly code.
e505224d
PB
606This description includes parts of those files.
607
608@section Flow of control and nested scopes
609
9cd64d11 610@table @strong
139741da
RP
611@item Directive:
612@code{.stabn}
613@item Types:
614@code{N_SLINE}, @code{N_LBRAC}, @code{N_RBRAC} (cont.)
615@end table
e505224d 616
899bafeb
RP
617Consider the body of @code{main}, from @file{example2.c}. It shows more
618about how @code{N_SLINE}, @code{N_RBRAC}, and @code{N_LBRAC} stabs are used.
e505224d
PB
619
620@example
62120 @{
62221 static float s_flap;
139741da
RP
62322 int times;
62423 for (times=0; times < s_g_repeat; times++)@{
62524 int inner;
62625 printf ("Hello world\n");
62726 @}
e505224d
PB
62827 @};
629@end example
630
899bafeb 631Here we have a single source line, the @samp{for} line, that generates
e505224d 632non-linear flow of control, and non-contiguous code. In this case, an
899bafeb 633@code{N_SLINE} stab with the same line number proceeds each block of
e505224d
PB
634non-contiguous code generated from the same source line.
635
139741da
RP
636The example also shows nested scopes. The @code{N_LBRAC} and
637@code{N_LBRAC} stabs that describe block structure are nested in the
638same order as the corresponding code blocks, those of the for loop
639inside those for the body of main.
e505224d 640
139741da
RP
641@noindent
642This is the label for the @code{N_LBRAC} (left brace) stab marking the
643start of @code{main}.
e505224d 644
139741da 645@example
e505224d 64657 LBB2:
139741da
RP
647@end example
648
649@noindent
650In the first code range for C source line 23, the @code{for} loop
651initialize and test, @code{N_SLINE} (68) records the line number:
e505224d 652
139741da
RP
653@example
654.stabn N_SLINE, NIL,
655 @var{line},
656 @var{address}
e505224d 657
e505224d
PB
65858 .stabn 68,0,23,LM2
65959 LM2:
139741da 66060 st %g0,[%fp-20]
e505224d 66161 L2:
139741da
RP
66262 sethi %hi(_s_g_repeat),%o0
66363 ld [%fp-20],%o1
66464 ld [%o0+%lo(_s_g_repeat)],%o0
66565 cmp %o1,%o0
66666 bge L3
66767 nop
e505224d 668
139741da 669@exdent label for the @code{N_LBRAC} (start block) marking the start of @code{for} loop
e505224d 670
e505224d
PB
67168 LBB3:
67269 .stabn 68,0,25,LM3
67370 LM3:
139741da
RP
67471 sethi %hi(LC0),%o1
67572 or %o1,%lo(LC0),%o0
67673 call _printf,0
67774 nop
e505224d
PB
67875 .stabn 68,0,26,LM4
67976 LM4:
e505224d 680
139741da 681@exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
e505224d 682
e505224d 68377 LBE3:
139741da 684@end example
e505224d 685
139741da
RP
686@noindent
687Now we come to the second code range for source line 23, the @code{for}
688loop increment and return. Once again, @code{N_SLINE} (68) records the
689source line number:
612dbd4c 690
139741da
RP
691@example
692.stabn, N_SLINE, NIL,
693 @var{line},
694 @var{address}
e505224d 695
e505224d
PB
69678 .stabn 68,0,23,LM5
69779 LM5:
69880 L4:
139741da
RP
69981 ld [%fp-20],%o0
70082 add %o0,1,%o1
70183 st %o1,[%fp-20]
70284 b,a L2
e505224d
PB
70385 L3:
70486 .stabn 68,0,27,LM6
70587 LM6:
e505224d 706
139741da 707@exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
e505224d 708
e505224d
PB
70988 LBE2:
71089 .stabn 68,0,27,LM7
71190 LM7:
71291 L1:
139741da
RP
71392 ret
71493 restore
e505224d
PB
71594 .stabs "main:F1",36,0,0,_main
71695 .stabs "argc:p1",160,0,0,68
71796 .stabs "argv:p20=*21=*2",160,0,0,72
71897 .stabs "s_flap:V12",40,0,0,_s_flap.0
71998 .stabs "times:1",128,0,0,-20
139741da
RP
720@end example
721
722@noindent
723Here is an illustration of stabs describing nested scopes. The scope
724nesting is reflected in the nested bracketing stabs (@code{N_LBRAC},
725192, appears here).
e505224d 726
139741da
RP
727@example
728.stabn N_LBRAC,NIL,NIL,
729 @var{block-start-address}
e505224d
PB
730
73199 .stabn 192,0,0,LBB2 ## begin proc label
732100 .stabs "inner:1",128,0,0,-24
733101 .stabn 192,0,0,LBB3 ## begin for label
139741da 734@end example
e505224d 735
139741da
RP
736@noindent
737@code{N_RBRAC} (224), ``right brace'' ends a lexical block (scope).
738
739@example
740.stabn N_RBRAC,NIL,NIL,
741 @var{block-end-address}
e505224d
PB
742
743102 .stabn 224,0,0,LBE3 ## end for label
744103 .stabn 224,0,0,LBE2 ## end proc label
745@end example
746
899bafeb 747@node Variables
e505224d
PB
748@chapter Variables
749
750@menu
751* Automatic variables:: locally scoped
8d0dca57 752* Global Variables::
e505224d
PB
753* Register variables::
754* Initialized statics::
755* Un-initialized statics::
756* Parameters::
757@end menu
758
899bafeb 759@node Automatic variables
e505224d
PB
760@section Locally scoped automatic variables
761
139741da
RP
762@table @strong
763@item Directive:
764@code{.stabs}
765@item Type:
766@code{N_LSYM}
767@item Symbol Descriptor:
768none
769@end table
e505224d 770
139741da
RP
771In addition to describing types, the @code{N_LSYM} stab type also
772describes locally scoped automatic variables. Refer again to the body
773of @code{main} in @file{example2.c}. It allocates two automatic
774variables: @samp{times} is scoped to the body of @code{main}, and
775@samp{inner} is scoped to the body of the @code{for} loop.
776@samp{s_flap} is locally scoped but not automatic, and will be discussed
777later.
e505224d
PB
778
779@example
78020 @{
78121 static float s_flap;
139741da
RP
78222 int times;
78323 for (times=0; times < s_g_repeat; times++)@{
78424 int inner;
78525 printf ("Hello world\n");
78626 @}
e505224d
PB
78727 @};
788@end example
789
139741da
RP
790The @code{N_LSYM} stab for an automatic variable is located just before the
791@code{N_LBRAC} stab describing the open brace of the block to which it is
e505224d
PB
792scoped.
793
794@example
139741da
RP
795@exdent @code{N_LSYM} (128): automatic variable, scoped locally to @code{main}
796
797.stabs "@var{name}:
8c59ee11 798 @var{type information}",
139741da
RP
799 N_LSYM, NIL, NIL,
800 @var{frame-pointer-offset}
e505224d
PB
801
80298 .stabs "times:1",128,0,0,-20
80399 .stabn 192,0,0,LBB2 ## begin `main' N_LBRAC
804
139741da
RP
805@exdent @code{N_LSYM} (128): automatic variable, scoped locally to the @code{for} loop
806
807.stabs "@var{name}:
8c59ee11 808 @var{type information}",
139741da
RP
809 N_LSYM, NIL, NIL,
810 @var{frame-pointer-offset}
e505224d
PB
811
812100 .stabs "inner:1",128,0,0,-24
813101 .stabn 192,0,0,LBB3 ## begin `for' loop N_LBRAC
814@end example
815
8c59ee11
JK
816The symbol descriptor is omitted for automatic variables. Since type
817information should being with a digit, @samp{-}, or @samp{(}, only
818digits, @samp{-}, and @samp{(} are precluded from being used for symbol
819descriptors by this fact. However, the Acorn RISC machine (ARM) is said
820to get this wrong: it puts out a mere type definition here, without the
821preceding @code{@var{typenumber}=}. This is a bad idea; there is no
822guarantee that type descriptors are distinct from symbol descriptors.
e505224d 823
899bafeb 824@node Global Variables
e505224d
PB
825@section Global Variables
826
139741da
RP
827@table @strong
828@item Directive:
829@code{.stabs}
830@item Type:
831@code{N_GSYM}
832@item Symbol Descriptor:
833@code{G}
834@end table
e505224d 835
139741da
RP
836Global variables are represented by the @code{N_GSYM} stab type. The symbol
837descriptor, following the colon in the string field, is @samp{G}. Following
838the @samp{G} is a type reference or type definition. In this example it is a
839type reference to the basic C type, @code{char}. The first source line in
840@file{example2.c},
e505224d
PB
841
842@example
8431 char g_foo = 'c';
844@end example
845
139741da
RP
846@noindent
847yields the following stab. The stab immediately precedes the code that
e505224d
PB
848allocates storage for the variable it describes.
849
850@example
139741da
RP
851@exdent @code{N_GSYM} (32): global symbol
852
853.stabs "@var{name}:
854 @var{descriptor}
855 @var{type-ref}",
856 N_GSYM, NIL, NIL, NIL
e505224d 857
e505224d 85821 .stabs "g_foo:G2",32,0,0,0
139741da
RP
85922 .global _g_foo
86023 .data
e505224d 86124 _g_foo:
139741da 86225 .byte 99
e505224d
PB
863@end example
864
139741da
RP
865The address of the variable represented by the @code{N_GSYM} is not contained
866in the @code{N_GSYM} stab. The debugger gets this information from the
e505224d
PB
867external symbol for the global variable.
868
899bafeb 869@node Register variables
6897f9ec 870@section Register variables
139741da 871
8c59ee11
JK
872@c According to an old version of this manual, AIX uses C_RPSYM instead
873@c of C_RSYM. I am skeptical; this should be verified.
6897f9ec
JK
874Register variables have their own stab type, @code{N_RSYM}, and their
875own symbol descriptor, @code{r}. The stab's value field contains the
876number of the register where the variable data will be stored.
e505224d 877
6897f9ec 878The value is the register number.
e505224d 879
6897f9ec
JK
880AIX defines a separate symbol descriptor @samp{d} for floating point
881registers. This seems incredibly stupid--why not just just give
8c59ee11
JK
882floating point registers different register numbers? I have not
883verified whether the compiler actually uses @samp{d}.
e505224d 884
6897f9ec
JK
885If the register is explicitly allocated to a global variable, but not
886initialized, as in
e505224d
PB
887
888@example
6897f9ec 889register int g_bar asm ("%g5");
e505224d
PB
890@end example
891
6897f9ec
JK
892the stab may be emitted at the end of the object file, with
893the other bss symbols.
e505224d 894
899bafeb 895@node Initialized statics
e505224d
PB
896@section Initialized static variables
897
139741da
RP
898@table @strong
899@item Directive:
900@code{.stabs}
901@item Type:
902@code{N_STSYM}
903@item Symbol Descriptors:
904@code{S} (file scope), @code{V} (procedure scope)
905@end table
e505224d 906
139741da
RP
907Initialized static variables are represented by the @code{N_STSYM} stab
908type. The symbol descriptor part of the string field shows if the
909variable is file scope static (@samp{S}) or procedure scope static
910(@samp{V}). The source line
e505224d
PB
911
912@example
9133 static int s_g_repeat = 2;
914@end example
915
139741da
RP
916@noindent
917yields the following code. The stab is located immediately preceding
e505224d 918the storage for the variable it represents. Since the variable in
139741da 919this example is file scope static the symbol descriptor is @samp{S}.
e505224d
PB
920
921@example
139741da
RP
922@exdent @code{N_STSYM} (38): initialized static variable (data seg w/internal linkage)
923
924.stabs "@var{name}:
925 @var{descriptor}
926 @var{type-ref}",
927 N_STSYM,NIL,NIL,
928 @var{address}
929
e505224d 93026 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
139741da 93127 .align 4
e505224d 93228 _s_g_repeat:
139741da 93329 .word 2
e505224d
PB
934@end example
935
936
899bafeb 937@node Un-initialized statics
e505224d
PB
938@section Un-initialized static variables
939
139741da
RP
940@table @strong
941@item Directive:
942@code{.stabs}
943@item Type:
944@code{N_LCSYM}
945@item Symbol Descriptors:
946@code{S} (file scope), @code{V} (procedure scope)
947@end table
e505224d 948
139741da
RP
949Un-initialized static variables are represented by the @code{N_LCSYM}
950stab type. The symbol descriptor part of the string shows if the
951variable is file scope static (@samp{S}) or procedure scope static
952(@samp{V}). In this example it is procedure scope static. The source
953line allocating @code{s_flap} immediately follows the open brace for the
954procedure @code{main}.
e505224d
PB
955
956@example
95720 @{
95821 static float s_flap;
959@end example
960
139741da
RP
961The code that reserves storage for the variable @code{s_flap} precedes the
962body of body of @code{main}.
e505224d
PB
963
964@example
139741da 96539 .reserve _s_flap.0,4,"bss",4
e505224d
PB
966@end example
967
139741da
RP
968But since @code{s_flap} is scoped locally to @code{main}, its stab is
969located with the other stabs representing symbols local to @code{main}.
970The stab for @code{s_flap} is located just before the @code{N_LBRAC} for
971@code{main}.
e505224d
PB
972
973@example
139741da
RP
974@exdent @code{N_LCSYM} (40): uninitialized static var (BSS seg w/internal linkage)
975
976.stabs "@var{name}:
977 @var{descriptor}
978 @var{type-ref}",
979 N_LCSYM, NIL, NIL,
980 @var{address}
e505224d 981
e505224d
PB
98297 .stabs "s_flap:V12",40,0,0,_s_flap.0
98398 .stabs "times:1",128,0,0,-20
139741da 98499 .stabn 192,0,0,LBB2 # N_LBRAC for main.
e505224d
PB
985@end example
986
139741da
RP
987@c ............................................................
988
899bafeb 989@node Parameters
e505224d
PB
990@section Parameters
991
497e44a5 992The symbol descriptor @samp{p} is used to refer to parameters which are
b82ea042
JK
993in the arglist. Symbols have symbol type @samp{N_PSYM}. The value of
994the symbol is the offset relative to the argument list.
995
996If the parameter is passed in a register, then the traditional way to do
497e44a5 997this is to provide two symbols for each argument:
e505224d
PB
998
999@example
b82ea042
JK
1000.stabs "arg:p1" . . . ; N_PSYM
1001.stabs "arg:r1" . . . ; N_RSYM
e505224d
PB
1002@end example
1003
497e44a5
JK
1004Debuggers are expected to use the second one to find the value, and the
1005first one to know that it is an argument.
e505224d 1006
b82ea042
JK
1007Because this is kind of ugly, some compilers use symbol descriptor
1008@samp{P} or @samp{R} to indicate an argument which is in a register.
1009The symbol value is the register number. @samp{P} and @samp{R} mean the
1010same thing, the difference is that @samp{P} is a GNU invention and
1011@samp{R} is an IBM (xcoff) invention. As of version 4.9, GDB should
1012handle either one. Symbol type @samp{C_RPSYM} is used with @samp{R} and
1013@samp{N_RSYM} is used with @samp{P}.
1014
6897f9ec
JK
1015AIX, according to the documentation, uses @samp{D} for a parameter
1016passed in a floating point register. This strikes me as incredibly
1017bogus---why doesn't it just use @samp{R} with a register number which
23aed449 1018indicates that it's a floating point register? I haven't verified
6897f9ec
JK
1019whether the system actually does what the documentation indicates.
1020
a2a2eac8
JK
1021There is at least one case where GCC uses a @samp{p}/@samp{r} pair
1022rather than @samp{P}; this is where the argument is passed in the
1023argument list and then loaded into a register.
1024
c156f3c1
JK
1025On the sparc and hppa, for a @samp{P} symbol whose type is a structure
1026or union, the register contains the address of the structure. On the
1027sparc, this is also true of a @samp{p}/@samp{r} pair (using Sun cc) or a
1028@samp{p} symbol. However, if a (small) structure is really in a
1029register, @samp{r} is used. And, to top it all off, on the hppa it
1030might be a structure which was passed on the stack and loaded into a
1031register and for which there is a @samp{p}/@samp{r} pair! I believe
6897f9ec
JK
1032that symbol descriptor @samp{i} is supposed to deal with this case, (it
1033is said to mean "value parameter by reference, indirect access", I don't
1034know the source for this information) but I don't know details or what
1035compilers or debuggers use it, if any (not GDB or GCC). It is not clear
1036to me whether this case needs to be dealt with differently than
1037parameters passed by reference (see below).
c156f3c1 1038
b82ea042 1039There is another case similar to an argument in a register, which is an
98ef6f31
JK
1040argument which is actually stored as a local variable. Sometimes this
1041happens when the argument was passed in a register and then the compiler
1042stores it as a local variable. If possible, the compiler should claim
1043that it's in a register, but this isn't always done. Some compilers use
1044the pair of symbols approach described above ("arg:p" followed by
1045"arg:"); this includes gcc1 (not gcc2) on the sparc when passing a small
23aed449
JK
1046structure and gcc2 (sometimes) when the argument type is float and it is
1047passed as a double and converted to float by the prologue (in the latter
1048case the type of the "arg:p" symbol is double and the type of the "arg:"
1049symbol is float). GCC, at least on the 960, uses a single @samp{p}
1050symbol descriptor for an argument which is stored as a local variable
1051but uses @samp{N_LSYM} instead of @samp{N_PSYM}. In this case the value
1052of the symbol is an offset relative to the local variables for that
1053function, not relative to the arguments (on some machines those are the
1054same thing, but not on all).
e505224d 1055
6897f9ec
JK
1056If the parameter is passed by reference (e.g. Pascal VAR parameters),
1057then type symbol descriptor is @samp{v} if it is in the argument list,
1058or @samp{a} if it in a register. Other than the fact that these contain
1059the address of the parameter other than the parameter itself, they are
1060identical to @samp{p} and @samp{R}, respectively. I believe @samp{a} is
1061an AIX invention; @samp{v} is supported by all stabs-using systems as
1062far as I know.
1063
1064@c Is this paragraph correct? It is based on piecing together patchy
1065@c information and some guesswork
1066Conformant arrays refer to a feature of Modula-2, and perhaps other
1067languages, in which the size of an array parameter is not known to the
1068called function until run-time. Such parameters have two stabs, a
1069@samp{x} for the array itself, and a @samp{C}, which represents the size
1070of the array. The value of the @samp{x} stab is the offset in the
1071argument list where the address of the array is stored (it this right?
1072it is a guess); the value of the @samp{C} stab is the offset in the
1073argument list where the size of the array (in elements? in bytes?) is
1074stored.
1075
1076The following are also said to go with @samp{N_PSYM}:
a2a2eac8
JK
1077
1078@example
1079"name" -> "param_name:#type"
a2a2eac8 1080 -> pP (<<??>>)
8c59ee11 1081 -> pF FORTRAN function parameter
a2a2eac8
JK
1082 -> X (function result variable)
1083 -> b (based variable)
1084
1085value -> offset from the argument pointer (positive).
1086@end example
1087
497e44a5 1088As a simple example, the code
899bafeb 1089
497e44a5 1090@example
b82ea042
JK
1091main (argc, argv)
1092 int argc;
1093 char **argv;
1094@{
497e44a5
JK
1095@end example
1096
1097produces the stabs
899bafeb 1098
497e44a5 1099@example
b82ea042
JK
1100.stabs "main:F1",36,0,0,_main ; 36 is N_FUN
1101.stabs "argc:p1",160,0,0,68 ; 160 is N_PSYM
1102.stabs "argv:p20=*21=*2",160,0,0,72
e505224d
PB
1103@end example
1104
497e44a5 1105The type definition of argv is interesting because it contains several
a2a2eac8
JK
1106type definitions. Type 21 is pointer to type 2 (char) and argv (type 20) is
1107pointer to type 21.
e505224d 1108
8c59ee11
JK
1109@node Types
1110@chapter Type definitions
e505224d 1111
612dbd4c 1112Now let's look at some variable definitions involving complex types.
e505224d
PB
1113This involves understanding better how types are described. In the
1114examples so far types have been described as references to previously
1115defined types or defined in terms of subranges of or pointers to
1116previously defined types. The section that follows will talk about
1117the various other type descriptors that may follow the = sign in a
1118type definition.
1119
1120@menu
8c59ee11
JK
1121* Builtin types:: Integers, floating point, void, etc.
1122* Miscellaneous Types:: Pointers, sets, files, etc.
1123* Cross-references:: Referring to a type not yet defined.
1124* Subranges:: A type with a specific range.
1125* Arrays:: An aggregate type of same-typed elements.
1126* Strings:: Like an array but also has a length.
1127* Enumerations:: Like an integer but the values have names.
1128* Structures:: An aggregate type of different-typed elements.
1129* Typedefs:: Giving a type a name
e505224d
PB
1130* Unions::
1131* Function types::
1132@end menu
1133
8c59ee11
JK
1134@node Builtin types
1135@section Builtin types
e505224d 1136
8c59ee11
JK
1137Certain types are built in (@code{int}, @code{short}, @code{void},
1138@code{float}, etc.); the debugger recognizes these types and knows how
1139to handle them. Thus don't be surprised if some of the following ways
1140of specifying builtin types do not specify everything that a debugger
1141would need to know about the type---in some cases they merely specify
1142enough information to distinguish the type from other types.
1143
1144The traditional way to define builtin types is convolunted, so new ways
1145have been invented to describe them. Sun's ACC uses the @samp{b} and
1146@samp{R} type descriptors, and IBM uses negative type numbers. GDB can
1147accept all three, as of version 4.8; dbx just accepts the traditional
1148builtin types and perhaps one of the other two formats.
1149
1150@menu
1151* Traditional Builtin Types:: Put on your seatbelts and prepare for kludgery
1152* Builtin Type Descriptors:: Builtin types with special type descriptors
1153* Negative Type Numbers:: Builtin types using negative type numbers
1154@end menu
1155
1156@node Traditional Builtin Types
1157@subsection Traditional Builtin types
1158
1159Often types are defined as subranges of themselves. If the array bounds
1160can fit within an @code{int}, then they are given normally. For example:
1161
1162@example
1163.stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0 ; 128 is N_LSYM
1164.stabs "char:t2=r2;0;127;",128,0,0,0
1165@end example
1166
1167Builtin types can also be described as subranges of @code{int}:
1168
1169@example
1170.stabs "unsigned short:t6=r1;0;65535;",128,0,0,0
1171@end example
1172
b273dc0f
JK
1173If the lower bound of a subrange is 0 and the upper bound is -1, it
1174means that the type is an unsigned integral type whose bounds are too
1175big to describe in an int. Traditionally this is only used for
1176@code{unsigned int} and @code{unsigned long}; GCC also sometimes uses it
1177for @code{long long} and @code{unsigned long long}, and the only way to
1178tell those types apart is to look at their names. On other machines GCC
1179puts out bounds in octal, with a leading 0. In this case a negative
1180bound consists of a number which is a 1 bit followed by a bunch of 0
1181bits, and a positive bound is one in which a bunch of bits are 1.
8c59ee11
JK
1182
1183@example
1184.stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
1185.stabs "long long int:t7=r1;0;-1;",128,0,0,0
1186@end example
1187
b273dc0f
JK
1188If the lower bound of a subrange is 0 and the upper bound is negative,
1189it means that it is an unsigned integral type whose size in bytes is the
1190absolute value of the upper bound. I believe this is a Convex
1191convention for @code{unsigned long long}.
1192
1193If the lower bound of a subrange is negative and the upper bound is 0,
1194it means that the type is a signed integral type whose size in bytes is
1195the absolute value of the lower bound. I believe this is a Convex
1196convention for @code{long long}. To distinguish this from a legitimate
1197subrange, the type should be a subrange of itself. I'm not sure whether
1198this is the case for Convex.
1199
8c59ee11
JK
1200If the upper bound of a subrange is 0, it means that this is a floating
1201point type, and the lower bound of the subrange indicates the number of
1202bytes in the type:
1203
1204@example
1205.stabs "float:t12=r1;4;0;",128,0,0,0
1206.stabs "double:t13=r1;8;0;",128,0,0,0
1207@end example
1208
1209However, GCC writes @code{long double} the same way it writes
1210@code{double}; the only way to distinguish them is by the name:
1211
1212@example
1213.stabs "long double:t14=r1;8;0;",128,0,0,0
1214@end example
1215
1216Complex types are defined the same way as floating-point types; the only
1217way to distinguish a single-precision complex from a double-precision
1218floating-point type is by the name.
1219
1220The C @code{void} type is defined as itself:
1221
1222@example
1223.stabs "void:t15=15",128,0,0,0
1224@end example
1225
1226I'm not sure how a boolean type is represented.
1227
1228@node Builtin Type Descriptors
1229@subsection Defining Builtin Types using Builtin Type Descriptors
1230
1231There are various type descriptors to define builtin types:
1232
1233@table @code
1a8b5668
JK
1234@c FIXME: clean up description of width and offset, once we figure out
1235@c what they mean
8c59ee11
JK
1236@item b @var{signed} @var{char-flag} @var{width} ; @var{offset} ; @var{nbits} ;
1237Define an integral type. @var{signed} is @samp{u} for unsigned or
1238@samp{s} for signed. @var{char-flag} is @samp{c} which indicates this
1239is a character type, or is omitted. I assume this is to distinguish an
1240integral type from a character type of the same size, for example it
1241might make sense to set it for the C type @code{wchar_t} so the debugger
1242can print such variables differently (Solaris does not do this). Sun
1243sets it on the C types @code{signed char} and @code{unsigned char} which
1244arguably is wrong. @var{width} and @var{offset} appear to be for small
1245objects stored in larger ones, for example a @code{short} in an
1246@code{int} register. @var{width} is normally the number of bytes in the
1247type. @var{offset} seems to always be zero. @var{nbits} is the number
1248of bits in the type.
1249
1250Note that type descriptor @samp{b} used for builtin types conflicts with
1251its use for Pascal space types (@pxref{Miscellaneous Types}); they can
1252be distinguished because the character following the type descriptor
1253will be a digit, @samp{(}, or @samp{-} for a Pascal space type, or
1254@samp{u} or @samp{s} for a builtin type.
1255
1256@item w
1257Documented by AIX to define a wide character type, but their compiler
1258actually uses negative type numbers (@pxref{Negative Type Numbers}).
1259
1a8b5668
JK
1260@item R @var{fp_type} ; @var{bytes} ;
1261Define a floating point type. @var{fp_type} has one of the following values:
1262
1263@table @code
1264@item 1 (NF_SINGLE)
1265IEEE 32-bit (single precision) floating point format.
1266
1267@item 2 (NF_DOUBLE)
1268IEEE 64-bit (double precision) floating point format.
1269
1270@item 3 (NF_COMPLEX)
1271@item 4 (NF_COMPLEX16)
1272@item 5 (NF_COMPLEX32)
1273These are for complex numbers. A comment in
1274@file{include/aout/stab_gnu.h} describes them as Fortran complex, double
1275complex, and complex*16, respectively, but what does that mean? (i.e.
1276Single precision? Double precison?).
1277
1278@item 6 (NF_LDOUBLE)
1279Long double. It would be cleaner to define a different code for every
1280possible format of long double.
1281@end table
1282
1283@var{bytes} is the number of bytes occupied by the type. This allows a
1284debugger to perform some operations with the type even if it doesn't
1285understand @var{fp_code}.
8c59ee11
JK
1286
1287@item g @var{type-information} ; @var{nbits}
1288Documented by AIX to define a floating type, but their compiler actually
1289uses negative type numbers (@pxref{Negative Type Numbers}).
1290
1291@item c @var{type-information} ; @var{nbits}
1292Documented by AIX to define a complex type, but their compiler actually
1293uses negative type numbers (@pxref{Negative Type Numbers}).
1294@end table
1295
1296The C @code{void} type is defined as a signed integral type 0 bits long:
1297@example
1298.stabs "void:t19=bs0;0;0",128,0,0,0
1299@end example
1300
1301I'm not sure how a boolean type is represented.
1302
1303@node Negative Type Numbers
1304@subsection Negative Type numbers
1305
1306Since the debugger knows about the builtin types anyway, the idea of
1307negative type numbers is simply to give a special type number which
1308indicates the built in type. There is no stab defining these types.
1309
1310I'm not sure whether anyone has tried to define what this means if
1311@code{int} can be other than 32 bits (or other types can be other than
1312their customary size). If @code{int} has exactly one size for each
1313architecture, then it can be handled easily enough, but if the size of
1314@code{int} can vary according the compiler options, then it gets hairy.
1315I guess the consistent way to do this would be to define separate
1316negative type numbers for 16-bit @code{int} and 32-bit @code{int};
1317therefore I have indicated below the customary size (and other format
1318information) for each type. The information below is currently correct
1319because AIX on the RS6000 is the only system which uses these type
1320numbers. If these type numbers start to get used on other systems, I
1321suspect the correct thing to do is to define a new number in cases where
1322a type does not have the size and format indicated below.
1323
b273dc0f
JK
1324Also note that part of the definition of the negative type number is
1325the name of the type. Types with identical size and format but
1326different names have different negative type numbers.
1327
8c59ee11
JK
1328@table @code
1329@item -1
1330@code{int}, 32 bit signed integral type.
1331
1332@item -2
1333@code{char}, 8 bit type holding a character. Both GDB and dbx on AIX
1334treat this as signed. GCC uses this type whether @code{char} is signed
1335or not, which seems like a bad idea. The AIX compiler (xlc) seems to
1336avoid this type; it uses -5 instead for @code{char}.
1337
1338@item -3
1339@code{short}, 16 bit signed integral type.
1340
1341@item -4
1342@code{long}, 32 bit signed integral type.
1343
1344@item -5
1345@code{unsigned char}, 8 bit unsigned integral type.
1346
1347@item -6
1348@code{signed char}, 8 bit signed integral type.
1349
1350@item -7
1351@code{unsigned short}, 16 bit unsigned integral type.
1352
1353@item -8
1354@code{unsigned int}, 32 bit unsigned integral type.
1355
1356@item -9
1357@code{unsigned}, 32 bit unsigned integral type.
1358
1359@item -10
1360@code{unsigned long}, 32 bit unsigned integral type.
1361
1362@item -11
1363@code{void}, type indicating the lack of a value.
1364
1365@item -12
1366@code{float}, IEEE single precision.
1367
1368@item -13
1369@code{double}, IEEE double precision.
1370
1371@item -14
b273dc0f
JK
1372@code{long double}, IEEE double precision. The compiler claims the size
1373will increase in a future release, and for binary compatibility you have
1374to avoid using @code{long double}. I hope when they increase it they
1375use a new negative type number.
8c59ee11
JK
1376
1377@item -15
b273dc0f 1378@code{integer}. 32 bit signed integral type.
8c59ee11
JK
1379
1380@item -16
b273dc0f 1381@code{boolean}. Only one bit is used, not sure about the actual size of the
8c59ee11
JK
1382type.
1383
1384@item -17
b273dc0f 1385@code{short real}. IEEE single precision.
8c59ee11
JK
1386
1387@item -18
b273dc0f 1388@code{real}. IEEE double precision.
8c59ee11
JK
1389
1390@item -19
b273dc0f 1391@code{stringptr}. @xref{Strings}.
8c59ee11
JK
1392
1393@item -20
1394@code{character}, 8 bit unsigned type.
1395
1396@item -21
1397@code{logical*1}, 8 bit unsigned integral type.
1398
1399@item -22
1400@code{logical*2}, 16 bit unsigned integral type.
1401
1402@item -23
1403@code{logical*4}, 32 bit unsigned integral type.
1404
1405@item -24
1406@code{logical}, 32 bit unsigned integral type.
1407
1408@item -25
b273dc0f
JK
1409@code{complex}. A complex type consisting of two IEEE single-precision
1410floating point values.
8c59ee11
JK
1411
1412@item -26
b273dc0f
JK
1413@code{complex}. A complex type consisting of two IEEE double-precision
1414floating point values.
8c59ee11
JK
1415
1416@item -27
1417@code{integer*1}, 8 bit signed integral type.
1418
1419@item -28
1420@code{integer*2}, 16 bit signed integral type.
1421
1422@item -29
1423@code{integer*4}, 32 bit signed integral type.
1424
1425@item -30
b273dc0f
JK
1426@code{wchar}. Wide character, 16 bits wide (Unicode format?). This is
1427not used for the C type @code{wchar_t}.
8c59ee11
JK
1428@end table
1429
1430@node Miscellaneous Types
1431@section Miscellaneous Types
1432
1433@table @code
1434@item b @var{type-information} ; @var{bytes}
1435Pascal space type. This is documented by IBM; what does it mean?
1436
1437Note that this use of the @samp{b} type descriptor can be distinguished
1438from its use for builtin integral types (@pxref{Builtin Type
1439Descriptors}) because the character following the type descriptor is
1440always a digit, @samp{(}, or @samp{-}.
1441
1442@item B @var{type-information}
1443A volatile-qualified version of @var{type-information}. This is a Sun
1444extension. A volatile-qualified type means that references and stores
1445to a variable of that type must not be optimized or cached; they must
1446occur as the user specifies them.
1447
1448@item d @var{type-information}
1449File of type @var{type-information}. As far as I know this is only used
1450by Pascal.
1451
1452@item k @var{type-information}
1453A const-qualified version of @var{type-information}. This is a Sun
1454extension. A const-qualified type means that a variable of this type
1455cannot be modified.
1456
1457@item M @var{type-information} ; @var{length}
1458Multiple instance type. The type seems to composed of @var{length}
1459repetitions of @var{type-information}, for example @code{character*3} is
1460represented by @samp{M-2;3}, where @samp{-2} is a reference to a
1461character type (@pxref{Negative Type Numbers}). I'm not sure how this
1462differs from an array. This appears to be a FORTRAN feature.
1463@var{length} is a bound, like those in range types, @xref{Subranges}.
1464
1465@item S @var{type-information}
1466Pascal set type. @var{type-information} must be a small type such as an
1467enumeration or a subrange, and the type is a bitmask whose length is
1468specified by the number of elements in @var{type-information}.
1469
1470@item * @var{type-information}
1471Pointer to @var{type-information}.
139741da 1472@end table
e505224d 1473
8c59ee11
JK
1474@node Cross-references
1475@section Cross-references to other types
1476
1477If a type is used before it is defined, one common way to deal with this
1478is just to use a type reference to a type which has not yet been
1479defined. The debugger is expected to be able to deal with this.
1480
1481Another way is with the @samp{x} type descriptor, which is followed by
1482@samp{s} for a structure tag, @samp{u} for a union tag, or @samp{e} for
1483a enumerator tag, followed by the name of the tag, followed by @samp{:}.
1484for example the following C declarations:
e505224d
PB
1485
1486@example
8c59ee11
JK
1487struct foo;
1488struct foo *bar;
e505224d
PB
1489@end example
1490
8c59ee11
JK
1491produce
1492
1493@example
1494.stabs "bar:G16=*17=xsfoo:",32,0,0,0
1495@end example
1496
1497Not all debuggers support the @samp{x} type descriptor, so on some
1498machines GCC does not use it. I believe that for the above example it
1499would just emit a reference to type 17 and never define it, but I
1500haven't verified that.
1501
1502Modula-2 imported types, at least on AIX, use the @samp{i} type
1503descriptor, which is followed by the name of the module from which the
1504type is imported, followed by @samp{:}, followed by the name of the
1505type. There is then optionally a comma followed by type information for
1506the type (This differs from merely naming the type (@pxref{Typedefs}) in
1507that it identifies the module; I don't understand whether the name of
1508the type given here is always just the same as the name we are giving
1509it, or whether this type descriptor is used with a nameless stab
1510(@pxref{Stabs Format}), or what). The symbol ends with @samp{;}.
e505224d 1511
8c59ee11
JK
1512@node Subranges
1513@section Subrange types
1514
1515The @samp{r} type descriptor defines a type as a subrange of another
1516type. It is followed by type information for the type which it is a
1517subrange of, a semicolon, an integral lower bound, a semicolon, an
1518integral upper bound, and a semicolon. The AIX documentation does not
1519specify the trailing semicolon; I believe it is confused.
1520
1521AIX allows the bounds to be one of the following instead of an integer:
1522
1523@table @code
1524@item A @var{offset}
1525The bound is passed by reference on the stack at offset @var{offset}
1526from the argument list. @xref{Parameters}, for more information on such
1527offsets.
1528
1529@item T @var{offset}
1530The bound is passed by value on the stack at offset @var{offset} from
1531the argument list.
1532
1533@item a @var{register-number}
1534The bound is pased by reference in register number
1535@var{register-number}.
1536
1537@item t @var{register-number}
1538The bound is passed by value in register number @var{register-number}.
1539
1540@item J
1541There is no bound.
1542@end table
1543
1544Subranges are also used for builtin types, @xref{Traditional Builtin Types}.
1545
1546@node Arrays
1547@section Array types
1548
1549Arrays use the @samp{a} type descriptor. Following the type descriptor
1550is the type of the index and the type of the array elements. The two
1551types types are not separated by any sort of delimiter; if the type of
1552the index does not end in a semicolon I don't know what is supposed to
1553happen. IBM documents a semicolon between the two types. For the
1554common case (a range type), this ends up as being the same since IBM
1555documents a range type as not ending in a semicolon, but the latter does
1556not accord with common practice, in which range types do end with
1557semicolons.
6aa83a79
JG
1558
1559The type of the index is often a range type, expressed as the letter r
8c59ee11
JK
1560and some parameters. It defines the size of the array. In the example
1561below, the range @code{r1;0;2;} defines an index type which is a
1562subrange of type 1 (integer), with a lower bound of 0 and an upper bound
1563of 2. This defines the valid range of subscripts of a three-element C
1564array.
e505224d 1565
8c59ee11 1566For example, the definition
e505224d
PB
1567
1568@example
8c59ee11
JK
1569char char_vec[3] = @{'a','b','c'@};
1570@end example
e505224d 1571
8c59ee11
JK
1572@noindent
1573produces the output
1574
1575@example
1576.stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
1577 .global _char_vec
1578 .align 4
1579_char_vec:
1580 .byte 97
1581 .byte 98
1582 .byte 99
1583@end example
1584
1585If an array is @dfn{packed}, it means that the elements are spaced more
1586closely than normal, saving memory at the expense of speed. For
1587example, an array of 3-byte objects might, if unpacked, have each
1588element aligned on a 4-byte boundary, but if packed, have no padding.
1589One way to specify that something is packed is with type attributes
1590(@pxref{Stabs Format}), in the case of arrays another is to use the
1591@samp{P} type descriptor instead of @samp{a}. Other than specifying a
1592packed array, @samp{P} is identical to @samp{a}.
1593
1594@c FIXME-what is it? A pointer?
1595An open array is represented by the @samp{A} type descriptor followed by
1596type information specifying the type of the array elements.
1597
1598@c FIXME: what is the format of this type? A pointer to a vector of pointers?
1599An N-dimensional dynamic array is represented by
1600
1601@example
1602D @var{dimensions} ; @var{type-information}
1603@end example
1604
1605@c Does dimensions really have this meaning? The AIX documentation
1606@c doesn't say.
1607@var{dimensions} is the number of dimensions; @var{type-information}
1608specifies the type of the array elements.
1609
1610@c FIXME: what is the format of this type? A pointer to some offsets in
1611@c another array?
1612A subarray of an N-dimensional array is represented by
1613
1614@example
1615E @var{dimensions} ; @var{type-information}
e505224d
PB
1616@end example
1617
8c59ee11
JK
1618@c Does dimensions really have this meaning? The AIX documentation
1619@c doesn't say.
1620@var{dimensions} is the number of dimensions; @var{type-information}
1621specifies the type of the array elements.
1622
1623@node Strings
1624@section Strings
1625
1626Some languages, like C or the original Pascal, do not have string types,
1627they just have related things like arrays of characters. But most
1628Pascals and various other languages have string types, which are
1629indicated as follows:
1630
1631@table @code
1632@item n @var{type-information} ; @var{bytes}
1633@var{bytes} is the maximum length. I'm not sure what
1634@var{type-information} is; I suspect that it means that this is a string
1635of @var{type-information} (thus allowing a string of integers, a string
1636of wide characters, etc., as well as a string of characters). Not sure
1637what the format of this type is. This is an AIX feature.
1638
1639@item z @var{type-information} ; @var{bytes}
1640Just like @samp{n} except that this is a gstring, not an ordinary
1641string. I don't know the difference.
1642
1643@item N
1644Pascal Stringptr. What is this? This is an AIX feature.
1645@end table
1646
899bafeb 1647@node Enumerations
e505224d
PB
1648@section Enumerations
1649
8c59ee11 1650Enumerations are defined with the @samp{e} type descriptor.
e505224d 1651
8c59ee11
JK
1652@c FIXME: Where does this information properly go? Perhaps it is
1653@c redundant with something we already explain.
e505224d
PB
1654The source line below declares an enumeration type. It is defined at
1655file scope between the bodies of main and s_proc in example2.c.
8c59ee11 1656The type definition is located after the N_RBRAC that marks the end of
e505224d 1657the previous procedure's block scope, and before the N_FUN that marks
8c59ee11
JK
1658the beginning of the next procedure's block scope. Therefore it does not
1659describe a block local symbol, but a file local one.
1660
1661The source line:
e505224d
PB
1662
1663@example
8c59ee11 1664enum e_places @{first,second=3,last@};
e505224d
PB
1665@end example
1666
899bafeb 1667@noindent
8c59ee11 1668generates the following stab
e505224d 1669
899bafeb 1670@example
8c59ee11 1671.stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
899bafeb 1672@end example
e505224d
PB
1673
1674The symbol descriptor (T) says that the stab describes a structure,
1675enumeration, or type tag. The type descriptor e, following the 22= of
1676the type definition narrows it down to an enumeration type. Following
1677the e is a list of the elements of the enumeration. The format is
1678name:value,. The list of elements ends with a ;.
1679
8c59ee11
JK
1680There is no standard way to specify the size of an enumeration type; it
1681is determined by the architecture (normally all enumerations types are
168232 bits). There should be a way to specify an enumeration type of
1683another size; type attributes would be one way to do this @xref{Stabs
1684Format}.
1685
1686@node Structures
1687@section Structures
e505224d 1688
139741da
RP
1689@table @strong
1690@item Directive:
1691@code{.stabs}
1692@item Type:
8c59ee11 1693@code{N_LSYM} or @code{C_DECL}
139741da
RP
1694@item Symbol Descriptor:
1695@code{T}
1696@item Type Descriptor:
1697@code{s}
1698@end table
e505224d
PB
1699
1700The following source code declares a structure tag and defines an
4d7f562d 1701instance of the structure in global scope. Then a typedef equates the
e505224d
PB
1702structure tag with a new type. A seperate stab is generated for the
1703structure tag, the structure typedef, and the structure instance. The
1704stabs for the tag and the typedef are emited when the definitions are
1705encountered. Since the structure elements are not initialized, the
1706stab and code for the structure variable itself is located at the end
1707of the program in .common.
1708
1709@example
17106 struct s_tag @{
17117 int s_int;
17128 float s_float;
17139 char s_char_vec[8];
171410 struct s_tag* s_next;
171511 @} g_an_s;
171612
171713 typedef struct s_tag s_typedef;
1718@end example
1719
1720The structure tag is an N_LSYM stab type because, like the enum, the
1721symbol is file scope. Like the enum, the symbol descriptor is T, for
1722enumeration, struct or tag type. The symbol descriptor s following
1723the 16= of the type definition narrows the symbol type to struct.
1724
1725Following the struct symbol descriptor is the number of bytes the
1726struct occupies, followed by a description of each structure element.
1727The structure element descriptions are of the form name:type, bit
1728offset from the start of the struct, and number of bits in the
1729element.
1730
1731
612dbd4c 1732@example
e505224d
PB
1733 <128> N_LSYM - type definition
1734 .stabs "name:sym_desc(struct tag) Type_def(16)=type_desc(struct type)
139741da 1735 struct_bytes
e505224d 1736 elem_name:type_ref(int),bit_offset,field_bits;
139741da 1737 elem_name:type_ref(float),bit_offset,field_bits;
6aa83a79
JG
1738 elem_name:type_def(17)=type_desc(array)
1739 index_type(range of int from 0 to 7);
1740 element_type(char),bit_offset,field_bits;;",
139741da 1741 N_LSYM,NIL,NIL,NIL
e505224d
PB
1742
174330 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
139741da 1744 s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
612dbd4c 1745@end example
e505224d
PB
1746
1747In this example, two of the structure elements are previously defined
1748types. For these, the type following the name: part of the element
1749description is a simple type reference. The other two structure
1750elements are new types. In this case there is a type definition
1751embedded after the name:. The type definition for the array element
1752looks just like a type definition for a standalone array. The s_next
1753field is a pointer to the same kind of structure that the field is an
1754element of. So the definition of structure type 16 contains an type
1755definition for an element which is a pointer to type 16.
1756
899bafeb 1757@node Typedefs
8c59ee11 1758@section Giving a type a name
e505224d 1759
8c59ee11 1760To give a type a name, use the @samp{t} symbol descriptor. For example,
e505224d 1761
899bafeb 1762@example
8c59ee11 1763.stabs "s_typedef:t16",128,0,0,0
899bafeb 1764@end example
e505224d 1765
8c59ee11
JK
1766specifies that @code{s_typedef} refers to type number 16. Such stabs
1767have symbol type @code{N_LSYM} or @code{C_DECL}.
e505224d 1768
8c59ee11
JK
1769If instead, you are giving a name to a tag for a structure, union, or
1770enumeration, use the @samp{T} symbol descriptor instead. I believe C is
1771the only language with this feature.
e505224d 1772
8c59ee11
JK
1773If the type is an opaque type (I believe this is a Modula-2 feature),
1774AIX provides a type descriptor to specify it. The type descriptor is
1775@samp{o} and is followed by a name. I don't know what the name
1776means---is it always the same as the name of the type, or is this type
1777descriptor used with a nameless stab (@pxref{Stabs Format})? There
1778optionally follows a comma followed by type information which defines
1779the type of this type. If omitted, a semicolon is used in place of the
1780comma and the type information, and, the type is much like a generic
1781pointer type---it has a known size but little else about it is
1782specified.
e505224d 1783
899bafeb 1784@node Unions
e505224d
PB
1785@section Unions
1786
612dbd4c 1787Next let's look at unions. In example2 this union type is declared
e505224d
PB
1788locally to a procedure and an instance of the union is defined.
1789
1790@example
179136 union u_tag @{
179237 int u_int;
179338 float u_float;
179439 char* u_char;
179540 @} an_u;
1796@end example
1797
1798This code generates a stab for the union tag and a stab for the union
1799variable. Both use the N_LSYM stab type. Since the union variable is
1800scoped locally to the procedure in which it is defined, its stab is
139741da 1801located immediately preceding the N_LBRAC for the procedure's block
e505224d
PB
1802start.
1803
139741da 1804The stab for the union tag, however is located preceding the code for
e505224d
PB
1805the procedure in which it is defined. The stab type is N_LSYM. This
1806would seem to imply that the union type is file scope, like the struct
1807type s_tag. This is not true. The contents and position of the stab
1808for u_type do not convey any infomation about its procedure local
1809scope.
1810
899bafeb 1811@display
e505224d
PB
1812 <128> N_LSYM - type
1813 .stabs "name:sym_desc(union tag)type_def(22)=type_desc(union)
1814 byte_size(4)
1815 elem_name:type_ref(int),bit_offset(0),bit_size(32);
1816 elem_name:type_ref(float),bit_offset(0),bit_size(32);
1817 elem_name:type_ref(ptr to char),bit_offset(0),bit_size(32);;"
1818 N_LSYM, NIL, NIL, NIL
899bafeb 1819@end display
e505224d 1820
5bc927fb
RP
1821@smallexample
1822105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
1823 128,0,0,0
1824@end smallexample
e505224d
PB
1825
1826The symbol descriptor, T, following the name: means that the stab
4d7f562d 1827describes an enumeration, struct or type tag. The type descriptor u,
e505224d
PB
1828following the 23= of the type definition, narrows it down to a union
1829type definition. Following the u is the number of bytes in the union.
1830After that is a list of union element descriptions. Their format is
1831name:type, bit offset into the union, and number of bytes for the
1832element;.
1833
1834The stab for the union variable follows. Notice that the frame
1835pointer offset for local variables is negative.
1836
899bafeb 1837@display
e505224d
PB
1838 <128> N_LSYM - local variable (with no symbol descriptor)
1839 .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset
899bafeb 1840@end display
e505224d 1841
899bafeb 1842@example
e505224d 1843130 .stabs "an_u:23",128,0,0,-20
899bafeb 1844@end example
e505224d 1845
899bafeb 1846@node Function types
e505224d
PB
1847@section Function types
1848
8c59ee11
JK
1849There are various types for function variables. These types are not
1850used in defining functions; see symbol descriptor @samp{f}; they are
1851used for things like pointers to functions.
e505224d 1852
8c59ee11
JK
1853The simple, traditional, type is type descriptor @samp{f} is followed by
1854type information for the return type of the function, followed by a
1855semicolon.
1856
1857This does not deal with functions the number and type of whose
1858parameters are part of their type, as found in Modula-2 or ANSI C. AIX
1859provides extensions to specify these, using the @samp{f}, @samp{F},
1860@samp{p}, and @samp{R} type descriptors.
1861
1862First comes the type descriptor. Then, if it is @samp{f} or @samp{F},
1863this is a function, and the type information for the return type of the
1864function follows, followed by a comma. Then comes the number of
1865parameters to the function and a semicolon. Then, for each parameter,
1866there is the name of the parameter followed by a colon (this is only
1867present for type descriptors @samp{R} and @samp{F} which represent
1868Pascal function or procedure parameters), type information for the
1869parameter, a comma, @samp{0} if passed by reference or @samp{1} if
1870passed by value, and a semicolon. The type definition ends with a
1871semicolon.
1872
1873For example,
e505224d
PB
1874
1875@example
8c59ee11 1876int (*g_pf)();
e505224d
PB
1877@end example
1878
8c59ee11
JK
1879@noindent
1880generates the following code:
e505224d 1881
899bafeb 1882@example
8c59ee11
JK
1883.stabs "g_pf:G24=*25=f1",32,0,0,0
1884 .common _g_pf,4,"bss"
899bafeb 1885@end example
e505224d 1886
8c59ee11
JK
1887The variable defines a new type, 24, which is a pointer to another new
1888type, 25, which is defined as a function returning int.
e505224d 1889
899bafeb 1890@node Symbol tables
e505224d
PB
1891@chapter Symbol information in symbol tables
1892
1893This section examines more closely the format of symbol table entries
1894and how stab assembler directives map to them. It also describes what
1895transformations the assembler and linker make on data from stabs.
1896
1897Each time the assembler encounters a stab in its input file it puts
1898each field of the stab into corresponding fields in a symbol table
1899entry of its output file. If the stab contains a string field, the
1900symbol table entry for that stab points to a string table entry
1901containing the string data from the stab. Assembler labels become
1902relocatable addresses. Symbol table entries in a.out have the format:
1903
1904@example
1905struct internal_nlist @{
139741da
RP
1906 unsigned long n_strx; /* index into string table of name */
1907 unsigned char n_type; /* type of symbol */
1908 unsigned char n_other; /* misc info (usually empty) */
1909 unsigned short n_desc; /* description field */
1910 bfd_vma n_value; /* value of symbol */
e505224d
PB
1911@};
1912@end example
1913
1914For .stabs directives, the n_strx field holds the character offset
1915from the start of the string table to the string table entry
1916containing the "string" field. For other classes of stabs (.stabn and
1917.stabd) this field is null.
1918
1919Symbol table entries with n_type fields containing a value greater or
1920equal to 0x20 originated as stabs generated by the compiler (with one
1921random exception). Those with n_type values less than 0x20 were
1922placed in the symbol table of the executable by the assembler or the
1923linker.
1924
1925The linker concatenates object files and does fixups of externally
1926defined symbols. You can see the transformations made on stab data by
1927the assembler and linker by examining the symbol table after each pass
1928of the build, first the assemble and then the link.
1929
1930To do this use nm with the -ap options. This dumps the symbol table,
1931including debugging information, unsorted. For stab entries the
1932columns are: value, other, desc, type, string. For assembler and
1933linker symbols, the columns are: value, type, string.
1934
1935There are a few important things to notice about symbol tables. Where
1936the value field of a stab contains a frame pointer offset, or a
1937register number, that value is unchanged by the rest of the build.
1938
1939Where the value field of a stab contains an assembly language label,
1940it is transformed by each build step. The assembler turns it into a
1941relocatable address and the linker turns it into an absolute address.
1942This source line defines a static variable at file scope:
1943
899bafeb 1944@example
e505224d 19453 static int s_g_repeat
899bafeb 1946@end example
e505224d 1947
899bafeb 1948@noindent
e505224d
PB
1949The following stab describes the symbol.
1950
899bafeb 1951@example
e505224d 195226 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
899bafeb 1953@end example
e505224d 1954
899bafeb 1955@noindent
e505224d 1956The assembler transforms the stab into this symbol table entry in the
899bafeb 1957@file{.o} file. The location is expressed as a data segment offset.
e505224d 1958
899bafeb 1959@example
e505224d 196021 00000084 - 00 0000 STSYM s_g_repeat:S1
899bafeb 1961@end example
e505224d 1962
899bafeb 1963@noindent
e505224d
PB
1964in the symbol table entry from the executable, the linker has made the
1965relocatable address absolute.
1966
899bafeb 1967@example
e505224d 196822 0000e00c - 00 0000 STSYM s_g_repeat:S1
899bafeb 1969@end example
e505224d
PB
1970
1971Stabs for global variables do not contain location information. In
1972this case the debugger finds location information in the assembler or
1973linker symbol table entry describing the variable. The source line:
1974
899bafeb 1975@example
e505224d 19761 char g_foo = 'c';
899bafeb 1977@end example
e505224d 1978
899bafeb 1979@noindent
e505224d
PB
1980generates the stab:
1981
899bafeb 1982@example
e505224d 198321 .stabs "g_foo:G2",32,0,0,0
899bafeb 1984@end example
e505224d
PB
1985
1986The variable is represented by the following two symbol table entries
1987in the object file. The first one originated as a stab. The second
1988one is an external symbol. The upper case D signifies that the n_type
1989field of the symbol table contains 7, N_DATA with local linkage (see
1990Table B). The value field following the file's line number is empty
1991for the stab entry. For the linker symbol it contains the
1992rellocatable address corresponding to the variable.
1993
899bafeb 1994@example
e505224d
PB
199519 00000000 - 00 0000 GSYM g_foo:G2
199620 00000080 D _g_foo
899bafeb 1997@end example
e505224d 1998
899bafeb 1999@noindent
e505224d
PB
2000These entries as transformed by the linker. The linker symbol table
2001entry now holds an absolute address.
2002
899bafeb 2003@example
e505224d 200421 00000000 - 00 0000 GSYM g_foo:G2
899bafeb 2005@dots{}
e505224d 2006215 0000e008 D _g_foo
899bafeb 2007@end example
e505224d 2008
8c59ee11 2009@node Cplusplus
612dbd4c 2010@chapter GNU C++ stabs
e505224d
PB
2011
2012@menu
b32ae57b 2013* Basic Cplusplus types::
e505224d
PB
2014* Simple classes::
2015* Class instance::
2016* Methods:: Method definition
2017* Protections::
2dd00294
JG
2018* Method Modifiers:: (const, volatile, const volatile)
2019* Virtual Methods::
2020* Inheritence::
2021* Virtual Base Classes::
2022* Static Members::
e505224d
PB
2023@end menu
2024
e505224d
PB
2025@subsection type descriptors added for C++ descriptions
2026
2027@table @code
2028@item #
2029method type (two ## if minimal debug)
2030
8c59ee11
JK
2031@item @@
2032Member (class and variable) type. It is followed by type information
2033for the offset basetype, a comma, and type information for the type of
2034the field being pointed to. (FIXME: this is acknowledged to be
2035gibberish. Can anyone say what really goes here?).
2036
2037Note that there is a conflict between this and type attributes
2038(@pxref{Stabs Format}); both use type descriptor @samp{@@}.
2039Fortunately, the @samp{@@} type descriptor used in this C++ sense always
2040will be followed by a digit, @samp{(}, or @samp{-}, and type attributes
2041never start with those things.
e505224d
PB
2042@end table
2043
b32ae57b 2044@node Basic Cplusplus types
e505224d
PB
2045@section Basic types for C++
2046
2047<< the examples that follow are based on a01.C >>
2048
2049
2050C++ adds two more builtin types to the set defined for C. These are
2051the unknown type and the vtable record type. The unknown type, type
205216, is defined in terms of itself like the void type.
2053
2054The vtable record type, type 17, is defined as a structure type and
2055then as a structure tag. The structure has four fields, delta, index,
2056pfn, and delta2. pfn is the function pointer.
2057
2058<< In boilerplate $vtbl_ptr_type, what are the fields delta,
2059index, and delta2 used for? >>
2060
2061This basic type is present in all C++ programs even if there are no
2062virtual methods defined.
2063
899bafeb 2064@display
e505224d 2065.stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8)
139741da
RP
2066 elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16);
2067 elem_name(index):type_ref(short int),bit_offset(16),field_bits(16);
2068 elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void),
2069 bit_offset(32),field_bits(32);
2070 elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;"
2071 N_LSYM, NIL, NIL
899bafeb 2072@end display
139741da 2073
899bafeb 2074@smallexample
e505224d 2075.stabs "$vtbl_ptr_type:t17=s8
139741da
RP
2076 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;"
2077 ,128,0,0,0
899bafeb 2078@end smallexample
e505224d 2079
899bafeb 2080@display
e505224d 2081.stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL
899bafeb 2082@end display
e505224d 2083
899bafeb 2084@example
e505224d 2085.stabs "$vtbl_ptr_type:T17",128,0,0,0
899bafeb 2086@end example
e505224d 2087
899bafeb 2088@node Simple classes
e505224d
PB
2089@section Simple class definition
2090
2091The stabs describing C++ language features are an extension of the
2092stabs describing C. Stabs representing C++ class types elaborate
2093extensively on the stab format used to describe structure types in C.
2094Stabs representing class type variables look just like stabs
2095representing C language variables.
2096
2097Consider the following very simple class definition.
2098
2099@example
2100class baseA @{
2101public:
139741da
RP
2102 int Adat;
2103 int Ameth(int in, char other);
e505224d
PB
2104@};
2105@end example
2106
2107The class baseA is represented by two stabs. The first stab describes
2108the class as a structure type. The second stab describes a structure
2109tag of the class type. Both stabs are of stab type N_LSYM. Since the
2110stab is not located between an N_FUN and a N_LBRAC stab this indicates
2111that the class is defined at file scope. If it were, then the N_LSYM
2112would signify a local variable.
2113
2114A stab describing a C++ class type is similar in format to a stab
2115describing a C struct, with each class member shown as a field in the
2116structure. The part of the struct format describing fields is
2117expanded to include extra information relevent to C++ class members.
2118In addition, if the class has multiple base classes or virtual
2119functions the struct format outside of the field parts is also
2120augmented.
2121
2122In this simple example the field part of the C++ class stab
2123representing member data looks just like the field part of a C struct
2124stab. The section on protections describes how its format is
2125sometimes extended for member data.
2126
2127The field part of a C++ class stab representing a member function
2128differs substantially from the field part of a C struct stab. It
2129still begins with `name:' but then goes on to define a new type number
2130for the member function, describe its return type, its argument types,
2131its protection level, any qualifiers applied to the method definition,
2132and whether the method is virtual or not. If the method is virtual
2133then the method description goes on to give the vtable index of the
2134method, and the type number of the first base class defining the
2135method.
2136
2137When the field name is a method name it is followed by two colons
2138rather than one. This is followed by a new type definition for the
2139method. This is a number followed by an equal sign and then the
2140symbol descriptor `##', indicating a method type. This is followed by
2141a type reference showing the return type of the method and a
2142semi-colon.
2143
2144The format of an overloaded operator method name differs from that
2145of other methods. It is "op$::XXXX." where XXXX is the operator name
612dbd4c
JG
2146such as + or +=. The name ends with a period, and any characters except
2147the period can occur in the XXXX string.
e505224d
PB
2148
2149The next part of the method description represents the arguments to
2150the method, preceeded by a colon and ending with a semi-colon. The
2151types of the arguments are expressed in the same way argument types
2152are expressed in C++ name mangling. In this example an int and a char
2153map to `ic'.
2154
2155This is followed by a number, a letter, and an asterisk or period,
2156followed by another semicolon. The number indicates the protections
2157that apply to the member function. Here the 2 means public. The
2158letter encodes any qualifier applied to the method definition. In
2159this case A means that it is a normal function definition. The dot
2160shows that the method is not virtual. The sections that follow
2161elaborate further on these fields and describe the additional
2162information present for virtual methods.
2163
2164
899bafeb 2165@display
e505224d 2166.stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
139741da 2167 field_name(Adat):type(int),bit_offset(0),field_bits(32);
e505224d 2168
139741da
RP
2169 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
2170 :arg_types(int char);
2171 protection(public)qualifier(normal)virtual(no);;"
2172 N_LSYM,NIL,NIL,NIL
899bafeb 2173@end display
e505224d 2174
899bafeb 2175@smallexample
e505224d
PB
2176.stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
2177
2178.stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
2179
2180.stabs "baseA:T20",128,0,0,0
899bafeb 2181@end smallexample
e505224d 2182
899bafeb 2183@node Class instance
e505224d
PB
2184@section Class instance
2185
2186As shown above, describing even a simple C++ class definition is
2187accomplished by massively extending the stab format used in C to
2188describe structure types. However, once the class is defined, C stabs
2189with no modifications can be used to describe class instances. The
2190following source:
2191
2192@example
2193main () @{
139741da 2194 baseA AbaseA;
e505224d
PB
2195@}
2196@end example
2197
899bafeb
RP
2198@noindent
2199yields the following stab describing the class instance. It looks no
e505224d
PB
2200different from a standard C stab describing a local variable.
2201
899bafeb 2202@display
e505224d 2203.stabs "name:type_ref(baseA)", N_LSYM, NIL, NIL, frame_ptr_offset
899bafeb 2204@end display
e505224d 2205
899bafeb 2206@example
e505224d 2207.stabs "AbaseA:20",128,0,0,-20
899bafeb 2208@end example
e505224d 2209
899bafeb 2210@node Methods
e505224d
PB
2211@section Method defintion
2212
2213The class definition shown above declares Ameth. The C++ source below
2214defines Ameth:
2215
2216@example
2217int
2218baseA::Ameth(int in, char other)
2219@{
139741da 2220 return in;
e505224d
PB
2221@};
2222@end example
2223
2224
2225This method definition yields three stabs following the code of the
2226method. One stab describes the method itself and following two
2227describe its parameters. Although there is only one formal argument
2228all methods have an implicit argument which is the `this' pointer.
2229The `this' pointer is a pointer to the object on which the method was
2230called. Note that the method name is mangled to encode the class name
2231and argument types. << Name mangling is not described by this
2232document - Is there already such a doc? >>
2233
612dbd4c 2234@example
e505224d 2235.stabs "name:symbol_desriptor(global function)return_type(int)",
139741da 2236 N_FUN, NIL, NIL, code_addr_of_method_start
e505224d
PB
2237
2238.stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic
612dbd4c 2239@end example
e505224d
PB
2240
2241Here is the stab for the `this' pointer implicit argument. The name
c2dc518b 2242of the `this' pointer is always `this.' Type 19, the `this' pointer is
e505224d
PB
2243defined as a pointer to type 20, baseA, but a stab defining baseA has
2244not yet been emited. Since the compiler knows it will be emited
2245shortly, here it just outputs a cross reference to the undefined
2246symbol, by prefixing the symbol name with xs.
2247
612dbd4c 2248@example
e505224d 2249.stabs "name:sym_desc(register param)type_def(19)=
139741da 2250 type_desc(ptr to)type_ref(baseA)=
e505224d
PB
2251 type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number
2252
c2dc518b 2253.stabs "this:P19=*20=xsbaseA:",64,0,0,8
612dbd4c 2254@end example
e505224d
PB
2255
2256The stab for the explicit integer argument looks just like a parameter
2257to a C function. The last field of the stab is the offset from the
2258argument pointer, which in most systems is the same as the frame
2259pointer.
2260
612dbd4c 2261@example
e505224d 2262.stabs "name:sym_desc(value parameter)type_ref(int)",
139741da 2263 N_PSYM,NIL,NIL,offset_from_arg_ptr
e505224d
PB
2264
2265.stabs "in:p1",160,0,0,72
612dbd4c 2266@end example
e505224d
PB
2267
2268<< The examples that follow are based on A1.C >>
2269
899bafeb 2270@node Protections
e505224d
PB
2271@section Protections
2272
2273
2274In the simple class definition shown above all member data and
2275functions were publicly accessable. The example that follows
2276contrasts public, protected and privately accessable fields and shows
2277how these protections are encoded in C++ stabs.
2278
2279Protections for class member data are signified by two characters
2280embeded in the stab defining the class type. These characters are
2281located after the name: part of the string. /0 means private, /1
2282means protected, and /2 means public. If these characters are omited
2283this means that the member is public. The following C++ source:
2284
2285@example
2286class all_data @{
139741da
RP
2287private:
2288 int priv_dat;
e505224d 2289protected:
139741da 2290 char prot_dat;
e505224d 2291public:
139741da 2292 float pub_dat;
e505224d
PB
2293@};
2294@end example
2295
899bafeb 2296@noindent
e505224d
PB
2297generates the following stab to describe the class type all_data.
2298
899bafeb 2299@display
e505224d 2300.stabs "class_name:sym_desc(type)type_def(19)=type_desc(struct)struct_bytes
139741da
RP
2301 data_name:/protection(private)type_ref(int),bit_offset,num_bits;
2302 data_name:/protection(protected)type_ref(char),bit_offset,num_bits;
2303 data_name:(/num omited, private)type_ref(float),bit_offset,num_bits;;"
2304 N_LSYM,NIL,NIL,NIL
899bafeb 2305@end display
e505224d 2306
899bafeb 2307@smallexample
e505224d 2308.stabs "all_data:t19=s12
139741da 2309 priv_dat:/01,0,32;prot_dat:/12,32,8;pub_dat:12,64,32;;",128,0,0,0
899bafeb 2310@end smallexample
e505224d
PB
2311
2312Protections for member functions are signified by one digit embeded in
2313the field part of the stab describing the method. The digit is 0 if
2314private, 1 if protected and 2 if public. Consider the C++ class
2315definition below:
2316
2317@example
2318class all_methods @{
2319private:
139741da 2320 int priv_meth(int in)@{return in;@};
e505224d 2321protected:
139741da 2322 char protMeth(char in)@{return in;@};
e505224d 2323public:
139741da 2324 float pubMeth(float in)@{return in;@};
e505224d
PB
2325@};
2326@end example
2327
2328It generates the following stab. The digit in question is to the left
2329of an `A' in each case. Notice also that in this case two symbol
2330descriptors apply to the class name struct tag and struct type.
2331
899bafeb 2332@display
e505224d 2333.stabs "class_name:sym_desc(struct tag&type)type_def(21)=
139741da
RP
2334 sym_desc(struct)struct_bytes(1)
2335 meth_name::type_def(22)=sym_desc(method)returning(int);
2336 :args(int);protection(private)modifier(normal)virtual(no);
2337 meth_name::type_def(23)=sym_desc(method)returning(char);
2338 :args(char);protection(protected)modifier(normal)virual(no);
2339 meth_name::type_def(24)=sym_desc(method)returning(float);
2340 :args(float);protection(public)modifier(normal)virtual(no);;",
2341 N_LSYM,NIL,NIL,NIL
899bafeb 2342@end display
139741da 2343
899bafeb 2344@smallexample
e505224d 2345.stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
139741da 2346 pubMeth::24=##12;:f;2A.;;",128,0,0,0
899bafeb 2347@end smallexample
e505224d 2348
899bafeb
RP
2349@node Method Modifiers
2350@section Method Modifiers (const, volatile, const volatile)
e505224d
PB
2351
2352<< based on a6.C >>
2353
2354In the class example described above all the methods have the normal
2355modifier. This method modifier information is located just after the
2356protection information for the method. This field has four possible
2357character values. Normal methods use A, const methods use B, volatile
2358methods use C, and const volatile methods use D. Consider the class
2359definition below:
2360
2361@example
2362class A @{
2363public:
139741da
RP
2364 int ConstMeth (int arg) const @{ return arg; @};
2365 char VolatileMeth (char arg) volatile @{ return arg; @};
2366 float ConstVolMeth (float arg) const volatile @{return arg; @};
e505224d
PB
2367@};
2368@end example
2369
2370This class is described by the following stab:
2371
899bafeb 2372@display
e505224d 2373.stabs "class(A):sym_desc(struct)type_def(20)=type_desc(struct)struct_bytes(1)
139741da
RP
2374 meth_name(ConstMeth)::type_def(21)sym_desc(method)
2375 returning(int);:arg(int);protection(public)modifier(const)virtual(no);
2376 meth_name(VolatileMeth)::type_def(22)=sym_desc(method)
2377 returning(char);:arg(char);protection(public)modifier(volatile)virt(no)
2378 meth_name(ConstVolMeth)::type_def(23)=sym_desc(method)
2379 returning(float);:arg(float);protection(public)modifer(const volatile)
2380 virtual(no);;", @dots{}
899bafeb 2381@end display
139741da 2382
899bafeb 2383@example
e505224d 2384.stabs "A:T20=s1ConstMeth::21=##1;:i;2B.;VolatileMeth::22=##2;:c;2C.;
139741da 2385 ConstVolMeth::23=##12;:f;2D.;;",128,0,0,0
612dbd4c 2386@end example
e505224d 2387
899bafeb 2388@node Virtual Methods
e505224d
PB
2389@section Virtual Methods
2390
2391<< The following examples are based on a4.C >>
2392
2393The presence of virtual methods in a class definition adds additional
2394data to the class description. The extra data is appended to the
2395description of the virtual method and to the end of the class
2396description. Consider the class definition below:
2397
2398@example
2399class A @{
2400public:
139741da
RP
2401 int Adat;
2402 virtual int A_virt (int arg) @{ return arg; @};
e505224d
PB
2403@};
2404@end example
2405
2406This results in the stab below describing class A. It defines a new
2407type (20) which is an 8 byte structure. The first field of the class
2408struct is Adat, an integer, starting at structure offset 0 and
2409occupying 32 bits.
2410
2411The second field in the class struct is not explicitly defined by the
2412C++ class definition but is implied by the fact that the class
2413contains a virtual method. This field is the vtable pointer. The
2414name of the vtable pointer field starts with $vf and continues with a
2415type reference to the class it is part of. In this example the type
2416reference for class A is 20 so the name of its vtable pointer field is
2417$vf20, followed by the usual colon.
2418
2419Next there is a type definition for the vtable pointer type (21).
2420This is in turn defined as a pointer to another new type (22).
2421
2422Type 22 is the vtable itself, which is defined as an array, indexed by
6aa83a79
JG
2423a range of integers between 0 and 1, and whose elements are of type
242417. Type 17 was the vtable record type defined by the boilerplate C++
2425type definitions, as shown earlier.
e505224d
PB
2426
2427The bit offset of the vtable pointer field is 32. The number of bits
2428in the field are not specified when the field is a vtable pointer.
2429
2430Next is the method definition for the virtual member function A_virt.
2431Its description starts out using the same format as the non-virtual
2432member functions described above, except instead of a dot after the
2433`A' there is an asterisk, indicating that the function is virtual.
2434Since is is virtual some addition information is appended to the end
2435of the method description.
2436
2437The first number represents the vtable index of the method. This is a
243832 bit unsigned number with the high bit set, followed by a
2439semi-colon.
2440
2441The second number is a type reference to the first base class in the
2442inheritence hierarchy defining the virtual member function. In this
2443case the class stab describes a base class so the virtual function is
2444not overriding any other definition of the method. Therefore the
2445reference is to the type number of the class that the stab is
2446describing (20).
2447
2448This is followed by three semi-colons. One marks the end of the
2449current sub-section, one marks the end of the method field, and the
2450third marks the end of the struct definition.
2451
2452For classes containing virtual functions the very last section of the
2453string part of the stab holds a type reference to the first base
2454class. This is preceeded by `~%' and followed by a final semi-colon.
2455
899bafeb 2456@display
e505224d 2457.stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
139741da
RP
2458 field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
2459 field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
6aa83a79
JG
2460 sym_desc(array)index_type_ref(range of int from 0 to 1);
2461 elem_type_ref(vtbl elem type),
139741da
RP
2462 bit_offset(32);
2463 meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
2464 :arg_type(int),protection(public)normal(yes)virtual(yes)
2465 vtable_index(1);class_first_defining(A);;;~%first_base(A);",
2466 N_LSYM,NIL,NIL,NIL
899bafeb 2467@end display
e505224d 2468
899bafeb 2469@example
e505224d 2470.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
612dbd4c 2471@end example
e505224d 2472
2dd00294
JG
2473@node Inheritence
2474@section Inheritence
e505224d
PB
2475
2476Stabs describing C++ derived classes include additional sections that
2477describe the inheritence hierarchy of the class. A derived class stab
2478also encodes the number of base classes. For each base class it tells
2479if the base class is virtual or not, and if the inheritence is private
2480or public. It also gives the offset into the object of the portion of
2481the object corresponding to each base class.
2482
2483This additional information is embeded in the class stab following the
2484number of bytes in the struct. First the number of base classes
2485appears bracketed by an exclamation point and a comma.
2486
2487Then for each base type there repeats a series: two digits, a number,
2488a comma, another number, and a semi-colon.
2489
2490The first of the two digits is 1 if the base class is virtual and 0 if
2491not. The second digit is 2 if the derivation is public and 0 if not.
2492
2493The number following the first two digits is the offset from the start
2494of the object to the part of the object pertaining to the base class.
2495
2496After the comma, the second number is a type_descriptor for the base
2497type. Finally a semi-colon ends the series, which repeats for each
2498base class.
2499
2500The source below defines three base classes A, B, and C and the
2501derived class D.
2502
2503
2504@example
2505class A @{
2506public:
139741da
RP
2507 int Adat;
2508 virtual int A_virt (int arg) @{ return arg; @};
e505224d
PB
2509@};
2510
2511class B @{
2512public:
139741da
RP
2513 int B_dat;
2514 virtual int B_virt (int arg) @{return arg; @};
e505224d
PB
2515@};
2516
2517class C @{
2518public:
139741da
RP
2519 int Cdat;
2520 virtual int C_virt (int arg) @{return arg; @};
e505224d
PB
2521@};
2522
2523class D : A, virtual B, public C @{
2524public:
139741da
RP
2525 int Ddat;
2526 virtual int A_virt (int arg ) @{ return arg+1; @};
2527 virtual int B_virt (int arg) @{ return arg+2; @};
2528 virtual int C_virt (int arg) @{ return arg+3; @};
2529 virtual int D_virt (int arg) @{ return arg; @};
e505224d
PB
2530@};
2531@end example
2532
2533Class stabs similar to the ones described earlier are generated for
2534each base class.
2535
5bc927fb
RP
2536@c FIXME!!! the linebreaks in the following example probably make the
2537@c examples literally unusable, but I don't know any other way to get
2538@c them on the page.
899bafeb 2539@smallexample
5bc927fb
RP
2540.stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2541 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
e505224d 2542
5bc927fb
RP
2543.stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
2544 :i;2A*-2147483647;25;;;~%25;",128,0,0,0
e505224d 2545
5bc927fb
RP
2546.stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
2547 :i;2A*-2147483647;28;;;~%28;",128,0,0,0
899bafeb 2548@end smallexample
e505224d
PB
2549
2550In the stab describing derived class D below, the information about
2551the derivation of this class is encoded as follows.
2552
899bafeb 2553@display
e505224d 2554.stabs "derived_class_name:symbol_descriptors(struct tag&type)=
139741da
RP
2555 type_descriptor(struct)struct_bytes(32)!num_bases(3),
2556 base_virtual(no)inheritence_public(no)base_offset(0),
2557 base_class_type_ref(A);
2558 base_virtual(yes)inheritence_public(no)base_offset(NIL),
2559 base_class_type_ref(B);
2560 base_virtual(no)inheritence_public(yes)base_offset(64),
2561 base_class_type_ref(C); @dots{}
899bafeb 2562@end display
139741da 2563
5bc927fb 2564@c FIXME! fake linebreaks.
899bafeb 2565@smallexample
5bc927fb
RP
2566.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
2567 1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
2568 :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
2569 28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
899bafeb 2570@end smallexample
e505224d 2571
2dd00294 2572@node Virtual Base Classes
e505224d
PB
2573@section Virtual Base Classes
2574
2575A derived class object consists of a concatination in memory of the
2576data areas defined by each base class, starting with the leftmost and
2577ending with the rightmost in the list of base classes. The exception
2578to this rule is for virtual inheritence. In the example above, class
2579D inherits virtually from base class B. This means that an instance
2580of a D object will not contain it's own B part but merely a pointer to
2581a B part, known as a virtual base pointer.
2582
2583In a derived class stab, the base offset part of the derivation
2584information, described above, shows how the base class parts are
2585ordered. The base offset for a virtual base class is always given as
25860. Notice that the base offset for B is given as 0 even though B is
2587not the first base class. The first base class A starts at offset 0.
2588
2589The field information part of the stab for class D describes the field
2590which is the pointer to the virtual base class B. The vbase pointer
2591name is $vb followed by a type reference to the virtual base class.
2592Since the type id for B in this example is 25, the vbase pointer name
2593is $vb25.
2594
5bc927fb 2595@c FIXME!! fake linebreaks below
899bafeb 2596@smallexample
5bc927fb
RP
2597.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,
2598 160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;
2599 2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt:
2600 :32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
899bafeb 2601@end smallexample
e505224d
PB
2602
2603Following the name and a semicolon is a type reference describing the
2604type of the virtual base class pointer, in this case 24. Type 24 was
c2dc518b 2605defined earlier as the type of the B class `this` pointer. The
e505224d
PB
2606`this' pointer for a class is a pointer to the class type.
2607
899bafeb 2608@example
c2dc518b 2609.stabs "this:P24=*25=xsB:",64,0,0,8
899bafeb 2610@end example
e505224d
PB
2611
2612Finally the field offset part of the vbase pointer field description
2613shows that the vbase pointer is the first field in the D object,
2614before any data fields defined by the class. The layout of a D class
2615object is a follows, Adat at 0, the vtable pointer for A at 32, Cdat
2616at 64, the vtable pointer for C at 96, the virtual ase pointer for B
2617at 128, and Ddat at 160.
2618
2619
899bafeb 2620@node Static Members
e505224d
PB
2621@section Static Members
2622
446e5d80
JG
2623The data area for a class is a concatenation of the space used by the
2624data members of the class. If the class has virtual methods, a vtable
e505224d 2625pointer follows the class data. The field offset part of each field
446e5d80 2626description in the class stab shows this ordering.
e505224d 2627
446e5d80 2628<< How is this reflected in stabs? See Cygnus bug #677 for some info. >>
e505224d 2629
899bafeb 2630@node Example2.c
e505224d
PB
2631@appendix Example2.c - source code for extended example
2632
2633@example
26341 char g_foo = 'c';
26352 register int g_bar asm ("%g5");
26363 static int s_g_repeat = 2;
26374 int (*g_pf)();
26385
26396 struct s_tag @{
26407 int s_int;
26418 float s_float;
26429 char s_char_vec[8];
264310 struct s_tag* s_next;
264411 @} g_an_s;
264512
264613 typedef struct s_tag s_typedef;
264714
264815 char char_vec[3] = @{'a','b','c'@};
264916
265017 main (argc, argv)
265118 int argc;
265219 char* argv[];
265320 @{
265421 static float s_flap;
139741da
RP
265522 int times;
265623 for (times=0; times < s_g_repeat; times++)@{
265724 int inner;
265825 printf ("Hello world\n");
265926 @}
e505224d
PB
266027 @};
266128
266229 enum e_places @{first,second=3,last@};
266330
266431 static s_proc (s_arg, s_ptr_arg, char_vec)
266532 s_typedef s_arg;
266633 s_typedef* s_ptr_arg;
266734 char* char_vec;
266835 @{
266936 union u_tag @{
267037 int u_int;
267138 float u_float;
267239 char* u_char;
267340 @} an_u;
267441 @}
267542
267643
2677@end example
2678
899bafeb 2679@node Example2.s
e505224d
PB
2680@appendix Example2.s - assembly code for extended example
2681
2682@example
26831 gcc2_compiled.:
26842 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
26853 .stabs "example2.c",100,0,0,Ltext0
139741da 26864 .text
e505224d
PB
26875 Ltext0:
26886 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
26897 .stabs "char:t2=r2;0;127;",128,0,0,0
26908 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
26919 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
269210 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
269311 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
269412 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
269513 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
269614 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
269715 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
269816 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
269917 .stabs "float:t12=r1;4;0;",128,0,0,0
270018 .stabs "double:t13=r1;8;0;",128,0,0,0
270119 .stabs "long double:t14=r1;8;0;",128,0,0,0
270220 .stabs "void:t15=15",128,0,0,0
270321 .stabs "g_foo:G2",32,0,0,0
139741da
RP
270422 .global _g_foo
270523 .data
e505224d 270624 _g_foo:
139741da 270725 .byte 99
e505224d 270826 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
139741da 270927 .align 4
e505224d 271028 _s_g_repeat:
139741da 271129 .word 2
5bc927fb
RP
2712@c FIXME! fake linebreak in line 30
271330 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;s_char_vec:
2714 17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
e505224d
PB
271531 .stabs "s_typedef:t16",128,0,0,0
271632 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
139741da
RP
271733 .global _char_vec
271834 .align 4
e505224d 271935 _char_vec:
139741da
RP
272036 .byte 97
272137 .byte 98
272238 .byte 99
272339 .reserve _s_flap.0,4,"bss",4
272440 .text
272541 .align 4
e505224d 272642 LC0:
139741da
RP
272743 .ascii "Hello world\12\0"
272844 .align 4
272945 .global _main
273046 .proc 1
e505224d
PB
273147 _main:
273248 .stabn 68,0,20,LM1
273349 LM1:
139741da
RP
273450 !#PROLOGUE# 0
273551 save %sp,-144,%sp
273652 !#PROLOGUE# 1
273753 st %i0,[%fp+68]
273854 st %i1,[%fp+72]
273955 call ___main,0
274056 nop
e505224d
PB
274157 LBB2:
274258 .stabn 68,0,23,LM2
274359 LM2:
139741da 274460 st %g0,[%fp-20]
e505224d 274561 L2:
139741da
RP
274662 sethi %hi(_s_g_repeat),%o0
274763 ld [%fp-20],%o1
274864 ld [%o0+%lo(_s_g_repeat)],%o0
274965 cmp %o1,%o0
275066 bge L3
275167 nop
e505224d
PB
275268 LBB3:
275369 .stabn 68,0,25,LM3
275470 LM3:
139741da
RP
275571 sethi %hi(LC0),%o1
275672 or %o1,%lo(LC0),%o0
275773 call _printf,0
275874 nop
e505224d
PB
275975 .stabn 68,0,26,LM4
276076 LM4:
276177 LBE3:
276278 .stabn 68,0,23,LM5
276379 LM5:
276480 L4:
139741da
RP
276581 ld [%fp-20],%o0
276682 add %o0,1,%o1
276783 st %o1,[%fp-20]
276884 b,a L2
e505224d
PB
276985 L3:
277086 .stabn 68,0,27,LM6
277187 LM6:
277288 LBE2:
277389 .stabn 68,0,27,LM7
277490 LM7:
277591 L1:
139741da
RP
277692 ret
277793 restore
e505224d
PB
277894 .stabs "main:F1",36,0,0,_main
277995 .stabs "argc:p1",160,0,0,68
278096 .stabs "argv:p20=*21=*2",160,0,0,72
278197 .stabs "s_flap:V12",40,0,0,_s_flap.0
278298 .stabs "times:1",128,0,0,-20
278399 .stabn 192,0,0,LBB2
2784100 .stabs "inner:1",128,0,0,-24
2785101 .stabn 192,0,0,LBB3
2786102 .stabn 224,0,0,LBE3
2787103 .stabn 224,0,0,LBE2
2788104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
5bc927fb
RP
2789@c FIXME: fake linebreak in line 105
2790105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
2791128,0,0,0
139741da
RP
2792106 .align 4
2793107 .proc 1
e505224d
PB
2794108 _s_proc:
2795109 .stabn 68,0,35,LM8
2796110 LM8:
139741da
RP
2797111 !#PROLOGUE# 0
2798112 save %sp,-120,%sp
2799113 !#PROLOGUE# 1
2800114 mov %i0,%o0
2801115 st %i1,[%fp+72]
2802116 st %i2,[%fp+76]
e505224d
PB
2803117 LBB4:
2804118 .stabn 68,0,41,LM9
2805119 LM9:
2806120 LBE4:
2807121 .stabn 68,0,41,LM10
2808122 LM10:
2809123 L5:
139741da
RP
2810124 ret
2811125 restore
e505224d
PB
2812126 .stabs "s_proc:f1",36,0,0,_s_proc
2813127 .stabs "s_arg:p16",160,0,0,0
2814128 .stabs "s_ptr_arg:p18",160,0,0,72
2815129 .stabs "char_vec:p21",160,0,0,76
2816130 .stabs "an_u:23",128,0,0,-20
2817131 .stabn 192,0,0,LBB4
2818132 .stabn 224,0,0,LBE4
2819133 .stabs "g_bar:r1",64,0,0,5
2820134 .stabs "g_pf:G24=*25=f1",32,0,0,0
139741da 2821135 .common _g_pf,4,"bss"
e505224d 2822136 .stabs "g_an_s:G16",32,0,0,0
139741da 2823137 .common _g_an_s,20,"bss"
e505224d
PB
2824@end example
2825
899bafeb 2826@node Stab types
8c59ee11 2827@appendix Table A: Symbol types from stabs
e505224d
PB
2828
2829Table A lists stab types sorted by type number. Stab type numbers are
283032 and greater. This is the full list of stab numbers, including stab
2831types that are used in languages other than C.
2832
2833The #define names for these stab types are defined in:
2834devo/include/aout/stab.def
2835
899bafeb 2836@smallexample
e505224d
PB
2837type type #define used to describe
2838dec hex name source program feature
5bc927fb 2839------------------------------------------------
139741da
RP
284032 0x20 N_GYSM global symbol
284134 0X22 N_FNAME function name (for BSD Fortran)
284236 0x24 N_FUN function name or text segment variable for C
284338 0x26 N_STSYM static symbol (data segment w/internal linkage)
284440 0x28 N_LCSYM .lcomm symbol(BSS-seg variable w/internal linkage)
284542 0x2a N_MAIN Name of main routine (not used in C)
284648 0x30 N_PC global symbol (for Pascal)
284750 0x32 N_NSYMS number of symbols (according to Ultrix V4.0)
284852 0x34 N_NOMAP no DST map for sym (according to Ultrix V4.0)
284964 0x40 N_RSYM register variable
285066 0x42 N_M2C Modula-2 compilation unit
285168 0x44 N_SLINE line number in text segment
285270 0x46 N_DSLINE line number in data segment
2853
285472 0x48 N_BSLINE line number in bss segment
285572 0x48 N_BROWS Sun source code browser, path to .cb file
2856
285774 0x4a N_DEFD GNU Modula2 definition module dependency
2858
285980 0x50 N_EHDECL GNU C++ exception variable
286080 0x50 N_MOD2 Modula2 info "for imc" (according to Ultrix V4.0)
2861
286284 0x54 N_CATCH GNU C++ "catch" clause
286396 0x60 N_SSYM structure of union element
2864100 0x64 N_SO path and name of source file
2865128 0x80 N_LSYM automatic var in the stack
2866 (also used for type desc.)
2867130 0x82 N_BINCL beginning of an include file (Sun only)
2868132 0x84 N_SOL Name of sub-source (#include) file.
2869160 0xa0 N_PSYM parameter variable
2870162 0xa2 N_EINCL end of an include file
2871164 0xa4 N_ENTRY alternate entry point
2872192 0xc0 N_LBRAC beginning of a lexical block
2873194 0xc2 N_EXCL place holder for a deleted include file
2874196 0xc4 N_SCOPE modula2 scope information (Sun linker)
2875224 0xe0 N_RBRAC end of a lexical block
2876226 0xe2 N_BCOMM begin named common block
2877228 0xe4 N_ECOMM end named common block
2878232 0xe8 N_ECOML end common (local name)
e505224d
PB
2879
2880 << used on Gould systems for non-base registers syms >>
139741da
RP
2881240 0xf0 N_NBTEXT ??
2882242 0xf2 N_NBDATA ??
2883244 0xf4 N_NBBSS ??
2884246 0xf6 N_NBSTS ??
2885248 0xf8 N_NBLCS ??
899bafeb 2886@end smallexample
e505224d 2887
899bafeb 2888@node Assembler types
8c59ee11 2889@appendix Table B: Symbol types from assembler and linker
e505224d
PB
2890
2891Table B shows the types of symbol table entries that hold assembler
2892and linker symbols.
2893
2894The #define names for these n_types values are defined in
2895/include/aout/aout64.h
2896
899bafeb 2897@smallexample
139741da
RP
2898dec hex #define
2899n_type n_type name used to describe
5bc927fb 2900------------------------------------------
139741da
RP
29011 0x0 N_UNDF undefined symbol
29022 0x2 N_ABS absolute symbol -- defined at a particular address
29033 0x3 extern " (vs. file scope)
29044 0x4 N_TEXT text symbol -- defined at offset in text segment
29055 0x5 extern " (vs. file scope)
29066 0x6 N_DATA data symbol -- defined at offset in data segment
29077 0x7 extern " (vs. file scope)
29088 0x8 N_BSS BSS symbol -- defined at offset in zero'd segment
29099 extern " (vs. file scope)
2910
291112 0x0C N_FN_SEQ func name for Sequent compilers (stab exception)
2912
291349 0x12 N_COMM common sym -- visable after shared lib dynamic link
291431 0x1f N_FN file name of a .o file
899bafeb 2915@end smallexample
e505224d 2916
8c59ee11
JK
2917@node Symbol Descriptors
2918@appendix Table C: Symbol descriptors
e505224d 2919
ed9708e2 2920@c Please keep this alphabetical
497e44a5 2921@table @code
8c59ee11
JK
2922@item @var{(digit)}
2923@itemx (
2924@itemx -
497e44a5
JK
2925Local variable, @xref{Automatic variables}.
2926
6897f9ec
JK
2927@item a
2928Parameter passed by reference in register, @xref{Parameters}.
2929
2930@item c
2931Constant, @xref{Constants}.
2932
ed9708e2 2933@item C
8c59ee11
JK
2934Conformant array bound (Pascal, maybe other languages),
2935@xref{Parameters}. Name of a caught exception (GNU C++). These can be
2936distinguished because the latter uses N_CATCH and the former uses
2937another symbol type.
6897f9ec
JK
2938
2939@item d
2940Floating point register variable, @xref{Register variables}.
2941
2942@item D
2943Parameter in floating point register, @xref{Parameters}.
ed9708e2 2944
497e44a5 2945@item f
6897f9ec 2946Static function, @xref{Procedures}.
497e44a5
JK
2947
2948@item F
2949Global function, @xref{Procedures}.
2950
497e44a5
JK
2951@item G
2952Global variable, @xref{Global Variables}.
2953
ed9708e2
JK
2954@item i
2955@xref{Parameters}.
2956
6897f9ec
JK
2957@item I
2958Internal (nested) procedure, @xref{Procedures}.
2959
2960@item J
2961Internal (nested) function, @xref{Procedures}.
2962
2963@item L
2964Label name (documented by AIX, no further information known).
2965
2966@item m
2967Module, @xref{Procedures}.
2968
ed9708e2 2969@item p
8c59ee11 2970Argument list parameter, @xref{Parameters}.
ed9708e2
JK
2971
2972@item pP
2973@xref{Parameters}.
2974
2975@item pF
8c59ee11 2976FORTRAN Function parameter, @xref{Parameters}.
ed9708e2
JK
2977
2978@item P
1a8b5668
JK
2979Unfortunately, three separate meanings have been independently invented
2980for this symbol descriptor. At least the GNU and Sun uses can be
2981distinguished by the symbol type. Global Procedure (AIX) (symbol type
2982used unknown), @xref{Procedures}. Register parameter (GNU) (symbol type
2983N_PSYM), @xref{Parameters}. Prototype of function referenced by this
2984file (Sun acc) (symbol type N_FUN).
6897f9ec
JK
2985
2986@item Q
2987Static Procedure, @xref{Procedures}.
2988
2989@item R
ed9708e2
JK
2990Register parameter @xref{Parameters}.
2991
497e44a5
JK
2992@item r
2993Register variable, @xref{Register variables}.
2994
2995@item S
2996Static file scope variable @xref{Initialized statics},
1b5c6c05 2997@xref{Un-initialized statics}.
497e44a5 2998
ed9708e2
JK
2999@item t
3000Type name, @xref{Typedefs}.
3001
3002@item T
8c59ee11 3003enumeration, struct or union tag, @xref{Typedefs}.
ed9708e2
JK
3004
3005@item v
8c59ee11 3006Parameter passed by reference, @xref{Parameters}.
ed9708e2 3007
497e44a5
JK
3008@item V
3009Static procedure scope variable @xref{Initialized statics},
1b5c6c05 3010@xref{Un-initialized statics}.
497e44a5 3011
6897f9ec
JK
3012@item x
3013Conformant array, @xref{Parameters}.
3014
ed9708e2
JK
3015@item X
3016Function return variable, @xref{Parameters}.
497e44a5 3017@end table
e505224d 3018
899bafeb 3019@node Type Descriptors
8c59ee11 3020@appendix Table D: Type Descriptors
e505224d 3021
6897f9ec 3022@table @code
8c59ee11
JK
3023@item @var{digit}
3024@itemx (
3025Type reference, @xref{Stabs Format}.
3026
3027@item -
3028Reference to builtin type, @xref{Negative Type Numbers}.
3029
3030@item #
3031Method (C++), @xref{Cplusplus}.
6897f9ec
JK
3032
3033@item *
8c59ee11
JK
3034Pointer, @xref{Miscellaneous Types}.
3035
3036@item &
3037Reference (C++).
6897f9ec
JK
3038
3039@item @@
8c59ee11
JK
3040Type Attributes (AIX), @xref{Stabs Format}. Member (class and variable)
3041type (GNU C++), @xref{Cplusplus}.
e505224d 3042
6897f9ec 3043@item a
8c59ee11
JK
3044Array, @xref{Arrays}.
3045
3046@item A
3047Open array, @xref{Arrays}.
3048
3049@item b
3050Pascal space type (AIX), @xref{Miscellaneous Types}. Builtin integer
3051type (Sun), @xref{Builtin Type Descriptors}.
3052
3053@item B
3054Volatile-qualified type, @xref{Miscellaneous Types}.
3055
3056@item c
3057Complex builtin type, @xref{Builtin Type Descriptors}.
3058
3059@item C
3060COBOL Picture type. See AIX documentation for details.
3061
3062@item d
3063File type, @xref{Miscellaneous Types}.
3064
3065@item D
3066N-dimensional dynamic array, @xref{Arrays}.
6897f9ec
JK
3067
3068@item e
8c59ee11
JK
3069Enumeration type, @xref{Enumerations}.
3070
3071@item E
3072N-dimensional subarray, @xref{Arrays}.
6897f9ec
JK
3073
3074@item f
8c59ee11
JK
3075Function type, @xref{Function types}.
3076
3077@item g
3078Builtin floating point type, @xref{Builtin Type Descriptors}.
3079
3080@item G
3081COBOL Group. See AIX documentation for details.
3082
3083@item i
3084Imported type, @xref{Cross-references}.
3085
3086@item k
3087Const-qualified type, @xref{Miscellaneous Types}.
3088
3089@item K
3090COBOL File Descriptor. See AIX documentation for details.
3091
3092@item n
3093String type, @xref{Strings}.
3094
3095@item N
3096Stringptr, @xref{Strings}.
3097
3098@item M
3099Multiple instance type, @xref{Miscellaneous Types}.
3100
3101@item o
3102Opaque type, @xref{Typedefs}.
3103
3104@item P
3105Packed array, @xref{Arrays}.
6897f9ec
JK
3106
3107@item r
8c59ee11
JK
3108Range type, @xref{Subranges}.
3109
3110@item R
3111Builtin floating type, @xref{Builtin Type Descriptors}.
6897f9ec
JK
3112
3113@item s
8c59ee11
JK
3114Structure type, @xref{Structures}.
3115
3116@item S
3117Set type, @xref{Miscellaneous Types}.
6897f9ec
JK
3118
3119@item u
8c59ee11
JK
3120Union, @xref{Unions}.
3121
3122@item v
3123Variant record. This is a Pascal and Modula-2 feature which is like a
3124union within a struct in C. See AIX documentation for details.
3125
3126@item w
3127Wide character, @xref{Builtin Type Descriptors}.
3128
3129@item x
3130Cross-reference, @xref{Cross-references}.
6897f9ec 3131
8c59ee11
JK
3132@item z
3133gstring, @xref{Strings}.
6897f9ec 3134@end table
e505224d 3135
899bafeb 3136@node Expanded reference
e505224d
PB
3137@appendix Expanded reference by stab type.
3138
8c59ee11
JK
3139@c FIXME: For most types this should be much shorter and much sweeter,
3140@c see N_PSYM for an example. For stuff like N_SO where the stab type
3141@c really is the important thing, the information can stay here.
3142
3143@c FIXME: It probably should be merged with Tables A and B.
3144
e505224d
PB
3145Format of an entry:
3146
3147The first line is the symbol type expressed in decimal, hexadecimal,
3148and as a #define (see devo/include/aout/stab.def).
3149
3150The second line describes the language constructs the symbol type
3151represents.
3152
3153The third line is the stab format with the significant stab fields
3154named and the rest NIL.
3155
3156Subsequent lines expand upon the meaning and possible values for each
3157significant stab field. # stands in for the type descriptor.
3158
3159Finally, any further information.
3160
899bafeb
RP
3161@menu
3162* N_GSYM:: Global variable
3163* N_FNAME:: Function name (BSD Fortran)
3164* N_FUN:: C Function name or text segment variable
3165* N_STSYM:: Initialized static symbol
3166* N_LCSYM:: Uninitialized static symbol
3167* N_MAIN:: Name of main routine (not for C)
3168* N_PC:: Pascal global symbol
3169* N_NSYMS:: Number of symbols
3170* N_NOMAP:: No DST map
3171* N_RSYM:: Register variable
3172* N_M2C:: Modula-2 compilation unit
3173* N_SLINE:: Line number in text segment
3174* N_DSLINE:: Line number in data segment
3175* N_BSLINE:: Line number in bss segment
3176* N_BROWS:: Path to .cb file for Sun source code browser
3177* N_DEFD:: GNU Modula2 definition module dependency
3178* N_EHDECL:: GNU C++ exception variable
3179* N_MOD2:: Modula2 information "for imc"
3180* N_CATCH:: GNU C++ "catch" clause
3181* N_SSYM:: Structure or union element
3182* N_SO:: Source file containing main
3183* N_LSYM:: Automatic variable
3184* N_BINCL:: Beginning of include file (Sun only)
3185* N_SOL:: Name of include file
3186* N_PSYM:: Parameter variable
3187* N_EINCL:: End of include file
3188* N_ENTRY:: Alternate entry point
3189* N_LBRAC:: Beginning of lexical block
3190* N_EXCL:: Deleted include file
3191* N_SCOPE:: Modula2 scope information (Sun only)
3192* N_RBRAC:: End of lexical block
3193* N_BCOMM:: Begin named common block
3194* N_ECOMM:: End named common block
3195* N_ECOML:: End common
3196* Gould:: non-base register symbols used on Gould systems
3197* N_LENG:: Length of preceding entry
3198@end menu
3199
3200@node N_GSYM
139741da 3201@section 32 - 0x20 - N_GYSM
899bafeb
RP
3202
3203@display
e505224d
PB
3204Global variable.
3205
3206.stabs "name", N_GSYM, NIL, NIL, NIL
899bafeb 3207@end display
e505224d 3208
899bafeb 3209@example
e505224d 3210"name" -> "symbol_name:#type"
139741da 3211 # -> G
899bafeb 3212@end example
e505224d 3213
4d7f562d 3214Only the "name" field is significant. The location of the variable is
e505224d
PB
3215obtained from the corresponding external symbol.
3216
899bafeb
RP
3217@node N_FNAME
3218@section 34 - 0x22 - N_FNAME
e505224d
PB
3219Function name (for BSD Fortran)
3220
899bafeb 3221@display
e505224d 3222.stabs "name", N_FNAME, NIL, NIL, NIL
899bafeb 3223@end display
e505224d 3224
899bafeb 3225@example
e505224d 3226"name" -> "function_name"
899bafeb 3227@end example
e505224d
PB
3228
3229Only the "name" field is significant. The location of the symbol is
3230obtained from the corresponding extern symbol.
3231
899bafeb 3232@node N_FUN
6897f9ec 3233@section 36 - 0x24 - N_FUN
e505224d 3234
6897f9ec
JK
3235Function name (@pxref{Procedures}) or text segment variable
3236(@pxref{Variables}).
899bafeb
RP
3237@example
3238@exdent @emph{For functions:}
e505224d 3239"name" -> "proc_name:#return_type"
139741da
RP
3240 # -> F (global function)
3241 f (local function)
e505224d
PB
3242desc -> line num for proc start. (GCC doesn't set and DBX doesn't miss it.)
3243value -> Code address of proc start.
3244
899bafeb 3245@exdent @emph{For text segment variables:}
e505224d 3246<<How to create one?>>
899bafeb 3247@end example
e505224d 3248
899bafeb
RP
3249@node N_STSYM
3250@section 38 - 0x26 - N_STSYM
e505224d
PB
3251Initialized static symbol (data segment w/internal linkage).
3252
899bafeb 3253@display
e505224d 3254.stabs "name", N_STSYM, NIL, NIL, value
899bafeb 3255@end display
e505224d 3256
899bafeb 3257@example
e505224d 3258"name" -> "symbol_name#type"
139741da
RP
3259 # -> S (scope global to compilation unit)
3260 -> V (scope local to a procedure)
e505224d 3261value -> Data Address
899bafeb 3262@end example
e505224d 3263
899bafeb
RP
3264@node N_LCSYM
3265@section 40 - 0x28 - N_LCSYM
e505224d
PB
3266Unitialized static (.lcomm) symbol(BSS segment w/internal linkage).
3267
899bafeb 3268@display
e505224d 3269.stabs "name", N_LCLSYM, NIL, NIL, value
899bafeb 3270@end display
e505224d 3271
899bafeb 3272@example
e505224d 3273"name" -> "symbol_name#type"
139741da
RP
3274 # -> S (scope global to compilation unit)
3275 -> V (scope local to procedure)
e505224d 3276value -> BSS Address
899bafeb 3277@end example
e505224d 3278
899bafeb 3279@node N_MAIN
139741da 3280@section 42 - 0x2a - N_MAIN
e505224d
PB
3281Name of main routine (not used in C)
3282
899bafeb 3283@display
e505224d 3284.stabs "name", N_MAIN, NIL, NIL, NIL
899bafeb 3285@end display
e505224d 3286
899bafeb 3287@example
e505224d 3288"name" -> "name_of_main_routine"
899bafeb 3289@end example
e505224d 3290
899bafeb 3291@node N_PC
139741da 3292@section 48 - 0x30 - N_PC
e505224d
PB
3293Global symbol (for Pascal)
3294
899bafeb 3295@display
e505224d 3296.stabs "name", N_PC, NIL, NIL, value
899bafeb 3297@end display
e505224d 3298
899bafeb 3299@example
e505224d
PB
3300"name" -> "symbol_name" <<?>>
3301value -> supposedly the line number (stab.def is skeptical)
899bafeb 3302@end example
e505224d 3303
899bafeb 3304@display
e505224d
PB
3305stabdump.c says:
3306
3307global pascal symbol: name,,0,subtype,line
3308<< subtype? >>
899bafeb 3309@end display
e505224d 3310
899bafeb 3311@node N_NSYMS
139741da 3312@section 50 - 0x32 - N_NSYMS
e505224d
PB
3313Number of symbols (according to Ultrix V4.0)
3314
899bafeb 3315@display
139741da 3316 0, files,,funcs,lines (stab.def)
899bafeb 3317@end display
e505224d 3318
899bafeb
RP
3319@node N_NOMAP
3320@section 52 - 0x34 - N_NOMAP
e505224d
PB
3321no DST map for sym (according to Ultrix V4.0)
3322
899bafeb 3323@display
139741da 3324 name, ,0,type,ignored (stab.def)
899bafeb
RP
3325@end display
3326
3327@node N_RSYM
139741da 3328@section 64 - 0x40 - N_RSYM
e505224d
PB
3329 register variable
3330
899bafeb 3331@display
e505224d 3332.stabs "name:type",N_RSYM,0,RegSize,RegNumber (Sun doc)
899bafeb 3333@end display
e505224d 3334
899bafeb 3335@node N_M2C
139741da 3336@section 66 - 0x42 - N_M2C
e505224d
PB
3337Modula-2 compilation unit
3338
899bafeb 3339@display
e505224d 3340.stabs "name", N_M2C, 0, desc, value
899bafeb 3341@end display
e505224d 3342
899bafeb 3343@example
e505224d
PB
3344"name" -> "unit_name,unit_time_stamp[,code_time_stamp]
3345desc -> unit_number
3346value -> 0 (main unit)
139741da 3347 1 (any other unit)
899bafeb 3348@end example
e505224d 3349
899bafeb 3350@node N_SLINE
139741da 3351@section 68 - 0x44 - N_SLINE
e505224d
PB
3352Line number in text segment
3353
899bafeb 3354@display
e505224d 3355.stabn N_SLINE, 0, desc, value
899bafeb 3356@end display
e505224d 3357
899bafeb 3358@example
e505224d
PB
3359desc -> line_number
3360value -> code_address (relocatable addr where the corresponding code starts)
899bafeb 3361@end example
e505224d
PB
3362
3363For single source lines that generate discontiguous code, such as flow
3364of control statements, there may be more than one N_SLINE stab for the
3365same source line. In this case there is a stab at the start of each
3366code range, each with the same line number.
3367
899bafeb
RP
3368@node N_DSLINE
3369@section 70 - 0x46 - N_DSLINE
e505224d
PB
3370Line number in data segment
3371
899bafeb 3372@display
e505224d 3373.stabn N_DSLINE, 0, desc, value
899bafeb 3374@end display
e505224d 3375
899bafeb 3376@example
e505224d 3377desc -> line_number
899bafeb
RP
3378value -> data_address (relocatable addr where the corresponding code
3379starts)
3380@end example
e505224d
PB
3381
3382See comment for N_SLINE above.
3383
899bafeb
RP
3384@node N_BSLINE
3385@section 72 - 0x48 - N_BSLINE
e505224d
PB
3386Line number in bss segment
3387
899bafeb 3388@display
e505224d 3389.stabn N_BSLINE, 0, desc, value
899bafeb 3390@end display
e505224d 3391
899bafeb 3392@example
e505224d 3393desc -> line_number
899bafeb
RP
3394value -> bss_address (relocatable addr where the corresponding code
3395starts)
3396@end example
e505224d
PB
3397
3398See comment for N_SLINE above.
3399
899bafeb 3400@node N_BROWS
139741da 3401@section 72 - 0x48 - N_BROWS
e505224d
PB
3402Sun source code browser, path to .cb file
3403
3404<<?>>
3405"path to associated .cb file"
3406
3407Note: type field value overlaps with N_BSLINE
3408
899bafeb 3409@node N_DEFD
139741da 3410@section 74 - 0x4a - N_DEFD
612dbd4c 3411GNU Modula2 definition module dependency
e505224d
PB
3412
3413GNU Modula-2 definition module dependency. Value is the modification
3414time of the definition file. Other is non-zero if it is imported with
3415the GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
3416are enough empty fields?
3417
899bafeb
RP
3418@node N_EHDECL
3419@section 80 - 0x50 - N_EHDECL
612dbd4c 3420GNU C++ exception variable <<?>>
e505224d
PB
3421
3422"name is variable name"
3423
3424Note: conflicts with N_MOD2.
3425
899bafeb
RP
3426@node N_MOD2
3427@section 80 - 0x50 - N_MOD2
3428Modula2 info "for imc" (according to Ultrix V4.0)
e505224d
PB
3429
3430Note: conflicts with N_EHDECL <<?>>
3431
899bafeb
RP
3432@node N_CATCH
3433@section 84 - 0x54 - N_CATCH
3434GNU C++ "catch" clause
e505224d
PB
3435
3436GNU C++ `catch' clause. Value is its address. Desc is nonzero if
3437this entry is immediately followed by a CAUGHT stab saying what
3438exception was caught. Multiple CAUGHT stabs means that multiple
3439exceptions can be caught here. If Desc is 0, it means all exceptions
3440are caught here.
3441
899bafeb 3442@node N_SSYM
139741da 3443@section 96 - 0x60 - N_SSYM
e505224d
PB
3444Structure or union element
3445
899bafeb
RP
3446Value is offset in the structure.
3447
3448<<?looking at structs and unions in C I didn't see these>>
e505224d 3449
899bafeb 3450@node N_SO
139741da 3451@section 100 - 0x64 - N_SO
e505224d
PB
3452Path and name of source file containing main routine
3453
899bafeb 3454@display
e505224d 3455.stabs "name", N_SO, NIL, NIL, value
899bafeb 3456@end display
e505224d 3457
899bafeb 3458@example
c0264596
JK
3459"name" -> /source/directory/
3460 -> source_file
e505224d
PB
3461
3462value -> the starting text address of the compilation.
899bafeb 3463@end example
e505224d 3464
c0264596
JK
3465These are found two in a row. The name field of the first N_SO contains
3466the directory that the source file is relative to. The name field of
3467the second N_SO contains the name of the source file itself.
3468
3469Only some compilers (e.g. gcc2, Sun cc) include the directory; this
3470symbol can be distinguished by the fact that it ends in a slash.
3471According to a comment in GDB's partial-stab.h, other compilers
3472(especially unnamed C++ compilers) put out useless N_SO's for
3473nonexistent source files (after the N_SO for the real source file).
e505224d 3474
899bafeb 3475@node N_LSYM
139741da 3476@section 128 - 0x80 - N_LSYM
e505224d
PB
3477Automatic var in the stack (also used for type descriptors.)
3478
899bafeb 3479@display
e505224d 3480.stabs "name" N_LSYM, NIL, NIL, value
899bafeb 3481@end display
e505224d 3482
899bafeb
RP
3483@example
3484@exdent @emph{For stack based local variables:}
e505224d
PB
3485
3486"name" -> name of the variable
3487value -> offset from frame pointer (negative)
3488
899bafeb 3489@exdent @emph{For type descriptors:}
e505224d
PB
3490
3491"name" -> "name_of_the_type:#type"
139741da 3492 # -> t
e505224d 3493
139741da 3494type -> type_ref (or) type_def
e505224d
PB
3495
3496type_ref -> type_number
3497type_def -> type_number=type_desc etc.
899bafeb 3498@end example
e505224d
PB
3499
3500Type may be either a type reference or a type definition. A type
3501reference is a number that refers to a previously defined type. A
3502type definition is the number that will refer to this type, followed
3503by an equals sign, a type descriptor and the additional data that
3504defines the type. See the Table D for type descriptors and the
3505section on types for what data follows each type descriptor.
3506
899bafeb 3507@node N_BINCL
139741da 3508@section 130 - 0x82 - N_BINCL
e505224d
PB
3509
3510Beginning of an include file (Sun only)
3511
3512Beginning of an include file. Only Sun uses this. In an object file,
3513only the name is significant. The Sun linker puts data into some of
3514the other fields.
3515
899bafeb
RP
3516@node N_SOL
3517@section 132 - 0x84 - N_SOL
e505224d
PB
3518
3519Name of a sub-source file (#include file). Value is starting address
3520of the compilation.
3521<<?>>
3522
899bafeb 3523@node N_PSYM
139741da 3524@section 160 - 0xa0 - N_PSYM
e505224d 3525
a2a2eac8 3526Parameter variable. @xref{Parameters}.
e505224d 3527
899bafeb
RP
3528@node N_EINCL
3529@section 162 - 0xa2 - N_EINCL
e505224d
PB
3530
3531End of an include file. This and N_BINCL act as brackets around the
3532file's output. In an ojbect file, there is no significant data in
899bafeb 3533this entry. The Sun linker puts data into some of the fields.
e505224d
PB
3534<<?>>
3535
899bafeb
RP
3536@node N_ENTRY
3537@section 164 - 0xa4 - N_ENTRY
e505224d
PB
3538
3539Alternate entry point.
3540Value is its address.
3541<<?>>
3542
899bafeb
RP
3543@node N_LBRAC
3544@section 192 - 0xc0 - N_LBRAC
e505224d
PB
3545
3546Beginning of a lexical block (left brace). The variable defined
3547inside the block precede the N_LBRAC symbol. Or can they follow as
3548well as long as a new N_FUNC was not encountered. <<?>>
3549
899bafeb 3550@display
e505224d 3551.stabn N_LBRAC, NIL, NIL, value
899bafeb 3552@end display
e505224d 3553
899bafeb 3554@example
e505224d 3555value -> code address of block start.
899bafeb 3556@end example
e505224d 3557
899bafeb
RP
3558@node N_EXCL
3559@section 194 - 0xc2 - N_EXCL
e505224d
PB
3560
3561Place holder for a deleted include file. Replaces a N_BINCL and
3562everything up to the corresponding N_EINCL. The Sun linker generates
3563these when it finds multiple indentical copies of the symbols from an
3564included file. This appears only in output from the Sun linker.
3565<<?>>
3566
899bafeb
RP
3567@node N_SCOPE
3568@section 196 - 0xc4 - N_SCOPE
e505224d
PB
3569
3570Modula2 scope information (Sun linker)
3571<<?>>
3572
899bafeb 3573@node N_RBRAC
139741da 3574@section 224 - 0xe0 - N_RBRAC
e505224d
PB
3575
3576End of a lexical block (right brace)
3577
899bafeb 3578@display
e505224d 3579.stabn N_RBRAC, NIL, NIL, value
899bafeb 3580@end display
e505224d 3581
899bafeb 3582@example
e505224d 3583value -> code address of the end of the block.
899bafeb 3584@end example
e505224d 3585
899bafeb 3586@node N_BCOMM
139741da 3587@section 226 - 0xe2 - N_BCOMM
e505224d
PB
3588
3589Begin named common block.
3590
3591Only the name is significant.
3592<<?>>
3593
899bafeb 3594@node N_ECOMM
139741da 3595@section 228 - 0xe4 - N_ECOMM
e505224d
PB
3596
3597End named common block.
3598
3599Only the name is significant and it should match the N_BCOMM
3600<<?>>
3601
899bafeb
RP
3602@node N_ECOML
3603@section 232 - 0xe8 - N_ECOML
e505224d
PB
3604
3605End common (local name)
3606
3607value is address.
3608<<?>>
3609
899bafeb
RP
3610@node Gould
3611@section Non-base registers on Gould systems
e505224d
PB
3612<< used on Gould systems for non-base registers syms, values assigned
3613at random, need real info from Gould. >>
3614<<?>>
3615
899bafeb 3616@example
139741da
RP
3617240 0xf0 N_NBTEXT ??
3618242 0xf2 N_NBDATA ??
3619244 0xf4 N_NBBSS ??
3620246 0xf6 N_NBSTS ??
3621248 0xf8 N_NBLCS ??
899bafeb 3622@end example
e505224d 3623
899bafeb
RP
3624@node N_LENG
3625@section - 0xfe - N_LENG
e505224d
PB
3626
3627Second symbol entry containing a length-value for the preceding entry.
3628The value is the length.
3629
899bafeb
RP
3630@node Questions
3631@appendix Questions and anomalies
e505224d
PB
3632
3633@itemize @bullet
3634@item
3635For GNU C stabs defining local and global variables (N_LSYM and
3636N_GSYM), the desc field is supposed to contain the source line number
3637on which the variable is defined. In reality the desc field is always
36380. (This behavour is defined in dbxout.c and putting a line number in
3639desc is controlled by #ifdef WINNING_GDB which defaults to false). Gdb
3640supposedly uses this information if you say 'list var'. In reality
3641var can be a variable defined in the program and gdb says `function
3642var not defined'
3643
3644@item
612dbd4c 3645In GNU C stabs there seems to be no way to differentiate tag types:
e505224d
PB
3646structures, unions, and enums (symbol descriptor T) and typedefs
3647(symbol descriptor t) defined at file scope from types defined locally
3648to a procedure or other more local scope. They all use the N_LSYM
3649stab type. Types defined at procedure scope are emited after the
139741da 3650N_RBRAC of the preceding function and before the code of the
e505224d
PB
3651procedure in which they are defined. This is exactly the same as
3652types defined in the source file between the two procedure bodies.
4d7f562d 3653GDB overcompensates by placing all types in block #1, the block for
e505224d 3654symbols of file scope. This is true for default, -ansi and
4d7f562d 3655-traditional compiler options. (Bugs gcc/1063, gdb/1066.)
e505224d
PB
3656
3657@item
3658What ends the procedure scope? Is it the proc block's N_RBRAC or the
3659next N_FUN? (I believe its the first.)
3660
3661@item
3662The comment in xcoff.h says DBX_STATIC_CONST_VAR_CODE is used for
3663static const variables. DBX_STATIC_CONST_VAR_CODE is set to N_FUN by
3664default, in dbxout.c. If included, xcoff.h redefines it to N_STSYM.
3665But testing the default behaviour, my Sun4 native example shows
3666N_STSYM not N_FUN is used to describe file static initialized
3667variables. (the code tests for TREE_READONLY(decl) &&
3668!TREE_THIS_VOLATILE(decl) and if true uses DBX_STATIC_CONST_VAR_CODE).
3669
3670@item
3671Global variable stabs don't have location information. This comes
3672from the external symbol for the same variable. The external symbol
3673has a leading underbar on the _name of the variable and the stab does
3674not. How do we know these two symbol table entries are talking about
3675the same symbol when their names are different?
3676
3677@item
3678Can gcc be configured to output stabs the way the Sun compiler
3679does, so that their native debugging tools work? <NO?> It doesn't by
3680default. GDB reads either format of stab. (gcc or SunC). How about
3681dbx?
3682@end itemize
3683
899bafeb 3684@node xcoff-differences
e505224d
PB
3685@appendix Differences between GNU stabs in a.out and GNU stabs in xcoff
3686
497e44a5
JK
3687@c FIXME: Merge *all* these into the main body of the document.
3688(The AIX/RS6000 native object file format is xcoff with stabs). This
3689appendix only covers those differences which are not covered in the main
3690body of this document.
e505224d
PB
3691
3692@itemize @bullet
3693@item
3694Instead of .stabs, xcoff uses .stabx.
3695
3696@item
3697The data fields of an xcoff .stabx are in a different order than an
1a8b5668
JK
3698a.out .stabs. The order is: string, value, type, sdb-type. The desc
3699and null fields present in a.out stabs are missing in xcoff stabs. For
3700N_GSYM the value field is the name of the symbol. sdb-type is unused
3701with stabs; it can always be set to 0.
e505224d
PB
3702
3703@item
5bc927fb 3704BSD a.out stab types correspond to AIX xcoff storage classes. In general the
e505224d
PB
3705mapping is N_STABTYPE becomes C_STABTYPE. Some stab types in a.out
3706are not supported in xcoff. See Table E. for full mappings.
3707
3708exception:
3709initialised static N_STSYM and un-initialized static N_LCSYM both map
3710to the C_STSYM storage class. But the destinction is preserved
3711because in xcoff N_STSYM and N_LCSYM must be emited in a named static
3712block. Begin the block with .bs s[RW] data_section_name for N_STSYM
3713or .bs s bss_section_name for N_LCSYM. End the block with .es
3714
e505224d
PB
3715@item
3716xcoff uses a .file stab type to represent the source file name. There
3717is no stab for the path to the source file.
3718
3719@item
3720xcoff uses a .line stab type to represent source lines. The format
3721is: .line line_number.
3722
3723@item
3724xcoff emits line numbers relative to the start of the current
3725function. The start of a function is marked by .bf. If a function
3726includes lines from a seperate file, then those line numbers are
3727absolute line numbers in the <<sub-?>> file being compiled.
3728
3729@item
3730The start of current include file is marked with: .bi "filename" and
3731the end marked with .ei "filename"
3732
3733@item
3734If the xcoff stab is a N_FUN (C_FUN) then follow the string field with
3735,. instead of just ,
e505224d
PB
3736@end itemize
3737
3738
3739(I think that's it for .s file differences. They could stand to be
3740better presented. This is just a list of what I have noticed so far.
3741There are a *lot* of differences in the information in the symbol
3742tables of the executable and object files.)
3743
3744Table E: mapping a.out stab types to xcoff storage classes
3745
3746@example
139741da 3747stab type storage class
e505224d 3748-------------------------------
139741da
RP
3749N_GSYM C_GSYM
3750N_FNAME unknown
3751N_FUN C_FUN
3752N_STSYM C_STSYM
3753N_LCSYM C_STSYM
3754N_MAIN unkown
3755N_PC unknown
3756N_RSYM C_RSYM
3757N_RPSYM (0x8e) C_RPSYM
3758N_M2C unknown
3759N_SLINE unknown
3760N_DSLINE unknown
3761N_BSLINE unknown
3762N_BROWSE unchanged
3763N_CATCH unknown
3764N_SSYM unknown
3765N_SO unknown
3766N_LSYM C_LSYM
3767N_DECL (0x8c) C_DECL
3768N_BINCL unknown
3769N_SOL unknown
3770N_PSYM C_PSYM
3771N_EINCL unknown
3772N_ENTRY C_ENTRY
3773N_LBRAC unknown
3774N_EXCL unknown
3775N_SCOPE unknown
3776N_RBRAC unknown
3777N_BCOMM C_BCOMM
3778N_ECOMM C_ECOMM
3779N_ECOML C_ECOML
3780
3781N_LENG unknown
e505224d
PB
3782@end example
3783
899bafeb 3784@node Sun-differences
e505224d
PB
3785@appendix Differences between GNU stabs and Sun native stabs.
3786
497e44a5
JK
3787@c FIXME: Merge all this stuff into the main body of the document.
3788
e505224d
PB
3789@itemize @bullet
3790@item
612dbd4c 3791GNU C stabs define *all* types, file or procedure scope, as
e505224d
PB
3792N_LSYM. Sun doc talks about using N_GSYM too.
3793
e505224d
PB
3794@item
3795Stabs describing block scopes, N_LBRAC and N_RBRAC are supposed to
3796contain the nesting level of the block in the desc field, re Sun doc.
497e44a5 3797GNU stabs always have 0 in that field. dbx seems not to care.
e505224d
PB
3798
3799@item
3800Sun C stabs use type number pairs in the format (a,b) where a is a
3801number starting with 1 and incremented for each sub-source file in the
3802compilation. b is a number starting with 1 and incremented for each
612dbd4c 3803new type defined in the compilation. GNU C stabs use the type number
e505224d
PB
3804alone, with no source file number.
3805@end itemize
3806
3807@contents
3808@bye
This page took 0.237378 seconds and 4 git commands to generate.