OSDN Git Service

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