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