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