OSDN Git Service

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