* gdbint.texinfo: Doc NO_MMALLOC and NO_MMALLOC_CHECK as host conditionals.
[deliverable/binutils-gdb.git] / gdb / doc / stabs.texinfo
1 \input texinfo
2 @setfilename stabs.info
3
4 @ifinfo
5 @format
6 START-INFO-DIR-ENTRY
7 * Stabs: (stabs). The "stabs" debugging information format.
8 END-INFO-DIR-ENTRY
9 @end format
10 @end ifinfo
11
12 @ifinfo
13 This document describes GNU stabs (debugging symbol tables) in a.out files.
14
15 Copyright 1992 Free Software Foundation, Inc.
16 Contributed by Cygnus Support. Written by Julia Menapace.
17
18 Permission is granted to make and distribute verbatim copies of
19 this manual provided the copyright notice and this permission notice
20 are preserved on all copies.
21
22 @ignore
23 Permission is granted to process this file through Tex and print the
24 results, provided the printed document carries copying permission
25 notice identical to this one except for the removal of this paragraph
26 (this paragraph not being relevant to the printed manual).
27
28 @end ignore
29 Permission is granted to copy or distribute modified versions of this
30 manual under the terms of the GPL (for which purpose this text may be
31 regarded as a program in the language TeX).
32 @end ifinfo
33
34 @setchapternewpage odd
35 @settitle STABS
36 @titlepage
37 @title The ``stabs'' debug format
38 @author Julia Menapace
39 @author Cygnus Support
40 @page
41 @tex
42 \def\$#1${{#1}} % Kluge: collect RCS revision info without $...$
43 \xdef\manvers{\$Revision$} % For use in headers, footers too
44 {\parskip=0pt
45 \hfill Cygnus Support\par
46 \hfill \manvers\par
47 \hfill \TeX{}info \texinfoversion\par
48 }
49 @end tex
50
51 @vskip 0pt plus 1filll
52 Copyright @copyright{} 1992 Free Software Foundation, Inc.
53 Contributed by Cygnus Support.
54
55 Permission is granted to make and distribute verbatim copies of
56 this manual provided the copyright notice and this permission notice
57 are preserved on all copies.
58
59 @end titlepage
60
61 @ifinfo
62 @node Top
63 @top The "stabs" representation of debugging information
64
65 This document describes the GNU stabs debugging format in a.out files.
66
67 @menu
68 * Overview:: Overview of stabs
69 * Program structure:: Encoding of the structure of the program
70 * Simple types::
71 * Example:: A comprehensive example in C
72 * Variables::
73 * Aggregate Types::
74 * Symbol tables:: Symbol information in symbol tables
75 * GNU Cplusplus stabs::
76
77 Appendixes:
78 * Example2.c:: Source code for extended example
79 * Example2.s:: Assembly code for extended example
80 * Quick reference:: Various refernce tables
81 * Expanded reference:: Reference information by stab type
82 * Questions:: Questions and anomolies
83 * xcoff-differences:: Differences between GNU stabs in a.out
84 and GNU stabs in xcoff
85 * Sun-differences:: Differences between GNU stabs and Sun
86 native stabs
87 @end menu
88 @end ifinfo
89
90
91 @node Overview
92 @chapter Overview of stabs
93
94 @dfn{Stabs} refers to a format for information that describes a program
95 to a debugger. This format was apparently invented by
96 @c FIXME! <<name of inventor>> at
97 the University of California at Berkeley, for the @code{pdx} Pascal
98 debugger; the format has spread widely since then.
99
100 @menu
101 * Flow:: Overview of debugging information flow
102 * Stabs format:: Overview of stab format
103 * C example:: A simple example in C source
104 * Assembly code:: The simple example at the assembly level
105 @end menu
106
107 @node Flow
108 @section Overview of debugging information flow
109
110 The GNU C compiler compiles C source in a @file{.c} file into assembly
111 language in a @file{.s} file, which is translated by the assembler into
112 a @file{.o} file, and then linked with other @file{.o} files and
113 libraries to produce an executable file.
114
115 With the @samp{-g} option, GCC puts additional debugging information in
116 the @file{.s} file, which is slightly transformed by the assembler and
117 linker, and carried through into the final executable. This debugging
118 information describes features of the source file like line numbers,
119 the types and scopes of variables, and functions, their parameters and
120 their scopes.
121
122 For some object file formats, the debugging information is
123 encapsulated in assembler directives known collectively as `stab' (symbol
124 table) directives, interspersed with the generated code. Stabs are
125 the native format for debugging information in the a.out and xcoff
126 object file formats. The GNU tools can also emit stabs in the coff
127 and ecoff object file formats.
128
129 The assembler adds the information from stabs to the symbol information
130 it places by default in the symbol table and the string table of the
131 @file{.o} file it is building. The linker consolidates the @file{.o}
132 files into one executable file, with one symbol table and one string
133 table. Debuggers use the symbol and string tables in the executable as
134 a source of debugging information about the program.
135
136 @node Stabs format
137 @section Overview of stab format
138
139 There are three overall formats for stab assembler directives
140 differentiated by the first word of the stab. The name of the directive
141 describes what combination of four possible data fields will follow. It
142 is either @code{.stabs} (string), @code{.stabn} (number), or
143 @code{.stabd} (dot).
144
145 The overall format of each class of stab is:
146
147 @example
148 .stabs "@var{string}",@var{type},0,@var{desc},@var{value}
149 .stabn @var{type},0,@var{desc},@var{value}
150 .stabd @var{type},0,@var{desc}
151 @end example
152
153 In general, in @code{.stabs} the @var{string} field contains name and type
154 information. For @code{.stabd} the value field is implicit and has the value
155 of the current file location. Otherwise the value field often
156 contains a relocatable address, frame pointer offset, or register
157 number, that maps to the source code element described by the stab.
158
159 The real key to decoding the meaning of a stab is the number in its type
160 field. Each possible type number defines a different stab type. The
161 stab type further defines the exact interpretation of, and possible
162 values for, any remaining @code{"@var{string}"}, @var{desc}, or
163 @var{value} fields present in the stab. Table A (@pxref{Stab
164 types,,Table A: Symbol types from stabs}) lists in numeric order
165 the possible type field values for stab directives. The reference
166 section that follows Table A describes the meaning of the fields for
167 each stab type in detail. The examples that follow this overview
168 introduce the stab types in terms of the source code elements they
169 describe.
170
171 For @code{.stabs} the @code{"@var{string}"} field holds the meat of the
172 debugging information. The generally unstructured nature of this field
173 is what makes stabs extensible. For some stab types the string field
174 contains only a name. For other stab types the contents can be a great
175 deal more complex.
176
177 The overall format is of the @code{"@var{string}"} field is:
178
179 @example
180 "@var{name}@r{[}:@var{symbol_descriptor}@r{]}
181 @r{[}@var{type_number}@r{[}=@var{type_descriptor} @r{@dots{}]]}"
182 @end example
183
184 @var{name} is the name of the symbol represented by the stab.
185
186 The @var{symbol_descriptor} following the @samp{:} is an alphabetic
187 character that tells more specifically what kind of symbol the stab
188 represents. If the @var{symbol_descriptor} is omitted, but type
189 information follows, then the stab represents a local variable. For a
190 list of symbol_descriptors, see @ref{Symbol descriptors,,Table C: Symbol
191 descriptors}.
192
193 Type information is either a @var{type_number}, or a
194 @samp{@var{type_number}=}. The @var{type_number} alone is a type
195 reference, referring directly to a type that has already been defined.
196
197 The @samp{@var{type_number}=} is a type definition, where the number
198 represents a new type which is about to be defined. The type definition
199 may refer to other types by number, and those type numbers may be
200 followed by @samp{=} and nested definitions.
201
202 In a type definition, if the character that follows the equals sign is
203 non-numeric then it is a @var{type_descriptor}, and tells what kind of
204 type is about to be defined. Any other values following the
205 @var{type_descriptor} vary, depending on the @var{type_descriptor}. If
206 a number follows the @samp{=} then the number is a @var{type_reference}.
207 This is described more thoroughly in the section on types. @xref{Type
208 Descriptors,,Table D: Type Descriptors}, for a list of
209 @var{type_descriptor} values.
210
211 All this can make the @code{"@var{string}"} field quite long. All
212 versions of GDB, and some versions of DBX, can handle arbitrarily long
213 strings. But many versions of DBX cretinously limit the strings to
214 about 80 characters, so compilers which must work with such DBX's need
215 to split the @code{.stabs} directive into several @code{.stabs}
216 directives. Each stab duplicates exactly all but the
217 @code{"@var{string}"} field. The @code{"@var{string}"} field of the
218 every stab except the last is marked as continued with a
219 double-backslash at the end. Removing the backslashes and concatenating
220 the @code{"@var{string}"} fields of each stab produces the original,
221 long string.
222
223 @node C example
224 @section A simple example in C source
225
226 To get the flavor of how stabs describe source information for a C
227 program, let's look at the simple program:
228
229 @example
230 main()
231 @{
232 printf("Hello world");
233 @}
234 @end example
235
236 When compiled with @samp{-g}, the program above yields the following
237 @file{.s} file. Line numbers have been added to make it easier to refer
238 to parts of the @file{.s} file in the description of the stabs that
239 follows.
240
241 @node Assembly code
242 @section The simple example at the assembly level
243
244 @example
245 1 gcc2_compiled.:
246 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
247 3 .stabs "hello.c",100,0,0,Ltext0
248 4 .text
249 5 Ltext0:
250 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
251 7 .stabs "char:t2=r2;0;127;",128,0,0,0
252 8 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
253 9 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
254 10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
255 11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
256 12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
257 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
258 14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
259 15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
260 16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
261 17 .stabs "float:t12=r1;4;0;",128,0,0,0
262 18 .stabs "double:t13=r1;8;0;",128,0,0,0
263 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
264 20 .stabs "void:t15=15",128,0,0,0
265 21 .align 4
266 22 LC0:
267 23 .ascii "Hello, world!\12\0"
268 24 .align 4
269 25 .global _main
270 26 .proc 1
271 27 _main:
272 28 .stabn 68,0,4,LM1
273 29 LM1:
274 30 !#PROLOGUE# 0
275 31 save %sp,-136,%sp
276 32 !#PROLOGUE# 1
277 33 call ___main,0
278 34 nop
279 35 .stabn 68,0,5,LM2
280 36 LM2:
281 37 LBB2:
282 38 sethi %hi(LC0),%o1
283 39 or %o1,%lo(LC0),%o0
284 40 call _printf,0
285 41 nop
286 42 .stabn 68,0,6,LM3
287 43 LM3:
288 44 LBE2:
289 45 .stabn 68,0,6,LM4
290 46 LM4:
291 47 L1:
292 48 ret
293 49 restore
294 50 .stabs "main:F1",36,0,0,_main
295 51 .stabn 192,0,0,LBB2
296 52 .stabn 224,0,0,LBE2
297 @end example
298
299 This simple ``hello world'' example demonstrates several of the stab
300 types used to describe C language source files.
301
302 @node Program structure
303 @chapter Encoding for the structure of the program
304
305 @menu
306 * Source file:: The path and name of the source file
307 * Line numbers::
308 * Procedures::
309 * Block Structure::
310 @end menu
311
312 @node Source file
313 @section The path and name of the source file
314
315 @table @strong
316 @item Directive:
317 @code{.stabs}
318 @item Type:
319 @code{N_SO}
320 @end table
321
322 The first stabs in the .s file contain the name and path of the source
323 file that was compiled to produce the .s file. This information is
324 contained in two records of stab type N_SO (100).
325
326 @example
327 .stabs "path_name", N_SO, NIL, NIL, Code_address_of_program_start
328 .stabs "file_name:", N_SO, NIL, NIL, Code_address_of_program_start
329 @end example
330
331 @example
332 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
333 3 .stabs "hello.c",100,0,0,Ltext0
334 4 .text
335 5 Ltext0:
336 @end example
337
338 @node Line numbers
339 @section Line Numbers
340
341 @table @strong
342 @item Directive:
343 @code{.stabn}
344 @item Type:
345 @code{N_SLINE}
346 @end table
347
348 The start of source lines is represented by the @code{N_SLINE} (68) stab
349 type.
350
351 @example
352 .stabn N_SLINE, NIL, @var{line}, @var{address}
353 @end example
354
355 @var{line} is a source line number; @var{address} represents the code
356 address for the start of that source line.
357
358 @example
359 27 _main:
360 28 .stabn 68,0,4,LM1
361 29 LM1:
362 30 !#PROLOGUE# 0
363 @end example
364
365 @node Procedures
366 @section Procedures
367
368 @table @strong
369 @item Directive:
370 @code{.stabs}
371 @item Type:
372 @code{N_FUN}
373 @item Symbol Descriptors:
374 @code{f} (local), @code{F} (global)
375 @end table
376
377 Procedures are described by the @code{N_FUN} stab type. The symbol
378 descriptor for a procedure is @samp{F} if the procedure is globally
379 scoped and @samp{f} if the procedure is static (locally scoped).
380
381 The @code{N_FUN} stab representing a procedure is located immediately
382 following the code of the procedure. The @code{N_FUN} stab is in turn
383 directly followed by a group of other stabs describing elements of the
384 procedure. These other stabs describe the procedure's parameters, its
385 block local variables and its block structure.
386
387 @example
388 48 ret
389 49 restore
390 @end example
391
392 The @code{.stabs} entry after this code fragment shows the @var{name} of
393 the procedure (@code{main}); the type descriptor @var{desc} (@code{F},
394 for a global procedure); a reference to the predefined type @code{int}
395 for the return type; and the starting @var{address} of the procedure.
396
397 Here is an exploded summary (with whitespace introduced for clarity),
398 followed by line 50 of our sample assembly output, which has this form:
399
400 @example
401 .stabs "@var{name}:
402 @var{desc} @r{(global proc @samp{F})}
403 @var{return_type_ref} @r{(int)}
404 ",N_FUN, NIL, NIL,
405 @var{address}
406 @end example
407
408 @example
409 50 .stabs "main:F1",36,0,0,_main
410 @end example
411
412 @node Block Structure
413 @section Block Structure
414
415 @table @strong
416 @item Directive:
417 @code{.stabn}
418 @item Types:
419 @code{N_LBRAC}, @code{N_RBRAC}
420 @end table
421
422 The program's block structure is represented by the @code{N_LBRAC} (left
423 brace) and the @code{N_RBRAC} (right brace) stab types. The following code
424 range, which is the body of @code{main}, is labeled with @samp{LBB2:} at the
425 beginning and @samp{LBE2:} at the end.
426
427 @example
428 37 LBB2:
429 38 sethi %hi(LC0),%o1
430 39 or %o1,%lo(LC0),%o0
431 40 call _printf,0
432 41 nop
433 42 .stabn 68,0,6,LM3
434 43 LM3:
435 44 LBE2:
436 @end example
437
438 The @code{N_LBRAC} and @code{N_RBRAC} stabs that describe the block
439 scope of the procedure are located after the @code{N_FUNC} stab that
440 represents the procedure itself. The @code{N_LBRAC} uses the
441 @code{LBB2} label as the code address in its value field, and the
442 @code{N_RBRAC} uses @code{LBE2}.
443
444 @example
445 50 .stabs "main:F1",36,0,0,_main
446 @end example
447
448 @example
449 .stabn N_LBRAC, NIL, NIL, @var{left-brace-address}
450 .stabn N_RBRAC, NIL, NIL, @var{right-brace-address}
451 @end example
452
453 @example
454 51 .stabn 192,0,0,LBB2
455 52 .stabn 224,0,0,LBE2
456 @end example
457
458 @node Simple types
459 @chapter Simple types
460
461 @menu
462 * Basic types:: Basic type definitions
463 * Range types:: Range types defined by min and max value
464 * Float "range" types:: Range type defined by size in bytes
465 @end menu
466
467 @node Basic types
468 @section Basic type definitions
469
470 @table @strong
471 @item Directive:
472 @code{.stabs}
473 @item Type:
474 @code{N_LSYM}
475 @item Symbol Descriptor:
476 @code{t}
477 @end table
478
479 The basic types for the language are described using the @code{N_LSYM} stab
480 type. They are boilerplate and are emited by the compiler for each
481 compilation unit. Basic type definitions are not always a complete
482 description of the type and are sometimes circular. The debugger
483 recognizes the type anyway, and knows how to read bits as that type.
484
485 Each language and compiler defines a slightly different set of basic
486 types. In this example we are looking at the basic types for C emited
487 by the GNU compiler targeting the Sun4. Here the basic types are
488 mostly defined as range types.
489
490
491 @node Range types
492 @section Range types defined by min and max value
493
494 @table @strong
495 @item Type Descriptor:
496 @code{r}
497 @end table
498
499 When defining a range type, if the number after the first semicolon is
500 smaller than the number after the second one, then the two numbers
501 represent the smallest and the largest values in the range.
502
503 @example
504 4 .text
505 5 Ltext0:
506
507 .stabs "@var{name}:
508 @var{descriptor} @r{(type)}
509 @var{type-def}=
510 @var{type-desc}
511 @var{type-ref};
512 @var{low-bound};
513 @var{high-bound};
514 ",
515 N_LSYM, NIL, NIL, NIL
516
517 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
518 7 .stabs "char:t2=r2;0;127;",128,0,0,0
519 @end example
520
521 Here the integer type (@code{1}) is defined as a range of the integer
522 type (@code{1}). Likewise @code{char} is a range of @code{char}. This
523 part of the definition is circular, but at least the high and low bound
524 values of the range hold more information about the type.
525
526 Here short unsigned int is defined as type number 8 and described as a
527 range of type @code{int}, with a minimum value of 0 and a maximum of 65535.
528
529 @example
530 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
531 @end example
532
533 @node Float "range" types
534 @section Range type defined by size in bytes
535
536 @table @strong
537 @item Type Descriptor:
538 @code{r}
539 @end table
540
541 In a range definition, if the first number after the semicolon is
542 positive and the second is zero, then the type being defined is a
543 floating point type, and the number after the first semicolon is the
544 number of bytes needed to represent the type. Note that this does not
545 provide a way to distinguish 8-byte real floating point types from
546 8-byte complex floating point types.
547
548 @example
549 .stabs "@var{name}:
550 @var{desc}
551 @var{type-def}=
552 @var{type-desc}
553 @var{type-ref};
554 @var{bit-count};
555 0;
556 ",
557 N_LSYM, NIL, NIL, NIL
558
559 17 .stabs "float:t12=r1;4;0;",128,0,0,0
560 18 .stabs "double:t13=r1;8;0;",128,0,0,0
561 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
562 @end example
563
564 Cosmically enough, the @code{void} type is defined directly in terms of
565 itself.
566
567 @example
568 .stabs "@var{name}:
569 @var{symbol-desc}
570 @var{type-def}=
571 @var{type-ref}
572 ",N_LSYM,NIL,NIL,NIL
573
574 20 .stabs "void:t15=15",128,0,0,0
575 @end example
576
577
578 @node Example
579 @chapter A Comprehensive Example in C
580
581 Now we'll examine a second program, @code{example2}, which builds on the
582 first example to introduce the rest of the stab types, symbol
583 descriptors, and type descriptors used in C.
584 @xref{Example2.c} for the complete @file{.c} source,
585 and @pxref{Example2.s} for the @file{.s} assembly code.
586 This description includes parts of those files.
587
588 @section Flow of control and nested scopes
589
590 @table @strong
591 @item Directive:
592 @code{.stabn}
593 @item Types:
594 @code{N_SLINE}, @code{N_LBRAC}, @code{N_RBRAC} (cont.)
595 @end table
596
597 Consider the body of @code{main}, from @file{example2.c}. It shows more
598 about how @code{N_SLINE}, @code{N_RBRAC}, and @code{N_LBRAC} stabs are used.
599
600 @example
601 20 @{
602 21 static float s_flap;
603 22 int times;
604 23 for (times=0; times < s_g_repeat; times++)@{
605 24 int inner;
606 25 printf ("Hello world\n");
607 26 @}
608 27 @};
609 @end example
610
611 Here we have a single source line, the @samp{for} line, that generates
612 non-linear flow of control, and non-contiguous code. In this case, an
613 @code{N_SLINE} stab with the same line number proceeds each block of
614 non-contiguous code generated from the same source line.
615
616 The example also shows nested scopes. The @code{N_LBRAC} and
617 @code{N_LBRAC} stabs that describe block structure are nested in the
618 same order as the corresponding code blocks, those of the for loop
619 inside those for the body of main.
620
621 @noindent
622 This is the label for the @code{N_LBRAC} (left brace) stab marking the
623 start of @code{main}.
624
625 @example
626 57 LBB2:
627 @end example
628
629 @noindent
630 In the first code range for C source line 23, the @code{for} loop
631 initialize and test, @code{N_SLINE} (68) records the line number:
632
633 @example
634 .stabn N_SLINE, NIL,
635 @var{line},
636 @var{address}
637
638 58 .stabn 68,0,23,LM2
639 59 LM2:
640 60 st %g0,[%fp-20]
641 61 L2:
642 62 sethi %hi(_s_g_repeat),%o0
643 63 ld [%fp-20],%o1
644 64 ld [%o0+%lo(_s_g_repeat)],%o0
645 65 cmp %o1,%o0
646 66 bge L3
647 67 nop
648
649 @exdent label for the @code{N_LBRAC} (start block) marking the start of @code{for} loop
650
651 68 LBB3:
652 69 .stabn 68,0,25,LM3
653 70 LM3:
654 71 sethi %hi(LC0),%o1
655 72 or %o1,%lo(LC0),%o0
656 73 call _printf,0
657 74 nop
658 75 .stabn 68,0,26,LM4
659 76 LM4:
660
661 @exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
662
663 77 LBE3:
664 @end example
665
666 @noindent
667 Now we come to the second code range for source line 23, the @code{for}
668 loop increment and return. Once again, @code{N_SLINE} (68) records the
669 source line number:
670
671 @example
672 .stabn, N_SLINE, NIL,
673 @var{line},
674 @var{address}
675
676 78 .stabn 68,0,23,LM5
677 79 LM5:
678 80 L4:
679 81 ld [%fp-20],%o0
680 82 add %o0,1,%o1
681 83 st %o1,[%fp-20]
682 84 b,a L2
683 85 L3:
684 86 .stabn 68,0,27,LM6
685 87 LM6:
686
687 @exdent label for the @code{N_RBRAC} (end block) stab marking the end of the @code{for} loop
688
689 88 LBE2:
690 89 .stabn 68,0,27,LM7
691 90 LM7:
692 91 L1:
693 92 ret
694 93 restore
695 94 .stabs "main:F1",36,0,0,_main
696 95 .stabs "argc:p1",160,0,0,68
697 96 .stabs "argv:p20=*21=*2",160,0,0,72
698 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
699 98 .stabs "times:1",128,0,0,-20
700 @end example
701
702 @noindent
703 Here is an illustration of stabs describing nested scopes. The scope
704 nesting is reflected in the nested bracketing stabs (@code{N_LBRAC},
705 192, appears here).
706
707 @example
708 .stabn N_LBRAC,NIL,NIL,
709 @var{block-start-address}
710
711 99 .stabn 192,0,0,LBB2 ## begin proc label
712 100 .stabs "inner:1",128,0,0,-24
713 101 .stabn 192,0,0,LBB3 ## begin for label
714 @end example
715
716 @noindent
717 @code{N_RBRAC} (224), ``right brace'' ends a lexical block (scope).
718
719 @example
720 .stabn N_RBRAC,NIL,NIL,
721 @var{block-end-address}
722
723 102 .stabn 224,0,0,LBE3 ## end for label
724 103 .stabn 224,0,0,LBE2 ## end proc label
725 @end example
726
727 @node Variables
728 @chapter Variables
729
730 @menu
731 * Automatic variables:: locally scoped
732 * Global Variables::
733 * Register variables::
734 * Initialized statics::
735 * Un-initialized statics::
736 * Parameters::
737 @end menu
738
739 @node Automatic variables
740 @section Locally scoped automatic variables
741
742 @table @strong
743 @item Directive:
744 @code{.stabs}
745 @item Type:
746 @code{N_LSYM}
747 @item Symbol Descriptor:
748 none
749 @end table
750
751
752 In addition to describing types, the @code{N_LSYM} stab type also
753 describes locally scoped automatic variables. Refer again to the body
754 of @code{main} in @file{example2.c}. It allocates two automatic
755 variables: @samp{times} is scoped to the body of @code{main}, and
756 @samp{inner} is scoped to the body of the @code{for} loop.
757 @samp{s_flap} is locally scoped but not automatic, and will be discussed
758 later.
759
760 @example
761 20 @{
762 21 static float s_flap;
763 22 int times;
764 23 for (times=0; times < s_g_repeat; times++)@{
765 24 int inner;
766 25 printf ("Hello world\n");
767 26 @}
768 27 @};
769 @end example
770
771 The @code{N_LSYM} stab for an automatic variable is located just before the
772 @code{N_LBRAC} stab describing the open brace of the block to which it is
773 scoped.
774
775 @example
776 @exdent @code{N_LSYM} (128): automatic variable, scoped locally to @code{main}
777
778 .stabs "@var{name}:
779 @var{type-ref}",
780 N_LSYM, NIL, NIL,
781 @var{frame-pointer-offset}
782
783 98 .stabs "times:1",128,0,0,-20
784 99 .stabn 192,0,0,LBB2 ## begin `main' N_LBRAC
785
786 @exdent @code{N_LSYM} (128): automatic variable, scoped locally to the @code{for} loop
787
788 .stabs "@var{name}:
789 @var{type-ref}",
790 N_LSYM, NIL, NIL,
791 @var{frame-pointer-offset}
792
793 100 .stabs "inner:1",128,0,0,-24
794 101 .stabn 192,0,0,LBB3 ## begin `for' loop N_LBRAC
795 @end example
796
797 Since the character in the string field following the colon is not a
798 letter, there is no symbol descriptor. This means that the stab
799 describes a local variable, and that the number after the colon is a
800 type reference. In this case it a a reference to the basic type @code{int}.
801 Notice also that the frame pointer offset is negative number for
802 automatic variables.
803
804
805 @node Global Variables
806 @section Global Variables
807
808 @table @strong
809 @item Directive:
810 @code{.stabs}
811 @item Type:
812 @code{N_GSYM}
813 @item Symbol Descriptor:
814 @code{G}
815 @end table
816
817 Global variables are represented by the @code{N_GSYM} stab type. The symbol
818 descriptor, following the colon in the string field, is @samp{G}. Following
819 the @samp{G} is a type reference or type definition. In this example it is a
820 type reference to the basic C type, @code{char}. The first source line in
821 @file{example2.c},
822
823 @example
824 1 char g_foo = 'c';
825 @end example
826
827 @noindent
828 yields the following stab. The stab immediately precedes the code that
829 allocates storage for the variable it describes.
830
831 @example
832 @exdent @code{N_GSYM} (32): global symbol
833
834 .stabs "@var{name}:
835 @var{descriptor}
836 @var{type-ref}",
837 N_GSYM, NIL, NIL, NIL
838
839 21 .stabs "g_foo:G2",32,0,0,0
840 22 .global _g_foo
841 23 .data
842 24 _g_foo:
843 25 .byte 99
844 @end example
845
846 The address of the variable represented by the @code{N_GSYM} is not contained
847 in the @code{N_GSYM} stab. The debugger gets this information from the
848 external symbol for the global variable.
849
850 @node Register variables
851 @section Global register variables
852
853 @table @strong
854 @item Directive:
855 @code{.stabs}
856 @item Type:
857 @code{N_RSYM}
858 @item Symbol Descriptor:
859 @code{r}
860 @end table
861
862 The following source line defines a global variable, @code{g_bar}, which is
863 explicitly allocated in global register @code{%g5}.
864
865 @example
866 2 register int g_bar asm ("%g5");
867 @end example
868
869 Register variables have their own stab type, @code{N_RSYM}, and their own
870 symbol descriptor, @code{r}. The stab's value field contains the number of
871 the register where the variable data will be stored. Since the
872 variable was not initialized in this compilation unit, the stab is
873 emited at the end of the object file, with the stabs for other
874 uninitialized globals (@code{bcc}).
875
876 @example
877 @exdent @code{N_RSYM} (64): register variable
878
879 .stabs "@var{name}:
880 @var{descriptor}
881 @var{type-ref}",
882 N_RSYM, NIL, NIL,
883 @var{register}
884
885 133 .stabs "g_bar:r1",64,0,0,5
886 @end example
887
888
889 @node Initialized statics
890 @section Initialized static variables
891
892 @table @strong
893 @item Directive:
894 @code{.stabs}
895 @item Type:
896 @code{N_STSYM}
897 @item Symbol Descriptors:
898 @code{S} (file scope), @code{V} (procedure scope)
899 @end table
900
901 Initialized static variables are represented by the @code{N_STSYM} stab
902 type. The symbol descriptor part of the string field shows if the
903 variable is file scope static (@samp{S}) or procedure scope static
904 (@samp{V}). The source line
905
906 @example
907 3 static int s_g_repeat = 2;
908 @end example
909
910 @noindent
911 yields the following code. The stab is located immediately preceding
912 the storage for the variable it represents. Since the variable in
913 this example is file scope static the symbol descriptor is @samp{S}.
914
915 @example
916 @exdent @code{N_STSYM} (38): initialized static variable (data seg w/internal linkage)
917
918 .stabs "@var{name}:
919 @var{descriptor}
920 @var{type-ref}",
921 N_STSYM,NIL,NIL,
922 @var{address}
923
924 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
925 27 .align 4
926 28 _s_g_repeat:
927 29 .word 2
928 @end example
929
930
931 @node Un-initialized statics
932 @section Un-initialized static variables
933
934 @table @strong
935 @item Directive:
936 @code{.stabs}
937 @item Type:
938 @code{N_LCSYM}
939 @item Symbol Descriptors:
940 @code{S} (file scope), @code{V} (procedure scope)
941 @end table
942
943 Un-initialized static variables are represented by the @code{N_LCSYM}
944 stab type. The symbol descriptor part of the string shows if the
945 variable is file scope static (@samp{S}) or procedure scope static
946 (@samp{V}). In this example it is procedure scope static. The source
947 line allocating @code{s_flap} immediately follows the open brace for the
948 procedure @code{main}.
949
950 @example
951 20 @{
952 21 static float s_flap;
953 @end example
954
955 The code that reserves storage for the variable @code{s_flap} precedes the
956 body of body of @code{main}.
957
958 @example
959 39 .reserve _s_flap.0,4,"bss",4
960 @end example
961
962 But since @code{s_flap} is scoped locally to @code{main}, its stab is
963 located with the other stabs representing symbols local to @code{main}.
964 The stab for @code{s_flap} is located just before the @code{N_LBRAC} for
965 @code{main}.
966
967 @example
968 @exdent @code{N_LCSYM} (40): uninitialized static var (BSS seg w/internal linkage)
969
970 .stabs "@var{name}:
971 @var{descriptor}
972 @var{type-ref}",
973 N_LCSYM, NIL, NIL,
974 @var{address}
975
976 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
977 98 .stabs "times:1",128,0,0,-20
978 99 .stabn 192,0,0,LBB2 # N_LBRAC for main.
979 @end example
980
981 @c ............................................................
982
983 @node Parameters
984 @section Parameters
985
986 @table @strong
987 @item Directive:
988 @code{.stabs}
989 @item Type:
990 @code{N_PSYM}
991 @item Symbol Descriptor:
992 @code{p}
993 @end table
994
995 Procedure parameters are represented by the N_PSYM stab type. The
996 following source lines show the parameters of the main routine.
997
998 @example
999 17 main (argc, argv)
1000 18 int argc;
1001 19 char* argv[];
1002 20 @{
1003 @end example
1004
1005 The N_PSYM stabs describing parameters to a function directly follow
1006 the N_FUN stab that represents the procedure itself. The N_FUN stab
1007 immediately follows the code of the procedure it describes. Following
1008 the N_PSYM parameter stabs are any N_LSYM stabs representing local
1009 variables.
1010
1011 @example
1012 @exdent <36> N_FUN - describing the procedure main
1013
1014 94 .stabs "main:F1",36,0,0,_main
1015
1016 @exdent <160> N_PSYM - parameters
1017 @exdent .stabs "name:sym_desc(value_param)type_ref(int)", N_PSYM,
1018 @exdent NIL, NIL, frame_ptr_offset
1019
1020 95 .stabs "argc:p1",160,0,0,68
1021
1022 @exdent <160> N_PSYM - parameter
1023 @exdent .stabs "name:sym_desc(value_param)type_def(20)=ptr_to type_def(21)=
1024 @exdent ptr_to type_ref(char)
1025
1026 96 .stabs "argv:p20=*21=*2",160,0,0,72
1027 @end example
1028
1029 The type definition of argv is interesting because it defines two new
1030 types in terms of an existing one. The ``array'' argv is really a
1031 pointer, according to C language rules, since it is declared as a
1032 parameter. Its element type is character pointers. Thus the type of
1033 argv is ptr to ptr to char. The stab for argv contains nested
1034 type_definitions. Type 21 is ptr to type 2 (char) and argv (type 20)
1035 is ptr to type 21.
1036
1037 @node Aggregate Types
1038 @chapter Aggregate Types
1039
1040 Now let's look at some variable definitions involving complex types.
1041 This involves understanding better how types are described. In the
1042 examples so far types have been described as references to previously
1043 defined types or defined in terms of subranges of or pointers to
1044 previously defined types. The section that follows will talk about
1045 the various other type descriptors that may follow the = sign in a
1046 type definition.
1047
1048 @menu
1049 * Arrays::
1050 * Enumerations::
1051 * Structure tags::
1052 * Typedefs::
1053 * Unions::
1054 * Function types::
1055 @end menu
1056
1057 @node Arrays
1058 @section Array types
1059
1060 @table @strong
1061 @item Directive:
1062 @code{.stabs}
1063 @item Types:
1064 @code{N_GSYM}, @code{N_LSYM}
1065 @item Symbol Descriptor:
1066 @code{T}
1067 @item Type Descriptor:
1068 @code{a}
1069 @end table
1070
1071 As an example of an array type consider the global variable below.
1072
1073 @example
1074 15 char char_vec[3] = @{'a','b','c'@};
1075 @end example
1076
1077 Since the array is a global variable, it is described by the N_GSYM
1078 stab type. The symbol descriptor G, following the colon in stab's
1079 string field, also says the array is a global variable. Following the
1080 G is a definition for type (19) as shown by the equals sign after the
1081 type number.
1082
1083 After the equals sign is a type descriptor, a, which says that the type
1084 being defined is an array. Following the type descriptor for an array
1085 is the type of the index, a semicolon, and the type of the array elements.
1086
1087 The type of the index is often a range type, expressed as the letter r
1088 and some parameters. It defines the size of the array. In in the
1089 example below, the range @code{r1;0;2;} defines an index type which is
1090 a subrange of type 1 (integer), with a lower bound of 0 and an upper
1091 bound of 2. This defines the valid range of subscripts of a
1092 three-element C array.
1093
1094 The array definition above generates the assembly language that
1095 follows.
1096
1097 @example
1098 @exdent <32> N_GSYM - global variable
1099 @exdent .stabs "name:sym_desc(global)type_def(19)=type_desc(array)
1100 @exdent index_type_ref(range of int from 0 to 2);element_type_ref(char)";
1101 @exdent N_GSYM, NIL, NIL, NIL
1102
1103 32 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
1104 33 .global _char_vec
1105 34 .align 4
1106 35 _char_vec:
1107 36 .byte 97
1108 37 .byte 98
1109 38 .byte 99
1110 @end example
1111
1112 @node Enumerations
1113 @section Enumerations
1114
1115 @table @strong
1116 @item Directive:
1117 @code{.stabs}
1118 @item Type:
1119 @code{N_LSYM}
1120 @item Symbol Descriptor:
1121 @code{T}
1122 @item Type Descriptor:
1123 @code{e}
1124 @end table
1125
1126 The source line below declares an enumeration type. It is defined at
1127 file scope between the bodies of main and s_proc in example2.c.
1128 Because the N_LSYM is located after the N_RBRAC that marks the end of
1129 the previous procedure's block scope, and before the N_FUN that marks
1130 the beginning of the next procedure's block scope, the N_LSYM does not
1131 describe a block local symbol, but a file local one. The source line:
1132
1133 @example
1134 29 enum e_places @{first,second=3,last@};
1135 @end example
1136
1137 @noindent
1138 generates the following stab, located just after the N_RBRAC (close
1139 brace stab) for main. The type definition is in an N_LSYM stab
1140 because type definitions are file scope not global scope.
1141
1142 @display
1143 <128> N_LSYM - local symbol
1144 .stab "name:sym_dec(type)type_def(22)=sym_desc(enum)
1145 enum_name:value(0),enum_name:value(3),enum_name:value(4),;",
1146 N_LSYM, NIL, NIL, NIL
1147 @end display
1148
1149 @example
1150 104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
1151 @end example
1152
1153 The symbol descriptor (T) says that the stab describes a structure,
1154 enumeration, or type tag. The type descriptor e, following the 22= of
1155 the type definition narrows it down to an enumeration type. Following
1156 the e is a list of the elements of the enumeration. The format is
1157 name:value,. The list of elements ends with a ;.
1158
1159 @node Structure tags
1160 @section Structure Tags
1161
1162 @table @strong
1163 @item Directive:
1164 @code{.stabs}
1165 @item Type:
1166 @code{N_LSYM}
1167 @item Symbol Descriptor:
1168 @code{T}
1169 @item Type Descriptor:
1170 @code{s}
1171 @end table
1172
1173 The following source code declares a structure tag and defines an
1174 instance of the structure in global scope. Then a typedef equates the
1175 structure tag with a new type. A seperate stab is generated for the
1176 structure tag, the structure typedef, and the structure instance. The
1177 stabs for the tag and the typedef are emited when the definitions are
1178 encountered. Since the structure elements are not initialized, the
1179 stab and code for the structure variable itself is located at the end
1180 of the program in .common.
1181
1182 @example
1183 6 struct s_tag @{
1184 7 int s_int;
1185 8 float s_float;
1186 9 char s_char_vec[8];
1187 10 struct s_tag* s_next;
1188 11 @} g_an_s;
1189 12
1190 13 typedef struct s_tag s_typedef;
1191 @end example
1192
1193 The structure tag is an N_LSYM stab type because, like the enum, the
1194 symbol is file scope. Like the enum, the symbol descriptor is T, for
1195 enumeration, struct or tag type. The symbol descriptor s following
1196 the 16= of the type definition narrows the symbol type to struct.
1197
1198 Following the struct symbol descriptor is the number of bytes the
1199 struct occupies, followed by a description of each structure element.
1200 The structure element descriptions are of the form name:type, bit
1201 offset from the start of the struct, and number of bits in the
1202 element.
1203
1204
1205 @example
1206 <128> N_LSYM - type definition
1207 .stabs "name:sym_desc(struct tag) Type_def(16)=type_desc(struct type)
1208 struct_bytes
1209 elem_name:type_ref(int),bit_offset,field_bits;
1210 elem_name:type_ref(float),bit_offset,field_bits;
1211 elem_name:type_def(17)=type_desc(array)
1212 index_type(range of int from 0 to 7);
1213 element_type(char),bit_offset,field_bits;;",
1214 N_LSYM,NIL,NIL,NIL
1215
1216 30 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;
1217 s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
1218 @end example
1219
1220 In this example, two of the structure elements are previously defined
1221 types. For these, the type following the name: part of the element
1222 description is a simple type reference. The other two structure
1223 elements are new types. In this case there is a type definition
1224 embedded after the name:. The type definition for the array element
1225 looks just like a type definition for a standalone array. The s_next
1226 field is a pointer to the same kind of structure that the field is an
1227 element of. So the definition of structure type 16 contains an type
1228 definition for an element which is a pointer to type 16.
1229
1230 @node Typedefs
1231 @section Typedefs
1232
1233 @table @strong
1234 @item Directive:
1235 @code{.stabs}
1236 @item Type:
1237 @code{N_LSYM}
1238 @item Symbol Descriptor:
1239 @code{t}
1240 @end table
1241
1242 Here is the stab for the typedef equating the structure tag with a
1243 type.
1244
1245 @display
1246 <128> N_LSYM - type definition
1247 .stabs "name:sym_desc(type name)type_ref(struct_tag)",N_LSYM,NIL,NIL,NIL
1248 @end display
1249
1250 @example
1251 31 .stabs "s_typedef:t16",128,0,0,0
1252 @end example
1253
1254 And here is the code generated for the structure variable.
1255
1256 @display
1257 <32> N_GSYM - global symbol
1258 .stabs "name:sym_desc(global)type_ref(struct_tag)",N_GSYM,NIL,NIL,NIL
1259 @end display
1260
1261 @example
1262 136 .stabs "g_an_s:G16",32,0,0,0
1263 137 .common _g_an_s,20,"bss"
1264 @end example
1265
1266 Notice that the structure tag has the same type number as the typedef
1267 for the structure tag. It is impossible to distinguish between a
1268 variable of the struct type and one of its typedef by looking at the
1269 debugging information.
1270
1271
1272 @node Unions
1273 @section Unions
1274
1275 @table @strong
1276 @item Directive:
1277 @code{.stabs}
1278 @item Type:
1279 @code{N_LSYM}
1280 @item Symbol Descriptor:
1281 @code{T}
1282 @item Type Descriptor:
1283 @code{u}
1284 @end table
1285
1286 Next let's look at unions. In example2 this union type is declared
1287 locally to a procedure and an instance of the union is defined.
1288
1289 @example
1290 36 union u_tag @{
1291 37 int u_int;
1292 38 float u_float;
1293 39 char* u_char;
1294 40 @} an_u;
1295 @end example
1296
1297 This code generates a stab for the union tag and a stab for the union
1298 variable. Both use the N_LSYM stab type. Since the union variable is
1299 scoped locally to the procedure in which it is defined, its stab is
1300 located immediately preceding the N_LBRAC for the procedure's block
1301 start.
1302
1303 The stab for the union tag, however is located preceding the code for
1304 the procedure in which it is defined. The stab type is N_LSYM. This
1305 would seem to imply that the union type is file scope, like the struct
1306 type s_tag. This is not true. The contents and position of the stab
1307 for u_type do not convey any infomation about its procedure local
1308 scope.
1309
1310 @display
1311 <128> N_LSYM - type
1312 .stabs "name:sym_desc(union tag)type_def(22)=type_desc(union)
1313 byte_size(4)
1314 elem_name:type_ref(int),bit_offset(0),bit_size(32);
1315 elem_name:type_ref(float),bit_offset(0),bit_size(32);
1316 elem_name:type_ref(ptr to char),bit_offset(0),bit_size(32);;"
1317 N_LSYM, NIL, NIL, NIL
1318 @end display
1319
1320 @smallexample
1321 105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
1322 128,0,0,0
1323 @end smallexample
1324
1325 The symbol descriptor, T, following the name: means that the stab
1326 describes an enumeration struct or type tag. The type descriptor u,
1327 following the 23= of the type definition, narrows it down to a union
1328 type definition. Following the u is the number of bytes in the union.
1329 After that is a list of union element descriptions. Their format is
1330 name:type, bit offset into the union, and number of bytes for the
1331 element;.
1332
1333 The stab for the union variable follows. Notice that the frame
1334 pointer offset for local variables is negative.
1335
1336 @display
1337 <128> N_LSYM - local variable (with no symbol descriptor)
1338 .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset
1339 @end display
1340
1341 @example
1342 130 .stabs "an_u:23",128,0,0,-20
1343 @end example
1344
1345 @node Function types
1346 @section Function types
1347
1348 @display
1349 type descriptor f
1350 @end display
1351
1352 The last type descriptor in C which remains to be described is used
1353 for function types. Consider the following source line defining a
1354 global function pointer.
1355
1356 @example
1357 4 int (*g_pf)();
1358 @end example
1359
1360 It generates the following code. Since the variable is not
1361 initialized, the code is located in the common area at the end of the
1362 file.
1363
1364 @display
1365 <32> N_GSYM - global variable
1366 .stabs "name:sym_desc(global)type_def(24)=ptr_to(25)=
1367 type_def(func)type_ref(int)
1368 @end display
1369
1370 @example
1371 134 .stabs "g_pf:G24=*25=f1",32,0,0,0
1372 135 .common _g_pf,4,"bss"
1373 @end example
1374
1375 Since the variable is global, the stab type is N_GSYM and the symbol
1376 descriptor is G. The variable defines a new type, 24, which is a
1377 pointer to another new type, 25, which is defined as a function
1378 returning int.
1379
1380 @node Symbol tables
1381 @chapter Symbol information in symbol tables
1382
1383 This section examines more closely the format of symbol table entries
1384 and how stab assembler directives map to them. It also describes what
1385 transformations the assembler and linker make on data from stabs.
1386
1387 Each time the assembler encounters a stab in its input file it puts
1388 each field of the stab into corresponding fields in a symbol table
1389 entry of its output file. If the stab contains a string field, the
1390 symbol table entry for that stab points to a string table entry
1391 containing the string data from the stab. Assembler labels become
1392 relocatable addresses. Symbol table entries in a.out have the format:
1393
1394 @example
1395 struct internal_nlist @{
1396 unsigned long n_strx; /* index into string table of name */
1397 unsigned char n_type; /* type of symbol */
1398 unsigned char n_other; /* misc info (usually empty) */
1399 unsigned short n_desc; /* description field */
1400 bfd_vma n_value; /* value of symbol */
1401 @};
1402 @end example
1403
1404 For .stabs directives, the n_strx field holds the character offset
1405 from the start of the string table to the string table entry
1406 containing the "string" field. For other classes of stabs (.stabn and
1407 .stabd) this field is null.
1408
1409 Symbol table entries with n_type fields containing a value greater or
1410 equal to 0x20 originated as stabs generated by the compiler (with one
1411 random exception). Those with n_type values less than 0x20 were
1412 placed in the symbol table of the executable by the assembler or the
1413 linker.
1414
1415 The linker concatenates object files and does fixups of externally
1416 defined symbols. You can see the transformations made on stab data by
1417 the assembler and linker by examining the symbol table after each pass
1418 of the build, first the assemble and then the link.
1419
1420 To do this use nm with the -ap options. This dumps the symbol table,
1421 including debugging information, unsorted. For stab entries the
1422 columns are: value, other, desc, type, string. For assembler and
1423 linker symbols, the columns are: value, type, string.
1424
1425 There are a few important things to notice about symbol tables. Where
1426 the value field of a stab contains a frame pointer offset, or a
1427 register number, that value is unchanged by the rest of the build.
1428
1429 Where the value field of a stab contains an assembly language label,
1430 it is transformed by each build step. The assembler turns it into a
1431 relocatable address and the linker turns it into an absolute address.
1432 This source line defines a static variable at file scope:
1433
1434 @example
1435 3 static int s_g_repeat
1436 @end example
1437
1438 @noindent
1439 The following stab describes the symbol.
1440
1441 @example
1442 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
1443 @end example
1444
1445 @noindent
1446 The assembler transforms the stab into this symbol table entry in the
1447 @file{.o} file. The location is expressed as a data segment offset.
1448
1449 @example
1450 21 00000084 - 00 0000 STSYM s_g_repeat:S1
1451 @end example
1452
1453 @noindent
1454 in the symbol table entry from the executable, the linker has made the
1455 relocatable address absolute.
1456
1457 @example
1458 22 0000e00c - 00 0000 STSYM s_g_repeat:S1
1459 @end example
1460
1461 Stabs for global variables do not contain location information. In
1462 this case the debugger finds location information in the assembler or
1463 linker symbol table entry describing the variable. The source line:
1464
1465 @example
1466 1 char g_foo = 'c';
1467 @end example
1468
1469 @noindent
1470 generates the stab:
1471
1472 @example
1473 21 .stabs "g_foo:G2",32,0,0,0
1474 @end example
1475
1476 The variable is represented by the following two symbol table entries
1477 in the object file. The first one originated as a stab. The second
1478 one is an external symbol. The upper case D signifies that the n_type
1479 field of the symbol table contains 7, N_DATA with local linkage (see
1480 Table B). The value field following the file's line number is empty
1481 for the stab entry. For the linker symbol it contains the
1482 rellocatable address corresponding to the variable.
1483
1484 @example
1485 19 00000000 - 00 0000 GSYM g_foo:G2
1486 20 00000080 D _g_foo
1487 @end example
1488
1489 @noindent
1490 These entries as transformed by the linker. The linker symbol table
1491 entry now holds an absolute address.
1492
1493 @example
1494 21 00000000 - 00 0000 GSYM g_foo:G2
1495 @dots{}
1496 215 0000e008 D _g_foo
1497 @end example
1498
1499 @node GNU Cplusplus stabs
1500 @chapter GNU C++ stabs
1501
1502 @menu
1503 * Basic Cplusplus types::
1504 * Simple classes::
1505 * Class instance::
1506 * Methods:: Method definition
1507 * Protections::
1508 * Method Modifiers:: (const, volatile, const volatile)
1509 * Virtual Methods::
1510 * Inheritence::
1511 * Virtual Base Classes::
1512 * Static Members::
1513 @end menu
1514
1515
1516 @subsection Symbol descriptors added for C++ descriptions:
1517
1518 @display
1519 P - register parameter.
1520 @end display
1521
1522 @subsection type descriptors added for C++ descriptions
1523
1524 @table @code
1525 @item #
1526 method type (two ## if minimal debug)
1527
1528 @item xs
1529 cross-reference
1530 @end table
1531
1532
1533 @node Basic Cplusplus types
1534 @section Basic types for C++
1535
1536 << the examples that follow are based on a01.C >>
1537
1538
1539 C++ adds two more builtin types to the set defined for C. These are
1540 the unknown type and the vtable record type. The unknown type, type
1541 16, is defined in terms of itself like the void type.
1542
1543 The vtable record type, type 17, is defined as a structure type and
1544 then as a structure tag. The structure has four fields, delta, index,
1545 pfn, and delta2. pfn is the function pointer.
1546
1547 << In boilerplate $vtbl_ptr_type, what are the fields delta,
1548 index, and delta2 used for? >>
1549
1550 This basic type is present in all C++ programs even if there are no
1551 virtual methods defined.
1552
1553 @display
1554 .stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8)
1555 elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16);
1556 elem_name(index):type_ref(short int),bit_offset(16),field_bits(16);
1557 elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void),
1558 bit_offset(32),field_bits(32);
1559 elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;"
1560 N_LSYM, NIL, NIL
1561 @end display
1562
1563 @smallexample
1564 .stabs "$vtbl_ptr_type:t17=s8
1565 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;"
1566 ,128,0,0,0
1567 @end smallexample
1568
1569 @display
1570 .stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL
1571 @end display
1572
1573 @example
1574 .stabs "$vtbl_ptr_type:T17",128,0,0,0
1575 @end example
1576
1577 @node Simple classes
1578 @section Simple class definition
1579
1580 The stabs describing C++ language features are an extension of the
1581 stabs describing C. Stabs representing C++ class types elaborate
1582 extensively on the stab format used to describe structure types in C.
1583 Stabs representing class type variables look just like stabs
1584 representing C language variables.
1585
1586 Consider the following very simple class definition.
1587
1588 @example
1589 class baseA @{
1590 public:
1591 int Adat;
1592 int Ameth(int in, char other);
1593 @};
1594 @end example
1595
1596 The class baseA is represented by two stabs. The first stab describes
1597 the class as a structure type. The second stab describes a structure
1598 tag of the class type. Both stabs are of stab type N_LSYM. Since the
1599 stab is not located between an N_FUN and a N_LBRAC stab this indicates
1600 that the class is defined at file scope. If it were, then the N_LSYM
1601 would signify a local variable.
1602
1603 A stab describing a C++ class type is similar in format to a stab
1604 describing a C struct, with each class member shown as a field in the
1605 structure. The part of the struct format describing fields is
1606 expanded to include extra information relevent to C++ class members.
1607 In addition, if the class has multiple base classes or virtual
1608 functions the struct format outside of the field parts is also
1609 augmented.
1610
1611 In this simple example the field part of the C++ class stab
1612 representing member data looks just like the field part of a C struct
1613 stab. The section on protections describes how its format is
1614 sometimes extended for member data.
1615
1616 The field part of a C++ class stab representing a member function
1617 differs substantially from the field part of a C struct stab. It
1618 still begins with `name:' but then goes on to define a new type number
1619 for the member function, describe its return type, its argument types,
1620 its protection level, any qualifiers applied to the method definition,
1621 and whether the method is virtual or not. If the method is virtual
1622 then the method description goes on to give the vtable index of the
1623 method, and the type number of the first base class defining the
1624 method.
1625
1626 When the field name is a method name it is followed by two colons
1627 rather than one. This is followed by a new type definition for the
1628 method. This is a number followed by an equal sign and then the
1629 symbol descriptor `##', indicating a method type. This is followed by
1630 a type reference showing the return type of the method and a
1631 semi-colon.
1632
1633 The format of an overloaded operator method name differs from that
1634 of other methods. It is "op$::XXXX." where XXXX is the operator name
1635 such as + or +=. The name ends with a period, and any characters except
1636 the period can occur in the XXXX string.
1637
1638 The next part of the method description represents the arguments to
1639 the method, preceeded by a colon and ending with a semi-colon. The
1640 types of the arguments are expressed in the same way argument types
1641 are expressed in C++ name mangling. In this example an int and a char
1642 map to `ic'.
1643
1644 This is followed by a number, a letter, and an asterisk or period,
1645 followed by another semicolon. The number indicates the protections
1646 that apply to the member function. Here the 2 means public. The
1647 letter encodes any qualifier applied to the method definition. In
1648 this case A means that it is a normal function definition. The dot
1649 shows that the method is not virtual. The sections that follow
1650 elaborate further on these fields and describe the additional
1651 information present for virtual methods.
1652
1653
1654 @display
1655 .stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
1656 field_name(Adat):type(int),bit_offset(0),field_bits(32);
1657
1658 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
1659 :arg_types(int char);
1660 protection(public)qualifier(normal)virtual(no);;"
1661 N_LSYM,NIL,NIL,NIL
1662 @end display
1663
1664 @smallexample
1665 .stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
1666
1667 .stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
1668
1669 .stabs "baseA:T20",128,0,0,0
1670 @end smallexample
1671
1672 @node Class instance
1673 @section Class instance
1674
1675 As shown above, describing even a simple C++ class definition is
1676 accomplished by massively extending the stab format used in C to
1677 describe structure types. However, once the class is defined, C stabs
1678 with no modifications can be used to describe class instances. The
1679 following source:
1680
1681 @example
1682 main () @{
1683 baseA AbaseA;
1684 @}
1685 @end example
1686
1687 @noindent
1688 yields the following stab describing the class instance. It looks no
1689 different from a standard C stab describing a local variable.
1690
1691 @display
1692 .stabs "name:type_ref(baseA)", N_LSYM, NIL, NIL, frame_ptr_offset
1693 @end display
1694
1695 @example
1696 .stabs "AbaseA:20",128,0,0,-20
1697 @end example
1698
1699 @node Methods
1700 @section Method defintion
1701
1702 The class definition shown above declares Ameth. The C++ source below
1703 defines Ameth:
1704
1705 @example
1706 int
1707 baseA::Ameth(int in, char other)
1708 @{
1709 return in;
1710 @};
1711 @end example
1712
1713
1714 This method definition yields three stabs following the code of the
1715 method. One stab describes the method itself and following two
1716 describe its parameters. Although there is only one formal argument
1717 all methods have an implicit argument which is the `this' pointer.
1718 The `this' pointer is a pointer to the object on which the method was
1719 called. Note that the method name is mangled to encode the class name
1720 and argument types. << Name mangling is not described by this
1721 document - Is there already such a doc? >>
1722
1723 @example
1724 .stabs "name:symbol_desriptor(global function)return_type(int)",
1725 N_FUN, NIL, NIL, code_addr_of_method_start
1726
1727 .stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic
1728 @end example
1729
1730 Here is the stab for the `this' pointer implicit argument. The name
1731 of the `this' pointer is always `this.' Type 19, the `this' pointer is
1732 defined as a pointer to type 20, baseA, but a stab defining baseA has
1733 not yet been emited. Since the compiler knows it will be emited
1734 shortly, here it just outputs a cross reference to the undefined
1735 symbol, by prefixing the symbol name with xs.
1736
1737 @example
1738 .stabs "name:sym_desc(register param)type_def(19)=
1739 type_desc(ptr to)type_ref(baseA)=
1740 type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number
1741
1742 .stabs "this:P19=*20=xsbaseA:",64,0,0,8
1743 @end example
1744
1745 The stab for the explicit integer argument looks just like a parameter
1746 to a C function. The last field of the stab is the offset from the
1747 argument pointer, which in most systems is the same as the frame
1748 pointer.
1749
1750 @example
1751 .stabs "name:sym_desc(value parameter)type_ref(int)",
1752 N_PSYM,NIL,NIL,offset_from_arg_ptr
1753
1754 .stabs "in:p1",160,0,0,72
1755 @end example
1756
1757 << The examples that follow are based on A1.C >>
1758
1759 @node Protections
1760 @section Protections
1761
1762
1763 In the simple class definition shown above all member data and
1764 functions were publicly accessable. The example that follows
1765 contrasts public, protected and privately accessable fields and shows
1766 how these protections are encoded in C++ stabs.
1767
1768 Protections for class member data are signified by two characters
1769 embeded in the stab defining the class type. These characters are
1770 located after the name: part of the string. /0 means private, /1
1771 means protected, and /2 means public. If these characters are omited
1772 this means that the member is public. The following C++ source:
1773
1774 @example
1775 class all_data @{
1776 private:
1777 int priv_dat;
1778 protected:
1779 char prot_dat;
1780 public:
1781 float pub_dat;
1782 @};
1783 @end example
1784
1785 @noindent
1786 generates the following stab to describe the class type all_data.
1787
1788 @display
1789 .stabs "class_name:sym_desc(type)type_def(19)=type_desc(struct)struct_bytes
1790 data_name:/protection(private)type_ref(int),bit_offset,num_bits;
1791 data_name:/protection(protected)type_ref(char),bit_offset,num_bits;
1792 data_name:(/num omited, private)type_ref(float),bit_offset,num_bits;;"
1793 N_LSYM,NIL,NIL,NIL
1794 @end display
1795
1796 @smallexample
1797 .stabs "all_data:t19=s12
1798 priv_dat:/01,0,32;prot_dat:/12,32,8;pub_dat:12,64,32;;",128,0,0,0
1799 @end smallexample
1800
1801 Protections for member functions are signified by one digit embeded in
1802 the field part of the stab describing the method. The digit is 0 if
1803 private, 1 if protected and 2 if public. Consider the C++ class
1804 definition below:
1805
1806 @example
1807 class all_methods @{
1808 private:
1809 int priv_meth(int in)@{return in;@};
1810 protected:
1811 char protMeth(char in)@{return in;@};
1812 public:
1813 float pubMeth(float in)@{return in;@};
1814 @};
1815 @end example
1816
1817 It generates the following stab. The digit in question is to the left
1818 of an `A' in each case. Notice also that in this case two symbol
1819 descriptors apply to the class name struct tag and struct type.
1820
1821 @display
1822 .stabs "class_name:sym_desc(struct tag&type)type_def(21)=
1823 sym_desc(struct)struct_bytes(1)
1824 meth_name::type_def(22)=sym_desc(method)returning(int);
1825 :args(int);protection(private)modifier(normal)virtual(no);
1826 meth_name::type_def(23)=sym_desc(method)returning(char);
1827 :args(char);protection(protected)modifier(normal)virual(no);
1828 meth_name::type_def(24)=sym_desc(method)returning(float);
1829 :args(float);protection(public)modifier(normal)virtual(no);;",
1830 N_LSYM,NIL,NIL,NIL
1831 @end display
1832
1833 @smallexample
1834 .stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
1835 pubMeth::24=##12;:f;2A.;;",128,0,0,0
1836 @end smallexample
1837
1838 @node Method Modifiers
1839 @section Method Modifiers (const, volatile, const volatile)
1840
1841 << based on a6.C >>
1842
1843 In the class example described above all the methods have the normal
1844 modifier. This method modifier information is located just after the
1845 protection information for the method. This field has four possible
1846 character values. Normal methods use A, const methods use B, volatile
1847 methods use C, and const volatile methods use D. Consider the class
1848 definition below:
1849
1850 @example
1851 class A @{
1852 public:
1853 int ConstMeth (int arg) const @{ return arg; @};
1854 char VolatileMeth (char arg) volatile @{ return arg; @};
1855 float ConstVolMeth (float arg) const volatile @{return arg; @};
1856 @};
1857 @end example
1858
1859 This class is described by the following stab:
1860
1861 @display
1862 .stabs "class(A):sym_desc(struct)type_def(20)=type_desc(struct)struct_bytes(1)
1863 meth_name(ConstMeth)::type_def(21)sym_desc(method)
1864 returning(int);:arg(int);protection(public)modifier(const)virtual(no);
1865 meth_name(VolatileMeth)::type_def(22)=sym_desc(method)
1866 returning(char);:arg(char);protection(public)modifier(volatile)virt(no)
1867 meth_name(ConstVolMeth)::type_def(23)=sym_desc(method)
1868 returning(float);:arg(float);protection(public)modifer(const volatile)
1869 virtual(no);;", @dots{}
1870 @end display
1871
1872 @example
1873 .stabs "A:T20=s1ConstMeth::21=##1;:i;2B.;VolatileMeth::22=##2;:c;2C.;
1874 ConstVolMeth::23=##12;:f;2D.;;",128,0,0,0
1875 @end example
1876
1877 @node Virtual Methods
1878 @section Virtual Methods
1879
1880 << The following examples are based on a4.C >>
1881
1882 The presence of virtual methods in a class definition adds additional
1883 data to the class description. The extra data is appended to the
1884 description of the virtual method and to the end of the class
1885 description. Consider the class definition below:
1886
1887 @example
1888 class A @{
1889 public:
1890 int Adat;
1891 virtual int A_virt (int arg) @{ return arg; @};
1892 @};
1893 @end example
1894
1895 This results in the stab below describing class A. It defines a new
1896 type (20) which is an 8 byte structure. The first field of the class
1897 struct is Adat, an integer, starting at structure offset 0 and
1898 occupying 32 bits.
1899
1900 The second field in the class struct is not explicitly defined by the
1901 C++ class definition but is implied by the fact that the class
1902 contains a virtual method. This field is the vtable pointer. The
1903 name of the vtable pointer field starts with $vf and continues with a
1904 type reference to the class it is part of. In this example the type
1905 reference for class A is 20 so the name of its vtable pointer field is
1906 $vf20, followed by the usual colon.
1907
1908 Next there is a type definition for the vtable pointer type (21).
1909 This is in turn defined as a pointer to another new type (22).
1910
1911 Type 22 is the vtable itself, which is defined as an array, indexed by
1912 a range of integers between 0 and 1, and whose elements are of type
1913 17. Type 17 was the vtable record type defined by the boilerplate C++
1914 type definitions, as shown earlier.
1915
1916 The bit offset of the vtable pointer field is 32. The number of bits
1917 in the field are not specified when the field is a vtable pointer.
1918
1919 Next is the method definition for the virtual member function A_virt.
1920 Its description starts out using the same format as the non-virtual
1921 member functions described above, except instead of a dot after the
1922 `A' there is an asterisk, indicating that the function is virtual.
1923 Since is is virtual some addition information is appended to the end
1924 of the method description.
1925
1926 The first number represents the vtable index of the method. This is a
1927 32 bit unsigned number with the high bit set, followed by a
1928 semi-colon.
1929
1930 The second number is a type reference to the first base class in the
1931 inheritence hierarchy defining the virtual member function. In this
1932 case the class stab describes a base class so the virtual function is
1933 not overriding any other definition of the method. Therefore the
1934 reference is to the type number of the class that the stab is
1935 describing (20).
1936
1937 This is followed by three semi-colons. One marks the end of the
1938 current sub-section, one marks the end of the method field, and the
1939 third marks the end of the struct definition.
1940
1941 For classes containing virtual functions the very last section of the
1942 string part of the stab holds a type reference to the first base
1943 class. This is preceeded by `~%' and followed by a final semi-colon.
1944
1945 @display
1946 .stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
1947 field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
1948 field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
1949 sym_desc(array)index_type_ref(range of int from 0 to 1);
1950 elem_type_ref(vtbl elem type),
1951 bit_offset(32);
1952 meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
1953 :arg_type(int),protection(public)normal(yes)virtual(yes)
1954 vtable_index(1);class_first_defining(A);;;~%first_base(A);",
1955 N_LSYM,NIL,NIL,NIL
1956 @end display
1957
1958 @example
1959 .stabs "A:t20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
1960 @end example
1961
1962 @node Inheritence
1963 @section Inheritence
1964
1965 Stabs describing C++ derived classes include additional sections that
1966 describe the inheritence hierarchy of the class. A derived class stab
1967 also encodes the number of base classes. For each base class it tells
1968 if the base class is virtual or not, and if the inheritence is private
1969 or public. It also gives the offset into the object of the portion of
1970 the object corresponding to each base class.
1971
1972 This additional information is embeded in the class stab following the
1973 number of bytes in the struct. First the number of base classes
1974 appears bracketed by an exclamation point and a comma.
1975
1976 Then for each base type there repeats a series: two digits, a number,
1977 a comma, another number, and a semi-colon.
1978
1979 The first of the two digits is 1 if the base class is virtual and 0 if
1980 not. The second digit is 2 if the derivation is public and 0 if not.
1981
1982 The number following the first two digits is the offset from the start
1983 of the object to the part of the object pertaining to the base class.
1984
1985 After the comma, the second number is a type_descriptor for the base
1986 type. Finally a semi-colon ends the series, which repeats for each
1987 base class.
1988
1989 The source below defines three base classes A, B, and C and the
1990 derived class D.
1991
1992
1993 @example
1994 class A @{
1995 public:
1996 int Adat;
1997 virtual int A_virt (int arg) @{ return arg; @};
1998 @};
1999
2000 class B @{
2001 public:
2002 int B_dat;
2003 virtual int B_virt (int arg) @{return arg; @};
2004 @};
2005
2006 class C @{
2007 public:
2008 int Cdat;
2009 virtual int C_virt (int arg) @{return arg; @};
2010 @};
2011
2012 class D : A, virtual B, public C @{
2013 public:
2014 int Ddat;
2015 virtual int A_virt (int arg ) @{ return arg+1; @};
2016 virtual int B_virt (int arg) @{ return arg+2; @};
2017 virtual int C_virt (int arg) @{ return arg+3; @};
2018 virtual int D_virt (int arg) @{ return arg; @};
2019 @};
2020 @end example
2021
2022 Class stabs similar to the ones described earlier are generated for
2023 each base class.
2024
2025 @c FIXME!!! the linebreaks in the following example probably make the
2026 @c examples literally unusable, but I don't know any other way to get
2027 @c them on the page.
2028 @smallexample
2029 .stabs "A:T20=s8Adat:1,0,32;$vf20:21=*22=ar1;0;1;17,32;
2030 A_virt::23=##1;:i;2A*-2147483647;20;;;~%20;",128,0,0,0
2031
2032 .stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;
2033 :i;2A*-2147483647;25;;;~%25;",128,0,0,0
2034
2035 .stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;
2036 :i;2A*-2147483647;28;;;~%28;",128,0,0,0
2037 @end smallexample
2038
2039 In the stab describing derived class D below, the information about
2040 the derivation of this class is encoded as follows.
2041
2042 @display
2043 .stabs "derived_class_name:symbol_descriptors(struct tag&type)=
2044 type_descriptor(struct)struct_bytes(32)!num_bases(3),
2045 base_virtual(no)inheritence_public(no)base_offset(0),
2046 base_class_type_ref(A);
2047 base_virtual(yes)inheritence_public(no)base_offset(NIL),
2048 base_class_type_ref(B);
2049 base_virtual(no)inheritence_public(yes)base_offset(64),
2050 base_class_type_ref(C); @dots{}
2051 @end display
2052
2053 @c FIXME! fake linebreaks.
2054 @smallexample
2055 .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:
2056 1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt:
2057 :32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;
2058 28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
2059 @end smallexample
2060
2061 @node Virtual Base Classes
2062 @section Virtual Base Classes
2063
2064 A derived class object consists of a concatination in memory of the
2065 data areas defined by each base class, starting with the leftmost and
2066 ending with the rightmost in the list of base classes. The exception
2067 to this rule is for virtual inheritence. In the example above, class
2068 D inherits virtually from base class B. This means that an instance
2069 of a D object will not contain it's own B part but merely a pointer to
2070 a B part, known as a virtual base pointer.
2071
2072 In a derived class stab, the base offset part of the derivation
2073 information, described above, shows how the base class parts are
2074 ordered. The base offset for a virtual base class is always given as
2075 0. Notice that the base offset for B is given as 0 even though B is
2076 not the first base class. The first base class A starts at offset 0.
2077
2078 The field information part of the stab for class D describes the field
2079 which is the pointer to the virtual base class B. The vbase pointer
2080 name is $vb followed by a type reference to the virtual base class.
2081 Since the type id for B in this example is 25, the vbase pointer name
2082 is $vb25.
2083
2084 @c FIXME!! fake linebreaks below
2085 @smallexample
2086 .stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,
2087 160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;
2088 2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt:
2089 :32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
2090 @end smallexample
2091
2092 Following the name and a semicolon is a type reference describing the
2093 type of the virtual base class pointer, in this case 24. Type 24 was
2094 defined earlier as the type of the B class `this` pointer. The
2095 `this' pointer for a class is a pointer to the class type.
2096
2097 @example
2098 .stabs "this:P24=*25=xsB:",64,0,0,8
2099 @end example
2100
2101 Finally the field offset part of the vbase pointer field description
2102 shows that the vbase pointer is the first field in the D object,
2103 before any data fields defined by the class. The layout of a D class
2104 object is a follows, Adat at 0, the vtable pointer for A at 32, Cdat
2105 at 64, the vtable pointer for C at 96, the virtual ase pointer for B
2106 at 128, and Ddat at 160.
2107
2108
2109 @node Static Members
2110 @section Static Members
2111
2112 The data area for a class is a concatenation of the space used by the
2113 data members of the class. If the class has virtual methods, a vtable
2114 pointer follows the class data. The field offset part of each field
2115 description in the class stab shows this ordering.
2116
2117 << How is this reflected in stabs? See Cygnus bug #677 for some info. >>
2118
2119 @node Example2.c
2120 @appendix Example2.c - source code for extended example
2121
2122 @example
2123 1 char g_foo = 'c';
2124 2 register int g_bar asm ("%g5");
2125 3 static int s_g_repeat = 2;
2126 4 int (*g_pf)();
2127 5
2128 6 struct s_tag @{
2129 7 int s_int;
2130 8 float s_float;
2131 9 char s_char_vec[8];
2132 10 struct s_tag* s_next;
2133 11 @} g_an_s;
2134 12
2135 13 typedef struct s_tag s_typedef;
2136 14
2137 15 char char_vec[3] = @{'a','b','c'@};
2138 16
2139 17 main (argc, argv)
2140 18 int argc;
2141 19 char* argv[];
2142 20 @{
2143 21 static float s_flap;
2144 22 int times;
2145 23 for (times=0; times < s_g_repeat; times++)@{
2146 24 int inner;
2147 25 printf ("Hello world\n");
2148 26 @}
2149 27 @};
2150 28
2151 29 enum e_places @{first,second=3,last@};
2152 30
2153 31 static s_proc (s_arg, s_ptr_arg, char_vec)
2154 32 s_typedef s_arg;
2155 33 s_typedef* s_ptr_arg;
2156 34 char* char_vec;
2157 35 @{
2158 36 union u_tag @{
2159 37 int u_int;
2160 38 float u_float;
2161 39 char* u_char;
2162 40 @} an_u;
2163 41 @}
2164 42
2165 43
2166 @end example
2167
2168 @node Example2.s
2169 @appendix Example2.s - assembly code for extended example
2170
2171 @example
2172 1 gcc2_compiled.:
2173 2 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
2174 3 .stabs "example2.c",100,0,0,Ltext0
2175 4 .text
2176 5 Ltext0:
2177 6 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
2178 7 .stabs "char:t2=r2;0;127;",128,0,0,0
2179 8 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
2180 9 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
2181 10 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
2182 11 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
2183 12 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
2184 13 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
2185 14 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
2186 15 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
2187 16 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
2188 17 .stabs "float:t12=r1;4;0;",128,0,0,0
2189 18 .stabs "double:t13=r1;8;0;",128,0,0,0
2190 19 .stabs "long double:t14=r1;8;0;",128,0,0,0
2191 20 .stabs "void:t15=15",128,0,0,0
2192 21 .stabs "g_foo:G2",32,0,0,0
2193 22 .global _g_foo
2194 23 .data
2195 24 _g_foo:
2196 25 .byte 99
2197 26 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
2198 27 .align 4
2199 28 _s_g_repeat:
2200 29 .word 2
2201 @c FIXME! fake linebreak in line 30
2202 30 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;s_char_vec:
2203 17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
2204 31 .stabs "s_typedef:t16",128,0,0,0
2205 32 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
2206 33 .global _char_vec
2207 34 .align 4
2208 35 _char_vec:
2209 36 .byte 97
2210 37 .byte 98
2211 38 .byte 99
2212 39 .reserve _s_flap.0,4,"bss",4
2213 40 .text
2214 41 .align 4
2215 42 LC0:
2216 43 .ascii "Hello world\12\0"
2217 44 .align 4
2218 45 .global _main
2219 46 .proc 1
2220 47 _main:
2221 48 .stabn 68,0,20,LM1
2222 49 LM1:
2223 50 !#PROLOGUE# 0
2224 51 save %sp,-144,%sp
2225 52 !#PROLOGUE# 1
2226 53 st %i0,[%fp+68]
2227 54 st %i1,[%fp+72]
2228 55 call ___main,0
2229 56 nop
2230 57 LBB2:
2231 58 .stabn 68,0,23,LM2
2232 59 LM2:
2233 60 st %g0,[%fp-20]
2234 61 L2:
2235 62 sethi %hi(_s_g_repeat),%o0
2236 63 ld [%fp-20],%o1
2237 64 ld [%o0+%lo(_s_g_repeat)],%o0
2238 65 cmp %o1,%o0
2239 66 bge L3
2240 67 nop
2241 68 LBB3:
2242 69 .stabn 68,0,25,LM3
2243 70 LM3:
2244 71 sethi %hi(LC0),%o1
2245 72 or %o1,%lo(LC0),%o0
2246 73 call _printf,0
2247 74 nop
2248 75 .stabn 68,0,26,LM4
2249 76 LM4:
2250 77 LBE3:
2251 78 .stabn 68,0,23,LM5
2252 79 LM5:
2253 80 L4:
2254 81 ld [%fp-20],%o0
2255 82 add %o0,1,%o1
2256 83 st %o1,[%fp-20]
2257 84 b,a L2
2258 85 L3:
2259 86 .stabn 68,0,27,LM6
2260 87 LM6:
2261 88 LBE2:
2262 89 .stabn 68,0,27,LM7
2263 90 LM7:
2264 91 L1:
2265 92 ret
2266 93 restore
2267 94 .stabs "main:F1",36,0,0,_main
2268 95 .stabs "argc:p1",160,0,0,68
2269 96 .stabs "argv:p20=*21=*2",160,0,0,72
2270 97 .stabs "s_flap:V12",40,0,0,_s_flap.0
2271 98 .stabs "times:1",128,0,0,-20
2272 99 .stabn 192,0,0,LBB2
2273 100 .stabs "inner:1",128,0,0,-24
2274 101 .stabn 192,0,0,LBB3
2275 102 .stabn 224,0,0,LBE3
2276 103 .stabn 224,0,0,LBE2
2277 104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
2278 @c FIXME: fake linebreak in line 105
2279 105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",
2280 128,0,0,0
2281 106 .align 4
2282 107 .proc 1
2283 108 _s_proc:
2284 109 .stabn 68,0,35,LM8
2285 110 LM8:
2286 111 !#PROLOGUE# 0
2287 112 save %sp,-120,%sp
2288 113 !#PROLOGUE# 1
2289 114 mov %i0,%o0
2290 115 st %i1,[%fp+72]
2291 116 st %i2,[%fp+76]
2292 117 LBB4:
2293 118 .stabn 68,0,41,LM9
2294 119 LM9:
2295 120 LBE4:
2296 121 .stabn 68,0,41,LM10
2297 122 LM10:
2298 123 L5:
2299 124 ret
2300 125 restore
2301 126 .stabs "s_proc:f1",36,0,0,_s_proc
2302 127 .stabs "s_arg:p16",160,0,0,0
2303 128 .stabs "s_ptr_arg:p18",160,0,0,72
2304 129 .stabs "char_vec:p21",160,0,0,76
2305 130 .stabs "an_u:23",128,0,0,-20
2306 131 .stabn 192,0,0,LBB4
2307 132 .stabn 224,0,0,LBE4
2308 133 .stabs "g_bar:r1",64,0,0,5
2309 134 .stabs "g_pf:G24=*25=f1",32,0,0,0
2310 135 .common _g_pf,4,"bss"
2311 136 .stabs "g_an_s:G16",32,0,0,0
2312 137 .common _g_an_s,20,"bss"
2313 @end example
2314
2315
2316 @node Quick reference
2317 @appendix Quick reference
2318
2319 @menu
2320 * Stab types:: Table A: Symbol types from stabs
2321 * Assembler types:: Table B: Symbol types from assembler and linker
2322 * Symbol descriptors:: Table C
2323 * Type Descriptors:: Table D
2324 @end menu
2325
2326 @node Stab types
2327 @section Table A: Symbol types from stabs
2328
2329 Table A lists stab types sorted by type number. Stab type numbers are
2330 32 and greater. This is the full list of stab numbers, including stab
2331 types that are used in languages other than C.
2332
2333 The #define names for these stab types are defined in:
2334 devo/include/aout/stab.def
2335
2336 @smallexample
2337 type type #define used to describe
2338 dec hex name source program feature
2339 ------------------------------------------------
2340 32 0x20 N_GYSM global symbol
2341 34 0X22 N_FNAME function name (for BSD Fortran)
2342 36 0x24 N_FUN function name or text segment variable for C
2343 38 0x26 N_STSYM static symbol (data segment w/internal linkage)
2344 40 0x28 N_LCSYM .lcomm symbol(BSS-seg variable w/internal linkage)
2345 42 0x2a N_MAIN Name of main routine (not used in C)
2346 48 0x30 N_PC global symbol (for Pascal)
2347 50 0x32 N_NSYMS number of symbols (according to Ultrix V4.0)
2348 52 0x34 N_NOMAP no DST map for sym (according to Ultrix V4.0)
2349 64 0x40 N_RSYM register variable
2350 66 0x42 N_M2C Modula-2 compilation unit
2351 68 0x44 N_SLINE line number in text segment
2352 70 0x46 N_DSLINE line number in data segment
2353
2354 72 0x48 N_BSLINE line number in bss segment
2355 72 0x48 N_BROWS Sun source code browser, path to .cb file
2356
2357 74 0x4a N_DEFD GNU Modula2 definition module dependency
2358
2359 80 0x50 N_EHDECL GNU C++ exception variable
2360 80 0x50 N_MOD2 Modula2 info "for imc" (according to Ultrix V4.0)
2361
2362 84 0x54 N_CATCH GNU C++ "catch" clause
2363 96 0x60 N_SSYM structure of union element
2364 100 0x64 N_SO path and name of source file
2365 128 0x80 N_LSYM automatic var in the stack
2366 (also used for type desc.)
2367 130 0x82 N_BINCL beginning of an include file (Sun only)
2368 132 0x84 N_SOL Name of sub-source (#include) file.
2369 160 0xa0 N_PSYM parameter variable
2370 162 0xa2 N_EINCL end of an include file
2371 164 0xa4 N_ENTRY alternate entry point
2372 192 0xc0 N_LBRAC beginning of a lexical block
2373 194 0xc2 N_EXCL place holder for a deleted include file
2374 196 0xc4 N_SCOPE modula2 scope information (Sun linker)
2375 224 0xe0 N_RBRAC end of a lexical block
2376 226 0xe2 N_BCOMM begin named common block
2377 228 0xe4 N_ECOMM end named common block
2378 232 0xe8 N_ECOML end common (local name)
2379
2380 << used on Gould systems for non-base registers syms >>
2381 240 0xf0 N_NBTEXT ??
2382 242 0xf2 N_NBDATA ??
2383 244 0xf4 N_NBBSS ??
2384 246 0xf6 N_NBSTS ??
2385 248 0xf8 N_NBLCS ??
2386 @end smallexample
2387
2388 @node Assembler types
2389 @section Table B: Symbol types from assembler and linker
2390
2391 Table B shows the types of symbol table entries that hold assembler
2392 and linker symbols.
2393
2394 The #define names for these n_types values are defined in
2395 /include/aout/aout64.h
2396
2397 @smallexample
2398 dec hex #define
2399 n_type n_type name used to describe
2400 ------------------------------------------
2401 1 0x0 N_UNDF undefined symbol
2402 2 0x2 N_ABS absolute symbol -- defined at a particular address
2403 3 0x3 extern " (vs. file scope)
2404 4 0x4 N_TEXT text symbol -- defined at offset in text segment
2405 5 0x5 extern " (vs. file scope)
2406 6 0x6 N_DATA data symbol -- defined at offset in data segment
2407 7 0x7 extern " (vs. file scope)
2408 8 0x8 N_BSS BSS symbol -- defined at offset in zero'd segment
2409 9 extern " (vs. file scope)
2410
2411 12 0x0C N_FN_SEQ func name for Sequent compilers (stab exception)
2412
2413 49 0x12 N_COMM common sym -- visable after shared lib dynamic link
2414 31 0x1f N_FN file name of a .o file
2415 @end smallexample
2416
2417 @node Symbol descriptors
2418 @section Table C: Symbol descriptors
2419
2420 @example
2421 descriptor meaning
2422 -------------------------------------------------
2423 (empty) local variable
2424 f local function
2425 F global function
2426 G global variable
2427 p value parameter
2428 r register variable
2429 S static global variable
2430 t type name
2431 T enumeration, struct or type tag
2432 V static local variable
2433 @end example
2434
2435 @node Type Descriptors
2436 @section Table D: Type Descriptors
2437
2438 @example
2439 descriptor meaning
2440 -------------------------------------
2441 (empty) type reference
2442 a array type
2443 e enumeration type
2444 f function type
2445 r range type
2446 s structure type
2447 u union specifications
2448 * pointer type
2449 @end example
2450
2451
2452 @node Expanded reference
2453 @appendix Expanded reference by stab type.
2454
2455 Format of an entry:
2456
2457 The first line is the symbol type expressed in decimal, hexadecimal,
2458 and as a #define (see devo/include/aout/stab.def).
2459
2460 The second line describes the language constructs the symbol type
2461 represents.
2462
2463 The third line is the stab format with the significant stab fields
2464 named and the rest NIL.
2465
2466 Subsequent lines expand upon the meaning and possible values for each
2467 significant stab field. # stands in for the type descriptor.
2468
2469 Finally, any further information.
2470
2471 @menu
2472 * N_GSYM:: Global variable
2473 * N_FNAME:: Function name (BSD Fortran)
2474 * N_FUN:: C Function name or text segment variable
2475 * N_STSYM:: Initialized static symbol
2476 * N_LCSYM:: Uninitialized static symbol
2477 * N_MAIN:: Name of main routine (not for C)
2478 * N_PC:: Pascal global symbol
2479 * N_NSYMS:: Number of symbols
2480 * N_NOMAP:: No DST map
2481 * N_RSYM:: Register variable
2482 * N_M2C:: Modula-2 compilation unit
2483 * N_SLINE:: Line number in text segment
2484 * N_DSLINE:: Line number in data segment
2485 * N_BSLINE:: Line number in bss segment
2486 * N_BROWS:: Path to .cb file for Sun source code browser
2487 * N_DEFD:: GNU Modula2 definition module dependency
2488 * N_EHDECL:: GNU C++ exception variable
2489 * N_MOD2:: Modula2 information "for imc"
2490 * N_CATCH:: GNU C++ "catch" clause
2491 * N_SSYM:: Structure or union element
2492 * N_SO:: Source file containing main
2493 * N_LSYM:: Automatic variable
2494 * N_BINCL:: Beginning of include file (Sun only)
2495 * N_SOL:: Name of include file
2496 * N_PSYM:: Parameter variable
2497 * N_EINCL:: End of include file
2498 * N_ENTRY:: Alternate entry point
2499 * N_LBRAC:: Beginning of lexical block
2500 * N_EXCL:: Deleted include file
2501 * N_SCOPE:: Modula2 scope information (Sun only)
2502 * N_RBRAC:: End of lexical block
2503 * N_BCOMM:: Begin named common block
2504 * N_ECOMM:: End named common block
2505 * N_ECOML:: End common
2506 * Gould:: non-base register symbols used on Gould systems
2507 * N_LENG:: Length of preceding entry
2508 @end menu
2509
2510 @node N_GSYM
2511 @section 32 - 0x20 - N_GYSM
2512
2513 @display
2514 Global variable.
2515
2516 .stabs "name", N_GSYM, NIL, NIL, NIL
2517 @end display
2518
2519 @example
2520 "name" -> "symbol_name:#type"
2521 # -> G
2522 @end example
2523
2524 Only the "name" field is significant. the location of the variable is
2525 obtained from the corresponding external symbol.
2526
2527 @node N_FNAME
2528 @section 34 - 0x22 - N_FNAME
2529 Function name (for BSD Fortran)
2530
2531 @display
2532 .stabs "name", N_FNAME, NIL, NIL, NIL
2533 @end display
2534
2535 @example
2536 "name" -> "function_name"
2537 @end example
2538
2539 Only the "name" field is significant. The location of the symbol is
2540 obtained from the corresponding extern symbol.
2541
2542 @node N_FUN
2543 @section 36 - 0x24 - N_FUN
2544 Function name or text segment variable for C.
2545
2546 @display
2547 .stabs "name", N_FUN, NIL, desc, value
2548 @end display
2549
2550 @example
2551 @exdent @emph{For functions:}
2552 "name" -> "proc_name:#return_type"
2553 # -> F (global function)
2554 f (local function)
2555 desc -> line num for proc start. (GCC doesn't set and DBX doesn't miss it.)
2556 value -> Code address of proc start.
2557
2558 @exdent @emph{For text segment variables:}
2559 <<How to create one?>>
2560 @end example
2561
2562 @node N_STSYM
2563 @section 38 - 0x26 - N_STSYM
2564 Initialized static symbol (data segment w/internal linkage).
2565
2566 @display
2567 .stabs "name", N_STSYM, NIL, NIL, value
2568 @end display
2569
2570 @example
2571 "name" -> "symbol_name#type"
2572 # -> S (scope global to compilation unit)
2573 -> V (scope local to a procedure)
2574 value -> Data Address
2575 @end example
2576
2577 @node N_LCSYM
2578 @section 40 - 0x28 - N_LCSYM
2579 Unitialized static (.lcomm) symbol(BSS segment w/internal linkage).
2580
2581 @display
2582 .stabs "name", N_LCLSYM, NIL, NIL, value
2583 @end display
2584
2585 @example
2586 "name" -> "symbol_name#type"
2587 # -> S (scope global to compilation unit)
2588 -> V (scope local to procedure)
2589 value -> BSS Address
2590 @end example
2591
2592 @node N_MAIN
2593 @section 42 - 0x2a - N_MAIN
2594 Name of main routine (not used in C)
2595
2596 @display
2597 .stabs "name", N_MAIN, NIL, NIL, NIL
2598 @end display
2599
2600 @example
2601 "name" -> "name_of_main_routine"
2602 @end example
2603
2604 @node N_PC
2605 @section 48 - 0x30 - N_PC
2606 Global symbol (for Pascal)
2607
2608 @display
2609 .stabs "name", N_PC, NIL, NIL, value
2610 @end display
2611
2612 @example
2613 "name" -> "symbol_name" <<?>>
2614 value -> supposedly the line number (stab.def is skeptical)
2615 @end example
2616
2617 @display
2618 stabdump.c says:
2619
2620 global pascal symbol: name,,0,subtype,line
2621 << subtype? >>
2622 @end display
2623
2624 @node N_NSYMS
2625 @section 50 - 0x32 - N_NSYMS
2626 Number of symbols (according to Ultrix V4.0)
2627
2628 @display
2629 0, files,,funcs,lines (stab.def)
2630 @end display
2631
2632 @node N_NOMAP
2633 @section 52 - 0x34 - N_NOMAP
2634 no DST map for sym (according to Ultrix V4.0)
2635
2636 @display
2637 name, ,0,type,ignored (stab.def)
2638 @end display
2639
2640 @node N_RSYM
2641 @section 64 - 0x40 - N_RSYM
2642 register variable
2643
2644 @display
2645 .stabs "name:type",N_RSYM,0,RegSize,RegNumber (Sun doc)
2646 @end display
2647
2648 @node N_M2C
2649 @section 66 - 0x42 - N_M2C
2650 Modula-2 compilation unit
2651
2652 @display
2653 .stabs "name", N_M2C, 0, desc, value
2654 @end display
2655
2656 @example
2657 "name" -> "unit_name,unit_time_stamp[,code_time_stamp]
2658 desc -> unit_number
2659 value -> 0 (main unit)
2660 1 (any other unit)
2661 @end example
2662
2663 @node N_SLINE
2664 @section 68 - 0x44 - N_SLINE
2665 Line number in text segment
2666
2667 @display
2668 .stabn N_SLINE, 0, desc, value
2669 @end display
2670
2671 @example
2672 desc -> line_number
2673 value -> code_address (relocatable addr where the corresponding code starts)
2674 @end example
2675
2676 For single source lines that generate discontiguous code, such as flow
2677 of control statements, there may be more than one N_SLINE stab for the
2678 same source line. In this case there is a stab at the start of each
2679 code range, each with the same line number.
2680
2681 @node N_DSLINE
2682 @section 70 - 0x46 - N_DSLINE
2683 Line number in data segment
2684
2685 @display
2686 .stabn N_DSLINE, 0, desc, value
2687 @end display
2688
2689 @example
2690 desc -> line_number
2691 value -> data_address (relocatable addr where the corresponding code
2692 starts)
2693 @end example
2694
2695 See comment for N_SLINE above.
2696
2697 @node N_BSLINE
2698 @section 72 - 0x48 - N_BSLINE
2699 Line number in bss segment
2700
2701 @display
2702 .stabn N_BSLINE, 0, desc, value
2703 @end display
2704
2705 @example
2706 desc -> line_number
2707 value -> bss_address (relocatable addr where the corresponding code
2708 starts)
2709 @end example
2710
2711 See comment for N_SLINE above.
2712
2713 @node N_BROWS
2714 @section 72 - 0x48 - N_BROWS
2715 Sun source code browser, path to .cb file
2716
2717 <<?>>
2718 "path to associated .cb file"
2719
2720 Note: type field value overlaps with N_BSLINE
2721
2722 @node N_DEFD
2723 @section 74 - 0x4a - N_DEFD
2724 GNU Modula2 definition module dependency
2725
2726 GNU Modula-2 definition module dependency. Value is the modification
2727 time of the definition file. Other is non-zero if it is imported with
2728 the GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
2729 are enough empty fields?
2730
2731 @node N_EHDECL
2732 @section 80 - 0x50 - N_EHDECL
2733 GNU C++ exception variable <<?>>
2734
2735 "name is variable name"
2736
2737 Note: conflicts with N_MOD2.
2738
2739 @node N_MOD2
2740 @section 80 - 0x50 - N_MOD2
2741 Modula2 info "for imc" (according to Ultrix V4.0)
2742
2743 Note: conflicts with N_EHDECL <<?>>
2744
2745 @node N_CATCH
2746 @section 84 - 0x54 - N_CATCH
2747 GNU C++ "catch" clause
2748
2749 GNU C++ `catch' clause. Value is its address. Desc is nonzero if
2750 this entry is immediately followed by a CAUGHT stab saying what
2751 exception was caught. Multiple CAUGHT stabs means that multiple
2752 exceptions can be caught here. If Desc is 0, it means all exceptions
2753 are caught here.
2754
2755 @node N_SSYM
2756 @section 96 - 0x60 - N_SSYM
2757 Structure or union element
2758
2759 Value is offset in the structure.
2760
2761 <<?looking at structs and unions in C I didn't see these>>
2762
2763 @node N_SO
2764 @section 100 - 0x64 - N_SO
2765 Path and name of source file containing main routine
2766
2767 @display
2768 .stabs "name", N_SO, NIL, NIL, value
2769 @end display
2770
2771 @example
2772 "name" -> /path/to/source/file
2773 -> source_file_terminal_name
2774
2775 value -> the starting text address of the compilation.
2776 @end example
2777
2778 These are found two in a row. The name field of the first N_SO
2779 contains the path to the source file. The name field of the second
2780 N_SO contains the terminal name of the source file itself.
2781
2782 @node N_LSYM
2783 @section 128 - 0x80 - N_LSYM
2784 Automatic var in the stack (also used for type descriptors.)
2785
2786 @display
2787 .stabs "name" N_LSYM, NIL, NIL, value
2788 @end display
2789
2790 @example
2791 @exdent @emph{For stack based local variables:}
2792
2793 "name" -> name of the variable
2794 value -> offset from frame pointer (negative)
2795
2796 @exdent @emph{For type descriptors:}
2797
2798 "name" -> "name_of_the_type:#type"
2799 # -> t
2800
2801 type -> type_ref (or) type_def
2802
2803 type_ref -> type_number
2804 type_def -> type_number=type_desc etc.
2805 @end example
2806
2807 Type may be either a type reference or a type definition. A type
2808 reference is a number that refers to a previously defined type. A
2809 type definition is the number that will refer to this type, followed
2810 by an equals sign, a type descriptor and the additional data that
2811 defines the type. See the Table D for type descriptors and the
2812 section on types for what data follows each type descriptor.
2813
2814 @node N_BINCL
2815 @section 130 - 0x82 - N_BINCL
2816
2817 Beginning of an include file (Sun only)
2818
2819 Beginning of an include file. Only Sun uses this. In an object file,
2820 only the name is significant. The Sun linker puts data into some of
2821 the other fields.
2822
2823 @node N_SOL
2824 @section 132 - 0x84 - N_SOL
2825
2826 Name of a sub-source file (#include file). Value is starting address
2827 of the compilation.
2828 <<?>>
2829
2830 @node N_PSYM
2831 @section 160 - 0xa0 - N_PSYM
2832
2833 Parameter variable
2834
2835 @display
2836 stabs. "name", N_PSYM, NIL, NIL, value
2837 @end display
2838
2839 @example
2840 "name" -> "param_name:#type"
2841 # -> p (value parameter)
2842 -> i (value parameter by reference, indirect access)
2843 -> v (variable parameter by reference)
2844 -> C (read-only parameter, conformant array bound)
2845 -> x (conformant array value parameter)
2846 -> pP (<<??>>)
2847 -> pF (<<??>>)
2848 -> X (function result variable)
2849 -> b (based variable)
2850
2851 value -> offset from the argument pointer (positive).
2852 @end example
2853
2854 On most machines the argument pointer is the same as the frame
2855 pointer.
2856
2857 @node N_EINCL
2858 @section 162 - 0xa2 - N_EINCL
2859
2860 End of an include file. This and N_BINCL act as brackets around the
2861 file's output. In an ojbect file, there is no significant data in
2862 this entry. The Sun linker puts data into some of the fields.
2863 <<?>>
2864
2865 @node N_ENTRY
2866 @section 164 - 0xa4 - N_ENTRY
2867
2868 Alternate entry point.
2869 Value is its address.
2870 <<?>>
2871
2872 @node N_LBRAC
2873 @section 192 - 0xc0 - N_LBRAC
2874
2875 Beginning of a lexical block (left brace). The variable defined
2876 inside the block precede the N_LBRAC symbol. Or can they follow as
2877 well as long as a new N_FUNC was not encountered. <<?>>
2878
2879 @display
2880 .stabn N_LBRAC, NIL, NIL, value
2881 @end display
2882
2883 @example
2884 value -> code address of block start.
2885 @end example
2886
2887 @node N_EXCL
2888 @section 194 - 0xc2 - N_EXCL
2889
2890 Place holder for a deleted include file. Replaces a N_BINCL and
2891 everything up to the corresponding N_EINCL. The Sun linker generates
2892 these when it finds multiple indentical copies of the symbols from an
2893 included file. This appears only in output from the Sun linker.
2894 <<?>>
2895
2896 @node N_SCOPE
2897 @section 196 - 0xc4 - N_SCOPE
2898
2899 Modula2 scope information (Sun linker)
2900 <<?>>
2901
2902 @node N_RBRAC
2903 @section 224 - 0xe0 - N_RBRAC
2904
2905 End of a lexical block (right brace)
2906
2907 @display
2908 .stabn N_RBRAC, NIL, NIL, value
2909 @end display
2910
2911 @example
2912 value -> code address of the end of the block.
2913 @end example
2914
2915 @node N_BCOMM
2916 @section 226 - 0xe2 - N_BCOMM
2917
2918 Begin named common block.
2919
2920 Only the name is significant.
2921 <<?>>
2922
2923 @node N_ECOMM
2924 @section 228 - 0xe4 - N_ECOMM
2925
2926 End named common block.
2927
2928 Only the name is significant and it should match the N_BCOMM
2929 <<?>>
2930
2931 @node N_ECOML
2932 @section 232 - 0xe8 - N_ECOML
2933
2934 End common (local name)
2935
2936 value is address.
2937 <<?>>
2938
2939 @node Gould
2940 @section Non-base registers on Gould systems
2941 << used on Gould systems for non-base registers syms, values assigned
2942 at random, need real info from Gould. >>
2943 <<?>>
2944
2945 @example
2946 240 0xf0 N_NBTEXT ??
2947 242 0xf2 N_NBDATA ??
2948 244 0xf4 N_NBBSS ??
2949 246 0xf6 N_NBSTS ??
2950 248 0xf8 N_NBLCS ??
2951 @end example
2952
2953 @node N_LENG
2954 @section - 0xfe - N_LENG
2955
2956 Second symbol entry containing a length-value for the preceding entry.
2957 The value is the length.
2958
2959 @node Questions
2960 @appendix Questions and anomalies
2961
2962 @itemize @bullet
2963 @item
2964 For GNU C stabs defining local and global variables (N_LSYM and
2965 N_GSYM), the desc field is supposed to contain the source line number
2966 on which the variable is defined. In reality the desc field is always
2967 0. (This behavour is defined in dbxout.c and putting a line number in
2968 desc is controlled by #ifdef WINNING_GDB which defaults to false). Gdb
2969 supposedly uses this information if you say 'list var'. In reality
2970 var can be a variable defined in the program and gdb says `function
2971 var not defined'
2972
2973 @item
2974 In GNU C stabs there seems to be no way to differentiate tag types:
2975 structures, unions, and enums (symbol descriptor T) and typedefs
2976 (symbol descriptor t) defined at file scope from types defined locally
2977 to a procedure or other more local scope. They all use the N_LSYM
2978 stab type. Types defined at procedure scope are emited after the
2979 N_RBRAC of the preceding function and before the code of the
2980 procedure in which they are defined. This is exactly the same as
2981 types defined in the source file between the two procedure bodies.
2982 GDB overcompensates by placing all types in block #1 the block for
2983 symbols of file scope. This is true for default, -ansi and
2984 -traditional compiler options. (p0001063-gcc, p0001066-gdb)
2985
2986 @item
2987 What ends the procedure scope? Is it the proc block's N_RBRAC or the
2988 next N_FUN? (I believe its the first.)
2989
2990 @item
2991 The comment in xcoff.h says DBX_STATIC_CONST_VAR_CODE is used for
2992 static const variables. DBX_STATIC_CONST_VAR_CODE is set to N_FUN by
2993 default, in dbxout.c. If included, xcoff.h redefines it to N_STSYM.
2994 But testing the default behaviour, my Sun4 native example shows
2995 N_STSYM not N_FUN is used to describe file static initialized
2996 variables. (the code tests for TREE_READONLY(decl) &&
2997 !TREE_THIS_VOLATILE(decl) and if true uses DBX_STATIC_CONST_VAR_CODE).
2998
2999 @item
3000 Global variable stabs don't have location information. This comes
3001 from the external symbol for the same variable. The external symbol
3002 has a leading underbar on the _name of the variable and the stab does
3003 not. How do we know these two symbol table entries are talking about
3004 the same symbol when their names are different?
3005
3006 @item
3007 Can gcc be configured to output stabs the way the Sun compiler
3008 does, so that their native debugging tools work? <NO?> It doesn't by
3009 default. GDB reads either format of stab. (gcc or SunC). How about
3010 dbx?
3011 @end itemize
3012
3013 @node xcoff-differences
3014 @appendix Differences between GNU stabs in a.out and GNU stabs in xcoff
3015
3016 (The AIX/RS6000 native object file format is xcoff with stabs)
3017
3018 @itemize @bullet
3019 @item
3020 Instead of .stabs, xcoff uses .stabx.
3021
3022 @item
3023 The data fields of an xcoff .stabx are in a different order than an
3024 a.out .stabs. The order is: string, value, type. The desc and null
3025 fields present in a.out stabs are missing in xcoff stabs. For N_GSYM
3026 the value field is the name of the symbol.
3027
3028 @item
3029 BSD a.out stab types correspond to AIX xcoff storage classes. In general the
3030 mapping is N_STABTYPE becomes C_STABTYPE. Some stab types in a.out
3031 are not supported in xcoff. See Table E. for full mappings.
3032
3033 exception:
3034 initialised static N_STSYM and un-initialized static N_LCSYM both map
3035 to the C_STSYM storage class. But the destinction is preserved
3036 because in xcoff N_STSYM and N_LCSYM must be emited in a named static
3037 block. Begin the block with .bs s[RW] data_section_name for N_STSYM
3038 or .bs s bss_section_name for N_LCSYM. End the block with .es
3039
3040 @item
3041 xcoff stabs describing tags and typedefs use the N_DECL (0x8c)instead
3042 of N_LSYM stab type.
3043
3044 @item
3045 xcoff uses N_RPSYM (0x8e) instead of the N_RSYM stab type for register
3046 variables. If the register variable is also a value parameter, then
3047 use R instead of P for the symbol descriptor.
3048
3049 6.
3050 xcoff uses negative numbers as type references to the basic types.
3051 There are no boilerplate type definitions emited for these basic
3052 types. << make table of basic types and type numbers for C >>
3053
3054 @item
3055 xcoff .stabx sometimes don't have the name part of the string field.
3056
3057 @item
3058 xcoff uses a .file stab type to represent the source file name. There
3059 is no stab for the path to the source file.
3060
3061 @item
3062 xcoff uses a .line stab type to represent source lines. The format
3063 is: .line line_number.
3064
3065 @item
3066 xcoff emits line numbers relative to the start of the current
3067 function. The start of a function is marked by .bf. If a function
3068 includes lines from a seperate file, then those line numbers are
3069 absolute line numbers in the <<sub-?>> file being compiled.
3070
3071 @item
3072 The start of current include file is marked with: .bi "filename" and
3073 the end marked with .ei "filename"
3074
3075 @item
3076 If the xcoff stab is a N_FUN (C_FUN) then follow the string field with
3077 ,. instead of just ,
3078
3079 @item
3080 The symbol descriptor for register parameters is P for a.out and R for
3081 xcoff.
3082 @end itemize
3083
3084
3085 (I think that's it for .s file differences. They could stand to be
3086 better presented. This is just a list of what I have noticed so far.
3087 There are a *lot* of differences in the information in the symbol
3088 tables of the executable and object files.)
3089
3090 Table E: mapping a.out stab types to xcoff storage classes
3091
3092 @example
3093 stab type storage class
3094 -------------------------------
3095 N_GSYM C_GSYM
3096 N_FNAME unknown
3097 N_FUN C_FUN
3098 N_STSYM C_STSYM
3099 N_LCSYM C_STSYM
3100 N_MAIN unkown
3101 N_PC unknown
3102 N_RSYM C_RSYM
3103 N_RPSYM (0x8e) C_RPSYM
3104 N_M2C unknown
3105 N_SLINE unknown
3106 N_DSLINE unknown
3107 N_BSLINE unknown
3108 N_BROWSE unchanged
3109 N_CATCH unknown
3110 N_SSYM unknown
3111 N_SO unknown
3112 N_LSYM C_LSYM
3113 N_DECL (0x8c) C_DECL
3114 N_BINCL unknown
3115 N_SOL unknown
3116 N_PSYM C_PSYM
3117 N_EINCL unknown
3118 N_ENTRY C_ENTRY
3119 N_LBRAC unknown
3120 N_EXCL unknown
3121 N_SCOPE unknown
3122 N_RBRAC unknown
3123 N_BCOMM C_BCOMM
3124 N_ECOMM C_ECOMM
3125 N_ECOML C_ECOML
3126
3127 N_LENG unknown
3128 @end example
3129
3130 @node Sun-differences
3131 @appendix Differences between GNU stabs and Sun native stabs.
3132
3133 @itemize @bullet
3134 @item
3135 GNU C stabs define *all* types, file or procedure scope, as
3136 N_LSYM. Sun doc talks about using N_GSYM too.
3137
3138 @item
3139 Stabs describing block scopes, N_LBRAC and N_RBRAC are supposed to
3140 contain the nesting level of the block in the desc field, re Sun doc.
3141 GNU stabs always have 0 in that field.
3142
3143 @item
3144 Sun C stabs use type number pairs in the format (a,b) where a is a
3145 number starting with 1 and incremented for each sub-source file in the
3146 compilation. b is a number starting with 1 and incremented for each
3147 new type defined in the compilation. GNU C stabs use the type number
3148 alone, with no source file number.
3149 @end itemize
3150
3151 @contents
3152 @bye
This page took 0.101766 seconds and 5 git commands to generate.