1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 /* mike@tredysvr.Tredydev.Unisys.COM says:
23 I modified the struct.c example and have a nm of a .o resulting from the
24 AT&T C compiler. From the example below I would conclude the following:
26 1. All .defs from structures are emitted as scanned. The example below
27 clearly shows the symbol table entries for BoxRec2 are after the first
30 2. All functions and their locals (including statics) are emitted as scanned.
32 3. All nested unnamed union and structure .defs must be emitted before
33 the structure in which they are nested. The AT&T assembler is a
34 one pass beast as far as symbolics are concerned.
36 4. All structure .defs are emitted before the typedefs that refer to them.
38 5. All top level static and external variable definitions are moved to the
39 end of file with all top level statics occurring first before externs.
41 6. All undefined references are at the end of the file.
46 #include "coretypes.h"
52 static GTY(()) tree anonymous_types
;
54 #ifdef SDB_DEBUGGING_INFO
59 #include "insn-config.h"
65 #include "langhooks.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
;
101 static void sdbout_init (const char *);
102 static void sdbout_finish (const char *);
103 static void sdbout_start_source_file (unsigned int, const char *);
104 static void sdbout_end_source_file (unsigned int);
105 static void sdbout_begin_block (unsigned int, unsigned int);
106 static void sdbout_end_block (unsigned int, unsigned int);
107 static void sdbout_source_line (unsigned int, const char *);
108 static void sdbout_end_epilogue (unsigned int, const char *);
109 static void sdbout_global_decl (tree
);
110 #ifndef MIPS_DEBUGGING_INFO
111 static void sdbout_begin_prologue (unsigned int, const char *);
113 static void sdbout_end_prologue (unsigned int, const char *);
114 static void sdbout_begin_function (tree
);
115 static void sdbout_end_function (unsigned int);
116 static void sdbout_toplevel_data (tree
);
117 static void sdbout_label (rtx
);
118 static char *gen_fake_label (void);
119 static int plain_type (tree
);
120 static int template_name_p (tree
);
121 static void sdbout_record_type_name (tree
);
122 static int plain_type_1 (tree
, int);
123 static void sdbout_block (tree
);
124 static void sdbout_syms (tree
);
125 #ifdef SDB_ALLOW_FORWARD_REFERENCES
126 static void sdbout_queue_anonymous_type (tree
);
127 static void sdbout_dequeue_anonymous_types (void);
129 static void sdbout_type (tree
);
130 static void sdbout_field_types (tree
);
131 static void sdbout_one_type (tree
);
132 static void sdbout_parms (tree
);
133 static void sdbout_reg_parms (tree
);
134 static void sdbout_global_decl (tree
);
136 /* Random macros describing parts of SDB data. */
138 /* Default value of delimiter is ";". */
140 #define SDB_DELIM ";"
143 /* Maximum number of dimensions the assembler will allow. */
145 #define SDB_MAX_DIM 4
149 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
152 #ifndef PUT_SDB_INT_VAL
153 #define PUT_SDB_INT_VAL(a) \
155 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
156 (HOST_WIDE_INT) (a), SDB_DELIM); \
162 #define PUT_SDB_VAL(a) \
163 ( fputs ("\t.val\t", asm_out_file), \
164 output_addr_const (asm_out_file, (a)), \
165 fprintf (asm_out_file, SDB_DELIM))
169 #define PUT_SDB_DEF(a) \
170 do { fprintf (asm_out_file, "\t.def\t"); \
171 assemble_name (asm_out_file, a); \
172 fprintf (asm_out_file, SDB_DELIM); } while (0)
175 #ifndef PUT_SDB_PLAIN_DEF
176 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
179 #ifndef PUT_SDB_ENDEF
180 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
184 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
188 #define PUT_SDB_SIZE(a) \
190 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
191 (HOST_WIDE_INT) (a), SDB_DELIM); \
195 #ifndef PUT_SDB_START_DIM
196 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
199 #ifndef PUT_SDB_NEXT_DIM
200 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
203 #ifndef PUT_SDB_LAST_DIM
204 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
208 #define PUT_SDB_TAG(a) \
209 do { fprintf (asm_out_file, "\t.tag\t"); \
210 assemble_name (asm_out_file, a); \
211 fprintf (asm_out_file, SDB_DELIM); } while (0)
214 #ifndef PUT_SDB_BLOCK_START
215 #define PUT_SDB_BLOCK_START(LINE) \
216 fprintf (asm_out_file, \
217 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
218 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
221 #ifndef PUT_SDB_BLOCK_END
222 #define PUT_SDB_BLOCK_END(LINE) \
223 fprintf (asm_out_file, \
224 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
225 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
228 #ifndef PUT_SDB_FUNCTION_START
229 #define PUT_SDB_FUNCTION_START(LINE) \
230 fprintf (asm_out_file, \
231 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
232 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
235 #ifndef PUT_SDB_FUNCTION_END
236 #define PUT_SDB_FUNCTION_END(LINE) \
237 fprintf (asm_out_file, \
238 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
239 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
242 #ifndef SDB_GENERATE_FAKE
243 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
244 sprintf ((BUFFER), ".%dfake", (NUMBER));
247 /* Return the sdb tag identifier string for TYPE
248 if TYPE has already been defined; otherwise return a null pointer. */
250 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
252 /* Set the sdb tag identifier string for TYPE to NAME. */
254 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
255 TYPE_SYMTAB_POINTER (TYPE) = (char *)(NAME)
257 /* Return the name (a string) of the struct, union or enum tag
258 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
260 #define TAG_NAME(link) \
261 (((link) && TREE_PURPOSE ((link)) \
262 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
263 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
265 /* Ensure we don't output a negative line number. */
266 #define MAKE_LINE_SAFE(line) \
267 if ((int) line <= sdb_begin_function_line) \
268 line = sdb_begin_function_line + 1
270 /* Perform linker optimization of merging header file definitions together
271 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
272 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
273 the optimization just won't be done. The native assembler already has the
274 necessary support. */
276 #ifdef MIPS_DEBUGGING_INFO
278 #ifndef PUT_SDB_SRC_FILE
279 #define PUT_SDB_SRC_FILE(FILENAME) \
280 output_file_directive (asm_out_file, (FILENAME))
283 /* ECOFF linkers have an optimization that does the same kind of thing as
284 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
285 executable. To achieve this, GCC must output a .file for each file
288 /* This is a stack of input files. */
292 struct sdb_file
*next
;
296 /* This is the top of the stack. */
298 static struct sdb_file
*current_file
;
300 #endif /* MIPS_DEBUGGING_INFO */
302 /* The debug hooks structure. */
303 const struct gcc_debug_hooks sdb_debug_hooks
=
305 sdbout_init
, /* init */
306 sdbout_finish
, /* finish */
307 debug_nothing_int_charstar
, /* define */
308 debug_nothing_int_charstar
, /* undef */
309 sdbout_start_source_file
, /* start_source_file */
310 sdbout_end_source_file
, /* end_source_file */
311 sdbout_begin_block
, /* begin_block */
312 sdbout_end_block
, /* end_block */
313 debug_true_tree
, /* ignore_block */
314 sdbout_source_line
, /* source_line */
315 #ifdef MIPS_DEBUGGING_INFO
316 /* Defer on MIPS systems so that parameter descriptions follow
318 debug_nothing_int_charstar
, /* begin_prologue */
319 sdbout_end_prologue
, /* end_prologue */
321 sdbout_begin_prologue
, /* begin_prologue */
322 debug_nothing_int_charstar
, /* end_prologue */
324 sdbout_end_epilogue
, /* end_epilogue */
325 sdbout_begin_function
, /* begin_function */
326 sdbout_end_function
, /* end_function */
327 debug_nothing_tree
, /* function_decl */
328 sdbout_global_decl
, /* global_decl */
329 debug_nothing_tree
, /* deferred_inline_function */
330 debug_nothing_tree
, /* outlining_inline_function */
331 sdbout_label
, /* label */
332 debug_nothing_int
/* handle_pch */
335 /* Return a unique string to name an anonymous type. */
338 gen_fake_label (void)
342 SDB_GENERATE_FAKE (label
, unnamed_struct_number
);
343 unnamed_struct_number
++;
344 labelstr
= xstrdup (label
);
348 /* Return the number which describes TYPE for SDB.
349 For pointers, etc., this function is recursive.
350 Each record, union or enumeral type must already have had a
351 tag number output. */
353 /* The number is given by d6d5d4d3d2d1bbbb
354 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
355 Thus, char *foo () has bbbb=T_CHAR
358 N_BTMASK= 017 1111 basic type field.
359 N_TSHIFT= 2 derived type shift
360 N_BTSHFT= 4 Basic type shift */
362 /* Produce the number that describes a pointer, function or array type.
363 PREV is the number describing the target, value or element type.
364 DT_type describes how to transform that type. */
365 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
366 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
367 | ((int) DT_type << (int) N_BTSHFT) \
368 | ((PREV) & (int) N_BTMASK))
370 /* Number of elements used in sdb_dims. */
371 static int sdb_n_dims
= 0;
373 /* Table of array dimensions of current type. */
374 static int sdb_dims
[SDB_MAX_DIM
];
376 /* Size of outermost array currently being processed. */
377 static int sdb_type_size
= -1;
380 plain_type (tree type
)
382 int val
= plain_type_1 (type
, 0);
384 /* If we have already saved up some array dimensions, print them now. */
389 for (i
= sdb_n_dims
- 1; i
> 0; i
--)
390 PUT_SDB_NEXT_DIM (sdb_dims
[i
]);
391 PUT_SDB_LAST_DIM (sdb_dims
[0]);
394 sdb_type_size
= int_size_in_bytes (type
);
395 /* Don't kill sdb if type is not laid out or has variable size. */
396 if (sdb_type_size
< 0)
399 /* If we have computed the size of an array containing this type,
401 if (sdb_type_size
>= 0)
403 PUT_SDB_SIZE (sdb_type_size
);
410 template_name_p (tree name
)
412 const char *ptr
= IDENTIFIER_POINTER (name
);
413 while (*ptr
&& *ptr
!= '<')
420 sdbout_record_type_name (tree type
)
422 const char *name
= 0;
425 if (KNOWN_TYPE_TAG (type
))
428 if (TYPE_NAME (type
) != 0)
432 /* Find the IDENTIFIER_NODE for the type name. */
433 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
434 t
= TYPE_NAME (type
);
435 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
)
437 t
= DECL_NAME (TYPE_NAME (type
));
438 /* The DECL_NAME for templates includes "<>", which breaks
439 most assemblers. Use its assembler name instead, which
440 has been mangled into being safe. */
441 if (t
&& template_name_p (t
))
442 t
= DECL_ASSEMBLER_NAME (TYPE_NAME (type
));
445 /* Now get the name as a string, or invent one. */
447 name
= IDENTIFIER_POINTER (t
);
450 no_name
= (name
== 0 || *name
== 0);
452 name
= gen_fake_label ();
454 SET_KNOWN_TYPE_TAG (type
, name
);
455 #ifdef SDB_ALLOW_FORWARD_REFERENCES
457 sdbout_queue_anonymous_type (type
);
461 /* Return the .type value for type TYPE.
463 LEVEL indicates how many levels deep we have recursed into the type.
464 The SDB debug format can only represent 6 derived levels of types.
465 After that, we must output inaccurate debug info. We deliberately
466 stop before the 7th level, so that ADA recursive types will not give an
470 plain_type_1 (tree type
, int level
)
473 type
= void_type_node
;
474 else if (type
== error_mark_node
)
475 type
= integer_type_node
;
477 type
= TYPE_MAIN_VARIANT (type
);
479 switch (TREE_CODE (type
))
486 int size
= int_size_in_bytes (type
) * BITS_PER_UNIT
;
488 /* Carefully distinguish all the standard types of C,
489 without messing up if the language is not C.
490 Note that we check only for the names that contain spaces;
491 other names might occur by coincidence in other languages. */
492 if (TYPE_NAME (type
) != 0
493 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
494 && DECL_NAME (TYPE_NAME (type
)) != 0
495 && TREE_CODE (DECL_NAME (TYPE_NAME (type
))) == IDENTIFIER_NODE
)
497 const char *const name
498 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
500 if (!strcmp (name
, "char"))
502 if (!strcmp (name
, "unsigned char"))
504 if (!strcmp (name
, "signed char"))
506 if (!strcmp (name
, "int"))
508 if (!strcmp (name
, "unsigned int"))
510 if (!strcmp (name
, "short int"))
512 if (!strcmp (name
, "short unsigned int"))
514 if (!strcmp (name
, "long int"))
516 if (!strcmp (name
, "long unsigned int"))
520 if (size
== INT_TYPE_SIZE
)
521 return (TREE_UNSIGNED (type
) ? T_UINT
: T_INT
);
522 if (size
== CHAR_TYPE_SIZE
)
523 return (TREE_UNSIGNED (type
) ? T_UCHAR
: T_CHAR
);
524 if (size
== SHORT_TYPE_SIZE
)
525 return (TREE_UNSIGNED (type
) ? T_USHORT
: T_SHORT
);
526 if (size
== LONG_TYPE_SIZE
)
527 return (TREE_UNSIGNED (type
) ? T_ULONG
: T_LONG
);
528 if (size
== LONG_LONG_TYPE_SIZE
) /* better than nothing */
529 return (TREE_UNSIGNED (type
) ? T_ULONG
: T_LONG
);
535 int precision
= TYPE_PRECISION (type
);
536 if (precision
== FLOAT_TYPE_SIZE
)
538 if (precision
== DOUBLE_TYPE_SIZE
)
540 #ifdef EXTENDED_SDB_BASIC_TYPES
541 if (precision
== LONG_DOUBLE_TYPE_SIZE
)
544 if (precision
== LONG_DOUBLE_TYPE_SIZE
)
545 return T_DOUBLE
; /* better than nothing */
556 m
= plain_type_1 (TREE_TYPE (type
), level
+1);
557 if (sdb_n_dims
< SDB_MAX_DIM
)
558 sdb_dims
[sdb_n_dims
++]
559 = (TYPE_DOMAIN (type
)
560 && TYPE_MIN_VALUE (TYPE_DOMAIN (type
)) != 0
561 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != 0
562 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), 0)
563 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0)
564 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), 0)
565 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0) + 1)
568 return PUSH_DERIVED_LEVEL (DT_ARY
, m
);
573 case QUAL_UNION_TYPE
:
577 #ifdef SDB_ALLOW_FORWARD_REFERENCES
578 sdbout_record_type_name (type
);
580 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
581 if ((TREE_ASM_WRITTEN (type
) && KNOWN_TYPE_TAG (type
) != 0)
582 #ifdef SDB_ALLOW_FORWARD_REFERENCES
583 || TYPE_MODE (type
) != VOIDmode
588 /* Output the referenced structure tag name
589 only if the .def has already been finished.
590 At least on 386, the Unix assembler
591 cannot handle forward references to tags. */
592 /* But the 88100, it requires them, sigh... */
593 /* And the MIPS requires unknown refs as well... */
594 tag
= KNOWN_TYPE_TAG (type
);
596 /* These 3 lines used to follow the close brace.
597 However, a size of 0 without a tag implies a tag of 0,
598 so if we don't know a tag, we can't mention the size. */
599 sdb_type_size
= int_size_in_bytes (type
);
600 if (sdb_type_size
< 0)
603 return ((TREE_CODE (type
) == RECORD_TYPE
) ? T_STRUCT
604 : (TREE_CODE (type
) == UNION_TYPE
) ? T_UNION
605 : (TREE_CODE (type
) == QUAL_UNION_TYPE
) ? T_UNION
615 m
= plain_type_1 (TREE_TYPE (type
), level
+1);
616 return PUSH_DERIVED_LEVEL (DT_PTR
, m
);
625 m
= plain_type_1 (TREE_TYPE (type
), level
+1);
626 return PUSH_DERIVED_LEVEL (DT_FCN
, m
);
633 /* Output the symbols defined in block number DO_BLOCK.
635 This function works by walking the tree structure of blocks,
636 counting blocks until it finds the desired block. */
638 static int do_block
= 0;
641 sdbout_block (tree block
)
645 /* Ignore blocks never expanded or otherwise marked as real. */
646 if (TREE_USED (block
))
648 /* When we reach the specified block, output its symbols. */
649 if (BLOCK_NUMBER (block
) == do_block
)
650 sdbout_syms (BLOCK_VARS (block
));
652 /* If we are past the specified block, stop the scan. */
653 if (BLOCK_NUMBER (block
) > do_block
)
656 /* Scan the blocks within this block. */
657 sdbout_block (BLOCK_SUBBLOCKS (block
));
660 block
= BLOCK_CHAIN (block
);
664 /* Call sdbout_symbol on each decl in the chain SYMS. */
667 sdbout_syms (tree syms
)
671 if (TREE_CODE (syms
) != LABEL_DECL
)
672 sdbout_symbol (syms
, 1);
673 syms
= TREE_CHAIN (syms
);
677 /* Output SDB information for a symbol described by DECL.
678 LOCAL is nonzero if the symbol is not file-scope. */
681 sdbout_symbol (tree decl
, int local
)
683 tree type
= TREE_TYPE (decl
);
684 tree context
= NULL_TREE
;
689 sdbout_one_type (type
);
691 switch (TREE_CODE (decl
))
694 /* Enum values are defined by defining the enum type. */
698 /* Don't mention a nested function under its parent. */
699 context
= decl_function_context (decl
);
700 if (context
== current_function_decl
)
702 /* Check DECL_INITIAL to distinguish declarations from definitions.
703 Don't output debug info here for declarations; they will have
704 a DECL_INITIAL value of 0. */
705 if (! DECL_INITIAL (decl
))
707 if (GET_CODE (DECL_RTL (decl
)) != MEM
708 || GET_CODE (XEXP (DECL_RTL (decl
), 0)) != SYMBOL_REF
)
710 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
711 PUT_SDB_VAL (XEXP (DECL_RTL (decl
), 0));
712 PUT_SDB_SCL (TREE_PUBLIC (decl
) ? C_EXT
: C_STAT
);
716 /* Done with tagged types. */
717 if (DECL_NAME (decl
) == 0)
719 if (DECL_IGNORED_P (decl
))
722 /* Output typedef name. */
723 if (template_name_p (DECL_NAME (decl
)))
724 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
726 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl
)));
727 PUT_SDB_SCL (C_TPDEF
);
731 /* Parm decls go in their own separate chains
732 and are output by sdbout_reg_parms and sdbout_parms. */
736 /* Don't mention a variable that is external.
737 Let the file that defines it describe it. */
738 if (DECL_EXTERNAL (decl
))
741 /* Ignore __FUNCTION__, etc. */
742 if (DECL_IGNORED_P (decl
))
745 /* If there was an error in the declaration, don't dump core
746 if there is no RTL associated with the variable doesn't
748 if (!DECL_RTL_SET_P (decl
))
752 eliminate_regs (DECL_RTL (decl
), 0, NULL_RTX
));
753 #ifdef LEAF_REG_REMAP
754 if (current_function_uses_only_leaf_regs
)
755 leaf_renumber_regs_insn (DECL_RTL (decl
));
757 value
= DECL_RTL (decl
);
759 /* Don't mention a variable at all
760 if it was completely optimized into nothingness.
762 If DECL was from an inline function, then its rtl
763 is not identically the rtl that was used in this
764 particular compilation. */
765 if (GET_CODE (value
) == REG
)
767 regno
= REGNO (value
);
768 if (regno
>= FIRST_PSEUDO_REGISTER
)
771 else if (GET_CODE (value
) == SUBREG
)
773 while (GET_CODE (value
) == SUBREG
)
774 value
= SUBREG_REG (value
);
775 if (GET_CODE (value
) == REG
)
777 if (REGNO (value
) >= FIRST_PSEUDO_REGISTER
)
780 regno
= REGNO (alter_subreg (&value
));
781 SET_DECL_RTL (decl
, value
);
783 /* Don't output anything if an auto variable
784 gets RTL that is static.
785 GAS version 2.2 can't handle such output. */
786 else if (GET_CODE (value
) == MEM
&& CONSTANT_P (XEXP (value
, 0))
787 && ! TREE_STATIC (decl
))
790 /* Emit any structure, union, or enum type that has not been output.
791 This occurs for tag-less structs (et al) used to declare variables
793 if (TREE_CODE (type
) == ENUMERAL_TYPE
794 || TREE_CODE (type
) == RECORD_TYPE
795 || TREE_CODE (type
) == UNION_TYPE
796 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
798 if (COMPLETE_TYPE_P (type
) /* not a forward reference */
799 && KNOWN_TYPE_TAG (type
) == 0) /* not yet declared */
800 sdbout_one_type (type
);
803 /* Defer SDB information for top-level initialized variables! */
805 && GET_CODE (value
) == MEM
806 && DECL_INITIAL (decl
))
809 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
810 For now, avoid crashing. */
811 if (DECL_NAME (decl
) == NULL_TREE
)
814 /* Record the name for, starting a symtab entry. */
816 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
818 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
820 if (GET_CODE (value
) == MEM
821 && GET_CODE (XEXP (value
, 0)) == SYMBOL_REF
)
824 if (TREE_PUBLIC (decl
))
826 PUT_SDB_VAL (XEXP (value
, 0));
831 PUT_SDB_VAL (XEXP (value
, 0));
832 PUT_SDB_SCL (C_STAT
);
838 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno
));
841 else if (GET_CODE (value
) == MEM
842 && (GET_CODE (XEXP (value
, 0)) == MEM
843 || (GET_CODE (XEXP (value
, 0)) == REG
844 && REGNO (XEXP (value
, 0)) != HARD_FRAME_POINTER_REGNUM
845 && REGNO (XEXP (value
, 0)) != STACK_POINTER_REGNUM
)))
846 /* If the value is indirect by memory or by a register
847 that isn't the frame pointer
848 then it means the object is variable-sized and address through
849 that register or stack slot. COFF has no way to represent this
850 so all we can do is output the variable as a pointer. */
853 if (GET_CODE (XEXP (value
, 0)) == REG
)
855 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value
, 0))));
860 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
862 We want the value of that CONST_INT. */
863 /* Encore compiler hates a newline in a macro arg, it seems. */
864 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
865 (XEXP (XEXP (value
, 0), 0)));
866 PUT_SDB_SCL (C_AUTO
);
869 /* Effectively do build_pointer_type, but don't cache this type,
870 since it might be temporary whereas the type it points to
871 might have been saved for inlining. */
872 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
873 type
= make_node (POINTER_TYPE
);
874 TREE_TYPE (type
) = TREE_TYPE (decl
);
876 else if (GET_CODE (value
) == MEM
877 && ((GET_CODE (XEXP (value
, 0)) == PLUS
878 && GET_CODE (XEXP (XEXP (value
, 0), 0)) == REG
879 && GET_CODE (XEXP (XEXP (value
, 0), 1)) == CONST_INT
)
880 /* This is for variables which are at offset zero from
881 the frame pointer. This happens on the Alpha.
882 Non-frame pointer registers are excluded above. */
883 || (GET_CODE (XEXP (value
, 0)) == REG
)))
885 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
886 or (MEM (REG...)). We want the value of that CONST_INT
889 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value
, 0)));
890 PUT_SDB_SCL (C_AUTO
);
894 /* 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 (tree decl
)
912 tree type
= TREE_TYPE (decl
);
914 if (DECL_IGNORED_P (decl
))
917 if (! (TREE_CODE (decl
) == VAR_DECL
918 && GET_CODE (DECL_RTL (decl
)) == MEM
919 && DECL_INITIAL (decl
)))
922 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
923 PUT_SDB_VAL (XEXP (DECL_RTL (decl
), 0));
924 if (TREE_PUBLIC (decl
))
930 PUT_SDB_SCL (C_STAT
);
932 PUT_SDB_TYPE (plain_type (type
));
936 #ifdef SDB_ALLOW_FORWARD_REFERENCES
938 /* Machinery to record and output anonymous types. */
941 sdbout_queue_anonymous_type (tree type
)
943 anonymous_types
= tree_cons (NULL_TREE
, type
, anonymous_types
);
947 sdbout_dequeue_anonymous_types (void)
951 while (anonymous_types
)
953 types
= nreverse (anonymous_types
);
954 anonymous_types
= NULL_TREE
;
956 for (link
= types
; link
; link
= TREE_CHAIN (link
))
958 tree type
= TREE_VALUE (link
);
960 if (type
&& ! TREE_ASM_WRITTEN (type
))
961 sdbout_one_type (type
);
968 /* Given a chain of ..._TYPE nodes, all of which have names,
969 output definitions of those names, as typedefs. */
972 sdbout_types (tree types
)
976 for (link
= types
; link
; link
= TREE_CHAIN (link
))
977 sdbout_one_type (link
);
979 #ifdef SDB_ALLOW_FORWARD_REFERENCES
980 sdbout_dequeue_anonymous_types ();
985 sdbout_type (tree type
)
987 if (type
== error_mark_node
)
988 type
= integer_type_node
;
989 PUT_SDB_TYPE (plain_type (type
));
992 /* Output types of the fields of type TYPE, if they are structs.
994 Formerly did not chase through pointer types, since that could be circular.
995 They must come before TYPE, since forward refs are not allowed.
996 Now james@bigtex.cactus.org says to try them. */
999 sdbout_field_types (tree type
)
1003 for (tail
= TYPE_FIELDS (type
); tail
; tail
= TREE_CHAIN (tail
))
1004 /* This condition should match the one for emitting the actual
1006 if (TREE_CODE (tail
) == FIELD_DECL
1009 && host_integerp (DECL_SIZE (tail
), 1)
1010 && host_integerp (bit_position (tail
), 0))
1012 if (POINTER_TYPE_P (TREE_TYPE (tail
)))
1013 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail
)));
1015 sdbout_one_type (TREE_TYPE (tail
));
1019 /* Use this to put out the top level defined record and union types
1020 for later reference. If this is a struct with a name, then put that
1021 name out. Other unnamed structs will have .xxfake labels generated so
1022 that they may be referred to later.
1023 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1024 It may NOT be called recursively. */
1027 sdbout_one_type (tree type
)
1029 if (current_function_decl
!= NULL_TREE
1030 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
1031 ; /* Don't change section amid function. */
1035 switch (TREE_CODE (type
))
1039 case QUAL_UNION_TYPE
:
1041 type
= TYPE_MAIN_VARIANT (type
);
1042 /* Don't output a type twice. */
1043 if (TREE_ASM_WRITTEN (type
))
1044 /* James said test TREE_ASM_BEING_WRITTEN here. */
1047 /* Output nothing if type is not yet defined. */
1048 if (!COMPLETE_TYPE_P (type
))
1051 TREE_ASM_WRITTEN (type
) = 1;
1053 /* This is reputed to cause trouble with the following case,
1054 but perhaps checking TYPE_SIZE above will fix it. */
1056 /* Here is a test case:
1062 typedef struct intermediate {
1066 typedef struct badstr {
1070 /* This change, which ought to make better output,
1071 used to make the COFF assembler unhappy.
1072 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1073 /* Before really doing anything, output types we want to refer to. */
1074 /* Note that in version 1 the following two lines
1075 are not used if forward references are in use. */
1076 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
1077 sdbout_field_types (type
);
1079 /* Output a structure type. */
1081 int size
= int_size_in_bytes (type
);
1084 int i
, n_baseclasses
= 0;
1086 /* Record the type tag, but not in its permanent place just yet. */
1087 sdbout_record_type_name (type
);
1089 PUT_SDB_DEF (KNOWN_TYPE_TAG (type
));
1091 switch (TREE_CODE (type
))
1094 case QUAL_UNION_TYPE
:
1095 PUT_SDB_SCL (C_UNTAG
);
1096 PUT_SDB_TYPE (T_UNION
);
1101 PUT_SDB_SCL (C_STRTAG
);
1102 PUT_SDB_TYPE (T_STRUCT
);
1107 PUT_SDB_SCL (C_ENTAG
);
1108 PUT_SDB_TYPE (T_ENUM
);
1116 PUT_SDB_SIZE (size
);
1119 /* Print out the base class information with fields
1120 named after the types they hold. */
1121 /* This is only relevant to aggregate types. TYPE_BINFO is used
1122 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1124 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
1126 if (TYPE_BINFO (type
)
1127 && TYPE_BINFO_BASETYPES (type
))
1128 n_baseclasses
= TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type
));
1129 for (i
= 0; i
< n_baseclasses
; i
++)
1131 tree child
= TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type
)),
1133 tree child_type
= BINFO_TYPE (child
);
1134 tree child_type_name
;
1135 if (TYPE_NAME (child_type
) == 0)
1137 if (TREE_CODE (TYPE_NAME (child_type
)) == IDENTIFIER_NODE
)
1138 child_type_name
= TYPE_NAME (child_type
);
1139 else if (TREE_CODE (TYPE_NAME (child_type
)) == TYPE_DECL
)
1141 child_type_name
= DECL_NAME (TYPE_NAME (child_type
));
1142 if (child_type_name
&& template_name_p (child_type_name
))
1144 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type
));
1149 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name
));
1150 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child
), 0));
1151 PUT_SDB_SCL (member_scl
);
1152 sdbout_type (BINFO_TYPE (child
));
1157 /* output the individual fields */
1159 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1161 for (tem
= TYPE_FIELDS (type
); tem
; tem
= TREE_CHAIN (tem
))
1162 if (host_integerp (TREE_VALUE (tem
), 0))
1164 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem
)));
1165 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem
), 0));
1166 PUT_SDB_SCL (C_MOE
);
1167 PUT_SDB_TYPE (T_MOE
);
1171 else /* record or union type */
1172 for (tem
= TYPE_FIELDS (type
); tem
; tem
= TREE_CHAIN (tem
))
1173 /* Output the name, type, position (in bits), size (in bits)
1176 /* Omit here the nameless fields that are used to skip bits.
1177 Also omit fields with variable size or position.
1178 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1179 if (TREE_CODE (tem
) == FIELD_DECL
1182 && host_integerp (DECL_SIZE (tem
), 1)
1183 && host_integerp (bit_position (tem
), 0))
1187 name
= IDENTIFIER_POINTER (DECL_NAME (tem
));
1189 if (DECL_BIT_FIELD_TYPE (tem
))
1191 PUT_SDB_INT_VAL (int_bit_position (tem
));
1192 PUT_SDB_SCL (C_FIELD
);
1193 sdbout_type (DECL_BIT_FIELD_TYPE (tem
));
1194 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem
), 1));
1198 PUT_SDB_INT_VAL (int_bit_position (tem
) / BITS_PER_UNIT
);
1199 PUT_SDB_SCL (member_scl
);
1200 sdbout_type (TREE_TYPE (tem
));
1204 /* output end of a structure,union, or enumeral definition */
1206 PUT_SDB_PLAIN_DEF ("eos");
1207 PUT_SDB_INT_VAL (size
);
1208 PUT_SDB_SCL (C_EOS
);
1209 PUT_SDB_TAG (KNOWN_TYPE_TAG (type
));
1210 PUT_SDB_SIZE (size
);
1220 /* The following two functions output definitions of function parameters.
1221 Each parameter gets a definition locating it in the parameter list.
1222 Each parameter that is a register variable gets a second definition
1223 locating it in the register.
1225 Printing or argument lists in gdb uses the definitions that
1226 locate in the parameter list. But reference to the variable in
1227 expressions uses preferentially the definition as a register. */
1229 /* Output definitions, referring to storage in the parmlist,
1230 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1233 sdbout_parms (tree parms
)
1235 for (; parms
; parms
= TREE_CHAIN (parms
))
1236 if (DECL_NAME (parms
))
1238 int current_sym_value
= 0;
1239 const char *name
= IDENTIFIER_POINTER (DECL_NAME (parms
));
1241 if (name
== 0 || *name
== 0)
1242 name
= gen_fake_label ();
1244 /* Perform any necessary register eliminations on the parameter's rtl,
1245 so that the debugging output will be accurate. */
1246 DECL_INCOMING_RTL (parms
)
1247 = eliminate_regs (DECL_INCOMING_RTL (parms
), 0, NULL_RTX
);
1248 SET_DECL_RTL (parms
,
1249 eliminate_regs (DECL_RTL (parms
), 0, NULL_RTX
));
1251 if (PARM_PASSED_IN_MEMORY (parms
))
1253 rtx addr
= XEXP (DECL_INCOMING_RTL (parms
), 0);
1256 /* ??? Here we assume that the parm address is indexed
1257 off the frame pointer or arg pointer.
1258 If that is not true, we produce meaningless results,
1259 but do not crash. */
1260 if (GET_CODE (addr
) == PLUS
1261 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
1262 current_sym_value
= INTVAL (XEXP (addr
, 1));
1264 current_sym_value
= 0;
1266 if (GET_CODE (DECL_RTL (parms
)) == REG
1267 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
)
1268 type
= DECL_ARG_TYPE (parms
);
1271 int original_sym_value
= current_sym_value
;
1273 /* This is the case where the parm is passed as an int or
1274 double and it is converted to a char, short or float
1275 and stored back in the parmlist. In this case, describe
1276 the parm with the variable's declared type, and adjust
1277 the address if the least significant bytes (which we are
1278 using) are not the first ones. */
1279 if (BYTES_BIG_ENDIAN
1280 && TREE_TYPE (parms
) != DECL_ARG_TYPE (parms
))
1281 current_sym_value
+=
1282 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms
)))
1283 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms
))));
1285 if (GET_CODE (DECL_RTL (parms
)) == MEM
1286 && GET_CODE (XEXP (DECL_RTL (parms
), 0)) == PLUS
1287 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms
), 0), 1))
1289 && (INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1))
1290 == current_sym_value
))
1291 type
= TREE_TYPE (parms
);
1294 current_sym_value
= original_sym_value
;
1295 type
= DECL_ARG_TYPE (parms
);
1300 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value
, addr
));
1301 PUT_SDB_SCL (C_ARG
);
1302 PUT_SDB_TYPE (plain_type (type
));
1305 else if (GET_CODE (DECL_RTL (parms
)) == REG
)
1308 /* Parm passed in registers and lives in registers or nowhere. */
1310 /* If parm lives in a register, use that register;
1311 pretend the parm was passed there. It would be more consistent
1312 to describe the register where the parm was passed,
1313 but in practice that register usually holds something else. */
1314 if (REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
)
1315 best_rtl
= DECL_RTL (parms
);
1316 /* If the parm lives nowhere,
1317 use the register where it was passed. */
1319 best_rtl
= DECL_INCOMING_RTL (parms
);
1322 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl
)));
1323 PUT_SDB_SCL (C_REGPARM
);
1324 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1327 else if (GET_CODE (DECL_RTL (parms
)) == MEM
1328 && XEXP (DECL_RTL (parms
), 0) != const0_rtx
)
1330 /* Parm was passed in registers but lives on the stack. */
1332 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1333 in which case we want the value of that CONST_INT,
1334 or (MEM (REG ...)) or (MEM (MEM ...)),
1335 in which case we use a value of zero. */
1336 if (GET_CODE (XEXP (DECL_RTL (parms
), 0)) == REG
1337 || GET_CODE (XEXP (DECL_RTL (parms
), 0)) == MEM
)
1338 current_sym_value
= 0;
1340 current_sym_value
= INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1));
1342 /* Again, this assumes the offset is based on the arg pointer. */
1344 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value
,
1345 XEXP (DECL_RTL (parms
), 0)));
1346 PUT_SDB_SCL (C_ARG
);
1347 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1353 /* Output definitions for the places where parms live during the function,
1354 when different from where they were passed, when the parms were passed
1357 It is not useful to do this for parms passed in registers
1358 that live during the function in different registers, because it is
1359 impossible to look in the passed register for the passed value,
1360 so we use the within-the-function register to begin with.
1362 PARMS is a chain of PARM_DECL nodes. */
1365 sdbout_reg_parms (tree parms
)
1367 for (; parms
; parms
= TREE_CHAIN (parms
))
1368 if (DECL_NAME (parms
))
1370 const char *name
= IDENTIFIER_POINTER (DECL_NAME (parms
));
1372 /* Report parms that live in registers during the function
1373 but were passed in memory. */
1374 if (GET_CODE (DECL_RTL (parms
)) == REG
1375 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
1376 && PARM_PASSED_IN_MEMORY (parms
))
1378 if (name
== 0 || *name
== 0)
1379 name
= gen_fake_label ();
1381 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms
))));
1382 PUT_SDB_SCL (C_REG
);
1383 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1386 /* Report parms that live in memory but not where they were passed. */
1387 else if (GET_CODE (DECL_RTL (parms
)) == MEM
1388 && GET_CODE (XEXP (DECL_RTL (parms
), 0)) == PLUS
1389 && GET_CODE (XEXP (XEXP (DECL_RTL (parms
), 0), 1)) == CONST_INT
1390 && PARM_PASSED_IN_MEMORY (parms
)
1391 && ! rtx_equal_p (DECL_RTL (parms
), DECL_INCOMING_RTL (parms
)))
1393 #if 0 /* ??? It is not clear yet what should replace this. */
1394 int offset
= DECL_OFFSET (parms
) / BITS_PER_UNIT
;
1395 /* A parm declared char is really passed as an int,
1396 so it occupies the least significant bytes.
1397 On a big-endian machine those are not the low-numbered ones. */
1398 if (BYTES_BIG_ENDIAN
1400 && TREE_TYPE (parms
) != DECL_ARG_TYPE (parms
))
1401 offset
+= (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms
)))
1402 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms
))));
1403 if (INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1)) != offset
) {...}
1406 if (name
== 0 || *name
== 0)
1407 name
= gen_fake_label ();
1409 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1410 (XEXP (DECL_RTL (parms
), 0)));
1411 PUT_SDB_SCL (C_AUTO
);
1412 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1419 /* Output debug information for a global DECL. Called from toplev.c
1420 after compilation proper has finished. */
1423 sdbout_global_decl (tree decl
)
1425 if (TREE_CODE (decl
) == VAR_DECL
1426 && !DECL_EXTERNAL (decl
)
1427 && DECL_RTL_SET_P (decl
))
1429 /* The COFF linker can move initialized global vars to the end.
1430 And that can screw up the symbol ordering. Defer those for
1431 sdbout_finish (). */
1432 if (!DECL_INITIAL (decl
) || !TREE_PUBLIC (decl
))
1433 sdbout_symbol (decl
, 0);
1435 /* Output COFF information for non-global file-scope initialized
1437 if (DECL_INITIAL (decl
) && GET_CODE (DECL_RTL (decl
)) == MEM
)
1438 sdbout_toplevel_data (decl
);
1442 /* Output initialized global vars at the end, in the order of
1443 definition. See comment in sdbout_global_decl. */
1446 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED
)
1448 tree decl
= (*lang_hooks
.decls
.getdecls
) ();
1449 unsigned int len
= list_length (decl
);
1450 tree
*vec
= (tree
*) xmalloc (sizeof (tree
) * len
);
1453 /* Process the decls in reverse order--earliest first. Put them
1454 into VEC from back to front, then take out from front. */
1456 for (i
= 0; i
< len
; i
++, decl
= TREE_CHAIN (decl
))
1457 vec
[len
- i
- 1] = decl
;
1459 for (i
= 0; i
< len
; i
++)
1462 if (TREE_CODE (decl
) == VAR_DECL
1463 && ! DECL_EXTERNAL (decl
)
1464 && DECL_INITIAL (decl
)
1465 && TREE_PUBLIC (decl
)
1466 && DECL_RTL_SET_P (decl
))
1467 sdbout_symbol (decl
, 0);
1473 /* Describe the beginning of an internal block within a function.
1474 Also output descriptions of variables defined in this block.
1476 N is the number of the block, by order of beginning, counting from 1,
1477 and not counting the outermost (function top-level) block.
1478 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1479 if the count starts at 0 for the outermost one. */
1482 sdbout_begin_block (unsigned int line
, unsigned int n
)
1484 tree decl
= current_function_decl
;
1485 MAKE_LINE_SAFE (line
);
1487 /* The SCO compiler does not emit a separate block for the function level
1488 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1489 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1490 #ifndef MIPS_DEBUGGING_INFO
1493 PUT_SDB_BLOCK_START (line
- sdb_begin_function_line
);
1497 /* Include the outermost BLOCK's variables in block 1. */
1498 do_block
= BLOCK_NUMBER (DECL_INITIAL (decl
));
1499 sdbout_block (DECL_INITIAL (decl
));
1501 /* If -g1, suppress all the internal symbols of functions
1502 except for arguments. */
1503 if (debug_info_level
!= DINFO_LEVEL_TERSE
)
1506 sdbout_block (DECL_INITIAL (decl
));
1509 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1510 sdbout_dequeue_anonymous_types ();
1514 /* Describe the end line-number of an internal block within a function. */
1517 sdbout_end_block (unsigned int line
, unsigned int n ATTRIBUTE_UNUSED
)
1519 MAKE_LINE_SAFE (line
);
1521 /* The SCO compiler does not emit a separate block for the function level
1522 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1523 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1524 #ifndef MIPS_DEBUGGING_INFO
1527 PUT_SDB_BLOCK_END (line
- sdb_begin_function_line
);
1531 sdbout_source_line (line
, filename
)
1533 const char *filename ATTRIBUTE_UNUSED
;
1535 /* COFF relative line numbers must be positive. */
1536 if ((int) line
> sdb_begin_function_line
)
1538 #ifdef ASM_OUTPUT_SOURCE_LINE
1539 ASM_OUTPUT_SOURCE_LINE (asm_out_file
, line
);
1541 fprintf (asm_out_file
, "\t.ln\t%d\n",
1542 ((sdb_begin_function_line
> -1)
1543 ? line
- sdb_begin_function_line
: 1));
1548 /* Output sdb info for the current function name.
1549 Called from assemble_start_function. */
1552 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED
)
1554 sdbout_symbol (current_function_decl
, 0);
1557 /* Called at beginning of function body (before or after prologue,
1558 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1559 line number, so we can output relative line numbers for the other
1560 lines. Describe beginning of outermost block. Also describe the
1563 #ifndef MIPS_DEBUGGING_INFO
1565 sdbout_begin_prologue (unsigned int line
, const char *file ATTRIBUTE_UNUSED
)
1567 sdbout_end_prologue (line
, file
);
1572 sdbout_end_prologue (line
, file
)
1574 const char *file ATTRIBUTE_UNUSED
;
1576 sdb_begin_function_line
= line
- 1;
1577 PUT_SDB_FUNCTION_START (line
);
1578 sdbout_parms (DECL_ARGUMENTS (current_function_decl
));
1579 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl
));
1582 /* Called at end of function (before epilogue).
1583 Describe end of outermost block. */
1586 sdbout_end_function (unsigned int line
)
1588 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1589 sdbout_dequeue_anonymous_types ();
1592 MAKE_LINE_SAFE (line
);
1593 PUT_SDB_FUNCTION_END (line
- sdb_begin_function_line
);
1595 /* Indicate we are between functions, for line-number output. */
1596 sdb_begin_function_line
= -1;
1599 /* Output sdb info for the absolute end of a function.
1600 Called after the epilogue is output. */
1603 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1604 const char *file ATTRIBUTE_UNUSED
)
1606 const char *const name ATTRIBUTE_UNUSED
1607 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl
));
1609 #ifdef PUT_SDB_EPILOGUE_END
1610 PUT_SDB_EPILOGUE_END (name
);
1612 fprintf (asm_out_file
, "\t.def\t");
1613 assemble_name (asm_out_file
, name
);
1614 fprintf (asm_out_file
, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1615 SDB_DELIM
, SDB_DELIM
, SDB_DELIM
);
1619 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1623 sdbout_label (rtx insn
)
1625 PUT_SDB_DEF (LABEL_NAME (insn
));
1627 PUT_SDB_SCL (C_LABEL
);
1628 PUT_SDB_TYPE (T_NULL
);
1632 /* Change to reading from a new source file. */
1635 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED
,
1636 const char *filename ATTRIBUTE_UNUSED
)
1638 #ifdef MIPS_DEBUGGING_INFO
1639 struct sdb_file
*n
= (struct sdb_file
*) xmalloc (sizeof *n
);
1641 n
->next
= current_file
;
1644 PUT_SDB_SRC_FILE (filename
);
1648 /* Revert to reading a previous source file. */
1651 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED
)
1653 #ifdef MIPS_DEBUGGING_INFO
1654 struct sdb_file
*next
;
1656 next
= current_file
->next
;
1657 free (current_file
);
1658 current_file
= next
;
1659 PUT_SDB_SRC_FILE (current_file
->name
);
1663 /* Set up for SDB output at the start of compilation. */
1666 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED
)
1668 #ifdef MIPS_DEBUGGING_INFO
1669 current_file
= (struct sdb_file
*) xmalloc (sizeof *current_file
);
1670 current_file
->next
= NULL
;
1671 current_file
->name
= input_file_name
;
1675 #else /* SDB_DEBUGGING_INFO */
1677 /* This should never be used, but its address is needed for comparisons. */
1678 const struct gcc_debug_hooks sdb_debug_hooks
;
1680 #endif /* SDB_DEBUGGING_INFO */
1682 #include "gt-sdbout.h"