OSDN Git Service

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