OSDN Git Service

* debug.h (struct gcc_debug_hooks): Add type_decl field.
[pf3gnuchains/gcc-fork.git] / gcc / dbxout.c
1 /* Output dbx-format symbol table information from GNU compiler.
2    Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3    1999, 2000, 2001, 2002, 2003, 2004 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
23 /* Output dbx-format symbol table data.
24    This consists of many symbol table entries, each of them
25    a .stabs assembler pseudo-op with four operands:
26    a "name" which is really a description of one symbol and its type,
27    a "code", which is a symbol defined in stab.h whose name starts with N_,
28    an unused operand always 0,
29    and a "value" which is an address or an offset.
30    The name is enclosed in doublequote characters.
31
32    Each function, variable, typedef, and structure tag
33    has a symbol table entry to define it.
34    The beginning and end of each level of name scoping within
35    a function are also marked by special symbol table entries.
36
37    The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
38    and a data type number.  The data type number may be followed by
39    "=" and a type definition; normally this will happen the first time
40    the type number is mentioned.  The type definition may refer to
41    other types by number, and those type numbers may be followed
42    by "=" and nested definitions.
43
44    This can make the "name" quite long.
45    When a name is more than 80 characters, we split the .stabs pseudo-op
46    into two .stabs pseudo-ops, both sharing the same "code" and "value".
47    The first one is marked as continued with a double-backslash at the
48    end of its "name".
49
50    The kind-of-symbol letter distinguished function names from global
51    variables from file-scope variables from parameters from auto
52    variables in memory from typedef names from register variables.
53    See `dbxout_symbol'.
54
55    The "code" is mostly redundant with the kind-of-symbol letter
56    that goes in the "name", but not entirely: for symbols located
57    in static storage, the "code" says which segment the address is in,
58    which controls how it is relocated.
59
60    The "value" for a symbol in static storage
61    is the core address of the symbol (actually, the assembler
62    label for the symbol).  For a symbol located in a stack slot
63    it is the stack offset; for one in a register, the register number.
64    For a typedef symbol, it is zero.
65
66    If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
67    output while in the text section.
68
69    For more on data type definitions, see `dbxout_type'.  */
70
71 #include "config.h"
72 #include "system.h"
73 #include "coretypes.h"
74 #include "tm.h"
75
76 #include "tree.h"
77 #include "rtl.h"
78 #include "flags.h"
79 #include "regs.h"
80 #include "insn-config.h"
81 #include "reload.h"
82 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions.  */
83 #include "dbxout.h"
84 #include "toplev.h"
85 #include "tm_p.h"
86 #include "ggc.h"
87 #include "debug.h"
88 #include "function.h"
89 #include "target.h"
90 #include "langhooks.h"
91
92 #ifdef XCOFF_DEBUGGING_INFO
93 #include "xcoffout.h"
94 #endif
95
96 #undef DBXOUT_DECR_NESTING
97 #define DBXOUT_DECR_NESTING \
98   if (--debug_nesting == 0 && symbol_queue_index > 0) \
99     { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); }
100
101 #undef DBXOUT_DECR_NESTING_AND_RETURN
102 #define DBXOUT_DECR_NESTING_AND_RETURN(x) \
103   do {--debug_nesting; return (x);} while (0)
104
105 #ifndef ASM_STABS_OP
106 #define ASM_STABS_OP "\t.stabs\t"
107 #endif
108
109 #ifndef ASM_STABN_OP
110 #define ASM_STABN_OP "\t.stabn\t"
111 #endif
112
113 #ifndef DBX_TYPE_DECL_STABS_CODE
114 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
115 #endif
116
117 #ifndef DBX_STATIC_CONST_VAR_CODE
118 #define DBX_STATIC_CONST_VAR_CODE N_FUN
119 #endif
120
121 #ifndef DBX_REGPARM_STABS_CODE
122 #define DBX_REGPARM_STABS_CODE N_RSYM
123 #endif
124
125 #ifndef DBX_REGPARM_STABS_LETTER
126 #define DBX_REGPARM_STABS_LETTER 'P'
127 #endif
128
129 /* This is used for parameters passed by invisible reference in a register.  */
130 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
131 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
132 #endif
133
134 #ifndef DBX_MEMPARM_STABS_LETTER
135 #define DBX_MEMPARM_STABS_LETTER 'p'
136 #endif
137
138 #ifndef FILE_NAME_JOINER
139 #define FILE_NAME_JOINER "/"
140 #endif
141
142 /* GDB needs to know that the stabs were generated by GCC.  We emit an
143    N_OPT stab at the beginning of the source file to indicate this.
144    The string is historical, and different on a very few targets.  */
145 #ifndef STABS_GCC_MARKER
146 #define STABS_GCC_MARKER "gcc2_compiled."
147 #endif
148
149 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
150
151 /* Structure recording information about a C data type.
152    The status element says whether we have yet output
153    the definition of the type.  TYPE_XREF says we have
154    output it as a cross-reference only.
155    The file_number and type_number elements are used if DBX_USE_BINCL
156    is defined.  */
157
158 struct typeinfo GTY(())
159 {
160   enum typestatus status;
161   int file_number;
162   int type_number;
163 };
164
165 /* Vector recording information about C data types.
166    When we first notice a data type (a tree node),
167    we assign it a number using next_type_number.
168    That is its index in this vector.  */
169
170 static GTY ((length ("typevec_len"))) struct typeinfo *typevec;
171
172 /* Number of elements of space allocated in `typevec'.  */
173
174 static GTY(()) int typevec_len;
175
176 /* In dbx output, each type gets a unique number.
177    This is the number for the next type output.
178    The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
179
180 static GTY(()) int next_type_number;
181
182 /* The C front end may call dbxout_symbol before dbxout_init runs.
183    We save all such decls in this list and output them when we get
184    to dbxout_init.  */
185
186 static GTY(()) tree preinit_symbols;
187
188 enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED};
189
190 /* When using N_BINCL in dbx output, each type number is actually a
191    pair of the file number and the type number within the file.
192    This is a stack of input files.  */
193
194 struct dbx_file
195 {
196   struct dbx_file *next;
197   int file_number;
198   int next_type_number;
199   enum binclstatus bincl_status;  /* Keep track of lazy bincl.  */
200   const char *pending_bincl_name; /* Name of bincl.  */
201   struct dbx_file *prev;          /* Chain to traverse all pending bincls.  */
202 };
203
204 /* This is the top of the stack.  
205    
206    This is not saved for PCH, because restoring a PCH should not change it.
207    next_file_number does have to be saved, because the PCH may use some
208    file numbers; however, just before restoring a PCH, next_file_number
209    should always be 0 because we should not have needed any file numbers
210    yet.  */
211
212 #if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \
213     && defined (DBX_USE_BINCL)
214 static struct dbx_file *current_file;
215 #endif
216
217 /* This is the next file number to use.  */
218
219 static GTY(()) int next_file_number;
220
221 /* A counter for dbxout_function_end.  */
222
223 static GTY(()) int scope_labelno;
224
225 /* A counter for dbxout_source_line.  */
226
227 static GTY(()) int dbxout_source_line_counter;
228
229 /* Nonzero if we have actually used any of the GDB extensions
230    to the debugging format.  The idea is that we use them for the
231    first time only if there's a strong reason, but once we have done that,
232    we use them whenever convenient.  */
233
234 static GTY(()) int have_used_extensions = 0;
235
236 /* Number for the next N_SOL filename stabs label.  The number 0 is reserved
237    for the N_SO filename stabs label.  */
238
239 static GTY(()) int source_label_number = 1;
240
241 /* Last source file name mentioned in a NOTE insn.  */
242
243 static GTY(()) const char *lastfile;
244
245 /* Used by PCH machinery to detect if 'lastfile' should be reset to
246    base_input_file.  */
247 static GTY(()) int lastfile_is_base;
248
249 /* Typical USG systems don't have stab.h, and they also have
250    no use for DBX-format debugging info.  */
251
252 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
253
254 #ifdef DBX_USE_BINCL
255 /* If zero then there is no pending BINCL.  */
256 static int pending_bincls = 0;
257 #endif
258
259 /* The original input file name.  */
260 static const char *base_input_file;
261
262 /* Current working directory.  */
263
264 static const char *cwd;
265
266 #ifdef DEBUG_SYMS_TEXT
267 #define FORCE_TEXT function_section (current_function_decl);
268 #else
269 #define FORCE_TEXT
270 #endif
271
272 #include "gstab.h"
273
274 #define STAB_CODE_TYPE enum __stab_debug_code
275
276 /* 1 if PARM is passed to this function in memory.  */
277
278 #define PARM_PASSED_IN_MEMORY(PARM) \
279  (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
280
281 /* A C expression for the integer offset value of an automatic variable
282    (N_LSYM) having address X (an RTX).  */
283 #ifndef DEBUGGER_AUTO_OFFSET
284 #define DEBUGGER_AUTO_OFFSET(X) \
285   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
286 #endif
287
288 /* A C expression for the integer offset value of an argument (N_PSYM)
289    having address X (an RTX).  The nominal offset is OFFSET.  */
290 #ifndef DEBUGGER_ARG_OFFSET
291 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
292 #endif
293
294 /* Stream for writing to assembler file.  */
295
296 static FILE *asmfile;
297
298 /* These variables are for dbxout_symbol to communicate to
299    dbxout_finish_symbol.
300    current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
301    current_sym_value and current_sym_addr are two ways to address the
302    value to store in the symtab entry.
303    current_sym_addr if nonzero represents the value as an rtx.
304    If that is zero, current_sym_value is used.  This is used
305    when the value is an offset (such as for auto variables,
306    register variables and parms).  */
307
308 static STAB_CODE_TYPE current_sym_code;
309 static int current_sym_value;
310 static rtx current_sym_addr;
311
312 /* Number of chars of symbol-description generated so far for the
313    current symbol.  Used by CHARS and CONTIN.  */
314
315 static int current_sym_nchars;
316
317 /* Report having output N chars of the current symbol-description.  */
318
319 #define CHARS(N) (current_sym_nchars += (N))
320
321 /* Break the current symbol-description, generating a continuation,
322    if it has become long.  */
323
324 #ifndef DBX_CONTIN_LENGTH
325 #define DBX_CONTIN_LENGTH 80
326 #endif
327
328 #if DBX_CONTIN_LENGTH > 0
329 #define CONTIN  \
330   do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
331 #else
332 #define CONTIN do { } while (0)
333 #endif
334
335 #ifdef DBX_USE_BINCL
336 static void emit_bincl_stab             (const char *c);
337 static void emit_pending_bincls         (void);
338 #endif
339 static inline void emit_pending_bincls_if_required (void);
340
341 static void dbxout_init (const char *);
342 static void dbxout_finish (const char *);
343 static void dbxout_start_source_file (unsigned, const char *);
344 static void dbxout_end_source_file (unsigned);
345 static void dbxout_typedefs (tree);
346 static void dbxout_type_index (tree);
347 #if DBX_CONTIN_LENGTH > 0
348 static void dbxout_continue (void);
349 #endif
350 static void dbxout_args (tree);
351 static void dbxout_type_fields (tree);
352 static void dbxout_type_method_1 (tree, const char *);
353 static void dbxout_type_methods (tree);
354 static void dbxout_range_type (tree);
355 static void dbxout_type (tree, int);
356 static bool print_int_cst_bounds_in_octal_p (tree);
357 static void print_int_cst_octal (tree);
358 static void print_octal (unsigned HOST_WIDE_INT, int);
359 static void print_wide_int (HOST_WIDE_INT);
360 static void dbxout_type_name (tree);
361 static void dbxout_class_name_qualifiers (tree);
362 static int dbxout_symbol_location (tree, tree, const char *, rtx);
363 static void dbxout_symbol_name (tree, const char *, int);
364 static void dbxout_prepare_symbol (tree);
365 static void dbxout_finish_symbol (tree);
366 static void dbxout_block (tree, int, tree);
367 static void dbxout_global_decl (tree);
368 static void dbxout_handle_pch (unsigned);
369 \f
370 /* The debug hooks structure.  */
371 #if defined (DBX_DEBUGGING_INFO)
372
373 static void dbxout_source_line (unsigned int, const char *);
374 static void dbxout_source_file (FILE *, const char *);
375 static void dbxout_function_end (void);
376 static void dbxout_begin_function (tree);
377 static void dbxout_begin_block (unsigned, unsigned);
378 static void dbxout_end_block (unsigned, unsigned);
379 static void dbxout_function_decl (tree);
380 static void dbxout_type_decl (tree, int);
381
382 const struct gcc_debug_hooks dbx_debug_hooks =
383 {
384   dbxout_init,
385   dbxout_finish,
386   debug_nothing_int_charstar,
387   debug_nothing_int_charstar,
388   dbxout_start_source_file,
389   dbxout_end_source_file,
390   dbxout_begin_block,
391   dbxout_end_block,
392   debug_true_tree,                       /* ignore_block */
393   dbxout_source_line,                    /* source_line */
394   dbxout_source_line,                    /* begin_prologue: just output 
395                                             line info */
396   debug_nothing_int_charstar,            /* end_prologue */
397   debug_nothing_int_charstar,            /* end_epilogue */
398 #ifdef DBX_FUNCTION_FIRST
399   dbxout_begin_function,
400 #else
401   debug_nothing_tree,                    /* begin_function */
402 #endif
403   debug_nothing_int,                     /* end_function */
404   dbxout_function_decl,
405   dbxout_global_decl,                    /* global_decl */
406   dbxout_type_decl,                      /* type_decl */
407   debug_nothing_tree_tree,               /* imported_module_or_decl */
408   debug_nothing_tree,                    /* deferred_inline_function */
409   debug_nothing_tree,                    /* outlining_inline_function */
410   debug_nothing_rtx,                     /* label */
411   dbxout_handle_pch,                     /* handle_pch */
412   debug_nothing_rtx                      /* var_location */
413 };
414 #endif /* DBX_DEBUGGING_INFO  */
415
416 #if defined (XCOFF_DEBUGGING_INFO)
417 const struct gcc_debug_hooks xcoff_debug_hooks =
418 {
419   dbxout_init,
420   dbxout_finish,
421   debug_nothing_int_charstar,
422   debug_nothing_int_charstar,
423   dbxout_start_source_file,
424   dbxout_end_source_file,
425   xcoffout_begin_block,
426   xcoffout_end_block,
427   debug_true_tree,                       /* ignore_block */
428   xcoffout_source_line,
429   xcoffout_begin_prologue,               /* begin_prologue */
430   debug_nothing_int_charstar,            /* end_prologue */
431   xcoffout_end_epilogue,
432   debug_nothing_tree,                    /* begin_function */
433   xcoffout_end_function,
434   debug_nothing_tree,                    /* function_decl */
435   dbxout_global_decl,                    /* global_decl */
436   dbxout_type_decl,                      /* type_decl */
437   debug_nothing_tree_tree,               /* imported_module_or_decl */
438   debug_nothing_tree,                    /* deferred_inline_function */
439   debug_nothing_tree,                    /* outlining_inline_function */
440   debug_nothing_rtx,                     /* label */
441   dbxout_handle_pch,                     /* handle_pch */
442   debug_nothing_rtx                      /* var_location */
443 };
444 #endif /* XCOFF_DEBUGGING_INFO  */
445 \f
446 #if defined (DBX_DEBUGGING_INFO)
447 static void
448 dbxout_function_end (void)
449 {
450   char lscope_label_name[100];
451   /* Convert Ltext into the appropriate format for local labels in case
452      the system doesn't insert underscores in front of user generated
453      labels.  */
454   ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
455   (*targetm.asm_out.internal_label) (asmfile, "Lscope", scope_labelno);
456   scope_labelno++;
457
458   /* By convention, GCC will mark the end of a function with an N_FUN
459      symbol and an empty string.  */
460 #ifdef DBX_OUTPUT_NFUN
461   DBX_OUTPUT_NFUN (asmfile, lscope_label_name, current_function_decl);
462 #else
463   fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
464   assemble_name (asmfile, lscope_label_name);
465   putc ('-', asmfile);
466   assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
467   fprintf (asmfile, "\n");
468 #endif
469 }
470 #endif /* DBX_DEBUGGING_INFO */
471
472 /* At the beginning of compilation, start writing the symbol table.
473    Initialize `typevec' and output the standard data types of C.  */
474
475 static void
476 dbxout_init (const char *input_file_name)
477 {
478   char ltext_label_name[100];
479   tree syms = (*lang_hooks.decls.getdecls) ();
480
481   asmfile = asm_out_file;
482
483   typevec_len = 100;
484   typevec = ggc_calloc (typevec_len, sizeof typevec[0]);
485
486   /* Convert Ltext into the appropriate format for local labels in case
487      the system doesn't insert underscores in front of user generated
488      labels.  */
489   ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
490
491   /* Put the current working directory in an N_SO symbol.  */
492   if (use_gnu_debug_info_extensions)
493     {
494       if (!cwd && (cwd = get_src_pwd ())
495           && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
496         cwd = concat (cwd, FILE_NAME_JOINER, NULL);
497       if (cwd)
498         {
499 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
500           DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
501 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
502           fprintf (asmfile, "%s", ASM_STABS_OP);
503           output_quoted_string (asmfile, cwd);
504           fprintf (asmfile, ",%d,0,0,", N_SO);
505           assemble_name (asmfile, ltext_label_name);
506           fputc ('\n', asmfile);
507 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
508         }
509     }
510
511 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
512   DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
513 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
514   /* We include outputting `Ltext:' here,
515      because that gives you a way to override it.  */
516   /* Used to put `Ltext:' before the reference, but that loses on sun 4.  */
517   fprintf (asmfile, "%s", ASM_STABS_OP);
518   output_quoted_string (asmfile, input_file_name);
519   fprintf (asmfile, ",%d,0,0,", N_SO);
520   assemble_name (asmfile, ltext_label_name);
521   fputc ('\n', asmfile);
522   text_section ();
523   (*targetm.asm_out.internal_label) (asmfile, "Ltext", 0);
524 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
525
526 #ifdef DBX_OUTPUT_GCC_MARKER
527   DBX_OUTPUT_GCC_MARKER (asmfile);
528 #else
529   /* Emit an N_OPT stab to indicate that this file was compiled by GCC.  */
530   fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
531            ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
532 #endif
533
534   base_input_file = lastfile = input_file_name;
535
536   next_type_number = 1;
537
538 #ifdef DBX_USE_BINCL
539   current_file = xmalloc (sizeof *current_file);
540   current_file->next = NULL;
541   current_file->file_number = 0;
542   current_file->next_type_number = 1;
543   next_file_number = 1;
544   current_file->prev = NULL;
545   current_file->bincl_status = BINCL_NOT_REQUIRED;
546   current_file->pending_bincl_name = NULL;
547 #endif
548
549   /* Get all permanent types that have typedef names, and output them
550      all, except for those already output.  Some language front ends
551      put these declarations in the top-level scope; some do not;
552      the latter are responsible for calling debug_hooks->type_decl from
553      their record_builtin_type function.  */
554   dbxout_typedefs (syms);
555
556   if (preinit_symbols)
557     {
558       tree t;
559       for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t))
560         dbxout_symbol (TREE_VALUE (t), 0);
561       preinit_symbols = 0;
562     }
563 }
564
565 /* Output any typedef names for types described by TYPE_DECLs in SYMS.  */
566
567 static void
568 dbxout_typedefs (tree syms)
569 {
570   for (; syms != NULL_TREE; syms = TREE_CHAIN (syms))
571     {
572       if (TREE_CODE (syms) == TYPE_DECL)
573         {
574           tree type = TREE_TYPE (syms);
575           if (TYPE_NAME (type)
576               && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
577               && COMPLETE_OR_VOID_TYPE_P (type)
578               && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
579             dbxout_symbol (TYPE_NAME (type), 0);
580         }
581     }
582 }
583
584 #ifdef DBX_USE_BINCL
585 /* Emit BINCL stab using given name.  */
586 static void
587 emit_bincl_stab (const char *name)
588 {
589   fprintf (asmfile, "%s", ASM_STABS_OP);
590   output_quoted_string (asmfile, name);
591   fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
592 }
593
594 /* If there are pending bincls then it is time to emit all of them.  */
595
596 static inline void
597 emit_pending_bincls_if_required (void)
598 {
599   if (pending_bincls)
600     emit_pending_bincls ();
601 }
602
603 /* Emit all pending bincls.  */
604
605 static void
606 emit_pending_bincls (void)
607 {
608   struct dbx_file *f = current_file;
609
610   /* Find first pending bincl.  */
611   while (f->bincl_status == BINCL_PENDING)
612     f = f->next;
613
614   /* Now emit all bincls.  */
615   f = f->prev;
616
617   while (f)
618     {
619       if (f->bincl_status == BINCL_PENDING)
620         {
621           emit_bincl_stab (f->pending_bincl_name);
622
623           /* Update file number and status.  */
624           f->file_number = next_file_number++;
625           f->bincl_status = BINCL_PROCESSED;
626         }
627       if (f == current_file)
628         break;
629       f = f->prev;
630     }
631
632   /* All pending bincls have been emitted.  */
633   pending_bincls = 0;
634 }
635
636 #else
637
638 static inline void
639 emit_pending_bincls_if_required (void) {}
640 #endif
641
642 /* Change to reading from a new source file.  Generate a N_BINCL stab.  */
643
644 static void
645 dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED,
646                           const char *filename ATTRIBUTE_UNUSED)
647 {
648 #ifdef DBX_USE_BINCL
649   struct dbx_file *n = xmalloc (sizeof *n);
650
651   n->next = current_file;
652   n->next_type_number = 1;
653   /* Do not assign file number now. 
654      Delay it until we actually emit BINCL.  */
655   n->file_number = 0;
656   n->prev = NULL;
657   current_file->prev = n;
658   n->bincl_status = BINCL_PENDING;
659   n->pending_bincl_name = filename;
660   pending_bincls = 1;
661   current_file = n;
662 #endif
663 }
664
665 /* Revert to reading a previous source file.  Generate a N_EINCL stab.  */
666
667 static void
668 dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED)
669 {
670 #ifdef DBX_USE_BINCL
671   /* Emit EINCL stab only if BINCL is not pending.  */
672   if (current_file->bincl_status == BINCL_PROCESSED)
673     fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
674   current_file->bincl_status = BINCL_NOT_REQUIRED;
675   current_file = current_file->next;
676 #endif
677 }
678
679 /* Handle a few odd cases that occur when trying to make PCH files work.  */
680
681 static void
682 dbxout_handle_pch (unsigned at_end)
683 {
684   if (! at_end)
685     {
686       /* When using the PCH, this file will be included, so we need to output
687          a BINCL.  */
688       dbxout_start_source_file (0, lastfile);
689
690       /* The base file when using the PCH won't be the same as
691          the base file when it's being generated.  */
692       lastfile = NULL;
693     }
694   else
695     {
696       /* ... and an EINCL.  */
697       dbxout_end_source_file (0);
698
699       /* Deal with cases where 'lastfile' was never actually changed.  */
700       lastfile_is_base = lastfile == NULL;
701     }
702 }
703
704 #if defined (DBX_DEBUGGING_INFO)
705 /* Output debugging info to FILE to switch to sourcefile FILENAME.  */
706
707 static void
708 dbxout_source_file (FILE *file, const char *filename)
709 {
710   if (lastfile == 0 && lastfile_is_base)
711     {
712       lastfile = base_input_file;
713       lastfile_is_base = 0;
714     }
715
716   if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
717     {
718       char ltext_label_name[100];
719
720       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
721                                    source_label_number);
722       fprintf (file, "%s", ASM_STABS_OP);
723       output_quoted_string (file, filename);
724       fprintf (asmfile, ",%d,0,0,", N_SOL);
725       assemble_name (asmfile, ltext_label_name);
726       fputc ('\n', asmfile);
727       if (current_function_decl != NULL_TREE
728           && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
729         ; /* Don't change section amid function.  */
730       else
731         text_section ();
732       (*targetm.asm_out.internal_label) (file, "Ltext", source_label_number);
733       source_label_number++;
734       lastfile = filename;
735     }
736 }
737
738 /* Output a line number symbol entry for source file FILENAME and line
739    number LINENO.  */
740
741 static void
742 dbxout_source_line (unsigned int lineno, const char *filename)
743 {
744   dbxout_source_file (asmfile, filename);
745
746 #ifdef ASM_OUTPUT_SOURCE_LINE
747   dbxout_source_line_counter += 1;
748   ASM_OUTPUT_SOURCE_LINE (asmfile, lineno, dbxout_source_line_counter);
749 #else
750   fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
751 #endif
752 }
753
754 /* Describe the beginning of an internal block within a function.  */
755
756 static void
757 dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
758 {
759   emit_pending_bincls_if_required ();
760   (*targetm.asm_out.internal_label) (asmfile, "LBB", n);
761 }
762
763 /* Describe the end line-number of an internal block within a function.  */
764
765 static void
766 dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n)
767 {
768   emit_pending_bincls_if_required ();
769   (*targetm.asm_out.internal_label) (asmfile, "LBE", n);
770 }
771
772 /* Output dbx data for a function definition.
773    This includes a definition of the function name itself (a symbol),
774    definitions of the parameters (locating them in the parameter list)
775    and then output the block that makes up the function's body
776    (including all the auto variables of the function).  */
777
778 static void
779 dbxout_function_decl (tree decl)
780 {
781   emit_pending_bincls_if_required ();
782 #ifndef DBX_FUNCTION_FIRST
783   dbxout_begin_function (decl);
784 #endif
785   dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
786 #ifdef DBX_OUTPUT_FUNCTION_END
787   DBX_OUTPUT_FUNCTION_END (asmfile, decl);
788 #endif
789   if (use_gnu_debug_info_extensions
790 #if defined(NO_DBX_FUNCTION_END)
791       && ! NO_DBX_FUNCTION_END
792 #endif
793       && targetm.have_named_sections)
794     dbxout_function_end ();
795 }
796
797 #endif /* DBX_DEBUGGING_INFO  */
798
799 /* Debug information for a global DECL.  Called from toplev.c after
800    compilation proper has finished.  */
801 static void
802 dbxout_global_decl (tree decl)
803 {
804   if (TREE_CODE (decl) == VAR_DECL
805       && ! DECL_EXTERNAL (decl)
806       && DECL_RTL_SET_P (decl)) /* Not necessary?  */
807     {
808       int saved_tree_used = TREE_USED (decl);
809       TREE_USED (decl) = 1;
810       dbxout_symbol (decl, 0);
811       TREE_USED (decl) = saved_tree_used;
812     }
813 }
814
815 /* This is just a function-type adapter; dbxout_symbol does exactly
816    what we want but returns an int.  */
817 static void
818 dbxout_type_decl (tree decl, int local)
819 {
820   dbxout_symbol (decl, local);
821 }
822
823 /* At the end of compilation, finish writing the symbol table.
824    Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
825    to do nothing.  */
826
827 static void
828 dbxout_finish (const char *filename ATTRIBUTE_UNUSED)
829 {
830 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
831   DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
832 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
833
834   debug_free_queue ();
835 }
836
837 /* Output the index of a type.  */
838
839 static void
840 dbxout_type_index (tree type)
841 {
842 #ifndef DBX_USE_BINCL
843   fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
844   CHARS (3);
845 #else
846   struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
847   fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
848   CHARS (9);
849 #endif
850 }
851
852 #if DBX_CONTIN_LENGTH > 0
853 /* Continue a symbol-description that gets too big.
854    End one symbol table entry with a double-backslash
855    and start a new one, eventually producing something like
856    .stabs "start......\\",code,0,value
857    .stabs "...rest",code,0,value   */
858
859 static void
860 dbxout_continue (void)
861 {
862   emit_pending_bincls_if_required ();
863 #ifdef DBX_CONTIN_CHAR
864   fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
865 #else
866   fprintf (asmfile, "\\\\");
867 #endif
868   dbxout_finish_symbol (NULL_TREE);
869   fprintf (asmfile, "%s\"", ASM_STABS_OP);
870   current_sym_nchars = 0;
871 }
872 #endif /* DBX_CONTIN_LENGTH > 0 */
873 \f
874 /* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
875    This must be a separate function because anonymous unions require
876    recursive calls.  */
877
878 static void
879 dbxout_type_fields (tree type)
880 {
881   tree tem;
882
883   /* Output the name, type, position (in bits), size (in bits) of each
884      field that we can support.  */
885   for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
886     {
887
888       /* If on of the nodes is an error_mark or its type is then return early. */
889       if (tem == error_mark_node || TREE_TYPE (tem) == error_mark_node)
890         return;
891
892       /* Omit here local type decls until we know how to support them.  */
893       if (TREE_CODE (tem) == TYPE_DECL
894           /* Omit fields whose position or size are variable or too large to
895              represent.  */
896           || (TREE_CODE (tem) == FIELD_DECL
897               && (! host_integerp (bit_position (tem), 0)
898                   || ! DECL_SIZE (tem)
899                   || ! host_integerp (DECL_SIZE (tem), 1)))
900           /* Omit here the nameless fields that are used to skip bits.  */
901            || DECL_IGNORED_P (tem))
902         continue;
903
904       else if (TREE_CODE (tem) != CONST_DECL)
905         {
906           /* Continue the line if necessary,
907              but not before the first field.  */
908           if (tem != TYPE_FIELDS (type))
909             CONTIN;
910
911           if (DECL_NAME (tem))
912             {
913               fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
914               CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
915             }
916           else
917             {
918               fprintf (asmfile, ":");
919               CHARS (1);
920             }
921
922           if (use_gnu_debug_info_extensions
923               && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
924                   || TREE_CODE (tem) != FIELD_DECL))
925             {
926               have_used_extensions = 1;
927               putc ('/', asmfile);
928               putc ((TREE_PRIVATE (tem) ? '0'
929                      : TREE_PROTECTED (tem) ? '1' : '2'),
930                     asmfile);
931               CHARS (2);
932             }
933
934           dbxout_type ((TREE_CODE (tem) == FIELD_DECL
935                         && DECL_BIT_FIELD_TYPE (tem))
936                        ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
937
938           if (TREE_CODE (tem) == VAR_DECL)
939             {
940               if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
941                 {
942                   tree name = DECL_ASSEMBLER_NAME (tem);
943
944                   have_used_extensions = 1;
945                   fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
946                   CHARS (IDENTIFIER_LENGTH (name) + 2);
947                 }
948               else
949                 {
950                   /* If TEM is non-static, GDB won't understand it.  */
951                   fprintf (asmfile, ",0,0;");
952                   CHARS (5);
953                 }
954             }
955           else
956             {
957               putc (',', asmfile);
958               print_wide_int (int_bit_position (tem));
959               putc (',', asmfile);
960               print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
961               putc (';', asmfile);
962               CHARS (3);
963             }
964         }
965     }
966 }
967 \f
968 /* Subroutine of `dbxout_type_methods'.  Output debug info about the
969    method described DECL.  DEBUG_NAME is an encoding of the method's
970    type signature.  ??? We may be able to do without DEBUG_NAME altogether
971    now.  */
972
973 static void
974 dbxout_type_method_1 (tree decl, const char *debug_name)
975 {
976   char c1 = 'A', c2;
977
978   if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
979     c2 = '?';
980   else /* it's a METHOD_TYPE.  */
981     {
982       tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
983       /* A for normal functions.
984          B for `const' member functions.
985          C for `volatile' member functions.
986          D for `const volatile' member functions.  */
987       if (TYPE_READONLY (TREE_TYPE (firstarg)))
988         c1 += 1;
989       if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
990         c1 += 2;
991
992       if (DECL_VINDEX (decl))
993         c2 = '*';
994       else
995         c2 = '.';
996     }
997
998   fprintf (asmfile, ":%s;%c%c%c", debug_name,
999            TREE_PRIVATE (decl) ? '0'
1000            : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
1001   CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
1002          - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
1003
1004   if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
1005     {
1006       print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
1007       putc (';', asmfile);
1008       CHARS (1);
1009       dbxout_type (DECL_CONTEXT (decl), 0);
1010       fprintf (asmfile, ";");
1011       CHARS (1);
1012     }
1013 }
1014 \f
1015 /* Subroutine of `dbxout_type'.  Output debug info about the methods defined
1016    in TYPE.  */
1017
1018 static void
1019 dbxout_type_methods (tree type)
1020 {
1021   /* C++: put out the method names and their parameter lists */
1022   tree methods = TYPE_METHODS (type);
1023   tree type_encoding;
1024   tree fndecl;
1025   tree last;
1026   char formatted_type_identifier_length[16];
1027   int type_identifier_length;
1028
1029   if (methods == NULL_TREE)
1030     return;
1031
1032   type_encoding = DECL_NAME (TYPE_NAME (type));
1033
1034 #if 0
1035   /* C++: Template classes break some assumptions made by this code about
1036      the class names, constructor names, and encodings for assembler
1037      label names.  For now, disable output of dbx info for them.  */
1038   {
1039     const char *ptr = IDENTIFIER_POINTER (type_encoding);
1040     /* This should use index.  (mrs) */
1041     while (*ptr && *ptr != '<') ptr++;
1042     if (*ptr != 0)
1043       {
1044         static int warned;
1045         if (!warned)
1046             warned = 1;
1047         return;
1048       }
1049   }
1050 #endif
1051
1052   type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
1053
1054   sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
1055
1056   if (TREE_CODE (methods) != TREE_VEC)
1057     fndecl = methods;
1058   else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
1059     fndecl = TREE_VEC_ELT (methods, 0);
1060   else
1061     fndecl = TREE_VEC_ELT (methods, 1);
1062
1063   while (fndecl)
1064     {
1065       int need_prefix = 1;
1066
1067       /* Group together all the methods for the same operation.
1068          These differ in the types of the arguments.  */
1069       for (last = NULL_TREE;
1070            fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
1071            fndecl = TREE_CHAIN (fndecl))
1072         /* Output the name of the field (after overloading), as
1073            well as the name of the field before overloading, along
1074            with its parameter list */
1075         {
1076           /* This is the "mangled" name of the method.
1077              It encodes the argument types.  */
1078           const char *debug_name;
1079
1080           /* Skip methods that aren't FUNCTION_DECLs.  (In C++, these
1081              include TEMPLATE_DECLs.)  The debugger doesn't know what
1082              to do with such entities anyhow.  */
1083           if (TREE_CODE (fndecl) != FUNCTION_DECL)
1084             continue;
1085
1086           debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
1087
1088           CONTIN;
1089
1090           last = fndecl;
1091
1092           /* Also ignore abstract methods; those are only interesting to
1093              the DWARF backends.  */
1094           if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
1095             continue;
1096
1097           /* Redundantly output the plain name, since that's what gdb
1098              expects.  */
1099           if (need_prefix)
1100             {
1101               tree name = DECL_NAME (fndecl);
1102               fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
1103               CHARS (IDENTIFIER_LENGTH (name) + 2);
1104               need_prefix = 0;
1105             }
1106
1107           dbxout_type (TREE_TYPE (fndecl), 0);
1108
1109           dbxout_type_method_1 (fndecl, debug_name);
1110         }
1111       if (!need_prefix)
1112         {
1113           putc (';', asmfile);
1114           CHARS (1);
1115         }
1116     }
1117 }
1118
1119 /* Emit a "range" type specification, which has the form:
1120    "r<index type>;<lower bound>;<upper bound>;".
1121    TYPE is an INTEGER_TYPE.  */
1122
1123 static void
1124 dbxout_range_type (tree type)
1125 {
1126   fprintf (asmfile, "r");
1127   if (TREE_TYPE (type))
1128     dbxout_type (TREE_TYPE (type), 0);
1129   else if (TREE_CODE (type) != INTEGER_TYPE)
1130     dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
1131   else
1132     {
1133       /* Traditionally, we made sure 'int' was type 1, and builtin types
1134          were defined to be sub-ranges of int.  Unfortunately, this
1135          does not allow us to distinguish true sub-ranges from integer
1136          types.  So, instead we define integer (non-sub-range) types as
1137          sub-ranges of themselves.  This matters for Chill.  If this isn't
1138          a subrange type, then we want to define it in terms of itself.
1139          However, in C, this may be an anonymous integer type, and we don't
1140          want to emit debug info referring to it.  Just calling
1141          dbxout_type_index won't work anyways, because the type hasn't been
1142          defined yet.  We make this work for both cases by checked to see
1143          whether this is a defined type, referring to it if it is, and using
1144          'int' otherwise.  */
1145       if (TYPE_SYMTAB_ADDRESS (type) != 0)
1146         dbxout_type_index (type);
1147       else
1148         dbxout_type_index (integer_type_node);
1149     }
1150
1151   if (TYPE_MIN_VALUE (type) != 0
1152       && host_integerp (TYPE_MIN_VALUE (type), 0))
1153     {
1154       putc (';', asmfile);
1155       CHARS (1);
1156       if (print_int_cst_bounds_in_octal_p (type))
1157         print_int_cst_octal (TYPE_MIN_VALUE (type));
1158       else
1159         print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1160     }
1161   else
1162     {
1163       fprintf (asmfile, ";0");
1164       CHARS (2);
1165     }
1166
1167   if (TYPE_MAX_VALUE (type) != 0
1168       && host_integerp (TYPE_MAX_VALUE (type), 0))
1169     {
1170       putc (';', asmfile);
1171       CHARS (1);
1172       if (print_int_cst_bounds_in_octal_p (type))
1173         print_int_cst_octal (TYPE_MAX_VALUE (type));
1174       else
1175         print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1176       putc (';', asmfile);
1177       CHARS (1);
1178     }
1179   else
1180     {
1181       fprintf (asmfile, ";-1;");
1182       CHARS (4);
1183     }
1184 }
1185 \f
1186
1187 /* Output a reference to a type.  If the type has not yet been
1188    described in the dbx output, output its definition now.
1189    For a type already defined, just refer to its definition
1190    using the type number.
1191
1192    If FULL is nonzero, and the type has been described only with
1193    a forward-reference, output the definition now.
1194    If FULL is zero in this case, just refer to the forward-reference
1195    using the number previously allocated.  */
1196
1197 static void
1198 dbxout_type (tree type, int full)
1199 {
1200   tree tem;
1201   tree main_variant;
1202   static int anonymous_type_number = 0;
1203
1204   if (TREE_CODE (type) == VECTOR_TYPE)
1205     /* The frontend feeds us a representation for the vector as a struct
1206        containing an array.  Pull out the array type.  */
1207     type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type)));
1208
1209   /* If there was an input error and we don't really have a type,
1210      avoid crashing and write something that is at least valid
1211      by assuming `int'.  */
1212   if (type == error_mark_node)
1213     type = integer_type_node;
1214   else
1215     {
1216       if (TYPE_NAME (type)
1217           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1218           && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1219         full = 0;
1220     }
1221
1222   /* Try to find the "main variant" with the same name.  */
1223   if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1224       && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1225     main_variant = TREE_TYPE (TYPE_NAME (type));
1226   else
1227     main_variant = TYPE_MAIN_VARIANT (type);
1228
1229   /* If we are not using extensions, stabs does not distinguish const and
1230      volatile, so there is no need to make them separate types.  */
1231   if (!use_gnu_debug_info_extensions)
1232     type = main_variant;
1233
1234   if (TYPE_SYMTAB_ADDRESS (type) == 0)
1235     {
1236       /* Type has no dbx number assigned.  Assign next available number.  */
1237       TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1238
1239       /* Make sure type vector is long enough to record about this type.  */
1240
1241       if (next_type_number == typevec_len)
1242         {
1243           typevec
1244             = ggc_realloc (typevec, (typevec_len * 2 * sizeof typevec[0]));
1245           memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]);
1246           typevec_len *= 2;
1247         }
1248
1249 #ifdef DBX_USE_BINCL
1250       emit_pending_bincls_if_required ();
1251       typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1252         = current_file->file_number;
1253       typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1254         = current_file->next_type_number++;
1255 #endif
1256     }
1257
1258   if (flag_debug_only_used_symbols)
1259     {
1260       if ((TREE_CODE (type) == RECORD_TYPE
1261            || TREE_CODE (type) == UNION_TYPE
1262            || TREE_CODE (type) == QUAL_UNION_TYPE
1263            || TREE_CODE (type) == ENUMERAL_TYPE)
1264           && TYPE_STUB_DECL (type)
1265           && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (type))) == 'd'
1266           && ! DECL_IGNORED_P (TYPE_STUB_DECL (type)))
1267         debug_queue_symbol (TYPE_STUB_DECL (type));
1268       else if (TYPE_NAME (type)
1269                && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1270         debug_queue_symbol (TYPE_NAME (type));
1271     }
1272
1273   /* Output the number of this type, to refer to it.  */
1274   dbxout_type_index (type);
1275
1276 #ifdef DBX_TYPE_DEFINED
1277   if (DBX_TYPE_DEFINED (type))
1278     return;
1279 #endif
1280
1281   /* If this type's definition has been output or is now being output,
1282      that is all.  */
1283
1284   switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1285     {
1286     case TYPE_UNSEEN:
1287       break;
1288     case TYPE_XREF:
1289       /* If we have already had a cross reference,
1290          and either that's all we want or that's the best we could do,
1291          don't repeat the cross reference.
1292          Sun dbx crashes if we do.  */
1293       if (! full || !COMPLETE_TYPE_P (type)
1294           /* No way in DBX fmt to describe a variable size.  */
1295           || ! host_integerp (TYPE_SIZE (type), 1))
1296         return;
1297       break;
1298     case TYPE_DEFINED:
1299       return;
1300     }
1301
1302 #ifdef DBX_NO_XREFS
1303   /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1304      leave the type-number completely undefined rather than output
1305      a cross-reference.  If we have already used GNU debug info extensions,
1306      then it is OK to output a cross reference.  This is necessary to get
1307      proper C++ debug output.  */
1308   if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1309        || TREE_CODE (type) == QUAL_UNION_TYPE
1310        || TREE_CODE (type) == ENUMERAL_TYPE)
1311       && ! use_gnu_debug_info_extensions)
1312     /* We must use the same test here as we use twice below when deciding
1313        whether to emit a cross-reference.  */
1314     if ((TYPE_NAME (type) != 0
1315          && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1316                && DECL_IGNORED_P (TYPE_NAME (type)))
1317          && !full)
1318         || !COMPLETE_TYPE_P (type)
1319         /* No way in DBX fmt to describe a variable size.  */
1320         || ! host_integerp (TYPE_SIZE (type), 1))
1321       {
1322         typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1323         return;
1324       }
1325 #endif
1326
1327   /* Output a definition now.  */
1328
1329   fprintf (asmfile, "=");
1330   CHARS (1);
1331
1332   /* Mark it as defined, so that if it is self-referent
1333      we will not get into an infinite recursion of definitions.  */
1334
1335   typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1336
1337   /* If this type is a variant of some other, hand off.  Types with
1338      different names are usefully distinguished.  We only distinguish
1339      cv-qualified types if we're using extensions.  */
1340   if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1341     {
1342       putc ('k', asmfile);
1343       CHARS (1);
1344       dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1345       return;
1346     }
1347   else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1348     {
1349       putc ('B', asmfile);
1350       CHARS (1);
1351       dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1352       return;
1353     }
1354   else if (main_variant != TYPE_MAIN_VARIANT (type))
1355     {
1356       if (flag_debug_only_used_symbols)
1357         {
1358           tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type));
1359
1360           if ((TREE_CODE (orig_type) == RECORD_TYPE
1361                || TREE_CODE (orig_type) == UNION_TYPE
1362                || TREE_CODE (orig_type) == QUAL_UNION_TYPE
1363                || TREE_CODE (orig_type) == ENUMERAL_TYPE)
1364               && TYPE_STUB_DECL (orig_type)
1365               && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type)))
1366             debug_queue_symbol (TYPE_STUB_DECL (orig_type));
1367         }
1368       /* 'type' is a typedef; output the type it refers to.  */
1369       dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1370       return;
1371     }
1372   /* else continue.  */
1373
1374   switch (TREE_CODE (type))
1375     {
1376     case VOID_TYPE:
1377     case LANG_TYPE:
1378       /* For a void type, just define it as itself; ie, "5=5".
1379          This makes us consider it defined
1380          without saying what it is.  The debugger will make it
1381          a void type when the reference is seen, and nothing will
1382          ever override that default.  */
1383       dbxout_type_index (type);
1384       break;
1385
1386     case INTEGER_TYPE:
1387       if (type == char_type_node && ! TREE_UNSIGNED (type))
1388         {
1389           /* Output the type `char' as a subrange of itself!
1390              I don't understand this definition, just copied it
1391              from the output of pcc.
1392              This used to use `r2' explicitly and we used to
1393              take care to make sure that `char' was type number 2.  */
1394           fprintf (asmfile, "r");
1395           CHARS (1);
1396           dbxout_type_index (type);
1397           fprintf (asmfile, ";0;127;");
1398           CHARS (7);
1399         }
1400
1401       /* If this is a subtype of another integer type, always prefer to
1402          write it as a subtype.  */
1403       else if (TREE_TYPE (type) != 0
1404                && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1405         {
1406           /* If the size is non-standard, say what it is if we can use
1407              GDB extensions.  */
1408
1409           if (use_gnu_debug_info_extensions
1410               && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1411             {
1412               have_used_extensions = 1;
1413               fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1414               CHARS (5);
1415             }
1416
1417           dbxout_range_type (type);
1418         }
1419
1420       else
1421         {
1422           /* If the size is non-standard, say what it is if we can use
1423              GDB extensions.  */
1424
1425           if (use_gnu_debug_info_extensions
1426               && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1427             {
1428               have_used_extensions = 1;
1429               fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1430               CHARS (5);
1431             }
1432
1433           if (print_int_cst_bounds_in_octal_p (type))
1434             {
1435               fprintf (asmfile, "r");
1436               CHARS (1);
1437
1438               /* If this type derives from another type, output type index of
1439                  parent type. This is particularly important when parent type
1440                  is an enumerated type, because not generating the parent type
1441                  index would transform the definition of this enumerated type
1442                  into a plain unsigned type.  */
1443               if (TREE_TYPE (type) != 0)
1444                 dbxout_type_index (TREE_TYPE (type));
1445               else
1446                 dbxout_type_index (type);
1447
1448               fprintf (asmfile, ";");
1449               CHARS (1);
1450               print_int_cst_octal (TYPE_MIN_VALUE (type));
1451               fprintf (asmfile, ";");
1452               CHARS (1);
1453               print_int_cst_octal (TYPE_MAX_VALUE (type));
1454               fprintf (asmfile, ";");
1455               CHARS (1);
1456             }
1457
1458           else
1459             /* Output other integer types as subranges of `int'.  */
1460             dbxout_range_type (type);
1461         }
1462
1463       break;
1464
1465     case REAL_TYPE:
1466       /* This used to say `r1' and we used to take care
1467          to make sure that `int' was type number 1.  */
1468       fprintf (asmfile, "r");
1469       CHARS (1);
1470       dbxout_type_index (integer_type_node);
1471       putc (';', asmfile);
1472       CHARS (1);
1473       print_wide_int (int_size_in_bytes (type));
1474       fputs (";0;", asmfile);
1475       CHARS (3);
1476       break;
1477
1478     case CHAR_TYPE:
1479       if (use_gnu_debug_info_extensions)
1480         {
1481           have_used_extensions = 1;
1482           fputs ("@s", asmfile);
1483           CHARS (2);
1484           print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1485           fputs (";-20;", asmfile);
1486           CHARS (4);
1487         }
1488       else
1489         {
1490           /* Output the type `char' as a subrange of itself.
1491              That is what pcc seems to do.  */
1492           fprintf (asmfile, "r");
1493           CHARS (1);
1494           dbxout_type_index (char_type_node);
1495           fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1496           CHARS (7);
1497         }
1498       break;
1499
1500     case BOOLEAN_TYPE:
1501       if (use_gnu_debug_info_extensions)
1502         {
1503           have_used_extensions = 1;
1504           fputs ("@s", asmfile);
1505           CHARS (2);
1506           print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1507           fputs (";-16;", asmfile);
1508           CHARS (4);
1509         }
1510       else /* Define as enumeral type (False, True) */
1511         {
1512           fprintf (asmfile, "eFalse:0,True:1,;");
1513           CHARS (17);
1514         }
1515       break;
1516
1517     case FILE_TYPE:
1518       putc ('d', asmfile);
1519       CHARS (1);
1520       dbxout_type (TREE_TYPE (type), 0);
1521       break;
1522
1523     case COMPLEX_TYPE:
1524       /* Differs from the REAL_TYPE by its new data type number.
1525          R3 is NF_COMPLEX.  We don't try to use any of the other NF_*
1526          codes since gdb doesn't care anyway.  */
1527
1528       if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1529         {
1530           fputs ("R3;", asmfile);
1531           CHARS (3);
1532           print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1533           fputs (";0;", asmfile);
1534           CHARS (3);
1535         }
1536       else
1537         {
1538           /* Output a complex integer type as a structure,
1539              pending some other way to do it.  */
1540           putc ('s', asmfile);
1541           CHARS (1);
1542           print_wide_int (int_size_in_bytes (type));
1543           fprintf (asmfile, "real:");
1544           CHARS (5);
1545
1546           dbxout_type (TREE_TYPE (type), 0);
1547           fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1548           CHARS (7);
1549           fprintf (asmfile, "imag:");
1550           CHARS (5);
1551           dbxout_type (TREE_TYPE (type), 0);
1552           fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1553                    TYPE_PRECISION (TREE_TYPE (type)));
1554           CHARS (10);
1555         }
1556       break;
1557
1558     case SET_TYPE:
1559       if (use_gnu_debug_info_extensions)
1560         {
1561           have_used_extensions = 1;
1562           fputs ("@s", asmfile);
1563           CHARS (2);
1564           print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1565           putc (';', asmfile);
1566           CHARS (1);
1567
1568           /* Check if a bitstring type, which in Chill is
1569              different from a [power]set.  */
1570           if (TYPE_STRING_FLAG (type))
1571             {
1572               fprintf (asmfile, "@S;");
1573               CHARS (3);
1574             }
1575         }
1576       putc ('S', asmfile);
1577       CHARS (1);
1578       dbxout_type (TYPE_DOMAIN (type), 0);
1579       break;
1580
1581     case ARRAY_TYPE:
1582       /* Make arrays of packed bits look like bitstrings for chill.  */
1583       if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1584         {
1585           have_used_extensions = 1;
1586           fputs ("@s", asmfile);
1587           CHARS (2);
1588           print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1589           fprintf (asmfile, ";@S;S");
1590           CHARS (5);
1591           dbxout_type (TYPE_DOMAIN (type), 0);
1592           break;
1593         }
1594
1595       /* Output "a" followed by a range type definition
1596          for the index type of the array
1597          followed by a reference to the target-type.
1598          ar1;0;N;M for a C array of type M and size N+1.  */
1599       /* Check if a character string type, which in Chill is
1600          different from an array of characters.  */
1601       if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1602         {
1603           have_used_extensions = 1;
1604           fprintf (asmfile, "@S;");
1605           CHARS (3);
1606         }
1607       tem = TYPE_DOMAIN (type);
1608       if (tem == NULL)
1609         {
1610           fprintf (asmfile, "ar");
1611           CHARS (2);
1612           dbxout_type_index (integer_type_node);
1613           fprintf (asmfile, ";0;-1;");
1614           CHARS (6);
1615         }
1616       else
1617         {
1618           fprintf (asmfile, "a");
1619           CHARS (1);
1620           dbxout_range_type (tem);
1621         }
1622
1623       dbxout_type (TREE_TYPE (type), 0);
1624       break;
1625
1626     case RECORD_TYPE:
1627     case UNION_TYPE:
1628     case QUAL_UNION_TYPE:
1629       {
1630         int i, n_baseclasses = 0;
1631
1632         if (TYPE_BINFO (type) != 0
1633             && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1634             && TYPE_BINFO_BASETYPES (type) != 0)
1635           n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1636
1637         /* Output a structure type.  We must use the same test here as we
1638            use in the DBX_NO_XREFS case above.  */
1639         if ((TYPE_NAME (type) != 0
1640              && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1641                    && DECL_IGNORED_P (TYPE_NAME (type)))
1642              && !full)
1643             || !COMPLETE_TYPE_P (type)
1644             /* No way in DBX fmt to describe a variable size.  */
1645             || ! host_integerp (TYPE_SIZE (type), 1))
1646           {
1647             /* If the type is just a cross reference, output one
1648                and mark the type as partially described.
1649                If it later becomes defined, we will output
1650                its real definition.
1651                If the type has a name, don't nest its definition within
1652                another type's definition; instead, output an xref
1653                and let the definition come when the name is defined.  */
1654             fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1655             CHARS (2);
1656 #if 0 /* This assertion is legitimately false in C++.  */
1657             /* We shouldn't be outputting a reference to a type before its
1658                definition unless the type has a tag name.
1659                A typedef name without a tag name should be impossible.  */
1660             if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1661               abort ();
1662 #endif
1663             if (TYPE_NAME (type) != 0)
1664               dbxout_type_name (type);
1665             else
1666               {
1667                 fprintf (asmfile, "$$%d", anonymous_type_number++);
1668                 CHARS (5);
1669               }
1670
1671             fprintf (asmfile, ":");
1672             CHARS (1);
1673             typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1674             break;
1675           }
1676
1677         /* Identify record or union, and print its size.  */
1678         putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1679         CHARS (1);
1680         print_wide_int (int_size_in_bytes (type));
1681
1682         if (use_gnu_debug_info_extensions)
1683           {
1684             if (n_baseclasses)
1685               {
1686                 have_used_extensions = 1;
1687                 fprintf (asmfile, "!%d,", n_baseclasses);
1688                 CHARS (8);
1689               }
1690           }
1691         for (i = 0; i < n_baseclasses; i++)
1692           {
1693             tree binfo = TYPE_BINFO (type);
1694             tree child = BINFO_BASETYPE (binfo, i);
1695             tree access = (BINFO_BASEACCESSES (binfo)
1696                            ? BINFO_BASEACCESS (binfo, i) : access_public_node);
1697
1698             if (use_gnu_debug_info_extensions)
1699               {
1700                 have_used_extensions = 1;
1701                 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1702                 putc (access == access_public_node ? '2' :
1703                       (access == access_protected_node ? '1' :'0'),
1704                       asmfile);
1705                 CHARS (2);
1706                 if (TREE_VIA_VIRTUAL (child)
1707                     && strcmp (lang_hooks.name, "GNU C++") == 0)
1708                   /* For a virtual base, print the (negative) offset within
1709                      the vtable where we must look to find the necessary
1710                      adjustment.  */
1711                   print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1712                                   * BITS_PER_UNIT);
1713                 else
1714                   print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1715                                   * BITS_PER_UNIT);
1716                 putc (',', asmfile);
1717                 CHARS (1);
1718                 dbxout_type (BINFO_TYPE (child), 0);
1719                 putc (';', asmfile);
1720                 CHARS (1);
1721               }
1722             else
1723               {
1724                 /* Print out the base class information with fields
1725                    which have the same names at the types they hold.  */
1726                 dbxout_type_name (BINFO_TYPE (child));
1727                 putc (':', asmfile);
1728                 CHARS (1);
1729                 dbxout_type (BINFO_TYPE (child), full);
1730                 putc (',', asmfile);
1731                 CHARS (1);
1732                 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1733                                 * BITS_PER_UNIT);
1734                 putc (',', asmfile);
1735                 CHARS (1);
1736                 print_wide_int (tree_low_cst (TYPE_SIZE (BINFO_TYPE (child)),
1737                                               0)
1738                                 * BITS_PER_UNIT);
1739                 putc (';', asmfile);
1740                 CHARS (1);
1741               }
1742           }
1743       }
1744
1745       /* Write out the field declarations.  */
1746       dbxout_type_fields (type);
1747       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1748         {
1749           have_used_extensions = 1;
1750           dbxout_type_methods (type);
1751         }
1752
1753       putc (';', asmfile);
1754       CHARS (1);
1755
1756       if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1757           /* Avoid the ~ if we don't really need it--it confuses dbx.  */
1758           && TYPE_VFIELD (type))
1759         {
1760           have_used_extensions = 1;
1761
1762           /* Tell GDB+ that it may keep reading.  */
1763           putc ('~', asmfile);
1764           CHARS (1);
1765
1766           /* We need to write out info about what field this class
1767              uses as its "main" vtable pointer field, because if this
1768              field is inherited from a base class, GDB cannot necessarily
1769              figure out which field it's using in time.  */
1770           if (TYPE_VFIELD (type))
1771             {
1772               putc ('%', asmfile);
1773               CHARS (1);
1774               dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1775             }
1776
1777           putc (';', asmfile);
1778           CHARS (1);
1779         }
1780       break;
1781
1782     case ENUMERAL_TYPE:
1783       /* We must use the same test here as we use in the DBX_NO_XREFS case
1784          above.  We simplify it a bit since an enum will never have a variable
1785          size.  */
1786       if ((TYPE_NAME (type) != 0
1787            && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1788                  && DECL_IGNORED_P (TYPE_NAME (type)))
1789            && !full)
1790           || !COMPLETE_TYPE_P (type))
1791         {
1792           fprintf (asmfile, "xe");
1793           CHARS (2);
1794           dbxout_type_name (type);
1795           typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1796           putc (':', asmfile);
1797           CHARS (1);
1798           return;
1799         }
1800       if (use_gnu_debug_info_extensions
1801           && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1802         {
1803           fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1804           CHARS (5);
1805         }
1806
1807       putc ('e', asmfile);
1808       CHARS (1);
1809       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1810         {
1811           fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1812           CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1813           if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1814             print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1815           else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1816                    && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1817             print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1818           else
1819             print_int_cst_octal (TREE_VALUE (tem));
1820
1821           putc (',', asmfile);
1822           CHARS (1);
1823           if (TREE_CHAIN (tem) != 0)
1824             CONTIN;
1825         }
1826
1827       putc (';', asmfile);
1828       CHARS (1);
1829       break;
1830
1831     case POINTER_TYPE:
1832       putc ('*', asmfile);
1833       CHARS (1);
1834       dbxout_type (TREE_TYPE (type), 0);
1835       break;
1836
1837     case METHOD_TYPE:
1838       if (use_gnu_debug_info_extensions)
1839         {
1840           have_used_extensions = 1;
1841           putc ('#', asmfile);
1842           CHARS (1);
1843
1844           /* Write the argument types out longhand.  */
1845           dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1846           putc (',', asmfile);
1847           CHARS (1);
1848           dbxout_type (TREE_TYPE (type), 0);
1849           dbxout_args (TYPE_ARG_TYPES (type));
1850           putc (';', asmfile);
1851           CHARS (1);
1852         }
1853       else
1854         /* Treat it as a function type.  */
1855         dbxout_type (TREE_TYPE (type), 0);
1856       break;
1857
1858     case OFFSET_TYPE:
1859       if (use_gnu_debug_info_extensions)
1860         {
1861           have_used_extensions = 1;
1862           putc ('@', asmfile);
1863           CHARS (1);
1864           dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1865           putc (',', asmfile);
1866           CHARS (1);
1867           dbxout_type (TREE_TYPE (type), 0);
1868         }
1869       else
1870         /* Should print as an int, because it is really just an offset.  */
1871         dbxout_type (integer_type_node, 0);
1872       break;
1873
1874     case REFERENCE_TYPE:
1875       if (use_gnu_debug_info_extensions)
1876         have_used_extensions = 1;
1877       putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1878       CHARS (1);
1879       dbxout_type (TREE_TYPE (type), 0);
1880       break;
1881
1882     case FUNCTION_TYPE:
1883       putc ('f', asmfile);
1884       CHARS (1);
1885       dbxout_type (TREE_TYPE (type), 0);
1886       break;
1887
1888     default:
1889       abort ();
1890     }
1891 }
1892
1893 /* Return nonzero if the given type represents an integer whose bounds
1894    should be printed in octal format.  */
1895
1896 static bool
1897 print_int_cst_bounds_in_octal_p (tree type)
1898 {
1899   /* If we can use GDB extensions and the size is wider than a long
1900      (the size used by GDB to read them) or we may have trouble writing
1901      the bounds the usual way, write them in octal.  Note the test is for
1902      the *target's* size of "long", not that of the host.  The host test
1903      is just to make sure we can write it out in case the host wide int
1904      is narrower than the target "long".
1905
1906      For unsigned types, we use octal if they are the same size or larger.
1907      This is because we print the bounds as signed decimal, and hence they
1908      can't span same size unsigned types.  */
1909
1910   if (use_gnu_debug_info_extensions
1911       && TYPE_MIN_VALUE (type) != 0
1912       && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1913       && TYPE_MAX_VALUE (type) != 0
1914       && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1915       && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1916           || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node))
1917               && TREE_UNSIGNED (type))
1918           || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1919           || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1920               && TREE_UNSIGNED (type))))
1921     return TRUE;
1922   else
1923     return FALSE;
1924 }
1925
1926 /* Print the value of integer constant C, in octal,
1927    handling double precision.  */
1928
1929 static void
1930 print_int_cst_octal (tree c)
1931 {
1932   unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1933   unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1934   int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1935   unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1936
1937   /* GDB wants constants with no extra leading "1" bits, so
1938      we need to remove any sign-extension that might be
1939      present.  */
1940   if (width == HOST_BITS_PER_WIDE_INT * 2)
1941     ;
1942   else if (width > HOST_BITS_PER_WIDE_INT)
1943     high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1944   else if (width == HOST_BITS_PER_WIDE_INT)
1945     high = 0;
1946   else
1947     high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1948
1949   fprintf (asmfile, "0");
1950   CHARS (1);
1951
1952   if (excess == 3)
1953     {
1954       print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1955       print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1956     }
1957   else
1958     {
1959       unsigned HOST_WIDE_INT beg = high >> excess;
1960       unsigned HOST_WIDE_INT middle
1961         = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1962            | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1963       unsigned HOST_WIDE_INT end
1964         = low & (((unsigned HOST_WIDE_INT) 1
1965                   << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1966                  - 1);
1967
1968       fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1969       CHARS (2);
1970       print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1971     }
1972 }
1973
1974 static void
1975 print_octal (unsigned HOST_WIDE_INT value, int digits)
1976 {
1977   int i;
1978
1979   for (i = digits - 1; i >= 0; i--)
1980     fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1981
1982   CHARS (digits);
1983 }
1984
1985 /* Output C in decimal while adjusting the number of digits written.  */
1986
1987 static void
1988 print_wide_int (HOST_WIDE_INT c)
1989 {
1990   int digs = 0;
1991
1992   fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1993
1994   if (c < 0)
1995     digs++, c = -c;
1996
1997   while (c > 0)
1998     c /= 10; digs++;
1999
2000   CHARS (digs);
2001 }
2002
2003 /* Output the name of type TYPE, with no punctuation.
2004    Such names can be set up either by typedef declarations
2005    or by struct, enum and union tags.  */
2006
2007 static void
2008 dbxout_type_name (tree type)
2009 {
2010   tree t;
2011   if (TYPE_NAME (type) == 0)
2012     abort ();
2013   if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
2014     {
2015       t = TYPE_NAME (type);
2016     }
2017   else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
2018     {
2019       t = DECL_NAME (TYPE_NAME (type));
2020     }
2021   else
2022     abort ();
2023
2024   fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
2025   CHARS (IDENTIFIER_LENGTH (t));
2026 }
2027
2028 /* Output leading leading struct or class names needed for qualifying
2029    type whose scope is limited to a struct or class.  */
2030
2031 static void
2032 dbxout_class_name_qualifiers (tree decl)
2033 {
2034   tree context = decl_type_context (decl);
2035
2036   if (context != NULL_TREE
2037       && TREE_CODE(context) == RECORD_TYPE
2038       && TYPE_NAME (context) != 0
2039       && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE
2040           || (DECL_NAME (TYPE_NAME (context)) != 0)))
2041     {
2042       tree name = TYPE_NAME (context);
2043
2044       emit_pending_bincls_if_required ();
2045
2046       if (TREE_CODE (name) == TYPE_DECL)
2047         {
2048           dbxout_class_name_qualifiers (name);
2049           name = DECL_NAME (name);
2050         }
2051       fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
2052       CHARS (IDENTIFIER_LENGTH (name) + 2);
2053     }
2054 }
2055 \f
2056 /* Output a .stabs for the symbol defined by DECL,
2057    which must be a ..._DECL node in the normal namespace.
2058    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
2059    LOCAL is nonzero if the scope is less than the entire file.
2060    Return 1 if a stabs might have been emitted.  */
2061
2062 int
2063 dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED)
2064 {
2065   tree type = TREE_TYPE (decl);
2066   tree context = NULL_TREE;
2067   int result = 0;
2068
2069   /* "Intercept" dbxout_symbol() calls like we do all debug_hooks.  */
2070   ++debug_nesting;
2071
2072   /* Ignore nameless syms, but don't ignore type tags.  */
2073
2074   if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
2075       || DECL_IGNORED_P (decl))
2076     DBXOUT_DECR_NESTING_AND_RETURN (0);
2077
2078   /* If we are to generate only the symbols actually used then such
2079      symbol nodees are flagged with TREE_USED.  Ignore any that
2080      aren't flaged as TREE_USED.  */
2081
2082   if (flag_debug_only_used_symbols
2083       && (!TREE_USED (decl)
2084           && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl))))
2085     DBXOUT_DECR_NESTING_AND_RETURN (0);
2086
2087   /* If dbxout_init has not yet run, queue this symbol for later.  */
2088   if (!typevec)
2089     {
2090       preinit_symbols = tree_cons (0, decl, preinit_symbols);
2091       DBXOUT_DECR_NESTING_AND_RETURN (0);
2092     }
2093
2094   if (flag_debug_only_used_symbols)
2095     {
2096       tree t;
2097
2098       /* We now have a used symbol.  We need to generate the info for
2099          the symbol's type in addition to the symbol itself.  These
2100          type symbols are queued to be generated after were done with
2101          the symbol itself (done because the symbol's info is generated
2102          with fprintf's, etc. as it determines what's needed).
2103
2104          Note, because the TREE_TYPE(type) might be something like a
2105          pointer to a named type we need to look for the first name
2106          we see following the TREE_TYPE chain.  */
2107
2108       t = type;
2109       while (POINTER_TYPE_P (t))
2110         t = TREE_TYPE (t);
2111
2112       /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE
2113          need special treatment.  The TYPE_STUB_DECL field in these
2114          types generally represents the tag name type we want to
2115          output.  In addition there  could be a typedef type with
2116          a different name.  In that case we also want to output
2117          that.  */
2118
2119       if ((TREE_CODE (t) == RECORD_TYPE
2120            || TREE_CODE (t) == UNION_TYPE
2121            || TREE_CODE (t) == QUAL_UNION_TYPE
2122            || TREE_CODE (t) == ENUMERAL_TYPE)
2123           && TYPE_STUB_DECL (t)
2124           && TYPE_STUB_DECL (t) != decl
2125           && TREE_CODE_CLASS (TREE_CODE (TYPE_STUB_DECL (t))) == 'd'
2126           && ! DECL_IGNORED_P (TYPE_STUB_DECL (t)))
2127         {
2128           debug_queue_symbol (TYPE_STUB_DECL (t));
2129           if (TYPE_NAME (t)
2130               && TYPE_NAME (t) != TYPE_STUB_DECL (t)
2131               && TYPE_NAME (t) != decl
2132               && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2133             debug_queue_symbol (TYPE_NAME (t));
2134         }
2135       else if (TYPE_NAME (t)
2136                && TYPE_NAME (t) != decl
2137                && TREE_CODE_CLASS (TREE_CODE (TYPE_NAME (t))) == 'd')
2138         debug_queue_symbol (TYPE_NAME (t));
2139     }
2140
2141   emit_pending_bincls_if_required ();
2142
2143   dbxout_prepare_symbol (decl);
2144
2145   /* The output will always start with the symbol name,
2146      so always count that in the length-output-so-far.  */
2147
2148   if (DECL_NAME (decl) != 0)
2149     current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
2150
2151   switch (TREE_CODE (decl))
2152     {
2153     case CONST_DECL:
2154       /* Enum values are defined by defining the enum type.  */
2155       break;
2156
2157     case FUNCTION_DECL:
2158       if (DECL_RTL (decl) == 0)
2159         DBXOUT_DECR_NESTING_AND_RETURN (0);
2160       if (DECL_EXTERNAL (decl))
2161         break;
2162       /* Don't mention a nested function under its parent.  */
2163       context = decl_function_context (decl);
2164       if (context == current_function_decl)
2165         break;
2166       if (GET_CODE (DECL_RTL (decl)) != MEM
2167           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
2168         break;
2169       FORCE_TEXT;
2170
2171       fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2172                IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2173                TREE_PUBLIC (decl) ? 'F' : 'f');
2174       result = 1;
2175
2176       current_sym_code = N_FUN;
2177       current_sym_addr = XEXP (DECL_RTL (decl), 0);
2178
2179       if (TREE_TYPE (type))
2180         dbxout_type (TREE_TYPE (type), 0);
2181       else
2182         dbxout_type (void_type_node, 0);
2183
2184       /* For a nested function, when that function is compiled,
2185          mention the containing function name
2186          as well as (since dbx wants it) our own assembler-name.  */
2187       if (context != 0)
2188         fprintf (asmfile, ",%s,%s",
2189                  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
2190                  IDENTIFIER_POINTER (DECL_NAME (context)));
2191
2192       dbxout_finish_symbol (decl);
2193       break;
2194
2195     case TYPE_DECL:
2196       /* Don't output the same typedef twice.
2197          And don't output what language-specific stuff doesn't want output.  */
2198       if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
2199         DBXOUT_DECR_NESTING_AND_RETURN (0);
2200
2201       /* Don't output typedefs for types with magic type numbers (XCOFF).  */
2202 #ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER
2203       {
2204         int fundamental_type_number =
2205           DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl);
2206
2207         if (fundamental_type_number != 0)
2208           {
2209             TREE_ASM_WRITTEN (decl) = 1;
2210             TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number;
2211             DBXOUT_DECR_NESTING_AND_RETURN (0);
2212           }
2213       }
2214 #endif
2215       FORCE_TEXT;
2216       result = 1;
2217       {
2218         int tag_needed = 1;
2219         int did_output = 0;
2220
2221         if (DECL_NAME (decl))
2222           {
2223             /* Nonzero means we must output a tag as well as a typedef.  */
2224             tag_needed = 0;
2225
2226             /* Handle the case of a C++ structure or union
2227                where the TYPE_NAME is a TYPE_DECL
2228                which gives both a typedef name and a tag.  */
2229             /* dbx requires the tag first and the typedef second.  */
2230             if ((TREE_CODE (type) == RECORD_TYPE
2231                  || TREE_CODE (type) == UNION_TYPE
2232                  || TREE_CODE (type) == QUAL_UNION_TYPE)
2233                 && TYPE_NAME (type) == decl
2234                 && !(use_gnu_debug_info_extensions && have_used_extensions)
2235                 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
2236                 /* Distinguish the implicit typedefs of C++
2237                    from explicit ones that might be found in C.  */
2238                 && DECL_ARTIFICIAL (decl)
2239                 /* Do not generate a tag for incomplete records.  */
2240                 && COMPLETE_TYPE_P (type)
2241                 /* Do not generate a tag for records of variable size,
2242                    since this type can not be properly described in the
2243                    DBX format, and it confuses some tools such as objdump.  */
2244                 && host_integerp (TYPE_SIZE (type), 1))
2245               {
2246                 tree name = TYPE_NAME (type);
2247                 if (TREE_CODE (name) == TYPE_DECL)
2248                   name = DECL_NAME (name);
2249
2250                 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2251                 current_sym_value = 0;
2252                 current_sym_addr = 0;
2253                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2254
2255                 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2256                          IDENTIFIER_POINTER (name));
2257                 dbxout_type (type, 1);
2258                 dbxout_finish_symbol (NULL_TREE);
2259               }
2260
2261             /* Output .stabs (or whatever) and leading double quote.  */
2262             fprintf (asmfile, "%s\"", ASM_STABS_OP);
2263
2264             if (use_gnu_debug_info_extensions)
2265               {
2266                 /* Output leading class/struct qualifiers.  */
2267                 dbxout_class_name_qualifiers (decl);
2268               }
2269
2270             /* Output typedef name.  */
2271             fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (decl)));
2272
2273             /* Short cut way to output a tag also.  */
2274             if ((TREE_CODE (type) == RECORD_TYPE
2275                  || TREE_CODE (type) == UNION_TYPE
2276                  || TREE_CODE (type) == QUAL_UNION_TYPE)
2277                 && TYPE_NAME (type) == decl
2278                 /* Distinguish the implicit typedefs of C++
2279                    from explicit ones that might be found in C.  */
2280                 && DECL_ARTIFICIAL (decl))
2281               {
2282                 if (use_gnu_debug_info_extensions && have_used_extensions)
2283                   {
2284                     putc ('T', asmfile);
2285                     TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
2286                   }
2287 #if 0 /* Now we generate the tag for this case up above.  */
2288                 else
2289                   tag_needed = 1;
2290 #endif
2291               }
2292
2293             putc ('t', asmfile);
2294             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2295
2296             dbxout_type (type, 1);
2297             dbxout_finish_symbol (decl);
2298             did_output = 1;
2299           }
2300
2301         /* Don't output a tag if this is an incomplete type.  This prevents
2302            the sun4 Sun OS 4.x dbx from crashing.  */
2303
2304         if (tag_needed && TYPE_NAME (type) != 0
2305             && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2306                 || (DECL_NAME (TYPE_NAME (type)) != 0))
2307             && COMPLETE_TYPE_P (type)
2308             && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2309           {
2310             /* For a TYPE_DECL with no name, but the type has a name,
2311                output a tag.
2312                This is what represents `struct foo' with no typedef.  */
2313             /* In C++, the name of a type is the corresponding typedef.
2314                In C, it is an IDENTIFIER_NODE.  */
2315             tree name = TYPE_NAME (type);
2316             if (TREE_CODE (name) == TYPE_DECL)
2317               name = DECL_NAME (name);
2318
2319             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2320             current_sym_value = 0;
2321             current_sym_addr = 0;
2322             current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2323
2324             fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2325                      IDENTIFIER_POINTER (name));
2326             dbxout_type (type, 1);
2327             dbxout_finish_symbol (NULL_TREE);
2328             did_output = 1;
2329           }
2330
2331         /* If an enum type has no name, it cannot be referred to,
2332            but we must output it anyway, since the enumeration constants
2333            can be referred to.  */
2334         if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2335           {
2336             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2337             current_sym_value = 0;
2338             current_sym_addr = 0;
2339             current_sym_nchars = 2;
2340
2341             /* Some debuggers fail when given NULL names, so give this a
2342                harmless name of ` '.  */
2343             fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2344             dbxout_type (type, 1);
2345             dbxout_finish_symbol (NULL_TREE);
2346           }
2347
2348         /* Prevent duplicate output of a typedef.  */
2349         TREE_ASM_WRITTEN (decl) = 1;
2350         break;
2351       }
2352
2353     case PARM_DECL:
2354       /* Parm decls go in their own separate chains
2355          and are output by dbxout_reg_parms and dbxout_parms.  */
2356       abort ();
2357
2358     case RESULT_DECL:
2359       /* Named return value, treat like a VAR_DECL.  */
2360     case VAR_DECL:
2361       if (! DECL_RTL_SET_P (decl))
2362         DBXOUT_DECR_NESTING_AND_RETURN (0);
2363       /* Don't mention a variable that is external.
2364          Let the file that defines it describe it.  */
2365       if (DECL_EXTERNAL (decl))
2366         break;
2367
2368       /* If the variable is really a constant
2369          and not written in memory, inform the debugger.  */
2370       if (TREE_STATIC (decl) && TREE_READONLY (decl)
2371           && DECL_INITIAL (decl) != 0
2372           && host_integerp (DECL_INITIAL (decl), 0)
2373           && ! TREE_ASM_WRITTEN (decl)
2374           && (DECL_CONTEXT (decl) == NULL_TREE
2375               || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2376         {
2377           if (TREE_PUBLIC (decl) == 0)
2378             {
2379               /* The sun4 assembler does not grok this.  */
2380               const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2381
2382               if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2383                   || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2384                 {
2385                   HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2386                   fprintf (asmfile, "%s\"%s:c=i" HOST_WIDE_INT_PRINT_DEC
2387                            "\",0x%x,0,0,0\n",
2388                            ASM_STABS_OP, name, ival, N_LSYM);
2389                   DBXOUT_DECR_NESTING;
2390                   return 1;
2391                 }
2392               else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2393                 {
2394                   /* Don't know how to do this yet.  */
2395                 }
2396               break;
2397             }
2398           /* else it is something we handle like a normal variable.  */
2399         }
2400
2401       SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2402 #ifdef LEAF_REG_REMAP
2403       if (current_function_uses_only_leaf_regs)
2404         leaf_renumber_regs_insn (DECL_RTL (decl));
2405 #endif
2406
2407       result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2408       break;
2409
2410     default:
2411       break;
2412     }
2413   DBXOUT_DECR_NESTING;
2414   return result;
2415 }
2416 \f
2417 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2418    Add SUFFIX to its name, if SUFFIX is not 0.
2419    Describe the variable as residing in HOME
2420    (usually HOME is DECL_RTL (DECL), but not always).
2421    Returns 1 if the stab was really emitted.  */
2422
2423 static int
2424 dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home)
2425 {
2426   int letter = 0;
2427   int regno = -1;
2428
2429   emit_pending_bincls_if_required ();
2430
2431   /* Don't mention a variable at all
2432      if it was completely optimized into nothingness.
2433
2434      If the decl was from an inline function, then its rtl
2435      is not identically the rtl that was used in this
2436      particular compilation.  */
2437   if (GET_CODE (home) == SUBREG)
2438     {
2439       rtx value = home;
2440
2441       while (GET_CODE (value) == SUBREG)
2442         value = SUBREG_REG (value);
2443       if (GET_CODE (value) == REG)
2444         {
2445           if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2446             return 0;
2447         }
2448       home = alter_subreg (&home);
2449     }
2450   if (GET_CODE (home) == REG)
2451     {
2452       regno = REGNO (home);
2453       if (regno >= FIRST_PSEUDO_REGISTER)
2454         return 0;
2455     }
2456
2457   /* The kind-of-variable letter depends on where
2458      the variable is and on the scope of its name:
2459      G and N_GSYM for static storage and global scope,
2460      S for static storage and file scope,
2461      V for static storage and local scope,
2462      for those two, use N_LCSYM if data is in bss segment,
2463      N_STSYM if in data segment, N_FUN otherwise.
2464      (We used N_FUN originally, then changed to N_STSYM
2465      to please GDB.  However, it seems that confused ld.
2466      Now GDB has been fixed to like N_FUN, says Kingdon.)
2467      no letter at all, and N_LSYM, for auto variable,
2468      r and N_RSYM for register variable.  */
2469
2470   if (GET_CODE (home) == MEM
2471       && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2472     {
2473       if (TREE_PUBLIC (decl))
2474         {
2475           letter = 'G';
2476           current_sym_code = N_GSYM;
2477         }
2478       else
2479         {
2480           current_sym_addr = XEXP (home, 0);
2481
2482           letter = decl_function_context (decl) ? 'V' : 'S';
2483
2484           /* This should be the same condition as in assemble_variable, but
2485              we don't have access to dont_output_data here.  So, instead,
2486              we rely on the fact that error_mark_node initializers always
2487              end up in bss for C++ and never end up in bss for C.  */
2488           if (DECL_INITIAL (decl) == 0
2489               || (!strcmp (lang_hooks.name, "GNU C++")
2490                   && DECL_INITIAL (decl) == error_mark_node))
2491             current_sym_code = N_LCSYM;
2492           else if (DECL_IN_TEXT_SECTION (decl))
2493             /* This is not quite right, but it's the closest
2494                of all the codes that Unix defines.  */
2495             current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2496           else
2497             {
2498               /* Some ports can transform a symbol ref into a label ref,
2499                  because the symbol ref is too far away and has to be
2500                  dumped into a constant pool.  Alternatively, the symbol
2501                  in the constant pool might be referenced by a different
2502                  symbol.  */
2503               if (GET_CODE (current_sym_addr) == SYMBOL_REF
2504                   && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2505                 {
2506                   rtx tmp = get_pool_constant (current_sym_addr);
2507
2508                   if (GET_CODE (tmp) == SYMBOL_REF
2509                       || GET_CODE (tmp) == LABEL_REF)
2510                     current_sym_addr = tmp;
2511                 }
2512
2513               /* Ultrix `as' seems to need this.  */
2514 #ifdef DBX_STATIC_STAB_DATA_SECTION
2515               data_section ();
2516 #endif
2517               current_sym_code = N_STSYM;
2518             }
2519         }
2520     }
2521   else if (regno >= 0)
2522     {
2523       letter = 'r';
2524       current_sym_code = N_RSYM;
2525       current_sym_value = DBX_REGISTER_NUMBER (regno);
2526     }
2527   else if (GET_CODE (home) == MEM
2528            && (GET_CODE (XEXP (home, 0)) == MEM
2529                || (GET_CODE (XEXP (home, 0)) == REG
2530                    && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2531                    && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2532 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2533                    && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2534 #endif
2535                    )))
2536     /* If the value is indirect by memory or by a register
2537        that isn't the frame pointer
2538        then it means the object is variable-sized and address through
2539        that register or stack slot.  DBX has no way to represent this
2540        so all we can do is output the variable as a pointer.
2541        If it's not a parameter, ignore it.
2542        (VAR_DECLs like this can be made by integrate.c.)  */
2543     {
2544       if (GET_CODE (XEXP (home, 0)) == REG)
2545         {
2546           letter = 'r';
2547           current_sym_code = N_RSYM;
2548           if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2549             return 0;
2550           current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2551         }
2552       else
2553         {
2554           current_sym_code = N_LSYM;
2555           /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2556              We want the value of that CONST_INT.  */
2557           current_sym_value
2558             = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2559         }
2560
2561       /* Effectively do build_pointer_type, but don't cache this type,
2562          since it might be temporary whereas the type it points to
2563          might have been saved for inlining.  */
2564       /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
2565       type = make_node (POINTER_TYPE);
2566       TREE_TYPE (type) = TREE_TYPE (decl);
2567     }
2568   else if (GET_CODE (home) == MEM
2569            && GET_CODE (XEXP (home, 0)) == REG)
2570     {
2571       current_sym_code = N_LSYM;
2572       current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2573     }
2574   else if (GET_CODE (home) == MEM
2575            && GET_CODE (XEXP (home, 0)) == PLUS
2576            && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2577     {
2578       current_sym_code = N_LSYM;
2579       /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2580          We want the value of that CONST_INT.  */
2581       current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2582     }
2583   else if (GET_CODE (home) == MEM
2584            && GET_CODE (XEXP (home, 0)) == CONST)
2585     {
2586       /* Handle an obscure case which can arise when optimizing and
2587          when there are few available registers.  (This is *always*
2588          the case for i386/i486 targets).  The RTL looks like
2589          (MEM (CONST ...)) even though this variable is a local `auto'
2590          or a local `register' variable.  In effect, what has happened
2591          is that the reload pass has seen that all assignments and
2592          references for one such a local variable can be replaced by
2593          equivalent assignments and references to some static storage
2594          variable, thereby avoiding the need for a register.  In such
2595          cases we're forced to lie to debuggers and tell them that
2596          this variable was itself `static'.  */
2597       current_sym_code = N_LCSYM;
2598       letter = 'V';
2599       current_sym_addr = XEXP (XEXP (home, 0), 0);
2600     }
2601   else if (GET_CODE (home) == CONCAT)
2602     {
2603       tree subtype;
2604
2605       /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2606          for example), then there is no easy way to figure out
2607          what SUBTYPE should be.  So, we give up.  */
2608       if (TREE_CODE (type) != COMPLEX_TYPE)
2609         return 0;
2610
2611       subtype = TREE_TYPE (type);
2612
2613       /* If the variable's storage is in two parts,
2614          output each as a separate stab with a modified name.  */
2615       if (WORDS_BIG_ENDIAN)
2616         dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2617       else
2618         dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2619
2620       dbxout_prepare_symbol (decl);
2621
2622       if (WORDS_BIG_ENDIAN)
2623         dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2624       else
2625         dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2626       return 1;
2627     }
2628   else
2629     /* Address might be a MEM, when DECL is a variable-sized object.
2630        Or it might be const0_rtx, meaning previous passes
2631        want us to ignore this variable.  */
2632     return 0;
2633
2634   /* Ok, start a symtab entry and output the variable name.  */
2635   FORCE_TEXT;
2636
2637 #ifdef DBX_STATIC_BLOCK_START
2638   DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2639 #endif
2640
2641   dbxout_symbol_name (decl, suffix, letter);
2642   dbxout_type (type, 0);
2643   dbxout_finish_symbol (decl);
2644
2645 #ifdef DBX_STATIC_BLOCK_END
2646   DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2647 #endif
2648   return 1;
2649 }
2650 \f
2651 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2652    Then output LETTER to indicate the kind of location the symbol has.  */
2653
2654 static void
2655 dbxout_symbol_name (tree decl, const char *suffix, int letter)
2656 {
2657   const char *name;
2658
2659   if (DECL_CONTEXT (decl) 
2660       && (TYPE_P (DECL_CONTEXT (decl))
2661           || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL))
2662     /* One slight hitch: if this is a VAR_DECL which is a class member
2663        or a namespace member, we must put out the mangled name instead of the
2664        DECL_NAME.  Note also that static member (variable) names DO NOT begin
2665        with underscores in .stabs directives.  */
2666     name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2667   else
2668     /* ...but if we're function-local, we don't want to include the junk
2669        added by ASM_FORMAT_PRIVATE_NAME.  */
2670     name = IDENTIFIER_POINTER (DECL_NAME (decl));
2671
2672   if (name == 0)
2673     name = "(anon)";
2674   fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2675            (suffix ? suffix : ""));
2676
2677   if (letter)
2678     putc (letter, asmfile);
2679 }
2680
2681 static void
2682 dbxout_prepare_symbol (tree decl ATTRIBUTE_UNUSED)
2683 {
2684 #ifdef WINNING_GDB
2685   const char *filename = DECL_SOURCE_FILE (decl);
2686
2687   dbxout_source_file (asmfile, filename);
2688 #endif
2689
2690   /* Initialize variables used to communicate each symbol's debug
2691      information to dbxout_finish_symbol with zeroes.  */
2692
2693   /* Cast avoids warning in old compilers.  */
2694   current_sym_code = (STAB_CODE_TYPE) 0;
2695   current_sym_value = 0;
2696   current_sym_addr = 0;
2697 }
2698
2699 static void
2700 dbxout_finish_symbol (tree sym)
2701 {
2702 #ifdef DBX_FINISH_SYMBOL
2703   DBX_FINISH_SYMBOL (sym);
2704 #else
2705   int line = 0;
2706   if (use_gnu_debug_info_extensions && sym != 0)
2707     line = DECL_SOURCE_LINE (sym);
2708
2709   fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2710   if (current_sym_addr)
2711     output_addr_const (asmfile, current_sym_addr);
2712   else
2713     fprintf (asmfile, "%d", current_sym_value);
2714   putc ('\n', asmfile);
2715 #endif
2716 }
2717
2718 /* Output definitions of all the decls in a chain. Return nonzero if
2719    anything was output */
2720
2721 int
2722 dbxout_syms (tree syms)
2723 {
2724   int result = 0;
2725   while (syms)
2726     {
2727       result += dbxout_symbol (syms, 1);
2728       syms = TREE_CHAIN (syms);
2729     }
2730   return result;
2731 }
2732 \f
2733 /* The following two functions output definitions of function parameters.
2734    Each parameter gets a definition locating it in the parameter list.
2735    Each parameter that is a register variable gets a second definition
2736    locating it in the register.
2737
2738    Printing or argument lists in gdb uses the definitions that
2739    locate in the parameter list.  But reference to the variable in
2740    expressions uses preferentially the definition as a register.  */
2741
2742 /* Output definitions, referring to storage in the parmlist,
2743    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
2744
2745 void
2746 dbxout_parms (tree parms)
2747 {
2748   ++debug_nesting;
2749
2750   emit_pending_bincls_if_required ();
2751
2752   for (; parms; parms = TREE_CHAIN (parms))
2753     if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2754       {
2755         dbxout_prepare_symbol (parms);
2756
2757         /* Perform any necessary register eliminations on the parameter's rtl,
2758            so that the debugging output will be accurate.  */
2759         DECL_INCOMING_RTL (parms)
2760           = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2761         SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2762 #ifdef LEAF_REG_REMAP
2763         if (current_function_uses_only_leaf_regs)
2764           {
2765             leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2766             leaf_renumber_regs_insn (DECL_RTL (parms));
2767           }
2768 #endif
2769
2770         if (PARM_PASSED_IN_MEMORY (parms))
2771           {
2772             rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2773
2774             /* ??? Here we assume that the parm address is indexed
2775                off the frame pointer or arg pointer.
2776                If that is not true, we produce meaningless results,
2777                but do not crash.  */
2778             if (GET_CODE (addr) == PLUS
2779                 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2780               current_sym_value = INTVAL (XEXP (addr, 1));
2781             else
2782               current_sym_value = 0;
2783
2784             current_sym_code = N_PSYM;
2785             current_sym_addr = 0;
2786
2787             FORCE_TEXT;
2788             if (DECL_NAME (parms))
2789               {
2790                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2791
2792                 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2793                          IDENTIFIER_POINTER (DECL_NAME (parms)),
2794                          DBX_MEMPARM_STABS_LETTER);
2795               }
2796             else
2797               {
2798                 current_sym_nchars = 8;
2799                 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2800                          DBX_MEMPARM_STABS_LETTER);
2801               }
2802
2803             /* It is quite tempting to use:
2804
2805                    dbxout_type (TREE_TYPE (parms), 0);
2806
2807                as the next statement, rather than using DECL_ARG_TYPE(), so
2808                that gcc reports the actual type of the parameter, rather
2809                than the promoted type.  This certainly makes GDB's life
2810                easier, at least for some ports.  The change is a bad idea
2811                however, since GDB expects to be able access the type without
2812                performing any conversions.  So for example, if we were
2813                passing a float to an unprototyped function, gcc will store a
2814                double on the stack, but if we emit a stab saying the type is a
2815                float, then gdb will only read in a single value, and this will
2816                produce an erroneous value.  */
2817             dbxout_type (DECL_ARG_TYPE (parms), 0);
2818             current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2819             dbxout_finish_symbol (parms);
2820           }
2821         else if (GET_CODE (DECL_RTL (parms)) == REG)
2822           {
2823             rtx best_rtl;
2824             char regparm_letter;
2825             tree parm_type;
2826             /* Parm passed in registers and lives in registers or nowhere.  */
2827
2828             current_sym_code = DBX_REGPARM_STABS_CODE;
2829             regparm_letter = DBX_REGPARM_STABS_LETTER;
2830             current_sym_addr = 0;
2831
2832             /* If parm lives in a register, use that register;
2833                pretend the parm was passed there.  It would be more consistent
2834                to describe the register where the parm was passed,
2835                but in practice that register usually holds something else.
2836
2837                If we use DECL_RTL, then we must use the declared type of
2838                the variable, not the type that it arrived in.  */
2839             if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2840               {
2841                 best_rtl = DECL_RTL (parms);
2842                 parm_type = TREE_TYPE (parms);
2843               }
2844             /* If the parm lives nowhere, use the register where it was
2845                passed.  It is also better to use the declared type here.  */
2846             else
2847               {
2848                 best_rtl = DECL_INCOMING_RTL (parms);
2849                 parm_type = TREE_TYPE (parms);
2850               }
2851             current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2852
2853             FORCE_TEXT;
2854             if (DECL_NAME (parms))
2855               {
2856                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2857                 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2858                          IDENTIFIER_POINTER (DECL_NAME (parms)),
2859                          regparm_letter);
2860               }
2861             else
2862               {
2863                 current_sym_nchars = 8;
2864                 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2865                          regparm_letter);
2866               }
2867
2868             dbxout_type (parm_type, 0);
2869             dbxout_finish_symbol (parms);
2870           }
2871         else if (GET_CODE (DECL_RTL (parms)) == MEM
2872                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2873                  && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2874                  && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2875 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2876                  && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2877 #endif
2878                  )
2879           {
2880             /* Parm was passed via invisible reference.
2881                That is, its address was passed in a register.
2882                Output it as if it lived in that register.
2883                The debugger will know from the type
2884                that it was actually passed by invisible reference.  */
2885
2886             char regparm_letter;
2887             /* Parm passed in registers and lives in registers or nowhere.  */
2888
2889             current_sym_code = DBX_REGPARM_STABS_CODE;
2890             if (use_gnu_debug_info_extensions)
2891               regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2892             else
2893               regparm_letter = DBX_REGPARM_STABS_LETTER;
2894
2895             /* DECL_RTL looks like (MEM (REG...).  Get the register number.
2896                If it is an unallocated pseudo-reg, then use the register where
2897                it was passed instead.  */
2898             if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2899               current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2900             else
2901               current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2902
2903             current_sym_addr = 0;
2904
2905             FORCE_TEXT;
2906             if (DECL_NAME (parms))
2907               {
2908                 current_sym_nchars
2909                   = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2910
2911                 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2912                          IDENTIFIER_POINTER (DECL_NAME (parms)),
2913                          regparm_letter);
2914               }
2915             else
2916               {
2917                 current_sym_nchars = 8;
2918                 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2919                          regparm_letter);
2920               }
2921
2922             dbxout_type (TREE_TYPE (parms), 0);
2923             dbxout_finish_symbol (parms);
2924           }
2925         else if (GET_CODE (DECL_RTL (parms)) == MEM
2926                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2927           {
2928             /* Parm was passed via invisible reference, with the reference
2929                living on the stack.  DECL_RTL looks like
2930                (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2931                could look like (MEM (MEM (REG))).  */
2932             const char *const decl_name = (DECL_NAME (parms)
2933                                      ? IDENTIFIER_POINTER (DECL_NAME (parms))
2934                                      : "(anon)");
2935             if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2936               current_sym_value = 0;
2937             else
2938               current_sym_value
2939                 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2940             current_sym_addr = 0;
2941             current_sym_code = N_PSYM;
2942
2943             FORCE_TEXT;
2944             fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2945
2946             current_sym_value
2947               = DEBUGGER_ARG_OFFSET (current_sym_value,
2948                                      XEXP (XEXP (DECL_RTL (parms), 0), 0));
2949             dbxout_type (TREE_TYPE (parms), 0);
2950             dbxout_finish_symbol (parms);
2951           }
2952         else if (GET_CODE (DECL_RTL (parms)) == MEM
2953                  && XEXP (DECL_RTL (parms), 0) != const0_rtx
2954                  /* ??? A constant address for a parm can happen
2955                     when the reg it lives in is equiv to a constant in memory.
2956                     Should make this not happen, after 2.4.  */
2957                  && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2958           {
2959             /* Parm was passed in registers but lives on the stack.  */
2960
2961             current_sym_code = N_PSYM;
2962             /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2963                in which case we want the value of that CONST_INT,
2964                or (MEM (REG ...)),
2965                in which case we use a value of zero.  */
2966             if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2967               current_sym_value = 0;
2968             else
2969                 current_sym_value
2970                   = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2971
2972             current_sym_addr = 0;
2973
2974             /* Make a big endian correction if the mode of the type of the
2975                parameter is not the same as the mode of the rtl.  */
2976             if (BYTES_BIG_ENDIAN
2977                 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2978                 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2979               {
2980                 current_sym_value +=
2981                     GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2982                     - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2983               }
2984
2985             FORCE_TEXT;
2986             if (DECL_NAME (parms))
2987               {
2988                 current_sym_nchars
2989                   = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2990
2991                 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2992                          IDENTIFIER_POINTER (DECL_NAME (parms)),
2993                          DBX_MEMPARM_STABS_LETTER);
2994               }
2995             else
2996               {
2997                 current_sym_nchars = 8;
2998                 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2999                 DBX_MEMPARM_STABS_LETTER);
3000               }
3001
3002             current_sym_value
3003               = DEBUGGER_ARG_OFFSET (current_sym_value,
3004                                      XEXP (DECL_RTL (parms), 0));
3005             dbxout_type (TREE_TYPE (parms), 0);
3006             dbxout_finish_symbol (parms);
3007           }
3008       }
3009   DBXOUT_DECR_NESTING;
3010 }
3011
3012 /* Output definitions for the places where parms live during the function,
3013    when different from where they were passed, when the parms were passed
3014    in memory.
3015
3016    It is not useful to do this for parms passed in registers
3017    that live during the function in different registers, because it is
3018    impossible to look in the passed register for the passed value,
3019    so we use the within-the-function register to begin with.
3020
3021    PARMS is a chain of PARM_DECL nodes.  */
3022
3023 void
3024 dbxout_reg_parms (tree parms)
3025 {
3026   ++debug_nesting;
3027
3028   for (; parms; parms = TREE_CHAIN (parms))
3029     if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
3030       {
3031         dbxout_prepare_symbol (parms);
3032
3033         /* Report parms that live in registers during the function
3034            but were passed in memory.  */
3035         if (GET_CODE (DECL_RTL (parms)) == REG
3036             && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
3037           dbxout_symbol_location (parms, TREE_TYPE (parms),
3038                                   0, DECL_RTL (parms));
3039         else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
3040           dbxout_symbol_location (parms, TREE_TYPE (parms),
3041                                   0, DECL_RTL (parms));
3042         /* Report parms that live in memory but not where they were passed.  */
3043         else if (GET_CODE (DECL_RTL (parms)) == MEM
3044                  && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
3045           dbxout_symbol_location (parms, TREE_TYPE (parms),
3046                                   0, DECL_RTL (parms));
3047       }
3048   DBXOUT_DECR_NESTING;
3049 }
3050 \f
3051 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
3052    output definitions of those names, in raw form */
3053
3054 static void
3055 dbxout_args (tree args)
3056 {
3057   while (args)
3058     {
3059       putc (',', asmfile);
3060       dbxout_type (TREE_VALUE (args), 0);
3061       CHARS (1);
3062       args = TREE_CHAIN (args);
3063     }
3064 }
3065 \f
3066 /* Output everything about a symbol block (a BLOCK node
3067    that represents a scope level),
3068    including recursive output of contained blocks.
3069
3070    BLOCK is the BLOCK node.
3071    DEPTH is its depth within containing symbol blocks.
3072    ARGS is usually zero; but for the outermost block of the
3073    body of a function, it is a chain of PARM_DECLs for the function parameters.
3074    We output definitions of all the register parms
3075    as if they were local variables of that block.
3076
3077    If -g1 was used, we count blocks just the same, but output nothing
3078    except for the outermost block.
3079
3080    Actually, BLOCK may be several blocks chained together.
3081    We handle them all in sequence.  */
3082
3083 static void
3084 dbxout_block (tree block, int depth, tree args)
3085 {
3086   int blocknum = -1;
3087
3088 #if DBX_BLOCKS_FUNCTION_RELATIVE
3089   const char *begin_label;
3090   if (current_function_func_begin_label != NULL_TREE)
3091     begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
3092   else
3093     begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
3094 #endif
3095
3096   while (block)
3097     {
3098       /* Ignore blocks never expanded or otherwise marked as real.  */
3099       if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
3100         {
3101           int did_output;
3102
3103           /* In dbx format, the syms of a block come before the N_LBRAC.
3104              If nothing is output, we don't need the N_LBRAC, either.  */
3105           did_output = 0;
3106           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
3107             did_output = dbxout_syms (BLOCK_VARS (block));
3108           if (args)
3109             dbxout_reg_parms (args);
3110
3111           /* Now output an N_LBRAC symbol to represent the beginning of
3112              the block.  Use the block's tree-walk order to generate
3113              the assembler symbols LBBn and LBEn
3114              that final will define around the code in this block.  */
3115           if (depth > 0 && did_output)
3116             {
3117               char buf[20];
3118               blocknum = BLOCK_NUMBER (block);
3119               ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
3120
3121               if (BLOCK_HANDLER_BLOCK (block))
3122                 {
3123                   /* A catch block.  Must precede N_LBRAC.  */
3124                   tree decl = BLOCK_VARS (block);
3125                   while (decl)
3126                     {
3127                       fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
3128                                IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
3129                       assemble_name (asmfile, buf);
3130                       fprintf (asmfile, "\n");
3131                       decl = TREE_CHAIN (decl);
3132                     }
3133                 }
3134
3135 #ifdef DBX_OUTPUT_LBRAC
3136               DBX_OUTPUT_LBRAC (asmfile, buf);
3137 #else
3138               fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
3139               assemble_name (asmfile, buf);
3140 #if DBX_BLOCKS_FUNCTION_RELATIVE
3141               putc ('-', asmfile);
3142               assemble_name (asmfile, begin_label);
3143 #endif
3144               fprintf (asmfile, "\n");
3145 #endif
3146             }
3147
3148           /* Output the subblocks.  */
3149           dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
3150
3151           /* Refer to the marker for the end of the block.  */
3152           if (depth > 0 && did_output)
3153             {
3154               char buf[20];
3155               ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
3156 #ifdef DBX_OUTPUT_RBRAC
3157               DBX_OUTPUT_RBRAC (asmfile, buf);
3158 #else
3159               fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
3160               assemble_name (asmfile, buf);
3161 #if DBX_BLOCKS_FUNCTION_RELATIVE
3162               putc ('-', asmfile);
3163               assemble_name (asmfile, begin_label);
3164 #endif
3165               fprintf (asmfile, "\n");
3166 #endif
3167             }
3168         }
3169       block = BLOCK_CHAIN (block);
3170     }
3171 }
3172
3173 /* Output the information about a function and its arguments and result.
3174    Usually this follows the function's code,
3175    but on some systems, it comes before.  */
3176
3177 #if defined (DBX_DEBUGGING_INFO)
3178 static void
3179 dbxout_begin_function (tree decl)
3180 {
3181   int saved_tree_used1 = TREE_USED (decl);
3182   TREE_USED (decl) = 1;
3183   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3184     {
3185       int saved_tree_used2 = TREE_USED (DECL_RESULT (decl));
3186       TREE_USED (DECL_RESULT (decl)) = 1;
3187       dbxout_symbol (decl, 0);
3188       TREE_USED (DECL_RESULT (decl)) = saved_tree_used2;
3189     }
3190   else
3191     dbxout_symbol (decl, 0);
3192   TREE_USED (decl) = saved_tree_used1;
3193
3194   dbxout_parms (DECL_ARGUMENTS (decl));
3195   if (DECL_NAME (DECL_RESULT (decl)) != 0)
3196     dbxout_symbol (DECL_RESULT (decl), 1);
3197 }
3198 #endif /* DBX_DEBUGGING_INFO */
3199
3200 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */
3201
3202 #include "gt-dbxout.h"