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