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)
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 sdbout_record_type_name (type
)
397 if (KNOWN_TYPE_TAG (type
))
400 if (TYPE_NAME (type
) != 0)
403 /* Find the IDENTIFIER_NODE for the type name. */
404 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
406 t
= TYPE_NAME (type
);
408 #if 1 /* As a temprary hack, use typedef names for C++ only. */
409 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
410 && TYPE_LANG_SPECIFIC (type
))
412 t
= DECL_NAME (TYPE_NAME (type
));
416 /* Now get the name as a string, or invent one. */
418 name
= IDENTIFIER_POINTER (t
);
421 no_name
= (name
== 0 || *name
== 0);
423 name
= gen_fake_label ();
425 SET_KNOWN_TYPE_TAG (type
, name
);
426 #ifdef SDB_ALLOW_FORWARD_REFERENCES
428 sdbout_queue_anonymous_type (type
);
437 type
= void_type_node
;
438 if (type
== error_mark_node
)
439 type
= integer_type_node
;
440 type
= TYPE_MAIN_VARIANT (type
);
442 switch (TREE_CODE (type
))
448 int size
= int_size_in_bytes (type
) * BITS_PER_UNIT
;
449 if (size
== CHAR_TYPE_SIZE
)
450 return (TREE_UNSIGNED (type
) ? T_UCHAR
: T_CHAR
);
451 if (size
== SHORT_TYPE_SIZE
)
452 return (TREE_UNSIGNED (type
) ? T_USHORT
: T_SHORT
);
453 if (size
== INT_TYPE_SIZE
)
454 return (TREE_UNSIGNED (type
) ? T_UINT
: T_INT
);
460 int size
= int_size_in_bytes (type
) * BITS_PER_UNIT
;
461 if (size
== FLOAT_TYPE_SIZE
)
463 if (size
== DOUBLE_TYPE_SIZE
)
471 m
= plain_type_1 (TREE_TYPE (type
));
472 if (sdb_n_dims
< SDB_MAX_DIM
)
473 sdb_dims
[sdb_n_dims
++]
474 = (TYPE_DOMAIN (type
)
475 ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type
))) + 1
477 return PUSH_DERIVED_LEVEL (DT_ARY
, m
);
485 #ifdef SDB_ALLOW_FORWARD_REFERENCES
486 sdbout_record_type_name (type
);
488 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
489 if ((TREE_ASM_WRITTEN (type
) && KNOWN_TYPE_TAG (type
) != 0)
490 #ifdef SDB_ALLOW_FORWARD_REFERENCES
491 || TYPE_MODE (type
) != VOIDmode
496 /* Output the referenced structure tag name
497 only if the .def has already been finished.
498 At least on 386, the Unix assembler
499 cannot handle forward references to tags. */
500 /* But the 88100, it requires them, sigh... */
501 /* And the MIPS requires unknown refs as well... */
502 tag
= KNOWN_TYPE_TAG (type
);
504 /* These 3 lines used to follow the close brace.
505 However, a size of 0 without a tag implies a tag of 0,
506 so if we don't know a tag, we can't mention the size. */
507 sdb_type_size
= int_size_in_bytes (type
);
508 if (sdb_type_size
< 0)
511 return ((TREE_CODE (type
) == RECORD_TYPE
) ? T_STRUCT
512 : (TREE_CODE (type
) == UNION_TYPE
) ? T_UNION
518 int m
= plain_type_1 (TREE_TYPE (type
));
519 return PUSH_DERIVED_LEVEL (DT_PTR
, m
);
524 int m
= plain_type_1 (TREE_TYPE (type
));
525 return PUSH_DERIVED_LEVEL (DT_FCN
, m
);
532 /* Output the symbols defined in block number DO_BLOCK.
533 Set NEXT_BLOCK_NUMBER to 0 before calling.
535 This function works by walking the tree structure of blocks,
536 counting blocks until it finds the desired block. */
538 static int do_block
= 0;
540 static int next_block_number
;
548 /* Ignore blocks never expanded or otherwise marked as real. */
549 if (TREE_USED (block
))
551 /* When we reach the specified block, output its symbols. */
552 if (next_block_number
== do_block
)
554 sdbout_syms (BLOCK_VARS (block
));
557 /* If we are past the specified block, stop the scan. */
558 if (next_block_number
> do_block
)
563 /* Scan the blocks within this block. */
564 sdbout_block (BLOCK_SUBBLOCKS (block
));
567 block
= BLOCK_CHAIN (block
);
571 /* Call sdbout_symbol on each decl in the chain SYMS. */
579 if (TREE_CODE (syms
) != LABEL_DECL
)
580 sdbout_symbol (syms
, 1);
581 syms
= TREE_CHAIN (syms
);
585 /* Output SDB information for a symbol described by DECL.
586 LOCAL is nonzero if the symbol is not file-scope. */
589 sdbout_symbol (decl
, local
)
594 tree type
= TREE_TYPE (decl
);
595 tree context
= NULL_TREE
;
600 sdbout_one_type (type
);
602 switch (TREE_CODE (decl
))
605 /* Enum values are defined by defining the enum type. */
609 /* Don't mention a nested function under its parent. */
610 context
= decl_function_context (decl
);
611 if (context
== current_function_decl
)
613 if (TREE_EXTERNAL (decl
))
615 if (GET_CODE (DECL_RTL (decl
)) != MEM
616 || GET_CODE (XEXP (DECL_RTL (decl
), 0)) != SYMBOL_REF
)
618 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
619 PUT_SDB_VAL (XEXP (DECL_RTL (decl
), 0));
620 PUT_SDB_SCL (TREE_PUBLIC (decl
) ? C_EXT
: C_STAT
);
624 /* Done with tagged types. */
625 if (DECL_NAME (decl
) == 0)
628 /* Output typedef name. */
629 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl
)));
630 PUT_SDB_SCL (C_TPDEF
);
634 /* Parm decls go in their own separate chains
635 and are output by sdbout_reg_parms and sdbout_parms. */
639 /* Don't mention a variable that is external.
640 Let the file that defines it describe it. */
641 if (TREE_EXTERNAL (decl
))
644 /* If there was an error in the declaration, don't dump core
645 if there is no RTL associated with the variable doesn't
647 if (DECL_RTL (decl
) == 0)
650 value
= eliminate_regs (DECL_RTL (decl
), 0, 0);
652 /* Don't mention a variable at all
653 if it was completely optimized into nothingness.
655 If DECL was from an inline function, then its rtl
656 is not identically the rtl that was used in this
657 particular compilation. */
658 if (GET_CODE (value
) == REG
)
660 regno
= REGNO (DECL_RTL (decl
));
661 if (regno
>= FIRST_PSEUDO_REGISTER
)
662 regno
= reg_renumber
[REGNO (DECL_RTL (decl
))];
666 else if (GET_CODE (DECL_RTL (decl
)) == SUBREG
)
669 while (GET_CODE (value
) == SUBREG
)
671 offset
+= SUBREG_WORD (value
);
672 value
= SUBREG_REG (value
);
674 if (GET_CODE (value
) == REG
)
676 regno
= REGNO (value
);
677 if (regno
>= FIRST_PSEUDO_REGISTER
)
678 regno
= reg_renumber
[REGNO (value
)];
684 /* Emit any structure, union, or enum type that has not been output.
685 This occurs for tag-less structs (et al) used to declare variables
687 if (TREE_CODE (type
) == ENUMERAL_TYPE
688 || TREE_CODE (type
) == RECORD_TYPE
689 || TREE_CODE (type
) == UNION_TYPE
)
691 if (TYPE_SIZE (type
) != 0 /* not a forward reference */
692 && KNOWN_TYPE_TAG (type
) == 0) /* not yet declared */
693 sdbout_one_type (type
);
696 /* Defer SDB information for top-level initialized variables! */
698 && GET_CODE (value
) == MEM
699 && DECL_INITIAL (decl
))
702 /* Record the name for, starting a symtab entry. */
703 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
705 if (GET_CODE (value
) == MEM
706 && GET_CODE (XEXP (value
, 0)) == SYMBOL_REF
)
709 if (TREE_PUBLIC (decl
))
711 PUT_SDB_VAL (XEXP (value
, 0));
716 PUT_SDB_VAL (XEXP (value
, 0));
717 PUT_SDB_SCL (C_STAT
);
723 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno
));
726 else if (GET_CODE (value
) == MEM
727 && (GET_CODE (XEXP (value
, 0)) == MEM
728 || (GET_CODE (XEXP (value
, 0)) == REG
729 && REGNO (XEXP (value
, 0)) != FRAME_POINTER_REGNUM
730 && REGNO (XEXP (value
, 0)) != STACK_POINTER_REGNUM
)))
731 /* If the value is indirect by memory or by a register
732 that isn't the frame pointer
733 then it means the object is variable-sized and address through
734 that register or stack slot. COFF has no way to represent this
735 so all we can do is output the variable as a pointer. */
738 if (GET_CODE (XEXP (value
, 0)) == REG
)
740 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value
, 0))));
745 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
747 We want the value of that CONST_INT. */
748 /* Encore compiler hates a newline in a macro arg, it seems. */
749 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
750 (XEXP (XEXP (value
, 0), 0)));
751 PUT_SDB_SCL (C_AUTO
);
754 type
= build_pointer_type (TREE_TYPE (decl
));
756 else if (GET_CODE (value
) == MEM
757 && GET_CODE (XEXP (value
, 0)) == PLUS
758 && GET_CODE (XEXP (XEXP (value
, 0), 0)) == REG
759 && GET_CODE (XEXP (XEXP (value
, 0), 1)) == CONST_INT
)
761 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))).
762 We want the value of that CONST_INT. */
764 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value
, 0)));
765 PUT_SDB_SCL (C_AUTO
);
767 else if (GET_CODE (value
) == MEM
&& GET_CODE (XEXP (value
, 0)) == CONST
)
769 /* Handle an obscure case which can arise when optimizing and
770 when there are few available registers. (This is *always*
771 the case for i386/i486 targets). The DECL_RTL looks like
772 (MEM (CONST ...)) even though this variable is a local `auto'
773 or a local `register' variable. In effect, what has happened
774 is that the reload pass has seen that all assignments and
775 references for one such a local variable can be replaced by
776 equivalent assignments and references to some static storage
777 variable, thereby avoiding the need for a register. In such
778 cases we're forced to lie to debuggers and tell them that
779 this variable was itself `static'. */
781 PUT_SDB_VAL (XEXP (XEXP (value
, 0), 0));
782 PUT_SDB_SCL (C_STAT
);
786 /* It is something we don't know how to represent for SDB. */
791 PUT_SDB_TYPE (plain_type (type
));
795 /* Output SDB information for a top-level initialized variable
796 that has been delayed. */
799 sdbout_toplevel_data (decl
)
802 tree type
= TREE_TYPE (decl
);
804 if (! (TREE_CODE (decl
) == VAR_DECL
805 && GET_CODE (DECL_RTL (decl
)) == MEM
806 && DECL_INITIAL (decl
)))
809 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
810 PUT_SDB_VAL (XEXP (DECL_RTL (decl
), 0));
811 if (TREE_PUBLIC (decl
))
817 PUT_SDB_SCL (C_STAT
);
819 PUT_SDB_TYPE (plain_type (type
));
823 #ifdef SDB_ALLOW_FORWARD_REFERENCES
825 /* Machinery to record and output anonymous types. */
827 static tree anonymous_types
;
830 sdbout_queue_anonymous_type (type
)
833 anonymous_types
= saveable_tree_cons (NULL_TREE
, type
, anonymous_types
);
837 sdbout_dequeue_anonymous_types ()
839 register tree types
, link
;
841 while (anonymous_types
)
843 types
= nreverse (anonymous_types
);
844 anonymous_types
= NULL_TREE
;
846 for (link
= types
; link
; link
= TREE_CHAIN (link
))
848 register tree type
= TREE_VALUE (link
);
850 if (type
&& ! TREE_ASM_WRITTEN (type
))
851 sdbout_one_type (type
);
858 /* Given a chain of ..._TYPE nodes, all of which have names,
859 output definitions of those names, as typedefs. */
867 for (link
= types
; link
; link
= TREE_CHAIN (link
))
868 sdbout_one_type (link
);
870 #ifdef SDB_ALLOW_FORWARD_REFERENCES
871 sdbout_dequeue_anonymous_types ();
880 if (type
== error_mark_node
)
881 type
= integer_type_node
;
882 PUT_SDB_TYPE (plain_type (type
));
885 /* Output types of the fields of type TYPE, if they are structs.
887 Formerly did not chase through pointer types, since that could be circular.
888 They must come before TYPE, since forward refs are not allowed.
889 Now james@bigtex.cactus.org says to try them. */
892 sdbout_field_types (type
)
896 for (tail
= TYPE_FIELDS (type
); tail
; tail
= TREE_CHAIN (tail
))
897 if (TREE_CODE (TREE_TYPE (tail
)) == POINTER_TYPE
)
898 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail
)));
900 sdbout_one_type (TREE_TYPE (tail
));
903 /* Use this to put out the top level defined record and union types
904 for later reference. If this is a struct with a name, then put that
905 name out. Other unnamed structs will have .xxfake labels generated so
906 that they may be referred to later.
907 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
908 It may NOT be called recursively. */
911 sdbout_one_type (type
)
916 switch (TREE_CODE (type
))
921 type
= TYPE_MAIN_VARIANT (type
);
922 /* Don't output a type twice. */
923 if (TREE_ASM_WRITTEN (type
))
924 /* James said test TREE_ASM_BEING_WRITTEN here. */
927 /* Output nothing if type is not yet defined. */
928 if (TYPE_SIZE (type
) == 0)
931 TREE_ASM_WRITTEN (type
) = 1;
933 /* This is reputed to cause trouble with the following case,
934 but perhaps checking TYPE_SIZE above will fix it.
936 /* Here is a test case:
942 typedef struct intermediate {
946 typedef struct badstr {
951 TREE_ASM_BEING_WRITTEN (type
) = 1;
953 /* This change, which ought to make better output,
954 used to make the COFF assembler unhappy.
955 Changes involving KNOWN_TYPE_TAG may fix the problem. */
956 /* Before really doing anything, output types we want to refer to. */
957 /* Note that in version 1 the following two lines
958 are not used if forward references are in use. */
959 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
960 sdbout_field_types (type
);
962 TREE_ASM_WRITTEN (type
) = 1;
966 /* Output a structure type. */
968 int size
= int_size_in_bytes (type
);
971 int i
, n_baseclasses
= 0;
973 /* Record the type tag, but not in its permanent place just yet. */
974 sdbout_record_type_name (type
);
976 PUT_SDB_DEF (KNOWN_TYPE_TAG (type
));
978 switch (TREE_CODE (type
))
981 PUT_SDB_SCL (C_UNTAG
);
982 PUT_SDB_TYPE (T_UNION
);
987 PUT_SDB_SCL (C_STRTAG
);
988 PUT_SDB_TYPE (T_STRUCT
);
993 PUT_SDB_SCL (C_ENTAG
);
994 PUT_SDB_TYPE (T_ENUM
);
1002 /* Print out the base class information with fields
1003 named after the types they hold. */
1004 if (TYPE_BINFO (type
)
1005 && TYPE_BINFO_BASETYPES (type
))
1006 n_baseclasses
= TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
));
1007 for (i
= 0; i
< n_baseclasses
; i
++)
1009 tree child
= TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type
)), i
);
1010 tree child_type
= BINFO_TYPE (child
);
1011 tree child_type_name
;
1012 if (TYPE_NAME (child_type
) == 0)
1014 if (TREE_CODE (TYPE_NAME (child_type
)) == IDENTIFIER_NODE
)
1015 child_type_name
= TYPE_NAME (child_type
);
1016 else if (TREE_CODE (TYPE_NAME (child_type
)) == TYPE_DECL
)
1017 child_type_name
= DECL_NAME (TYPE_NAME (child_type
));
1022 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name
));
1023 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child
)));
1024 PUT_SDB_SCL (member_scl
);
1025 sdbout_type (BINFO_TYPE (child
));
1029 /* output the individual fields */
1031 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1032 for (tem
= TYPE_FIELDS (type
); tem
; tem
= TREE_CHAIN (tem
))
1034 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem
)));
1035 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem
)));
1036 PUT_SDB_SCL (C_MOE
);
1037 PUT_SDB_TYPE (T_MOE
);
1041 else /* record or union type */
1042 for (tem
= TYPE_FIELDS (type
); tem
; tem
= TREE_CHAIN (tem
))
1043 /* Output the name, type, position (in bits), size (in bits)
1046 /* Omit here the nameless fields that are used to skip bits.
1047 Also omit fields with variable size or position.
1048 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1049 if (TREE_CODE (tem
) == FIELD_DECL
1050 && DECL_NAME (tem
) != 0
1051 && TREE_CODE (DECL_SIZE (tem
)) == INTEGER_CST
1052 && TREE_CODE (DECL_FIELD_BITPOS (tem
)) == INTEGER_CST
)
1055 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (tem
)));
1056 if (DECL_BIT_FIELD_TYPE (tem
))
1058 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem
)));
1059 PUT_SDB_SCL (C_FIELD
);
1060 sdbout_type (DECL_BIT_FIELD_TYPE (tem
));
1061 PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem
)));
1065 PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem
))
1067 PUT_SDB_SCL (member_scl
);
1068 sdbout_type (TREE_TYPE (tem
));
1072 /* output end of a structure,union, or enumeral definition */
1074 PUT_SDB_PLAIN_DEF ("eos");
1075 PUT_SDB_INT_VAL (size
);
1076 PUT_SDB_SCL (C_EOS
);
1077 PUT_SDB_TAG (KNOWN_TYPE_TAG (type
));
1078 PUT_SDB_SIZE (size
);
1085 /* The following two functions output definitions of function parameters.
1086 Each parameter gets a definition locating it in the parameter list.
1087 Each parameter that is a register variable gets a second definition
1088 locating it in the register.
1090 Printing or argument lists in gdb uses the definitions that
1091 locate in the parameter list. But reference to the variable in
1092 expressions uses preferentially the definition as a register. */
1094 /* Output definitions, referring to storage in the parmlist,
1095 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1098 sdbout_parms (parms
)
1101 for (; parms
; parms
= TREE_CHAIN (parms
))
1102 if (DECL_NAME (parms
))
1104 int current_sym_value
= 0;
1105 char *name
= IDENTIFIER_POINTER (DECL_NAME (parms
));
1107 if (name
== 0 || *name
== 0)
1108 name
= gen_fake_label ();
1110 /* Perform any necessary register eliminations on the parameter's rtl,
1111 so that the debugging output will be accurate. */
1112 DECL_INCOMING_RTL (parms
) =
1113 eliminate_regs (DECL_INCOMING_RTL (parms
), 0, 0);
1114 DECL_RTL (parms
) = eliminate_regs (DECL_RTL (parms
), 0, 0);
1116 if (PARM_PASSED_IN_MEMORY (parms
))
1118 rtx addr
= XEXP (DECL_INCOMING_RTL (parms
), 0);
1121 /* ??? Here we assume that the parm address is indexed
1122 off the frame pointer or arg pointer.
1123 If that is not true, we produce meaningless results,
1124 but do not crash. */
1125 if (GET_CODE (addr
) == PLUS
1126 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
1127 current_sym_value
= INTVAL (XEXP (addr
, 1));
1129 current_sym_value
= 0;
1131 if (GET_CODE (DECL_RTL (parms
)) == REG
1132 && REGNO (DECL_RTL (parms
)) >= 0
1133 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
)
1134 type
= DECL_ARG_TYPE (parms
);
1137 int original_sym_value
= current_sym_value
;
1139 /* This is the case where the parm is passed as an int or
1140 double and it is converted to a char, short or float
1141 and stored back in the parmlist. In this case, describe
1142 the parm with the variable's declared type, and adjust
1143 the address if the least significant bytes (which we are
1144 using) are not the first ones. */
1145 #if BYTES_BIG_ENDIAN
1146 if (TREE_TYPE (parms
) != DECL_ARG_TYPE (parms
))
1147 current_sym_value
+=
1148 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms
)))
1149 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms
))));
1151 if (GET_CODE (DECL_RTL (parms
)) == MEM
1152 && GET_CODE (XEXP (DECL_RTL (parms
), 0)) == PLUS
1153 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms
), 0), 1))
1155 && (INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1))
1156 == current_sym_value
))
1157 type
= TREE_TYPE (parms
);
1160 current_sym_value
= original_sym_value
;
1161 type
= DECL_ARG_TYPE (parms
);
1166 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value
, addr
));
1167 PUT_SDB_SCL (C_ARG
);
1168 PUT_SDB_TYPE (plain_type (type
));
1171 else if (GET_CODE (DECL_RTL (parms
)) == REG
)
1174 /* Parm passed in registers and lives in registers or nowhere. */
1176 /* If parm lives in a register, use that register;
1177 pretend the parm was passed there. It would be more consistent
1178 to describe the register where the parm was passed,
1179 but in practice that register usually holds something else. */
1180 if (REGNO (DECL_RTL (parms
)) >= 0
1181 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
)
1182 best_rtl
= DECL_RTL (parms
);
1183 /* If the parm lives nowhere,
1184 use the register where it was passed. */
1186 best_rtl
= DECL_INCOMING_RTL (parms
);
1189 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl
)));
1190 PUT_SDB_SCL (C_REGPARM
);
1191 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
), 0));
1194 else if (GET_CODE (DECL_RTL (parms
)) == MEM
1195 && XEXP (DECL_RTL (parms
), 0) != const0_rtx
)
1197 /* Parm was passed in registers but lives on the stack. */
1199 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1200 in which case we want the value of that CONST_INT,
1201 or (MEM (REG ...)) or (MEM (MEM ...)),
1202 in which case we use a value of zero. */
1203 if (GET_CODE (XEXP (DECL_RTL (parms
), 0)) == REG
1204 || GET_CODE (XEXP (DECL_RTL (parms
), 0)) == MEM
)
1205 current_sym_value
= 0;
1207 current_sym_value
= INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1));
1209 /* Again, this assumes the offset is based on the arg pointer. */
1211 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value
,
1212 XEXP (DECL_RTL (parms
), 0)));
1213 PUT_SDB_SCL (C_ARG
);
1214 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
), 0));
1220 /* Output definitions for the places where parms live during the function,
1221 when different from where they were passed, when the parms were passed
1224 It is not useful to do this for parms passed in registers
1225 that live during the function in different registers, because it is
1226 impossible to look in the passed register for the passed value,
1227 so we use the within-the-function register to begin with.
1229 PARMS is a chain of PARM_DECL nodes. */
1232 sdbout_reg_parms (parms
)
1235 for (; parms
; parms
= TREE_CHAIN (parms
))
1236 if (DECL_NAME (parms
))
1238 char *name
= IDENTIFIER_POINTER (DECL_NAME (parms
));
1240 /* Report parms that live in registers during the function
1241 but were passed in memory. */
1242 if (GET_CODE (DECL_RTL (parms
)) == REG
1243 && REGNO (DECL_RTL (parms
)) >= 0
1244 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
1245 && PARM_PASSED_IN_MEMORY (parms
))
1247 if (name
== 0 || *name
== 0)
1248 name
= gen_fake_label ();
1250 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms
))));
1251 PUT_SDB_SCL (C_REG
);
1252 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
), 0));
1255 /* Report parms that live in memory but not where they were passed. */
1256 else if (GET_CODE (DECL_RTL (parms
)) == MEM
1257 && GET_CODE (XEXP (DECL_RTL (parms
), 0)) == PLUS
1258 && GET_CODE (XEXP (XEXP (DECL_RTL (parms
), 0), 1)) == CONST_INT
1259 && PARM_PASSED_IN_MEMORY (parms
)
1260 && ! rtx_equal_p (DECL_RTL (parms
), DECL_INCOMING_RTL (parms
)))
1262 #if 0 /* ??? It is not clear yet what should replace this. */
1263 int offset
= DECL_OFFSET (parms
) / BITS_PER_UNIT
;
1264 /* A parm declared char is really passed as an int,
1265 so it occupies the least significant bytes.
1266 On a big-endian machine those are not the low-numbered ones. */
1267 #if BYTES_BIG_ENDIAN
1268 if (offset
!= -1 && TREE_TYPE (parms
) != DECL_ARG_TYPE (parms
))
1269 offset
+= (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms
)))
1270 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms
))));
1272 if (INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1)) != offset
) {...}
1275 if (name
== 0 || *name
== 0)
1276 name
= gen_fake_label ();
1278 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1279 (XEXP (DECL_RTL (parms
), 0)));
1280 PUT_SDB_SCL (C_AUTO
);
1281 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1288 /* Describe the beginning of an internal block within a function.
1289 Also output descriptions of variables defined in this block.
1291 N is the number of the block, by order of beginning, counting from 1,
1292 and not counting the outermost (function top-level) block.
1293 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1294 if the count starts at 0 for the outermost one. */
1297 sdbout_begin_block (file
, line
, n
)
1302 tree decl
= current_function_decl
;
1303 MAKE_LINE_SAFE (line
);
1304 PUT_SDB_BLOCK_START (line
- sdb_begin_function_line
);
1307 /* Include the outermost BLOCK's variables in block 1. */
1308 next_block_number
= 0;
1310 sdbout_block (DECL_INITIAL (decl
));
1312 /* If -g1, suppress all the internal symbols of functions
1313 except for arguments. */
1314 if (debug_info_level
!= DINFO_LEVEL_TERSE
)
1316 next_block_number
= 0;
1318 sdbout_block (DECL_INITIAL (decl
));
1321 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1322 sdbout_dequeue_anonymous_types ();
1326 /* Describe the end line-number of an internal block within a function. */
1329 sdbout_end_block (file
, line
)
1333 MAKE_LINE_SAFE (line
);
1334 PUT_SDB_BLOCK_END (line
- sdb_begin_function_line
);
1337 /* Output sdb info for the current function name.
1338 Called from assemble_start_function. */
1341 sdbout_mark_begin_function ()
1343 sdbout_symbol (current_function_decl
, 0);
1346 /* Called at beginning of function body (after prologue).
1347 Record the function's starting line number, so we can output
1348 relative line numbers for the other lines.
1349 Describe beginning of outermost block.
1350 Also describe the parameter list. */
1353 sdbout_begin_function (line
)
1356 sdb_begin_function_line
= line
- 1;
1357 PUT_SDB_FUNCTION_START (line
);
1358 sdbout_parms (DECL_ARGUMENTS (current_function_decl
));
1359 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl
));
1362 /* Called at end of function (before epilogue).
1363 Describe end of outermost block. */
1366 sdbout_end_function (line
)
1369 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1370 sdbout_dequeue_anonymous_types ();
1373 MAKE_LINE_SAFE (line
);
1374 PUT_SDB_FUNCTION_END (line
- sdb_begin_function_line
);
1376 /* Indicate we are between functions, for line-number output. */
1377 sdb_begin_function_line
= -1;
1380 /* Output sdb info for the absolute end of a function.
1381 Called after the epilogue is output. */
1384 sdbout_end_epilogue ()
1386 char *name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl
));
1387 PUT_SDB_EPILOGUE_END (name
);
1390 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1397 PUT_SDB_DEF (LABEL_NAME (insn
));
1399 PUT_SDB_SCL (C_LABEL
);
1400 PUT_SDB_TYPE (T_NULL
);
1404 #endif /* SDB_DEBUGGING_INFO */