1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
20 /* mike@tredysvr.Tredydev.Unisys.COM says:
21 I modified the struct.c example and have a nm of a .o resulting from the
22 AT&T C compiler. From the example below I would conclude the following:
24 1. All .defs from structures are emitted as scanned. The example below
25 clearly shows the symbol table entries for BoxRec2 are after the first
28 2. All functions and their locals (including statics) are emitted as scanned.
30 3. All nested unnamed union and structure .defs must be emitted before
31 the structure in which they are nested. The AT&T assembler is a
32 one pass beast as far as symbolics are concerned.
34 4. All structure .defs are emitted before the typedefs that refer to them.
36 5. All top level static and external variable definitions are moved to the
37 end of file with all top level statics occurring first before externs.
39 6. All undefined references are at the end of the file.
44 #ifdef SDB_DEBUGGING_INFO
51 #include "insn-config.h"
54 /* Mips systems use the SDB functions to dump out symbols, but
55 do not supply usable syms.h include files. */
56 #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(WINNT) && !defined(__linux__)
58 /* Use T_INT if we don't have T_VOID. */
62 #else /* not USG, or MIPS */
64 #endif /* not USG, or MIPS */
66 /* #include <storclass.h> used to be this instead of syms.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)
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)
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;
100 void sdbout_symbol ();
103 static void sdbout_typedefs ();
104 static void sdbout_syms ();
105 static void sdbout_one_type ();
106 static void sdbout_queue_anonymous_type ();
107 static void sdbout_dequeue_anonymous_types ();
108 static int plain_type_1 ();
110 /* Define the default sizes for various types. */
112 #ifndef CHAR_TYPE_SIZE
113 #define CHAR_TYPE_SIZE BITS_PER_UNIT
116 #ifndef SHORT_TYPE_SIZE
117 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
120 #ifndef INT_TYPE_SIZE
121 #define INT_TYPE_SIZE BITS_PER_WORD
124 #ifndef LONG_TYPE_SIZE
125 #define LONG_TYPE_SIZE BITS_PER_WORD
128 #ifndef LONG_LONG_TYPE_SIZE
129 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
132 #ifndef FLOAT_TYPE_SIZE
133 #define FLOAT_TYPE_SIZE BITS_PER_WORD
136 #ifndef DOUBLE_TYPE_SIZE
137 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
140 #ifndef LONG_DOUBLE_TYPE_SIZE
141 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
144 /* Random macros describing parts of SDB data. */
146 /* Put something here if lines get too long */
149 /* Default value of delimiter is ";". */
151 #define SDB_DELIM ";"
154 /* Maximum number of dimensions the assembler will allow. */
156 #define SDB_MAX_DIM 4
160 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
163 #ifndef PUT_SDB_INT_VAL
164 #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
168 #define PUT_SDB_VAL(a) \
169 ( fputs ("\t.val\t", asm_out_file), \
170 output_addr_const (asm_out_file, (a)), \
171 fprintf (asm_out_file, SDB_DELIM))
175 #define PUT_SDB_DEF(a) \
176 do { fprintf (asm_out_file, "\t.def\t"); \
177 ASM_OUTPUT_LABELREF (asm_out_file, a); \
178 fprintf (asm_out_file, SDB_DELIM); } while (0)
181 #ifndef PUT_SDB_PLAIN_DEF
182 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
185 #ifndef PUT_SDB_ENDEF
186 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
190 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
194 #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
197 #ifndef PUT_SDB_START_DIM
198 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
201 #ifndef PUT_SDB_NEXT_DIM
202 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
205 #ifndef PUT_SDB_LAST_DIM
206 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
210 #define PUT_SDB_TAG(a) \
211 do { fprintf (asm_out_file, "\t.tag\t"); \
212 ASM_OUTPUT_LABELREF (asm_out_file, a); \
213 fprintf (asm_out_file, SDB_DELIM); } while (0)
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)
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)
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)
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)
244 #ifndef PUT_SDB_EPILOGUE_END
245 #define PUT_SDB_EPILOGUE_END(NAME) \
246 do { fprintf (asm_out_file, "\t.def\t"); \
247 ASM_OUTPUT_LABELREF (asm_out_file, NAME); \
248 fprintf (asm_out_file, \
249 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
250 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
253 #ifndef SDB_GENERATE_FAKE
254 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
255 sprintf ((BUFFER), ".%dfake", (NUMBER));
258 /* Return the sdb tag identifier string for TYPE
259 if TYPE has already been defined; otherwise return a null pointer. */
261 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
263 /* Set the sdb tag identifier string for TYPE to NAME. */
265 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
266 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
268 /* Return the name (a string) of the struct, union or enum tag
269 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
271 #define TAG_NAME(link) \
272 (((link) && TREE_PURPOSE ((link)) \
273 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
274 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
276 /* Ensure we don't output a negative line number. */
277 #define MAKE_LINE_SAFE(line) \
278 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
280 /* Set up for SDB output at the start of compilation. */
283 sdbout_init (asm_file, input_file_name, syms)
285 char *input_file_name;
288 #ifdef RMS_QUICK_HACK_1
290 for (t = syms; t; t = TREE_CHAIN (t))
291 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
292 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
293 sdbout_symbol (t, 0);
296 #if 0 /* Nothing need be output for the predefined types. */
297 /* Get all permanent types that have typedef names,
298 and output them all, except for those already output. */
300 sdbout_typedefs (syms);
306 /* return the tag identifier for type
310 tag_of_ru_type (type,link)
313 if (TYPE_SYMTAB_ADDRESS (type))
314 return TYPE_SYMTAB_ADDRESS (type);
315 if (link && TREE_PURPOSE (link)
316 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
317 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
319 return (char *) TYPE_SYMTAB_ADDRESS (type);
323 /* Return a unique string to name an anonymous type. */
330 SDB_GENERATE_FAKE (label, unnamed_struct_number);
331 unnamed_struct_number++;
332 labelstr = (char *) permalloc (strlen (label) + 1);
333 strcpy (labelstr, label);
337 /* Return the number which describes TYPE for SDB.
338 For pointers, etc., this function is recursive.
339 Each record, union or enumeral type must already have had a
340 tag number output. */
342 /* The number is given by d6d5d4d3d2d1bbbb
343 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
344 Thus, char *foo () has bbbb=T_CHAR
347 N_BTMASK= 017 1111 basic type field.
348 N_TSHIFT= 2 derived type shift
349 N_BTSHFT= 4 Basic type shift */
351 /* Produce the number that describes a pointer, function or array type.
352 PREV is the number describing the target, value or element type.
353 DT_type describes how to transform that type. */
354 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
355 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
356 | ((int)DT_type << (int)N_BTSHFT) \
357 | ((PREV) & (int)N_BTMASK))
359 /* Number of elements used in sdb_dims. */
360 static int sdb_n_dims = 0;
362 /* Table of array dimensions of current type. */
363 static int sdb_dims[SDB_MAX_DIM];
365 /* Size of outermost array currently being processed. */
366 static int sdb_type_size = -1;
372 int val = plain_type_1 (type);
374 /* If we have already saved up some array dimensions, print them now. */
379 for (i = sdb_n_dims - 1; i > 0; i--)
380 PUT_SDB_NEXT_DIM (sdb_dims[i]);
381 PUT_SDB_LAST_DIM (sdb_dims[0]);
384 sdb_type_size = int_size_in_bytes (type);
385 /* Don't kill sdb if type is not laid out or has variable size. */
386 if (sdb_type_size < 0)
389 /* If we have computed the size of an array containing this type,
391 if (sdb_type_size >= 0)
393 PUT_SDB_SIZE (sdb_type_size);
400 template_name_p (name)
403 register char *ptr = IDENTIFIER_POINTER (name);
404 while (*ptr && *ptr != '<')
411 sdbout_record_type_name (type)
417 if (KNOWN_TYPE_TAG (type))
420 if (TYPE_NAME (type) != 0)
423 /* Find the IDENTIFIER_NODE for the type name. */
424 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
425 t = TYPE_NAME (type);
426 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
428 t = DECL_NAME (TYPE_NAME (type));
429 /* The DECL_NAME for templates includes "<>", which breaks
430 most assemblers. Use its assembler name instead, which
431 has been mangled into being safe. */
432 if (t && template_name_p (t))
433 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
436 /* Now get the name as a string, or invent one. */
438 name = IDENTIFIER_POINTER (t);
441 no_name = (name == 0 || *name == 0);
443 name = gen_fake_label ();
445 SET_KNOWN_TYPE_TAG (type, name);
446 #ifdef SDB_ALLOW_FORWARD_REFERENCES
448 sdbout_queue_anonymous_type (type);
457 type = void_type_node;
458 if (type == error_mark_node)
459 type = integer_type_node;
460 type = TYPE_MAIN_VARIANT (type);
462 switch (TREE_CODE (type))
468 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
470 /* Carefully distinguish all the standard types of C,
471 without messing up if the language is not C.
472 Note that we check only for the names that contain spaces;
473 other names might occur by coincidence in other languages. */
474 if (TYPE_NAME (type) != 0
475 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
476 && DECL_NAME (TYPE_NAME (type)) != 0
477 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
479 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
481 if (!strcmp (name, "unsigned char"))
483 if (!strcmp (name, "signed char"))
485 if (!strcmp (name, "unsigned int"))
487 if (!strcmp (name, "short int"))
489 if (!strcmp (name, "short unsigned int"))
491 if (!strcmp (name, "long int"))
493 if (!strcmp (name, "long unsigned int"))
497 if (size == CHAR_TYPE_SIZE)
498 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
499 if (size == SHORT_TYPE_SIZE)
500 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
501 if (size == INT_TYPE_SIZE)
502 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
503 if (size == LONG_TYPE_SIZE)
504 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
505 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
506 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
512 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
513 if (size == FLOAT_TYPE_SIZE)
515 if (size == DOUBLE_TYPE_SIZE)
523 m = plain_type_1 (TREE_TYPE (type));
524 if (sdb_n_dims < SDB_MAX_DIM)
525 sdb_dims[sdb_n_dims++]
526 = (TYPE_DOMAIN (type)
527 ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
529 return PUSH_DERIVED_LEVEL (DT_ARY, m);
534 case QUAL_UNION_TYPE:
538 #ifdef SDB_ALLOW_FORWARD_REFERENCES
539 sdbout_record_type_name (type);
541 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
542 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
543 #ifdef SDB_ALLOW_FORWARD_REFERENCES
544 || TYPE_MODE (type) != VOIDmode
549 /* Output the referenced structure tag name
550 only if the .def has already been finished.
551 At least on 386, the Unix assembler
552 cannot handle forward references to tags. */
553 /* But the 88100, it requires them, sigh... */
554 /* And the MIPS requires unknown refs as well... */
555 tag = KNOWN_TYPE_TAG (type);
557 /* These 3 lines used to follow the close brace.
558 However, a size of 0 without a tag implies a tag of 0,
559 so if we don't know a tag, we can't mention the size. */
560 sdb_type_size = int_size_in_bytes (type);
561 if (sdb_type_size < 0)
564 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
565 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
566 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
572 int m = plain_type_1 (TREE_TYPE (type));
573 return PUSH_DERIVED_LEVEL (DT_PTR, m);
578 int m = plain_type_1 (TREE_TYPE (type));
579 return PUSH_DERIVED_LEVEL (DT_FCN, m);
586 /* Output the symbols defined in block number DO_BLOCK.
587 Set NEXT_BLOCK_NUMBER to 0 before calling.
589 This function works by walking the tree structure of blocks,
590 counting blocks until it finds the desired block. */
592 static int do_block = 0;
594 static int next_block_number;
602 /* Ignore blocks never expanded or otherwise marked as real. */
603 if (TREE_USED (block))
605 /* When we reach the specified block, output its symbols. */
606 if (next_block_number == do_block)
608 sdbout_syms (BLOCK_VARS (block));
611 /* If we are past the specified block, stop the scan. */
612 if (next_block_number > do_block)
617 /* Scan the blocks within this block. */
618 sdbout_block (BLOCK_SUBBLOCKS (block));
621 block = BLOCK_CHAIN (block);
625 /* Call sdbout_symbol on each decl in the chain SYMS. */
633 if (TREE_CODE (syms) != LABEL_DECL)
634 sdbout_symbol (syms, 1);
635 syms = TREE_CHAIN (syms);
639 /* Output SDB information for a symbol described by DECL.
640 LOCAL is nonzero if the symbol is not file-scope. */
643 sdbout_symbol (decl, local)
647 tree type = TREE_TYPE (decl);
648 tree context = NULL_TREE;
653 sdbout_one_type (type);
655 #if 0 /* This loses when functions are marked to be ignored,
656 which happens in the C++ front end. */
657 if (DECL_IGNORED_P (decl))
661 switch (TREE_CODE (decl))
664 /* Enum values are defined by defining the enum type. */
668 /* Don't mention a nested function under its parent. */
669 context = decl_function_context (decl);
670 if (context == current_function_decl)
672 if (DECL_EXTERNAL (decl))
674 if (GET_CODE (DECL_RTL (decl)) != MEM
675 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
677 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
678 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
679 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
683 /* Done with tagged types. */
684 if (DECL_NAME (decl) == 0)
686 if (DECL_IGNORED_P (decl))
689 /* Output typedef name. */
690 if (template_name_p (DECL_NAME (decl)))
691 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
693 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
694 PUT_SDB_SCL (C_TPDEF);
698 /* Parm decls go in their own separate chains
699 and are output by sdbout_reg_parms and sdbout_parms. */
703 /* Don't mention a variable that is external.
704 Let the file that defines it describe it. */
705 if (DECL_EXTERNAL (decl))
708 /* Ignore __FUNCTION__, etc. */
709 if (DECL_IGNORED_P (decl))
712 /* If there was an error in the declaration, don't dump core
713 if there is no RTL associated with the variable doesn't
715 if (DECL_RTL (decl) == 0)
718 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
719 #ifdef LEAF_REG_REMAP
721 leaf_renumber_regs_insn (DECL_RTL (decl));
723 value = DECL_RTL (decl);
725 /* Don't mention a variable at all
726 if it was completely optimized into nothingness.
728 If DECL was from an inline function, then its rtl
729 is not identically the rtl that was used in this
730 particular compilation. */
731 if (GET_CODE (value) == REG)
733 regno = REGNO (DECL_RTL (decl));
734 if (regno >= FIRST_PSEUDO_REGISTER)
737 else if (GET_CODE (value) == SUBREG)
740 while (GET_CODE (value) == SUBREG)
742 offset += SUBREG_WORD (value);
743 value = SUBREG_REG (value);
745 if (GET_CODE (value) == REG)
747 regno = REGNO (value);
748 if (regno >= FIRST_PSEUDO_REGISTER)
752 alter_subreg (DECL_RTL (decl));
753 value = DECL_RTL (decl);
755 /* Don't output anything if an auto variable
756 gets RTL that is static.
757 GAS version 2.2 can't handle such output. */
758 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
759 && ! TREE_STATIC (decl))
762 /* Emit any structure, union, or enum type that has not been output.
763 This occurs for tag-less structs (et al) used to declare variables
765 if (TREE_CODE (type) == ENUMERAL_TYPE
766 || TREE_CODE (type) == RECORD_TYPE
767 || TREE_CODE (type) == UNION_TYPE
768 || TREE_CODE (type) == QUAL_UNION_TYPE)
770 if (TYPE_SIZE (type) != 0 /* not a forward reference */
771 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
772 sdbout_one_type (type);
775 /* Defer SDB information for top-level initialized variables! */
777 && GET_CODE (value) == MEM
778 && DECL_INITIAL (decl))
781 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
782 For now, avoid crashing. */
783 if (DECL_NAME (decl) == NULL_TREE)
786 /* Record the name for, starting a symtab entry. */
787 if (DECL_LANG_SPECIFIC (decl))
788 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
790 name = IDENTIFIER_POINTER (DECL_NAME (decl));
792 if (GET_CODE (value) == MEM
793 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
796 if (TREE_PUBLIC (decl))
798 PUT_SDB_VAL (XEXP (value, 0));
803 PUT_SDB_VAL (XEXP (value, 0));
804 PUT_SDB_SCL (C_STAT);
810 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
813 else if (GET_CODE (value) == MEM
814 && (GET_CODE (XEXP (value, 0)) == MEM
815 || (GET_CODE (XEXP (value, 0)) == REG
816 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
817 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
818 /* If the value is indirect by memory or by a register
819 that isn't the frame pointer
820 then it means the object is variable-sized and address through
821 that register or stack slot. COFF has no way to represent this
822 so all we can do is output the variable as a pointer. */
825 if (GET_CODE (XEXP (value, 0)) == REG)
827 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
832 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
834 We want the value of that CONST_INT. */
835 /* Encore compiler hates a newline in a macro arg, it seems. */
836 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
837 (XEXP (XEXP (value, 0), 0)));
838 PUT_SDB_SCL (C_AUTO);
841 type = build_pointer_type (TREE_TYPE (decl));
843 else if (GET_CODE (value) == MEM
844 && ((GET_CODE (XEXP (value, 0)) == PLUS
845 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
846 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
847 /* This is for variables which are at offset zero from
848 the frame pointer. This happens on the Alpha.
849 Non-frame pointer registers are excluded above. */
850 || (GET_CODE (XEXP (value, 0)) == REG)))
852 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
853 or (MEM (REG...)). We want the value of that CONST_INT
856 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
857 PUT_SDB_SCL (C_AUTO);
859 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
861 /* Handle an obscure case which can arise when optimizing and
862 when there are few available registers. (This is *always*
863 the case for i386/i486 targets). The DECL_RTL looks like
864 (MEM (CONST ...)) even though this variable is a local `auto'
865 or a local `register' variable. In effect, what has happened
866 is that the reload pass has seen that all assignments and
867 references for one such a local variable can be replaced by
868 equivalent assignments and references to some static storage
869 variable, thereby avoiding the need for a register. In such
870 cases we're forced to lie to debuggers and tell them that
871 this variable was itself `static'. */
873 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
874 PUT_SDB_SCL (C_STAT);
878 /* It is something we don't know how to represent for SDB. */
883 PUT_SDB_TYPE (plain_type (type));
887 /* Output SDB information for a top-level initialized variable
888 that has been delayed. */
891 sdbout_toplevel_data (decl)
894 tree type = TREE_TYPE (decl);
896 if (DECL_IGNORED_P (decl))
899 if (! (TREE_CODE (decl) == VAR_DECL
900 && GET_CODE (DECL_RTL (decl)) == MEM
901 && DECL_INITIAL (decl)))
904 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
905 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
906 if (TREE_PUBLIC (decl))
912 PUT_SDB_SCL (C_STAT);
914 PUT_SDB_TYPE (plain_type (type));
918 #ifdef SDB_ALLOW_FORWARD_REFERENCES
920 /* Machinery to record and output anonymous types. */
922 static tree anonymous_types;
925 sdbout_queue_anonymous_type (type)
928 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
932 sdbout_dequeue_anonymous_types ()
934 register tree types, link;
936 while (anonymous_types)
938 types = nreverse (anonymous_types);
939 anonymous_types = NULL_TREE;
941 for (link = types; link; link = TREE_CHAIN (link))
943 register tree type = TREE_VALUE (link);
945 if (type && ! TREE_ASM_WRITTEN (type))
946 sdbout_one_type (type);
953 /* Given a chain of ..._TYPE nodes, all of which have names,
954 output definitions of those names, as typedefs. */
962 for (link = types; link; link = TREE_CHAIN (link))
963 sdbout_one_type (link);
965 #ifdef SDB_ALLOW_FORWARD_REFERENCES
966 sdbout_dequeue_anonymous_types ();
974 if (type == error_mark_node)
975 type = integer_type_node;
976 PUT_SDB_TYPE (plain_type (type));
979 /* Output types of the fields of type TYPE, if they are structs.
981 Formerly did not chase through pointer types, since that could be circular.
982 They must come before TYPE, since forward refs are not allowed.
983 Now james@bigtex.cactus.org says to try them. */
986 sdbout_field_types (type)
990 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
991 if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
992 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
994 sdbout_one_type (TREE_TYPE (tail));
997 /* Use this to put out the top level defined record and union types
998 for later reference. If this is a struct with a name, then put that
999 name out. Other unnamed structs will have .xxfake labels generated so
1000 that they may be referred to later.
1001 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1002 It may NOT be called recursively. */
1005 sdbout_one_type (type)
1010 switch (TREE_CODE (type))
1014 case QUAL_UNION_TYPE:
1016 type = TYPE_MAIN_VARIANT (type);
1017 /* Don't output a type twice. */
1018 if (TREE_ASM_WRITTEN (type))
1019 /* James said test TREE_ASM_BEING_WRITTEN here. */
1022 /* Output nothing if type is not yet defined. */
1023 if (TYPE_SIZE (type) == 0)
1026 TREE_ASM_WRITTEN (type) = 1;
1028 /* This is reputed to cause trouble with the following case,
1029 but perhaps checking TYPE_SIZE above will fix it. */
1031 /* Here is a test case:
1037 typedef struct intermediate {
1041 typedef struct badstr {
1046 TREE_ASM_BEING_WRITTEN (type) = 1;
1048 /* This change, which ought to make better output,
1049 used to make the COFF assembler unhappy.
1050 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1051 /* Before really doing anything, output types we want to refer to. */
1052 /* Note that in version 1 the following two lines
1053 are not used if forward references are in use. */
1054 if (TREE_CODE (type) != ENUMERAL_TYPE)
1055 sdbout_field_types (type);
1057 TREE_ASM_WRITTEN (type) = 1;
1061 /* Output a structure type. */
1063 int size = int_size_in_bytes (type);
1066 int i, n_baseclasses = 0;
1068 /* Record the type tag, but not in its permanent place just yet. */
1069 sdbout_record_type_name (type);
1071 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1073 switch (TREE_CODE (type))
1076 case QUAL_UNION_TYPE:
1077 PUT_SDB_SCL (C_UNTAG);
1078 PUT_SDB_TYPE (T_UNION);
1083 PUT_SDB_SCL (C_STRTAG);
1084 PUT_SDB_TYPE (T_STRUCT);
1089 PUT_SDB_SCL (C_ENTAG);
1090 PUT_SDB_TYPE (T_ENUM);
1095 PUT_SDB_SIZE (size);
1098 /* Print out the base class information with fields
1099 named after the types they hold. */
1100 if (TYPE_BINFO (type)
1101 && TYPE_BINFO_BASETYPES (type))
1102 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1103 for (i = 0; i < n_baseclasses; i++)
1105 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1106 tree child_type = BINFO_TYPE (child);
1107 tree child_type_name;
1108 if (TYPE_NAME (child_type) == 0)
1110 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1111 child_type_name = TYPE_NAME (child_type);
1112 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1114 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1115 if (child_type_name && template_name_p (child_type_name))
1117 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1123 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1124 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1125 PUT_SDB_SCL (member_scl);
1126 sdbout_type (BINFO_TYPE (child));
1130 /* output the individual fields */
1132 if (TREE_CODE (type) == ENUMERAL_TYPE)
1133 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1135 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1136 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1137 PUT_SDB_SCL (C_MOE);
1138 PUT_SDB_TYPE (T_MOE);
1142 else /* record or union type */
1143 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1144 /* Output the name, type, position (in bits), size (in bits)
1147 /* Omit here the nameless fields that are used to skip bits.
1148 Also omit fields with variable size or position.
1149 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1150 if (TREE_CODE (tem) == FIELD_DECL
1151 && DECL_NAME (tem) != 0
1152 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1153 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1158 if (DECL_LANG_SPECIFIC (tem))
1159 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1161 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1163 if (DECL_BIT_FIELD_TYPE (tem))
1165 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1166 PUT_SDB_SCL (C_FIELD);
1167 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1168 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1172 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1174 PUT_SDB_SCL (member_scl);
1175 sdbout_type (TREE_TYPE (tem));
1179 /* output end of a structure,union, or enumeral definition */
1181 PUT_SDB_PLAIN_DEF ("eos");
1182 PUT_SDB_INT_VAL (size);
1183 PUT_SDB_SCL (C_EOS);
1184 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1185 PUT_SDB_SIZE (size);
1192 /* The following two functions output definitions of function parameters.
1193 Each parameter gets a definition locating it in the parameter list.
1194 Each parameter that is a register variable gets a second definition
1195 locating it in the register.
1197 Printing or argument lists in gdb uses the definitions that
1198 locate in the parameter list. But reference to the variable in
1199 expressions uses preferentially the definition as a register. */
1201 /* Output definitions, referring to storage in the parmlist,
1202 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1205 sdbout_parms (parms)
1208 for (; parms; parms = TREE_CHAIN (parms))
1209 if (DECL_NAME (parms))
1211 int current_sym_value = 0;
1212 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1214 if (name == 0 || *name == 0)
1215 name = gen_fake_label ();
1217 /* Perform any necessary register eliminations on the parameter's rtl,
1218 so that the debugging output will be accurate. */
1219 DECL_INCOMING_RTL (parms) =
1220 eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1221 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1223 if (PARM_PASSED_IN_MEMORY (parms))
1225 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1228 /* ??? Here we assume that the parm address is indexed
1229 off the frame pointer or arg pointer.
1230 If that is not true, we produce meaningless results,
1231 but do not crash. */
1232 if (GET_CODE (addr) == PLUS
1233 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1234 current_sym_value = INTVAL (XEXP (addr, 1));
1236 current_sym_value = 0;
1238 if (GET_CODE (DECL_RTL (parms)) == REG
1239 && REGNO (DECL_RTL (parms)) >= 0
1240 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1241 type = DECL_ARG_TYPE (parms);
1244 int original_sym_value = current_sym_value;
1246 /* This is the case where the parm is passed as an int or
1247 double and it is converted to a char, short or float
1248 and stored back in the parmlist. In this case, describe
1249 the parm with the variable's declared type, and adjust
1250 the address if the least significant bytes (which we are
1251 using) are not the first ones. */
1252 if (BYTES_BIG_ENDIAN
1253 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1254 current_sym_value +=
1255 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1256 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1258 if (GET_CODE (DECL_RTL (parms)) == MEM
1259 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1260 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1262 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1263 == current_sym_value))
1264 type = TREE_TYPE (parms);
1267 current_sym_value = original_sym_value;
1268 type = DECL_ARG_TYPE (parms);
1273 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1274 PUT_SDB_SCL (C_ARG);
1275 PUT_SDB_TYPE (plain_type (type));
1278 else if (GET_CODE (DECL_RTL (parms)) == REG)
1281 /* Parm passed in registers and lives in registers or nowhere. */
1283 /* If parm lives in a register, use that register;
1284 pretend the parm was passed there. It would be more consistent
1285 to describe the register where the parm was passed,
1286 but in practice that register usually holds something else. */
1287 if (REGNO (DECL_RTL (parms)) >= 0
1288 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1289 best_rtl = DECL_RTL (parms);
1290 /* If the parm lives nowhere,
1291 use the register where it was passed. */
1293 best_rtl = DECL_INCOMING_RTL (parms);
1296 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1297 PUT_SDB_SCL (C_REGPARM);
1298 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1301 else if (GET_CODE (DECL_RTL (parms)) == MEM
1302 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1304 /* Parm was passed in registers but lives on the stack. */
1306 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1307 in which case we want the value of that CONST_INT,
1308 or (MEM (REG ...)) or (MEM (MEM ...)),
1309 in which case we use a value of zero. */
1310 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1311 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1312 current_sym_value = 0;
1314 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1316 /* Again, this assumes the offset is based on the arg pointer. */
1318 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1319 XEXP (DECL_RTL (parms), 0)));
1320 PUT_SDB_SCL (C_ARG);
1321 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1327 /* Output definitions for the places where parms live during the function,
1328 when different from where they were passed, when the parms were passed
1331 It is not useful to do this for parms passed in registers
1332 that live during the function in different registers, because it is
1333 impossible to look in the passed register for the passed value,
1334 so we use the within-the-function register to begin with.
1336 PARMS is a chain of PARM_DECL nodes. */
1339 sdbout_reg_parms (parms)
1342 for (; parms; parms = TREE_CHAIN (parms))
1343 if (DECL_NAME (parms))
1345 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1347 /* Report parms that live in registers during the function
1348 but were passed in memory. */
1349 if (GET_CODE (DECL_RTL (parms)) == REG
1350 && REGNO (DECL_RTL (parms)) >= 0
1351 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1352 && PARM_PASSED_IN_MEMORY (parms))
1354 if (name == 0 || *name == 0)
1355 name = gen_fake_label ();
1357 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1358 PUT_SDB_SCL (C_REG);
1359 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1362 /* Report parms that live in memory but not where they were passed. */
1363 else if (GET_CODE (DECL_RTL (parms)) == MEM
1364 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1365 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1366 && PARM_PASSED_IN_MEMORY (parms)
1367 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1369 #if 0 /* ??? It is not clear yet what should replace this. */
1370 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1371 /* A parm declared char is really passed as an int,
1372 so it occupies the least significant bytes.
1373 On a big-endian machine those are not the low-numbered ones. */
1374 if (BYTES_BIG_ENDIAN
1376 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1377 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1378 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1379 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1382 if (name == 0 || *name == 0)
1383 name = gen_fake_label ();
1385 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1386 (XEXP (DECL_RTL (parms), 0)));
1387 PUT_SDB_SCL (C_AUTO);
1388 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1395 /* Describe the beginning of an internal block within a function.
1396 Also output descriptions of variables defined in this block.
1398 N is the number of the block, by order of beginning, counting from 1,
1399 and not counting the outermost (function top-level) block.
1400 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1401 if the count starts at 0 for the outermost one. */
1404 sdbout_begin_block (file, line, n)
1409 tree decl = current_function_decl;
1410 MAKE_LINE_SAFE (line);
1412 /* The SCO compiler does not emit a separate block for the function level
1413 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1414 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1415 #ifndef MIPS_DEBUGGING_INFO
1418 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1422 /* Include the outermost BLOCK's variables in block 1. */
1423 next_block_number = 0;
1425 sdbout_block (DECL_INITIAL (decl));
1427 /* If -g1, suppress all the internal symbols of functions
1428 except for arguments. */
1429 if (debug_info_level != DINFO_LEVEL_TERSE)
1431 next_block_number = 0;
1433 sdbout_block (DECL_INITIAL (decl));
1436 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1437 sdbout_dequeue_anonymous_types ();
1441 /* Describe the end line-number of an internal block within a function. */
1444 sdbout_end_block (file, line, n)
1449 MAKE_LINE_SAFE (line);
1451 /* The SCO compiler does not emit a separate block for the function level
1452 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1453 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1454 #ifndef MIPS_DEBUGGING_INFO
1457 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1460 /* Output sdb info for the current function name.
1461 Called from assemble_start_function. */
1464 sdbout_mark_begin_function ()
1466 sdbout_symbol (current_function_decl, 0);
1469 /* Called at beginning of function body (after prologue).
1470 Record the function's starting line number, so we can output
1471 relative line numbers for the other lines.
1472 Describe beginning of outermost block.
1473 Also describe the parameter list. */
1476 sdbout_begin_function (line)
1479 sdb_begin_function_line = line - 1;
1480 PUT_SDB_FUNCTION_START (line);
1481 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1482 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1485 /* Called at end of function (before epilogue).
1486 Describe end of outermost block. */
1489 sdbout_end_function (line)
1492 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1493 sdbout_dequeue_anonymous_types ();
1496 MAKE_LINE_SAFE (line);
1497 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1499 /* Indicate we are between functions, for line-number output. */
1500 sdb_begin_function_line = -1;
1503 /* Output sdb info for the absolute end of a function.
1504 Called after the epilogue is output. */
1507 sdbout_end_epilogue ()
1509 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1510 PUT_SDB_EPILOGUE_END (name);
1513 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1520 PUT_SDB_DEF (LABEL_NAME (insn));
1522 PUT_SDB_SCL (C_LABEL);
1523 PUT_SDB_TYPE (T_NULL);
1527 #endif /* SDB_DEBUGGING_INFO */