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