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