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