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