svn merge -r 217500:218679 svn+ssh://gcc.gnu.org/svn/gcc/trunk
[official-gcc.git] / gcc / sdbout.c
blob4cea780c6ebd401dfa27cc92f240d29d394b129e
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2014 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 "tree.h"
48 #include "varasm.h"
49 #include "stor-layout.h"
50 #include "ggc.h"
51 #include "vec.h"
53 static GTY(()) tree anonymous_types;
55 /* Counter to generate unique "names" for nameless struct members. */
57 static GTY(()) int unnamed_struct_number;
59 /* Declarations whose debug info was deferred till end of compilation. */
61 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
63 /* The C front end may call sdbout_symbol before sdbout_init runs.
64 We save all such decls in this list and output them when we get
65 to sdbout_init. */
67 static GTY(()) tree preinit_symbols;
68 static GTY(()) bool sdbout_initialized;
70 #ifdef SDB_DEBUGGING_INFO
72 #include "rtl.h"
73 #include "regs.h"
74 #include "flags.h"
75 #include "insn-config.h"
76 #include "reload.h"
77 #include "output.h"
78 #include "diagnostic-core.h"
79 #include "tm_p.h"
80 #include "gsyms.h"
81 #include "langhooks.h"
82 #include "target.h"
84 /* 1 if PARM is passed to this function in memory. */
86 #define PARM_PASSED_IN_MEMORY(PARM) \
87 (MEM_P (DECL_INCOMING_RTL (PARM)))
89 /* A C expression for the integer offset value of an automatic variable
90 (C_AUTO) having address X (an RTX). */
91 #ifndef DEBUGGER_AUTO_OFFSET
92 #define DEBUGGER_AUTO_OFFSET(X) \
93 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
94 #endif
96 /* A C expression for the integer offset value of an argument (C_ARG)
97 having address X (an RTX). The nominal offset is OFFSET. */
98 #ifndef DEBUGGER_ARG_OFFSET
99 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
100 #endif
102 /* Line number of beginning of current function, minus one.
103 Negative means not in a function or not using sdb. */
105 int sdb_begin_function_line = -1;
108 extern FILE *asm_out_file;
110 extern tree current_function_decl;
112 #include "sdbout.h"
114 static void sdbout_init (const char *);
115 static void sdbout_finish (const char *);
116 static void sdbout_start_source_file (unsigned int, const char *);
117 static void sdbout_end_source_file (unsigned int);
118 static void sdbout_begin_block (unsigned int, unsigned int);
119 static void sdbout_end_block (unsigned int, unsigned int);
120 static void sdbout_source_line (unsigned int, const char *, int, bool);
121 static void sdbout_end_epilogue (unsigned int, const char *);
122 static void sdbout_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);
145 static void sdbout_global_decl (tree);
147 /* Random macros describing parts of SDB data. */
149 /* Default value of delimiter is ";". */
150 #ifndef SDB_DELIM
151 #define SDB_DELIM ";"
152 #endif
154 /* Maximum number of dimensions the assembler will allow. */
155 #ifndef SDB_MAX_DIM
156 #define SDB_MAX_DIM 4
157 #endif
159 #ifndef PUT_SDB_SCL
160 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
161 #endif
163 #ifndef PUT_SDB_INT_VAL
164 #define PUT_SDB_INT_VAL(a) \
165 do { \
166 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
167 (HOST_WIDE_INT) (a), SDB_DELIM); \
168 } while (0)
170 #endif
172 #ifndef PUT_SDB_VAL
173 #define PUT_SDB_VAL(a) \
174 ( fputs ("\t.val\t", asm_out_file), \
175 output_addr_const (asm_out_file, (a)), \
176 fprintf (asm_out_file, SDB_DELIM))
177 #endif
179 #ifndef PUT_SDB_DEF
180 #define PUT_SDB_DEF(a) \
181 do { fprintf (asm_out_file, "\t.def\t"); \
182 assemble_name (asm_out_file, a); \
183 fprintf (asm_out_file, SDB_DELIM); } while (0)
184 #endif
186 #ifndef PUT_SDB_PLAIN_DEF
187 #define PUT_SDB_PLAIN_DEF(a) \
188 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
189 #endif
191 #ifndef PUT_SDB_ENDEF
192 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
193 #endif
195 #ifndef PUT_SDB_TYPE
196 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
197 #endif
199 #ifndef PUT_SDB_SIZE
200 #define PUT_SDB_SIZE(a) \
201 do { \
202 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
203 (HOST_WIDE_INT) (a), SDB_DELIM); \
204 } while (0)
205 #endif
207 #ifndef PUT_SDB_START_DIM
208 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
209 #endif
211 #ifndef PUT_SDB_NEXT_DIM
212 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
213 #endif
215 #ifndef PUT_SDB_LAST_DIM
216 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
217 #endif
219 #ifndef PUT_SDB_TAG
220 #define PUT_SDB_TAG(a) \
221 do { fprintf (asm_out_file, "\t.tag\t"); \
222 assemble_name (asm_out_file, a); \
223 fprintf (asm_out_file, SDB_DELIM); } while (0)
224 #endif
226 #ifndef PUT_SDB_BLOCK_START
227 #define PUT_SDB_BLOCK_START(LINE) \
228 fprintf (asm_out_file, \
229 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
230 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
231 #endif
233 #ifndef PUT_SDB_BLOCK_END
234 #define PUT_SDB_BLOCK_END(LINE) \
235 fprintf (asm_out_file, \
236 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
237 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
238 #endif
240 #ifndef PUT_SDB_FUNCTION_START
241 #define PUT_SDB_FUNCTION_START(LINE) \
242 fprintf (asm_out_file, \
243 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
244 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
245 #endif
247 #ifndef PUT_SDB_FUNCTION_END
248 #define PUT_SDB_FUNCTION_END(LINE) \
249 fprintf (asm_out_file, \
250 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
251 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
252 #endif
254 /* Return the sdb tag identifier string for TYPE
255 if TYPE has already been defined; otherwise return a null pointer. */
257 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
259 /* Set the sdb tag identifier string for TYPE to NAME. */
261 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
262 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
264 /* Return the name (a string) of the struct, union or enum tag
265 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
267 #define TAG_NAME(link) \
268 (((link) && TREE_PURPOSE ((link)) \
269 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
270 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
272 /* Ensure we don't output a negative line number. */
273 #define MAKE_LINE_SAFE(line) \
274 if ((int) line <= sdb_begin_function_line) \
275 line = sdb_begin_function_line + 1
277 /* The debug hooks structure. */
278 const struct gcc_debug_hooks sdb_debug_hooks =
280 sdbout_init, /* init */
281 sdbout_finish, /* 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, /* function_decl */
298 sdbout_global_decl, /* global_decl */
299 sdbout_symbol, /* type_decl */
300 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
301 debug_nothing_tree, /* deferred_inline_function */
302 debug_nothing_tree, /* outlining_inline_function */
303 sdbout_label, /* label */
304 debug_nothing_int, /* handle_pch */
305 debug_nothing_rtx_insn, /* var_location */
306 debug_nothing_void, /* switch_text_section */
307 debug_nothing_tree_tree, /* set_name */
308 0, /* start_end_main_source_file */
309 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
312 /* Return a unique string to name an anonymous type. */
314 static char *
315 gen_fake_label (void)
317 char label[10];
318 char *labelstr;
319 sprintf (label, ".%dfake", unnamed_struct_number);
320 unnamed_struct_number++;
321 labelstr = xstrdup (label);
322 return labelstr;
325 /* Return the number which describes TYPE for SDB.
326 For pointers, etc., this function is recursive.
327 Each record, union or enumeral type must already have had a
328 tag number output. */
330 /* The number is given by d6d5d4d3d2d1bbbb
331 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
332 Thus, char *foo () has bbbb=T_CHAR
333 d1=D_FCN
334 d2=D_PTR
335 N_BTMASK= 017 1111 basic type field.
336 N_TSHIFT= 2 derived type shift
337 N_BTSHFT= 4 Basic type shift */
339 /* Produce the number that describes a pointer, function or array type.
340 PREV is the number describing the target, value or element type.
341 DT_type describes how to transform that type. */
342 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
343 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
344 | ((int) DT_type << (int) N_BTSHFT) \
345 | ((PREV) & (int) N_BTMASK))
347 /* Number of elements used in sdb_dims. */
348 static int sdb_n_dims = 0;
350 /* Table of array dimensions of current type. */
351 static int sdb_dims[SDB_MAX_DIM];
353 /* Size of outermost array currently being processed. */
354 static int sdb_type_size = -1;
356 static int
357 plain_type (tree type)
359 int val = plain_type_1 (type, 0);
361 /* If we have already saved up some array dimensions, print them now. */
362 if (sdb_n_dims > 0)
364 int i;
365 PUT_SDB_START_DIM;
366 for (i = sdb_n_dims - 1; i > 0; i--)
367 PUT_SDB_NEXT_DIM (sdb_dims[i]);
368 PUT_SDB_LAST_DIM (sdb_dims[0]);
369 sdb_n_dims = 0;
371 sdb_type_size = int_size_in_bytes (type);
372 /* Don't kill sdb if type is not laid out or has variable size. */
373 if (sdb_type_size < 0)
374 sdb_type_size = 0;
376 /* If we have computed the size of an array containing this type,
377 print it now. */
378 if (sdb_type_size >= 0)
380 PUT_SDB_SIZE (sdb_type_size);
381 sdb_type_size = -1;
383 return val;
386 static int
387 template_name_p (tree name)
389 const char *ptr = IDENTIFIER_POINTER (name);
390 while (*ptr && *ptr != '<')
391 ptr++;
393 return *ptr != '\0';
396 static void
397 sdbout_record_type_name (tree type)
399 const char *name = 0;
400 int no_name;
402 if (KNOWN_TYPE_TAG (type))
403 return;
405 if (TYPE_NAME (type) != 0)
407 tree t = 0;
409 /* Find the IDENTIFIER_NODE for the type name. */
410 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
411 t = TYPE_NAME (type);
412 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
414 t = DECL_NAME (TYPE_NAME (type));
415 /* The DECL_NAME for templates includes "<>", which breaks
416 most assemblers. Use its assembler name instead, which
417 has been mangled into being safe. */
418 if (t && template_name_p (t))
419 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
422 /* Now get the name as a string, or invent one. */
423 if (t != NULL_TREE)
424 name = IDENTIFIER_POINTER (t);
427 no_name = (name == 0 || *name == 0);
428 if (no_name)
429 name = gen_fake_label ();
431 SET_KNOWN_TYPE_TAG (type, name);
432 #ifdef SDB_ALLOW_FORWARD_REFERENCES
433 if (no_name)
434 sdbout_queue_anonymous_type (type);
435 #endif
438 /* Return the .type value for type TYPE.
440 LEVEL indicates how many levels deep we have recursed into the type.
441 The SDB debug format can only represent 6 derived levels of types.
442 After that, we must output inaccurate debug info. We deliberately
443 stop before the 7th level, so that ADA recursive types will not give an
444 infinite loop. */
446 static int
447 plain_type_1 (tree type, int level)
449 if (type == 0)
450 type = void_type_node;
451 else if (type == error_mark_node)
452 type = integer_type_node;
453 else
454 type = TYPE_MAIN_VARIANT (type);
456 switch (TREE_CODE (type))
458 case VOID_TYPE:
459 case NULLPTR_TYPE:
460 return T_VOID;
461 case BOOLEAN_TYPE:
462 case INTEGER_TYPE:
464 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
466 /* Carefully distinguish all the standard types of C,
467 without messing up if the language is not C.
468 Note that we check only for the names that contain spaces;
469 other names might occur by coincidence in other languages. */
470 if (TYPE_NAME (type) != 0
471 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
472 && DECL_NAME (TYPE_NAME (type)) != 0
473 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
475 const char *const name
476 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
478 if (!strcmp (name, "char"))
479 return T_CHAR;
480 if (!strcmp (name, "unsigned char"))
481 return T_UCHAR;
482 if (!strcmp (name, "signed char"))
483 return T_CHAR;
484 if (!strcmp (name, "int"))
485 return T_INT;
486 if (!strcmp (name, "unsigned int"))
487 return T_UINT;
488 if (!strcmp (name, "short int"))
489 return T_SHORT;
490 if (!strcmp (name, "short unsigned int"))
491 return T_USHORT;
492 if (!strcmp (name, "long int"))
493 return T_LONG;
494 if (!strcmp (name, "long unsigned int"))
495 return T_ULONG;
498 if (size == INT_TYPE_SIZE)
499 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
500 if (size == CHAR_TYPE_SIZE)
501 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
502 if (size == SHORT_TYPE_SIZE)
503 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
504 if (size == LONG_TYPE_SIZE)
505 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
506 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
507 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
508 return 0;
511 case REAL_TYPE:
513 int precision = TYPE_PRECISION (type);
514 if (precision == FLOAT_TYPE_SIZE)
515 return T_FLOAT;
516 if (precision == DOUBLE_TYPE_SIZE)
517 return T_DOUBLE;
518 #ifdef EXTENDED_SDB_BASIC_TYPES
519 if (precision == LONG_DOUBLE_TYPE_SIZE)
520 return T_LNGDBL;
521 #else
522 if (precision == LONG_DOUBLE_TYPE_SIZE)
523 return T_DOUBLE; /* better than nothing */
524 #endif
525 return 0;
528 case ARRAY_TYPE:
530 int m;
531 if (level >= 6)
532 return T_VOID;
533 else
534 m = plain_type_1 (TREE_TYPE (type), level+1);
535 if (sdb_n_dims < SDB_MAX_DIM)
536 sdb_dims[sdb_n_dims++]
537 = (TYPE_DOMAIN (type)
538 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
539 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
540 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
541 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
542 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
543 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
544 : 0);
546 return PUSH_DERIVED_LEVEL (DT_ARY, m);
549 case RECORD_TYPE:
550 case UNION_TYPE:
551 case QUAL_UNION_TYPE:
552 case ENUMERAL_TYPE:
554 const char *tag;
555 #ifdef SDB_ALLOW_FORWARD_REFERENCES
556 sdbout_record_type_name (type);
557 #endif
558 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
559 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
560 #ifdef SDB_ALLOW_FORWARD_REFERENCES
561 || TYPE_MODE (type) != VOIDmode
562 #endif
564 #endif
566 /* Output the referenced structure tag name
567 only if the .def has already been finished.
568 At least on 386, the Unix assembler
569 cannot handle forward references to tags. */
570 /* But the 88100, it requires them, sigh... */
571 /* And the MIPS requires unknown refs as well... */
572 tag = KNOWN_TYPE_TAG (type);
573 PUT_SDB_TAG (tag);
574 /* These 3 lines used to follow the close brace.
575 However, a size of 0 without a tag implies a tag of 0,
576 so if we don't know a tag, we can't mention the size. */
577 sdb_type_size = int_size_in_bytes (type);
578 if (sdb_type_size < 0)
579 sdb_type_size = 0;
581 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
582 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
583 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
584 : T_ENUM);
586 case POINTER_TYPE:
587 case REFERENCE_TYPE:
589 int m;
590 if (level >= 6)
591 return T_VOID;
592 else
593 m = plain_type_1 (TREE_TYPE (type), level+1);
594 return PUSH_DERIVED_LEVEL (DT_PTR, m);
596 case FUNCTION_TYPE:
597 case METHOD_TYPE:
599 int m;
600 if (level >= 6)
601 return T_VOID;
602 else
603 m = plain_type_1 (TREE_TYPE (type), level+1);
604 return PUSH_DERIVED_LEVEL (DT_FCN, m);
606 default:
607 return 0;
611 /* Output the symbols defined in block number DO_BLOCK.
613 This function works by walking the tree structure of blocks,
614 counting blocks until it finds the desired block. */
616 static int do_block = 0;
618 static void
619 sdbout_block (tree block)
621 while (block)
623 /* Ignore blocks never expanded or otherwise marked as real. */
624 if (TREE_USED (block))
626 /* When we reach the specified block, output its symbols. */
627 if (BLOCK_NUMBER (block) == do_block)
628 sdbout_syms (BLOCK_VARS (block));
630 /* If we are past the specified block, stop the scan. */
631 if (BLOCK_NUMBER (block) > do_block)
632 return;
634 /* Scan the blocks within this block. */
635 sdbout_block (BLOCK_SUBBLOCKS (block));
638 block = BLOCK_CHAIN (block);
642 /* Call sdbout_symbol on each decl in the chain SYMS. */
644 static void
645 sdbout_syms (tree syms)
647 while (syms)
649 if (TREE_CODE (syms) != LABEL_DECL)
650 sdbout_symbol (syms, 1);
651 syms = TREE_CHAIN (syms);
655 /* Output SDB information for a symbol described by DECL.
656 LOCAL is nonzero if the symbol is not file-scope. */
658 void
659 sdbout_symbol (tree decl, int local)
661 tree type = TREE_TYPE (decl);
662 tree context = NULL_TREE;
663 rtx value;
664 int regno = -1;
665 const char *name;
667 /* If we are called before sdbout_init is run, just save the symbol
668 for later. */
669 if (!sdbout_initialized)
671 preinit_symbols = tree_cons (0, decl, preinit_symbols);
672 return;
675 sdbout_one_type (type);
677 switch (TREE_CODE (decl))
679 case CONST_DECL:
680 /* Enum values are defined by defining the enum type. */
681 return;
683 case FUNCTION_DECL:
684 /* Don't mention a nested function under its parent. */
685 context = decl_function_context (decl);
686 if (context == current_function_decl)
687 return;
688 /* Check DECL_INITIAL to distinguish declarations from definitions.
689 Don't output debug info here for declarations; they will have
690 a DECL_INITIAL value of 0. */
691 if (! DECL_INITIAL (decl))
692 return;
693 if (!MEM_P (DECL_RTL (decl))
694 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
695 return;
696 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
697 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
698 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
699 break;
701 case TYPE_DECL:
702 /* Done with tagged types. */
703 if (DECL_NAME (decl) == 0)
704 return;
705 if (DECL_IGNORED_P (decl))
706 return;
707 /* Don't output intrinsic types. GAS chokes on SDB .def
708 statements that contain identifiers with embedded spaces
709 (eg "unsigned long"). */
710 if (DECL_IS_BUILTIN (decl))
711 return;
713 /* Output typedef name. */
714 if (template_name_p (DECL_NAME (decl)))
715 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
716 else
717 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
718 PUT_SDB_SCL (C_TPDEF);
719 break;
721 case PARM_DECL:
722 /* Parm decls go in their own separate chains
723 and are output by sdbout_reg_parms and sdbout_parms. */
724 gcc_unreachable ();
726 case VAR_DECL:
727 /* Don't mention a variable that is external.
728 Let the file that defines it describe it. */
729 if (DECL_EXTERNAL (decl))
730 return;
732 /* Ignore __FUNCTION__, etc. */
733 if (DECL_IGNORED_P (decl))
734 return;
736 /* If there was an error in the declaration, don't dump core
737 if there is no RTL associated with the variable doesn't
738 exist. */
739 if (!DECL_RTL_SET_P (decl))
740 return;
742 value = DECL_RTL (decl);
744 if (!is_global_var (decl))
745 value = eliminate_regs (value, VOIDmode, NULL_RTX);
747 SET_DECL_RTL (decl, value);
748 #ifdef LEAF_REG_REMAP
749 if (crtl->uses_only_leaf_regs)
750 leaf_renumber_regs_insn (value);
751 #endif
753 /* Don't mention a variable at all
754 if it was completely optimized into nothingness.
756 If DECL was from an inline function, then its rtl
757 is not identically the rtl that was used in this
758 particular compilation. */
759 if (REG_P (value))
761 regno = REGNO (value);
762 if (regno >= FIRST_PSEUDO_REGISTER)
763 return;
765 else if (GET_CODE (value) == SUBREG)
767 while (GET_CODE (value) == SUBREG)
768 value = SUBREG_REG (value);
769 if (REG_P (value))
771 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
772 return;
774 regno = REGNO (alter_subreg (&value, true));
775 SET_DECL_RTL (decl, value);
777 /* Don't output anything if an auto variable
778 gets RTL that is static.
779 GAS version 2.2 can't handle such output. */
780 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
781 && ! TREE_STATIC (decl))
782 return;
784 /* Emit any structure, union, or enum type that has not been output.
785 This occurs for tag-less structs (et al) used to declare variables
786 within functions. */
787 if (TREE_CODE (type) == ENUMERAL_TYPE
788 || TREE_CODE (type) == RECORD_TYPE
789 || TREE_CODE (type) == UNION_TYPE
790 || TREE_CODE (type) == QUAL_UNION_TYPE)
792 if (COMPLETE_TYPE_P (type) /* not a forward reference */
793 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
794 sdbout_one_type (type);
797 /* Defer SDB information for top-level initialized variables! */
798 if (! local
799 && MEM_P (value)
800 && DECL_INITIAL (decl))
801 return;
803 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
804 For now, avoid crashing. */
805 if (DECL_NAME (decl) == NULL_TREE)
806 return;
808 /* Record the name for, starting a symtab entry. */
809 if (local)
810 name = IDENTIFIER_POINTER (DECL_NAME (decl));
811 else
812 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
814 if (MEM_P (value)
815 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
817 PUT_SDB_DEF (name);
818 if (TREE_PUBLIC (decl))
820 PUT_SDB_VAL (XEXP (value, 0));
821 PUT_SDB_SCL (C_EXT);
823 else
825 PUT_SDB_VAL (XEXP (value, 0));
826 PUT_SDB_SCL (C_STAT);
829 else if (regno >= 0)
831 PUT_SDB_DEF (name);
832 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
833 PUT_SDB_SCL (C_REG);
835 else if (MEM_P (value)
836 && (MEM_P (XEXP (value, 0))
837 || (REG_P (XEXP (value, 0))
838 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
839 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
840 /* If the value is indirect by memory or by a register
841 that isn't the frame pointer
842 then it means the object is variable-sized and address through
843 that register or stack slot. COFF has no way to represent this
844 so all we can do is output the variable as a pointer. */
846 PUT_SDB_DEF (name);
847 if (REG_P (XEXP (value, 0)))
849 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
850 PUT_SDB_SCL (C_REG);
852 else
854 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
855 (CONST_INT...)))).
856 We want the value of that CONST_INT. */
857 /* Encore compiler hates a newline in a macro arg, it seems. */
858 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
859 (XEXP (XEXP (value, 0), 0)));
860 PUT_SDB_SCL (C_AUTO);
863 /* Effectively do build_pointer_type, but don't cache this type,
864 since it might be temporary whereas the type it points to
865 might have been saved for inlining. */
866 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
867 type = make_node (POINTER_TYPE);
868 TREE_TYPE (type) = TREE_TYPE (decl);
870 else if (MEM_P (value)
871 && ((GET_CODE (XEXP (value, 0)) == PLUS
872 && REG_P (XEXP (XEXP (value, 0), 0))
873 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
874 /* This is for variables which are at offset zero from
875 the frame pointer. This happens on the Alpha.
876 Non-frame pointer registers are excluded above. */
877 || (REG_P (XEXP (value, 0)))))
879 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
880 or (MEM (REG...)). We want the value of that CONST_INT
881 or zero. */
882 PUT_SDB_DEF (name);
883 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
884 PUT_SDB_SCL (C_AUTO);
886 else
888 /* It is something we don't know how to represent for SDB. */
889 return;
891 break;
893 default:
894 break;
896 PUT_SDB_TYPE (plain_type (type));
897 PUT_SDB_ENDEF;
900 /* Output SDB information for a top-level initialized variable
901 that has been delayed. */
903 static void
904 sdbout_toplevel_data (tree decl)
906 tree type = TREE_TYPE (decl);
908 if (DECL_IGNORED_P (decl))
909 return;
911 gcc_assert (TREE_CODE (decl) == VAR_DECL);
912 gcc_assert (MEM_P (DECL_RTL (decl)));
913 gcc_assert (DECL_INITIAL (decl));
915 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
916 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
917 if (TREE_PUBLIC (decl))
919 PUT_SDB_SCL (C_EXT);
921 else
923 PUT_SDB_SCL (C_STAT);
925 PUT_SDB_TYPE (plain_type (type));
926 PUT_SDB_ENDEF;
929 #ifdef SDB_ALLOW_FORWARD_REFERENCES
931 /* Machinery to record and output anonymous types. */
933 static void
934 sdbout_queue_anonymous_type (tree type)
936 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
939 static void
940 sdbout_dequeue_anonymous_types (void)
942 tree types, link;
944 while (anonymous_types)
946 types = nreverse (anonymous_types);
947 anonymous_types = NULL_TREE;
949 for (link = types; link; link = TREE_CHAIN (link))
951 tree type = TREE_VALUE (link);
953 if (type && ! TREE_ASM_WRITTEN (type))
954 sdbout_one_type (type);
959 #endif
961 /* Given a chain of ..._TYPE nodes, all of which have names,
962 output definitions of those names, as typedefs. */
964 void
965 sdbout_types (tree types)
967 tree link;
969 for (link = types; link; link = TREE_CHAIN (link))
970 sdbout_one_type (link);
972 #ifdef SDB_ALLOW_FORWARD_REFERENCES
973 sdbout_dequeue_anonymous_types ();
974 #endif
977 static void
978 sdbout_type (tree type)
980 if (type == error_mark_node)
981 type = integer_type_node;
982 PUT_SDB_TYPE (plain_type (type));
985 /* Output types of the fields of type TYPE, if they are structs.
987 Formerly did not chase through pointer types, since that could be circular.
988 They must come before TYPE, since forward refs are not allowed.
989 Now james@bigtex.cactus.org says to try them. */
991 static void
992 sdbout_field_types (tree type)
994 tree tail;
996 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
997 /* This condition should match the one for emitting the actual
998 members below. */
999 if (TREE_CODE (tail) == FIELD_DECL
1000 && DECL_NAME (tail)
1001 && DECL_SIZE (tail)
1002 && tree_fits_uhwi_p (DECL_SIZE (tail))
1003 && tree_fits_shwi_p (bit_position (tail)))
1005 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1006 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1007 else
1008 sdbout_one_type (TREE_TYPE (tail));
1012 /* Use this to put out the top level defined record and union types
1013 for later reference. If this is a struct with a name, then put that
1014 name out. Other unnamed structs will have .xxfake labels generated so
1015 that they may be referred to later.
1016 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1017 It may NOT be called recursively. */
1019 static void
1020 sdbout_one_type (tree type)
1022 if (current_function_decl != NULL_TREE
1023 && DECL_SECTION_NAME (current_function_decl) != NULL)
1024 ; /* Don't change section amid function. */
1025 else
1026 switch_to_section (current_function_section ());
1028 switch (TREE_CODE (type))
1030 case RECORD_TYPE:
1031 case UNION_TYPE:
1032 case QUAL_UNION_TYPE:
1033 case ENUMERAL_TYPE:
1034 type = TYPE_MAIN_VARIANT (type);
1035 /* Don't output a type twice. */
1036 if (TREE_ASM_WRITTEN (type))
1037 /* James said test TREE_ASM_BEING_WRITTEN here. */
1038 return;
1040 /* Output nothing if type is not yet defined. */
1041 if (!COMPLETE_TYPE_P (type))
1042 return;
1044 TREE_ASM_WRITTEN (type) = 1;
1046 /* This is reputed to cause trouble with the following case,
1047 but perhaps checking TYPE_SIZE above will fix it. */
1049 /* Here is a testcase:
1051 struct foo {
1052 struct badstr *bbb;
1053 } forwardref;
1055 typedef struct intermediate {
1056 int aaaa;
1057 } intermediate_ref;
1059 typedef struct badstr {
1060 int ccccc;
1061 } badtype; */
1063 /* This change, which ought to make better output,
1064 used to make the COFF assembler unhappy.
1065 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1066 /* Before really doing anything, output types we want to refer to. */
1067 /* Note that in version 1 the following two lines
1068 are not used if forward references are in use. */
1069 if (TREE_CODE (type) != ENUMERAL_TYPE)
1070 sdbout_field_types (type);
1072 /* Output a structure type. */
1074 int size = int_size_in_bytes (type);
1075 int member_scl = 0;
1076 tree tem;
1078 /* Record the type tag, but not in its permanent place just yet. */
1079 sdbout_record_type_name (type);
1081 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1083 switch (TREE_CODE (type))
1085 case UNION_TYPE:
1086 case QUAL_UNION_TYPE:
1087 PUT_SDB_SCL (C_UNTAG);
1088 PUT_SDB_TYPE (T_UNION);
1089 member_scl = C_MOU;
1090 break;
1092 case RECORD_TYPE:
1093 PUT_SDB_SCL (C_STRTAG);
1094 PUT_SDB_TYPE (T_STRUCT);
1095 member_scl = C_MOS;
1096 break;
1098 case ENUMERAL_TYPE:
1099 PUT_SDB_SCL (C_ENTAG);
1100 PUT_SDB_TYPE (T_ENUM);
1101 member_scl = C_MOE;
1102 break;
1104 default:
1105 break;
1108 PUT_SDB_SIZE (size);
1109 PUT_SDB_ENDEF;
1111 /* Print out the base class information with fields
1112 named after the types they hold. */
1113 /* This is only relevant to aggregate types. TYPE_BINFO is used
1114 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1115 case. */
1116 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1118 int i;
1119 tree binfo, child;
1121 for (binfo = TYPE_BINFO (type), i = 0;
1122 BINFO_BASE_ITERATE (binfo, i, child); i++)
1124 tree child_type = BINFO_TYPE (child);
1125 tree child_type_name;
1127 if (TYPE_NAME (child_type) == 0)
1128 continue;
1129 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1130 child_type_name = TYPE_NAME (child_type);
1131 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1133 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1134 if (child_type_name && template_name_p (child_type_name))
1135 child_type_name
1136 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1138 else
1139 continue;
1141 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1142 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1143 PUT_SDB_SCL (member_scl);
1144 sdbout_type (BINFO_TYPE (child));
1145 PUT_SDB_ENDEF;
1149 /* Output the individual fields. */
1151 if (TREE_CODE (type) == ENUMERAL_TYPE)
1153 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1155 tree value = TREE_VALUE (tem);
1157 if (TREE_CODE (value) == CONST_DECL)
1158 value = DECL_INITIAL (value);
1160 if (tree_fits_shwi_p (value))
1162 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1163 PUT_SDB_INT_VAL (tree_to_shwi (value));
1164 PUT_SDB_SCL (C_MOE);
1165 PUT_SDB_TYPE (T_MOE);
1166 PUT_SDB_ENDEF;
1170 else /* record or union type */
1171 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1172 /* Output the name, type, position (in bits), size (in bits)
1173 of each field. */
1175 /* Omit here the nameless fields that are used to skip bits.
1176 Also omit fields with variable size or position.
1177 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1178 if (TREE_CODE (tem) == FIELD_DECL
1179 && DECL_NAME (tem)
1180 && DECL_SIZE (tem)
1181 && tree_fits_uhwi_p (DECL_SIZE (tem))
1182 && tree_fits_shwi_p (bit_position (tem)))
1184 const char *name;
1186 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1187 PUT_SDB_DEF (name);
1188 if (DECL_BIT_FIELD_TYPE (tem))
1190 PUT_SDB_INT_VAL (int_bit_position (tem));
1191 PUT_SDB_SCL (C_FIELD);
1192 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1193 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1195 else
1197 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1198 PUT_SDB_SCL (member_scl);
1199 sdbout_type (TREE_TYPE (tem));
1201 PUT_SDB_ENDEF;
1203 /* Output end of a structure,union, or enumeral definition. */
1205 PUT_SDB_PLAIN_DEF ("eos");
1206 PUT_SDB_INT_VAL (size);
1207 PUT_SDB_SCL (C_EOS);
1208 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1209 PUT_SDB_SIZE (size);
1210 PUT_SDB_ENDEF;
1211 break;
1214 default:
1215 break;
1219 /* The following two functions output definitions of function parameters.
1220 Each parameter gets a definition locating it in the parameter list.
1221 Each parameter that is a register variable gets a second definition
1222 locating it in the register.
1224 Printing or argument lists in gdb uses the definitions that
1225 locate in the parameter list. But reference to the variable in
1226 expressions uses preferentially the definition as a register. */
1228 /* Output definitions, referring to storage in the parmlist,
1229 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1231 static void
1232 sdbout_parms (tree parms)
1234 for (; parms; parms = TREE_CHAIN (parms))
1235 if (DECL_NAME (parms)
1236 && TREE_TYPE (parms) != error_mark_node
1237 && DECL_RTL_SET_P (parms)
1238 && DECL_INCOMING_RTL (parms))
1240 int current_sym_value = 0;
1241 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1243 if (name == 0 || *name == 0)
1244 name = gen_fake_label ();
1246 /* Perform any necessary register eliminations on the parameter's rtl,
1247 so that the debugging output will be accurate. */
1248 DECL_INCOMING_RTL (parms)
1249 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1250 SET_DECL_RTL (parms,
1251 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1253 if (PARM_PASSED_IN_MEMORY (parms))
1255 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1256 tree type;
1258 /* ??? Here we assume that the parm address is indexed
1259 off the frame pointer or arg pointer.
1260 If that is not true, we produce meaningless results,
1261 but do not crash. */
1262 if (GET_CODE (addr) == PLUS
1263 && CONST_INT_P (XEXP (addr, 1)))
1264 current_sym_value = INTVAL (XEXP (addr, 1));
1265 else
1266 current_sym_value = 0;
1268 if (REG_P (DECL_RTL (parms))
1269 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1270 type = DECL_ARG_TYPE (parms);
1271 else
1273 int original_sym_value = current_sym_value;
1275 /* This is the case where the parm is passed as an int or
1276 double and it is converted to a char, short or float
1277 and stored back in the parmlist. In this case, describe
1278 the parm with the variable's declared type, and adjust
1279 the address if the least significant bytes (which we are
1280 using) are not the first ones. */
1281 if (BYTES_BIG_ENDIAN
1282 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1283 current_sym_value +=
1284 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1285 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1287 if (MEM_P (DECL_RTL (parms))
1288 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1289 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1290 == CONST_INT)
1291 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1292 == current_sym_value))
1293 type = TREE_TYPE (parms);
1294 else
1296 current_sym_value = original_sym_value;
1297 type = DECL_ARG_TYPE (parms);
1301 PUT_SDB_DEF (name);
1302 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1303 PUT_SDB_SCL (C_ARG);
1304 PUT_SDB_TYPE (plain_type (type));
1305 PUT_SDB_ENDEF;
1307 else if (REG_P (DECL_RTL (parms)))
1309 rtx best_rtl;
1310 /* Parm passed in registers and lives in registers or nowhere. */
1312 /* If parm lives in a register, use that register;
1313 pretend the parm was passed there. It would be more consistent
1314 to describe the register where the parm was passed,
1315 but in practice that register usually holds something else. */
1316 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1317 best_rtl = DECL_RTL (parms);
1318 /* If the parm lives nowhere,
1319 use the register where it was passed. */
1320 else
1321 best_rtl = DECL_INCOMING_RTL (parms);
1323 PUT_SDB_DEF (name);
1324 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1325 PUT_SDB_SCL (C_REGPARM);
1326 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1327 PUT_SDB_ENDEF;
1329 else if (MEM_P (DECL_RTL (parms))
1330 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1332 /* Parm was passed in registers but lives on the stack. */
1334 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1335 in which case we want the value of that CONST_INT,
1336 or (MEM (REG ...)) or (MEM (MEM ...)),
1337 in which case we use a value of zero. */
1338 if (REG_P (XEXP (DECL_RTL (parms), 0))
1339 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1340 current_sym_value = 0;
1341 else
1342 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1344 /* Again, this assumes the offset is based on the arg pointer. */
1345 PUT_SDB_DEF (name);
1346 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1347 XEXP (DECL_RTL (parms), 0)));
1348 PUT_SDB_SCL (C_ARG);
1349 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1350 PUT_SDB_ENDEF;
1355 /* Output definitions for the places where parms live during the function,
1356 when different from where they were passed, when the parms were passed
1357 in memory.
1359 It is not useful to do this for parms passed in registers
1360 that live during the function in different registers, because it is
1361 impossible to look in the passed register for the passed value,
1362 so we use the within-the-function register to begin with.
1364 PARMS is a chain of PARM_DECL nodes. */
1366 static void
1367 sdbout_reg_parms (tree parms)
1369 for (; parms; parms = TREE_CHAIN (parms))
1370 if (DECL_NAME (parms)
1371 && TREE_TYPE (parms) != error_mark_node
1372 && DECL_RTL_SET_P (parms)
1373 && DECL_INCOMING_RTL (parms))
1375 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1377 /* Report parms that live in registers during the function
1378 but were passed in memory. */
1379 if (REG_P (DECL_RTL (parms))
1380 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1381 && PARM_PASSED_IN_MEMORY (parms))
1383 if (name == 0 || *name == 0)
1384 name = gen_fake_label ();
1385 PUT_SDB_DEF (name);
1386 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1387 PUT_SDB_SCL (C_REG);
1388 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1389 PUT_SDB_ENDEF;
1391 /* Report parms that live in memory but not where they were passed. */
1392 else if (MEM_P (DECL_RTL (parms))
1393 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1394 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1395 && PARM_PASSED_IN_MEMORY (parms)
1396 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1398 #if 0 /* ??? It is not clear yet what should replace this. */
1399 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1400 /* A parm declared char is really passed as an int,
1401 so it occupies the least significant bytes.
1402 On a big-endian machine those are not the low-numbered ones. */
1403 if (BYTES_BIG_ENDIAN
1404 && offset != -1
1405 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1406 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1407 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1408 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1409 #endif
1411 if (name == 0 || *name == 0)
1412 name = gen_fake_label ();
1413 PUT_SDB_DEF (name);
1414 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1415 (XEXP (DECL_RTL (parms), 0)));
1416 PUT_SDB_SCL (C_AUTO);
1417 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1418 PUT_SDB_ENDEF;
1424 /* Output debug information for a global DECL. Called from toplev.c
1425 after compilation proper has finished. */
1427 static void
1428 sdbout_global_decl (tree decl)
1430 if (TREE_CODE (decl) == VAR_DECL
1431 && !DECL_EXTERNAL (decl)
1432 && DECL_RTL_SET_P (decl))
1434 /* The COFF linker can move initialized global vars to the end.
1435 And that can screw up the symbol ordering. Defer those for
1436 sdbout_finish (). */
1437 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1438 sdbout_symbol (decl, 0);
1439 else
1440 vec_safe_push (deferred_global_decls, decl);
1442 /* Output COFF information for non-global file-scope initialized
1443 variables. */
1444 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1445 sdbout_toplevel_data (decl);
1449 /* Output initialized global vars at the end, in the order of
1450 definition. See comment in sdbout_global_decl. */
1452 static void
1453 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1455 size_t i;
1456 tree decl;
1458 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1459 sdbout_symbol (decl, 0);
1462 /* Describe the beginning of an internal block within a function.
1463 Also output descriptions of variables defined in this block.
1465 N is the number of the block, by order of beginning, counting from 1,
1466 and not counting the outermost (function top-level) block.
1467 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1468 if the count starts at 0 for the outermost one. */
1470 static void
1471 sdbout_begin_block (unsigned int line, unsigned int n)
1473 tree decl = current_function_decl;
1474 MAKE_LINE_SAFE (line);
1476 /* The SCO compiler does not emit a separate block for the function level
1477 scope, so we avoid it here also. */
1478 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1480 if (n == 1)
1482 /* Include the outermost BLOCK's variables in block 1. */
1483 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1484 sdbout_block (DECL_INITIAL (decl));
1486 /* If -g1, suppress all the internal symbols of functions
1487 except for arguments. */
1488 if (debug_info_level != DINFO_LEVEL_TERSE)
1490 do_block = n;
1491 sdbout_block (DECL_INITIAL (decl));
1494 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1495 sdbout_dequeue_anonymous_types ();
1496 #endif
1499 /* Describe the end line-number of an internal block within a function. */
1501 static void
1502 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1504 MAKE_LINE_SAFE (line);
1506 /* The SCO compiler does not emit a separate block for the function level
1507 scope, so we avoid it here also. */
1508 if (n != 1)
1509 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1512 /* Output a line number symbol entry for source file FILENAME and line
1513 number LINE. */
1515 static void
1516 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1517 int discriminator ATTRIBUTE_UNUSED,
1518 bool is_stmt ATTRIBUTE_UNUSED)
1520 /* COFF relative line numbers must be positive. */
1521 if ((int) line > sdb_begin_function_line)
1523 #ifdef SDB_OUTPUT_SOURCE_LINE
1524 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1525 #else
1526 fprintf (asm_out_file, "\t.ln\t%d\n",
1527 ((sdb_begin_function_line > -1)
1528 ? line - sdb_begin_function_line : 1));
1529 #endif
1533 /* Output sdb info for the current function name.
1534 Called from assemble_start_function. */
1536 static void
1537 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1539 sdbout_symbol (current_function_decl, 0);
1542 /* Called at beginning of function body after prologue. Record the
1543 function's starting line number, so we can output relative line numbers
1544 for the other lines. Describe beginning of outermost block. Also
1545 describe the parameter list. */
1547 static void
1548 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1550 sdbout_end_prologue (line, file);
1553 static void
1554 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1556 sdb_begin_function_line = line - 1;
1557 PUT_SDB_FUNCTION_START (line);
1558 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1559 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1562 /* Called at end of function (before epilogue).
1563 Describe end of outermost block. */
1565 static void
1566 sdbout_end_function (unsigned int line)
1568 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1569 sdbout_dequeue_anonymous_types ();
1570 #endif
1572 MAKE_LINE_SAFE (line);
1573 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1575 /* Indicate we are between functions, for line-number output. */
1576 sdb_begin_function_line = -1;
1579 /* Output sdb info for the absolute end of a function.
1580 Called after the epilogue is output. */
1582 static void
1583 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1584 const char *file ATTRIBUTE_UNUSED)
1586 const char *const name ATTRIBUTE_UNUSED
1587 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1589 #ifdef PUT_SDB_EPILOGUE_END
1590 PUT_SDB_EPILOGUE_END (name);
1591 #else
1592 fprintf (asm_out_file, "\t.def\t");
1593 assemble_name (asm_out_file, name);
1594 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1595 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1596 #endif
1599 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1600 is present. */
1602 static void
1603 sdbout_label (rtx_code_label *insn)
1605 PUT_SDB_DEF (LABEL_NAME (insn));
1606 PUT_SDB_VAL (insn);
1607 PUT_SDB_SCL (C_LABEL);
1608 PUT_SDB_TYPE (T_NULL);
1609 PUT_SDB_ENDEF;
1612 /* Change to reading from a new source file. */
1614 static void
1615 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1616 const char *filename ATTRIBUTE_UNUSED)
1620 /* Revert to reading a previous source file. */
1622 static void
1623 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1627 /* Set up for SDB output at the start of compilation. */
1629 static void
1630 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1632 tree t;
1634 vec_alloc (deferred_global_decls, 12);
1636 /* Emit debug information which was queued by sdbout_symbol before
1637 we got here. */
1638 sdbout_initialized = true;
1640 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1641 sdbout_symbol (TREE_VALUE (t), 0);
1642 preinit_symbols = 0;
1645 #endif /* SDB_DEBUGGING_INFO */
1647 #include "gt-sdbout.h"