OSDN Git Service

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