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