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