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