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