2014-10-24 Christophe Lyon <christophe.lyon@linaro.org>
[official-gcc.git] / gcc / sdbout.c
blob7b6f4573e05b6b036f7121f68182da841f0d3064
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 SET_DECL_RTL (decl,
743 eliminate_regs (DECL_RTL (decl), VOIDmode, NULL_RTX));
744 #ifdef LEAF_REG_REMAP
745 if (crtl->uses_only_leaf_regs)
746 leaf_renumber_regs_insn (DECL_RTL (decl));
747 #endif
748 value = DECL_RTL (decl);
750 /* Don't mention a variable at all
751 if it was completely optimized into nothingness.
753 If DECL was from an inline function, then its rtl
754 is not identically the rtl that was used in this
755 particular compilation. */
756 if (REG_P (value))
758 regno = REGNO (value);
759 if (regno >= FIRST_PSEUDO_REGISTER)
760 return;
762 else if (GET_CODE (value) == SUBREG)
764 while (GET_CODE (value) == SUBREG)
765 value = SUBREG_REG (value);
766 if (REG_P (value))
768 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
769 return;
771 regno = REGNO (alter_subreg (&value, true));
772 SET_DECL_RTL (decl, value);
774 /* Don't output anything if an auto variable
775 gets RTL that is static.
776 GAS version 2.2 can't handle such output. */
777 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
778 && ! TREE_STATIC (decl))
779 return;
781 /* Emit any structure, union, or enum type that has not been output.
782 This occurs for tag-less structs (et al) used to declare variables
783 within functions. */
784 if (TREE_CODE (type) == ENUMERAL_TYPE
785 || TREE_CODE (type) == RECORD_TYPE
786 || TREE_CODE (type) == UNION_TYPE
787 || TREE_CODE (type) == QUAL_UNION_TYPE)
789 if (COMPLETE_TYPE_P (type) /* not a forward reference */
790 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
791 sdbout_one_type (type);
794 /* Defer SDB information for top-level initialized variables! */
795 if (! local
796 && MEM_P (value)
797 && DECL_INITIAL (decl))
798 return;
800 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
801 For now, avoid crashing. */
802 if (DECL_NAME (decl) == NULL_TREE)
803 return;
805 /* Record the name for, starting a symtab entry. */
806 if (local)
807 name = IDENTIFIER_POINTER (DECL_NAME (decl));
808 else
809 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
811 if (MEM_P (value)
812 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
814 PUT_SDB_DEF (name);
815 if (TREE_PUBLIC (decl))
817 PUT_SDB_VAL (XEXP (value, 0));
818 PUT_SDB_SCL (C_EXT);
820 else
822 PUT_SDB_VAL (XEXP (value, 0));
823 PUT_SDB_SCL (C_STAT);
826 else if (regno >= 0)
828 PUT_SDB_DEF (name);
829 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
830 PUT_SDB_SCL (C_REG);
832 else if (MEM_P (value)
833 && (MEM_P (XEXP (value, 0))
834 || (REG_P (XEXP (value, 0))
835 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
836 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
837 /* If the value is indirect by memory or by a register
838 that isn't the frame pointer
839 then it means the object is variable-sized and address through
840 that register or stack slot. COFF has no way to represent this
841 so all we can do is output the variable as a pointer. */
843 PUT_SDB_DEF (name);
844 if (REG_P (XEXP (value, 0)))
846 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
847 PUT_SDB_SCL (C_REG);
849 else
851 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
852 (CONST_INT...)))).
853 We want the value of that CONST_INT. */
854 /* Encore compiler hates a newline in a macro arg, it seems. */
855 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
856 (XEXP (XEXP (value, 0), 0)));
857 PUT_SDB_SCL (C_AUTO);
860 /* Effectively do build_pointer_type, but don't cache this type,
861 since it might be temporary whereas the type it points to
862 might have been saved for inlining. */
863 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
864 type = make_node (POINTER_TYPE);
865 TREE_TYPE (type) = TREE_TYPE (decl);
867 else if (MEM_P (value)
868 && ((GET_CODE (XEXP (value, 0)) == PLUS
869 && REG_P (XEXP (XEXP (value, 0), 0))
870 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
871 /* This is for variables which are at offset zero from
872 the frame pointer. This happens on the Alpha.
873 Non-frame pointer registers are excluded above. */
874 || (REG_P (XEXP (value, 0)))))
876 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
877 or (MEM (REG...)). We want the value of that CONST_INT
878 or zero. */
879 PUT_SDB_DEF (name);
880 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
881 PUT_SDB_SCL (C_AUTO);
883 else
885 /* It is something we don't know how to represent for SDB. */
886 return;
888 break;
890 default:
891 break;
893 PUT_SDB_TYPE (plain_type (type));
894 PUT_SDB_ENDEF;
897 /* Output SDB information for a top-level initialized variable
898 that has been delayed. */
900 static void
901 sdbout_toplevel_data (tree decl)
903 tree type = TREE_TYPE (decl);
905 if (DECL_IGNORED_P (decl))
906 return;
908 gcc_assert (TREE_CODE (decl) == VAR_DECL);
909 gcc_assert (MEM_P (DECL_RTL (decl)));
910 gcc_assert (DECL_INITIAL (decl));
912 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
913 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
914 if (TREE_PUBLIC (decl))
916 PUT_SDB_SCL (C_EXT);
918 else
920 PUT_SDB_SCL (C_STAT);
922 PUT_SDB_TYPE (plain_type (type));
923 PUT_SDB_ENDEF;
926 #ifdef SDB_ALLOW_FORWARD_REFERENCES
928 /* Machinery to record and output anonymous types. */
930 static void
931 sdbout_queue_anonymous_type (tree type)
933 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
936 static void
937 sdbout_dequeue_anonymous_types (void)
939 tree types, link;
941 while (anonymous_types)
943 types = nreverse (anonymous_types);
944 anonymous_types = NULL_TREE;
946 for (link = types; link; link = TREE_CHAIN (link))
948 tree type = TREE_VALUE (link);
950 if (type && ! TREE_ASM_WRITTEN (type))
951 sdbout_one_type (type);
956 #endif
958 /* Given a chain of ..._TYPE nodes, all of which have names,
959 output definitions of those names, as typedefs. */
961 void
962 sdbout_types (tree types)
964 tree link;
966 for (link = types; link; link = TREE_CHAIN (link))
967 sdbout_one_type (link);
969 #ifdef SDB_ALLOW_FORWARD_REFERENCES
970 sdbout_dequeue_anonymous_types ();
971 #endif
974 static void
975 sdbout_type (tree type)
977 if (type == error_mark_node)
978 type = integer_type_node;
979 PUT_SDB_TYPE (plain_type (type));
982 /* Output types of the fields of type TYPE, if they are structs.
984 Formerly did not chase through pointer types, since that could be circular.
985 They must come before TYPE, since forward refs are not allowed.
986 Now james@bigtex.cactus.org says to try them. */
988 static void
989 sdbout_field_types (tree type)
991 tree tail;
993 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
994 /* This condition should match the one for emitting the actual
995 members below. */
996 if (TREE_CODE (tail) == FIELD_DECL
997 && DECL_NAME (tail)
998 && DECL_SIZE (tail)
999 && tree_fits_uhwi_p (DECL_SIZE (tail))
1000 && tree_fits_shwi_p (bit_position (tail)))
1002 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1003 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1004 else
1005 sdbout_one_type (TREE_TYPE (tail));
1009 /* Use this to put out the top level defined record and union types
1010 for later reference. If this is a struct with a name, then put that
1011 name out. Other unnamed structs will have .xxfake labels generated so
1012 that they may be referred to later.
1013 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1014 It may NOT be called recursively. */
1016 static void
1017 sdbout_one_type (tree type)
1019 if (current_function_decl != NULL_TREE
1020 && DECL_SECTION_NAME (current_function_decl) != NULL)
1021 ; /* Don't change section amid function. */
1022 else
1023 switch_to_section (current_function_section ());
1025 switch (TREE_CODE (type))
1027 case RECORD_TYPE:
1028 case UNION_TYPE:
1029 case QUAL_UNION_TYPE:
1030 case ENUMERAL_TYPE:
1031 type = TYPE_MAIN_VARIANT (type);
1032 /* Don't output a type twice. */
1033 if (TREE_ASM_WRITTEN (type))
1034 /* James said test TREE_ASM_BEING_WRITTEN here. */
1035 return;
1037 /* Output nothing if type is not yet defined. */
1038 if (!COMPLETE_TYPE_P (type))
1039 return;
1041 TREE_ASM_WRITTEN (type) = 1;
1043 /* This is reputed to cause trouble with the following case,
1044 but perhaps checking TYPE_SIZE above will fix it. */
1046 /* Here is a testcase:
1048 struct foo {
1049 struct badstr *bbb;
1050 } forwardref;
1052 typedef struct intermediate {
1053 int aaaa;
1054 } intermediate_ref;
1056 typedef struct badstr {
1057 int ccccc;
1058 } badtype; */
1060 /* This change, which ought to make better output,
1061 used to make the COFF assembler unhappy.
1062 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1063 /* Before really doing anything, output types we want to refer to. */
1064 /* Note that in version 1 the following two lines
1065 are not used if forward references are in use. */
1066 if (TREE_CODE (type) != ENUMERAL_TYPE)
1067 sdbout_field_types (type);
1069 /* Output a structure type. */
1071 int size = int_size_in_bytes (type);
1072 int member_scl = 0;
1073 tree tem;
1075 /* Record the type tag, but not in its permanent place just yet. */
1076 sdbout_record_type_name (type);
1078 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1080 switch (TREE_CODE (type))
1082 case UNION_TYPE:
1083 case QUAL_UNION_TYPE:
1084 PUT_SDB_SCL (C_UNTAG);
1085 PUT_SDB_TYPE (T_UNION);
1086 member_scl = C_MOU;
1087 break;
1089 case RECORD_TYPE:
1090 PUT_SDB_SCL (C_STRTAG);
1091 PUT_SDB_TYPE (T_STRUCT);
1092 member_scl = C_MOS;
1093 break;
1095 case ENUMERAL_TYPE:
1096 PUT_SDB_SCL (C_ENTAG);
1097 PUT_SDB_TYPE (T_ENUM);
1098 member_scl = C_MOE;
1099 break;
1101 default:
1102 break;
1105 PUT_SDB_SIZE (size);
1106 PUT_SDB_ENDEF;
1108 /* Print out the base class information with fields
1109 named after the types they hold. */
1110 /* This is only relevant to aggregate types. TYPE_BINFO is used
1111 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1112 case. */
1113 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1115 int i;
1116 tree binfo, child;
1118 for (binfo = TYPE_BINFO (type), i = 0;
1119 BINFO_BASE_ITERATE (binfo, i, child); i++)
1121 tree child_type = BINFO_TYPE (child);
1122 tree child_type_name;
1124 if (TYPE_NAME (child_type) == 0)
1125 continue;
1126 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1127 child_type_name = TYPE_NAME (child_type);
1128 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1130 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1131 if (child_type_name && template_name_p (child_type_name))
1132 child_type_name
1133 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1135 else
1136 continue;
1138 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1139 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1140 PUT_SDB_SCL (member_scl);
1141 sdbout_type (BINFO_TYPE (child));
1142 PUT_SDB_ENDEF;
1146 /* Output the individual fields. */
1148 if (TREE_CODE (type) == ENUMERAL_TYPE)
1150 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1152 tree value = TREE_VALUE (tem);
1154 if (TREE_CODE (value) == CONST_DECL)
1155 value = DECL_INITIAL (value);
1157 if (tree_fits_shwi_p (value))
1159 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1160 PUT_SDB_INT_VAL (tree_to_shwi (value));
1161 PUT_SDB_SCL (C_MOE);
1162 PUT_SDB_TYPE (T_MOE);
1163 PUT_SDB_ENDEF;
1167 else /* record or union type */
1168 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1169 /* Output the name, type, position (in bits), size (in bits)
1170 of each field. */
1172 /* Omit here the nameless fields that are used to skip bits.
1173 Also omit fields with variable size or position.
1174 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1175 if (TREE_CODE (tem) == FIELD_DECL
1176 && DECL_NAME (tem)
1177 && DECL_SIZE (tem)
1178 && tree_fits_uhwi_p (DECL_SIZE (tem))
1179 && tree_fits_shwi_p (bit_position (tem)))
1181 const char *name;
1183 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1184 PUT_SDB_DEF (name);
1185 if (DECL_BIT_FIELD_TYPE (tem))
1187 PUT_SDB_INT_VAL (int_bit_position (tem));
1188 PUT_SDB_SCL (C_FIELD);
1189 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1190 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1192 else
1194 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1195 PUT_SDB_SCL (member_scl);
1196 sdbout_type (TREE_TYPE (tem));
1198 PUT_SDB_ENDEF;
1200 /* Output end of a structure,union, or enumeral definition. */
1202 PUT_SDB_PLAIN_DEF ("eos");
1203 PUT_SDB_INT_VAL (size);
1204 PUT_SDB_SCL (C_EOS);
1205 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1206 PUT_SDB_SIZE (size);
1207 PUT_SDB_ENDEF;
1208 break;
1211 default:
1212 break;
1216 /* The following two functions output definitions of function parameters.
1217 Each parameter gets a definition locating it in the parameter list.
1218 Each parameter that is a register variable gets a second definition
1219 locating it in the register.
1221 Printing or argument lists in gdb uses the definitions that
1222 locate in the parameter list. But reference to the variable in
1223 expressions uses preferentially the definition as a register. */
1225 /* Output definitions, referring to storage in the parmlist,
1226 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1228 static void
1229 sdbout_parms (tree parms)
1231 for (; parms; parms = TREE_CHAIN (parms))
1232 if (DECL_NAME (parms)
1233 && TREE_TYPE (parms) != error_mark_node
1234 && DECL_RTL_SET_P (parms)
1235 && DECL_INCOMING_RTL (parms))
1237 int current_sym_value = 0;
1238 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1240 if (name == 0 || *name == 0)
1241 name = gen_fake_label ();
1243 /* Perform any necessary register eliminations on the parameter's rtl,
1244 so that the debugging output will be accurate. */
1245 DECL_INCOMING_RTL (parms)
1246 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1247 SET_DECL_RTL (parms,
1248 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1250 if (PARM_PASSED_IN_MEMORY (parms))
1252 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1253 tree type;
1255 /* ??? Here we assume that the parm address is indexed
1256 off the frame pointer or arg pointer.
1257 If that is not true, we produce meaningless results,
1258 but do not crash. */
1259 if (GET_CODE (addr) == PLUS
1260 && CONST_INT_P (XEXP (addr, 1)))
1261 current_sym_value = INTVAL (XEXP (addr, 1));
1262 else
1263 current_sym_value = 0;
1265 if (REG_P (DECL_RTL (parms))
1266 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1267 type = DECL_ARG_TYPE (parms);
1268 else
1270 int original_sym_value = current_sym_value;
1272 /* This is the case where the parm is passed as an int or
1273 double and it is converted to a char, short or float
1274 and stored back in the parmlist. In this case, describe
1275 the parm with the variable's declared type, and adjust
1276 the address if the least significant bytes (which we are
1277 using) are not the first ones. */
1278 if (BYTES_BIG_ENDIAN
1279 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1280 current_sym_value +=
1281 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1282 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1284 if (MEM_P (DECL_RTL (parms))
1285 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1286 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1287 == CONST_INT)
1288 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1289 == current_sym_value))
1290 type = TREE_TYPE (parms);
1291 else
1293 current_sym_value = original_sym_value;
1294 type = DECL_ARG_TYPE (parms);
1298 PUT_SDB_DEF (name);
1299 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1300 PUT_SDB_SCL (C_ARG);
1301 PUT_SDB_TYPE (plain_type (type));
1302 PUT_SDB_ENDEF;
1304 else if (REG_P (DECL_RTL (parms)))
1306 rtx best_rtl;
1307 /* Parm passed in registers and lives in registers or nowhere. */
1309 /* If parm lives in a register, use that register;
1310 pretend the parm was passed there. It would be more consistent
1311 to describe the register where the parm was passed,
1312 but in practice that register usually holds something else. */
1313 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1314 best_rtl = DECL_RTL (parms);
1315 /* If the parm lives nowhere,
1316 use the register where it was passed. */
1317 else
1318 best_rtl = DECL_INCOMING_RTL (parms);
1320 PUT_SDB_DEF (name);
1321 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1322 PUT_SDB_SCL (C_REGPARM);
1323 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1324 PUT_SDB_ENDEF;
1326 else if (MEM_P (DECL_RTL (parms))
1327 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1329 /* Parm was passed in registers but lives on the stack. */
1331 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1332 in which case we want the value of that CONST_INT,
1333 or (MEM (REG ...)) or (MEM (MEM ...)),
1334 in which case we use a value of zero. */
1335 if (REG_P (XEXP (DECL_RTL (parms), 0))
1336 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1337 current_sym_value = 0;
1338 else
1339 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1341 /* Again, this assumes the offset is based on the arg pointer. */
1342 PUT_SDB_DEF (name);
1343 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1344 XEXP (DECL_RTL (parms), 0)));
1345 PUT_SDB_SCL (C_ARG);
1346 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1347 PUT_SDB_ENDEF;
1352 /* Output definitions for the places where parms live during the function,
1353 when different from where they were passed, when the parms were passed
1354 in memory.
1356 It is not useful to do this for parms passed in registers
1357 that live during the function in different registers, because it is
1358 impossible to look in the passed register for the passed value,
1359 so we use the within-the-function register to begin with.
1361 PARMS is a chain of PARM_DECL nodes. */
1363 static void
1364 sdbout_reg_parms (tree parms)
1366 for (; parms; parms = TREE_CHAIN (parms))
1367 if (DECL_NAME (parms)
1368 && TREE_TYPE (parms) != error_mark_node
1369 && DECL_RTL_SET_P (parms)
1370 && DECL_INCOMING_RTL (parms))
1372 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1374 /* Report parms that live in registers during the function
1375 but were passed in memory. */
1376 if (REG_P (DECL_RTL (parms))
1377 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1378 && PARM_PASSED_IN_MEMORY (parms))
1380 if (name == 0 || *name == 0)
1381 name = gen_fake_label ();
1382 PUT_SDB_DEF (name);
1383 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1384 PUT_SDB_SCL (C_REG);
1385 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1386 PUT_SDB_ENDEF;
1388 /* Report parms that live in memory but not where they were passed. */
1389 else if (MEM_P (DECL_RTL (parms))
1390 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1391 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1392 && PARM_PASSED_IN_MEMORY (parms)
1393 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1395 #if 0 /* ??? It is not clear yet what should replace this. */
1396 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1397 /* A parm declared char is really passed as an int,
1398 so it occupies the least significant bytes.
1399 On a big-endian machine those are not the low-numbered ones. */
1400 if (BYTES_BIG_ENDIAN
1401 && offset != -1
1402 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1403 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1404 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1405 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1406 #endif
1408 if (name == 0 || *name == 0)
1409 name = gen_fake_label ();
1410 PUT_SDB_DEF (name);
1411 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1412 (XEXP (DECL_RTL (parms), 0)));
1413 PUT_SDB_SCL (C_AUTO);
1414 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1415 PUT_SDB_ENDEF;
1421 /* Output debug information for a global DECL. Called from toplev.c
1422 after compilation proper has finished. */
1424 static void
1425 sdbout_global_decl (tree decl)
1427 if (TREE_CODE (decl) == VAR_DECL
1428 && !DECL_EXTERNAL (decl)
1429 && DECL_RTL_SET_P (decl))
1431 /* The COFF linker can move initialized global vars to the end.
1432 And that can screw up the symbol ordering. Defer those for
1433 sdbout_finish (). */
1434 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1435 sdbout_symbol (decl, 0);
1436 else
1437 vec_safe_push (deferred_global_decls, decl);
1439 /* Output COFF information for non-global file-scope initialized
1440 variables. */
1441 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1442 sdbout_toplevel_data (decl);
1446 /* Output initialized global vars at the end, in the order of
1447 definition. See comment in sdbout_global_decl. */
1449 static void
1450 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1452 size_t i;
1453 tree decl;
1455 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1456 sdbout_symbol (decl, 0);
1459 /* Describe the beginning of an internal block within a function.
1460 Also output descriptions of variables defined in this block.
1462 N is the number of the block, by order of beginning, counting from 1,
1463 and not counting the outermost (function top-level) block.
1464 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1465 if the count starts at 0 for the outermost one. */
1467 static void
1468 sdbout_begin_block (unsigned int line, unsigned int n)
1470 tree decl = current_function_decl;
1471 MAKE_LINE_SAFE (line);
1473 /* The SCO compiler does not emit a separate block for the function level
1474 scope, so we avoid it here also. */
1475 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1477 if (n == 1)
1479 /* Include the outermost BLOCK's variables in block 1. */
1480 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1481 sdbout_block (DECL_INITIAL (decl));
1483 /* If -g1, suppress all the internal symbols of functions
1484 except for arguments. */
1485 if (debug_info_level != DINFO_LEVEL_TERSE)
1487 do_block = n;
1488 sdbout_block (DECL_INITIAL (decl));
1491 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1492 sdbout_dequeue_anonymous_types ();
1493 #endif
1496 /* Describe the end line-number of an internal block within a function. */
1498 static void
1499 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1501 MAKE_LINE_SAFE (line);
1503 /* The SCO compiler does not emit a separate block for the function level
1504 scope, so we avoid it here also. */
1505 if (n != 1)
1506 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1509 /* Output a line number symbol entry for source file FILENAME and line
1510 number LINE. */
1512 static void
1513 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1514 int discriminator ATTRIBUTE_UNUSED,
1515 bool is_stmt ATTRIBUTE_UNUSED)
1517 /* COFF relative line numbers must be positive. */
1518 if ((int) line > sdb_begin_function_line)
1520 #ifdef SDB_OUTPUT_SOURCE_LINE
1521 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1522 #else
1523 fprintf (asm_out_file, "\t.ln\t%d\n",
1524 ((sdb_begin_function_line > -1)
1525 ? line - sdb_begin_function_line : 1));
1526 #endif
1530 /* Output sdb info for the current function name.
1531 Called from assemble_start_function. */
1533 static void
1534 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1536 sdbout_symbol (current_function_decl, 0);
1539 /* Called at beginning of function body after prologue. Record the
1540 function's starting line number, so we can output relative line numbers
1541 for the other lines. Describe beginning of outermost block. Also
1542 describe the parameter list. */
1544 static void
1545 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1547 sdbout_end_prologue (line, file);
1550 static void
1551 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1553 sdb_begin_function_line = line - 1;
1554 PUT_SDB_FUNCTION_START (line);
1555 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1556 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1559 /* Called at end of function (before epilogue).
1560 Describe end of outermost block. */
1562 static void
1563 sdbout_end_function (unsigned int line)
1565 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1566 sdbout_dequeue_anonymous_types ();
1567 #endif
1569 MAKE_LINE_SAFE (line);
1570 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1572 /* Indicate we are between functions, for line-number output. */
1573 sdb_begin_function_line = -1;
1576 /* Output sdb info for the absolute end of a function.
1577 Called after the epilogue is output. */
1579 static void
1580 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1581 const char *file ATTRIBUTE_UNUSED)
1583 const char *const name ATTRIBUTE_UNUSED
1584 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1586 #ifdef PUT_SDB_EPILOGUE_END
1587 PUT_SDB_EPILOGUE_END (name);
1588 #else
1589 fprintf (asm_out_file, "\t.def\t");
1590 assemble_name (asm_out_file, name);
1591 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1592 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1593 #endif
1596 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1597 is present. */
1599 static void
1600 sdbout_label (rtx_code_label *insn)
1602 PUT_SDB_DEF (LABEL_NAME (insn));
1603 PUT_SDB_VAL (insn);
1604 PUT_SDB_SCL (C_LABEL);
1605 PUT_SDB_TYPE (T_NULL);
1606 PUT_SDB_ENDEF;
1609 /* Change to reading from a new source file. */
1611 static void
1612 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1613 const char *filename ATTRIBUTE_UNUSED)
1617 /* Revert to reading a previous source file. */
1619 static void
1620 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1624 /* Set up for SDB output at the start of compilation. */
1626 static void
1627 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1629 tree t;
1631 vec_alloc (deferred_global_decls, 12);
1633 /* Emit debug information which was queued by sdbout_symbol before
1634 we got here. */
1635 sdbout_initialized = true;
1637 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1638 sdbout_symbol (TREE_VALUE (t), 0);
1639 preinit_symbols = 0;
1642 #endif /* SDB_DEBUGGING_INFO */
1644 #include "gt-sdbout.h"