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