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