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