* config/i386/i386.h (TARGET_SUPPORTS_WIDE_INT): New define.
[official-gcc.git] / gcc / sdbout.c
blobb4f7325ee3c22286a53f69c11650a4f949d35325
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, /* function_decl */
307 sdbout_global_decl, /* global_decl */
308 sdbout_symbol, /* type_decl */
309 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
310 debug_nothing_tree, /* deferred_inline_function */
311 debug_nothing_tree, /* outlining_inline_function */
312 sdbout_label, /* label */
313 debug_nothing_int, /* handle_pch */
314 debug_nothing_rtx_insn, /* var_location */
315 debug_nothing_void, /* switch_text_section */
316 debug_nothing_tree_tree, /* set_name */
317 0, /* start_end_main_source_file */
318 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
321 /* Return a unique string to name an anonymous type. */
323 static char *
324 gen_fake_label (void)
326 char label[10];
327 char *labelstr;
328 sprintf (label, ".%dfake", unnamed_struct_number);
329 unnamed_struct_number++;
330 labelstr = xstrdup (label);
331 return labelstr;
334 /* Return the number which describes TYPE for SDB.
335 For pointers, etc., this function is recursive.
336 Each record, union or enumeral type must already have had a
337 tag number output. */
339 /* The number is given by d6d5d4d3d2d1bbbb
340 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
341 Thus, char *foo () has bbbb=T_CHAR
342 d1=D_FCN
343 d2=D_PTR
344 N_BTMASK= 017 1111 basic type field.
345 N_TSHIFT= 2 derived type shift
346 N_BTSHFT= 4 Basic type shift */
348 /* Produce the number that describes a pointer, function or array type.
349 PREV is the number describing the target, value or element type.
350 DT_type describes how to transform that type. */
351 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
352 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
353 | ((int) DT_type << (int) N_BTSHFT) \
354 | ((PREV) & (int) N_BTMASK))
356 /* Number of elements used in sdb_dims. */
357 static int sdb_n_dims = 0;
359 /* Table of array dimensions of current type. */
360 static int sdb_dims[SDB_MAX_DIM];
362 /* Size of outermost array currently being processed. */
363 static int sdb_type_size = -1;
365 static int
366 plain_type (tree type)
368 int val = plain_type_1 (type, 0);
370 /* If we have already saved up some array dimensions, print them now. */
371 if (sdb_n_dims > 0)
373 int i;
374 PUT_SDB_START_DIM;
375 for (i = sdb_n_dims - 1; i > 0; i--)
376 PUT_SDB_NEXT_DIM (sdb_dims[i]);
377 PUT_SDB_LAST_DIM (sdb_dims[0]);
378 sdb_n_dims = 0;
380 sdb_type_size = int_size_in_bytes (type);
381 /* Don't kill sdb if type is not laid out or has variable size. */
382 if (sdb_type_size < 0)
383 sdb_type_size = 0;
385 /* If we have computed the size of an array containing this type,
386 print it now. */
387 if (sdb_type_size >= 0)
389 PUT_SDB_SIZE (sdb_type_size);
390 sdb_type_size = -1;
392 return val;
395 static int
396 template_name_p (tree name)
398 const char *ptr = IDENTIFIER_POINTER (name);
399 while (*ptr && *ptr != '<')
400 ptr++;
402 return *ptr != '\0';
405 static void
406 sdbout_record_type_name (tree type)
408 const char *name = 0;
409 int no_name;
411 if (KNOWN_TYPE_TAG (type))
412 return;
414 if (TYPE_NAME (type) != 0)
416 tree t = 0;
418 /* Find the IDENTIFIER_NODE for the type name. */
419 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
420 t = TYPE_NAME (type);
421 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
423 t = DECL_NAME (TYPE_NAME (type));
424 /* The DECL_NAME for templates includes "<>", which breaks
425 most assemblers. Use its assembler name instead, which
426 has been mangled into being safe. */
427 if (t && template_name_p (t))
428 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
431 /* Now get the name as a string, or invent one. */
432 if (t != NULL_TREE)
433 name = IDENTIFIER_POINTER (t);
436 no_name = (name == 0 || *name == 0);
437 if (no_name)
438 name = gen_fake_label ();
440 SET_KNOWN_TYPE_TAG (type, name);
441 #ifdef SDB_ALLOW_FORWARD_REFERENCES
442 if (no_name)
443 sdbout_queue_anonymous_type (type);
444 #endif
447 /* Return the .type value for type TYPE.
449 LEVEL indicates how many levels deep we have recursed into the type.
450 The SDB debug format can only represent 6 derived levels of types.
451 After that, we must output inaccurate debug info. We deliberately
452 stop before the 7th level, so that ADA recursive types will not give an
453 infinite loop. */
455 static int
456 plain_type_1 (tree type, int level)
458 if (type == 0)
459 type = void_type_node;
460 else if (type == error_mark_node)
461 type = integer_type_node;
462 else
463 type = TYPE_MAIN_VARIANT (type);
465 switch (TREE_CODE (type))
467 case VOID_TYPE:
468 case NULLPTR_TYPE:
469 return T_VOID;
470 case BOOLEAN_TYPE:
471 case INTEGER_TYPE:
473 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
475 /* Carefully distinguish all the standard types of C,
476 without messing up if the language is not C.
477 Note that we check only for the names that contain spaces;
478 other names might occur by coincidence in other languages. */
479 if (TYPE_NAME (type) != 0
480 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
481 && DECL_NAME (TYPE_NAME (type)) != 0
482 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
484 const char *const name
485 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
487 if (!strcmp (name, "char"))
488 return T_CHAR;
489 if (!strcmp (name, "unsigned char"))
490 return T_UCHAR;
491 if (!strcmp (name, "signed char"))
492 return T_CHAR;
493 if (!strcmp (name, "int"))
494 return T_INT;
495 if (!strcmp (name, "unsigned int"))
496 return T_UINT;
497 if (!strcmp (name, "short int"))
498 return T_SHORT;
499 if (!strcmp (name, "short unsigned int"))
500 return T_USHORT;
501 if (!strcmp (name, "long int"))
502 return T_LONG;
503 if (!strcmp (name, "long unsigned int"))
504 return T_ULONG;
507 if (size == INT_TYPE_SIZE)
508 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
509 if (size == CHAR_TYPE_SIZE)
510 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
511 if (size == SHORT_TYPE_SIZE)
512 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
513 if (size == LONG_TYPE_SIZE)
514 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
515 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
516 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
517 return 0;
520 case REAL_TYPE:
522 int precision = TYPE_PRECISION (type);
523 if (precision == FLOAT_TYPE_SIZE)
524 return T_FLOAT;
525 if (precision == DOUBLE_TYPE_SIZE)
526 return T_DOUBLE;
527 #ifdef EXTENDED_SDB_BASIC_TYPES
528 if (precision == LONG_DOUBLE_TYPE_SIZE)
529 return T_LNGDBL;
530 #else
531 if (precision == LONG_DOUBLE_TYPE_SIZE)
532 return T_DOUBLE; /* better than nothing */
533 #endif
534 return 0;
537 case ARRAY_TYPE:
539 int m;
540 if (level >= 6)
541 return T_VOID;
542 else
543 m = plain_type_1 (TREE_TYPE (type), level+1);
544 if (sdb_n_dims < SDB_MAX_DIM)
545 sdb_dims[sdb_n_dims++]
546 = (TYPE_DOMAIN (type)
547 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
548 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
549 && tree_fits_shwi_p (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
550 && tree_fits_shwi_p (TYPE_MIN_VALUE (TYPE_DOMAIN (type)))
551 ? (tree_to_shwi (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
552 - tree_to_shwi (TYPE_MIN_VALUE (TYPE_DOMAIN (type))) + 1)
553 : 0);
555 return PUSH_DERIVED_LEVEL (DT_ARY, m);
558 case RECORD_TYPE:
559 case UNION_TYPE:
560 case QUAL_UNION_TYPE:
561 case ENUMERAL_TYPE:
563 const char *tag;
564 #ifdef SDB_ALLOW_FORWARD_REFERENCES
565 sdbout_record_type_name (type);
566 #endif
567 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
568 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
569 #ifdef SDB_ALLOW_FORWARD_REFERENCES
570 || TYPE_MODE (type) != VOIDmode
571 #endif
573 #endif
575 /* Output the referenced structure tag name
576 only if the .def has already been finished.
577 At least on 386, the Unix assembler
578 cannot handle forward references to tags. */
579 /* But the 88100, it requires them, sigh... */
580 /* And the MIPS requires unknown refs as well... */
581 tag = KNOWN_TYPE_TAG (type);
582 PUT_SDB_TAG (tag);
583 /* These 3 lines used to follow the close brace.
584 However, a size of 0 without a tag implies a tag of 0,
585 so if we don't know a tag, we can't mention the size. */
586 sdb_type_size = int_size_in_bytes (type);
587 if (sdb_type_size < 0)
588 sdb_type_size = 0;
590 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
591 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
592 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
593 : T_ENUM);
595 case POINTER_TYPE:
596 case REFERENCE_TYPE:
598 int m;
599 if (level >= 6)
600 return T_VOID;
601 else
602 m = plain_type_1 (TREE_TYPE (type), level+1);
603 return PUSH_DERIVED_LEVEL (DT_PTR, m);
605 case FUNCTION_TYPE:
606 case METHOD_TYPE:
608 int m;
609 if (level >= 6)
610 return T_VOID;
611 else
612 m = plain_type_1 (TREE_TYPE (type), level+1);
613 return PUSH_DERIVED_LEVEL (DT_FCN, m);
615 default:
616 return 0;
620 /* Output the symbols defined in block number DO_BLOCK.
622 This function works by walking the tree structure of blocks,
623 counting blocks until it finds the desired block. */
625 static int do_block = 0;
627 static void
628 sdbout_block (tree block)
630 while (block)
632 /* Ignore blocks never expanded or otherwise marked as real. */
633 if (TREE_USED (block))
635 /* When we reach the specified block, output its symbols. */
636 if (BLOCK_NUMBER (block) == do_block)
637 sdbout_syms (BLOCK_VARS (block));
639 /* If we are past the specified block, stop the scan. */
640 if (BLOCK_NUMBER (block) > do_block)
641 return;
643 /* Scan the blocks within this block. */
644 sdbout_block (BLOCK_SUBBLOCKS (block));
647 block = BLOCK_CHAIN (block);
651 /* Call sdbout_symbol on each decl in the chain SYMS. */
653 static void
654 sdbout_syms (tree syms)
656 while (syms)
658 if (TREE_CODE (syms) != LABEL_DECL)
659 sdbout_symbol (syms, 1);
660 syms = TREE_CHAIN (syms);
664 /* Output SDB information for a symbol described by DECL.
665 LOCAL is nonzero if the symbol is not file-scope. */
667 void
668 sdbout_symbol (tree decl, int local)
670 tree type = TREE_TYPE (decl);
671 tree context = NULL_TREE;
672 rtx value;
673 int regno = -1;
674 const char *name;
676 /* If we are called before sdbout_init is run, just save the symbol
677 for later. */
678 if (!sdbout_initialized)
680 preinit_symbols = tree_cons (0, decl, preinit_symbols);
681 return;
684 sdbout_one_type (type);
686 switch (TREE_CODE (decl))
688 case CONST_DECL:
689 /* Enum values are defined by defining the enum type. */
690 return;
692 case FUNCTION_DECL:
693 /* Don't mention a nested function under its parent. */
694 context = decl_function_context (decl);
695 if (context == current_function_decl)
696 return;
697 /* Check DECL_INITIAL to distinguish declarations from definitions.
698 Don't output debug info here for declarations; they will have
699 a DECL_INITIAL value of 0. */
700 if (! DECL_INITIAL (decl))
701 return;
702 if (!MEM_P (DECL_RTL (decl))
703 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
704 return;
705 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
706 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
707 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
708 break;
710 case TYPE_DECL:
711 /* Done with tagged types. */
712 if (DECL_NAME (decl) == 0)
713 return;
714 if (DECL_IGNORED_P (decl))
715 return;
716 /* Don't output intrinsic types. GAS chokes on SDB .def
717 statements that contain identifiers with embedded spaces
718 (eg "unsigned long"). */
719 if (DECL_IS_BUILTIN (decl))
720 return;
722 /* Output typedef name. */
723 if (template_name_p (DECL_NAME (decl)))
724 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
725 else
726 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
727 PUT_SDB_SCL (C_TPDEF);
728 break;
730 case PARM_DECL:
731 /* Parm decls go in their own separate chains
732 and are output by sdbout_reg_parms and sdbout_parms. */
733 gcc_unreachable ();
735 case VAR_DECL:
736 /* Don't mention a variable that is external.
737 Let the file that defines it describe it. */
738 if (DECL_EXTERNAL (decl))
739 return;
741 /* Ignore __FUNCTION__, etc. */
742 if (DECL_IGNORED_P (decl))
743 return;
745 /* If there was an error in the declaration, don't dump core
746 if there is no RTL associated with the variable doesn't
747 exist. */
748 if (!DECL_RTL_SET_P (decl))
749 return;
751 value = DECL_RTL (decl);
753 if (!is_global_var (decl))
754 value = eliminate_regs (value, VOIDmode, NULL_RTX);
756 SET_DECL_RTL (decl, value);
757 #ifdef LEAF_REG_REMAP
758 if (crtl->uses_only_leaf_regs)
759 leaf_renumber_regs_insn (value);
760 #endif
762 /* Don't mention a variable at all
763 if it was completely optimized into nothingness.
765 If DECL was from an inline function, then its rtl
766 is not identically the rtl that was used in this
767 particular compilation. */
768 if (REG_P (value))
770 regno = REGNO (value);
771 if (regno >= FIRST_PSEUDO_REGISTER)
772 return;
774 else if (GET_CODE (value) == SUBREG)
776 while (GET_CODE (value) == SUBREG)
777 value = SUBREG_REG (value);
778 if (REG_P (value))
780 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
781 return;
783 regno = REGNO (alter_subreg (&value, true));
784 SET_DECL_RTL (decl, value);
786 /* Don't output anything if an auto variable
787 gets RTL that is static.
788 GAS version 2.2 can't handle such output. */
789 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
790 && ! TREE_STATIC (decl))
791 return;
793 /* Emit any structure, union, or enum type that has not been output.
794 This occurs for tag-less structs (et al) used to declare variables
795 within functions. */
796 if (TREE_CODE (type) == ENUMERAL_TYPE
797 || TREE_CODE (type) == RECORD_TYPE
798 || TREE_CODE (type) == UNION_TYPE
799 || TREE_CODE (type) == QUAL_UNION_TYPE)
801 if (COMPLETE_TYPE_P (type) /* not a forward reference */
802 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
803 sdbout_one_type (type);
806 /* Defer SDB information for top-level initialized variables! */
807 if (! local
808 && MEM_P (value)
809 && DECL_INITIAL (decl))
810 return;
812 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
813 For now, avoid crashing. */
814 if (DECL_NAME (decl) == NULL_TREE)
815 return;
817 /* Record the name for, starting a symtab entry. */
818 if (local)
819 name = IDENTIFIER_POINTER (DECL_NAME (decl));
820 else
821 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
823 if (MEM_P (value)
824 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
826 PUT_SDB_DEF (name);
827 if (TREE_PUBLIC (decl))
829 PUT_SDB_VAL (XEXP (value, 0));
830 PUT_SDB_SCL (C_EXT);
832 else
834 PUT_SDB_VAL (XEXP (value, 0));
835 PUT_SDB_SCL (C_STAT);
838 else if (regno >= 0)
840 PUT_SDB_DEF (name);
841 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
842 PUT_SDB_SCL (C_REG);
844 else if (MEM_P (value)
845 && (MEM_P (XEXP (value, 0))
846 || (REG_P (XEXP (value, 0))
847 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
848 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
849 /* If the value is indirect by memory or by a register
850 that isn't the frame pointer
851 then it means the object is variable-sized and address through
852 that register or stack slot. COFF has no way to represent this
853 so all we can do is output the variable as a pointer. */
855 PUT_SDB_DEF (name);
856 if (REG_P (XEXP (value, 0)))
858 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
859 PUT_SDB_SCL (C_REG);
861 else
863 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
864 (CONST_INT...)))).
865 We want the value of that CONST_INT. */
866 /* Encore compiler hates a newline in a macro arg, it seems. */
867 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
868 (XEXP (XEXP (value, 0), 0)));
869 PUT_SDB_SCL (C_AUTO);
872 /* Effectively do build_pointer_type, but don't cache this type,
873 since it might be temporary whereas the type it points to
874 might have been saved for inlining. */
875 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
876 type = make_node (POINTER_TYPE);
877 TREE_TYPE (type) = TREE_TYPE (decl);
879 else if (MEM_P (value)
880 && ((GET_CODE (XEXP (value, 0)) == PLUS
881 && REG_P (XEXP (XEXP (value, 0), 0))
882 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
883 /* This is for variables which are at offset zero from
884 the frame pointer. This happens on the Alpha.
885 Non-frame pointer registers are excluded above. */
886 || (REG_P (XEXP (value, 0)))))
888 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
889 or (MEM (REG...)). We want the value of that CONST_INT
890 or zero. */
891 PUT_SDB_DEF (name);
892 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
893 PUT_SDB_SCL (C_AUTO);
895 else
897 /* It is something we don't know how to represent for SDB. */
898 return;
900 break;
902 default:
903 break;
905 PUT_SDB_TYPE (plain_type (type));
906 PUT_SDB_ENDEF;
909 /* Output SDB information for a top-level initialized variable
910 that has been delayed. */
912 static void
913 sdbout_toplevel_data (tree decl)
915 tree type = TREE_TYPE (decl);
917 if (DECL_IGNORED_P (decl))
918 return;
920 gcc_assert (TREE_CODE (decl) == VAR_DECL);
921 gcc_assert (MEM_P (DECL_RTL (decl)));
922 gcc_assert (DECL_INITIAL (decl));
924 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
925 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
926 if (TREE_PUBLIC (decl))
928 PUT_SDB_SCL (C_EXT);
930 else
932 PUT_SDB_SCL (C_STAT);
934 PUT_SDB_TYPE (plain_type (type));
935 PUT_SDB_ENDEF;
938 #ifdef SDB_ALLOW_FORWARD_REFERENCES
940 /* Machinery to record and output anonymous types. */
942 static void
943 sdbout_queue_anonymous_type (tree type)
945 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
948 static void
949 sdbout_dequeue_anonymous_types (void)
951 tree types, link;
953 while (anonymous_types)
955 types = nreverse (anonymous_types);
956 anonymous_types = NULL_TREE;
958 for (link = types; link; link = TREE_CHAIN (link))
960 tree type = TREE_VALUE (link);
962 if (type && ! TREE_ASM_WRITTEN (type))
963 sdbout_one_type (type);
968 #endif
970 /* Given a chain of ..._TYPE nodes, all of which have names,
971 output definitions of those names, as typedefs. */
973 void
974 sdbout_types (tree types)
976 tree link;
978 for (link = types; link; link = TREE_CHAIN (link))
979 sdbout_one_type (link);
981 #ifdef SDB_ALLOW_FORWARD_REFERENCES
982 sdbout_dequeue_anonymous_types ();
983 #endif
986 static void
987 sdbout_type (tree type)
989 if (type == error_mark_node)
990 type = integer_type_node;
991 PUT_SDB_TYPE (plain_type (type));
994 /* Output types of the fields of type TYPE, if they are structs.
996 Formerly did not chase through pointer types, since that could be circular.
997 They must come before TYPE, since forward refs are not allowed.
998 Now james@bigtex.cactus.org says to try them. */
1000 static void
1001 sdbout_field_types (tree type)
1003 tree tail;
1005 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1006 /* This condition should match the one for emitting the actual
1007 members below. */
1008 if (TREE_CODE (tail) == FIELD_DECL
1009 && DECL_NAME (tail)
1010 && DECL_SIZE (tail)
1011 && tree_fits_uhwi_p (DECL_SIZE (tail))
1012 && tree_fits_shwi_p (bit_position (tail)))
1014 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1015 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1016 else
1017 sdbout_one_type (TREE_TYPE (tail));
1021 /* Use this to put out the top level defined record and union types
1022 for later reference. If this is a struct with a name, then put that
1023 name out. Other unnamed structs will have .xxfake labels generated so
1024 that they may be referred to later.
1025 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1026 It may NOT be called recursively. */
1028 static void
1029 sdbout_one_type (tree type)
1031 if (current_function_decl != NULL_TREE
1032 && DECL_SECTION_NAME (current_function_decl) != NULL)
1033 ; /* Don't change section amid function. */
1034 else
1035 switch_to_section (current_function_section ());
1037 switch (TREE_CODE (type))
1039 case RECORD_TYPE:
1040 case UNION_TYPE:
1041 case QUAL_UNION_TYPE:
1042 case ENUMERAL_TYPE:
1043 type = TYPE_MAIN_VARIANT (type);
1044 /* Don't output a type twice. */
1045 if (TREE_ASM_WRITTEN (type))
1046 /* James said test TREE_ASM_BEING_WRITTEN here. */
1047 return;
1049 /* Output nothing if type is not yet defined. */
1050 if (!COMPLETE_TYPE_P (type))
1051 return;
1053 TREE_ASM_WRITTEN (type) = 1;
1055 /* This is reputed to cause trouble with the following case,
1056 but perhaps checking TYPE_SIZE above will fix it. */
1058 /* Here is a testcase:
1060 struct foo {
1061 struct badstr *bbb;
1062 } forwardref;
1064 typedef struct intermediate {
1065 int aaaa;
1066 } intermediate_ref;
1068 typedef struct badstr {
1069 int ccccc;
1070 } badtype; */
1072 /* This change, which ought to make better output,
1073 used to make the COFF assembler unhappy.
1074 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1075 /* Before really doing anything, output types we want to refer to. */
1076 /* Note that in version 1 the following two lines
1077 are not used if forward references are in use. */
1078 if (TREE_CODE (type) != ENUMERAL_TYPE)
1079 sdbout_field_types (type);
1081 /* Output a structure type. */
1083 int size = int_size_in_bytes (type);
1084 int member_scl = 0;
1085 tree tem;
1087 /* Record the type tag, but not in its permanent place just yet. */
1088 sdbout_record_type_name (type);
1090 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1092 switch (TREE_CODE (type))
1094 case UNION_TYPE:
1095 case QUAL_UNION_TYPE:
1096 PUT_SDB_SCL (C_UNTAG);
1097 PUT_SDB_TYPE (T_UNION);
1098 member_scl = C_MOU;
1099 break;
1101 case RECORD_TYPE:
1102 PUT_SDB_SCL (C_STRTAG);
1103 PUT_SDB_TYPE (T_STRUCT);
1104 member_scl = C_MOS;
1105 break;
1107 case ENUMERAL_TYPE:
1108 PUT_SDB_SCL (C_ENTAG);
1109 PUT_SDB_TYPE (T_ENUM);
1110 member_scl = C_MOE;
1111 break;
1113 default:
1114 break;
1117 PUT_SDB_SIZE (size);
1118 PUT_SDB_ENDEF;
1120 /* Print out the base class information with fields
1121 named after the types they hold. */
1122 /* This is only relevant to aggregate types. TYPE_BINFO is used
1123 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1124 case. */
1125 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1127 int i;
1128 tree binfo, child;
1130 for (binfo = TYPE_BINFO (type), i = 0;
1131 BINFO_BASE_ITERATE (binfo, i, child); i++)
1133 tree child_type = BINFO_TYPE (child);
1134 tree child_type_name;
1136 if (TYPE_NAME (child_type) == 0)
1137 continue;
1138 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1139 child_type_name = TYPE_NAME (child_type);
1140 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1142 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1143 if (child_type_name && template_name_p (child_type_name))
1144 child_type_name
1145 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1147 else
1148 continue;
1150 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1151 PUT_SDB_INT_VAL (tree_to_shwi (BINFO_OFFSET (child)));
1152 PUT_SDB_SCL (member_scl);
1153 sdbout_type (BINFO_TYPE (child));
1154 PUT_SDB_ENDEF;
1158 /* Output the individual fields. */
1160 if (TREE_CODE (type) == ENUMERAL_TYPE)
1162 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1164 tree value = TREE_VALUE (tem);
1166 if (TREE_CODE (value) == CONST_DECL)
1167 value = DECL_INITIAL (value);
1169 if (tree_fits_shwi_p (value))
1171 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1172 PUT_SDB_INT_VAL (tree_to_shwi (value));
1173 PUT_SDB_SCL (C_MOE);
1174 PUT_SDB_TYPE (T_MOE);
1175 PUT_SDB_ENDEF;
1179 else /* record or union type */
1180 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1181 /* Output the name, type, position (in bits), size (in bits)
1182 of each field. */
1184 /* Omit here the nameless fields that are used to skip bits.
1185 Also omit fields with variable size or position.
1186 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1187 if (TREE_CODE (tem) == FIELD_DECL
1188 && DECL_NAME (tem)
1189 && DECL_SIZE (tem)
1190 && tree_fits_uhwi_p (DECL_SIZE (tem))
1191 && tree_fits_shwi_p (bit_position (tem)))
1193 const char *name;
1195 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1196 PUT_SDB_DEF (name);
1197 if (DECL_BIT_FIELD_TYPE (tem))
1199 PUT_SDB_INT_VAL (int_bit_position (tem));
1200 PUT_SDB_SCL (C_FIELD);
1201 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1202 PUT_SDB_SIZE (tree_to_uhwi (DECL_SIZE (tem)));
1204 else
1206 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1207 PUT_SDB_SCL (member_scl);
1208 sdbout_type (TREE_TYPE (tem));
1210 PUT_SDB_ENDEF;
1212 /* Output end of a structure,union, or enumeral definition. */
1214 PUT_SDB_PLAIN_DEF ("eos");
1215 PUT_SDB_INT_VAL (size);
1216 PUT_SDB_SCL (C_EOS);
1217 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1218 PUT_SDB_SIZE (size);
1219 PUT_SDB_ENDEF;
1220 break;
1223 default:
1224 break;
1228 /* The following two functions output definitions of function parameters.
1229 Each parameter gets a definition locating it in the parameter list.
1230 Each parameter that is a register variable gets a second definition
1231 locating it in the register.
1233 Printing or argument lists in gdb uses the definitions that
1234 locate in the parameter list. But reference to the variable in
1235 expressions uses preferentially the definition as a register. */
1237 /* Output definitions, referring to storage in the parmlist,
1238 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1240 static void
1241 sdbout_parms (tree parms)
1243 for (; parms; parms = TREE_CHAIN (parms))
1244 if (DECL_NAME (parms)
1245 && TREE_TYPE (parms) != error_mark_node
1246 && DECL_RTL_SET_P (parms)
1247 && DECL_INCOMING_RTL (parms))
1249 int current_sym_value = 0;
1250 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1252 if (name == 0 || *name == 0)
1253 name = gen_fake_label ();
1255 /* Perform any necessary register eliminations on the parameter's rtl,
1256 so that the debugging output will be accurate. */
1257 DECL_INCOMING_RTL (parms)
1258 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1259 SET_DECL_RTL (parms,
1260 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1262 if (PARM_PASSED_IN_MEMORY (parms))
1264 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1265 tree type;
1267 /* ??? Here we assume that the parm address is indexed
1268 off the frame pointer or arg pointer.
1269 If that is not true, we produce meaningless results,
1270 but do not crash. */
1271 if (GET_CODE (addr) == PLUS
1272 && CONST_INT_P (XEXP (addr, 1)))
1273 current_sym_value = INTVAL (XEXP (addr, 1));
1274 else
1275 current_sym_value = 0;
1277 if (REG_P (DECL_RTL (parms))
1278 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1279 type = DECL_ARG_TYPE (parms);
1280 else
1282 int original_sym_value = current_sym_value;
1284 /* This is the case where the parm is passed as an int or
1285 double and it is converted to a char, short or float
1286 and stored back in the parmlist. In this case, describe
1287 the parm with the variable's declared type, and adjust
1288 the address if the least significant bytes (which we are
1289 using) are not the first ones. */
1290 if (BYTES_BIG_ENDIAN
1291 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1292 current_sym_value +=
1293 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1294 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1296 if (MEM_P (DECL_RTL (parms))
1297 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1298 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1299 == CONST_INT)
1300 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1301 == current_sym_value))
1302 type = TREE_TYPE (parms);
1303 else
1305 current_sym_value = original_sym_value;
1306 type = DECL_ARG_TYPE (parms);
1310 PUT_SDB_DEF (name);
1311 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1312 PUT_SDB_SCL (C_ARG);
1313 PUT_SDB_TYPE (plain_type (type));
1314 PUT_SDB_ENDEF;
1316 else if (REG_P (DECL_RTL (parms)))
1318 rtx best_rtl;
1319 /* Parm passed in registers and lives in registers or nowhere. */
1321 /* If parm lives in a register, use that register;
1322 pretend the parm was passed there. It would be more consistent
1323 to describe the register where the parm was passed,
1324 but in practice that register usually holds something else. */
1325 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1326 best_rtl = DECL_RTL (parms);
1327 /* If the parm lives nowhere,
1328 use the register where it was passed. */
1329 else
1330 best_rtl = DECL_INCOMING_RTL (parms);
1332 PUT_SDB_DEF (name);
1333 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1334 PUT_SDB_SCL (C_REGPARM);
1335 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1336 PUT_SDB_ENDEF;
1338 else if (MEM_P (DECL_RTL (parms))
1339 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1341 /* Parm was passed in registers but lives on the stack. */
1343 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1344 in which case we want the value of that CONST_INT,
1345 or (MEM (REG ...)) or (MEM (MEM ...)),
1346 in which case we use a value of zero. */
1347 if (REG_P (XEXP (DECL_RTL (parms), 0))
1348 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1349 current_sym_value = 0;
1350 else
1351 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1353 /* Again, this assumes the offset is based on the arg pointer. */
1354 PUT_SDB_DEF (name);
1355 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1356 XEXP (DECL_RTL (parms), 0)));
1357 PUT_SDB_SCL (C_ARG);
1358 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1359 PUT_SDB_ENDEF;
1364 /* Output definitions for the places where parms live during the function,
1365 when different from where they were passed, when the parms were passed
1366 in memory.
1368 It is not useful to do this for parms passed in registers
1369 that live during the function in different registers, because it is
1370 impossible to look in the passed register for the passed value,
1371 so we use the within-the-function register to begin with.
1373 PARMS is a chain of PARM_DECL nodes. */
1375 static void
1376 sdbout_reg_parms (tree parms)
1378 for (; parms; parms = TREE_CHAIN (parms))
1379 if (DECL_NAME (parms)
1380 && TREE_TYPE (parms) != error_mark_node
1381 && DECL_RTL_SET_P (parms)
1382 && DECL_INCOMING_RTL (parms))
1384 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1386 /* Report parms that live in registers during the function
1387 but were passed in memory. */
1388 if (REG_P (DECL_RTL (parms))
1389 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1390 && PARM_PASSED_IN_MEMORY (parms))
1392 if (name == 0 || *name == 0)
1393 name = gen_fake_label ();
1394 PUT_SDB_DEF (name);
1395 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1396 PUT_SDB_SCL (C_REG);
1397 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1398 PUT_SDB_ENDEF;
1400 /* Report parms that live in memory but not where they were passed. */
1401 else if (MEM_P (DECL_RTL (parms))
1402 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1403 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1404 && PARM_PASSED_IN_MEMORY (parms)
1405 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1407 #if 0 /* ??? It is not clear yet what should replace this. */
1408 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1409 /* A parm declared char is really passed as an int,
1410 so it occupies the least significant bytes.
1411 On a big-endian machine those are not the low-numbered ones. */
1412 if (BYTES_BIG_ENDIAN
1413 && offset != -1
1414 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1415 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1416 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1417 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1418 #endif
1420 if (name == 0 || *name == 0)
1421 name = gen_fake_label ();
1422 PUT_SDB_DEF (name);
1423 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1424 (XEXP (DECL_RTL (parms), 0)));
1425 PUT_SDB_SCL (C_AUTO);
1426 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1427 PUT_SDB_ENDEF;
1433 /* Output debug information for a global DECL. Called from toplev.c
1434 after compilation proper has finished. */
1436 static void
1437 sdbout_global_decl (tree decl)
1439 if (TREE_CODE (decl) == VAR_DECL
1440 && !DECL_EXTERNAL (decl)
1441 && DECL_RTL_SET_P (decl))
1443 /* The COFF linker can move initialized global vars to the end.
1444 And that can screw up the symbol ordering. Defer those for
1445 sdbout_finish (). */
1446 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1447 sdbout_symbol (decl, 0);
1448 else
1449 vec_safe_push (deferred_global_decls, decl);
1451 /* Output COFF information for non-global file-scope initialized
1452 variables. */
1453 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1454 sdbout_toplevel_data (decl);
1458 /* Output initialized global vars at the end, in the order of
1459 definition. See comment in sdbout_global_decl. */
1461 static void
1462 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1464 size_t i;
1465 tree decl;
1467 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1468 sdbout_symbol (decl, 0);
1471 /* Describe the beginning of an internal block within a function.
1472 Also output descriptions of variables defined in this block.
1474 N is the number of the block, by order of beginning, counting from 1,
1475 and not counting the outermost (function top-level) block.
1476 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1477 if the count starts at 0 for the outermost one. */
1479 static void
1480 sdbout_begin_block (unsigned int line, unsigned int n)
1482 tree decl = current_function_decl;
1483 MAKE_LINE_SAFE (line);
1485 /* The SCO compiler does not emit a separate block for the function level
1486 scope, so we avoid it here also. */
1487 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1489 if (n == 1)
1491 /* Include the outermost BLOCK's variables in block 1. */
1492 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1493 sdbout_block (DECL_INITIAL (decl));
1495 /* If -g1, suppress all the internal symbols of functions
1496 except for arguments. */
1497 if (debug_info_level != DINFO_LEVEL_TERSE)
1499 do_block = n;
1500 sdbout_block (DECL_INITIAL (decl));
1503 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1504 sdbout_dequeue_anonymous_types ();
1505 #endif
1508 /* Describe the end line-number of an internal block within a function. */
1510 static void
1511 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1513 MAKE_LINE_SAFE (line);
1515 /* The SCO compiler does not emit a separate block for the function level
1516 scope, so we avoid it here also. */
1517 if (n != 1)
1518 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1521 /* Output a line number symbol entry for source file FILENAME and line
1522 number LINE. */
1524 static void
1525 sdbout_source_line (unsigned int line, 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, const char *file ATTRIBUTE_UNUSED)
1559 sdbout_end_prologue (line, file);
1562 static void
1563 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1565 sdb_begin_function_line = line - 1;
1566 PUT_SDB_FUNCTION_START (line);
1567 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1568 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1571 /* Called at end of function (before epilogue).
1572 Describe end of outermost block. */
1574 static void
1575 sdbout_end_function (unsigned int line)
1577 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1578 sdbout_dequeue_anonymous_types ();
1579 #endif
1581 MAKE_LINE_SAFE (line);
1582 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1584 /* Indicate we are between functions, for line-number output. */
1585 sdb_begin_function_line = -1;
1588 /* Output sdb info for the absolute end of a function.
1589 Called after the epilogue is output. */
1591 static void
1592 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1593 const char *file ATTRIBUTE_UNUSED)
1595 const char *const name ATTRIBUTE_UNUSED
1596 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1598 #ifdef PUT_SDB_EPILOGUE_END
1599 PUT_SDB_EPILOGUE_END (name);
1600 #else
1601 fprintf (asm_out_file, "\t.def\t");
1602 assemble_name (asm_out_file, name);
1603 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1604 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1605 #endif
1608 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1609 is present. */
1611 static void
1612 sdbout_label (rtx_code_label *insn)
1614 PUT_SDB_DEF (LABEL_NAME (insn));
1615 PUT_SDB_VAL (insn);
1616 PUT_SDB_SCL (C_LABEL);
1617 PUT_SDB_TYPE (T_NULL);
1618 PUT_SDB_ENDEF;
1621 /* Change to reading from a new source file. */
1623 static void
1624 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1625 const char *filename ATTRIBUTE_UNUSED)
1629 /* Revert to reading a previous source file. */
1631 static void
1632 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1636 /* Set up for SDB output at the start of compilation. */
1638 static void
1639 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1641 tree t;
1643 vec_alloc (deferred_global_decls, 12);
1645 /* Emit debug information which was queued by sdbout_symbol before
1646 we got here. */
1647 sdbout_initialized = true;
1649 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1650 sdbout_symbol (TREE_VALUE (t), 0);
1651 preinit_symbols = 0;
1654 #endif /* SDB_DEBUGGING_INFO */
1656 #include "gt-sdbout.h"