omp-low.h (replace_oacc_fn_attrib, [...]): Declare.
[gcc.git] / gcc / sdbout.c
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2015 Free Software Foundation, Inc.
3
4 This file is part of GCC.
5
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.
10
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.
15
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/>. */
19
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:
23
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.
27
28 2. All functions and their locals (including statics) are emitted as scanned.
29
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.
33
34 4. All structure .defs are emitted before the typedefs that refer to them.
35
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.
38
39 6. All undefined references are at the end of the file.
40 */
41
42 #include "config.h"
43 #include "system.h"
44 #include "coretypes.h"
45 #include "tm.h"
46 #include "debug.h"
47 #include "tree.h"
48 #include "varasm.h"
49 #include "stor-layout.h"
50
51 static GTY(()) tree anonymous_types;
52
53 /* Counter to generate unique "names" for nameless struct members. */
54
55 static GTY(()) int unnamed_struct_number;
56
57 /* Declarations whose debug info was deferred till end of compilation. */
58
59 static GTY(()) vec<tree, va_gc> *deferred_global_decls;
60
61 /* The C front end may call sdbout_symbol before sdbout_init runs.
62 We save all such decls in this list and output them when we get
63 to sdbout_init. */
64
65 static GTY(()) tree preinit_symbols;
66 static GTY(()) bool sdbout_initialized;
67
68 #ifdef SDB_DEBUGGING_INFO
69
70 #include "rtl.h"
71 #include "regs.h"
72 #include "flags.h"
73 #include "insn-config.h"
74 #include "reload.h"
75 #include "output.h"
76 #include "diagnostic-core.h"
77 #include "tm_p.h"
78 #include "gsyms.h"
79 #include "langhooks.h"
80 #include "target.h"
81
82 /* 1 if PARM is passed to this function in memory. */
83
84 #define PARM_PASSED_IN_MEMORY(PARM) \
85 (MEM_P (DECL_INCOMING_RTL (PARM)))
86
87 /* A C expression for the integer offset value of an automatic variable
88 (C_AUTO) having address X (an RTX). */
89 #ifndef DEBUGGER_AUTO_OFFSET
90 #define DEBUGGER_AUTO_OFFSET(X) \
91 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
92 #endif
93
94 /* A C expression for the integer offset value of an argument (C_ARG)
95 having address X (an RTX). The nominal offset is OFFSET. */
96 #ifndef DEBUGGER_ARG_OFFSET
97 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
98 #endif
99
100 /* Line number of beginning of current function, minus one.
101 Negative means not in a function or not using sdb. */
102
103 int sdb_begin_function_line = -1;
104
105
106 extern FILE *asm_out_file;
107
108 extern tree current_function_decl;
109
110 #include "sdbout.h"
111
112 static void sdbout_init (const char *);
113 static void sdbout_finish (const char *);
114 static void sdbout_start_source_file (unsigned int, const char *);
115 static void sdbout_end_source_file (unsigned int);
116 static void sdbout_begin_block (unsigned int, unsigned int);
117 static void sdbout_end_block (unsigned int, unsigned int);
118 static void sdbout_source_line (unsigned int, const char *, int, bool);
119 static void sdbout_end_epilogue (unsigned int, const char *);
120 static void sdbout_early_global_decl (tree);
121 static void sdbout_late_global_decl (tree);
122 static void sdbout_begin_prologue (unsigned int, const char *);
123 static void sdbout_end_prologue (unsigned int, const char *);
124 static void sdbout_begin_function (tree);
125 static void sdbout_end_function (unsigned int);
126 static void sdbout_toplevel_data (tree);
127 static void sdbout_label (rtx_code_label *);
128 static char *gen_fake_label (void);
129 static int plain_type (tree);
130 static int template_name_p (tree);
131 static void sdbout_record_type_name (tree);
132 static int plain_type_1 (tree, int);
133 static void sdbout_block (tree);
134 static void sdbout_syms (tree);
135 #ifdef SDB_ALLOW_FORWARD_REFERENCES
136 static void sdbout_queue_anonymous_type (tree);
137 static void sdbout_dequeue_anonymous_types (void);
138 #endif
139 static void sdbout_type (tree);
140 static void sdbout_field_types (tree);
141 static void sdbout_one_type (tree);
142 static void sdbout_parms (tree);
143 static void sdbout_reg_parms (tree);
144
145 /* Random macros describing parts of SDB data. */
146
147 /* Default value of delimiter is ";". */
148 #ifndef SDB_DELIM
149 #define SDB_DELIM ";"
150 #endif
151
152 /* Maximum number of dimensions the assembler will allow. */
153 #ifndef SDB_MAX_DIM
154 #define SDB_MAX_DIM 4
155 #endif
156
157 #ifndef PUT_SDB_SCL
158 #define PUT_SDB_SCL(a) fprintf (asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
159 #endif
160
161 #ifndef PUT_SDB_INT_VAL
162 #define PUT_SDB_INT_VAL(a) \
163 do { \
164 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
165 (HOST_WIDE_INT) (a), SDB_DELIM); \
166 } while (0)
167
168 #endif
169
170 #ifndef PUT_SDB_VAL
171 #define PUT_SDB_VAL(a) \
172 ( fputs ("\t.val\t", asm_out_file), \
173 output_addr_const (asm_out_file, (a)), \
174 fprintf (asm_out_file, SDB_DELIM))
175 #endif
176
177 #ifndef PUT_SDB_DEF
178 #define PUT_SDB_DEF(a) \
179 do { fprintf (asm_out_file, "\t.def\t"); \
180 assemble_name (asm_out_file, a); \
181 fprintf (asm_out_file, SDB_DELIM); } while (0)
182 #endif
183
184 #ifndef PUT_SDB_PLAIN_DEF
185 #define PUT_SDB_PLAIN_DEF(a) \
186 fprintf (asm_out_file, "\t.def\t.%s%s", a, SDB_DELIM)
187 #endif
188
189 #ifndef PUT_SDB_ENDEF
190 #define PUT_SDB_ENDEF fputs ("\t.endef\n", asm_out_file)
191 #endif
192
193 #ifndef PUT_SDB_TYPE
194 #define PUT_SDB_TYPE(a) fprintf (asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
195 #endif
196
197 #ifndef PUT_SDB_SIZE
198 #define PUT_SDB_SIZE(a) \
199 do { \
200 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
201 (HOST_WIDE_INT) (a), SDB_DELIM); \
202 } while (0)
203 #endif
204
205 #ifndef PUT_SDB_START_DIM
206 #define PUT_SDB_START_DIM fprintf (asm_out_file, "\t.dim\t")
207 #endif
208
209 #ifndef PUT_SDB_NEXT_DIM
210 #define PUT_SDB_NEXT_DIM(a) fprintf (asm_out_file, "%d,", a)
211 #endif
212
213 #ifndef PUT_SDB_LAST_DIM
214 #define PUT_SDB_LAST_DIM(a) fprintf (asm_out_file, "%d%s", a, SDB_DELIM)
215 #endif
216
217 #ifndef PUT_SDB_TAG
218 #define PUT_SDB_TAG(a) \
219 do { fprintf (asm_out_file, "\t.tag\t"); \
220 assemble_name (asm_out_file, a); \
221 fprintf (asm_out_file, SDB_DELIM); } while (0)
222 #endif
223
224 #ifndef PUT_SDB_BLOCK_START
225 #define PUT_SDB_BLOCK_START(LINE) \
226 fprintf (asm_out_file, \
227 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
228 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
229 #endif
230
231 #ifndef PUT_SDB_BLOCK_END
232 #define PUT_SDB_BLOCK_END(LINE) \
233 fprintf (asm_out_file, \
234 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
235 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
236 #endif
237
238 #ifndef PUT_SDB_FUNCTION_START
239 #define PUT_SDB_FUNCTION_START(LINE) \
240 fprintf (asm_out_file, \
241 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
242 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
243 #endif
244
245 #ifndef PUT_SDB_FUNCTION_END
246 #define PUT_SDB_FUNCTION_END(LINE) \
247 fprintf (asm_out_file, \
248 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
249 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
250 #endif
251
252 /* Return the sdb tag identifier string for TYPE
253 if TYPE has already been defined; otherwise return a null pointer. */
254
255 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
256
257 /* Set the sdb tag identifier string for TYPE to NAME. */
258
259 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
260 TYPE_SYMTAB_POINTER (TYPE) = (const char *)(NAME)
261
262 /* Return the name (a string) of the struct, union or enum tag
263 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
264
265 #define TAG_NAME(link) \
266 (((link) && TREE_PURPOSE ((link)) \
267 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
268 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
269
270 /* Ensure we don't output a negative line number. */
271 #define MAKE_LINE_SAFE(line) \
272 if ((int) line <= sdb_begin_function_line) \
273 line = sdb_begin_function_line + 1
274
275 /* The debug hooks structure. */
276 const struct gcc_debug_hooks sdb_debug_hooks =
277 {
278 sdbout_init, /* init */
279 sdbout_finish, /* finish */
280 debug_nothing_void, /* early_finish */
281 debug_nothing_void, /* assembly_start */
282 debug_nothing_int_charstar, /* define */
283 debug_nothing_int_charstar, /* undef */
284 sdbout_start_source_file, /* start_source_file */
285 sdbout_end_source_file, /* end_source_file */
286 sdbout_begin_block, /* begin_block */
287 sdbout_end_block, /* end_block */
288 debug_true_const_tree, /* ignore_block */
289 sdbout_source_line, /* source_line */
290 sdbout_begin_prologue, /* begin_prologue */
291 debug_nothing_int_charstar, /* end_prologue */
292 debug_nothing_int_charstar, /* begin_epilogue */
293 sdbout_end_epilogue, /* end_epilogue */
294 sdbout_begin_function, /* begin_function */
295 sdbout_end_function, /* end_function */
296 debug_nothing_tree, /* register_main_translation_unit */
297 debug_nothing_tree, /* function_decl */
298 sdbout_early_global_decl, /* early_global_decl */
299 sdbout_late_global_decl, /* late_global_decl */
300 sdbout_symbol, /* type_decl */
301 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
302 debug_nothing_tree, /* deferred_inline_function */
303 debug_nothing_tree, /* outlining_inline_function */
304 sdbout_label, /* label */
305 debug_nothing_int, /* handle_pch */
306 debug_nothing_rtx_insn, /* var_location */
307 debug_nothing_void, /* switch_text_section */
308 debug_nothing_tree_tree, /* set_name */
309 0, /* start_end_main_source_file */
310 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
311 };
312
313 /* Return a unique string to name an anonymous type. */
314
315 static char *
316 gen_fake_label (void)
317 {
318 char label[10];
319 char *labelstr;
320 sprintf (label, ".%dfake", unnamed_struct_number);
321 unnamed_struct_number++;
322 labelstr = xstrdup (label);
323 return labelstr;
324 }
325
326 /* Return the number which describes TYPE for SDB.
327 For pointers, etc., this function is recursive.
328 Each record, union or enumeral type must already have had a
329 tag number output. */
330
331 /* The number is given by d6d5d4d3d2d1bbbb
332 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
333 Thus, char *foo () has bbbb=T_CHAR
334 d1=D_FCN
335 d2=D_PTR
336 N_BTMASK= 017 1111 basic type field.
337 N_TSHIFT= 2 derived type shift
338 N_BTSHFT= 4 Basic type shift */
339
340 /* Produce the number that describes a pointer, function or array type.
341 PREV is the number describing the target, value or element type.
342 DT_type describes how to transform that type. */
343 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
344 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
345 | ((int) DT_type << (int) N_BTSHFT) \
346 | ((PREV) & (int) N_BTMASK))
347
348 /* Number of elements used in sdb_dims. */
349 static int sdb_n_dims = 0;
350
351 /* Table of array dimensions of current type. */
352 static int sdb_dims[SDB_MAX_DIM];
353
354 /* Size of outermost array currently being processed. */
355 static int sdb_type_size = -1;
356
357 static int
358 plain_type (tree type)
359 {
360 int val = plain_type_1 (type, 0);
361
362 /* If we have already saved up some array dimensions, print them now. */
363 if (sdb_n_dims > 0)
364 {
365 int i;
366 PUT_SDB_START_DIM;
367 for (i = sdb_n_dims - 1; i > 0; i--)
368 PUT_SDB_NEXT_DIM (sdb_dims[i]);
369 PUT_SDB_LAST_DIM (sdb_dims[0]);
370 sdb_n_dims = 0;
371
372 sdb_type_size = int_size_in_bytes (type);
373 /* Don't kill sdb if type is not laid out or has variable size. */
374 if (sdb_type_size < 0)
375 sdb_type_size = 0;
376 }
377 /* If we have computed the size of an array containing this type,
378 print it now. */
379 if (sdb_type_size >= 0)
380 {
381 PUT_SDB_SIZE (sdb_type_size);
382 sdb_type_size = -1;
383 }
384 return val;
385 }
386
387 static int
388 template_name_p (tree name)
389 {
390 const char *ptr = IDENTIFIER_POINTER (name);
391 while (*ptr && *ptr != '<')
392 ptr++;
393
394 return *ptr != '\0';
395 }
396
397 static void
398 sdbout_record_type_name (tree type)
399 {
400 const char *name = 0;
401 int no_name;
402
403 if (KNOWN_TYPE_TAG (type))
404 return;
405
406 if (TYPE_NAME (type) != 0)
407 {
408 tree t = 0;
409
410 /* Find the IDENTIFIER_NODE for the type name. */
411 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
412 t = TYPE_NAME (type);
413 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
414 {
415 t = DECL_NAME (TYPE_NAME (type));
416 /* The DECL_NAME for templates includes "<>", which breaks
417 most assemblers. Use its assembler name instead, which
418 has been mangled into being safe. */
419 if (t && template_name_p (t))
420 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
421 }
422
423 /* Now get the name as a string, or invent one. */
424 if (t != NULL_TREE)
425 name = IDENTIFIER_POINTER (t);
426 }
427
428 no_name = (name == 0 || *name == 0);
429 if (no_name)
430 name = gen_fake_label ();
431
432 SET_KNOWN_TYPE_TAG (type, name);
433 #ifdef SDB_ALLOW_FORWARD_REFERENCES
434 if (no_name)
435 sdbout_queue_anonymous_type (type);
436 #endif
437 }
438
439 /* Return the .type value for type TYPE.
440
441 LEVEL indicates how many levels deep we have recursed into the type.
442 The SDB debug format can only represent 6 derived levels of types.
443 After that, we must output inaccurate debug info. We deliberately
444 stop before the 7th level, so that ADA recursive types will not give an
445 infinite loop. */
446
447 static int
448 plain_type_1 (tree type, int level)
449 {
450 if (type == 0)
451 type = void_type_node;
452 else if (type == error_mark_node)
453 type = integer_type_node;
454 else
455 type = TYPE_MAIN_VARIANT (type);
456
457 switch (TREE_CODE (type))
458 {
459 case VOID_TYPE:
460 case NULLPTR_TYPE:
461 return T_VOID;
462 case BOOLEAN_TYPE:
463 case INTEGER_TYPE:
464 {
465 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
466
467 /* Carefully distinguish all the standard types of C,
468 without messing up if the language is not C.
469 Note that we check only for the names that contain spaces;
470 other names might occur by coincidence in other languages. */
471 if (TYPE_NAME (type) != 0
472 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
473 && DECL_NAME (TYPE_NAME (type)) != 0
474 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
475 {
476 const char *const name
477 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
478
479 if (!strcmp (name, "char"))
480 return T_CHAR;
481 if (!strcmp (name, "unsigned char"))
482 return T_UCHAR;
483 if (!strcmp (name, "signed char"))
484 return T_CHAR;
485 if (!strcmp (name, "int"))
486 return T_INT;
487 if (!strcmp (name, "unsigned int"))
488 return T_UINT;
489 if (!strcmp (name, "short int"))
490 return T_SHORT;
491 if (!strcmp (name, "short unsigned int"))
492 return T_USHORT;
493 if (!strcmp (name, "long int"))
494 return T_LONG;
495 if (!strcmp (name, "long unsigned int"))
496 return T_ULONG;
497 }
498
499 if (size == INT_TYPE_SIZE)
500 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
501 if (size == CHAR_TYPE_SIZE)
502 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
503 if (size == SHORT_TYPE_SIZE)
504 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
505 if (size == LONG_TYPE_SIZE)
506 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
507 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
508 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
509 return 0;
510 }
511
512 case REAL_TYPE:
513 {
514 int precision = TYPE_PRECISION (type);
515 if (precision == FLOAT_TYPE_SIZE)
516 return T_FLOAT;
517 if (precision == DOUBLE_TYPE_SIZE)
518 return T_DOUBLE;
519 #ifdef EXTENDED_SDB_BASIC_TYPES
520 if (precision == LONG_DOUBLE_TYPE_SIZE)
521 return T_LNGDBL;
522 #else
523 if (precision == LONG_DOUBLE_TYPE_SIZE)
524 return T_DOUBLE; /* better than nothing */
525 #endif
526 return 0;
527 }
528
529 case ARRAY_TYPE:
530 {
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);
546
547 return PUSH_DERIVED_LEVEL (DT_ARY, m);
548 }
549
550 case RECORD_TYPE:
551 case UNION_TYPE:
552 case QUAL_UNION_TYPE:
553 case ENUMERAL_TYPE:
554 {
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
564 )
565 #endif
566 {
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;
581 }
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);
586 }
587 case POINTER_TYPE:
588 case REFERENCE_TYPE:
589 {
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);
596 }
597 case FUNCTION_TYPE:
598 case METHOD_TYPE:
599 {
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);
606 }
607 default:
608 return 0;
609 }
610 }
611
612 /* Output the symbols defined in block number DO_BLOCK.
613
614 This function works by walking the tree structure of blocks,
615 counting blocks until it finds the desired block. */
616
617 static int do_block = 0;
618
619 static void
620 sdbout_block (tree block)
621 {
622 while (block)
623 {
624 /* Ignore blocks never expanded or otherwise marked as real. */
625 if (TREE_USED (block))
626 {
627 /* When we reach the specified block, output its symbols. */
628 if (BLOCK_NUMBER (block) == do_block)
629 sdbout_syms (BLOCK_VARS (block));
630
631 /* If we are past the specified block, stop the scan. */
632 if (BLOCK_NUMBER (block) > do_block)
633 return;
634
635 /* Scan the blocks within this block. */
636 sdbout_block (BLOCK_SUBBLOCKS (block));
637 }
638
639 block = BLOCK_CHAIN (block);
640 }
641 }
642
643 /* Call sdbout_symbol on each decl in the chain SYMS. */
644
645 static void
646 sdbout_syms (tree syms)
647 {
648 while (syms)
649 {
650 if (TREE_CODE (syms) != LABEL_DECL)
651 sdbout_symbol (syms, 1);
652 syms = TREE_CHAIN (syms);
653 }
654 }
655
656 /* Output SDB information for a symbol described by DECL.
657 LOCAL is nonzero if the symbol is not file-scope. */
658
659 void
660 sdbout_symbol (tree decl, int local)
661 {
662 tree type = TREE_TYPE (decl);
663 tree context = NULL_TREE;
664 rtx value;
665 int regno = -1;
666 const char *name;
667
668 /* If we are called before sdbout_init is run, just save the symbol
669 for later. */
670 if (!sdbout_initialized)
671 {
672 preinit_symbols = tree_cons (0, decl, preinit_symbols);
673 return;
674 }
675
676 sdbout_one_type (type);
677
678 switch (TREE_CODE (decl))
679 {
680 case CONST_DECL:
681 /* Enum values are defined by defining the enum type. */
682 return;
683
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;
701
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;
713
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;
721
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 ();
726
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;
732
733 /* Ignore __FUNCTION__, etc. */
734 if (DECL_IGNORED_P (decl))
735 return;
736
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;
742
743 value = DECL_RTL (decl);
744
745 if (!is_global_var (decl))
746 value = eliminate_regs (value, VOIDmode, NULL_RTX);
747
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
753
754 /* Don't mention a variable at all
755 if it was completely optimized into nothingness.
756
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))
761 {
762 regno = REGNO (value);
763 if (regno >= FIRST_PSEUDO_REGISTER)
764 return;
765 }
766 else if (GET_CODE (value) == SUBREG)
767 {
768 while (GET_CODE (value) == SUBREG)
769 value = SUBREG_REG (value);
770 if (REG_P (value))
771 {
772 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
773 return;
774 }
775 regno = REGNO (alter_subreg (&value, true));
776 SET_DECL_RTL (decl, value);
777 }
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;
784
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)
792 {
793 if (COMPLETE_TYPE_P (type) /* not a forward reference */
794 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
795 sdbout_one_type (type);
796 }
797
798 /* Defer SDB information for top-level initialized variables! */
799 if (! local
800 && MEM_P (value)
801 && DECL_INITIAL (decl))
802 return;
803
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;
808
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));
814
815 if (MEM_P (value)
816 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
817 {
818 PUT_SDB_DEF (name);
819 if (TREE_PUBLIC (decl))
820 {
821 PUT_SDB_VAL (XEXP (value, 0));
822 PUT_SDB_SCL (C_EXT);
823 }
824 else
825 {
826 PUT_SDB_VAL (XEXP (value, 0));
827 PUT_SDB_SCL (C_STAT);
828 }
829 }
830 else if (regno >= 0)
831 {
832 PUT_SDB_DEF (name);
833 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
834 PUT_SDB_SCL (C_REG);
835 }
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. */
846 {
847 PUT_SDB_DEF (name);
848 if (REG_P (XEXP (value, 0)))
849 {
850 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
851 PUT_SDB_SCL (C_REG);
852 }
853 else
854 {
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);
862 }
863
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);
870 }
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)))))
879 {
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);
886 }
887 else
888 {
889 /* It is something we don't know how to represent for SDB. */
890 return;
891 }
892 break;
893
894 default:
895 break;
896 }
897 PUT_SDB_TYPE (plain_type (type));
898 PUT_SDB_ENDEF;
899 }
900
901 /* Output SDB information for a top-level initialized variable
902 that has been delayed. */
903
904 static void
905 sdbout_toplevel_data (tree decl)
906 {
907 tree type = TREE_TYPE (decl);
908
909 if (DECL_IGNORED_P (decl))
910 return;
911
912 gcc_assert (TREE_CODE (decl) == VAR_DECL);
913 gcc_assert (MEM_P (DECL_RTL (decl)));
914 gcc_assert (DECL_INITIAL (decl));
915
916 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
917 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
918 if (TREE_PUBLIC (decl))
919 {
920 PUT_SDB_SCL (C_EXT);
921 }
922 else
923 {
924 PUT_SDB_SCL (C_STAT);
925 }
926 PUT_SDB_TYPE (plain_type (type));
927 PUT_SDB_ENDEF;
928 }
929
930 #ifdef SDB_ALLOW_FORWARD_REFERENCES
931
932 /* Machinery to record and output anonymous types. */
933
934 static void
935 sdbout_queue_anonymous_type (tree type)
936 {
937 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
938 }
939
940 static void
941 sdbout_dequeue_anonymous_types (void)
942 {
943 tree types, link;
944
945 while (anonymous_types)
946 {
947 types = nreverse (anonymous_types);
948 anonymous_types = NULL_TREE;
949
950 for (link = types; link; link = TREE_CHAIN (link))
951 {
952 tree type = TREE_VALUE (link);
953
954 if (type && ! TREE_ASM_WRITTEN (type))
955 sdbout_one_type (type);
956 }
957 }
958 }
959
960 #endif
961
962 /* Given a chain of ..._TYPE nodes, all of which have names,
963 output definitions of those names, as typedefs. */
964
965 void
966 sdbout_types (tree types)
967 {
968 tree link;
969
970 for (link = types; link; link = TREE_CHAIN (link))
971 sdbout_one_type (link);
972
973 #ifdef SDB_ALLOW_FORWARD_REFERENCES
974 sdbout_dequeue_anonymous_types ();
975 #endif
976 }
977
978 static void
979 sdbout_type (tree type)
980 {
981 if (type == error_mark_node)
982 type = integer_type_node;
983 PUT_SDB_TYPE (plain_type (type));
984 }
985
986 /* Output types of the fields of type TYPE, if they are structs.
987
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. */
991
992 static void
993 sdbout_field_types (tree type)
994 {
995 tree tail;
996
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)))
1005 {
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));
1010 }
1011 }
1012
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. */
1019
1020 static void
1021 sdbout_one_type (tree type)
1022 {
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 ());
1028
1029 switch (TREE_CODE (type))
1030 {
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;
1040
1041 /* Output nothing if type is not yet defined. */
1042 if (!COMPLETE_TYPE_P (type))
1043 return;
1044
1045 TREE_ASM_WRITTEN (type) = 1;
1046
1047 /* This is reputed to cause trouble with the following case,
1048 but perhaps checking TYPE_SIZE above will fix it. */
1049
1050 /* Here is a testcase:
1051
1052 struct foo {
1053 struct badstr *bbb;
1054 } forwardref;
1055
1056 typedef struct intermediate {
1057 int aaaa;
1058 } intermediate_ref;
1059
1060 typedef struct badstr {
1061 int ccccc;
1062 } badtype; */
1063
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);
1072
1073 /* Output a structure type. */
1074 {
1075 int size = int_size_in_bytes (type);
1076 int member_scl = 0;
1077 tree tem;
1078
1079 /* Record the type tag, but not in its permanent place just yet. */
1080 sdbout_record_type_name (type);
1081
1082 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1083
1084 switch (TREE_CODE (type))
1085 {
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;
1092
1093 case RECORD_TYPE:
1094 PUT_SDB_SCL (C_STRTAG);
1095 PUT_SDB_TYPE (T_STRUCT);
1096 member_scl = C_MOS;
1097 break;
1098
1099 case ENUMERAL_TYPE:
1100 PUT_SDB_SCL (C_ENTAG);
1101 PUT_SDB_TYPE (T_ENUM);
1102 member_scl = C_MOE;
1103 break;
1104
1105 default:
1106 break;
1107 }
1108
1109 PUT_SDB_SIZE (size);
1110 PUT_SDB_ENDEF;
1111
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))
1118 {
1119 int i;
1120 tree binfo, child;
1121
1122 for (binfo = TYPE_BINFO (type), i = 0;
1123 BINFO_BASE_ITERATE (binfo, i, child); i++)
1124 {
1125 tree child_type = BINFO_TYPE (child);
1126 tree child_type_name;
1127
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)
1133 {
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));
1138 }
1139 else
1140 continue;
1141
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;
1147 }
1148 }
1149
1150 /* Output the individual fields. */
1151
1152 if (TREE_CODE (type) == ENUMERAL_TYPE)
1153 {
1154 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1155 {
1156 tree value = TREE_VALUE (tem);
1157
1158 if (TREE_CODE (value) == CONST_DECL)
1159 value = DECL_INITIAL (value);
1160
1161 if (tree_fits_shwi_p (value))
1162 {
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;
1168 }
1169 }
1170 }
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. */
1175
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)))
1184 {
1185 const char *name;
1186
1187 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1188 PUT_SDB_DEF (name);
1189 if (DECL_BIT_FIELD_TYPE (tem))
1190 {
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)));
1195 }
1196 else
1197 {
1198 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1199 PUT_SDB_SCL (member_scl);
1200 sdbout_type (TREE_TYPE (tem));
1201 }
1202 PUT_SDB_ENDEF;
1203 }
1204 /* Output end of a structure,union, or enumeral definition. */
1205
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;
1213 }
1214
1215 default:
1216 break;
1217 }
1218 }
1219
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.
1224
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. */
1228
1229 /* Output definitions, referring to storage in the parmlist,
1230 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1231
1232 static void
1233 sdbout_parms (tree parms)
1234 {
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))
1240 {
1241 int current_sym_value = 0;
1242 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1243
1244 if (name == 0 || *name == 0)
1245 name = gen_fake_label ();
1246
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));
1253
1254 if (PARM_PASSED_IN_MEMORY (parms))
1255 {
1256 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1257 tree type;
1258
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;
1268
1269 if (REG_P (DECL_RTL (parms))
1270 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1271 type = DECL_ARG_TYPE (parms);
1272 else
1273 {
1274 int original_sym_value = current_sym_value;
1275
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))));
1287
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
1296 {
1297 current_sym_value = original_sym_value;
1298 type = DECL_ARG_TYPE (parms);
1299 }
1300 }
1301
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;
1307 }
1308 else if (REG_P (DECL_RTL (parms)))
1309 {
1310 rtx best_rtl;
1311 /* Parm passed in registers and lives in registers or nowhere. */
1312
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);
1323
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;
1329 }
1330 else if (MEM_P (DECL_RTL (parms))
1331 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1332 {
1333 /* Parm was passed in registers but lives on the stack. */
1334
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));
1344
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;
1352 }
1353 }
1354 }
1355
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.
1359
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.
1364
1365 PARMS is a chain of PARM_DECL nodes. */
1366
1367 static void
1368 sdbout_reg_parms (tree parms)
1369 {
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))
1375 {
1376 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1377
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))
1383 {
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;
1391 }
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)))
1398 {
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
1411 {
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;
1420 }
1421 }
1422 }
1423 }
1424
1425 /* Output early debug information for a global DECL. Called from
1426 rest_of_decl_compilation during parsing. */
1427
1428 static void
1429 sdbout_early_global_decl (tree decl ATTRIBUTE_UNUSED)
1430 {
1431 /* NYI for non-dwarf. */
1432 }
1433
1434 /* Output late debug information for a global DECL after location
1435 information is available. */
1436
1437 static void
1438 sdbout_late_global_decl (tree decl)
1439 {
1440 if (TREE_CODE (decl) == VAR_DECL
1441 && !DECL_EXTERNAL (decl)
1442 && DECL_RTL_SET_P (decl))
1443 {
1444 /* The COFF linker can move initialized global vars to the end.
1445 And that can screw up the symbol ordering. Defer those for
1446 sdbout_finish (). */
1447 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1448 sdbout_symbol (decl, 0);
1449 else
1450 vec_safe_push (deferred_global_decls, decl);
1451
1452 /* Output COFF information for non-global file-scope initialized
1453 variables. */
1454 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1455 sdbout_toplevel_data (decl);
1456 }
1457 }
1458
1459 /* Output initialized global vars at the end, in the order of
1460 definition. See comment in sdbout_global_decl. */
1461
1462 static void
1463 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1464 {
1465 size_t i;
1466 tree decl;
1467
1468 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1469 sdbout_symbol (decl, 0);
1470 }
1471
1472 /* Describe the beginning of an internal block within a function.
1473 Also output descriptions of variables defined in this block.
1474
1475 N is the number of the block, by order of beginning, counting from 1,
1476 and not counting the outermost (function top-level) block.
1477 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1478 if the count starts at 0 for the outermost one. */
1479
1480 static void
1481 sdbout_begin_block (unsigned int line, unsigned int n)
1482 {
1483 tree decl = current_function_decl;
1484 MAKE_LINE_SAFE (line);
1485
1486 /* The SCO compiler does not emit a separate block for the function level
1487 scope, so we avoid it here also. */
1488 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1489
1490 if (n == 1)
1491 {
1492 /* Include the outermost BLOCK's variables in block 1. */
1493 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1494 sdbout_block (DECL_INITIAL (decl));
1495 }
1496 /* If -g1, suppress all the internal symbols of functions
1497 except for arguments. */
1498 if (debug_info_level != DINFO_LEVEL_TERSE)
1499 {
1500 do_block = n;
1501 sdbout_block (DECL_INITIAL (decl));
1502 }
1503
1504 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1505 sdbout_dequeue_anonymous_types ();
1506 #endif
1507 }
1508
1509 /* Describe the end line-number of an internal block within a function. */
1510
1511 static void
1512 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1513 {
1514 MAKE_LINE_SAFE (line);
1515
1516 /* The SCO compiler does not emit a separate block for the function level
1517 scope, so we avoid it here also. */
1518 if (n != 1)
1519 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1520 }
1521
1522 /* Output a line number symbol entry for source file FILENAME and line
1523 number LINE. */
1524
1525 static void
1526 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1527 int discriminator ATTRIBUTE_UNUSED,
1528 bool is_stmt ATTRIBUTE_UNUSED)
1529 {
1530 /* COFF relative line numbers must be positive. */
1531 if ((int) line > sdb_begin_function_line)
1532 {
1533 #ifdef SDB_OUTPUT_SOURCE_LINE
1534 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1535 #else
1536 fprintf (asm_out_file, "\t.ln\t%d\n",
1537 ((sdb_begin_function_line > -1)
1538 ? line - sdb_begin_function_line : 1));
1539 #endif
1540 }
1541 }
1542
1543 /* Output sdb info for the current function name.
1544 Called from assemble_start_function. */
1545
1546 static void
1547 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1548 {
1549 sdbout_symbol (current_function_decl, 0);
1550 }
1551
1552 /* Called at beginning of function body after prologue. Record the
1553 function's starting line number, so we can output relative line numbers
1554 for the other lines. Describe beginning of outermost block. Also
1555 describe the parameter list. */
1556
1557 static void
1558 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1559 {
1560 sdbout_end_prologue (line, file);
1561 }
1562
1563 static void
1564 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1565 {
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));
1570 }
1571
1572 /* Called at end of function (before epilogue).
1573 Describe end of outermost block. */
1574
1575 static void
1576 sdbout_end_function (unsigned int line)
1577 {
1578 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1579 sdbout_dequeue_anonymous_types ();
1580 #endif
1581
1582 MAKE_LINE_SAFE (line);
1583 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1584
1585 /* Indicate we are between functions, for line-number output. */
1586 sdb_begin_function_line = -1;
1587 }
1588
1589 /* Output sdb info for the absolute end of a function.
1590 Called after the epilogue is output. */
1591
1592 static void
1593 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1594 const char *file ATTRIBUTE_UNUSED)
1595 {
1596 const char *const name ATTRIBUTE_UNUSED
1597 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1598
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
1607 }
1608
1609 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1610 is present. */
1611
1612 static void
1613 sdbout_label (rtx_code_label *insn)
1614 {
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;
1620 }
1621
1622 /* Change to reading from a new source file. */
1623
1624 static void
1625 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1626 const char *filename ATTRIBUTE_UNUSED)
1627 {
1628 }
1629
1630 /* Revert to reading a previous source file. */
1631
1632 static void
1633 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1634 {
1635 }
1636
1637 /* Set up for SDB output at the start of compilation. */
1638
1639 static void
1640 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1641 {
1642 tree t;
1643
1644 vec_alloc (deferred_global_decls, 12);
1645
1646 /* Emit debug information which was queued by sdbout_symbol before
1647 we got here. */
1648 sdbout_initialized = true;
1649
1650 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1651 sdbout_symbol (TREE_VALUE (t), 0);
1652 preinit_symbols = 0;
1653 }
1654
1655 #endif /* SDB_DEBUGGING_INFO */
1656
1657 #include "gt-sdbout.h"