[AArch64] Fix size of memory store for the vst<n>_lane intrinsics
[gcc.git] / gcc / sdbout.c
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988-2013 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 "ggc.h"
49 #include "vec.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_global_decl (tree);
121 static void sdbout_begin_prologue (unsigned int, const char *);
122 static void sdbout_end_prologue (unsigned int, const char *);
123 static void sdbout_begin_function (tree);
124 static void sdbout_end_function (unsigned int);
125 static void sdbout_toplevel_data (tree);
126 static void sdbout_label (rtx);
127 static char *gen_fake_label (void);
128 static int plain_type (tree);
129 static int template_name_p (tree);
130 static void sdbout_record_type_name (tree);
131 static int plain_type_1 (tree, int);
132 static void sdbout_block (tree);
133 static void sdbout_syms (tree);
134 #ifdef SDB_ALLOW_FORWARD_REFERENCES
135 static void sdbout_queue_anonymous_type (tree);
136 static void sdbout_dequeue_anonymous_types (void);
137 #endif
138 static void sdbout_type (tree);
139 static void sdbout_field_types (tree);
140 static void sdbout_one_type (tree);
141 static void sdbout_parms (tree);
142 static void sdbout_reg_parms (tree);
143 static void sdbout_global_decl (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, /* assembly_start */
281 debug_nothing_int_charstar, /* define */
282 debug_nothing_int_charstar, /* undef */
283 sdbout_start_source_file, /* start_source_file */
284 sdbout_end_source_file, /* end_source_file */
285 sdbout_begin_block, /* begin_block */
286 sdbout_end_block, /* end_block */
287 debug_true_const_tree, /* ignore_block */
288 sdbout_source_line, /* source_line */
289 sdbout_begin_prologue, /* begin_prologue */
290 debug_nothing_int_charstar, /* end_prologue */
291 debug_nothing_int_charstar, /* begin_epilogue */
292 sdbout_end_epilogue, /* end_epilogue */
293 sdbout_begin_function, /* begin_function */
294 sdbout_end_function, /* end_function */
295 debug_nothing_tree, /* function_decl */
296 sdbout_global_decl, /* global_decl */
297 sdbout_symbol, /* type_decl */
298 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */
299 debug_nothing_tree, /* deferred_inline_function */
300 debug_nothing_tree, /* outlining_inline_function */
301 sdbout_label, /* label */
302 debug_nothing_int, /* handle_pch */
303 debug_nothing_rtx, /* var_location */
304 debug_nothing_void, /* switch_text_section */
305 debug_nothing_tree_tree, /* set_name */
306 0, /* start_end_main_source_file */
307 TYPE_SYMTAB_IS_POINTER /* tree_type_symtab_field */
308 };
309
310 /* Return a unique string to name an anonymous type. */
311
312 static char *
313 gen_fake_label (void)
314 {
315 char label[10];
316 char *labelstr;
317 sprintf (label, ".%dfake", unnamed_struct_number);
318 unnamed_struct_number++;
319 labelstr = xstrdup (label);
320 return labelstr;
321 }
322
323 /* Return the number which describes TYPE for SDB.
324 For pointers, etc., this function is recursive.
325 Each record, union or enumeral type must already have had a
326 tag number output. */
327
328 /* The number is given by d6d5d4d3d2d1bbbb
329 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
330 Thus, char *foo () has bbbb=T_CHAR
331 d1=D_FCN
332 d2=D_PTR
333 N_BTMASK= 017 1111 basic type field.
334 N_TSHIFT= 2 derived type shift
335 N_BTSHFT= 4 Basic type shift */
336
337 /* Produce the number that describes a pointer, function or array type.
338 PREV is the number describing the target, value or element type.
339 DT_type describes how to transform that type. */
340 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
341 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
342 | ((int) DT_type << (int) N_BTSHFT) \
343 | ((PREV) & (int) N_BTMASK))
344
345 /* Number of elements used in sdb_dims. */
346 static int sdb_n_dims = 0;
347
348 /* Table of array dimensions of current type. */
349 static int sdb_dims[SDB_MAX_DIM];
350
351 /* Size of outermost array currently being processed. */
352 static int sdb_type_size = -1;
353
354 static int
355 plain_type (tree type)
356 {
357 int val = plain_type_1 (type, 0);
358
359 /* If we have already saved up some array dimensions, print them now. */
360 if (sdb_n_dims > 0)
361 {
362 int i;
363 PUT_SDB_START_DIM;
364 for (i = sdb_n_dims - 1; i > 0; i--)
365 PUT_SDB_NEXT_DIM (sdb_dims[i]);
366 PUT_SDB_LAST_DIM (sdb_dims[0]);
367 sdb_n_dims = 0;
368
369 sdb_type_size = int_size_in_bytes (type);
370 /* Don't kill sdb if type is not laid out or has variable size. */
371 if (sdb_type_size < 0)
372 sdb_type_size = 0;
373 }
374 /* If we have computed the size of an array containing this type,
375 print it now. */
376 if (sdb_type_size >= 0)
377 {
378 PUT_SDB_SIZE (sdb_type_size);
379 sdb_type_size = -1;
380 }
381 return val;
382 }
383
384 static int
385 template_name_p (tree name)
386 {
387 const char *ptr = IDENTIFIER_POINTER (name);
388 while (*ptr && *ptr != '<')
389 ptr++;
390
391 return *ptr != '\0';
392 }
393
394 static void
395 sdbout_record_type_name (tree type)
396 {
397 const char *name = 0;
398 int no_name;
399
400 if (KNOWN_TYPE_TAG (type))
401 return;
402
403 if (TYPE_NAME (type) != 0)
404 {
405 tree t = 0;
406
407 /* Find the IDENTIFIER_NODE for the type name. */
408 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
409 t = TYPE_NAME (type);
410 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
411 {
412 t = DECL_NAME (TYPE_NAME (type));
413 /* The DECL_NAME for templates includes "<>", which breaks
414 most assemblers. Use its assembler name instead, which
415 has been mangled into being safe. */
416 if (t && template_name_p (t))
417 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
418 }
419
420 /* Now get the name as a string, or invent one. */
421 if (t != NULL_TREE)
422 name = IDENTIFIER_POINTER (t);
423 }
424
425 no_name = (name == 0 || *name == 0);
426 if (no_name)
427 name = gen_fake_label ();
428
429 SET_KNOWN_TYPE_TAG (type, name);
430 #ifdef SDB_ALLOW_FORWARD_REFERENCES
431 if (no_name)
432 sdbout_queue_anonymous_type (type);
433 #endif
434 }
435
436 /* Return the .type value for type TYPE.
437
438 LEVEL indicates how many levels deep we have recursed into the type.
439 The SDB debug format can only represent 6 derived levels of types.
440 After that, we must output inaccurate debug info. We deliberately
441 stop before the 7th level, so that ADA recursive types will not give an
442 infinite loop. */
443
444 static int
445 plain_type_1 (tree type, int level)
446 {
447 if (type == 0)
448 type = void_type_node;
449 else if (type == error_mark_node)
450 type = integer_type_node;
451 else
452 type = TYPE_MAIN_VARIANT (type);
453
454 switch (TREE_CODE (type))
455 {
456 case VOID_TYPE:
457 case NULLPTR_TYPE:
458 return T_VOID;
459 case BOOLEAN_TYPE:
460 case INTEGER_TYPE:
461 {
462 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
463
464 /* Carefully distinguish all the standard types of C,
465 without messing up if the language is not C.
466 Note that we check only for the names that contain spaces;
467 other names might occur by coincidence in other languages. */
468 if (TYPE_NAME (type) != 0
469 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
470 && DECL_NAME (TYPE_NAME (type)) != 0
471 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
472 {
473 const char *const name
474 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
475
476 if (!strcmp (name, "char"))
477 return T_CHAR;
478 if (!strcmp (name, "unsigned char"))
479 return T_UCHAR;
480 if (!strcmp (name, "signed char"))
481 return T_CHAR;
482 if (!strcmp (name, "int"))
483 return T_INT;
484 if (!strcmp (name, "unsigned int"))
485 return T_UINT;
486 if (!strcmp (name, "short int"))
487 return T_SHORT;
488 if (!strcmp (name, "short unsigned int"))
489 return T_USHORT;
490 if (!strcmp (name, "long int"))
491 return T_LONG;
492 if (!strcmp (name, "long unsigned int"))
493 return T_ULONG;
494 }
495
496 if (size == INT_TYPE_SIZE)
497 return (TYPE_UNSIGNED (type) ? T_UINT : T_INT);
498 if (size == CHAR_TYPE_SIZE)
499 return (TYPE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
500 if (size == SHORT_TYPE_SIZE)
501 return (TYPE_UNSIGNED (type) ? T_USHORT : T_SHORT);
502 if (size == LONG_TYPE_SIZE)
503 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
504 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
505 return (TYPE_UNSIGNED (type) ? T_ULONG : T_LONG);
506 return 0;
507 }
508
509 case REAL_TYPE:
510 {
511 int precision = TYPE_PRECISION (type);
512 if (precision == FLOAT_TYPE_SIZE)
513 return T_FLOAT;
514 if (precision == DOUBLE_TYPE_SIZE)
515 return T_DOUBLE;
516 #ifdef EXTENDED_SDB_BASIC_TYPES
517 if (precision == LONG_DOUBLE_TYPE_SIZE)
518 return T_LNGDBL;
519 #else
520 if (precision == LONG_DOUBLE_TYPE_SIZE)
521 return T_DOUBLE; /* better than nothing */
522 #endif
523 return 0;
524 }
525
526 case ARRAY_TYPE:
527 {
528 int m;
529 if (level >= 6)
530 return T_VOID;
531 else
532 m = plain_type_1 (TREE_TYPE (type), level+1);
533 if (sdb_n_dims < SDB_MAX_DIM)
534 sdb_dims[sdb_n_dims++]
535 = (TYPE_DOMAIN (type)
536 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
537 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
538 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
539 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
540 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
541 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
542 : 0);
543
544 return PUSH_DERIVED_LEVEL (DT_ARY, m);
545 }
546
547 case RECORD_TYPE:
548 case UNION_TYPE:
549 case QUAL_UNION_TYPE:
550 case ENUMERAL_TYPE:
551 {
552 const char *tag;
553 #ifdef SDB_ALLOW_FORWARD_REFERENCES
554 sdbout_record_type_name (type);
555 #endif
556 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
557 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
558 #ifdef SDB_ALLOW_FORWARD_REFERENCES
559 || TYPE_MODE (type) != VOIDmode
560 #endif
561 )
562 #endif
563 {
564 /* Output the referenced structure tag name
565 only if the .def has already been finished.
566 At least on 386, the Unix assembler
567 cannot handle forward references to tags. */
568 /* But the 88100, it requires them, sigh... */
569 /* And the MIPS requires unknown refs as well... */
570 tag = KNOWN_TYPE_TAG (type);
571 PUT_SDB_TAG (tag);
572 /* These 3 lines used to follow the close brace.
573 However, a size of 0 without a tag implies a tag of 0,
574 so if we don't know a tag, we can't mention the size. */
575 sdb_type_size = int_size_in_bytes (type);
576 if (sdb_type_size < 0)
577 sdb_type_size = 0;
578 }
579 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
580 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
581 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
582 : T_ENUM);
583 }
584 case POINTER_TYPE:
585 case REFERENCE_TYPE:
586 {
587 int m;
588 if (level >= 6)
589 return T_VOID;
590 else
591 m = plain_type_1 (TREE_TYPE (type), level+1);
592 return PUSH_DERIVED_LEVEL (DT_PTR, m);
593 }
594 case FUNCTION_TYPE:
595 case METHOD_TYPE:
596 {
597 int m;
598 if (level >= 6)
599 return T_VOID;
600 else
601 m = plain_type_1 (TREE_TYPE (type), level+1);
602 return PUSH_DERIVED_LEVEL (DT_FCN, m);
603 }
604 default:
605 return 0;
606 }
607 }
608
609 /* Output the symbols defined in block number DO_BLOCK.
610
611 This function works by walking the tree structure of blocks,
612 counting blocks until it finds the desired block. */
613
614 static int do_block = 0;
615
616 static void
617 sdbout_block (tree block)
618 {
619 while (block)
620 {
621 /* Ignore blocks never expanded or otherwise marked as real. */
622 if (TREE_USED (block))
623 {
624 /* When we reach the specified block, output its symbols. */
625 if (BLOCK_NUMBER (block) == do_block)
626 sdbout_syms (BLOCK_VARS (block));
627
628 /* If we are past the specified block, stop the scan. */
629 if (BLOCK_NUMBER (block) > do_block)
630 return;
631
632 /* Scan the blocks within this block. */
633 sdbout_block (BLOCK_SUBBLOCKS (block));
634 }
635
636 block = BLOCK_CHAIN (block);
637 }
638 }
639
640 /* Call sdbout_symbol on each decl in the chain SYMS. */
641
642 static void
643 sdbout_syms (tree syms)
644 {
645 while (syms)
646 {
647 if (TREE_CODE (syms) != LABEL_DECL)
648 sdbout_symbol (syms, 1);
649 syms = TREE_CHAIN (syms);
650 }
651 }
652
653 /* Output SDB information for a symbol described by DECL.
654 LOCAL is nonzero if the symbol is not file-scope. */
655
656 void
657 sdbout_symbol (tree decl, int local)
658 {
659 tree type = TREE_TYPE (decl);
660 tree context = NULL_TREE;
661 rtx value;
662 int regno = -1;
663 const char *name;
664
665 /* If we are called before sdbout_init is run, just save the symbol
666 for later. */
667 if (!sdbout_initialized)
668 {
669 preinit_symbols = tree_cons (0, decl, preinit_symbols);
670 return;
671 }
672
673 sdbout_one_type (type);
674
675 switch (TREE_CODE (decl))
676 {
677 case CONST_DECL:
678 /* Enum values are defined by defining the enum type. */
679 return;
680
681 case FUNCTION_DECL:
682 /* Don't mention a nested function under its parent. */
683 context = decl_function_context (decl);
684 if (context == current_function_decl)
685 return;
686 /* Check DECL_INITIAL to distinguish declarations from definitions.
687 Don't output debug info here for declarations; they will have
688 a DECL_INITIAL value of 0. */
689 if (! DECL_INITIAL (decl))
690 return;
691 if (!MEM_P (DECL_RTL (decl))
692 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
693 return;
694 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
695 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
696 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
697 break;
698
699 case TYPE_DECL:
700 /* Done with tagged types. */
701 if (DECL_NAME (decl) == 0)
702 return;
703 if (DECL_IGNORED_P (decl))
704 return;
705 /* Don't output intrinsic types. GAS chokes on SDB .def
706 statements that contain identifiers with embedded spaces
707 (eg "unsigned long"). */
708 if (DECL_IS_BUILTIN (decl))
709 return;
710
711 /* Output typedef name. */
712 if (template_name_p (DECL_NAME (decl)))
713 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
714 else
715 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
716 PUT_SDB_SCL (C_TPDEF);
717 break;
718
719 case PARM_DECL:
720 /* Parm decls go in their own separate chains
721 and are output by sdbout_reg_parms and sdbout_parms. */
722 gcc_unreachable ();
723
724 case VAR_DECL:
725 /* Don't mention a variable that is external.
726 Let the file that defines it describe it. */
727 if (DECL_EXTERNAL (decl))
728 return;
729
730 /* Ignore __FUNCTION__, etc. */
731 if (DECL_IGNORED_P (decl))
732 return;
733
734 /* If there was an error in the declaration, don't dump core
735 if there is no RTL associated with the variable doesn't
736 exist. */
737 if (!DECL_RTL_SET_P (decl))
738 return;
739
740 SET_DECL_RTL (decl,
741 eliminate_regs (DECL_RTL (decl), VOIDmode, NULL_RTX));
742 #ifdef LEAF_REG_REMAP
743 if (crtl->uses_only_leaf_regs)
744 leaf_renumber_regs_insn (DECL_RTL (decl));
745 #endif
746 value = DECL_RTL (decl);
747
748 /* Don't mention a variable at all
749 if it was completely optimized into nothingness.
750
751 If DECL was from an inline function, then its rtl
752 is not identically the rtl that was used in this
753 particular compilation. */
754 if (REG_P (value))
755 {
756 regno = REGNO (value);
757 if (regno >= FIRST_PSEUDO_REGISTER)
758 return;
759 }
760 else if (GET_CODE (value) == SUBREG)
761 {
762 while (GET_CODE (value) == SUBREG)
763 value = SUBREG_REG (value);
764 if (REG_P (value))
765 {
766 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
767 return;
768 }
769 regno = REGNO (alter_subreg (&value, true));
770 SET_DECL_RTL (decl, value);
771 }
772 /* Don't output anything if an auto variable
773 gets RTL that is static.
774 GAS version 2.2 can't handle such output. */
775 else if (MEM_P (value) && CONSTANT_P (XEXP (value, 0))
776 && ! TREE_STATIC (decl))
777 return;
778
779 /* Emit any structure, union, or enum type that has not been output.
780 This occurs for tag-less structs (et al) used to declare variables
781 within functions. */
782 if (TREE_CODE (type) == ENUMERAL_TYPE
783 || TREE_CODE (type) == RECORD_TYPE
784 || TREE_CODE (type) == UNION_TYPE
785 || TREE_CODE (type) == QUAL_UNION_TYPE)
786 {
787 if (COMPLETE_TYPE_P (type) /* not a forward reference */
788 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
789 sdbout_one_type (type);
790 }
791
792 /* Defer SDB information for top-level initialized variables! */
793 if (! local
794 && MEM_P (value)
795 && DECL_INITIAL (decl))
796 return;
797
798 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
799 For now, avoid crashing. */
800 if (DECL_NAME (decl) == NULL_TREE)
801 return;
802
803 /* Record the name for, starting a symtab entry. */
804 if (local)
805 name = IDENTIFIER_POINTER (DECL_NAME (decl));
806 else
807 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
808
809 if (MEM_P (value)
810 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
811 {
812 PUT_SDB_DEF (name);
813 if (TREE_PUBLIC (decl))
814 {
815 PUT_SDB_VAL (XEXP (value, 0));
816 PUT_SDB_SCL (C_EXT);
817 }
818 else
819 {
820 PUT_SDB_VAL (XEXP (value, 0));
821 PUT_SDB_SCL (C_STAT);
822 }
823 }
824 else if (regno >= 0)
825 {
826 PUT_SDB_DEF (name);
827 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
828 PUT_SDB_SCL (C_REG);
829 }
830 else if (MEM_P (value)
831 && (MEM_P (XEXP (value, 0))
832 || (REG_P (XEXP (value, 0))
833 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
834 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
835 /* If the value is indirect by memory or by a register
836 that isn't the frame pointer
837 then it means the object is variable-sized and address through
838 that register or stack slot. COFF has no way to represent this
839 so all we can do is output the variable as a pointer. */
840 {
841 PUT_SDB_DEF (name);
842 if (REG_P (XEXP (value, 0)))
843 {
844 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
845 PUT_SDB_SCL (C_REG);
846 }
847 else
848 {
849 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
850 (CONST_INT...)))).
851 We want the value of that CONST_INT. */
852 /* Encore compiler hates a newline in a macro arg, it seems. */
853 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
854 (XEXP (XEXP (value, 0), 0)));
855 PUT_SDB_SCL (C_AUTO);
856 }
857
858 /* Effectively do build_pointer_type, but don't cache this type,
859 since it might be temporary whereas the type it points to
860 might have been saved for inlining. */
861 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
862 type = make_node (POINTER_TYPE);
863 TREE_TYPE (type) = TREE_TYPE (decl);
864 }
865 else if (MEM_P (value)
866 && ((GET_CODE (XEXP (value, 0)) == PLUS
867 && REG_P (XEXP (XEXP (value, 0), 0))
868 && CONST_INT_P (XEXP (XEXP (value, 0), 1)))
869 /* This is for variables which are at offset zero from
870 the frame pointer. This happens on the Alpha.
871 Non-frame pointer registers are excluded above. */
872 || (REG_P (XEXP (value, 0)))))
873 {
874 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
875 or (MEM (REG...)). We want the value of that CONST_INT
876 or zero. */
877 PUT_SDB_DEF (name);
878 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
879 PUT_SDB_SCL (C_AUTO);
880 }
881 else
882 {
883 /* It is something we don't know how to represent for SDB. */
884 return;
885 }
886 break;
887
888 default:
889 break;
890 }
891 PUT_SDB_TYPE (plain_type (type));
892 PUT_SDB_ENDEF;
893 }
894
895 /* Output SDB information for a top-level initialized variable
896 that has been delayed. */
897
898 static void
899 sdbout_toplevel_data (tree decl)
900 {
901 tree type = TREE_TYPE (decl);
902
903 if (DECL_IGNORED_P (decl))
904 return;
905
906 gcc_assert (TREE_CODE (decl) == VAR_DECL);
907 gcc_assert (MEM_P (DECL_RTL (decl)));
908 gcc_assert (DECL_INITIAL (decl));
909
910 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
911 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
912 if (TREE_PUBLIC (decl))
913 {
914 PUT_SDB_SCL (C_EXT);
915 }
916 else
917 {
918 PUT_SDB_SCL (C_STAT);
919 }
920 PUT_SDB_TYPE (plain_type (type));
921 PUT_SDB_ENDEF;
922 }
923
924 #ifdef SDB_ALLOW_FORWARD_REFERENCES
925
926 /* Machinery to record and output anonymous types. */
927
928 static void
929 sdbout_queue_anonymous_type (tree type)
930 {
931 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
932 }
933
934 static void
935 sdbout_dequeue_anonymous_types (void)
936 {
937 tree types, link;
938
939 while (anonymous_types)
940 {
941 types = nreverse (anonymous_types);
942 anonymous_types = NULL_TREE;
943
944 for (link = types; link; link = TREE_CHAIN (link))
945 {
946 tree type = TREE_VALUE (link);
947
948 if (type && ! TREE_ASM_WRITTEN (type))
949 sdbout_one_type (type);
950 }
951 }
952 }
953
954 #endif
955
956 /* Given a chain of ..._TYPE nodes, all of which have names,
957 output definitions of those names, as typedefs. */
958
959 void
960 sdbout_types (tree types)
961 {
962 tree link;
963
964 for (link = types; link; link = TREE_CHAIN (link))
965 sdbout_one_type (link);
966
967 #ifdef SDB_ALLOW_FORWARD_REFERENCES
968 sdbout_dequeue_anonymous_types ();
969 #endif
970 }
971
972 static void
973 sdbout_type (tree type)
974 {
975 if (type == error_mark_node)
976 type = integer_type_node;
977 PUT_SDB_TYPE (plain_type (type));
978 }
979
980 /* Output types of the fields of type TYPE, if they are structs.
981
982 Formerly did not chase through pointer types, since that could be circular.
983 They must come before TYPE, since forward refs are not allowed.
984 Now james@bigtex.cactus.org says to try them. */
985
986 static void
987 sdbout_field_types (tree type)
988 {
989 tree tail;
990
991 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
992 /* This condition should match the one for emitting the actual
993 members below. */
994 if (TREE_CODE (tail) == FIELD_DECL
995 && DECL_NAME (tail)
996 && DECL_SIZE (tail)
997 && host_integerp (DECL_SIZE (tail), 1)
998 && host_integerp (bit_position (tail), 0))
999 {
1000 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1001 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1002 else
1003 sdbout_one_type (TREE_TYPE (tail));
1004 }
1005 }
1006
1007 /* Use this to put out the top level defined record and union types
1008 for later reference. If this is a struct with a name, then put that
1009 name out. Other unnamed structs will have .xxfake labels generated so
1010 that they may be referred to later.
1011 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1012 It may NOT be called recursively. */
1013
1014 static void
1015 sdbout_one_type (tree type)
1016 {
1017 if (current_function_decl != NULL_TREE
1018 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1019 ; /* Don't change section amid function. */
1020 else
1021 switch_to_section (current_function_section ());
1022
1023 switch (TREE_CODE (type))
1024 {
1025 case RECORD_TYPE:
1026 case UNION_TYPE:
1027 case QUAL_UNION_TYPE:
1028 case ENUMERAL_TYPE:
1029 type = TYPE_MAIN_VARIANT (type);
1030 /* Don't output a type twice. */
1031 if (TREE_ASM_WRITTEN (type))
1032 /* James said test TREE_ASM_BEING_WRITTEN here. */
1033 return;
1034
1035 /* Output nothing if type is not yet defined. */
1036 if (!COMPLETE_TYPE_P (type))
1037 return;
1038
1039 TREE_ASM_WRITTEN (type) = 1;
1040
1041 /* This is reputed to cause trouble with the following case,
1042 but perhaps checking TYPE_SIZE above will fix it. */
1043
1044 /* Here is a testcase:
1045
1046 struct foo {
1047 struct badstr *bbb;
1048 } forwardref;
1049
1050 typedef struct intermediate {
1051 int aaaa;
1052 } intermediate_ref;
1053
1054 typedef struct badstr {
1055 int ccccc;
1056 } badtype; */
1057
1058 /* This change, which ought to make better output,
1059 used to make the COFF assembler unhappy.
1060 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1061 /* Before really doing anything, output types we want to refer to. */
1062 /* Note that in version 1 the following two lines
1063 are not used if forward references are in use. */
1064 if (TREE_CODE (type) != ENUMERAL_TYPE)
1065 sdbout_field_types (type);
1066
1067 /* Output a structure type. */
1068 {
1069 int size = int_size_in_bytes (type);
1070 int member_scl = 0;
1071 tree tem;
1072
1073 /* Record the type tag, but not in its permanent place just yet. */
1074 sdbout_record_type_name (type);
1075
1076 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1077
1078 switch (TREE_CODE (type))
1079 {
1080 case UNION_TYPE:
1081 case QUAL_UNION_TYPE:
1082 PUT_SDB_SCL (C_UNTAG);
1083 PUT_SDB_TYPE (T_UNION);
1084 member_scl = C_MOU;
1085 break;
1086
1087 case RECORD_TYPE:
1088 PUT_SDB_SCL (C_STRTAG);
1089 PUT_SDB_TYPE (T_STRUCT);
1090 member_scl = C_MOS;
1091 break;
1092
1093 case ENUMERAL_TYPE:
1094 PUT_SDB_SCL (C_ENTAG);
1095 PUT_SDB_TYPE (T_ENUM);
1096 member_scl = C_MOE;
1097 break;
1098
1099 default:
1100 break;
1101 }
1102
1103 PUT_SDB_SIZE (size);
1104 PUT_SDB_ENDEF;
1105
1106 /* Print out the base class information with fields
1107 named after the types they hold. */
1108 /* This is only relevant to aggregate types. TYPE_BINFO is used
1109 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1110 case. */
1111 if (TREE_CODE (type) != ENUMERAL_TYPE && TYPE_BINFO (type))
1112 {
1113 int i;
1114 tree binfo, child;
1115
1116 for (binfo = TYPE_BINFO (type), i = 0;
1117 BINFO_BASE_ITERATE (binfo, i, child); i++)
1118 {
1119 tree child_type = BINFO_TYPE (child);
1120 tree child_type_name;
1121
1122 if (TYPE_NAME (child_type) == 0)
1123 continue;
1124 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1125 child_type_name = TYPE_NAME (child_type);
1126 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1127 {
1128 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1129 if (child_type_name && template_name_p (child_type_name))
1130 child_type_name
1131 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1132 }
1133 else
1134 continue;
1135
1136 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1137 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1138 PUT_SDB_SCL (member_scl);
1139 sdbout_type (BINFO_TYPE (child));
1140 PUT_SDB_ENDEF;
1141 }
1142 }
1143
1144 /* Output the individual fields. */
1145
1146 if (TREE_CODE (type) == ENUMERAL_TYPE)
1147 {
1148 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1149 {
1150 tree value = TREE_VALUE (tem);
1151
1152 if (TREE_CODE (value) == CONST_DECL)
1153 value = DECL_INITIAL (value);
1154
1155 if (host_integerp (value, 0))
1156 {
1157 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1158 PUT_SDB_INT_VAL (tree_low_cst (value, 0));
1159 PUT_SDB_SCL (C_MOE);
1160 PUT_SDB_TYPE (T_MOE);
1161 PUT_SDB_ENDEF;
1162 }
1163 }
1164 }
1165 else /* record or union type */
1166 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1167 /* Output the name, type, position (in bits), size (in bits)
1168 of each field. */
1169
1170 /* Omit here the nameless fields that are used to skip bits.
1171 Also omit fields with variable size or position.
1172 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1173 if (TREE_CODE (tem) == FIELD_DECL
1174 && DECL_NAME (tem)
1175 && DECL_SIZE (tem)
1176 && host_integerp (DECL_SIZE (tem), 1)
1177 && host_integerp (bit_position (tem), 0))
1178 {
1179 const char *name;
1180
1181 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1182 PUT_SDB_DEF (name);
1183 if (DECL_BIT_FIELD_TYPE (tem))
1184 {
1185 PUT_SDB_INT_VAL (int_bit_position (tem));
1186 PUT_SDB_SCL (C_FIELD);
1187 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1188 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1189 }
1190 else
1191 {
1192 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1193 PUT_SDB_SCL (member_scl);
1194 sdbout_type (TREE_TYPE (tem));
1195 }
1196 PUT_SDB_ENDEF;
1197 }
1198 /* Output end of a structure,union, or enumeral definition. */
1199
1200 PUT_SDB_PLAIN_DEF ("eos");
1201 PUT_SDB_INT_VAL (size);
1202 PUT_SDB_SCL (C_EOS);
1203 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1204 PUT_SDB_SIZE (size);
1205 PUT_SDB_ENDEF;
1206 break;
1207 }
1208
1209 default:
1210 break;
1211 }
1212 }
1213
1214 /* The following two functions output definitions of function parameters.
1215 Each parameter gets a definition locating it in the parameter list.
1216 Each parameter that is a register variable gets a second definition
1217 locating it in the register.
1218
1219 Printing or argument lists in gdb uses the definitions that
1220 locate in the parameter list. But reference to the variable in
1221 expressions uses preferentially the definition as a register. */
1222
1223 /* Output definitions, referring to storage in the parmlist,
1224 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1225
1226 static void
1227 sdbout_parms (tree parms)
1228 {
1229 for (; parms; parms = TREE_CHAIN (parms))
1230 if (DECL_NAME (parms))
1231 {
1232 int current_sym_value = 0;
1233 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1234
1235 if (name == 0 || *name == 0)
1236 name = gen_fake_label ();
1237
1238 /* Perform any necessary register eliminations on the parameter's rtl,
1239 so that the debugging output will be accurate. */
1240 DECL_INCOMING_RTL (parms)
1241 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX);
1242 SET_DECL_RTL (parms,
1243 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX));
1244
1245 if (PARM_PASSED_IN_MEMORY (parms))
1246 {
1247 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1248 tree type;
1249
1250 /* ??? Here we assume that the parm address is indexed
1251 off the frame pointer or arg pointer.
1252 If that is not true, we produce meaningless results,
1253 but do not crash. */
1254 if (GET_CODE (addr) == PLUS
1255 && CONST_INT_P (XEXP (addr, 1)))
1256 current_sym_value = INTVAL (XEXP (addr, 1));
1257 else
1258 current_sym_value = 0;
1259
1260 if (REG_P (DECL_RTL (parms))
1261 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1262 type = DECL_ARG_TYPE (parms);
1263 else
1264 {
1265 int original_sym_value = current_sym_value;
1266
1267 /* This is the case where the parm is passed as an int or
1268 double and it is converted to a char, short or float
1269 and stored back in the parmlist. In this case, describe
1270 the parm with the variable's declared type, and adjust
1271 the address if the least significant bytes (which we are
1272 using) are not the first ones. */
1273 if (BYTES_BIG_ENDIAN
1274 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1275 current_sym_value +=
1276 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1277 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1278
1279 if (MEM_P (DECL_RTL (parms))
1280 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1281 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1282 == CONST_INT)
1283 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1284 == current_sym_value))
1285 type = TREE_TYPE (parms);
1286 else
1287 {
1288 current_sym_value = original_sym_value;
1289 type = DECL_ARG_TYPE (parms);
1290 }
1291 }
1292
1293 PUT_SDB_DEF (name);
1294 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1295 PUT_SDB_SCL (C_ARG);
1296 PUT_SDB_TYPE (plain_type (type));
1297 PUT_SDB_ENDEF;
1298 }
1299 else if (REG_P (DECL_RTL (parms)))
1300 {
1301 rtx best_rtl;
1302 /* Parm passed in registers and lives in registers or nowhere. */
1303
1304 /* If parm lives in a register, use that register;
1305 pretend the parm was passed there. It would be more consistent
1306 to describe the register where the parm was passed,
1307 but in practice that register usually holds something else. */
1308 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1309 best_rtl = DECL_RTL (parms);
1310 /* If the parm lives nowhere,
1311 use the register where it was passed. */
1312 else
1313 best_rtl = DECL_INCOMING_RTL (parms);
1314
1315 PUT_SDB_DEF (name);
1316 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1317 PUT_SDB_SCL (C_REGPARM);
1318 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1319 PUT_SDB_ENDEF;
1320 }
1321 else if (MEM_P (DECL_RTL (parms))
1322 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1323 {
1324 /* Parm was passed in registers but lives on the stack. */
1325
1326 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1327 in which case we want the value of that CONST_INT,
1328 or (MEM (REG ...)) or (MEM (MEM ...)),
1329 in which case we use a value of zero. */
1330 if (REG_P (XEXP (DECL_RTL (parms), 0))
1331 || MEM_P (XEXP (DECL_RTL (parms), 0)))
1332 current_sym_value = 0;
1333 else
1334 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1335
1336 /* Again, this assumes the offset is based on the arg pointer. */
1337 PUT_SDB_DEF (name);
1338 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1339 XEXP (DECL_RTL (parms), 0)));
1340 PUT_SDB_SCL (C_ARG);
1341 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1342 PUT_SDB_ENDEF;
1343 }
1344 }
1345 }
1346
1347 /* Output definitions for the places where parms live during the function,
1348 when different from where they were passed, when the parms were passed
1349 in memory.
1350
1351 It is not useful to do this for parms passed in registers
1352 that live during the function in different registers, because it is
1353 impossible to look in the passed register for the passed value,
1354 so we use the within-the-function register to begin with.
1355
1356 PARMS is a chain of PARM_DECL nodes. */
1357
1358 static void
1359 sdbout_reg_parms (tree parms)
1360 {
1361 for (; parms; parms = TREE_CHAIN (parms))
1362 if (DECL_NAME (parms))
1363 {
1364 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1365
1366 /* Report parms that live in registers during the function
1367 but were passed in memory. */
1368 if (REG_P (DECL_RTL (parms))
1369 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1370 && PARM_PASSED_IN_MEMORY (parms))
1371 {
1372 if (name == 0 || *name == 0)
1373 name = gen_fake_label ();
1374 PUT_SDB_DEF (name);
1375 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1376 PUT_SDB_SCL (C_REG);
1377 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1378 PUT_SDB_ENDEF;
1379 }
1380 /* Report parms that live in memory but not where they were passed. */
1381 else if (MEM_P (DECL_RTL (parms))
1382 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1383 && CONST_INT_P (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1384 && PARM_PASSED_IN_MEMORY (parms)
1385 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1386 {
1387 #if 0 /* ??? It is not clear yet what should replace this. */
1388 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1389 /* A parm declared char is really passed as an int,
1390 so it occupies the least significant bytes.
1391 On a big-endian machine those are not the low-numbered ones. */
1392 if (BYTES_BIG_ENDIAN
1393 && offset != -1
1394 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1395 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1396 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1397 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1398 #endif
1399 {
1400 if (name == 0 || *name == 0)
1401 name = gen_fake_label ();
1402 PUT_SDB_DEF (name);
1403 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1404 (XEXP (DECL_RTL (parms), 0)));
1405 PUT_SDB_SCL (C_AUTO);
1406 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1407 PUT_SDB_ENDEF;
1408 }
1409 }
1410 }
1411 }
1412
1413 /* Output debug information for a global DECL. Called from toplev.c
1414 after compilation proper has finished. */
1415
1416 static void
1417 sdbout_global_decl (tree decl)
1418 {
1419 if (TREE_CODE (decl) == VAR_DECL
1420 && !DECL_EXTERNAL (decl)
1421 && DECL_RTL_SET_P (decl))
1422 {
1423 /* The COFF linker can move initialized global vars to the end.
1424 And that can screw up the symbol ordering. Defer those for
1425 sdbout_finish (). */
1426 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1427 sdbout_symbol (decl, 0);
1428 else
1429 vec_safe_push (deferred_global_decls, decl);
1430
1431 /* Output COFF information for non-global file-scope initialized
1432 variables. */
1433 if (DECL_INITIAL (decl) && MEM_P (DECL_RTL (decl)))
1434 sdbout_toplevel_data (decl);
1435 }
1436 }
1437
1438 /* Output initialized global vars at the end, in the order of
1439 definition. See comment in sdbout_global_decl. */
1440
1441 static void
1442 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1443 {
1444 size_t i;
1445 tree decl;
1446
1447 FOR_EACH_VEC_SAFE_ELT (deferred_global_decls, i, decl)
1448 sdbout_symbol (decl, 0);
1449 }
1450
1451 /* Describe the beginning of an internal block within a function.
1452 Also output descriptions of variables defined in this block.
1453
1454 N is the number of the block, by order of beginning, counting from 1,
1455 and not counting the outermost (function top-level) block.
1456 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1457 if the count starts at 0 for the outermost one. */
1458
1459 static void
1460 sdbout_begin_block (unsigned int line, unsigned int n)
1461 {
1462 tree decl = current_function_decl;
1463 MAKE_LINE_SAFE (line);
1464
1465 /* The SCO compiler does not emit a separate block for the function level
1466 scope, so we avoid it here also. */
1467 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1468
1469 if (n == 1)
1470 {
1471 /* Include the outermost BLOCK's variables in block 1. */
1472 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1473 sdbout_block (DECL_INITIAL (decl));
1474 }
1475 /* If -g1, suppress all the internal symbols of functions
1476 except for arguments. */
1477 if (debug_info_level != DINFO_LEVEL_TERSE)
1478 {
1479 do_block = n;
1480 sdbout_block (DECL_INITIAL (decl));
1481 }
1482
1483 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1484 sdbout_dequeue_anonymous_types ();
1485 #endif
1486 }
1487
1488 /* Describe the end line-number of an internal block within a function. */
1489
1490 static void
1491 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1492 {
1493 MAKE_LINE_SAFE (line);
1494
1495 /* The SCO compiler does not emit a separate block for the function level
1496 scope, so we avoid it here also. */
1497 if (n != 1)
1498 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1499 }
1500
1501 /* Output a line number symbol entry for source file FILENAME and line
1502 number LINE. */
1503
1504 static void
1505 sdbout_source_line (unsigned int line, const char *filename ATTRIBUTE_UNUSED,
1506 int discriminator ATTRIBUTE_UNUSED,
1507 bool is_stmt ATTRIBUTE_UNUSED)
1508 {
1509 /* COFF relative line numbers must be positive. */
1510 if ((int) line > sdb_begin_function_line)
1511 {
1512 #ifdef SDB_OUTPUT_SOURCE_LINE
1513 SDB_OUTPUT_SOURCE_LINE (asm_out_file, line);
1514 #else
1515 fprintf (asm_out_file, "\t.ln\t%d\n",
1516 ((sdb_begin_function_line > -1)
1517 ? line - sdb_begin_function_line : 1));
1518 #endif
1519 }
1520 }
1521
1522 /* Output sdb info for the current function name.
1523 Called from assemble_start_function. */
1524
1525 static void
1526 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1527 {
1528 sdbout_symbol (current_function_decl, 0);
1529 }
1530
1531 /* Called at beginning of function body after prologue. Record the
1532 function's starting line number, so we can output relative line numbers
1533 for the other lines. Describe beginning of outermost block. Also
1534 describe the parameter list. */
1535
1536 static void
1537 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1538 {
1539 sdbout_end_prologue (line, file);
1540 }
1541
1542 static void
1543 sdbout_end_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1544 {
1545 sdb_begin_function_line = line - 1;
1546 PUT_SDB_FUNCTION_START (line);
1547 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1548 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1549 }
1550
1551 /* Called at end of function (before epilogue).
1552 Describe end of outermost block. */
1553
1554 static void
1555 sdbout_end_function (unsigned int line)
1556 {
1557 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1558 sdbout_dequeue_anonymous_types ();
1559 #endif
1560
1561 MAKE_LINE_SAFE (line);
1562 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1563
1564 /* Indicate we are between functions, for line-number output. */
1565 sdb_begin_function_line = -1;
1566 }
1567
1568 /* Output sdb info for the absolute end of a function.
1569 Called after the epilogue is output. */
1570
1571 static void
1572 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1573 const char *file ATTRIBUTE_UNUSED)
1574 {
1575 const char *const name ATTRIBUTE_UNUSED
1576 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1577
1578 #ifdef PUT_SDB_EPILOGUE_END
1579 PUT_SDB_EPILOGUE_END (name);
1580 #else
1581 fprintf (asm_out_file, "\t.def\t");
1582 assemble_name (asm_out_file, name);
1583 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1584 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1585 #endif
1586 }
1587
1588 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1589 is present. */
1590
1591 static void
1592 sdbout_label (rtx insn)
1593 {
1594 PUT_SDB_DEF (LABEL_NAME (insn));
1595 PUT_SDB_VAL (insn);
1596 PUT_SDB_SCL (C_LABEL);
1597 PUT_SDB_TYPE (T_NULL);
1598 PUT_SDB_ENDEF;
1599 }
1600
1601 /* Change to reading from a new source file. */
1602
1603 static void
1604 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1605 const char *filename ATTRIBUTE_UNUSED)
1606 {
1607 }
1608
1609 /* Revert to reading a previous source file. */
1610
1611 static void
1612 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1613 {
1614 }
1615
1616 /* Set up for SDB output at the start of compilation. */
1617
1618 static void
1619 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1620 {
1621 tree t;
1622
1623 vec_alloc (deferred_global_decls, 12);
1624
1625 /* Emit debug information which was queued by sdbout_symbol before
1626 we got here. */
1627 sdbout_initialized = true;
1628
1629 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
1630 sdbout_symbol (TREE_VALUE (t), 0);
1631 preinit_symbols = 0;
1632 }
1633
1634 #endif /* SDB_DEBUGGING_INFO */
1635
1636 #include "gt-sdbout.h"