[PR67828] don't unswitch on default defs of non-parms
[official-gcc.git] / gcc / sdbout.c
blobba7e9f998ee7bfd6e78c07e7ab958cf6802a15fb
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 "tm.h"
46 #include "debug.h"
47 #include "alias.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 #ifdef SDB_DEBUGGING_INFO
71 #include "rtl.h"
72 #include "regs.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 "gsyms.h"
80 #include "langhooks.h"
81 #include "target.h"
83 /* 1 if PARM is passed to this function in memory. */
85 #define PARM_PASSED_IN_MEMORY(PARM) \
86 (MEM_P (DECL_INCOMING_RTL (PARM)))
88 /* A C expression for the integer offset value of an automatic variable
89 (C_AUTO) having address X (an RTX). */
90 #ifndef DEBUGGER_AUTO_OFFSET
91 #define DEBUGGER_AUTO_OFFSET(X) \
92 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
93 #endif
95 /* A C expression for the integer offset value of an argument (C_ARG)
96 having address X (an RTX). The nominal offset is OFFSET. */
97 #ifndef DEBUGGER_ARG_OFFSET
98 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
99 #endif
101 /* Line number of beginning of current function, minus one.
102 Negative means not in a function or not using sdb. */
104 int sdb_begin_function_line = -1;
107 extern FILE *asm_out_file;
109 extern tree current_function_decl;
111 #include "sdbout.h"
113 static void sdbout_init (const char *);
114 static void sdbout_finish (const char *);
115 static void sdbout_start_source_file (unsigned int, const char *);
116 static void sdbout_end_source_file (unsigned int);
117 static void sdbout_begin_block (unsigned int, unsigned int);
118 static void sdbout_end_block (unsigned int, unsigned int);
119 static void sdbout_source_line (unsigned int, const char *, int, bool);
120 static void sdbout_end_epilogue (unsigned int, const char *);
121 static void sdbout_early_global_decl (tree);
122 static void sdbout_late_global_decl (tree);
123 static void sdbout_begin_prologue (unsigned int, const char *);
124 static void sdbout_end_prologue (unsigned int, const char *);
125 static void sdbout_begin_function (tree);
126 static void sdbout_end_function (unsigned int);
127 static void sdbout_toplevel_data (tree);
128 static void sdbout_label (rtx_code_label *);
129 static char *gen_fake_label (void);
130 static int plain_type (tree);
131 static int template_name_p (tree);
132 static void sdbout_record_type_name (tree);
133 static int plain_type_1 (tree, int);
134 static void sdbout_block (tree);
135 static void sdbout_syms (tree);
136 #ifdef SDB_ALLOW_FORWARD_REFERENCES
137 static void sdbout_queue_anonymous_type (tree);
138 static void sdbout_dequeue_anonymous_types (void);
139 #endif
140 static void sdbout_type (tree);
141 static void sdbout_field_types (tree);
142 static void sdbout_one_type (tree);
143 static void sdbout_parms (tree);
144 static void sdbout_reg_parms (tree);
146 /* Random macros describing parts of SDB data. */
148 /* Default value of delimiter is ";". */
149 #ifndef SDB_DELIM
150 #define SDB_DELIM ";"
151 #endif
153 /* Maximum number of dimensions the assembler will allow. */
154 #ifndef SDB_MAX_DIM
155 #define SDB_MAX_DIM 4
156 #endif
158 #ifndef PUT_SDB_SCL
159 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
160 #endif
162 #ifndef PUT_SDB_INT_VAL
163 #define PUT_SDB_INT_VAL(a) \
164 do { \
165 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
166 (HOST_WIDE_INT) (a), SDB_DELIM); \
167 } while (0)
169 #endif
171 #ifndef PUT_SDB_VAL
172 #define PUT_SDB_VAL(a) \
173 ( fputs ("\t.val\t", asm_out_file), \
174 output_addr_const (asm_out_file, (a)), \
175 fprintf (asm_out_file, SDB_DELIM))
176 #endif
178 #ifndef PUT_SDB_DEF
179 #define PUT_SDB_DEF(a) \
180 do { fprintf (asm_out_file, "\t.def\t"); \
181 assemble_name (asm_out_file, a); \
182 fprintf (asm_out_file, SDB_DELIM); } while (0)
183 #endif
185 #ifndef PUT_SDB_PLAIN_DEF
186 #define PUT_SDB_PLAIN_DEF(a) \
187 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
188 #endif
190 #ifndef PUT_SDB_ENDEF
191 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
192 #endif
194 #ifndef PUT_SDB_TYPE
195 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
196 #endif
198 #ifndef PUT_SDB_SIZE
199 #define PUT_SDB_SIZE(a) \
200 do { \
201 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
202 (HOST_WIDE_INT) (a), SDB_DELIM); \
203 } while (0)
204 #endif
206 #ifndef PUT_SDB_START_DIM
207 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
208 #endif
210 #ifndef PUT_SDB_NEXT_DIM
211 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
212 #endif
214 #ifndef PUT_SDB_LAST_DIM
215 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
216 #endif
218 #ifndef PUT_SDB_TAG
219 #define PUT_SDB_TAG(a) \
220 do { fprintf (asm_out_file, "\t.tag\t"); \
221 assemble_name (asm_out_file, a); \
222 fprintf (asm_out_file, SDB_DELIM); } while (0)
223 #endif
225 #ifndef PUT_SDB_BLOCK_START
226 #define PUT_SDB_BLOCK_START(LINE) \
227 fprintf (asm_out_file, \
228 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
229 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
230 #endif
232 #ifndef PUT_SDB_BLOCK_END
233 #define PUT_SDB_BLOCK_END(LINE) \
234 fprintf (asm_out_file, \
235 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
236 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
237 #endif
239 #ifndef PUT_SDB_FUNCTION_START
240 #define PUT_SDB_FUNCTION_START(LINE) \
241 fprintf (asm_out_file, \
242 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
243 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
244 #endif
246 #ifndef PUT_SDB_FUNCTION_END
247 #define PUT_SDB_FUNCTION_END(LINE) \
248 fprintf (asm_out_file, \
249 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
250 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
251 #endif
253 /* Return the sdb tag identifier string for TYPE
254 if TYPE has already been defined; otherwise return a null pointer. */
256 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
258 /* Set the sdb tag identifier string for TYPE to NAME. */
260 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
261 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
263 /* Return the name (a string) of the struct, union or enum tag
264 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
266 #define TAG_NAME(link) \
267 (((link) && TREE_PURPOSE ((link)) \
268 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
269 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
271 /* Ensure we don't output a negative line number. */
272 #define MAKE_LINE_SAFE(line) \
273 if ((int) line <= sdb_begin_function_line) \
274 line = sdb_begin_function_line + 1
276 /* The debug hooks structure. */
277 const struct gcc_debug_hooks sdb_debug_hooks =
279 sdbout_init, /* init */
280 sdbout_finish, /* finish */
281 debug_nothing_void, /* early_finish */
282 debug_nothing_void, /* assembly_start */
283 debug_nothing_int_charstar, /* define */
284 debug_nothing_int_charstar, /* undef */
285 sdbout_start_source_file, /* start_source_file */
286 sdbout_end_source_file, /* end_source_file */
287 sdbout_begin_block, /* begin_block */
288 sdbout_end_block, /* end_block */
289 debug_true_const_tree, /* ignore_block */
290 sdbout_source_line, /* source_line */
291 sdbout_begin_prologue, /* begin_prologue */
292 debug_nothing_int_charstar, /* end_prologue */
293 debug_nothing_int_charstar, /* begin_epilogue */
294 sdbout_end_epilogue, /* end_epilogue */
295 sdbout_begin_function, /* begin_function */
296 sdbout_end_function, /* end_function */
297 debug_nothing_tree, /* register_main_translation_unit */
298 debug_nothing_tree, /* function_decl */
299 sdbout_early_global_decl, /* early_global_decl */
300 sdbout_late_global_decl, /* late_global_decl */
301 sdbout_symbol, /* type_decl */
302 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
303 debug_nothing_tree, /* deferred_inline_function */
304 debug_nothing_tree, /* outlining_inline_function */
305 sdbout_label, /* label */
306 debug_nothing_int, /* handle_pch */
307 debug_nothing_rtx_insn, /* var_location */
308 debug_nothing_void, /* switch_text_section */
309 debug_nothing_tree_tree, /* set_name */
310 0, /* start_end_main_source_file */
311 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
314 /* Return a unique string to name an anonymous type. */
316 static char *
317 gen_fake_label (void)
319 char label[10];
320 char *labelstr;
321 sprintf (label, ".%dfake", unnamed_struct_number);
322 unnamed_struct_number++;
323 labelstr = xstrdup (label);
324 return labelstr;
327 /* Return the number which describes TYPE for SDB.
328 For pointers, etc., this function is recursive.
329 Each record, union or enumeral type must already have had a
330 tag number output. */
332 /* The number is given by d6d5d4d3d2d1bbbb
333 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
334 Thus, char *foo () has bbbb=T_CHAR
335 d1=D_FCN
336 d2=D_PTR
337 N_BTMASK= 017 1111 basic type field.
338 N_TSHIFT= 2 derived type shift
339 N_BTSHFT= 4 Basic type shift */
341 /* Produce the number that describes a pointer, function or array type.
342 PREV is the number describing the target, value or element type.
343 DT_type describes how to transform that type. */
344 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
345 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
346 | ((int) DT_type << (int) N_BTSHFT) \
347 | ((PREV) & (int) N_BTMASK))
349 /* Number of elements used in sdb_dims. */
350 static int sdb_n_dims = 0;
352 /* Table of array dimensions of current type. */
353 static int sdb_dims[SDB_MAX_DIM];
355 /* Size of outermost array currently being processed. */
356 static int sdb_type_size = -1;
358 static int
359 plain_type (tree type)
361 int val = plain_type_1 (type, 0);
363 /* If we have already saved up some array dimensions, print them now. */
364 if (sdb_n_dims > 0)
366 int i;
367 PUT_SDB_START_DIM;
368 for (i = sdb_n_dims - 1; i > 0; i--)
369 PUT_SDB_NEXT_DIM (sdb_dims[i]);
370 PUT_SDB_LAST_DIM (sdb_dims[0]);
371 sdb_n_dims = 0;
373 sdb_type_size = int_size_in_bytes (type);
374 /* Don't kill sdb if type is not laid out or has variable size. */
375 if (sdb_type_size < 0)
376 sdb_type_size = 0;
378 /* If we have computed the size of an array containing this type,
379 print it now. */
380 if (sdb_type_size >= 0)
382 PUT_SDB_SIZE (sdb_type_size);
383 sdb_type_size = -1;
385 return val;
388 static int
389 template_name_p (tree name)
391 const char *ptr = IDENTIFIER_POINTER (name);
392 while (*ptr && *ptr != '<')
393 ptr++;
395 return *ptr != '\0';
398 static void
399 sdbout_record_type_name (tree type)
401 const char *name = 0;
402 int no_name;
404 if (KNOWN_TYPE_TAG (type))
405 return;
407 if (TYPE_NAME (type) != 0)
409 tree t = 0;
411 /* Find the IDENTIFIER_NODE for the type name. */
412 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
413 t = TYPE_NAME (type);
414 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
416 t = DECL_NAME (TYPE_NAME (type));
417 /* The DECL_NAME for templates includes "<>", which breaks
418 most assemblers. Use its assembler name instead, which
419 has been mangled into being safe. */
420 if (t && template_name_p (t))
421 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
424 /* Now get the name as a string, or invent one. */
425 if (t != NULL_TREE)
426 name = IDENTIFIER_POINTER (t);
429 no_name = (name == 0 || *name == 0);
430 if (no_name)
431 name = gen_fake_label ();
433 SET_KNOWN_TYPE_TAG (type, name);
434 #ifdef SDB_ALLOW_FORWARD_REFERENCES
435 if (no_name)
436 sdbout_queue_anonymous_type (type);
437 #endif
440 /* Return the .type value for type TYPE.
442 LEVEL indicates how many levels deep we have recursed into the type.
443 The SDB debug format can only represent 6 derived levels of types.
444 After that, we must output inaccurate debug info. We deliberately
445 stop before the 7th level, so that ADA recursive types will not give an
446 infinite loop. */
448 static int
449 plain_type_1 (tree type, int level)
451 if (type == 0)
452 type = void_type_node;
453 else if (type == error_mark_node)
454 type = integer_type_node;
455 else
456 type = TYPE_MAIN_VARIANT (type);
458 switch (TREE_CODE (type))
460 case VOID_TYPE:
461 case NULLPTR_TYPE:
462 return T_VOID;
463 case BOOLEAN_TYPE:
464 case INTEGER_TYPE:
466 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
468 /* Carefully distinguish all the standard types of C,
469 without messing up if the language is not C.
470 Note that we check only for the names that contain spaces;
471 other names might occur by coincidence in other languages. */
472 if (TYPE_NAME (type) != 0
473 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
474 && DECL_NAME (TYPE_NAME (type)) != 0
475 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
477 const char *const name
478 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
480 if (!strcmp (name, "char"))
481 return T_CHAR;
482 if (!strcmp (name, "unsigned char"))
483 return T_UCHAR;
484 if (!strcmp (name, "signed char"))
485 return T_CHAR;
486 if (!strcmp (name, "int"))
487 return T_INT;
488 if (!strcmp (name, "unsigned int"))
489 return T_UINT;
490 if (!strcmp (name, "short int"))
491 return T_SHORT;
492 if (!strcmp (name, "short unsigned int"))
493 return T_USHORT;
494 if (!strcmp (name, "long int"))
495 return T_LONG;
496 if (!strcmp (name, "long unsigned int"))
497 return T_ULONG;
500 if (size == INT_TYPE_SIZE)
501 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
502 if (size == CHAR_TYPE_SIZE)
503 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
504 if (size == SHORT_TYPE_SIZE)
505 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
506 if (size == LONG_TYPE_SIZE)
507 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
508 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
509 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
510 return 0;
513 case REAL_TYPE:
515 int precision = TYPE_PRECISION (type);
516 if (precision == FLOAT_TYPE_SIZE)
517 return T_FLOAT;
518 if (precision == DOUBLE_TYPE_SIZE)
519 return T_DOUBLE;
520 #ifdef EXTENDED_SDB_BASIC_TYPES
521 if (precision == LONG_DOUBLE_TYPE_SIZE)
522 return T_LNGDBL;
523 #else
524 if (precision == LONG_DOUBLE_TYPE_SIZE)
525 return T_DOUBLE; /* better than nothing */
526 #endif
527 return 0;
530 case ARRAY_TYPE:
532 int m;
533 if (level >= 6)
534 return T_VOID;
535 else
536 m = plain_type_1 (TREE_TYPE (type), level+1);
537 if (sdb_n_dims < SDB_MAX_DIM)
538 sdb_dims[sdb_n_dims++]
539 = (TYPE_DOMAIN (type)
540 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
541 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
542 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
543 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
544 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
545 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
546 : 0);
548 return PUSH_DERIVED_LEVEL (DT_ARY, m);
551 case RECORD_TYPE:
552 case UNION_TYPE:
553 case QUAL_UNION_TYPE:
554 case ENUMERAL_TYPE:
556 const char *tag;
557 #ifdef SDB_ALLOW_FORWARD_REFERENCES
558 sdbout_record_type_name (type);
559 #endif
560 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
561 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
562 #ifdef SDB_ALLOW_FORWARD_REFERENCES
563 || TYPE_MODE (type) != VOIDmode
564 #endif
566 #endif
568 /* Output the referenced structure tag name
569 only if the .def has already been finished.
570 At least on 386, the Unix assembler
571 cannot handle forward references to tags. */
572 /* But the 88100, it requires them, sigh... */
573 /* And the MIPS requires unknown refs as well... */
574 tag = KNOWN_TYPE_TAG (type);
575 PUT_SDB_TAG (tag);
576 /* These 3 lines used to follow the close brace.
577 However, a size of 0 without a tag implies a tag of 0,
578 so if we don't know a tag, we can't mention the size. */
579 sdb_type_size = int_size_in_bytes (type);
580 if (sdb_type_size < 0)
581 sdb_type_size = 0;
583 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
584 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
585 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
586 : T_ENUM);
588 case POINTER_TYPE:
589 case REFERENCE_TYPE:
591 int m;
592 if (level >= 6)
593 return T_VOID;
594 else
595 m = plain_type_1 (TREE_TYPE (type), level+1);
596 return PUSH_DERIVED_LEVEL (DT_PTR, m);
598 case FUNCTION_TYPE:
599 case METHOD_TYPE:
601 int m;
602 if (level >= 6)
603 return T_VOID;
604 else
605 m = plain_type_1 (TREE_TYPE (type), level+1);
606 return PUSH_DERIVED_LEVEL (DT_FCN, m);
608 default:
609 return 0;
613 /* Output the symbols defined in block number DO_BLOCK.
615 This function works by walking the tree structure of blocks,
616 counting blocks until it finds the desired block. */
618 static int do_block = 0;
620 static void
621 sdbout_block (tree block)
623 while (block)
625 /* Ignore blocks never expanded or otherwise marked as real. */
626 if (TREE_USED (block))
628 /* When we reach the specified block, output its symbols. */
629 if (BLOCK_NUMBER (block) == do_block)
630 sdbout_syms (BLOCK_VARS (block));
632 /* If we are past the specified block, stop the scan. */
633 if (BLOCK_NUMBER (block) > do_block)
634 return;
636 /* Scan the blocks within this block. */
637 sdbout_block (BLOCK_SUBBLOCKS (block));
640 block = BLOCK_CHAIN (block);
644 /* Call sdbout_symbol on each decl in the chain SYMS. */
646 static void
647 sdbout_syms (tree syms)
649 while (syms)
651 if (TREE_CODE (syms) != LABEL_DECL)
652 sdbout_symbol (syms, 1);
653 syms = TREE_CHAIN (syms);
657 /* Output SDB information for a symbol described by DECL.
658 LOCAL is nonzero if the symbol is not file-scope. */
660 void
661 sdbout_symbol (tree decl, int local)
663 tree type = TREE_TYPE (decl);
664 tree context = NULL_TREE;
665 rtx value;
666 int regno = -1;
667 const char *name;
669 /* If we are called before sdbout_init is run, just save the symbol
670 for later. */
671 if (!sdbout_initialized)
673 preinit_symbols = tree_cons (0, decl, preinit_symbols);
674 return;
677 sdbout_one_type (type);
679 switch (TREE_CODE (decl))
681 case CONST_DECL:
682 /* Enum values are defined by defining the enum type. */
683 return;
685 case FUNCTION_DECL:
686 /* Don't mention a nested function under its parent. */
687 context = decl_function_context (decl);
688 if (context == current_function_decl)
689 return;
690 /* Check DECL_INITIAL to distinguish declarations from definitions.
691 Don't output debug info here for declarations; they will have
692 a DECL_INITIAL value of 0. */
693 if (! DECL_INITIAL (decl))
694 return;
695 if (!MEM_P (DECL_RTL (decl))
696 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
697 return;
698 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
699 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
700 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
701 break;
703 case TYPE_DECL:
704 /* Done with tagged types. */
705 if (DECL_NAME (decl) == 0)
706 return;
707 if (DECL_IGNORED_P (decl))
708 return;
709 /* Don't output intrinsic types. GAS chokes on SDB .def
710 statements that contain identifiers with embedded spaces
711 (eg "unsigned long"). */
712 if (DECL_IS_BUILTIN (decl))
713 return;
715 /* Output typedef name. */
716 if (template_name_p (DECL_NAME (decl)))
717 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
718 else
719 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
720 PUT_SDB_SCL (C_TPDEF);
721 break;
723 case PARM_DECL:
724 /* Parm decls go in their own separate chains
725 and are output by sdbout_reg_parms and sdbout_parms. */
726 gcc_unreachable ();
728 case VAR_DECL:
729 /* Don't mention a variable that is external.
730 Let the file that defines it describe it. */
731 if (DECL_EXTERNAL (decl))
732 return;
734 /* Ignore __FUNCTION__, etc. */
735 if (DECL_IGNORED_P (decl))
736 return;
738 /* If there was an error in the declaration, don't dump core
739 if there is no RTL associated with the variable doesn't
740 exist. */
741 if (!DECL_RTL_SET_P (decl))
742 return;
744 value = DECL_RTL (decl);
746 if (!is_global_var (decl))
747 value = eliminate_regs (value, VOIDmode, NULL_RTX);
749 SET_DECL_RTL (decl, value);
750 #ifdef LEAF_REG_REMAP
751 if (crtl->uses_only_leaf_regs)
752 leaf_renumber_regs_insn (value);
753 #endif
755 /* Don't mention a variable at all
756 if it was completely optimized into nothingness.
758 If DECL was from an inline function, then its rtl
759 is not identically the rtl that was used in this
760 particular compilation. */
761 if (REG_P (value))
763 regno = REGNO (value);
764 if (regno >= FIRST_PSEUDO_REGISTER)
765 return;
767 else if (GET_CODE (value) == SUBREG)
769 while (GET_CODE (value) == SUBREG)
770 value = SUBREG_REG (value);
771 if (REG_P (value))
773 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
774 return;
776 regno = REGNO (alter_subreg (&value, true));
777 SET_DECL_RTL (decl, value);
779 /* Don't output anything if an auto variable
780 gets RTL that is static.
781 GAS version 2.2 can't handle such output. */
782 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
783 && ! TREE_STATIC (decl))
784 return;
786 /* Emit any structure, union, or enum type that has not been output.
787 This occurs for tag-less structs (et al) used to declare variables
788 within functions. */
789 if (TREE_CODE (type) == ENUMERAL_TYPE
790 || TREE_CODE (type) == RECORD_TYPE
791 || TREE_CODE (type) == UNION_TYPE
792 || TREE_CODE (type) == QUAL_UNION_TYPE)
794 if (COMPLETE_TYPE_P (type) /* not a forward reference */
795 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
796 sdbout_one_type (type);
799 /* Defer SDB information for top-level initialized variables! */
800 if (! local
801 && MEM_P (value)
802 && DECL_INITIAL (decl))
803 return;
805 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
806 For now, avoid crashing. */
807 if (DECL_NAME (decl) == NULL_TREE)
808 return;
810 /* Record the name for, starting a symtab entry. */
811 if (local)
812 name = IDENTIFIER_POINTER (DECL_NAME (decl));
813 else
814 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
816 if (MEM_P (value)
817 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
819 PUT_SDB_DEF (name);
820 if (TREE_PUBLIC (decl))
822 PUT_SDB_VAL (XEXP (value, 0));
823 PUT_SDB_SCL (C_EXT);
825 else
827 PUT_SDB_VAL (XEXP (value, 0));
828 PUT_SDB_SCL (C_STAT);
831 else if (regno >= 0)
833 PUT_SDB_DEF (name);
834 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
835 PUT_SDB_SCL (C_REG);
837 else if (MEM_P (value)
838 && (MEM_P (XEXP (value, 0))
839 || (REG_P (XEXP (value, 0))
840 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
841 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
842 /* If the value is indirect by memory or by a register
843 that isn't the frame pointer
844 then it means the object is variable-sized and address through
845 that register or stack slot. COFF has no way to represent this
846 so all we can do is output the variable as a pointer. */
848 PUT_SDB_DEF (name);
849 if (REG_P (XEXP (value, 0)))
851 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
852 PUT_SDB_SCL (C_REG);
854 else
856 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
857 (CONST_INT...)))).
858 We want the value of that CONST_INT. */
859 /* Encore compiler hates a newline in a macro arg, it seems. */
860 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
861 (XEXP (XEXP (value, 0), 0)));
862 PUT_SDB_SCL (C_AUTO);
865 /* Effectively do build_pointer_type, but don't cache this type,
866 since it might be temporary whereas the type it points to
867 might have been saved for inlining. */
868 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
869 type = make_node (POINTER_TYPE);
870 TREE_TYPE (type) = TREE_TYPE (decl);
872 else if (MEM_P (value)
873 && ((GET_CODE (XEXP (value, 0)) == PLUS
874 && REG_P (XEXP (XEXP (value, 0), 0))
875 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
876 /* This is for variables which are at offset zero from
877 the frame pointer. This happens on the Alpha.
878 Non-frame pointer registers are excluded above. */
879 || (REG_P (XEXP (value, 0)))))
881 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
882 or (MEM (REG...)). We want the value of that CONST_INT
883 or zero. */
884 PUT_SDB_DEF (name);
885 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
886 PUT_SDB_SCL (C_AUTO);
888 else
890 /* It is something we don't know how to represent for SDB. */
891 return;
893 break;
895 default:
896 break;
898 PUT_SDB_TYPE (plain_type (type));
899 PUT_SDB_ENDEF;
902 /* Output SDB information for a top-level initialized variable
903 that has been delayed. */
905 static void
906 sdbout_toplevel_data (tree decl)
908 tree type = TREE_TYPE (decl);
910 if (DECL_IGNORED_P (decl))
911 return;
913 gcc_assert (TREE_CODE (decl) == VAR_DECL);
914 gcc_assert (MEM_P (DECL_RTL (decl)));
915 gcc_assert (DECL_INITIAL (decl));
917 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
918 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
919 if (TREE_PUBLIC (decl))
921 PUT_SDB_SCL (C_EXT);
923 else
925 PUT_SDB_SCL (C_STAT);
927 PUT_SDB_TYPE (plain_type (type));
928 PUT_SDB_ENDEF;
931 #ifdef SDB_ALLOW_FORWARD_REFERENCES
933 /* Machinery to record and output anonymous types. */
935 static void
936 sdbout_queue_anonymous_type (tree type)
938 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
941 static void
942 sdbout_dequeue_anonymous_types (void)
944 tree types, link;
946 while (anonymous_types)
948 types = nreverse (anonymous_types);
949 anonymous_types = NULL_TREE;
951 for (link = types; link; link = TREE_CHAIN (link))
953 tree type = TREE_VALUE (link);
955 if (type && ! TREE_ASM_WRITTEN (type))
956 sdbout_one_type (type);
961 #endif
963 /* Given a chain of ..._TYPE nodes, all of which have names,
964 output definitions of those names, as typedefs. */
966 void
967 sdbout_types (tree types)
969 tree link;
971 for (link = types; link; link = TREE_CHAIN (link))
972 sdbout_one_type (link);
974 #ifdef SDB_ALLOW_FORWARD_REFERENCES
975 sdbout_dequeue_anonymous_types ();
976 #endif
979 static void
980 sdbout_type (tree type)
982 if (type == error_mark_node)
983 type = integer_type_node;
984 PUT_SDB_TYPE (plain_type (type));
987 /* Output types of the fields of type TYPE, if they are structs.
989 Formerly did not chase through pointer types, since that could be circular.
990 They must come before TYPE, since forward refs are not allowed.
991 Now james@bigtex.cactus.org says to try them. */
993 static void
994 sdbout_field_types (tree type)
996 tree tail;
998 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
999 /* This condition should match the one for emitting the actual
1000 members below. */
1001 if (TREE_CODE (tail) == FIELD_DECL
1002 && DECL_NAME (tail)
1003 && DECL_SIZE (tail)
1004 && tree_fits_uhwi_p (DECL_SIZE (tail))
1005 && tree_fits_shwi_p (bit_position (tail)))
1007 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1008 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1009 else
1010 sdbout_one_type (TREE_TYPE (tail));
1014 /* Use this to put out the top level defined record and union types
1015 for later reference. If this is a struct with a name, then put that
1016 name out. Other unnamed structs will have .xxfake labels generated so
1017 that they may be referred to later.
1018 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1019 It may NOT be called recursively. */
1021 static void
1022 sdbout_one_type (tree type)
1024 if (current_function_decl != NULL_TREE
1025 && DECL_SECTION_NAME (current_function_decl) != NULL)
1026 ; /* Don't change section amid function. */
1027 else
1028 switch_to_section (current_function_section ());
1030 switch (TREE_CODE (type))
1032 case RECORD_TYPE:
1033 case UNION_TYPE:
1034 case QUAL_UNION_TYPE:
1035 case ENUMERAL_TYPE:
1036 type = TYPE_MAIN_VARIANT (type);
1037 /* Don't output a type twice. */
1038 if (TREE_ASM_WRITTEN (type))
1039 /* James said test TREE_ASM_BEING_WRITTEN here. */
1040 return;
1042 /* Output nothing if type is not yet defined. */
1043 if (!COMPLETE_TYPE_P (type))
1044 return;
1046 TREE_ASM_WRITTEN (type) = 1;
1048 /* This is reputed to cause trouble with the following case,
1049 but perhaps checking TYPE_SIZE above will fix it. */
1051 /* Here is a testcase:
1053 struct foo {
1054 struct badstr *bbb;
1055 } forwardref;
1057 typedef struct intermediate {
1058 int aaaa;
1059 } intermediate_ref;
1061 typedef struct badstr {
1062 int ccccc;
1063 } badtype; */
1065 /* This change, which ought to make better output,
1066 used to make the COFF assembler unhappy.
1067 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1068 /* Before really doing anything, output types we want to refer to. */
1069 /* Note that in version 1 the following two lines
1070 are not used if forward references are in use. */
1071 if (TREE_CODE (type) != ENUMERAL_TYPE)
1072 sdbout_field_types (type);
1074 /* Output a structure type. */
1076 int size = int_size_in_bytes (type);
1077 int member_scl = 0;
1078 tree tem;
1080 /* Record the type tag, but not in its permanent place just yet. */
1081 sdbout_record_type_name (type);
1083 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1085 switch (TREE_CODE (type))
1087 case UNION_TYPE:
1088 case QUAL_UNION_TYPE:
1089 PUT_SDB_SCL (C_UNTAG);
1090 PUT_SDB_TYPE (T_UNION);
1091 member_scl = C_MOU;
1092 break;
1094 case RECORD_TYPE:
1095 PUT_SDB_SCL (C_STRTAG);
1096 PUT_SDB_TYPE (T_STRUCT);
1097 member_scl = C_MOS;
1098 break;
1100 case ENUMERAL_TYPE:
1101 PUT_SDB_SCL (C_ENTAG);
1102 PUT_SDB_TYPE (T_ENUM);
1103 member_scl = C_MOE;
1104 break;
1106 default:
1107 break;
1110 PUT_SDB_SIZE (size);
1111 PUT_SDB_ENDEF;
1113 /* Print out the base class information with fields
1114 named after the types they hold. */
1115 /* This is only relevant to aggregate types. TYPE_BINFO is used
1116 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1117 case. */
1118 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1120 int i;
1121 tree binfo, child;
1123 for (binfo = TYPE_BINFO (type), i = 0;
1124 BINFO_BASE_ITERATE (binfo, i, child); i++)
1126 tree child_type = BINFO_TYPE (child);
1127 tree child_type_name;
1129 if (TYPE_NAME (child_type) == 0)
1130 continue;
1131 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1132 child_type_name = TYPE_NAME (child_type);
1133 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1135 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1136 if (child_type_name && template_name_p (child_type_name))
1137 child_type_name
1138 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1140 else
1141 continue;
1143 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1144 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1145 PUT_SDB_SCL (member_scl);
1146 sdbout_type (BINFO_TYPE (child));
1147 PUT_SDB_ENDEF;
1151 /* Output the individual fields. */
1153 if (TREE_CODE (type) == ENUMERAL_TYPE)
1155 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1157 tree value = TREE_VALUE (tem);
1159 if (TREE_CODE (value) == CONST_DECL)
1160 value = DECL_INITIAL (value);
1162 if (tree_fits_shwi_p (value))
1164 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1165 PUT_SDB_INT_VAL (tree_to_shwi (value));
1166 PUT_SDB_SCL (C_MOE);
1167 PUT_SDB_TYPE (T_MOE);
1168 PUT_SDB_ENDEF;
1172 else /* record or union type */
1173 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1174 /* Output the name, type, position (in bits), size (in bits)
1175 of each field. */
1177 /* Omit here the nameless fields that are used to skip bits.
1178 Also omit fields with variable size or position.
1179 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1180 if (TREE_CODE (tem) == FIELD_DECL
1181 && DECL_NAME (tem)
1182 && DECL_SIZE (tem)
1183 && tree_fits_uhwi_p (DECL_SIZE (tem))
1184 && tree_fits_shwi_p (bit_position (tem)))
1186 const char *name;
1188 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1189 PUT_SDB_DEF (name);
1190 if (DECL_BIT_FIELD_TYPE (tem))
1192 PUT_SDB_INT_VAL (int_bit_position (tem));
1193 PUT_SDB_SCL (C_FIELD);
1194 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1195 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1197 else
1199 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1200 PUT_SDB_SCL (member_scl);
1201 sdbout_type (TREE_TYPE (tem));
1203 PUT_SDB_ENDEF;
1205 /* Output end of a structure,union, or enumeral definition. */
1207 PUT_SDB_PLAIN_DEF ("eos");
1208 PUT_SDB_INT_VAL (size);
1209 PUT_SDB_SCL (C_EOS);
1210 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1211 PUT_SDB_SIZE (size);
1212 PUT_SDB_ENDEF;
1213 break;
1216 default:
1217 break;
1221 /* The following two functions output definitions of function parameters.
1222 Each parameter gets a definition locating it in the parameter list.
1223 Each parameter that is a register variable gets a second definition
1224 locating it in the register.
1226 Printing or argument lists in gdb uses the definitions that
1227 locate in the parameter list. But reference to the variable in
1228 expressions uses preferentially the definition as a register. */
1230 /* Output definitions, referring to storage in the parmlist,
1231 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1233 static void
1234 sdbout_parms (tree parms)
1236 for (; parms; parms = TREE_CHAIN (parms))
1237 if (DECL_NAME (parms)
1238 && TREE_TYPE (parms) != error_mark_node
1239 && DECL_RTL_SET_P (parms)
1240 && DECL_INCOMING_RTL (parms))
1242 int current_sym_value = 0;
1243 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1245 if (name == 0 || *name == 0)
1246 name = gen_fake_label ();
1248 /* Perform any necessary register eliminations on the parameter's rtl,
1249 so that the debugging output will be accurate. */
1250 DECL_INCOMING_RTL (parms)
1251 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1252 SET_DECL_RTL (parms,
1253 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1255 if (PARM_PASSED_IN_MEMORY (parms))
1257 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1258 tree type;
1260 /* ??? Here we assume that the parm address is indexed
1261 off the frame pointer or arg pointer.
1262 If that is not true, we produce meaningless results,
1263 but do not crash. */
1264 if (GET_CODE (addr) == PLUS
1265 && CONST_INT_P (XEXP (addr, 1)))
1266 current_sym_value = INTVAL (XEXP (addr, 1));
1267 else
1268 current_sym_value = 0;
1270 if (REG_P (DECL_RTL (parms))
1271 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1272 type = DECL_ARG_TYPE (parms);
1273 else
1275 int original_sym_value = current_sym_value;
1277 /* This is the case where the parm is passed as an int or
1278 double and it is converted to a char, short or float
1279 and stored back in the parmlist. In this case, describe
1280 the parm with the variable's declared type, and adjust
1281 the address if the least significant bytes (which we are
1282 using) are not the first ones. */
1283 if (BYTES_BIG_ENDIAN
1284 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1285 current_sym_value +=
1286 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1287 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1289 if (MEM_P (DECL_RTL (parms))
1290 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1291 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1292 == CONST_INT)
1293 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1294 == current_sym_value))
1295 type = TREE_TYPE (parms);
1296 else
1298 current_sym_value = original_sym_value;
1299 type = DECL_ARG_TYPE (parms);
1303 PUT_SDB_DEF (name);
1304 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1305 PUT_SDB_SCL (C_ARG);
1306 PUT_SDB_TYPE (plain_type (type));
1307 PUT_SDB_ENDEF;
1309 else if (REG_P (DECL_RTL (parms)))
1311 rtx best_rtl;
1312 /* Parm passed in registers and lives in registers or nowhere. */
1314 /* If parm lives in a register, use that register;
1315 pretend the parm was passed there. It would be more consistent
1316 to describe the register where the parm was passed,
1317 but in practice that register usually holds something else. */
1318 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1319 best_rtl = DECL_RTL (parms);
1320 /* If the parm lives nowhere,
1321 use the register where it was passed. */
1322 else
1323 best_rtl = DECL_INCOMING_RTL (parms);
1325 PUT_SDB_DEF (name);
1326 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1327 PUT_SDB_SCL (C_REGPARM);
1328 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1329 PUT_SDB_ENDEF;
1331 else if (MEM_P (DECL_RTL (parms))
1332 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1334 /* Parm was passed in registers but lives on the stack. */
1336 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1337 in which case we want the value of that CONST_INT,
1338 or (MEM (REG ...)) or (MEM (MEM ...)),
1339 in which case we use a value of zero. */
1340 if (REG_P (XEXP (DECL_RTL (parms), 0))
1341 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1342 current_sym_value = 0;
1343 else
1344 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1346 /* Again, this assumes the offset is based on the arg pointer. */
1347 PUT_SDB_DEF (name);
1348 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1349 XEXP (DECL_RTL (parms), 0)));
1350 PUT_SDB_SCL (C_ARG);
1351 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1352 PUT_SDB_ENDEF;
1357 /* Output definitions for the places where parms live during the function,
1358 when different from where they were passed, when the parms were passed
1359 in memory.
1361 It is not useful to do this for parms passed in registers
1362 that live during the function in different registers, because it is
1363 impossible to look in the passed register for the passed value,
1364 so we use the within-the-function register to begin with.
1366 PARMS is a chain of PARM_DECL nodes. */
1368 static void
1369 sdbout_reg_parms (tree parms)
1371 for (; parms; parms = TREE_CHAIN (parms))
1372 if (DECL_NAME (parms)
1373 && TREE_TYPE (parms) != error_mark_node
1374 && DECL_RTL_SET_P (parms)
1375 && DECL_INCOMING_RTL (parms))
1377 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1379 /* Report parms that live in registers during the function
1380 but were passed in memory. */
1381 if (REG_P (DECL_RTL (parms))
1382 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1383 && PARM_PASSED_IN_MEMORY (parms))
1385 if (name == 0 || *name == 0)
1386 name = gen_fake_label ();
1387 PUT_SDB_DEF (name);
1388 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1389 PUT_SDB_SCL (C_REG);
1390 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1391 PUT_SDB_ENDEF;
1393 /* Report parms that live in memory but not where they were passed. */
1394 else if (MEM_P (DECL_RTL (parms))
1395 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1396 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1397 && PARM_PASSED_IN_MEMORY (parms)
1398 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1400 #if 0 /* ??? It is not clear yet what should replace this. */
1401 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1402 /* A parm declared char is really passed as an int,
1403 so it occupies the least significant bytes.
1404 On a big-endian machine those are not the low-numbered ones. */
1405 if (BYTES_BIG_ENDIAN
1406 && offset != -1
1407 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1408 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1409 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1410 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1411 #endif
1413 if (name == 0 || *name == 0)
1414 name = gen_fake_label ();
1415 PUT_SDB_DEF (name);
1416 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1417 (XEXP (DECL_RTL (parms), 0)));
1418 PUT_SDB_SCL (C_AUTO);
1419 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1420 PUT_SDB_ENDEF;
1426 /* Output early debug information for a global DECL. Called from
1427 rest_of_decl_compilation during parsing. */
1429 static void
1430 sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1432 /* NYI for non-dwarf. */
1435 /* Output late debug information for a global DECL after location
1436 information is available. */
1438 static void
1439 sdbout_late_global_decl (tree decl)
1441 if (TREE_CODE (decl) == VAR_DECL
1442 && !DECL_EXTERNAL (decl)
1443 && DECL_RTL_SET_P (decl))
1445 /* The COFF linker can move initialized global vars to the end.
1446 And that can screw up the symbol ordering. Defer those for
1447 sdbout_finish (). */
1448 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1449 sdbout_symbol (decl, 0);
1450 else
1451 vec_safe_push (deferred_global_decls, decl);
1453 /* Output COFF information for non-global file-scope initialized
1454 variables. */
1455 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1456 sdbout_toplevel_data (decl);
1460 /* Output initialized global vars at the end, in the order of
1461 definition. See comment in sdbout_global_decl. */
1463 static void
1464 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1466 size_t i;
1467 tree decl;
1469 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1470 sdbout_symbol (decl, 0);
1473 /* Describe the beginning of an internal block within a function.
1474 Also output descriptions of variables defined in this block.
1476 N is the number of the block, by order of beginning, counting from 1,
1477 and not counting the outermost (function top-level) block.
1478 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1479 if the count starts at 0 for the outermost one. */
1481 static void
1482 sdbout_begin_block (unsigned int line, unsigned int n)
1484 tree decl = current_function_decl;
1485 MAKE_LINE_SAFE (line);
1487 /* The SCO compiler does not emit a separate block for the function level
1488 scope, so we avoid it here also. */
1489 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1491 if (n == 1)
1493 /* Include the outermost BLOCK's variables in block 1. */
1494 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1495 sdbout_block (DECL_INITIAL (decl));
1497 /* If -g1, suppress all the internal symbols of functions
1498 except for arguments. */
1499 if (debug_info_level != DINFO_LEVEL_TERSE)
1501 do_block = n;
1502 sdbout_block (DECL_INITIAL (decl));
1505 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1506 sdbout_dequeue_anonymous_types ();
1507 #endif
1510 /* Describe the end line-number of an internal block within a function. */
1512 static void
1513 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1515 MAKE_LINE_SAFE (line);
1517 /* The SCO compiler does not emit a separate block for the function level
1518 scope, so we avoid it here also. */
1519 if (n != 1)
1520 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1523 /* Output a line number symbol entry for source file FILENAME and line
1524 number LINE. */
1526 static void
1527 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1528 int discriminator ATTRIBUTE_UNUSED,
1529 bool is_stmt ATTRIBUTE_UNUSED)
1531 /* COFF relative line numbers must be positive. */
1532 if ((int) line > sdb_begin_function_line)
1534 #ifdef SDB_OUTPUT_SOURCE_LINE
1535 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1536 #else
1537 fprintf (asm_out_file, "\t.ln\t%d\n",
1538 ((sdb_begin_function_line > -1)
1539 ? line - sdb_begin_function_line : 1));
1540 #endif
1544 /* Output sdb info for the current function name.
1545 Called from assemble_start_function. */
1547 static void
1548 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1550 sdbout_symbol (current_function_decl, 0);
1553 /* Called at beginning of function body after prologue. Record the
1554 function's starting line number, so we can output relative line numbers
1555 for the other lines. Describe beginning of outermost block. Also
1556 describe the parameter list. */
1558 static void
1559 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1561 sdbout_end_prologue (line, file);
1564 static void
1565 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1567 sdb_begin_function_line = line - 1;
1568 PUT_SDB_FUNCTION_START (line);
1569 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1570 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1573 /* Called at end of function (before epilogue).
1574 Describe end of outermost block. */
1576 static void
1577 sdbout_end_function (unsigned int line)
1579 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1580 sdbout_dequeue_anonymous_types ();
1581 #endif
1583 MAKE_LINE_SAFE (line);
1584 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1586 /* Indicate we are between functions, for line-number output. */
1587 sdb_begin_function_line = -1;
1590 /* Output sdb info for the absolute end of a function.
1591 Called after the epilogue is output. */
1593 static void
1594 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1595 const char *file ATTRIBUTE_UNUSED)
1597 const char *const name ATTRIBUTE_UNUSED
1598 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1600 #ifdef PUT_SDB_EPILOGUE_END
1601 PUT_SDB_EPILOGUE_END (name);
1602 #else
1603 fprintf (asm_out_file, "\t.def\t");
1604 assemble_name (asm_out_file, name);
1605 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1606 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1607 #endif
1610 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1611 is present. */
1613 static void
1614 sdbout_label (rtx_code_label *insn)
1616 PUT_SDB_DEF (LABEL_NAME (insn));
1617 PUT_SDB_VAL (insn);
1618 PUT_SDB_SCL (C_LABEL);
1619 PUT_SDB_TYPE (T_NULL);
1620 PUT_SDB_ENDEF;
1623 /* Change to reading from a new source file. */
1625 static void
1626 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1627 const char *filename ATTRIBUTE_UNUSED)
1631 /* Revert to reading a previous source file. */
1633 static void
1634 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1638 /* Set up for SDB output at the start of compilation. */
1640 static void
1641 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1643 tree t;
1645 vec_alloc (deferred_global_decls, 12);
1647 /* Emit debug information which was queued by sdbout_symbol before
1648 we got here. */
1649 sdbout_initialized = true;
1651 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1652 sdbout_symbol (TREE_VALUE (t), 0);
1653 preinit_symbols = 0;
1656 #endif /* SDB_DEBUGGING_INFO */
1658 #include "gt-sdbout.h"