[RTL-ifcvt] PR rtl-optimization/68506: Fix emitting order of insns in IF-THEN-JOIN...
[official-gcc.git] / gcc / sdbout.c
blob09fa06eb3bd08851248213351c295ece16da9dd3
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
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
26 function.
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.
42 #include "config.h"
43 #include "system.h"
44 #include "coretypes.h"
45 #include "gsyms.h"
46 #include "tm.h"
47 #include "debug.h"
48 #include "tree.h"
49 #include "varasm.h"
50 #include "stor-layout.h"
52 static GTY(()) tree anonymous_types;
54 /* Counter to generate unique "names" for nameless struct members. */
56 static GTY(()) int unnamed_struct_number;
58 /* Declarations whose debug info was deferred till end of compilation. */
60 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
62 /* The C front end may call sdbout_symbol before sdbout_init runs.
63 We save all such decls in this list and output them when we get
64 to sdbout_init. */
66 static GTY(()) tree preinit_symbols;
67 static GTY(()) bool sdbout_initialized;
69 #include "rtl.h"
70 #include "regs.h"
71 #include "function.h"
72 #include "emit-rtl.h"
73 #include "flags.h"
74 #include "insn-config.h"
75 #include "reload.h"
76 #include "output.h"
77 #include "diagnostic-core.h"
78 #include "tm_p.h"
79 #include "langhooks.h"
80 #include "target.h"
82 /* 1 if PARM is passed to this function in memory. */
84 #define PARM_PASSED_IN_MEMORY(PARM) \
85 (MEM_P (DECL_INCOMING_RTL (PARM)))
87 /* A C expression for the integer offset value of an automatic variable
88 (C_AUTO) having address X (an RTX). */
89 #ifndef DEBUGGER_AUTO_OFFSET
90 #define DEBUGGER_AUTO_OFFSET(X) \
91 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
92 #endif
94 /* A C expression for the integer offset value of an argument (C_ARG)
95 having address X (an RTX). The nominal offset is OFFSET. */
96 #ifndef DEBUGGER_ARG_OFFSET
97 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
98 #endif
100 /* Line number of beginning of current function, minus one.
101 Negative means not in a function or not using sdb. */
103 int sdb_begin_function_line = -1;
106 extern FILE *asm_out_file;
108 extern tree current_function_decl;
110 #include "sdbout.h"
112 static void sdbout_init (const char *);
113 static void sdbout_finish (const char *);
114 static void sdbout_start_source_file (unsigned int, const char *);
115 static void sdbout_end_source_file (unsigned int);
116 static void sdbout_begin_block (unsigned int, unsigned int);
117 static void sdbout_end_block (unsigned int, unsigned int);
118 static void sdbout_source_line (unsigned int, const char *, int, bool);
119 static void sdbout_end_epilogue (unsigned int, const char *);
120 static void sdbout_early_global_decl (tree);
121 static void sdbout_late_global_decl (tree);
122 static void sdbout_begin_prologue (unsigned int, const char *);
123 static void sdbout_end_prologue (unsigned int, const char *);
124 static void sdbout_begin_function (tree);
125 static void sdbout_end_function (unsigned int);
126 static void sdbout_toplevel_data (tree);
127 static void sdbout_label (rtx_code_label *);
128 static char *gen_fake_label (void);
129 static int plain_type (tree);
130 static int template_name_p (tree);
131 static void sdbout_record_type_name (tree);
132 static int plain_type_1 (tree, int);
133 static void sdbout_block (tree);
134 static void sdbout_syms (tree);
135 #ifdef SDB_ALLOW_FORWARD_REFERENCES
136 static void sdbout_queue_anonymous_type (tree);
137 static void sdbout_dequeue_anonymous_types (void);
138 #endif
139 static void sdbout_type (tree);
140 static void sdbout_field_types (tree);
141 static void sdbout_one_type (tree);
142 static void sdbout_parms (tree);
143 static void sdbout_reg_parms (tree);
145 /* Random macros describing parts of SDB data. */
147 /* Default value of delimiter is ";". */
148 #ifndef SDB_DELIM
149 #define SDB_DELIM ";"
150 #endif
152 /* Maximum number of dimensions the assembler will allow. */
153 #ifndef SDB_MAX_DIM
154 #define SDB_MAX_DIM 4
155 #endif
157 #ifndef PUT_SDB_SCL
158 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
159 #endif
161 #ifndef PUT_SDB_INT_VAL
162 #define PUT_SDB_INT_VAL(a) \
163 do { \
164 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
165 (HOST_WIDE_INT) (a), SDB_DELIM); \
166 } while (0)
168 #endif
170 #ifndef PUT_SDB_VAL
171 #define PUT_SDB_VAL(a) \
172 ( fputs ("\t.val\t", asm_out_file), \
173 output_addr_const (asm_out_file, (a)), \
174 fprintf (asm_out_file, SDB_DELIM))
175 #endif
177 #ifndef PUT_SDB_DEF
178 #define PUT_SDB_DEF(a) \
179 do { fprintf (asm_out_file, "\t.def\t"); \
180 assemble_name (asm_out_file, a); \
181 fprintf (asm_out_file, SDB_DELIM); } while (0)
182 #endif
184 #ifndef PUT_SDB_PLAIN_DEF
185 #define PUT_SDB_PLAIN_DEF(a) \
186 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
187 #endif
189 #ifndef PUT_SDB_ENDEF
190 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
191 #endif
193 #ifndef PUT_SDB_TYPE
194 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
195 #endif
197 #ifndef PUT_SDB_SIZE
198 #define PUT_SDB_SIZE(a) \
199 do { \
200 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
201 (HOST_WIDE_INT) (a), SDB_DELIM); \
202 } while (0)
203 #endif
205 #ifndef PUT_SDB_START_DIM
206 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
207 #endif
209 #ifndef PUT_SDB_NEXT_DIM
210 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
211 #endif
213 #ifndef PUT_SDB_LAST_DIM
214 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
215 #endif
217 #ifndef PUT_SDB_TAG
218 #define PUT_SDB_TAG(a) \
219 do { fprintf (asm_out_file, "\t.tag\t"); \
220 assemble_name (asm_out_file, a); \
221 fprintf (asm_out_file, SDB_DELIM); } while (0)
222 #endif
224 #ifndef PUT_SDB_BLOCK_START
225 #define PUT_SDB_BLOCK_START(LINE) \
226 fprintf (asm_out_file, \
227 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
228 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
229 #endif
231 #ifndef PUT_SDB_BLOCK_END
232 #define PUT_SDB_BLOCK_END(LINE) \
233 fprintf (asm_out_file, \
234 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
235 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
236 #endif
238 #ifndef PUT_SDB_FUNCTION_START
239 #define PUT_SDB_FUNCTION_START(LINE) \
240 fprintf (asm_out_file, \
241 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
242 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
243 #endif
245 #ifndef PUT_SDB_FUNCTION_END
246 #define PUT_SDB_FUNCTION_END(LINE) \
247 fprintf (asm_out_file, \
248 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
249 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
250 #endif
252 /* Return the sdb tag identifier string for TYPE
253 if TYPE has already been defined; otherwise return a null pointer. */
255 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
257 /* Set the sdb tag identifier string for TYPE to NAME. */
259 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
260 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
262 /* Return the name (a string) of the struct, union or enum tag
263 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
265 #define TAG_NAME(link) \
266 (((link) && TREE_PURPOSE ((link)) \
267 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
268 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
270 /* Ensure we don't output a negative line number. */
271 #define MAKE_LINE_SAFE(line) \
272 if ((int) line <= sdb_begin_function_line) \
273 line = sdb_begin_function_line + 1
275 /* The debug hooks structure. */
276 const struct gcc_debug_hooks sdb_debug_hooks =
278 sdbout_init, /* init */
279 sdbout_finish, /* finish */
280 debug_nothing_void, /* early_finish */
281 debug_nothing_void, /* assembly_start */
282 debug_nothing_int_charstar, /* define */
283 debug_nothing_int_charstar, /* undef */
284 sdbout_start_source_file, /* start_source_file */
285 sdbout_end_source_file, /* end_source_file */
286 sdbout_begin_block, /* begin_block */
287 sdbout_end_block, /* end_block */
288 debug_true_const_tree, /* ignore_block */
289 sdbout_source_line, /* source_line */
290 sdbout_begin_prologue, /* begin_prologue */
291 debug_nothing_int_charstar, /* end_prologue */
292 debug_nothing_int_charstar, /* begin_epilogue */
293 sdbout_end_epilogue, /* end_epilogue */
294 sdbout_begin_function, /* begin_function */
295 sdbout_end_function, /* end_function */
296 debug_nothing_tree, /* register_main_translation_unit */
297 debug_nothing_tree, /* function_decl */
298 sdbout_early_global_decl, /* early_global_decl */
299 sdbout_late_global_decl, /* late_global_decl */
300 sdbout_symbol, /* type_decl */
301 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
302 debug_nothing_tree, /* deferred_inline_function */
303 debug_nothing_tree, /* outlining_inline_function */
304 sdbout_label, /* label */
305 debug_nothing_int, /* handle_pch */
306 debug_nothing_rtx_insn, /* var_location */
307 debug_nothing_void, /* switch_text_section */
308 debug_nothing_tree_tree, /* set_name */
309 0, /* start_end_main_source_file */
310 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
313 /* Return a unique string to name an anonymous type. */
315 static char *
316 gen_fake_label (void)
318 char label[10];
319 char *labelstr;
320 sprintf (label, ".%dfake", unnamed_struct_number);
321 unnamed_struct_number++;
322 labelstr = xstrdup (label);
323 return labelstr;
326 /* Return the number which describes TYPE for SDB.
327 For pointers, etc., this function is recursive.
328 Each record, union or enumeral type must already have had a
329 tag number output. */
331 /* The number is given by d6d5d4d3d2d1bbbb
332 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
333 Thus, char *foo () has bbbb=T_CHAR
334 d1=D_FCN
335 d2=D_PTR
336 N_BTMASK= 017 1111 basic type field.
337 N_TSHIFT= 2 derived type shift
338 N_BTSHFT= 4 Basic type shift */
340 /* Produce the number that describes a pointer, function or array type.
341 PREV is the number describing the target, value or element type.
342 DT_type describes how to transform that type. */
343 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
344 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
345 | ((int) DT_type << (int) N_BTSHFT) \
346 | ((PREV) & (int) N_BTMASK))
348 /* Number of elements used in sdb_dims. */
349 static int sdb_n_dims = 0;
351 /* Table of array dimensions of current type. */
352 static int sdb_dims[SDB_MAX_DIM];
354 /* Size of outermost array currently being processed. */
355 static int sdb_type_size = -1;
357 static int
358 plain_type (tree type)
360 int val = plain_type_1 (type, 0);
362 /* If we have already saved up some array dimensions, print them now. */
363 if (sdb_n_dims > 0)
365 int i;
366 PUT_SDB_START_DIM;
367 for (i = sdb_n_dims - 1; i > 0; i--)
368 PUT_SDB_NEXT_DIM (sdb_dims[i]);
369 PUT_SDB_LAST_DIM (sdb_dims[0]);
370 sdb_n_dims = 0;
372 sdb_type_size = int_size_in_bytes (type);
373 /* Don't kill sdb if type is not laid out or has variable size. */
374 if (sdb_type_size < 0)
375 sdb_type_size = 0;
377 /* If we have computed the size of an array containing this type,
378 print it now. */
379 if (sdb_type_size >= 0)
381 PUT_SDB_SIZE (sdb_type_size);
382 sdb_type_size = -1;
384 return val;
387 static int
388 template_name_p (tree name)
390 const char *ptr = IDENTIFIER_POINTER (name);
391 while (*ptr && *ptr != '<')
392 ptr++;
394 return *ptr != '\0';
397 static void
398 sdbout_record_type_name (tree type)
400 const char *name = 0;
401 int no_name;
403 if (KNOWN_TYPE_TAG (type))
404 return;
406 if (TYPE_NAME (type) != 0)
408 tree t = 0;
410 /* Find the IDENTIFIER_NODE for the type name. */
411 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
412 t = TYPE_NAME (type);
413 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
415 t = DECL_NAME (TYPE_NAME (type));
416 /* The DECL_NAME for templates includes "<>", which breaks
417 most assemblers. Use its assembler name instead, which
418 has been mangled into being safe. */
419 if (t && template_name_p (t))
420 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
423 /* Now get the name as a string, or invent one. */
424 if (t != NULL_TREE)
425 name = IDENTIFIER_POINTER (t);
428 no_name = (name == 0 || *name == 0);
429 if (no_name)
430 name = gen_fake_label ();
432 SET_KNOWN_TYPE_TAG (type, name);
433 #ifdef SDB_ALLOW_FORWARD_REFERENCES
434 if (no_name)
435 sdbout_queue_anonymous_type (type);
436 #endif
439 /* Return the .type value for type TYPE.
441 LEVEL indicates how many levels deep we have recursed into the type.
442 The SDB debug format can only represent 6 derived levels of types.
443 After that, we must output inaccurate debug info. We deliberately
444 stop before the 7th level, so that ADA recursive types will not give an
445 infinite loop. */
447 static int
448 plain_type_1 (tree type, int level)
450 if (type == 0)
451 type = void_type_node;
452 else if (type == error_mark_node)
453 type = integer_type_node;
454 else
455 type = TYPE_MAIN_VARIANT (type);
457 switch (TREE_CODE (type))
459 case VOID_TYPE:
460 case NULLPTR_TYPE:
461 return T_VOID;
462 case BOOLEAN_TYPE:
463 case INTEGER_TYPE:
465 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
467 /* Carefully distinguish all the standard types of C,
468 without messing up if the language is not C.
469 Note that we check only for the names that contain spaces;
470 other names might occur by coincidence in other languages. */
471 if (TYPE_NAME (type) != 0
472 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
473 && DECL_NAME (TYPE_NAME (type)) != 0
474 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
476 const char *const name
477 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
479 if (!strcmp (name, "char"))
480 return T_CHAR;
481 if (!strcmp (name, "unsigned char"))
482 return T_UCHAR;
483 if (!strcmp (name, "signed char"))
484 return T_CHAR;
485 if (!strcmp (name, "int"))
486 return T_INT;
487 if (!strcmp (name, "unsigned int"))
488 return T_UINT;
489 if (!strcmp (name, "short int"))
490 return T_SHORT;
491 if (!strcmp (name, "short unsigned int"))
492 return T_USHORT;
493 if (!strcmp (name, "long int"))
494 return T_LONG;
495 if (!strcmp (name, "long unsigned int"))
496 return T_ULONG;
499 if (size == INT_TYPE_SIZE)
500 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
501 if (size == CHAR_TYPE_SIZE)
502 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
503 if (size == SHORT_TYPE_SIZE)
504 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
505 if (size == LONG_TYPE_SIZE)
506 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
507 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
508 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
509 return 0;
512 case REAL_TYPE:
514 int precision = TYPE_PRECISION (type);
515 if (precision == FLOAT_TYPE_SIZE)
516 return T_FLOAT;
517 if (precision == DOUBLE_TYPE_SIZE)
518 return T_DOUBLE;
519 if (precision == LONG_DOUBLE_TYPE_SIZE)
520 return T_DOUBLE; /* better than nothing */
522 return 0;
525 case ARRAY_TYPE:
527 int m;
528 if (level >= 6)
529 return T_VOID;
530 else
531 m = plain_type_1 (TREE_TYPE (type), level+1);
532 if (sdb_n_dims < SDB_MAX_DIM)
533 sdb_dims[sdb_n_dims++]
534 = (TYPE_DOMAIN (type)
535 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
536 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
537 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
538 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
539 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
540 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
541 : 0);
543 return PUSH_DERIVED_LEVEL (DT_ARY, m);
546 case RECORD_TYPE:
547 case UNION_TYPE:
548 case QUAL_UNION_TYPE:
549 case ENUMERAL_TYPE:
551 const char *tag;
552 #ifdef SDB_ALLOW_FORWARD_REFERENCES
553 sdbout_record_type_name (type);
554 #endif
555 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
556 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
557 #ifdef SDB_ALLOW_FORWARD_REFERENCES
558 || TYPE_MODE (type) != VOIDmode
559 #endif
561 #endif
563 /* Output the referenced structure tag name
564 only if the .def has already been finished.
565 At least on 386, the Unix assembler
566 cannot handle forward references to tags. */
567 /* But the 88100, it requires them, sigh... */
568 /* And the MIPS requires unknown refs as well... */
569 tag = KNOWN_TYPE_TAG (type);
570 PUT_SDB_TAG (tag);
571 /* These 3 lines used to follow the close brace.
572 However, a size of 0 without a tag implies a tag of 0,
573 so if we don't know a tag, we can't mention the size. */
574 sdb_type_size = int_size_in_bytes (type);
575 if (sdb_type_size < 0)
576 sdb_type_size = 0;
578 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
579 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
580 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
581 : T_ENUM);
583 case POINTER_TYPE:
584 case REFERENCE_TYPE:
586 int m;
587 if (level >= 6)
588 return T_VOID;
589 else
590 m = plain_type_1 (TREE_TYPE (type), level+1);
591 return PUSH_DERIVED_LEVEL (DT_PTR, m);
593 case FUNCTION_TYPE:
594 case METHOD_TYPE:
596 int m;
597 if (level >= 6)
598 return T_VOID;
599 else
600 m = plain_type_1 (TREE_TYPE (type), level+1);
601 return PUSH_DERIVED_LEVEL (DT_FCN, m);
603 default:
604 return 0;
608 /* Output the symbols defined in block number DO_BLOCK.
610 This function works by walking the tree structure of blocks,
611 counting blocks until it finds the desired block. */
613 static int do_block = 0;
615 static void
616 sdbout_block (tree block)
618 while (block)
620 /* Ignore blocks never expanded or otherwise marked as real. */
621 if (TREE_USED (block))
623 /* When we reach the specified block, output its symbols. */
624 if (BLOCK_NUMBER (block) == do_block)
625 sdbout_syms (BLOCK_VARS (block));
627 /* If we are past the specified block, stop the scan. */
628 if (BLOCK_NUMBER (block) > do_block)
629 return;
631 /* Scan the blocks within this block. */
632 sdbout_block (BLOCK_SUBBLOCKS (block));
635 block = BLOCK_CHAIN (block);
639 /* Call sdbout_symbol on each decl in the chain SYMS. */
641 static void
642 sdbout_syms (tree syms)
644 while (syms)
646 if (TREE_CODE (syms) != LABEL_DECL)
647 sdbout_symbol (syms, 1);
648 syms = TREE_CHAIN (syms);
652 /* Output SDB information for a symbol described by DECL.
653 LOCAL is nonzero if the symbol is not file-scope. */
655 void
656 sdbout_symbol (tree decl, int local)
658 tree type = TREE_TYPE (decl);
659 tree context = NULL_TREE;
660 rtx value;
661 int regno = -1;
662 const char *name;
664 /* If we are called before sdbout_init is run, just save the symbol
665 for later. */
666 if (!sdbout_initialized)
668 preinit_symbols = tree_cons (0, decl, preinit_symbols);
669 return;
672 sdbout_one_type (type);
674 switch (TREE_CODE (decl))
676 case CONST_DECL:
677 /* Enum values are defined by defining the enum type. */
678 return;
680 case FUNCTION_DECL:
681 /* Don't mention a nested function under its parent. */
682 context = decl_function_context (decl);
683 if (context == current_function_decl)
684 return;
685 /* Check DECL_INITIAL to distinguish declarations from definitions.
686 Don't output debug info here for declarations; they will have
687 a DECL_INITIAL value of 0. */
688 if (! DECL_INITIAL (decl))
689 return;
690 if (!MEM_P (DECL_RTL (decl))
691 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
692 return;
693 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
694 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
695 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
696 break;
698 case TYPE_DECL:
699 /* Done with tagged types. */
700 if (DECL_NAME (decl) == 0)
701 return;
702 if (DECL_IGNORED_P (decl))
703 return;
704 /* Don't output intrinsic types. GAS chokes on SDB .def
705 statements that contain identifiers with embedded spaces
706 (eg "unsigned long"). */
707 if (DECL_IS_BUILTIN (decl))
708 return;
710 /* Output typedef name. */
711 if (template_name_p (DECL_NAME (decl)))
712 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
713 else
714 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
715 PUT_SDB_SCL (C_TPDEF);
716 break;
718 case PARM_DECL:
719 /* Parm decls go in their own separate chains
720 and are output by sdbout_reg_parms and sdbout_parms. */
721 gcc_unreachable ();
723 case VAR_DECL:
724 /* Don't mention a variable that is external.
725 Let the file that defines it describe it. */
726 if (DECL_EXTERNAL (decl))
727 return;
729 /* Ignore __FUNCTION__, etc. */
730 if (DECL_IGNORED_P (decl))
731 return;
733 /* If there was an error in the declaration, don't dump core
734 if there is no RTL associated with the variable doesn't
735 exist. */
736 if (!DECL_RTL_SET_P (decl))
737 return;
739 value = DECL_RTL (decl);
741 if (!is_global_var (decl))
742 value = eliminate_regs (value, VOIDmode, NULL_RTX);
744 SET_DECL_RTL (decl, value);
745 #ifdef LEAF_REG_REMAP
746 if (crtl->uses_only_leaf_regs)
747 leaf_renumber_regs_insn (value);
748 #endif
750 /* Don't mention a variable at all
751 if it was completely optimized into nothingness.
753 If DECL was from an inline function, then its rtl
754 is not identically the rtl that was used in this
755 particular compilation. */
756 if (REG_P (value))
758 regno = REGNO (value);
759 if (regno >= FIRST_PSEUDO_REGISTER)
760 return;
762 else if (GET_CODE (value) == SUBREG)
764 while (GET_CODE (value) == SUBREG)
765 value = SUBREG_REG (value);
766 if (REG_P (value))
768 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
769 return;
771 regno = REGNO (alter_subreg (&value, true));
772 SET_DECL_RTL (decl, value);
774 /* Don't output anything if an auto variable
775 gets RTL that is static.
776 GAS version 2.2 can't handle such output. */
777 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
778 && ! TREE_STATIC (decl))
779 return;
781 /* Emit any structure, union, or enum type that has not been output.
782 This occurs for tag-less structs (et al) used to declare variables
783 within functions. */
784 if (TREE_CODE (type) == ENUMERAL_TYPE
785 || TREE_CODE (type) == RECORD_TYPE
786 || TREE_CODE (type) == UNION_TYPE
787 || TREE_CODE (type) == QUAL_UNION_TYPE)
789 if (COMPLETE_TYPE_P (type) /* not a forward reference */
790 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
791 sdbout_one_type (type);
794 /* Defer SDB information for top-level initialized variables! */
795 if (! local
796 && MEM_P (value)
797 && DECL_INITIAL (decl))
798 return;
800 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
801 For now, avoid crashing. */
802 if (DECL_NAME (decl) == NULL_TREE)
803 return;
805 /* Record the name for, starting a symtab entry. */
806 if (local)
807 name = IDENTIFIER_POINTER (DECL_NAME (decl));
808 else
809 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
811 if (MEM_P (value)
812 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
814 PUT_SDB_DEF (name);
815 if (TREE_PUBLIC (decl))
817 PUT_SDB_VAL (XEXP (value, 0));
818 PUT_SDB_SCL (C_EXT);
820 else
822 PUT_SDB_VAL (XEXP (value, 0));
823 PUT_SDB_SCL (C_STAT);
826 else if (regno >= 0)
828 PUT_SDB_DEF (name);
829 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
830 PUT_SDB_SCL (C_REG);
832 else if (MEM_P (value)
833 && (MEM_P (XEXP (value, 0))
834 || (REG_P (XEXP (value, 0))
835 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
836 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
837 /* If the value is indirect by memory or by a register
838 that isn't the frame pointer
839 then it means the object is variable-sized and address through
840 that register or stack slot. COFF has no way to represent this
841 so all we can do is output the variable as a pointer. */
843 PUT_SDB_DEF (name);
844 if (REG_P (XEXP (value, 0)))
846 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
847 PUT_SDB_SCL (C_REG);
849 else
851 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
852 (CONST_INT...)))).
853 We want the value of that CONST_INT. */
854 /* Encore compiler hates a newline in a macro arg, it seems. */
855 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
856 (XEXP (XEXP (value, 0), 0)));
857 PUT_SDB_SCL (C_AUTO);
860 /* Effectively do build_pointer_type, but don't cache this type,
861 since it might be temporary whereas the type it points to
862 might have been saved for inlining. */
863 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
864 type = make_node (POINTER_TYPE);
865 TREE_TYPE (type) = TREE_TYPE (decl);
867 else if (MEM_P (value)
868 && ((GET_CODE (XEXP (value, 0)) == PLUS
869 && REG_P (XEXP (XEXP (value, 0), 0))
870 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
871 /* This is for variables which are at offset zero from
872 the frame pointer. This happens on the Alpha.
873 Non-frame pointer registers are excluded above. */
874 || (REG_P (XEXP (value, 0)))))
876 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
877 or (MEM (REG...)). We want the value of that CONST_INT
878 or zero. */
879 PUT_SDB_DEF (name);
880 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
881 PUT_SDB_SCL (C_AUTO);
883 else
885 /* It is something we don't know how to represent for SDB. */
886 return;
888 break;
890 default:
891 break;
893 PUT_SDB_TYPE (plain_type (type));
894 PUT_SDB_ENDEF;
897 /* Output SDB information for a top-level initialized variable
898 that has been delayed. */
900 static void
901 sdbout_toplevel_data (tree decl)
903 tree type = TREE_TYPE (decl);
905 if (DECL_IGNORED_P (decl))
906 return;
908 gcc_assert (TREE_CODE (decl) == VAR_DECL);
909 gcc_assert (MEM_P (DECL_RTL (decl)));
910 gcc_assert (DECL_INITIAL (decl));
912 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
913 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
914 if (TREE_PUBLIC (decl))
916 PUT_SDB_SCL (C_EXT);
918 else
920 PUT_SDB_SCL (C_STAT);
922 PUT_SDB_TYPE (plain_type (type));
923 PUT_SDB_ENDEF;
926 #ifdef SDB_ALLOW_FORWARD_REFERENCES
928 /* Machinery to record and output anonymous types. */
930 static void
931 sdbout_queue_anonymous_type (tree type)
933 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
936 static void
937 sdbout_dequeue_anonymous_types (void)
939 tree types, link;
941 while (anonymous_types)
943 types = nreverse (anonymous_types);
944 anonymous_types = NULL_TREE;
946 for (link = types; link; link = TREE_CHAIN (link))
948 tree type = TREE_VALUE (link);
950 if (type && ! TREE_ASM_WRITTEN (type))
951 sdbout_one_type (type);
956 #endif
958 /* Given a chain of ..._TYPE nodes, all of which have names,
959 output definitions of those names, as typedefs. */
961 void
962 sdbout_types (tree types)
964 tree link;
966 for (link = types; link; link = TREE_CHAIN (link))
967 sdbout_one_type (link);
969 #ifdef SDB_ALLOW_FORWARD_REFERENCES
970 sdbout_dequeue_anonymous_types ();
971 #endif
974 static void
975 sdbout_type (tree type)
977 if (type == error_mark_node)
978 type = integer_type_node;
979 PUT_SDB_TYPE (plain_type (type));
982 /* Output types of the fields of type TYPE, if they are structs.
984 Formerly did not chase through pointer types, since that could be circular.
985 They must come before TYPE, since forward refs are not allowed.
986 Now james@bigtex.cactus.org says to try them. */
988 static void
989 sdbout_field_types (tree type)
991 tree tail;
993 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
994 /* This condition should match the one for emitting the actual
995 members below. */
996 if (TREE_CODE (tail) == FIELD_DECL
997 && DECL_NAME (tail)
998 && DECL_SIZE (tail)
999 && tree_fits_uhwi_p (DECL_SIZE (tail))
1000 && tree_fits_shwi_p (bit_position (tail)))
1002 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1003 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1004 else
1005 sdbout_one_type (TREE_TYPE (tail));
1009 /* Use this to put out the top level defined record and union types
1010 for later reference. If this is a struct with a name, then put that
1011 name out. Other unnamed structs will have .xxfake labels generated so
1012 that they may be referred to later.
1013 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1014 It may NOT be called recursively. */
1016 static void
1017 sdbout_one_type (tree type)
1019 if (current_function_decl != NULL_TREE
1020 && DECL_SECTION_NAME (current_function_decl) != NULL)
1021 ; /* Don't change section amid function. */
1022 else
1023 switch_to_section (current_function_section ());
1025 switch (TREE_CODE (type))
1027 case RECORD_TYPE:
1028 case UNION_TYPE:
1029 case QUAL_UNION_TYPE:
1030 case ENUMERAL_TYPE:
1031 type = TYPE_MAIN_VARIANT (type);
1032 /* Don't output a type twice. */
1033 if (TREE_ASM_WRITTEN (type))
1034 /* James said test TREE_ASM_BEING_WRITTEN here. */
1035 return;
1037 /* Output nothing if type is not yet defined. */
1038 if (!COMPLETE_TYPE_P (type))
1039 return;
1041 TREE_ASM_WRITTEN (type) = 1;
1043 /* This is reputed to cause trouble with the following case,
1044 but perhaps checking TYPE_SIZE above will fix it. */
1046 /* Here is a testcase:
1048 struct foo {
1049 struct badstr *bbb;
1050 } forwardref;
1052 typedef struct intermediate {
1053 int aaaa;
1054 } intermediate_ref;
1056 typedef struct badstr {
1057 int ccccc;
1058 } badtype; */
1060 /* This change, which ought to make better output,
1061 used to make the COFF assembler unhappy.
1062 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1063 /* Before really doing anything, output types we want to refer to. */
1064 /* Note that in version 1 the following two lines
1065 are not used if forward references are in use. */
1066 if (TREE_CODE (type) != ENUMERAL_TYPE)
1067 sdbout_field_types (type);
1069 /* Output a structure type. */
1071 int size = int_size_in_bytes (type);
1072 int member_scl = 0;
1073 tree tem;
1075 /* Record the type tag, but not in its permanent place just yet. */
1076 sdbout_record_type_name (type);
1078 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1080 switch (TREE_CODE (type))
1082 case UNION_TYPE:
1083 case QUAL_UNION_TYPE:
1084 PUT_SDB_SCL (C_UNTAG);
1085 PUT_SDB_TYPE (T_UNION);
1086 member_scl = C_MOU;
1087 break;
1089 case RECORD_TYPE:
1090 PUT_SDB_SCL (C_STRTAG);
1091 PUT_SDB_TYPE (T_STRUCT);
1092 member_scl = C_MOS;
1093 break;
1095 case ENUMERAL_TYPE:
1096 PUT_SDB_SCL (C_ENTAG);
1097 PUT_SDB_TYPE (T_ENUM);
1098 member_scl = C_MOE;
1099 break;
1101 default:
1102 break;
1105 PUT_SDB_SIZE (size);
1106 PUT_SDB_ENDEF;
1108 /* Print out the base class information with fields
1109 named after the types they hold. */
1110 /* This is only relevant to aggregate types. TYPE_BINFO is used
1111 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1112 case. */
1113 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1115 int i;
1116 tree binfo, child;
1118 for (binfo = TYPE_BINFO (type), i = 0;
1119 BINFO_BASE_ITERATE (binfo, i, child); i++)
1121 tree child_type = BINFO_TYPE (child);
1122 tree child_type_name;
1124 if (TYPE_NAME (child_type) == 0)
1125 continue;
1126 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1127 child_type_name = TYPE_NAME (child_type);
1128 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1130 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1131 if (child_type_name && template_name_p (child_type_name))
1132 child_type_name
1133 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1135 else
1136 continue;
1138 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1139 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1140 PUT_SDB_SCL (member_scl);
1141 sdbout_type (BINFO_TYPE (child));
1142 PUT_SDB_ENDEF;
1146 /* Output the individual fields. */
1148 if (TREE_CODE (type) == ENUMERAL_TYPE)
1150 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1152 tree value = TREE_VALUE (tem);
1154 if (TREE_CODE (value) == CONST_DECL)
1155 value = DECL_INITIAL (value);
1157 if (tree_fits_shwi_p (value))
1159 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1160 PUT_SDB_INT_VAL (tree_to_shwi (value));
1161 PUT_SDB_SCL (C_MOE);
1162 PUT_SDB_TYPE (T_MOE);
1163 PUT_SDB_ENDEF;
1167 else /* record or union type */
1168 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1169 /* Output the name, type, position (in bits), size (in bits)
1170 of each field. */
1172 /* Omit here the nameless fields that are used to skip bits.
1173 Also omit fields with variable size or position.
1174 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1175 if (TREE_CODE (tem) == FIELD_DECL
1176 && DECL_NAME (tem)
1177 && DECL_SIZE (tem)
1178 && tree_fits_uhwi_p (DECL_SIZE (tem))
1179 && tree_fits_shwi_p (bit_position (tem)))
1181 const char *name;
1183 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1184 PUT_SDB_DEF (name);
1185 if (DECL_BIT_FIELD_TYPE (tem))
1187 PUT_SDB_INT_VAL (int_bit_position (tem));
1188 PUT_SDB_SCL (C_FIELD);
1189 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1190 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1192 else
1194 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1195 PUT_SDB_SCL (member_scl);
1196 sdbout_type (TREE_TYPE (tem));
1198 PUT_SDB_ENDEF;
1200 /* Output end of a structure,union, or enumeral definition. */
1202 PUT_SDB_PLAIN_DEF ("eos");
1203 PUT_SDB_INT_VAL (size);
1204 PUT_SDB_SCL (C_EOS);
1205 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1206 PUT_SDB_SIZE (size);
1207 PUT_SDB_ENDEF;
1208 break;
1211 default:
1212 break;
1216 /* The following two functions output definitions of function parameters.
1217 Each parameter gets a definition locating it in the parameter list.
1218 Each parameter that is a register variable gets a second definition
1219 locating it in the register.
1221 Printing or argument lists in gdb uses the definitions that
1222 locate in the parameter list. But reference to the variable in
1223 expressions uses preferentially the definition as a register. */
1225 /* Output definitions, referring to storage in the parmlist,
1226 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1228 static void
1229 sdbout_parms (tree parms)
1231 for (; parms; parms = TREE_CHAIN (parms))
1232 if (DECL_NAME (parms)
1233 && TREE_TYPE (parms) != error_mark_node
1234 && DECL_RTL_SET_P (parms)
1235 && DECL_INCOMING_RTL (parms))
1237 int current_sym_value = 0;
1238 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1240 if (name == 0 || *name == 0)
1241 name = gen_fake_label ();
1243 /* Perform any necessary register eliminations on the parameter's rtl,
1244 so that the debugging output will be accurate. */
1245 DECL_INCOMING_RTL (parms)
1246 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1247 SET_DECL_RTL (parms,
1248 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1250 if (PARM_PASSED_IN_MEMORY (parms))
1252 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1253 tree type;
1255 /* ??? Here we assume that the parm address is indexed
1256 off the frame pointer or arg pointer.
1257 If that is not true, we produce meaningless results,
1258 but do not crash. */
1259 if (GET_CODE (addr) == PLUS
1260 && CONST_INT_P (XEXP (addr, 1)))
1261 current_sym_value = INTVAL (XEXP (addr, 1));
1262 else
1263 current_sym_value = 0;
1265 if (REG_P (DECL_RTL (parms))
1266 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1267 type = DECL_ARG_TYPE (parms);
1268 else
1270 int original_sym_value = current_sym_value;
1272 /* This is the case where the parm is passed as an int or
1273 double and it is converted to a char, short or float
1274 and stored back in the parmlist. In this case, describe
1275 the parm with the variable's declared type, and adjust
1276 the address if the least significant bytes (which we are
1277 using) are not the first ones. */
1278 if (BYTES_BIG_ENDIAN
1279 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1280 current_sym_value +=
1281 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1282 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1284 if (MEM_P (DECL_RTL (parms))
1285 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1286 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1287 == CONST_INT)
1288 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1289 == current_sym_value))
1290 type = TREE_TYPE (parms);
1291 else
1293 current_sym_value = original_sym_value;
1294 type = DECL_ARG_TYPE (parms);
1298 PUT_SDB_DEF (name);
1299 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1300 PUT_SDB_SCL (C_ARG);
1301 PUT_SDB_TYPE (plain_type (type));
1302 PUT_SDB_ENDEF;
1304 else if (REG_P (DECL_RTL (parms)))
1306 rtx best_rtl;
1307 /* Parm passed in registers and lives in registers or nowhere. */
1309 /* If parm lives in a register, use that register;
1310 pretend the parm was passed there. It would be more consistent
1311 to describe the register where the parm was passed,
1312 but in practice that register usually holds something else. */
1313 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1314 best_rtl = DECL_RTL (parms);
1315 /* If the parm lives nowhere,
1316 use the register where it was passed. */
1317 else
1318 best_rtl = DECL_INCOMING_RTL (parms);
1320 PUT_SDB_DEF (name);
1321 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1322 PUT_SDB_SCL (C_REGPARM);
1323 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1324 PUT_SDB_ENDEF;
1326 else if (MEM_P (DECL_RTL (parms))
1327 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1329 /* Parm was passed in registers but lives on the stack. */
1331 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1332 in which case we want the value of that CONST_INT,
1333 or (MEM (REG ...)) or (MEM (MEM ...)),
1334 in which case we use a value of zero. */
1335 if (REG_P (XEXP (DECL_RTL (parms), 0))
1336 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1337 current_sym_value = 0;
1338 else
1339 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1341 /* Again, this assumes the offset is based on the arg pointer. */
1342 PUT_SDB_DEF (name);
1343 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1344 XEXP (DECL_RTL (parms), 0)));
1345 PUT_SDB_SCL (C_ARG);
1346 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1347 PUT_SDB_ENDEF;
1352 /* Output definitions for the places where parms live during the function,
1353 when different from where they were passed, when the parms were passed
1354 in memory.
1356 It is not useful to do this for parms passed in registers
1357 that live during the function in different registers, because it is
1358 impossible to look in the passed register for the passed value,
1359 so we use the within-the-function register to begin with.
1361 PARMS is a chain of PARM_DECL nodes. */
1363 static void
1364 sdbout_reg_parms (tree parms)
1366 for (; parms; parms = TREE_CHAIN (parms))
1367 if (DECL_NAME (parms)
1368 && TREE_TYPE (parms) != error_mark_node
1369 && DECL_RTL_SET_P (parms)
1370 && DECL_INCOMING_RTL (parms))
1372 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1374 /* Report parms that live in registers during the function
1375 but were passed in memory. */
1376 if (REG_P (DECL_RTL (parms))
1377 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1378 && PARM_PASSED_IN_MEMORY (parms))
1380 if (name == 0 || *name == 0)
1381 name = gen_fake_label ();
1382 PUT_SDB_DEF (name);
1383 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1384 PUT_SDB_SCL (C_REG);
1385 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1386 PUT_SDB_ENDEF;
1388 /* Report parms that live in memory but not where they were passed. */
1389 else if (MEM_P (DECL_RTL (parms))
1390 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1391 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1392 && PARM_PASSED_IN_MEMORY (parms)
1393 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1395 #if 0 /* ??? It is not clear yet what should replace this. */
1396 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1397 /* A parm declared char is really passed as an int,
1398 so it occupies the least significant bytes.
1399 On a big-endian machine those are not the low-numbered ones. */
1400 if (BYTES_BIG_ENDIAN
1401 && offset != -1
1402 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1403 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1404 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1405 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1406 #endif
1408 if (name == 0 || *name == 0)
1409 name = gen_fake_label ();
1410 PUT_SDB_DEF (name);
1411 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1412 (XEXP (DECL_RTL (parms), 0)));
1413 PUT_SDB_SCL (C_AUTO);
1414 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1415 PUT_SDB_ENDEF;
1421 /* Output early debug information for a global DECL. Called from
1422 rest_of_decl_compilation during parsing. */
1424 static void
1425 sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1427 /* NYI for non-dwarf. */
1430 /* Output late debug information for a global DECL after location
1431 information is available. */
1433 static void
1434 sdbout_late_global_decl (tree decl)
1436 if (TREE_CODE (decl) == VAR_DECL
1437 && !DECL_EXTERNAL (decl)
1438 && DECL_RTL_SET_P (decl))
1440 /* The COFF linker can move initialized global vars to the end.
1441 And that can screw up the symbol ordering. Defer those for
1442 sdbout_finish (). */
1443 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1444 sdbout_symbol (decl, 0);
1445 else
1446 vec_safe_push (deferred_global_decls, decl);
1448 /* Output COFF information for non-global file-scope initialized
1449 variables. */
1450 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1451 sdbout_toplevel_data (decl);
1455 /* Output initialized global vars at the end, in the order of
1456 definition. See comment in sdbout_global_decl. */
1458 static void
1459 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1461 size_t i;
1462 tree decl;
1464 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1465 sdbout_symbol (decl, 0);
1468 /* Describe the beginning of an internal block within a function.
1469 Also output descriptions of variables defined in this block.
1471 N is the number of the block, by order of beginning, counting from 1,
1472 and not counting the outermost (function top-level) block.
1473 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1474 if the count starts at 0 for the outermost one. */
1476 static void
1477 sdbout_begin_block (unsigned int line, unsigned int n)
1479 tree decl = current_function_decl;
1480 MAKE_LINE_SAFE (line);
1482 /* The SCO compiler does not emit a separate block for the function level
1483 scope, so we avoid it here also. */
1484 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1486 if (n == 1)
1488 /* Include the outermost BLOCK's variables in block 1. */
1489 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1490 sdbout_block (DECL_INITIAL (decl));
1492 /* If -g1, suppress all the internal symbols of functions
1493 except for arguments. */
1494 if (debug_info_level != DINFO_LEVEL_TERSE)
1496 do_block = n;
1497 sdbout_block (DECL_INITIAL (decl));
1500 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1501 sdbout_dequeue_anonymous_types ();
1502 #endif
1505 /* Describe the end line-number of an internal block within a function. */
1507 static void
1508 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1510 MAKE_LINE_SAFE (line);
1512 /* The SCO compiler does not emit a separate block for the function level
1513 scope, so we avoid it here also. */
1514 if (n != 1)
1515 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1518 /* Output a line number symbol entry for source file FILENAME and line
1519 number LINE. */
1521 static void
1522 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1523 int discriminator ATTRIBUTE_UNUSED,
1524 bool is_stmt ATTRIBUTE_UNUSED)
1526 /* COFF relative line numbers must be positive. */
1527 if ((int) line > sdb_begin_function_line)
1529 #ifdef SDB_OUTPUT_SOURCE_LINE
1530 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1531 #else
1532 fprintf (asm_out_file, "\t.ln\t%d\n",
1533 ((sdb_begin_function_line > -1)
1534 ? line - sdb_begin_function_line : 1));
1535 #endif
1539 /* Output sdb info for the current function name.
1540 Called from assemble_start_function. */
1542 static void
1543 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1545 sdbout_symbol (current_function_decl, 0);
1548 /* Called at beginning of function body after prologue. Record the
1549 function's starting line number, so we can output relative line numbers
1550 for the other lines. Describe beginning of outermost block. Also
1551 describe the parameter list. */
1553 static void
1554 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1556 sdbout_end_prologue (line, file);
1559 static void
1560 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1562 sdb_begin_function_line = line - 1;
1563 PUT_SDB_FUNCTION_START (line);
1564 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1565 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1568 /* Called at end of function (before epilogue).
1569 Describe end of outermost block. */
1571 static void
1572 sdbout_end_function (unsigned int line)
1574 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1575 sdbout_dequeue_anonymous_types ();
1576 #endif
1578 MAKE_LINE_SAFE (line);
1579 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1581 /* Indicate we are between functions, for line-number output. */
1582 sdb_begin_function_line = -1;
1585 /* Output sdb info for the absolute end of a function.
1586 Called after the epilogue is output. */
1588 static void
1589 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1590 const char *file ATTRIBUTE_UNUSED)
1592 const char *const name ATTRIBUTE_UNUSED
1593 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1595 #ifdef PUT_SDB_EPILOGUE_END
1596 PUT_SDB_EPILOGUE_END (name);
1597 #else
1598 fprintf (asm_out_file, "\t.def\t");
1599 assemble_name (asm_out_file, name);
1600 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1601 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1602 #endif
1605 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1606 is present. */
1608 static void
1609 sdbout_label (rtx_code_label *insn)
1611 PUT_SDB_DEF (LABEL_NAME (insn));
1612 PUT_SDB_VAL (insn);
1613 PUT_SDB_SCL (C_LABEL);
1614 PUT_SDB_TYPE (T_NULL);
1615 PUT_SDB_ENDEF;
1618 /* Change to reading from a new source file. */
1620 static void
1621 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1622 const char *filename ATTRIBUTE_UNUSED)
1626 /* Revert to reading a previous source file. */
1628 static void
1629 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1633 /* Set up for SDB output at the start of compilation. */
1635 static void
1636 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1638 tree t;
1640 vec_alloc (deferred_global_decls, 12);
1642 /* Emit debug information which was queued by sdbout_symbol before
1643 we got here. */
1644 sdbout_initialized = true;
1646 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1647 sdbout_symbol (TREE_VALUE (t), 0);
1648 preinit_symbols = 0;
1651 #include "gt-sdbout.h"