Update version
[official-gcc.git] / gcc / sdbout.c
blob649bc0aa67d544869607dd5bdfb8eb3b59146115
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 GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 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"
60 /* Mips systems use the SDB functions to dump out symbols, but do not
61 supply usable syms.h include files. Which syms.h file to use is a
62 target parameter so don't use the native one if we're cross compiling. */
64 #if defined(USG) && !defined(MIPS) && !defined (hpux) && !defined(_WIN32) && !defined(__linux__) && !defined(__INTERIX) && !defined(CROSS_COMPILE)
65 #include <syms.h>
66 /* Use T_INT if we don't have T_VOID. */
67 #ifndef T_VOID
68 #define T_VOID T_INT
69 #endif
70 #else
71 #include "gsyms.h"
72 #endif
74 /* #include <storclass.h> used to be this instead of syms.h. */
76 /* 1 if PARM is passed to this function in memory. */
78 #define PARM_PASSED_IN_MEMORY(PARM) \
79 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
81 /* A C expression for the integer offset value of an automatic variable
82 (C_AUTO) having address X (an RTX). */
83 #ifndef DEBUGGER_AUTO_OFFSET
84 #define DEBUGGER_AUTO_OFFSET(X) \
85 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
86 #endif
88 /* A C expression for the integer offset value of an argument (C_ARG)
89 having address X (an RTX). The nominal offset is OFFSET. */
90 #ifndef DEBUGGER_ARG_OFFSET
91 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
92 #endif
94 /* Line number of beginning of current function, minus one.
95 Negative means not in a function or not using sdb. */
97 int sdb_begin_function_line = -1;
99 /* Counter to generate unique "names" for nameless struct members. */
101 static int unnamed_struct_number = 0;
103 extern FILE *asm_out_file;
105 extern tree current_function_decl;
107 #include "sdbout.h"
109 static char *gen_fake_label PARAMS ((void));
110 static int plain_type PARAMS ((tree));
111 static int template_name_p PARAMS ((tree));
112 static void sdbout_record_type_name PARAMS ((tree));
113 static int plain_type_1 PARAMS ((tree, int));
114 static void sdbout_block PARAMS ((tree));
115 static void sdbout_syms PARAMS ((tree));
116 #ifdef SDB_ALLOW_FORWARD_REFERENCES
117 static void sdbout_queue_anonymous_type PARAMS ((tree));
118 static void sdbout_dequeue_anonymous_types PARAMS ((void));
119 #endif
120 static void sdbout_type PARAMS ((tree));
121 static void sdbout_field_types PARAMS ((tree));
122 static void sdbout_one_type PARAMS ((tree));
123 static void sdbout_parms PARAMS ((tree));
124 static void sdbout_reg_parms PARAMS ((tree));
126 /* Random macros describing parts of SDB data. */
128 /* Put something here if lines get too long */
129 #define CONTIN
131 /* Default value of delimiter is ";". */
132 #ifndef SDB_DELIM
133 #define SDB_DELIM ";"
134 #endif
136 /* Maximum number of dimensions the assembler will allow. */
137 #ifndef SDB_MAX_DIM
138 #define SDB_MAX_DIM 4
139 #endif
141 #ifndef PUT_SDB_SCL
142 #define PUT_SDB_SCL(a) fprintf(asm_out_file, "\t.scl\t%d%s", (a), SDB_DELIM)
143 #endif
145 #ifndef PUT_SDB_INT_VAL
146 #define PUT_SDB_INT_VAL(a) \
147 do { \
148 fputs ("\t.val\t", asm_out_file); \
149 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
150 fprintf (asm_out_file, "%s", SDB_DELIM); \
151 } while (0)
153 #endif
155 #ifndef PUT_SDB_VAL
156 #define PUT_SDB_VAL(a) \
157 ( fputs ("\t.val\t", asm_out_file), \
158 output_addr_const (asm_out_file, (a)), \
159 fprintf (asm_out_file, SDB_DELIM))
160 #endif
162 #ifndef PUT_SDB_DEF
163 #define PUT_SDB_DEF(a) \
164 do { fprintf (asm_out_file, "\t.def\t"); \
165 assemble_name (asm_out_file, a); \
166 fprintf (asm_out_file, SDB_DELIM); } while (0)
167 #endif
169 #ifndef PUT_SDB_PLAIN_DEF
170 #define PUT_SDB_PLAIN_DEF(a) fprintf(asm_out_file,"\t.def\t.%s%s",a, SDB_DELIM)
171 #endif
173 #ifndef PUT_SDB_ENDEF
174 #define PUT_SDB_ENDEF fputs("\t.endef\n", asm_out_file)
175 #endif
177 #ifndef PUT_SDB_TYPE
178 #define PUT_SDB_TYPE(a) fprintf(asm_out_file, "\t.type\t0%o%s", a, SDB_DELIM)
179 #endif
181 #ifndef PUT_SDB_SIZE
182 #define PUT_SDB_SIZE(a) \
183 do { \
184 fputs ("\t.size\t", asm_out_file); \
185 fprintf (asm_out_file, HOST_WIDE_INT_PRINT_DEC, (HOST_WIDE_INT)(a)); \
186 fprintf (asm_out_file, "%s", SDB_DELIM); \
187 } while(0)
188 #endif
190 #ifndef PUT_SDB_START_DIM
191 #define PUT_SDB_START_DIM fprintf(asm_out_file, "\t.dim\t")
192 #endif
194 #ifndef PUT_SDB_NEXT_DIM
195 #define PUT_SDB_NEXT_DIM(a) fprintf(asm_out_file, "%d,", a)
196 #endif
198 #ifndef PUT_SDB_LAST_DIM
199 #define PUT_SDB_LAST_DIM(a) fprintf(asm_out_file, "%d%s", a, SDB_DELIM)
200 #endif
202 #ifndef PUT_SDB_TAG
203 #define PUT_SDB_TAG(a) \
204 do { fprintf (asm_out_file, "\t.tag\t"); \
205 assemble_name (asm_out_file, a); \
206 fprintf (asm_out_file, SDB_DELIM); } while (0)
207 #endif
209 #ifndef PUT_SDB_BLOCK_START
210 #define PUT_SDB_BLOCK_START(LINE) \
211 fprintf (asm_out_file, \
212 "\t.def\t.bb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
213 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
214 #endif
216 #ifndef PUT_SDB_BLOCK_END
217 #define PUT_SDB_BLOCK_END(LINE) \
218 fprintf (asm_out_file, \
219 "\t.def\t.eb%s\t.val\t.%s\t.scl\t100%s\t.line\t%d%s\t.endef\n", \
220 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
221 #endif
223 #ifndef PUT_SDB_FUNCTION_START
224 #define PUT_SDB_FUNCTION_START(LINE) \
225 fprintf (asm_out_file, \
226 "\t.def\t.bf%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
227 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
228 #endif
230 #ifndef PUT_SDB_FUNCTION_END
231 #define PUT_SDB_FUNCTION_END(LINE) \
232 fprintf (asm_out_file, \
233 "\t.def\t.ef%s\t.val\t.%s\t.scl\t101%s\t.line\t%d%s\t.endef\n", \
234 SDB_DELIM, SDB_DELIM, SDB_DELIM, (LINE), SDB_DELIM)
235 #endif
237 #ifndef PUT_SDB_EPILOGUE_END
238 #define PUT_SDB_EPILOGUE_END(NAME) \
239 do { fprintf (asm_out_file, "\t.def\t"); \
240 assemble_name (asm_out_file, NAME); \
241 fprintf (asm_out_file, \
242 "%s\t.val\t.%s\t.scl\t-1%s\t.endef\n", \
243 SDB_DELIM, SDB_DELIM, SDB_DELIM); } while (0)
244 #endif
246 #ifndef SDB_GENERATE_FAKE
247 #define SDB_GENERATE_FAKE(BUFFER, NUMBER) \
248 sprintf ((BUFFER), ".%dfake", (NUMBER));
249 #endif
251 /* Return the sdb tag identifier string for TYPE
252 if TYPE has already been defined; otherwise return a null pointer. */
254 #define KNOWN_TYPE_TAG(type) TYPE_SYMTAB_POINTER (type)
256 /* Set the sdb tag identifier string for TYPE to NAME. */
258 #define SET_KNOWN_TYPE_TAG(TYPE, NAME) \
259 TYPE_SYMTAB_POINTER (TYPE) = (NAME)
261 /* Return the name (a string) of the struct, union or enum tag
262 described by the TREE_LIST node LINK. This is 0 for an anonymous one. */
264 #define TAG_NAME(link) \
265 (((link) && TREE_PURPOSE ((link)) \
266 && IDENTIFIER_POINTER (TREE_PURPOSE ((link)))) \
267 ? IDENTIFIER_POINTER (TREE_PURPOSE ((link))) : (char *) 0)
269 /* Ensure we don't output a negative line number. */
270 #define MAKE_LINE_SAFE(line) \
271 if (line <= sdb_begin_function_line) line = sdb_begin_function_line + 1
273 /* Perform linker optimization of merging header file definitions together
274 for targets with MIPS_DEBUGGING_INFO defined. This won't work without a
275 post 960826 version of GAS. Nothing breaks with earlier versions of GAS,
276 the optimization just won't be done. The native assembler already has the
277 necessary support. */
279 #ifdef MIPS_DEBUGGING_INFO
281 #ifndef PUT_SDB_SRC_FILE
282 #define PUT_SDB_SRC_FILE(FILENAME) \
283 output_file_directive (asm_out_file, (FILENAME))
284 #endif
286 /* ECOFF linkers have an optimization that does the same kind of thing as
287 N_BINCL/E_INCL in stabs: eliminate duplicate debug information in the
288 executable. To achieve this, GCC must output a .file for each file
289 name change. */
291 /* This is a stack of input files. */
293 struct sdb_file
295 struct sdb_file *next;
296 const char *name;
299 /* This is the top of the stack. */
301 static struct sdb_file *current_file;
303 #endif /* MIPS_DEBUGGING_INFO */
306 #if 0
308 /* return the tag identifier for type
311 char *
312 tag_of_ru_type (type,link)
313 tree type,link;
315 if (TYPE_SYMTAB_ADDRESS (type))
316 return TYPE_SYMTAB_ADDRESS (type);
317 if (link && TREE_PURPOSE (link)
318 && IDENTIFIER_POINTER (TREE_PURPOSE (link)))
319 TYPE_SYMTAB_ADDRESS (type) = IDENTIFIER_POINTER (TREE_PURPOSE (link));
320 else
321 return (char *) TYPE_SYMTAB_ADDRESS (type);
323 #endif
325 /* Return a unique string to name an anonymous type. */
327 static char *
328 gen_fake_label ()
330 char label[10];
331 char *labelstr;
332 SDB_GENERATE_FAKE (label, unnamed_struct_number);
333 unnamed_struct_number++;
334 labelstr = (char *) permalloc (strlen (label) + 1);
335 strcpy (labelstr, label);
336 return labelstr;
339 /* Return the number which describes TYPE for SDB.
340 For pointers, etc., this function is recursive.
341 Each record, union or enumeral type must already have had a
342 tag number output. */
344 /* The number is given by d6d5d4d3d2d1bbbb
345 where bbbb is 4 bit basic type, and di indicate one of notype,ptr,fn,array.
346 Thus, char *foo () has bbbb=T_CHAR
347 d1=D_FCN
348 d2=D_PTR
349 N_BTMASK= 017 1111 basic type field.
350 N_TSHIFT= 2 derived type shift
351 N_BTSHFT= 4 Basic type shift */
353 /* Produce the number that describes a pointer, function or array type.
354 PREV is the number describing the target, value or element type.
355 DT_type describes how to transform that type. */
356 #define PUSH_DERIVED_LEVEL(DT_type,PREV) \
357 ((((PREV) & ~(int)N_BTMASK) << (int)N_TSHIFT) \
358 | ((int)DT_type << (int)N_BTSHFT) \
359 | ((PREV) & (int)N_BTMASK))
361 /* Number of elements used in sdb_dims. */
362 static int sdb_n_dims = 0;
364 /* Table of array dimensions of current type. */
365 static int sdb_dims[SDB_MAX_DIM];
367 /* Size of outermost array currently being processed. */
368 static int sdb_type_size = -1;
370 static int
371 plain_type (type)
372 tree type;
374 int val = plain_type_1 (type, 0);
376 /* If we have already saved up some array dimensions, print them now. */
377 if (sdb_n_dims > 0)
379 int i;
380 PUT_SDB_START_DIM;
381 for (i = sdb_n_dims - 1; i > 0; i--)
382 PUT_SDB_NEXT_DIM (sdb_dims[i]);
383 PUT_SDB_LAST_DIM (sdb_dims[0]);
384 sdb_n_dims = 0;
386 sdb_type_size = int_size_in_bytes (type);
387 /* Don't kill sdb if type is not laid out or has variable size. */
388 if (sdb_type_size < 0)
389 sdb_type_size = 0;
391 /* If we have computed the size of an array containing this type,
392 print it now. */
393 if (sdb_type_size >= 0)
395 PUT_SDB_SIZE (sdb_type_size);
396 sdb_type_size = -1;
398 return val;
401 static int
402 template_name_p (name)
403 tree name;
405 register const char *ptr = IDENTIFIER_POINTER (name);
406 while (*ptr && *ptr != '<')
407 ptr++;
409 return *ptr != '\0';
412 static void
413 sdbout_record_type_name (type)
414 tree type;
416 const char *name = 0;
417 int no_name;
419 if (KNOWN_TYPE_TAG (type))
420 return;
422 if (TYPE_NAME (type) != 0)
424 tree t = 0;
425 /* Find the IDENTIFIER_NODE for the type name. */
426 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
427 t = TYPE_NAME (type);
428 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
430 t = DECL_NAME (TYPE_NAME (type));
431 /* The DECL_NAME for templates includes "<>", which breaks
432 most assemblers. Use its assembler name instead, which
433 has been mangled into being safe. */
434 if (t && template_name_p (t))
435 t = DECL_ASSEMBLER_NAME (TYPE_NAME (type));
438 /* Now get the name as a string, or invent one. */
439 if (t != NULL_TREE)
440 name = IDENTIFIER_POINTER (t);
443 no_name = (name == 0 || *name == 0);
444 if (no_name)
445 name = gen_fake_label ();
447 SET_KNOWN_TYPE_TAG (type, name);
448 #ifdef SDB_ALLOW_FORWARD_REFERENCES
449 if (no_name)
450 sdbout_queue_anonymous_type (type);
451 #endif
454 /* Return the .type value for type TYPE.
456 LEVEL indicates how many levels deep we have recursed into the type.
457 The SDB debug format can only represent 6 derived levels of types.
458 After that, we must output inaccurate debug info. We deliberately
459 stop before the 7th level, so that ADA recursive types will not give an
460 infinite loop. */
462 static int
463 plain_type_1 (type, level)
464 tree type;
465 int level;
467 if (type == 0)
468 type = void_type_node;
469 else if (type == error_mark_node)
470 type = integer_type_node;
471 else
472 type = TYPE_MAIN_VARIANT (type);
474 switch (TREE_CODE (type))
476 case VOID_TYPE:
477 return T_VOID;
478 case BOOLEAN_TYPE:
479 case INTEGER_TYPE:
481 int size = int_size_in_bytes (type) * BITS_PER_UNIT;
483 /* Carefully distinguish all the standard types of C,
484 without messing up if the language is not C.
485 Note that we check only for the names that contain spaces;
486 other names might occur by coincidence in other languages. */
487 if (TYPE_NAME (type) != 0
488 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
489 && DECL_NAME (TYPE_NAME (type)) != 0
490 && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
492 const char *name
493 = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
495 if (!strcmp (name, "char"))
496 return T_CHAR;
497 if (!strcmp (name, "unsigned char"))
498 return T_UCHAR;
499 if (!strcmp (name, "signed char"))
500 return T_CHAR;
501 if (!strcmp (name, "int"))
502 return T_INT;
503 if (!strcmp (name, "unsigned int"))
504 return T_UINT;
505 if (!strcmp (name, "short int"))
506 return T_SHORT;
507 if (!strcmp (name, "short unsigned int"))
508 return T_USHORT;
509 if (!strcmp (name, "long int"))
510 return T_LONG;
511 if (!strcmp (name, "long unsigned int"))
512 return T_ULONG;
515 if (size == INT_TYPE_SIZE)
516 return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
517 if (size == CHAR_TYPE_SIZE)
518 return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
519 if (size == SHORT_TYPE_SIZE)
520 return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
521 if (size == LONG_TYPE_SIZE)
522 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
523 if (size == LONG_LONG_TYPE_SIZE) /* better than nothing */
524 return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
525 return 0;
528 case REAL_TYPE:
530 int precision = TYPE_PRECISION (type);
531 if (precision == FLOAT_TYPE_SIZE)
532 return T_FLOAT;
533 if (precision == DOUBLE_TYPE_SIZE)
534 return T_DOUBLE;
535 #ifdef EXTENDED_SDB_BASIC_TYPES
536 if (precision == LONG_DOUBLE_TYPE_SIZE)
537 return T_LNGDBL;
538 #else
539 if (precision == LONG_DOUBLE_TYPE_SIZE)
540 return T_DOUBLE; /* better than nothing */
541 #endif
542 return 0;
545 case ARRAY_TYPE:
547 int m;
548 if (level >= 6)
549 return T_VOID;
550 else
551 m = plain_type_1 (TREE_TYPE (type), level+1);
552 if (sdb_n_dims < SDB_MAX_DIM)
553 sdb_dims[sdb_n_dims++]
554 = (TYPE_DOMAIN (type)
555 && TYPE_MIN_VALUE (TYPE_DOMAIN (type)) != 0
556 && TYPE_MAX_VALUE (TYPE_DOMAIN (type)) != 0
557 && host_integerp (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
558 && host_integerp (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0)
559 ? (tree_low_cst (TYPE_MAX_VALUE (TYPE_DOMAIN (type)), 0)
560 - tree_low_cst (TYPE_MIN_VALUE (TYPE_DOMAIN (type)), 0) + 1)
561 : 0);
563 return PUSH_DERIVED_LEVEL (DT_ARY, m);
566 case RECORD_TYPE:
567 case UNION_TYPE:
568 case QUAL_UNION_TYPE:
569 case ENUMERAL_TYPE:
571 char *tag;
572 #ifdef SDB_ALLOW_FORWARD_REFERENCES
573 sdbout_record_type_name (type);
574 #endif
575 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
576 if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
577 #ifdef SDB_ALLOW_FORWARD_REFERENCES
578 || TYPE_MODE (type) != VOIDmode
579 #endif
581 #endif
583 /* Output the referenced structure tag name
584 only if the .def has already been finished.
585 At least on 386, the Unix assembler
586 cannot handle forward references to tags. */
587 /* But the 88100, it requires them, sigh... */
588 /* And the MIPS requires unknown refs as well... */
589 tag = KNOWN_TYPE_TAG (type);
590 PUT_SDB_TAG (tag);
591 /* These 3 lines used to follow the close brace.
592 However, a size of 0 without a tag implies a tag of 0,
593 so if we don't know a tag, we can't mention the size. */
594 sdb_type_size = int_size_in_bytes (type);
595 if (sdb_type_size < 0)
596 sdb_type_size = 0;
598 return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
599 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
600 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
601 : T_ENUM);
603 case POINTER_TYPE:
604 case REFERENCE_TYPE:
606 int m;
607 if (level >= 6)
608 return T_VOID;
609 else
610 m = plain_type_1 (TREE_TYPE (type), level+1);
611 return PUSH_DERIVED_LEVEL (DT_PTR, m);
613 case FUNCTION_TYPE:
614 case METHOD_TYPE:
616 int m;
617 if (level >= 6)
618 return T_VOID;
619 else
620 m = plain_type_1 (TREE_TYPE (type), level+1);
621 return PUSH_DERIVED_LEVEL (DT_FCN, m);
623 default:
624 return 0;
628 /* Output the symbols defined in block number DO_BLOCK.
630 This function works by walking the tree structure of blocks,
631 counting blocks until it finds the desired block. */
633 static int do_block = 0;
635 static void
636 sdbout_block (block)
637 register tree block;
639 while (block)
641 /* Ignore blocks never expanded or otherwise marked as real. */
642 if (TREE_USED (block))
644 /* When we reach the specified block, output its symbols. */
645 if (BLOCK_NUMBER (block) == do_block)
646 sdbout_syms (BLOCK_VARS (block));
648 /* If we are past the specified block, stop the scan. */
649 if (BLOCK_NUMBER (block) > do_block)
650 return;
652 /* Scan the blocks within this block. */
653 sdbout_block (BLOCK_SUBBLOCKS (block));
656 block = BLOCK_CHAIN (block);
660 /* Call sdbout_symbol on each decl in the chain SYMS. */
662 static void
663 sdbout_syms (syms)
664 tree syms;
666 while (syms)
668 if (TREE_CODE (syms) != LABEL_DECL)
669 sdbout_symbol (syms, 1);
670 syms = TREE_CHAIN (syms);
674 /* Output SDB information for a symbol described by DECL.
675 LOCAL is nonzero if the symbol is not file-scope. */
677 void
678 sdbout_symbol (decl, local)
679 tree decl;
680 int local;
682 tree type = TREE_TYPE (decl);
683 tree context = NULL_TREE;
684 rtx value;
685 int regno = -1;
686 const char *name;
688 sdbout_one_type (type);
690 #if 0 /* This loses when functions are marked to be ignored,
691 which happens in the C++ front end. */
692 if (DECL_IGNORED_P (decl))
693 return;
694 #endif
696 switch (TREE_CODE (decl))
698 case CONST_DECL:
699 /* Enum values are defined by defining the enum type. */
700 return;
702 case FUNCTION_DECL:
703 /* Don't mention a nested function under its parent. */
704 context = decl_function_context (decl);
705 if (context == current_function_decl)
706 return;
707 /* Check DECL_INITIAL to distinguish declarations from definitions.
708 Don't output debug info here for declarations; they will have
709 a DECL_INITIAL value of 0. */
710 if (! DECL_INITIAL (decl))
711 return;
712 if (GET_CODE (DECL_RTL (decl)) != MEM
713 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
714 return;
715 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
716 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
717 PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
718 break;
720 case TYPE_DECL:
721 /* Done with tagged types. */
722 if (DECL_NAME (decl) == 0)
723 return;
724 if (DECL_IGNORED_P (decl))
725 return;
727 /* Output typedef name. */
728 if (template_name_p (DECL_NAME (decl)))
729 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
730 else
731 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
732 PUT_SDB_SCL (C_TPDEF);
733 break;
735 case PARM_DECL:
736 /* Parm decls go in their own separate chains
737 and are output by sdbout_reg_parms and sdbout_parms. */
738 abort ();
740 case VAR_DECL:
741 /* Don't mention a variable that is external.
742 Let the file that defines it describe it. */
743 if (DECL_EXTERNAL (decl))
744 return;
746 /* Ignore __FUNCTION__, etc. */
747 if (DECL_IGNORED_P (decl))
748 return;
750 /* If there was an error in the declaration, don't dump core
751 if there is no RTL associated with the variable doesn't
752 exist. */
753 if (!DECL_RTL_SET_P (decl))
754 return;
756 SET_DECL_RTL (decl,
757 eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
758 #ifdef LEAF_REG_REMAP
759 if (current_function_uses_only_leaf_regs)
760 leaf_renumber_regs_insn (DECL_RTL (decl));
761 #endif
762 value = DECL_RTL (decl);
764 /* Don't mention a variable at all
765 if it was completely optimized into nothingness.
767 If DECL was from an inline function, then its rtl
768 is not identically the rtl that was used in this
769 particular compilation. */
770 if (GET_CODE (value) == REG)
772 regno = REGNO (DECL_RTL (decl));
773 if (regno >= FIRST_PSEUDO_REGISTER)
774 return;
776 else if (GET_CODE (value) == SUBREG)
778 int offset = 0;
779 while (GET_CODE (value) == SUBREG)
781 offset += SUBREG_WORD (value);
782 value = SUBREG_REG (value);
784 if (GET_CODE (value) == REG)
786 regno = REGNO (value);
787 if (regno >= FIRST_PSEUDO_REGISTER)
788 return;
789 regno += offset;
791 alter_subreg (DECL_RTL (decl));
792 value = DECL_RTL (decl);
794 /* Don't output anything if an auto variable
795 gets RTL that is static.
796 GAS version 2.2 can't handle such output. */
797 else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
798 && ! TREE_STATIC (decl))
799 return;
801 /* Emit any structure, union, or enum type that has not been output.
802 This occurs for tag-less structs (et al) used to declare variables
803 within functions. */
804 if (TREE_CODE (type) == ENUMERAL_TYPE
805 || TREE_CODE (type) == RECORD_TYPE
806 || TREE_CODE (type) == UNION_TYPE
807 || TREE_CODE (type) == QUAL_UNION_TYPE)
809 if (COMPLETE_TYPE_P (type) /* not a forward reference */
810 && KNOWN_TYPE_TAG (type) == 0) /* not yet declared */
811 sdbout_one_type (type);
814 /* Defer SDB information for top-level initialized variables! */
815 if (! local
816 && GET_CODE (value) == MEM
817 && DECL_INITIAL (decl))
818 return;
820 /* C++ in 2.3 makes nameless symbols. That will be fixed later.
821 For now, avoid crashing. */
822 if (DECL_NAME (decl) == NULL_TREE)
823 return;
825 /* Record the name for, starting a symtab entry. */
826 if (local)
827 name = IDENTIFIER_POINTER (DECL_NAME (decl));
828 else
829 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
831 if (GET_CODE (value) == MEM
832 && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
834 PUT_SDB_DEF (name);
835 if (TREE_PUBLIC (decl))
837 PUT_SDB_VAL (XEXP (value, 0));
838 PUT_SDB_SCL (C_EXT);
840 else
842 PUT_SDB_VAL (XEXP (value, 0));
843 PUT_SDB_SCL (C_STAT);
846 else if (regno >= 0)
848 PUT_SDB_DEF (name);
849 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
850 PUT_SDB_SCL (C_REG);
852 else if (GET_CODE (value) == MEM
853 && (GET_CODE (XEXP (value, 0)) == MEM
854 || (GET_CODE (XEXP (value, 0)) == REG
855 && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
856 && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
857 /* If the value is indirect by memory or by a register
858 that isn't the frame pointer
859 then it means the object is variable-sized and address through
860 that register or stack slot. COFF has no way to represent this
861 so all we can do is output the variable as a pointer. */
863 PUT_SDB_DEF (name);
864 if (GET_CODE (XEXP (value, 0)) == REG)
866 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
867 PUT_SDB_SCL (C_REG);
869 else
871 /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
872 (CONST_INT...)))).
873 We want the value of that CONST_INT. */
874 /* Encore compiler hates a newline in a macro arg, it seems. */
875 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
876 (XEXP (XEXP (value, 0), 0)));
877 PUT_SDB_SCL (C_AUTO);
880 /* Effectively do build_pointer_type, but don't cache this type,
881 since it might be temporary whereas the type it points to
882 might have been saved for inlining. */
883 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
884 type = make_node (POINTER_TYPE);
885 TREE_TYPE (type) = TREE_TYPE (decl);
887 else if (GET_CODE (value) == MEM
888 && ((GET_CODE (XEXP (value, 0)) == PLUS
889 && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
890 && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
891 /* This is for variables which are at offset zero from
892 the frame pointer. This happens on the Alpha.
893 Non-frame pointer registers are excluded above. */
894 || (GET_CODE (XEXP (value, 0)) == REG)))
896 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
897 or (MEM (REG...)). We want the value of that CONST_INT
898 or zero. */
899 PUT_SDB_DEF (name);
900 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
901 PUT_SDB_SCL (C_AUTO);
903 else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
905 /* Handle an obscure case which can arise when optimizing and
906 when there are few available registers. (This is *always*
907 the case for i386/i486 targets). The DECL_RTL looks like
908 (MEM (CONST ...)) even though this variable is a local `auto'
909 or a local `register' variable. In effect, what has happened
910 is that the reload pass has seen that all assignments and
911 references for one such a local variable can be replaced by
912 equivalent assignments and references to some static storage
913 variable, thereby avoiding the need for a register. In such
914 cases we're forced to lie to debuggers and tell them that
915 this variable was itself `static'. */
916 PUT_SDB_DEF (name);
917 PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
918 PUT_SDB_SCL (C_STAT);
920 else
922 /* It is something we don't know how to represent for SDB. */
923 return;
925 break;
927 default:
928 break;
930 PUT_SDB_TYPE (plain_type (type));
931 PUT_SDB_ENDEF;
934 /* Output SDB information for a top-level initialized variable
935 that has been delayed. */
937 void
938 sdbout_toplevel_data (decl)
939 tree decl;
941 tree type = TREE_TYPE (decl);
943 if (DECL_IGNORED_P (decl))
944 return;
946 if (! (TREE_CODE (decl) == VAR_DECL
947 && GET_CODE (DECL_RTL (decl)) == MEM
948 && DECL_INITIAL (decl)))
949 abort ();
951 PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
952 PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
953 if (TREE_PUBLIC (decl))
955 PUT_SDB_SCL (C_EXT);
957 else
959 PUT_SDB_SCL (C_STAT);
961 PUT_SDB_TYPE (plain_type (type));
962 PUT_SDB_ENDEF;
965 #ifdef SDB_ALLOW_FORWARD_REFERENCES
967 /* Machinery to record and output anonymous types. */
969 static tree anonymous_types;
971 static void
972 sdbout_queue_anonymous_type (type)
973 tree type;
975 anonymous_types = tree_cons (NULL_TREE, type, anonymous_types);
978 static void
979 sdbout_dequeue_anonymous_types ()
981 register tree types, link;
983 while (anonymous_types)
985 types = nreverse (anonymous_types);
986 anonymous_types = NULL_TREE;
988 for (link = types; link; link = TREE_CHAIN (link))
990 register tree type = TREE_VALUE (link);
992 if (type && ! TREE_ASM_WRITTEN (type))
993 sdbout_one_type (type);
998 #endif
1000 /* Given a chain of ..._TYPE nodes, all of which have names,
1001 output definitions of those names, as typedefs. */
1003 void
1004 sdbout_types (types)
1005 register tree types;
1007 register tree link;
1009 for (link = types; link; link = TREE_CHAIN (link))
1010 sdbout_one_type (link);
1012 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1013 sdbout_dequeue_anonymous_types ();
1014 #endif
1017 static void
1018 sdbout_type (type)
1019 tree type;
1021 if (type == error_mark_node)
1022 type = integer_type_node;
1023 PUT_SDB_TYPE (plain_type (type));
1026 /* Output types of the fields of type TYPE, if they are structs.
1028 Formerly did not chase through pointer types, since that could be circular.
1029 They must come before TYPE, since forward refs are not allowed.
1030 Now james@bigtex.cactus.org says to try them. */
1032 static void
1033 sdbout_field_types (type)
1034 tree type;
1036 tree tail;
1038 for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
1039 /* This condition should match the one for emitting the actual
1040 members below. */
1041 if (TREE_CODE (tail) == FIELD_DECL
1042 && DECL_NAME (tail)
1043 && DECL_SIZE (tail)
1044 && host_integerp (DECL_SIZE (tail), 1)
1045 && host_integerp (bit_position (tail), 0))
1047 if (POINTER_TYPE_P (TREE_TYPE (tail)))
1048 sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
1049 else
1050 sdbout_one_type (TREE_TYPE (tail));
1054 /* Use this to put out the top level defined record and union types
1055 for later reference. If this is a struct with a name, then put that
1056 name out. Other unnamed structs will have .xxfake labels generated so
1057 that they may be referred to later.
1058 The label will be stored in the KNOWN_TYPE_TAG slot of a type.
1059 It may NOT be called recursively. */
1061 static void
1062 sdbout_one_type (type)
1063 tree type;
1065 if (current_function_decl != NULL_TREE
1066 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
1067 ; /* Don't change section amid function. */
1068 else
1069 text_section ();
1071 switch (TREE_CODE (type))
1073 case RECORD_TYPE:
1074 case UNION_TYPE:
1075 case QUAL_UNION_TYPE:
1076 case ENUMERAL_TYPE:
1077 type = TYPE_MAIN_VARIANT (type);
1078 /* Don't output a type twice. */
1079 if (TREE_ASM_WRITTEN (type))
1080 /* James said test TREE_ASM_BEING_WRITTEN here. */
1081 return;
1083 /* Output nothing if type is not yet defined. */
1084 if (!COMPLETE_TYPE_P (type))
1085 return;
1087 TREE_ASM_WRITTEN (type) = 1;
1088 #if 1
1089 /* This is reputed to cause trouble with the following case,
1090 but perhaps checking TYPE_SIZE above will fix it. */
1092 /* Here is a test case:
1094 struct foo {
1095 struct badstr *bbb;
1096 } forwardref;
1098 typedef struct intermediate {
1099 int aaaa;
1100 } intermediate_ref;
1102 typedef struct badstr {
1103 int ccccc;
1104 } badtype; */
1106 #if 0
1107 TREE_ASM_BEING_WRITTEN (type) = 1;
1108 #endif
1109 /* This change, which ought to make better output,
1110 used to make the COFF assembler unhappy.
1111 Changes involving KNOWN_TYPE_TAG may fix the problem. */
1112 /* Before really doing anything, output types we want to refer to. */
1113 /* Note that in version 1 the following two lines
1114 are not used if forward references are in use. */
1115 if (TREE_CODE (type) != ENUMERAL_TYPE)
1116 sdbout_field_types (type);
1117 #if 0
1118 TREE_ASM_WRITTEN (type) = 1;
1119 #endif
1120 #endif
1122 /* Output a structure type. */
1124 int size = int_size_in_bytes (type);
1125 int member_scl = 0;
1126 tree tem;
1127 int i, n_baseclasses = 0;
1129 /* Record the type tag, but not in its permanent place just yet. */
1130 sdbout_record_type_name (type);
1132 PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1134 switch (TREE_CODE (type))
1136 case UNION_TYPE:
1137 case QUAL_UNION_TYPE:
1138 PUT_SDB_SCL (C_UNTAG);
1139 PUT_SDB_TYPE (T_UNION);
1140 member_scl = C_MOU;
1141 break;
1143 case RECORD_TYPE:
1144 PUT_SDB_SCL (C_STRTAG);
1145 PUT_SDB_TYPE (T_STRUCT);
1146 member_scl = C_MOS;
1147 break;
1149 case ENUMERAL_TYPE:
1150 PUT_SDB_SCL (C_ENTAG);
1151 PUT_SDB_TYPE (T_ENUM);
1152 member_scl = C_MOE;
1153 break;
1155 default:
1156 break;
1159 PUT_SDB_SIZE (size);
1160 PUT_SDB_ENDEF;
1162 /* Print out the base class information with fields
1163 named after the types they hold. */
1164 /* This is only relevent to aggregate types. TYPE_BINFO is used
1165 for other purposes in an ENUMERAL_TYPE, so we must exclude that
1166 case. */
1167 if (TREE_CODE (type) != ENUMERAL_TYPE)
1169 if (TYPE_BINFO (type)
1170 && TYPE_BINFO_BASETYPES (type))
1171 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1172 for (i = 0; i < n_baseclasses; i++)
1174 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)),
1176 tree child_type = BINFO_TYPE (child);
1177 tree child_type_name;
1178 if (TYPE_NAME (child_type) == 0)
1179 continue;
1180 if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1181 child_type_name = TYPE_NAME (child_type);
1182 else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1184 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1185 if (child_type_name && template_name_p (child_type_name))
1186 child_type_name
1187 = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1189 else
1190 continue;
1192 CONTIN;
1193 PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1194 PUT_SDB_INT_VAL (tree_low_cst (BINFO_OFFSET (child), 0));
1195 PUT_SDB_SCL (member_scl);
1196 sdbout_type (BINFO_TYPE (child));
1197 PUT_SDB_ENDEF;
1201 /* output the individual fields */
1203 if (TREE_CODE (type) == ENUMERAL_TYPE)
1205 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1206 if (host_integerp (TREE_VALUE (tem), 0))
1208 PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1209 PUT_SDB_INT_VAL (tree_low_cst (TREE_VALUE (tem), 0));
1210 PUT_SDB_SCL (C_MOE);
1211 PUT_SDB_TYPE (T_MOE);
1212 PUT_SDB_ENDEF;
1215 else /* record or union type */
1216 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1217 /* Output the name, type, position (in bits), size (in bits)
1218 of each field. */
1220 /* Omit here the nameless fields that are used to skip bits.
1221 Also omit fields with variable size or position.
1222 Also omit non FIELD_DECL nodes that GNU C++ may put here. */
1223 if (TREE_CODE (tem) == FIELD_DECL
1224 && DECL_NAME (tem)
1225 && DECL_SIZE (tem)
1226 && host_integerp (DECL_SIZE (tem), 1)
1227 && host_integerp (bit_position (tem), 0))
1229 const char *name;
1231 CONTIN;
1232 name = IDENTIFIER_POINTER (DECL_NAME (tem));
1233 PUT_SDB_DEF (name);
1234 if (DECL_BIT_FIELD_TYPE (tem))
1236 PUT_SDB_INT_VAL (int_bit_position (tem));
1237 PUT_SDB_SCL (C_FIELD);
1238 sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1239 PUT_SDB_SIZE (tree_low_cst (DECL_SIZE (tem), 1));
1241 else
1243 PUT_SDB_INT_VAL (int_bit_position (tem) / BITS_PER_UNIT);
1244 PUT_SDB_SCL (member_scl);
1245 sdbout_type (TREE_TYPE (tem));
1247 PUT_SDB_ENDEF;
1249 /* output end of a structure,union, or enumeral definition */
1251 PUT_SDB_PLAIN_DEF ("eos");
1252 PUT_SDB_INT_VAL (size);
1253 PUT_SDB_SCL (C_EOS);
1254 PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1255 PUT_SDB_SIZE (size);
1256 PUT_SDB_ENDEF;
1257 break;
1259 default:
1260 break;
1265 /* The following two functions output definitions of function parameters.
1266 Each parameter gets a definition locating it in the parameter list.
1267 Each parameter that is a register variable gets a second definition
1268 locating it in the register.
1270 Printing or argument lists in gdb uses the definitions that
1271 locate in the parameter list. But reference to the variable in
1272 expressions uses preferentially the definition as a register. */
1274 /* Output definitions, referring to storage in the parmlist,
1275 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
1277 static void
1278 sdbout_parms (parms)
1279 tree parms;
1281 for (; parms; parms = TREE_CHAIN (parms))
1282 if (DECL_NAME (parms))
1284 int current_sym_value = 0;
1285 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1287 if (name == 0 || *name == 0)
1288 name = gen_fake_label ();
1290 /* Perform any necessary register eliminations on the parameter's rtl,
1291 so that the debugging output will be accurate. */
1292 DECL_INCOMING_RTL (parms)
1293 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1294 SET_DECL_RTL (parms,
1295 eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
1297 if (PARM_PASSED_IN_MEMORY (parms))
1299 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1300 tree type;
1302 /* ??? Here we assume that the parm address is indexed
1303 off the frame pointer or arg pointer.
1304 If that is not true, we produce meaningless results,
1305 but do not crash. */
1306 if (GET_CODE (addr) == PLUS
1307 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1308 current_sym_value = INTVAL (XEXP (addr, 1));
1309 else
1310 current_sym_value = 0;
1312 if (GET_CODE (DECL_RTL (parms)) == REG
1313 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1314 type = DECL_ARG_TYPE (parms);
1315 else
1317 int original_sym_value = current_sym_value;
1319 /* This is the case where the parm is passed as an int or
1320 double and it is converted to a char, short or float
1321 and stored back in the parmlist. In this case, describe
1322 the parm with the variable's declared type, and adjust
1323 the address if the least significant bytes (which we are
1324 using) are not the first ones. */
1325 if (BYTES_BIG_ENDIAN
1326 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1327 current_sym_value +=
1328 (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1329 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1331 if (GET_CODE (DECL_RTL (parms)) == MEM
1332 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1333 && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1334 == CONST_INT)
1335 && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1336 == current_sym_value))
1337 type = TREE_TYPE (parms);
1338 else
1340 current_sym_value = original_sym_value;
1341 type = DECL_ARG_TYPE (parms);
1345 PUT_SDB_DEF (name);
1346 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1347 PUT_SDB_SCL (C_ARG);
1348 PUT_SDB_TYPE (plain_type (type));
1349 PUT_SDB_ENDEF;
1351 else if (GET_CODE (DECL_RTL (parms)) == REG)
1353 rtx best_rtl;
1354 /* Parm passed in registers and lives in registers or nowhere. */
1356 /* If parm lives in a register, use that register;
1357 pretend the parm was passed there. It would be more consistent
1358 to describe the register where the parm was passed,
1359 but in practice that register usually holds something else. */
1360 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1361 best_rtl = DECL_RTL (parms);
1362 /* If the parm lives nowhere,
1363 use the register where it was passed. */
1364 else
1365 best_rtl = DECL_INCOMING_RTL (parms);
1367 PUT_SDB_DEF (name);
1368 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1369 PUT_SDB_SCL (C_REGPARM);
1370 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1371 PUT_SDB_ENDEF;
1373 else if (GET_CODE (DECL_RTL (parms)) == MEM
1374 && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1376 /* Parm was passed in registers but lives on the stack. */
1378 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1379 in which case we want the value of that CONST_INT,
1380 or (MEM (REG ...)) or (MEM (MEM ...)),
1381 in which case we use a value of zero. */
1382 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1383 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1384 current_sym_value = 0;
1385 else
1386 current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1388 /* Again, this assumes the offset is based on the arg pointer. */
1389 PUT_SDB_DEF (name);
1390 PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1391 XEXP (DECL_RTL (parms), 0)));
1392 PUT_SDB_SCL (C_ARG);
1393 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1394 PUT_SDB_ENDEF;
1399 /* Output definitions for the places where parms live during the function,
1400 when different from where they were passed, when the parms were passed
1401 in memory.
1403 It is not useful to do this for parms passed in registers
1404 that live during the function in different registers, because it is
1405 impossible to look in the passed register for the passed value,
1406 so we use the within-the-function register to begin with.
1408 PARMS is a chain of PARM_DECL nodes. */
1410 static void
1411 sdbout_reg_parms (parms)
1412 tree parms;
1414 for (; parms; parms = TREE_CHAIN (parms))
1415 if (DECL_NAME (parms))
1417 const char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1419 /* Report parms that live in registers during the function
1420 but were passed in memory. */
1421 if (GET_CODE (DECL_RTL (parms)) == REG
1422 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1423 && PARM_PASSED_IN_MEMORY (parms))
1425 if (name == 0 || *name == 0)
1426 name = gen_fake_label ();
1427 PUT_SDB_DEF (name);
1428 PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1429 PUT_SDB_SCL (C_REG);
1430 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1431 PUT_SDB_ENDEF;
1433 /* Report parms that live in memory but not where they were passed. */
1434 else if (GET_CODE (DECL_RTL (parms)) == MEM
1435 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1436 && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1437 && PARM_PASSED_IN_MEMORY (parms)
1438 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1440 #if 0 /* ??? It is not clear yet what should replace this. */
1441 int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1442 /* A parm declared char is really passed as an int,
1443 so it occupies the least significant bytes.
1444 On a big-endian machine those are not the low-numbered ones. */
1445 if (BYTES_BIG_ENDIAN
1446 && offset != -1
1447 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1448 offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1449 - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1450 if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1451 #endif
1453 if (name == 0 || *name == 0)
1454 name = gen_fake_label ();
1455 PUT_SDB_DEF (name);
1456 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1457 (XEXP (DECL_RTL (parms), 0)));
1458 PUT_SDB_SCL (C_AUTO);
1459 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1460 PUT_SDB_ENDEF;
1466 /* Describe the beginning of an internal block within a function.
1467 Also output descriptions of variables defined in this block.
1469 N is the number of the block, by order of beginning, counting from 1,
1470 and not counting the outermost (function top-level) block.
1471 The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1472 if the count starts at 0 for the outermost one. */
1474 void
1475 sdbout_begin_block (file, line, n)
1476 FILE *file ATTRIBUTE_UNUSED;
1477 int line;
1478 int n;
1480 tree decl = current_function_decl;
1481 MAKE_LINE_SAFE (line);
1483 /* The SCO compiler does not emit a separate block for the function level
1484 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1485 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1486 #ifndef MIPS_DEBUGGING_INFO
1487 if (n != 1)
1488 #endif
1489 PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1491 if (n == 1)
1493 /* Include the outermost BLOCK's variables in block 1. */
1494 do_block = BLOCK_NUMBER (DECL_INITIAL (decl));
1495 sdbout_block (DECL_INITIAL (decl));
1497 /* If -g1, suppress all the internal symbols of functions
1498 except for arguments. */
1499 if (debug_info_level != DINFO_LEVEL_TERSE)
1501 do_block = n;
1502 sdbout_block (DECL_INITIAL (decl));
1505 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1506 sdbout_dequeue_anonymous_types ();
1507 #endif
1510 /* Describe the end line-number of an internal block within a function. */
1512 void
1513 sdbout_end_block (file, line, n)
1514 FILE *file ATTRIBUTE_UNUSED;
1515 int line;
1516 int n ATTRIBUTE_UNUSED;
1518 MAKE_LINE_SAFE (line);
1520 /* The SCO compiler does not emit a separate block for the function level
1521 scope, so we avoid it here also. However, mips ECOFF compilers do emit
1522 a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined. */
1523 #ifndef MIPS_DEBUGGING_INFO
1524 if (n != 1)
1525 #endif
1526 PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1529 /* Output sdb info for the current function name.
1530 Called from assemble_start_function. */
1532 void
1533 sdbout_mark_begin_function ()
1535 sdbout_symbol (current_function_decl, 0);
1538 /* Called at beginning of function body (after prologue).
1539 Record the function's starting line number, so we can output
1540 relative line numbers for the other lines.
1541 Describe beginning of outermost block.
1542 Also describe the parameter list. */
1544 void
1545 sdbout_begin_function (line)
1546 int line;
1548 sdb_begin_function_line = line - 1;
1549 PUT_SDB_FUNCTION_START (line);
1550 sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1551 sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1554 /* Called at end of function (before epilogue).
1555 Describe end of outermost block. */
1557 void
1558 sdbout_end_function (line)
1559 int line;
1561 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1562 sdbout_dequeue_anonymous_types ();
1563 #endif
1565 MAKE_LINE_SAFE (line);
1566 PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1568 /* Indicate we are between functions, for line-number output. */
1569 sdb_begin_function_line = -1;
1572 /* Output sdb info for the absolute end of a function.
1573 Called after the epilogue is output. */
1575 void
1576 sdbout_end_epilogue ()
1578 PUT_SDB_EPILOGUE_END
1579 (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
1582 /* Output sdb info for the given label. Called only if LABEL_NAME (insn)
1583 is present. */
1585 void
1586 sdbout_label (insn)
1587 register rtx insn;
1589 PUT_SDB_DEF (LABEL_NAME (insn));
1590 PUT_SDB_VAL (insn);
1591 PUT_SDB_SCL (C_LABEL);
1592 PUT_SDB_TYPE (T_NULL);
1593 PUT_SDB_ENDEF;
1596 /* Change to reading from a new source file. */
1598 void
1599 sdbout_start_new_source_file (filename)
1600 const char *filename ATTRIBUTE_UNUSED;
1602 #ifdef MIPS_DEBUGGING_INFO
1603 struct sdb_file *n = (struct sdb_file *) xmalloc (sizeof *n);
1605 n->next = current_file;
1606 n->name = filename;
1607 current_file = n;
1608 PUT_SDB_SRC_FILE (filename);
1609 #endif
1612 /* Revert to reading a previous source file. */
1614 void
1615 sdbout_resume_previous_source_file ()
1617 #ifdef MIPS_DEBUGGING_INFO
1618 struct sdb_file *next;
1620 next = current_file->next;
1621 free (current_file);
1622 current_file = next;
1623 PUT_SDB_SRC_FILE (current_file->name);
1624 #endif
1627 /* Set up for SDB output at the start of compilation. */
1629 void
1630 sdbout_init (asm_file, input_file_name, syms)
1631 FILE *asm_file ATTRIBUTE_UNUSED;
1632 const char *input_file_name ATTRIBUTE_UNUSED;
1633 tree syms ATTRIBUTE_UNUSED;
1635 #ifdef MIPS_DEBUGGING_INFO
1636 current_file = (struct sdb_file *) xmalloc (sizeof *current_file);
1637 current_file->next = NULL;
1638 current_file->name = input_file_name;
1639 #endif
1641 #ifdef RMS_QUICK_HACK_1
1642 tree t;
1643 for (t = syms; t; t = TREE_CHAIN (t))
1644 if (DECL_NAME (t) && IDENTIFIER_POINTER (DECL_NAME (t)) != 0
1645 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (t)), "__vtbl_ptr_type"))
1646 sdbout_symbol (t, 0);
1647 #endif
1649 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1650 ggc_add_tree_root (&anonymous_types, 1);
1651 #endif
1654 #endif /* SDB_DEBUGGING_INFO */