2003-05-31 Bud Davis <bdavis9659@comcast.net>
[official-gcc.git] / gcc / sdbout.c
blob9ad9f4295d56591835d38745fc9c15edd6dcee6c
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 "coretypes.h"
47 #include "tm.h"
48 #include "debug.h"
49 #include "tree.h"
50 #include "ggc.h"
52 static GTY(()) tree anonymous_types;
54 #ifdef SDB_DEBUGGING_INFO
56 #include "rtl.h"
57 #include "regs.h"
58 #include "flags.h"
59 #include "insn-config.h"
60 #include "reload.h"
61 #include "output.h"
62 #include "toplev.h"
63 #include "tm_p.h"
64 #include "gsyms.h"
65 #include "langhooks.h"
66 #include "target.h"
68 /* 1 if PARM is passed to this function in memory. */
70 #define PARM_PASSED_IN_MEMORY(PARM) \
71 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
73 /* A C expression for the integer offset value of an automatic variable
74 (C_AUTO) having address X (an RTX). */
75 #ifndef DEBUGGER_AUTO_OFFSET
76 #define DEBUGGER_AUTO_OFFSET(X) \
77 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
78 #endif
80 /* A C expression for the integer offset value of an argument (C_ARG)
81 having address X (an RTX). The nominal offset is OFFSET. */
82 #ifndef DEBUGGER_ARG_OFFSET
83 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
84 #endif
86 /* Line number of beginning of current function, minus one.
87 Negative means not in a function or not using sdb. */
89 int sdb_begin_function_line = -1;
91 /* Counter to generate unique "names" for nameless struct members. */
93 static int unnamed_struct_number = 0;
95 extern FILE *asm_out_file;
97 extern tree current_function_decl;
99 #include "sdbout.h"
101 static void sdbout_init PARAMS ((const char *));
102 static void sdbout_finish PARAMS ((const char *));
103 static void sdbout_start_source_file PARAMS ((unsigned int, const char *));
104 static void sdbout_end_source_file PARAMS ((unsigned int));
105 static void sdbout_begin_block PARAMS ((unsigned int, unsigned int));
106 static void sdbout_end_block PARAMS ((unsigned int, unsigned int));
107 static void sdbout_source_line PARAMS ((unsigned int, const char *));
108 static void sdbout_end_epilogue PARAMS ((unsigned int, const char *));
109 static void sdbout_global_decl PARAMS ((tree));
110 #ifndef MIPS_DEBUGGING_INFO
111 static void sdbout_begin_prologue PARAMS ((unsigned int, const char *));
112 #endif
113 static void sdbout_end_prologue PARAMS ((unsigned int, const char *));
114 static void sdbout_begin_function PARAMS ((tree));
115 static void sdbout_end_function PARAMS ((unsigned int));
116 static void sdbout_toplevel_data PARAMS ((tree));
117 static void sdbout_label PARAMS ((rtx));
118 static char *gen_fake_label PARAMS ((void));
119 static int plain_type PARAMS ((tree));
120 static int template_name_p PARAMS ((tree));
121 static void sdbout_record_type_name PARAMS ((tree));
122 static int plain_type_1 PARAMS ((tree, int));
123 static void sdbout_block PARAMS ((tree));
124 static void sdbout_syms PARAMS ((tree));
125 #ifdef SDB_ALLOW_FORWARD_REFERENCES
126 static void sdbout_queue_anonymous_type PARAMS ((tree));
127 static void sdbout_dequeue_anonymous_types PARAMS ((void));
128 #endif
129 static void sdbout_type PARAMS ((tree));
130 static void sdbout_field_types PARAMS ((tree));
131 static void sdbout_one_type PARAMS ((tree));
132 static void sdbout_parms PARAMS ((tree));
133 static void sdbout_reg_parms PARAMS ((tree));
134 static void sdbout_global_decl PARAMS ((tree));
136 /* Random macros describing parts of SDB data. */
138 /* Put something here if lines get too long */
139 #define CONTIN
141 /* Default value of delimiter is ";". */
142 #ifndef SDB_DELIM
143 #define SDB_DELIM ";"
144 #endif
146 /* Maximum number of dimensions the assembler will allow. */
147 #ifndef SDB_MAX_DIM
148 #define SDB_MAX_DIM 4
149 #endif
151 #ifndef PUT_SDB_SCL
152 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
153 #endif
155 #ifndef PUT_SDB_INT_VAL
156 #define PUT_SDB_INT_VAL(a) \
157 do { \
158 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
159 (HOST_WIDE_INT) (a), SDB_DELIM); \
160 } while (0)
162 #endif
164 #ifndef PUT_SDB_VAL
165 #define PUT_SDB_VAL(a) \
166 ( fputs ("\t.val\t", asm_out_file), \
167 output_addr_const (asm_out_file, (a)), \
168 fprintf (asm_out_file, SDB_DELIM))
169 #endif
171 #ifndef PUT_SDB_DEF
172 #define PUT_SDB_DEF(a) \
173 do { fprintf (asm_out_file, "\t.def\t"); \
174 assemble_name (asm_out_file, a); \
175 fprintf (asm_out_file, SDB_DELIM); } while (0)
176 #endif
178 #ifndef PUT_SDB_PLAIN_DEF
179 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
180 #endif
182 #ifndef PUT_SDB_ENDEF
183 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
184 #endif
186 #ifndef PUT_SDB_TYPE
187 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
188 #endif
190 #ifndef PUT_SDB_SIZE
191 #define PUT_SDB_SIZE(a) \
192 do { \
193 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
194 (HOST_WIDE_INT) (a), SDB_DELIM); \
195 } while(0)
196 #endif
198 #ifndef PUT_SDB_START_DIM
199 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
200 #endif
202 #ifndef PUT_SDB_NEXT_DIM
203 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
204 #endif
206 #ifndef PUT_SDB_LAST_DIM
207 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
208 #endif
210 #ifndef PUT_SDB_TAG
211 #define PUT_SDB_TAG(a) \
212 do { fprintf (asm_out_file, "\t.tag\t"); \
213 assemble_name (asm_out_file, a); \
214 fprintf (asm_out_file, SDB_DELIM); } while (0)
215 #endif
217 #ifndef PUT_SDB_BLOCK_START
218 #define PUT_SDB_BLOCK_START(LINE) \
219 fprintf (asm_out_file, \
220 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
221 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
222 #endif
224 #ifndef PUT_SDB_BLOCK_END
225 #define PUT_SDB_BLOCK_END(LINE) \
226 fprintf (asm_out_file, \
227 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
228 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
229 #endif
231 #ifndef PUT_SDB_FUNCTION_START
232 #define PUT_SDB_FUNCTION_START(LINE) \
233 fprintf (asm_out_file, \
234 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
235 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
236 #endif
238 #ifndef PUT_SDB_FUNCTION_END
239 #define PUT_SDB_FUNCTION_END(LINE) \
240 fprintf (asm_out_file, \
241 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
242 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
243 #endif
245 #ifndef SDB_GENERATE_FAKE
246 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
247 sprintf ((BUFFER), ".%dfake", (NUMBER));
248 #endif
250 /* Return the sdb tag identifier string for TYPE
251 if TYPE has already been defined; otherwise return a null pointer. */
253 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
255 /* Set the sdb tag identifier string for TYPE to NAME. */
257 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
258 TYPE_SYMTAB_POINTER (TYPE) = (char *)(NAME)
260 /* Return the name (a string) of the struct, union or enum tag
261 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
263 #define TAG_NAME(link) \
264 (((link) && TREE_PURPOSE ((link)) \
265 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
266 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
268 /* Ensure we don't output a negative line number. */
269 #define MAKE_LINE_SAFE(line) \
270 if ((int) line <= sdb_begin_function_line) \
271 line = sdb_begin_function_line + 1
273 /* Perform linker optimization of merging header file definitions together
274 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
275 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
276 the optimization just won't be done. The native assembler already has the
277 necessary support. */
279 #ifdef MIPS_DEBUGGING_INFO
281 #ifndef PUT_SDB_SRC_FILE
282 #define PUT_SDB_SRC_FILE(FILENAME) \
283 output_file_directive (asm_out_file, (FILENAME))
284 #endif
286 /* ECOFF linkers have an optimization that does the same kind of thing as
287 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
288 executable. To achieve this, GCC must output a .file for each file
289 name change. */
291 /* This is a stack of input files. */
293 struct sdb_file
295 struct sdb_file *next;
296 const char *name;
299 /* This is the top of the stack. */
301 static struct sdb_file *current_file;
303 #endif /* MIPS_DEBUGGING_INFO */
305 /* The debug hooks structure. */
306 const struct gcc_debug_hooks sdb_debug_hooks =
308 sdbout_init, /* init */
309 sdbout_finish, /* finish */
310 debug_nothing_int_charstar, /* define */
311 debug_nothing_int_charstar, /* undef */
312 sdbout_start_source_file, /* start_source_file */
313 sdbout_end_source_file, /* end_source_file */
314 sdbout_begin_block, /* begin_block */
315 sdbout_end_block, /* end_block */
316 debug_true_tree, /* ignore_block */
317 sdbout_source_line, /* source_line */
318 #ifdef MIPS_DEBUGGING_INFO
319 /* Defer on MIPS systems so that parameter descriptions follow
320 function entry. */
321 debug_nothing_int_charstar, /* begin_prologue */
322 sdbout_end_prologue, /* end_prologue */
323 #else
324 sdbout_begin_prologue, /* begin_prologue */
325 debug_nothing_int_charstar, /* end_prologue */
326 #endif
327 sdbout_end_epilogue, /* end_epilogue */
328 sdbout_begin_function, /* begin_function */
329 sdbout_end_function, /* end_function */
330 debug_nothing_tree, /* function_decl */
331 sdbout_global_decl, /* global_decl */
332 debug_nothing_tree, /* deferred_inline_function */
333 debug_nothing_tree, /* outlining_inline_function */
334 sdbout_label, /* label */
335 debug_nothing_int /* handle_pch */
338 #if 0
340 /* return the tag identifier for type
343 char *
344 tag_of_ru_type (type,link)
345 tree type,link;
347 if (TYPE_SYMTAB_ADDRESS (type))
348 return TYPE_SYMTAB_ADDRESS (type);
349 if (link && TREE_PURPOSE (link)
350 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
351 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
352 else
353 return (char *) TYPE_SYMTAB_ADDRESS (type);
355 #endif
357 /* Return a unique string to name an anonymous type. */
359 static char *
360 gen_fake_label ()
362 char label[10];
363 char *labelstr;
364 SDB_GENERATE_FAKE (label, unnamed_struct_number);
365 unnamed_struct_number++;
366 labelstr = xstrdup (label);
367 return labelstr;
370 /* Return the number which describes TYPE for SDB.
371 For pointers, etc., this function is recursive.
372 Each record, union or enumeral type must already have had a
373 tag number output. */
375 /* The number is given by d6d5d4d3d2d1bbbb
376 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
377 Thus, char *foo () has bbbb=T_CHAR
378 d1=D_FCN
379 d2=D_PTR
380 N_BTMASK= 017 1111 basic type field.
381 N_TSHIFT= 2 derived type shift
382 N_BTSHFT= 4 Basic type shift */
384 /* Produce the number that describes a pointer, function or array type.
385 PREV is the number describing the target, value or element type.
386 DT_type describes how to transform that type. */
387 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
388 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
389 | ((int) DT_type << (int) N_BTSHFT) \
390 | ((PREV) & (int) N_BTMASK))
392 /* Number of elements used in sdb_dims. */
393 static int sdb_n_dims = 0;
395 /* Table of array dimensions of current type. */
396 static int sdb_dims[SDB_MAX_DIM];
398 /* Size of outermost array currently being processed. */
399 static int sdb_type_size = -1;
401 static int
402 plain_type (type)
403 tree type;
405 int val = plain_type_1 (type, 0);
407 /* If we have already saved up some array dimensions, print them now. */
408 if (sdb_n_dims > 0)
410 int i;
411 PUT_SDB_START_DIM;
412 for (i = sdb_n_dims - 1; i > 0; i--)
413 PUT_SDB_NEXT_DIM (sdb_dims[i]);
414 PUT_SDB_LAST_DIM (sdb_dims[0]);
415 sdb_n_dims = 0;
417 sdb_type_size = int_size_in_bytes (type);
418 /* Don't kill sdb if type is not laid out or has variable size. */
419 if (sdb_type_size < 0)
420 sdb_type_size = 0;
422 /* If we have computed the size of an array containing this type,
423 print it now. */
424 if (sdb_type_size >= 0)
426 PUT_SDB_SIZE (sdb_type_size);
427 sdb_type_size = -1;
429 return val;
432 static int
433 template_name_p (name)
434 tree name;
436 const char *ptr = IDENTIFIER_POINTER (name);
437 while (*ptr && *ptr != '<')
438 ptr++;
440 return *ptr != '\0';
443 static void
444 sdbout_record_type_name (type)
445 tree type;
447 const char *name = 0;
448 int no_name;
450 if (KNOWN_TYPE_TAG (type))
451 return;
453 if (TYPE_NAME (type) != 0)
455 tree t = 0;
457 /* Find the IDENTIFIER_NODE for the type name. */
458 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
459 t = TYPE_NAME (type);
460 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
462 t = DECL_NAME (TYPE_NAME (type));
463 /* The DECL_NAME for templates includes "<>", which breaks
464 most assemblers. Use its assembler name instead, which
465 has been mangled into being safe. */
466 if (t && template_name_p (t))
467 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
470 /* Now get the name as a string, or invent one. */
471 if (t != NULL_TREE)
472 name = IDENTIFIER_POINTER (t);
475 no_name = (name == 0 || *name == 0);
476 if (no_name)
477 name = gen_fake_label ();
479 SET_KNOWN_TYPE_TAG (type, name);
480 #ifdef SDB_ALLOW_FORWARD_REFERENCES
481 if (no_name)
482 sdbout_queue_anonymous_type (type);
483 #endif
486 /* Return the .type value for type TYPE.
488 LEVEL indicates how many levels deep we have recursed into the type.
489 The SDB debug format can only represent 6 derived levels of types.
490 After that, we must output inaccurate debug info. We deliberately
491 stop before the 7th level, so that ADA recursive types will not give an
492 infinite loop. */
494 static int
495 plain_type_1 (type, level)
496 tree type;
497 int level;
499 if (type == 0)
500 type = void_type_node;
501 else if (type == error_mark_node)
502 type = integer_type_node;
503 else
504 type = TYPE_MAIN_VARIANT (type);
506 switch (TREE_CODE (type))
508 case VOID_TYPE:
509 return T_VOID;
510 case BOOLEAN_TYPE:
511 case INTEGER_TYPE:
513 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
515 /* Carefully distinguish all the standard types of C,
516 without messing up if the language is not C.
517 Note that we check only for the names that contain spaces;
518 other names might occur by coincidence in other languages. */
519 if (TYPE_NAME (type) != 0
520 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
521 && DECL_NAME (TYPE_NAME (type)) != 0
522 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
524 const char *const name
525 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
527 if (!strcmp (name, "char"))
528 return T_CHAR;
529 if (!strcmp (name, "unsigned char"))
530 return T_UCHAR;
531 if (!strcmp (name, "signed char"))
532 return T_CHAR;
533 if (!strcmp (name, "int"))
534 return T_INT;
535 if (!strcmp (name, "unsigned int"))
536 return T_UINT;
537 if (!strcmp (name, "short int"))
538 return T_SHORT;
539 if (!strcmp (name, "short unsigned int"))
540 return T_USHORT;
541 if (!strcmp (name, "long int"))
542 return T_LONG;
543 if (!strcmp (name, "long unsigned int"))
544 return T_ULONG;
547 if (size == INT_TYPE_SIZE)
548 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
549 if (size == CHAR_TYPE_SIZE)
550 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
551 if (size == SHORT_TYPE_SIZE)
552 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
553 if (size == LONG_TYPE_SIZE)
554 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
555 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
556 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
557 return 0;
560 case REAL_TYPE:
562 int precision = TYPE_PRECISION (type);
563 if (precision == FLOAT_TYPE_SIZE)
564 return T_FLOAT;
565 if (precision == DOUBLE_TYPE_SIZE)
566 return T_DOUBLE;
567 #ifdef EXTENDED_SDB_BASIC_TYPES
568 if (precision == LONG_DOUBLE_TYPE_SIZE)
569 return T_LNGDBL;
570 #else
571 if (precision == LONG_DOUBLE_TYPE_SIZE)
572 return T_DOUBLE; /* better than nothing */
573 #endif
574 return 0;
577 case ARRAY_TYPE:
579 int m;
580 if (level >= 6)
581 return T_VOID;
582 else
583 m = plain_type_1 (TREE_TYPE (type), level+1);
584 if (sdb_n_dims < SDB_MAX_DIM)
585 sdb_dims[sdb_n_dims++]
586 = (TYPE_DOMAIN (type)
587 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
588 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
589 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
590 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
591 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
592 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
593 : 0);
595 return PUSH_DERIVED_LEVEL (DT_ARY, m);
598 case RECORD_TYPE:
599 case UNION_TYPE:
600 case QUAL_UNION_TYPE:
601 case ENUMERAL_TYPE:
603 char *tag;
604 #ifdef SDB_ALLOW_FORWARD_REFERENCES
605 sdbout_record_type_name (type);
606 #endif
607 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
608 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
609 #ifdef SDB_ALLOW_FORWARD_REFERENCES
610 || TYPE_MODE (type) != VOIDmode
611 #endif
613 #endif
615 /* Output the referenced structure tag name
616 only if the .def has already been finished.
617 At least on 386, the Unix assembler
618 cannot handle forward references to tags. */
619 /* But the 88100, it requires them, sigh... */
620 /* And the MIPS requires unknown refs as well... */
621 tag = KNOWN_TYPE_TAG (type);
622 PUT_SDB_TAG (tag);
623 /* These 3 lines used to follow the close brace.
624 However, a size of 0 without a tag implies a tag of 0,
625 so if we don't know a tag, we can't mention the size. */
626 sdb_type_size = int_size_in_bytes (type);
627 if (sdb_type_size < 0)
628 sdb_type_size = 0;
630 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
631 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
632 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
633 : T_ENUM);
635 case POINTER_TYPE:
636 case REFERENCE_TYPE:
638 int m;
639 if (level >= 6)
640 return T_VOID;
641 else
642 m = plain_type_1 (TREE_TYPE (type), level+1);
643 return PUSH_DERIVED_LEVEL (DT_PTR, m);
645 case FUNCTION_TYPE:
646 case METHOD_TYPE:
648 int m;
649 if (level >= 6)
650 return T_VOID;
651 else
652 m = plain_type_1 (TREE_TYPE (type), level+1);
653 return PUSH_DERIVED_LEVEL (DT_FCN, m);
655 default:
656 return 0;
660 /* Output the symbols defined in block number DO_BLOCK.
662 This function works by walking the tree structure of blocks,
663 counting blocks until it finds the desired block. */
665 static int do_block = 0;
667 static void
668 sdbout_block (block)
669 tree block;
671 while (block)
673 /* Ignore blocks never expanded or otherwise marked as real. */
674 if (TREE_USED (block))
676 /* When we reach the specified block, output its symbols. */
677 if (BLOCK_NUMBER (block) == do_block)
678 sdbout_syms (BLOCK_VARS (block));
680 /* If we are past the specified block, stop the scan. */
681 if (BLOCK_NUMBER (block) > do_block)
682 return;
684 /* Scan the blocks within this block. */
685 sdbout_block (BLOCK_SUBBLOCKS (block));
688 block = BLOCK_CHAIN (block);
692 /* Call sdbout_symbol on each decl in the chain SYMS. */
694 static void
695 sdbout_syms (syms)
696 tree syms;
698 while (syms)
700 if (TREE_CODE (syms) != LABEL_DECL)
701 sdbout_symbol (syms, 1);
702 syms = TREE_CHAIN (syms);
706 /* Output SDB information for a symbol described by DECL.
707 LOCAL is nonzero if the symbol is not file-scope. */
709 void
710 sdbout_symbol (decl, local)
711 tree decl;
712 int local;
714 tree type = TREE_TYPE (decl);
715 tree context = NULL_TREE;
716 rtx value;
717 int regno = -1;
718 const char *name;
720 sdbout_one_type (type);
722 #if 0 /* This loses when functions are marked to be ignored,
723 which happens in the C++ front end. */
724 if (DECL_IGNORED_P (decl))
725 return;
726 #endif
728 switch (TREE_CODE (decl))
730 case CONST_DECL:
731 /* Enum values are defined by defining the enum type. */
732 return;
734 case FUNCTION_DECL:
735 /* Don't mention a nested function under its parent. */
736 context = decl_function_context (decl);
737 if (context == current_function_decl)
738 return;
739 /* Check DECL_INITIAL to distinguish declarations from definitions.
740 Don't output debug info here for declarations; they will have
741 a DECL_INITIAL value of 0. */
742 if (! DECL_INITIAL (decl))
743 return;
744 if (GET_CODE (DECL_RTL (decl)) != MEM
745 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
746 return;
747 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
748 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
749 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
750 break;
752 case TYPE_DECL:
753 /* Done with tagged types. */
754 if (DECL_NAME (decl) == 0)
755 return;
756 if (DECL_IGNORED_P (decl))
757 return;
759 /* Output typedef name. */
760 if (template_name_p (DECL_NAME (decl)))
761 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
762 else
763 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
764 PUT_SDB_SCL (C_TPDEF);
765 break;
767 case PARM_DECL:
768 /* Parm decls go in their own separate chains
769 and are output by sdbout_reg_parms and sdbout_parms. */
770 abort ();
772 case VAR_DECL:
773 /* Don't mention a variable that is external.
774 Let the file that defines it describe it. */
775 if (DECL_EXTERNAL (decl))
776 return;
778 /* Ignore __FUNCTION__, etc. */
779 if (DECL_IGNORED_P (decl))
780 return;
782 /* If there was an error in the declaration, don't dump core
783 if there is no RTL associated with the variable doesn't
784 exist. */
785 if (!DECL_RTL_SET_P (decl))
786 return;
788 SET_DECL_RTL (decl,
789 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
790 #ifdef LEAF_REG_REMAP
791 if (current_function_uses_only_leaf_regs)
792 leaf_renumber_regs_insn (DECL_RTL (decl));
793 #endif
794 value = DECL_RTL (decl);
796 /* Don't mention a variable at all
797 if it was completely optimized into nothingness.
799 If DECL was from an inline function, then its rtl
800 is not identically the rtl that was used in this
801 particular compilation. */
802 if (GET_CODE (value) == REG)
804 regno = REGNO (value);
805 if (regno >= FIRST_PSEUDO_REGISTER)
806 return;
808 else if (GET_CODE (value) == SUBREG)
810 while (GET_CODE (value) == SUBREG)
811 value = SUBREG_REG (value);
812 if (GET_CODE (value) == REG)
814 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
815 return;
817 regno = REGNO (alter_subreg (&value));
818 SET_DECL_RTL (decl, value);
820 /* Don't output anything if an auto variable
821 gets RTL that is static.
822 GAS version 2.2 can't handle such output. */
823 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
824 && ! TREE_STATIC (decl))
825 return;
827 /* Emit any structure, union, or enum type that has not been output.
828 This occurs for tag-less structs (et al) used to declare variables
829 within functions. */
830 if (TREE_CODE (type) == ENUMERAL_TYPE
831 || TREE_CODE (type) == RECORD_TYPE
832 || TREE_CODE (type) == UNION_TYPE
833 || TREE_CODE (type) == QUAL_UNION_TYPE)
835 if (COMPLETE_TYPE_P (type) /* not a forward reference */
836 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
837 sdbout_one_type (type);
840 /* Defer SDB information for top-level initialized variables! */
841 if (! local
842 && GET_CODE (value) == MEM
843 && DECL_INITIAL (decl))
844 return;
846 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
847 For now, avoid crashing. */
848 if (DECL_NAME (decl) == NULL_TREE)
849 return;
851 /* Record the name for, starting a symtab entry. */
852 if (local)
853 name = IDENTIFIER_POINTER (DECL_NAME (decl));
854 else
855 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
857 if (GET_CODE (value) == MEM
858 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
860 PUT_SDB_DEF (name);
861 if (TREE_PUBLIC (decl))
863 PUT_SDB_VAL (XEXP (value, 0));
864 PUT_SDB_SCL (C_EXT);
866 else
868 PUT_SDB_VAL (XEXP (value, 0));
869 PUT_SDB_SCL (C_STAT);
872 else if (regno >= 0)
874 PUT_SDB_DEF (name);
875 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
876 PUT_SDB_SCL (C_REG);
878 else if (GET_CODE (value) == MEM
879 && (GET_CODE (XEXP (value, 0)) == MEM
880 || (GET_CODE (XEXP (value, 0)) == REG
881 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
882 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
883 /* If the value is indirect by memory or by a register
884 that isn't the frame pointer
885 then it means the object is variable-sized and address through
886 that register or stack slot. COFF has no way to represent this
887 so all we can do is output the variable as a pointer. */
889 PUT_SDB_DEF (name);
890 if (GET_CODE (XEXP (value, 0)) == REG)
892 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
893 PUT_SDB_SCL (C_REG);
895 else
897 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
898 (CONST_INT...)))).
899 We want the value of that CONST_INT. */
900 /* Encore compiler hates a newline in a macro arg, it seems. */
901 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
902 (XEXP (XEXP (value, 0), 0)));
903 PUT_SDB_SCL (C_AUTO);
906 /* Effectively do build_pointer_type, but don't cache this type,
907 since it might be temporary whereas the type it points to
908 might have been saved for inlining. */
909 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
910 type = make_node (POINTER_TYPE);
911 TREE_TYPE (type) = TREE_TYPE (decl);
913 else if (GET_CODE (value) == MEM
914 && ((GET_CODE (XEXP (value, 0)) == PLUS
915 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
916 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
917 /* This is for variables which are at offset zero from
918 the frame pointer. This happens on the Alpha.
919 Non-frame pointer registers are excluded above. */
920 || (GET_CODE (XEXP (value, 0)) == REG)))
922 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
923 or (MEM (REG...)). We want the value of that CONST_INT
924 or zero. */
925 PUT_SDB_DEF (name);
926 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
927 PUT_SDB_SCL (C_AUTO);
929 else
931 /* It is something we don't know how to represent for SDB. */
932 return;
934 break;
936 default:
937 break;
939 PUT_SDB_TYPE (plain_type (type));
940 PUT_SDB_ENDEF;
943 /* Output SDB information for a top-level initialized variable
944 that has been delayed. */
946 static void
947 sdbout_toplevel_data (decl)
948 tree decl;
950 tree type = TREE_TYPE (decl);
952 if (DECL_IGNORED_P (decl))
953 return;
955 if (! (TREE_CODE (decl) == VAR_DECL
956 && GET_CODE (DECL_RTL (decl)) == MEM
957 && DECL_INITIAL (decl)))
958 abort ();
960 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
961 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
962 if (TREE_PUBLIC (decl))
964 PUT_SDB_SCL (C_EXT);
966 else
968 PUT_SDB_SCL (C_STAT);
970 PUT_SDB_TYPE (plain_type (type));
971 PUT_SDB_ENDEF;
974 #ifdef SDB_ALLOW_FORWARD_REFERENCES
976 /* Machinery to record and output anonymous types. */
978 static void
979 sdbout_queue_anonymous_type (type)
980 tree type;
982 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
985 static void
986 sdbout_dequeue_anonymous_types ()
988 tree types, link;
990 while (anonymous_types)
992 types = nreverse (anonymous_types);
993 anonymous_types = NULL_TREE;
995 for (link = types; link; link = TREE_CHAIN (link))
997 tree type = TREE_VALUE (link);
999 if (type && ! TREE_ASM_WRITTEN (type))
1000 sdbout_one_type (type);
1005 #endif
1007 /* Given a chain of ..._TYPE nodes, all of which have names,
1008 output definitions of those names, as typedefs. */
1010 void
1011 sdbout_types (types)
1012 tree types;
1014 tree link;
1016 for (link = types; link; link = TREE_CHAIN (link))
1017 sdbout_one_type (link);
1019 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1020 sdbout_dequeue_anonymous_types ();
1021 #endif
1024 static void
1025 sdbout_type (type)
1026 tree type;
1028 if (type == error_mark_node)
1029 type = integer_type_node;
1030 PUT_SDB_TYPE (plain_type (type));
1033 /* Output types of the fields of type TYPE, if they are structs.
1035 Formerly did not chase through pointer types, since that could be circular.
1036 They must come before TYPE, since forward refs are not allowed.
1037 Now james@bigtex.cactus.org says to try them. */
1039 static void
1040 sdbout_field_types (type)
1041 tree type;
1043 tree tail;
1045 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1046 /* This condition should match the one for emitting the actual
1047 members below. */
1048 if (TREE_CODE (tail) == FIELD_DECL
1049 && DECL_NAME (tail)
1050 && DECL_SIZE (tail)
1051 && host_integerp (DECL_SIZE (tail), 1)
1052 && host_integerp (bit_position (tail), 0))
1054 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1055 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1056 else
1057 sdbout_one_type (TREE_TYPE (tail));
1061 /* Use this to put out the top level defined record and union types
1062 for later reference. If this is a struct with a name, then put that
1063 name out. Other unnamed structs will have .xxfake labels generated so
1064 that they may be referred to later.
1065 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1066 It may NOT be called recursively. */
1068 static void
1069 sdbout_one_type (type)
1070 tree type;
1072 if (current_function_decl != NULL_TREE
1073 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1074 ; /* Don't change section amid function. */
1075 else
1076 text_section ();
1078 switch (TREE_CODE (type))
1080 case RECORD_TYPE:
1081 case UNION_TYPE:
1082 case QUAL_UNION_TYPE:
1083 case ENUMERAL_TYPE:
1084 type = TYPE_MAIN_VARIANT (type);
1085 /* Don't output a type twice. */
1086 if (TREE_ASM_WRITTEN (type))
1087 /* James said test TREE_ASM_BEING_WRITTEN here. */
1088 return;
1090 /* Output nothing if type is not yet defined. */
1091 if (!COMPLETE_TYPE_P (type))
1092 return;
1094 TREE_ASM_WRITTEN (type) = 1;
1095 #if 1
1096 /* This is reputed to cause trouble with the following case,
1097 but perhaps checking TYPE_SIZE above will fix it. */
1099 /* Here is a test case:
1101 struct foo {
1102 struct badstr *bbb;
1103 } forwardref;
1105 typedef struct intermediate {
1106 int aaaa;
1107 } intermediate_ref;
1109 typedef struct badstr {
1110 int ccccc;
1111 } badtype; */
1113 #if 0
1114 TREE_ASM_BEING_WRITTEN (type) = 1;
1115 #endif
1116 /* This change, which ought to make better output,
1117 used to make the COFF assembler unhappy.
1118 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1119 /* Before really doing anything, output types we want to refer to. */
1120 /* Note that in version 1 the following two lines
1121 are not used if forward references are in use. */
1122 if (TREE_CODE (type) != ENUMERAL_TYPE)
1123 sdbout_field_types (type);
1124 #if 0
1125 TREE_ASM_WRITTEN (type) = 1;
1126 #endif
1127 #endif
1129 /* Output a structure type. */
1131 int size = int_size_in_bytes (type);
1132 int member_scl = 0;
1133 tree tem;
1134 int i, n_baseclasses = 0;
1136 /* Record the type tag, but not in its permanent place just yet. */
1137 sdbout_record_type_name (type);
1139 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1141 switch (TREE_CODE (type))
1143 case UNION_TYPE:
1144 case QUAL_UNION_TYPE:
1145 PUT_SDB_SCL (C_UNTAG);
1146 PUT_SDB_TYPE (T_UNION);
1147 member_scl = C_MOU;
1148 break;
1150 case RECORD_TYPE:
1151 PUT_SDB_SCL (C_STRTAG);
1152 PUT_SDB_TYPE (T_STRUCT);
1153 member_scl = C_MOS;
1154 break;
1156 case ENUMERAL_TYPE:
1157 PUT_SDB_SCL (C_ENTAG);
1158 PUT_SDB_TYPE (T_ENUM);
1159 member_scl = C_MOE;
1160 break;
1162 default:
1163 break;
1166 PUT_SDB_SIZE (size);
1167 PUT_SDB_ENDEF;
1169 /* Print out the base class information with fields
1170 named after the types they hold. */
1171 /* This is only relevant to aggregate types. TYPE_BINFO is used
1172 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1173 case. */
1174 if (TREE_CODE (type) != ENUMERAL_TYPE)
1176 if (TYPE_BINFO (type)
1177 && TYPE_BINFO_BASETYPES (type))
1178 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1179 for (i = 0; i < n_baseclasses; i++)
1181 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1183 tree child_type = BINFO_TYPE (child);
1184 tree child_type_name;
1185 if (TYPE_NAME (child_type) == 0)
1186 continue;
1187 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1188 child_type_name = TYPE_NAME (child_type);
1189 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1191 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1192 if (child_type_name && template_name_p (child_type_name))
1193 child_type_name
1194 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1196 else
1197 continue;
1199 CONTIN;
1200 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1201 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1202 PUT_SDB_SCL (member_scl);
1203 sdbout_type (BINFO_TYPE (child));
1204 PUT_SDB_ENDEF;
1208 /* output the individual fields */
1210 if (TREE_CODE (type) == ENUMERAL_TYPE)
1212 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1213 if (host_integerp (TREE_VALUE (tem), 0))
1215 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1216 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1217 PUT_SDB_SCL (C_MOE);
1218 PUT_SDB_TYPE (T_MOE);
1219 PUT_SDB_ENDEF;
1222 else /* record or union type */
1223 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1224 /* Output the name, type, position (in bits), size (in bits)
1225 of each field. */
1227 /* Omit here the nameless fields that are used to skip bits.
1228 Also omit fields with variable size or position.
1229 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1230 if (TREE_CODE (tem) == FIELD_DECL
1231 && DECL_NAME (tem)
1232 && DECL_SIZE (tem)
1233 && host_integerp (DECL_SIZE (tem), 1)
1234 && host_integerp (bit_position (tem), 0))
1236 const char *name;
1238 CONTIN;
1239 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1240 PUT_SDB_DEF (name);
1241 if (DECL_BIT_FIELD_TYPE (tem))
1243 PUT_SDB_INT_VAL (int_bit_position (tem));
1244 PUT_SDB_SCL (C_FIELD);
1245 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1246 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1248 else
1250 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1251 PUT_SDB_SCL (member_scl);
1252 sdbout_type (TREE_TYPE (tem));
1254 PUT_SDB_ENDEF;
1256 /* output end of a structure,union, or enumeral definition */
1258 PUT_SDB_PLAIN_DEF ("eos");
1259 PUT_SDB_INT_VAL (size);
1260 PUT_SDB_SCL (C_EOS);
1261 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1262 PUT_SDB_SIZE (size);
1263 PUT_SDB_ENDEF;
1264 break;
1266 default:
1267 break;
1272 /* The following two functions output definitions of function parameters.
1273 Each parameter gets a definition locating it in the parameter list.
1274 Each parameter that is a register variable gets a second definition
1275 locating it in the register.
1277 Printing or argument lists in gdb uses the definitions that
1278 locate in the parameter list. But reference to the variable in
1279 expressions uses preferentially the definition as a register. */
1281 /* Output definitions, referring to storage in the parmlist,
1282 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1284 static void
1285 sdbout_parms (parms)
1286 tree parms;
1288 for (; parms; parms = TREE_CHAIN (parms))
1289 if (DECL_NAME (parms))
1291 int current_sym_value = 0;
1292 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1294 if (name == 0 || *name == 0)
1295 name = gen_fake_label ();
1297 /* Perform any necessary register eliminations on the parameter's rtl,
1298 so that the debugging output will be accurate. */
1299 DECL_INCOMING_RTL (parms)
1300 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1301 SET_DECL_RTL (parms,
1302 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1304 if (PARM_PASSED_IN_MEMORY (parms))
1306 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1307 tree type;
1309 /* ??? Here we assume that the parm address is indexed
1310 off the frame pointer or arg pointer.
1311 If that is not true, we produce meaningless results,
1312 but do not crash. */
1313 if (GET_CODE (addr) == PLUS
1314 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1315 current_sym_value = INTVAL (XEXP (addr, 1));
1316 else
1317 current_sym_value = 0;
1319 if (GET_CODE (DECL_RTL (parms)) == REG
1320 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1321 type = DECL_ARG_TYPE (parms);
1322 else
1324 int original_sym_value = current_sym_value;
1326 /* This is the case where the parm is passed as an int or
1327 double and it is converted to a char, short or float
1328 and stored back in the parmlist. In this case, describe
1329 the parm with the variable's declared type, and adjust
1330 the address if the least significant bytes (which we are
1331 using) are not the first ones. */
1332 if (BYTES_BIG_ENDIAN
1333 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1334 current_sym_value +=
1335 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1336 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1338 if (GET_CODE (DECL_RTL (parms)) == MEM
1339 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1340 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1341 == CONST_INT)
1342 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1343 == current_sym_value))
1344 type = TREE_TYPE (parms);
1345 else
1347 current_sym_value = original_sym_value;
1348 type = DECL_ARG_TYPE (parms);
1352 PUT_SDB_DEF (name);
1353 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1354 PUT_SDB_SCL (C_ARG);
1355 PUT_SDB_TYPE (plain_type (type));
1356 PUT_SDB_ENDEF;
1358 else if (GET_CODE (DECL_RTL (parms)) == REG)
1360 rtx best_rtl;
1361 /* Parm passed in registers and lives in registers or nowhere. */
1363 /* If parm lives in a register, use that register;
1364 pretend the parm was passed there. It would be more consistent
1365 to describe the register where the parm was passed,
1366 but in practice that register usually holds something else. */
1367 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1368 best_rtl = DECL_RTL (parms);
1369 /* If the parm lives nowhere,
1370 use the register where it was passed. */
1371 else
1372 best_rtl = DECL_INCOMING_RTL (parms);
1374 PUT_SDB_DEF (name);
1375 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1376 PUT_SDB_SCL (C_REGPARM);
1377 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1378 PUT_SDB_ENDEF;
1380 else if (GET_CODE (DECL_RTL (parms)) == MEM
1381 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1383 /* Parm was passed in registers but lives on the stack. */
1385 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1386 in which case we want the value of that CONST_INT,
1387 or (MEM (REG ...)) or (MEM (MEM ...)),
1388 in which case we use a value of zero. */
1389 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1390 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1391 current_sym_value = 0;
1392 else
1393 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1395 /* Again, this assumes the offset is based on the arg pointer. */
1396 PUT_SDB_DEF (name);
1397 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1398 XEXP (DECL_RTL (parms), 0)));
1399 PUT_SDB_SCL (C_ARG);
1400 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1401 PUT_SDB_ENDEF;
1406 /* Output definitions for the places where parms live during the function,
1407 when different from where they were passed, when the parms were passed
1408 in memory.
1410 It is not useful to do this for parms passed in registers
1411 that live during the function in different registers, because it is
1412 impossible to look in the passed register for the passed value,
1413 so we use the within-the-function register to begin with.
1415 PARMS is a chain of PARM_DECL nodes. */
1417 static void
1418 sdbout_reg_parms (parms)
1419 tree parms;
1421 for (; parms; parms = TREE_CHAIN (parms))
1422 if (DECL_NAME (parms))
1424 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1426 /* Report parms that live in registers during the function
1427 but were passed in memory. */
1428 if (GET_CODE (DECL_RTL (parms)) == REG
1429 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1430 && PARM_PASSED_IN_MEMORY (parms))
1432 if (name == 0 || *name == 0)
1433 name = gen_fake_label ();
1434 PUT_SDB_DEF (name);
1435 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1436 PUT_SDB_SCL (C_REG);
1437 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1438 PUT_SDB_ENDEF;
1440 /* Report parms that live in memory but not where they were passed. */
1441 else if (GET_CODE (DECL_RTL (parms)) == MEM
1442 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1443 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1444 && PARM_PASSED_IN_MEMORY (parms)
1445 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1447 #if 0 /* ??? It is not clear yet what should replace this. */
1448 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1449 /* A parm declared char is really passed as an int,
1450 so it occupies the least significant bytes.
1451 On a big-endian machine those are not the low-numbered ones. */
1452 if (BYTES_BIG_ENDIAN
1453 && offset != -1
1454 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1455 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1456 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1457 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1458 #endif
1460 if (name == 0 || *name == 0)
1461 name = gen_fake_label ();
1462 PUT_SDB_DEF (name);
1463 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1464 (XEXP (DECL_RTL (parms), 0)));
1465 PUT_SDB_SCL (C_AUTO);
1466 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1467 PUT_SDB_ENDEF;
1473 /* Output debug information for a global DECL. Called from toplev.c
1474 after compilation proper has finished. */
1476 static void
1477 sdbout_global_decl (decl)
1478 tree decl;
1480 if (TREE_CODE (decl) == VAR_DECL
1481 && !DECL_EXTERNAL (decl)
1482 && DECL_RTL_SET_P (decl))
1484 /* The COFF linker can move initialized global vars to the end.
1485 And that can screw up the symbol ordering. Defer those for
1486 sdbout_finish (). */
1487 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1488 sdbout_symbol (decl, 0);
1490 /* Output COFF information for non-global file-scope initialized
1491 variables. */
1492 if (DECL_INITIAL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
1493 sdbout_toplevel_data (decl);
1497 /* Output initialized global vars at the end, in the order of
1498 definition. See comment in sdbout_global_decl. */
1500 static void
1501 sdbout_finish (main_filename)
1502 const char *main_filename ATTRIBUTE_UNUSED;
1504 tree decl = (*lang_hooks.decls.getdecls) ();
1505 unsigned int len = list_length (decl);
1506 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
1507 unsigned int i;
1509 /* Process the decls in reverse order--earliest first. Put them
1510 into VEC from back to front, then take out from front. */
1512 for (i = 0; i < len; i++, decl = TREE_CHAIN (decl))
1513 vec[len - i - 1] = decl;
1515 for (i = 0; i < len; i++)
1517 decl = vec[i];
1518 if (TREE_CODE (decl) == VAR_DECL
1519 && ! DECL_EXTERNAL (decl)
1520 && DECL_INITIAL (decl)
1521 && TREE_PUBLIC (decl)
1522 && DECL_RTL_SET_P (decl))
1523 sdbout_symbol (decl, 0);
1526 free (vec);
1529 /* Describe the beginning of an internal block within a function.
1530 Also output descriptions of variables defined in this block.
1532 N is the number of the block, by order of beginning, counting from 1,
1533 and not counting the outermost (function top-level) block.
1534 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1535 if the count starts at 0 for the outermost one. */
1537 static void
1538 sdbout_begin_block (line, n)
1539 unsigned int line;
1540 unsigned int n;
1542 tree decl = current_function_decl;
1543 MAKE_LINE_SAFE (line);
1545 /* The SCO compiler does not emit a separate block for the function level
1546 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1547 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1548 #ifndef MIPS_DEBUGGING_INFO
1549 if (n != 1)
1550 #endif
1551 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1553 if (n == 1)
1555 /* Include the outermost BLOCK's variables in block 1. */
1556 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1557 sdbout_block (DECL_INITIAL (decl));
1559 /* If -g1, suppress all the internal symbols of functions
1560 except for arguments. */
1561 if (debug_info_level != DINFO_LEVEL_TERSE)
1563 do_block = n;
1564 sdbout_block (DECL_INITIAL (decl));
1567 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1568 sdbout_dequeue_anonymous_types ();
1569 #endif
1572 /* Describe the end line-number of an internal block within a function. */
1574 static void
1575 sdbout_end_block (line, n)
1576 unsigned int line;
1577 unsigned int n ATTRIBUTE_UNUSED;
1579 MAKE_LINE_SAFE (line);
1581 /* The SCO compiler does not emit a separate block for the function level
1582 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1583 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1584 #ifndef MIPS_DEBUGGING_INFO
1585 if (n != 1)
1586 #endif
1587 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1590 static void
1591 sdbout_source_line (line, filename)
1592 unsigned int line;
1593 const char *filename ATTRIBUTE_UNUSED;
1595 /* COFF relative line numbers must be positive. */
1596 if ((int) line > sdb_begin_function_line)
1598 #ifdef ASM_OUTPUT_SOURCE_LINE
1599 ASM_OUTPUT_SOURCE_LINE (asm_out_file, line);
1600 #else
1601 fprintf (asm_out_file, "\t.ln\t%d\n",
1602 ((sdb_begin_function_line > -1)
1603 ? line - sdb_begin_function_line : 1));
1604 #endif
1608 /* Output sdb info for the current function name.
1609 Called from assemble_start_function. */
1611 static void
1612 sdbout_begin_function (decl)
1613 tree decl ATTRIBUTE_UNUSED;
1615 sdbout_symbol (current_function_decl, 0);
1618 /* Called at beginning of function body (before or after prologue,
1619 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1620 line number, so we can output relative line numbers for the other
1621 lines. Describe beginning of outermost block. Also describe the
1622 parameter list. */
1624 #ifndef MIPS_DEBUGGING_INFO
1625 static void
1626 sdbout_begin_prologue (line, file)
1627 unsigned int line;
1628 const char *file ATTRIBUTE_UNUSED;
1630 sdbout_end_prologue (line, file);
1632 #endif
1634 static void
1635 sdbout_end_prologue (line, file)
1636 unsigned int line;
1637 const char *file ATTRIBUTE_UNUSED;
1639 sdb_begin_function_line = line - 1;
1640 PUT_SDB_FUNCTION_START (line);
1641 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1642 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1645 /* Called at end of function (before epilogue).
1646 Describe end of outermost block. */
1648 static void
1649 sdbout_end_function (line)
1650 unsigned int line;
1652 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1653 sdbout_dequeue_anonymous_types ();
1654 #endif
1656 MAKE_LINE_SAFE (line);
1657 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1659 /* Indicate we are between functions, for line-number output. */
1660 sdb_begin_function_line = -1;
1663 /* Output sdb info for the absolute end of a function.
1664 Called after the epilogue is output. */
1666 static void
1667 sdbout_end_epilogue (line, file)
1668 unsigned int line ATTRIBUTE_UNUSED;
1669 const char *file ATTRIBUTE_UNUSED;
1671 const char *const name ATTRIBUTE_UNUSED
1672 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1674 #ifdef PUT_SDB_EPILOGUE_END
1675 PUT_SDB_EPILOGUE_END (name);
1676 #else
1677 fprintf (asm_out_file, "\t.def\t");
1678 assemble_name (asm_out_file, name);
1679 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1680 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1681 #endif
1684 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1685 is present. */
1687 static void
1688 sdbout_label (insn)
1689 rtx insn;
1691 PUT_SDB_DEF (LABEL_NAME (insn));
1692 PUT_SDB_VAL (insn);
1693 PUT_SDB_SCL (C_LABEL);
1694 PUT_SDB_TYPE (T_NULL);
1695 PUT_SDB_ENDEF;
1698 /* Change to reading from a new source file. */
1700 static void
1701 sdbout_start_source_file (line, filename)
1702 unsigned int line ATTRIBUTE_UNUSED;
1703 const char *filename ATTRIBUTE_UNUSED;
1705 #ifdef MIPS_DEBUGGING_INFO
1706 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1708 n->next = current_file;
1709 n->name = filename;
1710 current_file = n;
1711 PUT_SDB_SRC_FILE (filename);
1712 #endif
1715 /* Revert to reading a previous source file. */
1717 static void
1718 sdbout_end_source_file (line)
1719 unsigned int line ATTRIBUTE_UNUSED;
1721 #ifdef MIPS_DEBUGGING_INFO
1722 struct sdb_file *next;
1724 next = current_file->next;
1725 free (current_file);
1726 current_file = next;
1727 PUT_SDB_SRC_FILE (current_file->name);
1728 #endif
1731 /* Set up for SDB output at the start of compilation. */
1733 static void
1734 sdbout_init (input_file_name)
1735 const char *input_file_name ATTRIBUTE_UNUSED;
1737 #ifdef MIPS_DEBUGGING_INFO
1738 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1739 current_file->next = NULL;
1740 current_file->name = input_file_name;
1741 #endif
1743 #ifdef RMS_QUICK_HACK_1
1744 tree t;
1745 for (t = (*lang_hooks.decls.getdecls) (); t; t = TREE_CHAIN (t))
1746 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
1747 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
1748 sdbout_symbol (t, 0);
1749 #endif
1752 #else /* SDB_DEBUGGING_INFO */
1754 /* This should never be used, but its address is needed for comparisons. */
1755 const struct gcc_debug_hooks sdb_debug_hooks;
1757 #endif /* SDB_DEBUGGING_INFO */
1759 #include "gt-sdbout.h"