2002-02-19 Philip Blundell <philb@gnu.org>
[official-gcc.git] / gcc / dbxout.c
blob2db1f3a9fe2c89855d5919f29df4a84c88a9150f
1 /* Output dbx-format symbol table information from GNU compiler.
2 Copyright (C) 1987, 1988, 1992, 1993, 1994, 1995, 1996, 1997, 1998,
3 1999, 2000, 2001 Free Software Foundation, Inc.
5 This file is part of GCC.
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.
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.
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. */
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.
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.
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.
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".
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'.
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.
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.
66 If DEBUG_SYMS_TEXT is defined, all debugging symbols must be
67 output while in the text section.
69 For more on data type definitions, see `dbxout_type'. */
71 #include "config.h"
72 #include "system.h"
74 #include "tree.h"
75 #include "rtl.h"
76 #include "flags.h"
77 #include "regs.h"
78 #include "insn-config.h"
79 #include "reload.h"
80 #include "output.h" /* ASM_OUTPUT_SOURCE_LINE may refer to sdb functions. */
81 #include "dbxout.h"
82 #include "toplev.h"
83 #include "tm_p.h"
84 #include "ggc.h"
85 #include "debug.h"
86 #include "function.h"
87 #include "target.h"
88 #include "langhooks.h"
90 #ifdef XCOFF_DEBUGGING_INFO
91 #include "xcoffout.h"
92 #endif
94 #ifndef ASM_STABS_OP
95 #define ASM_STABS_OP "\t.stabs\t"
96 #endif
98 #ifndef ASM_STABN_OP
99 #define ASM_STABN_OP "\t.stabn\t"
100 #endif
102 #ifndef DBX_TYPE_DECL_STABS_CODE
103 #define DBX_TYPE_DECL_STABS_CODE N_LSYM
104 #endif
106 #ifndef DBX_STATIC_CONST_VAR_CODE
107 #define DBX_STATIC_CONST_VAR_CODE N_FUN
108 #endif
110 #ifndef DBX_REGPARM_STABS_CODE
111 #define DBX_REGPARM_STABS_CODE N_RSYM
112 #endif
114 #ifndef DBX_REGPARM_STABS_LETTER
115 #define DBX_REGPARM_STABS_LETTER 'P'
116 #endif
118 /* This is used for parameters passed by invisible reference in a register. */
119 #ifndef GDB_INV_REF_REGPARM_STABS_LETTER
120 #define GDB_INV_REF_REGPARM_STABS_LETTER 'a'
121 #endif
123 #ifndef DBX_MEMPARM_STABS_LETTER
124 #define DBX_MEMPARM_STABS_LETTER 'p'
125 #endif
127 #ifndef FILE_NAME_JOINER
128 #define FILE_NAME_JOINER "/"
129 #endif
131 /* GDB needs to know that the stabs were generated by GCC. We emit an
132 N_OPT stab at the beginning of the source file to indicate this.
133 The string is historical, and different on a very few targets. */
134 #ifndef STABS_GCC_MARKER
135 #define STABS_GCC_MARKER "gcc2_compiled."
136 #endif
138 /* Typical USG systems don't have stab.h, and they also have
139 no use for DBX-format debugging info. */
141 #if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)
143 /* Nonzero if we have actually used any of the GDB extensions
144 to the debugging format. The idea is that we use them for the
145 first time only if there's a strong reason, but once we have done that,
146 we use them whenever convenient. */
148 static int have_used_extensions = 0;
150 /* Number for the next N_SOL filename stabs label. The number 0 is reserved
151 for the N_SO filename stabs label. */
153 #if defined (DBX_DEBUGGING_INFO) && !defined (DBX_OUTPUT_SOURCE_FILENAME)
154 static int source_label_number = 1;
155 #endif
157 #ifdef DEBUG_SYMS_TEXT
158 #define FORCE_TEXT text_section ();
159 #else
160 #define FORCE_TEXT
161 #endif
163 #include "gstab.h"
165 #define STAB_CODE_TYPE enum __stab_debug_code
167 /* 1 if PARM is passed to this function in memory. */
169 #define PARM_PASSED_IN_MEMORY(PARM) \
170 (GET_CODE (DECL_INCOMING_RTL (PARM)) == MEM)
172 /* A C expression for the integer offset value of an automatic variable
173 (N_LSYM) having address X (an RTX). */
174 #ifndef DEBUGGER_AUTO_OFFSET
175 #define DEBUGGER_AUTO_OFFSET(X) \
176 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0)
177 #endif
179 /* A C expression for the integer offset value of an argument (N_PSYM)
180 having address X (an RTX). The nominal offset is OFFSET. */
181 #ifndef DEBUGGER_ARG_OFFSET
182 #define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET)
183 #endif
185 /* Stream for writing to assembler file. */
187 static FILE *asmfile;
189 /* Last source file name mentioned in a NOTE insn. */
191 static const char *lastfile;
193 /* Current working directory. */
195 static const char *cwd;
197 enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED};
199 /* Structure recording information about a C data type.
200 The status element says whether we have yet output
201 the definition of the type. TYPE_XREF says we have
202 output it as a cross-reference only.
203 The file_number and type_number elements are used if DBX_USE_BINCL
204 is defined. */
206 struct typeinfo
208 enum typestatus status;
209 #ifdef DBX_USE_BINCL
210 int file_number;
211 int type_number;
212 #endif
215 /* Vector recording information about C data types.
216 When we first notice a data type (a tree node),
217 we assign it a number using next_type_number.
218 That is its index in this vector. */
220 struct typeinfo *typevec;
222 /* Number of elements of space allocated in `typevec'. */
224 static int typevec_len;
226 /* In dbx output, each type gets a unique number.
227 This is the number for the next type output.
228 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */
230 static int next_type_number;
232 #ifdef DBX_USE_BINCL
234 /* When using N_BINCL in dbx output, each type number is actually a
235 pair of the file number and the type number within the file.
236 This is a stack of input files. */
238 struct dbx_file
240 struct dbx_file *next;
241 int file_number;
242 int next_type_number;
245 /* This is the top of the stack. */
247 static struct dbx_file *current_file;
249 /* This is the next file number to use. */
251 static int next_file_number;
253 #endif /* DBX_USE_BINCL */
255 /* These variables are for dbxout_symbol to communicate to
256 dbxout_finish_symbol.
257 current_sym_code is the symbol-type-code, a symbol N_... define in stab.h.
258 current_sym_value and current_sym_addr are two ways to address the
259 value to store in the symtab entry.
260 current_sym_addr if nonzero represents the value as an rtx.
261 If that is zero, current_sym_value is used. This is used
262 when the value is an offset (such as for auto variables,
263 register variables and parms). */
265 static STAB_CODE_TYPE current_sym_code;
266 static int current_sym_value;
267 static rtx current_sym_addr;
269 /* Number of chars of symbol-description generated so far for the
270 current symbol. Used by CHARS and CONTIN. */
272 static int current_sym_nchars;
274 /* Report having output N chars of the current symbol-description. */
276 #define CHARS(N) (current_sym_nchars += (N))
278 /* Break the current symbol-description, generating a continuation,
279 if it has become long. */
281 #ifndef DBX_CONTIN_LENGTH
282 #define DBX_CONTIN_LENGTH 80
283 #endif
285 #if DBX_CONTIN_LENGTH > 0
286 #define CONTIN \
287 do {if (current_sym_nchars > DBX_CONTIN_LENGTH) dbxout_continue ();} while (0)
288 #else
289 #define CONTIN do { } while (0)
290 #endif
292 static void dbxout_init PARAMS ((const char *));
293 static void dbxout_finish PARAMS ((const char *));
294 static void dbxout_start_source_file PARAMS ((unsigned, const char *));
295 static void dbxout_end_source_file PARAMS ((unsigned));
296 static void dbxout_typedefs PARAMS ((tree));
297 static void dbxout_type_index PARAMS ((tree));
298 #if DBX_CONTIN_LENGTH > 0
299 static void dbxout_continue PARAMS ((void));
300 #endif
301 static void dbxout_args PARAMS ((tree));
302 static void dbxout_type_fields PARAMS ((tree));
303 static void dbxout_type_method_1 PARAMS ((tree, const char *));
304 static void dbxout_type_methods PARAMS ((tree));
305 static void dbxout_range_type PARAMS ((tree));
306 static void dbxout_type PARAMS ((tree, int));
307 static void print_int_cst_octal PARAMS ((tree));
308 static void print_octal PARAMS ((unsigned HOST_WIDE_INT, int));
309 static void print_wide_int PARAMS ((HOST_WIDE_INT));
310 static void dbxout_type_name PARAMS ((tree));
311 static int dbxout_symbol_location PARAMS ((tree, tree, const char *, rtx));
312 static void dbxout_symbol_name PARAMS ((tree, const char *, int));
313 static void dbxout_prepare_symbol PARAMS ((tree));
314 static void dbxout_finish_symbol PARAMS ((tree));
315 static void dbxout_block PARAMS ((tree, int, tree));
316 static void dbxout_global_decl PARAMS ((tree));
318 /* The debug hooks structure. */
319 #if defined (DBX_DEBUGGING_INFO)
321 static void dbxout_source_line PARAMS ((unsigned int, const char *));
322 static void dbxout_source_file PARAMS ((FILE *, const char *));
323 static void dbxout_function_end PARAMS ((void));
324 static void dbxout_begin_function PARAMS ((tree));
325 static void dbxout_begin_block PARAMS ((unsigned, unsigned));
326 static void dbxout_end_block PARAMS ((unsigned, unsigned));
327 static void dbxout_function_decl PARAMS ((tree));
329 struct gcc_debug_hooks dbx_debug_hooks =
331 dbxout_init,
332 dbxout_finish,
333 debug_nothing_int_charstar,
334 debug_nothing_int_charstar,
335 dbxout_start_source_file,
336 dbxout_end_source_file,
337 dbxout_begin_block,
338 dbxout_end_block,
339 debug_true_tree, /* ignore_block */
340 dbxout_source_line, /* source_line */
341 dbxout_source_line, /* begin_prologue: just output line info */
342 debug_nothing_int, /* end_prologue */
343 debug_nothing_void, /* end_epilogue */
344 #ifdef DBX_FUNCTION_FIRST
345 dbxout_begin_function,
346 #else
347 debug_nothing_tree, /* begin_function */
348 #endif
349 debug_nothing_int, /* end_function */
350 dbxout_function_decl,
351 dbxout_global_decl, /* global_decl */
352 debug_nothing_tree, /* deferred_inline_function */
353 debug_nothing_tree, /* outlining_inline_function */
354 debug_nothing_rtx /* label */
356 #endif /* DBX_DEBUGGING_INFO */
358 #if defined (XCOFF_DEBUGGING_INFO)
359 struct gcc_debug_hooks xcoff_debug_hooks =
361 dbxout_init,
362 dbxout_finish,
363 debug_nothing_int_charstar,
364 debug_nothing_int_charstar,
365 dbxout_start_source_file,
366 dbxout_end_source_file,
367 xcoffout_begin_block,
368 xcoffout_end_block,
369 debug_true_tree, /* ignore_block */
370 xcoffout_source_line,
371 xcoffout_begin_prologue, /* begin_prologue */
372 debug_nothing_int, /* end_prologue */
373 xcoffout_end_epilogue,
374 debug_nothing_tree, /* begin_function */
375 xcoffout_end_function,
376 debug_nothing_tree, /* function_decl */
377 dbxout_global_decl, /* global_decl */
378 debug_nothing_tree, /* deferred_inline_function */
379 debug_nothing_tree, /* outlining_inline_function */
380 debug_nothing_rtx /* label */
382 #endif /* XCOFF_DEBUGGING_INFO */
384 #if defined (DBX_DEBUGGING_INFO)
385 static void
386 dbxout_function_end ()
388 static int scope_labelno = 0;
389 char lscope_label_name[100];
390 /* Convert Ltext into the appropriate format for local labels in case
391 the system doesn't insert underscores in front of user generated
392 labels. */
393 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno);
394 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Lscope", scope_labelno);
395 scope_labelno++;
397 /* By convention, GCC will mark the end of a function with an N_FUN
398 symbol and an empty string. */
399 fprintf (asmfile, "%s\"\",%d,0,0,", ASM_STABS_OP, N_FUN);
400 assemble_name (asmfile, lscope_label_name);
401 putc ('-', asmfile);
402 assemble_name (asmfile, XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0));
403 fprintf (asmfile, "\n");
405 #endif /* DBX_DEBUGGING_INFO */
407 /* At the beginning of compilation, start writing the symbol table.
408 Initialize `typevec' and output the standard data types of C. */
410 static void
411 dbxout_init (input_file_name)
412 const char *input_file_name;
414 char ltext_label_name[100];
415 tree syms = getdecls ();
417 asmfile = asm_out_file;
419 typevec_len = 100;
420 typevec = (struct typeinfo *) xcalloc (typevec_len, sizeof typevec[0]);
422 /* Convert Ltext into the appropriate format for local labels in case
423 the system doesn't insert underscores in front of user generated
424 labels. */
425 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0);
427 /* Put the current working directory in an N_SO symbol. */
428 #ifndef DBX_WORKING_DIRECTORY /* Only some versions of DBX want this,
429 but GDB always does. */
430 if (use_gnu_debug_info_extensions)
431 #endif
433 if (!cwd && (cwd = getpwd ()) && (!*cwd || cwd[strlen (cwd) - 1] != '/'))
434 cwd = concat (cwd, FILE_NAME_JOINER, NULL);
435 if (cwd)
437 #ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY
438 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asmfile, cwd);
439 #else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
440 fprintf (asmfile, "%s", ASM_STABS_OP);
441 output_quoted_string (asmfile, cwd);
442 fprintf (asmfile, ",%d,0,0,", N_SO);
443 assemble_name (asmfile, ltext_label_name);
444 fputc ('\n', asmfile);
445 #endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */
449 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME
450 /* This should NOT be DBX_OUTPUT_SOURCE_FILENAME. That
451 would give us an N_SOL, and we want an N_SO. */
452 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asmfile, input_file_name);
453 #else /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
454 /* We include outputting `Ltext:' here,
455 because that gives you a way to override it. */
456 /* Used to put `Ltext:' before the reference, but that loses on sun 4. */
457 fprintf (asmfile, "%s", ASM_STABS_OP);
458 output_quoted_string (asmfile, input_file_name);
459 fprintf (asmfile, ",%d,0,0,", N_SO);
460 assemble_name (asmfile, ltext_label_name);
461 fputc ('\n', asmfile);
462 text_section ();
463 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "Ltext", 0);
464 #endif /* no DBX_OUTPUT_MAIN_SOURCE_FILENAME */
466 #ifdef DBX_OUTPUT_GCC_MARKER
467 DBX_OUTPUT_GCC_MARKER (asmfile);
468 #else
469 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. */
470 fprintf (asmfile, "%s\"%s\",%d,0,0,0\n",
471 ASM_STABS_OP, STABS_GCC_MARKER, N_OPT);
472 #endif
474 lastfile = input_file_name;
476 next_type_number = 1;
478 #ifdef DBX_USE_BINCL
479 current_file = (struct dbx_file *) xmalloc (sizeof *current_file);
480 current_file->next = NULL;
481 current_file->file_number = 0;
482 current_file->next_type_number = 1;
483 next_file_number = 1;
484 #endif
486 /* Make sure that types `int' and `char' have numbers 1 and 2.
487 Definitions of other integer types will refer to those numbers.
488 (Actually it should no longer matter what their numbers are.
489 Also, if any types with tags have been defined, dbxout_symbol
490 will output them first, so the numbers won't be 1 and 2. That
491 happens in C++. So it's a good thing it should no longer matter). */
493 #ifdef DBX_OUTPUT_STANDARD_TYPES
494 DBX_OUTPUT_STANDARD_TYPES (syms);
495 #else
496 dbxout_symbol (TYPE_NAME (integer_type_node), 0);
497 dbxout_symbol (TYPE_NAME (char_type_node), 0);
498 #endif
500 /* Get all permanent types that have typedef names,
501 and output them all, except for those already output. */
503 dbxout_typedefs (syms);
506 /* Output any typedef names for types described by TYPE_DECLs in SYMS,
507 in the reverse order from that which is found in SYMS. */
509 static void
510 dbxout_typedefs (syms)
511 tree syms;
513 if (syms)
515 dbxout_typedefs (TREE_CHAIN (syms));
516 if (TREE_CODE (syms) == TYPE_DECL)
518 tree type = TREE_TYPE (syms);
519 if (TYPE_NAME (type)
520 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
521 && COMPLETE_TYPE_P (type)
522 && ! TREE_ASM_WRITTEN (TYPE_NAME (type)))
523 dbxout_symbol (TYPE_NAME (type), 0);
528 /* Change to reading from a new source file. Generate a N_BINCL stab. */
530 static void
531 dbxout_start_source_file (line, filename)
532 unsigned int line ATTRIBUTE_UNUSED;
533 const char *filename ATTRIBUTE_UNUSED;
535 #ifdef DBX_USE_BINCL
536 struct dbx_file *n = (struct dbx_file *) xmalloc (sizeof *n);
538 n->next = current_file;
539 n->file_number = next_file_number++;
540 n->next_type_number = 1;
541 current_file = n;
542 fprintf (asmfile, "%s", ASM_STABS_OP);
543 output_quoted_string (asmfile, filename);
544 fprintf (asmfile, ",%d,0,0,0\n", N_BINCL);
545 #endif
548 /* Revert to reading a previous source file. Generate a N_EINCL stab. */
550 static void
551 dbxout_end_source_file (line)
552 unsigned int line ATTRIBUTE_UNUSED;
554 #ifdef DBX_USE_BINCL
555 struct dbx_file *next;
557 fprintf (asmfile, "%s%d,0,0,0\n", ASM_STABN_OP, N_EINCL);
558 next = current_file->next;
559 free (current_file);
560 current_file = next;
561 #endif
564 #if defined (DBX_DEBUGGING_INFO)
565 /* Output debugging info to FILE to switch to sourcefile FILENAME. */
567 static void
568 dbxout_source_file (file, filename)
569 FILE *file;
570 const char *filename;
572 if (filename && (lastfile == 0 || strcmp (filename, lastfile)))
574 #ifdef DBX_OUTPUT_SOURCE_FILENAME
575 DBX_OUTPUT_SOURCE_FILENAME (file, filename);
576 #else
577 char ltext_label_name[100];
579 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext",
580 source_label_number);
581 fprintf (file, "%s", ASM_STABS_OP);
582 output_quoted_string (file, filename);
583 fprintf (asmfile, ",%d,0,0,", N_SOL);
584 assemble_name (asmfile, ltext_label_name);
585 fputc ('\n', asmfile);
586 if (current_function_decl != NULL_TREE
587 && DECL_SECTION_NAME (current_function_decl) != NULL_TREE)
588 ; /* Don't change section amid function. */
589 else
590 text_section ();
591 ASM_OUTPUT_INTERNAL_LABEL (file, "Ltext", source_label_number);
592 source_label_number++;
593 #endif
594 lastfile = filename;
598 /* Output a line number symbol entry for source file FILENAME and line
599 number LINENO. */
601 static void
602 dbxout_source_line (lineno, filename)
603 unsigned int lineno;
604 const char *filename;
606 dbxout_source_file (asmfile, filename);
608 #ifdef ASM_OUTPUT_SOURCE_LINE
609 ASM_OUTPUT_SOURCE_LINE (asmfile, lineno);
610 #else
611 fprintf (asmfile, "%s%d,0,%d\n", ASM_STABD_OP, N_SLINE, lineno);
612 #endif
615 /* Describe the beginning of an internal block within a function. */
617 static void
618 dbxout_begin_block (line, n)
619 unsigned int line ATTRIBUTE_UNUSED;
620 unsigned int n;
622 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "LBB", n);
625 /* Describe the end line-number of an internal block within a function. */
627 static void
628 dbxout_end_block (line, n)
629 unsigned int line ATTRIBUTE_UNUSED;
630 unsigned int n;
632 ASM_OUTPUT_INTERNAL_LABEL (asmfile, "LBE", n);
635 /* Output dbx data for a function definition.
636 This includes a definition of the function name itself (a symbol),
637 definitions of the parameters (locating them in the parameter list)
638 and then output the block that makes up the function's body
639 (including all the auto variables of the function). */
641 static void
642 dbxout_function_decl (decl)
643 tree decl;
645 #ifndef DBX_FUNCTION_FIRST
646 dbxout_begin_function (decl);
647 #endif
648 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl));
649 #ifdef DBX_OUTPUT_FUNCTION_END
650 DBX_OUTPUT_FUNCTION_END (asmfile, decl);
651 #endif
652 if (use_gnu_debug_info_extensions
653 #if defined(NO_DBX_FUNCTION_END)
654 && ! NO_DBX_FUNCTION_END
655 #endif
656 && targetm.have_named_sections)
657 dbxout_function_end ();
660 #endif /* DBX_DEBUGGING_INFO */
662 /* Debug information for a global DECL. Called from toplev.c after
663 compilation proper has finished. */
664 static void
665 dbxout_global_decl (decl)
666 tree decl;
668 if (TREE_CODE (decl) == VAR_DECL
669 && ! DECL_EXTERNAL (decl)
670 && DECL_RTL_SET_P (decl)) /* Not necessary? */
671 dbxout_symbol (decl, 0);
674 /* At the end of compilation, finish writing the symbol table.
675 Unless you define DBX_OUTPUT_MAIN_SOURCE_FILE_END, the default is
676 to do nothing. */
678 static void
679 dbxout_finish (filename)
680 const char *filename ATTRIBUTE_UNUSED;
682 #ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END
683 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asmfile, filename);
684 #endif /* DBX_OUTPUT_MAIN_SOURCE_FILE_END */
687 /* Output the index of a type. */
689 static void
690 dbxout_type_index (type)
691 tree type;
693 #ifndef DBX_USE_BINCL
694 fprintf (asmfile, "%d", TYPE_SYMTAB_ADDRESS (type));
695 CHARS (3);
696 #else
697 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)];
698 fprintf (asmfile, "(%d,%d)", t->file_number, t->type_number);
699 CHARS (9);
700 #endif
703 #if DBX_CONTIN_LENGTH > 0
704 /* Continue a symbol-description that gets too big.
705 End one symbol table entry with a double-backslash
706 and start a new one, eventually producing something like
707 .stabs "start......\\",code,0,value
708 .stabs "...rest",code,0,value */
710 static void
711 dbxout_continue ()
713 #ifdef DBX_CONTIN_CHAR
714 fprintf (asmfile, "%c", DBX_CONTIN_CHAR);
715 #else
716 fprintf (asmfile, "\\\\");
717 #endif
718 dbxout_finish_symbol (NULL_TREE);
719 fprintf (asmfile, "%s\"", ASM_STABS_OP);
720 current_sym_nchars = 0;
722 #endif /* DBX_CONTIN_LENGTH > 0 */
724 /* Subroutine of `dbxout_type'. Output the type fields of TYPE.
725 This must be a separate function because anonymous unions require
726 recursive calls. */
728 static void
729 dbxout_type_fields (type)
730 tree type;
732 tree tem;
734 /* Output the name, type, position (in bits), size (in bits) of each
735 field that we can support. */
736 for (tem = TYPE_FIELDS (type); tem; tem = TREE_CHAIN (tem))
738 /* Omit here local type decls until we know how to support them. */
739 if (TREE_CODE (tem) == TYPE_DECL
740 /* Omit fields whose position or size are variable or too large to
741 represent. */
742 || (TREE_CODE (tem) == FIELD_DECL
743 && (! host_integerp (bit_position (tem), 0)
744 || ! DECL_SIZE (tem)
745 || ! host_integerp (DECL_SIZE (tem), 1)))
746 /* Omit here the nameless fields that are used to skip bits. */
747 || DECL_IGNORED_P (tem))
748 continue;
750 else if (TREE_CODE (tem) != CONST_DECL)
752 /* Continue the line if necessary,
753 but not before the first field. */
754 if (tem != TYPE_FIELDS (type))
755 CONTIN;
757 if (DECL_NAME (tem))
759 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (DECL_NAME (tem)));
760 CHARS (2 + IDENTIFIER_LENGTH (DECL_NAME (tem)));
762 else
764 fprintf (asmfile, ":");
765 CHARS (1);
768 if (use_gnu_debug_info_extensions
769 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem)
770 || TREE_CODE (tem) != FIELD_DECL))
772 have_used_extensions = 1;
773 putc ('/', asmfile);
774 putc ((TREE_PRIVATE (tem) ? '0'
775 : TREE_PROTECTED (tem) ? '1' : '2'),
776 asmfile);
777 CHARS (2);
780 dbxout_type ((TREE_CODE (tem) == FIELD_DECL
781 && DECL_BIT_FIELD_TYPE (tem))
782 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0);
784 if (TREE_CODE (tem) == VAR_DECL)
786 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions)
788 tree name = DECL_ASSEMBLER_NAME (tem);
790 have_used_extensions = 1;
791 fprintf (asmfile, ":%s;", IDENTIFIER_POINTER (name));
792 CHARS (IDENTIFIER_LENGTH (name) + 2);
794 else
796 /* If TEM is non-static, GDB won't understand it. */
797 fprintf (asmfile, ",0,0;");
798 CHARS (5);
801 else
803 putc (',', asmfile);
804 print_wide_int (int_bit_position (tem));
805 putc (',', asmfile);
806 print_wide_int (tree_low_cst (DECL_SIZE (tem), 1));
807 putc (';', asmfile);
808 CHARS (3);
814 /* Subroutine of `dbxout_type_methods'. Output debug info about the
815 method described DECL. DEBUG_NAME is an encoding of the method's
816 type signature. ??? We may be able to do without DEBUG_NAME altogether
817 now. */
819 static void
820 dbxout_type_method_1 (decl, debug_name)
821 tree decl;
822 const char *debug_name;
824 char c1 = 'A', c2;
826 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE)
827 c2 = '?';
828 else /* it's a METHOD_TYPE. */
830 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl)));
831 /* A for normal functions.
832 B for `const' member functions.
833 C for `volatile' member functions.
834 D for `const volatile' member functions. */
835 if (TYPE_READONLY (TREE_TYPE (firstarg)))
836 c1 += 1;
837 if (TYPE_VOLATILE (TREE_TYPE (firstarg)))
838 c1 += 2;
840 if (DECL_VINDEX (decl))
841 c2 = '*';
842 else
843 c2 = '.';
846 fprintf (asmfile, ":%s;%c%c%c", debug_name,
847 TREE_PRIVATE (decl) ? '0'
848 : TREE_PROTECTED (decl) ? '1' : '2', c1, c2);
849 CHARS (IDENTIFIER_LENGTH (DECL_ASSEMBLER_NAME (decl)) + 6
850 - (debug_name - IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))));
852 if (DECL_VINDEX (decl) && host_integerp (DECL_VINDEX (decl), 0))
854 print_wide_int (tree_low_cst (DECL_VINDEX (decl), 0));
855 putc (';', asmfile);
856 CHARS (1);
857 dbxout_type (DECL_CONTEXT (decl), 0);
858 fprintf (asmfile, ";");
859 CHARS (1);
863 /* Subroutine of `dbxout_type'. Output debug info about the methods defined
864 in TYPE. */
866 static void
867 dbxout_type_methods (type)
868 tree type;
870 /* C++: put out the method names and their parameter lists */
871 tree methods = TYPE_METHODS (type);
872 tree type_encoding;
873 tree fndecl;
874 tree last;
875 char formatted_type_identifier_length[16];
876 int type_identifier_length;
878 if (methods == NULL_TREE)
879 return;
881 type_encoding = DECL_NAME (TYPE_NAME (type));
883 #if 0
884 /* C++: Template classes break some assumptions made by this code about
885 the class names, constructor names, and encodings for assembler
886 label names. For now, disable output of dbx info for them. */
888 const char *ptr = IDENTIFIER_POINTER (type_encoding);
889 /* This should use index. (mrs) */
890 while (*ptr && *ptr != '<') ptr++;
891 if (*ptr != 0)
893 static int warned;
894 if (!warned)
895 warned = 1;
896 return;
899 #endif
901 type_identifier_length = IDENTIFIER_LENGTH (type_encoding);
903 sprintf (formatted_type_identifier_length, "%d", type_identifier_length);
905 if (TREE_CODE (methods) != TREE_VEC)
906 fndecl = methods;
907 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE)
908 fndecl = TREE_VEC_ELT (methods, 0);
909 else
910 fndecl = TREE_VEC_ELT (methods, 1);
912 while (fndecl)
914 int need_prefix = 1;
916 /* Group together all the methods for the same operation.
917 These differ in the types of the arguments. */
918 for (last = NULL_TREE;
919 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last));
920 fndecl = TREE_CHAIN (fndecl))
921 /* Output the name of the field (after overloading), as
922 well as the name of the field before overloading, along
923 with its parameter list */
925 /* This is the "mangled" name of the method.
926 It encodes the argument types. */
927 const char *debug_name;
929 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these
930 include TEMPLATE_DECLs.) The debugger doesn't know what
931 to do with such entities anyhow. */
932 if (TREE_CODE (fndecl) != FUNCTION_DECL)
933 continue;
935 debug_name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (fndecl));
937 CONTIN;
939 last = fndecl;
941 /* Also ignore abstract methods; those are only interesting to
942 the DWARF backends. */
943 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT (fndecl))
944 continue;
946 /* Redundantly output the plain name, since that's what gdb
947 expects. */
948 if (need_prefix)
950 tree name = DECL_NAME (fndecl);
951 fprintf (asmfile, "%s::", IDENTIFIER_POINTER (name));
952 CHARS (IDENTIFIER_LENGTH (name) + 2);
953 need_prefix = 0;
956 dbxout_type (TREE_TYPE (fndecl), 0);
958 dbxout_type_method_1 (fndecl, debug_name);
960 if (!need_prefix)
962 putc (';', asmfile);
963 CHARS (1);
968 /* Emit a "range" type specification, which has the form:
969 "r<index type>;<lower bound>;<upper bound>;".
970 TYPE is an INTEGER_TYPE. */
972 static void
973 dbxout_range_type (type)
974 tree type;
976 fprintf (asmfile, "r");
977 if (TREE_TYPE (type))
978 dbxout_type (TREE_TYPE (type), 0);
979 else if (TREE_CODE (type) != INTEGER_TYPE)
980 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */
981 else
983 /* Traditionally, we made sure 'int' was type 1, and builtin types
984 were defined to be sub-ranges of int. Unfortunately, this
985 does not allow us to distinguish true sub-ranges from integer
986 types. So, instead we define integer (non-sub-range) types as
987 sub-ranges of themselves. This matters for Chill. If this isn't
988 a subrange type, then we want to define it in terms of itself.
989 However, in C, this may be an anonymous integer type, and we don't
990 want to emit debug info referring to it. Just calling
991 dbxout_type_index won't work anyways, because the type hasn't been
992 defined yet. We make this work for both cases by checked to see
993 whether this is a defined type, referring to it if it is, and using
994 'int' otherwise. */
995 if (TYPE_SYMTAB_ADDRESS (type) != 0)
996 dbxout_type_index (type);
997 else
998 dbxout_type_index (integer_type_node);
1001 if (TYPE_MIN_VALUE (type) != 0
1002 && host_integerp (TYPE_MIN_VALUE (type), 0))
1004 putc (';', asmfile);
1005 CHARS (1);
1006 print_wide_int (tree_low_cst (TYPE_MIN_VALUE (type), 0));
1008 else
1010 fprintf (asmfile, ";0");
1011 CHARS (2);
1014 if (TYPE_MAX_VALUE (type) != 0
1015 && host_integerp (TYPE_MAX_VALUE (type), 0))
1017 putc (';', asmfile);
1018 CHARS (1);
1019 print_wide_int (tree_low_cst (TYPE_MAX_VALUE (type), 0));
1020 putc (';', asmfile);
1021 CHARS (1);
1023 else
1025 fprintf (asmfile, ";-1;");
1026 CHARS (4);
1030 /* Output a reference to a type. If the type has not yet been
1031 described in the dbx output, output its definition now.
1032 For a type already defined, just refer to its definition
1033 using the type number.
1035 If FULL is nonzero, and the type has been described only with
1036 a forward-reference, output the definition now.
1037 If FULL is zero in this case, just refer to the forward-reference
1038 using the number previously allocated. */
1040 static void
1041 dbxout_type (type, full)
1042 tree type;
1043 int full;
1045 tree tem;
1046 tree main_variant;
1047 static int anonymous_type_number = 0;
1049 if (TREE_CODE (type) == VECTOR_TYPE)
1050 type = TYPE_DEBUG_REPRESENTATION_TYPE (type);
1052 /* If there was an input error and we don't really have a type,
1053 avoid crashing and write something that is at least valid
1054 by assuming `int'. */
1055 if (type == error_mark_node)
1056 type = integer_type_node;
1057 else
1059 if (TYPE_NAME (type)
1060 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1061 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type)))
1062 full = 0;
1065 /* Try to find the "main variant" with the same name. */
1066 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1067 && DECL_ORIGINAL_TYPE (TYPE_NAME (type)))
1068 main_variant = TREE_TYPE (TYPE_NAME (type));
1069 else
1070 main_variant = TYPE_MAIN_VARIANT (type);
1072 /* If we are not using extensions, stabs does not distinguish const and
1073 volatile, so there is no need to make them separate types. */
1074 if (!use_gnu_debug_info_extensions)
1075 type = main_variant;
1077 if (TYPE_SYMTAB_ADDRESS (type) == 0)
1079 /* Type has no dbx number assigned. Assign next available number. */
1080 TYPE_SYMTAB_ADDRESS (type) = next_type_number++;
1082 /* Make sure type vector is long enough to record about this type. */
1084 if (next_type_number == typevec_len)
1086 typevec
1087 = (struct typeinfo *) xrealloc (typevec,
1088 typevec_len * 2 * sizeof typevec[0]);
1089 memset ((char *) (typevec + typevec_len), 0,
1090 typevec_len * sizeof typevec[0]);
1091 typevec_len *= 2;
1094 #ifdef DBX_USE_BINCL
1095 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number
1096 = current_file->file_number;
1097 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number
1098 = current_file->next_type_number++;
1099 #endif
1102 /* Output the number of this type, to refer to it. */
1103 dbxout_type_index (type);
1105 #ifdef DBX_TYPE_DEFINED
1106 if (DBX_TYPE_DEFINED (type))
1107 return;
1108 #endif
1110 /* If this type's definition has been output or is now being output,
1111 that is all. */
1113 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status)
1115 case TYPE_UNSEEN:
1116 break;
1117 case TYPE_XREF:
1118 /* If we have already had a cross reference,
1119 and either that's all we want or that's the best we could do,
1120 don't repeat the cross reference.
1121 Sun dbx crashes if we do. */
1122 if (! full || !COMPLETE_TYPE_P (type)
1123 /* No way in DBX fmt to describe a variable size. */
1124 || ! host_integerp (TYPE_SIZE (type), 1))
1125 return;
1126 break;
1127 case TYPE_DEFINED:
1128 return;
1131 #ifdef DBX_NO_XREFS
1132 /* For systems where dbx output does not allow the `=xsNAME:' syntax,
1133 leave the type-number completely undefined rather than output
1134 a cross-reference. If we have already used GNU debug info extensions,
1135 then it is OK to output a cross reference. This is necessary to get
1136 proper C++ debug output. */
1137 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE
1138 || TREE_CODE (type) == QUAL_UNION_TYPE
1139 || TREE_CODE (type) == ENUMERAL_TYPE)
1140 && ! use_gnu_debug_info_extensions)
1141 /* We must use the same test here as we use twice below when deciding
1142 whether to emit a cross-reference. */
1143 if ((TYPE_NAME (type) != 0
1144 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1145 && DECL_IGNORED_P (TYPE_NAME (type)))
1146 && !full)
1147 || !COMPLETE_TYPE_P (type)
1148 /* No way in DBX fmt to describe a variable size. */
1149 || ! host_integerp (TYPE_SIZE (type), 1))
1151 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1152 return;
1154 #endif
1156 /* Output a definition now. */
1158 fprintf (asmfile, "=");
1159 CHARS (1);
1161 /* Mark it as defined, so that if it is self-referent
1162 we will not get into an infinite recursion of definitions. */
1164 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED;
1166 /* If this type is a variant of some other, hand off. Types with
1167 different names are usefully distinguished. We only distinguish
1168 cv-qualified types if we're using extensions. */
1169 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant))
1171 putc ('k', asmfile);
1172 CHARS (1);
1173 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0);
1174 return;
1176 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant))
1178 putc ('B', asmfile);
1179 CHARS (1);
1180 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0);
1181 return;
1183 else if (main_variant != TYPE_MAIN_VARIANT (type))
1185 /* 'type' is a typedef; output the type it refers to. */
1186 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0);
1187 return;
1189 /* else continue. */
1191 switch (TREE_CODE (type))
1193 case VOID_TYPE:
1194 case LANG_TYPE:
1195 /* For a void type, just define it as itself; ie, "5=5".
1196 This makes us consider it defined
1197 without saying what it is. The debugger will make it
1198 a void type when the reference is seen, and nothing will
1199 ever override that default. */
1200 dbxout_type_index (type);
1201 break;
1203 case INTEGER_TYPE:
1204 if (type == char_type_node && ! TREE_UNSIGNED (type))
1206 /* Output the type `char' as a subrange of itself!
1207 I don't understand this definition, just copied it
1208 from the output of pcc.
1209 This used to use `r2' explicitly and we used to
1210 take care to make sure that `char' was type number 2. */
1211 fprintf (asmfile, "r");
1212 CHARS (1);
1213 dbxout_type_index (type);
1214 fprintf (asmfile, ";0;127;");
1215 CHARS (7);
1218 /* If this is a subtype of another integer type, always prefer to
1219 write it as a subtype. */
1220 else if (TREE_TYPE (type) != 0
1221 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE)
1222 dbxout_range_type (type);
1224 else
1226 /* If the size is non-standard, say what it is if we can use
1227 GDB extensions. */
1229 if (use_gnu_debug_info_extensions
1230 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1232 have_used_extensions = 1;
1233 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1234 CHARS (5);
1237 /* If we can use GDB extensions and the size is wider than a
1238 long (the size used by GDB to read them) or we may have
1239 trouble writing the bounds the usual way, write them in
1240 octal. Note the test is for the *target's* size of "long",
1241 not that of the host. The host test is just to make sure we
1242 can write it out in case the host wide int is narrower than the
1243 target "long". */
1245 /* For unsigned types, we use octal if they are the same size or
1246 larger. This is because we print the bounds as signed decimal,
1247 and hence they can't span same size unsigned types. */
1249 if (use_gnu_debug_info_extensions
1250 && TYPE_MIN_VALUE (type) != 0
1251 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1252 && TYPE_MAX_VALUE (type) != 0
1253 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1254 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1255 || ((TYPE_PRECISION (type)
1256 == TYPE_PRECISION (integer_type_node))
1257 && TREE_UNSIGNED (type))
1258 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1259 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1260 && TREE_UNSIGNED (type))))
1262 fprintf (asmfile, "r");
1263 CHARS (1);
1264 dbxout_type_index (type);
1265 fprintf (asmfile, ";");
1266 CHARS (1);
1267 print_int_cst_octal (TYPE_MIN_VALUE (type));
1268 fprintf (asmfile, ";");
1269 CHARS (1);
1270 print_int_cst_octal (TYPE_MAX_VALUE (type));
1271 fprintf (asmfile, ";");
1272 CHARS (1);
1275 else
1276 /* Output other integer types as subranges of `int'. */
1277 dbxout_range_type (type);
1280 break;
1282 case REAL_TYPE:
1283 /* This used to say `r1' and we used to take care
1284 to make sure that `int' was type number 1. */
1285 fprintf (asmfile, "r");
1286 CHARS (1);
1287 dbxout_type_index (integer_type_node);
1288 putc (';', asmfile);
1289 CHARS (1);
1290 print_wide_int (int_size_in_bytes (type));
1291 fputs (";0;", asmfile);
1292 CHARS (3);
1293 break;
1295 case CHAR_TYPE:
1296 if (use_gnu_debug_info_extensions)
1298 have_used_extensions = 1;
1299 fputs ("@s", asmfile);
1300 CHARS (2);
1301 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1302 fputs (";-20;", asmfile);
1303 CHARS (4);
1305 else
1307 /* Output the type `char' as a subrange of itself.
1308 That is what pcc seems to do. */
1309 fprintf (asmfile, "r");
1310 CHARS (1);
1311 dbxout_type_index (char_type_node);
1312 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1313 CHARS (7);
1315 break;
1317 case BOOLEAN_TYPE:
1318 if (use_gnu_debug_info_extensions)
1320 have_used_extensions = 1;
1321 fputs ("@s", asmfile);
1322 CHARS (2);
1323 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1324 fputs (";-16;", asmfile);
1325 CHARS (4);
1327 else /* Define as enumeral type (False, True) */
1329 fprintf (asmfile, "eFalse:0,True:1,;");
1330 CHARS (17);
1332 break;
1334 case FILE_TYPE:
1335 putc ('d', asmfile);
1336 CHARS (1);
1337 dbxout_type (TREE_TYPE (type), 0);
1338 break;
1340 case COMPLEX_TYPE:
1341 /* Differs from the REAL_TYPE by its new data type number */
1343 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1345 fprintf (asmfile, "r");
1346 CHARS (1);
1347 dbxout_type_index (type);
1348 putc (';', asmfile);
1349 CHARS (1);
1350 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1351 fputs (";0;", asmfile);
1352 CHARS (3);
1354 else
1356 /* Output a complex integer type as a structure,
1357 pending some other way to do it. */
1358 putc ('s', asmfile);
1359 CHARS (1);
1360 print_wide_int (int_size_in_bytes (type));
1361 fprintf (asmfile, "real:");
1362 CHARS (5);
1364 dbxout_type (TREE_TYPE (type), 0);
1365 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1366 CHARS (7);
1367 fprintf (asmfile, "imag:");
1368 CHARS (5);
1369 dbxout_type (TREE_TYPE (type), 0);
1370 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1371 TYPE_PRECISION (TREE_TYPE (type)));
1372 CHARS (10);
1374 break;
1376 case SET_TYPE:
1377 if (use_gnu_debug_info_extensions)
1379 have_used_extensions = 1;
1380 fputs ("@s", asmfile);
1381 CHARS (2);
1382 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1383 putc (';', asmfile);
1384 CHARS (1);
1386 /* Check if a bitstring type, which in Chill is
1387 different from a [power]set. */
1388 if (TYPE_STRING_FLAG (type))
1390 fprintf (asmfile, "@S;");
1391 CHARS (3);
1394 putc ('S', asmfile);
1395 CHARS (1);
1396 dbxout_type (TYPE_DOMAIN (type), 0);
1397 break;
1399 case ARRAY_TYPE:
1400 /* Make arrays of packed bits look like bitstrings for chill. */
1401 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1403 have_used_extensions = 1;
1404 fputs ("@s", asmfile);
1405 CHARS (2);
1406 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1407 fprintf (asmfile, ";@S;S");
1408 CHARS (5);
1409 dbxout_type (TYPE_DOMAIN (type), 0);
1410 break;
1413 /* Output "a" followed by a range type definition
1414 for the index type of the array
1415 followed by a reference to the target-type.
1416 ar1;0;N;M for a C array of type M and size N+1. */
1417 /* Check if a character string type, which in Chill is
1418 different from an array of characters. */
1419 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1421 have_used_extensions = 1;
1422 fprintf (asmfile, "@S;");
1423 CHARS (3);
1425 tem = TYPE_DOMAIN (type);
1426 if (tem == NULL)
1428 fprintf (asmfile, "ar");
1429 CHARS (2);
1430 dbxout_type_index (integer_type_node);
1431 fprintf (asmfile, ";0;-1;");
1432 CHARS (6);
1434 else
1436 fprintf (asmfile, "a");
1437 CHARS (1);
1438 dbxout_range_type (tem);
1441 dbxout_type (TREE_TYPE (type), 0);
1442 break;
1444 case RECORD_TYPE:
1445 case UNION_TYPE:
1446 case QUAL_UNION_TYPE:
1448 int i, n_baseclasses = 0;
1450 if (TYPE_BINFO (type) != 0
1451 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1452 && TYPE_BINFO_BASETYPES (type) != 0)
1453 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1455 /* Output a structure type. We must use the same test here as we
1456 use in the DBX_NO_XREFS case above. */
1457 if ((TYPE_NAME (type) != 0
1458 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1459 && DECL_IGNORED_P (TYPE_NAME (type)))
1460 && !full)
1461 || !COMPLETE_TYPE_P (type)
1462 /* No way in DBX fmt to describe a variable size. */
1463 || ! host_integerp (TYPE_SIZE (type), 1))
1465 /* If the type is just a cross reference, output one
1466 and mark the type as partially described.
1467 If it later becomes defined, we will output
1468 its real definition.
1469 If the type has a name, don't nest its definition within
1470 another type's definition; instead, output an xref
1471 and let the definition come when the name is defined. */
1472 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1473 CHARS (2);
1474 #if 0 /* This assertion is legitimately false in C++. */
1475 /* We shouldn't be outputting a reference to a type before its
1476 definition unless the type has a tag name.
1477 A typedef name without a tag name should be impossible. */
1478 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1479 abort ();
1480 #endif
1481 if (TYPE_NAME (type) != 0)
1482 dbxout_type_name (type);
1483 else
1485 fprintf (asmfile, "$$%d", anonymous_type_number++);
1486 CHARS (5);
1489 fprintf (asmfile, ":");
1490 CHARS (1);
1491 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1492 break;
1495 /* Identify record or union, and print its size. */
1496 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1497 CHARS (1);
1498 print_wide_int (int_size_in_bytes (type));
1500 if (use_gnu_debug_info_extensions)
1502 if (n_baseclasses)
1504 have_used_extensions = 1;
1505 fprintf (asmfile, "!%d,", n_baseclasses);
1506 CHARS (8);
1509 for (i = 0; i < n_baseclasses; i++)
1511 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1513 if (use_gnu_debug_info_extensions)
1515 have_used_extensions = 1;
1516 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1517 putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1518 CHARS (2);
1519 if (TREE_VIA_VIRTUAL (child) && strcmp (lang_hooks.name, "GNU C++") == 0)
1520 /* For a virtual base, print the (negative) offset within
1521 the vtable where we must look to find the necessary
1522 adjustment. */
1523 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1524 * BITS_PER_UNIT);
1525 else
1526 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1527 * BITS_PER_UNIT);
1528 putc (',', asmfile);
1529 CHARS (1);
1530 dbxout_type (BINFO_TYPE (child), 0);
1531 putc (';', asmfile);
1532 CHARS (1);
1534 else
1536 /* Print out the base class information with fields
1537 which have the same names at the types they hold. */
1538 dbxout_type_name (BINFO_TYPE (child));
1539 putc (':', asmfile);
1540 CHARS (1);
1541 dbxout_type (BINFO_TYPE (child), full);
1542 putc (',', asmfile);
1543 CHARS (1);
1544 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1545 * BITS_PER_UNIT);
1546 putc (',', asmfile);
1547 CHARS (1);
1548 print_wide_int (tree_low_cst (DECL_SIZE
1549 (TYPE_NAME
1550 (BINFO_TYPE (child))),
1552 * BITS_PER_UNIT);
1553 putc (';', asmfile);
1554 CHARS (1);
1559 /* Write out the field declarations. */
1560 dbxout_type_fields (type);
1561 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1563 have_used_extensions = 1;
1564 dbxout_type_methods (type);
1567 putc (';', asmfile);
1568 CHARS (1);
1570 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1571 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1572 && TYPE_VFIELD (type))
1574 have_used_extensions = 1;
1576 /* Tell GDB+ that it may keep reading. */
1577 putc ('~', asmfile);
1578 CHARS (1);
1580 /* We need to write out info about what field this class
1581 uses as its "main" vtable pointer field, because if this
1582 field is inherited from a base class, GDB cannot necessarily
1583 figure out which field it's using in time. */
1584 if (TYPE_VFIELD (type))
1586 putc ('%', asmfile);
1587 CHARS (1);
1588 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1591 putc (';', asmfile);
1592 CHARS (1);
1594 break;
1596 case ENUMERAL_TYPE:
1597 /* We must use the same test here as we use in the DBX_NO_XREFS case
1598 above. We simplify it a bit since an enum will never have a variable
1599 size. */
1600 if ((TYPE_NAME (type) != 0
1601 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1602 && DECL_IGNORED_P (TYPE_NAME (type)))
1603 && !full)
1604 || !COMPLETE_TYPE_P (type))
1606 fprintf (asmfile, "xe");
1607 CHARS (2);
1608 dbxout_type_name (type);
1609 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1610 putc (':', asmfile);
1611 CHARS (1);
1612 return;
1614 #ifdef DBX_OUTPUT_ENUM
1615 DBX_OUTPUT_ENUM (asmfile, type);
1616 #else
1617 if (use_gnu_debug_info_extensions
1618 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1620 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1621 CHARS (5);
1624 putc ('e', asmfile);
1625 CHARS (1);
1626 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1628 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1629 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1630 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1631 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1632 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1633 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1634 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1635 else
1636 print_int_cst_octal (TREE_VALUE (tem));
1638 putc (',', asmfile);
1639 CHARS (1);
1640 if (TREE_CHAIN (tem) != 0)
1641 CONTIN;
1644 putc (';', asmfile);
1645 CHARS (1);
1646 #endif
1647 break;
1649 case POINTER_TYPE:
1650 putc ('*', asmfile);
1651 CHARS (1);
1652 dbxout_type (TREE_TYPE (type), 0);
1653 break;
1655 case METHOD_TYPE:
1656 if (use_gnu_debug_info_extensions)
1658 have_used_extensions = 1;
1659 putc ('#', asmfile);
1660 CHARS (1);
1662 /* Write the argument types out longhand. */
1663 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1664 putc (',', asmfile);
1665 CHARS (1);
1666 dbxout_type (TREE_TYPE (type), 0);
1667 dbxout_args (TYPE_ARG_TYPES (type));
1668 putc (';', asmfile);
1669 CHARS (1);
1671 else
1672 /* Treat it as a function type. */
1673 dbxout_type (TREE_TYPE (type), 0);
1674 break;
1676 case OFFSET_TYPE:
1677 if (use_gnu_debug_info_extensions)
1679 have_used_extensions = 1;
1680 putc ('@', asmfile);
1681 CHARS (1);
1682 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1683 putc (',', asmfile);
1684 CHARS (1);
1685 dbxout_type (TREE_TYPE (type), 0);
1687 else
1688 /* Should print as an int, because it is really just an offset. */
1689 dbxout_type (integer_type_node, 0);
1690 break;
1692 case REFERENCE_TYPE:
1693 if (use_gnu_debug_info_extensions)
1694 have_used_extensions = 1;
1695 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1696 CHARS (1);
1697 dbxout_type (TREE_TYPE (type), 0);
1698 break;
1700 case FUNCTION_TYPE:
1701 putc ('f', asmfile);
1702 CHARS (1);
1703 dbxout_type (TREE_TYPE (type), 0);
1704 break;
1706 default:
1707 abort ();
1711 /* Print the value of integer constant C, in octal,
1712 handling double precision. */
1714 static void
1715 print_int_cst_octal (c)
1716 tree c;
1718 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1719 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1720 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1721 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1723 /* GDB wants constants with no extra leading "1" bits, so
1724 we need to remove any sign-extension that might be
1725 present. */
1726 if (width == HOST_BITS_PER_WIDE_INT * 2)
1728 else if (width > HOST_BITS_PER_WIDE_INT)
1729 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1730 else if (width == HOST_BITS_PER_WIDE_INT)
1731 high = 0;
1732 else
1733 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1735 fprintf (asmfile, "0");
1736 CHARS (1);
1738 if (excess == 3)
1740 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1741 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1743 else
1745 unsigned HOST_WIDE_INT beg = high >> excess;
1746 unsigned HOST_WIDE_INT middle
1747 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1748 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1749 unsigned HOST_WIDE_INT end
1750 = low & (((unsigned HOST_WIDE_INT) 1
1751 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1752 - 1);
1754 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1755 CHARS (2);
1756 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1760 static void
1761 print_octal (value, digits)
1762 unsigned HOST_WIDE_INT value;
1763 int digits;
1765 int i;
1767 for (i = digits - 1; i >= 0; i--)
1768 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1770 CHARS (digits);
1773 /* Output C in decimal while adjusting the number of digits written. */
1775 static void
1776 print_wide_int (c)
1777 HOST_WIDE_INT c;
1779 int digs = 0;
1781 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1783 if (c < 0)
1784 digs++, c = -c;
1786 while (c > 0)
1787 c /= 10; digs++;
1789 CHARS (digs);
1792 /* Output the name of type TYPE, with no punctuation.
1793 Such names can be set up either by typedef declarations
1794 or by struct, enum and union tags. */
1796 static void
1797 dbxout_type_name (type)
1798 tree type;
1800 tree t;
1801 if (TYPE_NAME (type) == 0)
1802 abort ();
1803 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1805 t = TYPE_NAME (type);
1807 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1809 t = DECL_NAME (TYPE_NAME (type));
1811 else
1812 abort ();
1814 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1815 CHARS (IDENTIFIER_LENGTH (t));
1818 /* Output a .stabs for the symbol defined by DECL,
1819 which must be a ..._DECL node in the normal namespace.
1820 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1821 LOCAL is nonzero if the scope is less than the entire file.
1822 Return 1 if a stabs might have been emitted. */
1825 dbxout_symbol (decl, local)
1826 tree decl;
1827 int local ATTRIBUTE_UNUSED;
1829 tree type = TREE_TYPE (decl);
1830 tree context = NULL_TREE;
1831 int result = 0;
1833 /* Cast avoids warning in old compilers. */
1834 current_sym_code = (STAB_CODE_TYPE) 0;
1835 current_sym_value = 0;
1836 current_sym_addr = 0;
1838 /* Ignore nameless syms, but don't ignore type tags. */
1840 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1841 || DECL_IGNORED_P (decl))
1842 return 0;
1844 dbxout_prepare_symbol (decl);
1846 /* The output will always start with the symbol name,
1847 so always count that in the length-output-so-far. */
1849 if (DECL_NAME (decl) != 0)
1850 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1852 switch (TREE_CODE (decl))
1854 case CONST_DECL:
1855 /* Enum values are defined by defining the enum type. */
1856 break;
1858 case FUNCTION_DECL:
1859 if (DECL_RTL (decl) == 0)
1860 return 0;
1861 if (DECL_EXTERNAL (decl))
1862 break;
1863 /* Don't mention a nested function under its parent. */
1864 context = decl_function_context (decl);
1865 if (context == current_function_decl)
1866 break;
1867 if (GET_CODE (DECL_RTL (decl)) != MEM
1868 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1869 break;
1870 FORCE_TEXT;
1872 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1873 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1874 TREE_PUBLIC (decl) ? 'F' : 'f');
1875 result = 1;
1877 current_sym_code = N_FUN;
1878 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1880 if (TREE_TYPE (type))
1881 dbxout_type (TREE_TYPE (type), 0);
1882 else
1883 dbxout_type (void_type_node, 0);
1885 /* For a nested function, when that function is compiled,
1886 mention the containing function name
1887 as well as (since dbx wants it) our own assembler-name. */
1888 if (context != 0)
1889 fprintf (asmfile, ",%s,%s",
1890 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1891 IDENTIFIER_POINTER (DECL_NAME (context)));
1893 dbxout_finish_symbol (decl);
1894 break;
1896 case TYPE_DECL:
1897 #if 0
1898 /* This seems all wrong. Outputting most kinds of types gives no name
1899 at all. A true definition gives no name; a cross-ref for a
1900 structure can give the tag name, but not a type name.
1901 It seems that no typedef name is defined by outputting a type. */
1903 /* If this typedef name was defined by outputting the type,
1904 don't duplicate it. */
1905 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
1906 && TYPE_NAME (TREE_TYPE (decl)) == decl)
1907 return 0;
1908 #endif
1909 /* Don't output the same typedef twice.
1910 And don't output what language-specific stuff doesn't want output. */
1911 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
1912 return 0;
1914 FORCE_TEXT;
1915 result = 1;
1917 int tag_needed = 1;
1918 int did_output = 0;
1920 if (DECL_NAME (decl))
1922 /* Nonzero means we must output a tag as well as a typedef. */
1923 tag_needed = 0;
1925 /* Handle the case of a C++ structure or union
1926 where the TYPE_NAME is a TYPE_DECL
1927 which gives both a typedef name and a tag. */
1928 /* dbx requires the tag first and the typedef second. */
1929 if ((TREE_CODE (type) == RECORD_TYPE
1930 || TREE_CODE (type) == UNION_TYPE
1931 || TREE_CODE (type) == QUAL_UNION_TYPE)
1932 && TYPE_NAME (type) == decl
1933 && !(use_gnu_debug_info_extensions && have_used_extensions)
1934 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
1935 /* Distinguish the implicit typedefs of C++
1936 from explicit ones that might be found in C. */
1937 && DECL_ARTIFICIAL (decl)
1938 /* Do not generate a tag for records of variable size,
1939 since this type can not be properly described in the
1940 DBX format, and it confuses some tools such as objdump. */
1941 && host_integerp (TYPE_SIZE (type), 1))
1943 tree name = TYPE_NAME (type);
1944 if (TREE_CODE (name) == TYPE_DECL)
1945 name = DECL_NAME (name);
1947 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1948 current_sym_value = 0;
1949 current_sym_addr = 0;
1950 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1952 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1953 IDENTIFIER_POINTER (name));
1954 dbxout_type (type, 1);
1955 dbxout_finish_symbol (NULL_TREE);
1958 /* Output typedef name. */
1959 fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
1960 IDENTIFIER_POINTER (DECL_NAME (decl)));
1962 /* Short cut way to output a tag also. */
1963 if ((TREE_CODE (type) == RECORD_TYPE
1964 || TREE_CODE (type) == UNION_TYPE
1965 || TREE_CODE (type) == QUAL_UNION_TYPE)
1966 && TYPE_NAME (type) == decl
1967 /* Distinguish the implicit typedefs of C++
1968 from explicit ones that might be found in C. */
1969 && DECL_ARTIFICIAL (decl))
1971 if (use_gnu_debug_info_extensions && have_used_extensions)
1973 putc ('T', asmfile);
1974 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1976 #if 0 /* Now we generate the tag for this case up above. */
1977 else
1978 tag_needed = 1;
1979 #endif
1982 putc ('t', asmfile);
1983 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1985 dbxout_type (type, 1);
1986 dbxout_finish_symbol (decl);
1987 did_output = 1;
1990 /* Don't output a tag if this is an incomplete type. This prevents
1991 the sun4 Sun OS 4.x dbx from crashing. */
1993 if (tag_needed && TYPE_NAME (type) != 0
1994 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
1995 || (DECL_NAME (TYPE_NAME (type)) != 0))
1996 && COMPLETE_TYPE_P (type)
1997 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
1999 /* For a TYPE_DECL with no name, but the type has a name,
2000 output a tag.
2001 This is what represents `struct foo' with no typedef. */
2002 /* In C++, the name of a type is the corresponding typedef.
2003 In C, it is an IDENTIFIER_NODE. */
2004 tree name = TYPE_NAME (type);
2005 if (TREE_CODE (name) == TYPE_DECL)
2006 name = DECL_NAME (name);
2008 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2009 current_sym_value = 0;
2010 current_sym_addr = 0;
2011 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2013 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2014 IDENTIFIER_POINTER (name));
2015 dbxout_type (type, 1);
2016 dbxout_finish_symbol (NULL_TREE);
2017 did_output = 1;
2020 /* If an enum type has no name, it cannot be referred to,
2021 but we must output it anyway, since the enumeration constants
2022 can be referred to. */
2023 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2025 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2026 current_sym_value = 0;
2027 current_sym_addr = 0;
2028 current_sym_nchars = 2;
2030 /* Some debuggers fail when given NULL names, so give this a
2031 harmless name of ` '. */
2032 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2033 dbxout_type (type, 1);
2034 dbxout_finish_symbol (NULL_TREE);
2037 /* Prevent duplicate output of a typedef. */
2038 TREE_ASM_WRITTEN (decl) = 1;
2039 break;
2042 case PARM_DECL:
2043 /* Parm decls go in their own separate chains
2044 and are output by dbxout_reg_parms and dbxout_parms. */
2045 abort ();
2047 case RESULT_DECL:
2048 /* Named return value, treat like a VAR_DECL. */
2049 case VAR_DECL:
2050 if (! DECL_RTL_SET_P (decl))
2051 return 0;
2052 /* Don't mention a variable that is external.
2053 Let the file that defines it describe it. */
2054 if (DECL_EXTERNAL (decl))
2055 break;
2057 /* If the variable is really a constant
2058 and not written in memory, inform the debugger. */
2059 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2060 && DECL_INITIAL (decl) != 0
2061 && host_integerp (DECL_INITIAL (decl), 0)
2062 && ! TREE_ASM_WRITTEN (decl)
2063 && (DECL_CONTEXT (decl) == NULL_TREE
2064 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2066 if (TREE_PUBLIC (decl) == 0)
2068 /* The sun4 assembler does not grok this. */
2069 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2071 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2072 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2074 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2075 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
2076 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
2077 #else
2078 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
2080 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
2081 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
2082 #endif
2083 return 1;
2085 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2087 /* don't know how to do this yet. */
2089 break;
2091 /* else it is something we handle like a normal variable. */
2094 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2095 #ifdef LEAF_REG_REMAP
2096 if (current_function_uses_only_leaf_regs)
2097 leaf_renumber_regs_insn (DECL_RTL (decl));
2098 #endif
2100 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2101 break;
2103 default:
2104 break;
2106 return result;
2109 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2110 Add SUFFIX to its name, if SUFFIX is not 0.
2111 Describe the variable as residing in HOME
2112 (usually HOME is DECL_RTL (DECL), but not always).
2113 Returns 1 if the stab was really emitted. */
2115 static int
2116 dbxout_symbol_location (decl, type, suffix, home)
2117 tree decl, type;
2118 const char *suffix;
2119 rtx home;
2121 int letter = 0;
2122 int regno = -1;
2124 /* Don't mention a variable at all
2125 if it was completely optimized into nothingness.
2127 If the decl was from an inline function, then its rtl
2128 is not identically the rtl that was used in this
2129 particular compilation. */
2130 if (GET_CODE (home) == SUBREG)
2132 rtx value = home;
2134 while (GET_CODE (value) == SUBREG)
2135 value = SUBREG_REG (value);
2136 if (GET_CODE (value) == REG)
2138 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2139 return 0;
2141 home = alter_subreg (&home);
2143 if (GET_CODE (home) == REG)
2145 regno = REGNO (home);
2146 if (regno >= FIRST_PSEUDO_REGISTER)
2147 return 0;
2150 /* The kind-of-variable letter depends on where
2151 the variable is and on the scope of its name:
2152 G and N_GSYM for static storage and global scope,
2153 S for static storage and file scope,
2154 V for static storage and local scope,
2155 for those two, use N_LCSYM if data is in bss segment,
2156 N_STSYM if in data segment, N_FUN otherwise.
2157 (We used N_FUN originally, then changed to N_STSYM
2158 to please GDB. However, it seems that confused ld.
2159 Now GDB has been fixed to like N_FUN, says Kingdon.)
2160 no letter at all, and N_LSYM, for auto variable,
2161 r and N_RSYM for register variable. */
2163 if (GET_CODE (home) == MEM
2164 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2166 if (TREE_PUBLIC (decl))
2168 letter = 'G';
2169 current_sym_code = N_GSYM;
2171 else
2173 current_sym_addr = XEXP (home, 0);
2175 letter = decl_function_context (decl) ? 'V' : 'S';
2177 /* This should be the same condition as in assemble_variable, but
2178 we don't have access to dont_output_data here. So, instead,
2179 we rely on the fact that error_mark_node initializers always
2180 end up in bss for C++ and never end up in bss for C. */
2181 if (DECL_INITIAL (decl) == 0
2182 || (!strcmp (lang_hooks.name, "GNU C++")
2183 && DECL_INITIAL (decl) == error_mark_node))
2184 current_sym_code = N_LCSYM;
2185 else if (DECL_IN_TEXT_SECTION (decl))
2186 /* This is not quite right, but it's the closest
2187 of all the codes that Unix defines. */
2188 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2189 else
2191 /* Some ports can transform a symbol ref into a label ref,
2192 because the symbol ref is too far away and has to be
2193 dumped into a constant pool. Alternatively, the symbol
2194 in the constant pool might be referenced by a different
2195 symbol. */
2196 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2197 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2199 rtx tmp = get_pool_constant (current_sym_addr);
2201 if (GET_CODE (tmp) == SYMBOL_REF
2202 || GET_CODE (tmp) == LABEL_REF)
2203 current_sym_addr = tmp;
2206 /* Ultrix `as' seems to need this. */
2207 #ifdef DBX_STATIC_STAB_DATA_SECTION
2208 data_section ();
2209 #endif
2210 current_sym_code = N_STSYM;
2214 else if (regno >= 0)
2216 letter = 'r';
2217 current_sym_code = N_RSYM;
2218 current_sym_value = DBX_REGISTER_NUMBER (regno);
2220 else if (GET_CODE (home) == MEM
2221 && (GET_CODE (XEXP (home, 0)) == MEM
2222 || (GET_CODE (XEXP (home, 0)) == REG
2223 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2224 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2225 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2226 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2227 #endif
2229 /* If the value is indirect by memory or by a register
2230 that isn't the frame pointer
2231 then it means the object is variable-sized and address through
2232 that register or stack slot. DBX has no way to represent this
2233 so all we can do is output the variable as a pointer.
2234 If it's not a parameter, ignore it.
2235 (VAR_DECLs like this can be made by integrate.c.) */
2237 if (GET_CODE (XEXP (home, 0)) == REG)
2239 letter = 'r';
2240 current_sym_code = N_RSYM;
2241 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2242 return 0;
2243 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2245 else
2247 current_sym_code = N_LSYM;
2248 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2249 We want the value of that CONST_INT. */
2250 current_sym_value
2251 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2254 /* Effectively do build_pointer_type, but don't cache this type,
2255 since it might be temporary whereas the type it points to
2256 might have been saved for inlining. */
2257 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2258 type = make_node (POINTER_TYPE);
2259 TREE_TYPE (type) = TREE_TYPE (decl);
2261 else if (GET_CODE (home) == MEM
2262 && GET_CODE (XEXP (home, 0)) == REG)
2264 current_sym_code = N_LSYM;
2265 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2267 else if (GET_CODE (home) == MEM
2268 && GET_CODE (XEXP (home, 0)) == PLUS
2269 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2271 current_sym_code = N_LSYM;
2272 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2273 We want the value of that CONST_INT. */
2274 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2276 else if (GET_CODE (home) == MEM
2277 && GET_CODE (XEXP (home, 0)) == CONST)
2279 /* Handle an obscure case which can arise when optimizing and
2280 when there are few available registers. (This is *always*
2281 the case for i386/i486 targets). The RTL looks like
2282 (MEM (CONST ...)) even though this variable is a local `auto'
2283 or a local `register' variable. In effect, what has happened
2284 is that the reload pass has seen that all assignments and
2285 references for one such a local variable can be replaced by
2286 equivalent assignments and references to some static storage
2287 variable, thereby avoiding the need for a register. In such
2288 cases we're forced to lie to debuggers and tell them that
2289 this variable was itself `static'. */
2290 current_sym_code = N_LCSYM;
2291 letter = 'V';
2292 current_sym_addr = XEXP (XEXP (home, 0), 0);
2294 else if (GET_CODE (home) == CONCAT)
2296 tree subtype;
2298 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2299 for example), then there is no easy way to figure out
2300 what SUBTYPE should be. So, we give up. */
2301 if (TREE_CODE (type) != COMPLEX_TYPE)
2302 return 0;
2304 subtype = TREE_TYPE (type);
2306 /* If the variable's storage is in two parts,
2307 output each as a separate stab with a modified name. */
2308 if (WORDS_BIG_ENDIAN)
2309 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2310 else
2311 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2313 /* Cast avoids warning in old compilers. */
2314 current_sym_code = (STAB_CODE_TYPE) 0;
2315 current_sym_value = 0;
2316 current_sym_addr = 0;
2317 dbxout_prepare_symbol (decl);
2319 if (WORDS_BIG_ENDIAN)
2320 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2321 else
2322 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2323 return 1;
2325 else
2326 /* Address might be a MEM, when DECL is a variable-sized object.
2327 Or it might be const0_rtx, meaning previous passes
2328 want us to ignore this variable. */
2329 return 0;
2331 /* Ok, start a symtab entry and output the variable name. */
2332 FORCE_TEXT;
2334 #ifdef DBX_STATIC_BLOCK_START
2335 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2336 #endif
2338 dbxout_symbol_name (decl, suffix, letter);
2339 dbxout_type (type, 0);
2340 dbxout_finish_symbol (decl);
2342 #ifdef DBX_STATIC_BLOCK_END
2343 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2344 #endif
2345 return 1;
2348 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2349 Then output LETTER to indicate the kind of location the symbol has. */
2351 static void
2352 dbxout_symbol_name (decl, suffix, letter)
2353 tree decl;
2354 const char *suffix;
2355 int letter;
2357 const char *name;
2359 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2360 /* One slight hitch: if this is a VAR_DECL which is a static
2361 class member, we must put out the mangled name instead of the
2362 DECL_NAME. Note also that static member (variable) names DO NOT begin
2363 with underscores in .stabs directives. */
2364 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2365 else
2366 /* ...but if we're function-local, we don't want to include the junk
2367 added by ASM_FORMAT_PRIVATE_NAME. */
2368 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2370 if (name == 0)
2371 name = "(anon)";
2372 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2373 (suffix ? suffix : ""));
2375 if (letter)
2376 putc (letter, asmfile);
2379 static void
2380 dbxout_prepare_symbol (decl)
2381 tree decl ATTRIBUTE_UNUSED;
2383 #ifdef WINNING_GDB
2384 const char *filename = DECL_SOURCE_FILE (decl);
2386 dbxout_source_file (asmfile, filename);
2387 #endif
2390 static void
2391 dbxout_finish_symbol (sym)
2392 tree sym;
2394 #ifdef DBX_FINISH_SYMBOL
2395 DBX_FINISH_SYMBOL (sym);
2396 #else
2397 int line = 0;
2398 if (use_gnu_debug_info_extensions && sym != 0)
2399 line = DECL_SOURCE_LINE (sym);
2401 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2402 if (current_sym_addr)
2403 output_addr_const (asmfile, current_sym_addr);
2404 else
2405 fprintf (asmfile, "%d", current_sym_value);
2406 putc ('\n', asmfile);
2407 #endif
2410 /* Output definitions of all the decls in a chain. Return non-zero if
2411 anything was output */
2414 dbxout_syms (syms)
2415 tree syms;
2417 int result = 0;
2418 while (syms)
2420 result += dbxout_symbol (syms, 1);
2421 syms = TREE_CHAIN (syms);
2423 return result;
2426 /* The following two functions output definitions of function parameters.
2427 Each parameter gets a definition locating it in the parameter list.
2428 Each parameter that is a register variable gets a second definition
2429 locating it in the register.
2431 Printing or argument lists in gdb uses the definitions that
2432 locate in the parameter list. But reference to the variable in
2433 expressions uses preferentially the definition as a register. */
2435 /* Output definitions, referring to storage in the parmlist,
2436 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2438 void
2439 dbxout_parms (parms)
2440 tree parms;
2442 for (; parms; parms = TREE_CHAIN (parms))
2443 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2445 dbxout_prepare_symbol (parms);
2447 /* Perform any necessary register eliminations on the parameter's rtl,
2448 so that the debugging output will be accurate. */
2449 DECL_INCOMING_RTL (parms)
2450 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2451 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2452 #ifdef LEAF_REG_REMAP
2453 if (current_function_uses_only_leaf_regs)
2455 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2456 leaf_renumber_regs_insn (DECL_RTL (parms));
2458 #endif
2460 if (PARM_PASSED_IN_MEMORY (parms))
2462 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2464 /* ??? Here we assume that the parm address is indexed
2465 off the frame pointer or arg pointer.
2466 If that is not true, we produce meaningless results,
2467 but do not crash. */
2468 if (GET_CODE (addr) == PLUS
2469 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2470 current_sym_value = INTVAL (XEXP (addr, 1));
2471 else
2472 current_sym_value = 0;
2474 current_sym_code = N_PSYM;
2475 current_sym_addr = 0;
2477 FORCE_TEXT;
2478 if (DECL_NAME (parms))
2480 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2482 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2483 IDENTIFIER_POINTER (DECL_NAME (parms)),
2484 DBX_MEMPARM_STABS_LETTER);
2486 else
2488 current_sym_nchars = 8;
2489 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2490 DBX_MEMPARM_STABS_LETTER);
2493 /* It is quite tempting to use:
2495 dbxout_type (TREE_TYPE (parms), 0);
2497 as the next statement, rather than using DECL_ARG_TYPE(), so
2498 that gcc reports the actual type of the parameter, rather
2499 than the promoted type. This certainly makes GDB's life
2500 easier, at least for some ports. The change is a bad idea
2501 however, since GDB expects to be able access the type without
2502 performing any conversions. So for example, if we were
2503 passing a float to an unprototyped function, gcc will store a
2504 double on the stack, but if we emit a stab saying the type is a
2505 float, then gdb will only read in a single value, and this will
2506 produce an erroneous value. */
2507 dbxout_type (DECL_ARG_TYPE (parms), 0);
2508 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2509 dbxout_finish_symbol (parms);
2511 else if (GET_CODE (DECL_RTL (parms)) == REG)
2513 rtx best_rtl;
2514 char regparm_letter;
2515 tree parm_type;
2516 /* Parm passed in registers and lives in registers or nowhere. */
2518 current_sym_code = DBX_REGPARM_STABS_CODE;
2519 regparm_letter = DBX_REGPARM_STABS_LETTER;
2520 current_sym_addr = 0;
2522 /* If parm lives in a register, use that register;
2523 pretend the parm was passed there. It would be more consistent
2524 to describe the register where the parm was passed,
2525 but in practice that register usually holds something else.
2527 If we use DECL_RTL, then we must use the declared type of
2528 the variable, not the type that it arrived in. */
2529 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2531 best_rtl = DECL_RTL (parms);
2532 parm_type = TREE_TYPE (parms);
2534 /* If the parm lives nowhere, use the register where it was
2535 passed. It is also better to use the declared type here. */
2536 else
2538 best_rtl = DECL_INCOMING_RTL (parms);
2539 parm_type = TREE_TYPE (parms);
2541 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2543 FORCE_TEXT;
2544 if (DECL_NAME (parms))
2546 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2547 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2548 IDENTIFIER_POINTER (DECL_NAME (parms)),
2549 regparm_letter);
2551 else
2553 current_sym_nchars = 8;
2554 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2555 regparm_letter);
2558 dbxout_type (parm_type, 0);
2559 dbxout_finish_symbol (parms);
2561 else if (GET_CODE (DECL_RTL (parms)) == MEM
2562 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2563 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2564 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2565 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2566 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2567 #endif
2570 /* Parm was passed via invisible reference.
2571 That is, its address was passed in a register.
2572 Output it as if it lived in that register.
2573 The debugger will know from the type
2574 that it was actually passed by invisible reference. */
2576 char regparm_letter;
2577 /* Parm passed in registers and lives in registers or nowhere. */
2579 current_sym_code = DBX_REGPARM_STABS_CODE;
2580 if (use_gnu_debug_info_extensions)
2581 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2582 else
2583 regparm_letter = DBX_REGPARM_STABS_LETTER;
2585 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2586 If it is an unallocated pseudo-reg, then use the register where
2587 it was passed instead. */
2588 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2589 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2590 else
2591 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2593 current_sym_addr = 0;
2595 FORCE_TEXT;
2596 if (DECL_NAME (parms))
2598 current_sym_nchars
2599 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2601 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2602 IDENTIFIER_POINTER (DECL_NAME (parms)),
2603 regparm_letter);
2605 else
2607 current_sym_nchars = 8;
2608 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2609 regparm_letter);
2612 dbxout_type (TREE_TYPE (parms), 0);
2613 dbxout_finish_symbol (parms);
2615 else if (GET_CODE (DECL_RTL (parms)) == MEM
2616 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2618 /* Parm was passed via invisible reference, with the reference
2619 living on the stack. DECL_RTL looks like
2620 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2621 could look like (MEM (MEM (REG))). */
2622 const char *const decl_name = (DECL_NAME (parms)
2623 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2624 : "(anon)");
2625 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2626 current_sym_value = 0;
2627 else
2628 current_sym_value
2629 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2630 current_sym_addr = 0;
2632 FORCE_TEXT;
2633 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2635 current_sym_value
2636 = DEBUGGER_ARG_OFFSET (current_sym_value,
2637 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2638 dbxout_type (TREE_TYPE (parms), 0);
2639 dbxout_finish_symbol (parms);
2641 else if (GET_CODE (DECL_RTL (parms)) == MEM
2642 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2643 /* ??? A constant address for a parm can happen
2644 when the reg it lives in is equiv to a constant in memory.
2645 Should make this not happen, after 2.4. */
2646 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2648 /* Parm was passed in registers but lives on the stack. */
2650 current_sym_code = N_PSYM;
2651 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2652 in which case we want the value of that CONST_INT,
2653 or (MEM (REG ...)),
2654 in which case we use a value of zero. */
2655 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2656 current_sym_value = 0;
2657 else
2658 current_sym_value
2659 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2661 current_sym_addr = 0;
2663 /* Make a big endian correction if the mode of the type of the
2664 parameter is not the same as the mode of the rtl. */
2665 if (BYTES_BIG_ENDIAN
2666 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2667 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2669 current_sym_value +=
2670 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2671 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2674 FORCE_TEXT;
2675 if (DECL_NAME (parms))
2677 current_sym_nchars
2678 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2680 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2681 IDENTIFIER_POINTER (DECL_NAME (parms)),
2682 DBX_MEMPARM_STABS_LETTER);
2684 else
2686 current_sym_nchars = 8;
2687 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2688 DBX_MEMPARM_STABS_LETTER);
2691 current_sym_value
2692 = DEBUGGER_ARG_OFFSET (current_sym_value,
2693 XEXP (DECL_RTL (parms), 0));
2694 dbxout_type (TREE_TYPE (parms), 0);
2695 dbxout_finish_symbol (parms);
2700 /* Output definitions for the places where parms live during the function,
2701 when different from where they were passed, when the parms were passed
2702 in memory.
2704 It is not useful to do this for parms passed in registers
2705 that live during the function in different registers, because it is
2706 impossible to look in the passed register for the passed value,
2707 so we use the within-the-function register to begin with.
2709 PARMS is a chain of PARM_DECL nodes. */
2711 void
2712 dbxout_reg_parms (parms)
2713 tree parms;
2715 for (; parms; parms = TREE_CHAIN (parms))
2716 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2718 dbxout_prepare_symbol (parms);
2720 /* Report parms that live in registers during the function
2721 but were passed in memory. */
2722 if (GET_CODE (DECL_RTL (parms)) == REG
2723 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2724 dbxout_symbol_location (parms, TREE_TYPE (parms),
2725 0, DECL_RTL (parms));
2726 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2727 dbxout_symbol_location (parms, TREE_TYPE (parms),
2728 0, DECL_RTL (parms));
2729 /* Report parms that live in memory but not where they were passed. */
2730 else if (GET_CODE (DECL_RTL (parms)) == MEM
2731 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2732 dbxout_symbol_location (parms, TREE_TYPE (parms),
2733 0, DECL_RTL (parms));
2737 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2738 output definitions of those names, in raw form */
2740 static void
2741 dbxout_args (args)
2742 tree args;
2744 while (args)
2746 putc (',', asmfile);
2747 dbxout_type (TREE_VALUE (args), 0);
2748 CHARS (1);
2749 args = TREE_CHAIN (args);
2753 /* Output everything about a symbol block (a BLOCK node
2754 that represents a scope level),
2755 including recursive output of contained blocks.
2757 BLOCK is the BLOCK node.
2758 DEPTH is its depth within containing symbol blocks.
2759 ARGS is usually zero; but for the outermost block of the
2760 body of a function, it is a chain of PARM_DECLs for the function parameters.
2761 We output definitions of all the register parms
2762 as if they were local variables of that block.
2764 If -g1 was used, we count blocks just the same, but output nothing
2765 except for the outermost block.
2767 Actually, BLOCK may be several blocks chained together.
2768 We handle them all in sequence. */
2770 static void
2771 dbxout_block (block, depth, args)
2772 tree block;
2773 int depth;
2774 tree args;
2776 int blocknum = -1;
2778 #if DBX_BLOCKS_FUNCTION_RELATIVE
2779 const char *begin_label;
2780 if (current_function_func_begin_label != NULL_TREE)
2781 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2782 else
2783 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2784 #endif
2786 while (block)
2788 /* Ignore blocks never expanded or otherwise marked as real. */
2789 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2791 int did_output;
2793 #ifdef DBX_LBRAC_FIRST
2794 did_output = 1;
2795 #else
2796 /* In dbx format, the syms of a block come before the N_LBRAC.
2797 If nothing is output, we don't need the N_LBRAC, either. */
2798 did_output = 0;
2799 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2800 did_output = dbxout_syms (BLOCK_VARS (block));
2801 if (args)
2802 dbxout_reg_parms (args);
2803 #endif
2805 /* Now output an N_LBRAC symbol to represent the beginning of
2806 the block. Use the block's tree-walk order to generate
2807 the assembler symbols LBBn and LBEn
2808 that final will define around the code in this block. */
2809 if (depth > 0 && did_output)
2811 char buf[20];
2812 blocknum = BLOCK_NUMBER (block);
2813 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2815 if (BLOCK_HANDLER_BLOCK (block))
2817 /* A catch block. Must precede N_LBRAC. */
2818 tree decl = BLOCK_VARS (block);
2819 while (decl)
2821 #ifdef DBX_OUTPUT_CATCH
2822 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2823 #else
2824 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2825 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2826 assemble_name (asmfile, buf);
2827 fprintf (asmfile, "\n");
2828 #endif
2829 decl = TREE_CHAIN (decl);
2833 #ifdef DBX_OUTPUT_LBRAC
2834 DBX_OUTPUT_LBRAC (asmfile, buf);
2835 #else
2836 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2837 assemble_name (asmfile, buf);
2838 #if DBX_BLOCKS_FUNCTION_RELATIVE
2839 putc ('-', asmfile);
2840 assemble_name (asmfile, begin_label);
2841 #endif
2842 fprintf (asmfile, "\n");
2843 #endif
2846 #ifdef DBX_LBRAC_FIRST
2847 /* On some weird machines, the syms of a block
2848 come after the N_LBRAC. */
2849 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2850 dbxout_syms (BLOCK_VARS (block));
2851 if (args)
2852 dbxout_reg_parms (args);
2853 #endif
2855 /* Output the subblocks. */
2856 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2858 /* Refer to the marker for the end of the block. */
2859 if (depth > 0 && did_output)
2861 char buf[20];
2862 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2863 #ifdef DBX_OUTPUT_RBRAC
2864 DBX_OUTPUT_RBRAC (asmfile, buf);
2865 #else
2866 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2867 assemble_name (asmfile, buf);
2868 #if DBX_BLOCKS_FUNCTION_RELATIVE
2869 putc ('-', asmfile);
2870 assemble_name (asmfile, begin_label);
2871 #endif
2872 fprintf (asmfile, "\n");
2873 #endif
2876 block = BLOCK_CHAIN (block);
2880 /* Output the information about a function and its arguments and result.
2881 Usually this follows the function's code,
2882 but on some systems, it comes before. */
2884 #if defined (DBX_DEBUGGING_INFO)
2885 static void
2886 dbxout_begin_function (decl)
2887 tree decl;
2889 dbxout_symbol (decl, 0);
2890 dbxout_parms (DECL_ARGUMENTS (decl));
2891 if (DECL_NAME (DECL_RESULT (decl)) != 0)
2892 dbxout_symbol (DECL_RESULT (decl), 1);
2894 #endif /* DBX_DEBUGGING_INFO */
2896 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */