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