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