OSDN Git Service

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