OSDN Git Service

(dbxout_source_line): New function.
[pf3gnuchains/gcc-fork.git] / gcc / dbxout.c
1 /* Output dbx-format symbol table information from GNU compiler.
2    Copyright (C) 1987, 1988, 1992 Free Software Foundation, Inc.
3
4 This file is part of GNU CC.
5
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
9 any later version.
10
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING.  If not, write to
18 the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
19
20
21 /* Output dbx-format symbol table data.
22    This consists of many symbol table entries, each of them
23    a .stabs assembler pseudo-op with four operands:
24    a "name" which is really a description of one symbol and its type,
25    a "code", which is a symbol defined in stab.h whose name starts with N_,
26    an unused operand always 0,
27    and a "value" which is an address or an offset.
28    The name is enclosed in doublequote characters.
29
30    Each function, variable, typedef, and structure tag
31    has a symbol table entry to define it.
32    The beginning and end of each level of name scoping within
33    a function are also marked by special symbol table entries.
34
35    The "name" consists of the symbol name, a colon, a kind-of-symbol letter,
36    and a data type number.  The data type number may be followed by
37    "=" and a type definition; normally this will happen the first time
38    the type number is mentioned.  The type definition may refer to
39    other types by number, and those type numbers may be followed
40    by "=" and nested definitions.
41
42    This can make the "name" quite long.
43    When a name is more than 80 characters, we split the .stabs pseudo-op
44    into two .stabs pseudo-ops, both sharing the same "code" and "value".
45    The first one is marked as continued with a double-backslash at the
46    end of its "name".
47
48    The kind-of-symbol letter distinguished function names from global
49    variables from file-scope variables from parameters from auto
50    variables in memory from typedef names from register variables.
51    See `dbxout_symbol'.
52
53    The "code" is mostly redundant with the kind-of-symbol letter
54    that goes in the "name", but not entirely: for symbols located
55    in static storage, the "code" says which segment the address is in,
56    which controls how it is relocated.
57
58    The "value" for a symbol in static storage
59    is the core address of the symbol (actually, the assembler
60    label for the symbol).  For a symbol located in a stack slot
61    it is the stack offset; for one in a register, the register number.
62    For a typedef symbol, it is zero.
63
64    If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
65    output while in the text section.
66
67    For more on data type definitions, see `dbxout_type'.  */
68
69 /* Include these first, because they may define MIN and MAX.  */
70 #include <stdio.h>
71 #include <errno.h>
72
73 #include "config.h"
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
81 #ifndef errno
82 extern int errno;
83 #endif
84
85 #ifdef XCOFF_DEBUGGING_INFO
86 #include "xcoffout.h"
87 #endif
88
89 #ifndef ASM_STABS_OP
90 #define ASM_STABS_OP ".stabs"
91 #endif
92
93 #ifndef ASM_STABN_OP
94 #define ASM_STABN_OP ".stabn"
95 #endif
96
97 #ifndef DBX_TYPE_DECL_STABS_CODE
98 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
99 #endif
100
101 #ifndef DBX_STATIC_CONST_VAR_CODE
102 #define DBX_STATIC_CONST_VAR_CODE N_FUN
103 #endif
104
105 #ifndef DBX_REGPARM_STABS_CODE
106 #define DBX_REGPARM_STABS_CODE N_RSYM
107 #endif
108
109 #ifndef DBX_REGPARM_STABS_LETTER
110 #define DBX_REGPARM_STABS_LETTER 'P'
111 #endif
112
113 #ifndef DBX_MEMPARM_STABS_LETTER
114 #define DBX_MEMPARM_STABS_LETTER 'p'
115 #endif
116
117 /* Nonzero means if the type has methods, only output debugging
118    information if methods are actually written to the asm file.  */
119
120 static int flag_minimal_debug = 1;
121
122 /* Nonzero if we have actually used any of the GDB extensions
123    to the debugging format.  The idea is that we use them for the
124    first time only if there's a strong reason, but once we have done that,
125    we use them whenever convenient.  */
126
127 static int have_used_extensions = 0;
128
129 char *getpwd ();
130
131 /* Typical USG systems don't have stab.h, and they also have
132    no use for DBX-format debugging info.  */
133
134 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
135
136 #ifdef DEBUG_SYMS_TEXT
137 #define FORCE_TEXT text_section ();
138 #else
139 #define FORCE_TEXT
140 #endif
141
142 #if defined (USG) || defined (NO_STAB_H)
143 #include "gstab.h"  /* If doing DBX on sysV, use our own stab.h.  */
144 #else
145 #include <stab.h>  /* On BSD, use the system's stab.h.  */
146
147 /* This is a GNU extension we need to reference in this file.  */
148 #ifndef N_CATCH
149 #define N_CATCH 0x54
150 #endif
151 #endif /* not USG */
152
153 #ifdef __GNU_STAB__
154 #define STAB_CODE_TYPE enum __stab_debug_code
155 #else
156 #define STAB_CODE_TYPE int
157 #endif
158
159 /* 1 if PARM is passed to this function in memory.  */
160
161 #define PARM_PASSED_IN_MEMORY(PARM) \
162  (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
163
164 /* A C expression for the integer offset value of an automatic variable
165    (N_LSYM) having address X (an RTX).  */
166 #ifndef DEBUGGER_AUTO_OFFSET
167 #define DEBUGGER_AUTO_OFFSET(X) \
168   (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
169 #endif
170
171 /* A C expression for the integer offset value of an argument (N_PSYM)
172    having address X (an RTX).  The nominal offset is OFFSET.  */
173 #ifndef DEBUGGER_ARG_OFFSET
174 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
175 #endif
176
177 /* Stream for writing to assembler file.  */
178
179 static FILE *asmfile;
180
181 /* Last source file name mentioned in a NOTE insn.  */
182
183 static char *lastfile;
184
185 /* Current working directory.  */
186
187 static char *cwd;
188
189 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
190
191 /* Vector recording the status of describing C data types.
192    When we first notice a data type (a tree node),
193    we assign it a number using next_type_number.
194    That is its index in this vector.
195    The vector element says whether we have yet output
196    the definition of the type.  TYPE_XREF says we have
197    output it as a cross-reference only.  */
198
199 enum typestatus *typevec;
200
201 /* Number of elements of space allocated in `typevec'.  */
202
203 static int typevec_len;
204
205 /* In dbx output, each type gets a unique number.
206    This is the number for the next type output.
207    The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field.  */
208
209 static int next_type_number;
210
211 /* In dbx output, we must assign symbol-blocks id numbers
212    in the order in which their beginnings are encountered.
213    We output debugging info that refers to the beginning and
214    end of the ranges of code in each block
215    with assembler labels LBBn and LBEn, where n is the block number.
216    The labels are generated in final, which assigns numbers to the
217    blocks in the same way.  */
218
219 static int next_block_number;
220
221 /* These variables are for dbxout_symbol to communicate to
222    dbxout_finish_symbol.
223    current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
224    current_sym_value and current_sym_addr are two ways to address the
225    value to store in the symtab entry.
226    current_sym_addr if nonzero represents the value as an rtx.
227    If that is zero, current_sym_value is used.  This is used
228    when the value is an offset (such as for auto variables,
229    register variables and parms).  */
230
231 static STAB_CODE_TYPE current_sym_code;
232 static int current_sym_value;
233 static rtx current_sym_addr;
234
235 /* Number of chars of symbol-description generated so far for the
236    current symbol.  Used by CHARS and CONTIN.  */
237
238 static int current_sym_nchars;
239
240 /* Report having output N chars of the current symbol-description.  */
241
242 #define CHARS(N) (current_sym_nchars += (N))
243
244 /* Break the current symbol-description, generating a continuation,
245    if it has become long.  */
246
247 #ifndef DBX_CONTIN_LENGTH
248 #define DBX_CONTIN_LENGTH 80
249 #endif
250
251 #if DBX_CONTIN_LENGTH > 0
252 #define CONTIN  \
253   do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
254 #else
255 #define CONTIN
256 #endif
257
258 void dbxout_types ();
259 void dbxout_args ();
260 void dbxout_symbol ();
261 static void dbxout_type_name ();
262 static void dbxout_type ();
263 static void dbxout_typedefs ();
264 static void dbxout_prepare_symbol ();
265 static void dbxout_finish_symbol ();
266 static void dbxout_continue ();
267 static void print_int_cst_octal ();
268 static void print_octal ();
269 \f
270 #if 0 /* Not clear we will actually need this.  */
271
272 /* Return the absolutized filename for the given relative
273    filename.  Note that if that filename is already absolute, it may
274    still be returned in a modified form because this routine also
275    eliminates redundant slashes and single dots and eliminates double
276    dots to get a shortest possible filename from the given input
277    filename.  The absolutization of relative filenames is made by
278    assuming that the given filename is to be taken as relative to
279    the first argument (cwd) or to the current directory if cwd is
280    NULL.  */
281
282 static char *
283 abspath (rel_filename)
284      char *rel_filename;
285 {
286   /* Setup the current working directory as needed.  */
287   char *abs_buffer
288     = (char *) alloca (strlen (cwd) + strlen (rel_filename) + 1);
289   char *endp = abs_buffer;
290   char *outp, *inp;
291   char *value;
292
293   /* Copy the filename (possibly preceded by the current working
294      directory name) into the absolutization buffer.  */
295
296   {
297     char *src_p;
298
299     if (rel_filename[0] != '/')
300       {
301         src_p = cwd;
302         while (*endp++ = *src_p++)
303           continue;
304         *(endp-1) = '/';                        /* overwrite null */
305       }
306     src_p = rel_filename;
307     while (*endp++ = *src_p++)
308       continue;
309     if (endp[-1] == '/')
310       *endp = '\0';
311
312   /* Now make a copy of abs_buffer into abs_buffer, shortening the
313      filename (by taking out slashes and dots) as we go.  */
314
315   outp = inp = abs_buffer;
316   *outp++ = *inp++;             /* copy first slash */
317   for (;;)
318     {
319       if (!inp[0])
320         break;
321       else if (inp[0] == '/' && outp[-1] == '/')
322         {
323           inp++;
324           continue;
325         }
326       else if (inp[0] == '.' && outp[-1] == '/')
327         {
328           if (!inp[1])
329                   break;
330           else if (inp[1] == '/')
331             {
332                     inp += 2;
333                     continue;
334             }
335           else if ((inp[1] == '.') && (inp[2] == 0 || inp[2] == '/'))
336             {
337                     inp += (inp[2] == '/') ? 3 : 2;
338                     outp -= 2;
339                     while (outp >= abs_buffer && *outp != '/')
340                 outp--;
341                     if (outp < abs_buffer)
342                 {
343                   /* Catch cases like /.. where we try to backup to a
344                      point above the absolute root of the logical file
345                      system.  */
346
347                   fprintf (stderr, "%s: invalid file name: %s\n",
348                            pname, rel_filename);
349                   exit (1);
350                 }
351                     *++outp = '\0';
352                     continue;
353             }
354         }
355       *outp++ = *inp++;
356     }
357
358   /* On exit, make sure that there is a trailing null, and make sure that
359      the last character of the returned string is *not* a slash.  */
360
361   *outp = '\0';
362   if (outp[-1] == '/')
363     *--outp  = '\0';
364
365   /* Make a copy (in the heap) of the stuff left in the absolutization
366      buffer and return a pointer to the copy.  */
367
368   value = (char *) oballoc (strlen (abs_buffer) + 1);
369   strcpy (value, abs_buffer);
370   return value;
371 }
372 #endif /* 0 */
373 \f
374 /* At the beginning of compilation, start writing the symbol table.
375    Initialize `typevec' and output the standard data types of C.  */
376
377 void
378 dbxout_init (asm_file, input_file_name, syms)
379      FILE *asm_file;
380      char *input_file_name;
381      tree syms;
382 {
383   char ltext_label_name[100];
384
385   asmfile = asm_file;
386
387   typevec_len = 100;
388   typevec = (enum typestatus *) xmalloc (typevec_len * sizeof typevec[0]);
389   bzero (typevec, typevec_len * sizeof typevec[0]);
390
391   /* Convert Ltext into the appropriate format for local labels in case
392      the system doesn't insert underscores in front of user generated
393      labels.  */
394   ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
395
396   /* Put the current working directory in an N_SO symbol.  */
397 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
398                                  but GDB always does.  */
399   if (use_gnu_debug_info_extensions)
400 #endif
401     {
402       if (cwd || (cwd = getpwd ()))
403         {
404 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
405           DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
406 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
407           fprintf (asmfile, "%s \"%s/\",%d,0,0,%s\n", ASM_STABS_OP,
408                    cwd, N_SO, &ltext_label_name[1]);
409 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
410         }
411     }
412
413 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
414   /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
415      would give us an N_SOL, and we want an N_SO.  */
416   DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
417 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
418   /* We include outputting `Ltext:' here,
419      because that gives you a way to override it.  */
420   /* Used to put `Ltext:' before the reference, but that loses on sun 4.  */
421   fprintf (asmfile, "%s \"%s\",%d,0,0,%s\n", ASM_STABS_OP, input_file_name,
422            N_SO, &ltext_label_name[1]);
423   text_section ();
424   ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
425 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
426
427   /* Possibly output something to inform GDB that this compilation was by
428      GCC.  It's easier for GDB to parse it when after the N_SO's.  This
429      is used in Solaris 2.  */
430 #ifdef ASM_IDENTIFY_GCC_AFTER_SOURCE
431   ASM_IDENTIFY_GCC_AFTER_SOURCE (asmfile);
432 #endif
433
434   lastfile = input_file_name;
435
436   next_type_number = 1;
437   next_block_number = 2;
438
439   /* Make sure that types `int' and `char' have numbers 1 and 2.
440      Definitions of other integer types will refer to those numbers.
441      (Actually it should no longer matter what their numbers are.
442      Also, if any types with tags have been defined, dbxout_symbol
443      will output them first, so the numbers won't be 1 and 2.  That
444      happens in C++.  So it's a good thing it should no longer matter).  */
445
446 #ifdef DBX_OUTPUT_STANDARD_TYPES
447   DBX_OUTPUT_STANDARD_TYPES (syms);
448 #else
449   dbxout_symbol (TYPE_NAME (integer_type_node), 0);
450   dbxout_symbol (TYPE_NAME (char_type_node), 0);
451 #endif
452
453   /* Get all permanent types that have typedef names,
454      and output them all, except for those already output.  */
455
456   dbxout_typedefs (syms);
457 }
458
459 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
460    in the reverse order from that which is found in SYMS.  */
461
462 static void
463 dbxout_typedefs (syms)
464      tree syms;
465 {
466   if (syms)
467     {
468       dbxout_typedefs (TREE_CHAIN (syms));
469       if (TREE_CODE (syms) == TYPE_DECL)
470         {
471           tree type = TREE_TYPE (syms);
472           if (TYPE_NAME (type)
473               && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
474               && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
475             dbxout_symbol (TYPE_NAME (type), 0);
476         }
477     }
478 }
479
480 /* Output debugging info to FILE to switch to sourcefile FILENAME.  */
481
482 void
483 dbxout_source_file (file, filename)
484      FILE *file;
485      char *filename;
486 {
487   char ltext_label_name[100];
488
489   if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
490     {
491 #ifdef DBX_OUTPUT_SOURCE_FILENAME
492       DBX_OUTPUT_SOURCE_FILENAME (file, filename);
493 #else
494       ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
495       fprintf (file, "%s \"%s\",%d,0,0,%s\n", ASM_STABS_OP,
496                filename, N_SOL, &ltext_label_name[1]);
497 #endif
498       lastfile = filename;
499     }
500 }
501
502 /* Output a line number symbol entry into output stream FILE, 
503    for source file FILENAME and line number LINENO.  */
504
505 void
506 dbxout_source_line (file, filename, lineno)
507      FILE *file;
508      char *filename;
509      int lineno;
510 {
511   dbxout_source_file (file, filename);
512
513 #ifdef ASM_OUTPUT_SOURCE_LINE
514   ASM_OUTPUT_SOURCE_LINE (file, lineno);
515 #else
516   fprintf (file, "\t%s %d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
517 #endif
518 }
519
520 /* At the end of compilation, finish writing the symbol table.
521    Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
522    to do nothing. */
523
524 void
525 dbxout_finish (file, filename)
526      FILE *file;
527      char *filename;
528 {
529 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
530   DBX_OUTPUT_MAIN_SOURCE_FILE_END (file, filename);
531 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
532 }
533
534 /* Continue a symbol-description that gets too big.
535    End one symbol table entry with a double-backslash
536    and start a new one, eventually producing something like
537    .stabs "start......\\",code,0,value
538    .stabs "...rest",code,0,value   */
539
540 static void
541 dbxout_continue ()
542 {
543 #ifdef DBX_CONTIN_CHAR
544   fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
545 #else
546   fprintf (asmfile, "\\\\");
547 #endif
548   dbxout_finish_symbol (NULL_TREE);
549   fprintf (asmfile, "%s \"", ASM_STABS_OP);
550   current_sym_nchars = 0;
551 }
552 \f
553 /* Subroutine of `dbxout_type'.  Output the type fields of TYPE.
554    This must be a separate function because anonymous unions require
555    recursive calls.  */
556
557 static void
558 dbxout_type_fields (type)
559      tree type;
560 {
561   tree tem;
562   for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
563     {
564       /* Output the name, type, position (in bits), size (in bits)
565          of each field.  */
566       if (DECL_NAME (tem) == NULL_TREE
567           && TREE_CODE (TREE_TYPE (tem)) == UNION_TYPE)
568         dbxout_type_fields (TREE_TYPE (tem));
569       /* Omit here local type decls until we know how to support them.  */
570       else if (TREE_CODE (tem) == TYPE_DECL)
571         continue;
572       /* Omit here the nameless fields that are used to skip bits.  */
573       else if (DECL_NAME (tem) != 0 && TREE_CODE (tem) != CONST_DECL)
574         {
575           /* Continue the line if necessary,
576              but not before the first field.  */
577           if (tem != TYPE_FIELDS (type))
578             CONTIN;
579
580           if (use_gnu_debug_info_extensions
581               && flag_minimal_debug
582               && TREE_CODE (tem) == FIELD_DECL
583               && DECL_VIRTUAL_P (tem)
584               && DECL_ASSEMBLER_NAME (tem))
585             {
586               have_used_extensions = 1;
587               CHARS (3 + IDENTIFIER_LENGTH (DECL_NAME (TYPE_NAME (DECL_FCONTEXT (tem)))));
588               fputs (IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem)), asmfile);
589               dbxout_type (DECL_FCONTEXT (tem), 0, 0);
590               fprintf (asmfile, ":");
591               dbxout_type (TREE_TYPE (tem), 0, 0);
592               fprintf (asmfile, ",%d;",
593                        TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)));
594               continue;
595             }
596
597           fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
598           CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
599
600           if (use_gnu_debug_info_extensions
601               && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
602                   || TREE_CODE (tem) != FIELD_DECL))
603             {
604               have_used_extensions = 1;
605               putc ('/', asmfile);
606               putc ((TREE_PRIVATE (tem) ? '0'
607                      : TREE_PROTECTED (tem) ? '1' : '2'),
608                     asmfile);
609               CHARS (2);
610             }
611
612           dbxout_type ((TREE_CODE (tem) == FIELD_DECL
613                         && DECL_BIT_FIELD_TYPE (tem))
614                        ? DECL_BIT_FIELD_TYPE (tem)
615                        : TREE_TYPE (tem), 0, 0);
616
617           if (TREE_CODE (tem) == VAR_DECL)
618             {
619               if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
620                 {
621                   char *name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (tem));
622                   have_used_extensions = 1;
623                   fprintf (asmfile, ":%s;", name);
624                   CHARS (strlen (name));
625                 }
626               else
627                 {
628                   /* If TEM is non-static, GDB won't understand it.  */
629                   fprintf (asmfile, ",0,0;");
630                 }
631             }
632           else if (TREE_CODE (DECL_FIELD_BITPOS (tem)) == INTEGER_CST)
633             {
634               fprintf (asmfile, ",%d,%d;",
635                        TREE_INT_CST_LOW (DECL_FIELD_BITPOS (tem)),
636                        TREE_INT_CST_LOW (DECL_SIZE (tem)));
637             }
638           else
639             /* This has yet to be implemented.  */
640             abort ();
641           CHARS (23);
642         }
643     }
644 }
645 \f
646 /* Subroutine of `dbxout_type_methods'.  Output debug info about the
647    method described DECL.  DEBUG_NAME is an encoding of the method's
648    type signature.  ??? We may be able to do without DEBUG_NAME altogether
649    now.  */
650
651 static void
652 dbxout_type_method_1 (decl, debug_name)
653      tree decl;
654      char *debug_name;
655 {
656   tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
657   char c1 = 'A', c2;
658
659   if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
660     c2 = '?';
661   else /* it's a METHOD_TYPE.  */
662     {
663       /* A for normal functions.
664          B for `const' member functions.
665          C for `volatile' member functions.
666          D for `const volatile' member functions.  */
667       if (TYPE_READONLY (TREE_TYPE (firstarg)))
668         c1 += 1;
669       if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
670         c1 += 2;
671
672       if (DECL_VINDEX (decl))
673         c2 = '*';
674       else
675         c2 = '.';
676     }
677
678   fprintf (asmfile, ":%s;%c%c%c", debug_name,
679            TREE_PRIVATE (decl) ? '0' : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
680   CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
681          - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
682   if (DECL_VINDEX (decl))
683     {
684       fprintf (asmfile, "%d;",
685                TREE_INT_CST_LOW (DECL_VINDEX (decl)));
686       dbxout_type (DECL_CONTEXT (decl), 0, 0);
687       fprintf (asmfile, ";");
688       CHARS (8);
689     }
690 }
691 \f
692 /* Subroutine of `dbxout_type'.  Output debug info about the methods defined
693    in TYPE.  */
694
695 static void
696 dbxout_type_methods (type)
697      register tree type;
698 {
699   /* C++: put out the method names and their parameter lists */
700   tree methods = TYPE_METHODS (type);
701   tree type_encoding;
702   register tree fndecl;
703   register tree last;
704   char formatted_type_identifier_length[16];
705   register int type_identifier_length;
706
707   if (methods == NULL_TREE)
708     return;
709
710   type_encoding = DECL_NAME (TYPE_NAME (type));
711
712   /* C++: Template classes break some assumptions made by this code about
713      the class names, constructor names, and encodings for assembler
714      label names.  For now, disable output of dbx info for them.  */
715   {
716     char *ptr = IDENTIFIER_POINTER (type_encoding);
717     /* This should use index.  (mrs) */
718     while (*ptr && *ptr != '<') ptr++;
719     if (*ptr != 0)
720       {
721         static int warned;
722         if (!warned)
723           {
724             warned = 1;
725             warning ("dbx info for template class methods not yet supported");
726           }
727         return;
728       }
729   }
730
731   type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
732
733   sprintf(formatted_type_identifier_length, "%d", type_identifier_length);
734
735   if (TREE_CODE (methods) == FUNCTION_DECL)
736     fndecl = methods;
737   else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
738     fndecl = TREE_VEC_ELT (methods, 0);
739   else
740     fndecl = TREE_VEC_ELT (methods, 1);
741
742   while (fndecl)
743     {
744       tree name = DECL_NAME (fndecl);
745       int need_prefix = 1;
746
747       /* Group together all the methods for the same operation.
748          These differ in the types of the arguments.  */
749       for (last = NULL_TREE;
750            fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
751            fndecl = TREE_CHAIN (fndecl))
752         /* Output the name of the field (after overloading), as
753            well as the name of the field before overloading, along
754            with its parameter list */
755         {
756           /* This is the "mangled" name of the method.
757              It encodes the argument types.  */
758           char *debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
759           int destructor = 0;
760
761           CONTIN;
762
763           last = fndecl;
764
765           if (DECL_IGNORED_P (fndecl))
766             continue;
767
768           if (flag_minimal_debug)
769             {
770               /* Detect ordinary methods because their mangled names
771                  start with the operation name.  */
772               if (!strncmp (IDENTIFIER_POINTER (name), debug_name,
773                             IDENTIFIER_LENGTH (name)))
774                 {
775                   debug_name += IDENTIFIER_LENGTH (name);
776                   if (debug_name[0] == '_' && debug_name[1] == '_')
777                     {
778                       char *method_name = debug_name + 2;
779                       char *length_ptr = formatted_type_identifier_length;
780                       /* Get past const and volatile qualifiers.  */
781                       while (*method_name == 'C' || *method_name == 'V')
782                         method_name++;
783                       /* Skip digits for length of type_encoding. */
784                       while (*method_name == *length_ptr && *length_ptr)
785                           length_ptr++, method_name++;
786                       if (! strncmp (method_name,
787                                      IDENTIFIER_POINTER (type_encoding),
788                                      type_identifier_length))
789                         method_name += type_identifier_length;
790                       debug_name = method_name;
791                     }
792                 }
793               /* Detect constructors by their style of name mangling.  */
794               else if (debug_name[0] == '_' && debug_name[1] == '_')
795                 {
796                   char *ctor_name = debug_name + 2;
797                   char *length_ptr = formatted_type_identifier_length;
798                   while (*ctor_name == 'C' || *ctor_name == 'V')
799                     ctor_name++;
800                   /* Skip digits for length of type_encoding. */
801                   while (*ctor_name == *length_ptr && *length_ptr)
802                       length_ptr++, ctor_name++;
803                   if (!strncmp (IDENTIFIER_POINTER (type_encoding), ctor_name,
804                                 type_identifier_length))
805                     debug_name = ctor_name + type_identifier_length;
806                 }
807               /* The other alternative is a destructor.  */
808               else
809                 destructor = 1;
810
811               /* Output the operation name just once, for the first method
812                  that we output.  */
813               if (need_prefix)
814                 {
815                   fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
816                   CHARS (IDENTIFIER_LENGTH (name) + 2);
817                   need_prefix = 0;
818                 }
819             }
820
821           dbxout_type (TREE_TYPE (fndecl), 0, destructor);
822
823           dbxout_type_method_1 (fndecl, debug_name);
824         }
825       if (!need_prefix)
826         {
827           putc (';', asmfile);
828           CHARS (1);
829         }
830     }
831 }
832 \f
833 /* Output a reference to a type.  If the type has not yet been
834    described in the dbx output, output its definition now.
835    For a type already defined, just refer to its definition
836    using the type number.
837
838    If FULL is nonzero, and the type has been described only with
839    a forward-reference, output the definition now.
840    If FULL is zero in this case, just refer to the forward-reference
841    using the number previously allocated.
842
843    If SHOW_ARG_TYPES is nonzero, we output a description of the argument
844    types for a METHOD_TYPE.  */
845
846 static void
847 dbxout_type (type, full, show_arg_types)
848      tree type;
849      int full;
850      int show_arg_types;
851 {
852   register tree tem;
853
854   /* If there was an input error and we don't really have a type,
855      avoid crashing and write something that is at least valid
856      by assuming `int'.  */
857   if (type == error_mark_node)
858     type = integer_type_node;
859   else
860     {
861       type = TYPE_MAIN_VARIANT (type);
862       if (TYPE_NAME (type)
863           && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
864           && DECL_IGNORED_P (TYPE_NAME (type)))
865         full = 0;
866     }
867
868   if (TYPE_SYMTAB_ADDRESS (type) == 0)
869     {
870       /* Type has no dbx number assigned.  Assign next available number.  */
871       TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
872
873       /* Make sure type vector is long enough to record about this type.  */
874
875       if (next_type_number == typevec_len)
876         {
877           typevec = (enum typestatus *) xrealloc (typevec, typevec_len * 2 * sizeof typevec[0]);
878           bzero (typevec + typevec_len, typevec_len * sizeof typevec[0]);
879           typevec_len *= 2;
880         }
881     }
882
883   /* Output the number of this type, to refer to it.  */
884   fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
885   CHARS (3);
886
887 #ifdef DBX_TYPE_DEFINED
888   if (DBX_TYPE_DEFINED (type))
889     return;
890 #endif
891
892   /* If this type's definition has been output or is now being output,
893      that is all.  */
894
895   switch (typevec[TYPE_SYMTAB_ADDRESS (type)])
896     {
897     case TYPE_UNSEEN:
898       break;
899     case TYPE_XREF:
900       /* If we have already had a cross reference,
901          and either that's all we want or that's the best we could do,
902          don't repeat the cross reference.
903          Sun dbx crashes if we do.  */
904       if (! full || TYPE_SIZE (type) == 0
905           /* No way in DBX fmt to describe a variable size.  */
906           || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
907         return;
908       break;
909     case TYPE_DEFINED:
910       return;
911     }
912
913 #ifdef DBX_NO_XREFS
914   /* For systems where dbx output does not allow the `=xsNAME:' syntax,
915      leave the type-number completely undefined rather than output
916      a cross-reference.  */
917   if (TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
918       || TREE_CODE (type) == ENUMERAL_TYPE)
919
920     if ((TYPE_NAME (type) != 0 && !full)
921         || TYPE_SIZE (type) == 0)
922       {
923         typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
924         return;
925       }
926 #endif
927
928   /* Output a definition now.  */
929
930   fprintf (asmfile, "=");
931   CHARS (1);
932
933   /* Mark it as defined, so that if it is self-referent
934      we will not get into an infinite recursion of definitions.  */
935
936   typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_DEFINED;
937
938   switch (TREE_CODE (type))
939     {
940     case VOID_TYPE:
941     case LANG_TYPE:
942       /* For a void type, just define it as itself; ie, "5=5".
943          This makes us consider it defined
944          without saying what it is.  The debugger will make it
945          a void type when the reference is seen, and nothing will
946          ever override that default.  */
947       fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
948       CHARS (3);
949       break;
950
951     case INTEGER_TYPE:
952       if (type == char_type_node && ! TREE_UNSIGNED (type))
953         /* Output the type `char' as a subrange of itself!
954            I don't understand this definition, just copied it
955            from the output of pcc.
956            This used to use `r2' explicitly and we used to
957            take care to make sure that `char' was type number 2.  */
958         fprintf (asmfile, "r%d;0;127;", TYPE_SYMTAB_ADDRESS (type));
959 #ifdef WINNING_GDB
960       else if (TYPE_PRECISION (type) > BITS_PER_WORD)
961         {
962           /* This used to say `r1' and we used to take care
963              to make sure that `int' was type number 1.  */
964           fprintf (asmfile, "r%d;", TYPE_SYMTAB_ADDRESS (integer_type_node));
965           print_int_cst_octal (TYPE_MIN_VALUE (type));
966           fprintf (asmfile, ";");
967           print_int_cst_octal (TYPE_MAX_VALUE (type));
968           fprintf (asmfile, ";");
969         }
970 #endif
971       else
972         /* Output other integer types as subranges of `int'.  */
973         /* This used to say `r1' and we used to take care
974            to make sure that `int' was type number 1.  */
975         fprintf (asmfile, "r%d;%d;%d;",
976                  TYPE_SYMTAB_ADDRESS (integer_type_node),
977                  TREE_INT_CST_LOW (TYPE_MIN_VALUE (type)),
978                  TREE_INT_CST_LOW (TYPE_MAX_VALUE (type)));
979       CHARS (25);
980       break;
981
982     case REAL_TYPE:
983       /* This used to say `r1' and we used to take care
984          to make sure that `int' was type number 1.  */
985       fprintf (asmfile, "r%d;%d;0;", TYPE_SYMTAB_ADDRESS (integer_type_node),
986                TREE_INT_CST_LOW (size_in_bytes (type)));
987       CHARS (16);
988       break;
989
990     case ARRAY_TYPE:
991       /* Output "a" followed by a range type definition
992          for the index type of the array
993          followed by a reference to the target-type.
994          ar1;0;N;M for an array of type M and size N.  */
995       /* This used to say `r1' and we used to take care
996          to make sure that `int' was type number 1.  */
997       fprintf (asmfile, "ar%d;0;%d;", TYPE_SYMTAB_ADDRESS (integer_type_node),
998
999                (TYPE_DOMAIN (type)
1000                 ? TREE_INT_CST_LOW (TYPE_MAX_VALUE (TYPE_DOMAIN (type)))
1001                 : -1));
1002       CHARS (17);
1003       dbxout_type (TREE_TYPE (type), 0, 0);
1004       break;
1005
1006     case RECORD_TYPE:
1007     case UNION_TYPE:
1008       {
1009         int i, n_baseclasses = 0;
1010
1011         if (TYPE_BINFO (type) != 0 && TYPE_BINFO_BASETYPES (type) != 0)
1012           n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1013
1014         /* Output a structure type.  */
1015         if ((TYPE_NAME (type) != 0
1016 #if 0 /* Tiemann says this creates output tha "confuses GDB".
1017          Too bad the info is so vague.  Hope this doesn't lose.  */
1018              && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1019                    && DECL_IGNORED_P (TYPE_NAME (type)))
1020 #endif
1021              && !full)
1022             || TYPE_SIZE (type) == 0
1023             /* No way in DBX fmt to describe a variable size.  */
1024             || TREE_CODE (TYPE_SIZE (type)) != INTEGER_CST)
1025           {
1026             /* If the type is just a cross reference, output one
1027                and mark the type as partially described.
1028                If it later becomes defined, we will output
1029                its real definition.
1030                If the type has a name, don't nest its definition within
1031                another type's definition; instead, output an xref
1032                and let the definition come when the name is defined.  */
1033             fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu");
1034             CHARS (3);
1035 #if 0 /* This assertion is legitimately false in C++.  */
1036             /* We shouldn't be outputting a reference to a type before its
1037                definition unless the type has a tag name.
1038                A typedef name without a tag name should be impossible.  */
1039             if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1040               abort ();
1041 #endif
1042             dbxout_type_name (type);
1043             fprintf (asmfile, ":");
1044             typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
1045             break;
1046           }
1047         tem = size_in_bytes (type);
1048
1049         /* Identify record or union, and print its size.  */
1050         fprintf (asmfile, (TREE_CODE (type) == RECORD_TYPE) ? "s%d" : "u%d",
1051                  TREE_INT_CST_LOW (tem));
1052
1053         if (use_gnu_debug_info_extensions)
1054           {
1055             if (n_baseclasses)
1056               {
1057                 have_used_extensions = 1;
1058                 fprintf (asmfile, "!%d,", n_baseclasses);
1059                 CHARS (8);
1060               }
1061           }
1062         for (i = 0; i < n_baseclasses; i++)
1063           {
1064             tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1065             if (use_gnu_debug_info_extensions)
1066               {
1067                 have_used_extensions = 1;
1068                 putc (TREE_VIA_VIRTUAL (child) ? '1'
1069                       : '0',
1070                       asmfile);
1071                 putc (TREE_VIA_PUBLIC (child) ? '2'
1072                       : '0',
1073                       asmfile);
1074                 fprintf (asmfile, "%d,",
1075                          TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT);
1076                 CHARS (15);
1077                 dbxout_type (BINFO_TYPE (child), 0, 0);
1078                 putc (';', asmfile);
1079               }
1080             else
1081               {
1082                 /* Print out the base class information with fields
1083                    which have the same names at the types they hold.  */
1084                 dbxout_type_name (BINFO_TYPE (child));
1085                 putc (':', asmfile);
1086                 dbxout_type (BINFO_TYPE (child), full, 0);
1087                 fprintf (asmfile, ",%d,%d;",
1088                          TREE_INT_CST_LOW (BINFO_OFFSET (child)) * BITS_PER_UNIT,
1089                          TREE_INT_CST_LOW (DECL_SIZE (TYPE_NAME (BINFO_TYPE (child)))) * BITS_PER_UNIT);
1090                 CHARS (20);
1091               }
1092           }
1093       }
1094
1095       CHARS (11);
1096
1097       /* Write out the field declarations.  */
1098       dbxout_type_fields (type);
1099       if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1100         {
1101           have_used_extensions = 1;
1102           dbxout_type_methods (type);
1103         }
1104       putc (';', asmfile);
1105
1106       if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1107           /* Avoid the ~ if we don't really need it--it confuses dbx.  */
1108           && TYPE_VFIELD (type))
1109         {
1110           have_used_extensions = 1;
1111
1112           /* Tell GDB+ that it may keep reading.  */
1113           putc ('~', asmfile);
1114
1115           /* We need to write out info about what field this class
1116              uses as its "main" vtable pointer field, because if this
1117              field is inherited from a base class, GDB cannot necessarily
1118              figure out which field it's using in time.  */
1119           if (TYPE_VFIELD (type))
1120             {
1121               putc ('%', asmfile);
1122               dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0, 0);
1123             }
1124           putc (';', asmfile);
1125           CHARS (3);
1126         }
1127       break;
1128
1129     case ENUMERAL_TYPE:
1130       if ((TYPE_NAME (type) != 0 && !full
1131            && (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1132                && ! DECL_IGNORED_P (TYPE_NAME (type))))
1133           || TYPE_SIZE (type) == 0)
1134         {
1135           fprintf (asmfile, "xe");
1136           CHARS (3);
1137           dbxout_type_name (type);
1138           typevec[TYPE_SYMTAB_ADDRESS (type)] = TYPE_XREF;
1139           fprintf (asmfile, ":");
1140           return;
1141         }
1142 #ifdef DBX_OUTPUT_ENUM
1143       DBX_OUTPUT_ENUM (asmfile, type);
1144 #else
1145       putc ('e', asmfile);
1146       CHARS (1);
1147       for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1148         {
1149           fprintf (asmfile, "%s:%d,", IDENTIFIER_POINTER (TREE_PURPOSE (tem)),
1150                    TREE_INT_CST_LOW (TREE_VALUE (tem)));
1151           CHARS (11 + IDENTIFIER_LENGTH (TREE_PURPOSE (tem)));
1152           if (TREE_CHAIN (tem) != 0)
1153             CONTIN;
1154         }
1155       putc (';', asmfile);
1156       CHARS (1);
1157 #endif
1158       break;
1159
1160     case POINTER_TYPE:
1161       putc ('*', asmfile);
1162       CHARS (1);
1163       dbxout_type (TREE_TYPE (type), 0, 0);
1164       break;
1165
1166     case METHOD_TYPE:
1167       if (use_gnu_debug_info_extensions)
1168         {
1169           have_used_extensions = 1;
1170           putc ('#', asmfile);
1171           CHARS (1);
1172           if (flag_minimal_debug && !show_arg_types)
1173             {
1174               /* Normally, just output the return type.
1175                  The argument types are encoded in the method name.  */
1176               putc ('#', asmfile);
1177               dbxout_type (TREE_TYPE (type), 0, 0);
1178               putc (';', asmfile);
1179               CHARS (1);
1180             }
1181           else
1182             {
1183               /* When outputting destructors, we need to write
1184                  the argument types out longhand.  */
1185               dbxout_type (TYPE_METHOD_BASETYPE (type), 0, 0);
1186               putc (',', asmfile);
1187               CHARS (1);
1188               dbxout_type (TREE_TYPE (type), 0, 0);
1189               dbxout_args (TYPE_ARG_TYPES (type));
1190               putc (';', asmfile);
1191               CHARS (1);
1192             }
1193         }
1194       else
1195         {
1196           /* Treat it as a function type.  */
1197           dbxout_type (TREE_TYPE (type), 0, 0);
1198         }
1199       break;
1200
1201     case OFFSET_TYPE:
1202       if (use_gnu_debug_info_extensions)
1203         {
1204           have_used_extensions = 1;
1205           putc ('@', asmfile);
1206           CHARS (1);
1207           dbxout_type (TYPE_OFFSET_BASETYPE (type), 0, 0);
1208           putc (',', asmfile);
1209           CHARS (1);
1210           dbxout_type (TREE_TYPE (type), 0, 0);
1211         }
1212       else
1213         {
1214           /* Should print as an int, because it is really
1215              just an offset.  */
1216           dbxout_type (integer_type_node, 0, 0);
1217         }
1218       break;
1219
1220     case REFERENCE_TYPE:
1221       if (use_gnu_debug_info_extensions)
1222         have_used_extensions = 1;
1223       putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1224       CHARS (1);
1225       dbxout_type (TREE_TYPE (type), 0, 0);
1226       break;
1227
1228     case FUNCTION_TYPE:
1229       putc ('f', asmfile);
1230       CHARS (1);
1231       dbxout_type (TREE_TYPE (type), 0, 0);
1232       break;
1233
1234     default:
1235       abort ();
1236     }
1237 }
1238
1239 /* Print the value of integer constant C, in octal,
1240    handling double precision.  */
1241
1242 static void
1243 print_int_cst_octal (c)
1244      tree c;
1245 {
1246   unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1247   unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1248   int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1249
1250   fprintf (asmfile, "0");
1251
1252   if (excess == 3)
1253     {
1254       print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1255       print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1256     }
1257   else
1258     {
1259       unsigned HOST_WIDE_INT beg = high >> excess;
1260       unsigned HOST_WIDE_INT middle
1261         = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1262            | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1263       unsigned HOST_WIDE_INT end
1264         = low & (((HOST_WIDE_INT) 1 << (HOST_BITS_PER_WIDE_INT / 3 * 3)) - 1);
1265       fprintf (asmfile, "%o%01o", beg, middle);
1266       print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1267     }
1268 }
1269
1270 static void
1271 print_octal (value, digits)
1272      unsigned HOST_WIDE_INT value;
1273      int digits;
1274 {
1275   int i;
1276
1277   for (i = digits - 1; i >= 0; i--)
1278     fprintf (asmfile, "%01o", ((value >> (3 * i)) & 7));
1279 }
1280
1281 /* Output the name of type TYPE, with no punctuation.
1282    Such names can be set up either by typedef declarations
1283    or by struct, enum and union tags.  */
1284
1285 static void
1286 dbxout_type_name (type)
1287      register tree type;
1288 {
1289   tree t;
1290   if (TYPE_NAME (type) == 0)
1291     abort ();
1292   if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1293     {
1294       t = TYPE_NAME (type);
1295     }
1296   else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1297     {
1298       t = DECL_NAME (TYPE_NAME (type));
1299     }
1300   else
1301     abort ();
1302
1303   fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1304   CHARS (IDENTIFIER_LENGTH (t));
1305 }
1306 \f
1307 /* Output a .stabs for the symbol defined by DECL,
1308    which must be a ..._DECL node in the normal namespace.
1309    It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1310    LOCAL is nonzero if the scope is less than the entire file.  */
1311
1312 void
1313 dbxout_symbol (decl, local)
1314      tree decl;
1315      int local;
1316 {
1317   int letter = 0;
1318   tree type = TREE_TYPE (decl);
1319   tree context = NULL_TREE;
1320   int regno = -1;
1321
1322   /* Cast avoids warning in old compilers.  */
1323   current_sym_code = (STAB_CODE_TYPE) 0;
1324   current_sym_value = 0;
1325   current_sym_addr = 0;
1326
1327   /* Ignore nameless syms, but don't ignore type tags.  */
1328
1329   if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1330       || DECL_IGNORED_P (decl))
1331     return;
1332
1333   dbxout_prepare_symbol (decl);
1334
1335   /* The output will always start with the symbol name,
1336      so always count that in the length-output-so-far.  */
1337
1338   if (DECL_NAME (decl) != 0)
1339     current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1340
1341   switch (TREE_CODE (decl))
1342     {
1343     case CONST_DECL:
1344       /* Enum values are defined by defining the enum type.  */
1345       break;
1346
1347     case FUNCTION_DECL:
1348       if (DECL_RTL (decl) == 0)
1349         return;
1350       if (DECL_EXTERNAL (decl))
1351         break;
1352       /* Don't mention a nested function under its parent.  */
1353       context = decl_function_context (decl);
1354       if (context == current_function_decl)
1355         break;
1356       if (GET_CODE (DECL_RTL (decl)) != MEM
1357           || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1358         break;
1359       FORCE_TEXT;
1360
1361       fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1362                IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1363                TREE_PUBLIC (decl) ? 'F' : 'f');
1364
1365       current_sym_code = N_FUN;
1366       current_sym_addr = XEXP (DECL_RTL (decl), 0);
1367
1368       if (TREE_TYPE (type))
1369         dbxout_type (TREE_TYPE (type), 0, 0);
1370       else
1371         dbxout_type (void_type_node, 0, 0);
1372
1373       /* For a nested function, when that function is compiled,
1374          mention the containing function name
1375          as well as (since dbx wants it) our own assembler-name.  */
1376       if (context != 0)
1377         fprintf (asmfile, ",%s,%s",
1378                  IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1379                  IDENTIFIER_POINTER (DECL_NAME (context)));
1380
1381       dbxout_finish_symbol (decl);
1382       break;
1383
1384     case TYPE_DECL:
1385 #if 0
1386       /* This seems all wrong.  Outputting most kinds of types gives no name
1387          at all.  A true definition gives no name; a cross-ref for a
1388          structure can give the tag name, but not a type name.
1389          It seems that no typedef name is defined by outputting a type.  */
1390
1391       /* If this typedef name was defined by outputting the type,
1392          don't duplicate it.  */
1393       if (typevec[TYPE_SYMTAB_ADDRESS (type)] == TYPE_DEFINED
1394           && TYPE_NAME (TREE_TYPE (decl)) == decl)
1395         return;
1396 #endif
1397       /* Don't output the same typedef twice.
1398          And don't output what language-specific stuff doesn't want output.  */
1399       if (TREE_ASM_WRITTEN (decl) || DECL_IGNORED_P (decl))
1400         return;
1401
1402       FORCE_TEXT;
1403
1404       {
1405         int tag_needed = 1;
1406
1407         if (DECL_NAME (decl))
1408           {
1409             /* Nonzero means we must output a tag as well as a typedef.  */
1410             tag_needed = 0;
1411
1412             /* Handle the case of a C++ structure or union
1413                where the TYPE_NAME is a TYPE_DECL
1414                which gives both a typedef name and a tag.  */
1415             /* dbx requires the tag first and the typedef second.
1416                ??? there is a bug here.  It generates spurious tags
1417                for C code.  */
1418             if ((TREE_CODE (type) == RECORD_TYPE
1419                  || TREE_CODE (type) == UNION_TYPE)
1420                 && TYPE_NAME (type) == decl
1421                 && !(use_gnu_debug_info_extensions && have_used_extensions)
1422                 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1423               {
1424                 tree name = TYPE_NAME (type);
1425                 if (TREE_CODE (name) == TYPE_DECL)
1426                   name = DECL_NAME (name);
1427
1428                 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1429                 current_sym_value = 0;
1430                 current_sym_addr = 0;
1431                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1432
1433                 fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP,
1434                          IDENTIFIER_POINTER (name));
1435                 dbxout_type (type, 1, 0);
1436                 dbxout_finish_symbol (NULL_TREE);
1437               }
1438
1439             /* Output typedef name.  */
1440             fprintf (asmfile, "%s \"%s:", ASM_STABS_OP,
1441                      IDENTIFIER_POINTER (DECL_NAME (decl)));
1442
1443             /* Short cut way to output a tag also.  */
1444             if ((TREE_CODE (type) == RECORD_TYPE
1445                  || TREE_CODE (type) == UNION_TYPE)
1446                 && TYPE_NAME (type) == decl)
1447               {
1448                 if (use_gnu_debug_info_extensions && have_used_extensions)
1449                   {
1450                     putc ('T', asmfile);
1451                     TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1452                   }
1453 #if 0 /* Now we generate the tag for this case up above.  */
1454                 else
1455                   tag_needed = 1;
1456 #endif
1457               }
1458
1459             putc ('t', asmfile);
1460             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1461
1462             dbxout_type (type, 1, 0);
1463             dbxout_finish_symbol (decl);
1464           }
1465
1466         if (tag_needed && TYPE_NAME (type) != 0
1467             && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1468           {
1469             /* For a TYPE_DECL with no name, but the type has a name,
1470                output a tag.
1471                This is what represents `struct foo' with no typedef.  */
1472             /* In C++, the name of a type is the corresponding typedef.
1473                In C, it is an IDENTIFIER_NODE.  */
1474             tree name = TYPE_NAME (type);
1475             if (TREE_CODE (name) == TYPE_DECL)
1476               name = DECL_NAME (name);
1477
1478             current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1479             current_sym_value = 0;
1480             current_sym_addr = 0;
1481             current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1482
1483             fprintf (asmfile, "%s \"%s:T", ASM_STABS_OP,
1484                      IDENTIFIER_POINTER (name));
1485             dbxout_type (type, 1, 0);
1486             dbxout_finish_symbol (NULL_TREE);
1487           }
1488
1489         /* Prevent duplicate output of a typedef.  */
1490         TREE_ASM_WRITTEN (decl) = 1;
1491         break;
1492       }
1493
1494     case PARM_DECL:
1495       /* Parm decls go in their own separate chains
1496          and are output by dbxout_reg_parms and dbxout_parms.  */
1497       abort ();
1498
1499     case RESULT_DECL:
1500       /* Named return value, treat like a VAR_DECL.  */
1501     case VAR_DECL:
1502       if (DECL_RTL (decl) == 0)
1503         return;
1504       /* Don't mention a variable that is external.
1505          Let the file that defines it describe it.  */
1506       if (DECL_EXTERNAL (decl))
1507         break;
1508
1509       /* If the variable is really a constant
1510          and not written in memory, inform the debugger.  */
1511       if (TREE_STATIC (decl) && TREE_READONLY (decl)
1512           && DECL_INITIAL (decl) != 0
1513           && ! TREE_ASM_WRITTEN (decl)
1514           && (DECL_FIELD_CONTEXT (decl) == NULL_TREE
1515               || TREE_CODE (DECL_FIELD_CONTEXT (decl)) == BLOCK))
1516         {
1517           if (TREE_PUBLIC (decl) == 0)
1518             {
1519               /* The sun4 assembler does not grok this.  */
1520               char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
1521               if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
1522                   || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
1523                 {
1524                   HOST_WIDE_INT ival = TREE_INT_CST_LOW (DECL_INITIAL (decl));
1525 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
1526                   DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
1527 #else
1528                   fprintf (asmfile, "%s \"%s:c=i%d\",0x%x,0,0,0\n",
1529                            ASM_STABS_OP, name, ival, N_LSYM);
1530 #endif
1531                   return;
1532                 }
1533               else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
1534                 {
1535                   /* don't know how to do this yet.  */
1536                 }
1537               break;
1538             }
1539           /* else it is something we handle like a normal variable.  */
1540         }
1541
1542       DECL_RTL (decl) = eliminate_regs (DECL_RTL (decl), 0, 0);
1543 #ifdef LEAF_REG_REMAP
1544       if (leaf_function)
1545         leaf_renumber_regs_insn (DECL_RTL (decl));
1546 #endif
1547
1548       /* Don't mention a variable at all
1549          if it was completely optimized into nothingness.
1550
1551          If DECL was from an inline function, then it's rtl
1552          is not identically the rtl that was used in this
1553          particular compilation.  */
1554       if (GET_CODE (DECL_RTL (decl)) == REG)
1555         {
1556           regno = REGNO (DECL_RTL (decl));
1557           if (regno >= FIRST_PSEUDO_REGISTER)
1558             return;
1559         }
1560       else if (GET_CODE (DECL_RTL (decl)) == SUBREG)
1561         {
1562           rtx value = DECL_RTL (decl);
1563           int offset = 0;
1564           while (GET_CODE (value) == SUBREG)
1565             {
1566               offset += SUBREG_WORD (value);
1567               value = SUBREG_REG (value);
1568             }
1569           if (GET_CODE (value) == REG)
1570             {
1571               regno = REGNO (value);
1572               if (regno >= FIRST_PSEUDO_REGISTER)
1573                 return;
1574               regno += offset;
1575             }
1576           alter_subreg (DECL_RTL (decl));
1577         }
1578
1579       /* The kind-of-variable letter depends on where
1580          the variable is and on the scope of its name:
1581          G and N_GSYM for static storage and global scope,
1582          S for static storage and file scope,
1583          V for static storage and local scope,
1584             for those two, use N_LCSYM if data is in bss segment,
1585             N_STSYM if in data segment, N_FUN otherwise.
1586             (We used N_FUN originally, then changed to N_STSYM
1587             to please GDB.  However, it seems that confused ld.
1588             Now GDB has been fixed to like N_FUN, says Kingdon.)
1589          no letter at all, and N_LSYM, for auto variable,
1590          r and N_RSYM for register variable.  */
1591
1592       if (GET_CODE (DECL_RTL (decl)) == MEM
1593           && GET_CODE (XEXP (DECL_RTL (decl), 0)) == SYMBOL_REF)
1594         {
1595           if (TREE_PUBLIC (decl))
1596             {
1597               letter = 'G';
1598               current_sym_code = N_GSYM;
1599             }
1600           else
1601             {
1602               current_sym_addr = XEXP (DECL_RTL (decl), 0);
1603
1604               letter = decl_function_context (decl) ? 'V' : 'S';
1605
1606               if (!DECL_INITIAL (decl))
1607                 current_sym_code = N_LCSYM;
1608               else if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl))
1609                 /* This is not quite right, but it's the closest
1610                    of all the codes that Unix defines.  */
1611                 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
1612               else
1613                 {
1614 /* Ultrix `as' seems to need this.  */
1615 #ifdef DBX_STATIC_STAB_DATA_SECTION
1616                   data_section ();
1617 #endif
1618                   current_sym_code = N_STSYM;
1619                 }
1620             }
1621         }
1622       else if (regno >= 0)
1623         {
1624           letter = 'r';
1625           current_sym_code = N_RSYM;
1626           current_sym_value = DBX_REGISTER_NUMBER (regno);
1627         }
1628       else if (GET_CODE (DECL_RTL (decl)) == MEM
1629                && (GET_CODE (XEXP (DECL_RTL (decl), 0)) == MEM
1630                    || (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG
1631                        && REGNO (XEXP (DECL_RTL (decl), 0)) != FRAME_POINTER_REGNUM)))
1632         /* If the value is indirect by memory or by a register
1633            that isn't the frame pointer
1634            then it means the object is variable-sized and address through
1635            that register or stack slot.  DBX has no way to represent this
1636            so all we can do is output the variable as a pointer.
1637            If it's not a parameter, ignore it.
1638            (VAR_DECLs like this can be made by integrate.c.)  */
1639         {
1640           if (GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1641             {
1642               letter = 'r';
1643               current_sym_code = N_RSYM;
1644               current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (DECL_RTL (decl), 0)));
1645             }
1646           else
1647             {
1648               current_sym_code = N_LSYM;
1649               /* DECL_RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
1650                  We want the value of that CONST_INT.  */
1651               current_sym_value
1652                 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (DECL_RTL (decl), 0), 0));
1653             }
1654
1655           /* Effectively do build_pointer_type, but don't cache this type,
1656              since it might be temporary whereas the type it points to
1657              might have been saved for inlining.  */
1658           /* Don't use REFERENCE_TYPE because dbx can't handle that.  */
1659           type = make_node (POINTER_TYPE);
1660           TREE_TYPE (type) = TREE_TYPE (decl);
1661         }
1662       else if (GET_CODE (DECL_RTL (decl)) == MEM
1663                && GET_CODE (XEXP (DECL_RTL (decl), 0)) == REG)
1664         {
1665           current_sym_code = N_LSYM;
1666           current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (DECL_RTL (decl), 0));
1667         }
1668       else if (GET_CODE (DECL_RTL (decl)) == MEM
1669                && GET_CODE (XEXP (DECL_RTL (decl), 0)) == PLUS
1670                && GET_CODE (XEXP (XEXP (DECL_RTL (decl), 0), 1)) == CONST_INT)
1671         {
1672           current_sym_code = N_LSYM;
1673           /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
1674              We want the value of that CONST_INT.  */
1675           current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (DECL_RTL (decl), 0));
1676         }
1677       else if (GET_CODE (DECL_RTL (decl)) == MEM
1678                && GET_CODE (XEXP (DECL_RTL (decl), 0)) == CONST)
1679         {
1680           /* Handle an obscure case which can arise when optimizing and
1681              when there are few available registers.  (This is *always*
1682              the case for i386/i486 targets).  The DECL_RTL looks like
1683              (MEM (CONST ...)) even though this variable is a local `auto'
1684              or a local `register' variable.  In effect, what has happened
1685              is that the reload pass has seen that all assignments and
1686              references for one such a local variable can be replaced by
1687              equivalent assignments and references to some static storage
1688              variable, thereby avoiding the need for a register.  In such
1689              cases we're forced to lie to debuggers and tell them that
1690              this variable was itself `static'.  */
1691           current_sym_code = N_LCSYM;
1692           letter = 'V';
1693           current_sym_addr = XEXP (XEXP (DECL_RTL (decl), 0), 0);
1694         }
1695       else
1696         /* Address might be a MEM, when DECL is a variable-sized object.
1697            Or it might be const0_rtx, meaning previous passes
1698            want us to ignore this variable.  */
1699         break;
1700
1701       /* Ok, start a symtab entry and output the variable name.  */
1702       FORCE_TEXT;
1703
1704 #ifdef DBX_STATIC_BLOCK_START
1705       DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
1706 #endif
1707
1708       /* One slight hitch: if this is a VAR_DECL which is a static
1709          class member, we must put out the mangled name instead of the
1710          DECL_NAME.  */
1711       {
1712         char *name;
1713         /* Note also that static member (variable) names DO NOT begin
1714            with underscores in .stabs directives.  */
1715         if (DECL_LANG_SPECIFIC (decl))
1716           name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
1717         else
1718           name = IDENTIFIER_POINTER (DECL_NAME (decl));
1719         fprintf (asmfile, "%s \"%s:", ASM_STABS_OP, name);
1720       }
1721       if (letter) putc (letter, asmfile);
1722       dbxout_type (type, 0, 0);
1723       dbxout_finish_symbol (decl);
1724
1725 #ifdef DBX_STATIC_BLOCK_END
1726       DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
1727 #endif
1728       break;
1729     }
1730 }
1731
1732 static void
1733 dbxout_prepare_symbol (decl)
1734      tree decl;
1735 {
1736 #ifdef WINNING_GDB
1737   char *filename = DECL_SOURCE_FILE (decl);
1738
1739   dbxout_source_file (asmfile, filename);
1740 #endif
1741 }
1742
1743 static void
1744 dbxout_finish_symbol (sym)
1745      tree sym;
1746 {
1747 #ifdef DBX_FINISH_SYMBOL
1748   DBX_FINISH_SYMBOL (sym);
1749 #else
1750   int line = 0;
1751 #ifdef WINNING_GDB
1752   if (sym != 0)
1753     line = DECL_SOURCE_LINE (sym);
1754 #endif
1755
1756   fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
1757   if (current_sym_addr)
1758     output_addr_const (asmfile, current_sym_addr);
1759   else
1760     fprintf (asmfile, "%d", current_sym_value);
1761   putc ('\n', asmfile);
1762 #endif
1763 }
1764
1765 /* Output definitions of all the decls in a chain.  */
1766
1767 void
1768 dbxout_syms (syms)
1769      tree syms;
1770 {
1771   while (syms)
1772     {
1773       dbxout_symbol (syms, 1);
1774       syms = TREE_CHAIN (syms);
1775     }
1776 }
1777 \f
1778 /* The following two functions output definitions of function parameters.
1779    Each parameter gets a definition locating it in the parameter list.
1780    Each parameter that is a register variable gets a second definition
1781    locating it in the register.
1782
1783    Printing or argument lists in gdb uses the definitions that
1784    locate in the parameter list.  But reference to the variable in
1785    expressions uses preferentially the definition as a register.  */
1786
1787 /* Output definitions, referring to storage in the parmlist,
1788    of all the parms in PARMS, which is a chain of PARM_DECL nodes.  */
1789
1790 void
1791 dbxout_parms (parms)
1792      tree parms;
1793 {
1794   for (; parms; parms = TREE_CHAIN (parms))
1795     if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
1796       {
1797         dbxout_prepare_symbol (parms);
1798
1799         /* Perform any necessary register eliminations on the parameter's rtl,
1800            so that the debugging output will be accurate.  */
1801         DECL_INCOMING_RTL (parms)
1802           = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
1803         DECL_RTL (parms) = eliminate_regs (DECL_RTL (parms), 0, NULL_RTX);
1804 #ifdef LEAF_REG_REMAP
1805         if (leaf_function)
1806           {
1807             leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
1808             leaf_renumber_regs_insn (DECL_RTL (parms));
1809           }
1810 #endif
1811
1812         if (PARM_PASSED_IN_MEMORY (parms))
1813           {
1814             rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
1815
1816             /* ??? Here we assume that the parm address is indexed
1817                off the frame pointer or arg pointer.
1818                If that is not true, we produce meaningless results,
1819                but do not crash.  */
1820             if (GET_CODE (addr) == PLUS
1821                 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
1822               current_sym_value = INTVAL (XEXP (addr, 1));
1823             else
1824               current_sym_value = 0;
1825
1826             current_sym_code = N_PSYM;
1827             current_sym_addr = 0;
1828
1829             FORCE_TEXT;
1830             if (DECL_NAME (parms))
1831               {
1832                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1833
1834                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1835                          IDENTIFIER_POINTER (DECL_NAME (parms)),
1836                          DBX_MEMPARM_STABS_LETTER);
1837               }
1838             else
1839               {
1840                 current_sym_nchars = 8;
1841                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
1842                          DBX_MEMPARM_STABS_LETTER);
1843               }
1844
1845             if (GET_CODE (DECL_RTL (parms)) == REG
1846                 && REGNO (DECL_RTL (parms)) >= 0
1847                 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1848               dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
1849             else
1850               {
1851                 int original_value = current_sym_value;
1852
1853                 /* This is the case where the parm is passed as an int or double
1854                    and it is converted to a char, short or float and stored back
1855                    in the parmlist.  In this case, describe the parm
1856                    with the variable's declared type, and adjust the address
1857                    if the least significant bytes (which we are using) are not
1858                    the first ones.  */
1859 #if BYTES_BIG_ENDIAN
1860                 if (TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
1861                   current_sym_value += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
1862                                         - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
1863 #endif
1864
1865                 if (GET_CODE (DECL_RTL (parms)) == MEM
1866                     && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
1867                     && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
1868                     && INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == current_sym_value)
1869                   dbxout_type (TREE_TYPE (parms), 0, 0);
1870                 else
1871                   {
1872                     current_sym_value = original_value;
1873                     dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
1874                   }
1875               }
1876             current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
1877             dbxout_finish_symbol (parms);
1878           }
1879         else if (GET_CODE (DECL_RTL (parms)) == REG)
1880           {
1881             rtx best_rtl;
1882             char regparm_letter;
1883             /* Parm passed in registers and lives in registers or nowhere.  */
1884
1885             current_sym_code = DBX_REGPARM_STABS_CODE;
1886             regparm_letter = DBX_REGPARM_STABS_LETTER;
1887             current_sym_addr = 0;
1888
1889             /* If parm lives in a register, use that register;
1890                pretend the parm was passed there.  It would be more consistent
1891                to describe the register where the parm was passed,
1892                but in practice that register usually holds something else.  */
1893             if (REGNO (DECL_RTL (parms)) >= 0
1894                 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
1895               best_rtl = DECL_RTL (parms);
1896             /* If the parm lives nowhere,
1897                use the register where it was passed.  */
1898             else
1899               best_rtl = DECL_INCOMING_RTL (parms);
1900             current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
1901
1902             FORCE_TEXT;
1903             if (DECL_NAME (parms))
1904               {
1905                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
1906                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1907                          IDENTIFIER_POINTER (DECL_NAME (parms)),
1908                          regparm_letter);
1909               }
1910             else
1911               {
1912                 current_sym_nchars = 8;
1913                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
1914                          regparm_letter);
1915               }
1916
1917             dbxout_type (DECL_ARG_TYPE (parms), 0, 0);
1918             dbxout_finish_symbol (parms);
1919           }
1920         else if (GET_CODE (DECL_RTL (parms)) == MEM
1921                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1922                  && rtx_equal_p (XEXP (DECL_RTL (parms), 0),
1923                                  DECL_INCOMING_RTL (parms)))
1924           {
1925             /* Parm was passed via invisible reference.
1926                That is, its address was passed in a register.
1927                Output it as if it lived in that register.
1928                The debugger will know from the type
1929                that it was actually passed by invisible reference.  */
1930
1931             char regparm_letter;
1932             /* Parm passed in registers and lives in registers or nowhere.  */
1933
1934             current_sym_code = DBX_REGPARM_STABS_CODE;
1935             regparm_letter = DBX_REGPARM_STABS_LETTER;
1936
1937             /* DECL_RTL looks like (MEM (REG...).  Get the register number.  */
1938             current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
1939             current_sym_addr = 0;
1940
1941             FORCE_TEXT;
1942             if (DECL_NAME (parms))
1943               {
1944                 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
1945
1946                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1947                          IDENTIFIER_POINTER (DECL_NAME (parms)),
1948                          DBX_REGPARM_STABS_LETTER);
1949               }
1950             else
1951               {
1952                 current_sym_nchars = 8;
1953                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
1954                          DBX_REGPARM_STABS_LETTER);
1955               }
1956
1957             dbxout_type (TREE_TYPE (parms), 0, 0);
1958             dbxout_finish_symbol (parms);
1959           }
1960         else if (GET_CODE (DECL_RTL (parms)) == MEM
1961                  && XEXP (DECL_RTL (parms), 0) != const0_rtx)
1962           {
1963             /* Parm was passed in registers but lives on the stack.  */
1964
1965             current_sym_code = N_PSYM;
1966             /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
1967                in which case we want the value of that CONST_INT,
1968                or (MEM (REG ...)) or (MEM (MEM ...)),
1969                in which case we use a value of zero.  */
1970             if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
1971                 || GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
1972               current_sym_value = 0;
1973             else
1974               current_sym_value = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
1975             current_sym_addr = 0;
1976
1977             FORCE_TEXT;
1978             if (DECL_NAME (parms))
1979               {
1980                 current_sym_nchars = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
1981
1982                 fprintf (asmfile, "%s \"%s:%c", ASM_STABS_OP,
1983                          IDENTIFIER_POINTER (DECL_NAME (parms)),
1984                          DBX_MEMPARM_STABS_LETTER);
1985               }
1986             else
1987               {
1988                 current_sym_nchars = 8;
1989                 fprintf (asmfile, "%s \"(anon):%c", ASM_STABS_OP,
1990                 DBX_MEMPARM_STABS_LETTER);
1991               }
1992
1993             current_sym_value
1994               = DEBUGGER_ARG_OFFSET (current_sym_value,
1995                                      XEXP (DECL_RTL (parms), 0));
1996             dbxout_type (TREE_TYPE (parms), 0, 0);
1997             dbxout_finish_symbol (parms);
1998           }
1999       }
2000 }
2001
2002 /* Output definitions for the places where parms live during the function,
2003    when different from where they were passed, when the parms were passed
2004    in memory.
2005
2006    It is not useful to do this for parms passed in registers
2007    that live during the function in different registers, because it is
2008    impossible to look in the passed register for the passed value,
2009    so we use the within-the-function register to begin with.
2010
2011    PARMS is a chain of PARM_DECL nodes.  */
2012
2013 void
2014 dbxout_reg_parms (parms)
2015      tree parms;
2016 {
2017   for (; parms; parms = TREE_CHAIN (parms))
2018     if (DECL_NAME (parms))
2019       {
2020         dbxout_prepare_symbol (parms);
2021
2022         /* Report parms that live in registers during the function
2023            but were passed in memory.  */
2024         if (GET_CODE (DECL_RTL (parms)) == REG
2025             && REGNO (DECL_RTL (parms)) >= 0
2026             && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER
2027             && PARM_PASSED_IN_MEMORY (parms))
2028           {
2029             current_sym_code = N_RSYM;
2030             current_sym_value = DBX_REGISTER_NUMBER (REGNO (DECL_RTL (parms)));
2031             current_sym_addr = 0;
2032
2033             FORCE_TEXT;
2034             if (DECL_NAME (parms))
2035               {
2036                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2037                 fprintf (asmfile, "%s \"%s:r", ASM_STABS_OP,
2038                          IDENTIFIER_POINTER (DECL_NAME (parms)));
2039               }
2040             else
2041               {
2042                 current_sym_nchars = 8;
2043                 fprintf (asmfile, "%s \"(anon):r", ASM_STABS_OP);
2044               }
2045             dbxout_type (TREE_TYPE (parms), 0, 0);
2046             dbxout_finish_symbol (parms);
2047           }
2048         /* Report parms that live in memory but not where they were passed.  */
2049         else if (GET_CODE (DECL_RTL (parms)) == MEM
2050                  && GET_CODE (XEXP (DECL_RTL (parms), 0)) == PLUS
2051                  && GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 1)) == CONST_INT
2052                  && PARM_PASSED_IN_MEMORY (parms)
2053                  && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2054           {
2055 #if 0 /* ??? It is not clear yet what should replace this.  */
2056             int offset = DECL_OFFSET (parms) / BITS_PER_UNIT;
2057             /* A parm declared char is really passed as an int,
2058                so it occupies the least significant bytes.
2059                On a big-endian machine those are not the low-numbered ones.  */
2060 #if BYTES_BIG_ENDIAN
2061             if (offset != -1 && TREE_TYPE (parms) != DECL_ARG_TYPE (parms))
2062               offset += (GET_MODE_SIZE (TYPE_MODE (DECL_ARG_TYPE (parms)))
2063                          - GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))));
2064 #endif
2065             if (INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)) != offset) {...}
2066 #endif
2067             current_sym_code = N_LSYM;
2068             current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (DECL_RTL (parms), 0));
2069             current_sym_addr = 0;
2070             FORCE_TEXT;
2071             if (DECL_NAME (parms))
2072               {
2073                 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2074                 fprintf (asmfile, "%s \"%s:", ASM_STABS_OP,
2075                          IDENTIFIER_POINTER (DECL_NAME (parms)));
2076               }
2077             else
2078               {
2079                 current_sym_nchars = 8;
2080                 fprintf (asmfile, "%s \"(anon):", ASM_STABS_OP);
2081               }
2082             dbxout_type (TREE_TYPE (parms), 0, 0);
2083             dbxout_finish_symbol (parms);
2084           }
2085       }
2086 }
2087 \f
2088 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2089    output definitions of those names, in raw form */
2090
2091 void
2092 dbxout_args (args)
2093      tree args;
2094 {
2095   while (args)
2096     {
2097       putc (',', asmfile);
2098       dbxout_type (TREE_VALUE (args), 0, 0);
2099       CHARS (1);
2100       args = TREE_CHAIN (args);
2101     }
2102 }
2103 \f
2104 /* Given a chain of ..._TYPE nodes,
2105    find those which have typedef names and output those names.
2106    This is to ensure those types get output.  */
2107
2108 void
2109 dbxout_types (types)
2110      register tree types;
2111 {
2112   while (types)
2113     {
2114       if (TYPE_NAME (types)
2115           && TREE_CODE (TYPE_NAME (types)) == TYPE_DECL
2116           && ! TREE_ASM_WRITTEN (TYPE_NAME (types)))
2117         dbxout_symbol (TYPE_NAME (types), 1);
2118       types = TREE_CHAIN (types);
2119     }
2120 }
2121 \f
2122 /* Output everything about a symbol block (a BLOCK node
2123    that represents a scope level),
2124    including recursive output of contained blocks.
2125
2126    BLOCK is the BLOCK node.
2127    DEPTH is its depth within containing symbol blocks.
2128    ARGS is usually zero; but for the outermost block of the
2129    body of a function, it is a chain of PARM_DECLs for the function parameters.
2130    We output definitions of all the register parms
2131    as if they were local variables of that block.
2132
2133    If -g1 was used, we count blocks just the same, but output nothing
2134    except for the outermost block.
2135
2136    Actually, BLOCK may be several blocks chained together.
2137    We handle them all in sequence.  */
2138
2139 static void
2140 dbxout_block (block, depth, args)
2141      register tree block;
2142      int depth;
2143      tree args;
2144 {
2145   int blocknum;
2146
2147   while (block)
2148     {
2149       /* Ignore blocks never expanded or otherwise marked as real.  */
2150       if (TREE_USED (block))
2151         {
2152 #ifndef DBX_LBRAC_FIRST
2153           /* In dbx format, the syms of a block come before the N_LBRAC.  */
2154           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2155             dbxout_syms (BLOCK_VARS (block));
2156           if (args)
2157             dbxout_reg_parms (args);
2158 #endif
2159
2160           /* Now output an N_LBRAC symbol to represent the beginning of
2161              the block.  Use the block's tree-walk order to generate
2162              the assembler symbols LBBn and LBEn
2163              that final will define around the code in this block.  */
2164           if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE)
2165             {
2166               char buf[20];
2167               blocknum = next_block_number++;
2168               ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2169
2170               if (BLOCK_HANDLER_BLOCK (block))
2171                 {
2172                   /* A catch block.  Must precede N_LBRAC.  */
2173                   tree decl = BLOCK_VARS (block);
2174                   while (decl)
2175                     {
2176 #ifdef DBX_OUTPUT_CATCH
2177                       DBX_OUTPUT_CATCH (asmfile, decl, buf);
2178 #else
2179                       fprintf (asmfile, "%s \"%s:C1\",%d,0,0,", ASM_STABS_OP,
2180                                IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2181                       assemble_name (asmfile, buf);
2182                       fprintf (asmfile, "\n");
2183 #endif
2184                       decl = TREE_CHAIN (decl);
2185                     }
2186                 }
2187
2188 #ifdef DBX_OUTPUT_LBRAC
2189               DBX_OUTPUT_LBRAC (asmfile, buf);
2190 #else
2191               fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_LBRAC);
2192               assemble_name (asmfile, buf);
2193 #if DBX_BLOCKS_FUNCTION_RELATIVE
2194               fputc ('-', asmfile);
2195               assemble_name (asmfile, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
2196 #endif
2197               fprintf (asmfile, "\n");
2198 #endif
2199             }
2200           else if (depth > 0)
2201             /* Count blocks the same way regardless of debug_info_level.  */
2202             next_block_number++;
2203
2204 #ifdef DBX_LBRAC_FIRST
2205           /* On some weird machines, the syms of a block
2206              come after the N_LBRAC.  */
2207           if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2208             dbxout_syms (BLOCK_VARS (block));
2209           if (args)
2210             dbxout_reg_parms (args);
2211 #endif
2212
2213           /* Output the subblocks.  */
2214           dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2215
2216           /* Refer to the marker for the end of the block.  */
2217           if (depth > 0 && debug_info_level != DINFO_LEVEL_TERSE)
2218             {
2219               char buf[20];
2220               ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2221 #ifdef DBX_OUTPUT_RBRAC
2222               DBX_OUTPUT_RBRAC (asmfile, buf);
2223 #else
2224               fprintf (asmfile, "%s %d,0,0,", ASM_STABN_OP, N_RBRAC);
2225               assemble_name (asmfile, buf);
2226 #if DBX_BLOCKS_FUNCTION_RELATIVE
2227               fputc ('-', asmfile);
2228               assemble_name (asmfile, IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (current_function_decl)));
2229 #endif
2230               fprintf (asmfile, "\n");
2231 #endif
2232             }
2233         }
2234       block = BLOCK_CHAIN (block);
2235     }
2236 }
2237
2238 /* Output the information about a function and its arguments and result.
2239    Usually this follows the function's code,
2240    but on some systems, it comes before.  */
2241
2242 static void
2243 dbxout_really_begin_function (decl)
2244      tree decl;
2245 {
2246   dbxout_symbol (decl, 0);
2247   dbxout_parms (DECL_ARGUMENTS (decl));
2248   if (DECL_NAME (DECL_RESULT (decl)) != 0)
2249     dbxout_symbol (DECL_RESULT (decl), 1);
2250 }
2251
2252 /* Called at beginning of output of function definition.  */
2253
2254 void
2255 dbxout_begin_function (decl)
2256      tree decl;
2257 {
2258 #ifdef DBX_FUNCTION_FIRST
2259   dbxout_really_begin_function (decl);
2260 #endif
2261 }
2262
2263 /* Output dbx data for a function definition.
2264    This includes a definition of the function name itself (a symbol),
2265    definitions of the parameters (locating them in the parameter list)
2266    and then output the block that makes up the function's body
2267    (including all the auto variables of the function).  */
2268
2269 void
2270 dbxout_function (decl)
2271      tree decl;
2272 {
2273 #ifndef DBX_FUNCTION_FIRST
2274   dbxout_really_begin_function (decl);
2275 #endif
2276   dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
2277 #ifdef DBX_OUTPUT_FUNCTION_END
2278   DBX_OUTPUT_FUNCTION_END (asmfile, decl);
2279 #endif
2280 }
2281 #endif /* DBX_DEBUGGING_INFO */