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