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