* c-gimplify.c (c_gimplify_expr): Handle [LR]ROTATE_EXPR like
[official-gcc.git] / gcc / sdbout.c
blobacd25a3c7658eae14609fffabab9963da2d53965
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2017 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 "gsyms.h"
46 #include "tm.h"
47 #include "debug.h"
48 #include "tree.h"
49 #include "varasm.h"
50 #include "stor-layout.h"
52 static GTY(()) tree anonymous_types;
54 /* Counter to generate unique "names" for nameless struct members. */
56 static GTY(()) int unnamed_struct_number;
58 /* Declarations whose debug info was deferred till end of compilation. */
60 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
62 /* The C front end may call sdbout_symbol before sdbout_init runs.
63 We save all such decls in this list and output them when we get
64 to sdbout_init. */
66 static GTY(()) tree preinit_symbols;
67 static GTY(()) bool sdbout_initialized;
69 #include "rtl.h"
70 #include "regs.h"
71 #include "function.h"
72 #include "memmodel.h"
73 #include "emit-rtl.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 "langhooks.h"
81 #include "target.h"
83 /* 1 if PARM is passed to this function in memory. */
85 #define PARM_PASSED_IN_MEMORY(PARM) \
86 (MEM_P (DECL_INCOMING_RTL (PARM)))
88 /* A C expression for the integer offset value of an automatic variable
89 (C_AUTO) having address X (an RTX). */
90 #ifndef DEBUGGER_AUTO_OFFSET
91 #define DEBUGGER_AUTO_OFFSET(X) \
92 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
93 #endif
95 /* A C expression for the integer offset value of an argument (C_ARG)
96 having address X (an RTX). The nominal offset is OFFSET. */
97 #ifndef DEBUGGER_ARG_OFFSET
98 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
99 #endif
101 /* Line number of beginning of current function, minus one.
102 Negative means not in a function or not using sdb. */
104 int sdb_begin_function_line = -1;
107 extern FILE *asm_out_file;
109 extern tree current_function_decl;
111 #include "sdbout.h"
113 static void sdbout_init (const char *);
114 static void sdbout_finish (const char *);
115 static void sdbout_start_source_file (unsigned int, const char *);
116 static void sdbout_end_source_file (unsigned int);
117 static void sdbout_begin_block (unsigned int, unsigned int);
118 static void sdbout_end_block (unsigned int, unsigned int);
119 static void sdbout_source_line (unsigned int, unsigned int,
120 const char *, int, bool);
121 static void sdbout_end_epilogue (unsigned int, const char *);
122 static void sdbout_early_global_decl (tree);
123 static void sdbout_late_global_decl (tree);
124 static void sdbout_begin_prologue (unsigned int, unsigned int,
125 const char *);
126 static void sdbout_end_prologue (unsigned int, const char *);
127 static void sdbout_begin_function (tree);
128 static void sdbout_end_function (unsigned int);
129 static void sdbout_toplevel_data (tree);
130 static void sdbout_label (rtx_code_label *);
131 static char *gen_fake_label (void);
132 static int plain_type (tree);
133 static int template_name_p (tree);
134 static void sdbout_record_type_name (tree);
135 static int plain_type_1 (tree, int);
136 static void sdbout_block (tree);
137 static void sdbout_syms (tree);
138 #ifdef SDB_ALLOW_FORWARD_REFERENCES
139 static void sdbout_queue_anonymous_type (tree);
140 static void sdbout_dequeue_anonymous_types (void);
141 #endif
142 static void sdbout_type (tree);
143 static void sdbout_field_types (tree);
144 static void sdbout_one_type (tree);
145 static void sdbout_parms (tree);
146 static void sdbout_reg_parms (tree);
148 /* Random macros describing parts of SDB data. */
150 /* Default value of delimiter is ";". */
151 #ifndef SDB_DELIM
152 #define SDB_DELIM ";"
153 #endif
155 /* Maximum number of dimensions the assembler will allow. */
156 #ifndef SDB_MAX_DIM
157 #define SDB_MAX_DIM 4
158 #endif
160 #ifndef PUT_SDB_SCL
161 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
162 #endif
164 #ifndef PUT_SDB_INT_VAL
165 #define PUT_SDB_INT_VAL(a) \
166 do { \
167 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
168 (HOST_WIDE_INT) (a), SDB_DELIM); \
169 } while (0)
171 #endif
173 #ifndef PUT_SDB_VAL
174 #define PUT_SDB_VAL(a) \
175 ( fputs ("\t.val\t", asm_out_file), \
176 output_addr_const (asm_out_file, (a)), \
177 fprintf (asm_out_file, SDB_DELIM))
178 #endif
180 #ifndef PUT_SDB_DEF
181 #define PUT_SDB_DEF(a) \
182 do { fprintf (asm_out_file, "\t.def\t"); \
183 assemble_name (asm_out_file, a); \
184 fprintf (asm_out_file, SDB_DELIM); } while (0)
185 #endif
187 #ifndef PUT_SDB_PLAIN_DEF
188 #define PUT_SDB_PLAIN_DEF(a) \
189 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
190 #endif
192 #ifndef PUT_SDB_ENDEF
193 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
194 #endif
196 #ifndef PUT_SDB_TYPE
197 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
198 #endif
200 #ifndef PUT_SDB_SIZE
201 #define PUT_SDB_SIZE(a) \
202 do { \
203 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
204 (HOST_WIDE_INT) (a), SDB_DELIM); \
205 } while (0)
206 #endif
208 #ifndef PUT_SDB_START_DIM
209 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
210 #endif
212 #ifndef PUT_SDB_NEXT_DIM
213 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
214 #endif
216 #ifndef PUT_SDB_LAST_DIM
217 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
218 #endif
220 #ifndef PUT_SDB_TAG
221 #define PUT_SDB_TAG(a) \
222 do { fprintf (asm_out_file, "\t.tag\t"); \
223 assemble_name (asm_out_file, a); \
224 fprintf (asm_out_file, SDB_DELIM); } while (0)
225 #endif
227 #ifndef PUT_SDB_BLOCK_START
228 #define PUT_SDB_BLOCK_START(LINE) \
229 fprintf (asm_out_file, \
230 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
231 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
232 #endif
234 #ifndef PUT_SDB_BLOCK_END
235 #define PUT_SDB_BLOCK_END(LINE) \
236 fprintf (asm_out_file, \
237 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
238 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
239 #endif
241 #ifndef PUT_SDB_FUNCTION_START
242 #define PUT_SDB_FUNCTION_START(LINE) \
243 fprintf (asm_out_file, \
244 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
245 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
246 #endif
248 #ifndef PUT_SDB_FUNCTION_END
249 #define PUT_SDB_FUNCTION_END(LINE) \
250 fprintf (asm_out_file, \
251 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
252 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
253 #endif
255 /* Return the sdb tag identifier string for TYPE
256 if TYPE has already been defined; otherwise return a null pointer. */
258 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
260 /* Set the sdb tag identifier string for TYPE to NAME. */
262 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
263 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
265 /* Return the name (a string) of the struct, union or enum tag
266 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
268 #define TAG_NAME(link) \
269 (((link) && TREE_PURPOSE ((link)) \
270 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
271 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
273 /* Ensure we don't output a negative line number. */
274 #define MAKE_LINE_SAFE(line) \
275 if ((int) line <= sdb_begin_function_line) \
276 line = sdb_begin_function_line + 1
278 /* The debug hooks structure. */
279 const struct gcc_debug_hooks sdb_debug_hooks =
281 sdbout_init, /* init */
282 sdbout_finish, /* finish */
283 debug_nothing_charstar, /* early_finish */
284 debug_nothing_void, /* assembly_start */
285 debug_nothing_int_charstar, /* define */
286 debug_nothing_int_charstar, /* undef */
287 sdbout_start_source_file, /* start_source_file */
288 sdbout_end_source_file, /* end_source_file */
289 sdbout_begin_block, /* begin_block */
290 sdbout_end_block, /* end_block */
291 debug_true_const_tree, /* ignore_block */
292 sdbout_source_line, /* source_line */
293 sdbout_begin_prologue, /* begin_prologue */
294 debug_nothing_int_charstar, /* end_prologue */
295 debug_nothing_int_charstar, /* begin_epilogue */
296 sdbout_end_epilogue, /* end_epilogue */
297 sdbout_begin_function, /* begin_function */
298 sdbout_end_function, /* end_function */
299 debug_nothing_tree, /* register_main_translation_unit */
300 debug_nothing_tree, /* function_decl */
301 sdbout_early_global_decl, /* early_global_decl */
302 sdbout_late_global_decl, /* late_global_decl */
303 sdbout_symbol, /* type_decl */
304 debug_nothing_tree_tree_tree_bool_bool,/* imported_module_or_decl */
305 debug_false_tree_charstarstar_uhwistar,/* die_ref_for_decl */
306 debug_nothing_tree_charstar_uhwi, /* register_external_die */
307 debug_nothing_tree, /* deferred_inline_function */
308 debug_nothing_tree, /* outlining_inline_function */
309 sdbout_label, /* label */
310 debug_nothing_int, /* handle_pch */
311 debug_nothing_rtx_insn, /* var_location */
312 debug_nothing_tree, /* size_function */
313 debug_nothing_void, /* switch_text_section */
314 debug_nothing_tree_tree, /* set_name */
315 0, /* start_end_main_source_file */
316 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
319 /* Return a unique string to name an anonymous type. */
321 static char *
322 gen_fake_label (void)
324 char label[10];
325 char *labelstr;
326 sprintf (label, ".%dfake", unnamed_struct_number);
327 unnamed_struct_number++;
328 labelstr = xstrdup (label);
329 return labelstr;
332 /* Return the number which describes TYPE for SDB.
333 For pointers, etc., this function is recursive.
334 Each record, union or enumeral type must already have had a
335 tag number output. */
337 /* The number is given by d6d5d4d3d2d1bbbb
338 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
339 Thus, char *foo () has bbbb=T_CHAR
340 d1=D_FCN
341 d2=D_PTR
342 N_BTMASK= 017 1111 basic type field.
343 N_TSHIFT= 2 derived type shift
344 N_BTSHFT= 4 Basic type shift */
346 /* Produce the number that describes a pointer, function or array type.
347 PREV is the number describing the target, value or element type.
348 DT_type describes how to transform that type. */
349 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
350 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
351 | ((int) DT_type << (int) N_BTSHFT) \
352 | ((PREV) & (int) N_BTMASK))
354 /* Number of elements used in sdb_dims. */
355 static int sdb_n_dims = 0;
357 /* Table of array dimensions of current type. */
358 static int sdb_dims[SDB_MAX_DIM];
360 /* Size of outermost array currently being processed. */
361 static int sdb_type_size = -1;
363 static int
364 plain_type (tree type)
366 int val = plain_type_1 (type, 0);
368 /* If we have already saved up some array dimensions, print them now. */
369 if (sdb_n_dims > 0)
371 int i;
372 PUT_SDB_START_DIM;
373 for (i = sdb_n_dims - 1; i > 0; i--)
374 PUT_SDB_NEXT_DIM (sdb_dims[i]);
375 PUT_SDB_LAST_DIM (sdb_dims[0]);
376 sdb_n_dims = 0;
378 sdb_type_size = int_size_in_bytes (type);
379 /* Don't kill sdb if type is not laid out or has variable size. */
380 if (sdb_type_size < 0)
381 sdb_type_size = 0;
383 /* If we have computed the size of an array containing this type,
384 print it now. */
385 if (sdb_type_size >= 0)
387 PUT_SDB_SIZE (sdb_type_size);
388 sdb_type_size = -1;
390 return val;
393 static int
394 template_name_p (tree name)
396 const char *ptr = IDENTIFIER_POINTER (name);
397 while (*ptr && *ptr != '<')
398 ptr++;
400 return *ptr != '\0';
403 static void
404 sdbout_record_type_name (tree type)
406 const char *name = 0;
407 int no_name;
409 if (KNOWN_TYPE_TAG (type))
410 return;
412 if (TYPE_NAME (type) != 0)
414 tree t = 0;
416 /* Find the IDENTIFIER_NODE for the type name. */
417 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
418 t = TYPE_NAME (type);
419 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
421 t = DECL_NAME (TYPE_NAME (type));
422 /* The DECL_NAME for templates includes "<>", which breaks
423 most assemblers. Use its assembler name instead, which
424 has been mangled into being safe. */
425 if (t && template_name_p (t))
426 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
429 /* Now get the name as a string, or invent one. */
430 if (t != NULL_TREE)
431 name = IDENTIFIER_POINTER (t);
434 no_name = (name == 0 || *name == 0);
435 if (no_name)
436 name = gen_fake_label ();
438 SET_KNOWN_TYPE_TAG (type, name);
439 #ifdef SDB_ALLOW_FORWARD_REFERENCES
440 if (no_name)
441 sdbout_queue_anonymous_type (type);
442 #endif
445 /* Return the .type value for type TYPE.
447 LEVEL indicates how many levels deep we have recursed into the type.
448 The SDB debug format can only represent 6 derived levels of types.
449 After that, we must output inaccurate debug info. We deliberately
450 stop before the 7th level, so that ADA recursive types will not give an
451 infinite loop. */
453 static int
454 plain_type_1 (tree type, int level)
456 if (type == 0)
457 type = void_type_node;
458 else if (type == error_mark_node)
459 type = integer_type_node;
460 else
461 type = TYPE_MAIN_VARIANT (type);
463 switch (TREE_CODE (type))
465 case VOID_TYPE:
466 case NULLPTR_TYPE:
467 return T_VOID;
468 case BOOLEAN_TYPE:
469 case INTEGER_TYPE:
471 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
473 /* Carefully distinguish all the standard types of C,
474 without messing up if the language is not C.
475 Note that we check only for the names that contain spaces;
476 other names might occur by coincidence in other languages. */
477 if (TYPE_NAME (type) != 0
478 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
479 && DECL_NAME (TYPE_NAME (type)) != 0
480 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
482 const char *const name
483 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
485 if (!strcmp (name, "char"))
486 return T_CHAR;
487 if (!strcmp (name, "unsigned char"))
488 return T_UCHAR;
489 if (!strcmp (name, "signed char"))
490 return T_CHAR;
491 if (!strcmp (name, "int"))
492 return T_INT;
493 if (!strcmp (name, "unsigned int"))
494 return T_UINT;
495 if (!strcmp (name, "short int"))
496 return T_SHORT;
497 if (!strcmp (name, "short unsigned int"))
498 return T_USHORT;
499 if (!strcmp (name, "long int"))
500 return T_LONG;
501 if (!strcmp (name, "long unsigned int"))
502 return T_ULONG;
505 if (size == INT_TYPE_SIZE)
506 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
507 if (size == CHAR_TYPE_SIZE)
508 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
509 if (size == SHORT_TYPE_SIZE)
510 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
511 if (size == LONG_TYPE_SIZE)
512 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
513 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
514 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
515 return 0;
518 case REAL_TYPE:
520 int precision = TYPE_PRECISION (type);
521 if (precision == FLOAT_TYPE_SIZE)
522 return T_FLOAT;
523 if (precision == DOUBLE_TYPE_SIZE)
524 return T_DOUBLE;
525 if (precision == LONG_DOUBLE_TYPE_SIZE)
526 return T_DOUBLE; /* better than nothing */
528 return 0;
531 case ARRAY_TYPE:
533 int m;
534 if (level >= 6)
535 return T_VOID;
536 else
537 m = plain_type_1 (TREE_TYPE (type), level+1);
538 if (sdb_n_dims < SDB_MAX_DIM)
539 sdb_dims[sdb_n_dims++]
540 = (TYPE_DOMAIN (type)
541 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
542 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
543 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
544 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
545 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
546 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
547 : 0);
549 return PUSH_DERIVED_LEVEL (DT_ARY, m);
552 case RECORD_TYPE:
553 case UNION_TYPE:
554 case QUAL_UNION_TYPE:
555 case ENUMERAL_TYPE:
557 const char *tag;
558 #ifdef SDB_ALLOW_FORWARD_REFERENCES
559 sdbout_record_type_name (type);
560 #endif
561 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
562 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
563 #ifdef SDB_ALLOW_FORWARD_REFERENCES
564 || TYPE_MODE (type) != VOIDmode
565 #endif
567 #endif
569 /* Output the referenced structure tag name
570 only if the .def has already been finished.
571 At least on 386, the Unix assembler
572 cannot handle forward references to tags. */
573 /* But the 88100, it requires them, sigh... */
574 /* And the MIPS requires unknown refs as well... */
575 tag = KNOWN_TYPE_TAG (type);
576 PUT_SDB_TAG (tag);
577 /* These 3 lines used to follow the close brace.
578 However, a size of 0 without a tag implies a tag of 0,
579 so if we don't know a tag, we can't mention the size. */
580 sdb_type_size = int_size_in_bytes (type);
581 if (sdb_type_size < 0)
582 sdb_type_size = 0;
584 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
585 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
586 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
587 : T_ENUM);
589 case POINTER_TYPE:
590 case REFERENCE_TYPE:
592 int m;
593 if (level >= 6)
594 return T_VOID;
595 else
596 m = plain_type_1 (TREE_TYPE (type), level+1);
597 return PUSH_DERIVED_LEVEL (DT_PTR, m);
599 case FUNCTION_TYPE:
600 case METHOD_TYPE:
602 int m;
603 if (level >= 6)
604 return T_VOID;
605 else
606 m = plain_type_1 (TREE_TYPE (type), level+1);
607 return PUSH_DERIVED_LEVEL (DT_FCN, m);
609 default:
610 return 0;
614 /* Output the symbols defined in block number DO_BLOCK.
616 This function works by walking the tree structure of blocks,
617 counting blocks until it finds the desired block. */
619 static int do_block = 0;
621 static void
622 sdbout_block (tree block)
624 while (block)
626 /* Ignore blocks never expanded or otherwise marked as real. */
627 if (TREE_USED (block))
629 /* When we reach the specified block, output its symbols. */
630 if (BLOCK_NUMBER (block) == do_block)
631 sdbout_syms (BLOCK_VARS (block));
633 /* If we are past the specified block, stop the scan. */
634 if (BLOCK_NUMBER (block) > do_block)
635 return;
637 /* Scan the blocks within this block. */
638 sdbout_block (BLOCK_SUBBLOCKS (block));
641 block = BLOCK_CHAIN (block);
645 /* Call sdbout_symbol on each decl in the chain SYMS. */
647 static void
648 sdbout_syms (tree syms)
650 while (syms)
652 if (TREE_CODE (syms) != LABEL_DECL)
653 sdbout_symbol (syms, 1);
654 syms = TREE_CHAIN (syms);
658 /* Output SDB information for a symbol described by DECL.
659 LOCAL is nonzero if the symbol is not file-scope. */
661 void
662 sdbout_symbol (tree decl, int local)
664 tree type = TREE_TYPE (decl);
665 tree context = NULL_TREE;
666 rtx value;
667 int regno = -1;
668 const char *name;
670 /* If we are called before sdbout_init is run, just save the symbol
671 for later. */
672 if (!sdbout_initialized)
674 preinit_symbols = tree_cons (0, decl, preinit_symbols);
675 return;
678 sdbout_one_type (type);
680 switch (TREE_CODE (decl))
682 case CONST_DECL:
683 /* Enum values are defined by defining the enum type. */
684 return;
686 case FUNCTION_DECL:
687 /* Don't mention a nested function under its parent. */
688 context = decl_function_context (decl);
689 if (context == current_function_decl)
690 return;
691 /* Check DECL_INITIAL to distinguish declarations from definitions.
692 Don't output debug info here for declarations; they will have
693 a DECL_INITIAL value of 0. */
694 if (! DECL_INITIAL (decl))
695 return;
696 if (!MEM_P (DECL_RTL (decl))
697 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
698 return;
699 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
700 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
701 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
702 break;
704 case TYPE_DECL:
705 /* Done with tagged types. */
706 if (DECL_NAME (decl) == 0)
707 return;
708 if (DECL_IGNORED_P (decl))
709 return;
710 /* Don't output intrinsic types. GAS chokes on SDB .def
711 statements that contain identifiers with embedded spaces
712 (eg "unsigned long"). */
713 if (DECL_IS_BUILTIN (decl))
714 return;
716 /* Output typedef name. */
717 if (template_name_p (DECL_NAME (decl)))
718 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
719 else
720 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
721 PUT_SDB_SCL (C_TPDEF);
722 break;
724 case PARM_DECL:
725 /* Parm decls go in their own separate chains
726 and are output by sdbout_reg_parms and sdbout_parms. */
727 gcc_unreachable ();
729 case VAR_DECL:
730 /* Don't mention a variable that is external.
731 Let the file that defines it describe it. */
732 if (DECL_EXTERNAL (decl))
733 return;
735 /* Ignore __FUNCTION__, etc. */
736 if (DECL_IGNORED_P (decl))
737 return;
739 /* If there was an error in the declaration, don't dump core
740 if there is no RTL associated with the variable doesn't
741 exist. */
742 if (!DECL_RTL_SET_P (decl))
743 return;
745 value = DECL_RTL (decl);
747 if (!is_global_var (decl))
748 value = eliminate_regs (value, VOIDmode, NULL_RTX);
750 SET_DECL_RTL (decl, value);
751 #ifdef LEAF_REG_REMAP
752 if (crtl->uses_only_leaf_regs)
753 leaf_renumber_regs_insn (value);
754 #endif
756 /* Don't mention a variable at all
757 if it was completely optimized into nothingness.
759 If DECL was from an inline function, then its rtl
760 is not identically the rtl that was used in this
761 particular compilation. */
762 if (REG_P (value))
764 regno = REGNO (value);
765 if (regno >= FIRST_PSEUDO_REGISTER)
766 return;
768 else if (GET_CODE (value) == SUBREG)
770 while (GET_CODE (value) == SUBREG)
771 value = SUBREG_REG (value);
772 if (REG_P (value))
774 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
775 return;
777 regno = REGNO (alter_subreg (&value, true));
778 SET_DECL_RTL (decl, value);
780 /* Don't output anything if an auto variable
781 gets RTL that is static.
782 GAS version 2.2 can't handle such output. */
783 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
784 && ! TREE_STATIC (decl))
785 return;
787 /* Emit any structure, union, or enum type that has not been output.
788 This occurs for tag-less structs (et al) used to declare variables
789 within functions. */
790 if (TREE_CODE (type) == ENUMERAL_TYPE
791 || TREE_CODE (type) == RECORD_TYPE
792 || TREE_CODE (type) == UNION_TYPE
793 || TREE_CODE (type) == QUAL_UNION_TYPE)
795 if (COMPLETE_TYPE_P (type) /* not a forward reference */
796 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
797 sdbout_one_type (type);
800 /* Defer SDB information for top-level initialized variables! */
801 if (! local
802 && MEM_P (value)
803 && DECL_INITIAL (decl))
804 return;
806 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
807 For now, avoid crashing. */
808 if (DECL_NAME (decl) == NULL_TREE)
809 return;
811 /* Record the name for, starting a symtab entry. */
812 if (local)
813 name = IDENTIFIER_POINTER (DECL_NAME (decl));
814 else
815 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
817 if (MEM_P (value)
818 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
820 PUT_SDB_DEF (name);
821 if (TREE_PUBLIC (decl))
823 PUT_SDB_VAL (XEXP (value, 0));
824 PUT_SDB_SCL (C_EXT);
826 else
828 PUT_SDB_VAL (XEXP (value, 0));
829 PUT_SDB_SCL (C_STAT);
832 else if (regno >= 0)
834 PUT_SDB_DEF (name);
835 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
836 PUT_SDB_SCL (C_REG);
838 else if (MEM_P (value)
839 && (MEM_P (XEXP (value, 0))
840 || (REG_P (XEXP (value, 0))
841 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
842 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
843 /* If the value is indirect by memory or by a register
844 that isn't the frame pointer
845 then it means the object is variable-sized and address through
846 that register or stack slot. COFF has no way to represent this
847 so all we can do is output the variable as a pointer. */
849 PUT_SDB_DEF (name);
850 if (REG_P (XEXP (value, 0)))
852 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
853 PUT_SDB_SCL (C_REG);
855 else
857 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
858 (CONST_INT...)))).
859 We want the value of that CONST_INT. */
860 /* Encore compiler hates a newline in a macro arg, it seems. */
861 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
862 (XEXP (XEXP (value, 0), 0)));
863 PUT_SDB_SCL (C_AUTO);
866 /* Effectively do build_pointer_type, but don't cache this type,
867 since it might be temporary whereas the type it points to
868 might have been saved for inlining. */
869 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
870 type = make_node (POINTER_TYPE);
871 TREE_TYPE (type) = TREE_TYPE (decl);
873 else if (MEM_P (value)
874 && ((GET_CODE (XEXP (value, 0)) == PLUS
875 && REG_P (XEXP (XEXP (value, 0), 0))
876 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
877 /* This is for variables which are at offset zero from
878 the frame pointer. This happens on the Alpha.
879 Non-frame pointer registers are excluded above. */
880 || (REG_P (XEXP (value, 0)))))
882 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
883 or (MEM (REG...)). We want the value of that CONST_INT
884 or zero. */
885 PUT_SDB_DEF (name);
886 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
887 PUT_SDB_SCL (C_AUTO);
889 else
891 /* It is something we don't know how to represent for SDB. */
892 return;
894 break;
896 default:
897 break;
899 PUT_SDB_TYPE (plain_type (type));
900 PUT_SDB_ENDEF;
903 /* Output SDB information for a top-level initialized variable
904 that has been delayed. */
906 static void
907 sdbout_toplevel_data (tree decl)
909 tree type = TREE_TYPE (decl);
911 if (DECL_IGNORED_P (decl))
912 return;
914 gcc_assert (VAR_P (decl));
915 gcc_assert (MEM_P (DECL_RTL (decl)));
916 gcc_assert (DECL_INITIAL (decl));
918 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
919 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
920 if (TREE_PUBLIC (decl))
922 PUT_SDB_SCL (C_EXT);
924 else
926 PUT_SDB_SCL (C_STAT);
928 PUT_SDB_TYPE (plain_type (type));
929 PUT_SDB_ENDEF;
932 #ifdef SDB_ALLOW_FORWARD_REFERENCES
934 /* Machinery to record and output anonymous types. */
936 static void
937 sdbout_queue_anonymous_type (tree type)
939 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
942 static void
943 sdbout_dequeue_anonymous_types (void)
945 tree types, link;
947 while (anonymous_types)
949 types = nreverse (anonymous_types);
950 anonymous_types = NULL_TREE;
952 for (link = types; link; link = TREE_CHAIN (link))
954 tree type = TREE_VALUE (link);
956 if (type && ! TREE_ASM_WRITTEN (type))
957 sdbout_one_type (type);
962 #endif
964 /* Given a chain of ..._TYPE nodes, all of which have names,
965 output definitions of those names, as typedefs. */
967 void
968 sdbout_types (tree types)
970 tree link;
972 for (link = types; link; link = TREE_CHAIN (link))
973 sdbout_one_type (link);
975 #ifdef SDB_ALLOW_FORWARD_REFERENCES
976 sdbout_dequeue_anonymous_types ();
977 #endif
980 static void
981 sdbout_type (tree type)
983 if (type == error_mark_node)
984 type = integer_type_node;
985 PUT_SDB_TYPE (plain_type (type));
988 /* Output types of the fields of type TYPE, if they are structs.
990 Formerly did not chase through pointer types, since that could be circular.
991 They must come before TYPE, since forward refs are not allowed.
992 Now james@bigtex.cactus.org says to try them. */
994 static void
995 sdbout_field_types (tree type)
997 tree tail;
999 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1000 /* This condition should match the one for emitting the actual
1001 members below. */
1002 if (TREE_CODE (tail) == FIELD_DECL
1003 && DECL_NAME (tail)
1004 && DECL_SIZE (tail)
1005 && tree_fits_uhwi_p (DECL_SIZE (tail))
1006 && tree_fits_shwi_p (bit_position (tail)))
1008 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1009 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1010 else
1011 sdbout_one_type (TREE_TYPE (tail));
1015 /* Use this to put out the top level defined record and union types
1016 for later reference. If this is a struct with a name, then put that
1017 name out. Other unnamed structs will have .xxfake labels generated so
1018 that they may be referred to later.
1019 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1020 It may NOT be called recursively. */
1022 static void
1023 sdbout_one_type (tree type)
1025 if (current_function_decl != NULL_TREE
1026 && DECL_SECTION_NAME (current_function_decl) != NULL)
1027 ; /* Don't change section amid function. */
1028 else
1029 switch_to_section (current_function_section ());
1031 switch (TREE_CODE (type))
1033 case RECORD_TYPE:
1034 case UNION_TYPE:
1035 case QUAL_UNION_TYPE:
1036 case ENUMERAL_TYPE:
1037 type = TYPE_MAIN_VARIANT (type);
1038 /* Don't output a type twice. */
1039 if (TREE_ASM_WRITTEN (type))
1040 /* James said test TREE_ASM_BEING_WRITTEN here. */
1041 return;
1043 /* Output nothing if type is not yet defined. */
1044 if (!COMPLETE_TYPE_P (type))
1045 return;
1047 TREE_ASM_WRITTEN (type) = 1;
1049 /* This is reputed to cause trouble with the following case,
1050 but perhaps checking TYPE_SIZE above will fix it. */
1052 /* Here is a testcase:
1054 struct foo {
1055 struct badstr *bbb;
1056 } forwardref;
1058 typedef struct intermediate {
1059 int aaaa;
1060 } intermediate_ref;
1062 typedef struct badstr {
1063 int ccccc;
1064 } badtype; */
1066 /* This change, which ought to make better output,
1067 used to make the COFF assembler unhappy.
1068 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1069 /* Before really doing anything, output types we want to refer to. */
1070 /* Note that in version 1 the following two lines
1071 are not used if forward references are in use. */
1072 if (TREE_CODE (type) != ENUMERAL_TYPE)
1073 sdbout_field_types (type);
1075 /* Output a structure type. */
1077 int size = int_size_in_bytes (type);
1078 int member_scl = 0;
1079 tree tem;
1081 /* Record the type tag, but not in its permanent place just yet. */
1082 sdbout_record_type_name (type);
1084 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1086 switch (TREE_CODE (type))
1088 case UNION_TYPE:
1089 case QUAL_UNION_TYPE:
1090 PUT_SDB_SCL (C_UNTAG);
1091 PUT_SDB_TYPE (T_UNION);
1092 member_scl = C_MOU;
1093 break;
1095 case RECORD_TYPE:
1096 PUT_SDB_SCL (C_STRTAG);
1097 PUT_SDB_TYPE (T_STRUCT);
1098 member_scl = C_MOS;
1099 break;
1101 case ENUMERAL_TYPE:
1102 PUT_SDB_SCL (C_ENTAG);
1103 PUT_SDB_TYPE (T_ENUM);
1104 member_scl = C_MOE;
1105 break;
1107 default:
1108 break;
1111 PUT_SDB_SIZE (size);
1112 PUT_SDB_ENDEF;
1114 /* Print out the base class information with fields
1115 named after the types they hold. */
1116 /* This is only relevant to aggregate types. TYPE_BINFO is used
1117 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1118 case. */
1119 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1121 int i;
1122 tree binfo, child;
1124 for (binfo = TYPE_BINFO (type), i = 0;
1125 BINFO_BASE_ITERATE (binfo, i, child); i++)
1127 tree child_type = BINFO_TYPE (child);
1128 tree child_type_name;
1130 if (TYPE_NAME (child_type) == 0)
1131 continue;
1132 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1133 child_type_name = TYPE_NAME (child_type);
1134 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1136 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1137 if (child_type_name && template_name_p (child_type_name))
1138 child_type_name
1139 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1141 else
1142 continue;
1144 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1145 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1146 PUT_SDB_SCL (member_scl);
1147 sdbout_type (BINFO_TYPE (child));
1148 PUT_SDB_ENDEF;
1152 /* Output the individual fields. */
1154 if (TREE_CODE (type) == ENUMERAL_TYPE)
1156 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1158 tree value = TREE_VALUE (tem);
1160 if (TREE_CODE (value) == CONST_DECL)
1161 value = DECL_INITIAL (value);
1163 if (tree_fits_shwi_p (value))
1165 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1166 PUT_SDB_INT_VAL (tree_to_shwi (value));
1167 PUT_SDB_SCL (C_MOE);
1168 PUT_SDB_TYPE (T_MOE);
1169 PUT_SDB_ENDEF;
1173 else /* record or union type */
1174 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1175 /* Output the name, type, position (in bits), size (in bits)
1176 of each field. */
1178 /* Omit here the nameless fields that are used to skip bits.
1179 Also omit fields with variable size or position.
1180 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1181 if (TREE_CODE (tem) == FIELD_DECL
1182 && DECL_NAME (tem)
1183 && DECL_SIZE (tem)
1184 && tree_fits_uhwi_p (DECL_SIZE (tem))
1185 && tree_fits_shwi_p (bit_position (tem)))
1187 const char *name;
1189 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1190 PUT_SDB_DEF (name);
1191 if (DECL_BIT_FIELD_TYPE (tem))
1193 PUT_SDB_INT_VAL (int_bit_position (tem));
1194 PUT_SDB_SCL (C_FIELD);
1195 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1196 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1198 else
1200 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1201 PUT_SDB_SCL (member_scl);
1202 sdbout_type (TREE_TYPE (tem));
1204 PUT_SDB_ENDEF;
1206 /* Output end of a structure,union, or enumeral definition. */
1208 PUT_SDB_PLAIN_DEF ("eos");
1209 PUT_SDB_INT_VAL (size);
1210 PUT_SDB_SCL (C_EOS);
1211 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1212 PUT_SDB_SIZE (size);
1213 PUT_SDB_ENDEF;
1214 break;
1217 default:
1218 break;
1222 /* The following two functions output definitions of function parameters.
1223 Each parameter gets a definition locating it in the parameter list.
1224 Each parameter that is a register variable gets a second definition
1225 locating it in the register.
1227 Printing or argument lists in gdb uses the definitions that
1228 locate in the parameter list. But reference to the variable in
1229 expressions uses preferentially the definition as a register. */
1231 /* Output definitions, referring to storage in the parmlist,
1232 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1234 static void
1235 sdbout_parms (tree parms)
1237 for (; parms; parms = TREE_CHAIN (parms))
1238 if (DECL_NAME (parms)
1239 && TREE_TYPE (parms) != error_mark_node
1240 && DECL_RTL_SET_P (parms)
1241 && DECL_INCOMING_RTL (parms))
1243 int current_sym_value = 0;
1244 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1246 if (name == 0 || *name == 0)
1247 name = gen_fake_label ();
1249 /* Perform any necessary register eliminations on the parameter's rtl,
1250 so that the debugging output will be accurate. */
1251 DECL_INCOMING_RTL (parms)
1252 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1253 SET_DECL_RTL (parms,
1254 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1256 if (PARM_PASSED_IN_MEMORY (parms))
1258 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1259 tree type;
1261 /* ??? Here we assume that the parm address is indexed
1262 off the frame pointer or arg pointer.
1263 If that is not true, we produce meaningless results,
1264 but do not crash. */
1265 if (GET_CODE (addr) == PLUS
1266 && CONST_INT_P (XEXP (addr, 1)))
1267 current_sym_value = INTVAL (XEXP (addr, 1));
1268 else
1269 current_sym_value = 0;
1271 if (REG_P (DECL_RTL (parms))
1272 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1273 type = DECL_ARG_TYPE (parms);
1274 else
1276 int original_sym_value = current_sym_value;
1278 /* This is the case where the parm is passed as an int or
1279 double and it is converted to a char, short or float
1280 and stored back in the parmlist. In this case, describe
1281 the parm with the variable's declared type, and adjust
1282 the address if the least significant bytes (which we are
1283 using) are not the first ones. */
1284 scalar_mode from_mode, to_mode;
1285 if (BYTES_BIG_ENDIAN
1286 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms)
1287 && is_a <scalar_mode> (TYPE_MODE (DECL_ARG_TYPE (parms)),
1288 &from_mode)
1289 && is_a <scalar_mode> (GET_MODE (DECL_RTL (parms)),
1290 &to_mode))
1291 current_sym_value += (GET_MODE_SIZE (from_mode)
1292 - GET_MODE_SIZE (to_mode));
1294 if (MEM_P (DECL_RTL (parms))
1295 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1296 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1297 == CONST_INT)
1298 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1299 == current_sym_value))
1300 type = TREE_TYPE (parms);
1301 else
1303 current_sym_value = original_sym_value;
1304 type = DECL_ARG_TYPE (parms);
1308 PUT_SDB_DEF (name);
1309 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1310 PUT_SDB_SCL (C_ARG);
1311 PUT_SDB_TYPE (plain_type (type));
1312 PUT_SDB_ENDEF;
1314 else if (REG_P (DECL_RTL (parms)))
1316 rtx best_rtl;
1317 /* Parm passed in registers and lives in registers or nowhere. */
1319 /* If parm lives in a register, use that register;
1320 pretend the parm was passed there. It would be more consistent
1321 to describe the register where the parm was passed,
1322 but in practice that register usually holds something else. */
1323 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1324 best_rtl = DECL_RTL (parms);
1325 /* If the parm lives nowhere,
1326 use the register where it was passed. */
1327 else
1328 best_rtl = DECL_INCOMING_RTL (parms);
1330 PUT_SDB_DEF (name);
1331 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1332 PUT_SDB_SCL (C_REGPARM);
1333 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1334 PUT_SDB_ENDEF;
1336 else if (MEM_P (DECL_RTL (parms))
1337 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1339 /* Parm was passed in registers but lives on the stack. */
1341 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1342 in which case we want the value of that CONST_INT,
1343 or (MEM (REG ...)) or (MEM (MEM ...)),
1344 in which case we use a value of zero. */
1345 if (REG_P (XEXP (DECL_RTL (parms), 0))
1346 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1347 current_sym_value = 0;
1348 else
1349 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1351 /* Again, this assumes the offset is based on the arg pointer. */
1352 PUT_SDB_DEF (name);
1353 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1354 XEXP (DECL_RTL (parms), 0)));
1355 PUT_SDB_SCL (C_ARG);
1356 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1357 PUT_SDB_ENDEF;
1362 /* Output definitions for the places where parms live during the function,
1363 when different from where they were passed, when the parms were passed
1364 in memory.
1366 It is not useful to do this for parms passed in registers
1367 that live during the function in different registers, because it is
1368 impossible to look in the passed register for the passed value,
1369 so we use the within-the-function register to begin with.
1371 PARMS is a chain of PARM_DECL nodes. */
1373 static void
1374 sdbout_reg_parms (tree parms)
1376 for (; parms; parms = TREE_CHAIN (parms))
1377 if (DECL_NAME (parms)
1378 && TREE_TYPE (parms) != error_mark_node
1379 && DECL_RTL_SET_P (parms)
1380 && DECL_INCOMING_RTL (parms))
1382 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1384 /* Report parms that live in registers during the function
1385 but were passed in memory. */
1386 if (REG_P (DECL_RTL (parms))
1387 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1388 && PARM_PASSED_IN_MEMORY (parms))
1390 if (name == 0 || *name == 0)
1391 name = gen_fake_label ();
1392 PUT_SDB_DEF (name);
1393 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1394 PUT_SDB_SCL (C_REG);
1395 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1396 PUT_SDB_ENDEF;
1398 /* Report parms that live in memory but not where they were passed. */
1399 else if (MEM_P (DECL_RTL (parms))
1400 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1401 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1402 && PARM_PASSED_IN_MEMORY (parms)
1403 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1405 #if 0 /* ??? It is not clear yet what should replace this. */
1406 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1407 /* A parm declared char is really passed as an int,
1408 so it occupies the least significant bytes.
1409 On a big-endian machine those are not the low-numbered ones. */
1410 if (BYTES_BIG_ENDIAN
1411 && offset != -1
1412 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1413 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1414 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1415 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1416 #endif
1418 if (name == 0 || *name == 0)
1419 name = gen_fake_label ();
1420 PUT_SDB_DEF (name);
1421 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1422 (XEXP (DECL_RTL (parms), 0)));
1423 PUT_SDB_SCL (C_AUTO);
1424 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1425 PUT_SDB_ENDEF;
1431 /* Output early debug information for a global DECL. Called from
1432 rest_of_decl_compilation during parsing. */
1434 static void
1435 sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1437 /* NYI for non-dwarf. */
1440 /* Output late debug information for a global DECL after location
1441 information is available. */
1443 static void
1444 sdbout_late_global_decl (tree decl)
1446 if (VAR_P (decl) && !DECL_EXTERNAL (decl) && DECL_RTL_SET_P (decl))
1448 /* The COFF linker can move initialized global vars to the end.
1449 And that can screw up the symbol ordering. Defer those for
1450 sdbout_finish (). */
1451 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1452 sdbout_symbol (decl, 0);
1453 else
1454 vec_safe_push (deferred_global_decls, decl);
1456 /* Output COFF information for non-global file-scope initialized
1457 variables. */
1458 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1459 sdbout_toplevel_data (decl);
1463 /* Output initialized global vars at the end, in the order of
1464 definition. See comment in sdbout_global_decl. */
1466 static void
1467 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1469 size_t i;
1470 tree decl;
1472 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1473 sdbout_symbol (decl, 0);
1476 /* Describe the beginning of an internal block within a function.
1477 Also output descriptions of variables defined in this block.
1479 N is the number of the block, by order of beginning, counting from 1,
1480 and not counting the outermost (function top-level) block.
1481 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1482 if the count starts at 0 for the outermost one. */
1484 static void
1485 sdbout_begin_block (unsigned int line, unsigned int n)
1487 tree decl = current_function_decl;
1488 MAKE_LINE_SAFE (line);
1490 /* The SCO compiler does not emit a separate block for the function level
1491 scope, so we avoid it here also. */
1492 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1494 if (n == 1)
1496 /* Include the outermost BLOCK's variables in block 1. */
1497 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1498 sdbout_block (DECL_INITIAL (decl));
1500 /* If -g1, suppress all the internal symbols of functions
1501 except for arguments. */
1502 if (debug_info_level != DINFO_LEVEL_TERSE)
1504 do_block = n;
1505 sdbout_block (DECL_INITIAL (decl));
1508 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1509 sdbout_dequeue_anonymous_types ();
1510 #endif
1513 /* Describe the end line-number of an internal block within a function. */
1515 static void
1516 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1518 MAKE_LINE_SAFE (line);
1520 /* The SCO compiler does not emit a separate block for the function level
1521 scope, so we avoid it here also. */
1522 if (n != 1)
1523 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1526 /* Output a line number symbol entry for source file FILENAME and line
1527 number LINE. */
1529 static void
1530 sdbout_source_line (unsigned int line, unsigned int column ATTRIBUTE_UNUSED,
1531 const char *filename ATTRIBUTE_UNUSED,
1532 int discriminator ATTRIBUTE_UNUSED,
1533 bool is_stmt ATTRIBUTE_UNUSED)
1535 /* COFF relative line numbers must be positive. */
1536 if ((int) line > sdb_begin_function_line)
1538 #ifdef SDB_OUTPUT_SOURCE_LINE
1539 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1540 #else
1541 fprintf (asm_out_file, "\t.ln\t%d\n",
1542 ((sdb_begin_function_line > -1)
1543 ? line - sdb_begin_function_line : 1));
1544 #endif
1548 /* Output sdb info for the current function name.
1549 Called from assemble_start_function. */
1551 static void
1552 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1554 sdbout_symbol (current_function_decl, 0);
1557 /* Called at beginning of function body after prologue. Record the
1558 function's starting line number, so we can output relative line numbers
1559 for the other lines. Describe beginning of outermost block. Also
1560 describe the parameter list. */
1562 static void
1563 sdbout_begin_prologue (unsigned int line, unsigned int column ATTRIBUTE_UNUSED,
1564 const char *file ATTRIBUTE_UNUSED)
1566 sdbout_end_prologue (line, file);
1569 static void
1570 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1572 sdb_begin_function_line = line - 1;
1573 PUT_SDB_FUNCTION_START (line);
1574 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1575 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1578 /* Called at end of function (before epilogue).
1579 Describe end of outermost block. */
1581 static void
1582 sdbout_end_function (unsigned int line)
1584 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1585 sdbout_dequeue_anonymous_types ();
1586 #endif
1588 MAKE_LINE_SAFE (line);
1589 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1591 /* Indicate we are between functions, for line-number output. */
1592 sdb_begin_function_line = -1;
1595 /* Output sdb info for the absolute end of a function.
1596 Called after the epilogue is output. */
1598 static void
1599 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1600 const char *file ATTRIBUTE_UNUSED)
1602 const char *const name ATTRIBUTE_UNUSED
1603 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1605 #ifdef PUT_SDB_EPILOGUE_END
1606 PUT_SDB_EPILOGUE_END (name);
1607 #else
1608 fprintf (asm_out_file, "\t.def\t");
1609 assemble_name (asm_out_file, name);
1610 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1611 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1612 #endif
1615 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1616 is present. */
1618 static void
1619 sdbout_label (rtx_code_label *insn)
1621 PUT_SDB_DEF (LABEL_NAME (insn));
1622 PUT_SDB_VAL (insn);
1623 PUT_SDB_SCL (C_LABEL);
1624 PUT_SDB_TYPE (T_NULL);
1625 PUT_SDB_ENDEF;
1628 /* Change to reading from a new source file. */
1630 static void
1631 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1632 const char *filename ATTRIBUTE_UNUSED)
1636 /* Revert to reading a previous source file. */
1638 static void
1639 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1643 /* Set up for SDB output at the start of compilation. */
1645 static void
1646 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1648 tree t;
1650 vec_alloc (deferred_global_decls, 12);
1652 /* Emit debug information which was queued by sdbout_symbol before
1653 we got here. */
1654 sdbout_initialized = true;
1656 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1657 sdbout_symbol (TREE_VALUE (t), 0);
1658 preinit_symbols = 0;
1661 #include "gt-sdbout.h"