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, 2004, 2005, 2007, 2008
4 Free Software Foundation, Inc.
6 This file is part of GCC.
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3. If not see
20 <http://www.gnu.org/licenses/>. */
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"
53 static GTY(()) tree anonymous_types
;
55 /* Counter to generate unique "names" for nameless struct members. */
57 static GTY(()) int unnamed_struct_number
;
59 /* Declarations whose debug info was deferred till end of compilation. */
61 static GTY(()) varray_type deferred_global_decls
;
63 /* The C front end may call sdbout_symbol before sdbout_init runs.
64 We save all such decls in this list and output them when we get
67 static GTY(()) tree preinit_symbols
;
68 static GTY(()) bool sdbout_initialized
;
70 #ifdef SDB_DEBUGGING_INFO
75 #include "insn-config.h"
81 #include "langhooks.h"
84 /* 1 if PARM is passed to this function in memory. */
86 #define PARM_PASSED_IN_MEMORY(PARM) \
87 (MEM_P (DECL_INCOMING_RTL (PARM)))
89 /* A C expression for the integer offset value of an automatic variable
90 (C_AUTO) having address X (an RTX). */
91 #ifndef DEBUGGER_AUTO_OFFSET
92 #define DEBUGGER_AUTO_OFFSET(X) \
93 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
96 /* A C expression for the integer offset value of an argument (C_ARG)
97 having address X (an RTX). The nominal offset is OFFSET. */
98 #ifndef DEBUGGER_ARG_OFFSET
99 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
102 /* Line number of beginning of current function, minus one.
103 Negative means not in a function or not using sdb. */
105 int sdb_begin_function_line
= -1;
108 extern FILE *asm_out_file
;
110 extern tree current_function_decl
;
114 static void sdbout_init (const char *);
115 static void sdbout_finish (const char *);
116 static void sdbout_start_source_file (unsigned int, const char *);
117 static void sdbout_end_source_file (unsigned int);
118 static void sdbout_begin_block (unsigned int, unsigned int);
119 static void sdbout_end_block (unsigned int, unsigned int);
120 static void sdbout_source_line (unsigned int, const char *);
121 static void sdbout_end_epilogue (unsigned int, const char *);
122 static void sdbout_global_decl (tree
);
123 #ifndef MIPS_DEBUGGING_INFO
124 static void sdbout_begin_prologue (unsigned int, const char *);
126 static void sdbout_end_prologue (unsigned int, const char *);
127 static void sdbout_begin_function (tree
);
128 static void sdbout_end_function (unsigned int);
129 static void sdbout_toplevel_data (tree
);
130 static void sdbout_label (rtx
);
131 static char *gen_fake_label (void);
132 static int plain_type (tree
);
133 static int template_name_p (tree
);
134 static void sdbout_record_type_name (tree
);
135 static int plain_type_1 (tree
, int);
136 static void sdbout_block (tree
);
137 static void sdbout_syms (tree
);
138 #ifdef SDB_ALLOW_FORWARD_REFERENCES
139 static void sdbout_queue_anonymous_type (tree
);
140 static void sdbout_dequeue_anonymous_types (void);
142 static void sdbout_type (tree
);
143 static void sdbout_field_types (tree
);
144 static void sdbout_one_type (tree
);
145 static void sdbout_parms (tree
);
146 static void sdbout_reg_parms (tree
);
147 static void sdbout_global_decl (tree
);
149 /* Random macros describing parts of SDB data. */
151 /* Default value of delimiter is ";". */
153 #define SDB_DELIM ";"
156 /* Maximum number of dimensions the assembler will allow. */
158 #define SDB_MAX_DIM 4
162 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
165 #ifndef PUT_SDB_INT_VAL
166 #define PUT_SDB_INT_VAL(a) \
168 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
169 (HOST_WIDE_INT) (a), SDB_DELIM); \
175 #define PUT_SDB_VAL(a) \
176 ( fputs ("\t.val\t", asm_out_file), \
177 output_addr_const (asm_out_file, (a)), \
178 fprintf (asm_out_file, SDB_DELIM))
182 #define PUT_SDB_DEF(a) \
183 do { fprintf (asm_out_file, "\t.def\t"); \
184 assemble_name (asm_out_file, a); \
185 fprintf (asm_out_file, SDB_DELIM); } while (0)
188 #ifndef PUT_SDB_PLAIN_DEF
189 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
192 #ifndef PUT_SDB_ENDEF
193 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
197 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
201 #define PUT_SDB_SIZE(a) \
203 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
204 (HOST_WIDE_INT) (a), SDB_DELIM); \
208 #ifndef PUT_SDB_START_DIM
209 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
212 #ifndef PUT_SDB_NEXT_DIM
213 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
216 #ifndef PUT_SDB_LAST_DIM
217 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
221 #define PUT_SDB_TAG(a) \
222 do { fprintf (asm_out_file, "\t.tag\t"); \
223 assemble_name (asm_out_file, a); \
224 fprintf (asm_out_file, SDB_DELIM); } while (0)
227 #ifndef PUT_SDB_BLOCK_START
228 #define PUT_SDB_BLOCK_START(LINE) \
229 fprintf (asm_out_file, \
230 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
231 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
234 #ifndef PUT_SDB_BLOCK_END
235 #define PUT_SDB_BLOCK_END(LINE) \
236 fprintf (asm_out_file, \
237 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
238 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
241 #ifndef PUT_SDB_FUNCTION_START
242 #define PUT_SDB_FUNCTION_START(LINE) \
243 fprintf (asm_out_file, \
244 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
245 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
248 #ifndef PUT_SDB_FUNCTION_END
249 #define PUT_SDB_FUNCTION_END(LINE) \
250 fprintf (asm_out_file, \
251 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
252 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
255 /* Return the sdb tag identifier string for TYPE
256 if TYPE has already been defined; otherwise return a null pointer. */
258 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
260 /* Set the sdb tag identifier string for TYPE to NAME. */
262 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
263 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
265 /* Return the name (a string) of the struct, union or enum tag
266 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
268 #define TAG_NAME(link) \
269 (((link) && TREE_PURPOSE ((link)) \
270 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
271 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
273 /* Ensure we don't output a negative line number. */
274 #define MAKE_LINE_SAFE(line) \
275 if ((int) line <= sdb_begin_function_line) \
276 line = sdb_begin_function_line + 1
278 /* Perform linker optimization of merging header file definitions together
279 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
280 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
281 the optimization just won't be done. The native assembler already has the
282 necessary support. */
284 #ifdef MIPS_DEBUGGING_INFO
286 /* ECOFF linkers have an optimization that does the same kind of thing as
287 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
288 executable. To achieve this, GCC must output a .file for each file
291 /* This is a stack of input files. */
295 struct sdb_file
*next
;
299 /* This is the top of the stack. */
301 static struct sdb_file
*current_file
;
303 #endif /* MIPS_DEBUGGING_INFO */
305 /* The debug hooks structure. */
306 const struct gcc_debug_hooks sdb_debug_hooks
=
308 sdbout_init
, /* init */
309 sdbout_finish
, /* finish */
310 debug_nothing_int_charstar
, /* define */
311 debug_nothing_int_charstar
, /* undef */
312 sdbout_start_source_file
, /* start_source_file */
313 sdbout_end_source_file
, /* end_source_file */
314 sdbout_begin_block
, /* begin_block */
315 sdbout_end_block
, /* end_block */
316 debug_true_const_tree
, /* ignore_block */
317 sdbout_source_line
, /* source_line */
318 #ifdef MIPS_DEBUGGING_INFO
319 /* Defer on MIPS systems so that parameter descriptions follow
321 debug_nothing_int_charstar
, /* begin_prologue */
322 sdbout_end_prologue
, /* end_prologue */
324 sdbout_begin_prologue
, /* begin_prologue */
325 debug_nothing_int_charstar
, /* end_prologue */
327 sdbout_end_epilogue
, /* end_epilogue */
328 sdbout_begin_function
, /* begin_function */
329 sdbout_end_function
, /* end_function */
330 debug_nothing_tree
, /* function_decl */
331 sdbout_global_decl
, /* global_decl */
332 sdbout_symbol
, /* type_decl */
333 debug_nothing_tree_tree_tree_bool
, /* imported_module_or_decl */
334 debug_nothing_tree
, /* deferred_inline_function */
335 debug_nothing_tree
, /* outlining_inline_function */
336 sdbout_label
, /* label */
337 debug_nothing_int
, /* handle_pch */
338 debug_nothing_rtx
, /* var_location */
339 debug_nothing_void
, /* switch_text_section */
340 0 /* start_end_main_source_file */
343 /* Return a unique string to name an anonymous type. */
346 gen_fake_label (void)
350 sprintf (label
, ".%dfake", unnamed_struct_number
);
351 unnamed_struct_number
++;
352 labelstr
= xstrdup (label
);
356 /* Return the number which describes TYPE for SDB.
357 For pointers, etc., this function is recursive.
358 Each record, union or enumeral type must already have had a
359 tag number output. */
361 /* The number is given by d6d5d4d3d2d1bbbb
362 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
363 Thus, char *foo () has bbbb=T_CHAR
366 N_BTMASK= 017 1111 basic type field.
367 N_TSHIFT= 2 derived type shift
368 N_BTSHFT= 4 Basic type shift */
370 /* Produce the number that describes a pointer, function or array type.
371 PREV is the number describing the target, value or element type.
372 DT_type describes how to transform that type. */
373 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
374 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
375 | ((int) DT_type << (int) N_BTSHFT) \
376 | ((PREV) & (int) N_BTMASK))
378 /* Number of elements used in sdb_dims. */
379 static int sdb_n_dims
= 0;
381 /* Table of array dimensions of current type. */
382 static int sdb_dims
[SDB_MAX_DIM
];
384 /* Size of outermost array currently being processed. */
385 static int sdb_type_size
= -1;
388 plain_type (tree type
)
390 int val
= plain_type_1 (type
, 0);
392 /* If we have already saved up some array dimensions, print them now. */
397 for (i
= sdb_n_dims
- 1; i
> 0; i
--)
398 PUT_SDB_NEXT_DIM (sdb_dims
[i
]);
399 PUT_SDB_LAST_DIM (sdb_dims
[0]);
402 sdb_type_size
= int_size_in_bytes (type
);
403 /* Don't kill sdb if type is not laid out or has variable size. */
404 if (sdb_type_size
< 0)
407 /* If we have computed the size of an array containing this type,
409 if (sdb_type_size
>= 0)
411 PUT_SDB_SIZE (sdb_type_size
);
418 template_name_p (tree name
)
420 const char *ptr
= IDENTIFIER_POINTER (name
);
421 while (*ptr
&& *ptr
!= '<')
428 sdbout_record_type_name (tree type
)
430 const char *name
= 0;
433 if (KNOWN_TYPE_TAG (type
))
436 if (TYPE_NAME (type
) != 0)
440 /* Find the IDENTIFIER_NODE for the type name. */
441 if (TREE_CODE (TYPE_NAME (type
)) == IDENTIFIER_NODE
)
442 t
= TYPE_NAME (type
);
443 else if (TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
)
445 t
= DECL_NAME (TYPE_NAME (type
));
446 /* The DECL_NAME for templates includes "<>", which breaks
447 most assemblers. Use its assembler name instead, which
448 has been mangled into being safe. */
449 if (t
&& template_name_p (t
))
450 t
= DECL_ASSEMBLER_NAME (TYPE_NAME (type
));
453 /* Now get the name as a string, or invent one. */
455 name
= IDENTIFIER_POINTER (t
);
458 no_name
= (name
== 0 || *name
== 0);
460 name
= gen_fake_label ();
462 SET_KNOWN_TYPE_TAG (type
, name
);
463 #ifdef SDB_ALLOW_FORWARD_REFERENCES
465 sdbout_queue_anonymous_type (type
);
469 /* Return the .type value for type TYPE.
471 LEVEL indicates how many levels deep we have recursed into the type.
472 The SDB debug format can only represent 6 derived levels of types.
473 After that, we must output inaccurate debug info. We deliberately
474 stop before the 7th level, so that ADA recursive types will not give an
478 plain_type_1 (tree type
, int level
)
481 type
= void_type_node
;
482 else if (type
== error_mark_node
)
483 type
= integer_type_node
;
485 type
= TYPE_MAIN_VARIANT (type
);
487 switch (TREE_CODE (type
))
494 int size
= int_size_in_bytes (type
) * BITS_PER_UNIT
;
496 /* Carefully distinguish all the standard types of C,
497 without messing up if the language is not C.
498 Note that we check only for the names that contain spaces;
499 other names might occur by coincidence in other languages. */
500 if (TYPE_NAME (type
) != 0
501 && TREE_CODE (TYPE_NAME (type
)) == TYPE_DECL
502 && DECL_NAME (TYPE_NAME (type
)) != 0
503 && TREE_CODE (DECL_NAME (TYPE_NAME (type
))) == IDENTIFIER_NODE
)
505 const char *const name
506 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type
)));
508 if (!strcmp (name
, "char"))
510 if (!strcmp (name
, "unsigned char"))
512 if (!strcmp (name
, "signed char"))
514 if (!strcmp (name
, "int"))
516 if (!strcmp (name
, "unsigned int"))
518 if (!strcmp (name
, "short int"))
520 if (!strcmp (name
, "short unsigned int"))
522 if (!strcmp (name
, "long int"))
524 if (!strcmp (name
, "long unsigned int"))
528 if (size
== INT_TYPE_SIZE
)
529 return (TYPE_UNSIGNED (type
) ? T_UINT
: T_INT
);
530 if (size
== CHAR_TYPE_SIZE
)
531 return (TYPE_UNSIGNED (type
) ? T_UCHAR
: T_CHAR
);
532 if (size
== SHORT_TYPE_SIZE
)
533 return (TYPE_UNSIGNED (type
) ? T_USHORT
: T_SHORT
);
534 if (size
== LONG_TYPE_SIZE
)
535 return (TYPE_UNSIGNED (type
) ? T_ULONG
: T_LONG
);
536 if (size
== LONG_LONG_TYPE_SIZE
) /* better than nothing */
537 return (TYPE_UNSIGNED (type
) ? T_ULONG
: T_LONG
);
543 int precision
= TYPE_PRECISION (type
);
544 if (precision
== FLOAT_TYPE_SIZE
)
546 if (precision
== DOUBLE_TYPE_SIZE
)
548 #ifdef EXTENDED_SDB_BASIC_TYPES
549 if (precision
== LONG_DOUBLE_TYPE_SIZE
)
552 if (precision
== LONG_DOUBLE_TYPE_SIZE
)
553 return T_DOUBLE
; /* better than nothing */
564 m
= plain_type_1 (TREE_TYPE (type
), level
+1);
565 if (sdb_n_dims
< SDB_MAX_DIM
)
566 sdb_dims
[sdb_n_dims
++]
567 = (TYPE_DOMAIN (type
)
568 && TYPE_MIN_VALUE (TYPE_DOMAIN (type
)) != 0
569 && TYPE_MAX_VALUE (TYPE_DOMAIN (type
)) != 0
570 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), 0)
571 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0)
572 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type
)), 0)
573 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type
)), 0) + 1)
576 return PUSH_DERIVED_LEVEL (DT_ARY
, m
);
581 case QUAL_UNION_TYPE
:
585 #ifdef SDB_ALLOW_FORWARD_REFERENCES
586 sdbout_record_type_name (type
);
588 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
589 if ((TREE_ASM_WRITTEN (type
) && KNOWN_TYPE_TAG (type
) != 0)
590 #ifdef SDB_ALLOW_FORWARD_REFERENCES
591 || TYPE_MODE (type
) != VOIDmode
596 /* Output the referenced structure tag name
597 only if the .def has already been finished.
598 At least on 386, the Unix assembler
599 cannot handle forward references to tags. */
600 /* But the 88100, it requires them, sigh... */
601 /* And the MIPS requires unknown refs as well... */
602 tag
= KNOWN_TYPE_TAG (type
);
604 /* These 3 lines used to follow the close brace.
605 However, a size of 0 without a tag implies a tag of 0,
606 so if we don't know a tag, we can't mention the size. */
607 sdb_type_size
= int_size_in_bytes (type
);
608 if (sdb_type_size
< 0)
611 return ((TREE_CODE (type
) == RECORD_TYPE
) ? T_STRUCT
612 : (TREE_CODE (type
) == UNION_TYPE
) ? T_UNION
613 : (TREE_CODE (type
) == QUAL_UNION_TYPE
) ? T_UNION
623 m
= plain_type_1 (TREE_TYPE (type
), level
+1);
624 return PUSH_DERIVED_LEVEL (DT_PTR
, m
);
633 m
= plain_type_1 (TREE_TYPE (type
), level
+1);
634 return PUSH_DERIVED_LEVEL (DT_FCN
, m
);
641 /* Output the symbols defined in block number DO_BLOCK.
643 This function works by walking the tree structure of blocks,
644 counting blocks until it finds the desired block. */
646 static int do_block
= 0;
649 sdbout_block (tree block
)
653 /* Ignore blocks never expanded or otherwise marked as real. */
654 if (TREE_USED (block
))
656 /* When we reach the specified block, output its symbols. */
657 if (BLOCK_NUMBER (block
) == do_block
)
658 sdbout_syms (BLOCK_VARS (block
));
660 /* If we are past the specified block, stop the scan. */
661 if (BLOCK_NUMBER (block
) > do_block
)
664 /* Scan the blocks within this block. */
665 sdbout_block (BLOCK_SUBBLOCKS (block
));
668 block
= BLOCK_CHAIN (block
);
672 /* Call sdbout_symbol on each decl in the chain SYMS. */
675 sdbout_syms (tree syms
)
679 if (TREE_CODE (syms
) != LABEL_DECL
)
680 sdbout_symbol (syms
, 1);
681 syms
= TREE_CHAIN (syms
);
685 /* Output SDB information for a symbol described by DECL.
686 LOCAL is nonzero if the symbol is not file-scope. */
689 sdbout_symbol (tree decl
, int local
)
691 tree type
= TREE_TYPE (decl
);
692 tree context
= NULL_TREE
;
697 /* If we are called before sdbout_init is run, just save the symbol
699 if (!sdbout_initialized
)
701 preinit_symbols
= tree_cons (0, decl
, preinit_symbols
);
705 sdbout_one_type (type
);
707 switch (TREE_CODE (decl
))
710 /* Enum values are defined by defining the enum type. */
714 /* Don't mention a nested function under its parent. */
715 context
= decl_function_context (decl
);
716 if (context
== current_function_decl
)
718 /* Check DECL_INITIAL to distinguish declarations from definitions.
719 Don't output debug info here for declarations; they will have
720 a DECL_INITIAL value of 0. */
721 if (! DECL_INITIAL (decl
))
723 if (!MEM_P (DECL_RTL (decl
))
724 || GET_CODE (XEXP (DECL_RTL (decl
), 0)) != SYMBOL_REF
)
726 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
727 PUT_SDB_VAL (XEXP (DECL_RTL (decl
), 0));
728 PUT_SDB_SCL (TREE_PUBLIC (decl
) ? C_EXT
: C_STAT
);
732 /* Done with tagged types. */
733 if (DECL_NAME (decl
) == 0)
735 if (DECL_IGNORED_P (decl
))
737 /* Don't output intrinsic types. GAS chokes on SDB .def
738 statements that contain identifiers with embedded spaces
739 (eg "unsigned long"). */
740 if (DECL_IS_BUILTIN (decl
))
743 /* Output typedef name. */
744 if (template_name_p (DECL_NAME (decl
)))
745 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
747 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl
)));
748 PUT_SDB_SCL (C_TPDEF
);
752 /* Parm decls go in their own separate chains
753 and are output by sdbout_reg_parms and sdbout_parms. */
757 /* Don't mention a variable that is external.
758 Let the file that defines it describe it. */
759 if (DECL_EXTERNAL (decl
))
762 /* Ignore __FUNCTION__, etc. */
763 if (DECL_IGNORED_P (decl
))
766 /* If there was an error in the declaration, don't dump core
767 if there is no RTL associated with the variable doesn't
769 if (!DECL_RTL_SET_P (decl
))
773 eliminate_regs (DECL_RTL (decl
), 0, NULL_RTX
));
774 #ifdef LEAF_REG_REMAP
775 if (current_function_uses_only_leaf_regs
)
776 leaf_renumber_regs_insn (DECL_RTL (decl
));
778 value
= DECL_RTL (decl
);
780 /* Don't mention a variable at all
781 if it was completely optimized into nothingness.
783 If DECL was from an inline function, then its rtl
784 is not identically the rtl that was used in this
785 particular compilation. */
788 regno
= REGNO (value
);
789 if (regno
>= FIRST_PSEUDO_REGISTER
)
792 else if (GET_CODE (value
) == SUBREG
)
794 while (GET_CODE (value
) == SUBREG
)
795 value
= SUBREG_REG (value
);
798 if (REGNO (value
) >= FIRST_PSEUDO_REGISTER
)
801 regno
= REGNO (alter_subreg (&value
));
802 SET_DECL_RTL (decl
, value
);
804 /* Don't output anything if an auto variable
805 gets RTL that is static.
806 GAS version 2.2 can't handle such output. */
807 else if (MEM_P (value
) && CONSTANT_P (XEXP (value
, 0))
808 && ! TREE_STATIC (decl
))
811 /* Emit any structure, union, or enum type that has not been output.
812 This occurs for tag-less structs (et al) used to declare variables
814 if (TREE_CODE (type
) == ENUMERAL_TYPE
815 || TREE_CODE (type
) == RECORD_TYPE
816 || TREE_CODE (type
) == UNION_TYPE
817 || TREE_CODE (type
) == QUAL_UNION_TYPE
)
819 if (COMPLETE_TYPE_P (type
) /* not a forward reference */
820 && KNOWN_TYPE_TAG (type
) == 0) /* not yet declared */
821 sdbout_one_type (type
);
824 /* Defer SDB information for top-level initialized variables! */
827 && DECL_INITIAL (decl
))
830 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
831 For now, avoid crashing. */
832 if (DECL_NAME (decl
) == NULL_TREE
)
835 /* Record the name for, starting a symtab entry. */
837 name
= IDENTIFIER_POINTER (DECL_NAME (decl
));
839 name
= IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
));
842 && GET_CODE (XEXP (value
, 0)) == SYMBOL_REF
)
845 if (TREE_PUBLIC (decl
))
847 PUT_SDB_VAL (XEXP (value
, 0));
852 PUT_SDB_VAL (XEXP (value
, 0));
853 PUT_SDB_SCL (C_STAT
);
859 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno
));
862 else if (MEM_P (value
)
863 && (MEM_P (XEXP (value
, 0))
864 || (REG_P (XEXP (value
, 0))
865 && REGNO (XEXP (value
, 0)) != HARD_FRAME_POINTER_REGNUM
866 && REGNO (XEXP (value
, 0)) != STACK_POINTER_REGNUM
)))
867 /* If the value is indirect by memory or by a register
868 that isn't the frame pointer
869 then it means the object is variable-sized and address through
870 that register or stack slot. COFF has no way to represent this
871 so all we can do is output the variable as a pointer. */
874 if (REG_P (XEXP (value
, 0)))
876 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value
, 0))));
881 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
883 We want the value of that CONST_INT. */
884 /* Encore compiler hates a newline in a macro arg, it seems. */
885 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
886 (XEXP (XEXP (value
, 0), 0)));
887 PUT_SDB_SCL (C_AUTO
);
890 /* Effectively do build_pointer_type, but don't cache this type,
891 since it might be temporary whereas the type it points to
892 might have been saved for inlining. */
893 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
894 type
= make_node (POINTER_TYPE
);
895 TREE_TYPE (type
) = TREE_TYPE (decl
);
897 else if (MEM_P (value
)
898 && ((GET_CODE (XEXP (value
, 0)) == PLUS
899 && REG_P (XEXP (XEXP (value
, 0), 0))
900 && GET_CODE (XEXP (XEXP (value
, 0), 1)) == CONST_INT
)
901 /* This is for variables which are at offset zero from
902 the frame pointer. This happens on the Alpha.
903 Non-frame pointer registers are excluded above. */
904 || (REG_P (XEXP (value
, 0)))))
906 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
907 or (MEM (REG...)). We want the value of that CONST_INT
910 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value
, 0)));
911 PUT_SDB_SCL (C_AUTO
);
915 /* It is something we don't know how to represent for SDB. */
923 PUT_SDB_TYPE (plain_type (type
));
927 /* Output SDB information for a top-level initialized variable
928 that has been delayed. */
931 sdbout_toplevel_data (tree decl
)
933 tree type
= TREE_TYPE (decl
);
935 if (DECL_IGNORED_P (decl
))
938 gcc_assert (TREE_CODE (decl
) == VAR_DECL
);
939 gcc_assert (MEM_P (DECL_RTL (decl
)));
940 gcc_assert (DECL_INITIAL (decl
));
942 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl
)));
943 PUT_SDB_VAL (XEXP (DECL_RTL (decl
), 0));
944 if (TREE_PUBLIC (decl
))
950 PUT_SDB_SCL (C_STAT
);
952 PUT_SDB_TYPE (plain_type (type
));
956 #ifdef SDB_ALLOW_FORWARD_REFERENCES
958 /* Machinery to record and output anonymous types. */
961 sdbout_queue_anonymous_type (tree type
)
963 anonymous_types
= tree_cons (NULL_TREE
, type
, anonymous_types
);
967 sdbout_dequeue_anonymous_types (void)
971 while (anonymous_types
)
973 types
= nreverse (anonymous_types
);
974 anonymous_types
= NULL_TREE
;
976 for (link
= types
; link
; link
= TREE_CHAIN (link
))
978 tree type
= TREE_VALUE (link
);
980 if (type
&& ! TREE_ASM_WRITTEN (type
))
981 sdbout_one_type (type
);
988 /* Given a chain of ..._TYPE nodes, all of which have names,
989 output definitions of those names, as typedefs. */
992 sdbout_types (tree types
)
996 for (link
= types
; link
; link
= TREE_CHAIN (link
))
997 sdbout_one_type (link
);
999 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1000 sdbout_dequeue_anonymous_types ();
1005 sdbout_type (tree type
)
1007 if (type
== error_mark_node
)
1008 type
= integer_type_node
;
1009 PUT_SDB_TYPE (plain_type (type
));
1012 /* Output types of the fields of type TYPE, if they are structs.
1014 Formerly did not chase through pointer types, since that could be circular.
1015 They must come before TYPE, since forward refs are not allowed.
1016 Now james@bigtex.cactus.org says to try them. */
1019 sdbout_field_types (tree type
)
1023 for (tail
= TYPE_FIELDS (type
); tail
; tail
= TREE_CHAIN (tail
))
1024 /* This condition should match the one for emitting the actual
1026 if (TREE_CODE (tail
) == FIELD_DECL
1029 && host_integerp (DECL_SIZE (tail
), 1)
1030 && host_integerp (bit_position (tail
), 0))
1032 if (POINTER_TYPE_P (TREE_TYPE (tail
)))
1033 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail
)));
1035 sdbout_one_type (TREE_TYPE (tail
));
1039 /* Use this to put out the top level defined record and union types
1040 for later reference. If this is a struct with a name, then put that
1041 name out. Other unnamed structs will have .xxfake labels generated so
1042 that they may be referred to later.
1043 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1044 It may NOT be called recursively. */
1047 sdbout_one_type (tree type
)
1049 if (current_function_decl
!= NULL_TREE
1050 && DECL_SECTION_NAME (current_function_decl
) != NULL_TREE
)
1051 ; /* Don't change section amid function. */
1053 switch_to_section (text_section
);
1055 switch (TREE_CODE (type
))
1059 case QUAL_UNION_TYPE
:
1061 type
= TYPE_MAIN_VARIANT (type
);
1062 /* Don't output a type twice. */
1063 if (TREE_ASM_WRITTEN (type
))
1064 /* James said test TREE_ASM_BEING_WRITTEN here. */
1067 /* Output nothing if type is not yet defined. */
1068 if (!COMPLETE_TYPE_P (type
))
1071 TREE_ASM_WRITTEN (type
) = 1;
1073 /* This is reputed to cause trouble with the following case,
1074 but perhaps checking TYPE_SIZE above will fix it. */
1076 /* Here is a testcase:
1082 typedef struct intermediate {
1086 typedef struct badstr {
1090 /* This change, which ought to make better output,
1091 used to make the COFF assembler unhappy.
1092 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1093 /* Before really doing anything, output types we want to refer to. */
1094 /* Note that in version 1 the following two lines
1095 are not used if forward references are in use. */
1096 if (TREE_CODE (type
) != ENUMERAL_TYPE
)
1097 sdbout_field_types (type
);
1099 /* Output a structure type. */
1101 int size
= int_size_in_bytes (type
);
1105 /* Record the type tag, but not in its permanent place just yet. */
1106 sdbout_record_type_name (type
);
1108 PUT_SDB_DEF (KNOWN_TYPE_TAG (type
));
1110 switch (TREE_CODE (type
))
1113 case QUAL_UNION_TYPE
:
1114 PUT_SDB_SCL (C_UNTAG
);
1115 PUT_SDB_TYPE (T_UNION
);
1120 PUT_SDB_SCL (C_STRTAG
);
1121 PUT_SDB_TYPE (T_STRUCT
);
1126 PUT_SDB_SCL (C_ENTAG
);
1127 PUT_SDB_TYPE (T_ENUM
);
1135 PUT_SDB_SIZE (size
);
1138 /* Print out the base class information with fields
1139 named after the types they hold. */
1140 /* This is only relevant to aggregate types. TYPE_BINFO is used
1141 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1143 if (TREE_CODE (type
) != ENUMERAL_TYPE
&& TYPE_BINFO (type
))
1148 for (binfo
= TYPE_BINFO (type
), i
= 0;
1149 BINFO_BASE_ITERATE (binfo
, i
, child
); i
++)
1151 tree child_type
= BINFO_TYPE (child
);
1152 tree child_type_name
;
1154 if (TYPE_NAME (child_type
) == 0)
1156 if (TREE_CODE (TYPE_NAME (child_type
)) == IDENTIFIER_NODE
)
1157 child_type_name
= TYPE_NAME (child_type
);
1158 else if (TREE_CODE (TYPE_NAME (child_type
)) == TYPE_DECL
)
1160 child_type_name
= DECL_NAME (TYPE_NAME (child_type
));
1161 if (child_type_name
&& template_name_p (child_type_name
))
1163 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type
));
1168 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name
));
1169 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child
), 0));
1170 PUT_SDB_SCL (member_scl
);
1171 sdbout_type (BINFO_TYPE (child
));
1176 /* Output the individual fields. */
1178 if (TREE_CODE (type
) == ENUMERAL_TYPE
)
1180 for (tem
= TYPE_VALUES (type
); tem
; tem
= TREE_CHAIN (tem
))
1182 tree value
= TREE_VALUE (tem
);
1184 if (TREE_CODE (value
) == CONST_DECL
)
1185 value
= DECL_INITIAL (value
);
1187 if (host_integerp (value
, 0))
1189 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem
)));
1190 PUT_SDB_INT_VAL (tree_low_cst (value
, 0));
1191 PUT_SDB_SCL (C_MOE
);
1192 PUT_SDB_TYPE (T_MOE
);
1197 else /* record or union type */
1198 for (tem
= TYPE_FIELDS (type
); tem
; tem
= TREE_CHAIN (tem
))
1199 /* Output the name, type, position (in bits), size (in bits)
1202 /* Omit here the nameless fields that are used to skip bits.
1203 Also omit fields with variable size or position.
1204 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1205 if (TREE_CODE (tem
) == FIELD_DECL
1208 && host_integerp (DECL_SIZE (tem
), 1)
1209 && host_integerp (bit_position (tem
), 0))
1213 name
= IDENTIFIER_POINTER (DECL_NAME (tem
));
1215 if (DECL_BIT_FIELD_TYPE (tem
))
1217 PUT_SDB_INT_VAL (int_bit_position (tem
));
1218 PUT_SDB_SCL (C_FIELD
);
1219 sdbout_type (DECL_BIT_FIELD_TYPE (tem
));
1220 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem
), 1));
1224 PUT_SDB_INT_VAL (int_bit_position (tem
) / BITS_PER_UNIT
);
1225 PUT_SDB_SCL (member_scl
);
1226 sdbout_type (TREE_TYPE (tem
));
1230 /* Output end of a structure,union, or enumeral definition. */
1232 PUT_SDB_PLAIN_DEF ("eos");
1233 PUT_SDB_INT_VAL (size
);
1234 PUT_SDB_SCL (C_EOS
);
1235 PUT_SDB_TAG (KNOWN_TYPE_TAG (type
));
1236 PUT_SDB_SIZE (size
);
1246 /* The following two functions output definitions of function parameters.
1247 Each parameter gets a definition locating it in the parameter list.
1248 Each parameter that is a register variable gets a second definition
1249 locating it in the register.
1251 Printing or argument lists in gdb uses the definitions that
1252 locate in the parameter list. But reference to the variable in
1253 expressions uses preferentially the definition as a register. */
1255 /* Output definitions, referring to storage in the parmlist,
1256 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1259 sdbout_parms (tree parms
)
1261 for (; parms
; parms
= TREE_CHAIN (parms
))
1262 if (DECL_NAME (parms
))
1264 int current_sym_value
= 0;
1265 const char *name
= IDENTIFIER_POINTER (DECL_NAME (parms
));
1267 if (name
== 0 || *name
== 0)
1268 name
= gen_fake_label ();
1270 /* Perform any necessary register eliminations on the parameter's rtl,
1271 so that the debugging output will be accurate. */
1272 DECL_INCOMING_RTL (parms
)
1273 = eliminate_regs (DECL_INCOMING_RTL (parms
), 0, NULL_RTX
);
1274 SET_DECL_RTL (parms
,
1275 eliminate_regs (DECL_RTL (parms
), 0, NULL_RTX
));
1277 if (PARM_PASSED_IN_MEMORY (parms
))
1279 rtx addr
= XEXP (DECL_INCOMING_RTL (parms
), 0);
1282 /* ??? Here we assume that the parm address is indexed
1283 off the frame pointer or arg pointer.
1284 If that is not true, we produce meaningless results,
1285 but do not crash. */
1286 if (GET_CODE (addr
) == PLUS
1287 && GET_CODE (XEXP (addr
, 1)) == CONST_INT
)
1288 current_sym_value
= INTVAL (XEXP (addr
, 1));
1290 current_sym_value
= 0;
1292 if (REG_P (DECL_RTL (parms
))
1293 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
)
1294 type
= DECL_ARG_TYPE (parms
);
1297 int original_sym_value
= current_sym_value
;
1299 /* This is the case where the parm is passed as an int or
1300 double and it is converted to a char, short or float
1301 and stored back in the parmlist. In this case, describe
1302 the parm with the variable's declared type, and adjust
1303 the address if the least significant bytes (which we are
1304 using) are not the first ones. */
1305 if (BYTES_BIG_ENDIAN
1306 && TREE_TYPE (parms
) != DECL_ARG_TYPE (parms
))
1307 current_sym_value
+=
1308 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms
)))
1309 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms
))));
1311 if (MEM_P (DECL_RTL (parms
))
1312 && GET_CODE (XEXP (DECL_RTL (parms
), 0)) == PLUS
1313 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms
), 0), 1))
1315 && (INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1))
1316 == current_sym_value
))
1317 type
= TREE_TYPE (parms
);
1320 current_sym_value
= original_sym_value
;
1321 type
= DECL_ARG_TYPE (parms
);
1326 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value
, addr
));
1327 PUT_SDB_SCL (C_ARG
);
1328 PUT_SDB_TYPE (plain_type (type
));
1331 else if (REG_P (DECL_RTL (parms
)))
1334 /* Parm passed in registers and lives in registers or nowhere. */
1336 /* If parm lives in a register, use that register;
1337 pretend the parm was passed there. It would be more consistent
1338 to describe the register where the parm was passed,
1339 but in practice that register usually holds something else. */
1340 if (REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
)
1341 best_rtl
= DECL_RTL (parms
);
1342 /* If the parm lives nowhere,
1343 use the register where it was passed. */
1345 best_rtl
= DECL_INCOMING_RTL (parms
);
1348 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl
)));
1349 PUT_SDB_SCL (C_REGPARM
);
1350 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1353 else if (MEM_P (DECL_RTL (parms
))
1354 && XEXP (DECL_RTL (parms
), 0) != const0_rtx
)
1356 /* Parm was passed in registers but lives on the stack. */
1358 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1359 in which case we want the value of that CONST_INT,
1360 or (MEM (REG ...)) or (MEM (MEM ...)),
1361 in which case we use a value of zero. */
1362 if (REG_P (XEXP (DECL_RTL (parms
), 0))
1363 || MEM_P (XEXP (DECL_RTL (parms
), 0)))
1364 current_sym_value
= 0;
1366 current_sym_value
= INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1));
1368 /* Again, this assumes the offset is based on the arg pointer. */
1370 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value
,
1371 XEXP (DECL_RTL (parms
), 0)));
1372 PUT_SDB_SCL (C_ARG
);
1373 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1379 /* Output definitions for the places where parms live during the function,
1380 when different from where they were passed, when the parms were passed
1383 It is not useful to do this for parms passed in registers
1384 that live during the function in different registers, because it is
1385 impossible to look in the passed register for the passed value,
1386 so we use the within-the-function register to begin with.
1388 PARMS is a chain of PARM_DECL nodes. */
1391 sdbout_reg_parms (tree parms
)
1393 for (; parms
; parms
= TREE_CHAIN (parms
))
1394 if (DECL_NAME (parms
))
1396 const char *name
= IDENTIFIER_POINTER (DECL_NAME (parms
));
1398 /* Report parms that live in registers during the function
1399 but were passed in memory. */
1400 if (REG_P (DECL_RTL (parms
))
1401 && REGNO (DECL_RTL (parms
)) < FIRST_PSEUDO_REGISTER
1402 && PARM_PASSED_IN_MEMORY (parms
))
1404 if (name
== 0 || *name
== 0)
1405 name
= gen_fake_label ();
1407 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms
))));
1408 PUT_SDB_SCL (C_REG
);
1409 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1412 /* Report parms that live in memory but not where they were passed. */
1413 else if (MEM_P (DECL_RTL (parms
))
1414 && GET_CODE (XEXP (DECL_RTL (parms
), 0)) == PLUS
1415 && GET_CODE (XEXP (XEXP (DECL_RTL (parms
), 0), 1)) == CONST_INT
1416 && PARM_PASSED_IN_MEMORY (parms
)
1417 && ! rtx_equal_p (DECL_RTL (parms
), DECL_INCOMING_RTL (parms
)))
1419 #if 0 /* ??? It is not clear yet what should replace this. */
1420 int offset
= DECL_OFFSET (parms
) / BITS_PER_UNIT
;
1421 /* A parm declared char is really passed as an int,
1422 so it occupies the least significant bytes.
1423 On a big-endian machine those are not the low-numbered ones. */
1424 if (BYTES_BIG_ENDIAN
1426 && TREE_TYPE (parms
) != DECL_ARG_TYPE (parms
))
1427 offset
+= (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms
)))
1428 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms
))));
1429 if (INTVAL (XEXP (XEXP (DECL_RTL (parms
), 0), 1)) != offset
) {...}
1432 if (name
== 0 || *name
== 0)
1433 name
= gen_fake_label ();
1435 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1436 (XEXP (DECL_RTL (parms
), 0)));
1437 PUT_SDB_SCL (C_AUTO
);
1438 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms
)));
1445 /* Output debug information for a global DECL. Called from toplev.c
1446 after compilation proper has finished. */
1449 sdbout_global_decl (tree decl
)
1451 if (TREE_CODE (decl
) == VAR_DECL
1452 && !DECL_EXTERNAL (decl
)
1453 && DECL_RTL_SET_P (decl
))
1455 /* The COFF linker can move initialized global vars to the end.
1456 And that can screw up the symbol ordering. Defer those for
1457 sdbout_finish (). */
1458 if (!DECL_INITIAL (decl
) || !TREE_PUBLIC (decl
))
1459 sdbout_symbol (decl
, 0);
1461 VARRAY_PUSH_TREE (deferred_global_decls
, decl
);
1463 /* Output COFF information for non-global file-scope initialized
1465 if (DECL_INITIAL (decl
) && MEM_P (DECL_RTL (decl
)))
1466 sdbout_toplevel_data (decl
);
1470 /* Output initialized global vars at the end, in the order of
1471 definition. See comment in sdbout_global_decl. */
1474 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED
)
1478 for (i
= 0; i
< VARRAY_ACTIVE_SIZE (deferred_global_decls
); i
++)
1479 sdbout_symbol (VARRAY_TREE (deferred_global_decls
, i
), 0);
1482 /* Describe the beginning of an internal block within a function.
1483 Also output descriptions of variables defined in this block.
1485 N is the number of the block, by order of beginning, counting from 1,
1486 and not counting the outermost (function top-level) block.
1487 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1488 if the count starts at 0 for the outermost one. */
1491 sdbout_begin_block (unsigned int line
, unsigned int n
)
1493 tree decl
= current_function_decl
;
1494 MAKE_LINE_SAFE (line
);
1496 /* The SCO compiler does not emit a separate block for the function level
1497 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1498 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1499 #ifndef MIPS_DEBUGGING_INFO
1502 PUT_SDB_BLOCK_START (line
- sdb_begin_function_line
);
1506 /* Include the outermost BLOCK's variables in block 1. */
1507 do_block
= BLOCK_NUMBER (DECL_INITIAL (decl
));
1508 sdbout_block (DECL_INITIAL (decl
));
1510 /* If -g1, suppress all the internal symbols of functions
1511 except for arguments. */
1512 if (debug_info_level
!= DINFO_LEVEL_TERSE
)
1515 sdbout_block (DECL_INITIAL (decl
));
1518 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1519 sdbout_dequeue_anonymous_types ();
1523 /* Describe the end line-number of an internal block within a function. */
1526 sdbout_end_block (unsigned int line
, unsigned int n ATTRIBUTE_UNUSED
)
1528 MAKE_LINE_SAFE (line
);
1530 /* The SCO compiler does not emit a separate block for the function level
1531 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1532 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1533 #ifndef MIPS_DEBUGGING_INFO
1536 PUT_SDB_BLOCK_END (line
- sdb_begin_function_line
);
1539 /* Output a line number symbol entry for source file FILENAME and line
1543 sdbout_source_line (unsigned int line
, const char *filename ATTRIBUTE_UNUSED
)
1545 /* COFF relative line numbers must be positive. */
1546 if ((int) line
> sdb_begin_function_line
)
1548 #ifdef SDB_OUTPUT_SOURCE_LINE
1549 SDB_OUTPUT_SOURCE_LINE (asm_out_file
, line
);
1551 fprintf (asm_out_file
, "\t.ln\t%d\n",
1552 ((sdb_begin_function_line
> -1)
1553 ? line
- sdb_begin_function_line
: 1));
1558 /* Output sdb info for the current function name.
1559 Called from assemble_start_function. */
1562 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED
)
1564 sdbout_symbol (current_function_decl
, 0);
1567 /* Called at beginning of function body (before or after prologue,
1568 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1569 line number, so we can output relative line numbers for the other
1570 lines. Describe beginning of outermost block. Also describe the
1573 #ifndef MIPS_DEBUGGING_INFO
1575 sdbout_begin_prologue (unsigned int line
, const char *file ATTRIBUTE_UNUSED
)
1577 sdbout_end_prologue (line
, file
);
1582 sdbout_end_prologue (unsigned int line
, const char *file ATTRIBUTE_UNUSED
)
1584 sdb_begin_function_line
= line
- 1;
1585 PUT_SDB_FUNCTION_START (line
);
1586 sdbout_parms (DECL_ARGUMENTS (current_function_decl
));
1587 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl
));
1590 /* Called at end of function (before epilogue).
1591 Describe end of outermost block. */
1594 sdbout_end_function (unsigned int line
)
1596 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1597 sdbout_dequeue_anonymous_types ();
1600 MAKE_LINE_SAFE (line
);
1601 PUT_SDB_FUNCTION_END (line
- sdb_begin_function_line
);
1603 /* Indicate we are between functions, for line-number output. */
1604 sdb_begin_function_line
= -1;
1607 /* Output sdb info for the absolute end of a function.
1608 Called after the epilogue is output. */
1611 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED
,
1612 const char *file ATTRIBUTE_UNUSED
)
1614 const char *const name ATTRIBUTE_UNUSED
1615 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl
));
1617 #ifdef PUT_SDB_EPILOGUE_END
1618 PUT_SDB_EPILOGUE_END (name
);
1620 fprintf (asm_out_file
, "\t.def\t");
1621 assemble_name (asm_out_file
, name
);
1622 fprintf (asm_out_file
, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1623 SDB_DELIM
, SDB_DELIM
, SDB_DELIM
);
1627 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1631 sdbout_label (rtx insn
)
1633 PUT_SDB_DEF (LABEL_NAME (insn
));
1635 PUT_SDB_SCL (C_LABEL
);
1636 PUT_SDB_TYPE (T_NULL
);
1640 /* Change to reading from a new source file. */
1643 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED
,
1644 const char *filename ATTRIBUTE_UNUSED
)
1646 #ifdef MIPS_DEBUGGING_INFO
1647 struct sdb_file
*n
= XNEW (struct sdb_file
);
1649 n
->next
= current_file
;
1652 output_file_directive (asm_out_file
, filename
);
1656 /* Revert to reading a previous source file. */
1659 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED
)
1661 #ifdef MIPS_DEBUGGING_INFO
1662 struct sdb_file
*next
;
1664 next
= current_file
->next
;
1665 free (current_file
);
1666 current_file
= next
;
1667 output_file_directive (asm_out_file
, current_file
->name
);
1671 /* Set up for SDB output at the start of compilation. */
1674 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED
)
1678 #ifdef MIPS_DEBUGGING_INFO
1679 current_file
= XNEW (struct sdb_file
);
1680 current_file
->next
= NULL
;
1681 current_file
->name
= input_file_name
;
1684 VARRAY_TREE_INIT (deferred_global_decls
, 12, "deferred_global_decls");
1686 /* Emit debug information which was queued by sdbout_symbol before
1688 sdbout_initialized
= true;
1690 for (t
= nreverse (preinit_symbols
); t
; t
= TREE_CHAIN (t
))
1691 sdbout_symbol (TREE_VALUE (t
), 0);
1692 preinit_symbols
= 0;
1695 #else /* SDB_DEBUGGING_INFO */
1697 /* This should never be used, but its address is needed for comparisons. */
1698 const struct gcc_debug_hooks sdb_debug_hooks
;
1700 #endif /* SDB_DEBUGGING_INFO */
1702 #include "gt-sdbout.h"