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, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
21 /* mike@tredysvr.Tredydev.Unisys.COM says:
22 I modified the struct.c example and have a nm of a .o resulting from the
23 AT&T C compiler. From the example below I would conclude the following:
25 1. All .defs from structures are emitted as scanned. The example below
26 clearly shows the symbol table entries for BoxRec2 are after the first
29 2. All functions and their locals (including statics) are emitted as scanned.
31 3. All nested unnamed union and structure .defs must be emitted before
32 the structure in which they are nested. The AT&T assembler is a
33 one pass beast as far as symbolics are concerned.
35 4. All structure .defs are emitted before the typedefs that refer to them.
37 5. All top level static and external variable definitions are moved to the
38 end of file with all top level statics occurring first before externs.
40 6. All undefined references are at the end of the file.
45 #ifdef SDB_DEBUGGING_INFO
52 #include "insn-config.h"
55 /* Mips systems use the SDB functions to dump out symbols, but
56 do not supply usable syms.h include files. */
57 #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__)
59 /* Use T_INT if we don't have T_VOID. */
63 #else /* not USG, or MIPS */
65 #endif /* not USG, or MIPS */
67 /* #include <storclass.h> used to be this instead of syms.h. */
69 /* 1 if PARM is passed to this function in memory. */
71 #define PARM_PASSED_IN_MEMORY(PARM) \
72 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
74 /* A C expression for the integer offset value of an automatic variable
75 (C_AUTO) having address X (an RTX). */
76 #ifndef DEBUGGER_AUTO_OFFSET
77 #define DEBUGGER_AUTO_OFFSET(X) \
78 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
81 /* A C expression for the integer offset value of an argument (C_ARG)
82 having address X (an RTX). The nominal offset is OFFSET. */
83 #ifndef DEBUGGER_ARG_OFFSET
84 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
87 /* Line number of beginning of current function, minus one.
88 Negative means not in a function or not using sdb. */
90 int sdb_begin_function_line = -1;
92 /* Counter to generate unique "names" for nameless struct members. */
94 static int unnamed_struct_number = 0;
96 extern FILE *asm_out_file;
98 extern tree current_function_decl;
101 void sdbout_symbol ();
104 static void sdbout_typedefs ();
105 static void sdbout_syms ();
106 static void sdbout_one_type ();
107 static void sdbout_queue_anonymous_type ();
108 static void sdbout_dequeue_anonymous_types ();
109 static int plain_type_1 ();
111 /* Define the default sizes for various types. */
113 #ifndef CHAR_TYPE_SIZE
114 #define CHAR_TYPE_SIZE BITS_PER_UNIT
117 #ifndef SHORT_TYPE_SIZE
118 #define SHORT_TYPE_SIZE (BITS_PER_UNIT * MIN ((UNITS_PER_WORD + 1) / 2, 2))
121 #ifndef INT_TYPE_SIZE
122 #define INT_TYPE_SIZE BITS_PER_WORD
125 #ifndef LONG_TYPE_SIZE
126 #define LONG_TYPE_SIZE BITS_PER_WORD
129 #ifndef LONG_LONG_TYPE_SIZE
130 #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2)
133 #ifndef FLOAT_TYPE_SIZE
134 #define FLOAT_TYPE_SIZE BITS_PER_WORD
137 #ifndef DOUBLE_TYPE_SIZE
138 #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
141 #ifndef LONG_DOUBLE_TYPE_SIZE
142 #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2)
145 /* Random macros describing parts of SDB data. */
147 /* Put something here if lines get too long */
150 /* Default value of delimiter is ";". */
152 #define SDB_DELIM ";"
155 /* Maximum number of dimensions the assembler will allow. */
157 #define SDB_MAX_DIM 4
161 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
164 #ifndef PUT_SDB_INT_VAL
165 #define PUT_SDB_INT_VAL(a) fprintf (asm_out_file, "\t.val\t%d%s", (a), SDB_DELIM)
169 #define PUT_SDB_VAL(a) \
170 ( fputs ("\t.val\t", asm_out_file), \
171 output_addr_const (asm_out_file, (a)), \
172 fprintf (asm_out_file, SDB_DELIM))
176 #define PUT_SDB_DEF(a) \
177 do { fprintf (asm_out_file, "\t.def\t"); \
178 ASM_OUTPUT_LABELREF (asm_out_file, a); \
179 fprintf (asm_out_file, SDB_DELIM); } while (0)
182 #ifndef PUT_SDB_PLAIN_DEF
183 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
186 #ifndef PUT_SDB_ENDEF
187 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
191 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
195 #define PUT_SDB_SIZE(a) fprintf(asm_out_file, "\t.size\t%d%s", a, SDB_DELIM)
198 #ifndef PUT_SDB_START_DIM
199 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
202 #ifndef PUT_SDB_NEXT_DIM
203 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
206 #ifndef PUT_SDB_LAST_DIM
207 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
211 #define PUT_SDB_TAG(a) \
212 do { fprintf (asm_out_file, "\t.tag\t"); \
213 ASM_OUTPUT_LABELREF (asm_out_file, a); \
214 fprintf (asm_out_file, SDB_DELIM); } while (0)
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)
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)
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)
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)
245 #ifndef PUT_SDB_EPILOGUE_END
246 #define PUT_SDB_EPILOGUE_END(NAME) \
247 do { fprintf (asm_out_file, "\t.def\t"); \
248 ASM_OUTPUT_LABELREF (asm_out_file, NAME); \
249 fprintf (asm_out_file, \
250 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
251 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
254 #ifndef SDB_GENERATE_FAKE
255 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
256 sprintf ((BUFFER), ".%dfake", (NUMBER));
259 /* Return the sdb tag identifier string for TYPE
260 if TYPE has already been defined; otherwise return a null pointer. */
262 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
264 /* Set the sdb tag identifier string for TYPE to NAME. */
266 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
267 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
269 /* Return the name (a string) of the struct, union or enum tag
270 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
272 #define TAG_NAME(link) \
273 (((link) && TREE_PURPOSE ((link)) \
274 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
275 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
277 /* Ensure we don't output a negative line number. */
278 #define MAKE_LINE_SAFE(line) \
279 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
281 /* Set up for SDB output at the start of compilation. */
284 sdbout_init (asm_file, input_file_name, syms)
286 char *input_file_name;
289 #ifdef RMS_QUICK_HACK_1
291 for (t = syms; t; t = TREE_CHAIN (t))
292 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
293 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
294 sdbout_symbol (t, 0);
297 #if 0 /* Nothing need be output for the predefined types. */
298 /* Get all permanent types that have typedef names,
299 and output them all, except for those already output. */
301 sdbout_typedefs (syms);
307 /* return the tag identifier for type
311 tag_of_ru_type (type,link)
314 if (TYPE_SYMTAB_ADDRESS (type))
315 return TYPE_SYMTAB_ADDRESS (type);
316 if (link && TREE_PURPOSE (link)
317 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
318 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
320 return (char *) TYPE_SYMTAB_ADDRESS (type);
324 /* Return a unique string to name an anonymous type. */
331 SDB_GENERATE_FAKE (label, unnamed_struct_number);
332 unnamed_struct_number++;
333 labelstr = (char *) permalloc (strlen (label) + 1);
334 strcpy (labelstr, label);
338 /* Return the number which describes TYPE for SDB.
339 For pointers, etc., this function is recursive.
340 Each record, union or enumeral type must already have had a
341 tag number output. */
343 /* The number is given by d6d5d4d3d2d1bbbb
344 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
345 Thus, char *foo () has bbbb=T_CHAR
348 N_BTMASK= 017 1111 basic type field.
349 N_TSHIFT= 2 derived type shift
350 N_BTSHFT= 4 Basic type shift */
352 /* Produce the number that describes a pointer, function or array type.
353 PREV is the number describing the target, value or element type.
354 DT_type describes how to transform that type. */
355 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
356 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
357 | ((int)DT_type << (int)N_BTSHFT) \
358 | ((PREV) & (int)N_BTMASK))
360 /* Number of elements used in sdb_dims. */
361 static int sdb_n_dims = 0;
363 /* Table of array dimensions of current type. */
364 static int sdb_dims[SDB_MAX_DIM];
366 /* Size of outermost array currently being processed. */
367 static int sdb_type_size = -1;
373 int val = plain_type_1 (type, 0);
375 /* If we have already saved up some array dimensions, print them now. */
380 for (i = sdb_n_dims - 1; i > 0; i--)
381 PUT_SDB_NEXT_DIM (sdb_dims[i]);
382 PUT_SDB_LAST_DIM (sdb_dims[0]);
385 sdb_type_size = int_size_in_bytes (type);
386 /* Don't kill sdb if type is not laid out or has variable size. */
387 if (sdb_type_size < 0)
390 /* If we have computed the size of an array containing this type,
392 if (sdb_type_size >= 0)
394 PUT_SDB_SIZE (sdb_type_size);
401 template_name_p (name)
404 register char *ptr = IDENTIFIER_POINTER (name);
405 while (*ptr && *ptr != '<')
412 sdbout_record_type_name (type)
418 if (KNOWN_TYPE_TAG (type))
421 if (TYPE_NAME (type) != 0)
424 /* Find the IDENTIFIER_NODE for the type name. */
425 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
426 t = TYPE_NAME (type);
427 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
429 t = DECL_NAME (TYPE_NAME (type));
430 /* The DECL_NAME for templates includes "<>", which breaks
431 most assemblers. Use its assembler name instead, which
432 has been mangled into being safe. */
433 if (t && template_name_p (t))
434 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
437 /* Now get the name as a string, or invent one. */
439 name = IDENTIFIER_POINTER (t);
442 no_name = (name == 0 || *name == 0);
444 name = gen_fake_label ();
446 SET_KNOWN_TYPE_TAG (type, name);
447 #ifdef SDB_ALLOW_FORWARD_REFERENCES
449 sdbout_queue_anonymous_type (type);
453 /* Return the .type value for type TYPE.
455 LEVEL indicates how many levels deep we have recursed into the type.
456 The SDB debug format can only represent 6 derived levels of types.
457 After that, we must output inaccurate debug info. We deliberately
458 stop before the 7th level, so that ADA recursive types will not give an
462 plain_type_1 (type, level)
467 type = void_type_node;
468 else if (type == error_mark_node)
469 type = integer_type_node;
471 type = TYPE_MAIN_VARIANT (type);
473 switch (TREE_CODE (type))
479 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
481 /* Carefully distinguish all the standard types of C,
482 without messing up if the language is not C.
483 Note that we check only for the names that contain spaces;
484 other names might occur by coincidence in other languages. */
485 if (TYPE_NAME (type) != 0
486 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
487 && DECL_NAME (TYPE_NAME (type)) != 0
488 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
490 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
492 if (!strcmp (name, "unsigned char"))
494 if (!strcmp (name, "signed char"))
496 if (!strcmp (name, "unsigned int"))
498 if (!strcmp (name, "short int"))
500 if (!strcmp (name, "short unsigned int"))
502 if (!strcmp (name, "long int"))
504 if (!strcmp (name, "long unsigned int"))
508 if (size == CHAR_TYPE_SIZE)
509 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
510 if (size == SHORT_TYPE_SIZE)
511 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
512 if (size == INT_TYPE_SIZE)
513 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
514 if (size == LONG_TYPE_SIZE)
515 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
516 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
517 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
523 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
524 if (size == FLOAT_TYPE_SIZE)
526 if (size == DOUBLE_TYPE_SIZE)
537 m = plain_type_1 (TREE_TYPE (type), level+1);
538 if (sdb_n_dims < SDB_MAX_DIM)
539 sdb_dims[sdb_n_dims++]
540 = (TYPE_DOMAIN (type)
541 ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
543 return PUSH_DERIVED_LEVEL (DT_ARY, m);
548 case QUAL_UNION_TYPE:
552 #ifdef SDB_ALLOW_FORWARD_REFERENCES
553 sdbout_record_type_name (type);
555 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
556 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
557 #ifdef SDB_ALLOW_FORWARD_REFERENCES
558 || TYPE_MODE (type) != VOIDmode
563 /* Output the referenced structure tag name
564 only if the .def has already been finished.
565 At least on 386, the Unix assembler
566 cannot handle forward references to tags. */
567 /* But the 88100, it requires them, sigh... */
568 /* And the MIPS requires unknown refs as well... */
569 tag = KNOWN_TYPE_TAG (type);
571 /* These 3 lines used to follow the close brace.
572 However, a size of 0 without a tag implies a tag of 0,
573 so if we don't know a tag, we can't mention the size. */
574 sdb_type_size = int_size_in_bytes (type);
575 if (sdb_type_size < 0)
578 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
579 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
580 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
590 m = plain_type_1 (TREE_TYPE (type), level+1);
591 return PUSH_DERIVED_LEVEL (DT_PTR, m);
600 m = plain_type_1 (TREE_TYPE (type), level+1);
601 return PUSH_DERIVED_LEVEL (DT_FCN, m);
608 /* Output the symbols defined in block number DO_BLOCK.
609 Set NEXT_BLOCK_NUMBER to 0 before calling.
611 This function works by walking the tree structure of blocks,
612 counting blocks until it finds the desired block. */
614 static int do_block = 0;
616 static int next_block_number;
624 /* Ignore blocks never expanded or otherwise marked as real. */
625 if (TREE_USED (block))
627 /* When we reach the specified block, output its symbols. */
628 if (next_block_number == do_block)
630 sdbout_syms (BLOCK_VARS (block));
633 /* If we are past the specified block, stop the scan. */
634 if (next_block_number > do_block)
639 /* Scan the blocks within this block. */
640 sdbout_block (BLOCK_SUBBLOCKS (block));
643 block = BLOCK_CHAIN (block);
647 /* Call sdbout_symbol on each decl in the chain SYMS. */
655 if (TREE_CODE (syms) != LABEL_DECL)
656 sdbout_symbol (syms, 1);
657 syms = TREE_CHAIN (syms);
661 /* Output SDB information for a symbol described by DECL.
662 LOCAL is nonzero if the symbol is not file-scope. */
665 sdbout_symbol (decl, local)
669 tree type = TREE_TYPE (decl);
670 tree context = NULL_TREE;
675 sdbout_one_type (type);
677 #if 0 /* This loses when functions are marked to be ignored,
678 which happens in the C++ front end. */
679 if (DECL_IGNORED_P (decl))
683 switch (TREE_CODE (decl))
686 /* Enum values are defined by defining the enum type. */
690 /* Don't mention a nested function under its parent. */
691 context = decl_function_context (decl);
692 if (context == current_function_decl)
694 if (DECL_EXTERNAL (decl))
696 if (GET_CODE (DECL_RTL (decl)) != MEM
697 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
699 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
700 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
701 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
705 /* Done with tagged types. */
706 if (DECL_NAME (decl) == 0)
708 if (DECL_IGNORED_P (decl))
711 /* Output typedef name. */
712 if (template_name_p (DECL_NAME (decl)))
713 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
715 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
716 PUT_SDB_SCL (C_TPDEF);
720 /* Parm decls go in their own separate chains
721 and are output by sdbout_reg_parms and sdbout_parms. */
725 /* Don't mention a variable that is external.
726 Let the file that defines it describe it. */
727 if (DECL_EXTERNAL (decl))
730 /* Ignore __FUNCTION__, etc. */
731 if (DECL_IGNORED_P (decl))
734 /* If there was an error in the declaration, don't dump core
735 if there is no RTL associated with the variable doesn't
737 if (DECL_RTL (decl) == 0)
740 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
741 #ifdef LEAF_REG_REMAP
743 leaf_renumber_regs_insn (DECL_RTL (decl));
745 value = DECL_RTL (decl);
747 /* Don't mention a variable at all
748 if it was completely optimized into nothingness.
750 If DECL was from an inline function, then its rtl
751 is not identically the rtl that was used in this
752 particular compilation. */
753 if (GET_CODE (value) == REG)
755 regno = REGNO (DECL_RTL (decl));
756 if (regno >= FIRST_PSEUDO_REGISTER)
759 else if (GET_CODE (value) == SUBREG)
762 while (GET_CODE (value) == SUBREG)
764 offset += SUBREG_WORD (value);
765 value = SUBREG_REG (value);
767 if (GET_CODE (value) == REG)
769 regno = REGNO (value);
770 if (regno >= FIRST_PSEUDO_REGISTER)
774 alter_subreg (DECL_RTL (decl));
775 value = DECL_RTL (decl);
777 /* Don't output anything if an auto variable
778 gets RTL that is static.
779 GAS version 2.2 can't handle such output. */
780 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
781 && ! TREE_STATIC (decl))
784 /* Emit any structure, union, or enum type that has not been output.
785 This occurs for tag-less structs (et al) used to declare variables
787 if (TREE_CODE (type) == ENUMERAL_TYPE
788 || TREE_CODE (type) == RECORD_TYPE
789 || TREE_CODE (type) == UNION_TYPE
790 || TREE_CODE (type) == QUAL_UNION_TYPE)
792 if (TYPE_SIZE (type) != 0 /* not a forward reference */
793 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
794 sdbout_one_type (type);
797 /* Defer SDB information for top-level initialized variables! */
799 && GET_CODE (value) == MEM
800 && DECL_INITIAL (decl))
803 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
804 For now, avoid crashing. */
805 if (DECL_NAME (decl) == NULL_TREE)
808 /* Record the name for, starting a symtab entry. */
809 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
811 if (GET_CODE (value) == MEM
812 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
815 if (TREE_PUBLIC (decl))
817 PUT_SDB_VAL (XEXP (value, 0));
822 PUT_SDB_VAL (XEXP (value, 0));
823 PUT_SDB_SCL (C_STAT);
829 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
832 else if (GET_CODE (value) == MEM
833 && (GET_CODE (XEXP (value, 0)) == MEM
834 || (GET_CODE (XEXP (value, 0)) == REG
835 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
836 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
837 /* If the value is indirect by memory or by a register
838 that isn't the frame pointer
839 then it means the object is variable-sized and address through
840 that register or stack slot. COFF has no way to represent this
841 so all we can do is output the variable as a pointer. */
844 if (GET_CODE (XEXP (value, 0)) == REG)
846 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
851 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
853 We want the value of that CONST_INT. */
854 /* Encore compiler hates a newline in a macro arg, it seems. */
855 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
856 (XEXP (XEXP (value, 0), 0)));
857 PUT_SDB_SCL (C_AUTO);
860 type = build_pointer_type (TREE_TYPE (decl));
862 else if (GET_CODE (value) == MEM
863 && ((GET_CODE (XEXP (value, 0)) == PLUS
864 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
865 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
866 /* This is for variables which are at offset zero from
867 the frame pointer. This happens on the Alpha.
868 Non-frame pointer registers are excluded above. */
869 || (GET_CODE (XEXP (value, 0)) == REG)))
871 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
872 or (MEM (REG...)). We want the value of that CONST_INT
875 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
876 PUT_SDB_SCL (C_AUTO);
878 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
880 /* Handle an obscure case which can arise when optimizing and
881 when there are few available registers. (This is *always*
882 the case for i386/i486 targets). The DECL_RTL looks like
883 (MEM (CONST ...)) even though this variable is a local `auto'
884 or a local `register' variable. In effect, what has happened
885 is that the reload pass has seen that all assignments and
886 references for one such a local variable can be replaced by
887 equivalent assignments and references to some static storage
888 variable, thereby avoiding the need for a register. In such
889 cases we're forced to lie to debuggers and tell them that
890 this variable was itself `static'. */
892 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
893 PUT_SDB_SCL (C_STAT);
897 /* It is something we don't know how to represent for SDB. */
902 PUT_SDB_TYPE (plain_type (type));
906 /* Output SDB information for a top-level initialized variable
907 that has been delayed. */
910 sdbout_toplevel_data (decl)
913 tree type = TREE_TYPE (decl);
915 if (DECL_IGNORED_P (decl))
918 if (! (TREE_CODE (decl) == VAR_DECL
919 && GET_CODE (DECL_RTL (decl)) == MEM
920 && DECL_INITIAL (decl)))
923 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
924 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
925 if (TREE_PUBLIC (decl))
931 PUT_SDB_SCL (C_STAT);
933 PUT_SDB_TYPE (plain_type (type));
937 #ifdef SDB_ALLOW_FORWARD_REFERENCES
939 /* Machinery to record and output anonymous types. */
941 static tree anonymous_types;
944 sdbout_queue_anonymous_type (type)
947 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
951 sdbout_dequeue_anonymous_types ()
953 register tree types, link;
955 while (anonymous_types)
957 types = nreverse (anonymous_types);
958 anonymous_types = NULL_TREE;
960 for (link = types; link; link = TREE_CHAIN (link))
962 register tree type = TREE_VALUE (link);
964 if (type && ! TREE_ASM_WRITTEN (type))
965 sdbout_one_type (type);
972 /* Given a chain of ..._TYPE nodes, all of which have names,
973 output definitions of those names, as typedefs. */
981 for (link = types; link; link = TREE_CHAIN (link))
982 sdbout_one_type (link);
984 #ifdef SDB_ALLOW_FORWARD_REFERENCES
985 sdbout_dequeue_anonymous_types ();
993 if (type == error_mark_node)
994 type = integer_type_node;
995 PUT_SDB_TYPE (plain_type (type));
998 /* Output types of the fields of type TYPE, if they are structs.
1000 Formerly did not chase through pointer types, since that could be circular.
1001 They must come before TYPE, since forward refs are not allowed.
1002 Now james@bigtex.cactus.org says to try them. */
1005 sdbout_field_types (type)
1009 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1010 if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
1011 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1013 sdbout_one_type (TREE_TYPE (tail));
1016 /* Use this to put out the top level defined record and union types
1017 for later reference. If this is a struct with a name, then put that
1018 name out. Other unnamed structs will have .xxfake labels generated so
1019 that they may be referred to later.
1020 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1021 It may NOT be called recursively. */
1024 sdbout_one_type (type)
1027 if (current_function_decl != NULL_TREE
1028 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1029 ; /* Don't change section amid function. */
1033 switch (TREE_CODE (type))
1037 case QUAL_UNION_TYPE:
1039 type = TYPE_MAIN_VARIANT (type);
1040 /* Don't output a type twice. */
1041 if (TREE_ASM_WRITTEN (type))
1042 /* James said test TREE_ASM_BEING_WRITTEN here. */
1045 /* Output nothing if type is not yet defined. */
1046 if (TYPE_SIZE (type) == 0)
1049 TREE_ASM_WRITTEN (type) = 1;
1051 /* This is reputed to cause trouble with the following case,
1052 but perhaps checking TYPE_SIZE above will fix it. */
1054 /* Here is a test case:
1060 typedef struct intermediate {
1064 typedef struct badstr {
1069 TREE_ASM_BEING_WRITTEN (type) = 1;
1071 /* This change, which ought to make better output,
1072 used to make the COFF assembler unhappy.
1073 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1074 /* Before really doing anything, output types we want to refer to. */
1075 /* Note that in version 1 the following two lines
1076 are not used if forward references are in use. */
1077 if (TREE_CODE (type) != ENUMERAL_TYPE)
1078 sdbout_field_types (type);
1080 TREE_ASM_WRITTEN (type) = 1;
1084 /* Output a structure type. */
1086 int size = int_size_in_bytes (type);
1089 int i, n_baseclasses = 0;
1091 /* Record the type tag, but not in its permanent place just yet. */
1092 sdbout_record_type_name (type);
1094 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1096 switch (TREE_CODE (type))
1099 case QUAL_UNION_TYPE:
1100 PUT_SDB_SCL (C_UNTAG);
1101 PUT_SDB_TYPE (T_UNION);
1106 PUT_SDB_SCL (C_STRTAG);
1107 PUT_SDB_TYPE (T_STRUCT);
1112 PUT_SDB_SCL (C_ENTAG);
1113 PUT_SDB_TYPE (T_ENUM);
1118 PUT_SDB_SIZE (size);
1121 /* Print out the base class information with fields
1122 named after the types they hold. */
1123 if (TYPE_BINFO (type)
1124 && TYPE_BINFO_BASETYPES (type))
1125 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1126 for (i = 0; i < n_baseclasses; i++)
1128 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1129 tree child_type = BINFO_TYPE (child);
1130 tree child_type_name;
1131 if (TYPE_NAME (child_type) == 0)
1133 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1134 child_type_name = TYPE_NAME (child_type);
1135 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1137 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1138 if (child_type_name && template_name_p (child_type_name))
1140 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1146 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1147 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1148 PUT_SDB_SCL (member_scl);
1149 sdbout_type (BINFO_TYPE (child));
1153 /* output the individual fields */
1155 if (TREE_CODE (type) == ENUMERAL_TYPE)
1156 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1158 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1159 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1160 PUT_SDB_SCL (C_MOE);
1161 PUT_SDB_TYPE (T_MOE);
1165 else /* record or union type */
1166 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1167 /* Output the name, type, position (in bits), size (in bits)
1170 /* Omit here the nameless fields that are used to skip bits.
1171 Also omit fields with variable size or position.
1172 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1173 if (TREE_CODE (tem) == FIELD_DECL
1174 && DECL_NAME (tem) != 0
1175 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1176 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1181 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1183 if (DECL_BIT_FIELD_TYPE (tem))
1185 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1186 PUT_SDB_SCL (C_FIELD);
1187 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1188 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1192 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1194 PUT_SDB_SCL (member_scl);
1195 sdbout_type (TREE_TYPE (tem));
1199 /* output end of a structure,union, or enumeral definition */
1201 PUT_SDB_PLAIN_DEF ("eos");
1202 PUT_SDB_INT_VAL (size);
1203 PUT_SDB_SCL (C_EOS);
1204 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1205 PUT_SDB_SIZE (size);
1212 /* The following two functions output definitions of function parameters.
1213 Each parameter gets a definition locating it in the parameter list.
1214 Each parameter that is a register variable gets a second definition
1215 locating it in the register.
1217 Printing or argument lists in gdb uses the definitions that
1218 locate in the parameter list. But reference to the variable in
1219 expressions uses preferentially the definition as a register. */
1221 /* Output definitions, referring to storage in the parmlist,
1222 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1225 sdbout_parms (parms)
1228 for (; parms; parms = TREE_CHAIN (parms))
1229 if (DECL_NAME (parms))
1231 int current_sym_value = 0;
1232 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1234 if (name == 0 || *name == 0)
1235 name = gen_fake_label ();
1237 /* Perform any necessary register eliminations on the parameter's rtl,
1238 so that the debugging output will be accurate. */
1239 DECL_INCOMING_RTL (parms) =
1240 eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1241 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1243 if (PARM_PASSED_IN_MEMORY (parms))
1245 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1248 /* ??? Here we assume that the parm address is indexed
1249 off the frame pointer or arg pointer.
1250 If that is not true, we produce meaningless results,
1251 but do not crash. */
1252 if (GET_CODE (addr) == PLUS
1253 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1254 current_sym_value = INTVAL (XEXP (addr, 1));
1256 current_sym_value = 0;
1258 if (GET_CODE (DECL_RTL (parms)) == REG
1259 && REGNO (DECL_RTL (parms)) >= 0
1260 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1261 type = DECL_ARG_TYPE (parms);
1264 int original_sym_value = current_sym_value;
1266 /* This is the case where the parm is passed as an int or
1267 double and it is converted to a char, short or float
1268 and stored back in the parmlist. In this case, describe
1269 the parm with the variable's declared type, and adjust
1270 the address if the least significant bytes (which we are
1271 using) are not the first ones. */
1272 if (BYTES_BIG_ENDIAN
1273 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1274 current_sym_value +=
1275 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1276 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1278 if (GET_CODE (DECL_RTL (parms)) == MEM
1279 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1280 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1282 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1283 == current_sym_value))
1284 type = TREE_TYPE (parms);
1287 current_sym_value = original_sym_value;
1288 type = DECL_ARG_TYPE (parms);
1293 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1294 PUT_SDB_SCL (C_ARG);
1295 PUT_SDB_TYPE (plain_type (type));
1298 else if (GET_CODE (DECL_RTL (parms)) == REG)
1301 /* Parm passed in registers and lives in registers or nowhere. */
1303 /* If parm lives in a register, use that register;
1304 pretend the parm was passed there. It would be more consistent
1305 to describe the register where the parm was passed,
1306 but in practice that register usually holds something else. */
1307 if (REGNO (DECL_RTL (parms)) >= 0
1308 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1309 best_rtl = DECL_RTL (parms);
1310 /* If the parm lives nowhere,
1311 use the register where it was passed. */
1313 best_rtl = DECL_INCOMING_RTL (parms);
1316 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1317 PUT_SDB_SCL (C_REGPARM);
1318 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1321 else if (GET_CODE (DECL_RTL (parms)) == MEM
1322 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1324 /* Parm was passed in registers but lives on the stack. */
1326 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1327 in which case we want the value of that CONST_INT,
1328 or (MEM (REG ...)) or (MEM (MEM ...)),
1329 in which case we use a value of zero. */
1330 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1331 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1332 current_sym_value = 0;
1334 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1336 /* Again, this assumes the offset is based on the arg pointer. */
1338 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1339 XEXP (DECL_RTL (parms), 0)));
1340 PUT_SDB_SCL (C_ARG);
1341 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1347 /* Output definitions for the places where parms live during the function,
1348 when different from where they were passed, when the parms were passed
1351 It is not useful to do this for parms passed in registers
1352 that live during the function in different registers, because it is
1353 impossible to look in the passed register for the passed value,
1354 so we use the within-the-function register to begin with.
1356 PARMS is a chain of PARM_DECL nodes. */
1359 sdbout_reg_parms (parms)
1362 for (; parms; parms = TREE_CHAIN (parms))
1363 if (DECL_NAME (parms))
1365 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1367 /* Report parms that live in registers during the function
1368 but were passed in memory. */
1369 if (GET_CODE (DECL_RTL (parms)) == REG
1370 && REGNO (DECL_RTL (parms)) >= 0
1371 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1372 && PARM_PASSED_IN_MEMORY (parms))
1374 if (name == 0 || *name == 0)
1375 name = gen_fake_label ();
1377 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1378 PUT_SDB_SCL (C_REG);
1379 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1382 /* Report parms that live in memory but not where they were passed. */
1383 else if (GET_CODE (DECL_RTL (parms)) == MEM
1384 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1385 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1386 && PARM_PASSED_IN_MEMORY (parms)
1387 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1389 #if 0 /* ??? It is not clear yet what should replace this. */
1390 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1391 /* A parm declared char is really passed as an int,
1392 so it occupies the least significant bytes.
1393 On a big-endian machine those are not the low-numbered ones. */
1394 if (BYTES_BIG_ENDIAN
1396 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1397 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1398 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1399 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1402 if (name == 0 || *name == 0)
1403 name = gen_fake_label ();
1405 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1406 (XEXP (DECL_RTL (parms), 0)));
1407 PUT_SDB_SCL (C_AUTO);
1408 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1415 /* Describe the beginning of an internal block within a function.
1416 Also output descriptions of variables defined in this block.
1418 N is the number of the block, by order of beginning, counting from 1,
1419 and not counting the outermost (function top-level) block.
1420 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1421 if the count starts at 0 for the outermost one. */
1424 sdbout_begin_block (file, line, n)
1429 tree decl = current_function_decl;
1430 MAKE_LINE_SAFE (line);
1432 /* The SCO compiler does not emit a separate block for the function level
1433 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1434 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1435 #ifndef MIPS_DEBUGGING_INFO
1438 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1442 /* Include the outermost BLOCK's variables in block 1. */
1443 next_block_number = 0;
1445 sdbout_block (DECL_INITIAL (decl));
1447 /* If -g1, suppress all the internal symbols of functions
1448 except for arguments. */
1449 if (debug_info_level != DINFO_LEVEL_TERSE)
1451 next_block_number = 0;
1453 sdbout_block (DECL_INITIAL (decl));
1456 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1457 sdbout_dequeue_anonymous_types ();
1461 /* Describe the end line-number of an internal block within a function. */
1464 sdbout_end_block (file, line, n)
1469 MAKE_LINE_SAFE (line);
1471 /* The SCO compiler does not emit a separate block for the function level
1472 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1473 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1474 #ifndef MIPS_DEBUGGING_INFO
1477 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1480 /* Output sdb info for the current function name.
1481 Called from assemble_start_function. */
1484 sdbout_mark_begin_function ()
1486 sdbout_symbol (current_function_decl, 0);
1489 /* Called at beginning of function body (after prologue).
1490 Record the function's starting line number, so we can output
1491 relative line numbers for the other lines.
1492 Describe beginning of outermost block.
1493 Also describe the parameter list. */
1496 sdbout_begin_function (line)
1499 sdb_begin_function_line = line - 1;
1500 PUT_SDB_FUNCTION_START (line);
1501 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1502 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1505 /* Called at end of function (before epilogue).
1506 Describe end of outermost block. */
1509 sdbout_end_function (line)
1512 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1513 sdbout_dequeue_anonymous_types ();
1516 MAKE_LINE_SAFE (line);
1517 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1519 /* Indicate we are between functions, for line-number output. */
1520 sdb_begin_function_line = -1;
1523 /* Output sdb info for the absolute end of a function.
1524 Called after the epilogue is output. */
1527 sdbout_end_epilogue ()
1529 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1530 PUT_SDB_EPILOGUE_END (name);
1533 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1540 PUT_SDB_DEF (LABEL_NAME (insn));
1542 PUT_SDB_SCL (C_LABEL);
1543 PUT_SDB_TYPE (T_NULL);
1547 #endif /* SDB_DEBUGGING_INFO */