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