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