OSDN Git Service

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