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