OSDN Git Service

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