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