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