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