OSDN Git Service

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