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