2015-06-11 Paul Thomas <pault@gcc.gnu.org>
[official-gcc.git] / gcc / sdbout.c
blob033886a675e8ba3635a35c856b1cb998ea831c1b
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 "input.h"
48 #include "alias.h"
49 #include "symtab.h"
50 #include "tree.h"
51 #include "varasm.h"
52 #include "stor-layout.h"
54 static GTY(()) tree anonymous_types;
56 /* Counter to generate unique "names" for nameless struct members. */
58 static GTY(()) int unnamed_struct_number;
60 /* Declarations whose debug info was deferred till end of compilation. */
62 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
64 /* The C front end may call sdbout_symbol before sdbout_init runs.
65 We save all such decls in this list and output them when we get
66 to sdbout_init. */
68 static GTY(()) tree preinit_symbols;
69 static GTY(()) bool sdbout_initialized;
71 #ifdef SDB_DEBUGGING_INFO
73 #include "rtl.h"
74 #include "regs.h"
75 #include "flags.h"
76 #include "insn-config.h"
77 #include "reload.h"
78 #include "output.h"
79 #include "diagnostic-core.h"
80 #include "tm_p.h"
81 #include "gsyms.h"
82 #include "langhooks.h"
83 #include "target.h"
85 /* 1 if PARM is passed to this function in memory. */
87 #define PARM_PASSED_IN_MEMORY(PARM) \
88 (MEM_P (DECL_INCOMING_RTL (PARM)))
90 /* A C expression for the integer offset value of an automatic variable
91 (C_AUTO) having address X (an RTX). */
92 #ifndef DEBUGGER_AUTO_OFFSET
93 #define DEBUGGER_AUTO_OFFSET(X) \
94 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
95 #endif
97 /* A C expression for the integer offset value of an argument (C_ARG)
98 having address X (an RTX). The nominal offset is OFFSET. */
99 #ifndef DEBUGGER_ARG_OFFSET
100 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
101 #endif
103 /* Line number of beginning of current function, minus one.
104 Negative means not in a function or not using sdb. */
106 int sdb_begin_function_line = -1;
109 extern FILE *asm_out_file;
111 extern tree current_function_decl;
113 #include "sdbout.h"
115 static void sdbout_init (const char *);
116 static void sdbout_finish (const char *);
117 static void sdbout_start_source_file (unsigned int, const char *);
118 static void sdbout_end_source_file (unsigned int);
119 static void sdbout_begin_block (unsigned int, unsigned int);
120 static void sdbout_end_block (unsigned int, unsigned int);
121 static void sdbout_source_line (unsigned int, const char *, int, bool);
122 static void sdbout_end_epilogue (unsigned int, const char *);
123 static void sdbout_early_global_decl (tree);
124 static void sdbout_late_global_decl (tree);
125 static void sdbout_begin_prologue (unsigned int, const char *);
126 static void sdbout_end_prologue (unsigned int, const char *);
127 static void sdbout_begin_function (tree);
128 static void sdbout_end_function (unsigned int);
129 static void sdbout_toplevel_data (tree);
130 static void sdbout_label (rtx_code_label *);
131 static char *gen_fake_label (void);
132 static int plain_type (tree);
133 static int template_name_p (tree);
134 static void sdbout_record_type_name (tree);
135 static int plain_type_1 (tree, int);
136 static void sdbout_block (tree);
137 static void sdbout_syms (tree);
138 #ifdef SDB_ALLOW_FORWARD_REFERENCES
139 static void sdbout_queue_anonymous_type (tree);
140 static void sdbout_dequeue_anonymous_types (void);
141 #endif
142 static void sdbout_type (tree);
143 static void sdbout_field_types (tree);
144 static void sdbout_one_type (tree);
145 static void sdbout_parms (tree);
146 static void sdbout_reg_parms (tree);
148 /* Random macros describing parts of SDB data. */
150 /* Default value of delimiter is ";". */
151 #ifndef SDB_DELIM
152 #define SDB_DELIM ";"
153 #endif
155 /* Maximum number of dimensions the assembler will allow. */
156 #ifndef SDB_MAX_DIM
157 #define SDB_MAX_DIM 4
158 #endif
160 #ifndef PUT_SDB_SCL
161 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
162 #endif
164 #ifndef PUT_SDB_INT_VAL
165 #define PUT_SDB_INT_VAL(a) \
166 do { \
167 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
168 (HOST_WIDE_INT) (a), SDB_DELIM); \
169 } while (0)
171 #endif
173 #ifndef PUT_SDB_VAL
174 #define PUT_SDB_VAL(a) \
175 ( fputs ("\t.val\t", asm_out_file), \
176 output_addr_const (asm_out_file, (a)), \
177 fprintf (asm_out_file, SDB_DELIM))
178 #endif
180 #ifndef PUT_SDB_DEF
181 #define PUT_SDB_DEF(a) \
182 do { fprintf (asm_out_file, "\t.def\t"); \
183 assemble_name (asm_out_file, a); \
184 fprintf (asm_out_file, SDB_DELIM); } while (0)
185 #endif
187 #ifndef PUT_SDB_PLAIN_DEF
188 #define PUT_SDB_PLAIN_DEF(a) \
189 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
190 #endif
192 #ifndef PUT_SDB_ENDEF
193 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
194 #endif
196 #ifndef PUT_SDB_TYPE
197 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
198 #endif
200 #ifndef PUT_SDB_SIZE
201 #define PUT_SDB_SIZE(a) \
202 do { \
203 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
204 (HOST_WIDE_INT) (a), SDB_DELIM); \
205 } while (0)
206 #endif
208 #ifndef PUT_SDB_START_DIM
209 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
210 #endif
212 #ifndef PUT_SDB_NEXT_DIM
213 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
214 #endif
216 #ifndef PUT_SDB_LAST_DIM
217 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
218 #endif
220 #ifndef PUT_SDB_TAG
221 #define PUT_SDB_TAG(a) \
222 do { fprintf (asm_out_file, "\t.tag\t"); \
223 assemble_name (asm_out_file, a); \
224 fprintf (asm_out_file, SDB_DELIM); } while (0)
225 #endif
227 #ifndef PUT_SDB_BLOCK_START
228 #define PUT_SDB_BLOCK_START(LINE) \
229 fprintf (asm_out_file, \
230 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
231 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
232 #endif
234 #ifndef PUT_SDB_BLOCK_END
235 #define PUT_SDB_BLOCK_END(LINE) \
236 fprintf (asm_out_file, \
237 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
238 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
239 #endif
241 #ifndef PUT_SDB_FUNCTION_START
242 #define PUT_SDB_FUNCTION_START(LINE) \
243 fprintf (asm_out_file, \
244 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
245 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
246 #endif
248 #ifndef PUT_SDB_FUNCTION_END
249 #define PUT_SDB_FUNCTION_END(LINE) \
250 fprintf (asm_out_file, \
251 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
252 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
253 #endif
255 /* Return the sdb tag identifier string for TYPE
256 if TYPE has already been defined; otherwise return a null pointer. */
258 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
260 /* Set the sdb tag identifier string for TYPE to NAME. */
262 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
263 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
265 /* Return the name (a string) of the struct, union or enum tag
266 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
268 #define TAG_NAME(link) \
269 (((link) && TREE_PURPOSE ((link)) \
270 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
271 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
273 /* Ensure we don't output a negative line number. */
274 #define MAKE_LINE_SAFE(line) \
275 if ((int) line <= sdb_begin_function_line) \
276 line = sdb_begin_function_line + 1
278 /* The debug hooks structure. */
279 const struct gcc_debug_hooks sdb_debug_hooks =
281 sdbout_init, /* init */
282 sdbout_finish, /* finish */
283 debug_nothing_void, /* early_finish */
284 debug_nothing_void, /* assembly_start */
285 debug_nothing_int_charstar, /* define */
286 debug_nothing_int_charstar, /* undef */
287 sdbout_start_source_file, /* start_source_file */
288 sdbout_end_source_file, /* end_source_file */
289 sdbout_begin_block, /* begin_block */
290 sdbout_end_block, /* end_block */
291 debug_true_const_tree, /* ignore_block */
292 sdbout_source_line, /* source_line */
293 sdbout_begin_prologue, /* begin_prologue */
294 debug_nothing_int_charstar, /* end_prologue */
295 debug_nothing_int_charstar, /* begin_epilogue */
296 sdbout_end_epilogue, /* end_epilogue */
297 sdbout_begin_function, /* begin_function */
298 sdbout_end_function, /* end_function */
299 debug_nothing_tree, /* register_main_translation_unit */
300 debug_nothing_tree, /* function_decl */
301 sdbout_early_global_decl, /* early_global_decl */
302 sdbout_late_global_decl, /* late_global_decl */
303 sdbout_symbol, /* type_decl */
304 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
305 debug_nothing_tree, /* deferred_inline_function */
306 debug_nothing_tree, /* outlining_inline_function */
307 sdbout_label, /* label */
308 debug_nothing_int, /* handle_pch */
309 debug_nothing_rtx_insn, /* var_location */
310 debug_nothing_void, /* switch_text_section */
311 debug_nothing_tree_tree, /* set_name */
312 0, /* start_end_main_source_file */
313 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
316 /* Return a unique string to name an anonymous type. */
318 static char *
319 gen_fake_label (void)
321 char label[10];
322 char *labelstr;
323 sprintf (label, ".%dfake", unnamed_struct_number);
324 unnamed_struct_number++;
325 labelstr = xstrdup (label);
326 return labelstr;
329 /* Return the number which describes TYPE for SDB.
330 For pointers, etc., this function is recursive.
331 Each record, union or enumeral type must already have had a
332 tag number output. */
334 /* The number is given by d6d5d4d3d2d1bbbb
335 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
336 Thus, char *foo () has bbbb=T_CHAR
337 d1=D_FCN
338 d2=D_PTR
339 N_BTMASK= 017 1111 basic type field.
340 N_TSHIFT= 2 derived type shift
341 N_BTSHFT= 4 Basic type shift */
343 /* Produce the number that describes a pointer, function or array type.
344 PREV is the number describing the target, value or element type.
345 DT_type describes how to transform that type. */
346 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
347 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
348 | ((int) DT_type << (int) N_BTSHFT) \
349 | ((PREV) & (int) N_BTMASK))
351 /* Number of elements used in sdb_dims. */
352 static int sdb_n_dims = 0;
354 /* Table of array dimensions of current type. */
355 static int sdb_dims[SDB_MAX_DIM];
357 /* Size of outermost array currently being processed. */
358 static int sdb_type_size = -1;
360 static int
361 plain_type (tree type)
363 int val = plain_type_1 (type, 0);
365 /* If we have already saved up some array dimensions, print them now. */
366 if (sdb_n_dims > 0)
368 int i;
369 PUT_SDB_START_DIM;
370 for (i = sdb_n_dims - 1; i > 0; i--)
371 PUT_SDB_NEXT_DIM (sdb_dims[i]);
372 PUT_SDB_LAST_DIM (sdb_dims[0]);
373 sdb_n_dims = 0;
375 sdb_type_size = int_size_in_bytes (type);
376 /* Don't kill sdb if type is not laid out or has variable size. */
377 if (sdb_type_size < 0)
378 sdb_type_size = 0;
380 /* If we have computed the size of an array containing this type,
381 print it now. */
382 if (sdb_type_size >= 0)
384 PUT_SDB_SIZE (sdb_type_size);
385 sdb_type_size = -1;
387 return val;
390 static int
391 template_name_p (tree name)
393 const char *ptr = IDENTIFIER_POINTER (name);
394 while (*ptr && *ptr != '<')
395 ptr++;
397 return *ptr != '\0';
400 static void
401 sdbout_record_type_name (tree type)
403 const char *name = 0;
404 int no_name;
406 if (KNOWN_TYPE_TAG (type))
407 return;
409 if (TYPE_NAME (type) != 0)
411 tree t = 0;
413 /* Find the IDENTIFIER_NODE for the type name. */
414 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
415 t = TYPE_NAME (type);
416 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
418 t = DECL_NAME (TYPE_NAME (type));
419 /* The DECL_NAME for templates includes "<>", which breaks
420 most assemblers. Use its assembler name instead, which
421 has been mangled into being safe. */
422 if (t && template_name_p (t))
423 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
426 /* Now get the name as a string, or invent one. */
427 if (t != NULL_TREE)
428 name = IDENTIFIER_POINTER (t);
431 no_name = (name == 0 || *name == 0);
432 if (no_name)
433 name = gen_fake_label ();
435 SET_KNOWN_TYPE_TAG (type, name);
436 #ifdef SDB_ALLOW_FORWARD_REFERENCES
437 if (no_name)
438 sdbout_queue_anonymous_type (type);
439 #endif
442 /* Return the .type value for type TYPE.
444 LEVEL indicates how many levels deep we have recursed into the type.
445 The SDB debug format can only represent 6 derived levels of types.
446 After that, we must output inaccurate debug info. We deliberately
447 stop before the 7th level, so that ADA recursive types will not give an
448 infinite loop. */
450 static int
451 plain_type_1 (tree type, int level)
453 if (type == 0)
454 type = void_type_node;
455 else if (type == error_mark_node)
456 type = integer_type_node;
457 else
458 type = TYPE_MAIN_VARIANT (type);
460 switch (TREE_CODE (type))
462 case VOID_TYPE:
463 case NULLPTR_TYPE:
464 return T_VOID;
465 case BOOLEAN_TYPE:
466 case INTEGER_TYPE:
468 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
470 /* Carefully distinguish all the standard types of C,
471 without messing up if the language is not C.
472 Note that we check only for the names that contain spaces;
473 other names might occur by coincidence in other languages. */
474 if (TYPE_NAME (type) != 0
475 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
476 && DECL_NAME (TYPE_NAME (type)) != 0
477 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
479 const char *const name
480 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
482 if (!strcmp (name, "char"))
483 return T_CHAR;
484 if (!strcmp (name, "unsigned char"))
485 return T_UCHAR;
486 if (!strcmp (name, "signed char"))
487 return T_CHAR;
488 if (!strcmp (name, "int"))
489 return T_INT;
490 if (!strcmp (name, "unsigned int"))
491 return T_UINT;
492 if (!strcmp (name, "short int"))
493 return T_SHORT;
494 if (!strcmp (name, "short unsigned int"))
495 return T_USHORT;
496 if (!strcmp (name, "long int"))
497 return T_LONG;
498 if (!strcmp (name, "long unsigned int"))
499 return T_ULONG;
502 if (size == INT_TYPE_SIZE)
503 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
504 if (size == CHAR_TYPE_SIZE)
505 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
506 if (size == SHORT_TYPE_SIZE)
507 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
508 if (size == LONG_TYPE_SIZE)
509 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
510 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
511 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
512 return 0;
515 case REAL_TYPE:
517 int precision = TYPE_PRECISION (type);
518 if (precision == FLOAT_TYPE_SIZE)
519 return T_FLOAT;
520 if (precision == DOUBLE_TYPE_SIZE)
521 return T_DOUBLE;
522 #ifdef EXTENDED_SDB_BASIC_TYPES
523 if (precision == LONG_DOUBLE_TYPE_SIZE)
524 return T_LNGDBL;
525 #else
526 if (precision == LONG_DOUBLE_TYPE_SIZE)
527 return T_DOUBLE; /* better than nothing */
528 #endif
529 return 0;
532 case ARRAY_TYPE:
534 int m;
535 if (level >= 6)
536 return T_VOID;
537 else
538 m = plain_type_1 (TREE_TYPE (type), level+1);
539 if (sdb_n_dims < SDB_MAX_DIM)
540 sdb_dims[sdb_n_dims++]
541 = (TYPE_DOMAIN (type)
542 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
543 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
544 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
545 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
546 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
547 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
548 : 0);
550 return PUSH_DERIVED_LEVEL (DT_ARY, m);
553 case RECORD_TYPE:
554 case UNION_TYPE:
555 case QUAL_UNION_TYPE:
556 case ENUMERAL_TYPE:
558 const char *tag;
559 #ifdef SDB_ALLOW_FORWARD_REFERENCES
560 sdbout_record_type_name (type);
561 #endif
562 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
563 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
564 #ifdef SDB_ALLOW_FORWARD_REFERENCES
565 || TYPE_MODE (type) != VOIDmode
566 #endif
568 #endif
570 /* Output the referenced structure tag name
571 only if the .def has already been finished.
572 At least on 386, the Unix assembler
573 cannot handle forward references to tags. */
574 /* But the 88100, it requires them, sigh... */
575 /* And the MIPS requires unknown refs as well... */
576 tag = KNOWN_TYPE_TAG (type);
577 PUT_SDB_TAG (tag);
578 /* These 3 lines used to follow the close brace.
579 However, a size of 0 without a tag implies a tag of 0,
580 so if we don't know a tag, we can't mention the size. */
581 sdb_type_size = int_size_in_bytes (type);
582 if (sdb_type_size < 0)
583 sdb_type_size = 0;
585 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
586 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
587 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
588 : T_ENUM);
590 case POINTER_TYPE:
591 case REFERENCE_TYPE:
593 int m;
594 if (level >= 6)
595 return T_VOID;
596 else
597 m = plain_type_1 (TREE_TYPE (type), level+1);
598 return PUSH_DERIVED_LEVEL (DT_PTR, m);
600 case FUNCTION_TYPE:
601 case METHOD_TYPE:
603 int m;
604 if (level >= 6)
605 return T_VOID;
606 else
607 m = plain_type_1 (TREE_TYPE (type), level+1);
608 return PUSH_DERIVED_LEVEL (DT_FCN, m);
610 default:
611 return 0;
615 /* Output the symbols defined in block number DO_BLOCK.
617 This function works by walking the tree structure of blocks,
618 counting blocks until it finds the desired block. */
620 static int do_block = 0;
622 static void
623 sdbout_block (tree block)
625 while (block)
627 /* Ignore blocks never expanded or otherwise marked as real. */
628 if (TREE_USED (block))
630 /* When we reach the specified block, output its symbols. */
631 if (BLOCK_NUMBER (block) == do_block)
632 sdbout_syms (BLOCK_VARS (block));
634 /* If we are past the specified block, stop the scan. */
635 if (BLOCK_NUMBER (block) > do_block)
636 return;
638 /* Scan the blocks within this block. */
639 sdbout_block (BLOCK_SUBBLOCKS (block));
642 block = BLOCK_CHAIN (block);
646 /* Call sdbout_symbol on each decl in the chain SYMS. */
648 static void
649 sdbout_syms (tree syms)
651 while (syms)
653 if (TREE_CODE (syms) != LABEL_DECL)
654 sdbout_symbol (syms, 1);
655 syms = TREE_CHAIN (syms);
659 /* Output SDB information for a symbol described by DECL.
660 LOCAL is nonzero if the symbol is not file-scope. */
662 void
663 sdbout_symbol (tree decl, int local)
665 tree type = TREE_TYPE (decl);
666 tree context = NULL_TREE;
667 rtx value;
668 int regno = -1;
669 const char *name;
671 /* If we are called before sdbout_init is run, just save the symbol
672 for later. */
673 if (!sdbout_initialized)
675 preinit_symbols = tree_cons (0, decl, preinit_symbols);
676 return;
679 sdbout_one_type (type);
681 switch (TREE_CODE (decl))
683 case CONST_DECL:
684 /* Enum values are defined by defining the enum type. */
685 return;
687 case FUNCTION_DECL:
688 /* Don't mention a nested function under its parent. */
689 context = decl_function_context (decl);
690 if (context == current_function_decl)
691 return;
692 /* Check DECL_INITIAL to distinguish declarations from definitions.
693 Don't output debug info here for declarations; they will have
694 a DECL_INITIAL value of 0. */
695 if (! DECL_INITIAL (decl))
696 return;
697 if (!MEM_P (DECL_RTL (decl))
698 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
699 return;
700 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
701 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
702 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
703 break;
705 case TYPE_DECL:
706 /* Done with tagged types. */
707 if (DECL_NAME (decl) == 0)
708 return;
709 if (DECL_IGNORED_P (decl))
710 return;
711 /* Don't output intrinsic types. GAS chokes on SDB .def
712 statements that contain identifiers with embedded spaces
713 (eg "unsigned long"). */
714 if (DECL_IS_BUILTIN (decl))
715 return;
717 /* Output typedef name. */
718 if (template_name_p (DECL_NAME (decl)))
719 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
720 else
721 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
722 PUT_SDB_SCL (C_TPDEF);
723 break;
725 case PARM_DECL:
726 /* Parm decls go in their own separate chains
727 and are output by sdbout_reg_parms and sdbout_parms. */
728 gcc_unreachable ();
730 case VAR_DECL:
731 /* Don't mention a variable that is external.
732 Let the file that defines it describe it. */
733 if (DECL_EXTERNAL (decl))
734 return;
736 /* Ignore __FUNCTION__, etc. */
737 if (DECL_IGNORED_P (decl))
738 return;
740 /* If there was an error in the declaration, don't dump core
741 if there is no RTL associated with the variable doesn't
742 exist. */
743 if (!DECL_RTL_SET_P (decl))
744 return;
746 value = DECL_RTL (decl);
748 if (!is_global_var (decl))
749 value = eliminate_regs (value, VOIDmode, NULL_RTX);
751 SET_DECL_RTL (decl, value);
752 #ifdef LEAF_REG_REMAP
753 if (crtl->uses_only_leaf_regs)
754 leaf_renumber_regs_insn (value);
755 #endif
757 /* Don't mention a variable at all
758 if it was completely optimized into nothingness.
760 If DECL was from an inline function, then its rtl
761 is not identically the rtl that was used in this
762 particular compilation. */
763 if (REG_P (value))
765 regno = REGNO (value);
766 if (regno >= FIRST_PSEUDO_REGISTER)
767 return;
769 else if (GET_CODE (value) == SUBREG)
771 while (GET_CODE (value) == SUBREG)
772 value = SUBREG_REG (value);
773 if (REG_P (value))
775 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
776 return;
778 regno = REGNO (alter_subreg (&value, true));
779 SET_DECL_RTL (decl, value);
781 /* Don't output anything if an auto variable
782 gets RTL that is static.
783 GAS version 2.2 can't handle such output. */
784 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
785 && ! TREE_STATIC (decl))
786 return;
788 /* Emit any structure, union, or enum type that has not been output.
789 This occurs for tag-less structs (et al) used to declare variables
790 within functions. */
791 if (TREE_CODE (type) == ENUMERAL_TYPE
792 || TREE_CODE (type) == RECORD_TYPE
793 || TREE_CODE (type) == UNION_TYPE
794 || TREE_CODE (type) == QUAL_UNION_TYPE)
796 if (COMPLETE_TYPE_P (type) /* not a forward reference */
797 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
798 sdbout_one_type (type);
801 /* Defer SDB information for top-level initialized variables! */
802 if (! local
803 && MEM_P (value)
804 && DECL_INITIAL (decl))
805 return;
807 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
808 For now, avoid crashing. */
809 if (DECL_NAME (decl) == NULL_TREE)
810 return;
812 /* Record the name for, starting a symtab entry. */
813 if (local)
814 name = IDENTIFIER_POINTER (DECL_NAME (decl));
815 else
816 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
818 if (MEM_P (value)
819 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
821 PUT_SDB_DEF (name);
822 if (TREE_PUBLIC (decl))
824 PUT_SDB_VAL (XEXP (value, 0));
825 PUT_SDB_SCL (C_EXT);
827 else
829 PUT_SDB_VAL (XEXP (value, 0));
830 PUT_SDB_SCL (C_STAT);
833 else if (regno >= 0)
835 PUT_SDB_DEF (name);
836 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
837 PUT_SDB_SCL (C_REG);
839 else if (MEM_P (value)
840 && (MEM_P (XEXP (value, 0))
841 || (REG_P (XEXP (value, 0))
842 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
843 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
844 /* If the value is indirect by memory or by a register
845 that isn't the frame pointer
846 then it means the object is variable-sized and address through
847 that register or stack slot. COFF has no way to represent this
848 so all we can do is output the variable as a pointer. */
850 PUT_SDB_DEF (name);
851 if (REG_P (XEXP (value, 0)))
853 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
854 PUT_SDB_SCL (C_REG);
856 else
858 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
859 (CONST_INT...)))).
860 We want the value of that CONST_INT. */
861 /* Encore compiler hates a newline in a macro arg, it seems. */
862 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
863 (XEXP (XEXP (value, 0), 0)));
864 PUT_SDB_SCL (C_AUTO);
867 /* Effectively do build_pointer_type, but don't cache this type,
868 since it might be temporary whereas the type it points to
869 might have been saved for inlining. */
870 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
871 type = make_node (POINTER_TYPE);
872 TREE_TYPE (type) = TREE_TYPE (decl);
874 else if (MEM_P (value)
875 && ((GET_CODE (XEXP (value, 0)) == PLUS
876 && REG_P (XEXP (XEXP (value, 0), 0))
877 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
878 /* This is for variables which are at offset zero from
879 the frame pointer. This happens on the Alpha.
880 Non-frame pointer registers are excluded above. */
881 || (REG_P (XEXP (value, 0)))))
883 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
884 or (MEM (REG...)). We want the value of that CONST_INT
885 or zero. */
886 PUT_SDB_DEF (name);
887 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
888 PUT_SDB_SCL (C_AUTO);
890 else
892 /* It is something we don't know how to represent for SDB. */
893 return;
895 break;
897 default:
898 break;
900 PUT_SDB_TYPE (plain_type (type));
901 PUT_SDB_ENDEF;
904 /* Output SDB information for a top-level initialized variable
905 that has been delayed. */
907 static void
908 sdbout_toplevel_data (tree decl)
910 tree type = TREE_TYPE (decl);
912 if (DECL_IGNORED_P (decl))
913 return;
915 gcc_assert (TREE_CODE (decl) == VAR_DECL);
916 gcc_assert (MEM_P (DECL_RTL (decl)));
917 gcc_assert (DECL_INITIAL (decl));
919 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
920 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
921 if (TREE_PUBLIC (decl))
923 PUT_SDB_SCL (C_EXT);
925 else
927 PUT_SDB_SCL (C_STAT);
929 PUT_SDB_TYPE (plain_type (type));
930 PUT_SDB_ENDEF;
933 #ifdef SDB_ALLOW_FORWARD_REFERENCES
935 /* Machinery to record and output anonymous types. */
937 static void
938 sdbout_queue_anonymous_type (tree type)
940 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
943 static void
944 sdbout_dequeue_anonymous_types (void)
946 tree types, link;
948 while (anonymous_types)
950 types = nreverse (anonymous_types);
951 anonymous_types = NULL_TREE;
953 for (link = types; link; link = TREE_CHAIN (link))
955 tree type = TREE_VALUE (link);
957 if (type && ! TREE_ASM_WRITTEN (type))
958 sdbout_one_type (type);
963 #endif
965 /* Given a chain of ..._TYPE nodes, all of which have names,
966 output definitions of those names, as typedefs. */
968 void
969 sdbout_types (tree types)
971 tree link;
973 for (link = types; link; link = TREE_CHAIN (link))
974 sdbout_one_type (link);
976 #ifdef SDB_ALLOW_FORWARD_REFERENCES
977 sdbout_dequeue_anonymous_types ();
978 #endif
981 static void
982 sdbout_type (tree type)
984 if (type == error_mark_node)
985 type = integer_type_node;
986 PUT_SDB_TYPE (plain_type (type));
989 /* Output types of the fields of type TYPE, if they are structs.
991 Formerly did not chase through pointer types, since that could be circular.
992 They must come before TYPE, since forward refs are not allowed.
993 Now james@bigtex.cactus.org says to try them. */
995 static void
996 sdbout_field_types (tree type)
998 tree tail;
1000 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1001 /* This condition should match the one for emitting the actual
1002 members below. */
1003 if (TREE_CODE (tail) == FIELD_DECL
1004 && DECL_NAME (tail)
1005 && DECL_SIZE (tail)
1006 && tree_fits_uhwi_p (DECL_SIZE (tail))
1007 && tree_fits_shwi_p (bit_position (tail)))
1009 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1010 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1011 else
1012 sdbout_one_type (TREE_TYPE (tail));
1016 /* Use this to put out the top level defined record and union types
1017 for later reference. If this is a struct with a name, then put that
1018 name out. Other unnamed structs will have .xxfake labels generated so
1019 that they may be referred to later.
1020 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1021 It may NOT be called recursively. */
1023 static void
1024 sdbout_one_type (tree type)
1026 if (current_function_decl != NULL_TREE
1027 && DECL_SECTION_NAME (current_function_decl) != NULL)
1028 ; /* Don't change section amid function. */
1029 else
1030 switch_to_section (current_function_section ());
1032 switch (TREE_CODE (type))
1034 case RECORD_TYPE:
1035 case UNION_TYPE:
1036 case QUAL_UNION_TYPE:
1037 case ENUMERAL_TYPE:
1038 type = TYPE_MAIN_VARIANT (type);
1039 /* Don't output a type twice. */
1040 if (TREE_ASM_WRITTEN (type))
1041 /* James said test TREE_ASM_BEING_WRITTEN here. */
1042 return;
1044 /* Output nothing if type is not yet defined. */
1045 if (!COMPLETE_TYPE_P (type))
1046 return;
1048 TREE_ASM_WRITTEN (type) = 1;
1050 /* This is reputed to cause trouble with the following case,
1051 but perhaps checking TYPE_SIZE above will fix it. */
1053 /* Here is a testcase:
1055 struct foo {
1056 struct badstr *bbb;
1057 } forwardref;
1059 typedef struct intermediate {
1060 int aaaa;
1061 } intermediate_ref;
1063 typedef struct badstr {
1064 int ccccc;
1065 } badtype; */
1067 /* This change, which ought to make better output,
1068 used to make the COFF assembler unhappy.
1069 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1070 /* Before really doing anything, output types we want to refer to. */
1071 /* Note that in version 1 the following two lines
1072 are not used if forward references are in use. */
1073 if (TREE_CODE (type) != ENUMERAL_TYPE)
1074 sdbout_field_types (type);
1076 /* Output a structure type. */
1078 int size = int_size_in_bytes (type);
1079 int member_scl = 0;
1080 tree tem;
1082 /* Record the type tag, but not in its permanent place just yet. */
1083 sdbout_record_type_name (type);
1085 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1087 switch (TREE_CODE (type))
1089 case UNION_TYPE:
1090 case QUAL_UNION_TYPE:
1091 PUT_SDB_SCL (C_UNTAG);
1092 PUT_SDB_TYPE (T_UNION);
1093 member_scl = C_MOU;
1094 break;
1096 case RECORD_TYPE:
1097 PUT_SDB_SCL (C_STRTAG);
1098 PUT_SDB_TYPE (T_STRUCT);
1099 member_scl = C_MOS;
1100 break;
1102 case ENUMERAL_TYPE:
1103 PUT_SDB_SCL (C_ENTAG);
1104 PUT_SDB_TYPE (T_ENUM);
1105 member_scl = C_MOE;
1106 break;
1108 default:
1109 break;
1112 PUT_SDB_SIZE (size);
1113 PUT_SDB_ENDEF;
1115 /* Print out the base class information with fields
1116 named after the types they hold. */
1117 /* This is only relevant to aggregate types. TYPE_BINFO is used
1118 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1119 case. */
1120 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1122 int i;
1123 tree binfo, child;
1125 for (binfo = TYPE_BINFO (type), i = 0;
1126 BINFO_BASE_ITERATE (binfo, i, child); i++)
1128 tree child_type = BINFO_TYPE (child);
1129 tree child_type_name;
1131 if (TYPE_NAME (child_type) == 0)
1132 continue;
1133 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1134 child_type_name = TYPE_NAME (child_type);
1135 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1137 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1138 if (child_type_name && template_name_p (child_type_name))
1139 child_type_name
1140 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1142 else
1143 continue;
1145 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1146 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1147 PUT_SDB_SCL (member_scl);
1148 sdbout_type (BINFO_TYPE (child));
1149 PUT_SDB_ENDEF;
1153 /* Output the individual fields. */
1155 if (TREE_CODE (type) == ENUMERAL_TYPE)
1157 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1159 tree value = TREE_VALUE (tem);
1161 if (TREE_CODE (value) == CONST_DECL)
1162 value = DECL_INITIAL (value);
1164 if (tree_fits_shwi_p (value))
1166 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1167 PUT_SDB_INT_VAL (tree_to_shwi (value));
1168 PUT_SDB_SCL (C_MOE);
1169 PUT_SDB_TYPE (T_MOE);
1170 PUT_SDB_ENDEF;
1174 else /* record or union type */
1175 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1176 /* Output the name, type, position (in bits), size (in bits)
1177 of each field. */
1179 /* Omit here the nameless fields that are used to skip bits.
1180 Also omit fields with variable size or position.
1181 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1182 if (TREE_CODE (tem) == FIELD_DECL
1183 && DECL_NAME (tem)
1184 && DECL_SIZE (tem)
1185 && tree_fits_uhwi_p (DECL_SIZE (tem))
1186 && tree_fits_shwi_p (bit_position (tem)))
1188 const char *name;
1190 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1191 PUT_SDB_DEF (name);
1192 if (DECL_BIT_FIELD_TYPE (tem))
1194 PUT_SDB_INT_VAL (int_bit_position (tem));
1195 PUT_SDB_SCL (C_FIELD);
1196 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1197 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1199 else
1201 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1202 PUT_SDB_SCL (member_scl);
1203 sdbout_type (TREE_TYPE (tem));
1205 PUT_SDB_ENDEF;
1207 /* Output end of a structure,union, or enumeral definition. */
1209 PUT_SDB_PLAIN_DEF ("eos");
1210 PUT_SDB_INT_VAL (size);
1211 PUT_SDB_SCL (C_EOS);
1212 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1213 PUT_SDB_SIZE (size);
1214 PUT_SDB_ENDEF;
1215 break;
1218 default:
1219 break;
1223 /* The following two functions output definitions of function parameters.
1224 Each parameter gets a definition locating it in the parameter list.
1225 Each parameter that is a register variable gets a second definition
1226 locating it in the register.
1228 Printing or argument lists in gdb uses the definitions that
1229 locate in the parameter list. But reference to the variable in
1230 expressions uses preferentially the definition as a register. */
1232 /* Output definitions, referring to storage in the parmlist,
1233 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1235 static void
1236 sdbout_parms (tree parms)
1238 for (; parms; parms = TREE_CHAIN (parms))
1239 if (DECL_NAME (parms)
1240 && TREE_TYPE (parms) != error_mark_node
1241 && DECL_RTL_SET_P (parms)
1242 && DECL_INCOMING_RTL (parms))
1244 int current_sym_value = 0;
1245 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1247 if (name == 0 || *name == 0)
1248 name = gen_fake_label ();
1250 /* Perform any necessary register eliminations on the parameter's rtl,
1251 so that the debugging output will be accurate. */
1252 DECL_INCOMING_RTL (parms)
1253 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1254 SET_DECL_RTL (parms,
1255 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1257 if (PARM_PASSED_IN_MEMORY (parms))
1259 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1260 tree type;
1262 /* ??? Here we assume that the parm address is indexed
1263 off the frame pointer or arg pointer.
1264 If that is not true, we produce meaningless results,
1265 but do not crash. */
1266 if (GET_CODE (addr) == PLUS
1267 && CONST_INT_P (XEXP (addr, 1)))
1268 current_sym_value = INTVAL (XEXP (addr, 1));
1269 else
1270 current_sym_value = 0;
1272 if (REG_P (DECL_RTL (parms))
1273 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1274 type = DECL_ARG_TYPE (parms);
1275 else
1277 int original_sym_value = current_sym_value;
1279 /* This is the case where the parm is passed as an int or
1280 double and it is converted to a char, short or float
1281 and stored back in the parmlist. In this case, describe
1282 the parm with the variable's declared type, and adjust
1283 the address if the least significant bytes (which we are
1284 using) are not the first ones. */
1285 if (BYTES_BIG_ENDIAN
1286 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1287 current_sym_value +=
1288 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1289 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1291 if (MEM_P (DECL_RTL (parms))
1292 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1293 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1294 == CONST_INT)
1295 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1296 == current_sym_value))
1297 type = TREE_TYPE (parms);
1298 else
1300 current_sym_value = original_sym_value;
1301 type = DECL_ARG_TYPE (parms);
1305 PUT_SDB_DEF (name);
1306 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1307 PUT_SDB_SCL (C_ARG);
1308 PUT_SDB_TYPE (plain_type (type));
1309 PUT_SDB_ENDEF;
1311 else if (REG_P (DECL_RTL (parms)))
1313 rtx best_rtl;
1314 /* Parm passed in registers and lives in registers or nowhere. */
1316 /* If parm lives in a register, use that register;
1317 pretend the parm was passed there. It would be more consistent
1318 to describe the register where the parm was passed,
1319 but in practice that register usually holds something else. */
1320 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1321 best_rtl = DECL_RTL (parms);
1322 /* If the parm lives nowhere,
1323 use the register where it was passed. */
1324 else
1325 best_rtl = DECL_INCOMING_RTL (parms);
1327 PUT_SDB_DEF (name);
1328 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1329 PUT_SDB_SCL (C_REGPARM);
1330 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1331 PUT_SDB_ENDEF;
1333 else if (MEM_P (DECL_RTL (parms))
1334 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1336 /* Parm was passed in registers but lives on the stack. */
1338 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1339 in which case we want the value of that CONST_INT,
1340 or (MEM (REG ...)) or (MEM (MEM ...)),
1341 in which case we use a value of zero. */
1342 if (REG_P (XEXP (DECL_RTL (parms), 0))
1343 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1344 current_sym_value = 0;
1345 else
1346 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1348 /* Again, this assumes the offset is based on the arg pointer. */
1349 PUT_SDB_DEF (name);
1350 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1351 XEXP (DECL_RTL (parms), 0)));
1352 PUT_SDB_SCL (C_ARG);
1353 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1354 PUT_SDB_ENDEF;
1359 /* Output definitions for the places where parms live during the function,
1360 when different from where they were passed, when the parms were passed
1361 in memory.
1363 It is not useful to do this for parms passed in registers
1364 that live during the function in different registers, because it is
1365 impossible to look in the passed register for the passed value,
1366 so we use the within-the-function register to begin with.
1368 PARMS is a chain of PARM_DECL nodes. */
1370 static void
1371 sdbout_reg_parms (tree parms)
1373 for (; parms; parms = TREE_CHAIN (parms))
1374 if (DECL_NAME (parms)
1375 && TREE_TYPE (parms) != error_mark_node
1376 && DECL_RTL_SET_P (parms)
1377 && DECL_INCOMING_RTL (parms))
1379 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1381 /* Report parms that live in registers during the function
1382 but were passed in memory. */
1383 if (REG_P (DECL_RTL (parms))
1384 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1385 && PARM_PASSED_IN_MEMORY (parms))
1387 if (name == 0 || *name == 0)
1388 name = gen_fake_label ();
1389 PUT_SDB_DEF (name);
1390 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1391 PUT_SDB_SCL (C_REG);
1392 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1393 PUT_SDB_ENDEF;
1395 /* Report parms that live in memory but not where they were passed. */
1396 else if (MEM_P (DECL_RTL (parms))
1397 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1398 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1399 && PARM_PASSED_IN_MEMORY (parms)
1400 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1402 #if 0 /* ??? It is not clear yet what should replace this. */
1403 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1404 /* A parm declared char is really passed as an int,
1405 so it occupies the least significant bytes.
1406 On a big-endian machine those are not the low-numbered ones. */
1407 if (BYTES_BIG_ENDIAN
1408 && offset != -1
1409 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1410 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1411 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1412 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1413 #endif
1415 if (name == 0 || *name == 0)
1416 name = gen_fake_label ();
1417 PUT_SDB_DEF (name);
1418 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1419 (XEXP (DECL_RTL (parms), 0)));
1420 PUT_SDB_SCL (C_AUTO);
1421 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1422 PUT_SDB_ENDEF;
1428 /* Output early debug information for a global DECL. Called from
1429 rest_of_decl_compilation during parsing. */
1431 static void
1432 sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1434 /* NYI for non-dwarf. */
1437 /* Output late debug information for a global DECL after location
1438 information is available. */
1440 static void
1441 sdbout_late_global_decl (tree decl)
1443 if (TREE_CODE (decl) == VAR_DECL
1444 && !DECL_EXTERNAL (decl)
1445 && DECL_RTL_SET_P (decl))
1447 /* The COFF linker can move initialized global vars to the end.
1448 And that can screw up the symbol ordering. Defer those for
1449 sdbout_finish (). */
1450 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1451 sdbout_symbol (decl, 0);
1452 else
1453 vec_safe_push (deferred_global_decls, decl);
1455 /* Output COFF information for non-global file-scope initialized
1456 variables. */
1457 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1458 sdbout_toplevel_data (decl);
1462 /* Output initialized global vars at the end, in the order of
1463 definition. See comment in sdbout_global_decl. */
1465 static void
1466 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1468 size_t i;
1469 tree decl;
1471 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1472 sdbout_symbol (decl, 0);
1475 /* Describe the beginning of an internal block within a function.
1476 Also output descriptions of variables defined in this block.
1478 N is the number of the block, by order of beginning, counting from 1,
1479 and not counting the outermost (function top-level) block.
1480 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1481 if the count starts at 0 for the outermost one. */
1483 static void
1484 sdbout_begin_block (unsigned int line, unsigned int n)
1486 tree decl = current_function_decl;
1487 MAKE_LINE_SAFE (line);
1489 /* The SCO compiler does not emit a separate block for the function level
1490 scope, so we avoid it here also. */
1491 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1493 if (n == 1)
1495 /* Include the outermost BLOCK's variables in block 1. */
1496 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1497 sdbout_block (DECL_INITIAL (decl));
1499 /* If -g1, suppress all the internal symbols of functions
1500 except for arguments. */
1501 if (debug_info_level != DINFO_LEVEL_TERSE)
1503 do_block = n;
1504 sdbout_block (DECL_INITIAL (decl));
1507 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1508 sdbout_dequeue_anonymous_types ();
1509 #endif
1512 /* Describe the end line-number of an internal block within a function. */
1514 static void
1515 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1517 MAKE_LINE_SAFE (line);
1519 /* The SCO compiler does not emit a separate block for the function level
1520 scope, so we avoid it here also. */
1521 if (n != 1)
1522 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1525 /* Output a line number symbol entry for source file FILENAME and line
1526 number LINE. */
1528 static void
1529 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1530 int discriminator ATTRIBUTE_UNUSED,
1531 bool is_stmt ATTRIBUTE_UNUSED)
1533 /* COFF relative line numbers must be positive. */
1534 if ((int) line > sdb_begin_function_line)
1536 #ifdef SDB_OUTPUT_SOURCE_LINE
1537 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1538 #else
1539 fprintf (asm_out_file, "\t.ln\t%d\n",
1540 ((sdb_begin_function_line > -1)
1541 ? line - sdb_begin_function_line : 1));
1542 #endif
1546 /* Output sdb info for the current function name.
1547 Called from assemble_start_function. */
1549 static void
1550 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1552 sdbout_symbol (current_function_decl, 0);
1555 /* Called at beginning of function body after prologue. Record the
1556 function's starting line number, so we can output relative line numbers
1557 for the other lines. Describe beginning of outermost block. Also
1558 describe the parameter list. */
1560 static void
1561 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1563 sdbout_end_prologue (line, file);
1566 static void
1567 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1569 sdb_begin_function_line = line - 1;
1570 PUT_SDB_FUNCTION_START (line);
1571 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1572 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1575 /* Called at end of function (before epilogue).
1576 Describe end of outermost block. */
1578 static void
1579 sdbout_end_function (unsigned int line)
1581 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1582 sdbout_dequeue_anonymous_types ();
1583 #endif
1585 MAKE_LINE_SAFE (line);
1586 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1588 /* Indicate we are between functions, for line-number output. */
1589 sdb_begin_function_line = -1;
1592 /* Output sdb info for the absolute end of a function.
1593 Called after the epilogue is output. */
1595 static void
1596 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1597 const char *file ATTRIBUTE_UNUSED)
1599 const char *const name ATTRIBUTE_UNUSED
1600 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1602 #ifdef PUT_SDB_EPILOGUE_END
1603 PUT_SDB_EPILOGUE_END (name);
1604 #else
1605 fprintf (asm_out_file, "\t.def\t");
1606 assemble_name (asm_out_file, name);
1607 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1608 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1609 #endif
1612 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1613 is present. */
1615 static void
1616 sdbout_label (rtx_code_label *insn)
1618 PUT_SDB_DEF (LABEL_NAME (insn));
1619 PUT_SDB_VAL (insn);
1620 PUT_SDB_SCL (C_LABEL);
1621 PUT_SDB_TYPE (T_NULL);
1622 PUT_SDB_ENDEF;
1625 /* Change to reading from a new source file. */
1627 static void
1628 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1629 const char *filename ATTRIBUTE_UNUSED)
1633 /* Revert to reading a previous source file. */
1635 static void
1636 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1640 /* Set up for SDB output at the start of compilation. */
1642 static void
1643 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1645 tree t;
1647 vec_alloc (deferred_global_decls, 12);
1649 /* Emit debug information which was queued by sdbout_symbol before
1650 we got here. */
1651 sdbout_initialized = true;
1653 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1654 sdbout_symbol (TREE_VALUE (t), 0);
1655 preinit_symbols = 0;
1658 #endif /* SDB_DEBUGGING_INFO */
1660 #include "gt-sdbout.h"