config.gcc: Reorganize --with-cpu section.
[official-gcc.git] / gcc / sdbout.c
blob0af958c79247895d7f5733bf59f5e82a504f44c3
1 /* Output sdb-format symbol table information from GNU compiler.
2 Copyright (C) 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999,
3 2000, 2001, 2002, 2003 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
17 You should have received a copy of the GNU General Public License
18 along with GCC; see the file COPYING. If not, write to the Free
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA
20 02111-1307, USA. */
22 /* mike@tredysvr.Tredydev.Unisys.COM says:
23 I modified the struct.c example and have a nm of a .o resulting from the
24 AT&T C compiler. From the example below I would conclude the following:
26 1. All .defs from structures are emitted as scanned. The example below
27 clearly shows the symbol table entries for BoxRec2 are after the first
28 function.
30 2. All functions and their locals (including statics) are emitted as scanned.
32 3. All nested unnamed union and structure .defs must be emitted before
33 the structure in which they are nested. The AT&T assembler is a
34 one pass beast as far as symbolics are concerned.
36 4. All structure .defs are emitted before the typedefs that refer to them.
38 5. All top level static and external variable definitions are moved to the
39 end of file with all top level statics occurring first before externs.
41 6. All undefined references are at the end of the file.
44 #include "config.h"
45 #include "system.h"
46 #include "coretypes.h"
47 #include "tm.h"
48 #include "debug.h"
49 #include "tree.h"
50 #include "ggc.h"
52 static GTY(()) tree anonymous_types;
54 #ifdef SDB_DEBUGGING_INFO
56 #include "rtl.h"
57 #include "regs.h"
58 #include "flags.h"
59 #include "insn-config.h"
60 #include "reload.h"
61 #include "output.h"
62 #include "toplev.h"
63 #include "tm_p.h"
64 #include "gsyms.h"
65 #include "langhooks.h"
66 #include "target.h"
68 /* 1 if PARM is passed to this function in memory. */
70 #define PARM_PASSED_IN_MEMORY(PARM) \
71 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
73 /* A C expression for the integer offset value of an automatic variable
74 (C_AUTO) having address X (an RTX). */
75 #ifndef DEBUGGER_AUTO_OFFSET
76 #define DEBUGGER_AUTO_OFFSET(X) \
77 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
78 #endif
80 /* A C expression for the integer offset value of an argument (C_ARG)
81 having address X (an RTX). The nominal offset is OFFSET. */
82 #ifndef DEBUGGER_ARG_OFFSET
83 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
84 #endif
86 /* Line number of beginning of current function, minus one.
87 Negative means not in a function or not using sdb. */
89 int sdb_begin_function_line = -1;
91 /* Counter to generate unique "names" for nameless struct members. */
93 static int unnamed_struct_number = 0;
95 extern FILE *asm_out_file;
97 extern tree current_function_decl;
99 #include "sdbout.h"
101 static void sdbout_init (const char *);
102 static void sdbout_finish (const char *);
103 static void sdbout_start_source_file (unsigned int, const char *);
104 static void sdbout_end_source_file (unsigned int);
105 static void sdbout_begin_block (unsigned int, unsigned int);
106 static void sdbout_end_block (unsigned int, unsigned int);
107 static void sdbout_source_line (unsigned int, const char *);
108 static void sdbout_end_epilogue (unsigned int, const char *);
109 static void sdbout_global_decl (tree);
110 #ifndef MIPS_DEBUGGING_INFO
111 static void sdbout_begin_prologue (unsigned int, const char *);
112 #endif
113 static void sdbout_end_prologue (unsigned int, const char *);
114 static void sdbout_begin_function (tree);
115 static void sdbout_end_function (unsigned int);
116 static void sdbout_toplevel_data (tree);
117 static void sdbout_label (rtx);
118 static char *gen_fake_label (void);
119 static int plain_type (tree);
120 static int template_name_p (tree);
121 static void sdbout_record_type_name (tree);
122 static int plain_type_1 (tree, int);
123 static void sdbout_block (tree);
124 static void sdbout_syms (tree);
125 #ifdef SDB_ALLOW_FORWARD_REFERENCES
126 static void sdbout_queue_anonymous_type (tree);
127 static void sdbout_dequeue_anonymous_types (void);
128 #endif
129 static void sdbout_type (tree);
130 static void sdbout_field_types (tree);
131 static void sdbout_one_type (tree);
132 static void sdbout_parms (tree);
133 static void sdbout_reg_parms (tree);
134 static void sdbout_global_decl (tree);
136 /* Random macros describing parts of SDB data. */
138 /* Default value of delimiter is ";". */
139 #ifndef SDB_DELIM
140 #define SDB_DELIM ";"
141 #endif
143 /* Maximum number of dimensions the assembler will allow. */
144 #ifndef SDB_MAX_DIM
145 #define SDB_MAX_DIM 4
146 #endif
148 #ifndef PUT_SDB_SCL
149 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
150 #endif
152 #ifndef PUT_SDB_INT_VAL
153 #define PUT_SDB_INT_VAL(a) \
154 do { \
155 fprintf (asm_out_file, "\t.val\t" HOST_WIDE_INT_PRINT_DEC "%s", \
156 (HOST_WIDE_INT) (a), SDB_DELIM); \
157 } while (0)
159 #endif
161 #ifndef PUT_SDB_VAL
162 #define PUT_SDB_VAL(a) \
163 ( fputs ("\t.val\t", asm_out_file), \
164 output_addr_const (asm_out_file, (a)), \
165 fprintf (asm_out_file, SDB_DELIM))
166 #endif
168 #ifndef PUT_SDB_DEF
169 #define PUT_SDB_DEF(a) \
170 do { fprintf (asm_out_file, "\t.def\t"); \
171 assemble_name (asm_out_file, a); \
172 fprintf (asm_out_file, SDB_DELIM); } while (0)
173 #endif
175 #ifndef PUT_SDB_PLAIN_DEF
176 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
177 #endif
179 #ifndef PUT_SDB_ENDEF
180 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
181 #endif
183 #ifndef PUT_SDB_TYPE
184 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
185 #endif
187 #ifndef PUT_SDB_SIZE
188 #define PUT_SDB_SIZE(a) \
189 do { \
190 fprintf (asm_out_file, "\t.size\t" HOST_WIDE_INT_PRINT_DEC "%s", \
191 (HOST_WIDE_INT) (a), SDB_DELIM); \
192 } while(0)
193 #endif
195 #ifndef PUT_SDB_START_DIM
196 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
197 #endif
199 #ifndef PUT_SDB_NEXT_DIM
200 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
201 #endif
203 #ifndef PUT_SDB_LAST_DIM
204 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
205 #endif
207 #ifndef PUT_SDB_TAG
208 #define PUT_SDB_TAG(a) \
209 do { fprintf (asm_out_file, "\t.tag\t"); \
210 assemble_name (asm_out_file, a); \
211 fprintf (asm_out_file, SDB_DELIM); } while (0)
212 #endif
214 #ifndef PUT_SDB_BLOCK_START
215 #define PUT_SDB_BLOCK_START(LINE) \
216 fprintf (asm_out_file, \
217 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
218 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
219 #endif
221 #ifndef PUT_SDB_BLOCK_END
222 #define PUT_SDB_BLOCK_END(LINE) \
223 fprintf (asm_out_file, \
224 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
225 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
226 #endif
228 #ifndef PUT_SDB_FUNCTION_START
229 #define PUT_SDB_FUNCTION_START(LINE) \
230 fprintf (asm_out_file, \
231 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
232 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
233 #endif
235 #ifndef PUT_SDB_FUNCTION_END
236 #define PUT_SDB_FUNCTION_END(LINE) \
237 fprintf (asm_out_file, \
238 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
239 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
240 #endif
242 #ifndef SDB_GENERATE_FAKE
243 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
244 sprintf ((BUFFER), ".%dfake", (NUMBER));
245 #endif
247 /* Return the sdb tag identifier string for TYPE
248 if TYPE has already been defined; otherwise return a null pointer. */
250 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
252 /* Set the sdb tag identifier string for TYPE to NAME. */
254 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
255 TYPE_SYMTAB_POINTER (TYPE) = (char *)(NAME)
257 /* Return the name (a string) of the struct, union or enum tag
258 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
260 #define TAG_NAME(link) \
261 (((link) && TREE_PURPOSE ((link)) \
262 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
263 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
265 /* Ensure we don't output a negative line number. */
266 #define MAKE_LINE_SAFE(line) \
267 if ((int) line <= sdb_begin_function_line) \
268 line = sdb_begin_function_line + 1
270 /* Perform linker optimization of merging header file definitions together
271 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
272 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
273 the optimization just won't be done. The native assembler already has the
274 necessary support. */
276 #ifdef MIPS_DEBUGGING_INFO
278 #ifndef PUT_SDB_SRC_FILE
279 #define PUT_SDB_SRC_FILE(FILENAME) \
280 output_file_directive (asm_out_file, (FILENAME))
281 #endif
283 /* ECOFF linkers have an optimization that does the same kind of thing as
284 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
285 executable. To achieve this, GCC must output a .file for each file
286 name change. */
288 /* This is a stack of input files. */
290 struct sdb_file
292 struct sdb_file *next;
293 const char *name;
296 /* This is the top of the stack. */
298 static struct sdb_file *current_file;
300 #endif /* MIPS_DEBUGGING_INFO */
302 /* The debug hooks structure. */
303 const struct gcc_debug_hooks sdb_debug_hooks =
305 sdbout_init, /* init */
306 sdbout_finish, /* finish */
307 debug_nothing_int_charstar, /* define */
308 debug_nothing_int_charstar, /* undef */
309 sdbout_start_source_file, /* start_source_file */
310 sdbout_end_source_file, /* end_source_file */
311 sdbout_begin_block, /* begin_block */
312 sdbout_end_block, /* end_block */
313 debug_true_tree, /* ignore_block */
314 sdbout_source_line, /* source_line */
315 #ifdef MIPS_DEBUGGING_INFO
316 /* Defer on MIPS systems so that parameter descriptions follow
317 function entry. */
318 debug_nothing_int_charstar, /* begin_prologue */
319 sdbout_end_prologue, /* end_prologue */
320 #else
321 sdbout_begin_prologue, /* begin_prologue */
322 debug_nothing_int_charstar, /* end_prologue */
323 #endif
324 sdbout_end_epilogue, /* end_epilogue */
325 sdbout_begin_function, /* begin_function */
326 sdbout_end_function, /* end_function */
327 debug_nothing_tree, /* function_decl */
328 sdbout_global_decl, /* global_decl */
329 debug_nothing_tree, /* deferred_inline_function */
330 debug_nothing_tree, /* outlining_inline_function */
331 sdbout_label, /* label */
332 debug_nothing_int /* handle_pch */
335 /* Return a unique string to name an anonymous type. */
337 static char *
338 gen_fake_label (void)
340 char label[10];
341 char *labelstr;
342 SDB_GENERATE_FAKE (label, unnamed_struct_number);
343 unnamed_struct_number++;
344 labelstr = xstrdup (label);
345 return labelstr;
348 /* Return the number which describes TYPE for SDB.
349 For pointers, etc., this function is recursive.
350 Each record, union or enumeral type must already have had a
351 tag number output. */
353 /* The number is given by d6d5d4d3d2d1bbbb
354 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
355 Thus, char *foo () has bbbb=T_CHAR
356 d1=D_FCN
357 d2=D_PTR
358 N_BTMASK= 017 1111 basic type field.
359 N_TSHIFT= 2 derived type shift
360 N_BTSHFT= 4 Basic type shift */
362 /* Produce the number that describes a pointer, function or array type.
363 PREV is the number describing the target, value or element type.
364 DT_type describes how to transform that type. */
365 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
366 ((((PREV) & ~(int) N_BTMASK) << (int) N_TSHIFT) \
367 | ((int) DT_type << (int) N_BTSHFT) \
368 | ((PREV) & (int) N_BTMASK))
370 /* Number of elements used in sdb_dims. */
371 static int sdb_n_dims = 0;
373 /* Table of array dimensions of current type. */
374 static int sdb_dims[SDB_MAX_DIM];
376 /* Size of outermost array currently being processed. */
377 static int sdb_type_size = -1;
379 static int
380 plain_type (tree type)
382 int val = plain_type_1 (type, 0);
384 /* If we have already saved up some array dimensions, print them now. */
385 if (sdb_n_dims > 0)
387 int i;
388 PUT_SDB_START_DIM;
389 for (i = sdb_n_dims - 1; i > 0; i--)
390 PUT_SDB_NEXT_DIM (sdb_dims[i]);
391 PUT_SDB_LAST_DIM (sdb_dims[0]);
392 sdb_n_dims = 0;
394 sdb_type_size = int_size_in_bytes (type);
395 /* Don't kill sdb if type is not laid out or has variable size. */
396 if (sdb_type_size < 0)
397 sdb_type_size = 0;
399 /* If we have computed the size of an array containing this type,
400 print it now. */
401 if (sdb_type_size >= 0)
403 PUT_SDB_SIZE (sdb_type_size);
404 sdb_type_size = -1;
406 return val;
409 static int
410 template_name_p (tree name)
412 const char *ptr = IDENTIFIER_POINTER (name);
413 while (*ptr && *ptr != '<')
414 ptr++;
416 return *ptr != '\0';
419 static void
420 sdbout_record_type_name (tree type)
422 const char *name = 0;
423 int no_name;
425 if (KNOWN_TYPE_TAG (type))
426 return;
428 if (TYPE_NAME (type) != 0)
430 tree t = 0;
432 /* Find the IDENTIFIER_NODE for the type name. */
433 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
434 t = TYPE_NAME (type);
435 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
437 t = DECL_NAME (TYPE_NAME (type));
438 /* The DECL_NAME for templates includes "<>", which breaks
439 most assemblers. Use its assembler name instead, which
440 has been mangled into being safe. */
441 if (t && template_name_p (t))
442 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
445 /* Now get the name as a string, or invent one. */
446 if (t != NULL_TREE)
447 name = IDENTIFIER_POINTER (t);
450 no_name = (name == 0 || *name == 0);
451 if (no_name)
452 name = gen_fake_label ();
454 SET_KNOWN_TYPE_TAG (type, name);
455 #ifdef SDB_ALLOW_FORWARD_REFERENCES
456 if (no_name)
457 sdbout_queue_anonymous_type (type);
458 #endif
461 /* Return the .type value for type TYPE.
463 LEVEL indicates how many levels deep we have recursed into the type.
464 The SDB debug format can only represent 6 derived levels of types.
465 After that, we must output inaccurate debug info. We deliberately
466 stop before the 7th level, so that ADA recursive types will not give an
467 infinite loop. */
469 static int
470 plain_type_1 (tree type, int level)
472 if (type == 0)
473 type = void_type_node;
474 else if (type == error_mark_node)
475 type = integer_type_node;
476 else
477 type = TYPE_MAIN_VARIANT (type);
479 switch (TREE_CODE (type))
481 case VOID_TYPE:
482 return T_VOID;
483 case BOOLEAN_TYPE:
484 case INTEGER_TYPE:
486 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
488 /* Carefully distinguish all the standard types of C,
489 without messing up if the language is not C.
490 Note that we check only for the names that contain spaces;
491 other names might occur by coincidence in other languages. */
492 if (TYPE_NAME (type) != 0
493 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
494 && DECL_NAME (TYPE_NAME (type)) != 0
495 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
497 const char *const name
498 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
500 if (!strcmp (name, "char"))
501 return T_CHAR;
502 if (!strcmp (name, "unsigned char"))
503 return T_UCHAR;
504 if (!strcmp (name, "signed char"))
505 return T_CHAR;
506 if (!strcmp (name, "int"))
507 return T_INT;
508 if (!strcmp (name, "unsigned int"))
509 return T_UINT;
510 if (!strcmp (name, "short int"))
511 return T_SHORT;
512 if (!strcmp (name, "short unsigned int"))
513 return T_USHORT;
514 if (!strcmp (name, "long int"))
515 return T_LONG;
516 if (!strcmp (name, "long unsigned int"))
517 return T_ULONG;
520 if (size == INT_TYPE_SIZE)
521 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
522 if (size == CHAR_TYPE_SIZE)
523 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
524 if (size == SHORT_TYPE_SIZE)
525 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
526 if (size == LONG_TYPE_SIZE)
527 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
528 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
529 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
530 return 0;
533 case REAL_TYPE:
535 int precision = TYPE_PRECISION (type);
536 if (precision == FLOAT_TYPE_SIZE)
537 return T_FLOAT;
538 if (precision == DOUBLE_TYPE_SIZE)
539 return T_DOUBLE;
540 #ifdef EXTENDED_SDB_BASIC_TYPES
541 if (precision == LONG_DOUBLE_TYPE_SIZE)
542 return T_LNGDBL;
543 #else
544 if (precision == LONG_DOUBLE_TYPE_SIZE)
545 return T_DOUBLE; /* better than nothing */
546 #endif
547 return 0;
550 case ARRAY_TYPE:
552 int m;
553 if (level >= 6)
554 return T_VOID;
555 else
556 m = plain_type_1 (TREE_TYPE (type), level+1);
557 if (sdb_n_dims < SDB_MAX_DIM)
558 sdb_dims[sdb_n_dims++]
559 = (TYPE_DOMAIN (type)
560 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
561 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
562 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
563 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
564 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
565 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
566 : 0);
568 return PUSH_DERIVED_LEVEL (DT_ARY, m);
571 case RECORD_TYPE:
572 case UNION_TYPE:
573 case QUAL_UNION_TYPE:
574 case ENUMERAL_TYPE:
576 char *tag;
577 #ifdef SDB_ALLOW_FORWARD_REFERENCES
578 sdbout_record_type_name (type);
579 #endif
580 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
581 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
582 #ifdef SDB_ALLOW_FORWARD_REFERENCES
583 || TYPE_MODE (type) != VOIDmode
584 #endif
586 #endif
588 /* Output the referenced structure tag name
589 only if the .def has already been finished.
590 At least on 386, the Unix assembler
591 cannot handle forward references to tags. */
592 /* But the 88100, it requires them, sigh... */
593 /* And the MIPS requires unknown refs as well... */
594 tag = KNOWN_TYPE_TAG (type);
595 PUT_SDB_TAG (tag);
596 /* These 3 lines used to follow the close brace.
597 However, a size of 0 without a tag implies a tag of 0,
598 so if we don't know a tag, we can't mention the size. */
599 sdb_type_size = int_size_in_bytes (type);
600 if (sdb_type_size < 0)
601 sdb_type_size = 0;
603 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
604 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
605 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
606 : T_ENUM);
608 case POINTER_TYPE:
609 case REFERENCE_TYPE:
611 int m;
612 if (level >= 6)
613 return T_VOID;
614 else
615 m = plain_type_1 (TREE_TYPE (type), level+1);
616 return PUSH_DERIVED_LEVEL (DT_PTR, m);
618 case FUNCTION_TYPE:
619 case METHOD_TYPE:
621 int m;
622 if (level >= 6)
623 return T_VOID;
624 else
625 m = plain_type_1 (TREE_TYPE (type), level+1);
626 return PUSH_DERIVED_LEVEL (DT_FCN, m);
628 default:
629 return 0;
633 /* Output the symbols defined in block number DO_BLOCK.
635 This function works by walking the tree structure of blocks,
636 counting blocks until it finds the desired block. */
638 static int do_block = 0;
640 static void
641 sdbout_block (tree block)
643 while (block)
645 /* Ignore blocks never expanded or otherwise marked as real. */
646 if (TREE_USED (block))
648 /* When we reach the specified block, output its symbols. */
649 if (BLOCK_NUMBER (block) == do_block)
650 sdbout_syms (BLOCK_VARS (block));
652 /* If we are past the specified block, stop the scan. */
653 if (BLOCK_NUMBER (block) > do_block)
654 return;
656 /* Scan the blocks within this block. */
657 sdbout_block (BLOCK_SUBBLOCKS (block));
660 block = BLOCK_CHAIN (block);
664 /* Call sdbout_symbol on each decl in the chain SYMS. */
666 static void
667 sdbout_syms (tree syms)
669 while (syms)
671 if (TREE_CODE (syms) != LABEL_DECL)
672 sdbout_symbol (syms, 1);
673 syms = TREE_CHAIN (syms);
677 /* Output SDB information for a symbol described by DECL.
678 LOCAL is nonzero if the symbol is not file-scope. */
680 void
681 sdbout_symbol (tree decl, int local)
683 tree type = TREE_TYPE (decl);
684 tree context = NULL_TREE;
685 rtx value;
686 int regno = -1;
687 const char *name;
689 sdbout_one_type (type);
691 switch (TREE_CODE (decl))
693 case CONST_DECL:
694 /* Enum values are defined by defining the enum type. */
695 return;
697 case FUNCTION_DECL:
698 /* Don't mention a nested function under its parent. */
699 context = decl_function_context (decl);
700 if (context == current_function_decl)
701 return;
702 /* Check DECL_INITIAL to distinguish declarations from definitions.
703 Don't output debug info here for declarations; they will have
704 a DECL_INITIAL value of 0. */
705 if (! DECL_INITIAL (decl))
706 return;
707 if (GET_CODE (DECL_RTL (decl)) != MEM
708 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
709 return;
710 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
711 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
712 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
713 break;
715 case TYPE_DECL:
716 /* Done with tagged types. */
717 if (DECL_NAME (decl) == 0)
718 return;
719 if (DECL_IGNORED_P (decl))
720 return;
722 /* Output typedef name. */
723 if (template_name_p (DECL_NAME (decl)))
724 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
725 else
726 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
727 PUT_SDB_SCL (C_TPDEF);
728 break;
730 case PARM_DECL:
731 /* Parm decls go in their own separate chains
732 and are output by sdbout_reg_parms and sdbout_parms. */
733 abort ();
735 case VAR_DECL:
736 /* Don't mention a variable that is external.
737 Let the file that defines it describe it. */
738 if (DECL_EXTERNAL (decl))
739 return;
741 /* Ignore __FUNCTION__, etc. */
742 if (DECL_IGNORED_P (decl))
743 return;
745 /* If there was an error in the declaration, don't dump core
746 if there is no RTL associated with the variable doesn't
747 exist. */
748 if (!DECL_RTL_SET_P (decl))
749 return;
751 SET_DECL_RTL (decl,
752 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
753 #ifdef LEAF_REG_REMAP
754 if (current_function_uses_only_leaf_regs)
755 leaf_renumber_regs_insn (DECL_RTL (decl));
756 #endif
757 value = DECL_RTL (decl);
759 /* Don't mention a variable at all
760 if it was completely optimized into nothingness.
762 If DECL was from an inline function, then its rtl
763 is not identically the rtl that was used in this
764 particular compilation. */
765 if (GET_CODE (value) == REG)
767 regno = REGNO (value);
768 if (regno >= FIRST_PSEUDO_REGISTER)
769 return;
771 else if (GET_CODE (value) == SUBREG)
773 while (GET_CODE (value) == SUBREG)
774 value = SUBREG_REG (value);
775 if (GET_CODE (value) == REG)
777 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
778 return;
780 regno = REGNO (alter_subreg (&value));
781 SET_DECL_RTL (decl, value);
783 /* Don't output anything if an auto variable
784 gets RTL that is static.
785 GAS version 2.2 can't handle such output. */
786 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
787 && ! TREE_STATIC (decl))
788 return;
790 /* Emit any structure, union, or enum type that has not been output.
791 This occurs for tag-less structs (et al) used to declare variables
792 within functions. */
793 if (TREE_CODE (type) == ENUMERAL_TYPE
794 || TREE_CODE (type) == RECORD_TYPE
795 || TREE_CODE (type) == UNION_TYPE
796 || TREE_CODE (type) == QUAL_UNION_TYPE)
798 if (COMPLETE_TYPE_P (type) /* not a forward reference */
799 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
800 sdbout_one_type (type);
803 /* Defer SDB information for top-level initialized variables! */
804 if (! local
805 && GET_CODE (value) == MEM
806 && DECL_INITIAL (decl))
807 return;
809 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
810 For now, avoid crashing. */
811 if (DECL_NAME (decl) == NULL_TREE)
812 return;
814 /* Record the name for, starting a symtab entry. */
815 if (local)
816 name = IDENTIFIER_POINTER (DECL_NAME (decl));
817 else
818 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
820 if (GET_CODE (value) == MEM
821 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
823 PUT_SDB_DEF (name);
824 if (TREE_PUBLIC (decl))
826 PUT_SDB_VAL (XEXP (value, 0));
827 PUT_SDB_SCL (C_EXT);
829 else
831 PUT_SDB_VAL (XEXP (value, 0));
832 PUT_SDB_SCL (C_STAT);
835 else if (regno >= 0)
837 PUT_SDB_DEF (name);
838 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
839 PUT_SDB_SCL (C_REG);
841 else if (GET_CODE (value) == MEM
842 && (GET_CODE (XEXP (value, 0)) == MEM
843 || (GET_CODE (XEXP (value, 0)) == REG
844 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
845 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
846 /* If the value is indirect by memory or by a register
847 that isn't the frame pointer
848 then it means the object is variable-sized and address through
849 that register or stack slot. COFF has no way to represent this
850 so all we can do is output the variable as a pointer. */
852 PUT_SDB_DEF (name);
853 if (GET_CODE (XEXP (value, 0)) == REG)
855 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
856 PUT_SDB_SCL (C_REG);
858 else
860 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
861 (CONST_INT...)))).
862 We want the value of that CONST_INT. */
863 /* Encore compiler hates a newline in a macro arg, it seems. */
864 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
865 (XEXP (XEXP (value, 0), 0)));
866 PUT_SDB_SCL (C_AUTO);
869 /* Effectively do build_pointer_type, but don't cache this type,
870 since it might be temporary whereas the type it points to
871 might have been saved for inlining. */
872 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
873 type = make_node (POINTER_TYPE);
874 TREE_TYPE (type) = TREE_TYPE (decl);
876 else if (GET_CODE (value) == MEM
877 && ((GET_CODE (XEXP (value, 0)) == PLUS
878 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
879 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
880 /* This is for variables which are at offset zero from
881 the frame pointer. This happens on the Alpha.
882 Non-frame pointer registers are excluded above. */
883 || (GET_CODE (XEXP (value, 0)) == REG)))
885 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
886 or (MEM (REG...)). We want the value of that CONST_INT
887 or zero. */
888 PUT_SDB_DEF (name);
889 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
890 PUT_SDB_SCL (C_AUTO);
892 else
894 /* It is something we don't know how to represent for SDB. */
895 return;
897 break;
899 default:
900 break;
902 PUT_SDB_TYPE (plain_type (type));
903 PUT_SDB_ENDEF;
906 /* Output SDB information for a top-level initialized variable
907 that has been delayed. */
909 static void
910 sdbout_toplevel_data (tree decl)
912 tree type = TREE_TYPE (decl);
914 if (DECL_IGNORED_P (decl))
915 return;
917 if (! (TREE_CODE (decl) == VAR_DECL
918 && GET_CODE (DECL_RTL (decl)) == MEM
919 && DECL_INITIAL (decl)))
920 abort ();
922 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
923 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
924 if (TREE_PUBLIC (decl))
926 PUT_SDB_SCL (C_EXT);
928 else
930 PUT_SDB_SCL (C_STAT);
932 PUT_SDB_TYPE (plain_type (type));
933 PUT_SDB_ENDEF;
936 #ifdef SDB_ALLOW_FORWARD_REFERENCES
938 /* Machinery to record and output anonymous types. */
940 static void
941 sdbout_queue_anonymous_type (tree type)
943 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
946 static void
947 sdbout_dequeue_anonymous_types (void)
949 tree types, link;
951 while (anonymous_types)
953 types = nreverse (anonymous_types);
954 anonymous_types = NULL_TREE;
956 for (link = types; link; link = TREE_CHAIN (link))
958 tree type = TREE_VALUE (link);
960 if (type && ! TREE_ASM_WRITTEN (type))
961 sdbout_one_type (type);
966 #endif
968 /* Given a chain of ..._TYPE nodes, all of which have names,
969 output definitions of those names, as typedefs. */
971 void
972 sdbout_types (tree types)
974 tree link;
976 for (link = types; link; link = TREE_CHAIN (link))
977 sdbout_one_type (link);
979 #ifdef SDB_ALLOW_FORWARD_REFERENCES
980 sdbout_dequeue_anonymous_types ();
981 #endif
984 static void
985 sdbout_type (tree type)
987 if (type == error_mark_node)
988 type = integer_type_node;
989 PUT_SDB_TYPE (plain_type (type));
992 /* Output types of the fields of type TYPE, if they are structs.
994 Formerly did not chase through pointer types, since that could be circular.
995 They must come before TYPE, since forward refs are not allowed.
996 Now james@bigtex.cactus.org says to try them. */
998 static void
999 sdbout_field_types (tree type)
1001 tree tail;
1003 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1004 /* This condition should match the one for emitting the actual
1005 members below. */
1006 if (TREE_CODE (tail) == FIELD_DECL
1007 && DECL_NAME (tail)
1008 && DECL_SIZE (tail)
1009 && host_integerp (DECL_SIZE (tail), 1)
1010 && host_integerp (bit_position (tail), 0))
1012 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1013 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1014 else
1015 sdbout_one_type (TREE_TYPE (tail));
1019 /* Use this to put out the top level defined record and union types
1020 for later reference. If this is a struct with a name, then put that
1021 name out. Other unnamed structs will have .xxfake labels generated so
1022 that they may be referred to later.
1023 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1024 It may NOT be called recursively. */
1026 static void
1027 sdbout_one_type (tree type)
1029 if (current_function_decl != NULL_TREE
1030 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1031 ; /* Don't change section amid function. */
1032 else
1033 text_section ();
1035 switch (TREE_CODE (type))
1037 case RECORD_TYPE:
1038 case UNION_TYPE:
1039 case QUAL_UNION_TYPE:
1040 case ENUMERAL_TYPE:
1041 type = TYPE_MAIN_VARIANT (type);
1042 /* Don't output a type twice. */
1043 if (TREE_ASM_WRITTEN (type))
1044 /* James said test TREE_ASM_BEING_WRITTEN here. */
1045 return;
1047 /* Output nothing if type is not yet defined. */
1048 if (!COMPLETE_TYPE_P (type))
1049 return;
1051 TREE_ASM_WRITTEN (type) = 1;
1053 /* This is reputed to cause trouble with the following case,
1054 but perhaps checking TYPE_SIZE above will fix it. */
1056 /* Here is a test case:
1058 struct foo {
1059 struct badstr *bbb;
1060 } forwardref;
1062 typedef struct intermediate {
1063 int aaaa;
1064 } intermediate_ref;
1066 typedef struct badstr {
1067 int ccccc;
1068 } badtype; */
1070 /* This change, which ought to make better output,
1071 used to make the COFF assembler unhappy.
1072 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1073 /* Before really doing anything, output types we want to refer to. */
1074 /* Note that in version 1 the following two lines
1075 are not used if forward references are in use. */
1076 if (TREE_CODE (type) != ENUMERAL_TYPE)
1077 sdbout_field_types (type);
1079 /* Output a structure type. */
1081 int size = int_size_in_bytes (type);
1082 int member_scl = 0;
1083 tree tem;
1084 int i, n_baseclasses = 0;
1086 /* Record the type tag, but not in its permanent place just yet. */
1087 sdbout_record_type_name (type);
1089 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1091 switch (TREE_CODE (type))
1093 case UNION_TYPE:
1094 case QUAL_UNION_TYPE:
1095 PUT_SDB_SCL (C_UNTAG);
1096 PUT_SDB_TYPE (T_UNION);
1097 member_scl = C_MOU;
1098 break;
1100 case RECORD_TYPE:
1101 PUT_SDB_SCL (C_STRTAG);
1102 PUT_SDB_TYPE (T_STRUCT);
1103 member_scl = C_MOS;
1104 break;
1106 case ENUMERAL_TYPE:
1107 PUT_SDB_SCL (C_ENTAG);
1108 PUT_SDB_TYPE (T_ENUM);
1109 member_scl = C_MOE;
1110 break;
1112 default:
1113 break;
1116 PUT_SDB_SIZE (size);
1117 PUT_SDB_ENDEF;
1119 /* Print out the base class information with fields
1120 named after the types they hold. */
1121 /* This is only relevant to aggregate types. TYPE_BINFO is used
1122 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1123 case. */
1124 if (TREE_CODE (type) != ENUMERAL_TYPE)
1126 if (TYPE_BINFO (type)
1127 && TYPE_BINFO_BASETYPES (type))
1128 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1129 for (i = 0; i < n_baseclasses; i++)
1131 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1133 tree child_type = BINFO_TYPE (child);
1134 tree child_type_name;
1135 if (TYPE_NAME (child_type) == 0)
1136 continue;
1137 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1138 child_type_name = TYPE_NAME (child_type);
1139 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1141 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1142 if (child_type_name && template_name_p (child_type_name))
1143 child_type_name
1144 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1146 else
1147 continue;
1149 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1150 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1151 PUT_SDB_SCL (member_scl);
1152 sdbout_type (BINFO_TYPE (child));
1153 PUT_SDB_ENDEF;
1157 /* output the individual fields */
1159 if (TREE_CODE (type) == ENUMERAL_TYPE)
1161 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1162 if (host_integerp (TREE_VALUE (tem), 0))
1164 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1165 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1166 PUT_SDB_SCL (C_MOE);
1167 PUT_SDB_TYPE (T_MOE);
1168 PUT_SDB_ENDEF;
1171 else /* record or union type */
1172 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1173 /* Output the name, type, position (in bits), size (in bits)
1174 of each field. */
1176 /* Omit here the nameless fields that are used to skip bits.
1177 Also omit fields with variable size or position.
1178 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1179 if (TREE_CODE (tem) == FIELD_DECL
1180 && DECL_NAME (tem)
1181 && DECL_SIZE (tem)
1182 && host_integerp (DECL_SIZE (tem), 1)
1183 && host_integerp (bit_position (tem), 0))
1185 const char *name;
1187 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1188 PUT_SDB_DEF (name);
1189 if (DECL_BIT_FIELD_TYPE (tem))
1191 PUT_SDB_INT_VAL (int_bit_position (tem));
1192 PUT_SDB_SCL (C_FIELD);
1193 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1194 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1196 else
1198 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1199 PUT_SDB_SCL (member_scl);
1200 sdbout_type (TREE_TYPE (tem));
1202 PUT_SDB_ENDEF;
1204 /* output end of a structure,union, or enumeral definition */
1206 PUT_SDB_PLAIN_DEF ("eos");
1207 PUT_SDB_INT_VAL (size);
1208 PUT_SDB_SCL (C_EOS);
1209 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1210 PUT_SDB_SIZE (size);
1211 PUT_SDB_ENDEF;
1212 break;
1214 default:
1215 break;
1220 /* The following two functions output definitions of function parameters.
1221 Each parameter gets a definition locating it in the parameter list.
1222 Each parameter that is a register variable gets a second definition
1223 locating it in the register.
1225 Printing or argument lists in gdb uses the definitions that
1226 locate in the parameter list. But reference to the variable in
1227 expressions uses preferentially the definition as a register. */
1229 /* Output definitions, referring to storage in the parmlist,
1230 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1232 static void
1233 sdbout_parms (tree parms)
1235 for (; parms; parms = TREE_CHAIN (parms))
1236 if (DECL_NAME (parms))
1238 int current_sym_value = 0;
1239 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1241 if (name == 0 || *name == 0)
1242 name = gen_fake_label ();
1244 /* Perform any necessary register eliminations on the parameter's rtl,
1245 so that the debugging output will be accurate. */
1246 DECL_INCOMING_RTL (parms)
1247 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1248 SET_DECL_RTL (parms,
1249 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1251 if (PARM_PASSED_IN_MEMORY (parms))
1253 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1254 tree type;
1256 /* ??? Here we assume that the parm address is indexed
1257 off the frame pointer or arg pointer.
1258 If that is not true, we produce meaningless results,
1259 but do not crash. */
1260 if (GET_CODE (addr) == PLUS
1261 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1262 current_sym_value = INTVAL (XEXP (addr, 1));
1263 else
1264 current_sym_value = 0;
1266 if (GET_CODE (DECL_RTL (parms)) == REG
1267 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1268 type = DECL_ARG_TYPE (parms);
1269 else
1271 int original_sym_value = current_sym_value;
1273 /* This is the case where the parm is passed as an int or
1274 double and it is converted to a char, short or float
1275 and stored back in the parmlist. In this case, describe
1276 the parm with the variable's declared type, and adjust
1277 the address if the least significant bytes (which we are
1278 using) are not the first ones. */
1279 if (BYTES_BIG_ENDIAN
1280 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1281 current_sym_value +=
1282 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1283 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1285 if (GET_CODE (DECL_RTL (parms)) == MEM
1286 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1287 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1288 == CONST_INT)
1289 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1290 == current_sym_value))
1291 type = TREE_TYPE (parms);
1292 else
1294 current_sym_value = original_sym_value;
1295 type = DECL_ARG_TYPE (parms);
1299 PUT_SDB_DEF (name);
1300 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1301 PUT_SDB_SCL (C_ARG);
1302 PUT_SDB_TYPE (plain_type (type));
1303 PUT_SDB_ENDEF;
1305 else if (GET_CODE (DECL_RTL (parms)) == REG)
1307 rtx best_rtl;
1308 /* Parm passed in registers and lives in registers or nowhere. */
1310 /* If parm lives in a register, use that register;
1311 pretend the parm was passed there. It would be more consistent
1312 to describe the register where the parm was passed,
1313 but in practice that register usually holds something else. */
1314 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1315 best_rtl = DECL_RTL (parms);
1316 /* If the parm lives nowhere,
1317 use the register where it was passed. */
1318 else
1319 best_rtl = DECL_INCOMING_RTL (parms);
1321 PUT_SDB_DEF (name);
1322 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1323 PUT_SDB_SCL (C_REGPARM);
1324 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1325 PUT_SDB_ENDEF;
1327 else if (GET_CODE (DECL_RTL (parms)) == MEM
1328 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1330 /* Parm was passed in registers but lives on the stack. */
1332 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1333 in which case we want the value of that CONST_INT,
1334 or (MEM (REG ...)) or (MEM (MEM ...)),
1335 in which case we use a value of zero. */
1336 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1337 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1338 current_sym_value = 0;
1339 else
1340 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1342 /* Again, this assumes the offset is based on the arg pointer. */
1343 PUT_SDB_DEF (name);
1344 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1345 XEXP (DECL_RTL (parms), 0)));
1346 PUT_SDB_SCL (C_ARG);
1347 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1348 PUT_SDB_ENDEF;
1353 /* Output definitions for the places where parms live during the function,
1354 when different from where they were passed, when the parms were passed
1355 in memory.
1357 It is not useful to do this for parms passed in registers
1358 that live during the function in different registers, because it is
1359 impossible to look in the passed register for the passed value,
1360 so we use the within-the-function register to begin with.
1362 PARMS is a chain of PARM_DECL nodes. */
1364 static void
1365 sdbout_reg_parms (tree parms)
1367 for (; parms; parms = TREE_CHAIN (parms))
1368 if (DECL_NAME (parms))
1370 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1372 /* Report parms that live in registers during the function
1373 but were passed in memory. */
1374 if (GET_CODE (DECL_RTL (parms)) == REG
1375 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1376 && PARM_PASSED_IN_MEMORY (parms))
1378 if (name == 0 || *name == 0)
1379 name = gen_fake_label ();
1380 PUT_SDB_DEF (name);
1381 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1382 PUT_SDB_SCL (C_REG);
1383 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1384 PUT_SDB_ENDEF;
1386 /* Report parms that live in memory but not where they were passed. */
1387 else if (GET_CODE (DECL_RTL (parms)) == MEM
1388 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1389 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1390 && PARM_PASSED_IN_MEMORY (parms)
1391 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1393 #if 0 /* ??? It is not clear yet what should replace this. */
1394 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1395 /* A parm declared char is really passed as an int,
1396 so it occupies the least significant bytes.
1397 On a big-endian machine those are not the low-numbered ones. */
1398 if (BYTES_BIG_ENDIAN
1399 && offset != -1
1400 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1401 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1402 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1403 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1404 #endif
1406 if (name == 0 || *name == 0)
1407 name = gen_fake_label ();
1408 PUT_SDB_DEF (name);
1409 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1410 (XEXP (DECL_RTL (parms), 0)));
1411 PUT_SDB_SCL (C_AUTO);
1412 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1413 PUT_SDB_ENDEF;
1419 /* Output debug information for a global DECL. Called from toplev.c
1420 after compilation proper has finished. */
1422 static void
1423 sdbout_global_decl (tree decl)
1425 if (TREE_CODE (decl) == VAR_DECL
1426 && !DECL_EXTERNAL (decl)
1427 && DECL_RTL_SET_P (decl))
1429 /* The COFF linker can move initialized global vars to the end.
1430 And that can screw up the symbol ordering. Defer those for
1431 sdbout_finish (). */
1432 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1433 sdbout_symbol (decl, 0);
1435 /* Output COFF information for non-global file-scope initialized
1436 variables. */
1437 if (DECL_INITIAL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
1438 sdbout_toplevel_data (decl);
1442 /* Output initialized global vars at the end, in the order of
1443 definition. See comment in sdbout_global_decl. */
1445 static void
1446 sdbout_finish (const char *main_filename ATTRIBUTE_UNUSED)
1448 tree decl = (*lang_hooks.decls.getdecls) ();
1449 unsigned int len = list_length (decl);
1450 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
1451 unsigned int i;
1453 /* Process the decls in reverse order--earliest first. Put them
1454 into VEC from back to front, then take out from front. */
1456 for (i = 0; i < len; i++, decl = TREE_CHAIN (decl))
1457 vec[len - i - 1] = decl;
1459 for (i = 0; i < len; i++)
1461 decl = vec[i];
1462 if (TREE_CODE (decl) == VAR_DECL
1463 && ! DECL_EXTERNAL (decl)
1464 && DECL_INITIAL (decl)
1465 && TREE_PUBLIC (decl)
1466 && DECL_RTL_SET_P (decl))
1467 sdbout_symbol (decl, 0);
1470 free (vec);
1473 /* Describe the beginning of an internal block within a function.
1474 Also output descriptions of variables defined in this block.
1476 N is the number of the block, by order of beginning, counting from 1,
1477 and not counting the outermost (function top-level) block.
1478 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1479 if the count starts at 0 for the outermost one. */
1481 static void
1482 sdbout_begin_block (unsigned int line, unsigned int n)
1484 tree decl = current_function_decl;
1485 MAKE_LINE_SAFE (line);
1487 /* The SCO compiler does not emit a separate block for the function level
1488 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1489 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1490 #ifndef MIPS_DEBUGGING_INFO
1491 if (n != 1)
1492 #endif
1493 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1495 if (n == 1)
1497 /* Include the outermost BLOCK's variables in block 1. */
1498 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1499 sdbout_block (DECL_INITIAL (decl));
1501 /* If -g1, suppress all the internal symbols of functions
1502 except for arguments. */
1503 if (debug_info_level != DINFO_LEVEL_TERSE)
1505 do_block = n;
1506 sdbout_block (DECL_INITIAL (decl));
1509 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1510 sdbout_dequeue_anonymous_types ();
1511 #endif
1514 /* Describe the end line-number of an internal block within a function. */
1516 static void
1517 sdbout_end_block (unsigned int line, unsigned int n ATTRIBUTE_UNUSED)
1519 MAKE_LINE_SAFE (line);
1521 /* The SCO compiler does not emit a separate block for the function level
1522 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1523 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1524 #ifndef MIPS_DEBUGGING_INFO
1525 if (n != 1)
1526 #endif
1527 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1530 static void
1531 sdbout_source_line (line, filename)
1532 unsigned int line;
1533 const char *filename ATTRIBUTE_UNUSED;
1535 /* COFF relative line numbers must be positive. */
1536 if ((int) line > sdb_begin_function_line)
1538 #ifdef ASM_OUTPUT_SOURCE_LINE
1539 ASM_OUTPUT_SOURCE_LINE (asm_out_file, line);
1540 #else
1541 fprintf (asm_out_file, "\t.ln\t%d\n",
1542 ((sdb_begin_function_line > -1)
1543 ? line - sdb_begin_function_line : 1));
1544 #endif
1548 /* Output sdb info for the current function name.
1549 Called from assemble_start_function. */
1551 static void
1552 sdbout_begin_function (tree decl ATTRIBUTE_UNUSED)
1554 sdbout_symbol (current_function_decl, 0);
1557 /* Called at beginning of function body (before or after prologue,
1558 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1559 line number, so we can output relative line numbers for the other
1560 lines. Describe beginning of outermost block. Also describe the
1561 parameter list. */
1563 #ifndef MIPS_DEBUGGING_INFO
1564 static void
1565 sdbout_begin_prologue (unsigned int line, const char *file ATTRIBUTE_UNUSED)
1567 sdbout_end_prologue (line, file);
1569 #endif
1571 static void
1572 sdbout_end_prologue (line, file)
1573 unsigned int line;
1574 const char *file ATTRIBUTE_UNUSED;
1576 sdb_begin_function_line = line - 1;
1577 PUT_SDB_FUNCTION_START (line);
1578 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1579 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1582 /* Called at end of function (before epilogue).
1583 Describe end of outermost block. */
1585 static void
1586 sdbout_end_function (unsigned int line)
1588 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1589 sdbout_dequeue_anonymous_types ();
1590 #endif
1592 MAKE_LINE_SAFE (line);
1593 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1595 /* Indicate we are between functions, for line-number output. */
1596 sdb_begin_function_line = -1;
1599 /* Output sdb info for the absolute end of a function.
1600 Called after the epilogue is output. */
1602 static void
1603 sdbout_end_epilogue (unsigned int line ATTRIBUTE_UNUSED,
1604 const char *file ATTRIBUTE_UNUSED)
1606 const char *const name ATTRIBUTE_UNUSED
1607 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1609 #ifdef PUT_SDB_EPILOGUE_END
1610 PUT_SDB_EPILOGUE_END (name);
1611 #else
1612 fprintf (asm_out_file, "\t.def\t");
1613 assemble_name (asm_out_file, name);
1614 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1615 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1616 #endif
1619 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1620 is present. */
1622 static void
1623 sdbout_label (rtx insn)
1625 PUT_SDB_DEF (LABEL_NAME (insn));
1626 PUT_SDB_VAL (insn);
1627 PUT_SDB_SCL (C_LABEL);
1628 PUT_SDB_TYPE (T_NULL);
1629 PUT_SDB_ENDEF;
1632 /* Change to reading from a new source file. */
1634 static void
1635 sdbout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
1636 const char *filename ATTRIBUTE_UNUSED)
1638 #ifdef MIPS_DEBUGGING_INFO
1639 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1641 n->next = current_file;
1642 n->name = filename;
1643 current_file = n;
1644 PUT_SDB_SRC_FILE (filename);
1645 #endif
1648 /* Revert to reading a previous source file. */
1650 static void
1651 sdbout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
1653 #ifdef MIPS_DEBUGGING_INFO
1654 struct sdb_file *next;
1656 next = current_file->next;
1657 free (current_file);
1658 current_file = next;
1659 PUT_SDB_SRC_FILE (current_file->name);
1660 #endif
1663 /* Set up for SDB output at the start of compilation. */
1665 static void
1666 sdbout_init (const char *input_file_name ATTRIBUTE_UNUSED)
1668 #ifdef MIPS_DEBUGGING_INFO
1669 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1670 current_file->next = NULL;
1671 current_file->name = input_file_name;
1672 #endif
1675 #else /* SDB_DEBUGGING_INFO */
1677 /* This should never be used, but its address is needed for comparisons. */
1678 const struct gcc_debug_hooks sdb_debug_hooks;
1680 #endif /* SDB_DEBUGGING_INFO */
1682 #include "gt-sdbout.h"