OSDN Git Service

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