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