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