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