OSDN Git Service

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