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