OSDN Git Service

Adjust for deletion of config.run in Makefile.in
[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(WINNT) && !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);
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 static int
453 plain_type_1 (type)
454      tree type;
455 {
456   if (type == 0)
457     type = void_type_node;
458   if (type == error_mark_node)
459     type = integer_type_node;
460   type = TYPE_MAIN_VARIANT (type);
461
462   switch (TREE_CODE (type))
463     {
464     case VOID_TYPE:
465       return T_VOID;
466     case INTEGER_TYPE:
467       {
468         int size = int_size_in_bytes (type) * BITS_PER_UNIT;
469
470         /* Carefully distinguish all the standard types of C,
471            without messing up if the language is not C.
472            Note that we check only for the names that contain spaces;
473            other names might occur by coincidence in other languages.  */
474         if (TYPE_NAME (type) != 0
475             && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
476             && DECL_NAME (TYPE_NAME (type)) != 0
477             && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE)
478           {
479             char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type)));
480
481             if (!strcmp (name, "unsigned char"))
482               return T_UCHAR;
483             if (!strcmp (name, "signed char"))
484               return T_CHAR;
485             if (!strcmp (name, "unsigned int"))
486               return T_UINT;
487             if (!strcmp (name, "short int"))
488               return T_SHORT;
489             if (!strcmp (name, "short unsigned int"))
490               return T_USHORT;
491             if (!strcmp (name, "long int"))
492               return T_LONG;
493             if (!strcmp (name, "long unsigned int"))
494               return T_ULONG;
495           }
496
497         if (size == CHAR_TYPE_SIZE)
498           return (TREE_UNSIGNED (type) ? T_UCHAR : T_CHAR);
499         if (size == SHORT_TYPE_SIZE)
500           return (TREE_UNSIGNED (type) ? T_USHORT : T_SHORT);
501         if (size == INT_TYPE_SIZE)
502           return (TREE_UNSIGNED (type) ? T_UINT : T_INT);
503         if (size == LONG_TYPE_SIZE)
504           return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
505         if (size == LONG_LONG_TYPE_SIZE)        /* better than nothing */
506           return (TREE_UNSIGNED (type) ? T_ULONG : T_LONG);
507         return 0;
508       }
509
510     case REAL_TYPE:
511       {
512         int size = int_size_in_bytes (type) * BITS_PER_UNIT;
513         if (size == FLOAT_TYPE_SIZE)
514           return T_FLOAT;
515         if (size == DOUBLE_TYPE_SIZE)
516           return T_DOUBLE;
517         return 0;
518       }
519
520     case ARRAY_TYPE:
521       {
522         int m;
523         m = plain_type_1 (TREE_TYPE (type));
524         if (sdb_n_dims < SDB_MAX_DIM)
525           sdb_dims[sdb_n_dims++]
526             = (TYPE_DOMAIN (type)
527                ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type))) + 1
528                : 0);
529         return PUSH_DERIVED_LEVEL (DT_ARY, m);
530       }
531
532     case RECORD_TYPE:
533     case UNION_TYPE:
534     case QUAL_UNION_TYPE:
535     case ENUMERAL_TYPE:
536       {
537         char *tag;
538 #ifdef SDB_ALLOW_FORWARD_REFERENCES
539         sdbout_record_type_name (type);
540 #endif
541 #ifndef SDB_ALLOW_UNKNOWN_REFERENCES
542         if ((TREE_ASM_WRITTEN (type) && KNOWN_TYPE_TAG (type) != 0)
543 #ifdef SDB_ALLOW_FORWARD_REFERENCES
544             || TYPE_MODE (type) != VOIDmode
545 #endif
546             )
547 #endif
548           {
549             /* Output the referenced structure tag name
550                only if the .def has already been finished.
551                At least on 386, the Unix assembler
552                cannot handle forward references to tags.  */
553             /* But the 88100, it requires them, sigh... */
554             /* And the MIPS requires unknown refs as well... */
555             tag = KNOWN_TYPE_TAG (type);
556             PUT_SDB_TAG (tag);
557             /* These 3 lines used to follow the close brace.
558                However, a size of 0 without a tag implies a tag of 0,
559                so if we don't know a tag, we can't mention the size.  */
560             sdb_type_size = int_size_in_bytes (type);
561             if (sdb_type_size < 0)
562               sdb_type_size = 0;
563           }
564         return ((TREE_CODE (type) == RECORD_TYPE) ? T_STRUCT
565                 : (TREE_CODE (type) == UNION_TYPE) ? T_UNION
566                 : (TREE_CODE (type) == QUAL_UNION_TYPE) ? T_UNION
567                 : T_ENUM);
568       }
569     case POINTER_TYPE:
570     case REFERENCE_TYPE:
571       {
572         int m = plain_type_1 (TREE_TYPE (type));
573         return PUSH_DERIVED_LEVEL (DT_PTR, m);
574       }
575     case FUNCTION_TYPE:
576     case METHOD_TYPE:
577       {
578         int m = plain_type_1 (TREE_TYPE (type));
579         return PUSH_DERIVED_LEVEL (DT_FCN, m);
580       }
581     default:
582       return 0;
583     }
584 }
585 \f
586 /* Output the symbols defined in block number DO_BLOCK.
587    Set NEXT_BLOCK_NUMBER to 0 before calling.
588
589    This function works by walking the tree structure of blocks,
590    counting blocks until it finds the desired block.  */
591
592 static int do_block = 0;
593
594 static int next_block_number;
595
596 static void
597 sdbout_block (block)
598      register tree block;
599 {
600   while (block)
601     {
602       /* Ignore blocks never expanded or otherwise marked as real.  */
603       if (TREE_USED (block))
604         {
605           /* When we reach the specified block, output its symbols.  */
606           if (next_block_number == do_block)
607             {
608               sdbout_syms (BLOCK_VARS (block));
609             }
610
611           /* If we are past the specified block, stop the scan.  */
612           if (next_block_number > do_block)
613             return;
614
615           next_block_number++;
616
617           /* Scan the blocks within this block.  */
618           sdbout_block (BLOCK_SUBBLOCKS (block));
619         }
620
621       block = BLOCK_CHAIN (block);
622     }
623 }
624 \f
625 /* Call sdbout_symbol on each decl in the chain SYMS.  */
626
627 static void
628 sdbout_syms (syms)
629      tree syms;
630 {
631   while (syms)
632     {
633       if (TREE_CODE (syms) != LABEL_DECL)
634         sdbout_symbol (syms, 1);
635       syms = TREE_CHAIN (syms);
636     }
637 }
638
639 /* Output SDB information for a symbol described by DECL.
640    LOCAL is nonzero if the symbol is not file-scope.  */
641
642 void
643 sdbout_symbol (decl, local)
644      tree decl;
645      int local;
646 {
647   tree type = TREE_TYPE (decl);
648   tree context = NULL_TREE;
649   rtx value;
650   int regno = -1;
651   char *name;
652
653   sdbout_one_type (type);
654
655 #if 0 /* This loses when functions are marked to be ignored,
656          which happens in the C++ front end.  */
657   if (DECL_IGNORED_P (decl))
658     return;
659 #endif
660
661   switch (TREE_CODE (decl))
662     {
663     case CONST_DECL:
664       /* Enum values are defined by defining the enum type.  */
665       return;
666
667     case FUNCTION_DECL:
668       /* Don't mention a nested function under its parent.  */
669       context = decl_function_context (decl);
670       if (context == current_function_decl)
671         return;
672       if (DECL_EXTERNAL (decl))
673         return;
674       if (GET_CODE (DECL_RTL (decl)) != MEM
675           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
676         return;
677       PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
678       PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
679       PUT_SDB_SCL (TREE_PUBLIC (decl) ? C_EXT : C_STAT);
680       break;
681
682     case TYPE_DECL:
683       /* Done with tagged types.  */
684       if (DECL_NAME (decl) == 0)
685         return;
686       if (DECL_IGNORED_P (decl))
687         return;
688
689       /* Output typedef name.  */
690       if (template_name_p (DECL_NAME (decl)))
691         PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
692       else
693         PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_NAME (decl)));
694       PUT_SDB_SCL (C_TPDEF);
695       break;
696
697     case PARM_DECL:
698       /* Parm decls go in their own separate chains
699          and are output by sdbout_reg_parms and sdbout_parms.  */
700       abort ();
701
702     case VAR_DECL:
703       /* Don't mention a variable that is external.
704          Let the file that defines it describe it.  */
705       if (DECL_EXTERNAL (decl))
706         return;
707
708       /* Ignore __FUNCTION__, etc.  */
709       if (DECL_IGNORED_P (decl))
710         return;
711
712       /* If there was an error in the declaration, don't dump core
713          if there is no RTL associated with the variable doesn't
714          exist.  */
715       if (DECL_RTL (decl) == 0)
716         return;
717
718       DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, NULL_RTX);
719 #ifdef LEAF_REG_REMAP
720       if (leaf_function)
721         leaf_renumber_regs_insn (DECL_RTL (decl));
722 #endif
723       value = DECL_RTL (decl);
724
725       /* Don't mention a variable at all
726          if it was completely optimized into nothingness.
727
728          If DECL was from an inline function, then its rtl
729          is not identically the rtl that was used in this
730          particular compilation.  */
731       if (GET_CODE (value) == REG)
732         {
733           regno = REGNO (DECL_RTL (decl));
734           if (regno >= FIRST_PSEUDO_REGISTER)
735             return;
736         }
737       else if (GET_CODE (value) == SUBREG)
738         {
739           int offset = 0;
740           while (GET_CODE (value) == SUBREG)
741             {
742               offset += SUBREG_WORD (value);
743               value = SUBREG_REG (value);
744             }
745           if (GET_CODE (value) == REG)
746             {
747               regno = REGNO (value);
748               if (regno >= FIRST_PSEUDO_REGISTER)
749                 return;
750               regno += offset;
751             }
752           alter_subreg (DECL_RTL (decl));
753           value = DECL_RTL (decl);
754         }
755       /* Don't output anything if an auto variable
756          gets RTL that is static.
757          GAS version 2.2 can't handle such output.  */
758       else if (GET_CODE (value) == MEM && CONSTANT_P (XEXP (value, 0))
759                && ! TREE_STATIC (decl))
760         return;
761
762       /* Emit any structure, union, or enum type that has not been output.
763          This occurs for tag-less structs (et al) used to declare variables
764          within functions.  */
765       if (TREE_CODE (type) == ENUMERAL_TYPE
766           || TREE_CODE (type) == RECORD_TYPE
767           || TREE_CODE (type) == UNION_TYPE
768           || TREE_CODE (type) == QUAL_UNION_TYPE)
769         {
770           if (TYPE_SIZE (type) != 0             /* not a forward reference */
771               && KNOWN_TYPE_TAG (type) == 0)    /* not yet declared */
772             sdbout_one_type (type);
773         }
774
775       /* Defer SDB information for top-level initialized variables! */
776       if (! local
777           && GET_CODE (value) == MEM
778           && DECL_INITIAL (decl))
779         return;
780
781       /* C++ in 2.3 makes nameless symbols.  That will be fixed later.
782          For now, avoid crashing.  */
783       if (DECL_NAME (decl) == NULL_TREE)
784         return;
785
786       /* Record the name for, starting a symtab entry.  */
787       name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
788
789       if (GET_CODE (value) == MEM
790           && GET_CODE (XEXP (value, 0)) == SYMBOL_REF)
791         {
792           PUT_SDB_DEF (name);
793           if (TREE_PUBLIC (decl))
794             {
795               PUT_SDB_VAL (XEXP (value, 0));
796               PUT_SDB_SCL (C_EXT);
797             }
798           else
799             {
800               PUT_SDB_VAL (XEXP (value, 0));
801               PUT_SDB_SCL (C_STAT);
802             }
803         }
804       else if (regno >= 0)
805         {
806           PUT_SDB_DEF (name);
807           PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (regno));
808           PUT_SDB_SCL (C_REG);
809         }
810       else if (GET_CODE (value) == MEM
811                && (GET_CODE (XEXP (value, 0)) == MEM
812                    || (GET_CODE (XEXP (value, 0)) == REG
813                        && REGNO (XEXP (value, 0)) != HARD_FRAME_POINTER_REGNUM
814                        && REGNO (XEXP (value, 0)) != STACK_POINTER_REGNUM)))
815         /* If the value is indirect by memory or by a register
816            that isn't the frame pointer
817            then it means the object is variable-sized and address through
818            that register or stack slot.  COFF has no way to represent this
819            so all we can do is output the variable as a pointer.  */
820         {
821           PUT_SDB_DEF (name);
822           if (GET_CODE (XEXP (value, 0)) == REG)
823             {
824               PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (XEXP (value, 0))));
825               PUT_SDB_SCL (C_REG);
826             }
827           else
828             {
829               /* DECL_RTL looks like (MEM (MEM (PLUS (REG...)
830                  (CONST_INT...)))).
831                  We want the value of that CONST_INT.  */
832               /* Encore compiler hates a newline in a macro arg, it seems.  */
833               PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
834                                (XEXP (XEXP (value, 0), 0)));
835               PUT_SDB_SCL (C_AUTO);
836             }
837
838           type = build_pointer_type (TREE_TYPE (decl));
839         }
840       else if (GET_CODE (value) == MEM
841                && ((GET_CODE (XEXP (value, 0)) == PLUS
842                     && GET_CODE (XEXP (XEXP (value, 0), 0)) == REG
843                     && GET_CODE (XEXP (XEXP (value, 0), 1)) == CONST_INT)
844                    /* This is for variables which are at offset zero from
845                       the frame pointer.  This happens on the Alpha.
846                       Non-frame pointer registers are excluded above.  */
847                    || (GET_CODE (XEXP (value, 0)) == REG)))
848         {
849           /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
850              or (MEM (REG...)).  We want the value of that CONST_INT
851              or zero.  */
852           PUT_SDB_DEF (name);
853           PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET (XEXP (value, 0)));
854           PUT_SDB_SCL (C_AUTO);
855         }
856       else if (GET_CODE (value) == MEM && GET_CODE (XEXP (value, 0)) == CONST)
857         {
858           /* Handle an obscure case which can arise when optimizing and
859              when there are few available registers.  (This is *always*
860              the case for i386/i486 targets).  The DECL_RTL looks like
861              (MEM (CONST ...)) even though this variable is a local `auto'
862              or a local `register' variable.  In effect, what has happened
863              is that the reload pass has seen that all assignments and
864              references for one such a local variable can be replaced by
865              equivalent assignments and references to some static storage
866              variable, thereby avoiding the need for a register.  In such
867              cases we're forced to lie to debuggers and tell them that
868              this variable was itself `static'.  */
869           PUT_SDB_DEF (name);
870           PUT_SDB_VAL (XEXP (XEXP (value, 0), 0));
871           PUT_SDB_SCL (C_STAT);
872         }
873       else
874         {
875           /* It is something we don't know how to represent for SDB.  */
876           return;
877         }
878       break;
879     }
880   PUT_SDB_TYPE (plain_type (type));
881   PUT_SDB_ENDEF;
882 }
883 \f
884 /* Output SDB information for a top-level initialized variable
885    that has been delayed.  */
886
887 void
888 sdbout_toplevel_data (decl)
889      tree decl;
890 {
891   tree type = TREE_TYPE (decl);
892
893   if (DECL_IGNORED_P (decl))
894     return;
895
896   if (! (TREE_CODE (decl) == VAR_DECL
897          && GET_CODE (DECL_RTL (decl)) == MEM
898          && DECL_INITIAL (decl)))
899     abort ();
900
901   PUT_SDB_DEF (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)));
902   PUT_SDB_VAL (XEXP (DECL_RTL (decl), 0));
903   if (TREE_PUBLIC (decl))
904     {
905       PUT_SDB_SCL (C_EXT);
906     }
907   else
908     {
909       PUT_SDB_SCL (C_STAT);
910     }
911   PUT_SDB_TYPE (plain_type (type));
912   PUT_SDB_ENDEF;
913 }
914 \f
915 #ifdef SDB_ALLOW_FORWARD_REFERENCES
916
917 /* Machinery to record and output anonymous types. */
918
919 static tree anonymous_types;
920
921 static void
922 sdbout_queue_anonymous_type (type)
923      tree type;
924 {
925   anonymous_types = saveable_tree_cons (NULL_TREE, type, anonymous_types);
926 }
927
928 static void
929 sdbout_dequeue_anonymous_types ()
930 {
931   register tree types, link;
932
933   while (anonymous_types)
934     {
935       types = nreverse (anonymous_types);
936       anonymous_types = NULL_TREE;
937
938       for (link = types; link; link = TREE_CHAIN (link))
939         {
940           register tree type = TREE_VALUE (link);
941
942           if (type && ! TREE_ASM_WRITTEN (type))
943             sdbout_one_type (type);
944         }
945     }
946 }
947
948 #endif
949 \f
950 /* Given a chain of ..._TYPE nodes, all of which have names,
951    output definitions of those names, as typedefs.  */
952
953 void
954 sdbout_types (types)
955      register tree types;
956 {
957   register tree link;
958
959   for (link = types; link; link = TREE_CHAIN (link))
960     sdbout_one_type (link);
961
962 #ifdef SDB_ALLOW_FORWARD_REFERENCES
963   sdbout_dequeue_anonymous_types ();
964 #endif
965 }
966
967 static void
968 sdbout_type (type)
969      tree type;
970 {
971   if (type == error_mark_node)
972     type = integer_type_node;
973   PUT_SDB_TYPE (plain_type (type));
974 }
975
976 /* Output types of the fields of type TYPE, if they are structs.
977
978    Formerly did not chase through pointer types, since that could be circular.
979    They must come before TYPE, since forward refs are not allowed.
980    Now james@bigtex.cactus.org says to try them.  */
981
982 static void
983 sdbout_field_types (type)
984      tree type;
985 {
986   tree tail;
987   for (tail = TYPE_FIELDS (type); tail; tail = TREE_CHAIN (tail))
988     if (TREE_CODE (TREE_TYPE (tail)) == POINTER_TYPE)
989       sdbout_one_type (TREE_TYPE (TREE_TYPE (tail)));
990     else
991       sdbout_one_type (TREE_TYPE (tail));
992 }
993
994 /* Use this to put out the top level defined record and union types
995    for later reference.  If this is a struct with a name, then put that
996    name out.  Other unnamed structs will have .xxfake labels generated so
997    that they may be referred to later.
998    The label will be stored in the KNOWN_TYPE_TAG slot of a type.
999    It may NOT be called recursively.  */
1000
1001 static void
1002 sdbout_one_type (type)
1003      tree type;
1004 {
1005   text_section ();
1006
1007   switch (TREE_CODE (type))
1008     {
1009     case RECORD_TYPE:
1010     case UNION_TYPE:
1011     case QUAL_UNION_TYPE:
1012     case ENUMERAL_TYPE:
1013       type = TYPE_MAIN_VARIANT (type);
1014       /* Don't output a type twice.  */
1015       if (TREE_ASM_WRITTEN (type))
1016         /* James said test TREE_ASM_BEING_WRITTEN here.  */
1017         return;
1018
1019       /* Output nothing if type is not yet defined.  */
1020       if (TYPE_SIZE (type) == 0)
1021         return;
1022
1023       TREE_ASM_WRITTEN (type) = 1;
1024 #if 1
1025       /* This is reputed to cause trouble with the following case,
1026          but perhaps checking TYPE_SIZE above will fix it.  */
1027
1028       /* Here is a test case:
1029
1030         struct foo {
1031           struct badstr *bbb;
1032         } forwardref;
1033
1034         typedef struct intermediate {
1035           int aaaa;
1036         } intermediate_ref;
1037
1038         typedef struct badstr {
1039           int ccccc;
1040         } badtype;   */
1041
1042 #if 0
1043       TREE_ASM_BEING_WRITTEN (type) = 1;
1044 #endif
1045       /* This change, which ought to make better output,
1046          used to make the COFF assembler unhappy.
1047          Changes involving KNOWN_TYPE_TAG may fix the problem.  */
1048       /* Before really doing anything, output types we want to refer to.  */
1049       /* Note that in version 1 the following two lines
1050          are not used if forward references are in use.  */
1051       if (TREE_CODE (type) != ENUMERAL_TYPE)
1052         sdbout_field_types (type);
1053 #if 0
1054       TREE_ASM_WRITTEN (type) = 1;
1055 #endif
1056 #endif
1057
1058       /* Output a structure type.  */
1059       {
1060         int size = int_size_in_bytes (type);
1061         int member_scl;
1062         tree tem;
1063         int i, n_baseclasses = 0;
1064
1065         /* Record the type tag, but not in its permanent place just yet.  */
1066         sdbout_record_type_name (type);
1067
1068         PUT_SDB_DEF (KNOWN_TYPE_TAG (type));
1069
1070         switch (TREE_CODE (type))
1071           {
1072           case UNION_TYPE:
1073           case QUAL_UNION_TYPE:
1074             PUT_SDB_SCL (C_UNTAG);
1075             PUT_SDB_TYPE (T_UNION);
1076             member_scl = C_MOU;
1077             break;
1078
1079           case RECORD_TYPE:
1080             PUT_SDB_SCL (C_STRTAG);
1081             PUT_SDB_TYPE (T_STRUCT);
1082             member_scl = C_MOS;
1083             break;
1084
1085           case ENUMERAL_TYPE:
1086             PUT_SDB_SCL (C_ENTAG);
1087             PUT_SDB_TYPE (T_ENUM);
1088             member_scl = C_MOE;
1089             break;
1090           }
1091
1092         PUT_SDB_SIZE (size);
1093         PUT_SDB_ENDEF;
1094
1095         /* Print out the base class information with fields
1096            named after the types they hold.  */
1097         if (TYPE_BINFO (type)
1098             && TYPE_BINFO_BASETYPES (type))
1099           n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1100         for (i = 0; i < n_baseclasses; i++)
1101           {
1102             tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1103             tree child_type = BINFO_TYPE (child);
1104             tree child_type_name;
1105             if (TYPE_NAME (child_type) == 0)
1106               continue;
1107             if (TREE_CODE (TYPE_NAME (child_type)) == IDENTIFIER_NODE)
1108               child_type_name = TYPE_NAME (child_type);
1109             else if (TREE_CODE (TYPE_NAME (child_type)) == TYPE_DECL)
1110               {
1111                 child_type_name = DECL_NAME (TYPE_NAME (child_type));
1112                 if (child_type_name && template_name_p (child_type_name))
1113                   child_type_name
1114                     = DECL_ASSEMBLER_NAME (TYPE_NAME (child_type));
1115               }
1116             else
1117               continue;
1118
1119             CONTIN;
1120             PUT_SDB_DEF (IDENTIFIER_POINTER (child_type_name));
1121             PUT_SDB_INT_VAL (TREE_INT_CST_LOW (BINFO_OFFSET (child)));
1122             PUT_SDB_SCL (member_scl);
1123             sdbout_type (BINFO_TYPE (child));
1124             PUT_SDB_ENDEF;
1125           }
1126
1127         /* output the individual fields */
1128
1129         if (TREE_CODE (type) == ENUMERAL_TYPE)
1130           for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1131             {
1132               PUT_SDB_DEF (IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1133               PUT_SDB_INT_VAL (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1134               PUT_SDB_SCL (C_MOE);
1135               PUT_SDB_TYPE (T_MOE);
1136               PUT_SDB_ENDEF;
1137             }
1138
1139         else                    /* record or union type */
1140           for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
1141             /* Output the name, type, position (in bits), size (in bits)
1142                of each field.  */
1143
1144             /* Omit here the nameless fields that are used to skip bits.
1145                Also omit fields with variable size or position.
1146                Also omit non FIELD_DECL nodes that GNU C++ may put here.  */
1147             if (TREE_CODE (tem) == FIELD_DECL
1148                 && DECL_NAME (tem) != 0
1149                 && TREE_CODE (DECL_SIZE (tem)) == INTEGER_CST
1150                 && TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
1151               {
1152                 char *name;
1153
1154                 CONTIN;
1155                 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
1156                 PUT_SDB_DEF (name);
1157                 if (DECL_BIT_FIELD_TYPE (tem))
1158                   {
1159                     PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
1160                     PUT_SDB_SCL (C_FIELD);
1161                     sdbout_type (DECL_BIT_FIELD_TYPE (tem));
1162                     PUT_SDB_SIZE (TREE_INT_CST_LOW (DECL_SIZE (tem)));
1163                   }
1164                 else
1165                   {
1166                     PUT_SDB_INT_VAL (TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem))
1167                                      / BITS_PER_UNIT);
1168                     PUT_SDB_SCL (member_scl);
1169                     sdbout_type (TREE_TYPE (tem));
1170                   }
1171                 PUT_SDB_ENDEF;
1172               }
1173         /* output end of a structure,union, or enumeral definition */
1174
1175         PUT_SDB_PLAIN_DEF ("eos");
1176         PUT_SDB_INT_VAL (size);
1177         PUT_SDB_SCL (C_EOS);
1178         PUT_SDB_TAG (KNOWN_TYPE_TAG (type));
1179         PUT_SDB_SIZE (size);
1180         PUT_SDB_ENDEF;
1181         break;
1182       }
1183     }
1184 }
1185 \f
1186 /* The following two functions output definitions of function parameters.
1187    Each parameter gets a definition locating it in the parameter list.
1188    Each parameter that is a register variable gets a second definition
1189    locating it in the register.
1190
1191    Printing or argument lists in gdb uses the definitions that
1192    locate in the parameter list.  But reference to the variable in
1193    expressions uses preferentially the definition as a register.  */
1194
1195 /* Output definitions, referring to storage in the parmlist,
1196    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
1197
1198 static void
1199 sdbout_parms (parms)
1200      tree parms;
1201 {
1202   for (; parms; parms = TREE_CHAIN (parms))
1203     if (DECL_NAME (parms))
1204       {
1205         int current_sym_value = 0;
1206         char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1207
1208         if (name == 0 || *name == 0)
1209           name = gen_fake_label ();
1210
1211         /* Perform any necessary register eliminations on the parameter's rtl,
1212            so that the debugging output will be accurate.  */
1213         DECL_INCOMING_RTL (parms) =
1214           eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1215         DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1216
1217         if (PARM_PASSED_IN_MEMORY (parms))
1218           {
1219             rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1220             tree type;
1221
1222             /* ??? Here we assume that the parm address is indexed
1223                off the frame pointer or arg pointer.
1224                If that is not true, we produce meaningless results,
1225                but do not crash.  */
1226             if (GET_CODE (addr) == PLUS
1227                 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1228               current_sym_value = INTVAL (XEXP (addr, 1));
1229             else
1230               current_sym_value = 0;
1231
1232             if (GET_CODE (DECL_RTL (parms)) == REG
1233                 && REGNO (DECL_RTL (parms)) >= 0
1234                 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1235               type = DECL_ARG_TYPE (parms);
1236             else
1237               {
1238                 int original_sym_value = current_sym_value;
1239
1240                 /* This is the case where the parm is passed as an int or
1241                    double and it is converted to a char, short or float
1242                    and stored back in the parmlist.  In this case, describe
1243                    the parm with the variable's declared type, and adjust
1244                    the address if the least significant bytes (which we are
1245                    using) are not the first ones.  */
1246                 if (BYTES_BIG_ENDIAN
1247                     && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1248                   current_sym_value +=
1249                     (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1250                      - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1251
1252                 if (GET_CODE (DECL_RTL (parms)) == MEM
1253                     && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1254                     && (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1255                         == CONST_INT)
1256                     && (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1))
1257                         == current_sym_value))
1258                   type = TREE_TYPE (parms);
1259                 else
1260                   {
1261                     current_sym_value = original_sym_value;
1262                     type = DECL_ARG_TYPE (parms);
1263                   }
1264               }
1265
1266             PUT_SDB_DEF (name);
1267             PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value, addr));
1268             PUT_SDB_SCL (C_ARG);
1269             PUT_SDB_TYPE (plain_type (type));
1270             PUT_SDB_ENDEF;
1271           }
1272         else if (GET_CODE (DECL_RTL (parms)) == REG)
1273           {
1274             rtx best_rtl;
1275             /* Parm passed in registers and lives in registers or nowhere.  */
1276
1277             /* If parm lives in a register, use that register;
1278                pretend the parm was passed there.  It would be more consistent
1279                to describe the register where the parm was passed,
1280                but in practice that register usually holds something else.  */
1281             if (REGNO (DECL_RTL (parms)) >= 0
1282                 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1283               best_rtl = DECL_RTL (parms);
1284             /* If the parm lives nowhere,
1285                use the register where it was passed.  */
1286             else
1287               best_rtl = DECL_INCOMING_RTL (parms);
1288
1289             PUT_SDB_DEF (name);
1290             PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (best_rtl)));
1291             PUT_SDB_SCL (C_REGPARM);
1292             PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1293             PUT_SDB_ENDEF;
1294           }
1295         else if (GET_CODE (DECL_RTL (parms)) == MEM
1296                  && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1297           {
1298             /* Parm was passed in registers but lives on the stack.  */
1299
1300             /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1301                in which case we want the value of that CONST_INT,
1302                or (MEM (REG ...)) or (MEM (MEM ...)),
1303                in which case we use a value of zero.  */
1304             if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1305                 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1306               current_sym_value = 0;
1307             else
1308               current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1309
1310             /* Again, this assumes the offset is based on the arg pointer.  */
1311             PUT_SDB_DEF (name);
1312             PUT_SDB_INT_VAL (DEBUGGER_ARG_OFFSET (current_sym_value,
1313                                                   XEXP (DECL_RTL (parms), 0)));
1314             PUT_SDB_SCL (C_ARG);
1315             PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1316             PUT_SDB_ENDEF;
1317           }
1318       }
1319 }
1320
1321 /* Output definitions for the places where parms live during the function,
1322    when different from where they were passed, when the parms were passed
1323    in memory.
1324
1325    It is not useful to do this for parms passed in registers
1326    that live during the function in different registers, because it is
1327    impossible to look in the passed register for the passed value,
1328    so we use the within-the-function register to begin with.
1329
1330    PARMS is a chain of PARM_DECL nodes.  */
1331
1332 static void
1333 sdbout_reg_parms (parms)
1334      tree parms;
1335 {
1336   for (; parms; parms = TREE_CHAIN (parms))
1337     if (DECL_NAME (parms))
1338       {
1339         char *name = IDENTIFIER_POINTER (DECL_NAME (parms));
1340
1341         /* Report parms that live in registers during the function
1342            but were passed in memory.  */
1343         if (GET_CODE (DECL_RTL (parms)) == REG
1344             && REGNO (DECL_RTL (parms)) >= 0
1345             && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
1346             && PARM_PASSED_IN_MEMORY (parms))
1347           {
1348             if (name == 0 || *name == 0)
1349               name = gen_fake_label ();
1350             PUT_SDB_DEF (name);
1351             PUT_SDB_INT_VAL (DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms))));
1352             PUT_SDB_SCL (C_REG);
1353             PUT_SDB_TYPE (plain_type (TREE_TYPE (parms), 0));
1354             PUT_SDB_ENDEF;
1355           }
1356         /* Report parms that live in memory but not where they were passed.  */
1357         else if (GET_CODE (DECL_RTL (parms)) == MEM
1358                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1359                  && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1360                  && PARM_PASSED_IN_MEMORY (parms)
1361                  && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
1362           {
1363 #if 0 /* ??? It is not clear yet what should replace this.  */
1364             int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
1365             /* A parm declared char is really passed as an int,
1366                so it occupies the least significant bytes.
1367                On a big-endian machine those are not the low-numbered ones.  */
1368             if (BYTES_BIG_ENDIAN
1369                 && offset != -1
1370                 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1371               offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1372                          - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1373             if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
1374 #endif
1375               {
1376                 if (name == 0 || *name == 0)
1377                   name = gen_fake_label ();
1378                 PUT_SDB_DEF (name);
1379                 PUT_SDB_INT_VAL (DEBUGGER_AUTO_OFFSET
1380                                  (XEXP (DECL_RTL (parms), 0)));
1381                 PUT_SDB_SCL (C_AUTO);
1382                 PUT_SDB_TYPE (plain_type (TREE_TYPE (parms)));
1383                 PUT_SDB_ENDEF;
1384               }
1385           }
1386       }
1387 }
1388 \f
1389 /* Describe the beginning of an internal block within a function.
1390    Also output descriptions of variables defined in this block.
1391
1392    N is the number of the block, by order of beginning, counting from 1,
1393    and not counting the outermost (function top-level) block.
1394    The blocks match the BLOCKs in DECL_INITIAL (current_function_decl),
1395    if the count starts at 0 for the outermost one.  */
1396
1397 void
1398 sdbout_begin_block (file, line, n)
1399      FILE *file;
1400      int line;
1401      int n;
1402 {
1403   tree decl = current_function_decl;
1404   MAKE_LINE_SAFE (line);
1405
1406   /* The SCO compiler does not emit a separate block for the function level
1407      scope, so we avoid it here also.  However, mips ECOFF compilers do emit
1408      a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
1409 #ifndef MIPS_DEBUGGING_INFO
1410   if (n != 1)
1411 #endif
1412     PUT_SDB_BLOCK_START (line - sdb_begin_function_line);
1413
1414   if (n == 1)
1415     {
1416       /* Include the outermost BLOCK's variables in block 1.  */
1417       next_block_number = 0;
1418       do_block = 0;
1419       sdbout_block (DECL_INITIAL (decl));
1420     }
1421   /* If -g1, suppress all the internal symbols of functions
1422      except for arguments.  */
1423   if (debug_info_level != DINFO_LEVEL_TERSE)
1424     {
1425       next_block_number = 0;
1426       do_block = n;
1427       sdbout_block (DECL_INITIAL (decl));
1428     }
1429
1430 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1431   sdbout_dequeue_anonymous_types ();
1432 #endif
1433 }
1434
1435 /* Describe the end line-number of an internal block within a function.  */
1436
1437 void
1438 sdbout_end_block (file, line, n)
1439      FILE *file;
1440      int line;
1441      int n;
1442 {
1443   MAKE_LINE_SAFE (line);
1444
1445   /* The SCO compiler does not emit a separate block for the function level
1446      scope, so we avoid it here also.  However, mips ECOFF compilers do emit
1447      a separate block, so we retain it when MIPS_DEBUGGING_INFO is defined.  */
1448 #ifndef MIPS_DEBUGGING_INFO
1449   if (n != 1)
1450 #endif
1451   PUT_SDB_BLOCK_END (line - sdb_begin_function_line);
1452 }
1453
1454 /* Output sdb info for the current function name.
1455    Called from assemble_start_function.  */
1456
1457 void
1458 sdbout_mark_begin_function ()
1459 {
1460   sdbout_symbol (current_function_decl, 0);
1461 }
1462
1463 /* Called at beginning of function body (after prologue).
1464    Record the function's starting line number, so we can output
1465    relative line numbers for the other lines.
1466    Describe beginning of outermost block.
1467    Also describe the parameter list.  */
1468
1469 void
1470 sdbout_begin_function (line)
1471      int line;
1472 {
1473   sdb_begin_function_line = line - 1;
1474   PUT_SDB_FUNCTION_START (line);
1475   sdbout_parms (DECL_ARGUMENTS (current_function_decl));
1476   sdbout_reg_parms (DECL_ARGUMENTS (current_function_decl));
1477 }
1478
1479 /* Called at end of function (before epilogue).
1480    Describe end of outermost block.  */
1481
1482 void
1483 sdbout_end_function (line)
1484      int line;
1485 {
1486 #ifdef SDB_ALLOW_FORWARD_REFERENCES
1487   sdbout_dequeue_anonymous_types ();
1488 #endif
1489
1490   MAKE_LINE_SAFE (line);
1491   PUT_SDB_FUNCTION_END (line - sdb_begin_function_line);
1492
1493   /* Indicate we are between functions, for line-number output.  */
1494   sdb_begin_function_line = -1;
1495 }
1496
1497 /* Output sdb info for the absolute end of a function.
1498    Called after the epilogue is output.  */
1499
1500 void
1501 sdbout_end_epilogue ()
1502 {
1503   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl));
1504   PUT_SDB_EPILOGUE_END (name);
1505 }
1506
1507 /* Output sdb info for the given label.  Called only if LABEL_NAME (insn)
1508    is present.  */
1509
1510 void
1511 sdbout_label (insn)
1512      register rtx insn;
1513 {
1514   PUT_SDB_DEF (LABEL_NAME (insn));
1515   PUT_SDB_VAL (insn);
1516   PUT_SDB_SCL (C_LABEL);
1517   PUT_SDB_TYPE (T_NULL);
1518   PUT_SDB_ENDEF;
1519 }
1520
1521 #endif /* SDB_DEBUGGING_INFO */