OSDN Git Service

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