vectorizer cost model enhancement
[official-gcc.git] / gcc / sdbout.c
blob13c11c296820307b09316de5c2a25654239ca2a9
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2013 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 "ggc.h"
49 #include "vec.h"
51 static GTY(()) tree anonymous_types;
53 /* Counter to generate unique "names" for nameless struct members. */
55 static GTY(()) int unnamed_struct_number;
57 /* Declarations whose debug info was deferred till end of compilation. */
59 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
61 /* The C front end may call sdbout_symbol before sdbout_init runs.
62 We save all such decls in this list and output them when we get
63 to sdbout_init. */
65 static GTY(()) tree preinit_symbols;
66 static GTY(()) bool sdbout_initialized;
68 #ifdef SDB_DEBUGGING_INFO
70 #include "rtl.h"
71 #include "regs.h"
72 #include "flags.h"
73 #include "insn-config.h"
74 #include "reload.h"
75 #include "output.h"
76 #include "diagnostic-core.h"
77 #include "tm_p.h"
78 #include "gsyms.h"
79 #include "langhooks.h"
80 #include "target.h"
82 /* 1 if PARM is passed to this function in memory. */
84 #define PARM_PASSED_IN_MEMORY(PARM) \
85 (MEM_P (DECL_INCOMING_RTL (PARM)))
87 /* A C expression for the integer offset value of an automatic variable
88 (C_AUTO) having address X (an RTX). */
89 #ifndef DEBUGGER_AUTO_OFFSET
90 #define DEBUGGER_AUTO_OFFSET(X) \
91 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
92 #endif
94 /* A C expression for the integer offset value of an argument (C_ARG)
95 having address X (an RTX). The nominal offset is OFFSET. */
96 #ifndef DEBUGGER_ARG_OFFSET
97 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
98 #endif
100 /* Line number of beginning of current function, minus one.
101 Negative means not in a function or not using sdb. */
103 int sdb_begin_function_line = -1;
106 extern FILE *asm_out_file;
108 extern tree current_function_decl;
110 #include "sdbout.h"
112 static void sdbout_init (const char *);
113 static void sdbout_finish (const char *);
114 static void sdbout_start_source_file (unsigned int, const char *);
115 static void sdbout_end_source_file (unsigned int);
116 static void sdbout_begin_block (unsigned int, unsigned int);
117 static void sdbout_end_block (unsigned int, unsigned int);
118 static void sdbout_source_line (unsigned int, const char *, int, bool);
119 static void sdbout_end_epilogue (unsigned int, const char *);
120 static void sdbout_global_decl (tree);
121 static void sdbout_begin_prologue (unsigned int, const char *);
122 static void sdbout_end_prologue (unsigned int, const char *);
123 static void sdbout_begin_function (tree);
124 static void sdbout_end_function (unsigned int);
125 static void sdbout_toplevel_data (tree);
126 static void sdbout_label (rtx);
127 static char *gen_fake_label (void);
128 static int plain_type (tree);
129 static int template_name_p (tree);
130 static void sdbout_record_type_name (tree);
131 static int plain_type_1 (tree, int);
132 static void sdbout_block (tree);
133 static void sdbout_syms (tree);
134 #ifdef SDB_ALLOW_FORWARD_REFERENCES
135 static void sdbout_queue_anonymous_type (tree);
136 static void sdbout_dequeue_anonymous_types (void);
137 #endif
138 static void sdbout_type (tree);
139 static void sdbout_field_types (tree);
140 static void sdbout_one_type (tree);
141 static void sdbout_parms (tree);
142 static void sdbout_reg_parms (tree);
143 static void sdbout_global_decl (tree);
145 /* Random macros describing parts of SDB data. */
147 /* Default value of delimiter is ";". */
148 #ifndef SDB_DELIM
149 #define SDB_DELIM ";"
150 #endif
152 /* Maximum number of dimensions the assembler will allow. */
153 #ifndef SDB_MAX_DIM
154 #define SDB_MAX_DIM 4
155 #endif
157 #ifndef PUT_SDB_SCL
158 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
159 #endif
161 #ifndef PUT_SDB_INT_VAL
162 #define PUT_SDB_INT_VAL(a) \
163 do { \
164 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
165 (HOST_WIDE_INT) (a), SDB_DELIM); \
166 } while (0)
168 #endif
170 #ifndef PUT_SDB_VAL
171 #define PUT_SDB_VAL(a) \
172 ( fputs ("\t.val\t", asm_out_file), \
173 output_addr_const (asm_out_file, (a)), \
174 fprintf (asm_out_file, SDB_DELIM))
175 #endif
177 #ifndef PUT_SDB_DEF
178 #define PUT_SDB_DEF(a) \
179 do { fprintf (asm_out_file, "\t.def\t"); \
180 assemble_name (asm_out_file, a); \
181 fprintf (asm_out_file, SDB_DELIM); } while (0)
182 #endif
184 #ifndef PUT_SDB_PLAIN_DEF
185 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
186 #endif
188 #ifndef PUT_SDB_ENDEF
189 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
190 #endif
192 #ifndef PUT_SDB_TYPE
193 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
194 #endif
196 #ifndef PUT_SDB_SIZE
197 #define PUT_SDB_SIZE(a) \
198 do { \
199 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
200 (HOST_WIDE_INT) (a), SDB_DELIM); \
201 } while(0)
202 #endif
204 #ifndef PUT_SDB_START_DIM
205 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
206 #endif
208 #ifndef PUT_SDB_NEXT_DIM
209 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
210 #endif
212 #ifndef PUT_SDB_LAST_DIM
213 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
214 #endif
216 #ifndef PUT_SDB_TAG
217 #define PUT_SDB_TAG(a) \
218 do { fprintf (asm_out_file, "\t.tag\t"); \
219 assemble_name (asm_out_file, a); \
220 fprintf (asm_out_file, SDB_DELIM); } while (0)
221 #endif
223 #ifndef PUT_SDB_BLOCK_START
224 #define PUT_SDB_BLOCK_START(LINE) \
225 fprintf (asm_out_file, \
226 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
227 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
228 #endif
230 #ifndef PUT_SDB_BLOCK_END
231 #define PUT_SDB_BLOCK_END(LINE) \
232 fprintf (asm_out_file, \
233 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
234 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
235 #endif
237 #ifndef PUT_SDB_FUNCTION_START
238 #define PUT_SDB_FUNCTION_START(LINE) \
239 fprintf (asm_out_file, \
240 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
241 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
242 #endif
244 #ifndef PUT_SDB_FUNCTION_END
245 #define PUT_SDB_FUNCTION_END(LINE) \
246 fprintf (asm_out_file, \
247 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
248 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
249 #endif
251 /* Return the sdb tag identifier string for TYPE
252 if TYPE has already been defined; otherwise return a null pointer. */
254 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
256 /* Set the sdb tag identifier string for TYPE to NAME. */
258 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
259 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
261 /* Return the name (a string) of the struct, union or enum tag
262 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
264 #define TAG_NAME(link) \
265 (((link) && TREE_PURPOSE ((link)) \
266 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
267 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
269 /* Ensure we don't output a negative line number. */
270 #define MAKE_LINE_SAFE(line) \
271 if ((int) line <= sdb_begin_function_line) \
272 line = sdb_begin_function_line + 1
274 /* The debug hooks structure. */
275 const struct gcc_debug_hooks sdb_debug_hooks =
277 sdbout_init, /* init */
278 sdbout_finish, /* finish */
279 debug_nothing_void, /* assembly_start */
280 debug_nothing_int_charstar, /* define */
281 debug_nothing_int_charstar, /* undef */
282 sdbout_start_source_file, /* start_source_file */
283 sdbout_end_source_file, /* end_source_file */
284 sdbout_begin_block, /* begin_block */
285 sdbout_end_block, /* end_block */
286 debug_true_const_tree, /* ignore_block */
287 sdbout_source_line, /* source_line */
288 sdbout_begin_prologue, /* begin_prologue */
289 debug_nothing_int_charstar, /* end_prologue */
290 debug_nothing_int_charstar, /* begin_epilogue */
291 sdbout_end_epilogue, /* end_epilogue */
292 sdbout_begin_function, /* begin_function */
293 sdbout_end_function, /* end_function */
294 debug_nothing_tree, /* function_decl */
295 sdbout_global_decl, /* global_decl */
296 sdbout_symbol, /* type_decl */
297 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
298 debug_nothing_tree, /* deferred_inline_function */
299 debug_nothing_tree, /* outlining_inline_function */
300 sdbout_label, /* label */
301 debug_nothing_int, /* handle_pch */
302 debug_nothing_rtx, /* var_location */
303 debug_nothing_void, /* switch_text_section */
304 debug_nothing_tree_tree, /* set_name */
305 0, /* start_end_main_source_file */
306 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
309 /* Return a unique string to name an anonymous type. */
311 static char *
312 gen_fake_label (void)
314 char label[10];
315 char *labelstr;
316 sprintf (label, ".%dfake", unnamed_struct_number);
317 unnamed_struct_number++;
318 labelstr = xstrdup (label);
319 return labelstr;
322 /* Return the number which describes TYPE for SDB.
323 For pointers, etc., this function is recursive.
324 Each record, union or enumeral type must already have had a
325 tag number output. */
327 /* The number is given by d6d5d4d3d2d1bbbb
328 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
329 Thus, char *foo () has bbbb=T_CHAR
330 d1=D_FCN
331 d2=D_PTR
332 N_BTMASK= 017 1111 basic type field.
333 N_TSHIFT= 2 derived type shift
334 N_BTSHFT= 4 Basic type shift */
336 /* Produce the number that describes a pointer, function or array type.
337 PREV is the number describing the target, value or element type.
338 DT_type describes how to transform that type. */
339 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
340 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
341 | ((int) DT_type << (int) N_BTSHFT) \
342 | ((PREV) & (int) N_BTMASK))
344 /* Number of elements used in sdb_dims. */
345 static int sdb_n_dims = 0;
347 /* Table of array dimensions of current type. */
348 static int sdb_dims[SDB_MAX_DIM];
350 /* Size of outermost array currently being processed. */
351 static int sdb_type_size = -1;
353 static int
354 plain_type (tree type)
356 int val = plain_type_1 (type, 0);
358 /* If we have already saved up some array dimensions, print them now. */
359 if (sdb_n_dims > 0)
361 int i;
362 PUT_SDB_START_DIM;
363 for (i = sdb_n_dims - 1; i > 0; i--)
364 PUT_SDB_NEXT_DIM (sdb_dims[i]);
365 PUT_SDB_LAST_DIM (sdb_dims[0]);
366 sdb_n_dims = 0;
368 sdb_type_size = int_size_in_bytes (type);
369 /* Don't kill sdb if type is not laid out or has variable size. */
370 if (sdb_type_size < 0)
371 sdb_type_size = 0;
373 /* If we have computed the size of an array containing this type,
374 print it now. */
375 if (sdb_type_size >= 0)
377 PUT_SDB_SIZE (sdb_type_size);
378 sdb_type_size = -1;
380 return val;
383 static int
384 template_name_p (tree name)
386 const char *ptr = IDENTIFIER_POINTER (name);
387 while (*ptr && *ptr != '<')
388 ptr++;
390 return *ptr != '\0';
393 static void
394 sdbout_record_type_name (tree type)
396 const char *name = 0;
397 int no_name;
399 if (KNOWN_TYPE_TAG (type))
400 return;
402 if (TYPE_NAME (type) != 0)
404 tree t = 0;
406 /* Find the IDENTIFIER_NODE for the type name. */
407 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
408 t = TYPE_NAME (type);
409 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
411 t = DECL_NAME (TYPE_NAME (type));
412 /* The DECL_NAME for templates includes "<>", which breaks
413 most assemblers. Use its assembler name instead, which
414 has been mangled into being safe. */
415 if (t && template_name_p (t))
416 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
419 /* Now get the name as a string, or invent one. */
420 if (t != NULL_TREE)
421 name = IDENTIFIER_POINTER (t);
424 no_name = (name == 0 || *name == 0);
425 if (no_name)
426 name = gen_fake_label ();
428 SET_KNOWN_TYPE_TAG (type, name);
429 #ifdef SDB_ALLOW_FORWARD_REFERENCES
430 if (no_name)
431 sdbout_queue_anonymous_type (type);
432 #endif
435 /* Return the .type value for type TYPE.
437 LEVEL indicates how many levels deep we have recursed into the type.
438 The SDB debug format can only represent 6 derived levels of types.
439 After that, we must output inaccurate debug info. We deliberately
440 stop before the 7th level, so that ADA recursive types will not give an
441 infinite loop. */
443 static int
444 plain_type_1 (tree type, int level)
446 if (type == 0)
447 type = void_type_node;
448 else if (type == error_mark_node)
449 type = integer_type_node;
450 else
451 type = TYPE_MAIN_VARIANT (type);
453 switch (TREE_CODE (type))
455 case VOID_TYPE:
456 case NULLPTR_TYPE:
457 return T_VOID;
458 case BOOLEAN_TYPE:
459 case INTEGER_TYPE:
461 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
463 /* Carefully distinguish all the standard types of C,
464 without messing up if the language is not C.
465 Note that we check only for the names that contain spaces;
466 other names might occur by coincidence in other languages. */
467 if (TYPE_NAME (type) != 0
468 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
469 && DECL_NAME (TYPE_NAME (type)) != 0
470 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
472 const char *const name
473 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
475 if (!strcmp (name, "char"))
476 return T_CHAR;
477 if (!strcmp (name, "unsigned char"))
478 return T_UCHAR;
479 if (!strcmp (name, "signed char"))
480 return T_CHAR;
481 if (!strcmp (name, "int"))
482 return T_INT;
483 if (!strcmp (name, "unsigned int"))
484 return T_UINT;
485 if (!strcmp (name, "short int"))
486 return T_SHORT;
487 if (!strcmp (name, "short unsigned int"))
488 return T_USHORT;
489 if (!strcmp (name, "long int"))
490 return T_LONG;
491 if (!strcmp (name, "long unsigned int"))
492 return T_ULONG;
495 if (size == INT_TYPE_SIZE)
496 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
497 if (size == CHAR_TYPE_SIZE)
498 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
499 if (size == SHORT_TYPE_SIZE)
500 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
501 if (size == LONG_TYPE_SIZE)
502 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
503 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
504 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
505 return 0;
508 case REAL_TYPE:
510 int precision = TYPE_PRECISION (type);
511 if (precision == FLOAT_TYPE_SIZE)
512 return T_FLOAT;
513 if (precision == DOUBLE_TYPE_SIZE)
514 return T_DOUBLE;
515 #ifdef EXTENDED_SDB_BASIC_TYPES
516 if (precision == LONG_DOUBLE_TYPE_SIZE)
517 return T_LNGDBL;
518 #else
519 if (precision == LONG_DOUBLE_TYPE_SIZE)
520 return T_DOUBLE; /* better than nothing */
521 #endif
522 return 0;
525 case ARRAY_TYPE:
527 int m;
528 if (level >= 6)
529 return T_VOID;
530 else
531 m = plain_type_1 (TREE_TYPE (type), level+1);
532 if (sdb_n_dims < SDB_MAX_DIM)
533 sdb_dims[sdb_n_dims++]
534 = (TYPE_DOMAIN (type)
535 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
536 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
537 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
538 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
539 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
540 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
541 : 0);
543 return PUSH_DERIVED_LEVEL (DT_ARY, m);
546 case RECORD_TYPE:
547 case UNION_TYPE:
548 case QUAL_UNION_TYPE:
549 case ENUMERAL_TYPE:
551 const char *tag;
552 #ifdef SDB_ALLOW_FORWARD_REFERENCES
553 sdbout_record_type_name (type);
554 #endif
555 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
556 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
557 #ifdef SDB_ALLOW_FORWARD_REFERENCES
558 || TYPE_MODE (type) != VOIDmode
559 #endif
561 #endif
563 /* Output the referenced structure tag name
564 only if the .def has already been finished.
565 At least on 386, the Unix assembler
566 cannot handle forward references to tags. */
567 /* But the 88100, it requires them, sigh... */
568 /* And the MIPS requires unknown refs as well... */
569 tag = KNOWN_TYPE_TAG (type);
570 PUT_SDB_TAG (tag);
571 /* These 3 lines used to follow the close brace.
572 However, a size of 0 without a tag implies a tag of 0,
573 so if we don't know a tag, we can't mention the size. */
574 sdb_type_size = int_size_in_bytes (type);
575 if (sdb_type_size < 0)
576 sdb_type_size = 0;
578 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
579 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
580 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
581 : T_ENUM);
583 case POINTER_TYPE:
584 case REFERENCE_TYPE:
586 int m;
587 if (level >= 6)
588 return T_VOID;
589 else
590 m = plain_type_1 (TREE_TYPE (type), level+1);
591 return PUSH_DERIVED_LEVEL (DT_PTR, m);
593 case FUNCTION_TYPE:
594 case METHOD_TYPE:
596 int m;
597 if (level >= 6)
598 return T_VOID;
599 else
600 m = plain_type_1 (TREE_TYPE (type), level+1);
601 return PUSH_DERIVED_LEVEL (DT_FCN, m);
603 default:
604 return 0;
608 /* Output the symbols defined in block number DO_BLOCK.
610 This function works by walking the tree structure of blocks,
611 counting blocks until it finds the desired block. */
613 static int do_block = 0;
615 static void
616 sdbout_block (tree block)
618 while (block)
620 /* Ignore blocks never expanded or otherwise marked as real. */
621 if (TREE_USED (block))
623 /* When we reach the specified block, output its symbols. */
624 if (BLOCK_NUMBER (block) == do_block)
625 sdbout_syms (BLOCK_VARS (block));
627 /* If we are past the specified block, stop the scan. */
628 if (BLOCK_NUMBER (block) > do_block)
629 return;
631 /* Scan the blocks within this block. */
632 sdbout_block (BLOCK_SUBBLOCKS (block));
635 block = BLOCK_CHAIN (block);
639 /* Call sdbout_symbol on each decl in the chain SYMS. */
641 static void
642 sdbout_syms (tree syms)
644 while (syms)
646 if (TREE_CODE (syms) != LABEL_DECL)
647 sdbout_symbol (syms, 1);
648 syms = TREE_CHAIN (syms);
652 /* Output SDB information for a symbol described by DECL.
653 LOCAL is nonzero if the symbol is not file-scope. */
655 void
656 sdbout_symbol (tree decl, int local)
658 tree type = TREE_TYPE (decl);
659 tree context = NULL_TREE;
660 rtx value;
661 int regno = -1;
662 const char *name;
664 /* If we are called before sdbout_init is run, just save the symbol
665 for later. */
666 if (!sdbout_initialized)
668 preinit_symbols = tree_cons (0, decl, preinit_symbols);
669 return;
672 sdbout_one_type (type);
674 switch (TREE_CODE (decl))
676 case CONST_DECL:
677 /* Enum values are defined by defining the enum type. */
678 return;
680 case FUNCTION_DECL:
681 /* Don't mention a nested function under its parent. */
682 context = decl_function_context (decl);
683 if (context == current_function_decl)
684 return;
685 /* Check DECL_INITIAL to distinguish declarations from definitions.
686 Don't output debug info here for declarations; they will have
687 a DECL_INITIAL value of 0. */
688 if (! DECL_INITIAL (decl))
689 return;
690 if (!MEM_P (DECL_RTL (decl))
691 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
692 return;
693 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
694 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
695 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
696 break;
698 case TYPE_DECL:
699 /* Done with tagged types. */
700 if (DECL_NAME (decl) == 0)
701 return;
702 if (DECL_IGNORED_P (decl))
703 return;
704 /* Don't output intrinsic types. GAS chokes on SDB .def
705 statements that contain identifiers with embedded spaces
706 (eg "unsigned long"). */
707 if (DECL_IS_BUILTIN (decl))
708 return;
710 /* Output typedef name. */
711 if (template_name_p (DECL_NAME (decl)))
712 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
713 else
714 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
715 PUT_SDB_SCL (C_TPDEF);
716 break;
718 case PARM_DECL:
719 /* Parm decls go in their own separate chains
720 and are output by sdbout_reg_parms and sdbout_parms. */
721 gcc_unreachable ();
723 case VAR_DECL:
724 /* Don't mention a variable that is external.
725 Let the file that defines it describe it. */
726 if (DECL_EXTERNAL (decl))
727 return;
729 /* Ignore __FUNCTION__, etc. */
730 if (DECL_IGNORED_P (decl))
731 return;
733 /* If there was an error in the declaration, don't dump core
734 if there is no RTL associated with the variable doesn't
735 exist. */
736 if (!DECL_RTL_SET_P (decl))
737 return;
739 SET_DECL_RTL (decl,
740 eliminate_regs (DECL_RTL (decl), VOIDmode, NULL_RTX));
741 #ifdef LEAF_REG_REMAP
742 if (crtl->uses_only_leaf_regs)
743 leaf_renumber_regs_insn (DECL_RTL (decl));
744 #endif
745 value = DECL_RTL (decl);
747 /* Don't mention a variable at all
748 if it was completely optimized into nothingness.
750 If DECL was from an inline function, then its rtl
751 is not identically the rtl that was used in this
752 particular compilation. */
753 if (REG_P (value))
755 regno = REGNO (value);
756 if (regno >= FIRST_PSEUDO_REGISTER)
757 return;
759 else if (GET_CODE (value) == SUBREG)
761 while (GET_CODE (value) == SUBREG)
762 value = SUBREG_REG (value);
763 if (REG_P (value))
765 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
766 return;
768 regno = REGNO (alter_subreg (&value, true));
769 SET_DECL_RTL (decl, value);
771 /* Don't output anything if an auto variable
772 gets RTL that is static.
773 GAS version 2.2 can't handle such output. */
774 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
775 && ! TREE_STATIC (decl))
776 return;
778 /* Emit any structure, union, or enum type that has not been output.
779 This occurs for tag-less structs (et al) used to declare variables
780 within functions. */
781 if (TREE_CODE (type) == ENUMERAL_TYPE
782 || TREE_CODE (type) == RECORD_TYPE
783 || TREE_CODE (type) == UNION_TYPE
784 || TREE_CODE (type) == QUAL_UNION_TYPE)
786 if (COMPLETE_TYPE_P (type) /* not a forward reference */
787 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
788 sdbout_one_type (type);
791 /* Defer SDB information for top-level initialized variables! */
792 if (! local
793 && MEM_P (value)
794 && DECL_INITIAL (decl))
795 return;
797 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
798 For now, avoid crashing. */
799 if (DECL_NAME (decl) == NULL_TREE)
800 return;
802 /* Record the name for, starting a symtab entry. */
803 if (local)
804 name = IDENTIFIER_POINTER (DECL_NAME (decl));
805 else
806 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
808 if (MEM_P (value)
809 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
811 PUT_SDB_DEF (name);
812 if (TREE_PUBLIC (decl))
814 PUT_SDB_VAL (XEXP (value, 0));
815 PUT_SDB_SCL (C_EXT);
817 else
819 PUT_SDB_VAL (XEXP (value, 0));
820 PUT_SDB_SCL (C_STAT);
823 else if (regno >= 0)
825 PUT_SDB_DEF (name);
826 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
827 PUT_SDB_SCL (C_REG);
829 else if (MEM_P (value)
830 && (MEM_P (XEXP (value, 0))
831 || (REG_P (XEXP (value, 0))
832 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
833 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
834 /* If the value is indirect by memory or by a register
835 that isn't the frame pointer
836 then it means the object is variable-sized and address through
837 that register or stack slot. COFF has no way to represent this
838 so all we can do is output the variable as a pointer. */
840 PUT_SDB_DEF (name);
841 if (REG_P (XEXP (value, 0)))
843 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
844 PUT_SDB_SCL (C_REG);
846 else
848 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
849 (CONST_INT...)))).
850 We want the value of that CONST_INT. */
851 /* Encore compiler hates a newline in a macro arg, it seems. */
852 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
853 (XEXP (XEXP (value, 0), 0)));
854 PUT_SDB_SCL (C_AUTO);
857 /* Effectively do build_pointer_type, but don't cache this type,
858 since it might be temporary whereas the type it points to
859 might have been saved for inlining. */
860 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
861 type = make_node (POINTER_TYPE);
862 TREE_TYPE (type) = TREE_TYPE (decl);
864 else if (MEM_P (value)
865 && ((GET_CODE (XEXP (value, 0)) == PLUS
866 && REG_P (XEXP (XEXP (value, 0), 0))
867 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
868 /* This is for variables which are at offset zero from
869 the frame pointer. This happens on the Alpha.
870 Non-frame pointer registers are excluded above. */
871 || (REG_P (XEXP (value, 0)))))
873 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
874 or (MEM (REG...)). We want the value of that CONST_INT
875 or zero. */
876 PUT_SDB_DEF (name);
877 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
878 PUT_SDB_SCL (C_AUTO);
880 else
882 /* It is something we don't know how to represent for SDB. */
883 return;
885 break;
887 default:
888 break;
890 PUT_SDB_TYPE (plain_type (type));
891 PUT_SDB_ENDEF;
894 /* Output SDB information for a top-level initialized variable
895 that has been delayed. */
897 static void
898 sdbout_toplevel_data (tree decl)
900 tree type = TREE_TYPE (decl);
902 if (DECL_IGNORED_P (decl))
903 return;
905 gcc_assert (TREE_CODE (decl) == VAR_DECL);
906 gcc_assert (MEM_P (DECL_RTL (decl)));
907 gcc_assert (DECL_INITIAL (decl));
909 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
910 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
911 if (TREE_PUBLIC (decl))
913 PUT_SDB_SCL (C_EXT);
915 else
917 PUT_SDB_SCL (C_STAT);
919 PUT_SDB_TYPE (plain_type (type));
920 PUT_SDB_ENDEF;
923 #ifdef SDB_ALLOW_FORWARD_REFERENCES
925 /* Machinery to record and output anonymous types. */
927 static void
928 sdbout_queue_anonymous_type (tree type)
930 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
933 static void
934 sdbout_dequeue_anonymous_types (void)
936 tree types, link;
938 while (anonymous_types)
940 types = nreverse (anonymous_types);
941 anonymous_types = NULL_TREE;
943 for (link = types; link; link = TREE_CHAIN (link))
945 tree type = TREE_VALUE (link);
947 if (type && ! TREE_ASM_WRITTEN (type))
948 sdbout_one_type (type);
953 #endif
955 /* Given a chain of ..._TYPE nodes, all of which have names,
956 output definitions of those names, as typedefs. */
958 void
959 sdbout_types (tree types)
961 tree link;
963 for (link = types; link; link = TREE_CHAIN (link))
964 sdbout_one_type (link);
966 #ifdef SDB_ALLOW_FORWARD_REFERENCES
967 sdbout_dequeue_anonymous_types ();
968 #endif
971 static void
972 sdbout_type (tree type)
974 if (type == error_mark_node)
975 type = integer_type_node;
976 PUT_SDB_TYPE (plain_type (type));
979 /* Output types of the fields of type TYPE, if they are structs.
981 Formerly did not chase through pointer types, since that could be circular.
982 They must come before TYPE, since forward refs are not allowed.
983 Now james@bigtex.cactus.org says to try them. */
985 static void
986 sdbout_field_types (tree type)
988 tree tail;
990 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
991 /* This condition should match the one for emitting the actual
992 members below. */
993 if (TREE_CODE (tail) == FIELD_DECL
994 && DECL_NAME (tail)
995 && DECL_SIZE (tail)
996 && host_integerp (DECL_SIZE (tail), 1)
997 && host_integerp (bit_position (tail), 0))
999 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1000 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1001 else
1002 sdbout_one_type (TREE_TYPE (tail));
1006 /* Use this to put out the top level defined record and union types
1007 for later reference. If this is a struct with a name, then put that
1008 name out. Other unnamed structs will have .xxfake labels generated so
1009 that they may be referred to later.
1010 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1011 It may NOT be called recursively. */
1013 static void
1014 sdbout_one_type (tree type)
1016 if (current_function_decl != NULL_TREE
1017 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1018 ; /* Don't change section amid function. */
1019 else
1020 switch_to_section (current_function_section ());
1022 switch (TREE_CODE (type))
1024 case RECORD_TYPE:
1025 case UNION_TYPE:
1026 case QUAL_UNION_TYPE:
1027 case ENUMERAL_TYPE:
1028 type = TYPE_MAIN_VARIANT (type);
1029 /* Don't output a type twice. */
1030 if (TREE_ASM_WRITTEN (type))
1031 /* James said test TREE_ASM_BEING_WRITTEN here. */
1032 return;
1034 /* Output nothing if type is not yet defined. */
1035 if (!COMPLETE_TYPE_P (type))
1036 return;
1038 TREE_ASM_WRITTEN (type) = 1;
1040 /* This is reputed to cause trouble with the following case,
1041 but perhaps checking TYPE_SIZE above will fix it. */
1043 /* Here is a testcase:
1045 struct foo {
1046 struct badstr *bbb;
1047 } forwardref;
1049 typedef struct intermediate {
1050 int aaaa;
1051 } intermediate_ref;
1053 typedef struct badstr {
1054 int ccccc;
1055 } badtype; */
1057 /* This change, which ought to make better output,
1058 used to make the COFF assembler unhappy.
1059 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1060 /* Before really doing anything, output types we want to refer to. */
1061 /* Note that in version 1 the following two lines
1062 are not used if forward references are in use. */
1063 if (TREE_CODE (type) != ENUMERAL_TYPE)
1064 sdbout_field_types (type);
1066 /* Output a structure type. */
1068 int size = int_size_in_bytes (type);
1069 int member_scl = 0;
1070 tree tem;
1072 /* Record the type tag, but not in its permanent place just yet. */
1073 sdbout_record_type_name (type);
1075 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1077 switch (TREE_CODE (type))
1079 case UNION_TYPE:
1080 case QUAL_UNION_TYPE:
1081 PUT_SDB_SCL (C_UNTAG);
1082 PUT_SDB_TYPE (T_UNION);
1083 member_scl = C_MOU;
1084 break;
1086 case RECORD_TYPE:
1087 PUT_SDB_SCL (C_STRTAG);
1088 PUT_SDB_TYPE (T_STRUCT);
1089 member_scl = C_MOS;
1090 break;
1092 case ENUMERAL_TYPE:
1093 PUT_SDB_SCL (C_ENTAG);
1094 PUT_SDB_TYPE (T_ENUM);
1095 member_scl = C_MOE;
1096 break;
1098 default:
1099 break;
1102 PUT_SDB_SIZE (size);
1103 PUT_SDB_ENDEF;
1105 /* Print out the base class information with fields
1106 named after the types they hold. */
1107 /* This is only relevant to aggregate types. TYPE_BINFO is used
1108 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1109 case. */
1110 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1112 int i;
1113 tree binfo, child;
1115 for (binfo = TYPE_BINFO (type), i = 0;
1116 BINFO_BASE_ITERATE (binfo, i, child); i++)
1118 tree child_type = BINFO_TYPE (child);
1119 tree child_type_name;
1121 if (TYPE_NAME (child_type) == 0)
1122 continue;
1123 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1124 child_type_name = TYPE_NAME (child_type);
1125 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1127 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1128 if (child_type_name && template_name_p (child_type_name))
1129 child_type_name
1130 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1132 else
1133 continue;
1135 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1136 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1137 PUT_SDB_SCL (member_scl);
1138 sdbout_type (BINFO_TYPE (child));
1139 PUT_SDB_ENDEF;
1143 /* Output the individual fields. */
1145 if (TREE_CODE (type) == ENUMERAL_TYPE)
1147 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1149 tree value = TREE_VALUE (tem);
1151 if (TREE_CODE (value) == CONST_DECL)
1152 value = DECL_INITIAL (value);
1154 if (host_integerp (value, 0))
1156 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1157 PUT_SDB_INT_VAL (tree_low_cst (value, 0));
1158 PUT_SDB_SCL (C_MOE);
1159 PUT_SDB_TYPE (T_MOE);
1160 PUT_SDB_ENDEF;
1164 else /* record or union type */
1165 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1166 /* Output the name, type, position (in bits), size (in bits)
1167 of each field. */
1169 /* Omit here the nameless fields that are used to skip bits.
1170 Also omit fields with variable size or position.
1171 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1172 if (TREE_CODE (tem) == FIELD_DECL
1173 && DECL_NAME (tem)
1174 && DECL_SIZE (tem)
1175 && host_integerp (DECL_SIZE (tem), 1)
1176 && host_integerp (bit_position (tem), 0))
1178 const char *name;
1180 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1181 PUT_SDB_DEF (name);
1182 if (DECL_BIT_FIELD_TYPE (tem))
1184 PUT_SDB_INT_VAL (int_bit_position (tem));
1185 PUT_SDB_SCL (C_FIELD);
1186 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1187 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1189 else
1191 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1192 PUT_SDB_SCL (member_scl);
1193 sdbout_type (TREE_TYPE (tem));
1195 PUT_SDB_ENDEF;
1197 /* Output end of a structure,union, or enumeral definition. */
1199 PUT_SDB_PLAIN_DEF ("eos");
1200 PUT_SDB_INT_VAL (size);
1201 PUT_SDB_SCL (C_EOS);
1202 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1203 PUT_SDB_SIZE (size);
1204 PUT_SDB_ENDEF;
1205 break;
1208 default:
1209 break;
1213 /* The following two functions output definitions of function parameters.
1214 Each parameter gets a definition locating it in the parameter list.
1215 Each parameter that is a register variable gets a second definition
1216 locating it in the register.
1218 Printing or argument lists in gdb uses the definitions that
1219 locate in the parameter list. But reference to the variable in
1220 expressions uses preferentially the definition as a register. */
1222 /* Output definitions, referring to storage in the parmlist,
1223 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1225 static void
1226 sdbout_parms (tree parms)
1228 for (; parms; parms = TREE_CHAIN (parms))
1229 if (DECL_NAME (parms))
1231 int current_sym_value = 0;
1232 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1234 if (name == 0 || *name == 0)
1235 name = gen_fake_label ();
1237 /* Perform any necessary register eliminations on the parameter's rtl,
1238 so that the debugging output will be accurate. */
1239 DECL_INCOMING_RTL (parms)
1240 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1241 SET_DECL_RTL (parms,
1242 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1244 if (PARM_PASSED_IN_MEMORY (parms))
1246 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1247 tree type;
1249 /* ??? Here we assume that the parm address is indexed
1250 off the frame pointer or arg pointer.
1251 If that is not true, we produce meaningless results,
1252 but do not crash. */
1253 if (GET_CODE (addr) == PLUS
1254 && CONST_INT_P (XEXP (addr, 1)))
1255 current_sym_value = INTVAL (XEXP (addr, 1));
1256 else
1257 current_sym_value = 0;
1259 if (REG_P (DECL_RTL (parms))
1260 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1261 type = DECL_ARG_TYPE (parms);
1262 else
1264 int original_sym_value = current_sym_value;
1266 /* This is the case where the parm is passed as an int or
1267 double and it is converted to a char, short or float
1268 and stored back in the parmlist. In this case, describe
1269 the parm with the variable's declared type, and adjust
1270 the address if the least significant bytes (which we are
1271 using) are not the first ones. */
1272 if (BYTES_BIG_ENDIAN
1273 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1274 current_sym_value +=
1275 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1276 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1278 if (MEM_P (DECL_RTL (parms))
1279 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1280 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1281 == CONST_INT)
1282 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1283 == current_sym_value))
1284 type = TREE_TYPE (parms);
1285 else
1287 current_sym_value = original_sym_value;
1288 type = DECL_ARG_TYPE (parms);
1292 PUT_SDB_DEF (name);
1293 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1294 PUT_SDB_SCL (C_ARG);
1295 PUT_SDB_TYPE (plain_type (type));
1296 PUT_SDB_ENDEF;
1298 else if (REG_P (DECL_RTL (parms)))
1300 rtx best_rtl;
1301 /* Parm passed in registers and lives in registers or nowhere. */
1303 /* If parm lives in a register, use that register;
1304 pretend the parm was passed there. It would be more consistent
1305 to describe the register where the parm was passed,
1306 but in practice that register usually holds something else. */
1307 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1308 best_rtl = DECL_RTL (parms);
1309 /* If the parm lives nowhere,
1310 use the register where it was passed. */
1311 else
1312 best_rtl = DECL_INCOMING_RTL (parms);
1314 PUT_SDB_DEF (name);
1315 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1316 PUT_SDB_SCL (C_REGPARM);
1317 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1318 PUT_SDB_ENDEF;
1320 else if (MEM_P (DECL_RTL (parms))
1321 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1323 /* Parm was passed in registers but lives on the stack. */
1325 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1326 in which case we want the value of that CONST_INT,
1327 or (MEM (REG ...)) or (MEM (MEM ...)),
1328 in which case we use a value of zero. */
1329 if (REG_P (XEXP (DECL_RTL (parms), 0))
1330 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1331 current_sym_value = 0;
1332 else
1333 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1335 /* Again, this assumes the offset is based on the arg pointer. */
1336 PUT_SDB_DEF (name);
1337 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1338 XEXP (DECL_RTL (parms), 0)));
1339 PUT_SDB_SCL (C_ARG);
1340 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1341 PUT_SDB_ENDEF;
1346 /* Output definitions for the places where parms live during the function,
1347 when different from where they were passed, when the parms were passed
1348 in memory.
1350 It is not useful to do this for parms passed in registers
1351 that live during the function in different registers, because it is
1352 impossible to look in the passed register for the passed value,
1353 so we use the within-the-function register to begin with.
1355 PARMS is a chain of PARM_DECL nodes. */
1357 static void
1358 sdbout_reg_parms (tree parms)
1360 for (; parms; parms = TREE_CHAIN (parms))
1361 if (DECL_NAME (parms))
1363 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1365 /* Report parms that live in registers during the function
1366 but were passed in memory. */
1367 if (REG_P (DECL_RTL (parms))
1368 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1369 && PARM_PASSED_IN_MEMORY (parms))
1371 if (name == 0 || *name == 0)
1372 name = gen_fake_label ();
1373 PUT_SDB_DEF (name);
1374 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1375 PUT_SDB_SCL (C_REG);
1376 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1377 PUT_SDB_ENDEF;
1379 /* Report parms that live in memory but not where they were passed. */
1380 else if (MEM_P (DECL_RTL (parms))
1381 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1382 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1383 && PARM_PASSED_IN_MEMORY (parms)
1384 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1386 #if 0 /* ??? It is not clear yet what should replace this. */
1387 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1388 /* A parm declared char is really passed as an int,
1389 so it occupies the least significant bytes.
1390 On a big-endian machine those are not the low-numbered ones. */
1391 if (BYTES_BIG_ENDIAN
1392 && offset != -1
1393 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1394 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1395 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1396 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1397 #endif
1399 if (name == 0 || *name == 0)
1400 name = gen_fake_label ();
1401 PUT_SDB_DEF (name);
1402 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1403 (XEXP (DECL_RTL (parms), 0)));
1404 PUT_SDB_SCL (C_AUTO);
1405 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1406 PUT_SDB_ENDEF;
1412 /* Output debug information for a global DECL. Called from toplev.c
1413 after compilation proper has finished. */
1415 static void
1416 sdbout_global_decl (tree decl)
1418 if (TREE_CODE (decl) == VAR_DECL
1419 && !DECL_EXTERNAL (decl)
1420 && DECL_RTL_SET_P (decl))
1422 /* The COFF linker can move initialized global vars to the end.
1423 And that can screw up the symbol ordering. Defer those for
1424 sdbout_finish (). */
1425 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1426 sdbout_symbol (decl, 0);
1427 else
1428 vec_safe_push (deferred_global_decls, decl);
1430 /* Output COFF information for non-global file-scope initialized
1431 variables. */
1432 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1433 sdbout_toplevel_data (decl);
1437 /* Output initialized global vars at the end, in the order of
1438 definition. See comment in sdbout_global_decl. */
1440 static void
1441 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1443 size_t i;
1444 tree decl;
1446 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1447 sdbout_symbol (decl, 0);
1450 /* Describe the beginning of an internal block within a function.
1451 Also output descriptions of variables defined in this block.
1453 N is the number of the block, by order of beginning, counting from 1,
1454 and not counting the outermost (function top-level) block.
1455 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1456 if the count starts at 0 for the outermost one. */
1458 static void
1459 sdbout_begin_block (unsigned int line, unsigned int n)
1461 tree decl = current_function_decl;
1462 MAKE_LINE_SAFE (line);
1464 /* The SCO compiler does not emit a separate block for the function level
1465 scope, so we avoid it here also. */
1466 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1468 if (n == 1)
1470 /* Include the outermost BLOCK's variables in block 1. */
1471 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1472 sdbout_block (DECL_INITIAL (decl));
1474 /* If -g1, suppress all the internal symbols of functions
1475 except for arguments. */
1476 if (debug_info_level != DINFO_LEVEL_TERSE)
1478 do_block = n;
1479 sdbout_block (DECL_INITIAL (decl));
1482 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1483 sdbout_dequeue_anonymous_types ();
1484 #endif
1487 /* Describe the end line-number of an internal block within a function. */
1489 static void
1490 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1492 MAKE_LINE_SAFE (line);
1494 /* The SCO compiler does not emit a separate block for the function level
1495 scope, so we avoid it here also. */
1496 if (n != 1)
1497 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1500 /* Output a line number symbol entry for source file FILENAME and line
1501 number LINE. */
1503 static void
1504 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1505 int discriminator ATTRIBUTE_UNUSED,
1506 bool is_stmt ATTRIBUTE_UNUSED)
1508 /* COFF relative line numbers must be positive. */
1509 if ((int) line > sdb_begin_function_line)
1511 #ifdef SDB_OUTPUT_SOURCE_LINE
1512 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1513 #else
1514 fprintf (asm_out_file, "\t.ln\t%d\n",
1515 ((sdb_begin_function_line > -1)
1516 ? line - sdb_begin_function_line : 1));
1517 #endif
1521 /* Output sdb info for the current function name.
1522 Called from assemble_start_function. */
1524 static void
1525 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1527 sdbout_symbol (current_function_decl, 0);
1530 /* Called at beginning of function body after prologue. Record the
1531 function's starting line number, so we can output relative line numbers
1532 for the other lines. Describe beginning of outermost block. Also
1533 describe the parameter list. */
1535 static void
1536 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1538 sdbout_end_prologue (line, file);
1541 static void
1542 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1544 sdb_begin_function_line = line - 1;
1545 PUT_SDB_FUNCTION_START (line);
1546 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1547 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1550 /* Called at end of function (before epilogue).
1551 Describe end of outermost block. */
1553 static void
1554 sdbout_end_function (unsigned int line)
1556 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1557 sdbout_dequeue_anonymous_types ();
1558 #endif
1560 MAKE_LINE_SAFE (line);
1561 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1563 /* Indicate we are between functions, for line-number output. */
1564 sdb_begin_function_line = -1;
1567 /* Output sdb info for the absolute end of a function.
1568 Called after the epilogue is output. */
1570 static void
1571 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1572 const char *file ATTRIBUTE_UNUSED)
1574 const char *const name ATTRIBUTE_UNUSED
1575 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1577 #ifdef PUT_SDB_EPILOGUE_END
1578 PUT_SDB_EPILOGUE_END (name);
1579 #else
1580 fprintf (asm_out_file, "\t.def\t");
1581 assemble_name (asm_out_file, name);
1582 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1583 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1584 #endif
1587 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1588 is present. */
1590 static void
1591 sdbout_label (rtx insn)
1593 PUT_SDB_DEF (LABEL_NAME (insn));
1594 PUT_SDB_VAL (insn);
1595 PUT_SDB_SCL (C_LABEL);
1596 PUT_SDB_TYPE (T_NULL);
1597 PUT_SDB_ENDEF;
1600 /* Change to reading from a new source file. */
1602 static void
1603 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1604 const char *filename ATTRIBUTE_UNUSED)
1608 /* Revert to reading a previous source file. */
1610 static void
1611 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1615 /* Set up for SDB output at the start of compilation. */
1617 static void
1618 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1620 tree t;
1622 vec_alloc (deferred_global_decls, 12);
1624 /* Emit debug information which was queued by sdbout_symbol before
1625 we got here. */
1626 sdbout_initialized = true;
1628 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1629 sdbout_symbol (TREE_VALUE (t), 0);
1630 preinit_symbols = 0;
1633 #endif /* SDB_DEBUGGING_INFO */
1635 #include "gt-sdbout.h"