2002-05-17 David S. Miller <davem@redhat.com>
[official-gcc.git] / gcc / dbxout.c
blobfc49ad70a5a6ec1fc262b62b7cf12dafc7d56963
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 const 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 const 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 = (*lang_hooks.decls.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)
1223 /* If the size is non-standard, say what it is if we can use
1224 GDB extensions. */
1226 if (use_gnu_debug_info_extensions
1227 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1229 have_used_extensions = 1;
1230 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1231 CHARS (5);
1234 dbxout_range_type (type);
1237 else
1239 /* If the size is non-standard, say what it is if we can use
1240 GDB extensions. */
1242 if (use_gnu_debug_info_extensions
1243 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1245 have_used_extensions = 1;
1246 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1247 CHARS (5);
1250 /* If we can use GDB extensions and the size is wider than a
1251 long (the size used by GDB to read them) or we may have
1252 trouble writing the bounds the usual way, write them in
1253 octal. Note the test is for the *target's* size of "long",
1254 not that of the host. The host test is just to make sure we
1255 can write it out in case the host wide int is narrower than the
1256 target "long". */
1258 /* For unsigned types, we use octal if they are the same size or
1259 larger. This is because we print the bounds as signed decimal,
1260 and hence they can't span same size unsigned types. */
1262 if (use_gnu_debug_info_extensions
1263 && TYPE_MIN_VALUE (type) != 0
1264 && TREE_CODE (TYPE_MIN_VALUE (type)) == INTEGER_CST
1265 && TYPE_MAX_VALUE (type) != 0
1266 && TREE_CODE (TYPE_MAX_VALUE (type)) == INTEGER_CST
1267 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node)
1268 || ((TYPE_PRECISION (type)
1269 == TYPE_PRECISION (integer_type_node))
1270 && TREE_UNSIGNED (type))
1271 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT
1272 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT
1273 && TREE_UNSIGNED (type))))
1275 fprintf (asmfile, "r");
1276 CHARS (1);
1277 dbxout_type_index (type);
1278 fprintf (asmfile, ";");
1279 CHARS (1);
1280 print_int_cst_octal (TYPE_MIN_VALUE (type));
1281 fprintf (asmfile, ";");
1282 CHARS (1);
1283 print_int_cst_octal (TYPE_MAX_VALUE (type));
1284 fprintf (asmfile, ";");
1285 CHARS (1);
1288 else
1289 /* Output other integer types as subranges of `int'. */
1290 dbxout_range_type (type);
1293 break;
1295 case REAL_TYPE:
1296 /* This used to say `r1' and we used to take care
1297 to make sure that `int' was type number 1. */
1298 fprintf (asmfile, "r");
1299 CHARS (1);
1300 dbxout_type_index (integer_type_node);
1301 putc (';', asmfile);
1302 CHARS (1);
1303 print_wide_int (int_size_in_bytes (type));
1304 fputs (";0;", asmfile);
1305 CHARS (3);
1306 break;
1308 case CHAR_TYPE:
1309 if (use_gnu_debug_info_extensions)
1311 have_used_extensions = 1;
1312 fputs ("@s", asmfile);
1313 CHARS (2);
1314 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1315 fputs (";-20;", asmfile);
1316 CHARS (4);
1318 else
1320 /* Output the type `char' as a subrange of itself.
1321 That is what pcc seems to do. */
1322 fprintf (asmfile, "r");
1323 CHARS (1);
1324 dbxout_type_index (char_type_node);
1325 fprintf (asmfile, ";0;%d;", TREE_UNSIGNED (type) ? 255 : 127);
1326 CHARS (7);
1328 break;
1330 case BOOLEAN_TYPE:
1331 if (use_gnu_debug_info_extensions)
1333 have_used_extensions = 1;
1334 fputs ("@s", asmfile);
1335 CHARS (2);
1336 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1337 fputs (";-16;", asmfile);
1338 CHARS (4);
1340 else /* Define as enumeral type (False, True) */
1342 fprintf (asmfile, "eFalse:0,True:1,;");
1343 CHARS (17);
1345 break;
1347 case FILE_TYPE:
1348 putc ('d', asmfile);
1349 CHARS (1);
1350 dbxout_type (TREE_TYPE (type), 0);
1351 break;
1353 case COMPLEX_TYPE:
1354 /* Differs from the REAL_TYPE by its new data type number */
1356 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE)
1358 fprintf (asmfile, "r");
1359 CHARS (1);
1360 dbxout_type_index (type);
1361 putc (';', asmfile);
1362 CHARS (1);
1363 print_wide_int (2 * int_size_in_bytes (TREE_TYPE (type)));
1364 fputs (";0;", asmfile);
1365 CHARS (3);
1367 else
1369 /* Output a complex integer type as a structure,
1370 pending some other way to do it. */
1371 putc ('s', asmfile);
1372 CHARS (1);
1373 print_wide_int (int_size_in_bytes (type));
1374 fprintf (asmfile, "real:");
1375 CHARS (5);
1377 dbxout_type (TREE_TYPE (type), 0);
1378 fprintf (asmfile, ",0,%d;", TYPE_PRECISION (TREE_TYPE (type)));
1379 CHARS (7);
1380 fprintf (asmfile, "imag:");
1381 CHARS (5);
1382 dbxout_type (TREE_TYPE (type), 0);
1383 fprintf (asmfile, ",%d,%d;;", TYPE_PRECISION (TREE_TYPE (type)),
1384 TYPE_PRECISION (TREE_TYPE (type)));
1385 CHARS (10);
1387 break;
1389 case SET_TYPE:
1390 if (use_gnu_debug_info_extensions)
1392 have_used_extensions = 1;
1393 fputs ("@s", asmfile);
1394 CHARS (2);
1395 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1396 putc (';', asmfile);
1397 CHARS (1);
1399 /* Check if a bitstring type, which in Chill is
1400 different from a [power]set. */
1401 if (TYPE_STRING_FLAG (type))
1403 fprintf (asmfile, "@S;");
1404 CHARS (3);
1407 putc ('S', asmfile);
1408 CHARS (1);
1409 dbxout_type (TYPE_DOMAIN (type), 0);
1410 break;
1412 case ARRAY_TYPE:
1413 /* Make arrays of packed bits look like bitstrings for chill. */
1414 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions)
1416 have_used_extensions = 1;
1417 fputs ("@s", asmfile);
1418 CHARS (2);
1419 print_wide_int (BITS_PER_UNIT * int_size_in_bytes (type));
1420 fprintf (asmfile, ";@S;S");
1421 CHARS (5);
1422 dbxout_type (TYPE_DOMAIN (type), 0);
1423 break;
1426 /* Output "a" followed by a range type definition
1427 for the index type of the array
1428 followed by a reference to the target-type.
1429 ar1;0;N;M for a C array of type M and size N+1. */
1430 /* Check if a character string type, which in Chill is
1431 different from an array of characters. */
1432 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions)
1434 have_used_extensions = 1;
1435 fprintf (asmfile, "@S;");
1436 CHARS (3);
1438 tem = TYPE_DOMAIN (type);
1439 if (tem == NULL)
1441 fprintf (asmfile, "ar");
1442 CHARS (2);
1443 dbxout_type_index (integer_type_node);
1444 fprintf (asmfile, ";0;-1;");
1445 CHARS (6);
1447 else
1449 fprintf (asmfile, "a");
1450 CHARS (1);
1451 dbxout_range_type (tem);
1454 dbxout_type (TREE_TYPE (type), 0);
1455 break;
1457 case RECORD_TYPE:
1458 case UNION_TYPE:
1459 case QUAL_UNION_TYPE:
1461 int i, n_baseclasses = 0;
1463 if (TYPE_BINFO (type) != 0
1464 && TREE_CODE (TYPE_BINFO (type)) == TREE_VEC
1465 && TYPE_BINFO_BASETYPES (type) != 0)
1466 n_baseclasses = TREE_VEC_LENGTH (TYPE_BINFO_BASETYPES (type));
1468 /* Output a structure type. We must use the same test here as we
1469 use in the DBX_NO_XREFS case above. */
1470 if ((TYPE_NAME (type) != 0
1471 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1472 && DECL_IGNORED_P (TYPE_NAME (type)))
1473 && !full)
1474 || !COMPLETE_TYPE_P (type)
1475 /* No way in DBX fmt to describe a variable size. */
1476 || ! host_integerp (TYPE_SIZE (type), 1))
1478 /* If the type is just a cross reference, output one
1479 and mark the type as partially described.
1480 If it later becomes defined, we will output
1481 its real definition.
1482 If the type has a name, don't nest its definition within
1483 another type's definition; instead, output an xref
1484 and let the definition come when the name is defined. */
1485 fputs ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu", asmfile);
1486 CHARS (2);
1487 #if 0 /* This assertion is legitimately false in C++. */
1488 /* We shouldn't be outputting a reference to a type before its
1489 definition unless the type has a tag name.
1490 A typedef name without a tag name should be impossible. */
1491 if (TREE_CODE (TYPE_NAME (type)) != IDENTIFIER_NODE)
1492 abort ();
1493 #endif
1494 if (TYPE_NAME (type) != 0)
1495 dbxout_type_name (type);
1496 else
1498 fprintf (asmfile, "$$%d", anonymous_type_number++);
1499 CHARS (5);
1502 fprintf (asmfile, ":");
1503 CHARS (1);
1504 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1505 break;
1508 /* Identify record or union, and print its size. */
1509 putc (((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'), asmfile);
1510 CHARS (1);
1511 print_wide_int (int_size_in_bytes (type));
1513 if (use_gnu_debug_info_extensions)
1515 if (n_baseclasses)
1517 have_used_extensions = 1;
1518 fprintf (asmfile, "!%d,", n_baseclasses);
1519 CHARS (8);
1522 for (i = 0; i < n_baseclasses; i++)
1524 tree child = TREE_VEC_ELT (BINFO_BASETYPES (TYPE_BINFO (type)), i);
1526 if (use_gnu_debug_info_extensions)
1528 have_used_extensions = 1;
1529 putc (TREE_VIA_VIRTUAL (child) ? '1' : '0', asmfile);
1530 putc (TREE_VIA_PUBLIC (child) ? '2' : '0', asmfile);
1531 CHARS (2);
1532 if (TREE_VIA_VIRTUAL (child) && strcmp (lang_hooks.name, "GNU C++") == 0)
1533 /* For a virtual base, print the (negative) offset within
1534 the vtable where we must look to find the necessary
1535 adjustment. */
1536 print_wide_int (tree_low_cst (BINFO_VPTR_FIELD (child), 0)
1537 * BITS_PER_UNIT);
1538 else
1539 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1540 * BITS_PER_UNIT);
1541 putc (',', asmfile);
1542 CHARS (1);
1543 dbxout_type (BINFO_TYPE (child), 0);
1544 putc (';', asmfile);
1545 CHARS (1);
1547 else
1549 /* Print out the base class information with fields
1550 which have the same names at the types they hold. */
1551 dbxout_type_name (BINFO_TYPE (child));
1552 putc (':', asmfile);
1553 CHARS (1);
1554 dbxout_type (BINFO_TYPE (child), full);
1555 putc (',', asmfile);
1556 CHARS (1);
1557 print_wide_int (tree_low_cst (BINFO_OFFSET (child), 0)
1558 * BITS_PER_UNIT);
1559 putc (',', asmfile);
1560 CHARS (1);
1561 print_wide_int (tree_low_cst (DECL_SIZE
1562 (TYPE_NAME
1563 (BINFO_TYPE (child))),
1565 * BITS_PER_UNIT);
1566 putc (';', asmfile);
1567 CHARS (1);
1572 /* Write out the field declarations. */
1573 dbxout_type_fields (type);
1574 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE)
1576 have_used_extensions = 1;
1577 dbxout_type_methods (type);
1580 putc (';', asmfile);
1581 CHARS (1);
1583 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE
1584 /* Avoid the ~ if we don't really need it--it confuses dbx. */
1585 && TYPE_VFIELD (type))
1587 have_used_extensions = 1;
1589 /* Tell GDB+ that it may keep reading. */
1590 putc ('~', asmfile);
1591 CHARS (1);
1593 /* We need to write out info about what field this class
1594 uses as its "main" vtable pointer field, because if this
1595 field is inherited from a base class, GDB cannot necessarily
1596 figure out which field it's using in time. */
1597 if (TYPE_VFIELD (type))
1599 putc ('%', asmfile);
1600 CHARS (1);
1601 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0);
1604 putc (';', asmfile);
1605 CHARS (1);
1607 break;
1609 case ENUMERAL_TYPE:
1610 /* We must use the same test here as we use in the DBX_NO_XREFS case
1611 above. We simplify it a bit since an enum will never have a variable
1612 size. */
1613 if ((TYPE_NAME (type) != 0
1614 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL
1615 && DECL_IGNORED_P (TYPE_NAME (type)))
1616 && !full)
1617 || !COMPLETE_TYPE_P (type))
1619 fprintf (asmfile, "xe");
1620 CHARS (2);
1621 dbxout_type_name (type);
1622 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF;
1623 putc (':', asmfile);
1624 CHARS (1);
1625 return;
1627 #ifdef DBX_OUTPUT_ENUM
1628 DBX_OUTPUT_ENUM (asmfile, type);
1629 #else
1630 if (use_gnu_debug_info_extensions
1631 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node))
1633 fprintf (asmfile, "@s%d;", TYPE_PRECISION (type));
1634 CHARS (5);
1637 putc ('e', asmfile);
1638 CHARS (1);
1639 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem))
1641 fprintf (asmfile, "%s:", IDENTIFIER_POINTER (TREE_PURPOSE (tem)));
1642 CHARS (IDENTIFIER_LENGTH (TREE_PURPOSE (tem)) + 1);
1643 if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == 0)
1644 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1645 else if (TREE_INT_CST_HIGH (TREE_VALUE (tem)) == -1
1646 && (HOST_WIDE_INT) TREE_INT_CST_LOW (TREE_VALUE (tem)) < 0)
1647 print_wide_int (TREE_INT_CST_LOW (TREE_VALUE (tem)));
1648 else
1649 print_int_cst_octal (TREE_VALUE (tem));
1651 putc (',', asmfile);
1652 CHARS (1);
1653 if (TREE_CHAIN (tem) != 0)
1654 CONTIN;
1657 putc (';', asmfile);
1658 CHARS (1);
1659 #endif
1660 break;
1662 case POINTER_TYPE:
1663 putc ('*', asmfile);
1664 CHARS (1);
1665 dbxout_type (TREE_TYPE (type), 0);
1666 break;
1668 case METHOD_TYPE:
1669 if (use_gnu_debug_info_extensions)
1671 have_used_extensions = 1;
1672 putc ('#', asmfile);
1673 CHARS (1);
1675 /* Write the argument types out longhand. */
1676 dbxout_type (TYPE_METHOD_BASETYPE (type), 0);
1677 putc (',', asmfile);
1678 CHARS (1);
1679 dbxout_type (TREE_TYPE (type), 0);
1680 dbxout_args (TYPE_ARG_TYPES (type));
1681 putc (';', asmfile);
1682 CHARS (1);
1684 else
1685 /* Treat it as a function type. */
1686 dbxout_type (TREE_TYPE (type), 0);
1687 break;
1689 case OFFSET_TYPE:
1690 if (use_gnu_debug_info_extensions)
1692 have_used_extensions = 1;
1693 putc ('@', asmfile);
1694 CHARS (1);
1695 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0);
1696 putc (',', asmfile);
1697 CHARS (1);
1698 dbxout_type (TREE_TYPE (type), 0);
1700 else
1701 /* Should print as an int, because it is really just an offset. */
1702 dbxout_type (integer_type_node, 0);
1703 break;
1705 case REFERENCE_TYPE:
1706 if (use_gnu_debug_info_extensions)
1707 have_used_extensions = 1;
1708 putc (use_gnu_debug_info_extensions ? '&' : '*', asmfile);
1709 CHARS (1);
1710 dbxout_type (TREE_TYPE (type), 0);
1711 break;
1713 case FUNCTION_TYPE:
1714 putc ('f', asmfile);
1715 CHARS (1);
1716 dbxout_type (TREE_TYPE (type), 0);
1717 break;
1719 default:
1720 abort ();
1724 /* Print the value of integer constant C, in octal,
1725 handling double precision. */
1727 static void
1728 print_int_cst_octal (c)
1729 tree c;
1731 unsigned HOST_WIDE_INT high = TREE_INT_CST_HIGH (c);
1732 unsigned HOST_WIDE_INT low = TREE_INT_CST_LOW (c);
1733 int excess = (3 - (HOST_BITS_PER_WIDE_INT % 3));
1734 unsigned int width = TYPE_PRECISION (TREE_TYPE (c));
1736 /* GDB wants constants with no extra leading "1" bits, so
1737 we need to remove any sign-extension that might be
1738 present. */
1739 if (width == HOST_BITS_PER_WIDE_INT * 2)
1741 else if (width > HOST_BITS_PER_WIDE_INT)
1742 high &= (((HOST_WIDE_INT) 1 << (width - HOST_BITS_PER_WIDE_INT)) - 1);
1743 else if (width == HOST_BITS_PER_WIDE_INT)
1744 high = 0;
1745 else
1746 high = 0, low &= (((HOST_WIDE_INT) 1 << width) - 1);
1748 fprintf (asmfile, "0");
1749 CHARS (1);
1751 if (excess == 3)
1753 print_octal (high, HOST_BITS_PER_WIDE_INT / 3);
1754 print_octal (low, HOST_BITS_PER_WIDE_INT / 3);
1756 else
1758 unsigned HOST_WIDE_INT beg = high >> excess;
1759 unsigned HOST_WIDE_INT middle
1760 = ((high & (((HOST_WIDE_INT) 1 << excess) - 1)) << (3 - excess)
1761 | (low >> (HOST_BITS_PER_WIDE_INT / 3 * 3)));
1762 unsigned HOST_WIDE_INT end
1763 = low & (((unsigned HOST_WIDE_INT) 1
1764 << (HOST_BITS_PER_WIDE_INT / 3 * 3))
1765 - 1);
1767 fprintf (asmfile, "%o%01o", (int) beg, (int) middle);
1768 CHARS (2);
1769 print_octal (end, HOST_BITS_PER_WIDE_INT / 3);
1773 static void
1774 print_octal (value, digits)
1775 unsigned HOST_WIDE_INT value;
1776 int digits;
1778 int i;
1780 for (i = digits - 1; i >= 0; i--)
1781 fprintf (asmfile, "%01o", (int) ((value >> (3 * i)) & 7));
1783 CHARS (digits);
1786 /* Output C in decimal while adjusting the number of digits written. */
1788 static void
1789 print_wide_int (c)
1790 HOST_WIDE_INT c;
1792 int digs = 0;
1794 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, c);
1796 if (c < 0)
1797 digs++, c = -c;
1799 while (c > 0)
1800 c /= 10; digs++;
1802 CHARS (digs);
1805 /* Output the name of type TYPE, with no punctuation.
1806 Such names can be set up either by typedef declarations
1807 or by struct, enum and union tags. */
1809 static void
1810 dbxout_type_name (type)
1811 tree type;
1813 tree t;
1814 if (TYPE_NAME (type) == 0)
1815 abort ();
1816 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE)
1818 t = TYPE_NAME (type);
1820 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL)
1822 t = DECL_NAME (TYPE_NAME (type));
1824 else
1825 abort ();
1827 fprintf (asmfile, "%s", IDENTIFIER_POINTER (t));
1828 CHARS (IDENTIFIER_LENGTH (t));
1831 /* Output a .stabs for the symbol defined by DECL,
1832 which must be a ..._DECL node in the normal namespace.
1833 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL.
1834 LOCAL is nonzero if the scope is less than the entire file.
1835 Return 1 if a stabs might have been emitted. */
1838 dbxout_symbol (decl, local)
1839 tree decl;
1840 int local ATTRIBUTE_UNUSED;
1842 tree type = TREE_TYPE (decl);
1843 tree context = NULL_TREE;
1844 int result = 0;
1846 /* Cast avoids warning in old compilers. */
1847 current_sym_code = (STAB_CODE_TYPE) 0;
1848 current_sym_value = 0;
1849 current_sym_addr = 0;
1851 /* Ignore nameless syms, but don't ignore type tags. */
1853 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL)
1854 || DECL_IGNORED_P (decl))
1855 return 0;
1857 dbxout_prepare_symbol (decl);
1859 /* The output will always start with the symbol name,
1860 so always count that in the length-output-so-far. */
1862 if (DECL_NAME (decl) != 0)
1863 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (decl));
1865 switch (TREE_CODE (decl))
1867 case CONST_DECL:
1868 /* Enum values are defined by defining the enum type. */
1869 break;
1871 case FUNCTION_DECL:
1872 if (DECL_RTL (decl) == 0)
1873 return 0;
1874 if (DECL_EXTERNAL (decl))
1875 break;
1876 /* Don't mention a nested function under its parent. */
1877 context = decl_function_context (decl);
1878 if (context == current_function_decl)
1879 break;
1880 if (GET_CODE (DECL_RTL (decl)) != MEM
1881 || GET_CODE (XEXP (DECL_RTL (decl), 0)) != SYMBOL_REF)
1882 break;
1883 FORCE_TEXT;
1885 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
1886 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1887 TREE_PUBLIC (decl) ? 'F' : 'f');
1888 result = 1;
1890 current_sym_code = N_FUN;
1891 current_sym_addr = XEXP (DECL_RTL (decl), 0);
1893 if (TREE_TYPE (type))
1894 dbxout_type (TREE_TYPE (type), 0);
1895 else
1896 dbxout_type (void_type_node, 0);
1898 /* For a nested function, when that function is compiled,
1899 mention the containing function name
1900 as well as (since dbx wants it) our own assembler-name. */
1901 if (context != 0)
1902 fprintf (asmfile, ",%s,%s",
1903 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl)),
1904 IDENTIFIER_POINTER (DECL_NAME (context)));
1906 dbxout_finish_symbol (decl);
1907 break;
1909 case TYPE_DECL:
1910 #if 0
1911 /* This seems all wrong. Outputting most kinds of types gives no name
1912 at all. A true definition gives no name; a cross-ref for a
1913 structure can give the tag name, but not a type name.
1914 It seems that no typedef name is defined by outputting a type. */
1916 /* If this typedef name was defined by outputting the type,
1917 don't duplicate it. */
1918 if (typevec[TYPE_SYMTAB_ADDRESS (type)].status == TYPE_DEFINED
1919 && TYPE_NAME (TREE_TYPE (decl)) == decl)
1920 return 0;
1921 #endif
1922 /* Don't output the same typedef twice.
1923 And don't output what language-specific stuff doesn't want output. */
1924 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl))
1925 return 0;
1927 FORCE_TEXT;
1928 result = 1;
1930 int tag_needed = 1;
1931 int did_output = 0;
1933 if (DECL_NAME (decl))
1935 /* Nonzero means we must output a tag as well as a typedef. */
1936 tag_needed = 0;
1938 /* Handle the case of a C++ structure or union
1939 where the TYPE_NAME is a TYPE_DECL
1940 which gives both a typedef name and a tag. */
1941 /* dbx requires the tag first and the typedef second. */
1942 if ((TREE_CODE (type) == RECORD_TYPE
1943 || TREE_CODE (type) == UNION_TYPE
1944 || TREE_CODE (type) == QUAL_UNION_TYPE)
1945 && TYPE_NAME (type) == decl
1946 && !(use_gnu_debug_info_extensions && have_used_extensions)
1947 && !TREE_ASM_WRITTEN (TYPE_NAME (type))
1948 /* Distinguish the implicit typedefs of C++
1949 from explicit ones that might be found in C. */
1950 && DECL_ARTIFICIAL (decl)
1951 /* Do not generate a tag for records of variable size,
1952 since this type can not be properly described in the
1953 DBX format, and it confuses some tools such as objdump. */
1954 && host_integerp (TYPE_SIZE (type), 1))
1956 tree name = TYPE_NAME (type);
1957 if (TREE_CODE (name) == TYPE_DECL)
1958 name = DECL_NAME (name);
1960 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1961 current_sym_value = 0;
1962 current_sym_addr = 0;
1963 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
1965 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
1966 IDENTIFIER_POINTER (name));
1967 dbxout_type (type, 1);
1968 dbxout_finish_symbol (NULL_TREE);
1971 /* Output typedef name. */
1972 fprintf (asmfile, "%s\"%s:", ASM_STABS_OP,
1973 IDENTIFIER_POINTER (DECL_NAME (decl)));
1975 /* Short cut way to output a tag also. */
1976 if ((TREE_CODE (type) == RECORD_TYPE
1977 || TREE_CODE (type) == UNION_TYPE
1978 || TREE_CODE (type) == QUAL_UNION_TYPE)
1979 && TYPE_NAME (type) == decl
1980 /* Distinguish the implicit typedefs of C++
1981 from explicit ones that might be found in C. */
1982 && DECL_ARTIFICIAL (decl))
1984 if (use_gnu_debug_info_extensions && have_used_extensions)
1986 putc ('T', asmfile);
1987 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1;
1989 #if 0 /* Now we generate the tag for this case up above. */
1990 else
1991 tag_needed = 1;
1992 #endif
1995 putc ('t', asmfile);
1996 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
1998 dbxout_type (type, 1);
1999 dbxout_finish_symbol (decl);
2000 did_output = 1;
2003 /* Don't output a tag if this is an incomplete type. This prevents
2004 the sun4 Sun OS 4.x dbx from crashing. */
2006 if (tag_needed && TYPE_NAME (type) != 0
2007 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE
2008 || (DECL_NAME (TYPE_NAME (type)) != 0))
2009 && COMPLETE_TYPE_P (type)
2010 && !TREE_ASM_WRITTEN (TYPE_NAME (type)))
2012 /* For a TYPE_DECL with no name, but the type has a name,
2013 output a tag.
2014 This is what represents `struct foo' with no typedef. */
2015 /* In C++, the name of a type is the corresponding typedef.
2016 In C, it is an IDENTIFIER_NODE. */
2017 tree name = TYPE_NAME (type);
2018 if (TREE_CODE (name) == TYPE_DECL)
2019 name = DECL_NAME (name);
2021 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2022 current_sym_value = 0;
2023 current_sym_addr = 0;
2024 current_sym_nchars = 2 + IDENTIFIER_LENGTH (name);
2026 fprintf (asmfile, "%s\"%s:T", ASM_STABS_OP,
2027 IDENTIFIER_POINTER (name));
2028 dbxout_type (type, 1);
2029 dbxout_finish_symbol (NULL_TREE);
2030 did_output = 1;
2033 /* If an enum type has no name, it cannot be referred to,
2034 but we must output it anyway, since the enumeration constants
2035 can be referred to. */
2036 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE)
2038 current_sym_code = DBX_TYPE_DECL_STABS_CODE;
2039 current_sym_value = 0;
2040 current_sym_addr = 0;
2041 current_sym_nchars = 2;
2043 /* Some debuggers fail when given NULL names, so give this a
2044 harmless name of ` '. */
2045 fprintf (asmfile, "%s\" :T", ASM_STABS_OP);
2046 dbxout_type (type, 1);
2047 dbxout_finish_symbol (NULL_TREE);
2050 /* Prevent duplicate output of a typedef. */
2051 TREE_ASM_WRITTEN (decl) = 1;
2052 break;
2055 case PARM_DECL:
2056 /* Parm decls go in their own separate chains
2057 and are output by dbxout_reg_parms and dbxout_parms. */
2058 abort ();
2060 case RESULT_DECL:
2061 /* Named return value, treat like a VAR_DECL. */
2062 case VAR_DECL:
2063 if (! DECL_RTL_SET_P (decl))
2064 return 0;
2065 /* Don't mention a variable that is external.
2066 Let the file that defines it describe it. */
2067 if (DECL_EXTERNAL (decl))
2068 break;
2070 /* If the variable is really a constant
2071 and not written in memory, inform the debugger. */
2072 if (TREE_STATIC (decl) && TREE_READONLY (decl)
2073 && DECL_INITIAL (decl) != 0
2074 && host_integerp (DECL_INITIAL (decl), 0)
2075 && ! TREE_ASM_WRITTEN (decl)
2076 && (DECL_CONTEXT (decl) == NULL_TREE
2077 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK))
2079 if (TREE_PUBLIC (decl) == 0)
2081 /* The sun4 assembler does not grok this. */
2082 const char *name = IDENTIFIER_POINTER (DECL_NAME (decl));
2084 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE
2085 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE)
2087 HOST_WIDE_INT ival = tree_low_cst (DECL_INITIAL (decl), 0);
2088 #ifdef DBX_OUTPUT_CONSTANT_SYMBOL
2089 DBX_OUTPUT_CONSTANT_SYMBOL (asmfile, name, ival);
2090 #else
2091 fprintf (asmfile, "%s\"%s:c=i", ASM_STABS_OP, name);
2093 fprintf (asmfile, HOST_WIDE_INT_PRINT_DEC, ival);
2094 fprintf (asmfile, "\",0x%x,0,0,0\n", N_LSYM);
2095 #endif
2096 return 1;
2098 else if (TREE_CODE (TREE_TYPE (decl)) == REAL_TYPE)
2100 /* don't know how to do this yet. */
2102 break;
2104 /* else it is something we handle like a normal variable. */
2107 SET_DECL_RTL (decl, eliminate_regs (DECL_RTL (decl), 0, NULL_RTX));
2108 #ifdef LEAF_REG_REMAP
2109 if (current_function_uses_only_leaf_regs)
2110 leaf_renumber_regs_insn (DECL_RTL (decl));
2111 #endif
2113 result = dbxout_symbol_location (decl, type, 0, DECL_RTL (decl));
2114 break;
2116 default:
2117 break;
2119 return result;
2122 /* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL.
2123 Add SUFFIX to its name, if SUFFIX is not 0.
2124 Describe the variable as residing in HOME
2125 (usually HOME is DECL_RTL (DECL), but not always).
2126 Returns 1 if the stab was really emitted. */
2128 static int
2129 dbxout_symbol_location (decl, type, suffix, home)
2130 tree decl, type;
2131 const char *suffix;
2132 rtx home;
2134 int letter = 0;
2135 int regno = -1;
2137 /* Don't mention a variable at all
2138 if it was completely optimized into nothingness.
2140 If the decl was from an inline function, then its rtl
2141 is not identically the rtl that was used in this
2142 particular compilation. */
2143 if (GET_CODE (home) == SUBREG)
2145 rtx value = home;
2147 while (GET_CODE (value) == SUBREG)
2148 value = SUBREG_REG (value);
2149 if (GET_CODE (value) == REG)
2151 if (REGNO (value) >= FIRST_PSEUDO_REGISTER)
2152 return 0;
2154 home = alter_subreg (&home);
2156 if (GET_CODE (home) == REG)
2158 regno = REGNO (home);
2159 if (regno >= FIRST_PSEUDO_REGISTER)
2160 return 0;
2163 /* The kind-of-variable letter depends on where
2164 the variable is and on the scope of its name:
2165 G and N_GSYM for static storage and global scope,
2166 S for static storage and file scope,
2167 V for static storage and local scope,
2168 for those two, use N_LCSYM if data is in bss segment,
2169 N_STSYM if in data segment, N_FUN otherwise.
2170 (We used N_FUN originally, then changed to N_STSYM
2171 to please GDB. However, it seems that confused ld.
2172 Now GDB has been fixed to like N_FUN, says Kingdon.)
2173 no letter at all, and N_LSYM, for auto variable,
2174 r and N_RSYM for register variable. */
2176 if (GET_CODE (home) == MEM
2177 && GET_CODE (XEXP (home, 0)) == SYMBOL_REF)
2179 if (TREE_PUBLIC (decl))
2181 letter = 'G';
2182 current_sym_code = N_GSYM;
2184 else
2186 current_sym_addr = XEXP (home, 0);
2188 letter = decl_function_context (decl) ? 'V' : 'S';
2190 /* This should be the same condition as in assemble_variable, but
2191 we don't have access to dont_output_data here. So, instead,
2192 we rely on the fact that error_mark_node initializers always
2193 end up in bss for C++ and never end up in bss for C. */
2194 if (DECL_INITIAL (decl) == 0
2195 || (!strcmp (lang_hooks.name, "GNU C++")
2196 && DECL_INITIAL (decl) == error_mark_node))
2197 current_sym_code = N_LCSYM;
2198 else if (DECL_IN_TEXT_SECTION (decl))
2199 /* This is not quite right, but it's the closest
2200 of all the codes that Unix defines. */
2201 current_sym_code = DBX_STATIC_CONST_VAR_CODE;
2202 else
2204 /* Some ports can transform a symbol ref into a label ref,
2205 because the symbol ref is too far away and has to be
2206 dumped into a constant pool. Alternatively, the symbol
2207 in the constant pool might be referenced by a different
2208 symbol. */
2209 if (GET_CODE (current_sym_addr) == SYMBOL_REF
2210 && CONSTANT_POOL_ADDRESS_P (current_sym_addr))
2212 rtx tmp = get_pool_constant (current_sym_addr);
2214 if (GET_CODE (tmp) == SYMBOL_REF
2215 || GET_CODE (tmp) == LABEL_REF)
2216 current_sym_addr = tmp;
2219 /* Ultrix `as' seems to need this. */
2220 #ifdef DBX_STATIC_STAB_DATA_SECTION
2221 data_section ();
2222 #endif
2223 current_sym_code = N_STSYM;
2227 else if (regno >= 0)
2229 letter = 'r';
2230 current_sym_code = N_RSYM;
2231 current_sym_value = DBX_REGISTER_NUMBER (regno);
2233 else if (GET_CODE (home) == MEM
2234 && (GET_CODE (XEXP (home, 0)) == MEM
2235 || (GET_CODE (XEXP (home, 0)) == REG
2236 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM
2237 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM
2238 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2239 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM
2240 #endif
2242 /* If the value is indirect by memory or by a register
2243 that isn't the frame pointer
2244 then it means the object is variable-sized and address through
2245 that register or stack slot. DBX has no way to represent this
2246 so all we can do is output the variable as a pointer.
2247 If it's not a parameter, ignore it.
2248 (VAR_DECLs like this can be made by integrate.c.) */
2250 if (GET_CODE (XEXP (home, 0)) == REG)
2252 letter = 'r';
2253 current_sym_code = N_RSYM;
2254 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER)
2255 return 0;
2256 current_sym_value = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0)));
2258 else
2260 current_sym_code = N_LSYM;
2261 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))).
2262 We want the value of that CONST_INT. */
2263 current_sym_value
2264 = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0));
2267 /* Effectively do build_pointer_type, but don't cache this type,
2268 since it might be temporary whereas the type it points to
2269 might have been saved for inlining. */
2270 /* Don't use REFERENCE_TYPE because dbx can't handle that. */
2271 type = make_node (POINTER_TYPE);
2272 TREE_TYPE (type) = TREE_TYPE (decl);
2274 else if (GET_CODE (home) == MEM
2275 && GET_CODE (XEXP (home, 0)) == REG)
2277 current_sym_code = N_LSYM;
2278 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2280 else if (GET_CODE (home) == MEM
2281 && GET_CODE (XEXP (home, 0)) == PLUS
2282 && GET_CODE (XEXP (XEXP (home, 0), 1)) == CONST_INT)
2284 current_sym_code = N_LSYM;
2285 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...)))
2286 We want the value of that CONST_INT. */
2287 current_sym_value = DEBUGGER_AUTO_OFFSET (XEXP (home, 0));
2289 else if (GET_CODE (home) == MEM
2290 && GET_CODE (XEXP (home, 0)) == CONST)
2292 /* Handle an obscure case which can arise when optimizing and
2293 when there are few available registers. (This is *always*
2294 the case for i386/i486 targets). The RTL looks like
2295 (MEM (CONST ...)) even though this variable is a local `auto'
2296 or a local `register' variable. In effect, what has happened
2297 is that the reload pass has seen that all assignments and
2298 references for one such a local variable can be replaced by
2299 equivalent assignments and references to some static storage
2300 variable, thereby avoiding the need for a register. In such
2301 cases we're forced to lie to debuggers and tell them that
2302 this variable was itself `static'. */
2303 current_sym_code = N_LCSYM;
2304 letter = 'V';
2305 current_sym_addr = XEXP (XEXP (home, 0), 0);
2307 else if (GET_CODE (home) == CONCAT)
2309 tree subtype;
2311 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE,
2312 for example), then there is no easy way to figure out
2313 what SUBTYPE should be. So, we give up. */
2314 if (TREE_CODE (type) != COMPLEX_TYPE)
2315 return 0;
2317 subtype = TREE_TYPE (type);
2319 /* If the variable's storage is in two parts,
2320 output each as a separate stab with a modified name. */
2321 if (WORDS_BIG_ENDIAN)
2322 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0));
2323 else
2324 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0));
2326 /* Cast avoids warning in old compilers. */
2327 current_sym_code = (STAB_CODE_TYPE) 0;
2328 current_sym_value = 0;
2329 current_sym_addr = 0;
2330 dbxout_prepare_symbol (decl);
2332 if (WORDS_BIG_ENDIAN)
2333 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1));
2334 else
2335 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1));
2336 return 1;
2338 else
2339 /* Address might be a MEM, when DECL is a variable-sized object.
2340 Or it might be const0_rtx, meaning previous passes
2341 want us to ignore this variable. */
2342 return 0;
2344 /* Ok, start a symtab entry and output the variable name. */
2345 FORCE_TEXT;
2347 #ifdef DBX_STATIC_BLOCK_START
2348 DBX_STATIC_BLOCK_START (asmfile, current_sym_code);
2349 #endif
2351 dbxout_symbol_name (decl, suffix, letter);
2352 dbxout_type (type, 0);
2353 dbxout_finish_symbol (decl);
2355 #ifdef DBX_STATIC_BLOCK_END
2356 DBX_STATIC_BLOCK_END (asmfile, current_sym_code);
2357 #endif
2358 return 1;
2361 /* Output the symbol name of DECL for a stabs, with suffix SUFFIX.
2362 Then output LETTER to indicate the kind of location the symbol has. */
2364 static void
2365 dbxout_symbol_name (decl, suffix, letter)
2366 tree decl;
2367 const char *suffix;
2368 int letter;
2370 const char *name;
2372 if (DECL_CONTEXT (decl) && TYPE_P (DECL_CONTEXT (decl)))
2373 /* One slight hitch: if this is a VAR_DECL which is a static
2374 class member, we must put out the mangled name instead of the
2375 DECL_NAME. Note also that static member (variable) names DO NOT begin
2376 with underscores in .stabs directives. */
2377 name = IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl));
2378 else
2379 /* ...but if we're function-local, we don't want to include the junk
2380 added by ASM_FORMAT_PRIVATE_NAME. */
2381 name = IDENTIFIER_POINTER (DECL_NAME (decl));
2383 if (name == 0)
2384 name = "(anon)";
2385 fprintf (asmfile, "%s\"%s%s:", ASM_STABS_OP, name,
2386 (suffix ? suffix : ""));
2388 if (letter)
2389 putc (letter, asmfile);
2392 static void
2393 dbxout_prepare_symbol (decl)
2394 tree decl ATTRIBUTE_UNUSED;
2396 #ifdef WINNING_GDB
2397 const char *filename = DECL_SOURCE_FILE (decl);
2399 dbxout_source_file (asmfile, filename);
2400 #endif
2403 static void
2404 dbxout_finish_symbol (sym)
2405 tree sym;
2407 #ifdef DBX_FINISH_SYMBOL
2408 DBX_FINISH_SYMBOL (sym);
2409 #else
2410 int line = 0;
2411 if (use_gnu_debug_info_extensions && sym != 0)
2412 line = DECL_SOURCE_LINE (sym);
2414 fprintf (asmfile, "\",%d,0,%d,", current_sym_code, line);
2415 if (current_sym_addr)
2416 output_addr_const (asmfile, current_sym_addr);
2417 else
2418 fprintf (asmfile, "%d", current_sym_value);
2419 putc ('\n', asmfile);
2420 #endif
2423 /* Output definitions of all the decls in a chain. Return non-zero if
2424 anything was output */
2427 dbxout_syms (syms)
2428 tree syms;
2430 int result = 0;
2431 while (syms)
2433 result += dbxout_symbol (syms, 1);
2434 syms = TREE_CHAIN (syms);
2436 return result;
2439 /* The following two functions output definitions of function parameters.
2440 Each parameter gets a definition locating it in the parameter list.
2441 Each parameter that is a register variable gets a second definition
2442 locating it in the register.
2444 Printing or argument lists in gdb uses the definitions that
2445 locate in the parameter list. But reference to the variable in
2446 expressions uses preferentially the definition as a register. */
2448 /* Output definitions, referring to storage in the parmlist,
2449 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */
2451 void
2452 dbxout_parms (parms)
2453 tree parms;
2455 for (; parms; parms = TREE_CHAIN (parms))
2456 if (DECL_NAME (parms) && TREE_TYPE (parms) != error_mark_node)
2458 dbxout_prepare_symbol (parms);
2460 /* Perform any necessary register eliminations on the parameter's rtl,
2461 so that the debugging output will be accurate. */
2462 DECL_INCOMING_RTL (parms)
2463 = eliminate_regs (DECL_INCOMING_RTL (parms), 0, NULL_RTX);
2464 SET_DECL_RTL (parms, eliminate_regs (DECL_RTL (parms), 0, NULL_RTX));
2465 #ifdef LEAF_REG_REMAP
2466 if (current_function_uses_only_leaf_regs)
2468 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms));
2469 leaf_renumber_regs_insn (DECL_RTL (parms));
2471 #endif
2473 if (PARM_PASSED_IN_MEMORY (parms))
2475 rtx addr = XEXP (DECL_INCOMING_RTL (parms), 0);
2477 /* ??? Here we assume that the parm address is indexed
2478 off the frame pointer or arg pointer.
2479 If that is not true, we produce meaningless results,
2480 but do not crash. */
2481 if (GET_CODE (addr) == PLUS
2482 && GET_CODE (XEXP (addr, 1)) == CONST_INT)
2483 current_sym_value = INTVAL (XEXP (addr, 1));
2484 else
2485 current_sym_value = 0;
2487 current_sym_code = N_PSYM;
2488 current_sym_addr = 0;
2490 FORCE_TEXT;
2491 if (DECL_NAME (parms))
2493 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2495 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2496 IDENTIFIER_POINTER (DECL_NAME (parms)),
2497 DBX_MEMPARM_STABS_LETTER);
2499 else
2501 current_sym_nchars = 8;
2502 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2503 DBX_MEMPARM_STABS_LETTER);
2506 /* It is quite tempting to use:
2508 dbxout_type (TREE_TYPE (parms), 0);
2510 as the next statement, rather than using DECL_ARG_TYPE(), so
2511 that gcc reports the actual type of the parameter, rather
2512 than the promoted type. This certainly makes GDB's life
2513 easier, at least for some ports. The change is a bad idea
2514 however, since GDB expects to be able access the type without
2515 performing any conversions. So for example, if we were
2516 passing a float to an unprototyped function, gcc will store a
2517 double on the stack, but if we emit a stab saying the type is a
2518 float, then gdb will only read in a single value, and this will
2519 produce an erroneous value. */
2520 dbxout_type (DECL_ARG_TYPE (parms), 0);
2521 current_sym_value = DEBUGGER_ARG_OFFSET (current_sym_value, addr);
2522 dbxout_finish_symbol (parms);
2524 else if (GET_CODE (DECL_RTL (parms)) == REG)
2526 rtx best_rtl;
2527 char regparm_letter;
2528 tree parm_type;
2529 /* Parm passed in registers and lives in registers or nowhere. */
2531 current_sym_code = DBX_REGPARM_STABS_CODE;
2532 regparm_letter = DBX_REGPARM_STABS_LETTER;
2533 current_sym_addr = 0;
2535 /* If parm lives in a register, use that register;
2536 pretend the parm was passed there. It would be more consistent
2537 to describe the register where the parm was passed,
2538 but in practice that register usually holds something else.
2540 If we use DECL_RTL, then we must use the declared type of
2541 the variable, not the type that it arrived in. */
2542 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2544 best_rtl = DECL_RTL (parms);
2545 parm_type = TREE_TYPE (parms);
2547 /* If the parm lives nowhere, use the register where it was
2548 passed. It is also better to use the declared type here. */
2549 else
2551 best_rtl = DECL_INCOMING_RTL (parms);
2552 parm_type = TREE_TYPE (parms);
2554 current_sym_value = DBX_REGISTER_NUMBER (REGNO (best_rtl));
2556 FORCE_TEXT;
2557 if (DECL_NAME (parms))
2559 current_sym_nchars = 2 + IDENTIFIER_LENGTH (DECL_NAME (parms));
2560 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2561 IDENTIFIER_POINTER (DECL_NAME (parms)),
2562 regparm_letter);
2564 else
2566 current_sym_nchars = 8;
2567 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2568 regparm_letter);
2571 dbxout_type (parm_type, 0);
2572 dbxout_finish_symbol (parms);
2574 else if (GET_CODE (DECL_RTL (parms)) == MEM
2575 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG
2576 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM
2577 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM
2578 #if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM
2579 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM
2580 #endif
2583 /* Parm was passed via invisible reference.
2584 That is, its address was passed in a register.
2585 Output it as if it lived in that register.
2586 The debugger will know from the type
2587 that it was actually passed by invisible reference. */
2589 char regparm_letter;
2590 /* Parm passed in registers and lives in registers or nowhere. */
2592 current_sym_code = DBX_REGPARM_STABS_CODE;
2593 if (use_gnu_debug_info_extensions)
2594 regparm_letter = GDB_INV_REF_REGPARM_STABS_LETTER;
2595 else
2596 regparm_letter = DBX_REGPARM_STABS_LETTER;
2598 /* DECL_RTL looks like (MEM (REG...). Get the register number.
2599 If it is an unallocated pseudo-reg, then use the register where
2600 it was passed instead. */
2601 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER)
2602 current_sym_value = REGNO (XEXP (DECL_RTL (parms), 0));
2603 else
2604 current_sym_value = REGNO (DECL_INCOMING_RTL (parms));
2606 current_sym_addr = 0;
2608 FORCE_TEXT;
2609 if (DECL_NAME (parms))
2611 current_sym_nchars
2612 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2614 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2615 IDENTIFIER_POINTER (DECL_NAME (parms)),
2616 regparm_letter);
2618 else
2620 current_sym_nchars = 8;
2621 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2622 regparm_letter);
2625 dbxout_type (TREE_TYPE (parms), 0);
2626 dbxout_finish_symbol (parms);
2628 else if (GET_CODE (DECL_RTL (parms)) == MEM
2629 && GET_CODE (XEXP (DECL_RTL (parms), 0)) == MEM)
2631 /* Parm was passed via invisible reference, with the reference
2632 living on the stack. DECL_RTL looks like
2633 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it
2634 could look like (MEM (MEM (REG))). */
2635 const char *const decl_name = (DECL_NAME (parms)
2636 ? IDENTIFIER_POINTER (DECL_NAME (parms))
2637 : "(anon)");
2638 if (GET_CODE (XEXP (XEXP (DECL_RTL (parms), 0), 0)) == REG)
2639 current_sym_value = 0;
2640 else
2641 current_sym_value
2642 = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1));
2643 current_sym_addr = 0;
2645 FORCE_TEXT;
2646 fprintf (asmfile, "%s\"%s:v", ASM_STABS_OP, decl_name);
2648 current_sym_value
2649 = DEBUGGER_ARG_OFFSET (current_sym_value,
2650 XEXP (XEXP (DECL_RTL (parms), 0), 0));
2651 dbxout_type (TREE_TYPE (parms), 0);
2652 dbxout_finish_symbol (parms);
2654 else if (GET_CODE (DECL_RTL (parms)) == MEM
2655 && XEXP (DECL_RTL (parms), 0) != const0_rtx
2656 /* ??? A constant address for a parm can happen
2657 when the reg it lives in is equiv to a constant in memory.
2658 Should make this not happen, after 2.4. */
2659 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0)))
2661 /* Parm was passed in registers but lives on the stack. */
2663 current_sym_code = N_PSYM;
2664 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))),
2665 in which case we want the value of that CONST_INT,
2666 or (MEM (REG ...)),
2667 in which case we use a value of zero. */
2668 if (GET_CODE (XEXP (DECL_RTL (parms), 0)) == REG)
2669 current_sym_value = 0;
2670 else
2671 current_sym_value
2672 = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1));
2674 current_sym_addr = 0;
2676 /* Make a big endian correction if the mode of the type of the
2677 parameter is not the same as the mode of the rtl. */
2678 if (BYTES_BIG_ENDIAN
2679 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms))
2680 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD)
2682 current_sym_value +=
2683 GET_MODE_SIZE (GET_MODE (DECL_RTL (parms)))
2684 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)));
2687 FORCE_TEXT;
2688 if (DECL_NAME (parms))
2690 current_sym_nchars
2691 = 2 + strlen (IDENTIFIER_POINTER (DECL_NAME (parms)));
2693 fprintf (asmfile, "%s\"%s:%c", ASM_STABS_OP,
2694 IDENTIFIER_POINTER (DECL_NAME (parms)),
2695 DBX_MEMPARM_STABS_LETTER);
2697 else
2699 current_sym_nchars = 8;
2700 fprintf (asmfile, "%s\"(anon):%c", ASM_STABS_OP,
2701 DBX_MEMPARM_STABS_LETTER);
2704 current_sym_value
2705 = DEBUGGER_ARG_OFFSET (current_sym_value,
2706 XEXP (DECL_RTL (parms), 0));
2707 dbxout_type (TREE_TYPE (parms), 0);
2708 dbxout_finish_symbol (parms);
2713 /* Output definitions for the places where parms live during the function,
2714 when different from where they were passed, when the parms were passed
2715 in memory.
2717 It is not useful to do this for parms passed in registers
2718 that live during the function in different registers, because it is
2719 impossible to look in the passed register for the passed value,
2720 so we use the within-the-function register to begin with.
2722 PARMS is a chain of PARM_DECL nodes. */
2724 void
2725 dbxout_reg_parms (parms)
2726 tree parms;
2728 for (; parms; parms = TREE_CHAIN (parms))
2729 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms))
2731 dbxout_prepare_symbol (parms);
2733 /* Report parms that live in registers during the function
2734 but were passed in memory. */
2735 if (GET_CODE (DECL_RTL (parms)) == REG
2736 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER)
2737 dbxout_symbol_location (parms, TREE_TYPE (parms),
2738 0, DECL_RTL (parms));
2739 else if (GET_CODE (DECL_RTL (parms)) == CONCAT)
2740 dbxout_symbol_location (parms, TREE_TYPE (parms),
2741 0, DECL_RTL (parms));
2742 /* Report parms that live in memory but not where they were passed. */
2743 else if (GET_CODE (DECL_RTL (parms)) == MEM
2744 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms)))
2745 dbxout_symbol_location (parms, TREE_TYPE (parms),
2746 0, DECL_RTL (parms));
2750 /* Given a chain of ..._TYPE nodes (as come in a parameter list),
2751 output definitions of those names, in raw form */
2753 static void
2754 dbxout_args (args)
2755 tree args;
2757 while (args)
2759 putc (',', asmfile);
2760 dbxout_type (TREE_VALUE (args), 0);
2761 CHARS (1);
2762 args = TREE_CHAIN (args);
2766 /* Output everything about a symbol block (a BLOCK node
2767 that represents a scope level),
2768 including recursive output of contained blocks.
2770 BLOCK is the BLOCK node.
2771 DEPTH is its depth within containing symbol blocks.
2772 ARGS is usually zero; but for the outermost block of the
2773 body of a function, it is a chain of PARM_DECLs for the function parameters.
2774 We output definitions of all the register parms
2775 as if they were local variables of that block.
2777 If -g1 was used, we count blocks just the same, but output nothing
2778 except for the outermost block.
2780 Actually, BLOCK may be several blocks chained together.
2781 We handle them all in sequence. */
2783 static void
2784 dbxout_block (block, depth, args)
2785 tree block;
2786 int depth;
2787 tree args;
2789 int blocknum = -1;
2791 #if DBX_BLOCKS_FUNCTION_RELATIVE
2792 const char *begin_label;
2793 if (current_function_func_begin_label != NULL_TREE)
2794 begin_label = IDENTIFIER_POINTER (current_function_func_begin_label);
2795 else
2796 begin_label = XSTR (XEXP (DECL_RTL (current_function_decl), 0), 0);
2797 #endif
2799 while (block)
2801 /* Ignore blocks never expanded or otherwise marked as real. */
2802 if (TREE_USED (block) && TREE_ASM_WRITTEN (block))
2804 int did_output;
2806 #ifdef DBX_LBRAC_FIRST
2807 did_output = 1;
2808 #else
2809 /* In dbx format, the syms of a block come before the N_LBRAC.
2810 If nothing is output, we don't need the N_LBRAC, either. */
2811 did_output = 0;
2812 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2813 did_output = dbxout_syms (BLOCK_VARS (block));
2814 if (args)
2815 dbxout_reg_parms (args);
2816 #endif
2818 /* Now output an N_LBRAC symbol to represent the beginning of
2819 the block. Use the block's tree-walk order to generate
2820 the assembler symbols LBBn and LBEn
2821 that final will define around the code in this block. */
2822 if (depth > 0 && did_output)
2824 char buf[20];
2825 blocknum = BLOCK_NUMBER (block);
2826 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum);
2828 if (BLOCK_HANDLER_BLOCK (block))
2830 /* A catch block. Must precede N_LBRAC. */
2831 tree decl = BLOCK_VARS (block);
2832 while (decl)
2834 #ifdef DBX_OUTPUT_CATCH
2835 DBX_OUTPUT_CATCH (asmfile, decl, buf);
2836 #else
2837 fprintf (asmfile, "%s\"%s:C1\",%d,0,0,", ASM_STABS_OP,
2838 IDENTIFIER_POINTER (DECL_NAME (decl)), N_CATCH);
2839 assemble_name (asmfile, buf);
2840 fprintf (asmfile, "\n");
2841 #endif
2842 decl = TREE_CHAIN (decl);
2846 #ifdef DBX_OUTPUT_LBRAC
2847 DBX_OUTPUT_LBRAC (asmfile, buf);
2848 #else
2849 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_LBRAC);
2850 assemble_name (asmfile, buf);
2851 #if DBX_BLOCKS_FUNCTION_RELATIVE
2852 putc ('-', asmfile);
2853 assemble_name (asmfile, begin_label);
2854 #endif
2855 fprintf (asmfile, "\n");
2856 #endif
2859 #ifdef DBX_LBRAC_FIRST
2860 /* On some weird machines, the syms of a block
2861 come after the N_LBRAC. */
2862 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0)
2863 dbxout_syms (BLOCK_VARS (block));
2864 if (args)
2865 dbxout_reg_parms (args);
2866 #endif
2868 /* Output the subblocks. */
2869 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE);
2871 /* Refer to the marker for the end of the block. */
2872 if (depth > 0 && did_output)
2874 char buf[20];
2875 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum);
2876 #ifdef DBX_OUTPUT_RBRAC
2877 DBX_OUTPUT_RBRAC (asmfile, buf);
2878 #else
2879 fprintf (asmfile, "%s%d,0,0,", ASM_STABN_OP, N_RBRAC);
2880 assemble_name (asmfile, buf);
2881 #if DBX_BLOCKS_FUNCTION_RELATIVE
2882 putc ('-', asmfile);
2883 assemble_name (asmfile, begin_label);
2884 #endif
2885 fprintf (asmfile, "\n");
2886 #endif
2889 block = BLOCK_CHAIN (block);
2893 /* Output the information about a function and its arguments and result.
2894 Usually this follows the function's code,
2895 but on some systems, it comes before. */
2897 #if defined (DBX_DEBUGGING_INFO)
2898 static void
2899 dbxout_begin_function (decl)
2900 tree decl;
2902 dbxout_symbol (decl, 0);
2903 dbxout_parms (DECL_ARGUMENTS (decl));
2904 if (DECL_NAME (DECL_RESULT (decl)) != 0)
2905 dbxout_symbol (DECL_RESULT (decl), 1);
2907 #endif /* DBX_DEBUGGING_INFO */
2909 #endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */