Pass pointer to RTX when calling alter_subreg().
[official-gcc.git] / gcc / sdbout.c
blobf8bd74470364efa78f8ff14018e713b824ecea54
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 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"
46 #ifdef SDB_DEBUGGING_INFO
48 #include "system.h"
49 #include "tree.h"
50 #include "rtl.h"
51 #include "regs.h"
52 #include "flags.h"
53 #include "insn-config.h"
54 #include "reload.h"
55 #include "output.h"
56 #include "toplev.h"
57 #include "ggc.h"
58 #include "tm_p.h"
59 #include "gsyms.h"
60 #include "debug.h"
62 /* 1 if PARM is passed to this function in memory. */
64 #define PARM_PASSED_IN_MEMORY(PARM) \
65 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
67 /* A C expression for the integer offset value of an automatic variable
68 (C_AUTO) having address X (an RTX). */
69 #ifndef DEBUGGER_AUTO_OFFSET
70 #define DEBUGGER_AUTO_OFFSET(X) \
71 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
72 #endif
74 /* A C expression for the integer offset value of an argument (C_ARG)
75 having address X (an RTX). The nominal offset is OFFSET. */
76 #ifndef DEBUGGER_ARG_OFFSET
77 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
78 #endif
80 /* Line number of beginning of current function, minus one.
81 Negative means not in a function or not using sdb. */
83 int sdb_begin_function_line = -1;
85 /* Counter to generate unique "names" for nameless struct members. */
87 static int unnamed_struct_number = 0;
89 extern FILE *asm_out_file;
91 extern tree current_function_decl;
93 #include "sdbout.h"
95 static void sdbout_init PARAMS ((const char *));
96 static void sdbout_finish PARAMS ((const char *));
97 static void sdbout_start_source_file PARAMS ((unsigned int, const char *));
98 static void sdbout_end_source_file PARAMS ((unsigned int));
99 static void sdbout_begin_block PARAMS ((unsigned int, unsigned int));
100 static void sdbout_end_block PARAMS ((unsigned int, unsigned int));
101 static void sdbout_source_line PARAMS ((unsigned int, const char *));
102 static void sdbout_end_epilogue PARAMS ((void));
103 static void sdbout_global_decl PARAMS ((tree));
104 #ifndef MIPS_DEBUGGING_INFO
105 static void sdbout_begin_prologue PARAMS ((unsigned int, const char *));
106 #endif
107 static void sdbout_end_prologue PARAMS ((unsigned int));
108 static void sdbout_begin_function PARAMS ((tree));
109 static void sdbout_end_function PARAMS ((unsigned int));
110 static void sdbout_toplevel_data PARAMS ((tree));
111 static void sdbout_label PARAMS ((rtx));
112 static char *gen_fake_label PARAMS ((void));
113 static int plain_type PARAMS ((tree));
114 static int template_name_p PARAMS ((tree));
115 static void sdbout_record_type_name PARAMS ((tree));
116 static int plain_type_1 PARAMS ((tree, int));
117 static void sdbout_block PARAMS ((tree));
118 static void sdbout_syms PARAMS ((tree));
119 #ifdef SDB_ALLOW_FORWARD_REFERENCES
120 static void sdbout_queue_anonymous_type PARAMS ((tree));
121 static void sdbout_dequeue_anonymous_types PARAMS ((void));
122 #endif
123 static void sdbout_type PARAMS ((tree));
124 static void sdbout_field_types PARAMS ((tree));
125 static void sdbout_one_type PARAMS ((tree));
126 static void sdbout_parms PARAMS ((tree));
127 static void sdbout_reg_parms PARAMS ((tree));
128 static void sdbout_global_decl PARAMS ((tree));
130 /* Random macros describing parts of SDB data. */
132 /* Put something here if lines get too long */
133 #define CONTIN
135 /* Default value of delimiter is ";". */
136 #ifndef SDB_DELIM
137 #define SDB_DELIM ";"
138 #endif
140 /* Maximum number of dimensions the assembler will allow. */
141 #ifndef SDB_MAX_DIM
142 #define SDB_MAX_DIM 4
143 #endif
145 #ifndef PUT_SDB_SCL
146 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
147 #endif
149 #ifndef PUT_SDB_INT_VAL
150 #define PUT_SDB_INT_VAL(a) \
151 do { \
152 fputs ("\t.val\t", asm_out_file); \
153 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
154 fprintf (asm_out_file, "%s", SDB_DELIM); \
155 } while (0)
157 #endif
159 #ifndef PUT_SDB_VAL
160 #define PUT_SDB_VAL(a) \
161 ( fputs ("\t.val\t", asm_out_file), \
162 output_addr_const (asm_out_file, (a)), \
163 fprintf (asm_out_file, SDB_DELIM))
164 #endif
166 #ifndef PUT_SDB_DEF
167 #define PUT_SDB_DEF(a) \
168 do { fprintf (asm_out_file, "\t.def\t"); \
169 assemble_name (asm_out_file, a); \
170 fprintf (asm_out_file, SDB_DELIM); } while (0)
171 #endif
173 #ifndef PUT_SDB_PLAIN_DEF
174 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
175 #endif
177 #ifndef PUT_SDB_ENDEF
178 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
179 #endif
181 #ifndef PUT_SDB_TYPE
182 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
183 #endif
185 #ifndef PUT_SDB_SIZE
186 #define PUT_SDB_SIZE(a) \
187 do { \
188 fputs ("\t.size\t", asm_out_file); \
189 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
190 fprintf (asm_out_file, "%s", SDB_DELIM); \
191 } while(0)
192 #endif
194 #ifndef PUT_SDB_START_DIM
195 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
196 #endif
198 #ifndef PUT_SDB_NEXT_DIM
199 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
200 #endif
202 #ifndef PUT_SDB_LAST_DIM
203 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
204 #endif
206 #ifndef PUT_SDB_TAG
207 #define PUT_SDB_TAG(a) \
208 do { fprintf (asm_out_file, "\t.tag\t"); \
209 assemble_name (asm_out_file, a); \
210 fprintf (asm_out_file, SDB_DELIM); } while (0)
211 #endif
213 #ifndef PUT_SDB_BLOCK_START
214 #define PUT_SDB_BLOCK_START(LINE) \
215 fprintf (asm_out_file, \
216 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
217 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
218 #endif
220 #ifndef PUT_SDB_BLOCK_END
221 #define PUT_SDB_BLOCK_END(LINE) \
222 fprintf (asm_out_file, \
223 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
224 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
225 #endif
227 #ifndef PUT_SDB_FUNCTION_START
228 #define PUT_SDB_FUNCTION_START(LINE) \
229 fprintf (asm_out_file, \
230 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
231 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
232 #endif
234 #ifndef PUT_SDB_FUNCTION_END
235 #define PUT_SDB_FUNCTION_END(LINE) \
236 fprintf (asm_out_file, \
237 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
238 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
239 #endif
241 #ifndef SDB_GENERATE_FAKE
242 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
243 sprintf ((BUFFER), ".%dfake", (NUMBER));
244 #endif
246 /* Return the sdb tag identifier string for TYPE
247 if TYPE has already been defined; otherwise return a null pointer. */
249 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
251 /* Set the sdb tag identifier string for TYPE to NAME. */
253 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
254 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
256 /* Return the name (a string) of the struct, union or enum tag
257 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
259 #define TAG_NAME(link) \
260 (((link) && TREE_PURPOSE ((link)) \
261 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
262 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
264 /* Ensure we don't output a negative line number. */
265 #define MAKE_LINE_SAFE(line) \
266 if ((int) line <= sdb_begin_function_line) \
267 line = sdb_begin_function_line + 1
269 /* Perform linker optimization of merging header file definitions together
270 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
271 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
272 the optimization just won't be done. The native assembler already has the
273 necessary support. */
275 #ifdef MIPS_DEBUGGING_INFO
277 #ifndef PUT_SDB_SRC_FILE
278 #define PUT_SDB_SRC_FILE(FILENAME) \
279 output_file_directive (asm_out_file, (FILENAME))
280 #endif
282 /* ECOFF linkers have an optimization that does the same kind of thing as
283 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
284 executable. To achieve this, GCC must output a .file for each file
285 name change. */
287 /* This is a stack of input files. */
289 struct sdb_file
291 struct sdb_file *next;
292 const char *name;
295 /* This is the top of the stack. */
297 static struct sdb_file *current_file;
299 #endif /* MIPS_DEBUGGING_INFO */
301 /* The debug hooks structure. */
302 struct gcc_debug_hooks sdb_debug_hooks =
304 sdbout_init, /* init */
305 sdbout_finish, /* finish */
306 debug_nothing_int_charstar, /* define */
307 debug_nothing_int_charstar, /* undef */
308 sdbout_start_source_file, /* start_source_file */
309 sdbout_end_source_file, /* end_source_file */
310 sdbout_begin_block, /* begin_block */
311 sdbout_end_block, /* end_block */
312 debug_true_tree, /* ignore_block */
313 sdbout_source_line, /* source_line */
314 #ifdef MIPS_DEBUGGING_INFO
315 /* Defer on MIPS systems so that parameter descriptions follow
316 function entry. */
317 debug_nothing_int_charstar, /* begin_prologue */
318 sdbout_end_prologue, /* end_prologue */
319 #else
320 sdbout_begin_prologue, /* begin_prologue */
321 debug_nothing_int, /* end_prologue */
322 #endif
323 sdbout_end_epilogue, /* end_epilogue */
324 sdbout_begin_function, /* begin_function */
325 sdbout_end_function, /* end_function */
326 debug_nothing_tree, /* function_decl */
327 sdbout_global_decl, /* global_decl */
328 debug_nothing_tree, /* deferred_inline_function */
329 debug_nothing_tree, /* outlining_inline_function */
330 sdbout_label
333 #if 0
335 /* return the tag identifier for type
338 char *
339 tag_of_ru_type (type,link)
340 tree type,link;
342 if (TYPE_SYMTAB_ADDRESS (type))
343 return TYPE_SYMTAB_ADDRESS (type);
344 if (link && TREE_PURPOSE (link)
345 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
346 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
347 else
348 return (char *) TYPE_SYMTAB_ADDRESS (type);
350 #endif
352 /* Return a unique string to name an anonymous type. */
354 static char *
355 gen_fake_label ()
357 char label[10];
358 char *labelstr;
359 SDB_GENERATE_FAKE (label, unnamed_struct_number);
360 unnamed_struct_number++;
361 labelstr = (char *) permalloc (strlen (label) + 1);
362 strcpy (labelstr, label);
363 return labelstr;
366 /* Return the number which describes TYPE for SDB.
367 For pointers, etc., this function is recursive.
368 Each record, union or enumeral type must already have had a
369 tag number output. */
371 /* The number is given by d6d5d4d3d2d1bbbb
372 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
373 Thus, char *foo () has bbbb=T_CHAR
374 d1=D_FCN
375 d2=D_PTR
376 N_BTMASK= 017 1111 basic type field.
377 N_TSHIFT= 2 derived type shift
378 N_BTSHFT= 4 Basic type shift */
380 /* Produce the number that describes a pointer, function or array type.
381 PREV is the number describing the target, value or element type.
382 DT_type describes how to transform that type. */
383 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
384 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
385 | ((int)DT_type << (int)N_BTSHFT) \
386 | ((PREV) & (int)N_BTMASK))
388 /* Number of elements used in sdb_dims. */
389 static int sdb_n_dims = 0;
391 /* Table of array dimensions of current type. */
392 static int sdb_dims[SDB_MAX_DIM];
394 /* Size of outermost array currently being processed. */
395 static int sdb_type_size = -1;
397 static int
398 plain_type (type)
399 tree type;
401 int val = plain_type_1 (type, 0);
403 /* If we have already saved up some array dimensions, print them now. */
404 if (sdb_n_dims > 0)
406 int i;
407 PUT_SDB_START_DIM;
408 for (i = sdb_n_dims - 1; i > 0; i--)
409 PUT_SDB_NEXT_DIM (sdb_dims[i]);
410 PUT_SDB_LAST_DIM (sdb_dims[0]);
411 sdb_n_dims = 0;
413 sdb_type_size = int_size_in_bytes (type);
414 /* Don't kill sdb if type is not laid out or has variable size. */
415 if (sdb_type_size < 0)
416 sdb_type_size = 0;
418 /* If we have computed the size of an array containing this type,
419 print it now. */
420 if (sdb_type_size >= 0)
422 PUT_SDB_SIZE (sdb_type_size);
423 sdb_type_size = -1;
425 return val;
428 static int
429 template_name_p (name)
430 tree name;
432 const char *ptr = IDENTIFIER_POINTER (name);
433 while (*ptr && *ptr != '<')
434 ptr++;
436 return *ptr != '\0';
439 static void
440 sdbout_record_type_name (type)
441 tree type;
443 char *name = 0;
444 int no_name;
446 if (KNOWN_TYPE_TAG (type))
447 return;
449 if (TYPE_NAME (type) != 0)
451 tree t = 0;
452 /* Find the IDENTIFIER_NODE for the type name. */
453 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
454 t = TYPE_NAME (type);
455 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
457 t = DECL_NAME (TYPE_NAME (type));
458 /* The DECL_NAME for templates includes "<>", which breaks
459 most assemblers. Use its assembler name instead, which
460 has been mangled into being safe. */
461 if (t && template_name_p (t))
462 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
465 /* Now get the name as a string, or invent one. */
466 if (t != NULL_TREE)
467 name = IDENTIFIER_POINTER (t);
470 no_name = (name == 0 || *name == 0);
471 if (no_name)
472 name = gen_fake_label ();
474 SET_KNOWN_TYPE_TAG (type, name);
475 #ifdef SDB_ALLOW_FORWARD_REFERENCES
476 if (no_name)
477 sdbout_queue_anonymous_type (type);
478 #endif
481 /* Return the .type value for type TYPE.
483 LEVEL indicates how many levels deep we have recursed into the type.
484 The SDB debug format can only represent 6 derived levels of types.
485 After that, we must output inaccurate debug info. We deliberately
486 stop before the 7th level, so that ADA recursive types will not give an
487 infinite loop. */
489 static int
490 plain_type_1 (type, level)
491 tree type;
492 int level;
494 if (type == 0)
495 type = void_type_node;
496 else if (type == error_mark_node)
497 type = integer_type_node;
498 else
499 type = TYPE_MAIN_VARIANT (type);
501 switch (TREE_CODE (type))
503 case VOID_TYPE:
504 return T_VOID;
505 case BOOLEAN_TYPE:
506 case INTEGER_TYPE:
508 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
510 /* Carefully distinguish all the standard types of C,
511 without messing up if the language is not C.
512 Note that we check only for the names that contain spaces;
513 other names might occur by coincidence in other languages. */
514 if (TYPE_NAME (type) != 0
515 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
516 && DECL_NAME (TYPE_NAME (type)) != 0
517 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
519 const char *const name
520 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
522 if (!strcmp (name, "char"))
523 return T_CHAR;
524 if (!strcmp (name, "unsigned char"))
525 return T_UCHAR;
526 if (!strcmp (name, "signed char"))
527 return T_CHAR;
528 if (!strcmp (name, "int"))
529 return T_INT;
530 if (!strcmp (name, "unsigned int"))
531 return T_UINT;
532 if (!strcmp (name, "short int"))
533 return T_SHORT;
534 if (!strcmp (name, "short unsigned int"))
535 return T_USHORT;
536 if (!strcmp (name, "long int"))
537 return T_LONG;
538 if (!strcmp (name, "long unsigned int"))
539 return T_ULONG;
542 if (size == INT_TYPE_SIZE)
543 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
544 if (size == CHAR_TYPE_SIZE)
545 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
546 if (size == SHORT_TYPE_SIZE)
547 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
548 if (size == LONG_TYPE_SIZE)
549 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
550 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
551 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
552 return 0;
555 case REAL_TYPE:
557 int precision = TYPE_PRECISION (type);
558 if (precision == FLOAT_TYPE_SIZE)
559 return T_FLOAT;
560 if (precision == DOUBLE_TYPE_SIZE)
561 return T_DOUBLE;
562 #ifdef EXTENDED_SDB_BASIC_TYPES
563 if (precision == LONG_DOUBLE_TYPE_SIZE)
564 return T_LNGDBL;
565 #else
566 if (precision == LONG_DOUBLE_TYPE_SIZE)
567 return T_DOUBLE; /* better than nothing */
568 #endif
569 return 0;
572 case ARRAY_TYPE:
574 int m;
575 if (level >= 6)
576 return T_VOID;
577 else
578 m = plain_type_1 (TREE_TYPE (type), level+1);
579 if (sdb_n_dims < SDB_MAX_DIM)
580 sdb_dims[sdb_n_dims++]
581 = (TYPE_DOMAIN (type)
582 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
583 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
584 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
585 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
586 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
587 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
588 : 0);
590 return PUSH_DERIVED_LEVEL (DT_ARY, m);
593 case RECORD_TYPE:
594 case UNION_TYPE:
595 case QUAL_UNION_TYPE:
596 case ENUMERAL_TYPE:
598 char *tag;
599 #ifdef SDB_ALLOW_FORWARD_REFERENCES
600 sdbout_record_type_name (type);
601 #endif
602 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
603 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
604 #ifdef SDB_ALLOW_FORWARD_REFERENCES
605 || TYPE_MODE (type) != VOIDmode
606 #endif
608 #endif
610 /* Output the referenced structure tag name
611 only if the .def has already been finished.
612 At least on 386, the Unix assembler
613 cannot handle forward references to tags. */
614 /* But the 88100, it requires them, sigh... */
615 /* And the MIPS requires unknown refs as well... */
616 tag = KNOWN_TYPE_TAG (type);
617 PUT_SDB_TAG (tag);
618 /* These 3 lines used to follow the close brace.
619 However, a size of 0 without a tag implies a tag of 0,
620 so if we don't know a tag, we can't mention the size. */
621 sdb_type_size = int_size_in_bytes (type);
622 if (sdb_type_size < 0)
623 sdb_type_size = 0;
625 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
626 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
627 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
628 : T_ENUM);
630 case POINTER_TYPE:
631 case REFERENCE_TYPE:
633 int m;
634 if (level >= 6)
635 return T_VOID;
636 else
637 m = plain_type_1 (TREE_TYPE (type), level+1);
638 return PUSH_DERIVED_LEVEL (DT_PTR, m);
640 case FUNCTION_TYPE:
641 case METHOD_TYPE:
643 int m;
644 if (level >= 6)
645 return T_VOID;
646 else
647 m = plain_type_1 (TREE_TYPE (type), level+1);
648 return PUSH_DERIVED_LEVEL (DT_FCN, m);
650 default:
651 return 0;
655 /* Output the symbols defined in block number DO_BLOCK.
657 This function works by walking the tree structure of blocks,
658 counting blocks until it finds the desired block. */
660 static int do_block = 0;
662 static void
663 sdbout_block (block)
664 tree block;
666 while (block)
668 /* Ignore blocks never expanded or otherwise marked as real. */
669 if (TREE_USED (block))
671 /* When we reach the specified block, output its symbols. */
672 if (BLOCK_NUMBER (block) == do_block)
673 sdbout_syms (BLOCK_VARS (block));
675 /* If we are past the specified block, stop the scan. */
676 if (BLOCK_NUMBER (block) > do_block)
677 return;
679 /* Scan the blocks within this block. */
680 sdbout_block (BLOCK_SUBBLOCKS (block));
683 block = BLOCK_CHAIN (block);
687 /* Call sdbout_symbol on each decl in the chain SYMS. */
689 static void
690 sdbout_syms (syms)
691 tree syms;
693 while (syms)
695 if (TREE_CODE (syms) != LABEL_DECL)
696 sdbout_symbol (syms, 1);
697 syms = TREE_CHAIN (syms);
701 /* Output SDB information for a symbol described by DECL.
702 LOCAL is nonzero if the symbol is not file-scope. */
704 void
705 sdbout_symbol (decl, local)
706 tree decl;
707 int local;
709 tree type = TREE_TYPE (decl);
710 tree context = NULL_TREE;
711 rtx value;
712 int regno = -1;
713 const char *name;
715 sdbout_one_type (type);
717 #if 0 /* This loses when functions are marked to be ignored,
718 which happens in the C++ front end. */
719 if (DECL_IGNORED_P (decl))
720 return;
721 #endif
723 switch (TREE_CODE (decl))
725 case CONST_DECL:
726 /* Enum values are defined by defining the enum type. */
727 return;
729 case FUNCTION_DECL:
730 /* Don't mention a nested function under its parent. */
731 context = decl_function_context (decl);
732 if (context == current_function_decl)
733 return;
734 /* Check DECL_INITIAL to distinguish declarations from definitions.
735 Don't output debug info here for declarations; they will have
736 a DECL_INITIAL value of 0. */
737 if (! DECL_INITIAL (decl))
738 return;
739 if (GET_CODE (DECL_RTL (decl)) != MEM
740 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
741 return;
742 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
743 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
744 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
745 break;
747 case TYPE_DECL:
748 /* Done with tagged types. */
749 if (DECL_NAME (decl) == 0)
750 return;
751 if (DECL_IGNORED_P (decl))
752 return;
754 /* Output typedef name. */
755 if (template_name_p (DECL_NAME (decl)))
756 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
757 else
758 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
759 PUT_SDB_SCL (C_TPDEF);
760 break;
762 case PARM_DECL:
763 /* Parm decls go in their own separate chains
764 and are output by sdbout_reg_parms and sdbout_parms. */
765 abort ();
767 case VAR_DECL:
768 /* Don't mention a variable that is external.
769 Let the file that defines it describe it. */
770 if (DECL_EXTERNAL (decl))
771 return;
773 /* Ignore __FUNCTION__, etc. */
774 if (DECL_IGNORED_P (decl))
775 return;
777 /* If there was an error in the declaration, don't dump core
778 if there is no RTL associated with the variable doesn't
779 exist. */
780 if (!DECL_RTL_SET_P (decl))
781 return;
783 SET_DECL_RTL (decl,
784 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
785 #ifdef LEAF_REG_REMAP
786 if (current_function_uses_only_leaf_regs)
787 leaf_renumber_regs_insn (DECL_RTL (decl));
788 #endif
789 value = DECL_RTL (decl);
791 /* Don't mention a variable at all
792 if it was completely optimized into nothingness.
794 If DECL was from an inline function, then its rtl
795 is not identically the rtl that was used in this
796 particular compilation. */
797 if (GET_CODE (value) == REG)
799 regno = REGNO (value);
800 if (regno >= FIRST_PSEUDO_REGISTER)
801 return;
803 else if (GET_CODE (value) == SUBREG)
805 while (GET_CODE (value) == SUBREG)
806 value = SUBREG_REG (value);
807 if (GET_CODE (value) == REG)
809 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
810 return;
812 regno = REGNO (alter_subreg (&value));
813 SET_DECL_RTL (decl, value);
815 /* Don't output anything if an auto variable
816 gets RTL that is static.
817 GAS version 2.2 can't handle such output. */
818 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
819 && ! TREE_STATIC (decl))
820 return;
822 /* Emit any structure, union, or enum type that has not been output.
823 This occurs for tag-less structs (et al) used to declare variables
824 within functions. */
825 if (TREE_CODE (type) == ENUMERAL_TYPE
826 || TREE_CODE (type) == RECORD_TYPE
827 || TREE_CODE (type) == UNION_TYPE
828 || TREE_CODE (type) == QUAL_UNION_TYPE)
830 if (COMPLETE_TYPE_P (type) /* not a forward reference */
831 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
832 sdbout_one_type (type);
835 /* Defer SDB information for top-level initialized variables! */
836 if (! local
837 && GET_CODE (value) == MEM
838 && DECL_INITIAL (decl))
839 return;
841 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
842 For now, avoid crashing. */
843 if (DECL_NAME (decl) == NULL_TREE)
844 return;
846 /* Record the name for, starting a symtab entry. */
847 if (local)
848 name = IDENTIFIER_POINTER (DECL_NAME (decl));
849 else
850 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
852 if (GET_CODE (value) == MEM
853 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
855 PUT_SDB_DEF (name);
856 if (TREE_PUBLIC (decl))
858 PUT_SDB_VAL (XEXP (value, 0));
859 PUT_SDB_SCL (C_EXT);
861 else
863 PUT_SDB_VAL (XEXP (value, 0));
864 PUT_SDB_SCL (C_STAT);
867 else if (regno >= 0)
869 PUT_SDB_DEF (name);
870 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
871 PUT_SDB_SCL (C_REG);
873 else if (GET_CODE (value) == MEM
874 && (GET_CODE (XEXP (value, 0)) == MEM
875 || (GET_CODE (XEXP (value, 0)) == REG
876 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
877 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
878 /* If the value is indirect by memory or by a register
879 that isn't the frame pointer
880 then it means the object is variable-sized and address through
881 that register or stack slot. COFF has no way to represent this
882 so all we can do is output the variable as a pointer. */
884 PUT_SDB_DEF (name);
885 if (GET_CODE (XEXP (value, 0)) == REG)
887 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
888 PUT_SDB_SCL (C_REG);
890 else
892 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
893 (CONST_INT...)))).
894 We want the value of that CONST_INT. */
895 /* Encore compiler hates a newline in a macro arg, it seems. */
896 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
897 (XEXP (XEXP (value, 0), 0)));
898 PUT_SDB_SCL (C_AUTO);
901 /* Effectively do build_pointer_type, but don't cache this type,
902 since it might be temporary whereas the type it points to
903 might have been saved for inlining. */
904 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
905 type = make_node (POINTER_TYPE);
906 TREE_TYPE (type) = TREE_TYPE (decl);
908 else if (GET_CODE (value) == MEM
909 && ((GET_CODE (XEXP (value, 0)) == PLUS
910 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
911 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
912 /* This is for variables which are at offset zero from
913 the frame pointer. This happens on the Alpha.
914 Non-frame pointer registers are excluded above. */
915 || (GET_CODE (XEXP (value, 0)) == REG)))
917 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
918 or (MEM (REG...)). We want the value of that CONST_INT
919 or zero. */
920 PUT_SDB_DEF (name);
921 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
922 PUT_SDB_SCL (C_AUTO);
924 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
926 /* Handle an obscure case which can arise when optimizing and
927 when there are few available registers. (This is *always*
928 the case for i386/i486 targets). The DECL_RTL looks like
929 (MEM (CONST ...)) even though this variable is a local `auto'
930 or a local `register' variable. In effect, what has happened
931 is that the reload pass has seen that all assignments and
932 references for one such a local variable can be replaced by
933 equivalent assignments and references to some static storage
934 variable, thereby avoiding the need for a register. In such
935 cases we're forced to lie to debuggers and tell them that
936 this variable was itself `static'. */
937 PUT_SDB_DEF (name);
938 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
939 PUT_SDB_SCL (C_STAT);
941 else
943 /* It is something we don't know how to represent for SDB. */
944 return;
946 break;
948 default:
949 break;
951 PUT_SDB_TYPE (plain_type (type));
952 PUT_SDB_ENDEF;
955 /* Output SDB information for a top-level initialized variable
956 that has been delayed. */
958 static void
959 sdbout_toplevel_data (decl)
960 tree decl;
962 tree type = TREE_TYPE (decl);
964 if (DECL_IGNORED_P (decl))
965 return;
967 if (! (TREE_CODE (decl) == VAR_DECL
968 && GET_CODE (DECL_RTL (decl)) == MEM
969 && DECL_INITIAL (decl)))
970 abort ();
972 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
973 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
974 if (TREE_PUBLIC (decl))
976 PUT_SDB_SCL (C_EXT);
978 else
980 PUT_SDB_SCL (C_STAT);
982 PUT_SDB_TYPE (plain_type (type));
983 PUT_SDB_ENDEF;
986 #ifdef SDB_ALLOW_FORWARD_REFERENCES
988 /* Machinery to record and output anonymous types. */
990 static tree anonymous_types;
992 static void
993 sdbout_queue_anonymous_type (type)
994 tree type;
996 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
999 static void
1000 sdbout_dequeue_anonymous_types ()
1002 tree types, link;
1004 while (anonymous_types)
1006 types = nreverse (anonymous_types);
1007 anonymous_types = NULL_TREE;
1009 for (link = types; link; link = TREE_CHAIN (link))
1011 tree type = TREE_VALUE (link);
1013 if (type && ! TREE_ASM_WRITTEN (type))
1014 sdbout_one_type (type);
1019 #endif
1021 /* Given a chain of ..._TYPE nodes, all of which have names,
1022 output definitions of those names, as typedefs. */
1024 void
1025 sdbout_types (types)
1026 tree types;
1028 tree link;
1030 for (link = types; link; link = TREE_CHAIN (link))
1031 sdbout_one_type (link);
1033 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1034 sdbout_dequeue_anonymous_types ();
1035 #endif
1038 static void
1039 sdbout_type (type)
1040 tree type;
1042 if (type == error_mark_node)
1043 type = integer_type_node;
1044 PUT_SDB_TYPE (plain_type (type));
1047 /* Output types of the fields of type TYPE, if they are structs.
1049 Formerly did not chase through pointer types, since that could be circular.
1050 They must come before TYPE, since forward refs are not allowed.
1051 Now james@bigtex.cactus.org says to try them. */
1053 static void
1054 sdbout_field_types (type)
1055 tree type;
1057 tree tail;
1059 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1060 /* This condition should match the one for emitting the actual
1061 members below. */
1062 if (TREE_CODE (tail) == FIELD_DECL
1063 && DECL_NAME (tail)
1064 && DECL_SIZE (tail)
1065 && host_integerp (DECL_SIZE (tail), 1)
1066 && host_integerp (bit_position (tail), 0))
1068 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1069 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1070 else
1071 sdbout_one_type (TREE_TYPE (tail));
1075 /* Use this to put out the top level defined record and union types
1076 for later reference. If this is a struct with a name, then put that
1077 name out. Other unnamed structs will have .xxfake labels generated so
1078 that they may be referred to later.
1079 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1080 It may NOT be called recursively. */
1082 static void
1083 sdbout_one_type (type)
1084 tree type;
1086 if (current_function_decl != NULL_TREE
1087 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1088 ; /* Don't change section amid function. */
1089 else
1090 text_section ();
1092 switch (TREE_CODE (type))
1094 case RECORD_TYPE:
1095 case UNION_TYPE:
1096 case QUAL_UNION_TYPE:
1097 case ENUMERAL_TYPE:
1098 type = TYPE_MAIN_VARIANT (type);
1099 /* Don't output a type twice. */
1100 if (TREE_ASM_WRITTEN (type))
1101 /* James said test TREE_ASM_BEING_WRITTEN here. */
1102 return;
1104 /* Output nothing if type is not yet defined. */
1105 if (!COMPLETE_TYPE_P (type))
1106 return;
1108 TREE_ASM_WRITTEN (type) = 1;
1109 #if 1
1110 /* This is reputed to cause trouble with the following case,
1111 but perhaps checking TYPE_SIZE above will fix it. */
1113 /* Here is a test case:
1115 struct foo {
1116 struct badstr *bbb;
1117 } forwardref;
1119 typedef struct intermediate {
1120 int aaaa;
1121 } intermediate_ref;
1123 typedef struct badstr {
1124 int ccccc;
1125 } badtype; */
1127 #if 0
1128 TREE_ASM_BEING_WRITTEN (type) = 1;
1129 #endif
1130 /* This change, which ought to make better output,
1131 used to make the COFF assembler unhappy.
1132 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1133 /* Before really doing anything, output types we want to refer to. */
1134 /* Note that in version 1 the following two lines
1135 are not used if forward references are in use. */
1136 if (TREE_CODE (type) != ENUMERAL_TYPE)
1137 sdbout_field_types (type);
1138 #if 0
1139 TREE_ASM_WRITTEN (type) = 1;
1140 #endif
1141 #endif
1143 /* Output a structure type. */
1145 int size = int_size_in_bytes (type);
1146 int member_scl = 0;
1147 tree tem;
1148 int i, n_baseclasses = 0;
1150 /* Record the type tag, but not in its permanent place just yet. */
1151 sdbout_record_type_name (type);
1153 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1155 switch (TREE_CODE (type))
1157 case UNION_TYPE:
1158 case QUAL_UNION_TYPE:
1159 PUT_SDB_SCL (C_UNTAG);
1160 PUT_SDB_TYPE (T_UNION);
1161 member_scl = C_MOU;
1162 break;
1164 case RECORD_TYPE:
1165 PUT_SDB_SCL (C_STRTAG);
1166 PUT_SDB_TYPE (T_STRUCT);
1167 member_scl = C_MOS;
1168 break;
1170 case ENUMERAL_TYPE:
1171 PUT_SDB_SCL (C_ENTAG);
1172 PUT_SDB_TYPE (T_ENUM);
1173 member_scl = C_MOE;
1174 break;
1176 default:
1177 break;
1180 PUT_SDB_SIZE (size);
1181 PUT_SDB_ENDEF;
1183 /* Print out the base class information with fields
1184 named after the types they hold. */
1185 /* This is only relevant to aggregate types. TYPE_BINFO is used
1186 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1187 case. */
1188 if (TREE_CODE (type) != ENUMERAL_TYPE)
1190 if (TYPE_BINFO (type)
1191 && TYPE_BINFO_BASETYPES (type))
1192 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1193 for (i = 0; i < n_baseclasses; i++)
1195 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1197 tree child_type = BINFO_TYPE (child);
1198 tree child_type_name;
1199 if (TYPE_NAME (child_type) == 0)
1200 continue;
1201 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1202 child_type_name = TYPE_NAME (child_type);
1203 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1205 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1206 if (child_type_name && template_name_p (child_type_name))
1207 child_type_name
1208 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1210 else
1211 continue;
1213 CONTIN;
1214 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1215 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1216 PUT_SDB_SCL (member_scl);
1217 sdbout_type (BINFO_TYPE (child));
1218 PUT_SDB_ENDEF;
1222 /* output the individual fields */
1224 if (TREE_CODE (type) == ENUMERAL_TYPE)
1226 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1227 if (host_integerp (TREE_VALUE (tem), 0))
1229 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1230 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1231 PUT_SDB_SCL (C_MOE);
1232 PUT_SDB_TYPE (T_MOE);
1233 PUT_SDB_ENDEF;
1236 else /* record or union type */
1237 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1238 /* Output the name, type, position (in bits), size (in bits)
1239 of each field. */
1241 /* Omit here the nameless fields that are used to skip bits.
1242 Also omit fields with variable size or position.
1243 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1244 if (TREE_CODE (tem) == FIELD_DECL
1245 && DECL_NAME (tem)
1246 && DECL_SIZE (tem)
1247 && host_integerp (DECL_SIZE (tem), 1)
1248 && host_integerp (bit_position (tem), 0))
1250 const char *name;
1252 CONTIN;
1253 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1254 PUT_SDB_DEF (name);
1255 if (DECL_BIT_FIELD_TYPE (tem))
1257 PUT_SDB_INT_VAL (int_bit_position (tem));
1258 PUT_SDB_SCL (C_FIELD);
1259 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1260 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1262 else
1264 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1265 PUT_SDB_SCL (member_scl);
1266 sdbout_type (TREE_TYPE (tem));
1268 PUT_SDB_ENDEF;
1270 /* output end of a structure,union, or enumeral definition */
1272 PUT_SDB_PLAIN_DEF ("eos");
1273 PUT_SDB_INT_VAL (size);
1274 PUT_SDB_SCL (C_EOS);
1275 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1276 PUT_SDB_SIZE (size);
1277 PUT_SDB_ENDEF;
1278 break;
1280 default:
1281 break;
1286 /* The following two functions output definitions of function parameters.
1287 Each parameter gets a definition locating it in the parameter list.
1288 Each parameter that is a register variable gets a second definition
1289 locating it in the register.
1291 Printing or argument lists in gdb uses the definitions that
1292 locate in the parameter list. But reference to the variable in
1293 expressions uses preferentially the definition as a register. */
1295 /* Output definitions, referring to storage in the parmlist,
1296 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1298 static void
1299 sdbout_parms (parms)
1300 tree parms;
1302 for (; parms; parms = TREE_CHAIN (parms))
1303 if (DECL_NAME (parms))
1305 int current_sym_value = 0;
1306 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1308 if (name == 0 || *name == 0)
1309 name = gen_fake_label ();
1311 /* Perform any necessary register eliminations on the parameter's rtl,
1312 so that the debugging output will be accurate. */
1313 DECL_INCOMING_RTL (parms)
1314 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1315 SET_DECL_RTL (parms,
1316 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1318 if (PARM_PASSED_IN_MEMORY (parms))
1320 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1321 tree type;
1323 /* ??? Here we assume that the parm address is indexed
1324 off the frame pointer or arg pointer.
1325 If that is not true, we produce meaningless results,
1326 but do not crash. */
1327 if (GET_CODE (addr) == PLUS
1328 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1329 current_sym_value = INTVAL (XEXP (addr, 1));
1330 else
1331 current_sym_value = 0;
1333 if (GET_CODE (DECL_RTL (parms)) == REG
1334 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1335 type = DECL_ARG_TYPE (parms);
1336 else
1338 int original_sym_value = current_sym_value;
1340 /* This is the case where the parm is passed as an int or
1341 double and it is converted to a char, short or float
1342 and stored back in the parmlist. In this case, describe
1343 the parm with the variable's declared type, and adjust
1344 the address if the least significant bytes (which we are
1345 using) are not the first ones. */
1346 if (BYTES_BIG_ENDIAN
1347 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1348 current_sym_value +=
1349 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1350 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1352 if (GET_CODE (DECL_RTL (parms)) == MEM
1353 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1354 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1355 == CONST_INT)
1356 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1357 == current_sym_value))
1358 type = TREE_TYPE (parms);
1359 else
1361 current_sym_value = original_sym_value;
1362 type = DECL_ARG_TYPE (parms);
1366 PUT_SDB_DEF (name);
1367 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1368 PUT_SDB_SCL (C_ARG);
1369 PUT_SDB_TYPE (plain_type (type));
1370 PUT_SDB_ENDEF;
1372 else if (GET_CODE (DECL_RTL (parms)) == REG)
1374 rtx best_rtl;
1375 /* Parm passed in registers and lives in registers or nowhere. */
1377 /* If parm lives in a register, use that register;
1378 pretend the parm was passed there. It would be more consistent
1379 to describe the register where the parm was passed,
1380 but in practice that register usually holds something else. */
1381 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1382 best_rtl = DECL_RTL (parms);
1383 /* If the parm lives nowhere,
1384 use the register where it was passed. */
1385 else
1386 best_rtl = DECL_INCOMING_RTL (parms);
1388 PUT_SDB_DEF (name);
1389 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1390 PUT_SDB_SCL (C_REGPARM);
1391 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1392 PUT_SDB_ENDEF;
1394 else if (GET_CODE (DECL_RTL (parms)) == MEM
1395 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1397 /* Parm was passed in registers but lives on the stack. */
1399 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1400 in which case we want the value of that CONST_INT,
1401 or (MEM (REG ...)) or (MEM (MEM ...)),
1402 in which case we use a value of zero. */
1403 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1404 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1405 current_sym_value = 0;
1406 else
1407 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1409 /* Again, this assumes the offset is based on the arg pointer. */
1410 PUT_SDB_DEF (name);
1411 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1412 XEXP (DECL_RTL (parms), 0)));
1413 PUT_SDB_SCL (C_ARG);
1414 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1415 PUT_SDB_ENDEF;
1420 /* Output definitions for the places where parms live during the function,
1421 when different from where they were passed, when the parms were passed
1422 in memory.
1424 It is not useful to do this for parms passed in registers
1425 that live during the function in different registers, because it is
1426 impossible to look in the passed register for the passed value,
1427 so we use the within-the-function register to begin with.
1429 PARMS is a chain of PARM_DECL nodes. */
1431 static void
1432 sdbout_reg_parms (parms)
1433 tree parms;
1435 for (; parms; parms = TREE_CHAIN (parms))
1436 if (DECL_NAME (parms))
1438 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1440 /* Report parms that live in registers during the function
1441 but were passed in memory. */
1442 if (GET_CODE (DECL_RTL (parms)) == REG
1443 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1444 && PARM_PASSED_IN_MEMORY (parms))
1446 if (name == 0 || *name == 0)
1447 name = gen_fake_label ();
1448 PUT_SDB_DEF (name);
1449 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1450 PUT_SDB_SCL (C_REG);
1451 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1452 PUT_SDB_ENDEF;
1454 /* Report parms that live in memory but not where they were passed. */
1455 else if (GET_CODE (DECL_RTL (parms)) == MEM
1456 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1457 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1458 && PARM_PASSED_IN_MEMORY (parms)
1459 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1461 #if 0 /* ??? It is not clear yet what should replace this. */
1462 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1463 /* A parm declared char is really passed as an int,
1464 so it occupies the least significant bytes.
1465 On a big-endian machine those are not the low-numbered ones. */
1466 if (BYTES_BIG_ENDIAN
1467 && offset != -1
1468 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1469 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1470 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1471 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1472 #endif
1474 if (name == 0 || *name == 0)
1475 name = gen_fake_label ();
1476 PUT_SDB_DEF (name);
1477 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1478 (XEXP (DECL_RTL (parms), 0)));
1479 PUT_SDB_SCL (C_AUTO);
1480 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1481 PUT_SDB_ENDEF;
1487 /* Output debug information for a global DECL. Called from toplev.c
1488 after compilation proper has finished. */
1490 static void
1491 sdbout_global_decl (decl)
1492 tree decl;
1494 if (TREE_CODE (decl) == VAR_DECL
1495 && !DECL_EXTERNAL (decl)
1496 && DECL_RTL_SET_P (decl))
1498 /* The COFF linker can move initialized global vars to the end.
1499 And that can screw up the symbol ordering. Defer those for
1500 sdbout_finish (). */
1501 if (!DECL_INITIAL (decl) || !TREE_PUBLIC (decl))
1502 sdbout_symbol (decl, 0);
1504 /* Output COFF information for non-global file-scope initialized
1505 variables. */
1506 if (DECL_INITIAL (decl) && GET_CODE (DECL_RTL (decl)) == MEM)
1507 sdbout_toplevel_data (decl);
1511 /* Output initialized global vars at the end, in the order of
1512 definition. See comment in sdbout_global_decl. */
1514 static void
1515 sdbout_finish (main_filename)
1516 const char *main_filename ATTRIBUTE_UNUSED;
1518 tree decl = getdecls ();
1519 unsigned int len = list_length (decl);
1520 tree *vec = (tree *) xmalloc (sizeof (tree) * len);
1521 unsigned int i;
1523 /* Process the decls in reverse order--earliest first. Put them
1524 into VEC from back to front, then take out from front. */
1526 for (i = 0; i < len; i++, decl = TREE_CHAIN (decl))
1527 vec[len - i - 1] = decl;
1529 for (i = 0; i < len; i++)
1531 decl = vec[i];
1532 if (TREE_CODE (decl) == VAR_DECL
1533 && ! DECL_EXTERNAL (decl)
1534 && DECL_INITIAL (decl)
1535 && TREE_PUBLIC (decl)
1536 && DECL_RTL_SET_P (decl))
1537 sdbout_symbol (decl, 0);
1540 free (vec);
1543 /* Describe the beginning of an internal block within a function.
1544 Also output descriptions of variables defined in this block.
1546 N is the number of the block, by order of beginning, counting from 1,
1547 and not counting the outermost (function top-level) block.
1548 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1549 if the count starts at 0 for the outermost one. */
1551 static void
1552 sdbout_begin_block (line, n)
1553 unsigned int line;
1554 unsigned int n;
1556 tree decl = current_function_decl;
1557 MAKE_LINE_SAFE (line);
1559 /* The SCO compiler does not emit a separate block for the function level
1560 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1561 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1562 #ifndef MIPS_DEBUGGING_INFO
1563 if (n != 1)
1564 #endif
1565 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1567 if (n == 1)
1569 /* Include the outermost BLOCK's variables in block 1. */
1570 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1571 sdbout_block (DECL_INITIAL (decl));
1573 /* If -g1, suppress all the internal symbols of functions
1574 except for arguments. */
1575 if (debug_info_level != DINFO_LEVEL_TERSE)
1577 do_block = n;
1578 sdbout_block (DECL_INITIAL (decl));
1581 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1582 sdbout_dequeue_anonymous_types ();
1583 #endif
1586 /* Describe the end line-number of an internal block within a function. */
1588 static void
1589 sdbout_end_block (line, n)
1590 unsigned int line;
1591 unsigned int n ATTRIBUTE_UNUSED;
1593 MAKE_LINE_SAFE (line);
1595 /* The SCO compiler does not emit a separate block for the function level
1596 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1597 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1598 #ifndef MIPS_DEBUGGING_INFO
1599 if (n != 1)
1600 #endif
1601 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1604 static void
1605 sdbout_source_line (line, filename)
1606 unsigned int line;
1607 const char *filename ATTRIBUTE_UNUSED;
1609 /* COFF relative line numbers must be positive. */
1610 if ((int) line > sdb_begin_function_line)
1612 #ifdef ASM_OUTPUT_SOURCE_LINE
1613 ASM_OUTPUT_SOURCE_LINE (asm_out_file, line);
1614 #else
1615 fprintf (asm_out_file, "\t.ln\t%d\n",
1616 ((sdb_begin_function_line > -1)
1617 ? line - sdb_begin_function_line : 1));
1618 #endif
1622 /* Output sdb info for the current function name.
1623 Called from assemble_start_function. */
1625 static void
1626 sdbout_begin_function (decl)
1627 tree decl ATTRIBUTE_UNUSED;
1629 sdbout_symbol (current_function_decl, 0);
1632 /* Called at beginning of function body (before or after prologue,
1633 depending on MIPS_DEBUGGING_INFO). Record the function's starting
1634 line number, so we can output relative line numbers for the other
1635 lines. Describe beginning of outermost block. Also describe the
1636 parameter list. */
1638 #ifndef MIPS_DEBUGGING_INFO
1639 static void
1640 sdbout_begin_prologue (line, file)
1641 unsigned int line;
1642 const char *file ATTRIBUTE_UNUSED;
1644 sdbout_end_prologue (line);
1646 #endif
1648 static void
1649 sdbout_end_prologue (line)
1650 unsigned int line;
1652 sdb_begin_function_line = line - 1;
1653 PUT_SDB_FUNCTION_START (line);
1654 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1655 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1658 /* Called at end of function (before epilogue).
1659 Describe end of outermost block. */
1661 static void
1662 sdbout_end_function (line)
1663 unsigned int line;
1665 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1666 sdbout_dequeue_anonymous_types ();
1667 #endif
1669 MAKE_LINE_SAFE (line);
1670 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1672 /* Indicate we are between functions, for line-number output. */
1673 sdb_begin_function_line = -1;
1676 /* Output sdb info for the absolute end of a function.
1677 Called after the epilogue is output. */
1679 static void
1680 sdbout_end_epilogue ()
1682 const char *const name ATTRIBUTE_UNUSED
1683 = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1685 #ifdef PUT_SDB_EPILOGUE_END
1686 PUT_SDB_EPILOGUE_END (name);
1687 #else
1688 fprintf (asm_out_file, "\t.def\t");
1689 assemble_name (asm_out_file, name);
1690 fprintf (asm_out_file, "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n",
1691 SDB_DELIM, SDB_DELIM, SDB_DELIM);
1692 #endif
1695 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1696 is present. */
1698 static void
1699 sdbout_label (insn)
1700 rtx insn;
1702 PUT_SDB_DEF (LABEL_NAME (insn));
1703 PUT_SDB_VAL (insn);
1704 PUT_SDB_SCL (C_LABEL);
1705 PUT_SDB_TYPE (T_NULL);
1706 PUT_SDB_ENDEF;
1709 /* Change to reading from a new source file. */
1711 static void
1712 sdbout_start_source_file (line, filename)
1713 unsigned int line ATTRIBUTE_UNUSED;
1714 const char *filename ATTRIBUTE_UNUSED;
1716 #ifdef MIPS_DEBUGGING_INFO
1717 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1719 n->next = current_file;
1720 n->name = filename;
1721 current_file = n;
1722 PUT_SDB_SRC_FILE (filename);
1723 #endif
1726 /* Revert to reading a previous source file. */
1728 static void
1729 sdbout_end_source_file (line)
1730 unsigned int line ATTRIBUTE_UNUSED;
1732 #ifdef MIPS_DEBUGGING_INFO
1733 struct sdb_file *next;
1735 next = current_file->next;
1736 free (current_file);
1737 current_file = next;
1738 PUT_SDB_SRC_FILE (current_file->name);
1739 #endif
1742 /* Set up for SDB output at the start of compilation. */
1744 static void
1745 sdbout_init (input_file_name)
1746 const char *input_file_name ATTRIBUTE_UNUSED;
1748 #ifdef MIPS_DEBUGGING_INFO
1749 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1750 current_file->next = NULL;
1751 current_file->name = input_file_name;
1752 #endif
1754 #ifdef RMS_QUICK_HACK_1
1755 tree t;
1756 for (t = getdecls (); t; t = TREE_CHAIN (t))
1757 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
1758 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
1759 sdbout_symbol (t, 0);
1760 #endif
1762 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1763 ggc_add_tree_root (&anonymous_types, 1);
1764 #endif
1767 #endif /* SDB_DEBUGGING_INFO */