Commit | Line | Data |
---|---|---|
9a874fe1 C |
1 | /* Output sdb-format symbol table information from GNU compiler. |
2 | Copyright (C) 1988, 1992 Free Software Foundation, Inc. | |
3 | ||
4 | This file is part of GNU CC. | |
5 | ||
6 | GNU CC is free software; you can redistribute it and/or modify | |
7 | it under the terms of the GNU General Public License as published by | |
8 | the Free Software Foundation; either version 2, or (at your option) | |
9 | any later version. | |
10 | ||
11 | GNU CC is distributed in the hope that it will be useful, | |
12 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | GNU General Public License for more details. | |
15 | ||
16 | You should have received a copy of the GNU General Public License | |
17 | along with GNU CC; see the file COPYING. If not, write to | |
18 | the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ | |
19 | ||
20 | /* mike@tredysvr.Tredydev.Unisys.COM says: | |
21 | I modified the struct.c example and have a nm of a .o resulting from the | |
22 | AT&T C compiler. From the example below I would conclude the following: | |
23 | ||
24 | 1. All .defs from structures are emitted as scanned. The example below | |
25 | clearly shows the symbol table entries for BoxRec2 are after the first | |
26 | function. | |
27 | ||
28 | 2. All functions and their locals (including statics) are emitted as scanned. | |
29 | ||
30 | 3. All nested unnamed union and structure .defs must be emitted before | |
31 | the structure in which they are nested. The AT&T assembler is a | |
32 | one pass beast as far as symbolics are concerned. | |
33 | ||
34 | 4. All structure .defs are emitted before the typedefs that refer to them. | |
35 | ||
36 | 5. All top level static and external variable definitions are moved to the | |
37 | end of file with all top level statics occurring first before externs. | |
38 | ||
39 | 6. All undefined references are at the end of the file. | |
40 | */ | |
41 | ||
42 | #include "config.h" | |
43 | ||
44 | #ifdef SDB_DEBUGGING_INFO | |
45 | ||
46 | #include "tree.h" | |
47 | #include "rtl.h" | |
48 | #include <stdio.h> | |
49 | #include "regs.h" | |
50 | #include "flags.h" | |
51 | #include "insn-config.h" | |
52 | #include "reload.h" | |
53 | ||
54 | /* Mips systems use the SDB functions to dump out symbols, but | |
55 | do not supply usable syms.h include files. */ | |
56 | #if defined(USG) && !defined(MIPS) && !defined (hpux) | |
57 | #include <syms.h> | |
58 | /* Use T_INT if we don't have T_VOID. */ | |
59 | #ifndef T_VOID | |
60 | #define T_VOID T_INT | |
61 | #endif | |
62 | #else /* not USG, or MIPS */ | |
63 | #include "gsyms.h" | |
64 | #endif /* not USG, or MIPS */ | |
65 | ||
66 | /* #include <storclass.h> used to be this instead of syms.h. */ | |
67 | ||
68 | /* 1 if PARM is passed to this function in memory. */ | |
69 | ||
70 | #define PARM_PASSED_IN_MEMORY(PARM) \ | |
71 | (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM) | |
72 | ||
73 | /* A C expression for the integer offset value of an automatic variable | |
74 | (C_AUTO) having address X (an RTX). */ | |
75 | #ifndef DEBUGGER_AUTO_OFFSET | |
76 | #define DEBUGGER_AUTO_OFFSET(X) \ | |
77 | (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0) | |
78 | #endif | |
79 | ||
80 | /* A C expression for the integer offset value of an argument (C_ARG) | |
81 | having address X (an RTX). The nominal offset is OFFSET. */ | |
82 | #ifndef DEBUGGER_ARG_OFFSET | |
83 | #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET) | |
84 | #endif | |
85 | ||
86 | /* Line number of beginning of current function, minus one. | |
87 | Negative means not in a function or not using sdb. */ | |
88 | ||
89 | int sdb_begin_function_line = -1; | |
90 | ||
91 | /* Counter to generate unique "names" for nameless struct members. */ | |
92 | ||
93 | static int unnamed_struct_number = 0; | |
94 | ||
95 | extern FILE *asm_out_file; | |
96 | ||
97 | extern tree current_function_decl; | |
98 | ||
99 | void sdbout_init (); | |
100 | void sdbout_symbol (); | |
101 | void sdbout_types(); | |
102 | ||
103 | static void sdbout_typedefs (); | |
104 | static void sdbout_syms (); | |
105 | static void sdbout_one_type (); | |
106 | static void sdbout_queue_anonymous_type (); | |
107 | static void sdbout_dequeue_anonymous_types (); | |
108 | static int plain_type_1 (); | |
109 | \f | |
110 | /* Define the default sizes for various types. */ | |
111 | ||
112 | #ifndef CHAR_TYPE_SIZE | |
113 | #define CHAR_TYPE_SIZE BITS_PER_UNIT | |
114 | #endif | |
115 | ||
116 | #ifndef SHORT_TYPE_SIZE | |
117 | #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2)) | |
118 | #endif | |
119 | ||
120 | #ifndef INT_TYPE_SIZE | |
121 | #define INT_TYPE_SIZE BITS_PER_WORD | |
122 | #endif | |
123 | ||
124 | #ifndef LONG_TYPE_SIZE | |
125 | #define LONG_TYPE_SIZE BITS_PER_WORD | |
126 | #endif | |
127 | ||
128 | #ifndef LONG_LONG_TYPE_SIZE | |
129 | #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) | |
130 | #endif | |
131 | ||
132 | #ifndef FLOAT_TYPE_SIZE | |
133 | #define FLOAT_TYPE_SIZE BITS_PER_WORD | |
134 | #endif | |
135 | ||
136 | #ifndef DOUBLE_TYPE_SIZE | |
137 | #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
138 | #endif | |
139 | ||
140 | #ifndef LONG_DOUBLE_TYPE_SIZE | |
141 | #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) | |
142 | #endif | |
143 | \f | |
144 | /* Random macros describing parts of SDB data. */ | |
145 | ||
146 | /* Put something here if lines get too long */ | |
147 | #define CONTIN | |
148 | ||
149 | /* Default value of delimiter is ";". */ | |
150 | #ifndef SDB_DELIM | |
151 | #define SDB_DELIM ";" | |
152 | #endif | |
153 | ||
154 | /* Maximum number of dimensions the assembler will allow. */ | |
155 | #ifndef SDB_MAX_DIM | |
156 | #define SDB_MAX_DIM 4 | |
157 | #endif | |
158 | ||
159 | #ifndef PUT_SDB_SCL | |
160 | #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM) | |
161 | #endif | |
162 | ||
163 | #ifndef PUT_SDB_INT_VAL | |
164 | #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM) | |
165 | #endif | |
166 | ||
167 | #ifndef PUT_SDB_VAL | |
168 | #define PUT_SDB_VAL(a) \ | |
169 | ( fputs ("\t.val\t", asm_out_file), \ | |
170 | output_addr_const (asm_out_file, (a)), \ | |
171 | fprintf (asm_out_file, SDB_DELIM)) | |
172 | #endif | |
173 | ||
174 | #ifndef PUT_SDB_DEF | |
175 | #define PUT_SDB_DEF(a) \ | |
176 | do { fprintf (asm_out_file, "\t.def\t"); \ | |
177 | ASM_OUTPUT_LABELREF (asm_out_file, a); \ | |
178 | fprintf (asm_out_file, SDB_DELIM); } while (0) | |
179 | #endif | |
180 | ||
181 | #ifndef PUT_SDB_PLAIN_DEF | |
182 | #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM) | |
183 | #endif | |
184 | ||
185 | #ifndef PUT_SDB_ENDEF | |
186 | #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file) | |
187 | #endif | |
188 | ||
189 | #ifndef PUT_SDB_TYPE | |
190 | #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM) | |
191 | #endif | |
192 | ||
193 | #ifndef PUT_SDB_SIZE | |
194 | #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM) | |
195 | #endif | |
196 | ||
197 | #ifndef PUT_SDB_START_DIM | |
198 | #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t") | |
199 | #endif | |
200 | ||
201 | #ifndef PUT_SDB_NEXT_DIM | |
202 | #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a) | |
203 | #endif | |
204 | ||
205 | #ifndef PUT_SDB_LAST_DIM | |
206 | #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM) | |
207 | #endif | |
208 | ||
209 | #ifndef PUT_SDB_TAG | |
210 | #define PUT_SDB_TAG(a) \ | |
211 | do { fprintf (asm_out_file, "\t.tag\t"); \ | |
212 | ASM_OUTPUT_LABELREF (asm_out_file, a); \ | |
213 | fprintf (asm_out_file, SDB_DELIM); } while (0) | |
214 | #endif | |
215 | ||
216 | #ifndef PUT_SDB_BLOCK_START | |
217 | #define PUT_SDB_BLOCK_START(LINE) \ | |
218 | fprintf (asm_out_file, \ | |
219 | "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \ | |
220 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
221 | #endif | |
222 | ||
223 | #ifndef PUT_SDB_BLOCK_END | |
224 | #define PUT_SDB_BLOCK_END(LINE) \ | |
225 | fprintf (asm_out_file, \ | |
226 | "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \ | |
227 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
228 | #endif | |
229 | ||
230 | #ifndef PUT_SDB_FUNCTION_START | |
231 | #define PUT_SDB_FUNCTION_START(LINE) \ | |
232 | fprintf (asm_out_file, \ | |
233 | "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \ | |
234 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
235 | #endif | |
236 | ||
237 | #ifndef PUT_SDB_FUNCTION_END | |
238 | #define PUT_SDB_FUNCTION_END(LINE) \ | |
239 | fprintf (asm_out_file, \ | |
240 | "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \ | |
241 | SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM) | |
242 | #endif | |
243 | ||
244 | #ifndef PUT_SDB_EPILOGUE_END | |
245 | #define PUT_SDB_EPILOGUE_END(NAME) \ | |
246 | do { fprintf (asm_out_file, "\t.def\t"); \ | |
247 | ASM_OUTPUT_LABELREF (asm_out_file, NAME); \ | |
248 | fprintf (asm_out_file, \ | |
249 | "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \ | |
250 | SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0) | |
251 | #endif | |
252 | ||
253 | #ifndef SDB_GENERATE_FAKE | |
254 | #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \ | |
255 | sprintf ((BUFFER), ".%dfake", (NUMBER)); | |
256 | #endif | |
257 | ||
258 | /* Return the sdb tag identifier string for TYPE | |
259 | if TYPE has already been defined; otherwise return a null pointer. */ | |
260 | ||
261 | #define KNOWN_TYPE_TAG(type) (char *)(TYPE_SYMTAB_ADDRESS (type)) | |
262 | ||
263 | /* Set the sdb tag identifier string for TYPE to NAME. */ | |
264 | ||
265 | #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \ | |
266 | (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(NAME)) | |
267 | ||
268 | /* Return the name (a string) of the struct, union or enum tag | |
269 | described by the TREE_LIST node LINK. This is 0 for an anonymous one. */ | |
270 | ||
271 | #define TAG_NAME(link) \ | |
272 | (((link) && TREE_PURPOSE ((link)) \ | |
273 | && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \ | |
274 | ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0) | |
275 | ||
276 | /* Ensure we don't output a negative line number. */ | |
277 | #define MAKE_LINE_SAFE(line) \ | |
278 | if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1 | |
279 | \f | |
280 | /* Set up for SDB output at the start of compilation. */ | |
281 | ||
282 | void | |
283 | sdbout_init (asm_file, input_file_name, syms) | |
284 | FILE *asm_file; | |
285 | char *input_file_name; | |
286 | tree syms; | |
287 | { | |
288 | #if 0 /* Nothing need be output for the predefined types. */ | |
289 | /* Get all permanent types that have typedef names, | |
290 | and output them all, except for those already output. */ | |
291 | ||
292 | sdbout_typedefs (syms); | |
293 | #endif | |
294 | } | |
295 | ||
296 | #if 0 | |
297 | ||
298 | /* return the tag identifier for type | |
299 | */ | |
300 | ||
301 | char * | |
302 | tag_of_ru_type (type,link) | |
303 | tree type,link; | |
304 | { | |
305 | if (TYPE_SYMTAB_ADDRESS (type)) | |
306 | return (char *)TYPE_SYMTAB_ADDRESS (type); | |
307 | if (link && TREE_PURPOSE (link) | |
308 | && IDENTIFIER_POINTER (TREE_PURPOSE (link))) | |
309 | TYPE_SYMTAB_ADDRESS (type) | |
310 | = (int)IDENTIFIER_POINTER (TREE_PURPOSE (link)); | |
311 | else | |
312 | return (char *) TYPE_SYMTAB_ADDRESS (type); | |
313 | } | |
314 | #endif | |
315 | ||
316 | /* Return a unique string to name an anonymous type. */ | |
317 | ||
318 | static char * | |
319 | gen_fake_label () | |
320 | { | |
321 | char label[10]; | |
322 | char *labelstr; | |
323 | SDB_GENERATE_FAKE (label, unnamed_struct_number); | |
324 | unnamed_struct_number++; | |
325 | labelstr = (char *) permalloc (strlen (label) + 1); | |
326 | strcpy (labelstr, label); | |
327 | return labelstr; | |
328 | } | |
329 | \f | |
330 | /* Return the number which describes TYPE for SDB. | |
331 | For pointers, etc., this function is recursive. | |
332 | Each record, union or enumeral type must already have had a | |
333 | tag number output. */ | |
334 | ||
335 | /* The number is given by d6d5d4d3d2d1bbbb | |
336 | where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array. | |
337 | Thus, char *foo () has bbbb=T_CHAR | |
338 | d1=D_FCN | |
339 | d2=D_PTR | |
340 | N_BTMASK= 017 1111 basic type field. | |
341 | N_TSHIFT= 2 derived type shift | |
342 | N_BTSHFT= 4 Basic type shift */ | |
343 | ||
344 | /* Produce the number that describes a pointer, function or array type. | |
345 | PREV is the number describing the target, value or element type. | |
346 | DT_type describes how to transform that type. */ | |
347 | #define PUSH_DERIVED_LEVEL(DT_type,PREV) \ | |
348 | ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK)) | |
349 | ||
350 | /* Number of elements used in sdb_dims. */ | |
351 | static int sdb_n_dims = 0; | |
352 | ||
353 | /* Table of array dimensions of current type. */ | |
354 | static int sdb_dims[SDB_MAX_DIM]; | |
355 | ||
356 | /* Size of outermost array currently being processed. */ | |
357 | static int sdb_type_size = -1; | |
358 | ||
359 | static int | |
360 | plain_type (type) | |
361 | tree type; | |
362 | { | |
363 | int val = plain_type_1 (type); | |
364 | ||
365 | /* If we have already saved up some array dimensions, print them now. */ | |
366 | if (sdb_n_dims > 0) | |
367 | { | |
368 | int i; | |
369 | PUT_SDB_START_DIM; | |
370 | for (i = sdb_n_dims - 1; i > 0; i--) | |
371 | PUT_SDB_NEXT_DIM (sdb_dims[i]); | |
372 | PUT_SDB_LAST_DIM (sdb_dims[0]); | |
373 | sdb_n_dims = 0; | |
374 | ||
375 | sdb_type_size = int_size_in_bytes (type); | |
376 | /* Don't kill sdb if type is not laid out or has variable size. */ | |
377 | if (sdb_type_size < 0) | |
378 | sdb_type_size = 0; | |
379 | } | |
380 | /* If we have computed the size of an array containing this type, | |
381 | print it now. */ | |
382 | if (sdb_type_size >= 0) | |
383 | { | |
384 | PUT_SDB_SIZE (sdb_type_size); | |
385 | sdb_type_size = -1; | |
386 | } | |
387 | return val; | |
388 | } | |
389 | ||
390 | static int | |
391 | template_name_p (name) | |
392 | tree name; | |
393 | { | |
394 | register char *ptr = IDENTIFIER_POINTER (name); | |
395 | while (*ptr && *ptr != '<') | |
396 | ptr++; | |
397 | ||
398 | return *ptr != '\0'; | |
399 | } | |
400 | ||
401 | static void | |
402 | sdbout_record_type_name (type) | |
403 | tree type; | |
404 | { | |
405 | char *name = 0; | |
406 | int no_name; | |
407 | ||
408 | if (KNOWN_TYPE_TAG (type)) | |
409 | return; | |
410 | ||
411 | if (TYPE_NAME (type) != 0) | |
412 | { | |
413 | tree t = 0; | |
414 | /* Find the IDENTIFIER_NODE for the type name. */ | |
415 | if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) | |
416 | { | |
417 | t = TYPE_NAME (type); | |
418 | } | |
419 | #if 1 /* As a temprary hack, use typedef names for C++ only. */ | |
420 | else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL | |
421 | && TYPE_LANG_SPECIFIC (type)) | |
422 | { | |
423 | t = DECL_NAME (TYPE_NAME (type)); | |
424 | /* The DECL_NAME for templates includes "<>", which breaks | |
425 | most assemblers. Use its assembler name instead, which | |
426 | has been mangled into being safe. */ | |
427 | if (t && template_name_p (t)) | |
428 | t = DECL_ASSEMBLER_NAME (TYPE_NAME (type)); | |
429 | } | |
430 | #endif | |
431 | ||
432 | /* Now get the name as a string, or invent one. */ | |
433 | if (t != NULL_TREE) | |
434 | name = IDENTIFIER_POINTER (t); | |
435 | } | |
436 | ||
437 | no_name = (name == 0 || *name == 0); | |
438 | if (no_name) | |
439 | name = gen_fake_label (); | |
440 | ||
441 | SET_KNOWN_TYPE_TAG (type, name); | |
442 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
443 | if (no_name) | |
444 | sdbout_queue_anonymous_type (type); | |
445 | #endif | |
446 | } | |
447 | ||
448 | static int | |
449 | plain_type_1 (type) | |
450 | tree type; | |
451 | { | |
452 | if (type == 0) | |
453 | type = void_type_node; | |
454 | if (type == error_mark_node) | |
455 | type = integer_type_node; | |
456 | type = TYPE_MAIN_VARIANT (type); | |
457 | ||
458 | switch (TREE_CODE (type)) | |
459 | { | |
460 | case VOID_TYPE: | |
461 | return T_VOID; | |
462 | case INTEGER_TYPE: | |
463 | { | |
464 | int size = int_size_in_bytes (type) * BITS_PER_UNIT; | |
465 | if (size == CHAR_TYPE_SIZE) | |
466 | return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR); | |
467 | if (size == SHORT_TYPE_SIZE) | |
468 | return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT); | |
469 | if (size == INT_TYPE_SIZE) | |
470 | return (TREE_UNSIGNED (type) ? T_UINT : T_INT); | |
471 | if (size == LONG_TYPE_SIZE) | |
472 | return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG); | |
473 | return 0; | |
474 | } | |
475 | ||
476 | case REAL_TYPE: | |
477 | { | |
478 | int size = int_size_in_bytes (type) * BITS_PER_UNIT; | |
479 | if (size == FLOAT_TYPE_SIZE) | |
480 | return T_FLOAT; | |
481 | if (size == DOUBLE_TYPE_SIZE) | |
482 | return T_DOUBLE; | |
483 | return 0; | |
484 | } | |
485 | ||
486 | case ARRAY_TYPE: | |
487 | { | |
488 | int m; | |
489 | m = plain_type_1 (TREE_TYPE (type)); | |
490 | if (sdb_n_dims < SDB_MAX_DIM) | |
491 | sdb_dims[sdb_n_dims++] | |
492 | = (TYPE_DOMAIN (type) | |
493 | ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1 | |
494 | : 0); | |
495 | return PUSH_DERIVED_LEVEL (DT_ARY, m); | |
496 | } | |
497 | ||
498 | case RECORD_TYPE: | |
499 | case UNION_TYPE: | |
500 | case ENUMERAL_TYPE: | |
501 | { | |
502 | char *tag; | |
503 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
504 | sdbout_record_type_name (type); | |
505 | #endif | |
506 | #ifndef SDB_ALLOW_UNKNOWN_REFERENCES | |
507 | if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0) | |
508 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
509 | || TYPE_MODE (type) != VOIDmode | |
510 | #endif | |
511 | ) | |
512 | #endif | |
513 | { | |
514 | /* Output the referenced structure tag name | |
515 | only if the .def has already been finished. | |
516 | At least on 386, the Unix assembler | |
517 | cannot handle forward references to tags. */ | |
518 | /* But the 88100, it requires them, sigh... */ | |
519 | /* And the MIPS requires unknown refs as well... */ | |
520 | tag = KNOWN_TYPE_TAG (type); | |
521 | PUT_SDB_TAG (tag); | |
522 | /* These 3 lines used to follow the close brace. | |
523 | However, a size of 0 without a tag implies a tag of 0, | |
524 | so if we don't know a tag, we can't mention the size. */ | |
525 | sdb_type_size = int_size_in_bytes (type); | |
526 | if (sdb_type_size < 0) | |
527 | sdb_type_size = 0; | |
528 | } | |
529 | return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT | |
530 | : (TREE_CODE (type) == UNION_TYPE) ? T_UNION | |
531 | : T_ENUM); | |
532 | } | |
533 | case POINTER_TYPE: | |
534 | case REFERENCE_TYPE: | |
535 | { | |
536 | int m = plain_type_1 (TREE_TYPE (type)); | |
537 | return PUSH_DERIVED_LEVEL (DT_PTR, m); | |
538 | } | |
539 | case FUNCTION_TYPE: | |
540 | case METHOD_TYPE: | |
541 | { | |
542 | int m = plain_type_1 (TREE_TYPE (type)); | |
543 | return PUSH_DERIVED_LEVEL (DT_FCN, m); | |
544 | } | |
545 | default: | |
546 | return 0; | |
547 | } | |
548 | } | |
549 | \f | |
550 | /* Output the symbols defined in block number DO_BLOCK. | |
551 | Set NEXT_BLOCK_NUMBER to 0 before calling. | |
552 | ||
553 | This function works by walking the tree structure of blocks, | |
554 | counting blocks until it finds the desired block. */ | |
555 | ||
556 | static int do_block = 0; | |
557 | ||
558 | static int next_block_number; | |
559 | ||
560 | static void | |
561 | sdbout_block (block) | |
562 | register tree block; | |
563 | { | |
564 | while (block) | |
565 | { | |
566 | /* Ignore blocks never expanded or otherwise marked as real. */ | |
567 | if (TREE_USED (block)) | |
568 | { | |
569 | /* When we reach the specified block, output its symbols. */ | |
570 | if (next_block_number == do_block) | |
571 | { | |
572 | sdbout_syms (BLOCK_VARS (block)); | |
573 | } | |
574 | ||
575 | /* If we are past the specified block, stop the scan. */ | |
576 | if (next_block_number > do_block) | |
577 | return; | |
578 | ||
579 | next_block_number++; | |
580 | ||
581 | /* Scan the blocks within this block. */ | |
582 | sdbout_block (BLOCK_SUBBLOCKS (block)); | |
583 | } | |
584 | ||
585 | block = BLOCK_CHAIN (block); | |
586 | } | |
587 | } | |
588 | \f | |
589 | /* Call sdbout_symbol on each decl in the chain SYMS. */ | |
590 | ||
591 | static void | |
592 | sdbout_syms (syms) | |
593 | tree syms; | |
594 | { | |
595 | while (syms) | |
596 | { | |
597 | if (TREE_CODE (syms) != LABEL_DECL) | |
598 | sdbout_symbol (syms, 1); | |
599 | syms = TREE_CHAIN (syms); | |
600 | } | |
601 | } | |
602 | ||
603 | /* Output SDB information for a symbol described by DECL. | |
604 | LOCAL is nonzero if the symbol is not file-scope. */ | |
605 | ||
606 | void | |
607 | sdbout_symbol (decl, local) | |
608 | tree decl; | |
609 | int local; | |
610 | { | |
611 | int letter = 0; | |
612 | tree type = TREE_TYPE (decl); | |
613 | tree context = NULL_TREE; | |
614 | rtx value; | |
615 | int regno = -1; | |
616 | char *name; | |
617 | ||
618 | sdbout_one_type (type); | |
619 | ||
620 | #if 0 /* This loses when functions are marked to be ignored, | |
621 | which happens in the C++ front end. */ | |
622 | if (DECL_IGNORED_P (decl)) | |
623 | return; | |
624 | #endif | |
625 | ||
626 | switch (TREE_CODE (decl)) | |
627 | { | |
628 | case CONST_DECL: | |
629 | /* Enum values are defined by defining the enum type. */ | |
630 | return; | |
631 | ||
632 | case FUNCTION_DECL: | |
633 | /* Don't mention a nested function under its parent. */ | |
634 | context = decl_function_context (decl); | |
635 | if (context == current_function_decl) | |
636 | return; | |
637 | if (DECL_EXTERNAL (decl)) | |
638 | return; | |
639 | if (GET_CODE (DECL_RTL (decl)) != MEM | |
640 | || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF) | |
641 | return; | |
642 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
643 | PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0)); | |
644 | PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT); | |
645 | break; | |
646 | ||
647 | case TYPE_DECL: | |
648 | /* Done with tagged types. */ | |
649 | if (DECL_NAME (decl) == 0) | |
650 | return; | |
651 | if (DECL_IGNORED_P (decl)) | |
652 | return; | |
653 | ||
654 | /* Output typedef name. */ | |
655 | if (template_name_p (DECL_NAME (decl))) | |
656 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
657 | else | |
658 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl))); | |
659 | PUT_SDB_SCL (C_TPDEF); | |
660 | break; | |
661 | ||
662 | case PARM_DECL: | |
663 | /* Parm decls go in their own separate chains | |
664 | and are output by sdbout_reg_parms and sdbout_parms. */ | |
665 | abort (); | |
666 | ||
667 | case VAR_DECL: | |
668 | /* Don't mention a variable that is external. | |
669 | Let the file that defines it describe it. */ | |
670 | if (DECL_EXTERNAL (decl)) | |
671 | return; | |
672 | ||
673 | /* Ignore __FUNCTION__, etc. */ | |
674 | if (DECL_IGNORED_P (decl)) | |
675 | return; | |
676 | ||
677 | /* If there was an error in the declaration, don't dump core | |
678 | if there is no RTL associated with the variable doesn't | |
679 | exist. */ | |
680 | if (DECL_RTL (decl) == 0) | |
681 | return; | |
682 | ||
683 | DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX); | |
684 | #ifdef LEAF_REG_REMAP | |
685 | if (leaf_function) | |
686 | leaf_renumber_regs_insn (DECL_RTL (decl)); | |
687 | #endif | |
688 | value = DECL_RTL (decl); | |
689 | ||
690 | /* Don't mention a variable at all | |
691 | if it was completely optimized into nothingness. | |
692 | ||
693 | If DECL was from an inline function, then its rtl | |
694 | is not identically the rtl that was used in this | |
695 | particular compilation. */ | |
696 | if (GET_CODE (value) == REG) | |
697 | { | |
698 | regno = REGNO (DECL_RTL (decl)); | |
699 | if (regno >= FIRST_PSEUDO_REGISTER) | |
700 | return; | |
701 | } | |
702 | else if (GET_CODE (value) == SUBREG) | |
703 | { | |
704 | int offset = 0; | |
705 | while (GET_CODE (value) == SUBREG) | |
706 | { | |
707 | offset += SUBREG_WORD (value); | |
708 | value = SUBREG_REG (value); | |
709 | } | |
710 | if (GET_CODE (value) == REG) | |
711 | { | |
712 | regno = REGNO (value); | |
713 | if (regno >= FIRST_PSEUDO_REGISTER) | |
714 | return; | |
715 | regno += offset; | |
716 | } | |
717 | alter_subreg (DECL_RTL (decl)); | |
718 | value = DECL_RTL (decl); | |
719 | } | |
720 | ||
721 | /* Emit any structure, union, or enum type that has not been output. | |
722 | This occurs for tag-less structs (et al) used to declare variables | |
723 | within functions. */ | |
724 | if (TREE_CODE (type) == ENUMERAL_TYPE | |
725 | || TREE_CODE (type) == RECORD_TYPE | |
726 | || TREE_CODE (type) == UNION_TYPE) | |
727 | { | |
728 | if (TYPE_SIZE (type) != 0 /* not a forward reference */ | |
729 | && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */ | |
730 | sdbout_one_type (type); | |
731 | } | |
732 | ||
733 | /* Defer SDB information for top-level initialized variables! */ | |
734 | if (! local | |
735 | && GET_CODE (value) == MEM | |
736 | && DECL_INITIAL (decl)) | |
737 | return; | |
738 | ||
739 | /* C++ in 2.3 makes nameless symbols. That will be fixed later. | |
740 | For now, avoid crashing. */ | |
741 | if (DECL_NAME (decl) == NULL_TREE) | |
742 | return; | |
743 | ||
744 | /* Record the name for, starting a symtab entry. */ | |
745 | name = IDENTIFIER_POINTER (DECL_NAME (decl)); | |
746 | ||
747 | if (GET_CODE (value) == MEM | |
748 | && GET_CODE (XEXP (value, 0)) == SYMBOL_REF) | |
749 | { | |
750 | PUT_SDB_DEF (name); | |
751 | if (TREE_PUBLIC (decl)) | |
752 | { | |
753 | PUT_SDB_VAL (XEXP (value, 0)); | |
754 | PUT_SDB_SCL (C_EXT); | |
755 | } | |
756 | else | |
757 | { | |
758 | PUT_SDB_VAL (XEXP (value, 0)); | |
759 | PUT_SDB_SCL (C_STAT); | |
760 | } | |
761 | } | |
762 | else if (regno >= 0) | |
763 | { | |
764 | PUT_SDB_DEF (name); | |
765 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno)); | |
766 | PUT_SDB_SCL (C_REG); | |
767 | } | |
768 | else if (GET_CODE (value) == MEM | |
769 | && (GET_CODE (XEXP (value, 0)) == MEM | |
770 | || (GET_CODE (XEXP (value, 0)) == REG | |
771 | && REGNO (XEXP (value, 0)) != FRAME_POINTER_REGNUM | |
772 | && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM))) | |
773 | /* If the value is indirect by memory or by a register | |
774 | that isn't the frame pointer | |
775 | then it means the object is variable-sized and address through | |
776 | that register or stack slot. COFF has no way to represent this | |
777 | so all we can do is output the variable as a pointer. */ | |
778 | { | |
779 | PUT_SDB_DEF (name); | |
780 | if (GET_CODE (XEXP (value, 0)) == REG) | |
781 | { | |
782 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0)))); | |
783 | PUT_SDB_SCL (C_REG); | |
784 | } | |
785 | else | |
786 | { | |
787 | /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) | |
788 | (CONST_INT...)))). | |
789 | We want the value of that CONST_INT. */ | |
790 | /* Encore compiler hates a newline in a macro arg, it seems. */ | |
791 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET | |
792 | (XEXP (XEXP (value, 0), 0))); | |
793 | PUT_SDB_SCL (C_AUTO); | |
794 | } | |
795 | ||
796 | type = build_pointer_type (TREE_TYPE (decl)); | |
797 | } | |
798 | else if (GET_CODE (value) == MEM | |
799 | && GET_CODE (XEXP (value, 0)) == PLUS | |
800 | && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG | |
801 | && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT) | |
802 | { | |
803 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))). | |
804 | We want the value of that CONST_INT. */ | |
805 | PUT_SDB_DEF (name); | |
806 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0))); | |
807 | PUT_SDB_SCL (C_AUTO); | |
808 | } | |
809 | else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST) | |
810 | { | |
811 | /* Handle an obscure case which can arise when optimizing and | |
812 | when there are few available registers. (This is *always* | |
813 | the case for i386/i486 targets). The DECL_RTL looks like | |
814 | (MEM (CONST ...)) even though this variable is a local `auto' | |
815 | or a local `register' variable. In effect, what has happened | |
816 | is that the reload pass has seen that all assignments and | |
817 | references for one such a local variable can be replaced by | |
818 | equivalent assignments and references to some static storage | |
819 | variable, thereby avoiding the need for a register. In such | |
820 | cases we're forced to lie to debuggers and tell them that | |
821 | this variable was itself `static'. */ | |
822 | PUT_SDB_DEF (name); | |
823 | PUT_SDB_VAL (XEXP (XEXP (value, 0), 0)); | |
824 | PUT_SDB_SCL (C_STAT); | |
825 | } | |
826 | else | |
827 | { | |
828 | /* It is something we don't know how to represent for SDB. */ | |
829 | return; | |
830 | } | |
831 | break; | |
832 | } | |
833 | PUT_SDB_TYPE (plain_type (type)); | |
834 | PUT_SDB_ENDEF; | |
835 | } | |
836 | \f | |
837 | /* Output SDB information for a top-level initialized variable | |
838 | that has been delayed. */ | |
839 | ||
840 | void | |
841 | sdbout_toplevel_data (decl) | |
842 | tree decl; | |
843 | { | |
844 | tree type = TREE_TYPE (decl); | |
845 | ||
846 | if (DECL_IGNORED_P (decl)) | |
847 | return; | |
848 | ||
849 | if (! (TREE_CODE (decl) == VAR_DECL | |
850 | && GET_CODE (DECL_RTL (decl)) == MEM | |
851 | && DECL_INITIAL (decl))) | |
852 | abort (); | |
853 | ||
854 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); | |
855 | PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0)); | |
856 | if (TREE_PUBLIC (decl)) | |
857 | { | |
858 | PUT_SDB_SCL (C_EXT); | |
859 | } | |
860 | else | |
861 | { | |
862 | PUT_SDB_SCL (C_STAT); | |
863 | } | |
864 | PUT_SDB_TYPE (plain_type (type)); | |
865 | PUT_SDB_ENDEF; | |
866 | } | |
867 | \f | |
868 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
869 | ||
870 | /* Machinery to record and output anonymous types. */ | |
871 | ||
872 | static tree anonymous_types; | |
873 | ||
874 | static void | |
875 | sdbout_queue_anonymous_type (type) | |
876 | tree type; | |
877 | { | |
878 | anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types); | |
879 | } | |
880 | ||
881 | static void | |
882 | sdbout_dequeue_anonymous_types () | |
883 | { | |
884 | register tree types, link; | |
885 | ||
886 | while (anonymous_types) | |
887 | { | |
888 | types = nreverse (anonymous_types); | |
889 | anonymous_types = NULL_TREE; | |
890 | ||
891 | for (link = types; link; link = TREE_CHAIN (link)) | |
892 | { | |
893 | register tree type = TREE_VALUE (link); | |
894 | ||
895 | if (type && ! TREE_ASM_WRITTEN (type)) | |
896 | sdbout_one_type (type); | |
897 | } | |
898 | } | |
899 | } | |
900 | ||
901 | #endif | |
902 | \f | |
903 | /* Given a chain of ..._TYPE nodes, all of which have names, | |
904 | output definitions of those names, as typedefs. */ | |
905 | ||
906 | void | |
907 | sdbout_types (types) | |
908 | register tree types; | |
909 | { | |
910 | register tree link; | |
911 | ||
912 | for (link = types; link; link = TREE_CHAIN (link)) | |
913 | sdbout_one_type (link); | |
914 | ||
915 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
916 | sdbout_dequeue_anonymous_types (); | |
917 | #endif | |
918 | } | |
919 | ||
920 | static void | |
921 | sdbout_type (type) | |
922 | tree type; | |
923 | { | |
924 | register tree tem; | |
925 | if (type == error_mark_node) | |
926 | type = integer_type_node; | |
927 | PUT_SDB_TYPE (plain_type (type)); | |
928 | } | |
929 | ||
930 | /* Output types of the fields of type TYPE, if they are structs. | |
931 | ||
932 | Formerly did not chase through pointer types, since that could be circular. | |
933 | They must come before TYPE, since forward refs are not allowed. | |
934 | Now james@bigtex.cactus.org says to try them. */ | |
935 | ||
936 | static void | |
937 | sdbout_field_types (type) | |
938 | tree type; | |
939 | { | |
940 | tree tail; | |
941 | for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail)) | |
942 | if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE) | |
943 | sdbout_one_type (TREE_TYPE (TREE_TYPE (tail))); | |
944 | else | |
945 | sdbout_one_type (TREE_TYPE (tail)); | |
946 | } | |
947 | ||
948 | /* Use this to put out the top level defined record and union types | |
949 | for later reference. If this is a struct with a name, then put that | |
950 | name out. Other unnamed structs will have .xxfake labels generated so | |
951 | that they may be referred to later. | |
952 | The label will be stored in the KNOWN_TYPE_TAG slot of a type. | |
953 | It may NOT be called recursively. */ | |
954 | ||
955 | static void | |
956 | sdbout_one_type (type) | |
957 | tree type; | |
958 | { | |
959 | text_section (); | |
960 | ||
961 | switch (TREE_CODE (type)) | |
962 | { | |
963 | case RECORD_TYPE: | |
964 | case UNION_TYPE: | |
965 | case ENUMERAL_TYPE: | |
966 | type = TYPE_MAIN_VARIANT (type); | |
967 | /* Don't output a type twice. */ | |
968 | if (TREE_ASM_WRITTEN (type)) | |
969 | /* James said test TREE_ASM_BEING_WRITTEN here. */ | |
970 | return; | |
971 | ||
972 | /* Output nothing if type is not yet defined. */ | |
973 | if (TYPE_SIZE (type) == 0) | |
974 | return; | |
975 | ||
976 | TREE_ASM_WRITTEN (type) = 1; | |
977 | #if 1 | |
978 | /* This is reputed to cause trouble with the following case, | |
979 | but perhaps checking TYPE_SIZE above will fix it. */ | |
980 | ||
981 | /* Here is a test case: | |
982 | ||
983 | struct foo { | |
984 | struct badstr *bbb; | |
985 | } forwardref; | |
986 | ||
987 | typedef struct intermediate { | |
988 | int aaaa; | |
989 | } intermediate_ref; | |
990 | ||
991 | typedef struct badstr { | |
992 | int ccccc; | |
993 | } badtype; */ | |
994 | ||
995 | #if 0 | |
996 | TREE_ASM_BEING_WRITTEN (type) = 1; | |
997 | #endif | |
998 | /* This change, which ought to make better output, | |
999 | used to make the COFF assembler unhappy. | |
1000 | Changes involving KNOWN_TYPE_TAG may fix the problem. */ | |
1001 | /* Before really doing anything, output types we want to refer to. */ | |
1002 | /* Note that in version 1 the following two lines | |
1003 | are not used if forward references are in use. */ | |
1004 | if (TREE_CODE (type) != ENUMERAL_TYPE) | |
1005 | sdbout_field_types (type); | |
1006 | #if 0 | |
1007 | TREE_ASM_WRITTEN (type) = 1; | |
1008 | #endif | |
1009 | #endif | |
1010 | ||
1011 | /* Output a structure type. */ | |
1012 | { | |
1013 | int size = int_size_in_bytes (type); | |
1014 | int member_scl; | |
1015 | tree tem; | |
1016 | int i, n_baseclasses = 0; | |
1017 | ||
1018 | /* Record the type tag, but not in its permanent place just yet. */ | |
1019 | sdbout_record_type_name (type); | |
1020 | ||
1021 | PUT_SDB_DEF (KNOWN_TYPE_TAG (type)); | |
1022 | ||
1023 | switch (TREE_CODE (type)) | |
1024 | { | |
1025 | case UNION_TYPE: | |
1026 | PUT_SDB_SCL (C_UNTAG); | |
1027 | PUT_SDB_TYPE (T_UNION); | |
1028 | member_scl = C_MOU; | |
1029 | break; | |
1030 | ||
1031 | case RECORD_TYPE: | |
1032 | PUT_SDB_SCL (C_STRTAG); | |
1033 | PUT_SDB_TYPE (T_STRUCT); | |
1034 | member_scl = C_MOS; | |
1035 | break; | |
1036 | ||
1037 | case ENUMERAL_TYPE: | |
1038 | PUT_SDB_SCL (C_ENTAG); | |
1039 | PUT_SDB_TYPE (T_ENUM); | |
1040 | member_scl = C_MOE; | |
1041 | break; | |
1042 | } | |
1043 | ||
1044 | PUT_SDB_SIZE (size); | |
1045 | PUT_SDB_ENDEF; | |
1046 | ||
1047 | /* Print out the base class information with fields | |
1048 | named after the types they hold. */ | |
1049 | if (TYPE_BINFO (type) | |
1050 | && TYPE_BINFO_BASETYPES (type)) | |
1051 | n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type)); | |
1052 | for (i = 0; i < n_baseclasses; i++) | |
1053 | { | |
1054 | tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i); | |
1055 | tree child_type = BINFO_TYPE (child); | |
1056 | tree child_type_name; | |
1057 | if (TYPE_NAME (child_type) == 0) | |
1058 | continue; | |
1059 | if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE) | |
1060 | child_type_name = TYPE_NAME (child_type); | |
1061 | else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL) | |
1062 | child_type_name = DECL_NAME (TYPE_NAME (child_type)); | |
1063 | else | |
1064 | continue; | |
1065 | ||
1066 | CONTIN; | |
1067 | PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name)); | |
1068 | PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child))); | |
1069 | PUT_SDB_SCL (member_scl); | |
1070 | sdbout_type (BINFO_TYPE (child)); | |
1071 | PUT_SDB_ENDEF; | |
1072 | } | |
1073 | ||
1074 | /* output the individual fields */ | |
1075 | ||
1076 | if (TREE_CODE (type) == ENUMERAL_TYPE) | |
1077 | for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem)) | |
1078 | { | |
1079 | PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem))); | |
1080 | PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem))); | |
1081 | PUT_SDB_SCL (C_MOE); | |
1082 | PUT_SDB_TYPE (T_MOE); | |
1083 | PUT_SDB_ENDEF; | |
1084 | } | |
1085 | ||
1086 | else /* record or union type */ | |
1087 | for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem)) | |
1088 | /* Output the name, type, position (in bits), size (in bits) | |
1089 | of each field. */ | |
1090 | ||
1091 | /* Omit here the nameless fields that are used to skip bits. | |
1092 | Also omit fields with variable size or position. | |
1093 | Also omit non FIELD_DECL nodes that GNU C++ may put here. */ | |
1094 | if (TREE_CODE (tem) == FIELD_DECL | |
1095 | && DECL_NAME (tem) != 0 | |
1096 | && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST | |
1097 | && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST) | |
1098 | { | |
1099 | CONTIN; | |
1100 | PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem))); | |
1101 | if (DECL_BIT_FIELD_TYPE (tem)) | |
1102 | { | |
1103 | PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))); | |
1104 | PUT_SDB_SCL (C_FIELD); | |
1105 | sdbout_type (DECL_BIT_FIELD_TYPE (tem)); | |
1106 | PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem))); | |
1107 | } | |
1108 | else | |
1109 | { | |
1110 | PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)) | |
1111 | / BITS_PER_UNIT); | |
1112 | PUT_SDB_SCL (member_scl); | |
1113 | sdbout_type (TREE_TYPE (tem)); | |
1114 | } | |
1115 | PUT_SDB_ENDEF; | |
1116 | } | |
1117 | /* output end of a structure,union, or enumeral definition */ | |
1118 | ||
1119 | PUT_SDB_PLAIN_DEF ("eos"); | |
1120 | PUT_SDB_INT_VAL (size); | |
1121 | PUT_SDB_SCL (C_EOS); | |
1122 | PUT_SDB_TAG (KNOWN_TYPE_TAG (type)); | |
1123 | PUT_SDB_SIZE (size); | |
1124 | PUT_SDB_ENDEF; | |
1125 | break; | |
1126 | } | |
1127 | } | |
1128 | } | |
1129 | \f | |
1130 | /* The following two functions output definitions of function parameters. | |
1131 | Each parameter gets a definition locating it in the parameter list. | |
1132 | Each parameter that is a register variable gets a second definition | |
1133 | locating it in the register. | |
1134 | ||
1135 | Printing or argument lists in gdb uses the definitions that | |
1136 | locate in the parameter list. But reference to the variable in | |
1137 | expressions uses preferentially the definition as a register. */ | |
1138 | ||
1139 | /* Output definitions, referring to storage in the parmlist, | |
1140 | of all the parms in PARMS, which is a chain of PARM_DECL nodes. */ | |
1141 | ||
1142 | static void | |
1143 | sdbout_parms (parms) | |
1144 | tree parms; | |
1145 | { | |
1146 | for (; parms; parms = TREE_CHAIN (parms)) | |
1147 | if (DECL_NAME (parms)) | |
1148 | { | |
1149 | int current_sym_value = 0; | |
1150 | char *name = IDENTIFIER_POINTER (DECL_NAME (parms)); | |
1151 | ||
1152 | if (name == 0 || *name == 0) | |
1153 | name = gen_fake_label (); | |
1154 | ||
1155 | /* Perform any necessary register eliminations on the parameter's rtl, | |
1156 | so that the debugging output will be accurate. */ | |
1157 | DECL_INCOMING_RTL (parms) = | |
1158 | eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX); | |
1159 | DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX); | |
1160 | ||
1161 | if (PARM_PASSED_IN_MEMORY (parms)) | |
1162 | { | |
1163 | rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0); | |
1164 | tree type; | |
1165 | ||
1166 | /* ??? Here we assume that the parm address is indexed | |
1167 | off the frame pointer or arg pointer. | |
1168 | If that is not true, we produce meaningless results, | |
1169 | but do not crash. */ | |
1170 | if (GET_CODE (addr) == PLUS | |
1171 | && GET_CODE (XEXP (addr, 1)) == CONST_INT) | |
1172 | current_sym_value = INTVAL (XEXP (addr, 1)); | |
1173 | else | |
1174 | current_sym_value = 0; | |
1175 | ||
1176 | if (GET_CODE (DECL_RTL (parms)) == REG | |
1177 | && REGNO (DECL_RTL (parms)) >= 0 | |
1178 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) | |
1179 | type = DECL_ARG_TYPE (parms); | |
1180 | else | |
1181 | { | |
1182 | int original_sym_value = current_sym_value; | |
1183 | ||
1184 | /* This is the case where the parm is passed as an int or | |
1185 | double and it is converted to a char, short or float | |
1186 | and stored back in the parmlist. In this case, describe | |
1187 | the parm with the variable's declared type, and adjust | |
1188 | the address if the least significant bytes (which we are | |
1189 | using) are not the first ones. */ | |
1190 | #if BYTES_BIG_ENDIAN | |
1191 | if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms)) | |
1192 | current_sym_value += | |
1193 | (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms))) | |
1194 | - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))); | |
1195 | #endif | |
1196 | if (GET_CODE (DECL_RTL (parms)) == MEM | |
1197 | && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS | |
1198 | && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) | |
1199 | == CONST_INT) | |
1200 | && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) | |
1201 | == current_sym_value)) | |
1202 | type = TREE_TYPE (parms); | |
1203 | else | |
1204 | { | |
1205 | current_sym_value = original_sym_value; | |
1206 | type = DECL_ARG_TYPE (parms); | |
1207 | } | |
1208 | } | |
1209 | ||
1210 | PUT_SDB_DEF (name); | |
1211 | PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr)); | |
1212 | PUT_SDB_SCL (C_ARG); | |
1213 | PUT_SDB_TYPE (plain_type (type)); | |
1214 | PUT_SDB_ENDEF; | |
1215 | } | |
1216 | else if (GET_CODE (DECL_RTL (parms)) == REG) | |
1217 | { | |
1218 | rtx best_rtl; | |
1219 | /* Parm passed in registers and lives in registers or nowhere. */ | |
1220 | ||
1221 | /* If parm lives in a register, use that register; | |
1222 | pretend the parm was passed there. It would be more consistent | |
1223 | to describe the register where the parm was passed, | |
1224 | but in practice that register usually holds something else. */ | |
1225 | if (REGNO (DECL_RTL (parms)) >= 0 | |
1226 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) | |
1227 | best_rtl = DECL_RTL (parms); | |
1228 | /* If the parm lives nowhere, | |
1229 | use the register where it was passed. */ | |
1230 | else | |
1231 | best_rtl = DECL_INCOMING_RTL (parms); | |
1232 | ||
1233 | PUT_SDB_DEF (name); | |
1234 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl))); | |
1235 | PUT_SDB_SCL (C_REGPARM); | |
1236 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0)); | |
1237 | PUT_SDB_ENDEF; | |
1238 | } | |
1239 | else if (GET_CODE (DECL_RTL (parms)) == MEM | |
1240 | && XEXP (DECL_RTL (parms), 0) != const0_rtx) | |
1241 | { | |
1242 | /* Parm was passed in registers but lives on the stack. */ | |
1243 | ||
1244 | /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))), | |
1245 | in which case we want the value of that CONST_INT, | |
1246 | or (MEM (REG ...)) or (MEM (MEM ...)), | |
1247 | in which case we use a value of zero. */ | |
1248 | if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG | |
1249 | || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM) | |
1250 | current_sym_value = 0; | |
1251 | else | |
1252 | current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)); | |
1253 | ||
1254 | /* Again, this assumes the offset is based on the arg pointer. */ | |
1255 | PUT_SDB_DEF (name); | |
1256 | PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, | |
1257 | XEXP (DECL_RTL (parms), 0))); | |
1258 | PUT_SDB_SCL (C_ARG); | |
1259 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0)); | |
1260 | PUT_SDB_ENDEF; | |
1261 | } | |
1262 | } | |
1263 | } | |
1264 | ||
1265 | /* Output definitions for the places where parms live during the function, | |
1266 | when different from where they were passed, when the parms were passed | |
1267 | in memory. | |
1268 | ||
1269 | It is not useful to do this for parms passed in registers | |
1270 | that live during the function in different registers, because it is | |
1271 | impossible to look in the passed register for the passed value, | |
1272 | so we use the within-the-function register to begin with. | |
1273 | ||
1274 | PARMS is a chain of PARM_DECL nodes. */ | |
1275 | ||
1276 | static void | |
1277 | sdbout_reg_parms (parms) | |
1278 | tree parms; | |
1279 | { | |
1280 | for (; parms; parms = TREE_CHAIN (parms)) | |
1281 | if (DECL_NAME (parms)) | |
1282 | { | |
1283 | char *name = IDENTIFIER_POINTER (DECL_NAME (parms)); | |
1284 | ||
1285 | /* Report parms that live in registers during the function | |
1286 | but were passed in memory. */ | |
1287 | if (GET_CODE (DECL_RTL (parms)) == REG | |
1288 | && REGNO (DECL_RTL (parms)) >= 0 | |
1289 | && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER | |
1290 | && PARM_PASSED_IN_MEMORY (parms)) | |
1291 | { | |
1292 | if (name == 0 || *name == 0) | |
1293 | name = gen_fake_label (); | |
1294 | PUT_SDB_DEF (name); | |
1295 | PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)))); | |
1296 | PUT_SDB_SCL (C_REG); | |
1297 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0)); | |
1298 | PUT_SDB_ENDEF; | |
1299 | } | |
1300 | /* Report parms that live in memory but not where they were passed. */ | |
1301 | else if (GET_CODE (DECL_RTL (parms)) == MEM | |
1302 | && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS | |
1303 | && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT | |
1304 | && PARM_PASSED_IN_MEMORY (parms) | |
1305 | && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms))) | |
1306 | { | |
1307 | #if 0 /* ??? It is not clear yet what should replace this. */ | |
1308 | int offset = DECL_OFFSET (parms) / BITS_PER_UNIT; | |
1309 | /* A parm declared char is really passed as an int, | |
1310 | so it occupies the least significant bytes. | |
1311 | On a big-endian machine those are not the low-numbered ones. */ | |
1312 | #if BYTES_BIG_ENDIAN | |
1313 | if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms)) | |
1314 | offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms))) | |
1315 | - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))); | |
1316 | #endif | |
1317 | if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...} | |
1318 | #endif | |
1319 | { | |
1320 | if (name == 0 || *name == 0) | |
1321 | name = gen_fake_label (); | |
1322 | PUT_SDB_DEF (name); | |
1323 | PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET | |
1324 | (XEXP (DECL_RTL (parms), 0))); | |
1325 | PUT_SDB_SCL (C_AUTO); | |
1326 | PUT_SDB_TYPE (plain_type (TREE_TYPE (parms))); | |
1327 | PUT_SDB_ENDEF; | |
1328 | } | |
1329 | } | |
1330 | } | |
1331 | } | |
1332 | \f | |
1333 | /* Describe the beginning of an internal block within a function. | |
1334 | Also output descriptions of variables defined in this block. | |
1335 | ||
1336 | N is the number of the block, by order of beginning, counting from 1, | |
1337 | and not counting the outermost (function top-level) block. | |
1338 | The blocks match the BLOCKs in DECL_INITIAL (current_function_decl), | |
1339 | if the count starts at 0 for the outermost one. */ | |
1340 | ||
1341 | void | |
1342 | sdbout_begin_block (file, line, n) | |
1343 | FILE *file; | |
1344 | int line; | |
1345 | int n; | |
1346 | { | |
1347 | tree decl = current_function_decl; | |
1348 | MAKE_LINE_SAFE (line); | |
1349 | PUT_SDB_BLOCK_START (line - sdb_begin_function_line); | |
1350 | if (n == 1) | |
1351 | { | |
1352 | /* Include the outermost BLOCK's variables in block 1. */ | |
1353 | next_block_number = 0; | |
1354 | do_block = 0; | |
1355 | sdbout_block (DECL_INITIAL (decl)); | |
1356 | } | |
1357 | /* If -g1, suppress all the internal symbols of functions | |
1358 | except for arguments. */ | |
1359 | if (debug_info_level != DINFO_LEVEL_TERSE) | |
1360 | { | |
1361 | next_block_number = 0; | |
1362 | do_block = n; | |
1363 | sdbout_block (DECL_INITIAL (decl)); | |
1364 | } | |
1365 | ||
1366 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1367 | sdbout_dequeue_anonymous_types (); | |
1368 | #endif | |
1369 | } | |
1370 | ||
1371 | /* Describe the end line-number of an internal block within a function. */ | |
1372 | ||
1373 | void | |
1374 | sdbout_end_block (file, line) | |
1375 | FILE *file; | |
1376 | int line; | |
1377 | { | |
1378 | MAKE_LINE_SAFE (line); | |
1379 | PUT_SDB_BLOCK_END (line - sdb_begin_function_line); | |
1380 | } | |
1381 | ||
1382 | /* Output sdb info for the current function name. | |
1383 | Called from assemble_start_function. */ | |
1384 | ||
1385 | void | |
1386 | sdbout_mark_begin_function () | |
1387 | { | |
1388 | sdbout_symbol (current_function_decl, 0); | |
1389 | } | |
1390 | ||
1391 | /* Called at beginning of function body (after prologue). | |
1392 | Record the function's starting line number, so we can output | |
1393 | relative line numbers for the other lines. | |
1394 | Describe beginning of outermost block. | |
1395 | Also describe the parameter list. */ | |
1396 | ||
1397 | void | |
1398 | sdbout_begin_function (line) | |
1399 | int line; | |
1400 | { | |
1401 | sdb_begin_function_line = line - 1; | |
1402 | PUT_SDB_FUNCTION_START (line); | |
1403 | sdbout_parms (DECL_ARGUMENTS (current_function_decl)); | |
1404 | sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl)); | |
1405 | } | |
1406 | ||
1407 | /* Called at end of function (before epilogue). | |
1408 | Describe end of outermost block. */ | |
1409 | ||
1410 | void | |
1411 | sdbout_end_function (line) | |
1412 | int line; | |
1413 | { | |
1414 | #ifdef SDB_ALLOW_FORWARD_REFERENCES | |
1415 | sdbout_dequeue_anonymous_types (); | |
1416 | #endif | |
1417 | ||
1418 | MAKE_LINE_SAFE (line); | |
1419 | PUT_SDB_FUNCTION_END (line - sdb_begin_function_line); | |
1420 | ||
1421 | /* Indicate we are between functions, for line-number output. */ | |
1422 | sdb_begin_function_line = -1; | |
1423 | } | |
1424 | ||
1425 | /* Output sdb info for the absolute end of a function. | |
1426 | Called after the epilogue is output. */ | |
1427 | ||
1428 | void | |
1429 | sdbout_end_epilogue () | |
1430 | { | |
1431 | char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)); | |
1432 | PUT_SDB_EPILOGUE_END (name); | |
1433 | } | |
1434 | ||
1435 | /* Output sdb info for the given label. Called only if LABEL_NAME (insn) | |
1436 | is present. */ | |
1437 | ||
1438 | void | |
1439 | sdbout_label (insn) | |
1440 | register rtx insn; | |
1441 | { | |
1442 | PUT_SDB_DEF (LABEL_NAME (insn)); | |
1443 | PUT_SDB_VAL (insn); | |
1444 | PUT_SDB_SCL (C_LABEL); | |
1445 | PUT_SDB_TYPE (T_NULL); | |
1446 | PUT_SDB_ENDEF; | |
1447 | } | |
1448 | ||
1449 | #endif /* SDB_DEBUGGING_INFO */ |