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