* config/h8300/h8300.h (ENCODE_SECTION_INFO): Check to see if DECL
[official-gcc.git] / gcc / sdbout.c
blob5ec4b2314d4b584db7c3cefaba561f7483715cab
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.
5 This file is part of GNU CC.
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.
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.
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. */
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:
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.
30 2. All functions and their locals (including statics) are emitted as scanned.
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.
36 4. All structure .defs are emitted before the typedefs that refer to them.
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.
41 6. All undefined references are at the end of the file.
44 #include "config.h"
46 #ifdef SDB_DEBUGGING_INFO
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"
62 /* 1 if PARM is passed to this function in memory. */
64 #define PARM_PASSED_IN_MEMORY(PARM) \
65 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
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
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
80 /* Line number of beginning of current function, minus one.
81 Negative means not in a function or not using sdb. */
83 int sdb_begin_function_line = -1;
85 /* Counter to generate unique "names" for nameless struct members. */
87 static int unnamed_struct_number = 0;
89 extern FILE *asm_out_file;
91 extern tree current_function_decl;
93 #include "sdbout.h"
95 static void sdbout_init PARAMS ((const char *));
96 static void sdbout_finish PARAMS ((const char *));
97 static void sdbout_start_source_file PARAMS ((unsigned, const char *));
98 static void sdbout_end_source_file PARAMS ((unsigned));
99 static void sdbout_begin_block PARAMS ((unsigned, unsigned));
100 static void sdbout_end_block PARAMS ((unsigned, unsigned));
101 static void sdbout_source_line PARAMS ((unsigned int, const char *));
102 static void sdbout_end_epilogue PARAMS ((void));
103 static void sdbout_global_decl PARAMS ((tree));
104 #ifndef MIPS_DEBUGGING_INFO
105 static void sdbout_begin_prologue PARAMS ((unsigned int, const char *));
106 #endif
107 static void sdbout_end_prologue PARAMS ((unsigned int));
108 static void sdbout_begin_function PARAMS ((tree));
109 static void sdbout_end_function PARAMS ((unsigned int));
110 static void sdbout_toplevel_data PARAMS ((tree));
111 static void sdbout_label PARAMS ((rtx));
112 static char *gen_fake_label PARAMS ((void));
113 static int plain_type PARAMS ((tree));
114 static int template_name_p PARAMS ((tree));
115 static void sdbout_record_type_name PARAMS ((tree));
116 static int plain_type_1 PARAMS ((tree, int));
117 static void sdbout_block PARAMS ((tree));
118 static void sdbout_syms PARAMS ((tree));
119 #ifdef SDB_ALLOW_FORWARD_REFERENCES
120 static void sdbout_queue_anonymous_type PARAMS ((tree));
121 static void sdbout_dequeue_anonymous_types PARAMS ((void));
122 #endif
123 static void sdbout_type PARAMS ((tree));
124 static void sdbout_field_types PARAMS ((tree));
125 static void sdbout_one_type PARAMS ((tree));
126 static void sdbout_parms PARAMS ((tree));
127 static void sdbout_reg_parms PARAMS ((tree));
128 static void sdbout_global_decl PARAMS ((tree));
130 /* Random macros describing parts of SDB data. */
132 /* Put something here if lines get too long */
133 #define CONTIN
135 /* Default value of delimiter is ";". */
136 #ifndef SDB_DELIM
137 #define SDB_DELIM ";"
138 #endif
140 /* Maximum number of dimensions the assembler will allow. */
141 #ifndef SDB_MAX_DIM
142 #define SDB_MAX_DIM 4
143 #endif
145 #ifndef PUT_SDB_SCL
146 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
147 #endif
149 #ifndef PUT_SDB_INT_VAL
150 #define PUT_SDB_INT_VAL(a) \
151 do { \
152 fputs ("\t.val\t", asm_out_file); \
153 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
154 fprintf (asm_out_file, "%s", SDB_DELIM); \
155 } while (0)
157 #endif
159 #ifndef PUT_SDB_VAL
160 #define PUT_SDB_VAL(a) \
161 ( fputs ("\t.val\t", asm_out_file), \
162 output_addr_const (asm_out_file, (a)), \
163 fprintf (asm_out_file, SDB_DELIM))
164 #endif
166 #ifndef PUT_SDB_DEF
167 #define PUT_SDB_DEF(a) \
168 do { fprintf (asm_out_file, "\t.def\t"); \
169 assemble_name (asm_out_file, a); \
170 fprintf (asm_out_file, SDB_DELIM); } while (0)
171 #endif
173 #ifndef PUT_SDB_PLAIN_DEF
174 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
175 #endif
177 #ifndef PUT_SDB_ENDEF
178 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
179 #endif
181 #ifndef PUT_SDB_TYPE
182 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
183 #endif
185 #ifndef PUT_SDB_SIZE
186 #define PUT_SDB_SIZE(a) \
187 do { \
188 fputs ("\t.size\t", asm_out_file); \
189 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
190 fprintf (asm_out_file, "%s", SDB_DELIM); \
191 } while(0)
192 #endif
194 #ifndef PUT_SDB_START_DIM
195 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
196 #endif
198 #ifndef PUT_SDB_NEXT_DIM
199 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
200 #endif
202 #ifndef PUT_SDB_LAST_DIM
203 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
204 #endif
206 #ifndef PUT_SDB_TAG
207 #define PUT_SDB_TAG(a) \
208 do { fprintf (asm_out_file, "\t.tag\t"); \
209 assemble_name (asm_out_file, a); \
210 fprintf (asm_out_file, SDB_DELIM); } while (0)
211 #endif
213 #ifndef PUT_SDB_BLOCK_START
214 #define PUT_SDB_BLOCK_START(LINE) \
215 fprintf (asm_out_file, \
216 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
217 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
218 #endif
220 #ifndef PUT_SDB_BLOCK_END
221 #define PUT_SDB_BLOCK_END(LINE) \
222 fprintf (asm_out_file, \
223 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
224 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
225 #endif
227 #ifndef PUT_SDB_FUNCTION_START
228 #define PUT_SDB_FUNCTION_START(LINE) \
229 fprintf (asm_out_file, \
230 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
231 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
232 #endif
234 #ifndef PUT_SDB_FUNCTION_END
235 #define PUT_SDB_FUNCTION_END(LINE) \
236 fprintf (asm_out_file, \
237 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
238 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
239 #endif
241 #ifndef SDB_GENERATE_FAKE
242 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
243 sprintf ((BUFFER), ".%dfake", (NUMBER));
244 #endif
246 /* Return the sdb tag identifier string for TYPE
247 if TYPE has already been defined; otherwise return a null pointer. */
249 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
251 /* Set the sdb tag identifier string for TYPE to NAME. */
253 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
254 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
256 /* Return the name (a string) of the struct, union or enum tag
257 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
259 #define TAG_NAME(link) \
260 (((link) && TREE_PURPOSE ((link)) \
261 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
262 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
264 /* Ensure we don't output a negative line number. */
265 #define MAKE_LINE_SAFE(line) \
266 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
268 /* Perform linker optimization of merging header file definitions together
269 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
270 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
271 the optimization just won't be done. The native assembler already has the
272 necessary support. */
274 #ifdef MIPS_DEBUGGING_INFO
276 #ifndef PUT_SDB_SRC_FILE
277 #define PUT_SDB_SRC_FILE(FILENAME) \
278 output_file_directive (asm_out_file, (FILENAME))
279 #endif
281 /* ECOFF linkers have an optimization that does the same kind of thing as
282 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
283 executable. To achieve this, GCC must output a .file for each file
284 name change. */
286 /* This is a stack of input files. */
288 struct sdb_file
290 struct sdb_file *next;
291 const char *name;
294 /* This is the top of the stack. */
296 static struct sdb_file *current_file;
298 #endif /* MIPS_DEBUGGING_INFO */
300 /* The debug hooks structure. */
301 struct gcc_debug_hooks sdb_debug_hooks =
303 sdbout_init, /* init */
304 sdbout_finish, /* finish */
305 debug_nothing_int_charstar, /* define */
306 debug_nothing_int_charstar, /* undef */
307 sdbout_start_source_file, /* start_source_file */
308 sdbout_end_source_file, /* end_source_file */
309 sdbout_begin_block, /* begin_block */
310 sdbout_end_block, /* end_block */
311 debug_true_tree, /* ignore_block */
312 sdbout_source_line, /* source_line */
313 #ifdef MIPS_DEBUGGING_INFO
314 /* Defer on MIPS systems so that parameter descriptions follow
315 function entry. */
316 debug_nothing_int_charstar, /* begin_prologue */
317 sdbout_end_prologue, /* end_prologue */
318 #else
319 sdbout_begin_prologue, /* begin_prologue */
320 debug_nothing_int, /* end_prologue */
321 #endif
322 sdbout_end_epilogue, /* end_epilogue */
323 sdbout_begin_function, /* begin_function */
324 sdbout_end_function, /* end_function */
325 debug_nothing_tree, /* function_decl */
326 sdbout_global_decl, /* global_decl */
327 debug_nothing_tree, /* deferred_inline_function */
328 debug_nothing_tree, /* outlining_inline_function */
329 sdbout_label
332 #if 0
334 /* return the tag identifier for type
337 char *
338 tag_of_ru_type (type,link)
339 tree type,link;
341 if (TYPE_SYMTAB_ADDRESS (type))
342 return TYPE_SYMTAB_ADDRESS (type);
343 if (link && TREE_PURPOSE (link)
344 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
345 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
346 else
347 return (char *) TYPE_SYMTAB_ADDRESS (type);
349 #endif
351 /* Return a unique string to name an anonymous type. */
353 static char *
354 gen_fake_label ()
356 char label[10];
357 char *labelstr;
358 SDB_GENERATE_FAKE (label, unnamed_struct_number);
359 unnamed_struct_number++;
360 labelstr = (char *) permalloc (strlen (label) + 1);
361 strcpy (labelstr, label);
362 return labelstr;
365 /* Return the number which describes TYPE for SDB.
366 For pointers, etc., this function is recursive.
367 Each record, union or enumeral type must already have had a
368 tag number output. */
370 /* The number is given by d6d5d4d3d2d1bbbb
371 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
372 Thus, char *foo () has bbbb=T_CHAR
373 d1=D_FCN
374 d2=D_PTR
375 N_BTMASK= 017 1111 basic type field.
376 N_TSHIFT= 2 derived type shift
377 N_BTSHFT= 4 Basic type shift */
379 /* Produce the number that describes a pointer, function or array type.
380 PREV is the number describing the target, value or element type.
381 DT_type describes how to transform that type. */
382 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
383 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
384 | ((int)DT_type << (int)N_BTSHFT) \
385 | ((PREV) & (int)N_BTMASK))
387 /* Number of elements used in sdb_dims. */
388 static int sdb_n_dims = 0;
390 /* Table of array dimensions of current type. */
391 static int sdb_dims[SDB_MAX_DIM];
393 /* Size of outermost array currently being processed. */
394 static int sdb_type_size = -1;
396 static int
397 plain_type (type)
398 tree type;
400 int val = plain_type_1 (type, 0);
402 /* If we have already saved up some array dimensions, print them now. */
403 if (sdb_n_dims > 0)
405 int i;
406 PUT_SDB_START_DIM;
407 for (i = sdb_n_dims - 1; i > 0; i--)
408 PUT_SDB_NEXT_DIM (sdb_dims[i]);
409 PUT_SDB_LAST_DIM (sdb_dims[0]);
410 sdb_n_dims = 0;
412 sdb_type_size = int_size_in_bytes (type);
413 /* Don't kill sdb if type is not laid out or has variable size. */
414 if (sdb_type_size < 0)
415 sdb_type_size = 0;
417 /* If we have computed the size of an array containing this type,
418 print it now. */
419 if (sdb_type_size >= 0)
421 PUT_SDB_SIZE (sdb_type_size);
422 sdb_type_size = -1;
424 return val;
427 static int
428 template_name_p (name)
429 tree name;
431 register const char *ptr = IDENTIFIER_POINTER (name);
432 while (*ptr && *ptr != '<')
433 ptr++;
435 return *ptr != '\0';
438 static void
439 sdbout_record_type_name (type)
440 tree type;
442 const char *name = 0;
443 int no_name;
445 if (KNOWN_TYPE_TAG (type))
446 return;
448 if (TYPE_NAME (type) != 0)
450 tree t = 0;
451 /* Find the IDENTIFIER_NODE for the type name. */
452 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
453 t = TYPE_NAME (type);
454 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
456 t = DECL_NAME (TYPE_NAME (type));
457 /* The DECL_NAME for templates includes "<>", which breaks
458 most assemblers. Use its assembler name instead, which
459 has been mangled into being safe. */
460 if (t && template_name_p (t))
461 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
464 /* Now get the name as a string, or invent one. */
465 if (t != NULL_TREE)
466 name = IDENTIFIER_POINTER (t);
469 no_name = (name == 0 || *name == 0);
470 if (no_name)
471 name = gen_fake_label ();
473 SET_KNOWN_TYPE_TAG (type, name);
474 #ifdef SDB_ALLOW_FORWARD_REFERENCES
475 if (no_name)
476 sdbout_queue_anonymous_type (type);
477 #endif
480 /* Return the .type value for type TYPE.
482 LEVEL indicates how many levels deep we have recursed into the type.
483 The SDB debug format can only represent 6 derived levels of types.
484 After that, we must output inaccurate debug info. We deliberately
485 stop before the 7th level, so that ADA recursive types will not give an
486 infinite loop. */
488 static int
489 plain_type_1 (type, level)
490 tree type;
491 int level;
493 if (type == 0)
494 type = void_type_node;
495 else if (type == error_mark_node)
496 type = integer_type_node;
497 else
498 type = TYPE_MAIN_VARIANT (type);
500 switch (TREE_CODE (type))
502 case VOID_TYPE:
503 return T_VOID;
504 case BOOLEAN_TYPE:
505 case INTEGER_TYPE:
507 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
509 /* Carefully distinguish all the standard types of C,
510 without messing up if the language is not C.
511 Note that we check only for the names that contain spaces;
512 other names might occur by coincidence in other languages. */
513 if (TYPE_NAME (type) != 0
514 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
515 && DECL_NAME (TYPE_NAME (type)) != 0
516 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
518 const char *name
519 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
521 if (!strcmp (name, "char"))
522 return T_CHAR;
523 if (!strcmp (name, "unsigned char"))
524 return T_UCHAR;
525 if (!strcmp (name, "signed char"))
526 return T_CHAR;
527 if (!strcmp (name, "int"))
528 return T_INT;
529 if (!strcmp (name, "unsigned int"))
530 return T_UINT;
531 if (!strcmp (name, "short int"))
532 return T_SHORT;
533 if (!strcmp (name, "short unsigned int"))
534 return T_USHORT;
535 if (!strcmp (name, "long int"))
536 return T_LONG;
537 if (!strcmp (name, "long unsigned int"))
538 return T_ULONG;
541 if (size == INT_TYPE_SIZE)
542 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
543 if (size == CHAR_TYPE_SIZE)
544 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
545 if (size == SHORT_TYPE_SIZE)
546 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
547 if (size == LONG_TYPE_SIZE)
548 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
549 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
550 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
551 return 0;
554 case REAL_TYPE:
556 int precision = TYPE_PRECISION (type);
557 if (precision == FLOAT_TYPE_SIZE)
558 return T_FLOAT;
559 if (precision == DOUBLE_TYPE_SIZE)
560 return T_DOUBLE;
561 #ifdef EXTENDED_SDB_BASIC_TYPES
562 if (precision == LONG_DOUBLE_TYPE_SIZE)
563 return T_LNGDBL;
564 #else
565 if (precision == LONG_DOUBLE_TYPE_SIZE)
566 return T_DOUBLE; /* better than nothing */
567 #endif
568 return 0;
571 case ARRAY_TYPE:
573 int m;
574 if (level >= 6)
575 return T_VOID;
576 else
577 m = plain_type_1 (TREE_TYPE (type), level+1);
578 if (sdb_n_dims < SDB_MAX_DIM)
579 sdb_dims[sdb_n_dims++]
580 = (TYPE_DOMAIN (type)
581 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
582 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
583 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
584 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
585 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
586 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
587 : 0);
589 return PUSH_DERIVED_LEVEL (DT_ARY, m);
592 case RECORD_TYPE:
593 case UNION_TYPE:
594 case QUAL_UNION_TYPE:
595 case ENUMERAL_TYPE:
597 char *tag;
598 #ifdef SDB_ALLOW_FORWARD_REFERENCES
599 sdbout_record_type_name (type);
600 #endif
601 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
602 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
603 #ifdef SDB_ALLOW_FORWARD_REFERENCES
604 || TYPE_MODE (type) != VOIDmode
605 #endif
607 #endif
609 /* Output the referenced structure tag name
610 only if the .def has already been finished.
611 At least on 386, the Unix assembler
612 cannot handle forward references to tags. */
613 /* But the 88100, it requires them, sigh... */
614 /* And the MIPS requires unknown refs as well... */
615 tag = KNOWN_TYPE_TAG (type);
616 PUT_SDB_TAG (tag);
617 /* These 3 lines used to follow the close brace.
618 However, a size of 0 without a tag implies a tag of 0,
619 so if we don't know a tag, we can't mention the size. */
620 sdb_type_size = int_size_in_bytes (type);
621 if (sdb_type_size < 0)
622 sdb_type_size = 0;
624 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
625 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
626 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
627 : T_ENUM);
629 case POINTER_TYPE:
630 case REFERENCE_TYPE:
632 int m;
633 if (level >= 6)
634 return T_VOID;
635 else
636 m = plain_type_1 (TREE_TYPE (type), level+1);
637 return PUSH_DERIVED_LEVEL (DT_PTR, m);
639 case FUNCTION_TYPE:
640 case METHOD_TYPE:
642 int m;
643 if (level >= 6)
644 return T_VOID;
645 else
646 m = plain_type_1 (TREE_TYPE (type), level+1);
647 return PUSH_DERIVED_LEVEL (DT_FCN, m);
649 default:
650 return 0;
654 /* Output the symbols defined in block number DO_BLOCK.
656 This function works by walking the tree structure of blocks,
657 counting blocks until it finds the desired block. */
659 static int do_block = 0;
661 static void
662 sdbout_block (block)
663 register tree block;
665 while (block)
667 /* Ignore blocks never expanded or otherwise marked as real. */
668 if (TREE_USED (block))
670 /* When we reach the specified block, output its symbols. */
671 if (BLOCK_NUMBER (block) == do_block)
672 sdbout_syms (BLOCK_VARS (block));
674 /* If we are past the specified block, stop the scan. */
675 if (BLOCK_NUMBER (block) > do_block)
676 return;
678 /* Scan the blocks within this block. */
679 sdbout_block (BLOCK_SUBBLOCKS (block));
682 block = BLOCK_CHAIN (block);
686 /* Call sdbout_symbol on each decl in the chain SYMS. */
688 static void
689 sdbout_syms (syms)
690 tree syms;
692 while (syms)
694 if (TREE_CODE (syms) != LABEL_DECL)
695 sdbout_symbol (syms, 1);
696 syms = TREE_CHAIN (syms);
700 /* Output SDB information for a symbol described by DECL.
701 LOCAL is nonzero if the symbol is not file-scope. */
703 void
704 sdbout_symbol (decl, local)
705 tree decl;
706 int local;
708 tree type = TREE_TYPE (decl);
709 tree context = NULL_TREE;
710 rtx value;
711 int regno = -1;
712 const char *name;
714 sdbout_one_type (type);
716 #if 0 /* This loses when functions are marked to be ignored,
717 which happens in the C++ front end. */
718 if (DECL_IGNORED_P (decl))
719 return;
720 #endif
722 switch (TREE_CODE (decl))
724 case CONST_DECL:
725 /* Enum values are defined by defining the enum type. */
726 return;
728 case FUNCTION_DECL:
729 /* Don't mention a nested function under its parent. */
730 context = decl_function_context (decl);
731 if (context == current_function_decl)
732 return;
733 /* Check DECL_INITIAL to distinguish declarations from definitions.
734 Don't output debug info here for declarations; they will have
735 a DECL_INITIAL value of 0. */
736 if (! DECL_INITIAL (decl))
737 return;
738 if (GET_CODE (DECL_RTL (decl)) != MEM
739 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
740 return;
741 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
742 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
743 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
744 break;
746 case TYPE_DECL:
747 /* Done with tagged types. */
748 if (DECL_NAME (decl) == 0)
749 return;
750 if (DECL_IGNORED_P (decl))
751 return;
753 /* Output typedef name. */
754 if (template_name_p (DECL_NAME (decl)))
755 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
756 else
757 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
758 PUT_SDB_SCL (C_TPDEF);
759 break;
761 case PARM_DECL:
762 /* Parm decls go in their own separate chains
763 and are output by sdbout_reg_parms and sdbout_parms. */
764 abort ();
766 case VAR_DECL:
767 /* Don't mention a variable that is external.
768 Let the file that defines it describe it. */
769 if (DECL_EXTERNAL (decl))
770 return;
772 /* Ignore __FUNCTION__, etc. */
773 if (DECL_IGNORED_P (decl))
774 return;
776 /* If there was an error in the declaration, don't dump core
777 if there is no RTL associated with the variable doesn't
778 exist. */
779 if (!DECL_RTL_SET_P (decl))
780 return;
782 SET_DECL_RTL (decl,
783 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
784 #ifdef LEAF_REG_REMAP
785 if (current_function_uses_only_leaf_regs)
786 leaf_renumber_regs_insn (DECL_RTL (decl));
787 #endif
788 value = DECL_RTL (decl);
790 /* Don't mention a variable at all
791 if it was completely optimized into nothingness.
793 If DECL was from an inline function, then its rtl
794 is not identically the rtl that was used in this
795 particular compilation. */
796 if (GET_CODE (value) == REG)
798 regno = REGNO (DECL_RTL (decl));
799 if (regno >= FIRST_PSEUDO_REGISTER)
800 return;
802 else if (GET_CODE (value) == SUBREG)
804 while (GET_CODE (value) == SUBREG)
805 value = SUBREG_REG (value);
806 if (GET_CODE (value) == REG)
808 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
809 return;
811 regno = REGNO (alter_subreg (DECL_RTL (decl)));
812 value = DECL_RTL (decl);
814 /* Don't output anything if an auto variable
815 gets RTL that is static.
816 GAS version 2.2 can't handle such output. */
817 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
818 && ! TREE_STATIC (decl))
819 return;
821 /* Emit any structure, union, or enum type that has not been output.
822 This occurs for tag-less structs (et al) used to declare variables
823 within functions. */
824 if (TREE_CODE (type) == ENUMERAL_TYPE
825 || TREE_CODE (type) == RECORD_TYPE
826 || TREE_CODE (type) == UNION_TYPE
827 || TREE_CODE (type) == QUAL_UNION_TYPE)
829 if (COMPLETE_TYPE_P (type) /* not a forward reference */
830 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
831 sdbout_one_type (type);
834 /* Defer SDB information for top-level initialized variables! */
835 if (! local
836 && GET_CODE (value) == MEM
837 && DECL_INITIAL (decl))
838 return;
840 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
841 For now, avoid crashing. */
842 if (DECL_NAME (decl) == NULL_TREE)
843 return;
845 /* Record the name for, starting a symtab entry. */
846 if (local)
847 name = IDENTIFIER_POINTER (DECL_NAME (decl));
848 else
849 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
851 if (GET_CODE (value) == MEM
852 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
854 PUT_SDB_DEF (name);
855 if (TREE_PUBLIC (decl))
857 PUT_SDB_VAL (XEXP (value, 0));
858 PUT_SDB_SCL (C_EXT);
860 else
862 PUT_SDB_VAL (XEXP (value, 0));
863 PUT_SDB_SCL (C_STAT);
866 else if (regno >= 0)
868 PUT_SDB_DEF (name);
869 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
870 PUT_SDB_SCL (C_REG);
872 else if (GET_CODE (value) == MEM
873 && (GET_CODE (XEXP (value, 0)) == MEM
874 || (GET_CODE (XEXP (value, 0)) == REG
875 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
876 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
877 /* If the value is indirect by memory or by a register
878 that isn't the frame pointer
879 then it means the object is variable-sized and address through
880 that register or stack slot. COFF has no way to represent this
881 so all we can do is output the variable as a pointer. */
883 PUT_SDB_DEF (name);
884 if (GET_CODE (XEXP (value, 0)) == REG)
886 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
887 PUT_SDB_SCL (C_REG);
889 else
891 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
892 (CONST_INT...)))).
893 We want the value of that CONST_INT. */
894 /* Encore compiler hates a newline in a macro arg, it seems. */
895 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
896 (XEXP (XEXP (value, 0), 0)));
897 PUT_SDB_SCL (C_AUTO);
900 /* Effectively do build_pointer_type, but don't cache this type,
901 since it might be temporary whereas the type it points to
902 might have been saved for inlining. */
903 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
904 type = make_node (POINTER_TYPE);
905 TREE_TYPE (type) = TREE_TYPE (decl);
907 else if (GET_CODE (value) == MEM
908 && ((GET_CODE (XEXP (value, 0)) == PLUS
909 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
910 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
911 /* This is for variables which are at offset zero from
912 the frame pointer. This happens on the Alpha.
913 Non-frame pointer registers are excluded above. */
914 || (GET_CODE (XEXP (value, 0)) == REG)))
916 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
917 or (MEM (REG...)). We want the value of that CONST_INT
918 or zero. */
919 PUT_SDB_DEF (name);
920 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
921 PUT_SDB_SCL (C_AUTO);
923 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
925 /* Handle an obscure case which can arise when optimizing and
926 when there are few available registers. (This is *always*
927 the case for i386/i486 targets). The DECL_RTL looks like
928 (MEM (CONST ...)) even though this variable is a local `auto'
929 or a local `register' variable. In effect, what has happened
930 is that the reload pass has seen that all assignments and
931 references for one such a local variable can be replaced by
932 equivalent assignments and references to some static storage
933 variable, thereby avoiding the need for a register. In such
934 cases we're forced to lie to debuggers and tell them that
935 this variable was itself `static'. */
936 PUT_SDB_DEF (name);
937 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
938 PUT_SDB_SCL (C_STAT);
940 else
942 /* It is something we don't know how to represent for SDB. */
943 return;
945 break;
947 default:
948 break;
950 PUT_SDB_TYPE (plain_type (type));
951 PUT_SDB_ENDEF;
954 /* Output SDB information for a top-level initialized variable
955 that has been delayed. */
957 static void
958 sdbout_toplevel_data (decl)
959 tree decl;
961 tree type = TREE_TYPE (decl);
963 if (DECL_IGNORED_P (decl))
964 return;
966 if (! (TREE_CODE (decl) == VAR_DECL
967 && GET_CODE (DECL_RTL (decl)) == MEM
968 && DECL_INITIAL (decl)))
969 abort ();
971 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
972 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
973 if (TREE_PUBLIC (decl))
975 PUT_SDB_SCL (C_EXT);
977 else
979 PUT_SDB_SCL (C_STAT);
981 PUT_SDB_TYPE (plain_type (type));
982 PUT_SDB_ENDEF;
985 #ifdef SDB_ALLOW_FORWARD_REFERENCES
987 /* Machinery to record and output anonymous types. */
989 static tree anonymous_types;
991 static void
992 sdbout_queue_anonymous_type (type)
993 tree type;
995 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
998 static void
999 sdbout_dequeue_anonymous_types ()
1001 register tree types, link;
1003 while (anonymous_types)
1005 types = nreverse (anonymous_types);
1006 anonymous_types = NULL_TREE;
1008 for (link = types; link; link = TREE_CHAIN (link))
1010 register tree type = TREE_VALUE (link);
1012 if (type && ! TREE_ASM_WRITTEN (type))
1013 sdbout_one_type (type);
1018 #endif
1020 /* Given a chain of ..._TYPE nodes, all of which have names,
1021 output definitions of those names, as typedefs. */
1023 void
1024 sdbout_types (types)
1025 register tree types;
1027 register tree link;
1029 for (link = types; link; link = TREE_CHAIN (link))
1030 sdbout_one_type (link);
1032 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1033 sdbout_dequeue_anonymous_types ();
1034 #endif
1037 static void
1038 sdbout_type (type)
1039 tree type;
1041 if (type == error_mark_node)
1042 type = integer_type_node;
1043 PUT_SDB_TYPE (plain_type (type));
1046 /* Output types of the fields of type TYPE, if they are structs.
1048 Formerly did not chase through pointer types, since that could be circular.
1049 They must come before TYPE, since forward refs are not allowed.
1050 Now james@bigtex.cactus.org says to try them. */
1052 static void
1053 sdbout_field_types (type)
1054 tree type;
1056 tree tail;
1058 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1059 /* This condition should match the one for emitting the actual
1060 members below. */
1061 if (TREE_CODE (tail) == FIELD_DECL
1062 && DECL_NAME (tail)
1063 && DECL_SIZE (tail)
1064 && host_integerp (DECL_SIZE (tail), 1)
1065 && host_integerp (bit_position (tail), 0))
1067 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1068 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1069 else
1070 sdbout_one_type (TREE_TYPE (tail));
1074 /* Use this to put out the top level defined record and union types
1075 for later reference. If this is a struct with a name, then put that
1076 name out. Other unnamed structs will have .xxfake labels generated so
1077 that they may be referred to later.
1078 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1079 It may NOT be called recursively. */
1081 static void
1082 sdbout_one_type (type)
1083 tree type;
1085 if (current_function_decl != NULL_TREE
1086 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1087 ; /* Don't change section amid function. */
1088 else
1089 text_section ();
1091 switch (TREE_CODE (type))
1093 case RECORD_TYPE:
1094 case UNION_TYPE:
1095 case QUAL_UNION_TYPE:
1096 case ENUMERAL_TYPE:
1097 type = TYPE_MAIN_VARIANT (type);
1098 /* Don't output a type twice. */
1099 if (TREE_ASM_WRITTEN (type))
1100 /* James said test TREE_ASM_BEING_WRITTEN here. */
1101 return;
1103 /* Output nothing if type is not yet defined. */
1104 if (!COMPLETE_TYPE_P (type))
1105 return;
1107 TREE_ASM_WRITTEN (type) = 1;
1108 #if 1
1109 /* This is reputed to cause trouble with the following case,
1110 but perhaps checking TYPE_SIZE above will fix it. */
1112 /* Here is a test case:
1114 struct foo {
1115 struct badstr *bbb;
1116 } forwardref;
1118 typedef struct intermediate {
1119 int aaaa;
1120 } intermediate_ref;
1122 typedef struct badstr {
1123 int ccccc;
1124 } badtype; */
1126 #if 0
1127 TREE_ASM_BEING_WRITTEN (type) = 1;
1128 #endif
1129 /* This change, which ought to make better output,
1130 used to make the COFF assembler unhappy.
1131 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1132 /* Before really doing anything, output types we want to refer to. */
1133 /* Note that in version 1 the following two lines
1134 are not used if forward references are in use. */
1135 if (TREE_CODE (type) != ENUMERAL_TYPE)
1136 sdbout_field_types (type);
1137 #if 0
1138 TREE_ASM_WRITTEN (type) = 1;
1139 #endif
1140 #endif
1142 /* Output a structure type. */
1144 int size = int_size_in_bytes (type);
1145 int member_scl = 0;
1146 tree tem;
1147 int i, n_baseclasses = 0;
1149 /* Record the type tag, but not in its permanent place just yet. */
1150 sdbout_record_type_name (type);
1152 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1154 switch (TREE_CODE (type))
1156 case UNION_TYPE:
1157 case QUAL_UNION_TYPE:
1158 PUT_SDB_SCL (C_UNTAG);
1159 PUT_SDB_TYPE (T_UNION);
1160 member_scl = C_MOU;
1161 break;
1163 case RECORD_TYPE:
1164 PUT_SDB_SCL (C_STRTAG);
1165 PUT_SDB_TYPE (T_STRUCT);
1166 member_scl = C_MOS;
1167 break;
1169 case ENUMERAL_TYPE:
1170 PUT_SDB_SCL (C_ENTAG);
1171 PUT_SDB_TYPE (T_ENUM);
1172 member_scl = C_MOE;
1173 break;
1175 default:
1176 break;
1179 PUT_SDB_SIZE (size);
1180 PUT_SDB_ENDEF;
1182 /* Print out the base class information with fields
1183 named after the types they hold. */
1184 /* This is only relevent to aggregate types. TYPE_BINFO is used
1185 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1186 case. */
1187 if (TREE_CODE (type) != ENUMERAL_TYPE)
1189 if (TYPE_BINFO (type)
1190 && TYPE_BINFO_BASETYPES (type))
1191 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1192 for (i = 0; i < n_baseclasses; i++)
1194 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1196 tree child_type = BINFO_TYPE (child);
1197 tree child_type_name;
1198 if (TYPE_NAME (child_type) == 0)
1199 continue;
1200 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1201 child_type_name = TYPE_NAME (child_type);
1202 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1204 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1205 if (child_type_name && template_name_p (child_type_name))
1206 child_type_name
1207 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1209 else
1210 continue;
1212 CONTIN;
1213 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1214 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1215 PUT_SDB_SCL (member_scl);
1216 sdbout_type (BINFO_TYPE (child));
1217 PUT_SDB_ENDEF;
1221 /* output the individual fields */
1223 if (TREE_CODE (type) == ENUMERAL_TYPE)
1225 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1226 if (host_integerp (TREE_VALUE (tem), 0))
1228 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1229 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1230 PUT_SDB_SCL (C_MOE);
1231 PUT_SDB_TYPE (T_MOE);
1232 PUT_SDB_ENDEF;
1235 else /* record or union type */
1236 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1237 /* Output the name, type, position (in bits), size (in bits)
1238 of each field. */
1240 /* Omit here the nameless fields that are used to skip bits.
1241 Also omit fields with variable size or position.
1242 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1243 if (TREE_CODE (tem) == FIELD_DECL
1244 && DECL_NAME (tem)
1245 && DECL_SIZE (tem)
1246 && host_integerp (DECL_SIZE (tem), 1)
1247 && host_integerp (bit_position (tem), 0))
1249 const char *name;
1251 CONTIN;
1252 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1253 PUT_SDB_DEF (name);
1254 if (DECL_BIT_FIELD_TYPE (tem))
1256 PUT_SDB_INT_VAL (int_bit_position (tem));
1257 PUT_SDB_SCL (C_FIELD);
1258 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1259 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1261 else
1263 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1264 PUT_SDB_SCL (member_scl);
1265 sdbout_type (TREE_TYPE (tem));
1267 PUT_SDB_ENDEF;
1269 /* output end of a structure,union, or enumeral definition */
1271 PUT_SDB_PLAIN_DEF ("eos");
1272 PUT_SDB_INT_VAL (size);
1273 PUT_SDB_SCL (C_EOS);
1274 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1275 PUT_SDB_SIZE (size);
1276 PUT_SDB_ENDEF;
1277 break;
1279 default:
1280 break;
1285 /* The following two functions output definitions of function parameters.
1286 Each parameter gets a definition locating it in the parameter list.
1287 Each parameter that is a register variable gets a second definition
1288 locating it in the register.
1290 Printing or argument lists in gdb uses the definitions that
1291 locate in the parameter list. But reference to the variable in
1292 expressions uses preferentially the definition as a register. */
1294 /* Output definitions, referring to storage in the parmlist,
1295 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1297 static void
1298 sdbout_parms (parms)
1299 tree parms;
1301 for (; parms; parms = TREE_CHAIN (parms))
1302 if (DECL_NAME (parms))
1304 int current_sym_value = 0;
1305 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1307 if (name == 0 || *name == 0)
1308 name = gen_fake_label ();
1310 /* Perform any necessary register eliminations on the parameter's rtl,
1311 so that the debugging output will be accurate. */
1312 DECL_INCOMING_RTL (parms)
1313 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1314 SET_DECL_RTL (parms,
1315 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1317 if (PARM_PASSED_IN_MEMORY (parms))
1319 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1320 tree type;
1322 /* ??? Here we assume that the parm address is indexed
1323 off the frame pointer or arg pointer.
1324 If that is not true, we produce meaningless results,
1325 but do not crash. */
1326 if (GET_CODE (addr) == PLUS
1327 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1328 current_sym_value = INTVAL (XEXP (addr, 1));
1329 else
1330 current_sym_value = 0;
1332 if (GET_CODE (DECL_RTL (parms)) == REG
1333 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1334 type = DECL_ARG_TYPE (parms);
1335 else
1337 int original_sym_value = current_sym_value;
1339 /* This is the case where the parm is passed as an int or
1340 double and it is converted to a char, short or float
1341 and stored back in the parmlist. In this case, describe
1342 the parm with the variable's declared type, and adjust
1343 the address if the least significant bytes (which we are
1344 using) are not the first ones. */
1345 if (BYTES_BIG_ENDIAN
1346 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1347 current_sym_value +=
1348 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1349 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1351 if (GET_CODE (DECL_RTL (parms)) == MEM
1352 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1353 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1354 == CONST_INT)
1355 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1356 == current_sym_value))
1357 type = TREE_TYPE (parms);
1358 else
1360 current_sym_value = original_sym_value;
1361 type = DECL_ARG_TYPE (parms);
1365 PUT_SDB_DEF (name);
1366 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1367 PUT_SDB_SCL (C_ARG);
1368 PUT_SDB_TYPE (plain_type (type));
1369 PUT_SDB_ENDEF;
1371 else if (GET_CODE (DECL_RTL (parms)) == REG)
1373 rtx best_rtl;
1374 /* Parm passed in registers and lives in registers or nowhere. */
1376 /* If parm lives in a register, use that register;
1377 pretend the parm was passed there. It would be more consistent
1378 to describe the register where the parm was passed,
1379 but in practice that register usually holds something else. */
1380 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1381 best_rtl = DECL_RTL (parms);
1382 /* If the parm lives nowhere,
1383 use the register where it was passed. */
1384 else
1385 best_rtl = DECL_INCOMING_RTL (parms);
1387 PUT_SDB_DEF (name);
1388 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1389 PUT_SDB_SCL (C_REGPARM);
1390 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1391 PUT_SDB_ENDEF;
1393 else if (GET_CODE (DECL_RTL (parms)) == MEM
1394 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1396 /* Parm was passed in registers but lives on the stack. */
1398 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1399 in which case we want the value of that CONST_INT,
1400 or (MEM (REG ...)) or (MEM (MEM ...)),
1401 in which case we use a value of zero. */
1402 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1403 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1404 current_sym_value = 0;
1405 else
1406 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1408 /* Again, this assumes the offset is based on the arg pointer. */
1409 PUT_SDB_DEF (name);
1410 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1411 XEXP (DECL_RTL (parms), 0)));
1412 PUT_SDB_SCL (C_ARG);
1413 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1414 PUT_SDB_ENDEF;
1419 /* Output definitions for the places where parms live during the function,
1420 when different from where they were passed, when the parms were passed
1421 in memory.
1423 It is not useful to do this for parms passed in registers
1424 that live during the function in different registers, because it is
1425 impossible to look in the passed register for the passed value,
1426 so we use the within-the-function register to begin with.
1428 PARMS is a chain of PARM_DECL nodes. */
1430 static void
1431 sdbout_reg_parms (parms)
1432 tree parms;
1434 for (; parms; parms = TREE_CHAIN (parms))
1435 if (DECL_NAME (parms))
1437 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1439 /* Report parms that live in registers during the function
1440 but were passed in memory. */
1441 if (GET_CODE (DECL_RTL (parms)) == REG
1442 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1443 && PARM_PASSED_IN_MEMORY (parms))
1445 if (name == 0 || *name == 0)
1446 name = gen_fake_label ();
1447 PUT_SDB_DEF (name);
1448 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1449 PUT_SDB_SCL (C_REG);
1450 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1451 PUT_SDB_ENDEF;
1453 /* Report parms that live in memory but not where they were passed. */
1454 else if (GET_CODE (DECL_RTL (parms)) == MEM
1455 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1456 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1457 && PARM_PASSED_IN_MEMORY (parms)
1458 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1460 #if 0 /* ??? It is not clear yet what should replace this. */
1461 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1462 /* A parm declared char is really passed as an int,
1463 so it occupies the least significant bytes.
1464 On a big-endian machine those are not the low-numbered ones. */
1465 if (BYTES_BIG_ENDIAN
1466 && offset != -1
1467 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1468 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1469 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1470 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1471 #endif
1473 if (name == 0 || *name == 0)
1474 name = gen_fake_label ();
1475 PUT_SDB_DEF (name);
1476 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1477 (XEXP (DECL_RTL (parms), 0)));
1478 PUT_SDB_SCL (C_AUTO);
1479 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1480 PUT_SDB_ENDEF;
1486 /* Output debug information for a global DECL. Called from toplev.c
1487 after compilation proper has finished. */
1489 static void
1490 sdbout_global_decl (decl)
1491 tree decl;
1493 if (TREE_CODE (decl) == VAR_DECL
1494 && !DECL_EXTERNAL (decl)
1495 && DECL_RTL_SET_P (decl))
1497 /* The COFF linker can move initialized global vars to the end.
1498 And that can screw up the symbol ordering. Defer those for
1499 sdbout_finish (). */
1500 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1501 sdbout_symbol (decl, 0);
1503 /* Output COFF information for non-global file-scope initialized
1504 variables. */
1505 if (DECL_INITIAL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
1506 sdbout_toplevel_data (decl);
1510 /* Output initialized global vars at the end, in the order of
1511 definition. See comment in sdbout_global_decl. */
1513 static void
1514 sdbout_finish (main_filename)
1515 const char *main_filename ATTRIBUTE_UNUSED;
1517 tree decl = getdecls ();
1518 unsigned int len = list_length (decl);
1519 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
1520 unsigned int i;
1522 /* Process the decls in reverse order--earliest first. Put them
1523 into VEC from back to front, then take out from front. */
1525 for (i = 0; i < len; i++, decl = TREE_CHAIN (decl))
1526 vec[len - i - 1] = decl;
1528 for (i = 0; i < len; i++)
1530 decl = vec[i];
1531 if (TREE_CODE (decl) == VAR_DECL
1532 && ! DECL_EXTERNAL (decl)
1533 && DECL_INITIAL (decl)
1534 && TREE_PUBLIC (decl)
1535 && DECL_RTL_SET_P (decl))
1536 sdbout_symbol (decl, 0);
1539 free (vec);
1542 /* Describe the beginning of an internal block within a function.
1543 Also output descriptions of variables defined in this block.
1545 N is the number of the block, by order of beginning, counting from 1,
1546 and not counting the outermost (function top-level) block.
1547 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1548 if the count starts at 0 for the outermost one. */
1550 static void
1551 sdbout_begin_block (line, n)
1552 unsigned int line;
1553 unsigned int n;
1555 tree decl = current_function_decl;
1556 MAKE_LINE_SAFE (line);
1558 /* The SCO compiler does not emit a separate block for the function level
1559 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1560 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1561 #ifndef MIPS_DEBUGGING_INFO
1562 if (n != 1)
1563 #endif
1564 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1566 if (n == 1)
1568 /* Include the outermost BLOCK's variables in block 1. */
1569 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1570 sdbout_block (DECL_INITIAL (decl));
1572 /* If -g1, suppress all the internal symbols of functions
1573 except for arguments. */
1574 if (debug_info_level != DINFO_LEVEL_TERSE)
1576 do_block = n;
1577 sdbout_block (DECL_INITIAL (decl));
1580 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1581 sdbout_dequeue_anonymous_types ();
1582 #endif
1585 /* Describe the end line-number of an internal block within a function. */
1587 static void
1588 sdbout_end_block (line, n)
1589 unsigned int line;
1590 unsigned int n ATTRIBUTE_UNUSED;
1592 MAKE_LINE_SAFE (line);
1594 /* The SCO compiler does not emit a separate block for the function level
1595 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1596 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1597 #ifndef MIPS_DEBUGGING_INFO
1598 if (n != 1)
1599 #endif
1600 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1603 static void
1604 sdbout_source_line (line, filename)
1605 unsigned int line;
1606 const char *filename ATTRIBUTE_UNUSED;
1608 /* COFF relative line numbers must be positive. */
1609 if (line > sdb_begin_function_line)
1611 #ifdef ASM_OUTPUT_SOURCE_LINE
1612 ASM_OUTPUT_SOURCE_LINE (asm_out_file, line);
1613 #else
1614 fprintf (asm_out_file, "\t.ln\t%d\n",
1615 ((sdb_begin_function_line > -1)
1616 ? line - sdb_begin_function_line : 1));
1617 #endif
1621 /* Output sdb info for the current function name.
1622 Called from assemble_start_function. */
1624 static void
1625 sdbout_begin_function (decl)
1626 tree decl ATTRIBUTE_UNUSED;
1628 sdbout_symbol (current_function_decl, 0);
1631 /* Called at beginning of function body (before or after prologue,
1632 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1633 line number, so we can output relative line numbers for the other
1634 lines. Describe beginning of outermost block. Also describe the
1635 parameter list. */
1637 #ifndef MIPS_DEBUGGING_INFO
1638 static void
1639 sdbout_begin_prologue (line, file)
1640 unsigned int line;
1641 const char *file ATTRIBUTE_UNUSED;
1643 sdbout_end_prologue (line);
1645 #endif
1647 static void
1648 sdbout_end_prologue (line)
1649 unsigned int line;
1651 sdb_begin_function_line = line - 1;
1652 PUT_SDB_FUNCTION_START (line);
1653 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1654 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1657 /* Called at end of function (before epilogue).
1658 Describe end of outermost block. */
1660 static void
1661 sdbout_end_function (line)
1662 unsigned int line;
1664 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1665 sdbout_dequeue_anonymous_types ();
1666 #endif
1668 MAKE_LINE_SAFE (line);
1669 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1671 /* Indicate we are between functions, for line-number output. */
1672 sdb_begin_function_line = -1;
1675 /* Output sdb info for the absolute end of a function.
1676 Called after the epilogue is output. */
1678 static void
1679 sdbout_end_epilogue ()
1681 const char *name
1682 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1684 #ifdef PUT_SDB_EPILOGUE_END
1685 PUT_SDB_EPILOGUE_END (name);
1686 #else
1687 fprintf (asm_out_file, "\t.def\t");
1688 assemble_name (asm_out_file, name);
1689 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1690 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1691 #endif
1694 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1695 is present. */
1697 static void
1698 sdbout_label (insn)
1699 register rtx insn;
1701 PUT_SDB_DEF (LABEL_NAME (insn));
1702 PUT_SDB_VAL (insn);
1703 PUT_SDB_SCL (C_LABEL);
1704 PUT_SDB_TYPE (T_NULL);
1705 PUT_SDB_ENDEF;
1708 /* Change to reading from a new source file. */
1710 static void
1711 sdbout_start_source_file (line, filename)
1712 unsigned int line ATTRIBUTE_UNUSED;
1713 const char *filename ATTRIBUTE_UNUSED;
1715 #ifdef MIPS_DEBUGGING_INFO
1716 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1718 n->next = current_file;
1719 n->name = filename;
1720 current_file = n;
1721 PUT_SDB_SRC_FILE (filename);
1722 #endif
1725 /* Revert to reading a previous source file. */
1727 static void
1728 sdbout_end_source_file (line)
1729 unsigned int line ATTRIBUTE_UNUSED;
1731 #ifdef MIPS_DEBUGGING_INFO
1732 struct sdb_file *next;
1734 next = current_file->next;
1735 free (current_file);
1736 current_file = next;
1737 PUT_SDB_SRC_FILE (current_file->name);
1738 #endif
1741 /* Set up for SDB output at the start of compilation. */
1743 static void
1744 sdbout_init (input_file_name)
1745 const char *input_file_name ATTRIBUTE_UNUSED;
1747 #ifdef MIPS_DEBUGGING_INFO
1748 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1749 current_file->next = NULL;
1750 current_file->name = input_file_name;
1751 #endif
1753 #ifdef RMS_QUICK_HACK_1
1754 tree t;
1755 for (t = getdecls (); t; t = TREE_CHAIN (t))
1756 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
1757 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
1758 sdbout_symbol (t, 0);
1759 #endif
1761 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1762 ggc_add_tree_root (&anonymous_types, 1);
1763 #endif
1766 #endif /* SDB_DEBUGGING_INFO */