Some improvements in Texinfo markup:
[deliverable/binutils-gdb.git] / gdb / doc / stabs.texinfo
CommitLineData
e505224d
PB
1\input texinfo
2@setfilename stabs.info
3
4@ifinfo
5@format
6START-INFO-DIR-ENTRY
612dbd4c 7* Stabs: (stabs). The "stabs" debugging information format.
e505224d
PB
8END-INFO-DIR-ENTRY
9@end format
10@end ifinfo
11
12@ifinfo
612dbd4c 13This document describes GNU stabs (debugging symbol tables) in a.out files.
e505224d 14
612dbd4c 15Copyright 1992 Free Software Foundation, Inc.
e505224d
PB
16Contributed by Cygnus Support. Written by Julia Menapace.
17
18Permission is granted to make and distribute verbatim copies of
19this manual provided the copyright notice and this permission notice
20are preserved on all copies.
21
22@ignore
23Permission is granted to process this file through Tex and print the
24results, provided the printed document carries copying permission
25notice 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
29Permission is granted to copy or distribute modified versions of this
30manual under the terms of the GPL (for which purpose this text may be
31regarded as a program in the language TeX).
32@end ifinfo
33
34@setchapternewpage off
35@settitle STABS
36@titlepage
612dbd4c 37@title{The "stabs" representation of debugging information.}
e505224d
PB
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
899bafeb
RP
52Copyright @copyright{} 1992 Free Software Foundation, Inc.
53Contributed by Cygnus Support.
e505224d
PB
54
55Permission is granted to make and distribute verbatim copies of
56this manual provided the copyright notice and this permission notice
57are preserved on all copies.
58
59@end titlepage
60
899bafeb
RP
61@ifinfo
62@node Top
63@top The "stabs" representation of debugging information
e505224d 64
612dbd4c 65This document describes the GNU stabs debugging format in a.out files.
e505224d
PB
66
67@menu
612dbd4c
JG
68* Overview:: Overview of stabs
69* Program structure:: Encoding of the structure of the program
e505224d 70* Simple types::
612dbd4c 71* Example:: A comprehensive example in C
e505224d
PB
72* Variables::
73* Aggregate types::
612dbd4c 74* Symbol tables:: Symbol information in symbol tables
e505224d
PB
75* GNU C++ stabs::
76
77Appendixes:
612dbd4c
JG
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
e505224d 87@end menu
899bafeb 88@end ifinfo
e505224d
PB
89
90
899bafeb 91@node Overview
e505224d
PB
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
899bafeb 101@node Flow
e505224d
PB
102@section Overview of debugging information flow
103
104GCC compiles C source in a .c file into assembly language in a .s
105file, which is translated by the assembler into a .o file, and then
106linked with other .o files and libraries to produce an executable
107file.
108
109When using the -g option, GCC puts additional debugging information in
110the .s file, which is slightly transformed by the assembler and
111linker, and carried through into the final executable. This debugging
112information describes features of the source file like line numbers,
113the types and scopes of variables, and functions, their parameters and
114their scopes.
115
116For some object file formats, the debugging information is
117encapsulated in pseudo-ops to the assembler known as `stab' (symbol
118table) directives, interspersed with the generated code. Stabs are
119the native format for debugging information in the a.out and xcoff
120object file formats. The GNU tools can also emit stabs in the coff
121and ecoff object file formats.
122
123The assembler adds the information from stabs to the symbol
124information it places by default in the symbol table and the string
125table of the .o file it is building. The linker consolidates the .o
126files into one executable file, with one symbol and one string table.
127Debuggers use the symbol and string tables in the executable as a
128source of debugging information about the program.
129
899bafeb 130@node Stabs format
e505224d
PB
131@section Overview of stab format
132
133There are three overall formats for stab assembler directives
134differentiated by the first word of the stab. The first word
135describes what combination of four possible data fields will follow.
136It is either .stabs (string), .stabn (number), or .stabd (dot).
137
138The 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
146In general, in .stabs the string field contains name and type
147information. For .stabd the value field is implicit and has the value
148of the current file location. Otherwise the value field often
149contains a relocatable address, frame pointer offset, or register
150number, that maps to the source code element described by the stab.
151
152The real key to decoding the meaning of a stab is the number in its
153type field. Each possible type number defines a different stab type.
154The stab type further defines the exact interpretation of, and
155possible values for, any remaining "string", desc, or value fields
156present in the stab. Table A lists in numeric order the possible type
157field values for stab directives. The reference section that follows
158Table A describes the meaning of the fields for each stab type in
159detail. The examples that follow this overview introduce the stab
160types in terms of the source code elements they describe.
161
162For .stabs the "string" field holds the meat of the debugging
163information. The generally unstructured nature of this field is what
164makes stabs extensible. For some stab types the string field contains
165only a name. For other stab types the contents can be a great deal
166more complex.
167
168The overall format is of the "string" field is:
169
170@example
171"name[:symbol_descriptor][type_number[=type_descriptor...]]"
172@end example
173
174name is the name of the symbol represented by the stab.
175
176The symbol_descriptor following the : is an alphabetic character that
177tells more specifically what kind of symbol the stab represents. If
178the symbol_descriptor is omitted, but type information follows, then
179the stab represents a local variable. See Table C for a list of
180symbol_descriptors.
181
182Type information it is either a type_number, or a type_number=. The
183type_number alone is a type reference, referring directly to a type
184that has already been defined.
185
186The type_number= is a type definition, where the number represents a
187new type which is about to be defined. The type definition may refer
188to other types by number, and those type numbers may be followed by =
189and nested definitions.
190
191In a type definition, if the character that follows the equals sign is
192non-numeric then it is a type_descriptor, and tells what kind of type
193is about to be defined. Any other values following the
194type_descriptor vary, depending on the type_descriptor. If a number
195follows the = then the number is a type_reference. This is described
196more thoroughly in the section on types. See Table D for a list of
197type_descriptors.
198
199All this can make the "string" field quite long. When the "string"
200part of a stab is more than 80 characters, we split the .stabs
201pseudo-op into two .stabs pseudo-ops, both stabs duplicate exactly all
202but the "string" field. The "string" field of the first stab contains
203the first part of the overlong string, marked as continued with a
204double-backslash at the end. The "string" field of the second stab
205holds the second half of the overlong string.
206
899bafeb 207@node C example
e505224d
PB
208@section A simple example in C source
209
210To get the flavor of how stabs describe source information for a C
211program, let's look at the simple program:
212
213@example
214main()
215@{
216 printf("Hello world");
217@}
218@end example
219
220When compiled with -g, the program above yields the following .s file.
221Line numbers have been added so it will be easier to refer to parts of
222the .s file in the description of the stabs that follows.
223
899bafeb 224@node Assembly code
e505224d
PB
225@section The simple example at the assembly level
226
227@example
2281 gcc2_compiled.:
2292 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
2303 .stabs "hello.c",100,0,0,Ltext0
2314 .text
2325 Ltext0:
2336 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
2347 .stabs "char:t2=r2;0;127;",128,0,0,0
2358 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
2369 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
23710 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
23811 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
23912 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
24013 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
24114 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
24215 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
24316 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
24417 .stabs "float:t12=r1;4;0;",128,0,0,0
24518 .stabs "double:t13=r1;8;0;",128,0,0,0
24619 .stabs "long double:t14=r1;8;0;",128,0,0,0
24720 .stabs "void:t15=15",128,0,0,0
24821 .align 4
24922 LC0:
25023 .ascii "Hello, world!\12\0"
25124 .align 4
25225 .global _main
25326 .proc 1
25427 _main:
25528 .stabn 68,0,4,LM1
25629 LM1:
25730 !#PROLOGUE# 0
25831 save %sp,-136,%sp
25932 !#PROLOGUE# 1
26033 call ___main,0
26134 nop
26235 .stabn 68,0,5,LM2
26336 LM2:
26437 LBB2:
26538 sethi %hi(LC0),%o1
26639 or %o1,%lo(LC0),%o0
26740 call _printf,0
26841 nop
26942 .stabn 68,0,6,LM3
27043 LM3:
27144 LBE2:
27245 .stabn 68,0,6,LM4
27346 LM4:
27447 L1:
27548 ret
27649 restore
27750 .stabs "main:F1",36,0,0,_main
27851 .stabn 192,0,0,LBB2
27952 .stabn 224,0,0,LBE2
280@end example
281
282This simple hello world example, demonstrates several of the stab
283types used to describe C language source files.
284
899bafeb 285@node Program structure
e505224d
PB
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
899bafeb 295@node Source file
e505224d
PB
296@section The path and name of the source file
297
298@example
299.stabs, stab type N_SO
300@end example
301
302The first stabs in the .s file contain the name and path of the source
303file that was compiled to produce the .s file. This information is
304contained 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
3122 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
3133 .stabs "hello.c",100,0,0,Ltext0
3144 .text
3155 Ltext0:
316@end example
317
899bafeb 318@node Line numbers
e505224d
PB
319@section Line Numbers
320
321@example
322.stabn, stab type N_SLINE
323@end example
324
325The start of source lines is represented by the N_SLINE (68) stab
326type.
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
33427 _main:
33528 .stabn 68,0,4,LM1
33629 LM1:
33730 !#PROLOGUE# 0
338@end example
339
899bafeb 340@node Procedures
e505224d
PB
341@section Procedures
342
343@example
344.stabs, stab type N_FUN,
345 symbol descriptors f (local), F (global)
346@end example
347
348Procedures are described by the N_FUN stab type. The symbol
349descriptor for a procedure is F if the proc is globally scoped and f
350if the procedure is static (locally scoped).
351
352The N_FUN stab representing a procedure is located immediatly
353following the code of the procedure. The N_FUN stab is in turn
354directly followed by a group of other stabs describing elements of the
355procedure. These other stabs describe the procedure's parameters, its
356block local variables and its block structure.
357
358@example
35948 ret
36049 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
36950 .stabs "main:F1",36,0,0,_main
370@end example
371
899bafeb 372@node Block Structure
e505224d
PB
373@section Block Structure
374
375@example
376.stabn, stab types N_LBRAC, N_RRAC
377@end example
378
379The program's block structure is represented by the N_LBRAC (left
380brace) and the N_RBRAC (right brace) stab types. The following code
381range, which is the body of main, is labeled with LBB2: at the
382beginning and LBE2: at the end.
383
384@example
38537 LBB2:
38638 sethi %hi(LC0),%o1
38739 or %o1,%lo(LC0),%o0
38840 call _printf,0
38941 nop
39042 .stabn 68,0,6,LM3
39143 LM3:
39244 LBE2:
393@end example
394
395The N_LBRAC and N_RBRAC stabs that describe the block scope of the
396procedure are located after the N_FUNC stab that represents the
397procedure itself. The N_LBRAC uses the LBB2 label as the code address
398in its value field and the N_RBRAC uses the LBE2.
399
400@example
40150 .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
41051 .stabn 192,0,0,LBB2
41152 .stabn 224,0,0,LBE2
412@end example
413
899bafeb 414@node Simple types
e505224d
PB
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
899bafeb 423@node Basic types
e505224d
PB
424@section Basic type definitions
425
426@example
427.stabs, stab type N_LSYM,
428 symbol descriptor t
429@end example
430
431The basic types for the language are described using the N_LSYM stab
432type. They are boilerplate and are emited by the compiler for each
433compilation unit. Basic type definitions are not always a complete
434description of the type and are sometimes circular. The debugger
435recognizes the type anyway, and knows how to read bits as that type.
436
437Each language and compiler defines a slightly different set of basic
438types. In this example we are looking at the basic types for C emited
439by the GNU compiler targeting the Sun4. Here the basic types are
440mostly defined as range types.
441
442
899bafeb 443@node Range types
e505224d
PB
444@section Range types defined by min and max value
445
446type descriptor r
447
448When defining a range type, if the number after the first semicolon is
449smaller than the number after the second one, then the two numbers
450represent the smallest and the largest values in the range.
451
452@example
4534 .text
4545 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
4596 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
4607 .stabs "char:t2=r2;0;127;",128,0,0,0
461@end example
462
463Here 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
465is circular, but at least the high and low bound values of the range
466hold more information about the type.
467
468Here short unsigned int is defined as type number 8 and described as a
469range of type int, with a minimum value of 0 and a maximum of 65535.
470
471@example
47213 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
473@end example
474
899bafeb 475@node Bit-ranges
e505224d
PB
476@section Range type defined by number of bits
477
478type descriptor r
479
480In a range definition, if the number after the second semicolon is 0,
481then the number after the first semicolon is the number of bits needed
482to 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
48817 .stabs "float:t12=r1;4;0;",128,0,0,0
48918 .stabs "double:t13=r1;8;0;",128,0,0,0
49019 .stabs "long double:t14=r1;8;0;",128,0,0,0
491@end example
492
493Cosmically enough, the void type is defined directly in terms of
494itself.
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
50120 .stabs "void:t15=15",128,0,0,0
502@end example
503
504
899bafeb 505@node Example
e505224d
PB
506@chapter A Comprehensive Example in C
507
508Now we'll examine a second program, example2, which builds on the
509first example to introduce the rest of the stab types, symbol
510descriptors, and type descriptors used in C.
511@xref{Example2.c} for the complete .c source,
899bafeb 512and @pxref{Example2.s} for the .s assembly code.
e505224d
PB
513This description includes parts of those files.
514
515@section Flow of control and nested scopes
516
899bafeb 517@code{.stabn}, stab types @code{N_SLINE}, @code{N_LBRAC}, @code{N_RBRAC} (cont.)
e505224d 518
899bafeb
RP
519Consider the body of @code{main}, from @file{example2.c}. It shows more
520about how @code{N_SLINE}, @code{N_RBRAC}, and @code{N_LBRAC} stabs are used.
e505224d
PB
521
522@example
52320 @{
52421 static float s_flap;
52522 int times;
52623 for (times=0; times < s_g_repeat; times++)@{
52724 int inner;
52825 printf ("Hello world\n");
52926 @}
53027 @};
531@end example
532
899bafeb 533Here we have a single source line, the @samp{for} line, that generates
e505224d 534non-linear flow of control, and non-contiguous code. In this case, an
899bafeb 535@code{N_SLINE} stab with the same line number proceeds each block of
e505224d
PB
536non-contiguous code generated from the same source line.
537
899bafeb 538The example also shows nested scopes. The @code{N_LBRAC} and @code{N_LBRAC} stabs
e505224d
PB
539that describe block structure are nested in the same order as the
540corresponding code blocks, those of the for loop inside those for the
541body of main.
542
899bafeb
RP
543@example
544@exdent Label for the @code{N_LBRAC} (left brace) stab marking the start of @code{main}.
e505224d
PB
545
54657 LBB2:
547
899bafeb
RP
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
e505224d 551
e505224d
PB
55258 .stabn 68,0,23,LM2
55359 LM2:
55460 st %g0,[%fp-20]
55561 L2:
55662 sethi %hi(_s_g_repeat),%o0
55763 ld [%fp-20],%o1
55864 ld [%o0+%lo(_s_g_repeat)],%o0
55965 cmp %o1,%o0
56066 bge L3
56167 nop
e505224d 562
899bafeb 563@exdent label for the N_LBRAC (start block) marking the start of `for' loop
e505224d 564
e505224d
PB
56568 LBB3:
56669 .stabn 68,0,25,LM3
56770 LM3:
56871 sethi %hi(LC0),%o1
56972 or %o1,%lo(LC0),%o0
57073 call _printf,0
57174 nop
57275 .stabn 68,0,26,LM4
57376 LM4:
e505224d 574
899bafeb 575@exdent label for the N_RBRAC (end block) stab marking the end of the for loop
e505224d 576
e505224d 57777 LBE3:
e505224d 578
899bafeb 579@exdent Second code range for source line 23, 'for' loop increment and return
612dbd4c 580
899bafeb 581@exdent <68> N_SLINE - source line number associated with this code
612dbd4c 582
899bafeb 583@exdent .stabn, SLINE, NIL, line_number, code_address_of_line_continuation.
e505224d 584
e505224d
PB
58578 .stabn 68,0,23,LM5
58679 LM5:
58780 L4:
58881 ld [%fp-20],%o0
58982 add %o0,1,%o1
59083 st %o1,[%fp-20]
59184 b,a L2
59285 L3:
59386 .stabn 68,0,27,LM6
59487 LM6:
e505224d 595
899bafeb 596@exdent label for the N_RBRAC (end block) stab marking the end of the for loop
e505224d 597
e505224d
PB
59888 LBE2:
59989 .stabn 68,0,27,LM7
60090 LM7:
60191 L1:
60292 ret
60393 restore
60494 .stabs "main:F1",36,0,0,_main
60595 .stabs "argc:p1",160,0,0,68
60696 .stabs "argv:p20=*21=*2",160,0,0,72
60797 .stabs "s_flap:V12",40,0,0,_s_flap.0
60898 .stabs "times:1",128,0,0,-20
609
899bafeb
RP
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
e505224d
PB
613
61499 .stabn 192,0,0,LBB2 ## begin proc label
615100 .stabs "inner:1",128,0,0,-24
616101 .stabn 192,0,0,LBB3 ## begin for label
617
899bafeb
RP
618@exdent <224> N_RBRAC - right brace, end lexical block (scope)
619@exdent .stabn N_RBRAC,NIL,NIL,code_addr_of_block_end
e505224d
PB
620
621102 .stabn 224,0,0,LBE3 ## end for label
622103 .stabn 224,0,0,LBE2 ## end proc label
623@end example
624
899bafeb 625@node Variables
e505224d
PB
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
899bafeb 637@node Automatic variables
e505224d
PB
638@section Locally scoped automatic variables
639
640@example
641.stabs, stab type N_LSYM,
642 symbol descriptor none
643@end example
644
645
646In addition to describing types, the N_LSYM stab type also describes
647locally scoped automatic variables. Refer again to the body of main
648in example2.c. It allocates two automatic variables, 'times' is
649scoped to the body of main and 'inner' is scoped to the body of the
650for loop. 's_flap' is locally scoped by not automatic and will be
651discussed later.
652
653@example
65420 @{
65521 static float s_flap;
65622 int times;
65723 for (times=0; times < s_g_repeat; times++)@{
65824 int inner;
65925 printf ("Hello world\n");
66026 @}
66127 @};
662@end example
663
664The N_LSYM stab for an automatic variable is located just before the
665N_LBRAC stab describing the open brace of the block to which it is
666scoped.
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
67298 .stabs "times:1",128,0,0,-20
67399 .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
678100 .stabs "inner:1",128,0,0,-24
679101 .stabn 192,0,0,LBB3 ## begin `for' loop N_LBRAC
680@end example
681
682Since the character in the string field following the colon is not a
683letter, there is no symbol descriptor. This means that the stab
684describes a local variable, and that the number after the colon is a
685type reference. In this case it a a reference to the basic type int.
686Notice also that the frame pointer offset is negative number for
687automatic variables.
688
689
899bafeb 690@node Global Variables
e505224d
PB
691@section Global Variables
692
693@example
694.stabs, stab type N_GSYM,
695 symbol descriptor G
696@end example
697
698Global variables are represented by the N_GSYM stab type. The symbol
699descriptor, following the colon in the string field, is G. Following
700the G is a type reference or type definition. In this example it is a
701type reference to the basic C type, char. The first source line in
702example2.c
703
704@example
7051 char g_foo = 'c';
706@end example
707
708yields the following stab. The stab immediatly preceeds the code that
709allocates 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
71721 .stabs "g_foo:G2",32,0,0,0
71822 .global _g_foo
71923 .data
72024 _g_foo:
72125 .byte 99
722@end example
723
724The address of the variable represented by the N_GSYM is not contained
725in the N_GSYM stab. The debugger gets this information from the
726external symbol for the global variable.
727
899bafeb 728@node Register variables
e505224d
PB
729@section Register variables
730
731@example
732.stabs, stab type N_RSYM,
733 symbol descriptor r
734@end example
735
736The following source line defines a global variable, g_bar, which is
737allocated in global register %g5.
738
739@example
7402 register int g_bar asm ("%g5");
741@end example
742
743Register variables have their own stab type, N_RSYM, and their own
744symbol descriptor, r. The stab's value field contains the number of
745the register where the variable data will be stored. Since the
746variable was not initialized in this compilation unit, the stab is
747emited at the end of the object file, with the stabs for other
748uninitialized 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
754133 .stabs "g_bar:r1",64,0,0,5
755@end example
756
757
899bafeb 758@node Initialized statics
e505224d
PB
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
766Initialized static variables are represented by the N_STSYM stab type.
767The symbol descriptor part of the string field shows if the variable
768is file scope static (S) or procedure scope static (V). The source
769line:
770
771@example
7723 static int s_g_repeat = 2;
773@end example
774
775yields the following code. The stab is located immediatly preceeding
776the storage for the variable it represents. Since the variable in
777this 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
78526 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
78627 .align 4
78728 _s_g_repeat:
78829 .word 2
789@end example
790
791
899bafeb 792@node Un-initialized statics
e505224d
PB
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
800Un-initilized static variables are represeted by the N_LCSYM stab
801type. The symbol descriptor part of the string shows if the variable
802is file scope static (S) or procedure scope static (V). In this
803example it is procedure scope static. The source line allocating
804s_flap immediatly follows the open brace for the procedure main.
805
806@example
80720 @{
80821 static float s_flap;
809@end example
810
811
812The code that reserves storage for the variable s_flap preceeds the
813body of body of main.
814
815@example
81639 .reserve _s_flap.0,4,"bss",4
817@end example
818
819But since s_flap is scoped locally to main, its stab is located with
820the other stabs representing symbols local to main. The stab for
821s_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
83097 .stabs "s_flap:V12",40,0,0,_s_flap.0
83198 .stabs "times:1",128,0,0,-20
83299 .stabn 192,0,0,LBB2 # N_LBRAC for main.
833@end example
834
899bafeb 835@node Parameters
e505224d
PB
836@section Parameters
837
838@example
839.stabs, stab type N_PSYM,
840 symbol descriptor p
841@end example
842
843Procedure parameters are represented by the N_PSYM stab type. The
844following source lines show the parameters of the main routine.
845
846@example
84717 main (argc, argv)
84818 int argc;
84919 char* argv[];
85020 @{
851@end example
852
853The N_PSYM stabs describing parameters to a function directly follow
854the N_FUN stab that represents the procedure itself. The N_FUN stab
855immediatly follows the code of the procedure it describes. Following
856the N_PSYM parameter stabs are any N_LSYM stabs representing local
857variables.
858
e505224d 859@example
899bafeb
RP
860@exdent <36> N_FUN - describing the procedure main
861
e505224d
PB
86294 .stabs "main:F1",36,0,0,_main
863
899bafeb
RP
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
e505224d
PB
86895 .stabs "argc:p1",160,0,0,68
869
899bafeb
RP
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
e505224d
PB
87496 .stabs "argv:p20=*21=*2",160,0,0,72
875@end example
876
877The type definition of argv is interesting because it defines two new
878types in terms of an existing one. The array argv contains character
879pointers. The type of the array name is a pointer to the type the
880array holds. Thus the type of argv is ptr to ptr to char. The stab
881for argv contains nested type_definitions. Type 21 is ptr to type 2
882(char) and argv (type 20) is ptr to type 21.
883
899bafeb 884@node Aggregate Types
e505224d
PB
885@chapter Aggregate Types
886
612dbd4c 887Now let's look at some variable definitions involving complex types.
e505224d
PB
888This involves understanding better how types are described. In the
889examples so far types have been described as references to previously
890defined types or defined in terms of subranges of or pointers to
891previously defined types. The section that follows will talk about
892the various other type descriptors that may follow the = sign in a
893type definition.
894
895@menu
896* Arrays::
897* Enumerations::
898* Structure tags::
899* Typedefs::
900* Unions::
901* Function types::
902@end menu
903
899bafeb
RP
904@node Arrays
905@section Array types
e505224d
PB
906
907.stabs, stab types N_GSYM, N_LSYM,
899bafeb 908
e505224d
PB
909 symbol descriptor T, type descriptor ar
910
911As an example of an array type consider the global variable below.
912
913@example
91415 char char_vec[3] = @{'a','b','c'@};
915@end example
916
917Since the array is a global variable, it is described by the N_GSYM
918stab type. The symbol descriptor G, following the colon in stab's
919string field, also says the array is a global variable. Following the
920G is a definition for type (19) as shown by the equals sign after the
921type number.
922
923After the equals sign is a type descriptor, ar, which says that the
924type being defined is an array. Following the type descriptor for an
925array is the type of the index, a null field, the upper bound of the
926array indexing, and the type of the array elements.
927
928The array definition above generates the assembly language that
929follows.
930
931@example
899bafeb
RP
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
e505224d
PB
936
93732 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
93833 .global _char_vec
93934 .align 4
94035 _char_vec:
94136 .byte 97
94237 .byte 98
94338 .byte 99
944@end example
945
899bafeb 946@node Enumerations
e505224d
PB
947@section Enumerations
948
899bafeb 949@display
e505224d
PB
950.stabs, stab type N_LSYM,
951 symbol descriptor T, type descriptor e
899bafeb 952@end display
e505224d
PB
953
954The source line below declares an enumeration type. It is defined at
955file scope between the bodies of main and s_proc in example2.c.
956Because the N_LSYM is located after the N_RBRAC that marks the end of
957the previous procedure's block scope, and before the N_FUN that marks
958the beginning of the next procedure's block scope, the N_LSYM does not
959describe a block local symbol, but a file local one. The source line:
960
961@example
96229 enum e_places @{first,second=3,last@};
963@end example
964
899bafeb 965@noindent
e505224d
PB
966generates the following stab, located just after the N_RBRAC (close
967brace stab) for main. The type definition is in an N_LSYM stab
968because type definitions are file scope not global scope.
969
899bafeb 970@display
e505224d
PB
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
899bafeb 975@end display
e505224d 976
899bafeb 977@example
e505224d 978104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
899bafeb 979@end example
e505224d
PB
980
981The symbol descriptor (T) says that the stab describes a structure,
982enumeration, or type tag. The type descriptor e, following the 22= of
983the type definition narrows it down to an enumeration type. Following
984the e is a list of the elements of the enumeration. The format is
985name:value,. The list of elements ends with a ;.
986
899bafeb 987@node Structure tags
e505224d
PB
988@section Structure Tags
989
899bafeb 990@display
e505224d
PB
991.stabs, stab type N_LSYM,
992 symbol descriptor T, type descriptor s
899bafeb 993@end display
e505224d
PB
994
995The following source code declares a structure tag and defines an
996instance of the structure in global scope. Then a typedef equates the
997structure tag with a new type. A seperate stab is generated for the
998structure tag, the structure typedef, and the structure instance. The
999stabs for the tag and the typedef are emited when the definitions are
1000encountered. Since the structure elements are not initialized, the
1001stab and code for the structure variable itself is located at the end
1002of the program in .common.
1003
1004@example
10056 struct s_tag @{
10067 int s_int;
10078 float s_float;
10089 char s_char_vec[8];
100910 struct s_tag* s_next;
101011 @} g_an_s;
101112
101213 typedef struct s_tag s_typedef;
1013@end example
1014
1015The structure tag is an N_LSYM stab type because, like the enum, the
1016symbol is file scope. Like the enum, the symbol descriptor is T, for
1017enumeration, struct or tag type. The symbol descriptor s following
1018the 16= of the type definition narrows the symbol type to struct.
1019
1020Following the struct symbol descriptor is the number of bytes the
1021struct occupies, followed by a description of each structure element.
1022The structure element descriptions are of the form name:type, bit
1023offset from the start of the struct, and number of bits in the
1024element.
1025
1026
612dbd4c 1027@example
e505224d
PB
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
103730 .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
612dbd4c 1039@end example
e505224d
PB
1040
1041In this example, two of the structure elements are previously defined
1042types. For these, the type following the name: part of the element
1043description is a simple type reference. The other two structure
1044elements are new types. In this case there is a type definition
1045embedded after the name:. The type definition for the array element
1046looks just like a type definition for a standalone array. The s_next
1047field is a pointer to the same kind of structure that the field is an
1048element of. So the definition of structure type 16 contains an type
1049definition for an element which is a pointer to type 16.
1050
899bafeb 1051@node Typedefs
e505224d
PB
1052@section Typedefs
1053
899bafeb 1054@display
e505224d
PB
1055.stabs, stab type N_LSYM,
1056 symbol descriptor t
899bafeb 1057@end display
e505224d
PB
1058
1059Here is the stab for the typedef equating the structure tag with a
1060type.
1061
899bafeb 1062@display
e505224d
PB
1063 <128> N_LSYM - type definition
1064 .stabs "name:sym_desc(type name)type_ref(struct_tag)",N_LSYM,NIL,NIL,NIL
899bafeb 1065@end display
e505224d 1066
899bafeb 1067@example
e505224d 106831 .stabs "s_typedef:t16",128,0,0,0
899bafeb 1069@end example
e505224d
PB
1070
1071And here is the code generated for the structure variable.
1072
899bafeb 1073@display
e505224d
PB
1074 <32> N_GSYM - global symbol
1075 .stabs "name:sym_desc(global)type_ref(struct_tag)",N_GSYM,NIL,NIL,NIL
899bafeb 1076@end display
e505224d
PB
1077
1078@example
1079136 .stabs "g_an_s:G16",32,0,0,0
1080137 .common _g_an_s,20,"bss"
1081@end example
1082
1083Notice that the structure tag has the same type number as the typedef
1084for the structure tag. It is impossible to distinguish between a
1085variable of the struct type and one of its typedef by looking at the
1086debugging information.
1087
1088
899bafeb 1089@node Unions
e505224d
PB
1090@section Unions
1091
899bafeb 1092@display
e505224d
PB
1093.stabs, stab type N_LSYM,
1094 symbol descriptor T, type descriptor u
899bafeb 1095@end display
e505224d 1096
612dbd4c 1097Next let's look at unions. In example2 this union type is declared
e505224d
PB
1098locally to a procedure and an instance of the union is defined.
1099
1100@example
110136 union u_tag @{
110237 int u_int;
110338 float u_float;
110439 char* u_char;
110540 @} an_u;
1106@end example
1107
1108This code generates a stab for the union tag and a stab for the union
1109variable. Both use the N_LSYM stab type. Since the union variable is
1110scoped locally to the procedure in which it is defined, its stab is
1111located immediatly preceeding the N_LBRAC for the procedure's block
1112start.
1113
1114The stab for the union tag, however is located preceeding the code for
1115the procedure in which it is defined. The stab type is N_LSYM. This
1116would seem to imply that the union type is file scope, like the struct
1117type s_tag. This is not true. The contents and position of the stab
1118for u_type do not convey any infomation about its procedure local
1119scope.
1120
899bafeb 1121@display
e505224d
PB
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
899bafeb 1129@end display
e505224d 1130
899bafeb 1131@example
e505224d 1132105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",128,0,0,0
899bafeb 1133@end example
e505224d
PB
1134
1135The symbol descriptor, T, following the name: means that the stab
1136describes an enumeration struct or type tag. The type descriptor u,
1137following the 23= of the type definition, narrows it down to a union
1138type definition. Following the u is the number of bytes in the union.
1139After that is a list of union element descriptions. Their format is
1140name:type, bit offset into the union, and number of bytes for the
1141element;.
1142
1143The stab for the union variable follows. Notice that the frame
1144pointer offset for local variables is negative.
1145
899bafeb 1146@display
e505224d
PB
1147 <128> N_LSYM - local variable (with no symbol descriptor)
1148 .stabs "name:type_ref(u_tag)", N_LSYM, NIL, NIL, frame_ptr_offset
899bafeb 1149@end display
e505224d 1150
899bafeb 1151@example
e505224d 1152130 .stabs "an_u:23",128,0,0,-20
899bafeb 1153@end example
e505224d 1154
899bafeb 1155@node Function types
e505224d
PB
1156@section Function types
1157
899bafeb 1158@display
e505224d 1159type descriptor f
899bafeb 1160@end display
e505224d
PB
1161
1162The last type descriptor in C which remains to be described is used
1163for function types. Consider the following source line defining a
1164global function pointer.
1165
1166@example
11674 int (*g_pf)();
1168@end example
1169
1170It generates the following code. Since the variable is not
1171initialized, the code is located in the common area at the end of the
1172file.
1173
899bafeb 1174@display
e505224d
PB
1175 <32> N_GSYM - global variable
1176 .stabs "name:sym_desc(global)type_def(24)=ptr_to(25)=
1177 type_def(func)type_ref(int)
899bafeb 1178@end display
e505224d 1179
899bafeb 1180@example
e505224d
PB
1181134 .stabs "g_pf:G24=*25=f1",32,0,0,0
1182135 .common _g_pf,4,"bss"
899bafeb 1183@end example
e505224d
PB
1184
1185Since the variable is global, the stab type is N_GSYM and the symbol
1186descriptor is G. The variable defines a new type, 24, which is a
1187pointer to another new type, 25, which is defined as a function
1188returning int.
1189
899bafeb 1190@node Symbol tables
e505224d
PB
1191@chapter Symbol information in symbol tables
1192
1193This section examines more closely the format of symbol table entries
1194and how stab assembler directives map to them. It also describes what
1195transformations the assembler and linker make on data from stabs.
1196
1197Each time the assembler encounters a stab in its input file it puts
1198each field of the stab into corresponding fields in a symbol table
1199entry of its output file. If the stab contains a string field, the
1200symbol table entry for that stab points to a string table entry
1201containing the string data from the stab. Assembler labels become
1202relocatable addresses. Symbol table entries in a.out have the format:
1203
1204@example
1205struct internal_nlist @{
1206 unsigned long n_strx; /* index into string table of name */
1207 unsigned char n_type; /* type of symbol */
1208 unsigned char n_other; /* misc info (usually empty) */
1209 unsigned short n_desc; /* description field */
1210 bfd_vma n_value; /* value of symbol */
1211@};
1212@end example
1213
1214For .stabs directives, the n_strx field holds the character offset
1215from the start of the string table to the string table entry
1216containing the "string" field. For other classes of stabs (.stabn and
1217.stabd) this field is null.
1218
1219Symbol table entries with n_type fields containing a value greater or
1220equal to 0x20 originated as stabs generated by the compiler (with one
1221random exception). Those with n_type values less than 0x20 were
1222placed in the symbol table of the executable by the assembler or the
1223linker.
1224
1225The linker concatenates object files and does fixups of externally
1226defined symbols. You can see the transformations made on stab data by
1227the assembler and linker by examining the symbol table after each pass
1228of the build, first the assemble and then the link.
1229
1230To do this use nm with the -ap options. This dumps the symbol table,
1231including debugging information, unsorted. For stab entries the
1232columns are: value, other, desc, type, string. For assembler and
1233linker symbols, the columns are: value, type, string.
1234
1235There are a few important things to notice about symbol tables. Where
1236the value field of a stab contains a frame pointer offset, or a
1237register number, that value is unchanged by the rest of the build.
1238
1239Where the value field of a stab contains an assembly language label,
1240it is transformed by each build step. The assembler turns it into a
1241relocatable address and the linker turns it into an absolute address.
1242This source line defines a static variable at file scope:
1243
899bafeb 1244@example
e505224d 12453 static int s_g_repeat
899bafeb 1246@end example
e505224d 1247
899bafeb 1248@noindent
e505224d
PB
1249The following stab describes the symbol.
1250
899bafeb 1251@example
e505224d 125226 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
899bafeb 1253@end example
e505224d 1254
899bafeb 1255@noindent
e505224d 1256The assembler transforms the stab into this symbol table entry in the
899bafeb 1257@file{.o} file. The location is expressed as a data segment offset.
e505224d 1258
899bafeb 1259@example
e505224d 126021 00000084 - 00 0000 STSYM s_g_repeat:S1
899bafeb 1261@end example
e505224d 1262
899bafeb 1263@noindent
e505224d
PB
1264in the symbol table entry from the executable, the linker has made the
1265relocatable address absolute.
1266
899bafeb 1267@example
e505224d 126822 0000e00c - 00 0000 STSYM s_g_repeat:S1
899bafeb 1269@end example
e505224d
PB
1270
1271Stabs for global variables do not contain location information. In
1272this case the debugger finds location information in the assembler or
1273linker symbol table entry describing the variable. The source line:
1274
899bafeb 1275@example
e505224d 12761 char g_foo = 'c';
899bafeb 1277@end example
e505224d 1278
899bafeb 1279@noindent
e505224d
PB
1280generates the stab:
1281
899bafeb 1282@example
e505224d 128321 .stabs "g_foo:G2",32,0,0,0
899bafeb 1284@end example
e505224d
PB
1285
1286The variable is represented by the following two symbol table entries
1287in the object file. The first one originated as a stab. The second
1288one is an external symbol. The upper case D signifies that the n_type
1289field of the symbol table contains 7, N_DATA with local linkage (see
1290Table B). The value field following the file's line number is empty
1291for the stab entry. For the linker symbol it contains the
1292rellocatable address corresponding to the variable.
1293
899bafeb 1294@example
e505224d
PB
129519 00000000 - 00 0000 GSYM g_foo:G2
129620 00000080 D _g_foo
899bafeb 1297@end example
e505224d 1298
899bafeb 1299@noindent
e505224d
PB
1300These entries as transformed by the linker. The linker symbol table
1301entry now holds an absolute address.
1302
899bafeb 1303@example
e505224d 130421 00000000 - 00 0000 GSYM g_foo:G2
899bafeb 1305@dots{}
e505224d 1306215 0000e008 D _g_foo
899bafeb 1307@end example
e505224d 1308
899bafeb 1309@node GNU C++ stabs
612dbd4c 1310@chapter GNU C++ stabs
e505224d
PB
1311
1312@menu
1313* Basic C++ types::
1314* Simple classes::
1315* Class instance::
1316* Methods:: Method definition
1317* Protections::
1318* Method Modifiers:: (const, volatile, const volatile)
1319* Virtual Methods::
1320* Inheritence::
1321* Virtual Base Classes::
1322* Static Members::
1323@end menu
1324
1325
1326@subsection Symbol descriptors added for C++ descriptions:
1327
899bafeb 1328@display
e505224d 1329P - register parameter.
899bafeb 1330@end display
e505224d
PB
1331
1332@subsection type descriptors added for C++ descriptions
1333
1334@table @code
1335@item #
1336method type (two ## if minimal debug)
1337
1338@item xs
1339cross-reference
1340@end table
1341
1342
899bafeb 1343@node Basic C++ types
e505224d
PB
1344@section Basic types for C++
1345
1346<< the examples that follow are based on a01.C >>
1347
1348
1349C++ adds two more builtin types to the set defined for C. These are
1350the unknown type and the vtable record type. The unknown type, type
135116, is defined in terms of itself like the void type.
1352
1353The vtable record type, type 17, is defined as a structure type and
1354then as a structure tag. The structure has four fields, delta, index,
1355pfn, and delta2. pfn is the function pointer.
1356
1357<< In boilerplate $vtbl_ptr_type, what are the fields delta,
1358index, and delta2 used for? >>
1359
1360This basic type is present in all C++ programs even if there are no
1361virtual methods defined.
1362
899bafeb 1363@display
e505224d
PB
1364.stabs "struct_name:sym_desc(type)type_def(17)=type_desc(struct)struct_bytes(8)
1365 elem_name(delta):type_ref(short int),bit_offset(0),field_bits(16);
1366 elem_name(index):type_ref(short int),bit_offset(16),field_bits(16);
1367 elem_name(pfn):type_def(18)=type_desc(ptr to)type_ref(void),
1368 bit_offset(32),field_bits(32);
1369 elem_name(delta2):type_def(short int);bit_offset(32),field_bits(16);;"
1370 N_LSYM, NIL, NIL
899bafeb 1371@end display
e505224d 1372
899bafeb 1373@smallexample
e505224d
PB
1374.stabs "$vtbl_ptr_type:t17=s8
1375 delta:6,0,16;index:6,16,16;pfn:18=*15,32,32;delta2:6,32,16;;"
1376 ,128,0,0,0
899bafeb 1377@end smallexample
e505224d 1378
899bafeb 1379@display
e505224d 1380.stabs "name:sym_dec(struct tag)type_ref($vtbl_ptr_type)",N_LSYM,NIL,NIL,NIL
899bafeb 1381@end display
e505224d 1382
899bafeb 1383@example
e505224d 1384.stabs "$vtbl_ptr_type:T17",128,0,0,0
899bafeb 1385@end example
e505224d 1386
899bafeb 1387@node Simple classes
e505224d
PB
1388@section Simple class definition
1389
1390The stabs describing C++ language features are an extension of the
1391stabs describing C. Stabs representing C++ class types elaborate
1392extensively on the stab format used to describe structure types in C.
1393Stabs representing class type variables look just like stabs
1394representing C language variables.
1395
1396Consider the following very simple class definition.
1397
1398@example
1399class baseA @{
1400public:
1401 int Adat;
1402 int Ameth(int in, char other);
1403@};
1404@end example
1405
1406The class baseA is represented by two stabs. The first stab describes
1407the class as a structure type. The second stab describes a structure
1408tag of the class type. Both stabs are of stab type N_LSYM. Since the
1409stab is not located between an N_FUN and a N_LBRAC stab this indicates
1410that the class is defined at file scope. If it were, then the N_LSYM
1411would signify a local variable.
1412
1413A stab describing a C++ class type is similar in format to a stab
1414describing a C struct, with each class member shown as a field in the
1415structure. The part of the struct format describing fields is
1416expanded to include extra information relevent to C++ class members.
1417In addition, if the class has multiple base classes or virtual
1418functions the struct format outside of the field parts is also
1419augmented.
1420
1421In this simple example the field part of the C++ class stab
1422representing member data looks just like the field part of a C struct
1423stab. The section on protections describes how its format is
1424sometimes extended for member data.
1425
1426The field part of a C++ class stab representing a member function
1427differs substantially from the field part of a C struct stab. It
1428still begins with `name:' but then goes on to define a new type number
1429for the member function, describe its return type, its argument types,
1430its protection level, any qualifiers applied to the method definition,
1431and whether the method is virtual or not. If the method is virtual
1432then the method description goes on to give the vtable index of the
1433method, and the type number of the first base class defining the
1434method.
1435
1436When the field name is a method name it is followed by two colons
1437rather than one. This is followed by a new type definition for the
1438method. This is a number followed by an equal sign and then the
1439symbol descriptor `##', indicating a method type. This is followed by
1440a type reference showing the return type of the method and a
1441semi-colon.
1442
1443The format of an overloaded operator method name differs from that
1444of other methods. It is "op$::XXXX." where XXXX is the operator name
612dbd4c
JG
1445such as + or +=. The name ends with a period, and any characters except
1446the period can occur in the XXXX string.
e505224d
PB
1447
1448The next part of the method description represents the arguments to
1449the method, preceeded by a colon and ending with a semi-colon. The
1450types of the arguments are expressed in the same way argument types
1451are expressed in C++ name mangling. In this example an int and a char
1452map to `ic'.
1453
1454This is followed by a number, a letter, and an asterisk or period,
1455followed by another semicolon. The number indicates the protections
1456that apply to the member function. Here the 2 means public. The
1457letter encodes any qualifier applied to the method definition. In
1458this case A means that it is a normal function definition. The dot
1459shows that the method is not virtual. The sections that follow
1460elaborate further on these fields and describe the additional
1461information present for virtual methods.
1462
1463
899bafeb 1464@display
e505224d
PB
1465.stabs "class_name:sym_desc(type)type_def(20)=type_desc(struct)struct_bytes(4)
1466 field_name(Adat):type(int),bit_offset(0),field_bits(32);
1467
1468 method_name(Ameth)::type_def(21)=type_desc(method)return_type(int);
1469 :arg_types(int char);
1470 protection(public)qualifier(normal)virtual(no);;"
1471 N_LSYM,NIL,NIL,NIL
899bafeb 1472@end display
e505224d 1473
899bafeb 1474@smallexample
e505224d
PB
1475.stabs "baseA:t20=s4Adat:1,0,32;Ameth::21=##1;:ic;2A.;;",128,0,0,0
1476
1477.stabs "class_name:sym_desc(struct tag)",N_LSYM,NIL,NIL,NIL
1478
1479.stabs "baseA:T20",128,0,0,0
899bafeb 1480@end smallexample
e505224d 1481
899bafeb 1482@node Class instance
e505224d
PB
1483@section Class instance
1484
1485As shown above, describing even a simple C++ class definition is
1486accomplished by massively extending the stab format used in C to
1487describe structure types. However, once the class is defined, C stabs
1488with no modifications can be used to describe class instances. The
1489following source:
1490
1491@example
1492main () @{
1493 baseA AbaseA;
1494@}
1495@end example
1496
899bafeb
RP
1497@noindent
1498yields the following stab describing the class instance. It looks no
e505224d
PB
1499different from a standard C stab describing a local variable.
1500
899bafeb 1501@display
e505224d 1502.stabs "name:type_ref(baseA)", N_LSYM, NIL, NIL, frame_ptr_offset
899bafeb 1503@end display
e505224d 1504
899bafeb 1505@example
e505224d 1506.stabs "AbaseA:20",128,0,0,-20
899bafeb 1507@end example
e505224d 1508
899bafeb 1509@node Methods
e505224d
PB
1510@section Method defintion
1511
1512The class definition shown above declares Ameth. The C++ source below
1513defines Ameth:
1514
1515@example
1516int
1517baseA::Ameth(int in, char other)
1518@{
1519 return in;
1520@};
1521@end example
1522
1523
1524This method definition yields three stabs following the code of the
1525method. One stab describes the method itself and following two
1526describe its parameters. Although there is only one formal argument
1527all methods have an implicit argument which is the `this' pointer.
1528The `this' pointer is a pointer to the object on which the method was
1529called. Note that the method name is mangled to encode the class name
1530and argument types. << Name mangling is not described by this
1531document - Is there already such a doc? >>
1532
612dbd4c 1533@example
e505224d
PB
1534.stabs "name:symbol_desriptor(global function)return_type(int)",
1535 N_FUN, NIL, NIL, code_addr_of_method_start
1536
1537.stabs "Ameth__5baseAic:F1",36,0,0,_Ameth__5baseAic
612dbd4c 1538@end example
e505224d
PB
1539
1540Here is the stab for the `this' pointer implicit argument. The name
1541of the `this' pointer is always $t. Type 19, the `this' pointer is
1542defined as a pointer to type 20, baseA, but a stab defining baseA has
1543not yet been emited. Since the compiler knows it will be emited
1544shortly, here it just outputs a cross reference to the undefined
1545symbol, by prefixing the symbol name with xs.
1546
612dbd4c 1547@example
e505224d
PB
1548.stabs "name:sym_desc(register param)type_def(19)=
1549 type_desc(ptr to)type_ref(baseA)=
1550 type_desc(cross-reference to)baseA:",N_RSYM,NIL,NIL,register_number
1551
1552.stabs "$t:P19=*20=xsbaseA:",64,0,0,8
612dbd4c 1553@end example
e505224d
PB
1554
1555The stab for the explicit integer argument looks just like a parameter
1556to a C function. The last field of the stab is the offset from the
1557argument pointer, which in most systems is the same as the frame
1558pointer.
1559
612dbd4c 1560@example
e505224d
PB
1561.stabs "name:sym_desc(value parameter)type_ref(int)",
1562 N_PSYM,NIL,NIL,offset_from_arg_ptr
1563
1564.stabs "in:p1",160,0,0,72
612dbd4c 1565@end example
e505224d
PB
1566
1567<< The examples that follow are based on A1.C >>
1568
899bafeb 1569@node Protections
e505224d
PB
1570@section Protections
1571
1572
1573In the simple class definition shown above all member data and
1574functions were publicly accessable. The example that follows
1575contrasts public, protected and privately accessable fields and shows
1576how these protections are encoded in C++ stabs.
1577
1578Protections for class member data are signified by two characters
1579embeded in the stab defining the class type. These characters are
1580located after the name: part of the string. /0 means private, /1
1581means protected, and /2 means public. If these characters are omited
1582this means that the member is public. The following C++ source:
1583
1584@example
1585class all_data @{
1586private:
1587 int priv_dat;
1588protected:
1589 char prot_dat;
1590public:
1591 float pub_dat;
1592@};
1593@end example
1594
899bafeb 1595@noindent
e505224d
PB
1596generates the following stab to describe the class type all_data.
1597
899bafeb 1598@display
e505224d
PB
1599.stabs "class_name:sym_desc(type)type_def(19)=type_desc(struct)struct_bytes
1600 data_name:/protection(private)type_ref(int),bit_offset,num_bits;
1601 data_name:/protection(protected)type_ref(char),bit_offset,num_bits;
1602 data_name:(/num omited, private)type_ref(float),bit_offset,num_bits;;"
1603 N_LSYM,NIL,NIL,NIL
899bafeb 1604@end display
e505224d 1605
899bafeb 1606@smallexample
e505224d
PB
1607.stabs "all_data:t19=s12
1608 priv_dat:/01,0,32;prot_dat:/12,32,8;pub_dat:12,64,32;;",128,0,0,0
899bafeb 1609@end smallexample
e505224d
PB
1610
1611Protections for member functions are signified by one digit embeded in
1612the field part of the stab describing the method. The digit is 0 if
1613private, 1 if protected and 2 if public. Consider the C++ class
1614definition below:
1615
1616@example
1617class all_methods @{
1618private:
1619 int priv_meth(int in)@{return in;@};
1620protected:
1621 char protMeth(char in)@{return in;@};
1622public:
1623 float pubMeth(float in)@{return in;@};
1624@};
1625@end example
1626
1627It generates the following stab. The digit in question is to the left
1628of an `A' in each case. Notice also that in this case two symbol
1629descriptors apply to the class name struct tag and struct type.
1630
899bafeb 1631@display
e505224d
PB
1632.stabs "class_name:sym_desc(struct tag&type)type_def(21)=
1633 sym_desc(struct)struct_bytes(1)
1634 meth_name::type_def(22)=sym_desc(method)returning(int);
1635 :args(int);protection(private)modifier(normal)virtual(no);
1636 meth_name::type_def(23)=sym_desc(method)returning(char);
1637 :args(char);protection(protected)modifier(normal)virual(no);
1638 meth_name::type_def(24)=sym_desc(method)returning(float);
1639 :args(float);protection(public)modifier(normal)virtual(no);;",
1640 N_LSYM,NIL,NIL,NIL
899bafeb 1641@end display
e505224d 1642
899bafeb 1643@smallexample
e505224d
PB
1644.stabs "all_methods:Tt21=s1priv_meth::22=##1;:i;0A.;protMeth::23=##2;:c;1A.;
1645 pubMeth::24=##12;:f;2A.;;",128,0,0,0
899bafeb 1646@end smallexample
e505224d 1647
899bafeb
RP
1648@node Method Modifiers
1649@section Method Modifiers (const, volatile, const volatile)
e505224d
PB
1650
1651<< based on a6.C >>
1652
1653In the class example described above all the methods have the normal
1654modifier. This method modifier information is located just after the
1655protection information for the method. This field has four possible
1656character values. Normal methods use A, const methods use B, volatile
1657methods use C, and const volatile methods use D. Consider the class
1658definition below:
1659
1660@example
1661class A @{
1662public:
1663 int ConstMeth (int arg) const @{ return arg; @};
1664 char VolatileMeth (char arg) volatile @{ return arg; @};
1665 float ConstVolMeth (float arg) const volatile @{return arg; @};
1666@};
1667@end example
1668
1669This class is described by the following stab:
1670
899bafeb 1671@display
e505224d
PB
1672.stabs "class(A):sym_desc(struct)type_def(20)=type_desc(struct)struct_bytes(1)
1673 meth_name(ConstMeth)::type_def(21)sym_desc(method)
1674 returning(int);:arg(int);protection(public)modifier(const)virtual(no);
1675 meth_name(VolatileMeth)::type_def(22)=sym_desc(method)
1676 returning(char);:arg(char);protection(public)modifier(volatile)virt(no)
1677 meth_name(ConstVolMeth)::type_def(23)=sym_desc(method)
1678 returning(float);:arg(float);protection(public)modifer(const volatile)
899bafeb
RP
1679 virtual(no);;", @dots{}
1680@end display
e505224d 1681
899bafeb 1682@example
e505224d
PB
1683.stabs "A:T20=s1ConstMeth::21=##1;:i;2B.;VolatileMeth::22=##2;:c;2C.;
1684 ConstVolMeth::23=##12;:f;2D.;;",128,0,0,0
612dbd4c 1685@end example
e505224d 1686
899bafeb 1687@node Virtual Methods
e505224d
PB
1688@section Virtual Methods
1689
1690<< The following examples are based on a4.C >>
1691
1692The presence of virtual methods in a class definition adds additional
1693data to the class description. The extra data is appended to the
1694description of the virtual method and to the end of the class
1695description. Consider the class definition below:
1696
1697@example
1698class A @{
1699public:
1700 int Adat;
1701 virtual int A_virt (int arg) @{ return arg; @};
1702@};
1703@end example
1704
1705This results in the stab below describing class A. It defines a new
1706type (20) which is an 8 byte structure. The first field of the class
1707struct is Adat, an integer, starting at structure offset 0 and
1708occupying 32 bits.
1709
1710The second field in the class struct is not explicitly defined by the
1711C++ class definition but is implied by the fact that the class
1712contains a virtual method. This field is the vtable pointer. The
1713name of the vtable pointer field starts with $vf and continues with a
1714type reference to the class it is part of. In this example the type
1715reference for class A is 20 so the name of its vtable pointer field is
1716$vf20, followed by the usual colon.
1717
1718Next there is a type definition for the vtable pointer type (21).
1719This is in turn defined as a pointer to another new type (22).
1720
1721Type 22 is the vtable itself, which is defined as an array, indexed by
1722integers, with a high bound of 1, and elements of type 17. Type 17
1723was the vtable record type defined by the boilerplate C++ type
1724definitions, as shown earlier.
1725
1726The bit offset of the vtable pointer field is 32. The number of bits
1727in the field are not specified when the field is a vtable pointer.
1728
1729Next is the method definition for the virtual member function A_virt.
1730Its description starts out using the same format as the non-virtual
1731member functions described above, except instead of a dot after the
1732`A' there is an asterisk, indicating that the function is virtual.
1733Since is is virtual some addition information is appended to the end
1734of the method description.
1735
1736The first number represents the vtable index of the method. This is a
173732 bit unsigned number with the high bit set, followed by a
1738semi-colon.
1739
1740The second number is a type reference to the first base class in the
1741inheritence hierarchy defining the virtual member function. In this
1742case the class stab describes a base class so the virtual function is
1743not overriding any other definition of the method. Therefore the
1744reference is to the type number of the class that the stab is
1745describing (20).
1746
1747This is followed by three semi-colons. One marks the end of the
1748current sub-section, one marks the end of the method field, and the
1749third marks the end of the struct definition.
1750
1751For classes containing virtual functions the very last section of the
1752string part of the stab holds a type reference to the first base
1753class. This is preceeded by `~%' and followed by a final semi-colon.
1754
899bafeb 1755@display
e505224d
PB
1756.stabs "class_name(A):type_def(20)=sym_desc(struct)struct_bytes(8)
1757 field_name(Adat):type_ref(int),bit_offset(0),field_bits(32);
1758 field_name(A virt func ptr):type_def(21)=type_desc(ptr to)type_def(22)=
1759 sym_desc(array)index_type_ref(int);NIL;elem_type_ref(vtbl elem type);
1760 bit_offset(32);
1761 meth_name(A_virt)::typedef(23)=sym_desc(method)returning(int);
1762 :arg_type(int),protection(public)normal(yes)virtual(yes)
1763 vtable_index(1);class_first_defining(A);;;~%first_base(A);",
1764 N_LSYM,NIL,NIL,NIL
899bafeb 1765@end display
e505224d 1766
899bafeb 1767@example
e505224d 1768.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
612dbd4c 1769@end example
e505224d 1770
899bafeb 1771@node Inheritence
e505224d
PB
1772@section Inheritence
1773
1774Stabs describing C++ derived classes include additional sections that
1775describe the inheritence hierarchy of the class. A derived class stab
1776also encodes the number of base classes. For each base class it tells
1777if the base class is virtual or not, and if the inheritence is private
1778or public. It also gives the offset into the object of the portion of
1779the object corresponding to each base class.
1780
1781This additional information is embeded in the class stab following the
1782number of bytes in the struct. First the number of base classes
1783appears bracketed by an exclamation point and a comma.
1784
1785Then for each base type there repeats a series: two digits, a number,
1786a comma, another number, and a semi-colon.
1787
1788The first of the two digits is 1 if the base class is virtual and 0 if
1789not. The second digit is 2 if the derivation is public and 0 if not.
1790
1791The number following the first two digits is the offset from the start
1792of the object to the part of the object pertaining to the base class.
1793
1794After the comma, the second number is a type_descriptor for the base
1795type. Finally a semi-colon ends the series, which repeats for each
1796base class.
1797
1798The source below defines three base classes A, B, and C and the
1799derived class D.
1800
1801
1802@example
1803class A @{
1804public:
1805 int Adat;
1806 virtual int A_virt (int arg) @{ return arg; @};
1807@};
1808
1809class B @{
1810public:
1811 int B_dat;
1812 virtual int B_virt (int arg) @{return arg; @};
1813@};
1814
1815class C @{
1816public:
1817 int Cdat;
1818 virtual int C_virt (int arg) @{return arg; @};
1819@};
1820
1821class D : A, virtual B, public C @{
1822public:
1823 int Ddat;
1824 virtual int A_virt (int arg ) @{ return arg+1; @};
1825 virtual int B_virt (int arg) @{ return arg+2; @};
1826 virtual int C_virt (int arg) @{ return arg+3; @};
1827 virtual int D_virt (int arg) @{ return arg; @};
1828@};
1829@end example
1830
1831Class stabs similar to the ones described earlier are generated for
1832each base class.
1833
899bafeb 1834@smallexample
e505224d
PB
1835.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
1836
1837.stabs "B:Tt25=s8Bdat:1,0,32;$vf25:21,32;B_virt::26=##1;:i;2A*-2147483647;25;;;~%25;",128,0,0,0
1838
1839.stabs "C:Tt28=s8Cdat:1,0,32;$vf28:21,32;C_virt::29=##1;:i;2A*-2147483647;28;;;~%28;",128,0,0,0
899bafeb 1840@end smallexample
e505224d
PB
1841
1842In the stab describing derived class D below, the information about
1843the derivation of this class is encoded as follows.
1844
899bafeb 1845@display
e505224d
PB
1846.stabs "derived_class_name:symbol_descriptors(struct tag&type)=
1847 type_descriptor(struct)struct_bytes(32)!num_bases(3),
1848 base_virtual(no)inheritence_public(no)base_offset(0),
1849 base_class_type_ref(A);
1850 base_virtual(yes)inheritence_public(no)base_offset(NIL),
1851 base_class_type_ref(B);
1852 base_virtual(no)inheritence_public(yes)base_offset(64),
899bafeb
RP
1853 base_class_type_ref(C); @dots{}
1854@end display
e505224d 1855
899bafeb 1856@smallexample
e505224d 1857.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
899bafeb 1858@end smallexample
e505224d 1859
899bafeb 1860@node Virtual Base Classes
e505224d
PB
1861@section Virtual Base Classes
1862
1863A derived class object consists of a concatination in memory of the
1864data areas defined by each base class, starting with the leftmost and
1865ending with the rightmost in the list of base classes. The exception
1866to this rule is for virtual inheritence. In the example above, class
1867D inherits virtually from base class B. This means that an instance
1868of a D object will not contain it's own B part but merely a pointer to
1869a B part, known as a virtual base pointer.
1870
1871In a derived class stab, the base offset part of the derivation
1872information, described above, shows how the base class parts are
1873ordered. The base offset for a virtual base class is always given as
18740. Notice that the base offset for B is given as 0 even though B is
1875not the first base class. The first base class A starts at offset 0.
1876
1877The field information part of the stab for class D describes the field
1878which is the pointer to the virtual base class B. The vbase pointer
1879name is $vb followed by a type reference to the virtual base class.
1880Since the type id for B in this example is 25, the vbase pointer name
1881is $vb25.
1882
899bafeb 1883@smallexample
e505224d 1884.stabs "D:Tt31=s32!3,000,20;100,25;0264,28;$vb25:24,128;Ddat:1,160,32;A_virt::32=##1;:i;2A*-2147483647;20;;B_virt::32:i;2A*-2147483647;25;;C_virt::32:i;2A*-2147483647;28;;D_virt::32:i;2A*-2147483646;31;;;~%20;",128,0,0,0
899bafeb 1885@end smallexample
e505224d
PB
1886
1887Following the name and a semicolon is a type reference describing the
1888type of the virtual base class pointer, in this case 24. Type 24 was
1889defined earlier as the type of the B class `this` pointer, $t. The
1890`this' pointer for a class is a pointer to the class type.
1891
899bafeb 1892@example
e505224d 1893.stabs "$t:P24=*25=xsB:",64,0,0,8
899bafeb 1894@end example
e505224d
PB
1895
1896Finally the field offset part of the vbase pointer field description
1897shows that the vbase pointer is the first field in the D object,
1898before any data fields defined by the class. The layout of a D class
1899object is a follows, Adat at 0, the vtable pointer for A at 32, Cdat
1900at 64, the vtable pointer for C at 96, the virtual ase pointer for B
1901at 128, and Ddat at 160.
1902
1903
899bafeb 1904@node Static Members
e505224d
PB
1905@section Static Members
1906
1907The data area for a class is a concatination of the space used by the
1908data members of the class. If the class has virtual methods a vtable
1909pointer follows the class data. The field offset part of each field
1910description in the class stab shows this ordering.
1911
1912<< how is this reflected in stabs? >>
1913
899bafeb 1914@node Example2.c
e505224d
PB
1915@appendix Example2.c - source code for extended example
1916
1917@example
19181 char g_foo = 'c';
19192 register int g_bar asm ("%g5");
19203 static int s_g_repeat = 2;
19214 int (*g_pf)();
19225
19236 struct s_tag @{
19247 int s_int;
19258 float s_float;
19269 char s_char_vec[8];
192710 struct s_tag* s_next;
192811 @} g_an_s;
192912
193013 typedef struct s_tag s_typedef;
193114
193215 char char_vec[3] = @{'a','b','c'@};
193316
193417 main (argc, argv)
193518 int argc;
193619 char* argv[];
193720 @{
193821 static float s_flap;
193922 int times;
194023 for (times=0; times < s_g_repeat; times++)@{
194124 int inner;
194225 printf ("Hello world\n");
194326 @}
194427 @};
194528
194629 enum e_places @{first,second=3,last@};
194730
194831 static s_proc (s_arg, s_ptr_arg, char_vec)
194932 s_typedef s_arg;
195033 s_typedef* s_ptr_arg;
195134 char* char_vec;
195235 @{
195336 union u_tag @{
195437 int u_int;
195538 float u_float;
195639 char* u_char;
195740 @} an_u;
195841 @}
195942
196043
1961@end example
1962
899bafeb 1963@node Example2.s
e505224d
PB
1964@appendix Example2.s - assembly code for extended example
1965
1966@example
19671 gcc2_compiled.:
19682 .stabs "/cygint/s1/users/jcm/play/",100,0,0,Ltext0
19693 .stabs "example2.c",100,0,0,Ltext0
19704 .text
19715 Ltext0:
19726 .stabs "int:t1=r1;-2147483648;2147483647;",128,0,0,0
19737 .stabs "char:t2=r2;0;127;",128,0,0,0
19748 .stabs "long int:t3=r1;-2147483648;2147483647;",128,0,0,0
19759 .stabs "unsigned int:t4=r1;0;-1;",128,0,0,0
197610 .stabs "long unsigned int:t5=r1;0;-1;",128,0,0,0
197711 .stabs "short int:t6=r1;-32768;32767;",128,0,0,0
197812 .stabs "long long int:t7=r1;0;-1;",128,0,0,0
197913 .stabs "short unsigned int:t8=r1;0;65535;",128,0,0,0
198014 .stabs "long long unsigned int:t9=r1;0;-1;",128,0,0,0
198115 .stabs "signed char:t10=r1;-128;127;",128,0,0,0
198216 .stabs "unsigned char:t11=r1;0;255;",128,0,0,0
198317 .stabs "float:t12=r1;4;0;",128,0,0,0
198418 .stabs "double:t13=r1;8;0;",128,0,0,0
198519 .stabs "long double:t14=r1;8;0;",128,0,0,0
198620 .stabs "void:t15=15",128,0,0,0
198721 .stabs "g_foo:G2",32,0,0,0
198822 .global _g_foo
198923 .data
199024 _g_foo:
199125 .byte 99
199226 .stabs "s_g_repeat:S1",38,0,0,_s_g_repeat
199327 .align 4
199428 _s_g_repeat:
199529 .word 2
199630 .stabs "s_tag:T16=s20s_int:1,0,32;s_float:12,32,32;s_char_vec:17=ar1;0;7;2,64,64;s_next:18=*16,128,32;;",128,0,0,0
199731 .stabs "s_typedef:t16",128,0,0,0
199832 .stabs "char_vec:G19=ar1;0;2;2",32,0,0,0
199933 .global _char_vec
200034 .align 4
200135 _char_vec:
200236 .byte 97
200337 .byte 98
200438 .byte 99
200539 .reserve _s_flap.0,4,"bss",4
200640 .text
200741 .align 4
200842 LC0:
200943 .ascii "Hello world\12\0"
201044 .align 4
201145 .global _main
201246 .proc 1
201347 _main:
201448 .stabn 68,0,20,LM1
201549 LM1:
201650 !#PROLOGUE# 0
201751 save %sp,-144,%sp
201852 !#PROLOGUE# 1
201953 st %i0,[%fp+68]
202054 st %i1,[%fp+72]
202155 call ___main,0
202256 nop
202357 LBB2:
202458 .stabn 68,0,23,LM2
202559 LM2:
202660 st %g0,[%fp-20]
202761 L2:
202862 sethi %hi(_s_g_repeat),%o0
202963 ld [%fp-20],%o1
203064 ld [%o0+%lo(_s_g_repeat)],%o0
203165 cmp %o1,%o0
203266 bge L3
203367 nop
203468 LBB3:
203569 .stabn 68,0,25,LM3
203670 LM3:
203771 sethi %hi(LC0),%o1
203872 or %o1,%lo(LC0),%o0
203973 call _printf,0
204074 nop
204175 .stabn 68,0,26,LM4
204276 LM4:
204377 LBE3:
204478 .stabn 68,0,23,LM5
204579 LM5:
204680 L4:
204781 ld [%fp-20],%o0
204882 add %o0,1,%o1
204983 st %o1,[%fp-20]
205084 b,a L2
205185 L3:
205286 .stabn 68,0,27,LM6
205387 LM6:
205488 LBE2:
205589 .stabn 68,0,27,LM7
205690 LM7:
205791 L1:
205892 ret
205993 restore
206094 .stabs "main:F1",36,0,0,_main
206195 .stabs "argc:p1",160,0,0,68
206296 .stabs "argv:p20=*21=*2",160,0,0,72
206397 .stabs "s_flap:V12",40,0,0,_s_flap.0
206498 .stabs "times:1",128,0,0,-20
206599 .stabn 192,0,0,LBB2
2066100 .stabs "inner:1",128,0,0,-24
2067101 .stabn 192,0,0,LBB3
2068102 .stabn 224,0,0,LBE3
2069103 .stabn 224,0,0,LBE2
2070104 .stabs "e_places:T22=efirst:0,second:3,last:4,;",128,0,0,0
2071105 .stabs "u_tag:T23=u4u_int:1,0,32;u_float:12,0,32;u_char:21,0,32;;",128,0,0,0
2072106 .align 4
2073107 .proc 1
2074108 _s_proc:
2075109 .stabn 68,0,35,LM8
2076110 LM8:
2077111 !#PROLOGUE# 0
2078112 save %sp,-120,%sp
2079113 !#PROLOGUE# 1
2080114 mov %i0,%o0
2081115 st %i1,[%fp+72]
2082116 st %i2,[%fp+76]
2083117 LBB4:
2084118 .stabn 68,0,41,LM9
2085119 LM9:
2086120 LBE4:
2087121 .stabn 68,0,41,LM10
2088122 LM10:
2089123 L5:
2090124 ret
2091125 restore
2092126 .stabs "s_proc:f1",36,0,0,_s_proc
2093127 .stabs "s_arg:p16",160,0,0,0
2094128 .stabs "s_ptr_arg:p18",160,0,0,72
2095129 .stabs "char_vec:p21",160,0,0,76
2096130 .stabs "an_u:23",128,0,0,-20
2097131 .stabn 192,0,0,LBB4
2098132 .stabn 224,0,0,LBE4
2099133 .stabs "g_bar:r1",64,0,0,5
2100134 .stabs "g_pf:G24=*25=f1",32,0,0,0
2101135 .common _g_pf,4,"bss"
2102136 .stabs "g_an_s:G16",32,0,0,0
2103137 .common _g_an_s,20,"bss"
2104@end example
2105
2106
899bafeb 2107@node Quick reference
e505224d
PB
2108@appendix Quick reference
2109
2110@menu
2111* Stab types:: Table A: Symbol types from stabs
2112* Assembler types:: Table B: Symbol types from assembler and linker
2113* Symbol descriptors:: Table C
2114* Type Descriptors:: Table D
2115@end menu
2116
899bafeb 2117@node Stab types
e505224d
PB
2118@section Table A: Symbol types from stabs
2119
2120Table A lists stab types sorted by type number. Stab type numbers are
212132 and greater. This is the full list of stab numbers, including stab
2122types that are used in languages other than C.
2123
2124The #define names for these stab types are defined in:
2125devo/include/aout/stab.def
2126
899bafeb 2127@smallexample
e505224d
PB
2128type type #define used to describe
2129dec hex name source program feature
2130-------------------------------------------------------------------------------
213132 0x20 N_GYSM global symbol
213234 0X22 N_FNAME function name (for BSD Fortran)
213336 0x24 N_FUN function name or text segment variable for C
213438 0x26 N_STSYM static symbol (data segment w/internal linkage)
213540 0x28 N_LCSYM .lcomm symbol(BSS-seg variable w/internal linkage)
213642 0x2a N_MAIN Name of main routine (not used in C)
213748 0x30 N_PC global symbol (for Pascal)
213850 0x32 N_NSYMS number of symbols (according to Ultrix V4.0)
213952 0x34 N_NOMAP no DST map for sym (according to Ultrix V4.0)
214064 0x40 N_RSYM register variable
214166 0x42 N_M2C Modula-2 compilation unit
214268 0x44 N_SLINE line number in text segment
214370 0x46 N_DSLINE line number in data segment
2144
214572 0x48 N_BSLINE line number in bss segment
214672 0x48 N_BROWS Sun source code browser, path to .cb file
2147
612dbd4c 214874 0x4a N_DEFD GNU Modula2 definition module dependency
e505224d 2149
612dbd4c 215080 0x50 N_EHDECL GNU C++ exception variable
e505224d
PB
215180 0x50 N_MOD2 Modula2 info "for imc" (according to Ultrix V4.0)
2152
612dbd4c 215384 0x54 N_CATCH GNU C++ "catch" clause
e505224d
PB
215496 0x60 N_SSYM structure of union element
2155100 0x64 N_SO path and name of source file
2156128 0x80 N_LSYM automatic var in the stack (also used for type desc.)
2157130 0x82 N_BINCL beginning of an include file (Sun only)
2158132 0x84 N_SOL Name of sub-source (#include) file.
2159160 0xa0 N_PSYM parameter variable
2160162 0xa2 N_EINCL end of an include file
2161164 0xa4 N_ENTRY alternate entry point
2162192 0xc0 N_LBRAC beginning of a lexical block
2163194 0xc2 N_EXCL place holder for a deleted include file
2164196 0xc4 N_SCOPE modula2 scope information (Sun linker)
2165224 0xe0 N_RBRAC end of a lexical block
2166226 0xe2 N_BCOMM begin named common block
2167228 0xe4 N_ECOMM end named common block
2168232 0xe8 N_ECOML end common (local name)
2169
2170 << used on Gould systems for non-base registers syms >>
2171240 0xf0 N_NBTEXT ??
2172242 0xf2 N_NBDATA ??
2173244 0xf4 N_NBBSS ??
2174246 0xf6 N_NBSTS ??
2175248 0xf8 N_NBLCS ??
899bafeb 2176@end smallexample
e505224d 2177
899bafeb 2178@node Assembler types
e505224d
PB
2179@section Table B: Symbol types from assembler and linker
2180
2181Table B shows the types of symbol table entries that hold assembler
2182and linker symbols.
2183
2184The #define names for these n_types values are defined in
2185/include/aout/aout64.h
2186
899bafeb 2187@smallexample
e505224d
PB
2188dec hex #define
2189n_type n_type name used to describe
2190-----------------------------------------------------------------------------
21911 0x0 N_UNDF undefined symbol
21922 0x2 N_ABS absolute symbol -- defined at a particular address
21933 0x3 extern " (vs. file scope)
21944 0x4 N_TEXT text symbol -- defined at offset in text segment
21955 0x5 extern " (vs. file scope)
21966 0x6 N_DATA data symbol -- defined at offset in data segment
21977 0x7 extern " (vs. file scope)
21988 0x8 N_BSS BSS symbol -- defined at offset in zero'd segment
21999 extern " (vs. file scope)
2200
220112 0x0C N_FN_SEQ func name for Sequent compilers (stab exception)
2202
220349 0x12 N_COMM common sym -- visable after shared lib dynamic link
220431 0x1f N_FN file name of a .o file
899bafeb 2205@end smallexample
e505224d 2206
899bafeb 2207@node Symbol descriptors
e505224d
PB
2208@section Table C: Symbol descriptors
2209
2210@example
2211descriptor meaning
2212-------------------------------------------------
2213(empty) local variable
2214 f local function
2215 F global function
2216 G global variable
2217 p value parameter
2218 r register variable
2219 S static global variable
2220 t type name
2221 T enumeration, struct or type tag
2222 V static local variable
2223@end example
2224
899bafeb 2225@node Type Descriptors
e505224d
PB
2226@section Table D: Type Descriptors
2227
2228@example
2229descriptor meaning
2230-------------------------------------
2231(empty) type reference
2232 a array type
2233 e enumeration type
2234 f function type
2235 r range type
2236 s structure type
2237 u union specifications
2238 * pointer type
2239@end example
2240
2241
899bafeb 2242@node Expanded reference
e505224d
PB
2243@appendix Expanded reference by stab type.
2244
2245Format of an entry:
2246
2247The first line is the symbol type expressed in decimal, hexadecimal,
2248and as a #define (see devo/include/aout/stab.def).
2249
2250The second line describes the language constructs the symbol type
2251represents.
2252
2253The third line is the stab format with the significant stab fields
2254named and the rest NIL.
2255
2256Subsequent lines expand upon the meaning and possible values for each
2257significant stab field. # stands in for the type descriptor.
2258
2259Finally, any further information.
2260
899bafeb
RP
2261@menu
2262* N_GSYM:: Global variable
2263* N_FNAME:: Function name (BSD Fortran)
2264* N_FUN:: C Function name or text segment variable
2265* N_STSYM:: Initialized static symbol
2266* N_LCSYM:: Uninitialized static symbol
2267* N_MAIN:: Name of main routine (not for C)
2268* N_PC:: Pascal global symbol
2269* N_NSYMS:: Number of symbols
2270* N_NOMAP:: No DST map
2271* N_RSYM:: Register variable
2272* N_M2C:: Modula-2 compilation unit
2273* N_SLINE:: Line number in text segment
2274* N_DSLINE:: Line number in data segment
2275* N_BSLINE:: Line number in bss segment
2276* N_BROWS:: Path to .cb file for Sun source code browser
2277* N_DEFD:: GNU Modula2 definition module dependency
2278* N_EHDECL:: GNU C++ exception variable
2279* N_MOD2:: Modula2 information "for imc"
2280* N_CATCH:: GNU C++ "catch" clause
2281* N_SSYM:: Structure or union element
2282* N_SO:: Source file containing main
2283* N_LSYM:: Automatic variable
2284* N_BINCL:: Beginning of include file (Sun only)
2285* N_SOL:: Name of include file
2286* N_PSYM:: Parameter variable
2287* N_EINCL:: End of include file
2288* N_ENTRY:: Alternate entry point
2289* N_LBRAC:: Beginning of lexical block
2290* N_EXCL:: Deleted include file
2291* N_SCOPE:: Modula2 scope information (Sun only)
2292* N_RBRAC:: End of lexical block
2293* N_BCOMM:: Begin named common block
2294* N_ECOMM:: End named common block
2295* N_ECOML:: End common
2296* Gould:: non-base register symbols used on Gould systems
2297* N_LENG:: Length of preceding entry
2298@end menu
2299
2300@node N_GSYM
2301@section 32 - 0x20 - N_GYSM
2302
2303@display
e505224d
PB
2304Global variable.
2305
2306.stabs "name", N_GSYM, NIL, NIL, NIL
899bafeb 2307@end display
e505224d 2308
899bafeb 2309@example
e505224d
PB
2310"name" -> "symbol_name:#type"
2311 # -> G
899bafeb 2312@end example
e505224d
PB
2313
2314Only the "name" field is significant. the location of the variable is
2315obtained from the corresponding external symbol.
2316
899bafeb
RP
2317@node N_FNAME
2318@section 34 - 0x22 - N_FNAME
e505224d
PB
2319Function name (for BSD Fortran)
2320
899bafeb 2321@display
e505224d 2322.stabs "name", N_FNAME, NIL, NIL, NIL
899bafeb 2323@end display
e505224d 2324
899bafeb 2325@example
e505224d 2326"name" -> "function_name"
899bafeb 2327@end example
e505224d
PB
2328
2329Only the "name" field is significant. The location of the symbol is
2330obtained from the corresponding extern symbol.
2331
899bafeb
RP
2332@node N_FUN
2333@section 36 - 0x24 - N_FUN
e505224d
PB
2334Function name or text segment variable for C.
2335
899bafeb 2336@display
e505224d 2337.stabs "name", N_FUN, NIL, desc, value
899bafeb 2338@end display
e505224d 2339
899bafeb
RP
2340@example
2341@exdent @emph{For functions:}
e505224d
PB
2342"name" -> "proc_name:#return_type"
2343 # -> F (global function)
2344 f (local function)
2345desc -> line num for proc start. (GCC doesn't set and DBX doesn't miss it.)
2346value -> Code address of proc start.
2347
899bafeb 2348@exdent @emph{For text segment variables:}
e505224d 2349<<How to create one?>>
899bafeb 2350@end example
e505224d 2351
899bafeb
RP
2352@node N_STSYM
2353@section 38 - 0x26 - N_STSYM
e505224d
PB
2354Initialized static symbol (data segment w/internal linkage).
2355
899bafeb 2356@display
e505224d 2357.stabs "name", N_STSYM, NIL, NIL, value
899bafeb 2358@end display
e505224d 2359
899bafeb 2360@example
e505224d
PB
2361"name" -> "symbol_name#type"
2362 # -> S (scope global to compilation unit)
2363 -> V (scope local to a procedure)
2364value -> Data Address
899bafeb 2365@end example
e505224d 2366
899bafeb
RP
2367@node N_LCSYM
2368@section 40 - 0x28 - N_LCSYM
e505224d
PB
2369Unitialized static (.lcomm) symbol(BSS segment w/internal linkage).
2370
899bafeb 2371@display
e505224d 2372.stabs "name", N_LCLSYM, NIL, NIL, value
899bafeb 2373@end display
e505224d 2374
899bafeb 2375@example
e505224d
PB
2376"name" -> "symbol_name#type"
2377 # -> S (scope global to compilation unit)
2378 -> V (scope local to procedure)
2379value -> BSS Address
899bafeb 2380@end example
e505224d 2381
899bafeb
RP
2382@node N_MAIN
2383@section 42 - 0x2a - N_MAIN
e505224d
PB
2384Name of main routine (not used in C)
2385
899bafeb 2386@display
e505224d 2387.stabs "name", N_MAIN, NIL, NIL, NIL
899bafeb 2388@end display
e505224d 2389
899bafeb 2390@example
e505224d 2391"name" -> "name_of_main_routine"
899bafeb 2392@end example
e505224d 2393
899bafeb
RP
2394@node N_PC
2395@section 48 - 0x30 - N_PC
e505224d
PB
2396Global symbol (for Pascal)
2397
899bafeb 2398@display
e505224d 2399.stabs "name", N_PC, NIL, NIL, value
899bafeb 2400@end display
e505224d 2401
899bafeb 2402@example
e505224d
PB
2403"name" -> "symbol_name" <<?>>
2404value -> supposedly the line number (stab.def is skeptical)
899bafeb 2405@end example
e505224d 2406
899bafeb 2407@display
e505224d
PB
2408stabdump.c says:
2409
2410global pascal symbol: name,,0,subtype,line
2411<< subtype? >>
899bafeb 2412@end display
e505224d 2413
899bafeb
RP
2414@node N_NSYMS
2415@section 50 - 0x32 - N_NSYMS
e505224d
PB
2416Number of symbols (according to Ultrix V4.0)
2417
899bafeb 2418@display
e505224d 2419 0, files,,funcs,lines (stab.def)
899bafeb 2420@end display
e505224d 2421
899bafeb
RP
2422@node N_NOMAP
2423@section 52 - 0x34 - N_NOMAP
e505224d
PB
2424no DST map for sym (according to Ultrix V4.0)
2425
899bafeb 2426@display
e505224d 2427 name, ,0,type,ignored (stab.def)
899bafeb
RP
2428@end display
2429
2430@node N_RSYM
2431@section 64 - 0x40 - N_RSYM
e505224d
PB
2432 register variable
2433
899bafeb 2434@display
e505224d 2435.stabs "name:type",N_RSYM,0,RegSize,RegNumber (Sun doc)
899bafeb 2436@end display
e505224d 2437
899bafeb
RP
2438@node N_M2C
2439@section 66 - 0x42 - N_M2C
e505224d
PB
2440Modula-2 compilation unit
2441
899bafeb 2442@display
e505224d 2443.stabs "name", N_M2C, 0, desc, value
899bafeb 2444@end display
e505224d 2445
899bafeb 2446@example
e505224d
PB
2447"name" -> "unit_name,unit_time_stamp[,code_time_stamp]
2448desc -> unit_number
2449value -> 0 (main unit)
2450 1 (any other unit)
899bafeb 2451@end example
e505224d 2452
899bafeb
RP
2453@node N_SLINE
2454@section 68 - 0x44 - N_SLINE
e505224d
PB
2455Line number in text segment
2456
899bafeb 2457@display
e505224d 2458.stabn N_SLINE, 0, desc, value
899bafeb 2459@end display
e505224d 2460
899bafeb 2461@example
e505224d
PB
2462desc -> line_number
2463value -> code_address (relocatable addr where the corresponding code starts)
899bafeb 2464@end example
e505224d
PB
2465
2466For single source lines that generate discontiguous code, such as flow
2467of control statements, there may be more than one N_SLINE stab for the
2468same source line. In this case there is a stab at the start of each
2469code range, each with the same line number.
2470
899bafeb
RP
2471@node N_DSLINE
2472@section 70 - 0x46 - N_DSLINE
e505224d
PB
2473Line number in data segment
2474
899bafeb 2475@display
e505224d 2476.stabn N_DSLINE, 0, desc, value
899bafeb 2477@end display
e505224d 2478
899bafeb 2479@example
e505224d 2480desc -> line_number
899bafeb
RP
2481value -> data_address (relocatable addr where the corresponding code
2482starts)
2483@end example
e505224d
PB
2484
2485See comment for N_SLINE above.
2486
899bafeb
RP
2487@node N_BSLINE
2488@section 72 - 0x48 - N_BSLINE
e505224d
PB
2489Line number in bss segment
2490
899bafeb 2491@display
e505224d 2492.stabn N_BSLINE, 0, desc, value
899bafeb 2493@end display
e505224d 2494
899bafeb 2495@example
e505224d 2496desc -> line_number
899bafeb
RP
2497value -> bss_address (relocatable addr where the corresponding code
2498starts)
2499@end example
e505224d
PB
2500
2501See comment for N_SLINE above.
2502
899bafeb
RP
2503@node N_BROWS
2504@section 72 - 0x48 - N_BROWS
e505224d
PB
2505Sun source code browser, path to .cb file
2506
2507<<?>>
2508"path to associated .cb file"
2509
2510Note: type field value overlaps with N_BSLINE
2511
899bafeb
RP
2512@node N_DEFD
2513@section 74 - 0x4a - N_DEFD
612dbd4c 2514GNU Modula2 definition module dependency
e505224d
PB
2515
2516GNU Modula-2 definition module dependency. Value is the modification
2517time of the definition file. Other is non-zero if it is imported with
2518the GNU M2 keyword %INITIALIZE. Perhaps N_M2C can be used if there
2519are enough empty fields?
2520
899bafeb
RP
2521@node N_EHDECL
2522@section 80 - 0x50 - N_EHDECL
612dbd4c 2523GNU C++ exception variable <<?>>
e505224d
PB
2524
2525"name is variable name"
2526
2527Note: conflicts with N_MOD2.
2528
899bafeb
RP
2529@node N_MOD2
2530@section 80 - 0x50 - N_MOD2
2531Modula2 info "for imc" (according to Ultrix V4.0)
e505224d
PB
2532
2533Note: conflicts with N_EHDECL <<?>>
2534
899bafeb
RP
2535@node N_CATCH
2536@section 84 - 0x54 - N_CATCH
2537GNU C++ "catch" clause
e505224d
PB
2538
2539GNU C++ `catch' clause. Value is its address. Desc is nonzero if
2540this entry is immediately followed by a CAUGHT stab saying what
2541exception was caught. Multiple CAUGHT stabs means that multiple
2542exceptions can be caught here. If Desc is 0, it means all exceptions
2543are caught here.
2544
899bafeb
RP
2545@node N_SSYM
2546@section 96 - 0x60 - N_SSYM
e505224d
PB
2547Structure or union element
2548
899bafeb
RP
2549Value is offset in the structure.
2550
2551<<?looking at structs and unions in C I didn't see these>>
e505224d 2552
899bafeb
RP
2553@node N_SO
2554@section 100 - 0x64 - N_SO
e505224d
PB
2555Path and name of source file containing main routine
2556
899bafeb 2557@display
e505224d 2558.stabs "name", N_SO, NIL, NIL, value
899bafeb 2559@end display
e505224d 2560
899bafeb 2561@example
e505224d
PB
2562"name" -> /path/to/source/file
2563 -> source_file_terminal_name
2564
2565value -> the starting text address of the compilation.
899bafeb 2566@end example
e505224d
PB
2567
2568These are found two in a row. The name field of the first N_SO
2569contains the path to the source file. The name field of the second
2570N_SO contains the terminal name of the source file itself.
2571
899bafeb
RP
2572@node N_LSYM
2573@section 128 - 0x80 - N_LSYM
e505224d
PB
2574Automatic var in the stack (also used for type descriptors.)
2575
899bafeb 2576@display
e505224d 2577.stabs "name" N_LSYM, NIL, NIL, value
899bafeb 2578@end display
e505224d 2579
899bafeb
RP
2580@example
2581@exdent @emph{For stack based local variables:}
e505224d
PB
2582
2583"name" -> name of the variable
2584value -> offset from frame pointer (negative)
2585
899bafeb 2586@exdent @emph{For type descriptors:}
e505224d
PB
2587
2588"name" -> "name_of_the_type:#type"
2589 # -> t
2590
2591type -> type_ref (or) type_def
2592
2593type_ref -> type_number
2594type_def -> type_number=type_desc etc.
899bafeb 2595@end example
e505224d
PB
2596
2597Type may be either a type reference or a type definition. A type
2598reference is a number that refers to a previously defined type. A
2599type definition is the number that will refer to this type, followed
2600by an equals sign, a type descriptor and the additional data that
2601defines the type. See the Table D for type descriptors and the
2602section on types for what data follows each type descriptor.
2603
899bafeb
RP
2604@node N_BINCL
2605@section 130 - 0x82 - N_BINCL
e505224d
PB
2606
2607Beginning of an include file (Sun only)
2608
2609Beginning of an include file. Only Sun uses this. In an object file,
2610only the name is significant. The Sun linker puts data into some of
2611the other fields.
2612
899bafeb
RP
2613@node N_SOL
2614@section 132 - 0x84 - N_SOL
e505224d
PB
2615
2616Name of a sub-source file (#include file). Value is starting address
2617of the compilation.
2618<<?>>
2619
899bafeb
RP
2620@node N_PSYM
2621@section 160 - 0xa0 - N_PSYM
e505224d
PB
2622
2623Parameter variable
2624
899bafeb 2625@display
e505224d 2626stabs. "name", N_PSYM, NIL, NIL, value
899bafeb 2627@end display
e505224d 2628
899bafeb 2629@example
e505224d
PB
2630"name" -> "param_name:#type"
2631 # -> p (value parameter)
2632 -> i (value parameter by reference, indirect access)
2633 -> v (variable parameter by reference)
2634 -> C ( read-only parameter, conformant array bound)
2635 -> x (confomant array value parameter)
2636 -> pP (<<??>>)
2637 -> pF (<<??>>)
2638 -> X (function result variable)
2639 -> b (based variable)
2640
2641value -> offset from the argument pointer (positive).
899bafeb 2642@end example
e505224d
PB
2643
2644On most machines the argument pointer is the same as the frame
2645pointer.
2646
899bafeb
RP
2647@node N_EINCL
2648@section 162 - 0xa2 - N_EINCL
e505224d
PB
2649
2650End of an include file. This and N_BINCL act as brackets around the
2651file's output. In an ojbect file, there is no significant data in
899bafeb 2652this entry. The Sun linker puts data into some of the fields.
e505224d
PB
2653<<?>>
2654
899bafeb
RP
2655@node N_ENTRY
2656@section 164 - 0xa4 - N_ENTRY
e505224d
PB
2657
2658Alternate entry point.
2659Value is its address.
2660<<?>>
2661
899bafeb
RP
2662@node N_LBRAC
2663@section 192 - 0xc0 - N_LBRAC
e505224d
PB
2664
2665Beginning of a lexical block (left brace). The variable defined
2666inside the block precede the N_LBRAC symbol. Or can they follow as
2667well as long as a new N_FUNC was not encountered. <<?>>
2668
899bafeb 2669@display
e505224d 2670.stabn N_LBRAC, NIL, NIL, value
899bafeb 2671@end display
e505224d 2672
899bafeb 2673@example
e505224d 2674value -> code address of block start.
899bafeb 2675@end example
e505224d 2676
899bafeb
RP
2677@node N_EXCL
2678@section 194 - 0xc2 - N_EXCL
e505224d
PB
2679
2680Place holder for a deleted include file. Replaces a N_BINCL and
2681everything up to the corresponding N_EINCL. The Sun linker generates
2682these when it finds multiple indentical copies of the symbols from an
2683included file. This appears only in output from the Sun linker.
2684<<?>>
2685
899bafeb
RP
2686@node N_SCOPE
2687@section 196 - 0xc4 - N_SCOPE
e505224d
PB
2688
2689Modula2 scope information (Sun linker)
2690<<?>>
2691
899bafeb
RP
2692@node N_RBRAC
2693@section 224 - 0xe0 - N_RBRAC
e505224d
PB
2694
2695End of a lexical block (right brace)
2696
899bafeb 2697@display
e505224d 2698.stabn N_RBRAC, NIL, NIL, value
899bafeb 2699@end display
e505224d 2700
899bafeb 2701@example
e505224d 2702value -> code address of the end of the block.
899bafeb 2703@end example
e505224d 2704
899bafeb
RP
2705@node N_BCOMM
2706@section 226 - 0xe2 - N_BCOMM
e505224d
PB
2707
2708Begin named common block.
2709
2710Only the name is significant.
2711<<?>>
2712
899bafeb
RP
2713@node N_ECOMM
2714@section 228 - 0xe4 - N_ECOMM
e505224d
PB
2715
2716End named common block.
2717
2718Only the name is significant and it should match the N_BCOMM
2719<<?>>
2720
899bafeb
RP
2721@node N_ECOML
2722@section 232 - 0xe8 - N_ECOML
e505224d
PB
2723
2724End common (local name)
2725
2726value is address.
2727<<?>>
2728
899bafeb
RP
2729@node Gould
2730@section Non-base registers on Gould systems
e505224d
PB
2731<< used on Gould systems for non-base registers syms, values assigned
2732at random, need real info from Gould. >>
2733<<?>>
2734
899bafeb 2735@example
e505224d
PB
2736240 0xf0 N_NBTEXT ??
2737242 0xf2 N_NBDATA ??
2738244 0xf4 N_NBBSS ??
2739246 0xf6 N_NBSTS ??
2740248 0xf8 N_NBLCS ??
899bafeb 2741@end example
e505224d 2742
899bafeb
RP
2743@node N_LENG
2744@section - 0xfe - N_LENG
e505224d
PB
2745
2746Second symbol entry containing a length-value for the preceding entry.
2747The value is the length.
2748
899bafeb
RP
2749@node Questions
2750@appendix Questions and anomalies
e505224d
PB
2751
2752@itemize @bullet
2753@item
2754For GNU C stabs defining local and global variables (N_LSYM and
2755N_GSYM), the desc field is supposed to contain the source line number
2756on which the variable is defined. In reality the desc field is always
27570. (This behavour is defined in dbxout.c and putting a line number in
2758desc is controlled by #ifdef WINNING_GDB which defaults to false). Gdb
2759supposedly uses this information if you say 'list var'. In reality
2760var can be a variable defined in the program and gdb says `function
2761var not defined'
2762
2763@item
612dbd4c 2764In GNU C stabs there seems to be no way to differentiate tag types:
e505224d
PB
2765structures, unions, and enums (symbol descriptor T) and typedefs
2766(symbol descriptor t) defined at file scope from types defined locally
2767to a procedure or other more local scope. They all use the N_LSYM
2768stab type. Types defined at procedure scope are emited after the
2769N_RBRAC of the preceeding function and before the code of the
2770procedure in which they are defined. This is exactly the same as
2771types defined in the source file between the two procedure bodies.
2772GDB overcompensates by placing all types in block #1 the block for
2773symbols of file scope. This is true for default, -ansi and
2774-traditional compiler options. (p0001063-gcc, p0001066-gdb)
2775
2776@item
2777What ends the procedure scope? Is it the proc block's N_RBRAC or the
2778next N_FUN? (I believe its the first.)
2779
2780@item
2781The comment in xcoff.h says DBX_STATIC_CONST_VAR_CODE is used for
2782static const variables. DBX_STATIC_CONST_VAR_CODE is set to N_FUN by
2783default, in dbxout.c. If included, xcoff.h redefines it to N_STSYM.
2784But testing the default behaviour, my Sun4 native example shows
2785N_STSYM not N_FUN is used to describe file static initialized
2786variables. (the code tests for TREE_READONLY(decl) &&
2787!TREE_THIS_VOLATILE(decl) and if true uses DBX_STATIC_CONST_VAR_CODE).
2788
2789@item
2790Global variable stabs don't have location information. This comes
2791from the external symbol for the same variable. The external symbol
2792has a leading underbar on the _name of the variable and the stab does
2793not. How do we know these two symbol table entries are talking about
2794the same symbol when their names are different?
2795
2796@item
2797Can gcc be configured to output stabs the way the Sun compiler
2798does, so that their native debugging tools work? <NO?> It doesn't by
2799default. GDB reads either format of stab. (gcc or SunC). How about
2800dbx?
2801@end itemize
2802
899bafeb 2803@node xcoff-differences
e505224d
PB
2804@appendix Differences between GNU stabs in a.out and GNU stabs in xcoff
2805
2806(The AIX/RS6000 native object file format is xcoff with stabs)
2807
2808@itemize @bullet
2809@item
2810Instead of .stabs, xcoff uses .stabx.
2811
2812@item
2813The data fields of an xcoff .stabx are in a different order than an
2814a.out .stabs. The order is: string, value, type. The desc and null
2815fields present in a.out stabs are missing in xcoff stabs. For N_GSYM
2816the value field is the name of the symbol.
2817
2818@item
2819BSD a.out stab types map to AIX xcoff storage classes. In general the
2820mapping is N_STABTYPE becomes C_STABTYPE. Some stab types in a.out
2821are not supported in xcoff. See Table E. for full mappings.
2822
2823exception:
2824initialised static N_STSYM and un-initialized static N_LCSYM both map
2825to the C_STSYM storage class. But the destinction is preserved
2826because in xcoff N_STSYM and N_LCSYM must be emited in a named static
2827block. Begin the block with .bs s[RW] data_section_name for N_STSYM
2828or .bs s bss_section_name for N_LCSYM. End the block with .es
2829
2830@item
2831xcoff stabs describing tags and typedefs use the N_DECL (0x8c)instead
2832of N_LSYM stab type.
2833
2834@item
2835xcoff uses N_RPSYM (0x8e) instead of the N_RSYM stab type for register
2836variables. If the register variable is also a value parameter, then
2837use R instead of P for the symbol descriptor.
2838
28396.
2840xcoff uses negative numbers as type references to the basic types.
2841There are no boilerplate type definitions emited for these basic
2842types. << make table of basic types and type numbers for C >>
2843
2844@item
2845xcoff .stabx sometimes don't have the name part of the string field.
2846
2847@item
2848xcoff uses a .file stab type to represent the source file name. There
2849is no stab for the path to the source file.
2850
2851@item
2852xcoff uses a .line stab type to represent source lines. The format
2853is: .line line_number.
2854
2855@item
2856xcoff emits line numbers relative to the start of the current
2857function. The start of a function is marked by .bf. If a function
2858includes lines from a seperate file, then those line numbers are
2859absolute line numbers in the <<sub-?>> file being compiled.
2860
2861@item
2862The start of current include file is marked with: .bi "filename" and
2863the end marked with .ei "filename"
2864
2865@item
2866If the xcoff stab is a N_FUN (C_FUN) then follow the string field with
2867,. instead of just ,
2868
2869@item
2870The symbol descriptor for register parameters is P for a.out and R for
2871xcoff.
2872@end itemize
2873
2874
2875(I think that's it for .s file differences. They could stand to be
2876better presented. This is just a list of what I have noticed so far.
2877There are a *lot* of differences in the information in the symbol
2878tables of the executable and object files.)
2879
2880Table E: mapping a.out stab types to xcoff storage classes
2881
2882@example
2883stab type storage class
2884-------------------------------
2885N_GSYM C_GSYM
2886N_FNAME unknown
2887N_FUN C_FUN
2888N_STSYM C_STSYM
2889N_LCSYM C_STSYM
2890N_MAIN unkown
2891N_PC unknown
2892N_RSYM C_RSYM
2893N_RPSYM (0x8e) C_RPSYM
2894N_M2C unknown
2895N_SLINE unknown
2896N_DSLINE unknown
2897N_BSLINE unknown
2898N_BROWSE unchanged
2899N_CATCH unknown
2900N_SSYM unknown
2901N_SO unknown
2902N_LSYM C_LSYM
2903N_DECL (0x8c) C_DECL
2904N_BINCL unknown
2905N_SOL unknown
2906N_PSYM C_PSYM
2907N_EINCL unknown
2908N_ENTRY C_ENTRY
2909N_LBRAC unknown
2910N_EXCL unknown
2911N_SCOPE unknown
2912N_RBRAC unknown
2913N_BCOMM C_BCOMM
2914N_ECOMM C_ECOMM
2915N_ECOML C_ECOML
2916
2917N_LENG unknown
2918@end example
2919
899bafeb 2920@node Sun-differences
e505224d
PB
2921@appendix Differences between GNU stabs and Sun native stabs.
2922
2923@itemize @bullet
2924@item
612dbd4c 2925GNU C stabs define *all* types, file or procedure scope, as
e505224d
PB
2926N_LSYM. Sun doc talks about using N_GSYM too.
2927
2928@item
612dbd4c 2929GNU C stabs use `ar' as type descriptor when defining arrays vs. just
e505224d
PB
2930`a' in Sun doc.
2931
2932@item
2933Stabs describing block scopes, N_LBRAC and N_RBRAC are supposed to
2934contain the nesting level of the block in the desc field, re Sun doc.
2935GNU stabs always have 0 in that field.
2936
2937@item
2938Sun C stabs use type number pairs in the format (a,b) where a is a
2939number starting with 1 and incremented for each sub-source file in the
2940compilation. b is a number starting with 1 and incremented for each
612dbd4c 2941new type defined in the compilation. GNU C stabs use the type number
e505224d
PB
2942alone, with no source file number.
2943@end itemize
2944
2945@contents
2946@bye
This page took 0.183952 seconds and 4 git commands to generate.