PR sanitizer/80403
[official-gcc.git] / gcc / sdbout.c
blob84798ac9fb3eb1cbe539c0764c92e1db34954c59
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, /* imported_module_or_decl */
305 debug_nothing_tree, /* deferred_inline_function */
306 debug_nothing_tree, /* outlining_inline_function */
307 sdbout_label, /* label */
308 debug_nothing_int, /* handle_pch */
309 debug_nothing_rtx_insn, /* var_location */
310 debug_nothing_tree, /* size_function */
311 debug_nothing_void, /* switch_text_section */
312 debug_nothing_tree_tree, /* set_name */
313 0, /* start_end_main_source_file */
314 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
317 /* Return a unique string to name an anonymous type. */
319 static char *
320 gen_fake_label (void)
322 char label[10];
323 char *labelstr;
324 sprintf (label, ".%dfake", unnamed_struct_number);
325 unnamed_struct_number++;
326 labelstr = xstrdup (label);
327 return labelstr;
330 /* Return the number which describes TYPE for SDB.
331 For pointers, etc., this function is recursive.
332 Each record, union or enumeral type must already have had a
333 tag number output. */
335 /* The number is given by d6d5d4d3d2d1bbbb
336 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
337 Thus, char *foo () has bbbb=T_CHAR
338 d1=D_FCN
339 d2=D_PTR
340 N_BTMASK= 017 1111 basic type field.
341 N_TSHIFT= 2 derived type shift
342 N_BTSHFT= 4 Basic type shift */
344 /* Produce the number that describes a pointer, function or array type.
345 PREV is the number describing the target, value or element type.
346 DT_type describes how to transform that type. */
347 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
348 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
349 | ((int) DT_type << (int) N_BTSHFT) \
350 | ((PREV) & (int) N_BTMASK))
352 /* Number of elements used in sdb_dims. */
353 static int sdb_n_dims = 0;
355 /* Table of array dimensions of current type. */
356 static int sdb_dims[SDB_MAX_DIM];
358 /* Size of outermost array currently being processed. */
359 static int sdb_type_size = -1;
361 static int
362 plain_type (tree type)
364 int val = plain_type_1 (type, 0);
366 /* If we have already saved up some array dimensions, print them now. */
367 if (sdb_n_dims > 0)
369 int i;
370 PUT_SDB_START_DIM;
371 for (i = sdb_n_dims - 1; i > 0; i--)
372 PUT_SDB_NEXT_DIM (sdb_dims[i]);
373 PUT_SDB_LAST_DIM (sdb_dims[0]);
374 sdb_n_dims = 0;
376 sdb_type_size = int_size_in_bytes (type);
377 /* Don't kill sdb if type is not laid out or has variable size. */
378 if (sdb_type_size < 0)
379 sdb_type_size = 0;
381 /* If we have computed the size of an array containing this type,
382 print it now. */
383 if (sdb_type_size >= 0)
385 PUT_SDB_SIZE (sdb_type_size);
386 sdb_type_size = -1;
388 return val;
391 static int
392 template_name_p (tree name)
394 const char *ptr = IDENTIFIER_POINTER (name);
395 while (*ptr && *ptr != '<')
396 ptr++;
398 return *ptr != '\0';
401 static void
402 sdbout_record_type_name (tree type)
404 const char *name = 0;
405 int no_name;
407 if (KNOWN_TYPE_TAG (type))
408 return;
410 if (TYPE_NAME (type) != 0)
412 tree t = 0;
414 /* Find the IDENTIFIER_NODE for the type name. */
415 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
416 t = TYPE_NAME (type);
417 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
419 t = DECL_NAME (TYPE_NAME (type));
420 /* The DECL_NAME for templates includes "<>", which breaks
421 most assemblers. Use its assembler name instead, which
422 has been mangled into being safe. */
423 if (t && template_name_p (t))
424 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
427 /* Now get the name as a string, or invent one. */
428 if (t != NULL_TREE)
429 name = IDENTIFIER_POINTER (t);
432 no_name = (name == 0 || *name == 0);
433 if (no_name)
434 name = gen_fake_label ();
436 SET_KNOWN_TYPE_TAG (type, name);
437 #ifdef SDB_ALLOW_FORWARD_REFERENCES
438 if (no_name)
439 sdbout_queue_anonymous_type (type);
440 #endif
443 /* Return the .type value for type TYPE.
445 LEVEL indicates how many levels deep we have recursed into the type.
446 The SDB debug format can only represent 6 derived levels of types.
447 After that, we must output inaccurate debug info. We deliberately
448 stop before the 7th level, so that ADA recursive types will not give an
449 infinite loop. */
451 static int
452 plain_type_1 (tree type, int level)
454 if (type == 0)
455 type = void_type_node;
456 else if (type == error_mark_node)
457 type = integer_type_node;
458 else
459 type = TYPE_MAIN_VARIANT (type);
461 switch (TREE_CODE (type))
463 case VOID_TYPE:
464 case NULLPTR_TYPE:
465 return T_VOID;
466 case BOOLEAN_TYPE:
467 case INTEGER_TYPE:
469 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
471 /* Carefully distinguish all the standard types of C,
472 without messing up if the language is not C.
473 Note that we check only for the names that contain spaces;
474 other names might occur by coincidence in other languages. */
475 if (TYPE_NAME (type) != 0
476 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
477 && DECL_NAME (TYPE_NAME (type)) != 0
478 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
480 const char *const name
481 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
483 if (!strcmp (name, "char"))
484 return T_CHAR;
485 if (!strcmp (name, "unsigned char"))
486 return T_UCHAR;
487 if (!strcmp (name, "signed char"))
488 return T_CHAR;
489 if (!strcmp (name, "int"))
490 return T_INT;
491 if (!strcmp (name, "unsigned int"))
492 return T_UINT;
493 if (!strcmp (name, "short int"))
494 return T_SHORT;
495 if (!strcmp (name, "short unsigned int"))
496 return T_USHORT;
497 if (!strcmp (name, "long int"))
498 return T_LONG;
499 if (!strcmp (name, "long unsigned int"))
500 return T_ULONG;
503 if (size == INT_TYPE_SIZE)
504 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
505 if (size == CHAR_TYPE_SIZE)
506 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
507 if (size == SHORT_TYPE_SIZE)
508 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
509 if (size == LONG_TYPE_SIZE)
510 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
511 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
512 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
513 return 0;
516 case REAL_TYPE:
518 int precision = TYPE_PRECISION (type);
519 if (precision == FLOAT_TYPE_SIZE)
520 return T_FLOAT;
521 if (precision == DOUBLE_TYPE_SIZE)
522 return T_DOUBLE;
523 if (precision == LONG_DOUBLE_TYPE_SIZE)
524 return T_DOUBLE; /* better than nothing */
526 return 0;
529 case ARRAY_TYPE:
531 int m;
532 if (level >= 6)
533 return T_VOID;
534 else
535 m = plain_type_1 (TREE_TYPE (type), level+1);
536 if (sdb_n_dims < SDB_MAX_DIM)
537 sdb_dims[sdb_n_dims++]
538 = (TYPE_DOMAIN (type)
539 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
540 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
541 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
542 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
543 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
544 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
545 : 0);
547 return PUSH_DERIVED_LEVEL (DT_ARY, m);
550 case RECORD_TYPE:
551 case UNION_TYPE:
552 case QUAL_UNION_TYPE:
553 case ENUMERAL_TYPE:
555 const char *tag;
556 #ifdef SDB_ALLOW_FORWARD_REFERENCES
557 sdbout_record_type_name (type);
558 #endif
559 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
560 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
561 #ifdef SDB_ALLOW_FORWARD_REFERENCES
562 || TYPE_MODE (type) != VOIDmode
563 #endif
565 #endif
567 /* Output the referenced structure tag name
568 only if the .def has already been finished.
569 At least on 386, the Unix assembler
570 cannot handle forward references to tags. */
571 /* But the 88100, it requires them, sigh... */
572 /* And the MIPS requires unknown refs as well... */
573 tag = KNOWN_TYPE_TAG (type);
574 PUT_SDB_TAG (tag);
575 /* These 3 lines used to follow the close brace.
576 However, a size of 0 without a tag implies a tag of 0,
577 so if we don't know a tag, we can't mention the size. */
578 sdb_type_size = int_size_in_bytes (type);
579 if (sdb_type_size < 0)
580 sdb_type_size = 0;
582 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
583 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
584 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
585 : T_ENUM);
587 case POINTER_TYPE:
588 case REFERENCE_TYPE:
590 int m;
591 if (level >= 6)
592 return T_VOID;
593 else
594 m = plain_type_1 (TREE_TYPE (type), level+1);
595 return PUSH_DERIVED_LEVEL (DT_PTR, m);
597 case FUNCTION_TYPE:
598 case METHOD_TYPE:
600 int m;
601 if (level >= 6)
602 return T_VOID;
603 else
604 m = plain_type_1 (TREE_TYPE (type), level+1);
605 return PUSH_DERIVED_LEVEL (DT_FCN, m);
607 default:
608 return 0;
612 /* Output the symbols defined in block number DO_BLOCK.
614 This function works by walking the tree structure of blocks,
615 counting blocks until it finds the desired block. */
617 static int do_block = 0;
619 static void
620 sdbout_block (tree block)
622 while (block)
624 /* Ignore blocks never expanded or otherwise marked as real. */
625 if (TREE_USED (block))
627 /* When we reach the specified block, output its symbols. */
628 if (BLOCK_NUMBER (block) == do_block)
629 sdbout_syms (BLOCK_VARS (block));
631 /* If we are past the specified block, stop the scan. */
632 if (BLOCK_NUMBER (block) > do_block)
633 return;
635 /* Scan the blocks within this block. */
636 sdbout_block (BLOCK_SUBBLOCKS (block));
639 block = BLOCK_CHAIN (block);
643 /* Call sdbout_symbol on each decl in the chain SYMS. */
645 static void
646 sdbout_syms (tree syms)
648 while (syms)
650 if (TREE_CODE (syms) != LABEL_DECL)
651 sdbout_symbol (syms, 1);
652 syms = TREE_CHAIN (syms);
656 /* Output SDB information for a symbol described by DECL.
657 LOCAL is nonzero if the symbol is not file-scope. */
659 void
660 sdbout_symbol (tree decl, int local)
662 tree type = TREE_TYPE (decl);
663 tree context = NULL_TREE;
664 rtx value;
665 int regno = -1;
666 const char *name;
668 /* If we are called before sdbout_init is run, just save the symbol
669 for later. */
670 if (!sdbout_initialized)
672 preinit_symbols = tree_cons (0, decl, preinit_symbols);
673 return;
676 sdbout_one_type (type);
678 switch (TREE_CODE (decl))
680 case CONST_DECL:
681 /* Enum values are defined by defining the enum type. */
682 return;
684 case FUNCTION_DECL:
685 /* Don't mention a nested function under its parent. */
686 context = decl_function_context (decl);
687 if (context == current_function_decl)
688 return;
689 /* Check DECL_INITIAL to distinguish declarations from definitions.
690 Don't output debug info here for declarations; they will have
691 a DECL_INITIAL value of 0. */
692 if (! DECL_INITIAL (decl))
693 return;
694 if (!MEM_P (DECL_RTL (decl))
695 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
696 return;
697 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
698 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
699 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
700 break;
702 case TYPE_DECL:
703 /* Done with tagged types. */
704 if (DECL_NAME (decl) == 0)
705 return;
706 if (DECL_IGNORED_P (decl))
707 return;
708 /* Don't output intrinsic types. GAS chokes on SDB .def
709 statements that contain identifiers with embedded spaces
710 (eg "unsigned long"). */
711 if (DECL_IS_BUILTIN (decl))
712 return;
714 /* Output typedef name. */
715 if (template_name_p (DECL_NAME (decl)))
716 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
717 else
718 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
719 PUT_SDB_SCL (C_TPDEF);
720 break;
722 case PARM_DECL:
723 /* Parm decls go in their own separate chains
724 and are output by sdbout_reg_parms and sdbout_parms. */
725 gcc_unreachable ();
727 case VAR_DECL:
728 /* Don't mention a variable that is external.
729 Let the file that defines it describe it. */
730 if (DECL_EXTERNAL (decl))
731 return;
733 /* Ignore __FUNCTION__, etc. */
734 if (DECL_IGNORED_P (decl))
735 return;
737 /* If there was an error in the declaration, don't dump core
738 if there is no RTL associated with the variable doesn't
739 exist. */
740 if (!DECL_RTL_SET_P (decl))
741 return;
743 value = DECL_RTL (decl);
745 if (!is_global_var (decl))
746 value = eliminate_regs (value, VOIDmode, NULL_RTX);
748 SET_DECL_RTL (decl, value);
749 #ifdef LEAF_REG_REMAP
750 if (crtl->uses_only_leaf_regs)
751 leaf_renumber_regs_insn (value);
752 #endif
754 /* Don't mention a variable at all
755 if it was completely optimized into nothingness.
757 If DECL was from an inline function, then its rtl
758 is not identically the rtl that was used in this
759 particular compilation. */
760 if (REG_P (value))
762 regno = REGNO (value);
763 if (regno >= FIRST_PSEUDO_REGISTER)
764 return;
766 else if (GET_CODE (value) == SUBREG)
768 while (GET_CODE (value) == SUBREG)
769 value = SUBREG_REG (value);
770 if (REG_P (value))
772 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
773 return;
775 regno = REGNO (alter_subreg (&value, true));
776 SET_DECL_RTL (decl, value);
778 /* Don't output anything if an auto variable
779 gets RTL that is static.
780 GAS version 2.2 can't handle such output. */
781 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
782 && ! TREE_STATIC (decl))
783 return;
785 /* Emit any structure, union, or enum type that has not been output.
786 This occurs for tag-less structs (et al) used to declare variables
787 within functions. */
788 if (TREE_CODE (type) == ENUMERAL_TYPE
789 || TREE_CODE (type) == RECORD_TYPE
790 || TREE_CODE (type) == UNION_TYPE
791 || TREE_CODE (type) == QUAL_UNION_TYPE)
793 if (COMPLETE_TYPE_P (type) /* not a forward reference */
794 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
795 sdbout_one_type (type);
798 /* Defer SDB information for top-level initialized variables! */
799 if (! local
800 && MEM_P (value)
801 && DECL_INITIAL (decl))
802 return;
804 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
805 For now, avoid crashing. */
806 if (DECL_NAME (decl) == NULL_TREE)
807 return;
809 /* Record the name for, starting a symtab entry. */
810 if (local)
811 name = IDENTIFIER_POINTER (DECL_NAME (decl));
812 else
813 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
815 if (MEM_P (value)
816 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
818 PUT_SDB_DEF (name);
819 if (TREE_PUBLIC (decl))
821 PUT_SDB_VAL (XEXP (value, 0));
822 PUT_SDB_SCL (C_EXT);
824 else
826 PUT_SDB_VAL (XEXP (value, 0));
827 PUT_SDB_SCL (C_STAT);
830 else if (regno >= 0)
832 PUT_SDB_DEF (name);
833 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
834 PUT_SDB_SCL (C_REG);
836 else if (MEM_P (value)
837 && (MEM_P (XEXP (value, 0))
838 || (REG_P (XEXP (value, 0))
839 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
840 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
841 /* If the value is indirect by memory or by a register
842 that isn't the frame pointer
843 then it means the object is variable-sized and address through
844 that register or stack slot. COFF has no way to represent this
845 so all we can do is output the variable as a pointer. */
847 PUT_SDB_DEF (name);
848 if (REG_P (XEXP (value, 0)))
850 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
851 PUT_SDB_SCL (C_REG);
853 else
855 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
856 (CONST_INT...)))).
857 We want the value of that CONST_INT. */
858 /* Encore compiler hates a newline in a macro arg, it seems. */
859 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
860 (XEXP (XEXP (value, 0), 0)));
861 PUT_SDB_SCL (C_AUTO);
864 /* Effectively do build_pointer_type, but don't cache this type,
865 since it might be temporary whereas the type it points to
866 might have been saved for inlining. */
867 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
868 type = make_node (POINTER_TYPE);
869 TREE_TYPE (type) = TREE_TYPE (decl);
871 else if (MEM_P (value)
872 && ((GET_CODE (XEXP (value, 0)) == PLUS
873 && REG_P (XEXP (XEXP (value, 0), 0))
874 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
875 /* This is for variables which are at offset zero from
876 the frame pointer. This happens on the Alpha.
877 Non-frame pointer registers are excluded above. */
878 || (REG_P (XEXP (value, 0)))))
880 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
881 or (MEM (REG...)). We want the value of that CONST_INT
882 or zero. */
883 PUT_SDB_DEF (name);
884 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
885 PUT_SDB_SCL (C_AUTO);
887 else
889 /* It is something we don't know how to represent for SDB. */
890 return;
892 break;
894 default:
895 break;
897 PUT_SDB_TYPE (plain_type (type));
898 PUT_SDB_ENDEF;
901 /* Output SDB information for a top-level initialized variable
902 that has been delayed. */
904 static void
905 sdbout_toplevel_data (tree decl)
907 tree type = TREE_TYPE (decl);
909 if (DECL_IGNORED_P (decl))
910 return;
912 gcc_assert (VAR_P (decl));
913 gcc_assert (MEM_P (DECL_RTL (decl)));
914 gcc_assert (DECL_INITIAL (decl));
916 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
917 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
918 if (TREE_PUBLIC (decl))
920 PUT_SDB_SCL (C_EXT);
922 else
924 PUT_SDB_SCL (C_STAT);
926 PUT_SDB_TYPE (plain_type (type));
927 PUT_SDB_ENDEF;
930 #ifdef SDB_ALLOW_FORWARD_REFERENCES
932 /* Machinery to record and output anonymous types. */
934 static void
935 sdbout_queue_anonymous_type (tree type)
937 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
940 static void
941 sdbout_dequeue_anonymous_types (void)
943 tree types, link;
945 while (anonymous_types)
947 types = nreverse (anonymous_types);
948 anonymous_types = NULL_TREE;
950 for (link = types; link; link = TREE_CHAIN (link))
952 tree type = TREE_VALUE (link);
954 if (type && ! TREE_ASM_WRITTEN (type))
955 sdbout_one_type (type);
960 #endif
962 /* Given a chain of ..._TYPE nodes, all of which have names,
963 output definitions of those names, as typedefs. */
965 void
966 sdbout_types (tree types)
968 tree link;
970 for (link = types; link; link = TREE_CHAIN (link))
971 sdbout_one_type (link);
973 #ifdef SDB_ALLOW_FORWARD_REFERENCES
974 sdbout_dequeue_anonymous_types ();
975 #endif
978 static void
979 sdbout_type (tree type)
981 if (type == error_mark_node)
982 type = integer_type_node;
983 PUT_SDB_TYPE (plain_type (type));
986 /* Output types of the fields of type TYPE, if they are structs.
988 Formerly did not chase through pointer types, since that could be circular.
989 They must come before TYPE, since forward refs are not allowed.
990 Now james@bigtex.cactus.org says to try them. */
992 static void
993 sdbout_field_types (tree type)
995 tree tail;
997 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
998 /* This condition should match the one for emitting the actual
999 members below. */
1000 if (TREE_CODE (tail) == FIELD_DECL
1001 && DECL_NAME (tail)
1002 && DECL_SIZE (tail)
1003 && tree_fits_uhwi_p (DECL_SIZE (tail))
1004 && tree_fits_shwi_p (bit_position (tail)))
1006 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1007 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1008 else
1009 sdbout_one_type (TREE_TYPE (tail));
1013 /* Use this to put out the top level defined record and union types
1014 for later reference. If this is a struct with a name, then put that
1015 name out. Other unnamed structs will have .xxfake labels generated so
1016 that they may be referred to later.
1017 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1018 It may NOT be called recursively. */
1020 static void
1021 sdbout_one_type (tree type)
1023 if (current_function_decl != NULL_TREE
1024 && DECL_SECTION_NAME (current_function_decl) != NULL)
1025 ; /* Don't change section amid function. */
1026 else
1027 switch_to_section (current_function_section ());
1029 switch (TREE_CODE (type))
1031 case RECORD_TYPE:
1032 case UNION_TYPE:
1033 case QUAL_UNION_TYPE:
1034 case ENUMERAL_TYPE:
1035 type = TYPE_MAIN_VARIANT (type);
1036 /* Don't output a type twice. */
1037 if (TREE_ASM_WRITTEN (type))
1038 /* James said test TREE_ASM_BEING_WRITTEN here. */
1039 return;
1041 /* Output nothing if type is not yet defined. */
1042 if (!COMPLETE_TYPE_P (type))
1043 return;
1045 TREE_ASM_WRITTEN (type) = 1;
1047 /* This is reputed to cause trouble with the following case,
1048 but perhaps checking TYPE_SIZE above will fix it. */
1050 /* Here is a testcase:
1052 struct foo {
1053 struct badstr *bbb;
1054 } forwardref;
1056 typedef struct intermediate {
1057 int aaaa;
1058 } intermediate_ref;
1060 typedef struct badstr {
1061 int ccccc;
1062 } badtype; */
1064 /* This change, which ought to make better output,
1065 used to make the COFF assembler unhappy.
1066 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1067 /* Before really doing anything, output types we want to refer to. */
1068 /* Note that in version 1 the following two lines
1069 are not used if forward references are in use. */
1070 if (TREE_CODE (type) != ENUMERAL_TYPE)
1071 sdbout_field_types (type);
1073 /* Output a structure type. */
1075 int size = int_size_in_bytes (type);
1076 int member_scl = 0;
1077 tree tem;
1079 /* Record the type tag, but not in its permanent place just yet. */
1080 sdbout_record_type_name (type);
1082 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1084 switch (TREE_CODE (type))
1086 case UNION_TYPE:
1087 case QUAL_UNION_TYPE:
1088 PUT_SDB_SCL (C_UNTAG);
1089 PUT_SDB_TYPE (T_UNION);
1090 member_scl = C_MOU;
1091 break;
1093 case RECORD_TYPE:
1094 PUT_SDB_SCL (C_STRTAG);
1095 PUT_SDB_TYPE (T_STRUCT);
1096 member_scl = C_MOS;
1097 break;
1099 case ENUMERAL_TYPE:
1100 PUT_SDB_SCL (C_ENTAG);
1101 PUT_SDB_TYPE (T_ENUM);
1102 member_scl = C_MOE;
1103 break;
1105 default:
1106 break;
1109 PUT_SDB_SIZE (size);
1110 PUT_SDB_ENDEF;
1112 /* Print out the base class information with fields
1113 named after the types they hold. */
1114 /* This is only relevant to aggregate types. TYPE_BINFO is used
1115 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1116 case. */
1117 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1119 int i;
1120 tree binfo, child;
1122 for (binfo = TYPE_BINFO (type), i = 0;
1123 BINFO_BASE_ITERATE (binfo, i, child); i++)
1125 tree child_type = BINFO_TYPE (child);
1126 tree child_type_name;
1128 if (TYPE_NAME (child_type) == 0)
1129 continue;
1130 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1131 child_type_name = TYPE_NAME (child_type);
1132 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1134 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1135 if (child_type_name && template_name_p (child_type_name))
1136 child_type_name
1137 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1139 else
1140 continue;
1142 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1143 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1144 PUT_SDB_SCL (member_scl);
1145 sdbout_type (BINFO_TYPE (child));
1146 PUT_SDB_ENDEF;
1150 /* Output the individual fields. */
1152 if (TREE_CODE (type) == ENUMERAL_TYPE)
1154 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1156 tree value = TREE_VALUE (tem);
1158 if (TREE_CODE (value) == CONST_DECL)
1159 value = DECL_INITIAL (value);
1161 if (tree_fits_shwi_p (value))
1163 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1164 PUT_SDB_INT_VAL (tree_to_shwi (value));
1165 PUT_SDB_SCL (C_MOE);
1166 PUT_SDB_TYPE (T_MOE);
1167 PUT_SDB_ENDEF;
1171 else /* record or union type */
1172 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1173 /* Output the name, type, position (in bits), size (in bits)
1174 of each field. */
1176 /* Omit here the nameless fields that are used to skip bits.
1177 Also omit fields with variable size or position.
1178 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1179 if (TREE_CODE (tem) == FIELD_DECL
1180 && DECL_NAME (tem)
1181 && DECL_SIZE (tem)
1182 && tree_fits_uhwi_p (DECL_SIZE (tem))
1183 && tree_fits_shwi_p (bit_position (tem)))
1185 const char *name;
1187 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1188 PUT_SDB_DEF (name);
1189 if (DECL_BIT_FIELD_TYPE (tem))
1191 PUT_SDB_INT_VAL (int_bit_position (tem));
1192 PUT_SDB_SCL (C_FIELD);
1193 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1194 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1196 else
1198 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1199 PUT_SDB_SCL (member_scl);
1200 sdbout_type (TREE_TYPE (tem));
1202 PUT_SDB_ENDEF;
1204 /* Output end of a structure,union, or enumeral definition. */
1206 PUT_SDB_PLAIN_DEF ("eos");
1207 PUT_SDB_INT_VAL (size);
1208 PUT_SDB_SCL (C_EOS);
1209 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1210 PUT_SDB_SIZE (size);
1211 PUT_SDB_ENDEF;
1212 break;
1215 default:
1216 break;
1220 /* The following two functions output definitions of function parameters.
1221 Each parameter gets a definition locating it in the parameter list.
1222 Each parameter that is a register variable gets a second definition
1223 locating it in the register.
1225 Printing or argument lists in gdb uses the definitions that
1226 locate in the parameter list. But reference to the variable in
1227 expressions uses preferentially the definition as a register. */
1229 /* Output definitions, referring to storage in the parmlist,
1230 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1232 static void
1233 sdbout_parms (tree parms)
1235 for (; parms; parms = TREE_CHAIN (parms))
1236 if (DECL_NAME (parms)
1237 && TREE_TYPE (parms) != error_mark_node
1238 && DECL_RTL_SET_P (parms)
1239 && DECL_INCOMING_RTL (parms))
1241 int current_sym_value = 0;
1242 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1244 if (name == 0 || *name == 0)
1245 name = gen_fake_label ();
1247 /* Perform any necessary register eliminations on the parameter's rtl,
1248 so that the debugging output will be accurate. */
1249 DECL_INCOMING_RTL (parms)
1250 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1251 SET_DECL_RTL (parms,
1252 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1254 if (PARM_PASSED_IN_MEMORY (parms))
1256 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1257 tree type;
1259 /* ??? Here we assume that the parm address is indexed
1260 off the frame pointer or arg pointer.
1261 If that is not true, we produce meaningless results,
1262 but do not crash. */
1263 if (GET_CODE (addr) == PLUS
1264 && CONST_INT_P (XEXP (addr, 1)))
1265 current_sym_value = INTVAL (XEXP (addr, 1));
1266 else
1267 current_sym_value = 0;
1269 if (REG_P (DECL_RTL (parms))
1270 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1271 type = DECL_ARG_TYPE (parms);
1272 else
1274 int original_sym_value = current_sym_value;
1276 /* This is the case where the parm is passed as an int or
1277 double and it is converted to a char, short or float
1278 and stored back in the parmlist. In this case, describe
1279 the parm with the variable's declared type, and adjust
1280 the address if the least significant bytes (which we are
1281 using) are not the first ones. */
1282 if (BYTES_BIG_ENDIAN
1283 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1284 current_sym_value +=
1285 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1286 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1288 if (MEM_P (DECL_RTL (parms))
1289 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1290 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1291 == CONST_INT)
1292 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1293 == current_sym_value))
1294 type = TREE_TYPE (parms);
1295 else
1297 current_sym_value = original_sym_value;
1298 type = DECL_ARG_TYPE (parms);
1302 PUT_SDB_DEF (name);
1303 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1304 PUT_SDB_SCL (C_ARG);
1305 PUT_SDB_TYPE (plain_type (type));
1306 PUT_SDB_ENDEF;
1308 else if (REG_P (DECL_RTL (parms)))
1310 rtx best_rtl;
1311 /* Parm passed in registers and lives in registers or nowhere. */
1313 /* If parm lives in a register, use that register;
1314 pretend the parm was passed there. It would be more consistent
1315 to describe the register where the parm was passed,
1316 but in practice that register usually holds something else. */
1317 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1318 best_rtl = DECL_RTL (parms);
1319 /* If the parm lives nowhere,
1320 use the register where it was passed. */
1321 else
1322 best_rtl = DECL_INCOMING_RTL (parms);
1324 PUT_SDB_DEF (name);
1325 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1326 PUT_SDB_SCL (C_REGPARM);
1327 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1328 PUT_SDB_ENDEF;
1330 else if (MEM_P (DECL_RTL (parms))
1331 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1333 /* Parm was passed in registers but lives on the stack. */
1335 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1336 in which case we want the value of that CONST_INT,
1337 or (MEM (REG ...)) or (MEM (MEM ...)),
1338 in which case we use a value of zero. */
1339 if (REG_P (XEXP (DECL_RTL (parms), 0))
1340 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1341 current_sym_value = 0;
1342 else
1343 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1345 /* Again, this assumes the offset is based on the arg pointer. */
1346 PUT_SDB_DEF (name);
1347 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1348 XEXP (DECL_RTL (parms), 0)));
1349 PUT_SDB_SCL (C_ARG);
1350 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1351 PUT_SDB_ENDEF;
1356 /* Output definitions for the places where parms live during the function,
1357 when different from where they were passed, when the parms were passed
1358 in memory.
1360 It is not useful to do this for parms passed in registers
1361 that live during the function in different registers, because it is
1362 impossible to look in the passed register for the passed value,
1363 so we use the within-the-function register to begin with.
1365 PARMS is a chain of PARM_DECL nodes. */
1367 static void
1368 sdbout_reg_parms (tree parms)
1370 for (; parms; parms = TREE_CHAIN (parms))
1371 if (DECL_NAME (parms)
1372 && TREE_TYPE (parms) != error_mark_node
1373 && DECL_RTL_SET_P (parms)
1374 && DECL_INCOMING_RTL (parms))
1376 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1378 /* Report parms that live in registers during the function
1379 but were passed in memory. */
1380 if (REG_P (DECL_RTL (parms))
1381 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1382 && PARM_PASSED_IN_MEMORY (parms))
1384 if (name == 0 || *name == 0)
1385 name = gen_fake_label ();
1386 PUT_SDB_DEF (name);
1387 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1388 PUT_SDB_SCL (C_REG);
1389 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1390 PUT_SDB_ENDEF;
1392 /* Report parms that live in memory but not where they were passed. */
1393 else if (MEM_P (DECL_RTL (parms))
1394 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1395 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1396 && PARM_PASSED_IN_MEMORY (parms)
1397 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1399 #if 0 /* ??? It is not clear yet what should replace this. */
1400 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1401 /* A parm declared char is really passed as an int,
1402 so it occupies the least significant bytes.
1403 On a big-endian machine those are not the low-numbered ones. */
1404 if (BYTES_BIG_ENDIAN
1405 && offset != -1
1406 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1407 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1408 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1409 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1410 #endif
1412 if (name == 0 || *name == 0)
1413 name = gen_fake_label ();
1414 PUT_SDB_DEF (name);
1415 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1416 (XEXP (DECL_RTL (parms), 0)));
1417 PUT_SDB_SCL (C_AUTO);
1418 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1419 PUT_SDB_ENDEF;
1425 /* Output early debug information for a global DECL. Called from
1426 rest_of_decl_compilation during parsing. */
1428 static void
1429 sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1431 /* NYI for non-dwarf. */
1434 /* Output late debug information for a global DECL after location
1435 information is available. */
1437 static void
1438 sdbout_late_global_decl (tree decl)
1440 if (VAR_P (decl) && !DECL_EXTERNAL (decl) && DECL_RTL_SET_P (decl))
1442 /* The COFF linker can move initialized global vars to the end.
1443 And that can screw up the symbol ordering. Defer those for
1444 sdbout_finish (). */
1445 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1446 sdbout_symbol (decl, 0);
1447 else
1448 vec_safe_push (deferred_global_decls, decl);
1450 /* Output COFF information for non-global file-scope initialized
1451 variables. */
1452 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1453 sdbout_toplevel_data (decl);
1457 /* Output initialized global vars at the end, in the order of
1458 definition. See comment in sdbout_global_decl. */
1460 static void
1461 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1463 size_t i;
1464 tree decl;
1466 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1467 sdbout_symbol (decl, 0);
1470 /* Describe the beginning of an internal block within a function.
1471 Also output descriptions of variables defined in this block.
1473 N is the number of the block, by order of beginning, counting from 1,
1474 and not counting the outermost (function top-level) block.
1475 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1476 if the count starts at 0 for the outermost one. */
1478 static void
1479 sdbout_begin_block (unsigned int line, unsigned int n)
1481 tree decl = current_function_decl;
1482 MAKE_LINE_SAFE (line);
1484 /* The SCO compiler does not emit a separate block for the function level
1485 scope, so we avoid it here also. */
1486 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1488 if (n == 1)
1490 /* Include the outermost BLOCK's variables in block 1. */
1491 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1492 sdbout_block (DECL_INITIAL (decl));
1494 /* If -g1, suppress all the internal symbols of functions
1495 except for arguments. */
1496 if (debug_info_level != DINFO_LEVEL_TERSE)
1498 do_block = n;
1499 sdbout_block (DECL_INITIAL (decl));
1502 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1503 sdbout_dequeue_anonymous_types ();
1504 #endif
1507 /* Describe the end line-number of an internal block within a function. */
1509 static void
1510 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1512 MAKE_LINE_SAFE (line);
1514 /* The SCO compiler does not emit a separate block for the function level
1515 scope, so we avoid it here also. */
1516 if (n != 1)
1517 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1520 /* Output a line number symbol entry for source file FILENAME and line
1521 number LINE. */
1523 static void
1524 sdbout_source_line (unsigned int line, unsigned int column ATTRIBUTE_UNUSED,
1525 const char *filename ATTRIBUTE_UNUSED,
1526 int discriminator ATTRIBUTE_UNUSED,
1527 bool is_stmt ATTRIBUTE_UNUSED)
1529 /* COFF relative line numbers must be positive. */
1530 if ((int) line > sdb_begin_function_line)
1532 #ifdef SDB_OUTPUT_SOURCE_LINE
1533 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1534 #else
1535 fprintf (asm_out_file, "\t.ln\t%d\n",
1536 ((sdb_begin_function_line > -1)
1537 ? line - sdb_begin_function_line : 1));
1538 #endif
1542 /* Output sdb info for the current function name.
1543 Called from assemble_start_function. */
1545 static void
1546 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1548 sdbout_symbol (current_function_decl, 0);
1551 /* Called at beginning of function body after prologue. Record the
1552 function's starting line number, so we can output relative line numbers
1553 for the other lines. Describe beginning of outermost block. Also
1554 describe the parameter list. */
1556 static void
1557 sdbout_begin_prologue (unsigned int line, unsigned int column ATTRIBUTE_UNUSED,
1558 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 #include "gt-sdbout.h"