1/* Output dbx-format symbol table information from GNU compiler. 2 Copyright (C) 1987-2015 Free Software Foundation, Inc. 3 4This file is part of GCC. 5 6GCC is free software; you can redistribute it and/or modify it under 7the terms of the GNU General Public License as published by the Free 8Software Foundation; either version 3, or (at your option) any later 9version. 10 11GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12WARRANTY; without even the implied warranty of MERCHANTABILITY or 13FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14for more details. 15 16You should have received a copy of the GNU General Public License 17along with GCC; see the file COPYING3. If not see 18<http://www.gnu.org/licenses/>. */ 19 20 21/* Output dbx-format symbol table data. 22 This consists of many symbol table entries, each of them 23 a .stabs assembler pseudo-op with four operands: 24 a "name" which is really a description of one symbol and its type, 25 a "code", which is a symbol defined in stab.h whose name starts with N_, 26 an unused operand always 0, 27 and a "value" which is an address or an offset. 28 The name is enclosed in doublequote characters. 29 30 Each function, variable, typedef, and structure tag 31 has a symbol table entry to define it. 32 The beginning and end of each level of name scoping within 33 a function are also marked by special symbol table entries. 34 35 The "name" consists of the symbol name, a colon, a kind-of-symbol letter, 36 and a data type number. The data type number may be followed by 37 "=" and a type definition; normally this will happen the first time 38 the type number is mentioned. The type definition may refer to 39 other types by number, and those type numbers may be followed 40 by "=" and nested definitions. 41 42 This can make the "name" quite long. 43 When a name is more than 80 characters, we split the .stabs pseudo-op 44 into two .stabs pseudo-ops, both sharing the same "code" and "value". 45 The first one is marked as continued with a double-backslash at the 46 end of its "name". 47 48 The kind-of-symbol letter distinguished function names from global 49 variables from file-scope variables from parameters from auto 50 variables in memory from typedef names from register variables. 51 See `dbxout_symbol'. 52 53 The "code" is mostly redundant with the kind-of-symbol letter 54 that goes in the "name", but not entirely: for symbols located 55 in static storage, the "code" says which segment the address is in, 56 which controls how it is relocated. 57 58 The "value" for a symbol in static storage 59 is the core address of the symbol (actually, the assembler 60 label for the symbol). For a symbol located in a stack slot 61 it is the stack offset; for one in a register, the register number. 62 For a typedef symbol, it is zero. 63 64 If DEBUG_SYMS_TEXT is defined, all debugging symbols must be 65 output while in the text section. 66 67 For more on data type definitions, see `dbxout_type'. */ 68 69#include "config.h" 70#include "system.h" 71#include "coretypes.h" 72#include "tm.h" 73#include "hash-set.h" 74#include "machmode.h" 75#include "vec.h" 76#include "double-int.h" 77#include "input.h" 78#include "alias.h" 79#include "symtab.h" 80#include "wide-int.h" 81#include "inchash.h" 82#include "tree.h" 83#include "fold-const.h" 84#include "varasm.h" 85#include "stor-layout.h" 86#include "rtl.h" 87#include "flags.h" 88#include "regs.h" 89#include "insn-config.h" 90#include "reload.h" 91#include "output.h" 92#include "dbxout.h" 93#include "diagnostic-core.h" 94#include "toplev.h" 95#include "tm_p.h" 96#include "ggc.h" 97#include "debug.h" 98#include "hashtab.h" 99#include "hard-reg-set.h" 100#include "function.h" 101#include "target.h" 102#include "common/common-target.h" 103#include "langhooks.h" 104#include "obstack.h" 105#include "statistics.h" 106#include "real.h" 107#include "fixed-value.h" 108#include "expmed.h" 109#include "dojump.h" 110#include "explow.h" 111#include "calls.h" 112#include "emit-rtl.h" 113#include "stmt.h" 114#include "expr.h" 115#include "hash-map.h" 116#include "is-a.h" 117#include "plugin-api.h" 118#include "ipa-ref.h" 119#include "cgraph.h" 120#include "stringpool.h" 121 122#ifdef XCOFF_DEBUGGING_INFO 123#include "xcoffout.h" 124#endif 125 126#ifndef ASM_STABS_OP 127# ifdef XCOFF_DEBUGGING_INFO 128# define ASM_STABS_OP "\t.stabx\t" 129# else 130# define ASM_STABS_OP "\t.stabs\t" 131# endif 132#endif 133 134#ifndef ASM_STABN_OP 135#define ASM_STABN_OP "\t.stabn\t" 136#endif 137 138#ifndef ASM_STABD_OP 139#define ASM_STABD_OP "\t.stabd\t" 140#endif 141 142#ifndef DBX_TYPE_DECL_STABS_CODE 143#define DBX_TYPE_DECL_STABS_CODE N_LSYM 144#endif 145 146#ifndef DBX_STATIC_CONST_VAR_CODE 147#define DBX_STATIC_CONST_VAR_CODE N_FUN 148#endif 149 150#ifndef DBX_REGPARM_STABS_CODE 151#define DBX_REGPARM_STABS_CODE N_RSYM 152#endif 153 154#ifndef DBX_REGPARM_STABS_LETTER 155#define DBX_REGPARM_STABS_LETTER 'P' 156#endif 157 158#ifndef NO_DBX_FUNCTION_END 159#define NO_DBX_FUNCTION_END 0 160#endif 161 162#ifndef NO_DBX_BNSYM_ENSYM 163#define NO_DBX_BNSYM_ENSYM 0 164#endif 165 166#ifndef NO_DBX_MAIN_SOURCE_DIRECTORY 167#define NO_DBX_MAIN_SOURCE_DIRECTORY 0 168#endif 169 170#ifndef DBX_BLOCKS_FUNCTION_RELATIVE 171#define DBX_BLOCKS_FUNCTION_RELATIVE 0 172#endif 173 174#ifndef DBX_LINES_FUNCTION_RELATIVE 175#define DBX_LINES_FUNCTION_RELATIVE 0 176#endif 177 178#ifndef DBX_CONTIN_LENGTH 179#define DBX_CONTIN_LENGTH 80 180#endif 181 182#ifndef DBX_CONTIN_CHAR 183#define DBX_CONTIN_CHAR '\\' 184#endif 185 186enum typestatus {TYPE_UNSEEN, TYPE_XREF, TYPE_DEFINED}; 187 188/* Structure recording information about a C data type. 189 The status element says whether we have yet output 190 the definition of the type. TYPE_XREF says we have 191 output it as a cross-reference only. 192 The file_number and type_number elements are used if DBX_USE_BINCL 193 is defined. */ 194 195struct GTY(()) typeinfo { 196 enum typestatus status; 197 int file_number; 198 int type_number; 199}; 200 201/* Vector recording information about C data types. 202 When we first notice a data type (a tree node), 203 we assign it a number using next_type_number. 204 That is its index in this vector. */ 205 206static GTY ((length ("typevec_len"))) struct typeinfo *typevec; 207 208/* Number of elements of space allocated in `typevec'. */ 209 210static GTY(()) int typevec_len; 211 212/* In dbx output, each type gets a unique number. 213 This is the number for the next type output. 214 The number, once assigned, is in the TYPE_SYMTAB_ADDRESS field. */ 215 216static GTY(()) int next_type_number; 217 218/* The C front end may call dbxout_symbol before dbxout_init runs. 219 We save all such decls in this list and output them when we get 220 to dbxout_init. */ 221 222static GTY(()) tree preinit_symbols; 223 224enum binclstatus {BINCL_NOT_REQUIRED, BINCL_PENDING, BINCL_PROCESSED}; 225 226/* When using N_BINCL in dbx output, each type number is actually a 227 pair of the file number and the type number within the file. 228 This is a stack of input files. */ 229 230struct dbx_file 231{ 232 struct dbx_file *next; 233 int file_number; 234 int next_type_number; 235 enum binclstatus bincl_status; /* Keep track of lazy bincl. */ 236 const char *pending_bincl_name; /* Name of bincl. */ 237 struct dbx_file *prev; /* Chain to traverse all pending bincls. */ 238}; 239 240/* This is the top of the stack. 241 242 This is not saved for PCH, because restoring a PCH should not change it. 243 next_file_number does have to be saved, because the PCH may use some 244 file numbers; however, just before restoring a PCH, next_file_number 245 should always be 0 because we should not have needed any file numbers 246 yet. */ 247 248#if (defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO)) \ 249 && defined (DBX_USE_BINCL) 250static struct dbx_file *current_file; 251#endif 252 253/* This is the next file number to use. */ 254 255static GTY(()) int next_file_number; 256 257/* A counter for dbxout_function_end. */ 258 259static GTY(()) int scope_labelno; 260 261/* A counter for dbxout_source_line. */ 262 263static GTY(()) int dbxout_source_line_counter; 264 265/* Number for the next N_SOL filename stabs label. The number 0 is reserved 266 for the N_SO filename stabs label. */ 267 268static GTY(()) int source_label_number = 1; 269 270/* Last source file name mentioned in a NOTE insn. */ 271 272static GTY(()) const char *lastfile; 273 274/* Used by PCH machinery to detect if 'lastfile' should be reset to 275 base_input_file. */ 276static GTY(()) int lastfile_is_base; 277 278/* Typical USG systems don't have stab.h, and they also have 279 no use for DBX-format debugging info. */ 280 281#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) 282 283#ifdef DBX_USE_BINCL 284/* If zero then there is no pending BINCL. */ 285static int pending_bincls = 0; 286#endif 287 288/* The original input file name. */ 289static const char *base_input_file; 290 291#ifdef DEBUG_SYMS_TEXT 292#define FORCE_TEXT switch_to_section (current_function_section ()) 293#else 294#define FORCE_TEXT 295#endif 296 297#include "gstab.h" 298 299/* 1 if PARM is passed to this function in memory. */ 300 301#define PARM_PASSED_IN_MEMORY(PARM) \ 302 (MEM_P (DECL_INCOMING_RTL (PARM))) 303 304/* A C expression for the integer offset value of an automatic variable 305 (N_LSYM) having address X (an RTX). */ 306#ifndef DEBUGGER_AUTO_OFFSET 307#define DEBUGGER_AUTO_OFFSET(X) \ 308 (GET_CODE (X) == PLUS ? INTVAL (XEXP (X, 1)) : 0) 309#endif 310 311/* A C expression for the integer offset value of an argument (N_PSYM) 312 having address X (an RTX). The nominal offset is OFFSET. 313 Note that we use OFFSET + 0 here to avoid the self-assign warning 314 when the macro is called in a context like 315 number = DEBUGGER_ARG_OFFSET(number, X) */ 316#ifndef DEBUGGER_ARG_OFFSET 317#define DEBUGGER_ARG_OFFSET(OFFSET, X) (OFFSET + 0) 318#endif 319 320/* This obstack holds the stab string currently being constructed. We 321 build it up here, then write it out, so we can split long lines up 322 properly (see dbxout_finish_complex_stabs). */ 323static struct obstack stabstr_ob; 324static size_t stabstr_last_contin_point; 325 326#ifdef DBX_USE_BINCL 327static void emit_bincl_stab (const char *c); 328static void emit_pending_bincls (void); 329#endif 330static inline void emit_pending_bincls_if_required (void); 331 332static void dbxout_init (const char *); 333 334static void dbxout_finish (const char *); 335static void dbxout_start_source_file (unsigned, const char *); 336static void dbxout_end_source_file (unsigned); 337static void dbxout_typedefs (tree); 338static void dbxout_type_index (tree); 339static void dbxout_args (tree); 340static void dbxout_type_fields (tree); 341static void dbxout_type_method_1 (tree); 342static void dbxout_type_methods (tree); 343static void dbxout_range_type (tree, tree, tree); 344static void dbxout_type (tree, int); 345static bool print_int_cst_bounds_in_octal_p (tree, tree, tree); 346static bool is_fortran (void); 347static void dbxout_type_name (tree); 348static void dbxout_class_name_qualifiers (tree); 349static int dbxout_symbol_location (tree, tree, const char *, rtx); 350static void dbxout_symbol_name (tree, const char *, int); 351static void dbxout_common_name (tree, const char *, stab_code_type); 352static const char *dbxout_common_check (tree, int *); 353static void dbxout_global_decl (tree); 354static void dbxout_type_decl (tree, int); 355static void dbxout_handle_pch (unsigned); 356static void debug_free_queue (void); 357 358/* The debug hooks structure. */ 359#if defined (DBX_DEBUGGING_INFO) 360 361static void dbxout_source_line (unsigned int, const char *, int, bool); 362static void dbxout_begin_prologue (unsigned int, const char *); 363static void dbxout_source_file (const char *); 364static void dbxout_function_end (tree); 365static void dbxout_begin_function (tree); 366static void dbxout_begin_block (unsigned, unsigned); 367static void dbxout_end_block (unsigned, unsigned); 368static void dbxout_function_decl (tree); 369 370const struct gcc_debug_hooks dbx_debug_hooks = 371{ 372 dbxout_init, 373 dbxout_finish, 374 debug_nothing_void, 375 debug_nothing_int_charstar, 376 debug_nothing_int_charstar, 377 dbxout_start_source_file, 378 dbxout_end_source_file, 379 dbxout_begin_block, 380 dbxout_end_block, 381 debug_true_const_tree, /* ignore_block */ 382 dbxout_source_line, /* source_line */ 383 dbxout_begin_prologue, /* begin_prologue */ 384 debug_nothing_int_charstar, /* end_prologue */ 385 debug_nothing_int_charstar, /* begin_epilogue */ 386 debug_nothing_int_charstar, /* end_epilogue */ 387#ifdef DBX_FUNCTION_FIRST 388 dbxout_begin_function, 389#else 390 debug_nothing_tree, /* begin_function */ 391#endif 392 debug_nothing_int, /* end_function */ 393 debug_nothing_tree, /* register_main_translation_unit */ 394 dbxout_function_decl, 395 dbxout_global_decl, /* global_decl */ 396 dbxout_type_decl, /* type_decl */ 397 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */ 398 debug_nothing_tree, /* deferred_inline_function */ 399 debug_nothing_tree, /* outlining_inline_function */ 400 debug_nothing_rtx_code_label, /* label */ 401 dbxout_handle_pch, /* handle_pch */ 402 debug_nothing_rtx_insn, /* var_location */ 403 debug_nothing_void, /* switch_text_section */ 404 debug_nothing_tree_tree, /* set_name */ 405 0, /* start_end_main_source_file */ 406 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */ 407}; 408#endif /* DBX_DEBUGGING_INFO */ 409 410#if defined (XCOFF_DEBUGGING_INFO) 411const struct gcc_debug_hooks xcoff_debug_hooks = 412{ 413 dbxout_init, 414 dbxout_finish, 415 debug_nothing_void, 416 debug_nothing_int_charstar, 417 debug_nothing_int_charstar, 418 dbxout_start_source_file, 419 dbxout_end_source_file, 420 xcoffout_begin_block, 421 xcoffout_end_block, 422 debug_true_const_tree, /* ignore_block */ 423 xcoffout_source_line, 424 xcoffout_begin_prologue, /* begin_prologue */ 425 debug_nothing_int_charstar, /* end_prologue */ 426 debug_nothing_int_charstar, /* begin_epilogue */ 427 xcoffout_end_epilogue, 428 debug_nothing_tree, /* begin_function */ 429 xcoffout_end_function, 430 debug_nothing_tree, /* register_main_translation_unit */ 431 debug_nothing_tree, /* function_decl */ 432 dbxout_global_decl, /* global_decl */ 433 dbxout_type_decl, /* type_decl */ 434 debug_nothing_tree_tree_tree_bool, /* imported_module_or_decl */ 435 debug_nothing_tree, /* deferred_inline_function */ 436 debug_nothing_tree, /* outlining_inline_function */ 437 debug_nothing_rtx_code_label, /* label */ 438 dbxout_handle_pch, /* handle_pch */ 439 debug_nothing_rtx_insn, /* var_location */ 440 debug_nothing_void, /* switch_text_section */ 441 debug_nothing_tree_tree, /* set_name */ 442 0, /* start_end_main_source_file */ 443 TYPE_SYMTAB_IS_ADDRESS /* tree_type_symtab_field */ 444}; 445#endif /* XCOFF_DEBUGGING_INFO */ 446 447/* Numeric formatting helper macro. Note that this does not handle 448 hexadecimal. */ 449#define NUMBER_FMT_LOOP(P, NUM, BASE) \ 450 do \ 451 { \ 452 int digit = NUM % BASE; \ 453 NUM /= BASE; \ 454 *--P = digit + '0'; \ 455 } \ 456 while (NUM > 0) 457 458/* Utility: write a decimal integer NUM to asm_out_file. */ 459void 460dbxout_int (int num) 461{ 462 char buf[64]; 463 char *p = buf + sizeof buf; 464 unsigned int unum; 465 466 if (num == 0) 467 { 468 putc ('0', asm_out_file); 469 return; 470 } 471 if (num < 0) 472 { 473 putc ('-', asm_out_file); 474 unum = -num; 475 } 476 else 477 unum = num; 478 479 NUMBER_FMT_LOOP (p, unum, 10); 480 481 while (p < buf + sizeof buf) 482 { 483 putc (*p, asm_out_file); 484 p++; 485 } 486} 487 488 489/* Primitives for emitting simple stabs directives. All other stabs 490 routines should use these functions instead of directly emitting 491 stabs. They are exported because machine-dependent code may need 492 to invoke them, e.g. in a DBX_OUTPUT_* macro whose definition 493 forwards to code in CPU.c. */ 494 495/* The following functions should all be called immediately after one 496 of the dbxout_begin_stab* functions (below). They write out 497 various things as the value of a stab. */ 498 499/* Write out a literal zero as the value of a stab. */ 500void 501dbxout_stab_value_zero (void) 502{ 503 fputs ("0\n", asm_out_file); 504} 505 506/* Write out the label LABEL as the value of a stab. */ 507void 508dbxout_stab_value_label (const char *label) 509{ 510 assemble_name (asm_out_file, label); 511 putc ('\n', asm_out_file); 512} 513 514/* Write out the difference of two labels, LABEL - BASE, as the value 515 of a stab. */ 516void 517dbxout_stab_value_label_diff (const char *label, const char *base) 518{ 519 assemble_name (asm_out_file, label); 520 putc ('-', asm_out_file); 521 assemble_name (asm_out_file, base); 522 putc ('\n', asm_out_file); 523} 524 525/* Write out an internal label as the value of a stab, and immediately 526 emit that internal label. This should be used only when 527 dbxout_stabd will not work. STEM is the name stem of the label, 528 COUNTERP is a pointer to a counter variable which will be used to 529 guarantee label uniqueness. */ 530void 531dbxout_stab_value_internal_label (const char *stem, int *counterp) 532{ 533 char label[100]; 534 int counter = counterp ? (*counterp)++ : 0; 535 536 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter); 537 dbxout_stab_value_label (label); 538 targetm.asm_out.internal_label (asm_out_file, stem, counter); 539} 540 541/* Write out the difference between BASE and an internal label as the 542 value of a stab, and immediately emit that internal label. STEM and 543 COUNTERP are as for dbxout_stab_value_internal_label. */ 544void 545dbxout_stab_value_internal_label_diff (const char *stem, int *counterp, 546 const char *base) 547{ 548 char label[100]; 549 int counter = counterp ? (*counterp)++ : 0; 550 551 ASM_GENERATE_INTERNAL_LABEL (label, stem, counter); 552 dbxout_stab_value_label_diff (label, base); 553 targetm.asm_out.internal_label (asm_out_file, stem, counter); 554} 555 556/* The following functions produce specific kinds of stab directives. */ 557 558/* Write a .stabd directive with type STYPE and desc SDESC to asm_out_file. */ 559void 560dbxout_stabd (int stype, int sdesc) 561{ 562 fputs (ASM_STABD_OP, asm_out_file); 563 dbxout_int (stype); 564 fputs (",0,", asm_out_file); 565 dbxout_int (sdesc); 566 putc ('\n', asm_out_file); 567} 568 569/* Write a .stabn directive with type STYPE. This function stops 570 short of emitting the value field, which is the responsibility of 571 the caller (normally it will be either a symbol or the difference 572 of two symbols). */ 573 574void 575dbxout_begin_stabn (int stype) 576{ 577 fputs (ASM_STABN_OP, asm_out_file); 578 dbxout_int (stype); 579 fputs (",0,0,", asm_out_file); 580} 581 582/* Write a .stabn directive with type N_SLINE and desc LINE. As above, 583 the value field is the responsibility of the caller. */ 584void 585dbxout_begin_stabn_sline (int lineno) 586{ 587 fputs (ASM_STABN_OP, asm_out_file); 588 dbxout_int (N_SLINE); 589 fputs (",0,", asm_out_file); 590 dbxout_int (lineno); 591 putc (',', asm_out_file); 592} 593 594/* Begin a .stabs directive with string "", type STYPE, and desc and 595 other fields 0. The value field is the responsibility of the 596 caller. This function cannot be used for .stabx directives. */ 597void 598dbxout_begin_empty_stabs (int stype) 599{ 600 fputs (ASM_STABS_OP, asm_out_file); 601 fputs ("\"\",", asm_out_file); 602 dbxout_int (stype); 603 fputs (",0,0,", asm_out_file); 604} 605 606/* Begin a .stabs directive with string STR, type STYPE, and desc 0. 607 The value field is the responsibility of the caller. */ 608void 609dbxout_begin_simple_stabs (const char *str, int stype) 610{ 611 fputs (ASM_STABS_OP, asm_out_file); 612 output_quoted_string (asm_out_file, str); 613 putc (',', asm_out_file); 614 dbxout_int (stype); 615 fputs (",0,0,", asm_out_file); 616} 617 618/* As above but use SDESC for the desc field. */ 619void 620dbxout_begin_simple_stabs_desc (const char *str, int stype, int sdesc) 621{ 622 fputs (ASM_STABS_OP, asm_out_file); 623 output_quoted_string (asm_out_file, str); 624 putc (',', asm_out_file); 625 dbxout_int (stype); 626 fputs (",0,", asm_out_file); 627 dbxout_int (sdesc); 628 putc (',', asm_out_file); 629} 630 631/* The next set of functions are entirely concerned with production of 632 "complex" .stabs directives: that is, .stabs directives whose 633 strings have to be constructed piecemeal. dbxout_type, 634 dbxout_symbol, etc. use these routines heavily. The string is queued 635 up in an obstack, then written out by dbxout_finish_complex_stabs, which 636 is also responsible for splitting it up if it exceeds DBX_CONTIN_LENGTH. 637 (You might think it would be more efficient to go straight to stdio 638 when DBX_CONTIN_LENGTH is 0 (i.e. no length limit) but that turns 639 out not to be the case, and anyway this needs fewer #ifdefs.) */ 640 641/* Begin a complex .stabs directive. If we can, write the initial 642 ASM_STABS_OP to the asm_out_file. */ 643 644static void 645dbxout_begin_complex_stabs (void) 646{ 647 emit_pending_bincls_if_required (); 648 FORCE_TEXT; 649 fputs (ASM_STABS_OP, asm_out_file); 650 putc ('"', asm_out_file); 651 gcc_assert (stabstr_last_contin_point == 0); 652} 653 654/* As above, but do not force text or emit pending bincls. This is 655 used by dbxout_symbol_location, which needs to do something else. */ 656static void 657dbxout_begin_complex_stabs_noforcetext (void) 658{ 659 fputs (ASM_STABS_OP, asm_out_file); 660 putc ('"', asm_out_file); 661 gcc_assert (stabstr_last_contin_point == 0); 662} 663 664/* Add CHR, a single character, to the string being built. */ 665#define stabstr_C(chr) obstack_1grow (&stabstr_ob, chr) 666 667/* Add STR, a normal C string, to the string being built. */ 668#define stabstr_S(str) obstack_grow (&stabstr_ob, str, strlen (str)) 669 670/* Add the text of ID, an IDENTIFIER_NODE, to the string being built. */ 671#define stabstr_I(id) obstack_grow (&stabstr_ob, \ 672 IDENTIFIER_POINTER (id), \ 673 IDENTIFIER_LENGTH (id)) 674 675/* Add NUM, a signed decimal number, to the string being built. */ 676static void 677stabstr_D (HOST_WIDE_INT num) 678{ 679 char buf[64]; 680 char *p = buf + sizeof buf; 681 unsigned int unum; 682 683 if (num == 0) 684 { 685 stabstr_C ('0'); 686 return; 687 } 688 if (num < 0) 689 { 690 stabstr_C ('-'); 691 unum = -num; 692 } 693 else 694 unum = num; 695 696 NUMBER_FMT_LOOP (p, unum, 10); 697 698 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p); 699} 700 701/* Add NUM, an unsigned decimal number, to the string being built. */ 702static void 703stabstr_U (unsigned HOST_WIDE_INT num) 704{ 705 char buf[64]; 706 char *p = buf + sizeof buf; 707 if (num == 0) 708 { 709 stabstr_C ('0'); 710 return; 711 } 712 NUMBER_FMT_LOOP (p, num, 10); 713 obstack_grow (&stabstr_ob, p, (buf + sizeof buf) - p); 714} 715 716/* Add CST, an INTEGER_CST tree, to the string being built as an 717 unsigned octal number. This routine handles values which are 718 larger than a single HOST_WIDE_INT. */ 719static void 720stabstr_O (tree cst) 721{ 722 int prec = TYPE_PRECISION (TREE_TYPE (cst)); 723 int res_pres = prec % 3; 724 int i; 725 unsigned int digit; 726 727 /* Leading zero for base indicator. */ 728 stabstr_C ('0'); 729 730 /* If the value is zero, the base indicator will serve as the value 731 all by itself. */ 732 if (wi::eq_p (cst, 0)) 733 return; 734 735 /* GDB wants constants with no extra leading "1" bits, so 736 we need to remove any sign-extension that might be 737 present. */ 738 if (res_pres == 1) 739 { 740 digit = wi::extract_uhwi (cst, prec - 1, 1); 741 stabstr_C ('0' + digit); 742 } 743 else if (res_pres == 2) 744 { 745 digit = wi::extract_uhwi (cst, prec - 2, 2); 746 stabstr_C ('0' + digit); 747 } 748 749 prec -= res_pres; 750 for (i = prec - 3; i >= 0; i = i - 3) 751 { 752 digit = wi::extract_uhwi (cst, i, 3); 753 stabstr_C ('0' + digit); 754 } 755} 756 757/* Called whenever it is safe to break a stabs string into multiple 758 .stabs directives. If the current string has exceeded the limit 759 set by DBX_CONTIN_LENGTH, mark the current position in the buffer 760 as a continuation point by inserting DBX_CONTIN_CHAR (doubled if 761 it is a backslash) and a null character. */ 762static inline void 763stabstr_continue (void) 764{ 765 if (DBX_CONTIN_LENGTH > 0 766 && obstack_object_size (&stabstr_ob) - stabstr_last_contin_point 767 > DBX_CONTIN_LENGTH) 768 { 769 if (DBX_CONTIN_CHAR == '\\') 770 obstack_1grow (&stabstr_ob, '\\'); 771 obstack_1grow (&stabstr_ob, DBX_CONTIN_CHAR); 772 obstack_1grow (&stabstr_ob, '\0'); 773 stabstr_last_contin_point = obstack_object_size (&stabstr_ob); 774 } 775} 776#define CONTIN stabstr_continue () 777 778/* Macro subroutine of dbxout_finish_complex_stabs, which emits 779 all of the arguments to the .stabs directive after the string. 780 Overridden by xcoffout.h. CODE is the stabs code for this symbol; 781 LINE is the source line to write into the desc field (in extended 782 mode); SYM is the symbol itself. 783 784 ADDR, LABEL, and NUMBER are three different ways to represent the 785 stabs value field. At most one of these should be nonzero. 786 787 ADDR is used most of the time; it represents the value as an 788 RTL address constant. 789 790 LABEL is used (currently) only for N_CATCH stabs; it represents 791 the value as a string suitable for assemble_name. 792 793 NUMBER is used when the value is an offset from an implicit base 794 pointer (e.g. for a stack variable), or an index (e.g. for a 795 register variable). It represents the value as a decimal integer. */ 796 797#ifndef DBX_FINISH_STABS 798#define DBX_FINISH_STABS(SYM, CODE, LINE, ADDR, LABEL, NUMBER) \ 799do { \ 800 int line_ = use_gnu_debug_info_extensions ? LINE : 0; \ 801 \ 802 dbxout_int (CODE); \ 803 fputs (",0,", asm_out_file); \ 804 dbxout_int (line_); \ 805 putc (',', asm_out_file); \ 806 if (ADDR) \ 807 output_addr_const (asm_out_file, ADDR); \ 808 else if (LABEL) \ 809 assemble_name (asm_out_file, LABEL); \ 810 else \ 811 dbxout_int (NUMBER); \ 812 putc ('\n', asm_out_file); \ 813} while (0) 814#endif 815 816/* Finish the emission of a complex .stabs directive. When DBX_CONTIN_LENGTH 817 is zero, this has only to emit the close quote and the remainder of 818 the arguments. When it is nonzero, the string has been marshalled in 819 stabstr_ob, and this routine is responsible for breaking it up into 820 DBX_CONTIN_LENGTH-sized chunks. 821 822 SYM is the DECL of the symbol under consideration; it is used only 823 for its DECL_SOURCE_LINE. The other arguments are all passed directly 824 to DBX_FINISH_STABS; see above for details. */ 825 826static void 827dbxout_finish_complex_stabs (tree sym, stab_code_type code, 828 rtx addr, const char *label, int number) 829{ 830 int line ATTRIBUTE_UNUSED; 831 char *str; 832 size_t len; 833 834 line = sym ? DECL_SOURCE_LINE (sym) : 0; 835 if (DBX_CONTIN_LENGTH > 0) 836 { 837 char *chunk; 838 size_t chunklen; 839 840 /* Nul-terminate the growing string, then get its size and 841 address. */ 842 obstack_1grow (&stabstr_ob, '\0'); 843 844 len = obstack_object_size (&stabstr_ob); 845 chunk = str = XOBFINISH (&stabstr_ob, char *); 846 847 /* Within the buffer are a sequence of NUL-separated strings, 848 each of which is to be written out as a separate stab 849 directive. */ 850 for (;;) 851 { 852 chunklen = strlen (chunk); 853 fwrite (chunk, 1, chunklen, asm_out_file); 854 fputs ("\",", asm_out_file); 855 856 /* Must add an extra byte to account for the NUL separator. */ 857 chunk += chunklen + 1; 858 len -= chunklen + 1; 859 860 /* Only put a line number on the last stab in the sequence. */ 861 DBX_FINISH_STABS (sym, code, len == 0 ? line : 0, 862 addr, label, number); 863 if (len == 0) 864 break; 865 866 fputs (ASM_STABS_OP, asm_out_file); 867 putc ('"', asm_out_file); 868 } 869 stabstr_last_contin_point = 0; 870 } 871 else 872 { 873 /* No continuations - we can put the whole string out at once. 874 It is faster to augment the string with the close quote and 875 comma than to do a two-character fputs. */ 876 obstack_grow (&stabstr_ob, "\",", 2); 877 len = obstack_object_size (&stabstr_ob); 878 str = XOBFINISH (&stabstr_ob, char *); 879 880 fwrite (str, 1, len, asm_out_file); 881 DBX_FINISH_STABS (sym, code, line, addr, label, number); 882 } 883 obstack_free (&stabstr_ob, str); 884} 885 886#if defined (DBX_DEBUGGING_INFO) || defined (XCOFF_DEBUGGING_INFO) 887 888/* When -gused is used, emit debug info for only used symbols. But in 889 addition to the standard intercepted debug_hooks there are some 890 direct calls into this file, i.e., dbxout_symbol, dbxout_parms, and 891 dbxout_reg_params. Those routines may also be called from a higher 892 level intercepted routine. So to prevent recording data for an inner 893 call to one of these for an intercept, we maintain an intercept 894 nesting counter (debug_nesting). We only save the intercepted 895 arguments if the nesting is 1. */ 896static int debug_nesting = 0; 897 898static tree *symbol_queue; 899static int symbol_queue_index = 0; 900static int symbol_queue_size = 0; 901 902#define DBXOUT_DECR_NESTING \ 903 if (--debug_nesting == 0 && symbol_queue_index > 0) \ 904 { emit_pending_bincls_if_required (); debug_flush_symbol_queue (); } 905 906#define DBXOUT_DECR_NESTING_AND_RETURN(x) \ 907 do {--debug_nesting; return (x);} while (0) 908 909#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ 910 911#if defined (DBX_DEBUGGING_INFO) 912 913static void 914dbxout_function_end (tree decl ATTRIBUTE_UNUSED) 915{ 916 char lscope_label_name[100]; 917 918 /* The Lscope label must be emitted even if we aren't doing anything 919 else; dbxout_block needs it. */ 920 switch_to_section (function_section (current_function_decl)); 921 922 /* Convert Lscope into the appropriate format for local labels in case 923 the system doesn't insert underscores in front of user generated 924 labels. */ 925 ASM_GENERATE_INTERNAL_LABEL (lscope_label_name, "Lscope", scope_labelno); 926 targetm.asm_out.internal_label (asm_out_file, "Lscope", scope_labelno); 927 928 /* The N_FUN tag at the end of the function is a GNU extension, 929 which may be undesirable, and is unnecessary if we do not have 930 named sections. */ 931 if (!use_gnu_debug_info_extensions 932 || NO_DBX_FUNCTION_END 933 || !targetm_common.have_named_sections) 934 return; 935 936 /* By convention, GCC will mark the end of a function with an N_FUN 937 symbol and an empty string. */ 938 if (flag_reorder_blocks_and_partition) 939 { 940 dbxout_begin_empty_stabs (N_FUN); 941 dbxout_stab_value_label_diff (crtl->subsections.hot_section_end_label, 942 crtl->subsections.hot_section_label); 943 dbxout_begin_empty_stabs (N_FUN); 944 dbxout_stab_value_label_diff (crtl->subsections.cold_section_end_label, 945 crtl->subsections.cold_section_label); 946 } 947 else 948 { 949 char begin_label[20]; 950 /* Reference current function start using LFBB. */ 951 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno); 952 dbxout_begin_empty_stabs (N_FUN); 953 dbxout_stab_value_label_diff (lscope_label_name, begin_label); 954 } 955 956 if (!NO_DBX_BNSYM_ENSYM && !flag_debug_only_used_symbols) 957 dbxout_stabd (N_ENSYM, 0); 958} 959#endif /* DBX_DEBUGGING_INFO */ 960 961/* Get lang description for N_SO stab. */ 962static unsigned int ATTRIBUTE_UNUSED 963get_lang_number (void) 964{ 965 const char *language_string = lang_hooks.name; 966 if (lang_GNU_C ()) 967 return N_SO_C; 968 else if (lang_GNU_CXX ()) 969 return N_SO_CC; 970 else if (strcmp (language_string, "GNU F77") == 0) 971 return N_SO_FORTRAN; 972 else if (lang_GNU_Fortran ()) 973 return N_SO_FORTRAN90; /* CHECKME */ 974 else if (strcmp (language_string, "GNU Pascal") == 0) 975 return N_SO_PASCAL; 976 else if (strcmp (language_string, "GNU Objective-C") == 0) 977 return N_SO_OBJC; 978 else if (strcmp (language_string, "GNU Objective-C++") == 0) 979 return N_SO_OBJCPLUS; 980 else 981 return 0; 982 983} 984 985static bool 986is_fortran (void) 987{ 988 unsigned int lang = get_lang_number (); 989 990 return (lang == N_SO_FORTRAN) || (lang == N_SO_FORTRAN90); 991} 992 993/* At the beginning of compilation, start writing the symbol table. 994 Initialize `typevec' and output the standard data types of C. */ 995 996static void 997dbxout_init (const char *input_file_name) 998{ 999 char ltext_label_name[100]; 1000 bool used_ltext_label_name = false; 1001 tree syms = lang_hooks.decls.getdecls (); 1002 const char *mapped_name; 1003 1004 typevec_len = 100; 1005 typevec = ggc_cleared_vec_alloc<typeinfo> (typevec_len); 1006 1007 /* stabstr_ob contains one string, which will be just fine with 1008 1-byte alignment. */ 1009 obstack_specify_allocation (&stabstr_ob, 0, 1, xmalloc, free); 1010 1011 /* Convert Ltext into the appropriate format for local labels in case 1012 the system doesn't insert underscores in front of user generated 1013 labels. */ 1014 ASM_GENERATE_INTERNAL_LABEL (ltext_label_name, "Ltext", 0); 1015 1016 /* Put the current working directory in an N_SO symbol. */ 1017 if (use_gnu_debug_info_extensions && !NO_DBX_MAIN_SOURCE_DIRECTORY) 1018 { 1019 static const char *cwd; 1020 1021 if (!cwd) 1022 { 1023 cwd = get_src_pwd (); 1024 if (cwd[0] == '\0') 1025 cwd = "/"; 1026 else if (!IS_DIR_SEPARATOR (cwd[strlen (cwd) - 1])) 1027 cwd = concat (cwd, "/", NULL); 1028 cwd = remap_debug_filename (cwd); 1029 } 1030#ifdef DBX_OUTPUT_MAIN_SOURCE_DIRECTORY 1031 DBX_OUTPUT_MAIN_SOURCE_DIRECTORY (asm_out_file, cwd); 1032#else /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */ 1033 dbxout_begin_simple_stabs_desc (cwd, N_SO, get_lang_number ()); 1034 dbxout_stab_value_label (ltext_label_name); 1035 used_ltext_label_name = true; 1036#endif /* no DBX_OUTPUT_MAIN_SOURCE_DIRECTORY */ 1037 } 1038 1039 mapped_name = remap_debug_filename (input_file_name); 1040#ifdef DBX_OUTPUT_MAIN_SOURCE_FILENAME 1041 DBX_OUTPUT_MAIN_SOURCE_FILENAME (asm_out_file, mapped_name); 1042#else 1043 dbxout_begin_simple_stabs_desc (mapped_name, N_SO, get_lang_number ()); 1044 dbxout_stab_value_label (ltext_label_name); 1045 used_ltext_label_name = true; 1046#endif 1047 1048 if (used_ltext_label_name) 1049 { 1050 switch_to_section (text_section); 1051 targetm.asm_out.internal_label (asm_out_file, "Ltext", 0); 1052 } 1053 1054 /* Emit an N_OPT stab to indicate that this file was compiled by GCC. 1055 The string used is historical. */ 1056#ifndef NO_DBX_GCC_MARKER 1057 dbxout_begin_simple_stabs ("gcc2_compiled.", N_OPT); 1058 dbxout_stab_value_zero (); 1059#endif 1060 1061 base_input_file = lastfile = input_file_name; 1062 1063 next_type_number = 1; 1064 1065#ifdef DBX_USE_BINCL 1066 current_file = XNEW (struct dbx_file); 1067 current_file->next = NULL; 1068 current_file->file_number = 0; 1069 current_file->next_type_number = 1; 1070 next_file_number = 1; 1071 current_file->prev = NULL; 1072 current_file->bincl_status = BINCL_NOT_REQUIRED; 1073 current_file->pending_bincl_name = NULL; 1074#endif 1075 1076 /* Get all permanent types that have typedef names, and output them 1077 all, except for those already output. Some language front ends 1078 put these declarations in the top-level scope; some do not; 1079 the latter are responsible for calling debug_hooks->type_decl from 1080 their record_builtin_type function. */ 1081 dbxout_typedefs (syms); 1082 1083 if (preinit_symbols) 1084 { 1085 tree t; 1086 for (t = nreverse (preinit_symbols); t; t = TREE_CHAIN (t)) 1087 dbxout_symbol (TREE_VALUE (t), 0); 1088 preinit_symbols = 0; 1089 } 1090} 1091 1092/* Output any typedef names for types described by TYPE_DECLs in SYMS. */ 1093 1094static void 1095dbxout_typedefs (tree syms) 1096{ 1097 for (; syms != NULL_TREE; syms = DECL_CHAIN (syms)) 1098 { 1099 if (TREE_CODE (syms) == TYPE_DECL) 1100 { 1101 tree type = TREE_TYPE (syms); 1102 if (TYPE_NAME (type) 1103 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 1104 && COMPLETE_OR_VOID_TYPE_P (type) 1105 && ! TREE_ASM_WRITTEN (TYPE_NAME (type))) 1106 dbxout_symbol (TYPE_NAME (type), 0); 1107 } 1108 } 1109} 1110 1111#ifdef DBX_USE_BINCL 1112/* Emit BINCL stab using given name. */ 1113static void 1114emit_bincl_stab (const char *name) 1115{ 1116 dbxout_begin_simple_stabs (name, N_BINCL); 1117 dbxout_stab_value_zero (); 1118} 1119 1120/* If there are pending bincls then it is time to emit all of them. */ 1121 1122static inline void 1123emit_pending_bincls_if_required (void) 1124{ 1125 if (pending_bincls) 1126 emit_pending_bincls (); 1127} 1128 1129/* Emit all pending bincls. */ 1130 1131static void 1132emit_pending_bincls (void) 1133{ 1134 struct dbx_file *f = current_file; 1135 1136 /* Find first pending bincl. */ 1137 while (f->bincl_status == BINCL_PENDING) 1138 f = f->next; 1139 1140 /* Now emit all bincls. */ 1141 f = f->prev; 1142 1143 while (f) 1144 { 1145 if (f->bincl_status == BINCL_PENDING) 1146 { 1147 emit_bincl_stab (f->pending_bincl_name); 1148 1149 /* Update file number and status. */ 1150 f->file_number = next_file_number++; 1151 f->bincl_status = BINCL_PROCESSED; 1152 } 1153 if (f == current_file) 1154 break; 1155 f = f->prev; 1156 } 1157 1158 /* All pending bincls have been emitted. */ 1159 pending_bincls = 0; 1160} 1161 1162#else 1163 1164static inline void 1165emit_pending_bincls_if_required (void) {} 1166#endif 1167 1168/* Change to reading from a new source file. Generate a N_BINCL stab. */ 1169 1170static void 1171dbxout_start_source_file (unsigned int line ATTRIBUTE_UNUSED, 1172 const char *filename ATTRIBUTE_UNUSED) 1173{ 1174#ifdef DBX_USE_BINCL 1175 struct dbx_file *n = XNEW (struct dbx_file); 1176 1177 n->next = current_file; 1178 n->next_type_number = 1; 1179 /* Do not assign file number now. 1180 Delay it until we actually emit BINCL. */ 1181 n->file_number = 0; 1182 n->prev = NULL; 1183 current_file->prev = n; 1184 n->bincl_status = BINCL_PENDING; 1185 n->pending_bincl_name = remap_debug_filename (filename); 1186 pending_bincls = 1; 1187 current_file = n; 1188#endif 1189} 1190 1191/* Revert to reading a previous source file. Generate a N_EINCL stab. */ 1192 1193static void 1194dbxout_end_source_file (unsigned int line ATTRIBUTE_UNUSED) 1195{ 1196#ifdef DBX_USE_BINCL 1197 /* Emit EINCL stab only if BINCL is not pending. */ 1198 if (current_file->bincl_status == BINCL_PROCESSED) 1199 { 1200 dbxout_begin_stabn (N_EINCL); 1201 dbxout_stab_value_zero (); 1202 } 1203 current_file->bincl_status = BINCL_NOT_REQUIRED; 1204 current_file = current_file->next; 1205#endif 1206} 1207 1208/* Handle a few odd cases that occur when trying to make PCH files work. */ 1209 1210static void 1211dbxout_handle_pch (unsigned at_end) 1212{ 1213 if (! at_end) 1214 { 1215 /* When using the PCH, this file will be included, so we need to output 1216 a BINCL. */ 1217 dbxout_start_source_file (0, lastfile); 1218 1219 /* The base file when using the PCH won't be the same as 1220 the base file when it's being generated. */ 1221 lastfile = NULL; 1222 } 1223 else 1224 { 1225 /* ... and an EINCL. */ 1226 dbxout_end_source_file (0); 1227 1228 /* Deal with cases where 'lastfile' was never actually changed. */ 1229 lastfile_is_base = lastfile == NULL; 1230 } 1231} 1232 1233#if defined (DBX_DEBUGGING_INFO) 1234 1235static void dbxout_block (tree, int, tree); 1236 1237/* Output debugging info to FILE to switch to sourcefile FILENAME. */ 1238 1239static void 1240dbxout_source_file (const char *filename) 1241{ 1242 if (lastfile == 0 && lastfile_is_base) 1243 { 1244 lastfile = base_input_file; 1245 lastfile_is_base = 0; 1246 } 1247 1248 if (filename && (lastfile == 0 || strcmp (filename, lastfile))) 1249 { 1250 /* Don't change section amid function. */ 1251 if (current_function_decl == NULL_TREE) 1252 switch_to_section (text_section); 1253 1254 dbxout_begin_simple_stabs (remap_debug_filename (filename), N_SOL); 1255 dbxout_stab_value_internal_label ("Ltext", &source_label_number); 1256 lastfile = filename; 1257 } 1258} 1259 1260/* Output N_BNSYM, line number symbol entry, and local symbol at 1261 function scope */ 1262 1263static void 1264dbxout_begin_prologue (unsigned int lineno, const char *filename) 1265{ 1266 if (use_gnu_debug_info_extensions 1267 && !NO_DBX_FUNCTION_END 1268 && !NO_DBX_BNSYM_ENSYM 1269 && !flag_debug_only_used_symbols) 1270 dbxout_stabd (N_BNSYM, 0); 1271 1272 /* pre-increment the scope counter */ 1273 scope_labelno++; 1274 1275 dbxout_source_line (lineno, filename, 0, true); 1276 /* Output function begin block at function scope, referenced 1277 by dbxout_block, dbxout_source_line and dbxout_function_end. */ 1278 emit_pending_bincls_if_required (); 1279 targetm.asm_out.internal_label (asm_out_file, "LFBB", scope_labelno); 1280} 1281 1282/* Output a line number symbol entry for source file FILENAME and line 1283 number LINENO. */ 1284 1285static void 1286dbxout_source_line (unsigned int lineno, const char *filename, 1287 int discriminator ATTRIBUTE_UNUSED, 1288 bool is_stmt ATTRIBUTE_UNUSED) 1289{ 1290 dbxout_source_file (filename); 1291 1292#ifdef DBX_OUTPUT_SOURCE_LINE 1293 DBX_OUTPUT_SOURCE_LINE (asm_out_file, lineno, dbxout_source_line_counter); 1294#else 1295 if (DBX_LINES_FUNCTION_RELATIVE) 1296 { 1297 char begin_label[20]; 1298 dbxout_begin_stabn_sline (lineno); 1299 /* Reference current function start using LFBB. */ 1300 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno); 1301 dbxout_stab_value_internal_label_diff ("LM", &dbxout_source_line_counter, 1302 begin_label); 1303 } 1304 else 1305 dbxout_stabd (N_SLINE, lineno); 1306#endif 1307} 1308 1309/* Describe the beginning of an internal block within a function. */ 1310 1311static void 1312dbxout_begin_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n) 1313{ 1314 emit_pending_bincls_if_required (); 1315 targetm.asm_out.internal_label (asm_out_file, "LBB", n); 1316} 1317 1318/* Describe the end line-number of an internal block within a function. */ 1319 1320static void 1321dbxout_end_block (unsigned int line ATTRIBUTE_UNUSED, unsigned int n) 1322{ 1323 emit_pending_bincls_if_required (); 1324 targetm.asm_out.internal_label (asm_out_file, "LBE", n); 1325} 1326 1327/* Output dbx data for a function definition. 1328 This includes a definition of the function name itself (a symbol), 1329 definitions of the parameters (locating them in the parameter list) 1330 and then output the block that makes up the function's body 1331 (including all the auto variables of the function). */ 1332 1333static void 1334dbxout_function_decl (tree decl) 1335{ 1336 emit_pending_bincls_if_required (); 1337#ifndef DBX_FUNCTION_FIRST 1338 dbxout_begin_function (decl); 1339#endif 1340 dbxout_block (DECL_INITIAL (decl), 0, DECL_ARGUMENTS (decl)); 1341 dbxout_function_end (decl); 1342} 1343 1344#endif /* DBX_DEBUGGING_INFO */ 1345 1346/* Debug information for a global DECL. Called from toplev.c after 1347 compilation proper has finished. */ 1348static void 1349dbxout_global_decl (tree decl) 1350{ 1351 if (TREE_CODE (decl) == VAR_DECL && !DECL_EXTERNAL (decl)) 1352 { 1353 int saved_tree_used = TREE_USED (decl); 1354 TREE_USED (decl) = 1; 1355 dbxout_symbol (decl, 0); 1356 TREE_USED (decl) = saved_tree_used; 1357 } 1358} 1359 1360/* This is just a function-type adapter; dbxout_symbol does exactly 1361 what we want but returns an int. */ 1362static void 1363dbxout_type_decl (tree decl, int local) 1364{ 1365 dbxout_symbol (decl, local); 1366} 1367 1368/* At the end of compilation, finish writing the symbol table. 1369 The default is to call debug_free_queue but do nothing else. */ 1370 1371static void 1372dbxout_finish (const char *filename ATTRIBUTE_UNUSED) 1373{ 1374#ifdef DBX_OUTPUT_MAIN_SOURCE_FILE_END 1375 DBX_OUTPUT_MAIN_SOURCE_FILE_END (asm_out_file, filename); 1376#elif defined DBX_OUTPUT_NULL_N_SO_AT_MAIN_SOURCE_FILE_END 1377 { 1378 switch_to_section (text_section); 1379 dbxout_begin_empty_stabs (N_SO); 1380 dbxout_stab_value_internal_label ("Letext", 0); 1381 } 1382#endif 1383 debug_free_queue (); 1384} 1385 1386/* Output the index of a type. */ 1387 1388static void 1389dbxout_type_index (tree type) 1390{ 1391#ifndef DBX_USE_BINCL 1392 stabstr_D (TYPE_SYMTAB_ADDRESS (type)); 1393#else 1394 struct typeinfo *t = &typevec[TYPE_SYMTAB_ADDRESS (type)]; 1395 stabstr_C ('('); 1396 stabstr_D (t->file_number); 1397 stabstr_C (','); 1398 stabstr_D (t->type_number); 1399 stabstr_C (')'); 1400#endif 1401} 1402 1403 1404/* Generate the symbols for any queued up type symbols we encountered 1405 while generating the type info for some originally used symbol. 1406 This might generate additional entries in the queue. Only when 1407 the nesting depth goes to 0 is this routine called. */ 1408 1409static void 1410debug_flush_symbol_queue (void) 1411{ 1412 int i; 1413 1414 /* Make sure that additionally queued items are not flushed 1415 prematurely. */ 1416 1417 ++debug_nesting; 1418 1419 for (i = 0; i < symbol_queue_index; ++i) 1420 { 1421 /* If we pushed queued symbols then such symbols must be 1422 output no matter what anyone else says. Specifically, 1423 we need to make sure dbxout_symbol() thinks the symbol was 1424 used and also we need to override TYPE_DECL_SUPPRESS_DEBUG 1425 which may be set for outside reasons. */ 1426 int saved_tree_used = TREE_USED (symbol_queue[i]); 1427 int saved_suppress_debug = TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]); 1428 TREE_USED (symbol_queue[i]) = 1; 1429 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = 0; 1430 1431#ifdef DBX_DEBUGGING_INFO 1432 dbxout_symbol (symbol_queue[i], 0); 1433#endif 1434 1435 TREE_USED (symbol_queue[i]) = saved_tree_used; 1436 TYPE_DECL_SUPPRESS_DEBUG (symbol_queue[i]) = saved_suppress_debug; 1437 } 1438 1439 symbol_queue_index = 0; 1440 --debug_nesting; 1441} 1442 1443/* Queue a type symbol needed as part of the definition of a decl 1444 symbol. These symbols are generated when debug_flush_symbol_queue() 1445 is called. */ 1446 1447static void 1448debug_queue_symbol (tree decl) 1449{ 1450 if (symbol_queue_index >= symbol_queue_size) 1451 { 1452 symbol_queue_size += 10; 1453 symbol_queue = XRESIZEVEC (tree, symbol_queue, symbol_queue_size); 1454 } 1455 1456 symbol_queue[symbol_queue_index++] = decl; 1457} 1458 1459/* Free symbol queue. */ 1460static void 1461debug_free_queue (void) 1462{ 1463 if (symbol_queue) 1464 { 1465 free (symbol_queue); 1466 symbol_queue = NULL; 1467 symbol_queue_size = 0; 1468 } 1469} 1470 1471/* Used in several places: evaluates to '0' for a private decl, 1472 '1' for a protected decl, '2' for a public decl. */ 1473#define DECL_ACCESSIBILITY_CHAR(DECL) \ 1474(TREE_PRIVATE (DECL) ? '0' : TREE_PROTECTED (DECL) ? '1' : '2') 1475 1476/* Subroutine of `dbxout_type'. Output the type fields of TYPE. 1477 This must be a separate function because anonymous unions require 1478 recursive calls. */ 1479 1480static void 1481dbxout_type_fields (tree type) 1482{ 1483 tree tem; 1484 1485 /* Output the name, type, position (in bits), size (in bits) of each 1486 field that we can support. */ 1487 for (tem = TYPE_FIELDS (type); tem; tem = DECL_CHAIN (tem)) 1488 { 1489 /* If one of the nodes is an error_mark or its type is then 1490 return early. */ 1491 if (error_operand_p (tem)) 1492 return; 1493 1494 /* Omit here local type decls until we know how to support them. */ 1495 if (TREE_CODE (tem) == TYPE_DECL 1496 /* Omit here the nameless fields that are used to skip bits. */ 1497 || DECL_IGNORED_P (tem) 1498 /* Omit fields whose position or size are variable or too large to 1499 represent. */ 1500 || (TREE_CODE (tem) == FIELD_DECL 1501 && (! tree_fits_shwi_p (bit_position (tem)) 1502 || ! DECL_SIZE (tem) 1503 || ! tree_fits_uhwi_p (DECL_SIZE (tem))))) 1504 continue; 1505 1506 else if (TREE_CODE (tem) != CONST_DECL) 1507 { 1508 /* Continue the line if necessary, 1509 but not before the first field. */ 1510 if (tem != TYPE_FIELDS (type)) 1511 CONTIN; 1512 1513 if (DECL_NAME (tem)) 1514 stabstr_I (DECL_NAME (tem)); 1515 stabstr_C (':'); 1516 1517 if (use_gnu_debug_info_extensions 1518 && (TREE_PRIVATE (tem) || TREE_PROTECTED (tem) 1519 || TREE_CODE (tem) != FIELD_DECL)) 1520 { 1521 stabstr_C ('/'); 1522 stabstr_C (DECL_ACCESSIBILITY_CHAR (tem)); 1523 } 1524 1525 dbxout_type ((TREE_CODE (tem) == FIELD_DECL 1526 && DECL_BIT_FIELD_TYPE (tem)) 1527 ? DECL_BIT_FIELD_TYPE (tem) : TREE_TYPE (tem), 0); 1528 1529 if (TREE_CODE (tem) == VAR_DECL) 1530 { 1531 if (TREE_STATIC (tem) && use_gnu_debug_info_extensions) 1532 { 1533 tree name = DECL_ASSEMBLER_NAME (tem); 1534 1535 stabstr_C (':'); 1536 stabstr_I (name); 1537 stabstr_C (';'); 1538 } 1539 else 1540 /* If TEM is non-static, GDB won't understand it. */ 1541 stabstr_S (",0,0;"); 1542 } 1543 else 1544 { 1545 stabstr_C (','); 1546 stabstr_D (int_bit_position (tem)); 1547 stabstr_C (','); 1548 stabstr_D (tree_to_uhwi (DECL_SIZE (tem))); 1549 stabstr_C (';'); 1550 } 1551 } 1552 } 1553} 1554 1555/* Subroutine of `dbxout_type_methods'. Output debug info about the 1556 method described DECL. */ 1557 1558static void 1559dbxout_type_method_1 (tree decl) 1560{ 1561 char c1 = 'A', c2; 1562 1563 if (TREE_CODE (TREE_TYPE (decl)) == FUNCTION_TYPE) 1564 c2 = '?'; 1565 else /* it's a METHOD_TYPE. */ 1566 { 1567 tree firstarg = TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))); 1568 /* A for normal functions. 1569 B for `const' member functions. 1570 C for `volatile' member functions. 1571 D for `const volatile' member functions. */ 1572 if (TYPE_READONLY (TREE_TYPE (firstarg))) 1573 c1 += 1; 1574 if (TYPE_VOLATILE (TREE_TYPE (firstarg))) 1575 c1 += 2; 1576 1577 if (DECL_VINDEX (decl)) 1578 c2 = '*'; 1579 else 1580 c2 = '.'; 1581 } 1582 1583 /* ??? Output the mangled name, which contains an encoding of the 1584 method's type signature. May not be necessary anymore. */ 1585 stabstr_C (':'); 1586 stabstr_I (DECL_ASSEMBLER_NAME (decl)); 1587 stabstr_C (';'); 1588 stabstr_C (DECL_ACCESSIBILITY_CHAR (decl)); 1589 stabstr_C (c1); 1590 stabstr_C (c2); 1591 1592 if (DECL_VINDEX (decl) && tree_fits_shwi_p (DECL_VINDEX (decl))) 1593 { 1594 stabstr_D (tree_to_shwi (DECL_VINDEX (decl))); 1595 stabstr_C (';'); 1596 dbxout_type (DECL_CONTEXT (decl), 0); 1597 stabstr_C (';'); 1598 } 1599} 1600 1601/* Subroutine of `dbxout_type'. Output debug info about the methods defined 1602 in TYPE. */ 1603 1604static void 1605dbxout_type_methods (tree type) 1606{ 1607 /* C++: put out the method names and their parameter lists */ 1608 tree methods = TYPE_METHODS (type); 1609 tree fndecl; 1610 tree last; 1611 1612 if (methods == NULL_TREE) 1613 return; 1614 1615 if (TREE_CODE (methods) != TREE_VEC) 1616 fndecl = methods; 1617 else if (TREE_VEC_ELT (methods, 0) != NULL_TREE) 1618 fndecl = TREE_VEC_ELT (methods, 0); 1619 else 1620 fndecl = TREE_VEC_ELT (methods, 1); 1621 1622 while (fndecl) 1623 { 1624 int need_prefix = 1; 1625 1626 /* Group together all the methods for the same operation. 1627 These differ in the types of the arguments. */ 1628 for (last = NULL_TREE; 1629 fndecl && (last == NULL_TREE || DECL_NAME (fndecl) == DECL_NAME (last)); 1630 fndecl = DECL_CHAIN (fndecl)) 1631 /* Output the name of the field (after overloading), as 1632 well as the name of the field before overloading, along 1633 with its parameter list */ 1634 { 1635 /* Skip methods that aren't FUNCTION_DECLs. (In C++, these 1636 include TEMPLATE_DECLs.) The debugger doesn't know what 1637 to do with such entities anyhow. */ 1638 if (TREE_CODE (fndecl) != FUNCTION_DECL) 1639 continue; 1640 1641 CONTIN; 1642 1643 last = fndecl; 1644 1645 /* Also ignore abstract methods; those are only interesting to 1646 the DWARF backends. */ 1647 if (DECL_IGNORED_P (fndecl) || DECL_ABSTRACT_P (fndecl)) 1648 continue; 1649 1650 /* Redundantly output the plain name, since that's what gdb 1651 expects. */ 1652 if (need_prefix) 1653 { 1654 stabstr_I (DECL_NAME (fndecl)); 1655 stabstr_S ("::"); 1656 need_prefix = 0; 1657 } 1658 1659 dbxout_type (TREE_TYPE (fndecl), 0); 1660 dbxout_type_method_1 (fndecl); 1661 } 1662 if (!need_prefix) 1663 stabstr_C (';'); 1664 } 1665} 1666 1667/* Emit a "range" type specification, which has the form: 1668 "r<index type>;<lower bound>;<upper bound>;". 1669 TYPE is an INTEGER_TYPE, LOW and HIGH are the bounds. */ 1670 1671static void 1672dbxout_range_type (tree type, tree low, tree high) 1673{ 1674 stabstr_C ('r'); 1675 if (TREE_TYPE (type)) 1676 dbxout_type (TREE_TYPE (type), 0); 1677 else if (TREE_CODE (type) != INTEGER_TYPE) 1678 dbxout_type (type, 0); /* E.g. Pascal's ARRAY [BOOLEAN] of INTEGER */ 1679 else 1680 { 1681 /* Traditionally, we made sure 'int' was type 1, and builtin types 1682 were defined to be sub-ranges of int. Unfortunately, this 1683 does not allow us to distinguish true sub-ranges from integer 1684 types. So, instead we define integer (non-sub-range) types as 1685 sub-ranges of themselves. This matters for Chill. If this isn't 1686 a subrange type, then we want to define it in terms of itself. 1687 However, in C, this may be an anonymous integer type, and we don't 1688 want to emit debug info referring to it. Just calling 1689 dbxout_type_index won't work anyways, because the type hasn't been 1690 defined yet. We make this work for both cases by checked to see 1691 whether this is a defined type, referring to it if it is, and using 1692 'int' otherwise. */ 1693 if (TYPE_SYMTAB_ADDRESS (type) != 0) 1694 dbxout_type_index (type); 1695 else 1696 dbxout_type_index (integer_type_node); 1697 } 1698 1699 stabstr_C (';'); 1700 if (low && tree_fits_shwi_p (low)) 1701 { 1702 if (print_int_cst_bounds_in_octal_p (type, low, high)) 1703 stabstr_O (low); 1704 else 1705 stabstr_D (tree_to_shwi (low)); 1706 } 1707 else 1708 stabstr_C ('0'); 1709 1710 stabstr_C (';'); 1711 if (high && tree_fits_shwi_p (high)) 1712 { 1713 if (print_int_cst_bounds_in_octal_p (type, low, high)) 1714 stabstr_O (high); 1715 else 1716 stabstr_D (tree_to_shwi (high)); 1717 stabstr_C (';'); 1718 } 1719 else 1720 stabstr_S ("-1;"); 1721} 1722 1723 1724/* Output a reference to a type. If the type has not yet been 1725 described in the dbx output, output its definition now. 1726 For a type already defined, just refer to its definition 1727 using the type number. 1728 1729 If FULL is nonzero, and the type has been described only with 1730 a forward-reference, output the definition now. 1731 If FULL is zero in this case, just refer to the forward-reference 1732 using the number previously allocated. */ 1733 1734static void 1735dbxout_type (tree type, int full) 1736{ 1737 static int anonymous_type_number = 0; 1738 tree tem, main_variant, low, high; 1739 1740 if (TREE_CODE (type) == INTEGER_TYPE) 1741 { 1742 if (TREE_TYPE (type) == 0) 1743 { 1744 low = TYPE_MIN_VALUE (type); 1745 high = TYPE_MAX_VALUE (type); 1746 } 1747 1748 else if (subrange_type_for_debug_p (type, &low, &high)) 1749 ; 1750 1751 /* If this is a subtype that should not be emitted as a subrange type, 1752 use the base type. */ 1753 else 1754 { 1755 type = TREE_TYPE (type); 1756 low = TYPE_MIN_VALUE (type); 1757 high = TYPE_MAX_VALUE (type); 1758 } 1759 } 1760 1761 /* If there was an input error and we don't really have a type, 1762 avoid crashing and write something that is at least valid 1763 by assuming `int'. */ 1764 if (type == error_mark_node) 1765 type = integer_type_node; 1766 else 1767 { 1768 if (TYPE_NAME (type) 1769 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 1770 && TYPE_DECL_SUPPRESS_DEBUG (TYPE_NAME (type))) 1771 full = 0; 1772 } 1773 1774 /* Try to find the "main variant" with the same name. */ 1775 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 1776 && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) 1777 main_variant = TREE_TYPE (TYPE_NAME (type)); 1778 else 1779 main_variant = TYPE_MAIN_VARIANT (type); 1780 1781 /* If we are not using extensions, stabs does not distinguish const and 1782 volatile, so there is no need to make them separate types. */ 1783 if (!use_gnu_debug_info_extensions) 1784 type = main_variant; 1785 1786 if (TYPE_SYMTAB_ADDRESS (type) == 0) 1787 { 1788 /* Type has no dbx number assigned. Assign next available number. */ 1789 TYPE_SYMTAB_ADDRESS (type) = next_type_number++; 1790 1791 /* Make sure type vector is long enough to record about this type. */ 1792 1793 if (next_type_number == typevec_len) 1794 { 1795 typevec = GGC_RESIZEVEC (struct typeinfo, typevec, typevec_len * 2); 1796 memset (typevec + typevec_len, 0, typevec_len * sizeof typevec[0]); 1797 typevec_len *= 2; 1798 } 1799 1800#ifdef DBX_USE_BINCL 1801 emit_pending_bincls_if_required (); 1802 typevec[TYPE_SYMTAB_ADDRESS (type)].file_number 1803 = current_file->file_number; 1804 typevec[TYPE_SYMTAB_ADDRESS (type)].type_number 1805 = current_file->next_type_number++; 1806#endif 1807 } 1808 1809 if (flag_debug_only_used_symbols) 1810 { 1811 if ((TREE_CODE (type) == RECORD_TYPE 1812 || TREE_CODE (type) == UNION_TYPE 1813 || TREE_CODE (type) == QUAL_UNION_TYPE 1814 || TREE_CODE (type) == ENUMERAL_TYPE) 1815 && TYPE_STUB_DECL (type) 1816 && DECL_P (TYPE_STUB_DECL (type)) 1817 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type))) 1818 debug_queue_symbol (TYPE_STUB_DECL (type)); 1819 else if (TYPE_NAME (type) 1820 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) 1821 debug_queue_symbol (TYPE_NAME (type)); 1822 } 1823 1824 /* Output the number of this type, to refer to it. */ 1825 dbxout_type_index (type); 1826 1827#ifdef DBX_TYPE_DEFINED 1828 if (DBX_TYPE_DEFINED (type)) 1829 return; 1830#endif 1831 1832 /* If this type's definition has been output or is now being output, 1833 that is all. */ 1834 1835 switch (typevec[TYPE_SYMTAB_ADDRESS (type)].status) 1836 { 1837 case TYPE_UNSEEN: 1838 break; 1839 case TYPE_XREF: 1840 /* If we have already had a cross reference, 1841 and either that's all we want or that's the best we could do, 1842 don't repeat the cross reference. 1843 Sun dbx crashes if we do. */ 1844 if (! full || !COMPLETE_TYPE_P (type) 1845 /* No way in DBX fmt to describe a variable size. */ 1846 || ! tree_fits_uhwi_p (TYPE_SIZE (type))) 1847 return; 1848 break; 1849 case TYPE_DEFINED: 1850 return; 1851 } 1852 1853#ifdef DBX_NO_XREFS 1854 /* For systems where dbx output does not allow the `=xsNAME:' syntax, 1855 leave the type-number completely undefined rather than output 1856 a cross-reference. If we have already used GNU debug info extensions, 1857 then it is OK to output a cross reference. This is necessary to get 1858 proper C++ debug output. */ 1859 if ((TREE_CODE (type) == RECORD_TYPE || TREE_CODE (type) == UNION_TYPE 1860 || TREE_CODE (type) == QUAL_UNION_TYPE 1861 || TREE_CODE (type) == ENUMERAL_TYPE) 1862 && ! use_gnu_debug_info_extensions) 1863 /* We must use the same test here as we use twice below when deciding 1864 whether to emit a cross-reference. */ 1865 if ((TYPE_NAME (type) != 0 1866 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 1867 && DECL_IGNORED_P (TYPE_NAME (type))) 1868 && !full) 1869 || !COMPLETE_TYPE_P (type) 1870 /* No way in DBX fmt to describe a variable size. */ 1871 || ! tree_fits_uhwi_p (TYPE_SIZE (type))) 1872 { 1873 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF; 1874 return; 1875 } 1876#endif 1877 1878 /* Output a definition now. */ 1879 stabstr_C ('='); 1880 1881 /* Mark it as defined, so that if it is self-referent 1882 we will not get into an infinite recursion of definitions. */ 1883 1884 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_DEFINED; 1885 1886 /* If this type is a variant of some other, hand off. Types with 1887 different names are usefully distinguished. We only distinguish 1888 cv-qualified types if we're using extensions. */ 1889 if (TYPE_READONLY (type) > TYPE_READONLY (main_variant)) 1890 { 1891 stabstr_C ('k'); 1892 dbxout_type (build_type_variant (type, 0, TYPE_VOLATILE (type)), 0); 1893 return; 1894 } 1895 else if (TYPE_VOLATILE (type) > TYPE_VOLATILE (main_variant)) 1896 { 1897 stabstr_C ('B'); 1898 dbxout_type (build_type_variant (type, TYPE_READONLY (type), 0), 0); 1899 return; 1900 } 1901 else if (main_variant != TYPE_MAIN_VARIANT (type)) 1902 { 1903 if (flag_debug_only_used_symbols) 1904 { 1905 tree orig_type = DECL_ORIGINAL_TYPE (TYPE_NAME (type)); 1906 1907 if ((TREE_CODE (orig_type) == RECORD_TYPE 1908 || TREE_CODE (orig_type) == UNION_TYPE 1909 || TREE_CODE (orig_type) == QUAL_UNION_TYPE 1910 || TREE_CODE (orig_type) == ENUMERAL_TYPE) 1911 && TYPE_STUB_DECL (orig_type) 1912 && ! DECL_IGNORED_P (TYPE_STUB_DECL (orig_type))) 1913 debug_queue_symbol (TYPE_STUB_DECL (orig_type)); 1914 } 1915 /* 'type' is a typedef; output the type it refers to. */ 1916 dbxout_type (DECL_ORIGINAL_TYPE (TYPE_NAME (type)), 0); 1917 return; 1918 } 1919 /* else continue. */ 1920 1921 switch (TREE_CODE (type)) 1922 { 1923 case VOID_TYPE: 1924 case NULLPTR_TYPE: 1925 case LANG_TYPE: 1926 /* For a void type, just define it as itself; i.e., "5=5". 1927 This makes us consider it defined 1928 without saying what it is. The debugger will make it 1929 a void type when the reference is seen, and nothing will 1930 ever override that default. */ 1931 dbxout_type_index (type); 1932 break; 1933 1934 case INTEGER_TYPE: 1935 if (type == char_type_node && ! TYPE_UNSIGNED (type)) 1936 { 1937 /* Output the type `char' as a subrange of itself! 1938 I don't understand this definition, just copied it 1939 from the output of pcc. 1940 This used to use `r2' explicitly and we used to 1941 take care to make sure that `char' was type number 2. */ 1942 stabstr_C ('r'); 1943 dbxout_type_index (type); 1944 stabstr_S (";0;127;"); 1945 } 1946 1947 /* If this is a subtype of another integer type, always prefer to 1948 write it as a subtype. */ 1949 else if (TREE_TYPE (type) != 0 1950 && TREE_CODE (TREE_TYPE (type)) == INTEGER_TYPE) 1951 { 1952 /* If the size is non-standard, say what it is if we can use 1953 GDB extensions. */ 1954 1955 if (use_gnu_debug_info_extensions 1956 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) 1957 { 1958 stabstr_S ("@s"); 1959 stabstr_D (TYPE_PRECISION (type)); 1960 stabstr_C (';'); 1961 } 1962 1963 dbxout_range_type (type, low, high); 1964 } 1965 1966 else 1967 { 1968 /* If the size is non-standard, say what it is if we can use 1969 GDB extensions. */ 1970 1971 if (use_gnu_debug_info_extensions 1972 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) 1973 { 1974 stabstr_S ("@s"); 1975 stabstr_D (TYPE_PRECISION (type)); 1976 stabstr_C (';'); 1977 } 1978 1979 if (print_int_cst_bounds_in_octal_p (type, low, high)) 1980 { 1981 stabstr_C ('r'); 1982 1983 /* If this type derives from another type, output type index of 1984 parent type. This is particularly important when parent type 1985 is an enumerated type, because not generating the parent type 1986 index would transform the definition of this enumerated type 1987 into a plain unsigned type. */ 1988 if (TREE_TYPE (type) != 0) 1989 dbxout_type_index (TREE_TYPE (type)); 1990 else 1991 dbxout_type_index (type); 1992 1993 stabstr_C (';'); 1994 stabstr_O (low); 1995 stabstr_C (';'); 1996 stabstr_O (high); 1997 stabstr_C (';'); 1998 } 1999 2000 else 2001 /* Output other integer types as subranges of `int'. */ 2002 dbxout_range_type (type, low, high); 2003 } 2004 2005 break; 2006 2007 case REAL_TYPE: 2008 case FIXED_POINT_TYPE: 2009 /* This used to say `r1' and we used to take care 2010 to make sure that `int' was type number 1. */ 2011 stabstr_C ('r'); 2012 dbxout_type_index (integer_type_node); 2013 stabstr_C (';'); 2014 stabstr_D (int_size_in_bytes (type)); 2015 stabstr_S (";0;"); 2016 break; 2017 2018 case BOOLEAN_TYPE: 2019 if (use_gnu_debug_info_extensions) 2020 { 2021 stabstr_S ("@s"); 2022 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type)); 2023 stabstr_S (";-16;"); 2024 } 2025 else /* Define as enumeral type (False, True) */ 2026 stabstr_S ("eFalse:0,True:1,;"); 2027 break; 2028 2029 case COMPLEX_TYPE: 2030 /* Differs from the REAL_TYPE by its new data type number. 2031 R3 is NF_COMPLEX. We don't try to use any of the other NF_* 2032 codes since gdb doesn't care anyway. */ 2033 2034 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) 2035 { 2036 stabstr_S ("R3;"); 2037 stabstr_D (2 * int_size_in_bytes (TREE_TYPE (type))); 2038 stabstr_S (";0;"); 2039 } 2040 else 2041 { 2042 /* Output a complex integer type as a structure, 2043 pending some other way to do it. */ 2044 stabstr_C ('s'); 2045 stabstr_D (int_size_in_bytes (type)); 2046 2047 stabstr_S ("real:"); 2048 dbxout_type (TREE_TYPE (type), 0); 2049 stabstr_S (",0,"); 2050 stabstr_D (TYPE_PRECISION (TREE_TYPE (type))); 2051 2052 stabstr_S (";imag:"); 2053 dbxout_type (TREE_TYPE (type), 0); 2054 stabstr_C (','); 2055 stabstr_D (TYPE_PRECISION (TREE_TYPE (type))); 2056 stabstr_C (','); 2057 stabstr_D (TYPE_PRECISION (TREE_TYPE (type))); 2058 stabstr_S (";;"); 2059 } 2060 break; 2061 2062 case ARRAY_TYPE: 2063 /* Make arrays of packed bits look like bitstrings for chill. */ 2064 if (TYPE_PACKED (type) && use_gnu_debug_info_extensions) 2065 { 2066 stabstr_S ("@s"); 2067 stabstr_D (BITS_PER_UNIT * int_size_in_bytes (type)); 2068 stabstr_S (";@S;S"); 2069 dbxout_type (TYPE_DOMAIN (type), 0); 2070 break; 2071 } 2072 2073 /* Output "a" followed by a range type definition 2074 for the index type of the array 2075 followed by a reference to the target-type. 2076 ar1;0;N;M for a C array of type M and size N+1. */ 2077 /* Check if a character string type, which in Chill is 2078 different from an array of characters. */ 2079 if (TYPE_STRING_FLAG (type) && use_gnu_debug_info_extensions) 2080 { 2081 stabstr_S ("@S;"); 2082 } 2083 tem = TYPE_DOMAIN (type); 2084 if (tem == NULL) 2085 { 2086 stabstr_S ("ar"); 2087 dbxout_type_index (integer_type_node); 2088 stabstr_S (";0;-1;"); 2089 } 2090 else 2091 { 2092 stabstr_C ('a'); 2093 dbxout_range_type (tem, TYPE_MIN_VALUE (tem), TYPE_MAX_VALUE (tem)); 2094 } 2095 2096 dbxout_type (TREE_TYPE (type), 0); 2097 break; 2098 2099 case VECTOR_TYPE: 2100 /* Make vectors look like an array. */ 2101 if (use_gnu_debug_info_extensions) 2102 stabstr_S ("@V;"); 2103 2104 /* Output "a" followed by a range type definition 2105 for the index type of the array 2106 followed by a reference to the target-type. 2107 ar1;0;N;M for a C array of type M and size N+1. */ 2108 stabstr_C ('a'); 2109 dbxout_range_type (integer_type_node, size_zero_node, 2110 size_int (TYPE_VECTOR_SUBPARTS (type) - 1)); 2111 2112 dbxout_type (TREE_TYPE (type), 0); 2113 break; 2114 2115 case RECORD_TYPE: 2116 case UNION_TYPE: 2117 case QUAL_UNION_TYPE: 2118 { 2119 tree binfo = TYPE_BINFO (type); 2120 2121 /* Output a structure type. We must use the same test here as we 2122 use in the DBX_NO_XREFS case above. */ 2123 if ((TYPE_NAME (type) != 0 2124 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 2125 && DECL_IGNORED_P (TYPE_NAME (type))) 2126 && !full) 2127 || !COMPLETE_TYPE_P (type) 2128 /* No way in DBX fmt to describe a variable size. */ 2129 || ! tree_fits_uhwi_p (TYPE_SIZE (type))) 2130 { 2131 /* If the type is just a cross reference, output one 2132 and mark the type as partially described. 2133 If it later becomes defined, we will output 2134 its real definition. 2135 If the type has a name, don't nest its definition within 2136 another type's definition; instead, output an xref 2137 and let the definition come when the name is defined. */ 2138 stabstr_S ((TREE_CODE (type) == RECORD_TYPE) ? "xs" : "xu"); 2139 if (TYPE_IDENTIFIER (type)) 2140 { 2141 /* Note that the C frontend creates for anonymous variable 2142 length records/unions TYPE_NAME with DECL_NAME NULL. */ 2143 dbxout_type_name (type); 2144 } 2145 else 2146 { 2147 stabstr_S ("$$"); 2148 stabstr_D (anonymous_type_number++); 2149 } 2150 2151 stabstr_C (':'); 2152 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF; 2153 break; 2154 } 2155 2156 /* Identify record or union, and print its size. */ 2157 stabstr_C ((TREE_CODE (type) == RECORD_TYPE) ? 's' : 'u'); 2158 stabstr_D (int_size_in_bytes (type)); 2159 2160 if (binfo) 2161 { 2162 int i; 2163 tree child; 2164 vec<tree, va_gc> *accesses = BINFO_BASE_ACCESSES (binfo); 2165 2166 if (use_gnu_debug_info_extensions) 2167 { 2168 if (BINFO_N_BASE_BINFOS (binfo)) 2169 { 2170 stabstr_C ('!'); 2171 stabstr_U (BINFO_N_BASE_BINFOS (binfo)); 2172 stabstr_C (','); 2173 } 2174 } 2175 for (i = 0; BINFO_BASE_ITERATE (binfo, i, child); i++) 2176 { 2177 tree access = (accesses ? (*accesses)[i] : access_public_node); 2178 2179 if (use_gnu_debug_info_extensions) 2180 { 2181 stabstr_C (BINFO_VIRTUAL_P (child) ? '1' : '0'); 2182 stabstr_C (access == access_public_node ? '2' : 2183 access == access_protected_node 2184 ? '1' :'0'); 2185 if (BINFO_VIRTUAL_P (child) 2186 && (lang_GNU_CXX () 2187 || strcmp (lang_hooks.name, "GNU Objective-C++") == 0)) 2188 /* For a virtual base, print the (negative) 2189 offset within the vtable where we must look 2190 to find the necessary adjustment. */ 2191 stabstr_D 2192 (tree_to_shwi (BINFO_VPTR_FIELD (child)) 2193 * BITS_PER_UNIT); 2194 else 2195 stabstr_D (tree_to_shwi (BINFO_OFFSET (child)) 2196 * BITS_PER_UNIT); 2197 stabstr_C (','); 2198 dbxout_type (BINFO_TYPE (child), 0); 2199 stabstr_C (';'); 2200 } 2201 else 2202 { 2203 /* Print out the base class information with 2204 fields which have the same names at the types 2205 they hold. */ 2206 dbxout_type_name (BINFO_TYPE (child)); 2207 stabstr_C (':'); 2208 dbxout_type (BINFO_TYPE (child), full); 2209 stabstr_C (','); 2210 stabstr_D (tree_to_shwi (BINFO_OFFSET (child)) 2211 * BITS_PER_UNIT); 2212 stabstr_C (','); 2213 stabstr_D 2214 (tree_to_shwi (TYPE_SIZE (BINFO_TYPE (child))) 2215 * BITS_PER_UNIT); 2216 stabstr_C (';'); 2217 } 2218 } 2219 } 2220 } 2221 2222 /* Write out the field declarations. */ 2223 dbxout_type_fields (type); 2224 if (use_gnu_debug_info_extensions && TYPE_METHODS (type) != NULL_TREE) 2225 { 2226 dbxout_type_methods (type); 2227 } 2228 2229 stabstr_C (';'); 2230 2231 if (use_gnu_debug_info_extensions && TREE_CODE (type) == RECORD_TYPE 2232 /* Avoid the ~ if we don't really need it--it confuses dbx. */ 2233 && TYPE_VFIELD (type)) 2234 { 2235 2236 /* We need to write out info about what field this class 2237 uses as its "main" vtable pointer field, because if this 2238 field is inherited from a base class, GDB cannot necessarily 2239 figure out which field it's using in time. */ 2240 stabstr_S ("~%"); 2241 dbxout_type (DECL_FCONTEXT (TYPE_VFIELD (type)), 0); 2242 stabstr_C (';'); 2243 } 2244 break; 2245 2246 case ENUMERAL_TYPE: 2247 /* We must use the same test here as we use in the DBX_NO_XREFS case 2248 above. We simplify it a bit since an enum will never have a variable 2249 size. */ 2250 if ((TYPE_NAME (type) != 0 2251 && ! (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 2252 && DECL_IGNORED_P (TYPE_NAME (type))) 2253 && !full) 2254 || !COMPLETE_TYPE_P (type)) 2255 { 2256 stabstr_S ("xe"); 2257 dbxout_type_name (type); 2258 typevec[TYPE_SYMTAB_ADDRESS (type)].status = TYPE_XREF; 2259 stabstr_C (':'); 2260 return; 2261 } 2262 if (use_gnu_debug_info_extensions 2263 && TYPE_PRECISION (type) != TYPE_PRECISION (integer_type_node)) 2264 { 2265 stabstr_S ("@s"); 2266 stabstr_D (TYPE_PRECISION (type)); 2267 stabstr_C (';'); 2268 } 2269 2270 stabstr_C ('e'); 2271 for (tem = TYPE_VALUES (type); tem; tem = TREE_CHAIN (tem)) 2272 { 2273 tree value = TREE_VALUE (tem); 2274 2275 stabstr_I (TREE_PURPOSE (tem)); 2276 stabstr_C (':'); 2277 2278 if (TREE_CODE (value) == CONST_DECL) 2279 value = DECL_INITIAL (value); 2280 2281 if (cst_and_fits_in_hwi (value)) 2282 stabstr_D (TREE_INT_CST_LOW (value)); 2283 else 2284 stabstr_O (value); 2285 2286 stabstr_C (','); 2287 if (TREE_CHAIN (tem) != 0) 2288 CONTIN; 2289 } 2290 2291 stabstr_C (';'); 2292 break; 2293 2294 case POINTER_TYPE: 2295 stabstr_C ('*'); 2296 dbxout_type (TREE_TYPE (type), 0); 2297 break; 2298 2299 case METHOD_TYPE: 2300 if (use_gnu_debug_info_extensions) 2301 { 2302 stabstr_C ('#'); 2303 2304 /* Write the argument types out longhand. */ 2305 dbxout_type (TYPE_METHOD_BASETYPE (type), 0); 2306 stabstr_C (','); 2307 dbxout_type (TREE_TYPE (type), 0); 2308 dbxout_args (TYPE_ARG_TYPES (type)); 2309 stabstr_C (';'); 2310 } 2311 else 2312 /* Treat it as a function type. */ 2313 dbxout_type (TREE_TYPE (type), 0); 2314 break; 2315 2316 case OFFSET_TYPE: 2317 if (use_gnu_debug_info_extensions) 2318 { 2319 stabstr_C ('@'); 2320 dbxout_type (TYPE_OFFSET_BASETYPE (type), 0); 2321 stabstr_C (','); 2322 dbxout_type (TREE_TYPE (type), 0); 2323 } 2324 else 2325 /* Should print as an int, because it is really just an offset. */ 2326 dbxout_type (integer_type_node, 0); 2327 break; 2328 2329 case REFERENCE_TYPE: 2330 if (use_gnu_debug_info_extensions) 2331 { 2332 stabstr_C ('&'); 2333 } 2334 else 2335 stabstr_C ('*'); 2336 dbxout_type (TREE_TYPE (type), 0); 2337 break; 2338 2339 case FUNCTION_TYPE: 2340 stabstr_C ('f'); 2341 dbxout_type (TREE_TYPE (type), 0); 2342 break; 2343 2344 case POINTER_BOUNDS_TYPE: 2345 /* No debug info for pointer bounds type supported yet. */ 2346 break; 2347 2348 default: 2349 /* A C++ function with deduced return type can have a TEMPLATE_TYPE_PARM 2350 named 'auto' in its type. 2351 No debug info for TEMPLATE_TYPE_PARM type supported yet. */ 2352 if (lang_GNU_CXX ()) 2353 { 2354 tree name = TYPE_IDENTIFIER (type); 2355 if (name == get_identifier ("auto") 2356 || name == get_identifier ("decltype(auto)")) 2357 break; 2358 } 2359 2360 gcc_unreachable (); 2361 } 2362} 2363 2364/* Return nonzero if the given type represents an integer whose bounds 2365 should be printed in octal format. */ 2366 2367static bool 2368print_int_cst_bounds_in_octal_p (tree type, tree low, tree high) 2369{ 2370 /* If we can use GDB extensions and the size is wider than a long 2371 (the size used by GDB to read them) or we may have trouble writing 2372 the bounds the usual way, write them in octal. Note the test is for 2373 the *target's* size of "long", not that of the host. The host test 2374 is just to make sure we can write it out in case the host wide int 2375 is narrower than the target "long". 2376 2377 For unsigned types, we use octal if they are the same size or larger. 2378 This is because we print the bounds as signed decimal, and hence they 2379 can't span same size unsigned types. */ 2380 2381 if (use_gnu_debug_info_extensions 2382 && low && TREE_CODE (low) == INTEGER_CST 2383 && high && TREE_CODE (high) == INTEGER_CST 2384 && (TYPE_PRECISION (type) > TYPE_PRECISION (integer_type_node) 2385 || ((TYPE_PRECISION (type) == TYPE_PRECISION (integer_type_node)) 2386 && TYPE_UNSIGNED (type)) 2387 || TYPE_PRECISION (type) > HOST_BITS_PER_WIDE_INT 2388 || (TYPE_PRECISION (type) == HOST_BITS_PER_WIDE_INT 2389 && TYPE_UNSIGNED (type)))) 2390 return TRUE; 2391 else 2392 return FALSE; 2393} 2394 2395/* Output the name of type TYPE, with no punctuation. 2396 Such names can be set up either by typedef declarations 2397 or by struct, enum and union tags. */ 2398 2399static void 2400dbxout_type_name (tree type) 2401{ 2402 tree t = TYPE_NAME (type); 2403 2404 gcc_assert (t); 2405 switch (TREE_CODE (t)) 2406 { 2407 case IDENTIFIER_NODE: 2408 break; 2409 case TYPE_DECL: 2410 t = DECL_NAME (t); 2411 break; 2412 default: 2413 gcc_unreachable (); 2414 } 2415 2416 stabstr_I (t); 2417} 2418 2419/* Output leading leading struct or class names needed for qualifying 2420 type whose scope is limited to a struct or class. */ 2421 2422static void 2423dbxout_class_name_qualifiers (tree decl) 2424{ 2425 tree context = decl_type_context (decl); 2426 2427 if (context != NULL_TREE 2428 && TREE_CODE (context) == RECORD_TYPE 2429 && TYPE_NAME (context) != 0 2430 && (TREE_CODE (TYPE_NAME (context)) == IDENTIFIER_NODE 2431 || (DECL_NAME (TYPE_NAME (context)) != 0))) 2432 { 2433 tree name = TYPE_NAME (context); 2434 2435 if (TREE_CODE (name) == TYPE_DECL) 2436 { 2437 dbxout_class_name_qualifiers (name); 2438 name = DECL_NAME (name); 2439 } 2440 stabstr_I (name); 2441 stabstr_S ("::"); 2442 } 2443} 2444 2445/* This is a specialized subset of expand_expr for use by dbxout_symbol in 2446 evaluating DECL_VALUE_EXPR. In particular, we stop if we find decls that 2447 haven't been expanded, or if the expression is getting so complex we won't 2448 be able to represent it in stabs anyway. Returns NULL on failure. */ 2449 2450static rtx 2451dbxout_expand_expr (tree expr) 2452{ 2453 switch (TREE_CODE (expr)) 2454 { 2455 case VAR_DECL: 2456 /* We can't handle emulated tls variables, because the address is an 2457 offset to the return value of __emutls_get_address, and there is no 2458 way to express that in stabs. Also, there are name mangling issues 2459 here. We end up with references to undefined symbols if we don't 2460 disable debug info for these variables. */ 2461 if (!targetm.have_tls && DECL_THREAD_LOCAL_P (expr)) 2462 return NULL; 2463 if (TREE_STATIC (expr) 2464 && !TREE_ASM_WRITTEN (expr) 2465 && !DECL_HAS_VALUE_EXPR_P (expr) 2466 && !TREE_PUBLIC (expr) 2467 && DECL_RTL_SET_P (expr) 2468 && MEM_P (DECL_RTL (expr))) 2469 { 2470 /* If this is a var that might not be actually output, 2471 return NULL, otherwise stabs might reference an undefined 2472 symbol. */ 2473 varpool_node *node = varpool_node::get (expr); 2474 if (!node || !node->definition) 2475 return NULL; 2476 } 2477 /* FALLTHRU */ 2478 2479 case PARM_DECL: 2480 case RESULT_DECL: 2481 if (DECL_HAS_VALUE_EXPR_P (expr)) 2482 return dbxout_expand_expr (DECL_VALUE_EXPR (expr)); 2483 /* FALLTHRU */ 2484 2485 case CONST_DECL: 2486 return DECL_RTL_IF_SET (expr); 2487 2488 case INTEGER_CST: 2489 return expand_expr (expr, NULL_RTX, VOIDmode, EXPAND_INITIALIZER); 2490 2491 case COMPONENT_REF: 2492 case ARRAY_REF: 2493 case ARRAY_RANGE_REF: 2494 case BIT_FIELD_REF: 2495 { 2496 machine_mode mode; 2497 HOST_WIDE_INT bitsize, bitpos; 2498 tree offset, tem; 2499 int volatilep = 0, unsignedp = 0; 2500 rtx x; 2501 2502 tem = get_inner_reference (expr, &bitsize, &bitpos, &offset, 2503 &mode, &unsignedp, &volatilep, true); 2504 2505 x = dbxout_expand_expr (tem); 2506 if (x == NULL || !MEM_P (x)) 2507 return NULL; 2508 if (offset != NULL) 2509 { 2510 if (!tree_fits_shwi_p (offset)) 2511 return NULL; 2512 x = adjust_address_nv (x, mode, tree_to_shwi (offset)); 2513 } 2514 if (bitpos != 0) 2515 x = adjust_address_nv (x, mode, bitpos / BITS_PER_UNIT); 2516 2517 return x; 2518 } 2519 2520 default: 2521 return NULL; 2522 } 2523} 2524 2525/* Helper function for output_used_types. Queue one entry from the 2526 used types hash to be output. */ 2527 2528bool 2529output_used_types_helper (tree const &type, vec<tree> *types_p) 2530{ 2531 if ((TREE_CODE (type) == RECORD_TYPE 2532 || TREE_CODE (type) == UNION_TYPE 2533 || TREE_CODE (type) == QUAL_UNION_TYPE 2534 || TREE_CODE (type) == ENUMERAL_TYPE) 2535 && TYPE_STUB_DECL (type) 2536 && DECL_P (TYPE_STUB_DECL (type)) 2537 && ! DECL_IGNORED_P (TYPE_STUB_DECL (type))) 2538 types_p->quick_push (TYPE_STUB_DECL (type)); 2539 else if (TYPE_NAME (type) 2540 && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) 2541 types_p->quick_push (TYPE_NAME (type)); 2542 2543 return true; 2544} 2545 2546/* This is a qsort callback which sorts types and declarations into a 2547 predictable order (types, then declarations, sorted by UID 2548 within). */ 2549 2550static int 2551output_types_sort (const void *pa, const void *pb) 2552{ 2553 const tree lhs = *((const tree *)pa); 2554 const tree rhs = *((const tree *)pb); 2555 2556 if (TYPE_P (lhs)) 2557 { 2558 if (TYPE_P (rhs)) 2559 return TYPE_UID (lhs) - TYPE_UID (rhs); 2560 else 2561 return 1; 2562 } 2563 else 2564 { 2565 if (TYPE_P (rhs)) 2566 return -1; 2567 else 2568 return DECL_UID (lhs) - DECL_UID (rhs); 2569 } 2570} 2571 2572 2573/* Force all types used by this function to be output in debug 2574 information. */ 2575 2576static void 2577output_used_types (void) 2578{ 2579 if (cfun && cfun->used_types_hash) 2580 { 2581 vec<tree> types; 2582 int i; 2583 tree type; 2584 2585 types.create (cfun->used_types_hash->elements ()); 2586 cfun->used_types_hash->traverse<vec<tree> *, output_used_types_helper> 2587 (&types); 2588 2589 /* Sort by UID to prevent dependence on hash table ordering. */ 2590 types.qsort (output_types_sort); 2591 2592 FOR_EACH_VEC_ELT (types, i, type) 2593 debug_queue_symbol (type); 2594 2595 types.release (); 2596 } 2597} 2598 2599/* Output a .stabs for the symbol defined by DECL, 2600 which must be a ..._DECL node in the normal namespace. 2601 It may be a CONST_DECL, a FUNCTION_DECL, a PARM_DECL or a VAR_DECL. 2602 LOCAL is nonzero if the scope is less than the entire file. 2603 Return 1 if a stabs might have been emitted. */ 2604 2605int 2606dbxout_symbol (tree decl, int local ATTRIBUTE_UNUSED) 2607{ 2608 tree type = TREE_TYPE (decl); 2609 tree context = NULL_TREE; 2610 int result = 0; 2611 rtx decl_rtl; 2612 2613 /* "Intercept" dbxout_symbol() calls like we do all debug_hooks. */ 2614 ++debug_nesting; 2615 2616 /* Ignore nameless syms, but don't ignore type tags. */ 2617 2618 if ((DECL_NAME (decl) == 0 && TREE_CODE (decl) != TYPE_DECL) 2619 || DECL_IGNORED_P (decl)) 2620 DBXOUT_DECR_NESTING_AND_RETURN (0); 2621 2622 /* If we are to generate only the symbols actually used then such 2623 symbol nodes are flagged with TREE_USED. Ignore any that 2624 aren't flagged as TREE_USED. */ 2625 2626 if (flag_debug_only_used_symbols 2627 && (!TREE_USED (decl) 2628 && (TREE_CODE (decl) != VAR_DECL || !DECL_INITIAL (decl)))) 2629 DBXOUT_DECR_NESTING_AND_RETURN (0); 2630 2631 /* If dbxout_init has not yet run, queue this symbol for later. */ 2632 if (!typevec) 2633 { 2634 preinit_symbols = tree_cons (0, decl, preinit_symbols); 2635 DBXOUT_DECR_NESTING_AND_RETURN (0); 2636 } 2637 2638 if (flag_debug_only_used_symbols) 2639 { 2640 tree t; 2641 2642 /* We now have a used symbol. We need to generate the info for 2643 the symbol's type in addition to the symbol itself. These 2644 type symbols are queued to be generated after were done with 2645 the symbol itself (otherwise they would fight over the 2646 stabstr obstack). 2647 2648 Note, because the TREE_TYPE(type) might be something like a 2649 pointer to a named type we need to look for the first name 2650 we see following the TREE_TYPE chain. */ 2651 2652 t = type; 2653 while (POINTER_TYPE_P (t)) 2654 t = TREE_TYPE (t); 2655 2656 /* RECORD_TYPE, UNION_TYPE, QUAL_UNION_TYPE, and ENUMERAL_TYPE 2657 need special treatment. The TYPE_STUB_DECL field in these 2658 types generally represents the tag name type we want to 2659 output. In addition there could be a typedef type with 2660 a different name. In that case we also want to output 2661 that. */ 2662 2663 if (TREE_CODE (t) == RECORD_TYPE 2664 || TREE_CODE (t) == UNION_TYPE 2665 || TREE_CODE (t) == QUAL_UNION_TYPE 2666 || TREE_CODE (t) == ENUMERAL_TYPE) 2667 { 2668 if (TYPE_STUB_DECL (t) 2669 && TYPE_STUB_DECL (t) != decl 2670 && DECL_P (TYPE_STUB_DECL (t)) 2671 && ! DECL_IGNORED_P (TYPE_STUB_DECL (t))) 2672 { 2673 debug_queue_symbol (TYPE_STUB_DECL (t)); 2674 if (TYPE_NAME (t) 2675 && TYPE_NAME (t) != TYPE_STUB_DECL (t) 2676 && TYPE_NAME (t) != decl 2677 && DECL_P (TYPE_NAME (t))) 2678 debug_queue_symbol (TYPE_NAME (t)); 2679 } 2680 } 2681 else if (TYPE_NAME (t) 2682 && TYPE_NAME (t) != decl 2683 && DECL_P (TYPE_NAME (t))) 2684 debug_queue_symbol (TYPE_NAME (t)); 2685 } 2686 2687 emit_pending_bincls_if_required (); 2688 2689 switch (TREE_CODE (decl)) 2690 { 2691 case CONST_DECL: 2692 /* Enum values are defined by defining the enum type. */ 2693 break; 2694 2695 case FUNCTION_DECL: 2696 decl_rtl = DECL_RTL_IF_SET (decl); 2697 if (!decl_rtl) 2698 DBXOUT_DECR_NESTING_AND_RETURN (0); 2699 if (DECL_EXTERNAL (decl)) 2700 break; 2701 /* Don't mention a nested function under its parent. */ 2702 context = decl_function_context (decl); 2703 if (context == current_function_decl) 2704 break; 2705 /* Don't mention an inline instance of a nested function. */ 2706 if (context && DECL_FROM_INLINE (decl)) 2707 break; 2708 if (!MEM_P (decl_rtl) 2709 || GET_CODE (XEXP (decl_rtl, 0)) != SYMBOL_REF) 2710 break; 2711 2712 if (flag_debug_only_used_symbols) 2713 output_used_types (); 2714 2715 dbxout_begin_complex_stabs (); 2716 stabstr_I (DECL_ASSEMBLER_NAME (decl)); 2717 stabstr_S (TREE_PUBLIC (decl) ? ":F" : ":f"); 2718 result = 1; 2719 2720 if (TREE_TYPE (type)) 2721 dbxout_type (TREE_TYPE (type), 0); 2722 else 2723 dbxout_type (void_type_node, 0); 2724 2725 /* For a nested function, when that function is compiled, 2726 mention the containing function name 2727 as well as (since dbx wants it) our own assembler-name. */ 2728 if (context != 0) 2729 { 2730 stabstr_C (','); 2731 stabstr_I (DECL_ASSEMBLER_NAME (decl)); 2732 stabstr_C (','); 2733 stabstr_I (DECL_NAME (context)); 2734 } 2735 2736 dbxout_finish_complex_stabs (decl, N_FUN, XEXP (decl_rtl, 0), 0, 0); 2737 break; 2738 2739 case TYPE_DECL: 2740 /* Don't output the same typedef twice. 2741 And don't output what language-specific stuff doesn't want output. */ 2742 if (TREE_ASM_WRITTEN (decl) || TYPE_DECL_SUPPRESS_DEBUG (decl)) 2743 DBXOUT_DECR_NESTING_AND_RETURN (0); 2744 2745 /* Don't output typedefs for types with magic type numbers (XCOFF). */ 2746#ifdef DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER 2747 { 2748 int fundamental_type_number = 2749 DBX_ASSIGN_FUNDAMENTAL_TYPE_NUMBER (decl); 2750 2751 if (fundamental_type_number != 0) 2752 { 2753 TREE_ASM_WRITTEN (decl) = 1; 2754 TYPE_SYMTAB_ADDRESS (TREE_TYPE (decl)) = fundamental_type_number; 2755 DBXOUT_DECR_NESTING_AND_RETURN (0); 2756 } 2757 } 2758#endif 2759 FORCE_TEXT; 2760 result = 1; 2761 { 2762 int tag_needed = 1; 2763 int did_output = 0; 2764 2765 if (DECL_NAME (decl)) 2766 { 2767 /* Nonzero means we must output a tag as well as a typedef. */ 2768 tag_needed = 0; 2769 2770 /* Handle the case of a C++ structure or union 2771 where the TYPE_NAME is a TYPE_DECL 2772 which gives both a typedef name and a tag. */ 2773 /* dbx requires the tag first and the typedef second. */ 2774 if ((TREE_CODE (type) == RECORD_TYPE 2775 || TREE_CODE (type) == UNION_TYPE 2776 || TREE_CODE (type) == QUAL_UNION_TYPE) 2777 && TYPE_NAME (type) == decl 2778 && !use_gnu_debug_info_extensions 2779 && !TREE_ASM_WRITTEN (TYPE_NAME (type)) 2780 /* Distinguish the implicit typedefs of C++ 2781 from explicit ones that might be found in C. */ 2782 && DECL_ARTIFICIAL (decl) 2783 /* Do not generate a tag for incomplete records. */ 2784 && COMPLETE_TYPE_P (type) 2785 /* Do not generate a tag for records of variable size, 2786 since this type can not be properly described in the 2787 DBX format, and it confuses some tools such as objdump. */ 2788 && tree_fits_uhwi_p (TYPE_SIZE (type))) 2789 { 2790 tree name = TYPE_IDENTIFIER (type); 2791 2792 dbxout_begin_complex_stabs (); 2793 stabstr_I (name); 2794 stabstr_S (":T"); 2795 dbxout_type (type, 1); 2796 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 2797 0, 0, 0); 2798 } 2799 2800 dbxout_begin_complex_stabs (); 2801 2802 /* Output leading class/struct qualifiers. */ 2803 if (use_gnu_debug_info_extensions) 2804 dbxout_class_name_qualifiers (decl); 2805 2806 /* Output typedef name. */ 2807 stabstr_I (DECL_NAME (decl)); 2808 stabstr_C (':'); 2809 2810 /* Short cut way to output a tag also. */ 2811 if ((TREE_CODE (type) == RECORD_TYPE 2812 || TREE_CODE (type) == UNION_TYPE 2813 || TREE_CODE (type) == QUAL_UNION_TYPE) 2814 && TYPE_NAME (type) == decl 2815 /* Distinguish the implicit typedefs of C++ 2816 from explicit ones that might be found in C. */ 2817 && DECL_ARTIFICIAL (decl)) 2818 { 2819 if (use_gnu_debug_info_extensions) 2820 { 2821 stabstr_C ('T'); 2822 TREE_ASM_WRITTEN (TYPE_NAME (type)) = 1; 2823 } 2824 } 2825 2826 stabstr_C ('t'); 2827 dbxout_type (type, 1); 2828 dbxout_finish_complex_stabs (decl, DBX_TYPE_DECL_STABS_CODE, 2829 0, 0, 0); 2830 did_output = 1; 2831 } 2832 2833 /* Don't output a tag if this is an incomplete type. This prevents 2834 the sun4 Sun OS 4.x dbx from crashing. */ 2835 2836 if (tag_needed && TYPE_NAME (type) != 0 2837 && (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE 2838 || (DECL_NAME (TYPE_NAME (type)) != 0)) 2839 && COMPLETE_TYPE_P (type) 2840 && !TREE_ASM_WRITTEN (TYPE_NAME (type))) 2841 { 2842 /* For a TYPE_DECL with no name, but the type has a name, 2843 output a tag. 2844 This is what represents `struct foo' with no typedef. */ 2845 /* In C++, the name of a type is the corresponding typedef. 2846 In C, it is an IDENTIFIER_NODE. */ 2847 tree name = TYPE_IDENTIFIER (type); 2848 2849 dbxout_begin_complex_stabs (); 2850 stabstr_I (name); 2851 stabstr_S (":T"); 2852 dbxout_type (type, 1); 2853 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0); 2854 did_output = 1; 2855 } 2856 2857 /* If an enum type has no name, it cannot be referred to, but 2858 we must output it anyway, to record the enumeration 2859 constants. */ 2860 2861 if (!did_output && TREE_CODE (type) == ENUMERAL_TYPE) 2862 { 2863 dbxout_begin_complex_stabs (); 2864 /* Some debuggers fail when given NULL names, so give this a 2865 harmless name of " " (Why not "(anon)"?). */ 2866 stabstr_S (" :T"); 2867 dbxout_type (type, 1); 2868 dbxout_finish_complex_stabs (0, DBX_TYPE_DECL_STABS_CODE, 0, 0, 0); 2869 } 2870 2871 /* Prevent duplicate output of a typedef. */ 2872 TREE_ASM_WRITTEN (decl) = 1; 2873 break; 2874 } 2875 2876 case PARM_DECL: 2877 if (DECL_HAS_VALUE_EXPR_P (decl)) 2878 decl = DECL_VALUE_EXPR (decl); 2879 2880 /* PARM_DECLs go in their own separate chain and are output by 2881 dbxout_reg_parms and dbxout_parms, except for those that are 2882 disguised VAR_DECLs like Out parameters in Ada. */ 2883 gcc_assert (TREE_CODE (decl) == VAR_DECL); 2884 2885 /* ... fall through ... */ 2886 2887 case RESULT_DECL: 2888 case VAR_DECL: 2889 /* Don't mention a variable that is external. 2890 Let the file that defines it describe it. */ 2891 if (DECL_EXTERNAL (decl)) 2892 break; 2893 2894 /* If the variable is really a constant 2895 and not written in memory, inform the debugger. 2896 2897 ??? Why do we skip emitting the type and location in this case? */ 2898 if (TREE_STATIC (decl) && TREE_READONLY (decl) 2899 && DECL_INITIAL (decl) != 0 2900 && tree_fits_shwi_p (DECL_INITIAL (decl)) 2901 && ! TREE_ASM_WRITTEN (decl) 2902 && (DECL_FILE_SCOPE_P (decl) 2903 || TREE_CODE (DECL_CONTEXT (decl)) == BLOCK 2904 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL) 2905 && TREE_PUBLIC (decl) == 0) 2906 { 2907 /* The sun4 assembler does not grok this. */ 2908 2909 if (TREE_CODE (TREE_TYPE (decl)) == INTEGER_TYPE 2910 || TREE_CODE (TREE_TYPE (decl)) == ENUMERAL_TYPE) 2911 { 2912 HOST_WIDE_INT ival = tree_to_shwi (DECL_INITIAL (decl)); 2913 2914 dbxout_begin_complex_stabs (); 2915 dbxout_symbol_name (decl, NULL, 'c'); 2916 stabstr_S ("=i"); 2917 stabstr_D (ival); 2918 dbxout_finish_complex_stabs (0, N_LSYM, 0, 0, 0); 2919 DBXOUT_DECR_NESTING; 2920 return 1; 2921 } 2922 else 2923 break; 2924 } 2925 /* else it is something we handle like a normal variable. */ 2926 2927 decl_rtl = dbxout_expand_expr (decl); 2928 if (!decl_rtl) 2929 DBXOUT_DECR_NESTING_AND_RETURN (0); 2930 2931 if (!is_global_var (decl)) 2932 decl_rtl = eliminate_regs (decl_rtl, VOIDmode, NULL_RTX); 2933#ifdef LEAF_REG_REMAP 2934 if (crtl->uses_only_leaf_regs) 2935 leaf_renumber_regs_insn (decl_rtl); 2936#endif 2937 2938 result = dbxout_symbol_location (decl, type, 0, decl_rtl); 2939 break; 2940 2941 default: 2942 break; 2943 } 2944 DBXOUT_DECR_NESTING; 2945 return result; 2946} 2947 2948/* Output the stab for DECL, a VAR_DECL, RESULT_DECL or PARM_DECL. 2949 Add SUFFIX to its name, if SUFFIX is not 0. 2950 Describe the variable as residing in HOME 2951 (usually HOME is DECL_RTL (DECL), but not always). 2952 Returns 1 if the stab was really emitted. */ 2953 2954static int 2955dbxout_symbol_location (tree decl, tree type, const char *suffix, rtx home) 2956{ 2957 int letter = 0; 2958 stab_code_type code; 2959 rtx addr = 0; 2960 int number = 0; 2961 int regno = -1; 2962 2963 /* Don't mention a variable at all 2964 if it was completely optimized into nothingness. 2965 2966 If the decl was from an inline function, then its rtl 2967 is not identically the rtl that was used in this 2968 particular compilation. */ 2969 if (GET_CODE (home) == SUBREG) 2970 { 2971 rtx value = home; 2972 2973 while (GET_CODE (value) == SUBREG) 2974 value = SUBREG_REG (value); 2975 if (REG_P (value)) 2976 { 2977 if (REGNO (value) >= FIRST_PSEUDO_REGISTER) 2978 return 0; 2979 } 2980 home = alter_subreg (&home, true); 2981 } 2982 if (REG_P (home)) 2983 { 2984 regno = REGNO (home); 2985 if (regno >= FIRST_PSEUDO_REGISTER) 2986 return 0; 2987 } 2988 2989 /* The kind-of-variable letter depends on where 2990 the variable is and on the scope of its name: 2991 G and N_GSYM for static storage and global scope, 2992 S for static storage and file scope, 2993 V for static storage and local scope, 2994 for those two, use N_LCSYM if data is in bss segment, 2995 N_STSYM if in data segment, N_FUN otherwise. 2996 (We used N_FUN originally, then changed to N_STSYM 2997 to please GDB. However, it seems that confused ld. 2998 Now GDB has been fixed to like N_FUN, says Kingdon.) 2999 no letter at all, and N_LSYM, for auto variable, 3000 r and N_RSYM for register variable. */ 3001 3002 if (MEM_P (home) && GET_CODE (XEXP (home, 0)) == SYMBOL_REF) 3003 { 3004 if (TREE_PUBLIC (decl)) 3005 { 3006 int offs; 3007 letter = 'G'; 3008 code = N_GSYM; 3009 if (NULL != dbxout_common_check (decl, &offs)) 3010 { 3011 letter = 'V'; 3012 addr = 0; 3013 number = offs; 3014 } 3015 } 3016 else 3017 { 3018 addr = XEXP (home, 0); 3019 3020 letter = decl_function_context (decl) ? 'V' : 'S'; 3021 3022 /* Some ports can transform a symbol ref into a label ref, 3023 because the symbol ref is too far away and has to be 3024 dumped into a constant pool. Alternatively, the symbol 3025 in the constant pool might be referenced by a different 3026 symbol. */ 3027 if (GET_CODE (addr) == SYMBOL_REF 3028 && CONSTANT_POOL_ADDRESS_P (addr)) 3029 { 3030 bool marked; 3031 rtx tmp = get_pool_constant_mark (addr, &marked); 3032 3033 if (GET_CODE (tmp) == SYMBOL_REF) 3034 { 3035 addr = tmp; 3036 if (CONSTANT_POOL_ADDRESS_P (addr)) 3037 get_pool_constant_mark (addr, &marked); 3038 else 3039 marked = true; 3040 } 3041 else if (GET_CODE (tmp) == LABEL_REF) 3042 { 3043 addr = tmp; 3044 marked = true; 3045 } 3046 3047 /* If all references to the constant pool were optimized 3048 out, we just ignore the symbol. */ 3049 if (!marked) 3050 return 0; 3051 } 3052 3053 /* This should be the same condition as in assemble_variable, but 3054 we don't have access to dont_output_data here. So, instead, 3055 we rely on the fact that error_mark_node initializers always 3056 end up in bss for C++ and never end up in bss for C. */ 3057 if (DECL_INITIAL (decl) == 0 3058 || (lang_GNU_CXX () 3059 && DECL_INITIAL (decl) == error_mark_node)) 3060 { 3061 int offs; 3062 code = N_LCSYM; 3063 if (NULL != dbxout_common_check (decl, &offs)) 3064 { 3065 addr = 0; 3066 number = offs; 3067 letter = 'V'; 3068 code = N_GSYM; 3069 } 3070 } 3071 else if (DECL_IN_TEXT_SECTION (decl)) 3072 /* This is not quite right, but it's the closest 3073 of all the codes that Unix defines. */ 3074 code = DBX_STATIC_CONST_VAR_CODE; 3075 else 3076 { 3077 /* Ultrix `as' seems to need this. */ 3078#ifdef DBX_STATIC_STAB_DATA_SECTION 3079 switch_to_section (data_section); 3080#endif 3081 code = N_STSYM; 3082 } 3083 } 3084 } 3085 else if (regno >= 0) 3086 { 3087 letter = 'r'; 3088 code = N_RSYM; 3089 number = DBX_REGISTER_NUMBER (regno); 3090 } 3091 else if (MEM_P (home) 3092 && (MEM_P (XEXP (home, 0)) 3093 || (REG_P (XEXP (home, 0)) 3094 && REGNO (XEXP (home, 0)) != HARD_FRAME_POINTER_REGNUM 3095 && REGNO (XEXP (home, 0)) != STACK_POINTER_REGNUM 3096#if !HARD_FRAME_POINTER_IS_ARG_POINTER 3097 && REGNO (XEXP (home, 0)) != ARG_POINTER_REGNUM 3098#endif 3099 ))) 3100 /* If the value is indirect by memory or by a register 3101 that isn't the frame pointer 3102 then it means the object is variable-sized and address through 3103 that register or stack slot. DBX has no way to represent this 3104 so all we can do is output the variable as a pointer. 3105 If it's not a parameter, ignore it. */ 3106 { 3107 if (REG_P (XEXP (home, 0))) 3108 { 3109 letter = 'r'; 3110 code = N_RSYM; 3111 if (REGNO (XEXP (home, 0)) >= FIRST_PSEUDO_REGISTER) 3112 return 0; 3113 number = DBX_REGISTER_NUMBER (REGNO (XEXP (home, 0))); 3114 } 3115 else 3116 { 3117 code = N_LSYM; 3118 /* RTL looks like (MEM (MEM (PLUS (REG...) (CONST_INT...)))). 3119 We want the value of that CONST_INT. */ 3120 number = DEBUGGER_AUTO_OFFSET (XEXP (XEXP (home, 0), 0)); 3121 } 3122 3123 /* Effectively do build_pointer_type, but don't cache this type, 3124 since it might be temporary whereas the type it points to 3125 might have been saved for inlining. */ 3126 /* Don't use REFERENCE_TYPE because dbx can't handle that. */ 3127 type = make_node (POINTER_TYPE); 3128 TREE_TYPE (type) = TREE_TYPE (decl); 3129 } 3130 else if (MEM_P (home) 3131 && REG_P (XEXP (home, 0))) 3132 { 3133 code = N_LSYM; 3134 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0)); 3135 } 3136 else if (MEM_P (home) 3137 && GET_CODE (XEXP (home, 0)) == PLUS 3138 && CONST_INT_P (XEXP (XEXP (home, 0), 1))) 3139 { 3140 code = N_LSYM; 3141 /* RTL looks like (MEM (PLUS (REG...) (CONST_INT...))) 3142 We want the value of that CONST_INT. */ 3143 number = DEBUGGER_AUTO_OFFSET (XEXP (home, 0)); 3144 } 3145 else if (MEM_P (home) 3146 && GET_CODE (XEXP (home, 0)) == CONST) 3147 { 3148 /* Handle an obscure case which can arise when optimizing and 3149 when there are few available registers. (This is *always* 3150 the case for i386/i486 targets). The RTL looks like 3151 (MEM (CONST ...)) even though this variable is a local `auto' 3152 or a local `register' variable. In effect, what has happened 3153 is that the reload pass has seen that all assignments and 3154 references for one such a local variable can be replaced by 3155 equivalent assignments and references to some static storage 3156 variable, thereby avoiding the need for a register. In such 3157 cases we're forced to lie to debuggers and tell them that 3158 this variable was itself `static'. */ 3159 int offs; 3160 code = N_LCSYM; 3161 letter = 'V'; 3162 if (NULL == dbxout_common_check (decl, &offs)) 3163 addr = XEXP (XEXP (home, 0), 0); 3164 else 3165 { 3166 addr = 0; 3167 number = offs; 3168 code = N_GSYM; 3169 } 3170 } 3171 else if (GET_CODE (home) == CONCAT) 3172 { 3173 tree subtype; 3174 3175 /* If TYPE is not a COMPLEX_TYPE (it might be a RECORD_TYPE, 3176 for example), then there is no easy way to figure out 3177 what SUBTYPE should be. So, we give up. */ 3178 if (TREE_CODE (type) != COMPLEX_TYPE) 3179 return 0; 3180 3181 subtype = TREE_TYPE (type); 3182 3183 /* If the variable's storage is in two parts, 3184 output each as a separate stab with a modified name. */ 3185 if (WORDS_BIG_ENDIAN) 3186 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 0)); 3187 else 3188 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 0)); 3189 3190 if (WORDS_BIG_ENDIAN) 3191 dbxout_symbol_location (decl, subtype, "$real", XEXP (home, 1)); 3192 else 3193 dbxout_symbol_location (decl, subtype, "$imag", XEXP (home, 1)); 3194 return 1; 3195 } 3196 else 3197 /* Address might be a MEM, when DECL is a variable-sized object. 3198 Or it might be const0_rtx, meaning previous passes 3199 want us to ignore this variable. */ 3200 return 0; 3201 3202 /* Ok, start a symtab entry and output the variable name. */ 3203 emit_pending_bincls_if_required (); 3204 FORCE_TEXT; 3205 3206#ifdef DBX_STATIC_BLOCK_START 3207 DBX_STATIC_BLOCK_START (asm_out_file, code); 3208#endif 3209 3210 dbxout_begin_complex_stabs_noforcetext (); 3211 dbxout_symbol_name (decl, suffix, letter); 3212 dbxout_type (type, 0); 3213 dbxout_finish_complex_stabs (decl, code, addr, 0, number); 3214 3215#ifdef DBX_STATIC_BLOCK_END 3216 DBX_STATIC_BLOCK_END (asm_out_file, code); 3217#endif 3218 return 1; 3219} 3220 3221/* Output the symbol name of DECL for a stabs, with suffix SUFFIX. 3222 Then output LETTER to indicate the kind of location the symbol has. */ 3223 3224static void 3225dbxout_symbol_name (tree decl, const char *suffix, int letter) 3226{ 3227 tree name; 3228 3229 if (DECL_CONTEXT (decl) 3230 && (TYPE_P (DECL_CONTEXT (decl)) 3231 || TREE_CODE (DECL_CONTEXT (decl)) == NAMESPACE_DECL)) 3232 /* One slight hitch: if this is a VAR_DECL which is a class member 3233 or a namespace member, we must put out the mangled name instead of the 3234 DECL_NAME. Note also that static member (variable) names DO NOT begin 3235 with underscores in .stabs directives. */ 3236 name = DECL_ASSEMBLER_NAME (decl); 3237 else 3238 /* ...but if we're function-local, we don't want to include the junk 3239 added by ASM_FORMAT_PRIVATE_NAME. */ 3240 name = DECL_NAME (decl); 3241 3242 if (name) 3243 stabstr_I (name); 3244 else 3245 stabstr_S ("(anon)"); 3246 3247 if (suffix) 3248 stabstr_S (suffix); 3249 stabstr_C (':'); 3250 if (letter) 3251 stabstr_C (letter); 3252} 3253 3254 3255/* Output the common block name for DECL in a stabs. 3256 3257 Symbols in global common (.comm) get wrapped with an N_BCOMM/N_ECOMM pair 3258 around each group of symbols in the same .comm area. The N_GSYM stabs 3259 that are emitted only contain the offset in the common area. This routine 3260 emits the N_BCOMM and N_ECOMM stabs. */ 3261 3262static void 3263dbxout_common_name (tree decl, const char *name, stab_code_type op) 3264{ 3265 dbxout_begin_complex_stabs (); 3266 stabstr_S (name); 3267 dbxout_finish_complex_stabs (decl, op, NULL_RTX, NULL, 0); 3268} 3269 3270/* Check decl to determine whether it is a VAR_DECL destined for storage in a 3271 common area. If it is, the return value will be a non-null string giving 3272 the name of the common storage block it will go into. If non-null, the 3273 value is the offset into the common block for that symbol's storage. */ 3274 3275static const char * 3276dbxout_common_check (tree decl, int *value) 3277{ 3278 rtx home; 3279 rtx sym_addr; 3280 const char *name = NULL; 3281 3282 /* If the decl isn't a VAR_DECL, or if it isn't static, or if 3283 it does not have a value (the offset into the common area), or if it 3284 is thread local (as opposed to global) then it isn't common, and shouldn't 3285 be handled as such. 3286 3287 ??? DECL_THREAD_LOCAL_P check prevents problems with improper .stabs 3288 for thread-local symbols. Can be handled via same mechanism as used 3289 in dwarf2out.c. */ 3290 if (TREE_CODE (decl) != VAR_DECL 3291 || !TREE_STATIC (decl) 3292 || !DECL_HAS_VALUE_EXPR_P (decl) 3293 || DECL_THREAD_LOCAL_P (decl) 3294 || !is_fortran ()) 3295 return NULL; 3296 3297 home = DECL_RTL (decl); 3298 if (home == NULL_RTX || GET_CODE (home) != MEM) 3299 return NULL; 3300 3301 sym_addr = dbxout_expand_expr (DECL_VALUE_EXPR (decl)); 3302 if (sym_addr == NULL_RTX || GET_CODE (sym_addr) != MEM) 3303 return NULL; 3304 3305 sym_addr = XEXP (sym_addr, 0); 3306 if (GET_CODE (sym_addr) == CONST) 3307 sym_addr = XEXP (sym_addr, 0); 3308 if ((GET_CODE (sym_addr) == SYMBOL_REF || GET_CODE (sym_addr) == PLUS) 3309 && DECL_INITIAL (decl) == 0) 3310 { 3311 3312 /* We have a sym that will go into a common area, meaning that it 3313 will get storage reserved with a .comm/.lcomm assembler pseudo-op. 3314 3315 Determine name of common area this symbol will be an offset into, 3316 and offset into that area. Also retrieve the decl for the area 3317 that the symbol is offset into. */ 3318 tree cdecl = NULL; 3319 3320 switch (GET_CODE (sym_addr)) 3321 { 3322 case PLUS: 3323 if (CONST_INT_P (XEXP (sym_addr, 0))) 3324 { 3325 name = 3326 targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 1), 0)); 3327 *value = INTVAL (XEXP (sym_addr, 0)); 3328 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 1)); 3329 } 3330 else 3331 { 3332 name = 3333 targetm.strip_name_encoding (XSTR (XEXP (sym_addr, 0), 0)); 3334 *value = INTVAL (XEXP (sym_addr, 1)); 3335 cdecl = SYMBOL_REF_DECL (XEXP (sym_addr, 0)); 3336 } 3337 break; 3338 3339 case SYMBOL_REF: 3340 name = targetm.strip_name_encoding (XSTR (sym_addr, 0)); 3341 *value = 0; 3342 cdecl = SYMBOL_REF_DECL (sym_addr); 3343 break; 3344 3345 default: 3346 error ("common symbol debug info is not structured as " 3347 "symbol+offset"); 3348 } 3349 3350 /* Check area common symbol is offset into. If this is not public, then 3351 it is not a symbol in a common block. It must be a .lcomm symbol, not 3352 a .comm symbol. */ 3353 if (cdecl == NULL || !TREE_PUBLIC (cdecl)) 3354 name = NULL; 3355 } 3356 else 3357 name = NULL; 3358 3359 return name; 3360} 3361 3362/* Output definitions of all the decls in a chain. Return nonzero if 3363 anything was output */ 3364 3365int 3366dbxout_syms (tree syms) 3367{ 3368 int result = 0; 3369 const char *comm_prev = NULL; 3370 tree syms_prev = NULL; 3371 3372 while (syms) 3373 { 3374 int temp, copen, cclos; 3375 const char *comm_new; 3376 3377 /* Check for common symbol, and then progression into a new/different 3378 block of common symbols. Emit closing/opening common bracket if 3379 necessary. */ 3380 comm_new = dbxout_common_check (syms, &temp); 3381 copen = comm_new != NULL 3382 && (comm_prev == NULL || strcmp (comm_new, comm_prev)); 3383 cclos = comm_prev != NULL 3384 && (comm_new == NULL || strcmp (comm_new, comm_prev)); 3385 if (cclos) 3386 dbxout_common_name (syms_prev, comm_prev, N_ECOMM); 3387 if (copen) 3388 { 3389 dbxout_common_name (syms, comm_new, N_BCOMM); 3390 syms_prev = syms; 3391 } 3392 comm_prev = comm_new; 3393 3394 result += dbxout_symbol (syms, 1); 3395 syms = DECL_CHAIN (syms); 3396 } 3397 3398 if (comm_prev != NULL) 3399 dbxout_common_name (syms_prev, comm_prev, N_ECOMM); 3400 3401 return result; 3402} 3403 3404/* The following two functions output definitions of function parameters. 3405 Each parameter gets a definition locating it in the parameter list. 3406 Each parameter that is a register variable gets a second definition 3407 locating it in the register. 3408 3409 Printing or argument lists in gdb uses the definitions that 3410 locate in the parameter list. But reference to the variable in 3411 expressions uses preferentially the definition as a register. */ 3412 3413/* Output definitions, referring to storage in the parmlist, 3414 of all the parms in PARMS, which is a chain of PARM_DECL nodes. */ 3415 3416void 3417dbxout_parms (tree parms) 3418{ 3419 ++debug_nesting; 3420 emit_pending_bincls_if_required (); 3421 3422 for (; parms; parms = DECL_CHAIN (parms)) 3423 if (DECL_NAME (parms) 3424 && TREE_TYPE (parms) != error_mark_node 3425 && DECL_RTL_SET_P (parms) 3426 && DECL_INCOMING_RTL (parms)) 3427 { 3428 tree eff_type; 3429 char letter; 3430 stab_code_type code; 3431 int number; 3432 3433 /* Perform any necessary register eliminations on the parameter's rtl, 3434 so that the debugging output will be accurate. */ 3435 DECL_INCOMING_RTL (parms) 3436 = eliminate_regs (DECL_INCOMING_RTL (parms), VOIDmode, NULL_RTX); 3437 SET_DECL_RTL (parms, 3438 eliminate_regs (DECL_RTL (parms), VOIDmode, NULL_RTX)); 3439#ifdef LEAF_REG_REMAP 3440 if (crtl->uses_only_leaf_regs) 3441 { 3442 leaf_renumber_regs_insn (DECL_INCOMING_RTL (parms)); 3443 leaf_renumber_regs_insn (DECL_RTL (parms)); 3444 } 3445#endif 3446 3447 if (PARM_PASSED_IN_MEMORY (parms)) 3448 { 3449 rtx inrtl = XEXP (DECL_INCOMING_RTL (parms), 0); 3450 3451 /* ??? Here we assume that the parm address is indexed 3452 off the frame pointer or arg pointer. 3453 If that is not true, we produce meaningless results, 3454 but do not crash. */ 3455 if (GET_CODE (inrtl) == PLUS 3456 && CONST_INT_P (XEXP (inrtl, 1))) 3457 number = INTVAL (XEXP (inrtl, 1)); 3458 else 3459 number = 0; 3460 3461 code = N_PSYM; 3462 number = DEBUGGER_ARG_OFFSET (number, inrtl); 3463 letter = 'p'; 3464 3465 /* It is quite tempting to use TREE_TYPE (parms) instead 3466 of DECL_ARG_TYPE (parms) for the eff_type, so that gcc 3467 reports the actual type of the parameter, rather than 3468 the promoted type. This certainly makes GDB's life 3469 easier, at least for some ports. The change is a bad 3470 idea however, since GDB expects to be able access the 3471 type without performing any conversions. So for 3472 example, if we were passing a float to an unprototyped 3473 function, gcc will store a double on the stack, but if 3474 we emit a stab saying the type is a float, then gdb 3475 will only read in a single value, and this will produce 3476 an erroneous value. */ 3477 eff_type = DECL_ARG_TYPE (parms); 3478 } 3479 else if (REG_P (DECL_RTL (parms))) 3480 { 3481 rtx best_rtl; 3482 3483 /* Parm passed in registers and lives in registers or nowhere. */ 3484 code = DBX_REGPARM_STABS_CODE; 3485 letter = DBX_REGPARM_STABS_LETTER; 3486 3487 /* For parms passed in registers, it is better to use the 3488 declared type of the variable, not the type it arrived in. */ 3489 eff_type = TREE_TYPE (parms); 3490 3491 /* If parm lives in a register, use that register; pretend 3492 the parm was passed there. It would be more consistent 3493 to describe the register where the parm was passed, but 3494 in practice that register usually holds something else. 3495 If the parm lives nowhere, use the register where it 3496 was passed. */ 3497 if (REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) 3498 best_rtl = DECL_RTL (parms); 3499 else if (GET_CODE (DECL_INCOMING_RTL (parms)) == PARALLEL) 3500 best_rtl = XEXP (XVECEXP (DECL_INCOMING_RTL (parms), 0, 0), 0); 3501 else 3502 best_rtl = DECL_INCOMING_RTL (parms); 3503 3504 number = DBX_REGISTER_NUMBER (REGNO (best_rtl)); 3505 } 3506 else if (MEM_P (DECL_RTL (parms)) 3507 && REG_P (XEXP (DECL_RTL (parms), 0)) 3508 && REGNO (XEXP (DECL_RTL (parms), 0)) != HARD_FRAME_POINTER_REGNUM 3509 && REGNO (XEXP (DECL_RTL (parms), 0)) != STACK_POINTER_REGNUM 3510#if !HARD_FRAME_POINTER_IS_ARG_POINTER 3511 && REGNO (XEXP (DECL_RTL (parms), 0)) != ARG_POINTER_REGNUM 3512#endif 3513 ) 3514 { 3515 /* Parm was passed via invisible reference. 3516 That is, its address was passed in a register. 3517 Output it as if it lived in that register. 3518 The debugger will know from the type 3519 that it was actually passed by invisible reference. */ 3520 3521 code = DBX_REGPARM_STABS_CODE; 3522 3523 /* GDB likes this marked with a special letter. */ 3524 letter = (use_gnu_debug_info_extensions 3525 ? 'a' : DBX_REGPARM_STABS_LETTER); 3526 eff_type = TREE_TYPE (parms); 3527 3528 /* DECL_RTL looks like (MEM (REG...). Get the register number. 3529 If it is an unallocated pseudo-reg, then use the register where 3530 it was passed instead. 3531 ??? Why is DBX_REGISTER_NUMBER not used here? */ 3532 3533 if (REGNO (XEXP (DECL_RTL (parms), 0)) < FIRST_PSEUDO_REGISTER) 3534 number = REGNO (XEXP (DECL_RTL (parms), 0)); 3535 else 3536 number = REGNO (DECL_INCOMING_RTL (parms)); 3537 } 3538 else if (MEM_P (DECL_RTL (parms)) 3539 && MEM_P (XEXP (DECL_RTL (parms), 0))) 3540 { 3541 /* Parm was passed via invisible reference, with the reference 3542 living on the stack. DECL_RTL looks like 3543 (MEM (MEM (PLUS (REG ...) (CONST_INT ...)))) or it 3544 could look like (MEM (MEM (REG))). */ 3545 3546 code = N_PSYM; 3547 letter = 'v'; 3548 eff_type = TREE_TYPE (parms); 3549 3550 if (!REG_P (XEXP (XEXP (DECL_RTL (parms), 0), 0))) 3551 number = INTVAL (XEXP (XEXP (XEXP (DECL_RTL (parms), 0), 0), 1)); 3552 else 3553 number = 0; 3554 3555 number = DEBUGGER_ARG_OFFSET (number, 3556 XEXP (XEXP (DECL_RTL (parms), 0), 0)); 3557 } 3558 else if (MEM_P (DECL_RTL (parms)) 3559 && XEXP (DECL_RTL (parms), 0) != const0_rtx 3560 /* ??? A constant address for a parm can happen 3561 when the reg it lives in is equiv to a constant in memory. 3562 Should make this not happen, after 2.4. */ 3563 && ! CONSTANT_P (XEXP (DECL_RTL (parms), 0))) 3564 { 3565 /* Parm was passed in registers but lives on the stack. */ 3566 3567 code = N_PSYM; 3568 letter = 'p'; 3569 eff_type = TREE_TYPE (parms); 3570 3571 /* DECL_RTL looks like (MEM (PLUS (REG...) (CONST_INT...))), 3572 in which case we want the value of that CONST_INT, 3573 or (MEM (REG ...)), 3574 in which case we use a value of zero. */ 3575 if (!REG_P (XEXP (DECL_RTL (parms), 0))) 3576 number = INTVAL (XEXP (XEXP (DECL_RTL (parms), 0), 1)); 3577 else 3578 number = 0; 3579 3580 /* Make a big endian correction if the mode of the type of the 3581 parameter is not the same as the mode of the rtl. */ 3582 if (BYTES_BIG_ENDIAN 3583 && TYPE_MODE (TREE_TYPE (parms)) != GET_MODE (DECL_RTL (parms)) 3584 && GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms))) < UNITS_PER_WORD) 3585 number += (GET_MODE_SIZE (GET_MODE (DECL_RTL (parms))) 3586 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (parms)))); 3587 } 3588 else 3589 /* ??? We don't know how to represent this argument. */ 3590 continue; 3591 3592 dbxout_begin_complex_stabs (); 3593 3594 if (DECL_NAME (parms)) 3595 { 3596 stabstr_I (DECL_NAME (parms)); 3597 stabstr_C (':'); 3598 } 3599 else 3600 stabstr_S ("(anon):"); 3601 stabstr_C (letter); 3602 dbxout_type (eff_type, 0); 3603 dbxout_finish_complex_stabs (parms, code, 0, 0, number); 3604 } 3605 DBXOUT_DECR_NESTING; 3606} 3607 3608/* Output definitions for the places where parms live during the function, 3609 when different from where they were passed, when the parms were passed 3610 in memory. 3611 3612 It is not useful to do this for parms passed in registers 3613 that live during the function in different registers, because it is 3614 impossible to look in the passed register for the passed value, 3615 so we use the within-the-function register to begin with. 3616 3617 PARMS is a chain of PARM_DECL nodes. */ 3618 3619void 3620dbxout_reg_parms (tree parms) 3621{ 3622 ++debug_nesting; 3623 3624 for (; parms; parms = DECL_CHAIN (parms)) 3625 if (DECL_NAME (parms) && PARM_PASSED_IN_MEMORY (parms)) 3626 { 3627 /* Report parms that live in registers during the function 3628 but were passed in memory. */ 3629 if (REG_P (DECL_RTL (parms)) 3630 && REGNO (DECL_RTL (parms)) < FIRST_PSEUDO_REGISTER) 3631 dbxout_symbol_location (parms, TREE_TYPE (parms), 3632 0, DECL_RTL (parms)); 3633 else if (GET_CODE (DECL_RTL (parms)) == CONCAT) 3634 dbxout_symbol_location (parms, TREE_TYPE (parms), 3635 0, DECL_RTL (parms)); 3636 /* Report parms that live in memory but not where they were passed. */ 3637 else if (MEM_P (DECL_RTL (parms)) 3638 && ! rtx_equal_p (DECL_RTL (parms), DECL_INCOMING_RTL (parms))) 3639 dbxout_symbol_location (parms, TREE_TYPE (parms), 3640 0, DECL_RTL (parms)); 3641 } 3642 DBXOUT_DECR_NESTING; 3643} 3644 3645/* Given a chain of ..._TYPE nodes (as come in a parameter list), 3646 output definitions of those names, in raw form */ 3647 3648static void 3649dbxout_args (tree args) 3650{ 3651 while (args) 3652 { 3653 stabstr_C (','); 3654 dbxout_type (TREE_VALUE (args), 0); 3655 args = TREE_CHAIN (args); 3656 } 3657} 3658 3659#if defined (DBX_DEBUGGING_INFO) 3660 3661/* Subroutine of dbxout_block. Emit an N_LBRAC stab referencing LABEL. 3662 BEGIN_LABEL is the name of the beginning of the function, which may 3663 be required. */ 3664static void 3665dbx_output_lbrac (const char *label, 3666 const char *begin_label ATTRIBUTE_UNUSED) 3667{ 3668 dbxout_begin_stabn (N_LBRAC); 3669 if (DBX_BLOCKS_FUNCTION_RELATIVE) 3670 dbxout_stab_value_label_diff (label, begin_label); 3671 else 3672 dbxout_stab_value_label (label); 3673} 3674 3675/* Subroutine of dbxout_block. Emit an N_RBRAC stab referencing LABEL. 3676 BEGIN_LABEL is the name of the beginning of the function, which may 3677 be required. */ 3678static void 3679dbx_output_rbrac (const char *label, 3680 const char *begin_label ATTRIBUTE_UNUSED) 3681{ 3682 dbxout_begin_stabn (N_RBRAC); 3683 if (DBX_BLOCKS_FUNCTION_RELATIVE) 3684 dbxout_stab_value_label_diff (label, begin_label); 3685 else 3686 dbxout_stab_value_label (label); 3687} 3688 3689/* Output everything about a symbol block (a BLOCK node 3690 that represents a scope level), 3691 including recursive output of contained blocks. 3692 3693 BLOCK is the BLOCK node. 3694 DEPTH is its depth within containing symbol blocks. 3695 ARGS is usually zero; but for the outermost block of the 3696 body of a function, it is a chain of PARM_DECLs for the function parameters. 3697 We output definitions of all the register parms 3698 as if they were local variables of that block. 3699 3700 If -g1 was used, we count blocks just the same, but output nothing 3701 except for the outermost block. 3702 3703 Actually, BLOCK may be several blocks chained together. 3704 We handle them all in sequence. */ 3705 3706static void 3707dbxout_block (tree block, int depth, tree args) 3708{ 3709 char begin_label[20]; 3710 /* Reference current function start using LFBB. */ 3711 ASM_GENERATE_INTERNAL_LABEL (begin_label, "LFBB", scope_labelno); 3712 3713 while (block) 3714 { 3715 /* Ignore blocks never expanded or otherwise marked as real. */ 3716 if (TREE_USED (block) && TREE_ASM_WRITTEN (block)) 3717 { 3718 int did_output; 3719 int blocknum = BLOCK_NUMBER (block); 3720 3721 /* In dbx format, the syms of a block come before the N_LBRAC. 3722 If nothing is output, we don't need the N_LBRAC, either. */ 3723 did_output = 0; 3724 if (debug_info_level != DINFO_LEVEL_TERSE || depth == 0) 3725 did_output = dbxout_syms (BLOCK_VARS (block)); 3726 if (args) 3727 dbxout_reg_parms (args); 3728 3729 /* Now output an N_LBRAC symbol to represent the beginning of 3730 the block. Use the block's tree-walk order to generate 3731 the assembler symbols LBBn and LBEn 3732 that final will define around the code in this block. */ 3733 if (did_output) 3734 { 3735 char buf[20]; 3736 const char *scope_start; 3737 3738 if (depth == 0) 3739 /* The outermost block doesn't get LBB labels; use 3740 the LFBB local symbol emitted by dbxout_begin_prologue. */ 3741 scope_start = begin_label; 3742 else 3743 { 3744 ASM_GENERATE_INTERNAL_LABEL (buf, "LBB", blocknum); 3745 scope_start = buf; 3746 } 3747 3748 dbx_output_lbrac (scope_start, begin_label); 3749 } 3750 3751 /* Output the subblocks. */ 3752 dbxout_block (BLOCK_SUBBLOCKS (block), depth + 1, NULL_TREE); 3753 3754 /* Refer to the marker for the end of the block. */ 3755 if (did_output) 3756 { 3757 char buf[100]; 3758 if (depth == 0) 3759 /* The outermost block doesn't get LBE labels; 3760 use the "scope" label which will be emitted 3761 by dbxout_function_end. */ 3762 ASM_GENERATE_INTERNAL_LABEL (buf, "Lscope", scope_labelno); 3763 else 3764 ASM_GENERATE_INTERNAL_LABEL (buf, "LBE", blocknum); 3765 3766 dbx_output_rbrac (buf, begin_label); 3767 } 3768 } 3769 block = BLOCK_CHAIN (block); 3770 } 3771} 3772 3773/* Output the information about a function and its arguments and result. 3774 Usually this follows the function's code, 3775 but on some systems, it comes before. */ 3776 3777static void 3778dbxout_begin_function (tree decl) 3779{ 3780 int saved_tree_used1; 3781 3782 saved_tree_used1 = TREE_USED (decl); 3783 TREE_USED (decl) = 1; 3784 if (DECL_NAME (DECL_RESULT (decl)) != 0) 3785 { 3786 int saved_tree_used2 = TREE_USED (DECL_RESULT (decl)); 3787 TREE_USED (DECL_RESULT (decl)) = 1; 3788 dbxout_symbol (decl, 0); 3789 TREE_USED (DECL_RESULT (decl)) = saved_tree_used2; 3790 } 3791 else 3792 dbxout_symbol (decl, 0); 3793 TREE_USED (decl) = saved_tree_used1; 3794 3795 dbxout_parms (DECL_ARGUMENTS (decl)); 3796 if (DECL_NAME (DECL_RESULT (decl)) != 0) 3797 dbxout_symbol (DECL_RESULT (decl), 1); 3798} 3799#endif /* DBX_DEBUGGING_INFO */ 3800 3801#endif /* DBX_DEBUGGING_INFO || XCOFF_DEBUGGING_INFO */ 3802 3803/* Record an element in the table of global destructors. SYMBOL is 3804 a SYMBOL_REF of the function to be called; PRIORITY is a number 3805 between 0 and MAX_INIT_PRIORITY. */ 3806 3807void 3808default_stabs_asm_out_destructor (rtx symbol ATTRIBUTE_UNUSED, 3809 int priority ATTRIBUTE_UNUSED) 3810{ 3811#if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO 3812 /* Tell GNU LD that this is part of the static destructor set. 3813 This will work for any system that uses stabs, most usefully 3814 aout systems. */ 3815 dbxout_begin_simple_stabs ("___DTOR_LIST__", 22 /* N_SETT */); 3816 dbxout_stab_value_label (XSTR (symbol, 0)); 3817#else 3818 sorry ("global destructors not supported on this target"); 3819#endif 3820} 3821 3822/* Likewise for global constructors. */ 3823 3824void 3825default_stabs_asm_out_constructor (rtx symbol ATTRIBUTE_UNUSED, 3826 int priority ATTRIBUTE_UNUSED) 3827{ 3828#if defined DBX_DEBUGGING_INFO || defined XCOFF_DEBUGGING_INFO 3829 /* Tell GNU LD that this is part of the static destructor set. 3830 This will work for any system that uses stabs, most usefully 3831 aout systems. */ 3832 dbxout_begin_simple_stabs ("___CTOR_LIST__", 22 /* N_SETT */); 3833 dbxout_stab_value_label (XSTR (symbol, 0)); 3834#else 3835 sorry ("global constructors not supported on this target"); 3836#endif 3837} 3838 3839#include "gt-dbxout.h" 3840