kernel - support dummy reallocblks in devfs
[dragonfly.git] / contrib / gcc-5.0 / gcc / sdbout.c
blobdd12c67e9c95c0cf35e10b4a17d66a3dca42e827
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2015 Free Software Foundation, Inc.
4 This file is part of GCC.
6 GCC is free software; you can redistribute it and/or modify it under
7 the terms of the GNU General Public License as published by the Free
8 Software Foundation; either version 3, or (at your option) any later
9 version.
11 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 for more details.
16 You should have received a copy of the GNU General Public License
17 along with GCC; see the file COPYING3. If not see
18 <http://www.gnu.org/licenses/>. */
20 /* mike@tredysvr.Tredydev.Unisys.COM says:
21 I modified the struct.c example and have a nm of a .o resulting from the
22 AT&T C compiler. From the example below I would conclude the following:
24 1. All .defs from structures are emitted as scanned. The example below
25 clearly shows the symbol table entries for BoxRec2 are after the first
26 function.
28 2. All functions and their locals (including statics) are emitted as scanned.
30 3. All nested unnamed union and structure .defs must be emitted before
31 the structure in which they are nested. The AT&T assembler is a
32 one pass beast as far as symbolics are concerned.
34 4. All structure .defs are emitted before the typedefs that refer to them.
36 5. All top level static and external variable definitions are moved to the
37 end of file with all top level statics occurring first before externs.
39 6. All undefined references are at the end of the file.
42 #include "config.h"
43 #include "system.h"
44 #include "coretypes.h"
45 #include "tm.h"
46 #include "debug.h"
47 #include "hash-set.h"
48 #include "machmode.h"
49 #include "vec.h"
50 #include "double-int.h"
51 #include "input.h"
52 #include "alias.h"
53 #include "symtab.h"
54 #include "wide-int.h"
55 #include "inchash.h"
56 #include "tree.h"
57 #include "varasm.h"
58 #include "stor-layout.h"
59 #include "ggc.h"
60 #include "vec.h"
62 static GTY(()) tree anonymous_types;
64 /* Counter to generate unique "names" for nameless struct members. */
66 static GTY(()) int unnamed_struct_number;
68 /* Declarations whose debug info was deferred till end of compilation. */
70 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
72 /* The C front end may call sdbout_symbol before sdbout_init runs.
73 We save all such decls in this list and output them when we get
74 to sdbout_init. */
76 static GTY(()) tree preinit_symbols;
77 static GTY(()) bool sdbout_initialized;
79 #ifdef SDB_DEBUGGING_INFO
81 #include "rtl.h"
82 #include "regs.h"
83 #include "flags.h"
84 #include "insn-config.h"
85 #include "reload.h"
86 #include "output.h"
87 #include "diagnostic-core.h"
88 #include "tm_p.h"
89 #include "gsyms.h"
90 #include "langhooks.h"
91 #include "target.h"
93 /* 1 if PARM is passed to this function in memory. */
95 #define PARM_PASSED_IN_MEMORY(PARM) \
96 (MEM_P (DECL_INCOMING_RTL (PARM)))
98 /* A C expression for the integer offset value of an automatic variable
99 (C_AUTO) having address X (an RTX). */
100 #ifndef DEBUGGER_AUTO_OFFSET
101 #define DEBUGGER_AUTO_OFFSET(X) \
102 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
103 #endif
105 /* A C expression for the integer offset value of an argument (C_ARG)
106 having address X (an RTX). The nominal offset is OFFSET. */
107 #ifndef DEBUGGER_ARG_OFFSET
108 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
109 #endif
111 /* Line number of beginning of current function, minus one.
112 Negative means not in a function or not using sdb. */
114 int sdb_begin_function_line = -1;
117 extern FILE *asm_out_file;
119 extern tree current_function_decl;
121 #include "sdbout.h"
123 static void sdbout_init (const char *);
124 static void sdbout_finish (const char *);
125 static void sdbout_start_source_file (unsigned int, const char *);
126 static void sdbout_end_source_file (unsigned int);
127 static void sdbout_begin_block (unsigned int, unsigned int);
128 static void sdbout_end_block (unsigned int, unsigned int);
129 static void sdbout_source_line (unsigned int, const char *, int, bool);
130 static void sdbout_end_epilogue (unsigned int, const char *);
131 static void sdbout_global_decl (tree);
132 static void sdbout_begin_prologue (unsigned int, const char *);
133 static void sdbout_end_prologue (unsigned int, const char *);
134 static void sdbout_begin_function (tree);
135 static void sdbout_end_function (unsigned int);
136 static void sdbout_toplevel_data (tree);
137 static void sdbout_label (rtx_code_label *);
138 static char *gen_fake_label (void);
139 static int plain_type (tree);
140 static int template_name_p (tree);
141 static void sdbout_record_type_name (tree);
142 static int plain_type_1 (tree, int);
143 static void sdbout_block (tree);
144 static void sdbout_syms (tree);
145 #ifdef SDB_ALLOW_FORWARD_REFERENCES
146 static void sdbout_queue_anonymous_type (tree);
147 static void sdbout_dequeue_anonymous_types (void);
148 #endif
149 static void sdbout_type (tree);
150 static void sdbout_field_types (tree);
151 static void sdbout_one_type (tree);
152 static void sdbout_parms (tree);
153 static void sdbout_reg_parms (tree);
154 static void sdbout_global_decl (tree);
156 /* Random macros describing parts of SDB data. */
158 /* Default value of delimiter is ";". */
159 #ifndef SDB_DELIM
160 #define SDB_DELIM ";"
161 #endif
163 /* Maximum number of dimensions the assembler will allow. */
164 #ifndef SDB_MAX_DIM
165 #define SDB_MAX_DIM 4
166 #endif
168 #ifndef PUT_SDB_SCL
169 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
170 #endif
172 #ifndef PUT_SDB_INT_VAL
173 #define PUT_SDB_INT_VAL(a) \
174 do { \
175 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
176 (HOST_WIDE_INT) (a), SDB_DELIM); \
177 } while (0)
179 #endif
181 #ifndef PUT_SDB_VAL
182 #define PUT_SDB_VAL(a) \
183 ( fputs ("\t.val\t", asm_out_file), \
184 output_addr_const (asm_out_file, (a)), \
185 fprintf (asm_out_file, SDB_DELIM))
186 #endif
188 #ifndef PUT_SDB_DEF
189 #define PUT_SDB_DEF(a) \
190 do { fprintf (asm_out_file, "\t.def\t"); \
191 assemble_name (asm_out_file, a); \
192 fprintf (asm_out_file, SDB_DELIM); } while (0)
193 #endif
195 #ifndef PUT_SDB_PLAIN_DEF
196 #define PUT_SDB_PLAIN_DEF(a) \
197 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
198 #endif
200 #ifndef PUT_SDB_ENDEF
201 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
202 #endif
204 #ifndef PUT_SDB_TYPE
205 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
206 #endif
208 #ifndef PUT_SDB_SIZE
209 #define PUT_SDB_SIZE(a) \
210 do { \
211 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
212 (HOST_WIDE_INT) (a), SDB_DELIM); \
213 } while (0)
214 #endif
216 #ifndef PUT_SDB_START_DIM
217 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
218 #endif
220 #ifndef PUT_SDB_NEXT_DIM
221 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
222 #endif
224 #ifndef PUT_SDB_LAST_DIM
225 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
226 #endif
228 #ifndef PUT_SDB_TAG
229 #define PUT_SDB_TAG(a) \
230 do { fprintf (asm_out_file, "\t.tag\t"); \
231 assemble_name (asm_out_file, a); \
232 fprintf (asm_out_file, SDB_DELIM); } while (0)
233 #endif
235 #ifndef PUT_SDB_BLOCK_START
236 #define PUT_SDB_BLOCK_START(LINE) \
237 fprintf (asm_out_file, \
238 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
239 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
240 #endif
242 #ifndef PUT_SDB_BLOCK_END
243 #define PUT_SDB_BLOCK_END(LINE) \
244 fprintf (asm_out_file, \
245 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
246 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
247 #endif
249 #ifndef PUT_SDB_FUNCTION_START
250 #define PUT_SDB_FUNCTION_START(LINE) \
251 fprintf (asm_out_file, \
252 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
253 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
254 #endif
256 #ifndef PUT_SDB_FUNCTION_END
257 #define PUT_SDB_FUNCTION_END(LINE) \
258 fprintf (asm_out_file, \
259 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
260 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
261 #endif
263 /* Return the sdb tag identifier string for TYPE
264 if TYPE has already been defined; otherwise return a null pointer. */
266 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
268 /* Set the sdb tag identifier string for TYPE to NAME. */
270 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
271 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
273 /* Return the name (a string) of the struct, union or enum tag
274 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
276 #define TAG_NAME(link) \
277 (((link) && TREE_PURPOSE ((link)) \
278 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
279 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
281 /* Ensure we don't output a negative line number. */
282 #define MAKE_LINE_SAFE(line) \
283 if ((int) line <= sdb_begin_function_line) \
284 line = sdb_begin_function_line + 1
286 /* The debug hooks structure. */
287 const struct gcc_debug_hooks sdb_debug_hooks =
289 sdbout_init, /* init */
290 sdbout_finish, /* finish */
291 debug_nothing_void, /* assembly_start */
292 debug_nothing_int_charstar, /* define */
293 debug_nothing_int_charstar, /* undef */
294 sdbout_start_source_file, /* start_source_file */
295 sdbout_end_source_file, /* end_source_file */
296 sdbout_begin_block, /* begin_block */
297 sdbout_end_block, /* end_block */
298 debug_true_const_tree, /* ignore_block */
299 sdbout_source_line, /* source_line */
300 sdbout_begin_prologue, /* begin_prologue */
301 debug_nothing_int_charstar, /* end_prologue */
302 debug_nothing_int_charstar, /* begin_epilogue */
303 sdbout_end_epilogue, /* end_epilogue */
304 sdbout_begin_function, /* begin_function */
305 sdbout_end_function, /* end_function */
306 debug_nothing_tree, /* register_main_translation_unit */
307 debug_nothing_tree, /* function_decl */
308 sdbout_global_decl, /* global_decl */
309 sdbout_symbol, /* type_decl */
310 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
311 debug_nothing_tree, /* deferred_inline_function */
312 debug_nothing_tree, /* outlining_inline_function */
313 sdbout_label, /* label */
314 debug_nothing_int, /* handle_pch */
315 debug_nothing_rtx_insn, /* var_location */
316 debug_nothing_void, /* switch_text_section */
317 debug_nothing_tree_tree, /* set_name */
318 0, /* start_end_main_source_file */
319 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
322 /* Return a unique string to name an anonymous type. */
324 static char *
325 gen_fake_label (void)
327 char label[10];
328 char *labelstr;
329 sprintf (label, ".%dfake", unnamed_struct_number);
330 unnamed_struct_number++;
331 labelstr = xstrdup (label);
332 return labelstr;
335 /* Return the number which describes TYPE for SDB.
336 For pointers, etc., this function is recursive.
337 Each record, union or enumeral type must already have had a
338 tag number output. */
340 /* The number is given by d6d5d4d3d2d1bbbb
341 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
342 Thus, char *foo () has bbbb=T_CHAR
343 d1=D_FCN
344 d2=D_PTR
345 N_BTMASK= 017 1111 basic type field.
346 N_TSHIFT= 2 derived type shift
347 N_BTSHFT= 4 Basic type shift */
349 /* Produce the number that describes a pointer, function or array type.
350 PREV is the number describing the target, value or element type.
351 DT_type describes how to transform that type. */
352 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
353 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
354 | ((int) DT_type << (int) N_BTSHFT) \
355 | ((PREV) & (int) N_BTMASK))
357 /* Number of elements used in sdb_dims. */
358 static int sdb_n_dims = 0;
360 /* Table of array dimensions of current type. */
361 static int sdb_dims[SDB_MAX_DIM];
363 /* Size of outermost array currently being processed. */
364 static int sdb_type_size = -1;
366 static int
367 plain_type (tree type)
369 int val = plain_type_1 (type, 0);
371 /* If we have already saved up some array dimensions, print them now. */
372 if (sdb_n_dims > 0)
374 int i;
375 PUT_SDB_START_DIM;
376 for (i = sdb_n_dims - 1; i > 0; i--)
377 PUT_SDB_NEXT_DIM (sdb_dims[i]);
378 PUT_SDB_LAST_DIM (sdb_dims[0]);
379 sdb_n_dims = 0;
381 sdb_type_size = int_size_in_bytes (type);
382 /* Don't kill sdb if type is not laid out or has variable size. */
383 if (sdb_type_size < 0)
384 sdb_type_size = 0;
386 /* If we have computed the size of an array containing this type,
387 print it now. */
388 if (sdb_type_size >= 0)
390 PUT_SDB_SIZE (sdb_type_size);
391 sdb_type_size = -1;
393 return val;
396 static int
397 template_name_p (tree name)
399 const char *ptr = IDENTIFIER_POINTER (name);
400 while (*ptr && *ptr != '<')
401 ptr++;
403 return *ptr != '\0';
406 static void
407 sdbout_record_type_name (tree type)
409 const char *name = 0;
410 int no_name;
412 if (KNOWN_TYPE_TAG (type))
413 return;
415 if (TYPE_NAME (type) != 0)
417 tree t = 0;
419 /* Find the IDENTIFIER_NODE for the type name. */
420 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
421 t = TYPE_NAME (type);
422 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
424 t = DECL_NAME (TYPE_NAME (type));
425 /* The DECL_NAME for templates includes "<>", which breaks
426 most assemblers. Use its assembler name instead, which
427 has been mangled into being safe. */
428 if (t && template_name_p (t))
429 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
432 /* Now get the name as a string, or invent one. */
433 if (t != NULL_TREE)
434 name = IDENTIFIER_POINTER (t);
437 no_name = (name == 0 || *name == 0);
438 if (no_name)
439 name = gen_fake_label ();
441 SET_KNOWN_TYPE_TAG (type, name);
442 #ifdef SDB_ALLOW_FORWARD_REFERENCES
443 if (no_name)
444 sdbout_queue_anonymous_type (type);
445 #endif
448 /* Return the .type value for type TYPE.
450 LEVEL indicates how many levels deep we have recursed into the type.
451 The SDB debug format can only represent 6 derived levels of types.
452 After that, we must output inaccurate debug info. We deliberately
453 stop before the 7th level, so that ADA recursive types will not give an
454 infinite loop. */
456 static int
457 plain_type_1 (tree type, int level)
459 if (type == 0)
460 type = void_type_node;
461 else if (type == error_mark_node)
462 type = integer_type_node;
463 else
464 type = TYPE_MAIN_VARIANT (type);
466 switch (TREE_CODE (type))
468 case VOID_TYPE:
469 case NULLPTR_TYPE:
470 return T_VOID;
471 case BOOLEAN_TYPE:
472 case INTEGER_TYPE:
474 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
476 /* Carefully distinguish all the standard types of C,
477 without messing up if the language is not C.
478 Note that we check only for the names that contain spaces;
479 other names might occur by coincidence in other languages. */
480 if (TYPE_NAME (type) != 0
481 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
482 && DECL_NAME (TYPE_NAME (type)) != 0
483 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
485 const char *const name
486 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
488 if (!strcmp (name, "char"))
489 return T_CHAR;
490 if (!strcmp (name, "unsigned char"))
491 return T_UCHAR;
492 if (!strcmp (name, "signed char"))
493 return T_CHAR;
494 if (!strcmp (name, "int"))
495 return T_INT;
496 if (!strcmp (name, "unsigned int"))
497 return T_UINT;
498 if (!strcmp (name, "short int"))
499 return T_SHORT;
500 if (!strcmp (name, "short unsigned int"))
501 return T_USHORT;
502 if (!strcmp (name, "long int"))
503 return T_LONG;
504 if (!strcmp (name, "long unsigned int"))
505 return T_ULONG;
508 if (size == INT_TYPE_SIZE)
509 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
510 if (size == CHAR_TYPE_SIZE)
511 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
512 if (size == SHORT_TYPE_SIZE)
513 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
514 if (size == LONG_TYPE_SIZE)
515 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
516 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
517 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
518 return 0;
521 case REAL_TYPE:
523 int precision = TYPE_PRECISION (type);
524 if (precision == FLOAT_TYPE_SIZE)
525 return T_FLOAT;
526 if (precision == DOUBLE_TYPE_SIZE)
527 return T_DOUBLE;
528 #ifdef EXTENDED_SDB_BASIC_TYPES
529 if (precision == LONG_DOUBLE_TYPE_SIZE)
530 return T_LNGDBL;
531 #else
532 if (precision == LONG_DOUBLE_TYPE_SIZE)
533 return T_DOUBLE; /* better than nothing */
534 #endif
535 return 0;
538 case ARRAY_TYPE:
540 int m;
541 if (level >= 6)
542 return T_VOID;
543 else
544 m = plain_type_1 (TREE_TYPE (type), level+1);
545 if (sdb_n_dims < SDB_MAX_DIM)
546 sdb_dims[sdb_n_dims++]
547 = (TYPE_DOMAIN (type)
548 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
549 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
550 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
551 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
552 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
553 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
554 : 0);
556 return PUSH_DERIVED_LEVEL (DT_ARY, m);
559 case RECORD_TYPE:
560 case UNION_TYPE:
561 case QUAL_UNION_TYPE:
562 case ENUMERAL_TYPE:
564 const char *tag;
565 #ifdef SDB_ALLOW_FORWARD_REFERENCES
566 sdbout_record_type_name (type);
567 #endif
568 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
569 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
570 #ifdef SDB_ALLOW_FORWARD_REFERENCES
571 || TYPE_MODE (type) != VOIDmode
572 #endif
574 #endif
576 /* Output the referenced structure tag name
577 only if the .def has already been finished.
578 At least on 386, the Unix assembler
579 cannot handle forward references to tags. */
580 /* But the 88100, it requires them, sigh... */
581 /* And the MIPS requires unknown refs as well... */
582 tag = KNOWN_TYPE_TAG (type);
583 PUT_SDB_TAG (tag);
584 /* These 3 lines used to follow the close brace.
585 However, a size of 0 without a tag implies a tag of 0,
586 so if we don't know a tag, we can't mention the size. */
587 sdb_type_size = int_size_in_bytes (type);
588 if (sdb_type_size < 0)
589 sdb_type_size = 0;
591 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
592 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
593 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
594 : T_ENUM);
596 case POINTER_TYPE:
597 case REFERENCE_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_PTR, m);
606 case FUNCTION_TYPE:
607 case METHOD_TYPE:
609 int m;
610 if (level >= 6)
611 return T_VOID;
612 else
613 m = plain_type_1 (TREE_TYPE (type), level+1);
614 return PUSH_DERIVED_LEVEL (DT_FCN, m);
616 default:
617 return 0;
621 /* Output the symbols defined in block number DO_BLOCK.
623 This function works by walking the tree structure of blocks,
624 counting blocks until it finds the desired block. */
626 static int do_block = 0;
628 static void
629 sdbout_block (tree block)
631 while (block)
633 /* Ignore blocks never expanded or otherwise marked as real. */
634 if (TREE_USED (block))
636 /* When we reach the specified block, output its symbols. */
637 if (BLOCK_NUMBER (block) == do_block)
638 sdbout_syms (BLOCK_VARS (block));
640 /* If we are past the specified block, stop the scan. */
641 if (BLOCK_NUMBER (block) > do_block)
642 return;
644 /* Scan the blocks within this block. */
645 sdbout_block (BLOCK_SUBBLOCKS (block));
648 block = BLOCK_CHAIN (block);
652 /* Call sdbout_symbol on each decl in the chain SYMS. */
654 static void
655 sdbout_syms (tree syms)
657 while (syms)
659 if (TREE_CODE (syms) != LABEL_DECL)
660 sdbout_symbol (syms, 1);
661 syms = TREE_CHAIN (syms);
665 /* Output SDB information for a symbol described by DECL.
666 LOCAL is nonzero if the symbol is not file-scope. */
668 void
669 sdbout_symbol (tree decl, int local)
671 tree type = TREE_TYPE (decl);
672 tree context = NULL_TREE;
673 rtx value;
674 int regno = -1;
675 const char *name;
677 /* If we are called before sdbout_init is run, just save the symbol
678 for later. */
679 if (!sdbout_initialized)
681 preinit_symbols = tree_cons (0, decl, preinit_symbols);
682 return;
685 sdbout_one_type (type);
687 switch (TREE_CODE (decl))
689 case CONST_DECL:
690 /* Enum values are defined by defining the enum type. */
691 return;
693 case FUNCTION_DECL:
694 /* Don't mention a nested function under its parent. */
695 context = decl_function_context (decl);
696 if (context == current_function_decl)
697 return;
698 /* Check DECL_INITIAL to distinguish declarations from definitions.
699 Don't output debug info here for declarations; they will have
700 a DECL_INITIAL value of 0. */
701 if (! DECL_INITIAL (decl))
702 return;
703 if (!MEM_P (DECL_RTL (decl))
704 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
705 return;
706 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
707 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
708 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
709 break;
711 case TYPE_DECL:
712 /* Done with tagged types. */
713 if (DECL_NAME (decl) == 0)
714 return;
715 if (DECL_IGNORED_P (decl))
716 return;
717 /* Don't output intrinsic types. GAS chokes on SDB .def
718 statements that contain identifiers with embedded spaces
719 (eg "unsigned long"). */
720 if (DECL_IS_BUILTIN (decl))
721 return;
723 /* Output typedef name. */
724 if (template_name_p (DECL_NAME (decl)))
725 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
726 else
727 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
728 PUT_SDB_SCL (C_TPDEF);
729 break;
731 case PARM_DECL:
732 /* Parm decls go in their own separate chains
733 and are output by sdbout_reg_parms and sdbout_parms. */
734 gcc_unreachable ();
736 case VAR_DECL:
737 /* Don't mention a variable that is external.
738 Let the file that defines it describe it. */
739 if (DECL_EXTERNAL (decl))
740 return;
742 /* Ignore __FUNCTION__, etc. */
743 if (DECL_IGNORED_P (decl))
744 return;
746 /* If there was an error in the declaration, don't dump core
747 if there is no RTL associated with the variable doesn't
748 exist. */
749 if (!DECL_RTL_SET_P (decl))
750 return;
752 value = DECL_RTL (decl);
754 if (!is_global_var (decl))
755 value = eliminate_regs (value, VOIDmode, NULL_RTX);
757 SET_DECL_RTL (decl, value);
758 #ifdef LEAF_REG_REMAP
759 if (crtl->uses_only_leaf_regs)
760 leaf_renumber_regs_insn (value);
761 #endif
763 /* Don't mention a variable at all
764 if it was completely optimized into nothingness.
766 If DECL was from an inline function, then its rtl
767 is not identically the rtl that was used in this
768 particular compilation. */
769 if (REG_P (value))
771 regno = REGNO (value);
772 if (regno >= FIRST_PSEUDO_REGISTER)
773 return;
775 else if (GET_CODE (value) == SUBREG)
777 while (GET_CODE (value) == SUBREG)
778 value = SUBREG_REG (value);
779 if (REG_P (value))
781 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
782 return;
784 regno = REGNO (alter_subreg (&value, true));
785 SET_DECL_RTL (decl, value);
787 /* Don't output anything if an auto variable
788 gets RTL that is static.
789 GAS version 2.2 can't handle such output. */
790 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
791 && ! TREE_STATIC (decl))
792 return;
794 /* Emit any structure, union, or enum type that has not been output.
795 This occurs for tag-less structs (et al) used to declare variables
796 within functions. */
797 if (TREE_CODE (type) == ENUMERAL_TYPE
798 || TREE_CODE (type) == RECORD_TYPE
799 || TREE_CODE (type) == UNION_TYPE
800 || TREE_CODE (type) == QUAL_UNION_TYPE)
802 if (COMPLETE_TYPE_P (type) /* not a forward reference */
803 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
804 sdbout_one_type (type);
807 /* Defer SDB information for top-level initialized variables! */
808 if (! local
809 && MEM_P (value)
810 && DECL_INITIAL (decl))
811 return;
813 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
814 For now, avoid crashing. */
815 if (DECL_NAME (decl) == NULL_TREE)
816 return;
818 /* Record the name for, starting a symtab entry. */
819 if (local)
820 name = IDENTIFIER_POINTER (DECL_NAME (decl));
821 else
822 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
824 if (MEM_P (value)
825 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
827 PUT_SDB_DEF (name);
828 if (TREE_PUBLIC (decl))
830 PUT_SDB_VAL (XEXP (value, 0));
831 PUT_SDB_SCL (C_EXT);
833 else
835 PUT_SDB_VAL (XEXP (value, 0));
836 PUT_SDB_SCL (C_STAT);
839 else if (regno >= 0)
841 PUT_SDB_DEF (name);
842 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
843 PUT_SDB_SCL (C_REG);
845 else if (MEM_P (value)
846 && (MEM_P (XEXP (value, 0))
847 || (REG_P (XEXP (value, 0))
848 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
849 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
850 /* If the value is indirect by memory or by a register
851 that isn't the frame pointer
852 then it means the object is variable-sized and address through
853 that register or stack slot. COFF has no way to represent this
854 so all we can do is output the variable as a pointer. */
856 PUT_SDB_DEF (name);
857 if (REG_P (XEXP (value, 0)))
859 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
860 PUT_SDB_SCL (C_REG);
862 else
864 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
865 (CONST_INT...)))).
866 We want the value of that CONST_INT. */
867 /* Encore compiler hates a newline in a macro arg, it seems. */
868 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
869 (XEXP (XEXP (value, 0), 0)));
870 PUT_SDB_SCL (C_AUTO);
873 /* Effectively do build_pointer_type, but don't cache this type,
874 since it might be temporary whereas the type it points to
875 might have been saved for inlining. */
876 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
877 type = make_node (POINTER_TYPE);
878 TREE_TYPE (type) = TREE_TYPE (decl);
880 else if (MEM_P (value)
881 && ((GET_CODE (XEXP (value, 0)) == PLUS
882 && REG_P (XEXP (XEXP (value, 0), 0))
883 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
884 /* This is for variables which are at offset zero from
885 the frame pointer. This happens on the Alpha.
886 Non-frame pointer registers are excluded above. */
887 || (REG_P (XEXP (value, 0)))))
889 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
890 or (MEM (REG...)). We want the value of that CONST_INT
891 or zero. */
892 PUT_SDB_DEF (name);
893 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
894 PUT_SDB_SCL (C_AUTO);
896 else
898 /* It is something we don't know how to represent for SDB. */
899 return;
901 break;
903 default:
904 break;
906 PUT_SDB_TYPE (plain_type (type));
907 PUT_SDB_ENDEF;
910 /* Output SDB information for a top-level initialized variable
911 that has been delayed. */
913 static void
914 sdbout_toplevel_data (tree decl)
916 tree type = TREE_TYPE (decl);
918 if (DECL_IGNORED_P (decl))
919 return;
921 gcc_assert (TREE_CODE (decl) == VAR_DECL);
922 gcc_assert (MEM_P (DECL_RTL (decl)));
923 gcc_assert (DECL_INITIAL (decl));
925 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
926 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
927 if (TREE_PUBLIC (decl))
929 PUT_SDB_SCL (C_EXT);
931 else
933 PUT_SDB_SCL (C_STAT);
935 PUT_SDB_TYPE (plain_type (type));
936 PUT_SDB_ENDEF;
939 #ifdef SDB_ALLOW_FORWARD_REFERENCES
941 /* Machinery to record and output anonymous types. */
943 static void
944 sdbout_queue_anonymous_type (tree type)
946 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
949 static void
950 sdbout_dequeue_anonymous_types (void)
952 tree types, link;
954 while (anonymous_types)
956 types = nreverse (anonymous_types);
957 anonymous_types = NULL_TREE;
959 for (link = types; link; link = TREE_CHAIN (link))
961 tree type = TREE_VALUE (link);
963 if (type && ! TREE_ASM_WRITTEN (type))
964 sdbout_one_type (type);
969 #endif
971 /* Given a chain of ..._TYPE nodes, all of which have names,
972 output definitions of those names, as typedefs. */
974 void
975 sdbout_types (tree types)
977 tree link;
979 for (link = types; link; link = TREE_CHAIN (link))
980 sdbout_one_type (link);
982 #ifdef SDB_ALLOW_FORWARD_REFERENCES
983 sdbout_dequeue_anonymous_types ();
984 #endif
987 static void
988 sdbout_type (tree type)
990 if (type == error_mark_node)
991 type = integer_type_node;
992 PUT_SDB_TYPE (plain_type (type));
995 /* Output types of the fields of type TYPE, if they are structs.
997 Formerly did not chase through pointer types, since that could be circular.
998 They must come before TYPE, since forward refs are not allowed.
999 Now james@bigtex.cactus.org says to try them. */
1001 static void
1002 sdbout_field_types (tree type)
1004 tree tail;
1006 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1007 /* This condition should match the one for emitting the actual
1008 members below. */
1009 if (TREE_CODE (tail) == FIELD_DECL
1010 && DECL_NAME (tail)
1011 && DECL_SIZE (tail)
1012 && tree_fits_uhwi_p (DECL_SIZE (tail))
1013 && tree_fits_shwi_p (bit_position (tail)))
1015 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1016 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1017 else
1018 sdbout_one_type (TREE_TYPE (tail));
1022 /* Use this to put out the top level defined record and union types
1023 for later reference. If this is a struct with a name, then put that
1024 name out. Other unnamed structs will have .xxfake labels generated so
1025 that they may be referred to later.
1026 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1027 It may NOT be called recursively. */
1029 static void
1030 sdbout_one_type (tree type)
1032 if (current_function_decl != NULL_TREE
1033 && DECL_SECTION_NAME (current_function_decl) != NULL)
1034 ; /* Don't change section amid function. */
1035 else
1036 switch_to_section (current_function_section ());
1038 switch (TREE_CODE (type))
1040 case RECORD_TYPE:
1041 case UNION_TYPE:
1042 case QUAL_UNION_TYPE:
1043 case ENUMERAL_TYPE:
1044 type = TYPE_MAIN_VARIANT (type);
1045 /* Don't output a type twice. */
1046 if (TREE_ASM_WRITTEN (type))
1047 /* James said test TREE_ASM_BEING_WRITTEN here. */
1048 return;
1050 /* Output nothing if type is not yet defined. */
1051 if (!COMPLETE_TYPE_P (type))
1052 return;
1054 TREE_ASM_WRITTEN (type) = 1;
1056 /* This is reputed to cause trouble with the following case,
1057 but perhaps checking TYPE_SIZE above will fix it. */
1059 /* Here is a testcase:
1061 struct foo {
1062 struct badstr *bbb;
1063 } forwardref;
1065 typedef struct intermediate {
1066 int aaaa;
1067 } intermediate_ref;
1069 typedef struct badstr {
1070 int ccccc;
1071 } badtype; */
1073 /* This change, which ought to make better output,
1074 used to make the COFF assembler unhappy.
1075 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1076 /* Before really doing anything, output types we want to refer to. */
1077 /* Note that in version 1 the following two lines
1078 are not used if forward references are in use. */
1079 if (TREE_CODE (type) != ENUMERAL_TYPE)
1080 sdbout_field_types (type);
1082 /* Output a structure type. */
1084 int size = int_size_in_bytes (type);
1085 int member_scl = 0;
1086 tree tem;
1088 /* Record the type tag, but not in its permanent place just yet. */
1089 sdbout_record_type_name (type);
1091 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1093 switch (TREE_CODE (type))
1095 case UNION_TYPE:
1096 case QUAL_UNION_TYPE:
1097 PUT_SDB_SCL (C_UNTAG);
1098 PUT_SDB_TYPE (T_UNION);
1099 member_scl = C_MOU;
1100 break;
1102 case RECORD_TYPE:
1103 PUT_SDB_SCL (C_STRTAG);
1104 PUT_SDB_TYPE (T_STRUCT);
1105 member_scl = C_MOS;
1106 break;
1108 case ENUMERAL_TYPE:
1109 PUT_SDB_SCL (C_ENTAG);
1110 PUT_SDB_TYPE (T_ENUM);
1111 member_scl = C_MOE;
1112 break;
1114 default:
1115 break;
1118 PUT_SDB_SIZE (size);
1119 PUT_SDB_ENDEF;
1121 /* Print out the base class information with fields
1122 named after the types they hold. */
1123 /* This is only relevant to aggregate types. TYPE_BINFO is used
1124 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1125 case. */
1126 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1128 int i;
1129 tree binfo, child;
1131 for (binfo = TYPE_BINFO (type), i = 0;
1132 BINFO_BASE_ITERATE (binfo, i, child); i++)
1134 tree child_type = BINFO_TYPE (child);
1135 tree child_type_name;
1137 if (TYPE_NAME (child_type) == 0)
1138 continue;
1139 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1140 child_type_name = TYPE_NAME (child_type);
1141 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1143 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1144 if (child_type_name && template_name_p (child_type_name))
1145 child_type_name
1146 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1148 else
1149 continue;
1151 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1152 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1153 PUT_SDB_SCL (member_scl);
1154 sdbout_type (BINFO_TYPE (child));
1155 PUT_SDB_ENDEF;
1159 /* Output the individual fields. */
1161 if (TREE_CODE (type) == ENUMERAL_TYPE)
1163 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1165 tree value = TREE_VALUE (tem);
1167 if (TREE_CODE (value) == CONST_DECL)
1168 value = DECL_INITIAL (value);
1170 if (tree_fits_shwi_p (value))
1172 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1173 PUT_SDB_INT_VAL (tree_to_shwi (value));
1174 PUT_SDB_SCL (C_MOE);
1175 PUT_SDB_TYPE (T_MOE);
1176 PUT_SDB_ENDEF;
1180 else /* record or union type */
1181 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1182 /* Output the name, type, position (in bits), size (in bits)
1183 of each field. */
1185 /* Omit here the nameless fields that are used to skip bits.
1186 Also omit fields with variable size or position.
1187 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1188 if (TREE_CODE (tem) == FIELD_DECL
1189 && DECL_NAME (tem)
1190 && DECL_SIZE (tem)
1191 && tree_fits_uhwi_p (DECL_SIZE (tem))
1192 && tree_fits_shwi_p (bit_position (tem)))
1194 const char *name;
1196 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1197 PUT_SDB_DEF (name);
1198 if (DECL_BIT_FIELD_TYPE (tem))
1200 PUT_SDB_INT_VAL (int_bit_position (tem));
1201 PUT_SDB_SCL (C_FIELD);
1202 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1203 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1205 else
1207 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1208 PUT_SDB_SCL (member_scl);
1209 sdbout_type (TREE_TYPE (tem));
1211 PUT_SDB_ENDEF;
1213 /* Output end of a structure,union, or enumeral definition. */
1215 PUT_SDB_PLAIN_DEF ("eos");
1216 PUT_SDB_INT_VAL (size);
1217 PUT_SDB_SCL (C_EOS);
1218 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1219 PUT_SDB_SIZE (size);
1220 PUT_SDB_ENDEF;
1221 break;
1224 default:
1225 break;
1229 /* The following two functions output definitions of function parameters.
1230 Each parameter gets a definition locating it in the parameter list.
1231 Each parameter that is a register variable gets a second definition
1232 locating it in the register.
1234 Printing or argument lists in gdb uses the definitions that
1235 locate in the parameter list. But reference to the variable in
1236 expressions uses preferentially the definition as a register. */
1238 /* Output definitions, referring to storage in the parmlist,
1239 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1241 static void
1242 sdbout_parms (tree parms)
1244 for (; parms; parms = TREE_CHAIN (parms))
1245 if (DECL_NAME (parms)
1246 && TREE_TYPE (parms) != error_mark_node
1247 && DECL_RTL_SET_P (parms)
1248 && DECL_INCOMING_RTL (parms))
1250 int current_sym_value = 0;
1251 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1253 if (name == 0 || *name == 0)
1254 name = gen_fake_label ();
1256 /* Perform any necessary register eliminations on the parameter's rtl,
1257 so that the debugging output will be accurate. */
1258 DECL_INCOMING_RTL (parms)
1259 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1260 SET_DECL_RTL (parms,
1261 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1263 if (PARM_PASSED_IN_MEMORY (parms))
1265 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1266 tree type;
1268 /* ??? Here we assume that the parm address is indexed
1269 off the frame pointer or arg pointer.
1270 If that is not true, we produce meaningless results,
1271 but do not crash. */
1272 if (GET_CODE (addr) == PLUS
1273 && CONST_INT_P (XEXP (addr, 1)))
1274 current_sym_value = INTVAL (XEXP (addr, 1));
1275 else
1276 current_sym_value = 0;
1278 if (REG_P (DECL_RTL (parms))
1279 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1280 type = DECL_ARG_TYPE (parms);
1281 else
1283 int original_sym_value = current_sym_value;
1285 /* This is the case where the parm is passed as an int or
1286 double and it is converted to a char, short or float
1287 and stored back in the parmlist. In this case, describe
1288 the parm with the variable's declared type, and adjust
1289 the address if the least significant bytes (which we are
1290 using) are not the first ones. */
1291 if (BYTES_BIG_ENDIAN
1292 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1293 current_sym_value +=
1294 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1295 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1297 if (MEM_P (DECL_RTL (parms))
1298 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1299 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1300 == CONST_INT)
1301 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1302 == current_sym_value))
1303 type = TREE_TYPE (parms);
1304 else
1306 current_sym_value = original_sym_value;
1307 type = DECL_ARG_TYPE (parms);
1311 PUT_SDB_DEF (name);
1312 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1313 PUT_SDB_SCL (C_ARG);
1314 PUT_SDB_TYPE (plain_type (type));
1315 PUT_SDB_ENDEF;
1317 else if (REG_P (DECL_RTL (parms)))
1319 rtx best_rtl;
1320 /* Parm passed in registers and lives in registers or nowhere. */
1322 /* If parm lives in a register, use that register;
1323 pretend the parm was passed there. It would be more consistent
1324 to describe the register where the parm was passed,
1325 but in practice that register usually holds something else. */
1326 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1327 best_rtl = DECL_RTL (parms);
1328 /* If the parm lives nowhere,
1329 use the register where it was passed. */
1330 else
1331 best_rtl = DECL_INCOMING_RTL (parms);
1333 PUT_SDB_DEF (name);
1334 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1335 PUT_SDB_SCL (C_REGPARM);
1336 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1337 PUT_SDB_ENDEF;
1339 else if (MEM_P (DECL_RTL (parms))
1340 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1342 /* Parm was passed in registers but lives on the stack. */
1344 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1345 in which case we want the value of that CONST_INT,
1346 or (MEM (REG ...)) or (MEM (MEM ...)),
1347 in which case we use a value of zero. */
1348 if (REG_P (XEXP (DECL_RTL (parms), 0))
1349 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1350 current_sym_value = 0;
1351 else
1352 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1354 /* Again, this assumes the offset is based on the arg pointer. */
1355 PUT_SDB_DEF (name);
1356 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1357 XEXP (DECL_RTL (parms), 0)));
1358 PUT_SDB_SCL (C_ARG);
1359 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1360 PUT_SDB_ENDEF;
1365 /* Output definitions for the places where parms live during the function,
1366 when different from where they were passed, when the parms were passed
1367 in memory.
1369 It is not useful to do this for parms passed in registers
1370 that live during the function in different registers, because it is
1371 impossible to look in the passed register for the passed value,
1372 so we use the within-the-function register to begin with.
1374 PARMS is a chain of PARM_DECL nodes. */
1376 static void
1377 sdbout_reg_parms (tree parms)
1379 for (; parms; parms = TREE_CHAIN (parms))
1380 if (DECL_NAME (parms)
1381 && TREE_TYPE (parms) != error_mark_node
1382 && DECL_RTL_SET_P (parms)
1383 && DECL_INCOMING_RTL (parms))
1385 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1387 /* Report parms that live in registers during the function
1388 but were passed in memory. */
1389 if (REG_P (DECL_RTL (parms))
1390 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1391 && PARM_PASSED_IN_MEMORY (parms))
1393 if (name == 0 || *name == 0)
1394 name = gen_fake_label ();
1395 PUT_SDB_DEF (name);
1396 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1397 PUT_SDB_SCL (C_REG);
1398 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1399 PUT_SDB_ENDEF;
1401 /* Report parms that live in memory but not where they were passed. */
1402 else if (MEM_P (DECL_RTL (parms))
1403 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1404 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1405 && PARM_PASSED_IN_MEMORY (parms)
1406 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1408 #if 0 /* ??? It is not clear yet what should replace this. */
1409 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1410 /* A parm declared char is really passed as an int,
1411 so it occupies the least significant bytes.
1412 On a big-endian machine those are not the low-numbered ones. */
1413 if (BYTES_BIG_ENDIAN
1414 && offset != -1
1415 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1416 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1417 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1418 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1419 #endif
1421 if (name == 0 || *name == 0)
1422 name = gen_fake_label ();
1423 PUT_SDB_DEF (name);
1424 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1425 (XEXP (DECL_RTL (parms), 0)));
1426 PUT_SDB_SCL (C_AUTO);
1427 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1428 PUT_SDB_ENDEF;
1434 /* Output debug information for a global DECL. Called from toplev.c
1435 after compilation proper has finished. */
1437 static void
1438 sdbout_global_decl (tree decl)
1440 if (TREE_CODE (decl) == VAR_DECL
1441 && !DECL_EXTERNAL (decl)
1442 && DECL_RTL_SET_P (decl))
1444 /* The COFF linker can move initialized global vars to the end.
1445 And that can screw up the symbol ordering. Defer those for
1446 sdbout_finish (). */
1447 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1448 sdbout_symbol (decl, 0);
1449 else
1450 vec_safe_push (deferred_global_decls, decl);
1452 /* Output COFF information for non-global file-scope initialized
1453 variables. */
1454 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1455 sdbout_toplevel_data (decl);
1459 /* Output initialized global vars at the end, in the order of
1460 definition. See comment in sdbout_global_decl. */
1462 static void
1463 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1465 size_t i;
1466 tree decl;
1468 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1469 sdbout_symbol (decl, 0);
1472 /* Describe the beginning of an internal block within a function.
1473 Also output descriptions of variables defined in this block.
1475 N is the number of the block, by order of beginning, counting from 1,
1476 and not counting the outermost (function top-level) block.
1477 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1478 if the count starts at 0 for the outermost one. */
1480 static void
1481 sdbout_begin_block (unsigned int line, unsigned int n)
1483 tree decl = current_function_decl;
1484 MAKE_LINE_SAFE (line);
1486 /* The SCO compiler does not emit a separate block for the function level
1487 scope, so we avoid it here also. */
1488 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1490 if (n == 1)
1492 /* Include the outermost BLOCK's variables in block 1. */
1493 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1494 sdbout_block (DECL_INITIAL (decl));
1496 /* If -g1, suppress all the internal symbols of functions
1497 except for arguments. */
1498 if (debug_info_level != DINFO_LEVEL_TERSE)
1500 do_block = n;
1501 sdbout_block (DECL_INITIAL (decl));
1504 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1505 sdbout_dequeue_anonymous_types ();
1506 #endif
1509 /* Describe the end line-number of an internal block within a function. */
1511 static void
1512 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1514 MAKE_LINE_SAFE (line);
1516 /* The SCO compiler does not emit a separate block for the function level
1517 scope, so we avoid it here also. */
1518 if (n != 1)
1519 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1522 /* Output a line number symbol entry for source file FILENAME and line
1523 number LINE. */
1525 static void
1526 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1527 int discriminator ATTRIBUTE_UNUSED,
1528 bool is_stmt ATTRIBUTE_UNUSED)
1530 /* COFF relative line numbers must be positive. */
1531 if ((int) line > sdb_begin_function_line)
1533 #ifdef SDB_OUTPUT_SOURCE_LINE
1534 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1535 #else
1536 fprintf (asm_out_file, "\t.ln\t%d\n",
1537 ((sdb_begin_function_line > -1)
1538 ? line - sdb_begin_function_line : 1));
1539 #endif
1543 /* Output sdb info for the current function name.
1544 Called from assemble_start_function. */
1546 static void
1547 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1549 sdbout_symbol (current_function_decl, 0);
1552 /* Called at beginning of function body after prologue. Record the
1553 function's starting line number, so we can output relative line numbers
1554 for the other lines. Describe beginning of outermost block. Also
1555 describe the parameter list. */
1557 static void
1558 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1560 sdbout_end_prologue (line, file);
1563 static void
1564 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1566 sdb_begin_function_line = line - 1;
1567 PUT_SDB_FUNCTION_START (line);
1568 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1569 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1572 /* Called at end of function (before epilogue).
1573 Describe end of outermost block. */
1575 static void
1576 sdbout_end_function (unsigned int line)
1578 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1579 sdbout_dequeue_anonymous_types ();
1580 #endif
1582 MAKE_LINE_SAFE (line);
1583 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1585 /* Indicate we are between functions, for line-number output. */
1586 sdb_begin_function_line = -1;
1589 /* Output sdb info for the absolute end of a function.
1590 Called after the epilogue is output. */
1592 static void
1593 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1594 const char *file ATTRIBUTE_UNUSED)
1596 const char *const name ATTRIBUTE_UNUSED
1597 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1599 #ifdef PUT_SDB_EPILOGUE_END
1600 PUT_SDB_EPILOGUE_END (name);
1601 #else
1602 fprintf (asm_out_file, "\t.def\t");
1603 assemble_name (asm_out_file, name);
1604 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1605 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1606 #endif
1609 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1610 is present. */
1612 static void
1613 sdbout_label (rtx_code_label *insn)
1615 PUT_SDB_DEF (LABEL_NAME (insn));
1616 PUT_SDB_VAL (insn);
1617 PUT_SDB_SCL (C_LABEL);
1618 PUT_SDB_TYPE (T_NULL);
1619 PUT_SDB_ENDEF;
1622 /* Change to reading from a new source file. */
1624 static void
1625 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1626 const char *filename ATTRIBUTE_UNUSED)
1630 /* Revert to reading a previous source file. */
1632 static void
1633 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1637 /* Set up for SDB output at the start of compilation. */
1639 static void
1640 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1642 tree t;
1644 vec_alloc (deferred_global_decls, 12);
1646 /* Emit debug information which was queued by sdbout_symbol before
1647 we got here. */
1648 sdbout_initialized = true;
1650 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1651 sdbout_symbol (TREE_VALUE (t), 0);
1652 preinit_symbols = 0;
1655 #endif /* SDB_DEBUGGING_INFO */
1657 #include "gt-sdbout.h"