1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 1992 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)
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) (char *)(TYPE_SYMTAB_ADDRESS (type))
263 /* Set the sdb tag identifier string for TYPE to NAME. */
265 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
266 (TYPE_SYMTAB_ADDRESS (TYPE) = (int)(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 #if 0 /* Nothing need be output for the predefined types. */
289 /* Get all permanent types that have typedef names,
290 and output them all, except for those already output. */
292 sdbout_typedefs (syms);
298 /* return the tag identifier for type
302 tag_of_ru_type (type,link)
305 if (TYPE_SYMTAB_ADDRESS (type))
306 return (char *)TYPE_SYMTAB_ADDRESS (type);
307 if (link && TREE_PURPOSE (link)
308 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
309 TYPE_SYMTAB_ADDRESS (type)
310 = (int)IDENTIFIER_POINTER (TREE_PURPOSE (link));
312 return (char *) TYPE_SYMTAB_ADDRESS (type);
316 /* Return a unique string to name an anonymous type. */
323 SDB_GENERATE_FAKE (label, unnamed_struct_number);
324 unnamed_struct_number++;
325 labelstr = (char *) permalloc (strlen (label) + 1);
326 strcpy (labelstr, label);
330 /* Return the number which describes TYPE for SDB.
331 For pointers, etc., this function is recursive.
332 Each record, union or enumeral type must already have had a
333 tag number output. */
335 /* The number is given by d6d5d4d3d2d1bbbb
336 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
337 Thus, char *foo () has bbbb=T_CHAR
340 N_BTMASK= 017 1111 basic type field.
341 N_TSHIFT= 2 derived type shift
342 N_BTSHFT= 4 Basic type shift */
344 /* Produce the number that describes a pointer, function or array type.
345 PREV is the number describing the target, value or element type.
346 DT_type describes how to transform that type. */
347 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
348 ((((PREV)&~N_BTMASK)<<N_TSHIFT)|(DT_type<<N_BTSHFT)|(PREV&N_BTMASK))
350 /* Number of elements used in sdb_dims. */
351 static int sdb_n_dims = 0;
353 /* Table of array dimensions of current type. */
354 static int sdb_dims[SDB_MAX_DIM];
356 /* Size of outermost array currently being processed. */
357 static int sdb_type_size = -1;
363 int val = plain_type_1 (type);
365 /* If we have already saved up some array dimensions, print them now. */
370 for (i = sdb_n_dims - 1; i > 0; i--)
371 PUT_SDB_NEXT_DIM (sdb_dims[i]);
372 PUT_SDB_LAST_DIM (sdb_dims[0]);
375 sdb_type_size = int_size_in_bytes (type);
376 /* Don't kill sdb if type is not laid out or has variable size. */
377 if (sdb_type_size < 0)
380 /* If we have computed the size of an array containing this type,
382 if (sdb_type_size >= 0)
384 PUT_SDB_SIZE (sdb_type_size);
391 template_name_p (name)
394 register char *ptr = IDENTIFIER_POINTER (name);
395 while (*ptr && *ptr != '<')
402 sdbout_record_type_name (type)
408 if (KNOWN_TYPE_TAG (type))
411 if (TYPE_NAME (type) != 0)
414 /* Find the IDENTIFIER_NODE for the type name. */
415 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
417 t = TYPE_NAME (type);
419 #if 1 /* As a temporary hack, use typedef names for C++ only. */
420 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
421 && TYPE_LANG_SPECIFIC (type))
423 t = DECL_NAME (TYPE_NAME (type));
424 /* The DECL_NAME for templates includes "<>", which breaks
425 most assemblers. Use its assembler name instead, which
426 has been mangled into being safe. */
427 if (t && template_name_p (t))
428 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
432 /* Now get the name as a string, or invent one. */
434 name = IDENTIFIER_POINTER (t);
437 no_name = (name == 0 || *name == 0);
439 name = gen_fake_label ();
441 SET_KNOWN_TYPE_TAG (type, name);
442 #ifdef SDB_ALLOW_FORWARD_REFERENCES
444 sdbout_queue_anonymous_type (type);
453 type = void_type_node;
454 if (type == error_mark_node)
455 type = integer_type_node;
456 type = TYPE_MAIN_VARIANT (type);
458 switch (TREE_CODE (type))
464 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
466 /* Carefully distinguish all the standard types of C,
467 without messing up if the language is not C.
468 Note that we check only for the names that contain spaces;
469 other names might occur by coincidence in other languages. */
470 if (TYPE_NAME (type) != 0
471 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
472 && DECL_NAME (TYPE_NAME (type)) != 0
473 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
475 char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
477 if (!strcmp (name, "unsigned char"))
479 if (!strcmp (name, "signed char"))
481 if (!strcmp (name, "unsigned int"))
483 if (!strcmp (name, "short int"))
485 if (!strcmp (name, "short unsigned int"))
487 if (!strcmp (name, "long int"))
489 if (!strcmp (name, "long unsigned int"))
493 if (size == CHAR_TYPE_SIZE)
494 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
495 if (size == SHORT_TYPE_SIZE)
496 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
497 if (size == INT_TYPE_SIZE)
498 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
499 if (size == LONG_TYPE_SIZE)
500 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
506 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
507 if (size == FLOAT_TYPE_SIZE)
509 if (size == DOUBLE_TYPE_SIZE)
517 m = plain_type_1 (TREE_TYPE (type));
518 if (sdb_n_dims < SDB_MAX_DIM)
519 sdb_dims[sdb_n_dims++]
520 = (TYPE_DOMAIN (type)
521 ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
523 return PUSH_DERIVED_LEVEL (DT_ARY, m);
531 #ifdef SDB_ALLOW_FORWARD_REFERENCES
532 sdbout_record_type_name (type);
534 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
535 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
536 #ifdef SDB_ALLOW_FORWARD_REFERENCES
537 || TYPE_MODE (type) != VOIDmode
542 /* Output the referenced structure tag name
543 only if the .def has already been finished.
544 At least on 386, the Unix assembler
545 cannot handle forward references to tags. */
546 /* But the 88100, it requires them, sigh... */
547 /* And the MIPS requires unknown refs as well... */
548 tag = KNOWN_TYPE_TAG (type);
550 /* These 3 lines used to follow the close brace.
551 However, a size of 0 without a tag implies a tag of 0,
552 so if we don't know a tag, we can't mention the size. */
553 sdb_type_size = int_size_in_bytes (type);
554 if (sdb_type_size < 0)
557 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
558 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
564 int m = plain_type_1 (TREE_TYPE (type));
565 return PUSH_DERIVED_LEVEL (DT_PTR, m);
570 int m = plain_type_1 (TREE_TYPE (type));
571 return PUSH_DERIVED_LEVEL (DT_FCN, m);
578 /* Output the symbols defined in block number DO_BLOCK.
579 Set NEXT_BLOCK_NUMBER to 0 before calling.
581 This function works by walking the tree structure of blocks,
582 counting blocks until it finds the desired block. */
584 static int do_block = 0;
586 static int next_block_number;
594 /* Ignore blocks never expanded or otherwise marked as real. */
595 if (TREE_USED (block))
597 /* When we reach the specified block, output its symbols. */
598 if (next_block_number == do_block)
600 sdbout_syms (BLOCK_VARS (block));
603 /* If we are past the specified block, stop the scan. */
604 if (next_block_number > do_block)
609 /* Scan the blocks within this block. */
610 sdbout_block (BLOCK_SUBBLOCKS (block));
613 block = BLOCK_CHAIN (block);
617 /* Call sdbout_symbol on each decl in the chain SYMS. */
625 if (TREE_CODE (syms) != LABEL_DECL)
626 sdbout_symbol (syms, 1);
627 syms = TREE_CHAIN (syms);
631 /* Output SDB information for a symbol described by DECL.
632 LOCAL is nonzero if the symbol is not file-scope. */
635 sdbout_symbol (decl, local)
640 tree type = TREE_TYPE (decl);
641 tree context = NULL_TREE;
646 sdbout_one_type (type);
648 #if 0 /* This loses when functions are marked to be ignored,
649 which happens in the C++ front end. */
650 if (DECL_IGNORED_P (decl))
654 switch (TREE_CODE (decl))
657 /* Enum values are defined by defining the enum type. */
661 /* Don't mention a nested function under its parent. */
662 context = decl_function_context (decl);
663 if (context == current_function_decl)
665 if (DECL_EXTERNAL (decl))
667 if (GET_CODE (DECL_RTL (decl)) != MEM
668 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
670 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
671 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
672 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
676 /* Done with tagged types. */
677 if (DECL_NAME (decl) == 0)
679 if (DECL_IGNORED_P (decl))
682 /* Output typedef name. */
683 if (template_name_p (DECL_NAME (decl)))
684 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
686 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
687 PUT_SDB_SCL (C_TPDEF);
691 /* Parm decls go in their own separate chains
692 and are output by sdbout_reg_parms and sdbout_parms. */
696 /* Don't mention a variable that is external.
697 Let the file that defines it describe it. */
698 if (DECL_EXTERNAL (decl))
701 /* Ignore __FUNCTION__, etc. */
702 if (DECL_IGNORED_P (decl))
705 /* If there was an error in the declaration, don't dump core
706 if there is no RTL associated with the variable doesn't
708 if (DECL_RTL (decl) == 0)
711 DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
712 #ifdef LEAF_REG_REMAP
714 leaf_renumber_regs_insn (DECL_RTL (decl));
716 value = DECL_RTL (decl);
718 /* Don't mention a variable at all
719 if it was completely optimized into nothingness.
721 If DECL was from an inline function, then its rtl
722 is not identically the rtl that was used in this
723 particular compilation. */
724 if (GET_CODE (value) == REG)
726 regno = REGNO (DECL_RTL (decl));
727 if (regno >= FIRST_PSEUDO_REGISTER)
730 else if (GET_CODE (value) == SUBREG)
733 while (GET_CODE (value) == SUBREG)
735 offset += SUBREG_WORD (value);
736 value = SUBREG_REG (value);
738 if (GET_CODE (value) == REG)
740 regno = REGNO (value);
741 if (regno >= FIRST_PSEUDO_REGISTER)
745 alter_subreg (DECL_RTL (decl));
746 value = DECL_RTL (decl);
749 /* Emit any structure, union, or enum type that has not been output.
750 This occurs for tag-less structs (et al) used to declare variables
752 if (TREE_CODE (type) == ENUMERAL_TYPE
753 || TREE_CODE (type) == RECORD_TYPE
754 || TREE_CODE (type) == UNION_TYPE)
756 if (TYPE_SIZE (type) != 0 /* not a forward reference */
757 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
758 sdbout_one_type (type);
761 /* Defer SDB information for top-level initialized variables! */
763 && GET_CODE (value) == MEM
764 && DECL_INITIAL (decl))
767 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
768 For now, avoid crashing. */
769 if (DECL_NAME (decl) == NULL_TREE)
772 /* Record the name for, starting a symtab entry. */
773 name = IDENTIFIER_POINTER (DECL_NAME (decl));
775 if (GET_CODE (value) == MEM
776 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
779 if (TREE_PUBLIC (decl))
781 PUT_SDB_VAL (XEXP (value, 0));
786 PUT_SDB_VAL (XEXP (value, 0));
787 PUT_SDB_SCL (C_STAT);
793 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
796 else if (GET_CODE (value) == MEM
797 && (GET_CODE (XEXP (value, 0)) == MEM
798 || (GET_CODE (XEXP (value, 0)) == REG
799 && REGNO (XEXP (value, 0)) != FRAME_POINTER_REGNUM
800 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
801 /* If the value is indirect by memory or by a register
802 that isn't the frame pointer
803 then it means the object is variable-sized and address through
804 that register or stack slot. COFF has no way to represent this
805 so all we can do is output the variable as a pointer. */
808 if (GET_CODE (XEXP (value, 0)) == REG)
810 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
815 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
817 We want the value of that CONST_INT. */
818 /* Encore compiler hates a newline in a macro arg, it seems. */
819 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
820 (XEXP (XEXP (value, 0), 0)));
821 PUT_SDB_SCL (C_AUTO);
824 type = build_pointer_type (TREE_TYPE (decl));
826 else if (GET_CODE (value) == MEM
827 && GET_CODE (XEXP (value, 0)) == PLUS
828 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
829 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
831 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
832 We want the value of that CONST_INT. */
834 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
835 PUT_SDB_SCL (C_AUTO);
837 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
839 /* Handle an obscure case which can arise when optimizing and
840 when there are few available registers. (This is *always*
841 the case for i386/i486 targets). The DECL_RTL looks like
842 (MEM (CONST ...)) even though this variable is a local `auto'
843 or a local `register' variable. In effect, what has happened
844 is that the reload pass has seen that all assignments and
845 references for one such a local variable can be replaced by
846 equivalent assignments and references to some static storage
847 variable, thereby avoiding the need for a register. In such
848 cases we're forced to lie to debuggers and tell them that
849 this variable was itself `static'. */
851 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
852 PUT_SDB_SCL (C_STAT);
856 /* It is something we don't know how to represent for SDB. */
861 PUT_SDB_TYPE (plain_type (type));
865 /* Output SDB information for a top-level initialized variable
866 that has been delayed. */
869 sdbout_toplevel_data (decl)
872 tree type = TREE_TYPE (decl);
874 if (DECL_IGNORED_P (decl))
877 if (! (TREE_CODE (decl) == VAR_DECL
878 && GET_CODE (DECL_RTL (decl)) == MEM
879 && DECL_INITIAL (decl)))
882 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
883 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
884 if (TREE_PUBLIC (decl))
890 PUT_SDB_SCL (C_STAT);
892 PUT_SDB_TYPE (plain_type (type));
896 #ifdef SDB_ALLOW_FORWARD_REFERENCES
898 /* Machinery to record and output anonymous types. */
900 static tree anonymous_types;
903 sdbout_queue_anonymous_type (type)
906 anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
910 sdbout_dequeue_anonymous_types ()
912 register tree types, link;
914 while (anonymous_types)
916 types = nreverse (anonymous_types);
917 anonymous_types = NULL_TREE;
919 for (link = types; link; link = TREE_CHAIN (link))
921 register tree type = TREE_VALUE (link);
923 if (type && ! TREE_ASM_WRITTEN (type))
924 sdbout_one_type (type);
931 /* Given a chain of ..._TYPE nodes, all of which have names,
932 output definitions of those names, as typedefs. */
940 for (link = types; link; link = TREE_CHAIN (link))
941 sdbout_one_type (link);
943 #ifdef SDB_ALLOW_FORWARD_REFERENCES
944 sdbout_dequeue_anonymous_types ();
953 if (type == error_mark_node)
954 type = integer_type_node;
955 PUT_SDB_TYPE (plain_type (type));
958 /* Output types of the fields of type TYPE, if they are structs.
960 Formerly did not chase through pointer types, since that could be circular.
961 They must come before TYPE, since forward refs are not allowed.
962 Now james@bigtex.cactus.org says to try them. */
965 sdbout_field_types (type)
969 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
970 if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
971 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
973 sdbout_one_type (TREE_TYPE (tail));
976 /* Use this to put out the top level defined record and union types
977 for later reference. If this is a struct with a name, then put that
978 name out. Other unnamed structs will have .xxfake labels generated so
979 that they may be referred to later.
980 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
981 It may NOT be called recursively. */
984 sdbout_one_type (type)
989 switch (TREE_CODE (type))
994 type = TYPE_MAIN_VARIANT (type);
995 /* Don't output a type twice. */
996 if (TREE_ASM_WRITTEN (type))
997 /* James said test TREE_ASM_BEING_WRITTEN here. */
1000 /* Output nothing if type is not yet defined. */
1001 if (TYPE_SIZE (type) == 0)
1004 TREE_ASM_WRITTEN (type) = 1;
1006 /* This is reputed to cause trouble with the following case,
1007 but perhaps checking TYPE_SIZE above will fix it. */
1009 /* Here is a test case:
1015 typedef struct intermediate {
1019 typedef struct badstr {
1024 TREE_ASM_BEING_WRITTEN (type) = 1;
1026 /* This change, which ought to make better output,
1027 used to make the COFF assembler unhappy.
1028 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1029 /* Before really doing anything, output types we want to refer to. */
1030 /* Note that in version 1 the following two lines
1031 are not used if forward references are in use. */
1032 if (TREE_CODE (type) != ENUMERAL_TYPE)
1033 sdbout_field_types (type);
1035 TREE_ASM_WRITTEN (type) = 1;
1039 /* Output a structure type. */
1041 int size = int_size_in_bytes (type);
1044 int i, n_baseclasses = 0;
1046 /* Record the type tag, but not in its permanent place just yet. */
1047 sdbout_record_type_name (type);
1049 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1051 switch (TREE_CODE (type))
1054 PUT_SDB_SCL (C_UNTAG);
1055 PUT_SDB_TYPE (T_UNION);
1060 PUT_SDB_SCL (C_STRTAG);
1061 PUT_SDB_TYPE (T_STRUCT);
1066 PUT_SDB_SCL (C_ENTAG);
1067 PUT_SDB_TYPE (T_ENUM);
1072 PUT_SDB_SIZE (size);
1075 /* Print out the base class information with fields
1076 named after the types they hold. */
1077 if (TYPE_BINFO (type)
1078 && TYPE_BINFO_BASETYPES (type))
1079 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1080 for (i = 0; i < n_baseclasses; i++)
1082 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1083 tree child_type = BINFO_TYPE (child);
1084 tree child_type_name;
1085 if (TYPE_NAME (child_type) == 0)
1087 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1088 child_type_name = TYPE_NAME (child_type);
1089 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1090 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1095 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1096 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1097 PUT_SDB_SCL (member_scl);
1098 sdbout_type (BINFO_TYPE (child));
1102 /* output the individual fields */
1104 if (TREE_CODE (type) == ENUMERAL_TYPE)
1105 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1107 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1108 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1109 PUT_SDB_SCL (C_MOE);
1110 PUT_SDB_TYPE (T_MOE);
1114 else /* record or union type */
1115 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1116 /* Output the name, type, position (in bits), size (in bits)
1119 /* Omit here the nameless fields that are used to skip bits.
1120 Also omit fields with variable size or position.
1121 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1122 if (TREE_CODE (tem) == FIELD_DECL
1123 && DECL_NAME (tem) != 0
1124 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1125 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1128 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem)));
1129 if (DECL_BIT_FIELD_TYPE (tem))
1131 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1132 PUT_SDB_SCL (C_FIELD);
1133 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1134 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1138 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1140 PUT_SDB_SCL (member_scl);
1141 sdbout_type (TREE_TYPE (tem));
1145 /* output end of a structure,union, or enumeral definition */
1147 PUT_SDB_PLAIN_DEF ("eos");
1148 PUT_SDB_INT_VAL (size);
1149 PUT_SDB_SCL (C_EOS);
1150 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1151 PUT_SDB_SIZE (size);
1158 /* The following two functions output definitions of function parameters.
1159 Each parameter gets a definition locating it in the parameter list.
1160 Each parameter that is a register variable gets a second definition
1161 locating it in the register.
1163 Printing or argument lists in gdb uses the definitions that
1164 locate in the parameter list. But reference to the variable in
1165 expressions uses preferentially the definition as a register. */
1167 /* Output definitions, referring to storage in the parmlist,
1168 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1171 sdbout_parms (parms)
1174 for (; parms; parms = TREE_CHAIN (parms))
1175 if (DECL_NAME (parms))
1177 int current_sym_value = 0;
1178 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1180 if (name == 0 || *name == 0)
1181 name = gen_fake_label ();
1183 /* Perform any necessary register eliminations on the parameter's rtl,
1184 so that the debugging output will be accurate. */
1185 DECL_INCOMING_RTL (parms) =
1186 eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1187 DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1189 if (PARM_PASSED_IN_MEMORY (parms))
1191 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1194 /* ??? Here we assume that the parm address is indexed
1195 off the frame pointer or arg pointer.
1196 If that is not true, we produce meaningless results,
1197 but do not crash. */
1198 if (GET_CODE (addr) == PLUS
1199 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1200 current_sym_value = INTVAL (XEXP (addr, 1));
1202 current_sym_value = 0;
1204 if (GET_CODE (DECL_RTL (parms)) == REG
1205 && REGNO (DECL_RTL (parms)) >= 0
1206 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1207 type = DECL_ARG_TYPE (parms);
1210 int original_sym_value = current_sym_value;
1212 /* This is the case where the parm is passed as an int or
1213 double and it is converted to a char, short or float
1214 and stored back in the parmlist. In this case, describe
1215 the parm with the variable's declared type, and adjust
1216 the address if the least significant bytes (which we are
1217 using) are not the first ones. */
1218 #if BYTES_BIG_ENDIAN
1219 if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1220 current_sym_value +=
1221 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1222 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1224 if (GET_CODE (DECL_RTL (parms)) == MEM
1225 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1226 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1228 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1229 == current_sym_value))
1230 type = TREE_TYPE (parms);
1233 current_sym_value = original_sym_value;
1234 type = DECL_ARG_TYPE (parms);
1239 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1240 PUT_SDB_SCL (C_ARG);
1241 PUT_SDB_TYPE (plain_type (type));
1244 else if (GET_CODE (DECL_RTL (parms)) == REG)
1247 /* Parm passed in registers and lives in registers or nowhere. */
1249 /* If parm lives in a register, use that register;
1250 pretend the parm was passed there. It would be more consistent
1251 to describe the register where the parm was passed,
1252 but in practice that register usually holds something else. */
1253 if (REGNO (DECL_RTL (parms)) >= 0
1254 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1255 best_rtl = DECL_RTL (parms);
1256 /* If the parm lives nowhere,
1257 use the register where it was passed. */
1259 best_rtl = DECL_INCOMING_RTL (parms);
1262 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1263 PUT_SDB_SCL (C_REGPARM);
1264 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1267 else if (GET_CODE (DECL_RTL (parms)) == MEM
1268 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1270 /* Parm was passed in registers but lives on the stack. */
1272 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1273 in which case we want the value of that CONST_INT,
1274 or (MEM (REG ...)) or (MEM (MEM ...)),
1275 in which case we use a value of zero. */
1276 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1277 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1278 current_sym_value = 0;
1280 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1282 /* Again, this assumes the offset is based on the arg pointer. */
1284 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1285 XEXP (DECL_RTL (parms), 0)));
1286 PUT_SDB_SCL (C_ARG);
1287 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1293 /* Output definitions for the places where parms live during the function,
1294 when different from where they were passed, when the parms were passed
1297 It is not useful to do this for parms passed in registers
1298 that live during the function in different registers, because it is
1299 impossible to look in the passed register for the passed value,
1300 so we use the within-the-function register to begin with.
1302 PARMS is a chain of PARM_DECL nodes. */
1305 sdbout_reg_parms (parms)
1308 for (; parms; parms = TREE_CHAIN (parms))
1309 if (DECL_NAME (parms))
1311 char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1313 /* Report parms that live in registers during the function
1314 but were passed in memory. */
1315 if (GET_CODE (DECL_RTL (parms)) == REG
1316 && REGNO (DECL_RTL (parms)) >= 0
1317 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1318 && PARM_PASSED_IN_MEMORY (parms))
1320 if (name == 0 || *name == 0)
1321 name = gen_fake_label ();
1323 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1324 PUT_SDB_SCL (C_REG);
1325 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1328 /* Report parms that live in memory but not where they were passed. */
1329 else if (GET_CODE (DECL_RTL (parms)) == MEM
1330 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1331 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1332 && PARM_PASSED_IN_MEMORY (parms)
1333 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1335 #if 0 /* ??? It is not clear yet what should replace this. */
1336 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1337 /* A parm declared char is really passed as an int,
1338 so it occupies the least significant bytes.
1339 On a big-endian machine those are not the low-numbered ones. */
1340 #if BYTES_BIG_ENDIAN
1341 if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1342 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1343 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1345 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1348 if (name == 0 || *name == 0)
1349 name = gen_fake_label ();
1351 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1352 (XEXP (DECL_RTL (parms), 0)));
1353 PUT_SDB_SCL (C_AUTO);
1354 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1361 /* Describe the beginning of an internal block within a function.
1362 Also output descriptions of variables defined in this block.
1364 N is the number of the block, by order of beginning, counting from 1,
1365 and not counting the outermost (function top-level) block.
1366 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1367 if the count starts at 0 for the outermost one. */
1370 sdbout_begin_block (file, line, n)
1375 tree decl = current_function_decl;
1376 MAKE_LINE_SAFE (line);
1377 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1380 /* Include the outermost BLOCK's variables in block 1. */
1381 next_block_number = 0;
1383 sdbout_block (DECL_INITIAL (decl));
1385 /* If -g1, suppress all the internal symbols of functions
1386 except for arguments. */
1387 if (debug_info_level != DINFO_LEVEL_TERSE)
1389 next_block_number = 0;
1391 sdbout_block (DECL_INITIAL (decl));
1394 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1395 sdbout_dequeue_anonymous_types ();
1399 /* Describe the end line-number of an internal block within a function. */
1402 sdbout_end_block (file, line)
1406 MAKE_LINE_SAFE (line);
1407 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1410 /* Output sdb info for the current function name.
1411 Called from assemble_start_function. */
1414 sdbout_mark_begin_function ()
1416 sdbout_symbol (current_function_decl, 0);
1419 /* Called at beginning of function body (after prologue).
1420 Record the function's starting line number, so we can output
1421 relative line numbers for the other lines.
1422 Describe beginning of outermost block.
1423 Also describe the parameter list. */
1426 sdbout_begin_function (line)
1429 sdb_begin_function_line = line - 1;
1430 PUT_SDB_FUNCTION_START (line);
1431 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1432 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1435 /* Called at end of function (before epilogue).
1436 Describe end of outermost block. */
1439 sdbout_end_function (line)
1442 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1443 sdbout_dequeue_anonymous_types ();
1446 MAKE_LINE_SAFE (line);
1447 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1449 /* Indicate we are between functions, for line-number output. */
1450 sdb_begin_function_line = -1;
1453 /* Output sdb info for the absolute end of a function.
1454 Called after the epilogue is output. */
1457 sdbout_end_epilogue ()
1459 char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1460 PUT_SDB_EPILOGUE_END (name);
1463 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1470 PUT_SDB_DEF (LABEL_NAME (insn));
1472 PUT_SDB_SCL (C_LABEL);
1473 PUT_SDB_TYPE (T_NULL);
1477 #endif /* SDB_DEBUGGING_INFO */