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