dwarf2out.c revision 117395
1/* Output Dwarf2 format symbol table information from the GNU C compiler. 2 Copyright (C) 1992, 1993, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002 3 Free Software Foundation, Inc. 4 Contributed by Gary Funck (gary@intrepid.com). 5 Derived from DWARF 1 implementation of Ron Guilmette (rfg@monkeys.com). 6 Extensively modified by Jason Merrill (jason@cygnus.com). 7 8This file is part of GCC. 9 10GCC is free software; you can redistribute it and/or modify it under 11the terms of the GNU General Public License as published by the Free 12Software Foundation; either version 2, or (at your option) any later 13version. 14 15GCC is distributed in the hope that it will be useful, but WITHOUT ANY 16WARRANTY; without even the implied warranty of MERCHANTABILITY or 17FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 18for more details. 19 20You should have received a copy of the GNU General Public License 21along with GCC; see the file COPYING. If not, write to the Free 22Software Foundation, 59 Temple Place - Suite 330, Boston, MA 2302111-1307, USA. */ 24 25/* TODO: Emit .debug_line header even when there are no functions, since 26 the file numbers are used by .debug_info. Alternately, leave 27 out locations for types and decls. 28 Avoid talking about ctors and op= for PODs. 29 Factor out common prologue sequences into multiple CIEs. */ 30 31/* The first part of this file deals with the DWARF 2 frame unwind 32 information, which is also used by the GCC efficient exception handling 33 mechanism. The second part, controlled only by an #ifdef 34 DWARF2_DEBUGGING_INFO, deals with the other DWARF 2 debugging 35 information. */ 36 37#include "config.h" 38#include "system.h" 39#include "tree.h" 40#include "flags.h" 41#include "real.h" 42#include "rtl.h" 43#include "hard-reg-set.h" 44#include "regs.h" 45#include "insn-config.h" 46#include "reload.h" 47#include "function.h" 48#include "output.h" 49#include "expr.h" 50#include "libfuncs.h" 51#include "except.h" 52#include "dwarf2.h" 53#include "dwarf2out.h" 54#include "dwarf2asm.h" 55#include "toplev.h" 56#include "varray.h" 57#include "ggc.h" 58#include "md5.h" 59#include "tm_p.h" 60#include "diagnostic.h" 61#include "debug.h" 62#include "target.h" 63#include "langhooks.h" 64#include "hashtable.h" 65#include "hashtab.h" 66 67#ifdef DWARF2_DEBUGGING_INFO 68static void dwarf2out_source_line PARAMS ((unsigned int, const char *)); 69#endif 70 71/* DWARF2 Abbreviation Glossary: 72 CFA = Canonical Frame Address 73 a fixed address on the stack which identifies a call frame. 74 We define it to be the value of SP just before the call insn. 75 The CFA register and offset, which may change during the course 76 of the function, are used to calculate its value at runtime. 77 CFI = Call Frame Instruction 78 an instruction for the DWARF2 abstract machine 79 CIE = Common Information Entry 80 information describing information common to one or more FDEs 81 DIE = Debugging Information Entry 82 FDE = Frame Description Entry 83 information describing the stack call frame, in particular, 84 how to restore registers 85 86 DW_CFA_... = DWARF2 CFA call frame instruction 87 DW_TAG_... = DWARF2 DIE tag */ 88 89/* Decide whether we want to emit frame unwind information for the current 90 translation unit. */ 91 92int 93dwarf2out_do_frame () 94{ 95 return (write_symbols == DWARF2_DEBUG 96 || write_symbols == VMS_AND_DWARF2_DEBUG 97#ifdef DWARF2_FRAME_INFO 98 || DWARF2_FRAME_INFO 99#endif 100#ifdef DWARF2_UNWIND_INFO 101 || flag_unwind_tables 102 || (flag_exceptions && ! USING_SJLJ_EXCEPTIONS) 103#endif 104 ); 105} 106 107/* The size of the target's pointer type. */ 108#ifndef PTR_SIZE 109#define PTR_SIZE (POINTER_SIZE / BITS_PER_UNIT) 110#endif 111 112/* Default version of targetm.eh_frame_section. Note this must appear 113 outside the DWARF2_DEBUGGING_INFO || DWARF2_UNWIND_INFO macro 114 guards. */ 115 116void 117default_eh_frame_section () 118{ 119#ifdef EH_FRAME_SECTION_NAME 120#ifdef HAVE_LD_RO_RW_SECTION_MIXING 121 int fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); 122 int per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); 123 int lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); 124 int flags; 125 126 flags = (! flag_pic 127 || ((fde_encoding & 0x70) != DW_EH_PE_absptr 128 && (fde_encoding & 0x70) != DW_EH_PE_aligned 129 && (per_encoding & 0x70) != DW_EH_PE_absptr 130 && (per_encoding & 0x70) != DW_EH_PE_aligned 131 && (lsda_encoding & 0x70) != DW_EH_PE_absptr 132 && (lsda_encoding & 0x70) != DW_EH_PE_aligned)) 133 ? 0 : SECTION_WRITE; 134 named_section_flags (EH_FRAME_SECTION_NAME, flags); 135#else 136 named_section_flags (EH_FRAME_SECTION_NAME, SECTION_WRITE); 137#endif 138#else 139 tree label = get_file_function_name ('F'); 140 141 data_section (); 142 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); 143 (*targetm.asm_out.globalize_label) (asm_out_file, IDENTIFIER_POINTER (label)); 144 ASM_OUTPUT_LABEL (asm_out_file, IDENTIFIER_POINTER (label)); 145#endif 146} 147 148/* Array of RTXes referenced by the debugging information, which therefore 149 must be kept around forever. */ 150static GTY(()) varray_type used_rtx_varray; 151 152/* A pointer to the base of a list of incomplete types which might be 153 completed at some later time. incomplete_types_list needs to be a VARRAY 154 because we want to tell the garbage collector about it. */ 155static GTY(()) varray_type incomplete_types; 156 157/* A pointer to the base of a table of references to declaration 158 scopes. This table is a display which tracks the nesting 159 of declaration scopes at the current scope and containing 160 scopes. This table is used to find the proper place to 161 define type declaration DIE's. */ 162static GTY(()) varray_type decl_scope_table; 163 164#if defined (DWARF2_DEBUGGING_INFO) || defined (DWARF2_UNWIND_INFO) 165 166/* How to start an assembler comment. */ 167#ifndef ASM_COMMENT_START 168#define ASM_COMMENT_START ";#" 169#endif 170 171typedef struct dw_cfi_struct *dw_cfi_ref; 172typedef struct dw_fde_struct *dw_fde_ref; 173typedef union dw_cfi_oprnd_struct *dw_cfi_oprnd_ref; 174 175/* Call frames are described using a sequence of Call Frame 176 Information instructions. The register number, offset 177 and address fields are provided as possible operands; 178 their use is selected by the opcode field. */ 179 180typedef union dw_cfi_oprnd_struct 181{ 182 unsigned long dw_cfi_reg_num; 183 long int dw_cfi_offset; 184 const char *dw_cfi_addr; 185 struct dw_loc_descr_struct *dw_cfi_loc; 186} 187dw_cfi_oprnd; 188 189typedef struct dw_cfi_struct 190{ 191 dw_cfi_ref dw_cfi_next; 192 enum dwarf_call_frame_info dw_cfi_opc; 193 dw_cfi_oprnd dw_cfi_oprnd1; 194 dw_cfi_oprnd dw_cfi_oprnd2; 195} 196dw_cfi_node; 197 198/* This is how we define the location of the CFA. We use to handle it 199 as REG + OFFSET all the time, but now it can be more complex. 200 It can now be either REG + CFA_OFFSET or *(REG + BASE_OFFSET) + CFA_OFFSET. 201 Instead of passing around REG and OFFSET, we pass a copy 202 of this structure. */ 203typedef struct cfa_loc 204{ 205 unsigned long reg; 206 long offset; 207 long base_offset; 208 int indirect; /* 1 if CFA is accessed via a dereference. */ 209} dw_cfa_location; 210 211/* All call frame descriptions (FDE's) in the GCC generated DWARF 212 refer to a single Common Information Entry (CIE), defined at 213 the beginning of the .debug_frame section. This use of a single 214 CIE obviates the need to keep track of multiple CIE's 215 in the DWARF generation routines below. */ 216 217typedef struct dw_fde_struct 218{ 219 const char *dw_fde_begin; 220 const char *dw_fde_current_label; 221 const char *dw_fde_end; 222 dw_cfi_ref dw_fde_cfi; 223 unsigned funcdef_number; 224 unsigned all_throwers_are_sibcalls : 1; 225 unsigned nothrow : 1; 226 unsigned uses_eh_lsda : 1; 227} 228dw_fde_node; 229 230/* Maximum size (in bytes) of an artificially generated label. */ 231#define MAX_ARTIFICIAL_LABEL_BYTES 30 232 233/* The size of addresses as they appear in the Dwarf 2 data. 234 Some architectures use word addresses to refer to code locations, 235 but Dwarf 2 info always uses byte addresses. On such machines, 236 Dwarf 2 addresses need to be larger than the architecture's 237 pointers. */ 238#ifndef DWARF2_ADDR_SIZE 239#define DWARF2_ADDR_SIZE (POINTER_SIZE / BITS_PER_UNIT) 240#endif 241 242/* The size in bytes of a DWARF field indicating an offset or length 243 relative to a debug info section, specified to be 4 bytes in the 244 DWARF-2 specification. The SGI/MIPS ABI defines it to be the same 245 as PTR_SIZE. */ 246 247#ifndef DWARF_OFFSET_SIZE 248#define DWARF_OFFSET_SIZE 4 249#endif 250 251#define DWARF_VERSION 2 252 253/* Round SIZE up to the nearest BOUNDARY. */ 254#define DWARF_ROUND(SIZE,BOUNDARY) \ 255 ((((SIZE) + (BOUNDARY) - 1) / (BOUNDARY)) * (BOUNDARY)) 256 257/* Offsets recorded in opcodes are a multiple of this alignment factor. */ 258#ifndef DWARF_CIE_DATA_ALIGNMENT 259#ifdef STACK_GROWS_DOWNWARD 260#define DWARF_CIE_DATA_ALIGNMENT (-((int) UNITS_PER_WORD)) 261#else 262#define DWARF_CIE_DATA_ALIGNMENT ((int) UNITS_PER_WORD) 263#endif 264#endif 265 266/* A pointer to the base of a table that contains frame description 267 information for each routine. */ 268static dw_fde_ref fde_table; 269 270/* Number of elements currently allocated for fde_table. */ 271static unsigned fde_table_allocated; 272 273/* Number of elements in fde_table currently in use. */ 274static unsigned fde_table_in_use; 275 276/* Size (in elements) of increments by which we may expand the 277 fde_table. */ 278#define FDE_TABLE_INCREMENT 256 279 280/* A list of call frame insns for the CIE. */ 281static dw_cfi_ref cie_cfi_head; 282 283/* Some DWARF extensions (e.g., MIPS/SGI) implement a subprogram 284 attribute that accelerates the lookup of the FDE associated 285 with the subprogram. This variable holds the table index of the FDE 286 associated with the current function (body) definition. */ 287static unsigned current_funcdef_fde; 288 289struct ht *debug_str_hash; 290 291struct indirect_string_node 292{ 293 struct ht_identifier id; 294 unsigned int refcount; 295 unsigned int form; 296 char *label; 297}; 298 299/* Forward declarations for functions defined in this file. */ 300 301static char *stripattributes PARAMS ((const char *)); 302static const char *dwarf_cfi_name PARAMS ((unsigned)); 303static dw_cfi_ref new_cfi PARAMS ((void)); 304static void add_cfi PARAMS ((dw_cfi_ref *, dw_cfi_ref)); 305static void add_fde_cfi PARAMS ((const char *, dw_cfi_ref)); 306static void lookup_cfa_1 PARAMS ((dw_cfi_ref, 307 dw_cfa_location *)); 308static void lookup_cfa PARAMS ((dw_cfa_location *)); 309static void reg_save PARAMS ((const char *, unsigned, 310 unsigned, long)); 311static void initial_return_save PARAMS ((rtx)); 312static long stack_adjust_offset PARAMS ((rtx)); 313static void output_cfi PARAMS ((dw_cfi_ref, dw_fde_ref, int)); 314static void output_call_frame_info PARAMS ((int)); 315static void dwarf2out_stack_adjust PARAMS ((rtx)); 316static void queue_reg_save PARAMS ((const char *, rtx, long)); 317static void flush_queued_reg_saves PARAMS ((void)); 318static bool clobbers_queued_reg_save PARAMS ((rtx)); 319static void dwarf2out_frame_debug_expr PARAMS ((rtx, const char *)); 320 321/* Support for complex CFA locations. */ 322static void output_cfa_loc PARAMS ((dw_cfi_ref)); 323static void get_cfa_from_loc_descr PARAMS ((dw_cfa_location *, 324 struct dw_loc_descr_struct *)); 325static struct dw_loc_descr_struct *build_cfa_loc 326 PARAMS ((dw_cfa_location *)); 327static void def_cfa_1 PARAMS ((const char *, 328 dw_cfa_location *)); 329 330/* How to start an assembler comment. */ 331#ifndef ASM_COMMENT_START 332#define ASM_COMMENT_START ";#" 333#endif 334 335/* Data and reference forms for relocatable data. */ 336#define DW_FORM_data (DWARF_OFFSET_SIZE == 8 ? DW_FORM_data8 : DW_FORM_data4) 337#define DW_FORM_ref (DWARF_OFFSET_SIZE == 8 ? DW_FORM_ref8 : DW_FORM_ref4) 338 339#ifndef DEBUG_FRAME_SECTION 340#define DEBUG_FRAME_SECTION ".debug_frame" 341#endif 342 343#ifndef FUNC_BEGIN_LABEL 344#define FUNC_BEGIN_LABEL "LFB" 345#endif 346 347#ifndef FUNC_END_LABEL 348#define FUNC_END_LABEL "LFE" 349#endif 350 351#define FRAME_BEGIN_LABEL "Lframe" 352#define CIE_AFTER_SIZE_LABEL "LSCIE" 353#define CIE_END_LABEL "LECIE" 354#define FDE_LABEL "LSFDE" 355#define FDE_AFTER_SIZE_LABEL "LASFDE" 356#define FDE_END_LABEL "LEFDE" 357#define LINE_NUMBER_BEGIN_LABEL "LSLT" 358#define LINE_NUMBER_END_LABEL "LELT" 359#define LN_PROLOG_AS_LABEL "LASLTP" 360#define LN_PROLOG_END_LABEL "LELTP" 361#define DIE_LABEL_PREFIX "DW" 362 363/* The DWARF 2 CFA column which tracks the return address. Normally this 364 is the column for PC, or the first column after all of the hard 365 registers. */ 366#ifndef DWARF_FRAME_RETURN_COLUMN 367#ifdef PC_REGNUM 368#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGNUM (PC_REGNUM) 369#else 370#define DWARF_FRAME_RETURN_COLUMN DWARF_FRAME_REGISTERS 371#endif 372#endif 373 374/* The mapping from gcc register number to DWARF 2 CFA column number. By 375 default, we just provide columns for all registers. */ 376#ifndef DWARF_FRAME_REGNUM 377#define DWARF_FRAME_REGNUM(REG) DBX_REGISTER_NUMBER (REG) 378#endif 379 380/* The offset from the incoming value of %sp to the top of the stack frame 381 for the current function. */ 382#ifndef INCOMING_FRAME_SP_OFFSET 383#define INCOMING_FRAME_SP_OFFSET 0 384#endif 385 386/* Hook used by __throw. */ 387 388rtx 389expand_builtin_dwarf_sp_column () 390{ 391 return GEN_INT (DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)); 392} 393 394/* Return a pointer to a copy of the section string name S with all 395 attributes stripped off, and an asterisk prepended (for assemble_name). */ 396 397static inline char * 398stripattributes (s) 399 const char *s; 400{ 401 char *stripped = xmalloc (strlen (s) + 2); 402 char *p = stripped; 403 404 *p++ = '*'; 405 406 while (*s && *s != ',') 407 *p++ = *s++; 408 409 *p = '\0'; 410 return stripped; 411} 412 413/* Generate code to initialize the register size table. */ 414 415void 416expand_builtin_init_dwarf_reg_sizes (address) 417 tree address; 418{ 419 int i; 420 enum machine_mode mode = TYPE_MODE (char_type_node); 421 rtx addr = expand_expr (address, NULL_RTX, VOIDmode, 0); 422 rtx mem = gen_rtx_MEM (BLKmode, addr); 423 424 for (i = 0; i < FIRST_PSEUDO_REGISTER; i++) 425 if (DWARF_FRAME_REGNUM (i) < DWARF_FRAME_REGISTERS) 426 { 427 HOST_WIDE_INT offset = DWARF_FRAME_REGNUM (i) * GET_MODE_SIZE (mode); 428 HOST_WIDE_INT size = GET_MODE_SIZE (reg_raw_mode[i]); 429 430 if (offset < 0) 431 continue; 432 433 emit_move_insn (adjust_address (mem, mode, offset), GEN_INT (size)); 434 } 435} 436 437/* Convert a DWARF call frame info. operation to its string name */ 438 439static const char * 440dwarf_cfi_name (cfi_opc) 441 unsigned cfi_opc; 442{ 443 switch (cfi_opc) 444 { 445 case DW_CFA_advance_loc: 446 return "DW_CFA_advance_loc"; 447 case DW_CFA_offset: 448 return "DW_CFA_offset"; 449 case DW_CFA_restore: 450 return "DW_CFA_restore"; 451 case DW_CFA_nop: 452 return "DW_CFA_nop"; 453 case DW_CFA_set_loc: 454 return "DW_CFA_set_loc"; 455 case DW_CFA_advance_loc1: 456 return "DW_CFA_advance_loc1"; 457 case DW_CFA_advance_loc2: 458 return "DW_CFA_advance_loc2"; 459 case DW_CFA_advance_loc4: 460 return "DW_CFA_advance_loc4"; 461 case DW_CFA_offset_extended: 462 return "DW_CFA_offset_extended"; 463 case DW_CFA_restore_extended: 464 return "DW_CFA_restore_extended"; 465 case DW_CFA_undefined: 466 return "DW_CFA_undefined"; 467 case DW_CFA_same_value: 468 return "DW_CFA_same_value"; 469 case DW_CFA_register: 470 return "DW_CFA_register"; 471 case DW_CFA_remember_state: 472 return "DW_CFA_remember_state"; 473 case DW_CFA_restore_state: 474 return "DW_CFA_restore_state"; 475 case DW_CFA_def_cfa: 476 return "DW_CFA_def_cfa"; 477 case DW_CFA_def_cfa_register: 478 return "DW_CFA_def_cfa_register"; 479 case DW_CFA_def_cfa_offset: 480 return "DW_CFA_def_cfa_offset"; 481 482 /* DWARF 3 */ 483 case DW_CFA_def_cfa_expression: 484 return "DW_CFA_def_cfa_expression"; 485 case DW_CFA_expression: 486 return "DW_CFA_expression"; 487 case DW_CFA_offset_extended_sf: 488 return "DW_CFA_offset_extended_sf"; 489 case DW_CFA_def_cfa_sf: 490 return "DW_CFA_def_cfa_sf"; 491 case DW_CFA_def_cfa_offset_sf: 492 return "DW_CFA_def_cfa_offset_sf"; 493 494 /* SGI/MIPS specific */ 495 case DW_CFA_MIPS_advance_loc8: 496 return "DW_CFA_MIPS_advance_loc8"; 497 498 /* GNU extensions */ 499 case DW_CFA_GNU_window_save: 500 return "DW_CFA_GNU_window_save"; 501 case DW_CFA_GNU_args_size: 502 return "DW_CFA_GNU_args_size"; 503 case DW_CFA_GNU_negative_offset_extended: 504 return "DW_CFA_GNU_negative_offset_extended"; 505 506 default: 507 return "DW_CFA_<unknown>"; 508 } 509} 510 511/* Return a pointer to a newly allocated Call Frame Instruction. */ 512 513static inline dw_cfi_ref 514new_cfi () 515{ 516 dw_cfi_ref cfi = (dw_cfi_ref) xmalloc (sizeof (dw_cfi_node)); 517 518 cfi->dw_cfi_next = NULL; 519 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = 0; 520 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = 0; 521 522 return cfi; 523} 524 525/* Add a Call Frame Instruction to list of instructions. */ 526 527static inline void 528add_cfi (list_head, cfi) 529 dw_cfi_ref *list_head; 530 dw_cfi_ref cfi; 531{ 532 dw_cfi_ref *p; 533 534 /* Find the end of the chain. */ 535 for (p = list_head; (*p) != NULL; p = &(*p)->dw_cfi_next) 536 ; 537 538 *p = cfi; 539} 540 541/* Generate a new label for the CFI info to refer to. */ 542 543char * 544dwarf2out_cfi_label () 545{ 546 static char label[20]; 547 static unsigned long label_num = 0; 548 549 ASM_GENERATE_INTERNAL_LABEL (label, "LCFI", label_num++); 550 ASM_OUTPUT_LABEL (asm_out_file, label); 551 return label; 552} 553 554/* Add CFI to the current fde at the PC value indicated by LABEL if specified, 555 or to the CIE if LABEL is NULL. */ 556 557static void 558add_fde_cfi (label, cfi) 559 const char *label; 560 dw_cfi_ref cfi; 561{ 562 if (label) 563 { 564 dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; 565 566 if (*label == 0) 567 label = dwarf2out_cfi_label (); 568 569 if (fde->dw_fde_current_label == NULL 570 || strcmp (label, fde->dw_fde_current_label) != 0) 571 { 572 dw_cfi_ref xcfi; 573 574 fde->dw_fde_current_label = label = xstrdup (label); 575 576 /* Set the location counter to the new label. */ 577 xcfi = new_cfi (); 578 xcfi->dw_cfi_opc = DW_CFA_advance_loc4; 579 xcfi->dw_cfi_oprnd1.dw_cfi_addr = label; 580 add_cfi (&fde->dw_fde_cfi, xcfi); 581 } 582 583 add_cfi (&fde->dw_fde_cfi, cfi); 584 } 585 586 else 587 add_cfi (&cie_cfi_head, cfi); 588} 589 590/* Subroutine of lookup_cfa. */ 591 592static inline void 593lookup_cfa_1 (cfi, loc) 594 dw_cfi_ref cfi; 595 dw_cfa_location *loc; 596{ 597 switch (cfi->dw_cfi_opc) 598 { 599 case DW_CFA_def_cfa_offset: 600 loc->offset = cfi->dw_cfi_oprnd1.dw_cfi_offset; 601 break; 602 case DW_CFA_def_cfa_register: 603 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; 604 break; 605 case DW_CFA_def_cfa: 606 loc->reg = cfi->dw_cfi_oprnd1.dw_cfi_reg_num; 607 loc->offset = cfi->dw_cfi_oprnd2.dw_cfi_offset; 608 break; 609 case DW_CFA_def_cfa_expression: 610 get_cfa_from_loc_descr (loc, cfi->dw_cfi_oprnd1.dw_cfi_loc); 611 break; 612 default: 613 break; 614 } 615} 616 617/* Find the previous value for the CFA. */ 618 619static void 620lookup_cfa (loc) 621 dw_cfa_location *loc; 622{ 623 dw_cfi_ref cfi; 624 625 loc->reg = (unsigned long) -1; 626 loc->offset = 0; 627 loc->indirect = 0; 628 loc->base_offset = 0; 629 630 for (cfi = cie_cfi_head; cfi; cfi = cfi->dw_cfi_next) 631 lookup_cfa_1 (cfi, loc); 632 633 if (fde_table_in_use) 634 { 635 dw_fde_ref fde = &fde_table[fde_table_in_use - 1]; 636 for (cfi = fde->dw_fde_cfi; cfi; cfi = cfi->dw_cfi_next) 637 lookup_cfa_1 (cfi, loc); 638 } 639} 640 641/* The current rule for calculating the DWARF2 canonical frame address. */ 642static dw_cfa_location cfa; 643 644/* The register used for saving registers to the stack, and its offset 645 from the CFA. */ 646static dw_cfa_location cfa_store; 647 648/* The running total of the size of arguments pushed onto the stack. */ 649static long args_size; 650 651/* The last args_size we actually output. */ 652static long old_args_size; 653 654/* Entry point to update the canonical frame address (CFA). 655 LABEL is passed to add_fde_cfi. The value of CFA is now to be 656 calculated from REG+OFFSET. */ 657 658void 659dwarf2out_def_cfa (label, reg, offset) 660 const char *label; 661 unsigned reg; 662 long offset; 663{ 664 dw_cfa_location loc; 665 loc.indirect = 0; 666 loc.base_offset = 0; 667 loc.reg = reg; 668 loc.offset = offset; 669 def_cfa_1 (label, &loc); 670} 671 672/* This routine does the actual work. The CFA is now calculated from 673 the dw_cfa_location structure. */ 674 675static void 676def_cfa_1 (label, loc_p) 677 const char *label; 678 dw_cfa_location *loc_p; 679{ 680 dw_cfi_ref cfi; 681 dw_cfa_location old_cfa, loc; 682 683 cfa = *loc_p; 684 loc = *loc_p; 685 686 if (cfa_store.reg == loc.reg && loc.indirect == 0) 687 cfa_store.offset = loc.offset; 688 689 loc.reg = DWARF_FRAME_REGNUM (loc.reg); 690 lookup_cfa (&old_cfa); 691 692 /* If nothing changed, no need to issue any call frame instructions. */ 693 if (loc.reg == old_cfa.reg && loc.offset == old_cfa.offset 694 && loc.indirect == old_cfa.indirect 695 && (loc.indirect == 0 || loc.base_offset == old_cfa.base_offset)) 696 return; 697 698 cfi = new_cfi (); 699 700 if (loc.reg == old_cfa.reg && !loc.indirect) 701 { 702 /* Construct a "DW_CFA_def_cfa_offset <offset>" instruction, 703 indicating the CFA register did not change but the offset 704 did. */ 705 cfi->dw_cfi_opc = DW_CFA_def_cfa_offset; 706 cfi->dw_cfi_oprnd1.dw_cfi_offset = loc.offset; 707 } 708 709#ifndef MIPS_DEBUGGING_INFO /* SGI dbx thinks this means no offset. */ 710 else if (loc.offset == old_cfa.offset && old_cfa.reg != (unsigned long) -1 711 && !loc.indirect) 712 { 713 /* Construct a "DW_CFA_def_cfa_register <register>" instruction, 714 indicating the CFA register has changed to <register> but the 715 offset has not changed. */ 716 cfi->dw_cfi_opc = DW_CFA_def_cfa_register; 717 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; 718 } 719#endif 720 721 else if (loc.indirect == 0) 722 { 723 /* Construct a "DW_CFA_def_cfa <register> <offset>" instruction, 724 indicating the CFA register has changed to <register> with 725 the specified offset. */ 726 cfi->dw_cfi_opc = DW_CFA_def_cfa; 727 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = loc.reg; 728 cfi->dw_cfi_oprnd2.dw_cfi_offset = loc.offset; 729 } 730 else 731 { 732 /* Construct a DW_CFA_def_cfa_expression instruction to 733 calculate the CFA using a full location expression since no 734 register-offset pair is available. */ 735 struct dw_loc_descr_struct *loc_list; 736 737 cfi->dw_cfi_opc = DW_CFA_def_cfa_expression; 738 loc_list = build_cfa_loc (&loc); 739 cfi->dw_cfi_oprnd1.dw_cfi_loc = loc_list; 740 } 741 742 add_fde_cfi (label, cfi); 743} 744 745/* Add the CFI for saving a register. REG is the CFA column number. 746 LABEL is passed to add_fde_cfi. 747 If SREG is -1, the register is saved at OFFSET from the CFA; 748 otherwise it is saved in SREG. */ 749 750static void 751reg_save (label, reg, sreg, offset) 752 const char *label; 753 unsigned reg; 754 unsigned sreg; 755 long offset; 756{ 757 dw_cfi_ref cfi = new_cfi (); 758 759 cfi->dw_cfi_oprnd1.dw_cfi_reg_num = reg; 760 761 /* The following comparison is correct. -1 is used to indicate that 762 the value isn't a register number. */ 763 if (sreg == (unsigned int) -1) 764 { 765 if (reg & ~0x3f) 766 /* The register number won't fit in 6 bits, so we have to use 767 the long form. */ 768 cfi->dw_cfi_opc = DW_CFA_offset_extended; 769 else 770 cfi->dw_cfi_opc = DW_CFA_offset; 771 772#ifdef ENABLE_CHECKING 773 { 774 /* If we get an offset that is not a multiple of 775 DWARF_CIE_DATA_ALIGNMENT, there is either a bug in the 776 definition of DWARF_CIE_DATA_ALIGNMENT, or a bug in the machine 777 description. */ 778 long check_offset = offset / DWARF_CIE_DATA_ALIGNMENT; 779 780 if (check_offset * DWARF_CIE_DATA_ALIGNMENT != offset) 781 abort (); 782 } 783#endif 784 offset /= DWARF_CIE_DATA_ALIGNMENT; 785 if (offset < 0) 786 cfi->dw_cfi_opc = DW_CFA_offset_extended_sf; 787 788 cfi->dw_cfi_oprnd2.dw_cfi_offset = offset; 789 } 790 else if (sreg == reg) 791 /* We could emit a DW_CFA_same_value in this case, but don't bother. */ 792 return; 793 else 794 { 795 cfi->dw_cfi_opc = DW_CFA_register; 796 cfi->dw_cfi_oprnd2.dw_cfi_reg_num = sreg; 797 } 798 799 add_fde_cfi (label, cfi); 800} 801 802/* Add the CFI for saving a register window. LABEL is passed to reg_save. 803 This CFI tells the unwinder that it needs to restore the window registers 804 from the previous frame's window save area. 805 806 ??? Perhaps we should note in the CIE where windows are saved (instead of 807 assuming 0(cfa)) and what registers are in the window. */ 808 809void 810dwarf2out_window_save (label) 811 const char *label; 812{ 813 dw_cfi_ref cfi = new_cfi (); 814 815 cfi->dw_cfi_opc = DW_CFA_GNU_window_save; 816 add_fde_cfi (label, cfi); 817} 818 819/* Add a CFI to update the running total of the size of arguments 820 pushed onto the stack. */ 821 822void 823dwarf2out_args_size (label, size) 824 const char *label; 825 long size; 826{ 827 dw_cfi_ref cfi; 828 829 if (size == old_args_size) 830 return; 831 832 old_args_size = size; 833 834 cfi = new_cfi (); 835 cfi->dw_cfi_opc = DW_CFA_GNU_args_size; 836 cfi->dw_cfi_oprnd1.dw_cfi_offset = size; 837 add_fde_cfi (label, cfi); 838} 839 840/* Entry point for saving a register to the stack. REG is the GCC register 841 number. LABEL and OFFSET are passed to reg_save. */ 842 843void 844dwarf2out_reg_save (label, reg, offset) 845 const char *label; 846 unsigned reg; 847 long offset; 848{ 849 reg_save (label, DWARF_FRAME_REGNUM (reg), -1, offset); 850} 851 852/* Entry point for saving the return address in the stack. 853 LABEL and OFFSET are passed to reg_save. */ 854 855void 856dwarf2out_return_save (label, offset) 857 const char *label; 858 long offset; 859{ 860 reg_save (label, DWARF_FRAME_RETURN_COLUMN, -1, offset); 861} 862 863/* Entry point for saving the return address in a register. 864 LABEL and SREG are passed to reg_save. */ 865 866void 867dwarf2out_return_reg (label, sreg) 868 const char *label; 869 unsigned sreg; 870{ 871 reg_save (label, DWARF_FRAME_RETURN_COLUMN, sreg, 0); 872} 873 874/* Record the initial position of the return address. RTL is 875 INCOMING_RETURN_ADDR_RTX. */ 876 877static void 878initial_return_save (rtl) 879 rtx rtl; 880{ 881 unsigned int reg = (unsigned int) -1; 882 HOST_WIDE_INT offset = 0; 883 884 switch (GET_CODE (rtl)) 885 { 886 case REG: 887 /* RA is in a register. */ 888 reg = DWARF_FRAME_REGNUM (REGNO (rtl)); 889 break; 890 891 case MEM: 892 /* RA is on the stack. */ 893 rtl = XEXP (rtl, 0); 894 switch (GET_CODE (rtl)) 895 { 896 case REG: 897 if (REGNO (rtl) != STACK_POINTER_REGNUM) 898 abort (); 899 offset = 0; 900 break; 901 902 case PLUS: 903 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) 904 abort (); 905 offset = INTVAL (XEXP (rtl, 1)); 906 break; 907 908 case MINUS: 909 if (REGNO (XEXP (rtl, 0)) != STACK_POINTER_REGNUM) 910 abort (); 911 offset = -INTVAL (XEXP (rtl, 1)); 912 break; 913 914 default: 915 abort (); 916 } 917 918 break; 919 920 case PLUS: 921 /* The return address is at some offset from any value we can 922 actually load. For instance, on the SPARC it is in %i7+8. Just 923 ignore the offset for now; it doesn't matter for unwinding frames. */ 924 if (GET_CODE (XEXP (rtl, 1)) != CONST_INT) 925 abort (); 926 initial_return_save (XEXP (rtl, 0)); 927 return; 928 929 default: 930 abort (); 931 } 932 933 reg_save (NULL, DWARF_FRAME_RETURN_COLUMN, reg, offset - cfa.offset); 934} 935 936/* Given a SET, calculate the amount of stack adjustment it 937 contains. */ 938 939static long 940stack_adjust_offset (pattern) 941 rtx pattern; 942{ 943 rtx src = SET_SRC (pattern); 944 rtx dest = SET_DEST (pattern); 945 HOST_WIDE_INT offset = 0; 946 enum rtx_code code; 947 948 if (dest == stack_pointer_rtx) 949 { 950 /* (set (reg sp) (plus (reg sp) (const_int))) */ 951 code = GET_CODE (src); 952 if (! (code == PLUS || code == MINUS) 953 || XEXP (src, 0) != stack_pointer_rtx 954 || GET_CODE (XEXP (src, 1)) != CONST_INT) 955 return 0; 956 957 offset = INTVAL (XEXP (src, 1)); 958 if (code == PLUS) 959 offset = -offset; 960 } 961 else if (GET_CODE (dest) == MEM) 962 { 963 /* (set (mem (pre_dec (reg sp))) (foo)) */ 964 src = XEXP (dest, 0); 965 code = GET_CODE (src); 966 967 switch (code) 968 { 969 case PRE_MODIFY: 970 case POST_MODIFY: 971 if (XEXP (src, 0) == stack_pointer_rtx) 972 { 973 rtx val = XEXP (XEXP (src, 1), 1); 974 /* We handle only adjustments by constant amount. */ 975 if (GET_CODE (XEXP (src, 1)) != PLUS || 976 GET_CODE (val) != CONST_INT) 977 abort (); 978 offset = -INTVAL (val); 979 break; 980 } 981 return 0; 982 983 case PRE_DEC: 984 case POST_DEC: 985 if (XEXP (src, 0) == stack_pointer_rtx) 986 { 987 offset = GET_MODE_SIZE (GET_MODE (dest)); 988 break; 989 } 990 return 0; 991 992 case PRE_INC: 993 case POST_INC: 994 if (XEXP (src, 0) == stack_pointer_rtx) 995 { 996 offset = -GET_MODE_SIZE (GET_MODE (dest)); 997 break; 998 } 999 return 0; 1000 1001 default: 1002 return 0; 1003 } 1004 } 1005 else 1006 return 0; 1007 1008 return offset; 1009} 1010 1011/* Check INSN to see if it looks like a push or a stack adjustment, and 1012 make a note of it if it does. EH uses this information to find out how 1013 much extra space it needs to pop off the stack. */ 1014 1015static void 1016dwarf2out_stack_adjust (insn) 1017 rtx insn; 1018{ 1019 HOST_WIDE_INT offset; 1020 const char *label; 1021 int i; 1022 1023 if (!flag_asynchronous_unwind_tables && GET_CODE (insn) == CALL_INSN) 1024 { 1025 /* Extract the size of the args from the CALL rtx itself. */ 1026 insn = PATTERN (insn); 1027 if (GET_CODE (insn) == PARALLEL) 1028 insn = XVECEXP (insn, 0, 0); 1029 if (GET_CODE (insn) == SET) 1030 insn = SET_SRC (insn); 1031 if (GET_CODE (insn) != CALL) 1032 abort (); 1033 1034 dwarf2out_args_size ("", INTVAL (XEXP (insn, 1))); 1035 return; 1036 } 1037 1038 /* If only calls can throw, and we have a frame pointer, 1039 save up adjustments until we see the CALL_INSN. */ 1040 else if (!flag_asynchronous_unwind_tables && cfa.reg != STACK_POINTER_REGNUM) 1041 return; 1042 1043 if (GET_CODE (insn) == BARRIER) 1044 { 1045 /* When we see a BARRIER, we know to reset args_size to 0. Usually 1046 the compiler will have already emitted a stack adjustment, but 1047 doesn't bother for calls to noreturn functions. */ 1048#ifdef STACK_GROWS_DOWNWARD 1049 offset = -args_size; 1050#else 1051 offset = args_size; 1052#endif 1053 } 1054 else if (GET_CODE (PATTERN (insn)) == SET) 1055 offset = stack_adjust_offset (PATTERN (insn)); 1056 else if (GET_CODE (PATTERN (insn)) == PARALLEL 1057 || GET_CODE (PATTERN (insn)) == SEQUENCE) 1058 { 1059 /* There may be stack adjustments inside compound insns. Search 1060 for them. */ 1061 for (offset = 0, i = XVECLEN (PATTERN (insn), 0) - 1; i >= 0; i--) 1062 if (GET_CODE (XVECEXP (PATTERN (insn), 0, i)) == SET) 1063 offset += stack_adjust_offset (XVECEXP (PATTERN (insn), 0, i)); 1064 } 1065 else 1066 return; 1067 1068 if (offset == 0) 1069 return; 1070 1071 if (cfa.reg == STACK_POINTER_REGNUM) 1072 cfa.offset += offset; 1073 1074#ifndef STACK_GROWS_DOWNWARD 1075 offset = -offset; 1076#endif 1077 1078 args_size += offset; 1079 if (args_size < 0) 1080 args_size = 0; 1081 1082 label = dwarf2out_cfi_label (); 1083 def_cfa_1 (label, &cfa); 1084 dwarf2out_args_size (label, args_size); 1085} 1086 1087/* We delay emitting a register save until either (a) we reach the end 1088 of the prologue or (b) the register is clobbered. This clusters 1089 register saves so that there are fewer pc advances. */ 1090 1091struct queued_reg_save 1092{ 1093 struct queued_reg_save *next; 1094 rtx reg; 1095 long cfa_offset; 1096}; 1097 1098static struct queued_reg_save *queued_reg_saves; 1099static const char *last_reg_save_label; 1100 1101static void 1102queue_reg_save (label, reg, offset) 1103 const char *label; 1104 rtx reg; 1105 long offset; 1106{ 1107 struct queued_reg_save *q = (struct queued_reg_save *) xmalloc (sizeof (*q)); 1108 1109 q->next = queued_reg_saves; 1110 q->reg = reg; 1111 q->cfa_offset = offset; 1112 queued_reg_saves = q; 1113 1114 last_reg_save_label = label; 1115} 1116 1117static void 1118flush_queued_reg_saves () 1119{ 1120 struct queued_reg_save *q, *next; 1121 1122 for (q = queued_reg_saves; q; q = next) 1123 { 1124 dwarf2out_reg_save (last_reg_save_label, REGNO (q->reg), q->cfa_offset); 1125 next = q->next; 1126 free (q); 1127 } 1128 1129 queued_reg_saves = NULL; 1130 last_reg_save_label = NULL; 1131} 1132 1133static bool 1134clobbers_queued_reg_save (insn) 1135 rtx insn; 1136{ 1137 struct queued_reg_save *q; 1138 1139 for (q = queued_reg_saves; q; q = q->next) 1140 if (modified_in_p (q->reg, insn)) 1141 return true; 1142 1143 return false; 1144} 1145 1146 1147/* A temporary register holding an integral value used in adjusting SP 1148 or setting up the store_reg. The "offset" field holds the integer 1149 value, not an offset. */ 1150static dw_cfa_location cfa_temp; 1151 1152/* Record call frame debugging information for an expression EXPR, 1153 which either sets SP or FP (adjusting how we calculate the frame 1154 address) or saves a register to the stack. LABEL indicates the 1155 address of EXPR. 1156 1157 This function encodes a state machine mapping rtxes to actions on 1158 cfa, cfa_store, and cfa_temp.reg. We describe these rules so 1159 users need not read the source code. 1160 1161 The High-Level Picture 1162 1163 Changes in the register we use to calculate the CFA: Currently we 1164 assume that if you copy the CFA register into another register, we 1165 should take the other one as the new CFA register; this seems to 1166 work pretty well. If it's wrong for some target, it's simple 1167 enough not to set RTX_FRAME_RELATED_P on the insn in question. 1168 1169 Changes in the register we use for saving registers to the stack: 1170 This is usually SP, but not always. Again, we deduce that if you 1171 copy SP into another register (and SP is not the CFA register), 1172 then the new register is the one we will be using for register 1173 saves. This also seems to work. 1174 1175 Register saves: There's not much guesswork about this one; if 1176 RTX_FRAME_RELATED_P is set on an insn which modifies memory, it's a 1177 register save, and the register used to calculate the destination 1178 had better be the one we think we're using for this purpose. 1179 1180 Except: If the register being saved is the CFA register, and the 1181 offset is nonzero, we are saving the CFA, so we assume we have to 1182 use DW_CFA_def_cfa_expression. If the offset is 0, we assume that 1183 the intent is to save the value of SP from the previous frame. 1184 1185 Invariants / Summaries of Rules 1186 1187 cfa current rule for calculating the CFA. It usually 1188 consists of a register and an offset. 1189 cfa_store register used by prologue code to save things to the stack 1190 cfa_store.offset is the offset from the value of 1191 cfa_store.reg to the actual CFA 1192 cfa_temp register holding an integral value. cfa_temp.offset 1193 stores the value, which will be used to adjust the 1194 stack pointer. cfa_temp is also used like cfa_store, 1195 to track stores to the stack via fp or a temp reg. 1196 1197 Rules 1- 4: Setting a register's value to cfa.reg or an expression 1198 with cfa.reg as the first operand changes the cfa.reg and its 1199 cfa.offset. Rule 1 and 4 also set cfa_temp.reg and 1200 cfa_temp.offset. 1201 1202 Rules 6- 9: Set a non-cfa.reg register value to a constant or an 1203 expression yielding a constant. This sets cfa_temp.reg 1204 and cfa_temp.offset. 1205 1206 Rule 5: Create a new register cfa_store used to save items to the 1207 stack. 1208 1209 Rules 10-14: Save a register to the stack. Define offset as the 1210 difference of the original location and cfa_store's 1211 location (or cfa_temp's location if cfa_temp is used). 1212 1213 The Rules 1214 1215 "{a,b}" indicates a choice of a xor b. 1216 "<reg>:cfa.reg" indicates that <reg> must equal cfa.reg. 1217 1218 Rule 1: 1219 (set <reg1> <reg2>:cfa.reg) 1220 effects: cfa.reg = <reg1> 1221 cfa.offset unchanged 1222 cfa_temp.reg = <reg1> 1223 cfa_temp.offset = cfa.offset 1224 1225 Rule 2: 1226 (set sp ({minus,plus,losum} {sp,fp}:cfa.reg 1227 {<const_int>,<reg>:cfa_temp.reg})) 1228 effects: cfa.reg = sp if fp used 1229 cfa.offset += {+/- <const_int>, cfa_temp.offset} if cfa.reg==sp 1230 cfa_store.offset += {+/- <const_int>, cfa_temp.offset} 1231 if cfa_store.reg==sp 1232 1233 Rule 3: 1234 (set fp ({minus,plus,losum} <reg>:cfa.reg <const_int>)) 1235 effects: cfa.reg = fp 1236 cfa_offset += +/- <const_int> 1237 1238 Rule 4: 1239 (set <reg1> ({plus,losum} <reg2>:cfa.reg <const_int>)) 1240 constraints: <reg1> != fp 1241 <reg1> != sp 1242 effects: cfa.reg = <reg1> 1243 cfa_temp.reg = <reg1> 1244 cfa_temp.offset = cfa.offset 1245 1246 Rule 5: 1247 (set <reg1> (plus <reg2>:cfa_temp.reg sp:cfa.reg)) 1248 constraints: <reg1> != fp 1249 <reg1> != sp 1250 effects: cfa_store.reg = <reg1> 1251 cfa_store.offset = cfa.offset - cfa_temp.offset 1252 1253 Rule 6: 1254 (set <reg> <const_int>) 1255 effects: cfa_temp.reg = <reg> 1256 cfa_temp.offset = <const_int> 1257 1258 Rule 7: 1259 (set <reg1>:cfa_temp.reg (ior <reg2>:cfa_temp.reg <const_int>)) 1260 effects: cfa_temp.reg = <reg1> 1261 cfa_temp.offset |= <const_int> 1262 1263 Rule 8: 1264 (set <reg> (high <exp>)) 1265 effects: none 1266 1267 Rule 9: 1268 (set <reg> (lo_sum <exp> <const_int>)) 1269 effects: cfa_temp.reg = <reg> 1270 cfa_temp.offset = <const_int> 1271 1272 Rule 10: 1273 (set (mem (pre_modify sp:cfa_store (???? <reg1> <const_int>))) <reg2>) 1274 effects: cfa_store.offset -= <const_int> 1275 cfa.offset = cfa_store.offset if cfa.reg == sp 1276 cfa.reg = sp 1277 cfa.base_offset = -cfa_store.offset 1278 1279 Rule 11: 1280 (set (mem ({pre_inc,pre_dec} sp:cfa_store.reg)) <reg>) 1281 effects: cfa_store.offset += -/+ mode_size(mem) 1282 cfa.offset = cfa_store.offset if cfa.reg == sp 1283 cfa.reg = sp 1284 cfa.base_offset = -cfa_store.offset 1285 1286 Rule 12: 1287 (set (mem ({minus,plus,losum} <reg1>:{cfa_store,cfa_temp} <const_int>)) 1288 1289 <reg2>) 1290 effects: cfa.reg = <reg1> 1291 cfa.base_offset = -/+ <const_int> - {cfa_store,cfa_temp}.offset 1292 1293 Rule 13: 1294 (set (mem <reg1>:{cfa_store,cfa_temp}) <reg2>) 1295 effects: cfa.reg = <reg1> 1296 cfa.base_offset = -{cfa_store,cfa_temp}.offset 1297 1298 Rule 14: 1299 (set (mem (postinc <reg1>:cfa_temp <const_int>)) <reg2>) 1300 effects: cfa.reg = <reg1> 1301 cfa.base_offset = -cfa_temp.offset 1302 cfa_temp.offset -= mode_size(mem) */ 1303 1304static void 1305dwarf2out_frame_debug_expr (expr, label) 1306 rtx expr; 1307 const char *label; 1308{ 1309 rtx src, dest; 1310 HOST_WIDE_INT offset; 1311 1312 /* If RTX_FRAME_RELATED_P is set on a PARALLEL, process each member of 1313 the PARALLEL independently. The first element is always processed if 1314 it is a SET. This is for backward compatibility. Other elements 1315 are processed only if they are SETs and the RTX_FRAME_RELATED_P 1316 flag is set in them. */ 1317 if (GET_CODE (expr) == PARALLEL || GET_CODE (expr) == SEQUENCE) 1318 { 1319 int par_index; 1320 int limit = XVECLEN (expr, 0); 1321 1322 for (par_index = 0; par_index < limit; par_index++) 1323 if (GET_CODE (XVECEXP (expr, 0, par_index)) == SET 1324 && (RTX_FRAME_RELATED_P (XVECEXP (expr, 0, par_index)) 1325 || par_index == 0)) 1326 dwarf2out_frame_debug_expr (XVECEXP (expr, 0, par_index), label); 1327 1328 return; 1329 } 1330 1331 if (GET_CODE (expr) != SET) 1332 abort (); 1333 1334 src = SET_SRC (expr); 1335 dest = SET_DEST (expr); 1336 1337 switch (GET_CODE (dest)) 1338 { 1339 case REG: 1340 /* Rule 1 */ 1341 /* Update the CFA rule wrt SP or FP. Make sure src is 1342 relative to the current CFA register. */ 1343 switch (GET_CODE (src)) 1344 { 1345 /* Setting FP from SP. */ 1346 case REG: 1347 if (cfa.reg == (unsigned) REGNO (src)) 1348 /* OK. */ 1349 ; 1350 else 1351 abort (); 1352 1353 /* We used to require that dest be either SP or FP, but the 1354 ARM copies SP to a temporary register, and from there to 1355 FP. So we just rely on the backends to only set 1356 RTX_FRAME_RELATED_P on appropriate insns. */ 1357 cfa.reg = REGNO (dest); 1358 cfa_temp.reg = cfa.reg; 1359 cfa_temp.offset = cfa.offset; 1360 break; 1361 1362 case PLUS: 1363 case MINUS: 1364 case LO_SUM: 1365 if (dest == stack_pointer_rtx) 1366 { 1367 /* Rule 2 */ 1368 /* Adjusting SP. */ 1369 switch (GET_CODE (XEXP (src, 1))) 1370 { 1371 case CONST_INT: 1372 offset = INTVAL (XEXP (src, 1)); 1373 break; 1374 case REG: 1375 if ((unsigned) REGNO (XEXP (src, 1)) != cfa_temp.reg) 1376 abort (); 1377 offset = cfa_temp.offset; 1378 break; 1379 default: 1380 abort (); 1381 } 1382 1383 if (XEXP (src, 0) == hard_frame_pointer_rtx) 1384 { 1385 /* Restoring SP from FP in the epilogue. */ 1386 if (cfa.reg != (unsigned) HARD_FRAME_POINTER_REGNUM) 1387 abort (); 1388 cfa.reg = STACK_POINTER_REGNUM; 1389 } 1390 else if (GET_CODE (src) == LO_SUM) 1391 /* Assume we've set the source reg of the LO_SUM from sp. */ 1392 ; 1393 else if (XEXP (src, 0) != stack_pointer_rtx) 1394 abort (); 1395 1396 if (GET_CODE (src) != MINUS) 1397 offset = -offset; 1398 if (cfa.reg == STACK_POINTER_REGNUM) 1399 cfa.offset += offset; 1400 if (cfa_store.reg == STACK_POINTER_REGNUM) 1401 cfa_store.offset += offset; 1402 } 1403 else if (dest == hard_frame_pointer_rtx) 1404 { 1405 /* Rule 3 */ 1406 /* Either setting the FP from an offset of the SP, 1407 or adjusting the FP */ 1408 if (! frame_pointer_needed) 1409 abort (); 1410 1411 if (GET_CODE (XEXP (src, 0)) == REG 1412 && (unsigned) REGNO (XEXP (src, 0)) == cfa.reg 1413 && GET_CODE (XEXP (src, 1)) == CONST_INT) 1414 { 1415 offset = INTVAL (XEXP (src, 1)); 1416 if (GET_CODE (src) != MINUS) 1417 offset = -offset; 1418 cfa.offset += offset; 1419 cfa.reg = HARD_FRAME_POINTER_REGNUM; 1420 } 1421 else 1422 abort (); 1423 } 1424 else 1425 { 1426 if (GET_CODE (src) == MINUS) 1427 abort (); 1428 1429 /* Rule 4 */ 1430 if (GET_CODE (XEXP (src, 0)) == REG 1431 && REGNO (XEXP (src, 0)) == cfa.reg 1432 && GET_CODE (XEXP (src, 1)) == CONST_INT) 1433 { 1434 /* Setting a temporary CFA register that will be copied 1435 into the FP later on. */ 1436 offset = - INTVAL (XEXP (src, 1)); 1437 cfa.offset += offset; 1438 cfa.reg = REGNO (dest); 1439 /* Or used to save regs to the stack. */ 1440 cfa_temp.reg = cfa.reg; 1441 cfa_temp.offset = cfa.offset; 1442 } 1443 1444 /* Rule 5 */ 1445 else if (GET_CODE (XEXP (src, 0)) == REG 1446 && REGNO (XEXP (src, 0)) == cfa_temp.reg 1447 && XEXP (src, 1) == stack_pointer_rtx) 1448 { 1449 /* Setting a scratch register that we will use instead 1450 of SP for saving registers to the stack. */ 1451 if (cfa.reg != STACK_POINTER_REGNUM) 1452 abort (); 1453 cfa_store.reg = REGNO (dest); 1454 cfa_store.offset = cfa.offset - cfa_temp.offset; 1455 } 1456 1457 /* Rule 9 */ 1458 else if (GET_CODE (src) == LO_SUM 1459 && GET_CODE (XEXP (src, 1)) == CONST_INT) 1460 { 1461 cfa_temp.reg = REGNO (dest); 1462 cfa_temp.offset = INTVAL (XEXP (src, 1)); 1463 } 1464 else 1465 abort (); 1466 } 1467 break; 1468 1469 /* Rule 6 */ 1470 case CONST_INT: 1471 cfa_temp.reg = REGNO (dest); 1472 cfa_temp.offset = INTVAL (src); 1473 break; 1474 1475 /* Rule 7 */ 1476 case IOR: 1477 if (GET_CODE (XEXP (src, 0)) != REG 1478 || (unsigned) REGNO (XEXP (src, 0)) != cfa_temp.reg 1479 || GET_CODE (XEXP (src, 1)) != CONST_INT) 1480 abort (); 1481 1482 if ((unsigned) REGNO (dest) != cfa_temp.reg) 1483 cfa_temp.reg = REGNO (dest); 1484 cfa_temp.offset |= INTVAL (XEXP (src, 1)); 1485 break; 1486 1487 /* Skip over HIGH, assuming it will be followed by a LO_SUM, 1488 which will fill in all of the bits. */ 1489 /* Rule 8 */ 1490 case HIGH: 1491 break; 1492 1493 default: 1494 abort (); 1495 } 1496 1497 def_cfa_1 (label, &cfa); 1498 break; 1499 1500 case MEM: 1501 if (GET_CODE (src) != REG) 1502 abort (); 1503 1504 /* Saving a register to the stack. Make sure dest is relative to the 1505 CFA register. */ 1506 switch (GET_CODE (XEXP (dest, 0))) 1507 { 1508 /* Rule 10 */ 1509 /* With a push. */ 1510 case PRE_MODIFY: 1511 /* We can't handle variable size modifications. */ 1512 if (GET_CODE (XEXP (XEXP (XEXP (dest, 0), 1), 1)) != CONST_INT) 1513 abort (); 1514 offset = -INTVAL (XEXP (XEXP (XEXP (dest, 0), 1), 1)); 1515 1516 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM 1517 || cfa_store.reg != STACK_POINTER_REGNUM) 1518 abort (); 1519 1520 cfa_store.offset += offset; 1521 if (cfa.reg == STACK_POINTER_REGNUM) 1522 cfa.offset = cfa_store.offset; 1523 1524 offset = -cfa_store.offset; 1525 break; 1526 1527 /* Rule 11 */ 1528 case PRE_INC: 1529 case PRE_DEC: 1530 offset = GET_MODE_SIZE (GET_MODE (dest)); 1531 if (GET_CODE (XEXP (dest, 0)) == PRE_INC) 1532 offset = -offset; 1533 1534 if (REGNO (XEXP (XEXP (dest, 0), 0)) != STACK_POINTER_REGNUM 1535 || cfa_store.reg != STACK_POINTER_REGNUM) 1536 abort (); 1537 1538 cfa_store.offset += offset; 1539 if (cfa.reg == STACK_POINTER_REGNUM) 1540 cfa.offset = cfa_store.offset; 1541 1542 offset = -cfa_store.offset; 1543 break; 1544 1545 /* Rule 12 */ 1546 /* With an offset. */ 1547 case PLUS: 1548 case MINUS: 1549 case LO_SUM: 1550 if (GET_CODE (XEXP (XEXP (dest, 0), 1)) != CONST_INT) 1551 abort (); 1552 offset = INTVAL (XEXP (XEXP (dest, 0), 1)); 1553 if (GET_CODE (XEXP (dest, 0)) == MINUS) 1554 offset = -offset; 1555 1556 if (cfa_store.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) 1557 offset -= cfa_store.offset; 1558 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) 1559 offset -= cfa_temp.offset; 1560 else 1561 abort (); 1562 break; 1563 1564 /* Rule 13 */ 1565 /* Without an offset. */ 1566 case REG: 1567 if (cfa_store.reg == (unsigned) REGNO (XEXP (dest, 0))) 1568 offset = -cfa_store.offset; 1569 else if (cfa_temp.reg == (unsigned) REGNO (XEXP (dest, 0))) 1570 offset = -cfa_temp.offset; 1571 else 1572 abort (); 1573 break; 1574 1575 /* Rule 14 */ 1576 case POST_INC: 1577 if (cfa_temp.reg != (unsigned) REGNO (XEXP (XEXP (dest, 0), 0))) 1578 abort (); 1579 offset = -cfa_temp.offset; 1580 cfa_temp.offset -= GET_MODE_SIZE (GET_MODE (dest)); 1581 break; 1582 1583 default: 1584 abort (); 1585 } 1586 1587 if (REGNO (src) != STACK_POINTER_REGNUM 1588 && REGNO (src) != HARD_FRAME_POINTER_REGNUM 1589 && (unsigned) REGNO (src) == cfa.reg) 1590 { 1591 /* We're storing the current CFA reg into the stack. */ 1592 1593 if (cfa.offset == 0) 1594 { 1595 /* If the source register is exactly the CFA, assume 1596 we're saving SP like any other register; this happens 1597 on the ARM. */ 1598 def_cfa_1 (label, &cfa); 1599 queue_reg_save (label, stack_pointer_rtx, offset); 1600 break; 1601 } 1602 else 1603 { 1604 /* Otherwise, we'll need to look in the stack to 1605 calculate the CFA. */ 1606 rtx x = XEXP (dest, 0); 1607 1608 if (GET_CODE (x) != REG) 1609 x = XEXP (x, 0); 1610 if (GET_CODE (x) != REG) 1611 abort (); 1612 1613 cfa.reg = REGNO (x); 1614 cfa.base_offset = offset; 1615 cfa.indirect = 1; 1616 def_cfa_1 (label, &cfa); 1617 break; 1618 } 1619 } 1620 1621 def_cfa_1 (label, &cfa); 1622 queue_reg_save (label, src, offset); 1623 break; 1624 1625 default: 1626 abort (); 1627 } 1628} 1629 1630/* Record call frame debugging information for INSN, which either 1631 sets SP or FP (adjusting how we calculate the frame address) or saves a 1632 register to the stack. If INSN is NULL_RTX, initialize our state. */ 1633 1634void 1635dwarf2out_frame_debug (insn) 1636 rtx insn; 1637{ 1638 const char *label; 1639 rtx src; 1640 1641 if (insn == NULL_RTX) 1642 { 1643 /* Flush any queued register saves. */ 1644 flush_queued_reg_saves (); 1645 1646 /* Set up state for generating call frame debug info. */ 1647 lookup_cfa (&cfa); 1648 if (cfa.reg != (unsigned long) DWARF_FRAME_REGNUM (STACK_POINTER_REGNUM)) 1649 abort (); 1650 1651 cfa.reg = STACK_POINTER_REGNUM; 1652 cfa_store = cfa; 1653 cfa_temp.reg = -1; 1654 cfa_temp.offset = 0; 1655 return; 1656 } 1657 1658 if (GET_CODE (insn) != INSN || clobbers_queued_reg_save (insn)) 1659 flush_queued_reg_saves (); 1660 1661 if (! RTX_FRAME_RELATED_P (insn)) 1662 { 1663 if (!ACCUMULATE_OUTGOING_ARGS) 1664 dwarf2out_stack_adjust (insn); 1665 1666 return; 1667 } 1668 1669 label = dwarf2out_cfi_label (); 1670 src = find_reg_note (insn, REG_FRAME_RELATED_EXPR, NULL_RTX); 1671 if (src) 1672 insn = XEXP (src, 0); 1673 else 1674 insn = PATTERN (insn); 1675 1676 dwarf2out_frame_debug_expr (insn, label); 1677} 1678 1679/* Output a Call Frame Information opcode and its operand(s). */ 1680 1681static void 1682output_cfi (cfi, fde, for_eh) 1683 dw_cfi_ref cfi; 1684 dw_fde_ref fde; 1685 int for_eh; 1686{ 1687 if (cfi->dw_cfi_opc == DW_CFA_advance_loc) 1688 dw2_asm_output_data (1, (cfi->dw_cfi_opc 1689 | (cfi->dw_cfi_oprnd1.dw_cfi_offset & 0x3f)), 1690 "DW_CFA_advance_loc 0x%lx", 1691 cfi->dw_cfi_oprnd1.dw_cfi_offset); 1692 else if (cfi->dw_cfi_opc == DW_CFA_offset) 1693 { 1694 dw2_asm_output_data (1, (cfi->dw_cfi_opc 1695 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), 1696 "DW_CFA_offset, column 0x%lx", 1697 cfi->dw_cfi_oprnd1.dw_cfi_reg_num); 1698 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); 1699 } 1700 else if (cfi->dw_cfi_opc == DW_CFA_restore) 1701 dw2_asm_output_data (1, (cfi->dw_cfi_opc 1702 | (cfi->dw_cfi_oprnd1.dw_cfi_reg_num & 0x3f)), 1703 "DW_CFA_restore, column 0x%lx", 1704 cfi->dw_cfi_oprnd1.dw_cfi_reg_num); 1705 else 1706 { 1707 dw2_asm_output_data (1, cfi->dw_cfi_opc, 1708 "%s", dwarf_cfi_name (cfi->dw_cfi_opc)); 1709 1710 switch (cfi->dw_cfi_opc) 1711 { 1712 case DW_CFA_set_loc: 1713 if (for_eh) 1714 dw2_asm_output_encoded_addr_rtx ( 1715 ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0), 1716 gen_rtx_SYMBOL_REF (Pmode, cfi->dw_cfi_oprnd1.dw_cfi_addr), 1717 NULL); 1718 else 1719 dw2_asm_output_addr (DWARF2_ADDR_SIZE, 1720 cfi->dw_cfi_oprnd1.dw_cfi_addr, NULL); 1721 break; 1722 1723 case DW_CFA_advance_loc1: 1724 dw2_asm_output_delta (1, cfi->dw_cfi_oprnd1.dw_cfi_addr, 1725 fde->dw_fde_current_label, NULL); 1726 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; 1727 break; 1728 1729 case DW_CFA_advance_loc2: 1730 dw2_asm_output_delta (2, cfi->dw_cfi_oprnd1.dw_cfi_addr, 1731 fde->dw_fde_current_label, NULL); 1732 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; 1733 break; 1734 1735 case DW_CFA_advance_loc4: 1736 dw2_asm_output_delta (4, cfi->dw_cfi_oprnd1.dw_cfi_addr, 1737 fde->dw_fde_current_label, NULL); 1738 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; 1739 break; 1740 1741 case DW_CFA_MIPS_advance_loc8: 1742 dw2_asm_output_delta (8, cfi->dw_cfi_oprnd1.dw_cfi_addr, 1743 fde->dw_fde_current_label, NULL); 1744 fde->dw_fde_current_label = cfi->dw_cfi_oprnd1.dw_cfi_addr; 1745 break; 1746 1747 case DW_CFA_offset_extended: 1748 case DW_CFA_def_cfa: 1749 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1750 NULL); 1751 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); 1752 break; 1753 1754 case DW_CFA_offset_extended_sf: 1755 case DW_CFA_def_cfa_sf: 1756 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1757 NULL); 1758 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd2.dw_cfi_offset, NULL); 1759 break; 1760 1761 case DW_CFA_restore_extended: 1762 case DW_CFA_undefined: 1763 case DW_CFA_same_value: 1764 case DW_CFA_def_cfa_register: 1765 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1766 NULL); 1767 break; 1768 1769 case DW_CFA_register: 1770 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_reg_num, 1771 NULL); 1772 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd2.dw_cfi_reg_num, 1773 NULL); 1774 break; 1775 1776 case DW_CFA_def_cfa_offset: 1777 case DW_CFA_GNU_args_size: 1778 dw2_asm_output_data_uleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); 1779 break; 1780 1781 case DW_CFA_def_cfa_offset_sf: 1782 dw2_asm_output_data_sleb128 (cfi->dw_cfi_oprnd1.dw_cfi_offset, NULL); 1783 break; 1784 1785 case DW_CFA_GNU_window_save: 1786 break; 1787 1788 case DW_CFA_def_cfa_expression: 1789 case DW_CFA_expression: 1790 output_cfa_loc (cfi); 1791 break; 1792 1793 case DW_CFA_GNU_negative_offset_extended: 1794 /* Obsoleted by DW_CFA_offset_extended_sf. */ 1795 abort (); 1796 1797 default: 1798 break; 1799 } 1800 } 1801} 1802 1803/* Output the call frame information used to used to record information 1804 that relates to calculating the frame pointer, and records the 1805 location of saved registers. */ 1806 1807static void 1808output_call_frame_info (for_eh) 1809 int for_eh; 1810{ 1811 unsigned int i; 1812 dw_fde_ref fde; 1813 dw_cfi_ref cfi; 1814 char l1[20], l2[20], section_start_label[20]; 1815 bool any_lsda_needed = false; 1816 char augmentation[6]; 1817 int augmentation_size; 1818 int fde_encoding = DW_EH_PE_absptr; 1819 int per_encoding = DW_EH_PE_absptr; 1820 int lsda_encoding = DW_EH_PE_absptr; 1821 1822 /* Don't emit a CIE if there won't be any FDEs. */ 1823 if (fde_table_in_use == 0) 1824 return; 1825 1826 /* If we don't have any functions we'll want to unwind out of, don't 1827 emit any EH unwind information. Note that if exceptions aren't 1828 enabled, we won't have collected nothrow information, and if we 1829 asked for asynchronous tables, we always want this info. */ 1830 if (for_eh) 1831 { 1832 bool any_eh_needed = !flag_exceptions || flag_asynchronous_unwind_tables; 1833 1834 for (i = 0; i < fde_table_in_use; i++) 1835 if (fde_table[i].uses_eh_lsda) 1836 any_eh_needed = any_lsda_needed = true; 1837 else if (! fde_table[i].nothrow) 1838 any_eh_needed = true; 1839 1840 if (! any_eh_needed) 1841 return; 1842 } 1843 1844 /* We're going to be generating comments, so turn on app. */ 1845 if (flag_debug_asm) 1846 app_enable (); 1847 1848 if (for_eh) 1849 (*targetm.asm_out.eh_frame_section) (); 1850 else 1851 named_section_flags (DEBUG_FRAME_SECTION, SECTION_DEBUG); 1852 1853 ASM_GENERATE_INTERNAL_LABEL (section_start_label, FRAME_BEGIN_LABEL, for_eh); 1854 ASM_OUTPUT_LABEL (asm_out_file, section_start_label); 1855 1856 /* Output the CIE. */ 1857 ASM_GENERATE_INTERNAL_LABEL (l1, CIE_AFTER_SIZE_LABEL, for_eh); 1858 ASM_GENERATE_INTERNAL_LABEL (l2, CIE_END_LABEL, for_eh); 1859 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, 1860 "Length of Common Information Entry"); 1861 ASM_OUTPUT_LABEL (asm_out_file, l1); 1862 1863 /* Now that the CIE pointer is PC-relative for EH, 1864 use 0 to identify the CIE. */ 1865 dw2_asm_output_data ((for_eh ? 4 : DWARF_OFFSET_SIZE), 1866 (for_eh ? 0 : DW_CIE_ID), 1867 "CIE Identifier Tag"); 1868 1869 dw2_asm_output_data (1, DW_CIE_VERSION, "CIE Version"); 1870 1871 augmentation[0] = 0; 1872 augmentation_size = 0; 1873 if (for_eh) 1874 { 1875 char *p; 1876 1877 /* Augmentation: 1878 z Indicates that a uleb128 is present to size the 1879 augmentation section. 1880 L Indicates the encoding (and thus presence) of 1881 an LSDA pointer in the FDE augmentation. 1882 R Indicates a non-default pointer encoding for 1883 FDE code pointers. 1884 P Indicates the presence of an encoding + language 1885 personality routine in the CIE augmentation. */ 1886 1887 fde_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/1, /*global=*/0); 1888 per_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/2, /*global=*/1); 1889 lsda_encoding = ASM_PREFERRED_EH_DATA_FORMAT (/*code=*/0, /*global=*/0); 1890 1891 p = augmentation + 1; 1892 if (eh_personality_libfunc) 1893 { 1894 *p++ = 'P'; 1895 augmentation_size += 1 + size_of_encoded_value (per_encoding); 1896 } 1897 if (any_lsda_needed) 1898 { 1899 *p++ = 'L'; 1900 augmentation_size += 1; 1901 } 1902 if (fde_encoding != DW_EH_PE_absptr) 1903 { 1904 *p++ = 'R'; 1905 augmentation_size += 1; 1906 } 1907 if (p > augmentation + 1) 1908 { 1909 augmentation[0] = 'z'; 1910 *p = '\0'; 1911 } 1912 1913 /* Ug. Some platforms can't do unaligned dynamic relocations at all. */ 1914 if (eh_personality_libfunc && per_encoding == DW_EH_PE_aligned) 1915 { 1916 int offset = ( 4 /* Length */ 1917 + 4 /* CIE Id */ 1918 + 1 /* CIE version */ 1919 + strlen (augmentation) + 1 /* Augmentation */ 1920 + size_of_uleb128 (1) /* Code alignment */ 1921 + size_of_sleb128 (DWARF_CIE_DATA_ALIGNMENT) 1922 + 1 /* RA column */ 1923 + 1 /* Augmentation size */ 1924 + 1 /* Personality encoding */ ); 1925 int pad = -offset & (PTR_SIZE - 1); 1926 1927 augmentation_size += pad; 1928 1929 /* Augmentations should be small, so there's scarce need to 1930 iterate for a solution. Die if we exceed one uleb128 byte. */ 1931 if (size_of_uleb128 (augmentation_size) != 1) 1932 abort (); 1933 } 1934 } 1935 1936 dw2_asm_output_nstring (augmentation, -1, "CIE Augmentation"); 1937 dw2_asm_output_data_uleb128 (1, "CIE Code Alignment Factor"); 1938 dw2_asm_output_data_sleb128 (DWARF_CIE_DATA_ALIGNMENT, 1939 "CIE Data Alignment Factor"); 1940 dw2_asm_output_data (1, DWARF_FRAME_RETURN_COLUMN, "CIE RA Column"); 1941 1942 if (augmentation[0]) 1943 { 1944 dw2_asm_output_data_uleb128 (augmentation_size, "Augmentation size"); 1945 if (eh_personality_libfunc) 1946 { 1947 dw2_asm_output_data (1, per_encoding, "Personality (%s)", 1948 eh_data_format_name (per_encoding)); 1949 dw2_asm_output_encoded_addr_rtx (per_encoding, 1950 eh_personality_libfunc, NULL); 1951 } 1952 1953 if (any_lsda_needed) 1954 dw2_asm_output_data (1, lsda_encoding, "LSDA Encoding (%s)", 1955 eh_data_format_name (lsda_encoding)); 1956 1957 if (fde_encoding != DW_EH_PE_absptr) 1958 dw2_asm_output_data (1, fde_encoding, "FDE Encoding (%s)", 1959 eh_data_format_name (fde_encoding)); 1960 } 1961 1962 for (cfi = cie_cfi_head; cfi != NULL; cfi = cfi->dw_cfi_next) 1963 output_cfi (cfi, NULL, for_eh); 1964 1965 /* Pad the CIE out to an address sized boundary. */ 1966 ASM_OUTPUT_ALIGN (asm_out_file, 1967 floor_log2 (for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE)); 1968 ASM_OUTPUT_LABEL (asm_out_file, l2); 1969 1970 /* Loop through all of the FDE's. */ 1971 for (i = 0; i < fde_table_in_use; i++) 1972 { 1973 fde = &fde_table[i]; 1974 1975 /* Don't emit EH unwind info for leaf functions that don't need it. */ 1976 if (for_eh && !flag_asynchronous_unwind_tables && flag_exceptions 1977 && (fde->nothrow || fde->all_throwers_are_sibcalls) 1978 && !fde->uses_eh_lsda) 1979 continue; 1980 1981 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, FDE_LABEL, for_eh + i * 2); 1982 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_AFTER_SIZE_LABEL, for_eh + i * 2); 1983 ASM_GENERATE_INTERNAL_LABEL (l2, FDE_END_LABEL, for_eh + i * 2); 1984 dw2_asm_output_delta (for_eh ? 4 : DWARF_OFFSET_SIZE, l2, l1, 1985 "FDE Length"); 1986 ASM_OUTPUT_LABEL (asm_out_file, l1); 1987 1988 if (for_eh) 1989 dw2_asm_output_delta (4, l1, section_start_label, "FDE CIE offset"); 1990 else 1991 dw2_asm_output_offset (DWARF_OFFSET_SIZE, section_start_label, 1992 "FDE CIE offset"); 1993 1994 if (for_eh) 1995 { 1996 dw2_asm_output_encoded_addr_rtx (fde_encoding, 1997 gen_rtx_SYMBOL_REF (Pmode, fde->dw_fde_begin), 1998 "FDE initial location"); 1999 dw2_asm_output_delta (size_of_encoded_value (fde_encoding), 2000 fde->dw_fde_end, fde->dw_fde_begin, 2001 "FDE address range"); 2002 } 2003 else 2004 { 2005 dw2_asm_output_addr (DWARF2_ADDR_SIZE, fde->dw_fde_begin, 2006 "FDE initial location"); 2007 dw2_asm_output_delta (DWARF2_ADDR_SIZE, 2008 fde->dw_fde_end, fde->dw_fde_begin, 2009 "FDE address range"); 2010 } 2011 2012 if (augmentation[0]) 2013 { 2014 if (any_lsda_needed) 2015 { 2016 int size = size_of_encoded_value (lsda_encoding); 2017 2018 if (lsda_encoding == DW_EH_PE_aligned) 2019 { 2020 int offset = ( 4 /* Length */ 2021 + 4 /* CIE offset */ 2022 + 2 * size_of_encoded_value (fde_encoding) 2023 + 1 /* Augmentation size */ ); 2024 int pad = -offset & (PTR_SIZE - 1); 2025 2026 size += pad; 2027 if (size_of_uleb128 (size) != 1) 2028 abort (); 2029 } 2030 2031 dw2_asm_output_data_uleb128 (size, "Augmentation size"); 2032 2033 if (fde->uses_eh_lsda) 2034 { 2035 ASM_GENERATE_INTERNAL_LABEL (l1, "LLSDA", 2036 fde->funcdef_number); 2037 dw2_asm_output_encoded_addr_rtx ( 2038 lsda_encoding, gen_rtx_SYMBOL_REF (Pmode, l1), 2039 "Language Specific Data Area"); 2040 } 2041 else 2042 { 2043 if (lsda_encoding == DW_EH_PE_aligned) 2044 ASM_OUTPUT_ALIGN (asm_out_file, floor_log2 (PTR_SIZE)); 2045 dw2_asm_output_data 2046 (size_of_encoded_value (lsda_encoding), 0, 2047 "Language Specific Data Area (none)"); 2048 } 2049 } 2050 else 2051 dw2_asm_output_data_uleb128 (0, "Augmentation size"); 2052 } 2053 2054 /* Loop through the Call Frame Instructions associated with 2055 this FDE. */ 2056 fde->dw_fde_current_label = fde->dw_fde_begin; 2057 for (cfi = fde->dw_fde_cfi; cfi != NULL; cfi = cfi->dw_cfi_next) 2058 output_cfi (cfi, fde, for_eh); 2059 2060 /* Pad the FDE out to an address sized boundary. */ 2061 ASM_OUTPUT_ALIGN (asm_out_file, 2062 floor_log2 ((for_eh ? PTR_SIZE : DWARF2_ADDR_SIZE))); 2063 ASM_OUTPUT_LABEL (asm_out_file, l2); 2064 } 2065 2066 if (for_eh && targetm.terminate_dw2_eh_frame_info) 2067 dw2_asm_output_data (4, 0, "End of Table"); 2068#ifdef MIPS_DEBUGGING_INFO 2069 /* Work around Irix 6 assembler bug whereby labels at the end of a section 2070 get a value of 0. Putting .align 0 after the label fixes it. */ 2071 ASM_OUTPUT_ALIGN (asm_out_file, 0); 2072#endif 2073 2074 /* Turn off app to make assembly quicker. */ 2075 if (flag_debug_asm) 2076 app_disable (); 2077} 2078 2079/* Output a marker (i.e. a label) for the beginning of a function, before 2080 the prologue. */ 2081 2082void 2083dwarf2out_begin_prologue (line, file) 2084 unsigned int line ATTRIBUTE_UNUSED; 2085 const char *file ATTRIBUTE_UNUSED; 2086{ 2087 char label[MAX_ARTIFICIAL_LABEL_BYTES]; 2088 dw_fde_ref fde; 2089 2090 current_function_func_begin_label = 0; 2091 2092#ifdef IA64_UNWIND_INFO 2093 /* ??? current_function_func_begin_label is also used by except.c 2094 for call-site information. We must emit this label if it might 2095 be used. */ 2096 if ((! flag_exceptions || USING_SJLJ_EXCEPTIONS) 2097 && ! dwarf2out_do_frame ()) 2098 return; 2099#else 2100 if (! dwarf2out_do_frame ()) 2101 return; 2102#endif 2103 2104 function_section (current_function_decl); 2105 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_BEGIN_LABEL, 2106 current_function_funcdef_no); 2107 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, FUNC_BEGIN_LABEL, 2108 current_function_funcdef_no); 2109 current_function_func_begin_label = get_identifier (label); 2110 2111#ifdef IA64_UNWIND_INFO 2112 /* We can elide the fde allocation if we're not emitting debug info. */ 2113 if (! dwarf2out_do_frame ()) 2114 return; 2115#endif 2116 2117 /* Expand the fde table if necessary. */ 2118 if (fde_table_in_use == fde_table_allocated) 2119 { 2120 fde_table_allocated += FDE_TABLE_INCREMENT; 2121 fde_table 2122 = (dw_fde_ref) xrealloc (fde_table, 2123 fde_table_allocated * sizeof (dw_fde_node)); 2124 } 2125 2126 /* Record the FDE associated with this function. */ 2127 current_funcdef_fde = fde_table_in_use; 2128 2129 /* Add the new FDE at the end of the fde_table. */ 2130 fde = &fde_table[fde_table_in_use++]; 2131 fde->dw_fde_begin = xstrdup (label); 2132 fde->dw_fde_current_label = NULL; 2133 fde->dw_fde_end = NULL; 2134 fde->dw_fde_cfi = NULL; 2135 fde->funcdef_number = current_function_funcdef_no; 2136 fde->nothrow = current_function_nothrow; 2137 fde->uses_eh_lsda = cfun->uses_eh_lsda; 2138 fde->all_throwers_are_sibcalls = cfun->all_throwers_are_sibcalls; 2139 2140 args_size = old_args_size = 0; 2141 2142 /* We only want to output line number information for the genuine dwarf2 2143 prologue case, not the eh frame case. */ 2144#ifdef DWARF2_DEBUGGING_INFO 2145 if (file) 2146 dwarf2out_source_line (line, file); 2147#endif 2148} 2149 2150/* Output a marker (i.e. a label) for the absolute end of the generated code 2151 for a function definition. This gets called *after* the epilogue code has 2152 been generated. */ 2153 2154void 2155dwarf2out_end_epilogue (line, file) 2156 unsigned int line ATTRIBUTE_UNUSED; 2157 const char *file ATTRIBUTE_UNUSED; 2158{ 2159 dw_fde_ref fde; 2160 char label[MAX_ARTIFICIAL_LABEL_BYTES]; 2161 2162 /* Output a label to mark the endpoint of the code generated for this 2163 function. */ 2164 ASM_GENERATE_INTERNAL_LABEL (label, FUNC_END_LABEL, 2165 current_function_funcdef_no); 2166 ASM_OUTPUT_LABEL (asm_out_file, label); 2167 fde = &fde_table[fde_table_in_use - 1]; 2168 fde->dw_fde_end = xstrdup (label); 2169} 2170 2171void 2172dwarf2out_frame_init () 2173{ 2174 /* Allocate the initial hunk of the fde_table. */ 2175 fde_table = (dw_fde_ref) xcalloc (FDE_TABLE_INCREMENT, sizeof (dw_fde_node)); 2176 fde_table_allocated = FDE_TABLE_INCREMENT; 2177 fde_table_in_use = 0; 2178 2179 /* Generate the CFA instructions common to all FDE's. Do it now for the 2180 sake of lookup_cfa. */ 2181 2182#ifdef DWARF2_UNWIND_INFO 2183 /* On entry, the Canonical Frame Address is at SP. */ 2184 dwarf2out_def_cfa (NULL, STACK_POINTER_REGNUM, INCOMING_FRAME_SP_OFFSET); 2185 initial_return_save (INCOMING_RETURN_ADDR_RTX); 2186#endif 2187} 2188 2189void 2190dwarf2out_frame_finish () 2191{ 2192 /* Output call frame information. */ 2193 if (write_symbols == DWARF2_DEBUG || write_symbols == VMS_AND_DWARF2_DEBUG) 2194 output_call_frame_info (0); 2195 2196 if (! USING_SJLJ_EXCEPTIONS && (flag_unwind_tables || flag_exceptions)) 2197 output_call_frame_info (1); 2198} 2199 2200/* And now, the subset of the debugging information support code necessary 2201 for emitting location expressions. */ 2202 2203/* We need some way to distinguish DW_OP_addr with a direct symbol 2204 relocation from DW_OP_addr with a dtp-relative symbol relocation. */ 2205#define INTERNAL_DW_OP_tls_addr (0x100 + DW_OP_addr) 2206 2207 2208typedef struct dw_val_struct *dw_val_ref; 2209typedef struct die_struct *dw_die_ref; 2210typedef struct dw_loc_descr_struct *dw_loc_descr_ref; 2211typedef struct dw_loc_list_struct *dw_loc_list_ref; 2212 2213/* Each DIE may have a series of attribute/value pairs. Values 2214 can take on several forms. The forms that are used in this 2215 implementation are listed below. */ 2216 2217typedef enum 2218{ 2219 dw_val_class_addr, 2220 dw_val_class_offset, 2221 dw_val_class_loc, 2222 dw_val_class_loc_list, 2223 dw_val_class_range_list, 2224 dw_val_class_const, 2225 dw_val_class_unsigned_const, 2226 dw_val_class_long_long, 2227 dw_val_class_float, 2228 dw_val_class_flag, 2229 dw_val_class_die_ref, 2230 dw_val_class_fde_ref, 2231 dw_val_class_lbl_id, 2232 dw_val_class_lbl_offset, 2233 dw_val_class_str 2234} 2235dw_val_class; 2236 2237/* Describe a double word constant value. */ 2238/* ??? Every instance of long_long in the code really means CONST_DOUBLE. */ 2239 2240typedef struct dw_long_long_struct 2241{ 2242 unsigned long hi; 2243 unsigned long low; 2244} 2245dw_long_long_const; 2246 2247/* Describe a floating point constant value. */ 2248 2249typedef struct dw_fp_struct 2250{ 2251 long *array; 2252 unsigned length; 2253} 2254dw_float_const; 2255 2256/* The dw_val_node describes an attribute's value, as it is 2257 represented internally. */ 2258 2259typedef struct dw_val_struct 2260{ 2261 dw_val_class val_class; 2262 union 2263 { 2264 rtx val_addr; 2265 long unsigned val_offset; 2266 dw_loc_list_ref val_loc_list; 2267 dw_loc_descr_ref val_loc; 2268 long int val_int; 2269 long unsigned val_unsigned; 2270 dw_long_long_const val_long_long; 2271 dw_float_const val_float; 2272 struct 2273 { 2274 dw_die_ref die; 2275 int external; 2276 } val_die_ref; 2277 unsigned val_fde_index; 2278 struct indirect_string_node *val_str; 2279 char *val_lbl_id; 2280 unsigned char val_flag; 2281 } 2282 v; 2283} 2284dw_val_node; 2285 2286/* Locations in memory are described using a sequence of stack machine 2287 operations. */ 2288 2289typedef struct dw_loc_descr_struct 2290{ 2291 dw_loc_descr_ref dw_loc_next; 2292 enum dwarf_location_atom dw_loc_opc; 2293 dw_val_node dw_loc_oprnd1; 2294 dw_val_node dw_loc_oprnd2; 2295 int dw_loc_addr; 2296} 2297dw_loc_descr_node; 2298 2299/* Location lists are ranges + location descriptions for that range, 2300 so you can track variables that are in different places over 2301 their entire life. */ 2302typedef struct dw_loc_list_struct 2303{ 2304 dw_loc_list_ref dw_loc_next; 2305 const char *begin; /* Label for begin address of range */ 2306 const char *end; /* Label for end address of range */ 2307 char *ll_symbol; /* Label for beginning of location list. 2308 Only on head of list */ 2309 const char *section; /* Section this loclist is relative to */ 2310 dw_loc_descr_ref expr; 2311} dw_loc_list_node; 2312 2313static const char *dwarf_stack_op_name PARAMS ((unsigned)); 2314static dw_loc_descr_ref new_loc_descr PARAMS ((enum dwarf_location_atom, 2315 unsigned long, 2316 unsigned long)); 2317static void add_loc_descr PARAMS ((dw_loc_descr_ref *, 2318 dw_loc_descr_ref)); 2319static unsigned long size_of_loc_descr PARAMS ((dw_loc_descr_ref)); 2320static unsigned long size_of_locs PARAMS ((dw_loc_descr_ref)); 2321static void output_loc_operands PARAMS ((dw_loc_descr_ref)); 2322static void output_loc_sequence PARAMS ((dw_loc_descr_ref)); 2323 2324/* Convert a DWARF stack opcode into its string name. */ 2325 2326static const char * 2327dwarf_stack_op_name (op) 2328 unsigned op; 2329{ 2330 switch (op) 2331 { 2332 case DW_OP_addr: 2333 case INTERNAL_DW_OP_tls_addr: 2334 return "DW_OP_addr"; 2335 case DW_OP_deref: 2336 return "DW_OP_deref"; 2337 case DW_OP_const1u: 2338 return "DW_OP_const1u"; 2339 case DW_OP_const1s: 2340 return "DW_OP_const1s"; 2341 case DW_OP_const2u: 2342 return "DW_OP_const2u"; 2343 case DW_OP_const2s: 2344 return "DW_OP_const2s"; 2345 case DW_OP_const4u: 2346 return "DW_OP_const4u"; 2347 case DW_OP_const4s: 2348 return "DW_OP_const4s"; 2349 case DW_OP_const8u: 2350 return "DW_OP_const8u"; 2351 case DW_OP_const8s: 2352 return "DW_OP_const8s"; 2353 case DW_OP_constu: 2354 return "DW_OP_constu"; 2355 case DW_OP_consts: 2356 return "DW_OP_consts"; 2357 case DW_OP_dup: 2358 return "DW_OP_dup"; 2359 case DW_OP_drop: 2360 return "DW_OP_drop"; 2361 case DW_OP_over: 2362 return "DW_OP_over"; 2363 case DW_OP_pick: 2364 return "DW_OP_pick"; 2365 case DW_OP_swap: 2366 return "DW_OP_swap"; 2367 case DW_OP_rot: 2368 return "DW_OP_rot"; 2369 case DW_OP_xderef: 2370 return "DW_OP_xderef"; 2371 case DW_OP_abs: 2372 return "DW_OP_abs"; 2373 case DW_OP_and: 2374 return "DW_OP_and"; 2375 case DW_OP_div: 2376 return "DW_OP_div"; 2377 case DW_OP_minus: 2378 return "DW_OP_minus"; 2379 case DW_OP_mod: 2380 return "DW_OP_mod"; 2381 case DW_OP_mul: 2382 return "DW_OP_mul"; 2383 case DW_OP_neg: 2384 return "DW_OP_neg"; 2385 case DW_OP_not: 2386 return "DW_OP_not"; 2387 case DW_OP_or: 2388 return "DW_OP_or"; 2389 case DW_OP_plus: 2390 return "DW_OP_plus"; 2391 case DW_OP_plus_uconst: 2392 return "DW_OP_plus_uconst"; 2393 case DW_OP_shl: 2394 return "DW_OP_shl"; 2395 case DW_OP_shr: 2396 return "DW_OP_shr"; 2397 case DW_OP_shra: 2398 return "DW_OP_shra"; 2399 case DW_OP_xor: 2400 return "DW_OP_xor"; 2401 case DW_OP_bra: 2402 return "DW_OP_bra"; 2403 case DW_OP_eq: 2404 return "DW_OP_eq"; 2405 case DW_OP_ge: 2406 return "DW_OP_ge"; 2407 case DW_OP_gt: 2408 return "DW_OP_gt"; 2409 case DW_OP_le: 2410 return "DW_OP_le"; 2411 case DW_OP_lt: 2412 return "DW_OP_lt"; 2413 case DW_OP_ne: 2414 return "DW_OP_ne"; 2415 case DW_OP_skip: 2416 return "DW_OP_skip"; 2417 case DW_OP_lit0: 2418 return "DW_OP_lit0"; 2419 case DW_OP_lit1: 2420 return "DW_OP_lit1"; 2421 case DW_OP_lit2: 2422 return "DW_OP_lit2"; 2423 case DW_OP_lit3: 2424 return "DW_OP_lit3"; 2425 case DW_OP_lit4: 2426 return "DW_OP_lit4"; 2427 case DW_OP_lit5: 2428 return "DW_OP_lit5"; 2429 case DW_OP_lit6: 2430 return "DW_OP_lit6"; 2431 case DW_OP_lit7: 2432 return "DW_OP_lit7"; 2433 case DW_OP_lit8: 2434 return "DW_OP_lit8"; 2435 case DW_OP_lit9: 2436 return "DW_OP_lit9"; 2437 case DW_OP_lit10: 2438 return "DW_OP_lit10"; 2439 case DW_OP_lit11: 2440 return "DW_OP_lit11"; 2441 case DW_OP_lit12: 2442 return "DW_OP_lit12"; 2443 case DW_OP_lit13: 2444 return "DW_OP_lit13"; 2445 case DW_OP_lit14: 2446 return "DW_OP_lit14"; 2447 case DW_OP_lit15: 2448 return "DW_OP_lit15"; 2449 case DW_OP_lit16: 2450 return "DW_OP_lit16"; 2451 case DW_OP_lit17: 2452 return "DW_OP_lit17"; 2453 case DW_OP_lit18: 2454 return "DW_OP_lit18"; 2455 case DW_OP_lit19: 2456 return "DW_OP_lit19"; 2457 case DW_OP_lit20: 2458 return "DW_OP_lit20"; 2459 case DW_OP_lit21: 2460 return "DW_OP_lit21"; 2461 case DW_OP_lit22: 2462 return "DW_OP_lit22"; 2463 case DW_OP_lit23: 2464 return "DW_OP_lit23"; 2465 case DW_OP_lit24: 2466 return "DW_OP_lit24"; 2467 case DW_OP_lit25: 2468 return "DW_OP_lit25"; 2469 case DW_OP_lit26: 2470 return "DW_OP_lit26"; 2471 case DW_OP_lit27: 2472 return "DW_OP_lit27"; 2473 case DW_OP_lit28: 2474 return "DW_OP_lit28"; 2475 case DW_OP_lit29: 2476 return "DW_OP_lit29"; 2477 case DW_OP_lit30: 2478 return "DW_OP_lit30"; 2479 case DW_OP_lit31: 2480 return "DW_OP_lit31"; 2481 case DW_OP_reg0: 2482 return "DW_OP_reg0"; 2483 case DW_OP_reg1: 2484 return "DW_OP_reg1"; 2485 case DW_OP_reg2: 2486 return "DW_OP_reg2"; 2487 case DW_OP_reg3: 2488 return "DW_OP_reg3"; 2489 case DW_OP_reg4: 2490 return "DW_OP_reg4"; 2491 case DW_OP_reg5: 2492 return "DW_OP_reg5"; 2493 case DW_OP_reg6: 2494 return "DW_OP_reg6"; 2495 case DW_OP_reg7: 2496 return "DW_OP_reg7"; 2497 case DW_OP_reg8: 2498 return "DW_OP_reg8"; 2499 case DW_OP_reg9: 2500 return "DW_OP_reg9"; 2501 case DW_OP_reg10: 2502 return "DW_OP_reg10"; 2503 case DW_OP_reg11: 2504 return "DW_OP_reg11"; 2505 case DW_OP_reg12: 2506 return "DW_OP_reg12"; 2507 case DW_OP_reg13: 2508 return "DW_OP_reg13"; 2509 case DW_OP_reg14: 2510 return "DW_OP_reg14"; 2511 case DW_OP_reg15: 2512 return "DW_OP_reg15"; 2513 case DW_OP_reg16: 2514 return "DW_OP_reg16"; 2515 case DW_OP_reg17: 2516 return "DW_OP_reg17"; 2517 case DW_OP_reg18: 2518 return "DW_OP_reg18"; 2519 case DW_OP_reg19: 2520 return "DW_OP_reg19"; 2521 case DW_OP_reg20: 2522 return "DW_OP_reg20"; 2523 case DW_OP_reg21: 2524 return "DW_OP_reg21"; 2525 case DW_OP_reg22: 2526 return "DW_OP_reg22"; 2527 case DW_OP_reg23: 2528 return "DW_OP_reg23"; 2529 case DW_OP_reg24: 2530 return "DW_OP_reg24"; 2531 case DW_OP_reg25: 2532 return "DW_OP_reg25"; 2533 case DW_OP_reg26: 2534 return "DW_OP_reg26"; 2535 case DW_OP_reg27: 2536 return "DW_OP_reg27"; 2537 case DW_OP_reg28: 2538 return "DW_OP_reg28"; 2539 case DW_OP_reg29: 2540 return "DW_OP_reg29"; 2541 case DW_OP_reg30: 2542 return "DW_OP_reg30"; 2543 case DW_OP_reg31: 2544 return "DW_OP_reg31"; 2545 case DW_OP_breg0: 2546 return "DW_OP_breg0"; 2547 case DW_OP_breg1: 2548 return "DW_OP_breg1"; 2549 case DW_OP_breg2: 2550 return "DW_OP_breg2"; 2551 case DW_OP_breg3: 2552 return "DW_OP_breg3"; 2553 case DW_OP_breg4: 2554 return "DW_OP_breg4"; 2555 case DW_OP_breg5: 2556 return "DW_OP_breg5"; 2557 case DW_OP_breg6: 2558 return "DW_OP_breg6"; 2559 case DW_OP_breg7: 2560 return "DW_OP_breg7"; 2561 case DW_OP_breg8: 2562 return "DW_OP_breg8"; 2563 case DW_OP_breg9: 2564 return "DW_OP_breg9"; 2565 case DW_OP_breg10: 2566 return "DW_OP_breg10"; 2567 case DW_OP_breg11: 2568 return "DW_OP_breg11"; 2569 case DW_OP_breg12: 2570 return "DW_OP_breg12"; 2571 case DW_OP_breg13: 2572 return "DW_OP_breg13"; 2573 case DW_OP_breg14: 2574 return "DW_OP_breg14"; 2575 case DW_OP_breg15: 2576 return "DW_OP_breg15"; 2577 case DW_OP_breg16: 2578 return "DW_OP_breg16"; 2579 case DW_OP_breg17: 2580 return "DW_OP_breg17"; 2581 case DW_OP_breg18: 2582 return "DW_OP_breg18"; 2583 case DW_OP_breg19: 2584 return "DW_OP_breg19"; 2585 case DW_OP_breg20: 2586 return "DW_OP_breg20"; 2587 case DW_OP_breg21: 2588 return "DW_OP_breg21"; 2589 case DW_OP_breg22: 2590 return "DW_OP_breg22"; 2591 case DW_OP_breg23: 2592 return "DW_OP_breg23"; 2593 case DW_OP_breg24: 2594 return "DW_OP_breg24"; 2595 case DW_OP_breg25: 2596 return "DW_OP_breg25"; 2597 case DW_OP_breg26: 2598 return "DW_OP_breg26"; 2599 case DW_OP_breg27: 2600 return "DW_OP_breg27"; 2601 case DW_OP_breg28: 2602 return "DW_OP_breg28"; 2603 case DW_OP_breg29: 2604 return "DW_OP_breg29"; 2605 case DW_OP_breg30: 2606 return "DW_OP_breg30"; 2607 case DW_OP_breg31: 2608 return "DW_OP_breg31"; 2609 case DW_OP_regx: 2610 return "DW_OP_regx"; 2611 case DW_OP_fbreg: 2612 return "DW_OP_fbreg"; 2613 case DW_OP_bregx: 2614 return "DW_OP_bregx"; 2615 case DW_OP_piece: 2616 return "DW_OP_piece"; 2617 case DW_OP_deref_size: 2618 return "DW_OP_deref_size"; 2619 case DW_OP_xderef_size: 2620 return "DW_OP_xderef_size"; 2621 case DW_OP_nop: 2622 return "DW_OP_nop"; 2623 case DW_OP_push_object_address: 2624 return "DW_OP_push_object_address"; 2625 case DW_OP_call2: 2626 return "DW_OP_call2"; 2627 case DW_OP_call4: 2628 return "DW_OP_call4"; 2629 case DW_OP_call_ref: 2630 return "DW_OP_call_ref"; 2631 case DW_OP_GNU_push_tls_address: 2632 return "DW_OP_GNU_push_tls_address"; 2633 default: 2634 return "OP_<unknown>"; 2635 } 2636} 2637 2638/* Return a pointer to a newly allocated location description. Location 2639 descriptions are simple expression terms that can be strung 2640 together to form more complicated location (address) descriptions. */ 2641 2642static inline dw_loc_descr_ref 2643new_loc_descr (op, oprnd1, oprnd2) 2644 enum dwarf_location_atom op; 2645 unsigned long oprnd1; 2646 unsigned long oprnd2; 2647{ 2648 /* Use xcalloc here so we clear out all of the long_long constant in 2649 the union. */ 2650 dw_loc_descr_ref descr 2651 = (dw_loc_descr_ref) xcalloc (1, sizeof (dw_loc_descr_node)); 2652 2653 descr->dw_loc_opc = op; 2654 descr->dw_loc_oprnd1.val_class = dw_val_class_unsigned_const; 2655 descr->dw_loc_oprnd1.v.val_unsigned = oprnd1; 2656 descr->dw_loc_oprnd2.val_class = dw_val_class_unsigned_const; 2657 descr->dw_loc_oprnd2.v.val_unsigned = oprnd2; 2658 2659 return descr; 2660} 2661 2662 2663/* Add a location description term to a location description expression. */ 2664 2665static inline void 2666add_loc_descr (list_head, descr) 2667 dw_loc_descr_ref *list_head; 2668 dw_loc_descr_ref descr; 2669{ 2670 dw_loc_descr_ref *d; 2671 2672 /* Find the end of the chain. */ 2673 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) 2674 ; 2675 2676 *d = descr; 2677} 2678 2679/* Return the size of a location descriptor. */ 2680 2681static unsigned long 2682size_of_loc_descr (loc) 2683 dw_loc_descr_ref loc; 2684{ 2685 unsigned long size = 1; 2686 2687 switch (loc->dw_loc_opc) 2688 { 2689 case DW_OP_addr: 2690 case INTERNAL_DW_OP_tls_addr: 2691 size += DWARF2_ADDR_SIZE; 2692 break; 2693 case DW_OP_const1u: 2694 case DW_OP_const1s: 2695 size += 1; 2696 break; 2697 case DW_OP_const2u: 2698 case DW_OP_const2s: 2699 size += 2; 2700 break; 2701 case DW_OP_const4u: 2702 case DW_OP_const4s: 2703 size += 4; 2704 break; 2705 case DW_OP_const8u: 2706 case DW_OP_const8s: 2707 size += 8; 2708 break; 2709 case DW_OP_constu: 2710 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); 2711 break; 2712 case DW_OP_consts: 2713 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); 2714 break; 2715 case DW_OP_pick: 2716 size += 1; 2717 break; 2718 case DW_OP_plus_uconst: 2719 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); 2720 break; 2721 case DW_OP_skip: 2722 case DW_OP_bra: 2723 size += 2; 2724 break; 2725 case DW_OP_breg0: 2726 case DW_OP_breg1: 2727 case DW_OP_breg2: 2728 case DW_OP_breg3: 2729 case DW_OP_breg4: 2730 case DW_OP_breg5: 2731 case DW_OP_breg6: 2732 case DW_OP_breg7: 2733 case DW_OP_breg8: 2734 case DW_OP_breg9: 2735 case DW_OP_breg10: 2736 case DW_OP_breg11: 2737 case DW_OP_breg12: 2738 case DW_OP_breg13: 2739 case DW_OP_breg14: 2740 case DW_OP_breg15: 2741 case DW_OP_breg16: 2742 case DW_OP_breg17: 2743 case DW_OP_breg18: 2744 case DW_OP_breg19: 2745 case DW_OP_breg20: 2746 case DW_OP_breg21: 2747 case DW_OP_breg22: 2748 case DW_OP_breg23: 2749 case DW_OP_breg24: 2750 case DW_OP_breg25: 2751 case DW_OP_breg26: 2752 case DW_OP_breg27: 2753 case DW_OP_breg28: 2754 case DW_OP_breg29: 2755 case DW_OP_breg30: 2756 case DW_OP_breg31: 2757 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); 2758 break; 2759 case DW_OP_regx: 2760 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); 2761 break; 2762 case DW_OP_fbreg: 2763 size += size_of_sleb128 (loc->dw_loc_oprnd1.v.val_int); 2764 break; 2765 case DW_OP_bregx: 2766 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); 2767 size += size_of_sleb128 (loc->dw_loc_oprnd2.v.val_int); 2768 break; 2769 case DW_OP_piece: 2770 size += size_of_uleb128 (loc->dw_loc_oprnd1.v.val_unsigned); 2771 break; 2772 case DW_OP_deref_size: 2773 case DW_OP_xderef_size: 2774 size += 1; 2775 break; 2776 case DW_OP_call2: 2777 size += 2; 2778 break; 2779 case DW_OP_call4: 2780 size += 4; 2781 break; 2782 case DW_OP_call_ref: 2783 size += DWARF2_ADDR_SIZE; 2784 break; 2785 default: 2786 break; 2787 } 2788 2789 return size; 2790} 2791 2792/* Return the size of a series of location descriptors. */ 2793 2794static unsigned long 2795size_of_locs (loc) 2796 dw_loc_descr_ref loc; 2797{ 2798 unsigned long size; 2799 2800 for (size = 0; loc != NULL; loc = loc->dw_loc_next) 2801 { 2802 loc->dw_loc_addr = size; 2803 size += size_of_loc_descr (loc); 2804 } 2805 2806 return size; 2807} 2808 2809/* Output location description stack opcode's operands (if any). */ 2810 2811static void 2812output_loc_operands (loc) 2813 dw_loc_descr_ref loc; 2814{ 2815 dw_val_ref val1 = &loc->dw_loc_oprnd1; 2816 dw_val_ref val2 = &loc->dw_loc_oprnd2; 2817 2818 switch (loc->dw_loc_opc) 2819 { 2820#ifdef DWARF2_DEBUGGING_INFO 2821 case DW_OP_addr: 2822 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, val1->v.val_addr, NULL); 2823 break; 2824 case DW_OP_const2u: 2825 case DW_OP_const2s: 2826 dw2_asm_output_data (2, val1->v.val_int, NULL); 2827 break; 2828 case DW_OP_const4u: 2829 case DW_OP_const4s: 2830 dw2_asm_output_data (4, val1->v.val_int, NULL); 2831 break; 2832 case DW_OP_const8u: 2833 case DW_OP_const8s: 2834 if (HOST_BITS_PER_LONG < 64) 2835 abort (); 2836 dw2_asm_output_data (8, val1->v.val_int, NULL); 2837 break; 2838 case DW_OP_skip: 2839 case DW_OP_bra: 2840 { 2841 int offset; 2842 2843 if (val1->val_class == dw_val_class_loc) 2844 offset = val1->v.val_loc->dw_loc_addr - (loc->dw_loc_addr + 3); 2845 else 2846 abort (); 2847 2848 dw2_asm_output_data (2, offset, NULL); 2849 } 2850 break; 2851#else 2852 case DW_OP_addr: 2853 case DW_OP_const2u: 2854 case DW_OP_const2s: 2855 case DW_OP_const4u: 2856 case DW_OP_const4s: 2857 case DW_OP_const8u: 2858 case DW_OP_const8s: 2859 case DW_OP_skip: 2860 case DW_OP_bra: 2861 /* We currently don't make any attempt to make sure these are 2862 aligned properly like we do for the main unwind info, so 2863 don't support emitting things larger than a byte if we're 2864 only doing unwinding. */ 2865 abort (); 2866#endif 2867 case DW_OP_const1u: 2868 case DW_OP_const1s: 2869 dw2_asm_output_data (1, val1->v.val_int, NULL); 2870 break; 2871 case DW_OP_constu: 2872 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); 2873 break; 2874 case DW_OP_consts: 2875 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); 2876 break; 2877 case DW_OP_pick: 2878 dw2_asm_output_data (1, val1->v.val_int, NULL); 2879 break; 2880 case DW_OP_plus_uconst: 2881 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); 2882 break; 2883 case DW_OP_breg0: 2884 case DW_OP_breg1: 2885 case DW_OP_breg2: 2886 case DW_OP_breg3: 2887 case DW_OP_breg4: 2888 case DW_OP_breg5: 2889 case DW_OP_breg6: 2890 case DW_OP_breg7: 2891 case DW_OP_breg8: 2892 case DW_OP_breg9: 2893 case DW_OP_breg10: 2894 case DW_OP_breg11: 2895 case DW_OP_breg12: 2896 case DW_OP_breg13: 2897 case DW_OP_breg14: 2898 case DW_OP_breg15: 2899 case DW_OP_breg16: 2900 case DW_OP_breg17: 2901 case DW_OP_breg18: 2902 case DW_OP_breg19: 2903 case DW_OP_breg20: 2904 case DW_OP_breg21: 2905 case DW_OP_breg22: 2906 case DW_OP_breg23: 2907 case DW_OP_breg24: 2908 case DW_OP_breg25: 2909 case DW_OP_breg26: 2910 case DW_OP_breg27: 2911 case DW_OP_breg28: 2912 case DW_OP_breg29: 2913 case DW_OP_breg30: 2914 case DW_OP_breg31: 2915 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); 2916 break; 2917 case DW_OP_regx: 2918 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); 2919 break; 2920 case DW_OP_fbreg: 2921 dw2_asm_output_data_sleb128 (val1->v.val_int, NULL); 2922 break; 2923 case DW_OP_bregx: 2924 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); 2925 dw2_asm_output_data_sleb128 (val2->v.val_int, NULL); 2926 break; 2927 case DW_OP_piece: 2928 dw2_asm_output_data_uleb128 (val1->v.val_unsigned, NULL); 2929 break; 2930 case DW_OP_deref_size: 2931 case DW_OP_xderef_size: 2932 dw2_asm_output_data (1, val1->v.val_int, NULL); 2933 break; 2934 2935 case INTERNAL_DW_OP_tls_addr: 2936#ifdef ASM_OUTPUT_DWARF_DTPREL 2937 ASM_OUTPUT_DWARF_DTPREL (asm_out_file, DWARF2_ADDR_SIZE, 2938 val1->v.val_addr); 2939 fputc ('\n', asm_out_file); 2940#else 2941 abort (); 2942#endif 2943 break; 2944 2945 default: 2946 /* Other codes have no operands. */ 2947 break; 2948 } 2949} 2950 2951/* Output a sequence of location operations. */ 2952 2953static void 2954output_loc_sequence (loc) 2955 dw_loc_descr_ref loc; 2956{ 2957 for (; loc != NULL; loc = loc->dw_loc_next) 2958 { 2959 /* Output the opcode. */ 2960 dw2_asm_output_data (1, loc->dw_loc_opc, 2961 "%s", dwarf_stack_op_name (loc->dw_loc_opc)); 2962 2963 /* Output the operand(s) (if any). */ 2964 output_loc_operands (loc); 2965 } 2966} 2967 2968/* This routine will generate the correct assembly data for a location 2969 description based on a cfi entry with a complex address. */ 2970 2971static void 2972output_cfa_loc (cfi) 2973 dw_cfi_ref cfi; 2974{ 2975 dw_loc_descr_ref loc; 2976 unsigned long size; 2977 2978 /* Output the size of the block. */ 2979 loc = cfi->dw_cfi_oprnd1.dw_cfi_loc; 2980 size = size_of_locs (loc); 2981 dw2_asm_output_data_uleb128 (size, NULL); 2982 2983 /* Now output the operations themselves. */ 2984 output_loc_sequence (loc); 2985} 2986 2987/* This function builds a dwarf location descriptor sequence from 2988 a dw_cfa_location. */ 2989 2990static struct dw_loc_descr_struct * 2991build_cfa_loc (cfa) 2992 dw_cfa_location *cfa; 2993{ 2994 struct dw_loc_descr_struct *head, *tmp; 2995 2996 if (cfa->indirect == 0) 2997 abort (); 2998 2999 if (cfa->base_offset) 3000 { 3001 if (cfa->reg <= 31) 3002 head = new_loc_descr (DW_OP_breg0 + cfa->reg, cfa->base_offset, 0); 3003 else 3004 head = new_loc_descr (DW_OP_bregx, cfa->reg, cfa->base_offset); 3005 } 3006 else if (cfa->reg <= 31) 3007 head = new_loc_descr (DW_OP_reg0 + cfa->reg, 0, 0); 3008 else 3009 head = new_loc_descr (DW_OP_regx, cfa->reg, 0); 3010 3011 head->dw_loc_oprnd1.val_class = dw_val_class_const; 3012 tmp = new_loc_descr (DW_OP_deref, 0, 0); 3013 add_loc_descr (&head, tmp); 3014 if (cfa->offset != 0) 3015 { 3016 tmp = new_loc_descr (DW_OP_plus_uconst, cfa->offset, 0); 3017 add_loc_descr (&head, tmp); 3018 } 3019 3020 return head; 3021} 3022 3023/* This function fills in aa dw_cfa_location structure from a dwarf location 3024 descriptor sequence. */ 3025 3026static void 3027get_cfa_from_loc_descr (cfa, loc) 3028 dw_cfa_location *cfa; 3029 struct dw_loc_descr_struct *loc; 3030{ 3031 struct dw_loc_descr_struct *ptr; 3032 cfa->offset = 0; 3033 cfa->base_offset = 0; 3034 cfa->indirect = 0; 3035 cfa->reg = -1; 3036 3037 for (ptr = loc; ptr != NULL; ptr = ptr->dw_loc_next) 3038 { 3039 enum dwarf_location_atom op = ptr->dw_loc_opc; 3040 3041 switch (op) 3042 { 3043 case DW_OP_reg0: 3044 case DW_OP_reg1: 3045 case DW_OP_reg2: 3046 case DW_OP_reg3: 3047 case DW_OP_reg4: 3048 case DW_OP_reg5: 3049 case DW_OP_reg6: 3050 case DW_OP_reg7: 3051 case DW_OP_reg8: 3052 case DW_OP_reg9: 3053 case DW_OP_reg10: 3054 case DW_OP_reg11: 3055 case DW_OP_reg12: 3056 case DW_OP_reg13: 3057 case DW_OP_reg14: 3058 case DW_OP_reg15: 3059 case DW_OP_reg16: 3060 case DW_OP_reg17: 3061 case DW_OP_reg18: 3062 case DW_OP_reg19: 3063 case DW_OP_reg20: 3064 case DW_OP_reg21: 3065 case DW_OP_reg22: 3066 case DW_OP_reg23: 3067 case DW_OP_reg24: 3068 case DW_OP_reg25: 3069 case DW_OP_reg26: 3070 case DW_OP_reg27: 3071 case DW_OP_reg28: 3072 case DW_OP_reg29: 3073 case DW_OP_reg30: 3074 case DW_OP_reg31: 3075 cfa->reg = op - DW_OP_reg0; 3076 break; 3077 case DW_OP_regx: 3078 cfa->reg = ptr->dw_loc_oprnd1.v.val_int; 3079 break; 3080 case DW_OP_breg0: 3081 case DW_OP_breg1: 3082 case DW_OP_breg2: 3083 case DW_OP_breg3: 3084 case DW_OP_breg4: 3085 case DW_OP_breg5: 3086 case DW_OP_breg6: 3087 case DW_OP_breg7: 3088 case DW_OP_breg8: 3089 case DW_OP_breg9: 3090 case DW_OP_breg10: 3091 case DW_OP_breg11: 3092 case DW_OP_breg12: 3093 case DW_OP_breg13: 3094 case DW_OP_breg14: 3095 case DW_OP_breg15: 3096 case DW_OP_breg16: 3097 case DW_OP_breg17: 3098 case DW_OP_breg18: 3099 case DW_OP_breg19: 3100 case DW_OP_breg20: 3101 case DW_OP_breg21: 3102 case DW_OP_breg22: 3103 case DW_OP_breg23: 3104 case DW_OP_breg24: 3105 case DW_OP_breg25: 3106 case DW_OP_breg26: 3107 case DW_OP_breg27: 3108 case DW_OP_breg28: 3109 case DW_OP_breg29: 3110 case DW_OP_breg30: 3111 case DW_OP_breg31: 3112 cfa->reg = op - DW_OP_breg0; 3113 cfa->base_offset = ptr->dw_loc_oprnd1.v.val_int; 3114 break; 3115 case DW_OP_bregx: 3116 cfa->reg = ptr->dw_loc_oprnd1.v.val_int; 3117 cfa->base_offset = ptr->dw_loc_oprnd2.v.val_int; 3118 break; 3119 case DW_OP_deref: 3120 cfa->indirect = 1; 3121 break; 3122 case DW_OP_plus_uconst: 3123 cfa->offset = ptr->dw_loc_oprnd1.v.val_unsigned; 3124 break; 3125 default: 3126 internal_error ("DW_LOC_OP %s not implemented\n", 3127 dwarf_stack_op_name (ptr->dw_loc_opc)); 3128 } 3129 } 3130} 3131#endif /* .debug_frame support */ 3132 3133/* And now, the support for symbolic debugging information. */ 3134#ifdef DWARF2_DEBUGGING_INFO 3135 3136/* .debug_str support. */ 3137static hashnode indirect_string_alloc PARAMS ((hash_table *)); 3138static int output_indirect_string PARAMS ((struct cpp_reader *, 3139 hashnode, const PTR)); 3140 3141 3142static void dwarf2out_init PARAMS ((const char *)); 3143static void dwarf2out_finish PARAMS ((const char *)); 3144static void dwarf2out_define PARAMS ((unsigned int, const char *)); 3145static void dwarf2out_undef PARAMS ((unsigned int, const char *)); 3146static void dwarf2out_start_source_file PARAMS ((unsigned, const char *)); 3147static void dwarf2out_end_source_file PARAMS ((unsigned)); 3148static void dwarf2out_begin_block PARAMS ((unsigned, unsigned)); 3149static void dwarf2out_end_block PARAMS ((unsigned, unsigned)); 3150static bool dwarf2out_ignore_block PARAMS ((tree)); 3151static void dwarf2out_global_decl PARAMS ((tree)); 3152static void dwarf2out_abstract_function PARAMS ((tree)); 3153 3154/* The debug hooks structure. */ 3155 3156const struct gcc_debug_hooks dwarf2_debug_hooks = 3157{ 3158 dwarf2out_init, 3159 dwarf2out_finish, 3160 dwarf2out_define, 3161 dwarf2out_undef, 3162 dwarf2out_start_source_file, 3163 dwarf2out_end_source_file, 3164 dwarf2out_begin_block, 3165 dwarf2out_end_block, 3166 dwarf2out_ignore_block, 3167 dwarf2out_source_line, 3168 dwarf2out_begin_prologue, 3169 debug_nothing_int_charstar, /* end_prologue */ 3170 dwarf2out_end_epilogue, 3171 debug_nothing_tree, /* begin_function */ 3172 debug_nothing_int, /* end_function */ 3173 dwarf2out_decl, /* function_decl */ 3174 dwarf2out_global_decl, 3175 debug_nothing_tree, /* deferred_inline_function */ 3176 /* The DWARF 2 backend tries to reduce debugging bloat by not 3177 emitting the abstract description of inline functions until 3178 something tries to reference them. */ 3179 dwarf2out_abstract_function, /* outlining_inline_function */ 3180 debug_nothing_rtx /* label */ 3181}; 3182 3183/* NOTE: In the comments in this file, many references are made to 3184 "Debugging Information Entries". This term is abbreviated as `DIE' 3185 throughout the remainder of this file. */ 3186 3187/* An internal representation of the DWARF output is built, and then 3188 walked to generate the DWARF debugging info. The walk of the internal 3189 representation is done after the entire program has been compiled. 3190 The types below are used to describe the internal representation. */ 3191 3192/* Various DIE's use offsets relative to the beginning of the 3193 .debug_info section to refer to each other. */ 3194 3195typedef long int dw_offset; 3196 3197/* Define typedefs here to avoid circular dependencies. */ 3198 3199typedef struct dw_attr_struct *dw_attr_ref; 3200typedef struct dw_line_info_struct *dw_line_info_ref; 3201typedef struct dw_separate_line_info_struct *dw_separate_line_info_ref; 3202typedef struct pubname_struct *pubname_ref; 3203typedef struct dw_ranges_struct *dw_ranges_ref; 3204 3205/* Each entry in the line_info_table maintains the file and 3206 line number associated with the label generated for that 3207 entry. The label gives the PC value associated with 3208 the line number entry. */ 3209 3210typedef struct dw_line_info_struct 3211{ 3212 unsigned long dw_file_num; 3213 unsigned long dw_line_num; 3214} 3215dw_line_info_entry; 3216 3217/* Line information for functions in separate sections; each one gets its 3218 own sequence. */ 3219typedef struct dw_separate_line_info_struct 3220{ 3221 unsigned long dw_file_num; 3222 unsigned long dw_line_num; 3223 unsigned long function; 3224} 3225dw_separate_line_info_entry; 3226 3227/* Each DIE attribute has a field specifying the attribute kind, 3228 a link to the next attribute in the chain, and an attribute value. 3229 Attributes are typically linked below the DIE they modify. */ 3230 3231typedef struct dw_attr_struct 3232{ 3233 enum dwarf_attribute dw_attr; 3234 dw_attr_ref dw_attr_next; 3235 dw_val_node dw_attr_val; 3236} 3237dw_attr_node; 3238 3239/* The Debugging Information Entry (DIE) structure */ 3240 3241typedef struct die_struct 3242{ 3243 enum dwarf_tag die_tag; 3244 char *die_symbol; 3245 dw_attr_ref die_attr; 3246 dw_die_ref die_parent; 3247 dw_die_ref die_child; 3248 dw_die_ref die_sib; 3249 dw_offset die_offset; 3250 unsigned long die_abbrev; 3251 int die_mark; 3252} 3253die_node; 3254 3255/* The pubname structure */ 3256 3257typedef struct pubname_struct 3258{ 3259 dw_die_ref die; 3260 char *name; 3261} 3262pubname_entry; 3263 3264struct dw_ranges_struct 3265{ 3266 int block_num; 3267}; 3268 3269/* The limbo die list structure. */ 3270typedef struct limbo_die_struct 3271{ 3272 dw_die_ref die; 3273 tree created_for; 3274 struct limbo_die_struct *next; 3275} 3276limbo_die_node; 3277 3278/* How to start an assembler comment. */ 3279#ifndef ASM_COMMENT_START 3280#define ASM_COMMENT_START ";#" 3281#endif 3282 3283/* Define a macro which returns nonzero for a TYPE_DECL which was 3284 implicitly generated for a tagged type. 3285 3286 Note that unlike the gcc front end (which generates a NULL named 3287 TYPE_DECL node for each complete tagged type, each array type, and 3288 each function type node created) the g++ front end generates a 3289 _named_ TYPE_DECL node for each tagged type node created. 3290 These TYPE_DECLs have DECL_ARTIFICIAL set, so we know not to 3291 generate a DW_TAG_typedef DIE for them. */ 3292 3293#define TYPE_DECL_IS_STUB(decl) \ 3294 (DECL_NAME (decl) == NULL_TREE \ 3295 || (DECL_ARTIFICIAL (decl) \ 3296 && is_tagged_type (TREE_TYPE (decl)) \ 3297 && ((decl == TYPE_STUB_DECL (TREE_TYPE (decl))) \ 3298 /* This is necessary for stub decls that \ 3299 appear in nested inline functions. */ \ 3300 || (DECL_ABSTRACT_ORIGIN (decl) != NULL_TREE \ 3301 && (decl_ultimate_origin (decl) \ 3302 == TYPE_STUB_DECL (TREE_TYPE (decl))))))) 3303 3304/* Information concerning the compilation unit's programming 3305 language, and compiler version. */ 3306 3307/* Fixed size portion of the DWARF compilation unit header. */ 3308#define DWARF_COMPILE_UNIT_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 3) 3309 3310/* Fixed size portion of public names info. */ 3311#define DWARF_PUBNAMES_HEADER_SIZE (2 * DWARF_OFFSET_SIZE + 2) 3312 3313/* Fixed size portion of the address range info. */ 3314#define DWARF_ARANGES_HEADER_SIZE \ 3315 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ 3316 - DWARF_OFFSET_SIZE) 3317 3318/* Size of padding portion in the address range info. It must be 3319 aligned to twice the pointer size. */ 3320#define DWARF_ARANGES_PAD_SIZE \ 3321 (DWARF_ROUND (2 * DWARF_OFFSET_SIZE + 4, DWARF2_ADDR_SIZE * 2) \ 3322 - (2 * DWARF_OFFSET_SIZE + 4)) 3323 3324/* Use assembler line directives if available. */ 3325#ifndef DWARF2_ASM_LINE_DEBUG_INFO 3326#ifdef HAVE_AS_DWARF2_DEBUG_LINE 3327#define DWARF2_ASM_LINE_DEBUG_INFO 1 3328#else 3329#define DWARF2_ASM_LINE_DEBUG_INFO 0 3330#endif 3331#endif 3332 3333/* Minimum line offset in a special line info. opcode. 3334 This value was chosen to give a reasonable range of values. */ 3335#define DWARF_LINE_BASE -10 3336 3337/* First special line opcode - leave room for the standard opcodes. */ 3338#define DWARF_LINE_OPCODE_BASE 10 3339 3340/* Range of line offsets in a special line info. opcode. */ 3341#define DWARF_LINE_RANGE (254-DWARF_LINE_OPCODE_BASE+1) 3342 3343/* Flag that indicates the initial value of the is_stmt_start flag. 3344 In the present implementation, we do not mark any lines as 3345 the beginning of a source statement, because that information 3346 is not made available by the GCC front-end. */ 3347#define DWARF_LINE_DEFAULT_IS_STMT_START 1 3348 3349/* This location is used by calc_die_sizes() to keep track 3350 the offset of each DIE within the .debug_info section. */ 3351static unsigned long next_die_offset; 3352 3353/* Record the root of the DIE's built for the current compilation unit. */ 3354static dw_die_ref comp_unit_die; 3355 3356/* We need special handling in dwarf2out_start_source_file if it is 3357 first one. */ 3358static int is_main_source; 3359 3360/* A list of DIEs with a NULL parent waiting to be relocated. */ 3361static limbo_die_node *limbo_die_list = 0; 3362 3363/* Structure used by lookup_filename to manage sets of filenames. */ 3364struct file_table 3365{ 3366 char **table; 3367 unsigned allocated; 3368 unsigned in_use; 3369 unsigned last_lookup_index; 3370}; 3371 3372/* Size (in elements) of increments by which we may expand the filename 3373 table. */ 3374#define FILE_TABLE_INCREMENT 64 3375 3376/* Filenames referenced by this compilation unit. */ 3377static struct file_table file_table; 3378 3379/* Local pointer to the name of the main input file. Initialized in 3380 dwarf2out_init. */ 3381static const char *primary_filename; 3382 3383/* A pointer to the base of a table of references to DIE's that describe 3384 declarations. The table is indexed by DECL_UID() which is a unique 3385 number identifying each decl. */ 3386static dw_die_ref *decl_die_table; 3387 3388/* Number of elements currently allocated for the decl_die_table. */ 3389static unsigned decl_die_table_allocated; 3390 3391/* Number of elements in decl_die_table currently in use. */ 3392static unsigned decl_die_table_in_use; 3393 3394/* Size (in elements) of increments by which we may expand the 3395 decl_die_table. */ 3396#define DECL_DIE_TABLE_INCREMENT 256 3397 3398/* A pointer to the base of a list of references to DIE's that 3399 are uniquely identified by their tag, presence/absence of 3400 children DIE's, and list of attribute/value pairs. */ 3401static dw_die_ref *abbrev_die_table; 3402 3403/* Number of elements currently allocated for abbrev_die_table. */ 3404static unsigned abbrev_die_table_allocated; 3405 3406/* Number of elements in type_die_table currently in use. */ 3407static unsigned abbrev_die_table_in_use; 3408 3409/* Size (in elements) of increments by which we may expand the 3410 abbrev_die_table. */ 3411#define ABBREV_DIE_TABLE_INCREMENT 256 3412 3413/* A pointer to the base of a table that contains line information 3414 for each source code line in .text in the compilation unit. */ 3415static dw_line_info_ref line_info_table; 3416 3417/* Number of elements currently allocated for line_info_table. */ 3418static unsigned line_info_table_allocated; 3419 3420/* Number of elements in separate_line_info_table currently in use. */ 3421static unsigned separate_line_info_table_in_use; 3422 3423/* A pointer to the base of a table that contains line information 3424 for each source code line outside of .text in the compilation unit. */ 3425static dw_separate_line_info_ref separate_line_info_table; 3426 3427/* Number of elements currently allocated for separate_line_info_table. */ 3428static unsigned separate_line_info_table_allocated; 3429 3430/* Number of elements in line_info_table currently in use. */ 3431static unsigned line_info_table_in_use; 3432 3433/* Size (in elements) of increments by which we may expand the 3434 line_info_table. */ 3435#define LINE_INFO_TABLE_INCREMENT 1024 3436 3437/* A pointer to the base of a table that contains a list of publicly 3438 accessible names. */ 3439static pubname_ref pubname_table; 3440 3441/* Number of elements currently allocated for pubname_table. */ 3442static unsigned pubname_table_allocated; 3443 3444/* Number of elements in pubname_table currently in use. */ 3445static unsigned pubname_table_in_use; 3446 3447/* Size (in elements) of increments by which we may expand the 3448 pubname_table. */ 3449#define PUBNAME_TABLE_INCREMENT 64 3450 3451/* Array of dies for which we should generate .debug_arange info. */ 3452static dw_die_ref *arange_table; 3453 3454/* Number of elements currently allocated for arange_table. */ 3455static unsigned arange_table_allocated; 3456 3457/* Number of elements in arange_table currently in use. */ 3458static unsigned arange_table_in_use; 3459 3460/* Size (in elements) of increments by which we may expand the 3461 arange_table. */ 3462#define ARANGE_TABLE_INCREMENT 64 3463 3464/* Array of dies for which we should generate .debug_ranges info. */ 3465static dw_ranges_ref ranges_table; 3466 3467/* Number of elements currently allocated for ranges_table. */ 3468static unsigned ranges_table_allocated; 3469 3470/* Number of elements in ranges_table currently in use. */ 3471static unsigned ranges_table_in_use; 3472 3473/* Size (in elements) of increments by which we may expand the 3474 ranges_table. */ 3475#define RANGES_TABLE_INCREMENT 64 3476 3477/* Whether we have location lists that need outputting */ 3478static unsigned have_location_lists; 3479 3480/* Record whether the function being analyzed contains inlined functions. */ 3481static int current_function_has_inlines; 3482#if 0 && defined (MIPS_DEBUGGING_INFO) 3483static int comp_unit_has_inlines; 3484#endif 3485 3486/* Forward declarations for functions defined in this file. */ 3487 3488static int is_pseudo_reg PARAMS ((rtx)); 3489static tree type_main_variant PARAMS ((tree)); 3490static int is_tagged_type PARAMS ((tree)); 3491static const char *dwarf_tag_name PARAMS ((unsigned)); 3492static const char *dwarf_attr_name PARAMS ((unsigned)); 3493static const char *dwarf_form_name PARAMS ((unsigned)); 3494#if 0 3495static const char *dwarf_type_encoding_name PARAMS ((unsigned)); 3496#endif 3497static tree decl_ultimate_origin PARAMS ((tree)); 3498static tree block_ultimate_origin PARAMS ((tree)); 3499static tree decl_class_context PARAMS ((tree)); 3500static void add_dwarf_attr PARAMS ((dw_die_ref, dw_attr_ref)); 3501static inline dw_val_class AT_class PARAMS ((dw_attr_ref)); 3502static void add_AT_flag PARAMS ((dw_die_ref, 3503 enum dwarf_attribute, 3504 unsigned)); 3505static inline unsigned AT_flag PARAMS ((dw_attr_ref)); 3506static void add_AT_int PARAMS ((dw_die_ref, 3507 enum dwarf_attribute, long)); 3508static inline long int AT_int PARAMS ((dw_attr_ref)); 3509static void add_AT_unsigned PARAMS ((dw_die_ref, 3510 enum dwarf_attribute, 3511 unsigned long)); 3512static inline unsigned long AT_unsigned PARAMS ((dw_attr_ref)); 3513static void add_AT_long_long PARAMS ((dw_die_ref, 3514 enum dwarf_attribute, 3515 unsigned long, 3516 unsigned long)); 3517static void add_AT_float PARAMS ((dw_die_ref, 3518 enum dwarf_attribute, 3519 unsigned, long *)); 3520static void add_AT_string PARAMS ((dw_die_ref, 3521 enum dwarf_attribute, 3522 const char *)); 3523static inline const char *AT_string PARAMS ((dw_attr_ref)); 3524static int AT_string_form PARAMS ((dw_attr_ref)); 3525static void add_AT_die_ref PARAMS ((dw_die_ref, 3526 enum dwarf_attribute, 3527 dw_die_ref)); 3528static inline dw_die_ref AT_ref PARAMS ((dw_attr_ref)); 3529static inline int AT_ref_external PARAMS ((dw_attr_ref)); 3530static inline void set_AT_ref_external PARAMS ((dw_attr_ref, int)); 3531static void add_AT_fde_ref PARAMS ((dw_die_ref, 3532 enum dwarf_attribute, 3533 unsigned)); 3534static void add_AT_loc PARAMS ((dw_die_ref, 3535 enum dwarf_attribute, 3536 dw_loc_descr_ref)); 3537static inline dw_loc_descr_ref AT_loc PARAMS ((dw_attr_ref)); 3538static void add_AT_loc_list PARAMS ((dw_die_ref, 3539 enum dwarf_attribute, 3540 dw_loc_list_ref)); 3541static inline dw_loc_list_ref AT_loc_list PARAMS ((dw_attr_ref)); 3542static void add_AT_addr PARAMS ((dw_die_ref, 3543 enum dwarf_attribute, 3544 rtx)); 3545static inline rtx AT_addr PARAMS ((dw_attr_ref)); 3546static void add_AT_lbl_id PARAMS ((dw_die_ref, 3547 enum dwarf_attribute, 3548 const char *)); 3549static void add_AT_lbl_offset PARAMS ((dw_die_ref, 3550 enum dwarf_attribute, 3551 const char *)); 3552static void add_AT_offset PARAMS ((dw_die_ref, 3553 enum dwarf_attribute, 3554 unsigned long)); 3555static void add_AT_range_list PARAMS ((dw_die_ref, 3556 enum dwarf_attribute, 3557 unsigned long)); 3558static inline const char *AT_lbl PARAMS ((dw_attr_ref)); 3559static dw_attr_ref get_AT PARAMS ((dw_die_ref, 3560 enum dwarf_attribute)); 3561static const char *get_AT_low_pc PARAMS ((dw_die_ref)); 3562static const char *get_AT_hi_pc PARAMS ((dw_die_ref)); 3563static const char *get_AT_string PARAMS ((dw_die_ref, 3564 enum dwarf_attribute)); 3565static int get_AT_flag PARAMS ((dw_die_ref, 3566 enum dwarf_attribute)); 3567static unsigned get_AT_unsigned PARAMS ((dw_die_ref, 3568 enum dwarf_attribute)); 3569static inline dw_die_ref get_AT_ref PARAMS ((dw_die_ref, 3570 enum dwarf_attribute)); 3571static int is_c_family PARAMS ((void)); 3572static int is_cxx PARAMS ((void)); 3573static int is_java PARAMS ((void)); 3574static int is_fortran PARAMS ((void)); 3575static void remove_AT PARAMS ((dw_die_ref, 3576 enum dwarf_attribute)); 3577static inline void free_die PARAMS ((dw_die_ref)); 3578static void remove_children PARAMS ((dw_die_ref)); 3579static void add_child_die PARAMS ((dw_die_ref, dw_die_ref)); 3580static dw_die_ref new_die PARAMS ((enum dwarf_tag, dw_die_ref, 3581 tree)); 3582static dw_die_ref lookup_type_die PARAMS ((tree)); 3583static void equate_type_number_to_die PARAMS ((tree, dw_die_ref)); 3584static dw_die_ref lookup_decl_die PARAMS ((tree)); 3585static void equate_decl_number_to_die PARAMS ((tree, dw_die_ref)); 3586static void print_spaces PARAMS ((FILE *)); 3587static void print_die PARAMS ((dw_die_ref, FILE *)); 3588static void print_dwarf_line_table PARAMS ((FILE *)); 3589static void reverse_die_lists PARAMS ((dw_die_ref)); 3590static void reverse_all_dies PARAMS ((dw_die_ref)); 3591static dw_die_ref push_new_compile_unit PARAMS ((dw_die_ref, dw_die_ref)); 3592static dw_die_ref pop_compile_unit PARAMS ((dw_die_ref)); 3593static void loc_checksum PARAMS ((dw_loc_descr_ref, 3594 struct md5_ctx *)); 3595static void attr_checksum PARAMS ((dw_attr_ref, 3596 struct md5_ctx *, 3597 int *)); 3598static void die_checksum PARAMS ((dw_die_ref, 3599 struct md5_ctx *, 3600 int *)); 3601static int same_loc_p PARAMS ((dw_loc_descr_ref, 3602 dw_loc_descr_ref, int *)); 3603static int same_dw_val_p PARAMS ((dw_val_node *, dw_val_node *, 3604 int *)); 3605static int same_attr_p PARAMS ((dw_attr_ref, dw_attr_ref, int *)); 3606static int same_die_p PARAMS ((dw_die_ref, dw_die_ref, int *)); 3607static int same_die_p_wrap PARAMS ((dw_die_ref, dw_die_ref)); 3608static void compute_section_prefix PARAMS ((dw_die_ref)); 3609static int is_type_die PARAMS ((dw_die_ref)); 3610static int is_comdat_die PARAMS ((dw_die_ref)); 3611static int is_symbol_die PARAMS ((dw_die_ref)); 3612static void assign_symbol_names PARAMS ((dw_die_ref)); 3613static void break_out_includes PARAMS ((dw_die_ref)); 3614static hashval_t htab_cu_hash PARAMS ((const void *)); 3615static int htab_cu_eq PARAMS ((const void *, const void *)); 3616static void htab_cu_del PARAMS ((void *)); 3617static int check_duplicate_cu PARAMS ((dw_die_ref, htab_t, unsigned *)); 3618static void record_comdat_symbol_number PARAMS ((dw_die_ref, htab_t, unsigned)); 3619static void add_sibling_attributes PARAMS ((dw_die_ref)); 3620static void build_abbrev_table PARAMS ((dw_die_ref)); 3621static void output_location_lists PARAMS ((dw_die_ref)); 3622static int constant_size PARAMS ((long unsigned)); 3623static unsigned long size_of_die PARAMS ((dw_die_ref)); 3624static void calc_die_sizes PARAMS ((dw_die_ref)); 3625static void mark_dies PARAMS ((dw_die_ref)); 3626static void unmark_dies PARAMS ((dw_die_ref)); 3627static void unmark_all_dies PARAMS ((dw_die_ref)); 3628static unsigned long size_of_pubnames PARAMS ((void)); 3629static unsigned long size_of_aranges PARAMS ((void)); 3630static enum dwarf_form value_format PARAMS ((dw_attr_ref)); 3631static void output_value_format PARAMS ((dw_attr_ref)); 3632static void output_abbrev_section PARAMS ((void)); 3633static void output_die_symbol PARAMS ((dw_die_ref)); 3634static void output_die PARAMS ((dw_die_ref)); 3635static void output_compilation_unit_header PARAMS ((void)); 3636static void output_comp_unit PARAMS ((dw_die_ref, int)); 3637static const char *dwarf2_name PARAMS ((tree, int)); 3638static void add_pubname PARAMS ((tree, dw_die_ref)); 3639static void output_pubnames PARAMS ((void)); 3640static void add_arange PARAMS ((tree, dw_die_ref)); 3641static void output_aranges PARAMS ((void)); 3642static unsigned int add_ranges PARAMS ((tree)); 3643static void output_ranges PARAMS ((void)); 3644static void output_line_info PARAMS ((void)); 3645static void output_file_names PARAMS ((void)); 3646static dw_die_ref base_type_die PARAMS ((tree)); 3647static tree root_type PARAMS ((tree)); 3648static int is_base_type PARAMS ((tree)); 3649static dw_die_ref modified_type_die PARAMS ((tree, int, int, dw_die_ref)); 3650static int type_is_enum PARAMS ((tree)); 3651static unsigned int reg_number PARAMS ((rtx)); 3652static dw_loc_descr_ref reg_loc_descriptor PARAMS ((rtx)); 3653static dw_loc_descr_ref int_loc_descriptor PARAMS ((HOST_WIDE_INT)); 3654static dw_loc_descr_ref based_loc_descr PARAMS ((unsigned, long)); 3655static int is_based_loc PARAMS ((rtx)); 3656static dw_loc_descr_ref mem_loc_descriptor PARAMS ((rtx, enum machine_mode mode)); 3657static dw_loc_descr_ref concat_loc_descriptor PARAMS ((rtx, rtx)); 3658static dw_loc_descr_ref loc_descriptor PARAMS ((rtx)); 3659static dw_loc_descr_ref loc_descriptor_from_tree PARAMS ((tree, int)); 3660static HOST_WIDE_INT ceiling PARAMS ((HOST_WIDE_INT, unsigned int)); 3661static tree field_type PARAMS ((tree)); 3662static unsigned int simple_type_align_in_bits PARAMS ((tree)); 3663static unsigned int simple_decl_align_in_bits PARAMS ((tree)); 3664static unsigned HOST_WIDE_INT simple_type_size_in_bits PARAMS ((tree)); 3665static HOST_WIDE_INT field_byte_offset PARAMS ((tree)); 3666static void add_AT_location_description PARAMS ((dw_die_ref, 3667 enum dwarf_attribute, 3668 dw_loc_descr_ref)); 3669static void add_data_member_location_attribute PARAMS ((dw_die_ref, tree)); 3670static void add_const_value_attribute PARAMS ((dw_die_ref, rtx)); 3671static rtx rtl_for_decl_location PARAMS ((tree)); 3672static void add_location_or_const_value_attribute PARAMS ((dw_die_ref, tree)); 3673static void tree_add_const_value_attribute PARAMS ((dw_die_ref, tree)); 3674static void add_name_attribute PARAMS ((dw_die_ref, const char *)); 3675static void add_bound_info PARAMS ((dw_die_ref, 3676 enum dwarf_attribute, tree)); 3677static void add_subscript_info PARAMS ((dw_die_ref, tree)); 3678static void add_byte_size_attribute PARAMS ((dw_die_ref, tree)); 3679static void add_bit_offset_attribute PARAMS ((dw_die_ref, tree)); 3680static void add_bit_size_attribute PARAMS ((dw_die_ref, tree)); 3681static void add_prototyped_attribute PARAMS ((dw_die_ref, tree)); 3682static void add_abstract_origin_attribute PARAMS ((dw_die_ref, tree)); 3683static void add_pure_or_virtual_attribute PARAMS ((dw_die_ref, tree)); 3684static void add_src_coords_attributes PARAMS ((dw_die_ref, tree)); 3685static void add_name_and_src_coords_attributes PARAMS ((dw_die_ref, tree)); 3686static void push_decl_scope PARAMS ((tree)); 3687static void pop_decl_scope PARAMS ((void)); 3688static dw_die_ref scope_die_for PARAMS ((tree, dw_die_ref)); 3689static inline int local_scope_p PARAMS ((dw_die_ref)); 3690static inline int class_scope_p PARAMS ((dw_die_ref)); 3691static void add_type_attribute PARAMS ((dw_die_ref, tree, int, int, 3692 dw_die_ref)); 3693static const char *type_tag PARAMS ((tree)); 3694static tree member_declared_type PARAMS ((tree)); 3695#if 0 3696static const char *decl_start_label PARAMS ((tree)); 3697#endif 3698static void gen_array_type_die PARAMS ((tree, dw_die_ref)); 3699static void gen_set_type_die PARAMS ((tree, dw_die_ref)); 3700#if 0 3701static void gen_entry_point_die PARAMS ((tree, dw_die_ref)); 3702#endif 3703static void gen_inlined_enumeration_type_die PARAMS ((tree, dw_die_ref)); 3704static void gen_inlined_structure_type_die PARAMS ((tree, dw_die_ref)); 3705static void gen_inlined_union_type_die PARAMS ((tree, dw_die_ref)); 3706static void gen_enumeration_type_die PARAMS ((tree, dw_die_ref)); 3707static dw_die_ref gen_formal_parameter_die PARAMS ((tree, dw_die_ref)); 3708static void gen_unspecified_parameters_die PARAMS ((tree, dw_die_ref)); 3709static void gen_formal_types_die PARAMS ((tree, dw_die_ref)); 3710static void gen_subprogram_die PARAMS ((tree, dw_die_ref)); 3711static void gen_variable_die PARAMS ((tree, dw_die_ref)); 3712static void gen_label_die PARAMS ((tree, dw_die_ref)); 3713static void gen_lexical_block_die PARAMS ((tree, dw_die_ref, int)); 3714static void gen_inlined_subroutine_die PARAMS ((tree, dw_die_ref, int)); 3715static void gen_field_die PARAMS ((tree, dw_die_ref)); 3716static void gen_ptr_to_mbr_type_die PARAMS ((tree, dw_die_ref)); 3717static dw_die_ref gen_compile_unit_die PARAMS ((const char *)); 3718static void gen_string_type_die PARAMS ((tree, dw_die_ref)); 3719static void gen_inheritance_die PARAMS ((tree, dw_die_ref)); 3720static void gen_member_die PARAMS ((tree, dw_die_ref)); 3721static void gen_struct_or_union_type_die PARAMS ((tree, dw_die_ref)); 3722static void gen_subroutine_type_die PARAMS ((tree, dw_die_ref)); 3723static void gen_typedef_die PARAMS ((tree, dw_die_ref)); 3724static void gen_type_die PARAMS ((tree, dw_die_ref)); 3725static void gen_tagged_type_instantiation_die PARAMS ((tree, dw_die_ref)); 3726static void gen_block_die PARAMS ((tree, dw_die_ref, int)); 3727static void decls_for_scope PARAMS ((tree, dw_die_ref, int)); 3728static int is_redundant_typedef PARAMS ((tree)); 3729static void gen_decl_die PARAMS ((tree, dw_die_ref)); 3730static unsigned lookup_filename PARAMS ((const char *)); 3731static void init_file_table PARAMS ((void)); 3732static void retry_incomplete_types PARAMS ((void)); 3733static void gen_type_die_for_member PARAMS ((tree, tree, dw_die_ref)); 3734static void splice_child_die PARAMS ((dw_die_ref, dw_die_ref)); 3735static int file_info_cmp PARAMS ((const void *, const void *)); 3736static dw_loc_list_ref new_loc_list PARAMS ((dw_loc_descr_ref, 3737 const char *, const char *, 3738 const char *, unsigned)); 3739static void add_loc_descr_to_loc_list PARAMS ((dw_loc_list_ref *, 3740 dw_loc_descr_ref, 3741 const char *, const char *, const char *)); 3742static void output_loc_list PARAMS ((dw_loc_list_ref)); 3743static char *gen_internal_sym PARAMS ((const char *)); 3744static void mark_limbo_die_list PARAMS ((void *)); 3745 3746/* Section names used to hold DWARF debugging information. */ 3747#ifndef DEBUG_INFO_SECTION 3748#define DEBUG_INFO_SECTION ".debug_info" 3749#endif 3750#ifndef DEBUG_ABBREV_SECTION 3751#define DEBUG_ABBREV_SECTION ".debug_abbrev" 3752#endif 3753#ifndef DEBUG_ARANGES_SECTION 3754#define DEBUG_ARANGES_SECTION ".debug_aranges" 3755#endif 3756#ifndef DEBUG_MACINFO_SECTION 3757#define DEBUG_MACINFO_SECTION ".debug_macinfo" 3758#endif 3759#ifndef DEBUG_LINE_SECTION 3760#define DEBUG_LINE_SECTION ".debug_line" 3761#endif 3762#ifndef DEBUG_LOC_SECTION 3763#define DEBUG_LOC_SECTION ".debug_loc" 3764#endif 3765#ifndef DEBUG_PUBNAMES_SECTION 3766#define DEBUG_PUBNAMES_SECTION ".debug_pubnames" 3767#endif 3768#ifndef DEBUG_STR_SECTION 3769#define DEBUG_STR_SECTION ".debug_str" 3770#endif 3771#ifndef DEBUG_RANGES_SECTION 3772#define DEBUG_RANGES_SECTION ".debug_ranges" 3773#endif 3774 3775/* Standard ELF section names for compiled code and data. */ 3776#ifndef TEXT_SECTION_NAME 3777#define TEXT_SECTION_NAME ".text" 3778#endif 3779 3780/* Section flags for .debug_str section. */ 3781#ifdef HAVE_GAS_SHF_MERGE 3782#define DEBUG_STR_SECTION_FLAGS \ 3783 (SECTION_DEBUG | SECTION_MERGE | SECTION_STRINGS | 1) 3784#else 3785#define DEBUG_STR_SECTION_FLAGS SECTION_DEBUG 3786#endif 3787 3788/* Labels we insert at beginning sections we can reference instead of 3789 the section names themselves. */ 3790 3791#ifndef TEXT_SECTION_LABEL 3792#define TEXT_SECTION_LABEL "Ltext" 3793#endif 3794#ifndef DEBUG_LINE_SECTION_LABEL 3795#define DEBUG_LINE_SECTION_LABEL "Ldebug_line" 3796#endif 3797#ifndef DEBUG_INFO_SECTION_LABEL 3798#define DEBUG_INFO_SECTION_LABEL "Ldebug_info" 3799#endif 3800#ifndef DEBUG_ABBREV_SECTION_LABEL 3801#define DEBUG_ABBREV_SECTION_LABEL "Ldebug_abbrev" 3802#endif 3803#ifndef DEBUG_LOC_SECTION_LABEL 3804#define DEBUG_LOC_SECTION_LABEL "Ldebug_loc" 3805#endif 3806#ifndef DEBUG_RANGES_SECTION_LABEL 3807#define DEBUG_RANGES_SECTION_LABEL "Ldebug_ranges" 3808#endif 3809#ifndef DEBUG_MACINFO_SECTION_LABEL 3810#define DEBUG_MACINFO_SECTION_LABEL "Ldebug_macinfo" 3811#endif 3812 3813/* Definitions of defaults for formats and names of various special 3814 (artificial) labels which may be generated within this file (when the -g 3815 options is used and DWARF_DEBUGGING_INFO is in effect. 3816 If necessary, these may be overridden from within the tm.h file, but 3817 typically, overriding these defaults is unnecessary. */ 3818 3819static char text_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3820static char text_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3821static char abbrev_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3822static char debug_info_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3823static char debug_line_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3824static char macinfo_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3825static char loc_section_label[MAX_ARTIFICIAL_LABEL_BYTES]; 3826static char ranges_section_label[2 * MAX_ARTIFICIAL_LABEL_BYTES]; 3827 3828#ifndef TEXT_END_LABEL 3829#define TEXT_END_LABEL "Letext" 3830#endif 3831#ifndef BLOCK_BEGIN_LABEL 3832#define BLOCK_BEGIN_LABEL "LBB" 3833#endif 3834#ifndef BLOCK_END_LABEL 3835#define BLOCK_END_LABEL "LBE" 3836#endif 3837#ifndef LINE_CODE_LABEL 3838#define LINE_CODE_LABEL "LM" 3839#endif 3840#ifndef SEPARATE_LINE_CODE_LABEL 3841#define SEPARATE_LINE_CODE_LABEL "LSM" 3842#endif 3843 3844/* We allow a language front-end to designate a function that is to be 3845 called to "demangle" any name before it it put into a DIE. */ 3846 3847static const char *(*demangle_name_func) PARAMS ((const char *)); 3848 3849void 3850dwarf2out_set_demangle_name_func (func) 3851 const char *(*func) PARAMS ((const char *)); 3852{ 3853 demangle_name_func = func; 3854} 3855 3856/* Test if rtl node points to a pseudo register. */ 3857 3858static inline int 3859is_pseudo_reg (rtl) 3860 rtx rtl; 3861{ 3862 return ((GET_CODE (rtl) == REG && REGNO (rtl) >= FIRST_PSEUDO_REGISTER) 3863 || (GET_CODE (rtl) == SUBREG 3864 && REGNO (SUBREG_REG (rtl)) >= FIRST_PSEUDO_REGISTER)); 3865} 3866 3867/* Return a reference to a type, with its const and volatile qualifiers 3868 removed. */ 3869 3870static inline tree 3871type_main_variant (type) 3872 tree type; 3873{ 3874 type = TYPE_MAIN_VARIANT (type); 3875 3876 /* ??? There really should be only one main variant among any group of 3877 variants of a given type (and all of the MAIN_VARIANT values for all 3878 members of the group should point to that one type) but sometimes the C 3879 front-end messes this up for array types, so we work around that bug 3880 here. */ 3881 if (TREE_CODE (type) == ARRAY_TYPE) 3882 while (type != TYPE_MAIN_VARIANT (type)) 3883 type = TYPE_MAIN_VARIANT (type); 3884 3885 return type; 3886} 3887 3888/* Return nonzero if the given type node represents a tagged type. */ 3889 3890static inline int 3891is_tagged_type (type) 3892 tree type; 3893{ 3894 enum tree_code code = TREE_CODE (type); 3895 3896 return (code == RECORD_TYPE || code == UNION_TYPE 3897 || code == QUAL_UNION_TYPE || code == ENUMERAL_TYPE); 3898} 3899 3900/* Convert a DIE tag into its string name. */ 3901 3902static const char * 3903dwarf_tag_name (tag) 3904 unsigned tag; 3905{ 3906 switch (tag) 3907 { 3908 case DW_TAG_padding: 3909 return "DW_TAG_padding"; 3910 case DW_TAG_array_type: 3911 return "DW_TAG_array_type"; 3912 case DW_TAG_class_type: 3913 return "DW_TAG_class_type"; 3914 case DW_TAG_entry_point: 3915 return "DW_TAG_entry_point"; 3916 case DW_TAG_enumeration_type: 3917 return "DW_TAG_enumeration_type"; 3918 case DW_TAG_formal_parameter: 3919 return "DW_TAG_formal_parameter"; 3920 case DW_TAG_imported_declaration: 3921 return "DW_TAG_imported_declaration"; 3922 case DW_TAG_label: 3923 return "DW_TAG_label"; 3924 case DW_TAG_lexical_block: 3925 return "DW_TAG_lexical_block"; 3926 case DW_TAG_member: 3927 return "DW_TAG_member"; 3928 case DW_TAG_pointer_type: 3929 return "DW_TAG_pointer_type"; 3930 case DW_TAG_reference_type: 3931 return "DW_TAG_reference_type"; 3932 case DW_TAG_compile_unit: 3933 return "DW_TAG_compile_unit"; 3934 case DW_TAG_string_type: 3935 return "DW_TAG_string_type"; 3936 case DW_TAG_structure_type: 3937 return "DW_TAG_structure_type"; 3938 case DW_TAG_subroutine_type: 3939 return "DW_TAG_subroutine_type"; 3940 case DW_TAG_typedef: 3941 return "DW_TAG_typedef"; 3942 case DW_TAG_union_type: 3943 return "DW_TAG_union_type"; 3944 case DW_TAG_unspecified_parameters: 3945 return "DW_TAG_unspecified_parameters"; 3946 case DW_TAG_variant: 3947 return "DW_TAG_variant"; 3948 case DW_TAG_common_block: 3949 return "DW_TAG_common_block"; 3950 case DW_TAG_common_inclusion: 3951 return "DW_TAG_common_inclusion"; 3952 case DW_TAG_inheritance: 3953 return "DW_TAG_inheritance"; 3954 case DW_TAG_inlined_subroutine: 3955 return "DW_TAG_inlined_subroutine"; 3956 case DW_TAG_module: 3957 return "DW_TAG_module"; 3958 case DW_TAG_ptr_to_member_type: 3959 return "DW_TAG_ptr_to_member_type"; 3960 case DW_TAG_set_type: 3961 return "DW_TAG_set_type"; 3962 case DW_TAG_subrange_type: 3963 return "DW_TAG_subrange_type"; 3964 case DW_TAG_with_stmt: 3965 return "DW_TAG_with_stmt"; 3966 case DW_TAG_access_declaration: 3967 return "DW_TAG_access_declaration"; 3968 case DW_TAG_base_type: 3969 return "DW_TAG_base_type"; 3970 case DW_TAG_catch_block: 3971 return "DW_TAG_catch_block"; 3972 case DW_TAG_const_type: 3973 return "DW_TAG_const_type"; 3974 case DW_TAG_constant: 3975 return "DW_TAG_constant"; 3976 case DW_TAG_enumerator: 3977 return "DW_TAG_enumerator"; 3978 case DW_TAG_file_type: 3979 return "DW_TAG_file_type"; 3980 case DW_TAG_friend: 3981 return "DW_TAG_friend"; 3982 case DW_TAG_namelist: 3983 return "DW_TAG_namelist"; 3984 case DW_TAG_namelist_item: 3985 return "DW_TAG_namelist_item"; 3986 case DW_TAG_packed_type: 3987 return "DW_TAG_packed_type"; 3988 case DW_TAG_subprogram: 3989 return "DW_TAG_subprogram"; 3990 case DW_TAG_template_type_param: 3991 return "DW_TAG_template_type_param"; 3992 case DW_TAG_template_value_param: 3993 return "DW_TAG_template_value_param"; 3994 case DW_TAG_thrown_type: 3995 return "DW_TAG_thrown_type"; 3996 case DW_TAG_try_block: 3997 return "DW_TAG_try_block"; 3998 case DW_TAG_variant_part: 3999 return "DW_TAG_variant_part"; 4000 case DW_TAG_variable: 4001 return "DW_TAG_variable"; 4002 case DW_TAG_volatile_type: 4003 return "DW_TAG_volatile_type"; 4004 case DW_TAG_MIPS_loop: 4005 return "DW_TAG_MIPS_loop"; 4006 case DW_TAG_format_label: 4007 return "DW_TAG_format_label"; 4008 case DW_TAG_function_template: 4009 return "DW_TAG_function_template"; 4010 case DW_TAG_class_template: 4011 return "DW_TAG_class_template"; 4012 case DW_TAG_GNU_BINCL: 4013 return "DW_TAG_GNU_BINCL"; 4014 case DW_TAG_GNU_EINCL: 4015 return "DW_TAG_GNU_EINCL"; 4016 default: 4017 return "DW_TAG_<unknown>"; 4018 } 4019} 4020 4021/* Convert a DWARF attribute code into its string name. */ 4022 4023static const char * 4024dwarf_attr_name (attr) 4025 unsigned attr; 4026{ 4027 switch (attr) 4028 { 4029 case DW_AT_sibling: 4030 return "DW_AT_sibling"; 4031 case DW_AT_location: 4032 return "DW_AT_location"; 4033 case DW_AT_name: 4034 return "DW_AT_name"; 4035 case DW_AT_ordering: 4036 return "DW_AT_ordering"; 4037 case DW_AT_subscr_data: 4038 return "DW_AT_subscr_data"; 4039 case DW_AT_byte_size: 4040 return "DW_AT_byte_size"; 4041 case DW_AT_bit_offset: 4042 return "DW_AT_bit_offset"; 4043 case DW_AT_bit_size: 4044 return "DW_AT_bit_size"; 4045 case DW_AT_element_list: 4046 return "DW_AT_element_list"; 4047 case DW_AT_stmt_list: 4048 return "DW_AT_stmt_list"; 4049 case DW_AT_low_pc: 4050 return "DW_AT_low_pc"; 4051 case DW_AT_high_pc: 4052 return "DW_AT_high_pc"; 4053 case DW_AT_language: 4054 return "DW_AT_language"; 4055 case DW_AT_member: 4056 return "DW_AT_member"; 4057 case DW_AT_discr: 4058 return "DW_AT_discr"; 4059 case DW_AT_discr_value: 4060 return "DW_AT_discr_value"; 4061 case DW_AT_visibility: 4062 return "DW_AT_visibility"; 4063 case DW_AT_import: 4064 return "DW_AT_import"; 4065 case DW_AT_string_length: 4066 return "DW_AT_string_length"; 4067 case DW_AT_common_reference: 4068 return "DW_AT_common_reference"; 4069 case DW_AT_comp_dir: 4070 return "DW_AT_comp_dir"; 4071 case DW_AT_const_value: 4072 return "DW_AT_const_value"; 4073 case DW_AT_containing_type: 4074 return "DW_AT_containing_type"; 4075 case DW_AT_default_value: 4076 return "DW_AT_default_value"; 4077 case DW_AT_inline: 4078 return "DW_AT_inline"; 4079 case DW_AT_is_optional: 4080 return "DW_AT_is_optional"; 4081 case DW_AT_lower_bound: 4082 return "DW_AT_lower_bound"; 4083 case DW_AT_producer: 4084 return "DW_AT_producer"; 4085 case DW_AT_prototyped: 4086 return "DW_AT_prototyped"; 4087 case DW_AT_return_addr: 4088 return "DW_AT_return_addr"; 4089 case DW_AT_start_scope: 4090 return "DW_AT_start_scope"; 4091 case DW_AT_stride_size: 4092 return "DW_AT_stride_size"; 4093 case DW_AT_upper_bound: 4094 return "DW_AT_upper_bound"; 4095 case DW_AT_abstract_origin: 4096 return "DW_AT_abstract_origin"; 4097 case DW_AT_accessibility: 4098 return "DW_AT_accessibility"; 4099 case DW_AT_address_class: 4100 return "DW_AT_address_class"; 4101 case DW_AT_artificial: 4102 return "DW_AT_artificial"; 4103 case DW_AT_base_types: 4104 return "DW_AT_base_types"; 4105 case DW_AT_calling_convention: 4106 return "DW_AT_calling_convention"; 4107 case DW_AT_count: 4108 return "DW_AT_count"; 4109 case DW_AT_data_member_location: 4110 return "DW_AT_data_member_location"; 4111 case DW_AT_decl_column: 4112 return "DW_AT_decl_column"; 4113 case DW_AT_decl_file: 4114 return "DW_AT_decl_file"; 4115 case DW_AT_decl_line: 4116 return "DW_AT_decl_line"; 4117 case DW_AT_declaration: 4118 return "DW_AT_declaration"; 4119 case DW_AT_discr_list: 4120 return "DW_AT_discr_list"; 4121 case DW_AT_encoding: 4122 return "DW_AT_encoding"; 4123 case DW_AT_external: 4124 return "DW_AT_external"; 4125 case DW_AT_frame_base: 4126 return "DW_AT_frame_base"; 4127 case DW_AT_friend: 4128 return "DW_AT_friend"; 4129 case DW_AT_identifier_case: 4130 return "DW_AT_identifier_case"; 4131 case DW_AT_macro_info: 4132 return "DW_AT_macro_info"; 4133 case DW_AT_namelist_items: 4134 return "DW_AT_namelist_items"; 4135 case DW_AT_priority: 4136 return "DW_AT_priority"; 4137 case DW_AT_segment: 4138 return "DW_AT_segment"; 4139 case DW_AT_specification: 4140 return "DW_AT_specification"; 4141 case DW_AT_static_link: 4142 return "DW_AT_static_link"; 4143 case DW_AT_type: 4144 return "DW_AT_type"; 4145 case DW_AT_use_location: 4146 return "DW_AT_use_location"; 4147 case DW_AT_variable_parameter: 4148 return "DW_AT_variable_parameter"; 4149 case DW_AT_virtuality: 4150 return "DW_AT_virtuality"; 4151 case DW_AT_vtable_elem_location: 4152 return "DW_AT_vtable_elem_location"; 4153 4154 case DW_AT_allocated: 4155 return "DW_AT_allocated"; 4156 case DW_AT_associated: 4157 return "DW_AT_associated"; 4158 case DW_AT_data_location: 4159 return "DW_AT_data_location"; 4160 case DW_AT_stride: 4161 return "DW_AT_stride"; 4162 case DW_AT_entry_pc: 4163 return "DW_AT_entry_pc"; 4164 case DW_AT_use_UTF8: 4165 return "DW_AT_use_UTF8"; 4166 case DW_AT_extension: 4167 return "DW_AT_extension"; 4168 case DW_AT_ranges: 4169 return "DW_AT_ranges"; 4170 case DW_AT_trampoline: 4171 return "DW_AT_trampoline"; 4172 case DW_AT_call_column: 4173 return "DW_AT_call_column"; 4174 case DW_AT_call_file: 4175 return "DW_AT_call_file"; 4176 case DW_AT_call_line: 4177 return "DW_AT_call_line"; 4178 4179 case DW_AT_MIPS_fde: 4180 return "DW_AT_MIPS_fde"; 4181 case DW_AT_MIPS_loop_begin: 4182 return "DW_AT_MIPS_loop_begin"; 4183 case DW_AT_MIPS_tail_loop_begin: 4184 return "DW_AT_MIPS_tail_loop_begin"; 4185 case DW_AT_MIPS_epilog_begin: 4186 return "DW_AT_MIPS_epilog_begin"; 4187 case DW_AT_MIPS_loop_unroll_factor: 4188 return "DW_AT_MIPS_loop_unroll_factor"; 4189 case DW_AT_MIPS_software_pipeline_depth: 4190 return "DW_AT_MIPS_software_pipeline_depth"; 4191 case DW_AT_MIPS_linkage_name: 4192 return "DW_AT_MIPS_linkage_name"; 4193 case DW_AT_MIPS_stride: 4194 return "DW_AT_MIPS_stride"; 4195 case DW_AT_MIPS_abstract_name: 4196 return "DW_AT_MIPS_abstract_name"; 4197 case DW_AT_MIPS_clone_origin: 4198 return "DW_AT_MIPS_clone_origin"; 4199 case DW_AT_MIPS_has_inlines: 4200 return "DW_AT_MIPS_has_inlines"; 4201 4202 case DW_AT_sf_names: 4203 return "DW_AT_sf_names"; 4204 case DW_AT_src_info: 4205 return "DW_AT_src_info"; 4206 case DW_AT_mac_info: 4207 return "DW_AT_mac_info"; 4208 case DW_AT_src_coords: 4209 return "DW_AT_src_coords"; 4210 case DW_AT_body_begin: 4211 return "DW_AT_body_begin"; 4212 case DW_AT_body_end: 4213 return "DW_AT_body_end"; 4214 case DW_AT_GNU_vector: 4215 return "DW_AT_GNU_vector"; 4216 4217 case DW_AT_VMS_rtnbeg_pd_address: 4218 return "DW_AT_VMS_rtnbeg_pd_address"; 4219 4220 default: 4221 return "DW_AT_<unknown>"; 4222 } 4223} 4224 4225/* Convert a DWARF value form code into its string name. */ 4226 4227static const char * 4228dwarf_form_name (form) 4229 unsigned form; 4230{ 4231 switch (form) 4232 { 4233 case DW_FORM_addr: 4234 return "DW_FORM_addr"; 4235 case DW_FORM_block2: 4236 return "DW_FORM_block2"; 4237 case DW_FORM_block4: 4238 return "DW_FORM_block4"; 4239 case DW_FORM_data2: 4240 return "DW_FORM_data2"; 4241 case DW_FORM_data4: 4242 return "DW_FORM_data4"; 4243 case DW_FORM_data8: 4244 return "DW_FORM_data8"; 4245 case DW_FORM_string: 4246 return "DW_FORM_string"; 4247 case DW_FORM_block: 4248 return "DW_FORM_block"; 4249 case DW_FORM_block1: 4250 return "DW_FORM_block1"; 4251 case DW_FORM_data1: 4252 return "DW_FORM_data1"; 4253 case DW_FORM_flag: 4254 return "DW_FORM_flag"; 4255 case DW_FORM_sdata: 4256 return "DW_FORM_sdata"; 4257 case DW_FORM_strp: 4258 return "DW_FORM_strp"; 4259 case DW_FORM_udata: 4260 return "DW_FORM_udata"; 4261 case DW_FORM_ref_addr: 4262 return "DW_FORM_ref_addr"; 4263 case DW_FORM_ref1: 4264 return "DW_FORM_ref1"; 4265 case DW_FORM_ref2: 4266 return "DW_FORM_ref2"; 4267 case DW_FORM_ref4: 4268 return "DW_FORM_ref4"; 4269 case DW_FORM_ref8: 4270 return "DW_FORM_ref8"; 4271 case DW_FORM_ref_udata: 4272 return "DW_FORM_ref_udata"; 4273 case DW_FORM_indirect: 4274 return "DW_FORM_indirect"; 4275 default: 4276 return "DW_FORM_<unknown>"; 4277 } 4278} 4279 4280/* Convert a DWARF type code into its string name. */ 4281 4282#if 0 4283static const char * 4284dwarf_type_encoding_name (enc) 4285 unsigned enc; 4286{ 4287 switch (enc) 4288 { 4289 case DW_ATE_address: 4290 return "DW_ATE_address"; 4291 case DW_ATE_boolean: 4292 return "DW_ATE_boolean"; 4293 case DW_ATE_complex_float: 4294 return "DW_ATE_complex_float"; 4295 case DW_ATE_float: 4296 return "DW_ATE_float"; 4297 case DW_ATE_signed: 4298 return "DW_ATE_signed"; 4299 case DW_ATE_signed_char: 4300 return "DW_ATE_signed_char"; 4301 case DW_ATE_unsigned: 4302 return "DW_ATE_unsigned"; 4303 case DW_ATE_unsigned_char: 4304 return "DW_ATE_unsigned_char"; 4305 default: 4306 return "DW_ATE_<unknown>"; 4307 } 4308} 4309#endif 4310 4311/* Determine the "ultimate origin" of a decl. The decl may be an inlined 4312 instance of an inlined instance of a decl which is local to an inline 4313 function, so we have to trace all of the way back through the origin chain 4314 to find out what sort of node actually served as the original seed for the 4315 given block. */ 4316 4317static tree 4318decl_ultimate_origin (decl) 4319 tree decl; 4320{ 4321 /* output_inline_function sets DECL_ABSTRACT_ORIGIN for all the 4322 nodes in the function to point to themselves; ignore that if 4323 we're trying to output the abstract instance of this function. */ 4324 if (DECL_ABSTRACT (decl) && DECL_ABSTRACT_ORIGIN (decl) == decl) 4325 return NULL_TREE; 4326 4327#ifdef ENABLE_CHECKING 4328 if (DECL_FROM_INLINE (DECL_ORIGIN (decl))) 4329 /* Since the DECL_ABSTRACT_ORIGIN for a DECL is supposed to be the 4330 most distant ancestor, this should never happen. */ 4331 abort (); 4332#endif 4333 4334 return DECL_ABSTRACT_ORIGIN (decl); 4335} 4336 4337/* Determine the "ultimate origin" of a block. The block may be an inlined 4338 instance of an inlined instance of a block which is local to an inline 4339 function, so we have to trace all of the way back through the origin chain 4340 to find out what sort of node actually served as the original seed for the 4341 given block. */ 4342 4343static tree 4344block_ultimate_origin (block) 4345 tree block; 4346{ 4347 tree immediate_origin = BLOCK_ABSTRACT_ORIGIN (block); 4348 4349 /* output_inline_function sets BLOCK_ABSTRACT_ORIGIN for all the 4350 nodes in the function to point to themselves; ignore that if 4351 we're trying to output the abstract instance of this function. */ 4352 if (BLOCK_ABSTRACT (block) && immediate_origin == block) 4353 return NULL_TREE; 4354 4355 if (immediate_origin == NULL_TREE) 4356 return NULL_TREE; 4357 else 4358 { 4359 tree ret_val; 4360 tree lookahead = immediate_origin; 4361 4362 do 4363 { 4364 ret_val = lookahead; 4365 lookahead = (TREE_CODE (ret_val) == BLOCK 4366 ? BLOCK_ABSTRACT_ORIGIN (ret_val) : NULL); 4367 } 4368 while (lookahead != NULL && lookahead != ret_val); 4369 4370 return ret_val; 4371 } 4372} 4373 4374/* Get the class to which DECL belongs, if any. In g++, the DECL_CONTEXT 4375 of a virtual function may refer to a base class, so we check the 'this' 4376 parameter. */ 4377 4378static tree 4379decl_class_context (decl) 4380 tree decl; 4381{ 4382 tree context = NULL_TREE; 4383 4384 if (TREE_CODE (decl) != FUNCTION_DECL || ! DECL_VINDEX (decl)) 4385 context = DECL_CONTEXT (decl); 4386 else 4387 context = TYPE_MAIN_VARIANT 4388 (TREE_TYPE (TREE_VALUE (TYPE_ARG_TYPES (TREE_TYPE (decl))))); 4389 4390 if (context && !TYPE_P (context)) 4391 context = NULL_TREE; 4392 4393 return context; 4394} 4395 4396/* Add an attribute/value pair to a DIE. We build the lists up in reverse 4397 addition order, and correct that in reverse_all_dies. */ 4398 4399static inline void 4400add_dwarf_attr (die, attr) 4401 dw_die_ref die; 4402 dw_attr_ref attr; 4403{ 4404 if (die != NULL && attr != NULL) 4405 { 4406 attr->dw_attr_next = die->die_attr; 4407 die->die_attr = attr; 4408 } 4409} 4410 4411static inline dw_val_class 4412AT_class (a) 4413 dw_attr_ref a; 4414{ 4415 return a->dw_attr_val.val_class; 4416} 4417 4418/* Add a flag value attribute to a DIE. */ 4419 4420static inline void 4421add_AT_flag (die, attr_kind, flag) 4422 dw_die_ref die; 4423 enum dwarf_attribute attr_kind; 4424 unsigned flag; 4425{ 4426 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4427 4428 attr->dw_attr_next = NULL; 4429 attr->dw_attr = attr_kind; 4430 attr->dw_attr_val.val_class = dw_val_class_flag; 4431 attr->dw_attr_val.v.val_flag = flag; 4432 add_dwarf_attr (die, attr); 4433} 4434 4435static inline unsigned 4436AT_flag (a) 4437 dw_attr_ref a; 4438{ 4439 if (a && AT_class (a) == dw_val_class_flag) 4440 return a->dw_attr_val.v.val_flag; 4441 4442 abort (); 4443} 4444 4445/* Add a signed integer attribute value to a DIE. */ 4446 4447static inline void 4448add_AT_int (die, attr_kind, int_val) 4449 dw_die_ref die; 4450 enum dwarf_attribute attr_kind; 4451 long int int_val; 4452{ 4453 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4454 4455 attr->dw_attr_next = NULL; 4456 attr->dw_attr = attr_kind; 4457 attr->dw_attr_val.val_class = dw_val_class_const; 4458 attr->dw_attr_val.v.val_int = int_val; 4459 add_dwarf_attr (die, attr); 4460} 4461 4462static inline long int 4463AT_int (a) 4464 dw_attr_ref a; 4465{ 4466 if (a && AT_class (a) == dw_val_class_const) 4467 return a->dw_attr_val.v.val_int; 4468 4469 abort (); 4470} 4471 4472/* Add an unsigned integer attribute value to a DIE. */ 4473 4474static inline void 4475add_AT_unsigned (die, attr_kind, unsigned_val) 4476 dw_die_ref die; 4477 enum dwarf_attribute attr_kind; 4478 unsigned long unsigned_val; 4479{ 4480 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4481 4482 attr->dw_attr_next = NULL; 4483 attr->dw_attr = attr_kind; 4484 attr->dw_attr_val.val_class = dw_val_class_unsigned_const; 4485 attr->dw_attr_val.v.val_unsigned = unsigned_val; 4486 add_dwarf_attr (die, attr); 4487} 4488 4489static inline unsigned long 4490AT_unsigned (a) 4491 dw_attr_ref a; 4492{ 4493 if (a && AT_class (a) == dw_val_class_unsigned_const) 4494 return a->dw_attr_val.v.val_unsigned; 4495 4496 abort (); 4497} 4498 4499/* Add an unsigned double integer attribute value to a DIE. */ 4500 4501static inline void 4502add_AT_long_long (die, attr_kind, val_hi, val_low) 4503 dw_die_ref die; 4504 enum dwarf_attribute attr_kind; 4505 unsigned long val_hi; 4506 unsigned long val_low; 4507{ 4508 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4509 4510 attr->dw_attr_next = NULL; 4511 attr->dw_attr = attr_kind; 4512 attr->dw_attr_val.val_class = dw_val_class_long_long; 4513 attr->dw_attr_val.v.val_long_long.hi = val_hi; 4514 attr->dw_attr_val.v.val_long_long.low = val_low; 4515 add_dwarf_attr (die, attr); 4516} 4517 4518/* Add a floating point attribute value to a DIE and return it. */ 4519 4520static inline void 4521add_AT_float (die, attr_kind, length, array) 4522 dw_die_ref die; 4523 enum dwarf_attribute attr_kind; 4524 unsigned length; 4525 long *array; 4526{ 4527 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4528 4529 attr->dw_attr_next = NULL; 4530 attr->dw_attr = attr_kind; 4531 attr->dw_attr_val.val_class = dw_val_class_float; 4532 attr->dw_attr_val.v.val_float.length = length; 4533 attr->dw_attr_val.v.val_float.array = array; 4534 add_dwarf_attr (die, attr); 4535} 4536 4537/* Add a string attribute value to a DIE. */ 4538 4539static inline void 4540add_AT_string (die, attr_kind, str) 4541 dw_die_ref die; 4542 enum dwarf_attribute attr_kind; 4543 const char *str; 4544{ 4545 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4546 struct indirect_string_node *node; 4547 4548 if (! debug_str_hash) 4549 { 4550 debug_str_hash = ht_create (10); 4551 debug_str_hash->alloc_node = indirect_string_alloc; 4552 } 4553 4554 node = (struct indirect_string_node *) 4555 ht_lookup (debug_str_hash, (const unsigned char *) str, 4556 strlen (str), HT_ALLOC); 4557 node->refcount++; 4558 4559 attr->dw_attr_next = NULL; 4560 attr->dw_attr = attr_kind; 4561 attr->dw_attr_val.val_class = dw_val_class_str; 4562 attr->dw_attr_val.v.val_str = node; 4563 add_dwarf_attr (die, attr); 4564} 4565 4566static inline const char * 4567AT_string (a) 4568 dw_attr_ref a; 4569{ 4570 if (a && AT_class (a) == dw_val_class_str) 4571 return (const char *) HT_STR (&a->dw_attr_val.v.val_str->id); 4572 4573 abort (); 4574} 4575 4576/* Find out whether a string should be output inline in DIE 4577 or out-of-line in .debug_str section. */ 4578 4579static int 4580AT_string_form (a) 4581 dw_attr_ref a; 4582{ 4583 if (a && AT_class (a) == dw_val_class_str) 4584 { 4585 struct indirect_string_node *node; 4586 unsigned int len; 4587 extern int const_labelno; 4588 char label[32]; 4589 4590 node = a->dw_attr_val.v.val_str; 4591 if (node->form) 4592 return node->form; 4593 4594 len = HT_LEN (&node->id) + 1; 4595 4596 /* If the string is shorter or equal to the size of the reference, it is 4597 always better to put it inline. */ 4598 if (len <= DWARF_OFFSET_SIZE || node->refcount == 0) 4599 return node->form = DW_FORM_string; 4600 4601 /* If we cannot expect the linker to merge strings in .debug_str 4602 section, only put it into .debug_str if it is worth even in this 4603 single module. */ 4604 if ((DEBUG_STR_SECTION_FLAGS & SECTION_MERGE) == 0 4605 && (len - DWARF_OFFSET_SIZE) * node->refcount <= len) 4606 return node->form = DW_FORM_string; 4607 4608 ASM_GENERATE_INTERNAL_LABEL (label, "LC", const_labelno); 4609 ++const_labelno; 4610 node->label = xstrdup (label); 4611 4612 return node->form = DW_FORM_strp; 4613 } 4614 4615 abort (); 4616} 4617 4618/* Add a DIE reference attribute value to a DIE. */ 4619 4620static inline void 4621add_AT_die_ref (die, attr_kind, targ_die) 4622 dw_die_ref die; 4623 enum dwarf_attribute attr_kind; 4624 dw_die_ref targ_die; 4625{ 4626 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4627 4628 attr->dw_attr_next = NULL; 4629 attr->dw_attr = attr_kind; 4630 attr->dw_attr_val.val_class = dw_val_class_die_ref; 4631 attr->dw_attr_val.v.val_die_ref.die = targ_die; 4632 attr->dw_attr_val.v.val_die_ref.external = 0; 4633 add_dwarf_attr (die, attr); 4634} 4635 4636static inline dw_die_ref 4637AT_ref (a) 4638 dw_attr_ref a; 4639{ 4640 if (a && AT_class (a) == dw_val_class_die_ref) 4641 return a->dw_attr_val.v.val_die_ref.die; 4642 4643 abort (); 4644} 4645 4646static inline int 4647AT_ref_external (a) 4648 dw_attr_ref a; 4649{ 4650 if (a && AT_class (a) == dw_val_class_die_ref) 4651 return a->dw_attr_val.v.val_die_ref.external; 4652 4653 return 0; 4654} 4655 4656static inline void 4657set_AT_ref_external (a, i) 4658 dw_attr_ref a; 4659 int i; 4660{ 4661 if (a && AT_class (a) == dw_val_class_die_ref) 4662 a->dw_attr_val.v.val_die_ref.external = i; 4663 else 4664 abort (); 4665} 4666 4667/* Add an FDE reference attribute value to a DIE. */ 4668 4669static inline void 4670add_AT_fde_ref (die, attr_kind, targ_fde) 4671 dw_die_ref die; 4672 enum dwarf_attribute attr_kind; 4673 unsigned targ_fde; 4674{ 4675 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4676 4677 attr->dw_attr_next = NULL; 4678 attr->dw_attr = attr_kind; 4679 attr->dw_attr_val.val_class = dw_val_class_fde_ref; 4680 attr->dw_attr_val.v.val_fde_index = targ_fde; 4681 add_dwarf_attr (die, attr); 4682} 4683 4684/* Add a location description attribute value to a DIE. */ 4685 4686static inline void 4687add_AT_loc (die, attr_kind, loc) 4688 dw_die_ref die; 4689 enum dwarf_attribute attr_kind; 4690 dw_loc_descr_ref loc; 4691{ 4692 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4693 4694 attr->dw_attr_next = NULL; 4695 attr->dw_attr = attr_kind; 4696 attr->dw_attr_val.val_class = dw_val_class_loc; 4697 attr->dw_attr_val.v.val_loc = loc; 4698 add_dwarf_attr (die, attr); 4699} 4700 4701static inline dw_loc_descr_ref 4702AT_loc (a) 4703 dw_attr_ref a; 4704{ 4705 if (a && AT_class (a) == dw_val_class_loc) 4706 return a->dw_attr_val.v.val_loc; 4707 4708 abort (); 4709} 4710 4711static inline void 4712add_AT_loc_list (die, attr_kind, loc_list) 4713 dw_die_ref die; 4714 enum dwarf_attribute attr_kind; 4715 dw_loc_list_ref loc_list; 4716{ 4717 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4718 4719 attr->dw_attr_next = NULL; 4720 attr->dw_attr = attr_kind; 4721 attr->dw_attr_val.val_class = dw_val_class_loc_list; 4722 attr->dw_attr_val.v.val_loc_list = loc_list; 4723 add_dwarf_attr (die, attr); 4724 have_location_lists = 1; 4725} 4726 4727static inline dw_loc_list_ref 4728AT_loc_list (a) 4729 dw_attr_ref a; 4730{ 4731 if (a && AT_class (a) == dw_val_class_loc_list) 4732 return a->dw_attr_val.v.val_loc_list; 4733 4734 abort (); 4735} 4736 4737/* Add an address constant attribute value to a DIE. */ 4738 4739static inline void 4740add_AT_addr (die, attr_kind, addr) 4741 dw_die_ref die; 4742 enum dwarf_attribute attr_kind; 4743 rtx addr; 4744{ 4745 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4746 4747 attr->dw_attr_next = NULL; 4748 attr->dw_attr = attr_kind; 4749 attr->dw_attr_val.val_class = dw_val_class_addr; 4750 attr->dw_attr_val.v.val_addr = addr; 4751 add_dwarf_attr (die, attr); 4752} 4753 4754static inline rtx 4755AT_addr (a) 4756 dw_attr_ref a; 4757{ 4758 if (a && AT_class (a) == dw_val_class_addr) 4759 return a->dw_attr_val.v.val_addr; 4760 4761 abort (); 4762} 4763 4764/* Add a label identifier attribute value to a DIE. */ 4765 4766static inline void 4767add_AT_lbl_id (die, attr_kind, lbl_id) 4768 dw_die_ref die; 4769 enum dwarf_attribute attr_kind; 4770 const char *lbl_id; 4771{ 4772 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4773 4774 attr->dw_attr_next = NULL; 4775 attr->dw_attr = attr_kind; 4776 attr->dw_attr_val.val_class = dw_val_class_lbl_id; 4777 attr->dw_attr_val.v.val_lbl_id = xstrdup (lbl_id); 4778 add_dwarf_attr (die, attr); 4779} 4780 4781/* Add a section offset attribute value to a DIE. */ 4782 4783static inline void 4784add_AT_lbl_offset (die, attr_kind, label) 4785 dw_die_ref die; 4786 enum dwarf_attribute attr_kind; 4787 const char *label; 4788{ 4789 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4790 4791 attr->dw_attr_next = NULL; 4792 attr->dw_attr = attr_kind; 4793 attr->dw_attr_val.val_class = dw_val_class_lbl_offset; 4794 attr->dw_attr_val.v.val_lbl_id = xstrdup (label); 4795 add_dwarf_attr (die, attr); 4796} 4797 4798/* Add an offset attribute value to a DIE. */ 4799 4800static inline void 4801add_AT_offset (die, attr_kind, offset) 4802 dw_die_ref die; 4803 enum dwarf_attribute attr_kind; 4804 unsigned long offset; 4805{ 4806 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4807 4808 attr->dw_attr_next = NULL; 4809 attr->dw_attr = attr_kind; 4810 attr->dw_attr_val.val_class = dw_val_class_offset; 4811 attr->dw_attr_val.v.val_offset = offset; 4812 add_dwarf_attr (die, attr); 4813} 4814 4815/* Add an range_list attribute value to a DIE. */ 4816 4817static void 4818add_AT_range_list (die, attr_kind, offset) 4819 dw_die_ref die; 4820 enum dwarf_attribute attr_kind; 4821 unsigned long offset; 4822{ 4823 dw_attr_ref attr = (dw_attr_ref) xmalloc (sizeof (dw_attr_node)); 4824 4825 attr->dw_attr_next = NULL; 4826 attr->dw_attr = attr_kind; 4827 attr->dw_attr_val.val_class = dw_val_class_range_list; 4828 attr->dw_attr_val.v.val_offset = offset; 4829 add_dwarf_attr (die, attr); 4830} 4831 4832static inline const char * 4833AT_lbl (a) 4834 dw_attr_ref a; 4835{ 4836 if (a && (AT_class (a) == dw_val_class_lbl_id 4837 || AT_class (a) == dw_val_class_lbl_offset)) 4838 return a->dw_attr_val.v.val_lbl_id; 4839 4840 abort (); 4841} 4842 4843/* Get the attribute of type attr_kind. */ 4844 4845static inline dw_attr_ref 4846get_AT (die, attr_kind) 4847 dw_die_ref die; 4848 enum dwarf_attribute attr_kind; 4849{ 4850 dw_attr_ref a; 4851 dw_die_ref spec = NULL; 4852 4853 if (die != NULL) 4854 { 4855 for (a = die->die_attr; a != NULL; a = a->dw_attr_next) 4856 if (a->dw_attr == attr_kind) 4857 return a; 4858 else if (a->dw_attr == DW_AT_specification 4859 || a->dw_attr == DW_AT_abstract_origin) 4860 spec = AT_ref (a); 4861 4862 if (spec) 4863 return get_AT (spec, attr_kind); 4864 } 4865 4866 return NULL; 4867} 4868 4869/* Return the "low pc" attribute value, typically associated with a subprogram 4870 DIE. Return null if the "low pc" attribute is either not present, or if it 4871 cannot be represented as an assembler label identifier. */ 4872 4873static inline const char * 4874get_AT_low_pc (die) 4875 dw_die_ref die; 4876{ 4877 dw_attr_ref a = get_AT (die, DW_AT_low_pc); 4878 4879 return a ? AT_lbl (a) : NULL; 4880} 4881 4882/* Return the "high pc" attribute value, typically associated with a subprogram 4883 DIE. Return null if the "high pc" attribute is either not present, or if it 4884 cannot be represented as an assembler label identifier. */ 4885 4886static inline const char * 4887get_AT_hi_pc (die) 4888 dw_die_ref die; 4889{ 4890 dw_attr_ref a = get_AT (die, DW_AT_high_pc); 4891 4892 return a ? AT_lbl (a) : NULL; 4893} 4894 4895/* Return the value of the string attribute designated by ATTR_KIND, or 4896 NULL if it is not present. */ 4897 4898static inline const char * 4899get_AT_string (die, attr_kind) 4900 dw_die_ref die; 4901 enum dwarf_attribute attr_kind; 4902{ 4903 dw_attr_ref a = get_AT (die, attr_kind); 4904 4905 return a ? AT_string (a) : NULL; 4906} 4907 4908/* Return the value of the flag attribute designated by ATTR_KIND, or -1 4909 if it is not present. */ 4910 4911static inline int 4912get_AT_flag (die, attr_kind) 4913 dw_die_ref die; 4914 enum dwarf_attribute attr_kind; 4915{ 4916 dw_attr_ref a = get_AT (die, attr_kind); 4917 4918 return a ? AT_flag (a) : 0; 4919} 4920 4921/* Return the value of the unsigned attribute designated by ATTR_KIND, or 0 4922 if it is not present. */ 4923 4924static inline unsigned 4925get_AT_unsigned (die, attr_kind) 4926 dw_die_ref die; 4927 enum dwarf_attribute attr_kind; 4928{ 4929 dw_attr_ref a = get_AT (die, attr_kind); 4930 4931 return a ? AT_unsigned (a) : 0; 4932} 4933 4934static inline dw_die_ref 4935get_AT_ref (die, attr_kind) 4936 dw_die_ref die; 4937 enum dwarf_attribute attr_kind; 4938{ 4939 dw_attr_ref a = get_AT (die, attr_kind); 4940 4941 return a ? AT_ref (a) : NULL; 4942} 4943 4944static inline int 4945is_c_family () 4946{ 4947 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); 4948 4949 return (lang == DW_LANG_C || lang == DW_LANG_C89 4950 || lang == DW_LANG_C_plus_plus); 4951} 4952 4953static inline int 4954is_cxx () 4955{ 4956 return (get_AT_unsigned (comp_unit_die, DW_AT_language) 4957 == DW_LANG_C_plus_plus); 4958} 4959 4960static inline int 4961is_fortran () 4962{ 4963 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); 4964 4965 return (lang == DW_LANG_Fortran77 || lang == DW_LANG_Fortran90); 4966} 4967 4968static inline int 4969is_java () 4970{ 4971 unsigned lang = get_AT_unsigned (comp_unit_die, DW_AT_language); 4972 4973 return (lang == DW_LANG_Java); 4974} 4975 4976/* Free up the memory used by A. */ 4977 4978static inline void free_AT PARAMS ((dw_attr_ref)); 4979static inline void 4980free_AT (a) 4981 dw_attr_ref a; 4982{ 4983 switch (AT_class (a)) 4984 { 4985 case dw_val_class_str: 4986 if (a->dw_attr_val.v.val_str->refcount) 4987 a->dw_attr_val.v.val_str->refcount--; 4988 break; 4989 4990 case dw_val_class_lbl_id: 4991 case dw_val_class_lbl_offset: 4992 free (a->dw_attr_val.v.val_lbl_id); 4993 break; 4994 4995 case dw_val_class_float: 4996 free (a->dw_attr_val.v.val_float.array); 4997 break; 4998 4999 default: 5000 break; 5001 } 5002 5003 free (a); 5004} 5005 5006/* Remove the specified attribute if present. */ 5007 5008static void 5009remove_AT (die, attr_kind) 5010 dw_die_ref die; 5011 enum dwarf_attribute attr_kind; 5012{ 5013 dw_attr_ref *p; 5014 dw_attr_ref removed = NULL; 5015 5016 if (die != NULL) 5017 { 5018 for (p = &(die->die_attr); *p; p = &((*p)->dw_attr_next)) 5019 if ((*p)->dw_attr == attr_kind) 5020 { 5021 removed = *p; 5022 *p = (*p)->dw_attr_next; 5023 break; 5024 } 5025 5026 if (removed != 0) 5027 free_AT (removed); 5028 } 5029} 5030 5031/* Free up the memory used by DIE. */ 5032 5033static inline void 5034free_die (die) 5035 dw_die_ref die; 5036{ 5037 remove_children (die); 5038 free (die); 5039} 5040 5041/* Discard the children of this DIE. */ 5042 5043static void 5044remove_children (die) 5045 dw_die_ref die; 5046{ 5047 dw_die_ref child_die = die->die_child; 5048 5049 die->die_child = NULL; 5050 5051 while (child_die != NULL) 5052 { 5053 dw_die_ref tmp_die = child_die; 5054 dw_attr_ref a; 5055 5056 child_die = child_die->die_sib; 5057 5058 for (a = tmp_die->die_attr; a != NULL;) 5059 { 5060 dw_attr_ref tmp_a = a; 5061 5062 a = a->dw_attr_next; 5063 free_AT (tmp_a); 5064 } 5065 5066 free_die (tmp_die); 5067 } 5068} 5069 5070/* Add a child DIE below its parent. We build the lists up in reverse 5071 addition order, and correct that in reverse_all_dies. */ 5072 5073static inline void 5074add_child_die (die, child_die) 5075 dw_die_ref die; 5076 dw_die_ref child_die; 5077{ 5078 if (die != NULL && child_die != NULL) 5079 { 5080 if (die == child_die) 5081 abort (); 5082 5083 child_die->die_parent = die; 5084 child_die->die_sib = die->die_child; 5085 die->die_child = child_die; 5086 } 5087} 5088 5089/* Move CHILD, which must be a child of PARENT or the DIE for which PARENT 5090 is the specification, to the front of PARENT's list of children. */ 5091 5092static void 5093splice_child_die (parent, child) 5094 dw_die_ref parent, child; 5095{ 5096 dw_die_ref *p; 5097 5098 /* We want the declaration DIE from inside the class, not the 5099 specification DIE at toplevel. */ 5100 if (child->die_parent != parent) 5101 { 5102 dw_die_ref tmp = get_AT_ref (child, DW_AT_specification); 5103 5104 if (tmp) 5105 child = tmp; 5106 } 5107 5108 if (child->die_parent != parent 5109 && child->die_parent != get_AT_ref (parent, DW_AT_specification)) 5110 abort (); 5111 5112 for (p = &(child->die_parent->die_child); *p; p = &((*p)->die_sib)) 5113 if (*p == child) 5114 { 5115 *p = child->die_sib; 5116 break; 5117 } 5118 5119 child->die_sib = parent->die_child; 5120 parent->die_child = child; 5121} 5122 5123/* Return a pointer to a newly created DIE node. */ 5124 5125static inline dw_die_ref 5126new_die (tag_value, parent_die, t) 5127 enum dwarf_tag tag_value; 5128 dw_die_ref parent_die; 5129 tree t; 5130{ 5131 dw_die_ref die = (dw_die_ref) xcalloc (1, sizeof (die_node)); 5132 5133 die->die_tag = tag_value; 5134 5135 if (parent_die != NULL) 5136 add_child_die (parent_die, die); 5137 else 5138 { 5139 limbo_die_node *limbo_node; 5140 5141 limbo_node = (limbo_die_node *) xmalloc (sizeof (limbo_die_node)); 5142 limbo_node->die = die; 5143 limbo_node->created_for = t; 5144 limbo_node->next = limbo_die_list; 5145 limbo_die_list = limbo_node; 5146 } 5147 5148 return die; 5149} 5150 5151/* Return the DIE associated with the given type specifier. */ 5152 5153static inline dw_die_ref 5154lookup_type_die (type) 5155 tree type; 5156{ 5157 return TYPE_SYMTAB_DIE (type); 5158} 5159 5160/* Equate a DIE to a given type specifier. */ 5161 5162static inline void 5163equate_type_number_to_die (type, type_die) 5164 tree type; 5165 dw_die_ref type_die; 5166{ 5167 TYPE_SYMTAB_DIE (type) = type_die; 5168} 5169 5170/* Return the DIE associated with a given declaration. */ 5171 5172static inline dw_die_ref 5173lookup_decl_die (decl) 5174 tree decl; 5175{ 5176 unsigned decl_id = DECL_UID (decl); 5177 5178 return (decl_id < decl_die_table_in_use ? decl_die_table[decl_id] : NULL); 5179} 5180 5181/* Equate a DIE to a particular declaration. */ 5182 5183static void 5184equate_decl_number_to_die (decl, decl_die) 5185 tree decl; 5186 dw_die_ref decl_die; 5187{ 5188 unsigned int decl_id = DECL_UID (decl); 5189 unsigned int num_allocated; 5190 5191 if (decl_id >= decl_die_table_allocated) 5192 { 5193 num_allocated 5194 = ((decl_id + 1 + DECL_DIE_TABLE_INCREMENT - 1) 5195 / DECL_DIE_TABLE_INCREMENT) 5196 * DECL_DIE_TABLE_INCREMENT; 5197 5198 decl_die_table 5199 = (dw_die_ref *) xrealloc (decl_die_table, 5200 sizeof (dw_die_ref) * num_allocated); 5201 5202 memset ((char *) &decl_die_table[decl_die_table_allocated], 0, 5203 (num_allocated - decl_die_table_allocated) * sizeof (dw_die_ref)); 5204 decl_die_table_allocated = num_allocated; 5205 } 5206 5207 if (decl_id >= decl_die_table_in_use) 5208 decl_die_table_in_use = (decl_id + 1); 5209 5210 decl_die_table[decl_id] = decl_die; 5211} 5212 5213/* Keep track of the number of spaces used to indent the 5214 output of the debugging routines that print the structure of 5215 the DIE internal representation. */ 5216static int print_indent; 5217 5218/* Indent the line the number of spaces given by print_indent. */ 5219 5220static inline void 5221print_spaces (outfile) 5222 FILE *outfile; 5223{ 5224 fprintf (outfile, "%*s", print_indent, ""); 5225} 5226 5227/* Print the information associated with a given DIE, and its children. 5228 This routine is a debugging aid only. */ 5229 5230static void 5231print_die (die, outfile) 5232 dw_die_ref die; 5233 FILE *outfile; 5234{ 5235 dw_attr_ref a; 5236 dw_die_ref c; 5237 5238 print_spaces (outfile); 5239 fprintf (outfile, "DIE %4lu: %s\n", 5240 die->die_offset, dwarf_tag_name (die->die_tag)); 5241 print_spaces (outfile); 5242 fprintf (outfile, " abbrev id: %lu", die->die_abbrev); 5243 fprintf (outfile, " offset: %lu\n", die->die_offset); 5244 5245 for (a = die->die_attr; a != NULL; a = a->dw_attr_next) 5246 { 5247 print_spaces (outfile); 5248 fprintf (outfile, " %s: ", dwarf_attr_name (a->dw_attr)); 5249 5250 switch (AT_class (a)) 5251 { 5252 case dw_val_class_addr: 5253 fprintf (outfile, "address"); 5254 break; 5255 case dw_val_class_offset: 5256 fprintf (outfile, "offset"); 5257 break; 5258 case dw_val_class_loc: 5259 fprintf (outfile, "location descriptor"); 5260 break; 5261 case dw_val_class_loc_list: 5262 fprintf (outfile, "location list -> label:%s", 5263 AT_loc_list (a)->ll_symbol); 5264 break; 5265 case dw_val_class_range_list: 5266 fprintf (outfile, "range list"); 5267 break; 5268 case dw_val_class_const: 5269 fprintf (outfile, "%ld", AT_int (a)); 5270 break; 5271 case dw_val_class_unsigned_const: 5272 fprintf (outfile, "%lu", AT_unsigned (a)); 5273 break; 5274 case dw_val_class_long_long: 5275 fprintf (outfile, "constant (%lu,%lu)", 5276 a->dw_attr_val.v.val_long_long.hi, 5277 a->dw_attr_val.v.val_long_long.low); 5278 break; 5279 case dw_val_class_float: 5280 fprintf (outfile, "floating-point constant"); 5281 break; 5282 case dw_val_class_flag: 5283 fprintf (outfile, "%u", AT_flag (a)); 5284 break; 5285 case dw_val_class_die_ref: 5286 if (AT_ref (a) != NULL) 5287 { 5288 if (AT_ref (a)->die_symbol) 5289 fprintf (outfile, "die -> label: %s", AT_ref (a)->die_symbol); 5290 else 5291 fprintf (outfile, "die -> %lu", AT_ref (a)->die_offset); 5292 } 5293 else 5294 fprintf (outfile, "die -> <null>"); 5295 break; 5296 case dw_val_class_lbl_id: 5297 case dw_val_class_lbl_offset: 5298 fprintf (outfile, "label: %s", AT_lbl (a)); 5299 break; 5300 case dw_val_class_str: 5301 if (AT_string (a) != NULL) 5302 fprintf (outfile, "\"%s\"", AT_string (a)); 5303 else 5304 fprintf (outfile, "<null>"); 5305 break; 5306 default: 5307 break; 5308 } 5309 5310 fprintf (outfile, "\n"); 5311 } 5312 5313 if (die->die_child != NULL) 5314 { 5315 print_indent += 4; 5316 for (c = die->die_child; c != NULL; c = c->die_sib) 5317 print_die (c, outfile); 5318 5319 print_indent -= 4; 5320 } 5321 if (print_indent == 0) 5322 fprintf (outfile, "\n"); 5323} 5324 5325/* Print the contents of the source code line number correspondence table. 5326 This routine is a debugging aid only. */ 5327 5328static void 5329print_dwarf_line_table (outfile) 5330 FILE *outfile; 5331{ 5332 unsigned i; 5333 dw_line_info_ref line_info; 5334 5335 fprintf (outfile, "\n\nDWARF source line information\n"); 5336 for (i = 1; i < line_info_table_in_use; i++) 5337 { 5338 line_info = &line_info_table[i]; 5339 fprintf (outfile, "%5d: ", i); 5340 fprintf (outfile, "%-20s", file_table.table[line_info->dw_file_num]); 5341 fprintf (outfile, "%6ld", line_info->dw_line_num); 5342 fprintf (outfile, "\n"); 5343 } 5344 5345 fprintf (outfile, "\n\n"); 5346} 5347 5348/* Print the information collected for a given DIE. */ 5349 5350void 5351debug_dwarf_die (die) 5352 dw_die_ref die; 5353{ 5354 print_die (die, stderr); 5355} 5356 5357/* Print all DWARF information collected for the compilation unit. 5358 This routine is a debugging aid only. */ 5359 5360void 5361debug_dwarf () 5362{ 5363 print_indent = 0; 5364 print_die (comp_unit_die, stderr); 5365 if (! DWARF2_ASM_LINE_DEBUG_INFO) 5366 print_dwarf_line_table (stderr); 5367} 5368 5369/* We build up the lists of children and attributes by pushing new ones 5370 onto the beginning of the list. Reverse the lists for DIE so that 5371 they are in order of addition. */ 5372 5373static void 5374reverse_die_lists (die) 5375 dw_die_ref die; 5376{ 5377 dw_die_ref c, cp, cn; 5378 dw_attr_ref a, ap, an; 5379 5380 for (a = die->die_attr, ap = 0; a; a = an) 5381 { 5382 an = a->dw_attr_next; 5383 a->dw_attr_next = ap; 5384 ap = a; 5385 } 5386 5387 die->die_attr = ap; 5388 5389 for (c = die->die_child, cp = 0; c; c = cn) 5390 { 5391 cn = c->die_sib; 5392 c->die_sib = cp; 5393 cp = c; 5394 } 5395 5396 die->die_child = cp; 5397} 5398 5399/* reverse_die_lists only reverses the single die you pass it. Since we used to 5400 reverse all dies in add_sibling_attributes, which runs through all the dies, 5401 it would reverse all the dies. Now, however, since we don't call 5402 reverse_die_lists in add_sibling_attributes, we need a routine to 5403 recursively reverse all the dies. This is that routine. */ 5404 5405static void 5406reverse_all_dies (die) 5407 dw_die_ref die; 5408{ 5409 dw_die_ref c; 5410 5411 reverse_die_lists (die); 5412 5413 for (c = die->die_child; c; c = c->die_sib) 5414 reverse_all_dies (c); 5415} 5416 5417/* Start a new compilation unit DIE for an include file. OLD_UNIT is the CU 5418 for the enclosing include file, if any. BINCL_DIE is the DW_TAG_GNU_BINCL 5419 DIE that marks the start of the DIEs for this include file. */ 5420 5421static dw_die_ref 5422push_new_compile_unit (old_unit, bincl_die) 5423 dw_die_ref old_unit, bincl_die; 5424{ 5425 const char *filename = get_AT_string (bincl_die, DW_AT_name); 5426 dw_die_ref new_unit = gen_compile_unit_die (filename); 5427 5428 new_unit->die_sib = old_unit; 5429 return new_unit; 5430} 5431 5432/* Close an include-file CU and reopen the enclosing one. */ 5433 5434static dw_die_ref 5435pop_compile_unit (old_unit) 5436 dw_die_ref old_unit; 5437{ 5438 dw_die_ref new_unit = old_unit->die_sib; 5439 5440 old_unit->die_sib = NULL; 5441 return new_unit; 5442} 5443 5444#define CHECKSUM(FOO) md5_process_bytes (&(FOO), sizeof (FOO), ctx) 5445#define CHECKSUM_STRING(FOO) md5_process_bytes ((FOO), strlen (FOO), ctx) 5446 5447/* Calculate the checksum of a location expression. */ 5448 5449static inline void 5450loc_checksum (loc, ctx) 5451 dw_loc_descr_ref loc; 5452 struct md5_ctx *ctx; 5453{ 5454 CHECKSUM (loc->dw_loc_opc); 5455 CHECKSUM (loc->dw_loc_oprnd1); 5456 CHECKSUM (loc->dw_loc_oprnd2); 5457} 5458 5459/* Calculate the checksum of an attribute. */ 5460 5461static void 5462attr_checksum (at, ctx, mark) 5463 dw_attr_ref at; 5464 struct md5_ctx *ctx; 5465 int *mark; 5466{ 5467 dw_loc_descr_ref loc; 5468 rtx r; 5469 5470 CHECKSUM (at->dw_attr); 5471 5472 /* We don't care about differences in file numbering. */ 5473 if (at->dw_attr == DW_AT_decl_file 5474 /* Or that this was compiled with a different compiler snapshot; if 5475 the output is the same, that's what matters. */ 5476 || at->dw_attr == DW_AT_producer) 5477 return; 5478 5479 switch (AT_class (at)) 5480 { 5481 case dw_val_class_const: 5482 CHECKSUM (at->dw_attr_val.v.val_int); 5483 break; 5484 case dw_val_class_unsigned_const: 5485 CHECKSUM (at->dw_attr_val.v.val_unsigned); 5486 break; 5487 case dw_val_class_long_long: 5488 CHECKSUM (at->dw_attr_val.v.val_long_long); 5489 break; 5490 case dw_val_class_float: 5491 CHECKSUM (at->dw_attr_val.v.val_float); 5492 break; 5493 case dw_val_class_flag: 5494 CHECKSUM (at->dw_attr_val.v.val_flag); 5495 break; 5496 case dw_val_class_str: 5497 CHECKSUM_STRING (AT_string (at)); 5498 break; 5499 5500 case dw_val_class_addr: 5501 r = AT_addr (at); 5502 switch (GET_CODE (r)) 5503 { 5504 case SYMBOL_REF: 5505 CHECKSUM_STRING (XSTR (r, 0)); 5506 break; 5507 5508 default: 5509 abort (); 5510 } 5511 break; 5512 5513 case dw_val_class_offset: 5514 CHECKSUM (at->dw_attr_val.v.val_offset); 5515 break; 5516 5517 case dw_val_class_loc: 5518 for (loc = AT_loc (at); loc; loc = loc->dw_loc_next) 5519 loc_checksum (loc, ctx); 5520 break; 5521 5522 case dw_val_class_die_ref: 5523 die_checksum (AT_ref (at), ctx, mark); 5524 break; 5525 5526 case dw_val_class_fde_ref: 5527 case dw_val_class_lbl_id: 5528 case dw_val_class_lbl_offset: 5529 break; 5530 5531 default: 5532 break; 5533 } 5534} 5535 5536/* Calculate the checksum of a DIE. */ 5537 5538static void 5539die_checksum (die, ctx, mark) 5540 dw_die_ref die; 5541 struct md5_ctx *ctx; 5542 int *mark; 5543{ 5544 dw_die_ref c; 5545 dw_attr_ref a; 5546 5547 /* To avoid infinite recursion. */ 5548 if (die->die_mark) 5549 { 5550 CHECKSUM (die->die_mark); 5551 return; 5552 } 5553 die->die_mark = ++(*mark); 5554 5555 CHECKSUM (die->die_tag); 5556 5557 for (a = die->die_attr; a; a = a->dw_attr_next) 5558 attr_checksum (a, ctx, mark); 5559 5560 for (c = die->die_child; c; c = c->die_sib) 5561 die_checksum (c, ctx, mark); 5562} 5563 5564#undef CHECKSUM 5565#undef CHECKSUM_STRING 5566 5567/* Do the location expressions look same? */ 5568static inline int 5569same_loc_p (loc1, loc2, mark) 5570 dw_loc_descr_ref loc1; 5571 dw_loc_descr_ref loc2; 5572 int *mark; 5573{ 5574 return loc1->dw_loc_opc == loc2->dw_loc_opc 5575 && same_dw_val_p (&loc1->dw_loc_oprnd1, &loc2->dw_loc_oprnd1, mark) 5576 && same_dw_val_p (&loc1->dw_loc_oprnd2, &loc2->dw_loc_oprnd2, mark); 5577} 5578 5579/* Do the values look the same? */ 5580static int 5581same_dw_val_p (v1, v2, mark) 5582 dw_val_node *v1; 5583 dw_val_node *v2; 5584 int *mark; 5585{ 5586 dw_loc_descr_ref loc1, loc2; 5587 rtx r1, r2; 5588 unsigned i; 5589 5590 if (v1->val_class != v2->val_class) 5591 return 0; 5592 5593 switch (v1->val_class) 5594 { 5595 case dw_val_class_const: 5596 return v1->v.val_int == v2->v.val_int; 5597 case dw_val_class_unsigned_const: 5598 return v1->v.val_unsigned == v2->v.val_unsigned; 5599 case dw_val_class_long_long: 5600 return v1->v.val_long_long.hi == v2->v.val_long_long.hi 5601 && v1->v.val_long_long.low == v2->v.val_long_long.low; 5602 case dw_val_class_float: 5603 if (v1->v.val_float.length != v2->v.val_float.length) 5604 return 0; 5605 for (i = 0; i < v1->v.val_float.length; i++) 5606 if (v1->v.val_float.array[i] != v2->v.val_float.array[i]) 5607 return 0; 5608 return 1; 5609 case dw_val_class_flag: 5610 return v1->v.val_flag == v2->v.val_flag; 5611 case dw_val_class_str: 5612 return !strcmp((const char *) HT_STR (&v1->v.val_str->id), 5613 (const char *) HT_STR (&v2->v.val_str->id)); 5614 5615 case dw_val_class_addr: 5616 r1 = v1->v.val_addr; 5617 r2 = v2->v.val_addr; 5618 if (GET_CODE (r1) != GET_CODE (r2)) 5619 return 0; 5620 switch (GET_CODE (r1)) 5621 { 5622 case SYMBOL_REF: 5623 return !strcmp (XSTR (r1, 0), XSTR (r2, 0)); 5624 5625 default: 5626 abort (); 5627 } 5628 5629 case dw_val_class_offset: 5630 return v1->v.val_offset == v2->v.val_offset; 5631 5632 case dw_val_class_loc: 5633 for (loc1 = v1->v.val_loc, loc2 = v2->v.val_loc; 5634 loc1 && loc2; 5635 loc1 = loc1->dw_loc_next, loc2 = loc2->dw_loc_next) 5636 if (!same_loc_p (loc1, loc2, mark)) 5637 return 0; 5638 return !loc1 && !loc2; 5639 5640 case dw_val_class_die_ref: 5641 return same_die_p (v1->v.val_die_ref.die, v2->v.val_die_ref.die, mark); 5642 5643 case dw_val_class_fde_ref: 5644 case dw_val_class_lbl_id: 5645 case dw_val_class_lbl_offset: 5646 return 1; 5647 5648 default: 5649 return 1; 5650 } 5651} 5652 5653/* Do the attributes look the same? */ 5654 5655static int 5656same_attr_p (at1, at2, mark) 5657 dw_attr_ref at1; 5658 dw_attr_ref at2; 5659 int *mark; 5660{ 5661 if (at1->dw_attr != at2->dw_attr) 5662 return 0; 5663 5664 /* We don't care about differences in file numbering. */ 5665 if (at1->dw_attr == DW_AT_decl_file 5666 /* Or that this was compiled with a different compiler snapshot; if 5667 the output is the same, that's what matters. */ 5668 || at1->dw_attr == DW_AT_producer) 5669 return 1; 5670 5671 return same_dw_val_p (&at1->dw_attr_val, &at2->dw_attr_val, mark); 5672} 5673 5674/* Do the dies look the same? */ 5675 5676static int 5677same_die_p (die1, die2, mark) 5678 dw_die_ref die1; 5679 dw_die_ref die2; 5680 int *mark; 5681{ 5682 dw_die_ref c1, c2; 5683 dw_attr_ref a1, a2; 5684 5685 /* To avoid infinite recursion. */ 5686 if (die1->die_mark) 5687 return die1->die_mark == die2->die_mark; 5688 die1->die_mark = die2->die_mark = ++(*mark); 5689 5690 if (die1->die_tag != die2->die_tag) 5691 return 0; 5692 5693 for (a1 = die1->die_attr, a2 = die2->die_attr; 5694 a1 && a2; 5695 a1 = a1->dw_attr_next, a2 = a2->dw_attr_next) 5696 if (!same_attr_p (a1, a2, mark)) 5697 return 0; 5698 if (a1 || a2) 5699 return 0; 5700 5701 for (c1 = die1->die_child, c2 = die2->die_child; 5702 c1 && c2; 5703 c1 = c1->die_sib, c2 = c2->die_sib) 5704 if (!same_die_p (c1, c2, mark)) 5705 return 0; 5706 if (c1 || c2) 5707 return 0; 5708 5709 return 1; 5710} 5711 5712/* Do the dies look the same? Wrapper around same_die_p. */ 5713 5714static int 5715same_die_p_wrap (die1, die2) 5716 dw_die_ref die1; 5717 dw_die_ref die2; 5718{ 5719 int mark = 0; 5720 int ret = same_die_p (die1, die2, &mark); 5721 5722 unmark_all_dies (die1); 5723 unmark_all_dies (die2); 5724 5725 return ret; 5726} 5727 5728/* The prefix to attach to symbols on DIEs in the current comdat debug 5729 info section. */ 5730static char *comdat_symbol_id; 5731 5732/* The index of the current symbol within the current comdat CU. */ 5733static unsigned int comdat_symbol_number; 5734 5735/* Calculate the MD5 checksum of the compilation unit DIE UNIT_DIE and its 5736 children, and set comdat_symbol_id accordingly. */ 5737 5738static void 5739compute_section_prefix (unit_die) 5740 dw_die_ref unit_die; 5741{ 5742 const char *die_name = get_AT_string (unit_die, DW_AT_name); 5743 const char *base = die_name ? lbasename (die_name) : "anonymous"; 5744 char *name = (char *) alloca (strlen (base) + 64); 5745 char *p; 5746 int i, mark; 5747 unsigned char checksum[16]; 5748 struct md5_ctx ctx; 5749 5750 /* Compute the checksum of the DIE, then append part of it as hex digits to 5751 the name filename of the unit. */ 5752 5753 md5_init_ctx (&ctx); 5754 mark = 0; 5755 die_checksum (unit_die, &ctx, &mark); 5756 unmark_all_dies (unit_die); 5757 md5_finish_ctx (&ctx, checksum); 5758 5759 sprintf (name, "%s.", base); 5760 clean_symbol_name (name); 5761 5762 p = name + strlen (name); 5763 for (i = 0; i < 4; i++) 5764 { 5765 sprintf (p, "%.2x", checksum[i]); 5766 p += 2; 5767 } 5768 5769 comdat_symbol_id = unit_die->die_symbol = xstrdup (name); 5770 comdat_symbol_number = 0; 5771} 5772 5773/* Returns nonzero if DIE represents a type, in the sense of TYPE_P. */ 5774 5775static int 5776is_type_die (die) 5777 dw_die_ref die; 5778{ 5779 switch (die->die_tag) 5780 { 5781 case DW_TAG_array_type: 5782 case DW_TAG_class_type: 5783 case DW_TAG_enumeration_type: 5784 case DW_TAG_pointer_type: 5785 case DW_TAG_reference_type: 5786 case DW_TAG_string_type: 5787 case DW_TAG_structure_type: 5788 case DW_TAG_subroutine_type: 5789 case DW_TAG_union_type: 5790 case DW_TAG_ptr_to_member_type: 5791 case DW_TAG_set_type: 5792 case DW_TAG_subrange_type: 5793 case DW_TAG_base_type: 5794 case DW_TAG_const_type: 5795 case DW_TAG_file_type: 5796 case DW_TAG_packed_type: 5797 case DW_TAG_volatile_type: 5798 case DW_TAG_typedef: 5799 return 1; 5800 default: 5801 return 0; 5802 } 5803} 5804 5805/* Returns 1 iff C is the sort of DIE that should go into a COMDAT CU. 5806 Basically, we want to choose the bits that are likely to be shared between 5807 compilations (types) and leave out the bits that are specific to individual 5808 compilations (functions). */ 5809 5810static int 5811is_comdat_die (c) 5812 dw_die_ref c; 5813{ 5814 /* I think we want to leave base types and __vtbl_ptr_type in the main CU, as 5815 we do for stabs. The advantage is a greater likelihood of sharing between 5816 objects that don't include headers in the same order (and therefore would 5817 put the base types in a different comdat). jason 8/28/00 */ 5818 5819 if (c->die_tag == DW_TAG_base_type) 5820 return 0; 5821 5822 if (c->die_tag == DW_TAG_pointer_type 5823 || c->die_tag == DW_TAG_reference_type 5824 || c->die_tag == DW_TAG_const_type 5825 || c->die_tag == DW_TAG_volatile_type) 5826 { 5827 dw_die_ref t = get_AT_ref (c, DW_AT_type); 5828 5829 return t ? is_comdat_die (t) : 0; 5830 } 5831 5832 return is_type_die (c); 5833} 5834 5835/* Returns 1 iff C is the sort of DIE that might be referred to from another 5836 compilation unit. */ 5837 5838static int 5839is_symbol_die (c) 5840 dw_die_ref c; 5841{ 5842 return (is_type_die (c) 5843 || (get_AT (c, DW_AT_declaration) 5844 && !get_AT (c, DW_AT_specification))); 5845} 5846 5847static char * 5848gen_internal_sym (prefix) 5849 const char *prefix; 5850{ 5851 char buf[256]; 5852 static int label_num; 5853 5854 ASM_GENERATE_INTERNAL_LABEL (buf, prefix, label_num++); 5855 return xstrdup (buf); 5856} 5857 5858/* Assign symbols to all worthy DIEs under DIE. */ 5859 5860static void 5861assign_symbol_names (die) 5862 dw_die_ref die; 5863{ 5864 dw_die_ref c; 5865 5866 if (is_symbol_die (die)) 5867 { 5868 if (comdat_symbol_id) 5869 { 5870 char *p = alloca (strlen (comdat_symbol_id) + 64); 5871 5872 sprintf (p, "%s.%s.%x", DIE_LABEL_PREFIX, 5873 comdat_symbol_id, comdat_symbol_number++); 5874 die->die_symbol = xstrdup (p); 5875 } 5876 else 5877 die->die_symbol = gen_internal_sym ("LDIE"); 5878 } 5879 5880 for (c = die->die_child; c != NULL; c = c->die_sib) 5881 assign_symbol_names (c); 5882} 5883 5884struct cu_hash_table_entry 5885{ 5886 dw_die_ref cu; 5887 unsigned min_comdat_num, max_comdat_num; 5888 struct cu_hash_table_entry *next; 5889}; 5890 5891/* Routines to manipulate hash table of CUs. */ 5892static hashval_t 5893htab_cu_hash (of) 5894 const void *of; 5895{ 5896 const struct cu_hash_table_entry *entry = of; 5897 5898 return htab_hash_string (entry->cu->die_symbol); 5899} 5900 5901static int 5902htab_cu_eq (of1, of2) 5903 const void *of1; 5904 const void *of2; 5905{ 5906 const struct cu_hash_table_entry *entry1 = of1; 5907 const struct die_struct *entry2 = of2; 5908 5909 return !strcmp (entry1->cu->die_symbol, entry2->die_symbol); 5910} 5911 5912static void 5913htab_cu_del (what) 5914 void *what; 5915{ 5916 struct cu_hash_table_entry *next, *entry = what; 5917 5918 while (entry) 5919 { 5920 next = entry->next; 5921 free (entry); 5922 entry = next; 5923 } 5924} 5925 5926/* Check whether we have already seen this CU and set up SYM_NUM 5927 accordingly. */ 5928static int 5929check_duplicate_cu (cu, htable, sym_num) 5930 dw_die_ref cu; 5931 htab_t htable; 5932 unsigned *sym_num; 5933{ 5934 struct cu_hash_table_entry dummy; 5935 struct cu_hash_table_entry **slot, *entry, *last = &dummy; 5936 5937 dummy.max_comdat_num = 0; 5938 5939 slot = (struct cu_hash_table_entry **) 5940 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), 5941 INSERT); 5942 entry = *slot; 5943 5944 for (; entry; last = entry, entry = entry->next) 5945 { 5946 if (same_die_p_wrap (cu, entry->cu)) 5947 break; 5948 } 5949 5950 if (entry) 5951 { 5952 *sym_num = entry->min_comdat_num; 5953 return 1; 5954 } 5955 5956 entry = xcalloc (1, sizeof (struct cu_hash_table_entry)); 5957 entry->cu = cu; 5958 entry->min_comdat_num = *sym_num = last->max_comdat_num; 5959 entry->next = *slot; 5960 *slot = entry; 5961 5962 return 0; 5963} 5964 5965/* Record SYM_NUM to record of CU in HTABLE. */ 5966static void 5967record_comdat_symbol_number (cu, htable, sym_num) 5968 dw_die_ref cu; 5969 htab_t htable; 5970 unsigned sym_num; 5971{ 5972 struct cu_hash_table_entry **slot, *entry; 5973 5974 slot = (struct cu_hash_table_entry **) 5975 htab_find_slot_with_hash (htable, cu, htab_hash_string (cu->die_symbol), 5976 NO_INSERT); 5977 entry = *slot; 5978 5979 entry->max_comdat_num = sym_num; 5980} 5981 5982/* Traverse the DIE (which is always comp_unit_die), and set up 5983 additional compilation units for each of the include files we see 5984 bracketed by BINCL/EINCL. */ 5985 5986static void 5987break_out_includes (die) 5988 dw_die_ref die; 5989{ 5990 dw_die_ref *ptr; 5991 dw_die_ref unit = NULL; 5992 limbo_die_node *node, **pnode; 5993 htab_t cu_hash_table; 5994 5995 for (ptr = &(die->die_child); *ptr;) 5996 { 5997 dw_die_ref c = *ptr; 5998 5999 if (c->die_tag == DW_TAG_GNU_BINCL || c->die_tag == DW_TAG_GNU_EINCL 6000 || (unit && is_comdat_die (c))) 6001 { 6002 /* This DIE is for a secondary CU; remove it from the main one. */ 6003 *ptr = c->die_sib; 6004 6005 if (c->die_tag == DW_TAG_GNU_BINCL) 6006 { 6007 unit = push_new_compile_unit (unit, c); 6008 free_die (c); 6009 } 6010 else if (c->die_tag == DW_TAG_GNU_EINCL) 6011 { 6012 unit = pop_compile_unit (unit); 6013 free_die (c); 6014 } 6015 else 6016 add_child_die (unit, c); 6017 } 6018 else 6019 { 6020 /* Leave this DIE in the main CU. */ 6021 ptr = &(c->die_sib); 6022 continue; 6023 } 6024 } 6025 6026#if 0 6027 /* We can only use this in debugging, since the frontend doesn't check 6028 to make sure that we leave every include file we enter. */ 6029 if (unit != NULL) 6030 abort (); 6031#endif 6032 6033 assign_symbol_names (die); 6034 cu_hash_table = htab_create (10, htab_cu_hash, htab_cu_eq, htab_cu_del); 6035 for (node = limbo_die_list, pnode = &limbo_die_list; 6036 node; 6037 node = node->next) 6038 { 6039 int is_dupl; 6040 6041 compute_section_prefix (node->die); 6042 is_dupl = check_duplicate_cu (node->die, cu_hash_table, 6043 &comdat_symbol_number); 6044 assign_symbol_names (node->die); 6045 if (is_dupl) 6046 *pnode = node->next; 6047 else 6048 { 6049 pnode = &node->next; 6050 record_comdat_symbol_number (node->die, cu_hash_table, 6051 comdat_symbol_number); 6052 } 6053 } 6054 htab_delete (cu_hash_table); 6055} 6056 6057/* Traverse the DIE and add a sibling attribute if it may have the 6058 effect of speeding up access to siblings. To save some space, 6059 avoid generating sibling attributes for DIE's without children. */ 6060 6061static void 6062add_sibling_attributes (die) 6063 dw_die_ref die; 6064{ 6065 dw_die_ref c; 6066 6067 if (die->die_tag != DW_TAG_compile_unit 6068 && die->die_sib && die->die_child != NULL) 6069 /* Add the sibling link to the front of the attribute list. */ 6070 add_AT_die_ref (die, DW_AT_sibling, die->die_sib); 6071 6072 for (c = die->die_child; c != NULL; c = c->die_sib) 6073 add_sibling_attributes (c); 6074} 6075 6076/* Output all location lists for the DIE and its children. */ 6077 6078static void 6079output_location_lists (die) 6080 dw_die_ref die; 6081{ 6082 dw_die_ref c; 6083 dw_attr_ref d_attr; 6084 6085 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) 6086 if (AT_class (d_attr) == dw_val_class_loc_list) 6087 output_loc_list (AT_loc_list (d_attr)); 6088 6089 for (c = die->die_child; c != NULL; c = c->die_sib) 6090 output_location_lists (c); 6091 6092} 6093 6094/* The format of each DIE (and its attribute value pairs) is encoded in an 6095 abbreviation table. This routine builds the abbreviation table and assigns 6096 a unique abbreviation id for each abbreviation entry. The children of each 6097 die are visited recursively. */ 6098 6099static void 6100build_abbrev_table (die) 6101 dw_die_ref die; 6102{ 6103 unsigned long abbrev_id; 6104 unsigned int n_alloc; 6105 dw_die_ref c; 6106 dw_attr_ref d_attr, a_attr; 6107 6108 /* Scan the DIE references, and mark as external any that refer to 6109 DIEs from other CUs (i.e. those which are not marked). */ 6110 for (d_attr = die->die_attr; d_attr; d_attr = d_attr->dw_attr_next) 6111 if (AT_class (d_attr) == dw_val_class_die_ref 6112 && AT_ref (d_attr)->die_mark == 0) 6113 { 6114 if (AT_ref (d_attr)->die_symbol == 0) 6115 abort (); 6116 6117 set_AT_ref_external (d_attr, 1); 6118 } 6119 6120 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) 6121 { 6122 dw_die_ref abbrev = abbrev_die_table[abbrev_id]; 6123 6124 if (abbrev->die_tag == die->die_tag) 6125 { 6126 if ((abbrev->die_child != NULL) == (die->die_child != NULL)) 6127 { 6128 a_attr = abbrev->die_attr; 6129 d_attr = die->die_attr; 6130 6131 while (a_attr != NULL && d_attr != NULL) 6132 { 6133 if ((a_attr->dw_attr != d_attr->dw_attr) 6134 || (value_format (a_attr) != value_format (d_attr))) 6135 break; 6136 6137 a_attr = a_attr->dw_attr_next; 6138 d_attr = d_attr->dw_attr_next; 6139 } 6140 6141 if (a_attr == NULL && d_attr == NULL) 6142 break; 6143 } 6144 } 6145 } 6146 6147 if (abbrev_id >= abbrev_die_table_in_use) 6148 { 6149 if (abbrev_die_table_in_use >= abbrev_die_table_allocated) 6150 { 6151 n_alloc = abbrev_die_table_allocated + ABBREV_DIE_TABLE_INCREMENT; 6152 abbrev_die_table 6153 = (dw_die_ref *) xrealloc (abbrev_die_table, 6154 sizeof (dw_die_ref) * n_alloc); 6155 6156 memset ((char *) &abbrev_die_table[abbrev_die_table_allocated], 0, 6157 (n_alloc - abbrev_die_table_allocated) * sizeof (dw_die_ref)); 6158 abbrev_die_table_allocated = n_alloc; 6159 } 6160 6161 ++abbrev_die_table_in_use; 6162 abbrev_die_table[abbrev_id] = die; 6163 } 6164 6165 die->die_abbrev = abbrev_id; 6166 for (c = die->die_child; c != NULL; c = c->die_sib) 6167 build_abbrev_table (c); 6168} 6169 6170/* Return the power-of-two number of bytes necessary to represent VALUE. */ 6171 6172static int 6173constant_size (value) 6174 long unsigned value; 6175{ 6176 int log; 6177 6178 if (value == 0) 6179 log = 0; 6180 else 6181 log = floor_log2 (value); 6182 6183 log = log / 8; 6184 log = 1 << (floor_log2 (log) + 1); 6185 6186 return log; 6187} 6188 6189/* Return the size of a DIE as it is represented in the 6190 .debug_info section. */ 6191 6192static unsigned long 6193size_of_die (die) 6194 dw_die_ref die; 6195{ 6196 unsigned long size = 0; 6197 dw_attr_ref a; 6198 6199 size += size_of_uleb128 (die->die_abbrev); 6200 for (a = die->die_attr; a != NULL; a = a->dw_attr_next) 6201 { 6202 switch (AT_class (a)) 6203 { 6204 case dw_val_class_addr: 6205 size += DWARF2_ADDR_SIZE; 6206 break; 6207 case dw_val_class_offset: 6208 size += DWARF_OFFSET_SIZE; 6209 break; 6210 case dw_val_class_loc: 6211 { 6212 unsigned long lsize = size_of_locs (AT_loc (a)); 6213 6214 /* Block length. */ 6215 size += constant_size (lsize); 6216 size += lsize; 6217 } 6218 break; 6219 case dw_val_class_loc_list: 6220 size += DWARF_OFFSET_SIZE; 6221 break; 6222 case dw_val_class_range_list: 6223 size += DWARF_OFFSET_SIZE; 6224 break; 6225 case dw_val_class_const: 6226 size += size_of_sleb128 (AT_int (a)); 6227 break; 6228 case dw_val_class_unsigned_const: 6229 size += constant_size (AT_unsigned (a)); 6230 break; 6231 case dw_val_class_long_long: 6232 size += 1 + 2*HOST_BITS_PER_LONG/HOST_BITS_PER_CHAR; /* block */ 6233 break; 6234 case dw_val_class_float: 6235 size += 1 + a->dw_attr_val.v.val_float.length * 4; /* block */ 6236 break; 6237 case dw_val_class_flag: 6238 size += 1; 6239 break; 6240 case dw_val_class_die_ref: 6241 size += DWARF_OFFSET_SIZE; 6242 break; 6243 case dw_val_class_fde_ref: 6244 size += DWARF_OFFSET_SIZE; 6245 break; 6246 case dw_val_class_lbl_id: 6247 size += DWARF2_ADDR_SIZE; 6248 break; 6249 case dw_val_class_lbl_offset: 6250 size += DWARF_OFFSET_SIZE; 6251 break; 6252 case dw_val_class_str: 6253 if (AT_string_form (a) == DW_FORM_strp) 6254 size += DWARF_OFFSET_SIZE; 6255 else 6256 size += HT_LEN (&a->dw_attr_val.v.val_str->id) + 1; 6257 break; 6258 default: 6259 abort (); 6260 } 6261 } 6262 6263 return size; 6264} 6265 6266/* Size the debugging information associated with a given DIE. Visits the 6267 DIE's children recursively. Updates the global variable next_die_offset, on 6268 each time through. Uses the current value of next_die_offset to update the 6269 die_offset field in each DIE. */ 6270 6271static void 6272calc_die_sizes (die) 6273 dw_die_ref die; 6274{ 6275 dw_die_ref c; 6276 6277 die->die_offset = next_die_offset; 6278 next_die_offset += size_of_die (die); 6279 6280 for (c = die->die_child; c != NULL; c = c->die_sib) 6281 calc_die_sizes (c); 6282 6283 if (die->die_child != NULL) 6284 /* Count the null byte used to terminate sibling lists. */ 6285 next_die_offset += 1; 6286} 6287 6288/* Set the marks for a die and its children. We do this so 6289 that we know whether or not a reference needs to use FORM_ref_addr; only 6290 DIEs in the same CU will be marked. We used to clear out the offset 6291 and use that as the flag, but ran into ordering problems. */ 6292 6293static void 6294mark_dies (die) 6295 dw_die_ref die; 6296{ 6297 dw_die_ref c; 6298 6299 if (die->die_mark) 6300 abort (); 6301 6302 die->die_mark = 1; 6303 for (c = die->die_child; c; c = c->die_sib) 6304 mark_dies (c); 6305} 6306 6307/* Clear the marks for a die and its children. */ 6308 6309static void 6310unmark_dies (die) 6311 dw_die_ref die; 6312{ 6313 dw_die_ref c; 6314 6315 if (!die->die_mark) 6316 abort (); 6317 6318 die->die_mark = 0; 6319 for (c = die->die_child; c; c = c->die_sib) 6320 unmark_dies (c); 6321} 6322 6323/* Clear the marks for a die, its children and referred dies. */ 6324 6325static void 6326unmark_all_dies (die) 6327 dw_die_ref die; 6328{ 6329 dw_die_ref c; 6330 dw_attr_ref a; 6331 6332 if (!die->die_mark) 6333 return; 6334 die->die_mark = 0; 6335 6336 for (c = die->die_child; c; c = c->die_sib) 6337 unmark_all_dies (c); 6338 6339 for (a = die->die_attr; a; a = a->dw_attr_next) 6340 if (AT_class (a) == dw_val_class_die_ref) 6341 unmark_all_dies (AT_ref (a)); 6342} 6343 6344/* Return the size of the .debug_pubnames table generated for the 6345 compilation unit. */ 6346 6347static unsigned long 6348size_of_pubnames () 6349{ 6350 unsigned long size; 6351 unsigned i; 6352 6353 size = DWARF_PUBNAMES_HEADER_SIZE; 6354 for (i = 0; i < pubname_table_in_use; i++) 6355 { 6356 pubname_ref p = &pubname_table[i]; 6357 size += DWARF_OFFSET_SIZE + strlen (p->name) + 1; 6358 } 6359 6360 size += DWARF_OFFSET_SIZE; 6361 return size; 6362} 6363 6364/* Return the size of the information in the .debug_aranges section. */ 6365 6366static unsigned long 6367size_of_aranges () 6368{ 6369 unsigned long size; 6370 6371 size = DWARF_ARANGES_HEADER_SIZE; 6372 6373 /* Count the address/length pair for this compilation unit. */ 6374 size += 2 * DWARF2_ADDR_SIZE; 6375 size += 2 * DWARF2_ADDR_SIZE * arange_table_in_use; 6376 6377 /* Count the two zero words used to terminated the address range table. */ 6378 size += 2 * DWARF2_ADDR_SIZE; 6379 return size; 6380} 6381 6382/* Select the encoding of an attribute value. */ 6383 6384static enum dwarf_form 6385value_format (a) 6386 dw_attr_ref a; 6387{ 6388 switch (a->dw_attr_val.val_class) 6389 { 6390 case dw_val_class_addr: 6391 return DW_FORM_addr; 6392 case dw_val_class_range_list: 6393 case dw_val_class_offset: 6394 if (DWARF_OFFSET_SIZE == 4) 6395 return DW_FORM_data4; 6396 if (DWARF_OFFSET_SIZE == 8) 6397 return DW_FORM_data8; 6398 abort (); 6399 case dw_val_class_loc_list: 6400 /* FIXME: Could be DW_FORM_data8, with a > 32 bit size 6401 .debug_loc section */ 6402 return DW_FORM_data4; 6403 case dw_val_class_loc: 6404 switch (constant_size (size_of_locs (AT_loc (a)))) 6405 { 6406 case 1: 6407 return DW_FORM_block1; 6408 case 2: 6409 return DW_FORM_block2; 6410 default: 6411 abort (); 6412 } 6413 case dw_val_class_const: 6414 return DW_FORM_sdata; 6415 case dw_val_class_unsigned_const: 6416 switch (constant_size (AT_unsigned (a))) 6417 { 6418 case 1: 6419 return DW_FORM_data1; 6420 case 2: 6421 return DW_FORM_data2; 6422 case 4: 6423 return DW_FORM_data4; 6424 case 8: 6425 return DW_FORM_data8; 6426 default: 6427 abort (); 6428 } 6429 case dw_val_class_long_long: 6430 return DW_FORM_block1; 6431 case dw_val_class_float: 6432 return DW_FORM_block1; 6433 case dw_val_class_flag: 6434 return DW_FORM_flag; 6435 case dw_val_class_die_ref: 6436 if (AT_ref_external (a)) 6437 return DW_FORM_ref_addr; 6438 else 6439 return DW_FORM_ref; 6440 case dw_val_class_fde_ref: 6441 return DW_FORM_data; 6442 case dw_val_class_lbl_id: 6443 return DW_FORM_addr; 6444 case dw_val_class_lbl_offset: 6445 return DW_FORM_data; 6446 case dw_val_class_str: 6447 return AT_string_form (a); 6448 6449 default: 6450 abort (); 6451 } 6452} 6453 6454/* Output the encoding of an attribute value. */ 6455 6456static void 6457output_value_format (a) 6458 dw_attr_ref a; 6459{ 6460 enum dwarf_form form = value_format (a); 6461 6462 dw2_asm_output_data_uleb128 (form, "(%s)", dwarf_form_name (form)); 6463} 6464 6465/* Output the .debug_abbrev section which defines the DIE abbreviation 6466 table. */ 6467 6468static void 6469output_abbrev_section () 6470{ 6471 unsigned long abbrev_id; 6472 6473 dw_attr_ref a_attr; 6474 6475 for (abbrev_id = 1; abbrev_id < abbrev_die_table_in_use; ++abbrev_id) 6476 { 6477 dw_die_ref abbrev = abbrev_die_table[abbrev_id]; 6478 6479 dw2_asm_output_data_uleb128 (abbrev_id, "(abbrev code)"); 6480 dw2_asm_output_data_uleb128 (abbrev->die_tag, "(TAG: %s)", 6481 dwarf_tag_name (abbrev->die_tag)); 6482 6483 if (abbrev->die_child != NULL) 6484 dw2_asm_output_data (1, DW_children_yes, "DW_children_yes"); 6485 else 6486 dw2_asm_output_data (1, DW_children_no, "DW_children_no"); 6487 6488 for (a_attr = abbrev->die_attr; a_attr != NULL; 6489 a_attr = a_attr->dw_attr_next) 6490 { 6491 dw2_asm_output_data_uleb128 (a_attr->dw_attr, "(%s)", 6492 dwarf_attr_name (a_attr->dw_attr)); 6493 output_value_format (a_attr); 6494 } 6495 6496 dw2_asm_output_data (1, 0, NULL); 6497 dw2_asm_output_data (1, 0, NULL); 6498 } 6499 6500 /* Terminate the table. */ 6501 dw2_asm_output_data (1, 0, NULL); 6502} 6503 6504/* Output a symbol we can use to refer to this DIE from another CU. */ 6505 6506static inline void 6507output_die_symbol (die) 6508 dw_die_ref die; 6509{ 6510 char *sym = die->die_symbol; 6511 6512 if (sym == 0) 6513 return; 6514 6515 if (strncmp (sym, DIE_LABEL_PREFIX, sizeof (DIE_LABEL_PREFIX) - 1) == 0) 6516 /* We make these global, not weak; if the target doesn't support 6517 .linkonce, it doesn't support combining the sections, so debugging 6518 will break. */ 6519 (*targetm.asm_out.globalize_label) (asm_out_file, sym); 6520 6521 ASM_OUTPUT_LABEL (asm_out_file, sym); 6522} 6523 6524/* Return a new location list, given the begin and end range, and the 6525 expression. gensym tells us whether to generate a new internal symbol for 6526 this location list node, which is done for the head of the list only. */ 6527 6528static inline dw_loc_list_ref 6529new_loc_list (expr, begin, end, section, gensym) 6530 dw_loc_descr_ref expr; 6531 const char *begin; 6532 const char *end; 6533 const char *section; 6534 unsigned gensym; 6535{ 6536 dw_loc_list_ref retlist 6537 = (dw_loc_list_ref) xcalloc (1, sizeof (dw_loc_list_node)); 6538 6539 retlist->begin = begin; 6540 retlist->end = end; 6541 retlist->expr = expr; 6542 retlist->section = section; 6543 if (gensym) 6544 retlist->ll_symbol = gen_internal_sym ("LLST"); 6545 6546 return retlist; 6547} 6548 6549/* Add a location description expression to a location list */ 6550 6551static inline void 6552add_loc_descr_to_loc_list (list_head, descr, begin, end, section) 6553 dw_loc_list_ref *list_head; 6554 dw_loc_descr_ref descr; 6555 const char *begin; 6556 const char *end; 6557 const char *section; 6558{ 6559 dw_loc_list_ref *d; 6560 6561 /* Find the end of the chain. */ 6562 for (d = list_head; (*d) != NULL; d = &(*d)->dw_loc_next) 6563 ; 6564 6565 /* Add a new location list node to the list */ 6566 *d = new_loc_list (descr, begin, end, section, 0); 6567} 6568 6569/* Output the location list given to us */ 6570 6571static void 6572output_loc_list (list_head) 6573 dw_loc_list_ref list_head; 6574{ 6575 dw_loc_list_ref curr = list_head; 6576 6577 ASM_OUTPUT_LABEL (asm_out_file, list_head->ll_symbol); 6578 6579 /* ??? This shouldn't be needed now that we've forced the 6580 compilation unit base address to zero when there is code 6581 in more than one section. */ 6582 if (strcmp (curr->section, ".text") == 0) 6583 { 6584 /* dw2_asm_output_data will mask off any extra bits in the ~0. */ 6585 dw2_asm_output_data (DWARF2_ADDR_SIZE, ~(unsigned HOST_WIDE_INT) 0, 6586 "Location list base address specifier fake entry"); 6587 dw2_asm_output_offset (DWARF2_ADDR_SIZE, curr->section, 6588 "Location list base address specifier base"); 6589 } 6590 6591 for (curr = list_head; curr != NULL; curr = curr->dw_loc_next) 6592 { 6593 unsigned long size; 6594 6595 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->begin, curr->section, 6596 "Location list begin address (%s)", 6597 list_head->ll_symbol); 6598 dw2_asm_output_delta (DWARF2_ADDR_SIZE, curr->end, curr->section, 6599 "Location list end address (%s)", 6600 list_head->ll_symbol); 6601 size = size_of_locs (curr->expr); 6602 6603 /* Output the block length for this list of location operations. */ 6604 if (size > 0xffff) 6605 abort (); 6606 dw2_asm_output_data (2, size, "%s", "Location expression size"); 6607 6608 output_loc_sequence (curr->expr); 6609 } 6610 6611 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, 6612 "Location list terminator begin (%s)", 6613 list_head->ll_symbol); 6614 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, 6615 "Location list terminator end (%s)", 6616 list_head->ll_symbol); 6617} 6618 6619/* Output the DIE and its attributes. Called recursively to generate 6620 the definitions of each child DIE. */ 6621 6622static void 6623output_die (die) 6624 dw_die_ref die; 6625{ 6626 dw_attr_ref a; 6627 dw_die_ref c; 6628 unsigned long size; 6629 6630 /* If someone in another CU might refer to us, set up a symbol for 6631 them to point to. */ 6632 if (die->die_symbol) 6633 output_die_symbol (die); 6634 6635 dw2_asm_output_data_uleb128 (die->die_abbrev, "(DIE (0x%lx) %s)", 6636 die->die_offset, dwarf_tag_name (die->die_tag)); 6637 6638 for (a = die->die_attr; a != NULL; a = a->dw_attr_next) 6639 { 6640 const char *name = dwarf_attr_name (a->dw_attr); 6641 6642 switch (AT_class (a)) 6643 { 6644 case dw_val_class_addr: 6645 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, AT_addr (a), "%s", name); 6646 break; 6647 6648 case dw_val_class_offset: 6649 dw2_asm_output_data (DWARF_OFFSET_SIZE, a->dw_attr_val.v.val_offset, 6650 "%s", name); 6651 break; 6652 6653 case dw_val_class_range_list: 6654 { 6655 char *p = strchr (ranges_section_label, '\0'); 6656 6657 sprintf (p, "+0x%lx", a->dw_attr_val.v.val_offset); 6658 dw2_asm_output_offset (DWARF_OFFSET_SIZE, ranges_section_label, 6659 "%s", name); 6660 *p = '\0'; 6661 } 6662 break; 6663 6664 case dw_val_class_loc: 6665 size = size_of_locs (AT_loc (a)); 6666 6667 /* Output the block length for this list of location operations. */ 6668 dw2_asm_output_data (constant_size (size), size, "%s", name); 6669 6670 output_loc_sequence (AT_loc (a)); 6671 break; 6672 6673 case dw_val_class_const: 6674 /* ??? It would be slightly more efficient to use a scheme like is 6675 used for unsigned constants below, but gdb 4.x does not sign 6676 extend. Gdb 5.x does sign extend. */ 6677 dw2_asm_output_data_sleb128 (AT_int (a), "%s", name); 6678 break; 6679 6680 case dw_val_class_unsigned_const: 6681 dw2_asm_output_data (constant_size (AT_unsigned (a)), 6682 AT_unsigned (a), "%s", name); 6683 break; 6684 6685 case dw_val_class_long_long: 6686 { 6687 unsigned HOST_WIDE_INT first, second; 6688 6689 dw2_asm_output_data (1, 6690 2 * HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, 6691 "%s", name); 6692 6693 if (WORDS_BIG_ENDIAN) 6694 { 6695 first = a->dw_attr_val.v.val_long_long.hi; 6696 second = a->dw_attr_val.v.val_long_long.low; 6697 } 6698 else 6699 { 6700 first = a->dw_attr_val.v.val_long_long.low; 6701 second = a->dw_attr_val.v.val_long_long.hi; 6702 } 6703 6704 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, 6705 first, "long long constant"); 6706 dw2_asm_output_data (HOST_BITS_PER_LONG / HOST_BITS_PER_CHAR, 6707 second, NULL); 6708 } 6709 break; 6710 6711 case dw_val_class_float: 6712 { 6713 unsigned int i; 6714 6715 dw2_asm_output_data (1, a->dw_attr_val.v.val_float.length * 4, 6716 "%s", name); 6717 6718 for (i = 0; i < a->dw_attr_val.v.val_float.length; i++) 6719 dw2_asm_output_data (4, a->dw_attr_val.v.val_float.array[i], 6720 "fp constant word %u", i); 6721 break; 6722 } 6723 6724 case dw_val_class_flag: 6725 dw2_asm_output_data (1, AT_flag (a), "%s", name); 6726 break; 6727 6728 case dw_val_class_loc_list: 6729 { 6730 char *sym = AT_loc_list (a)->ll_symbol; 6731 6732 if (sym == 0) 6733 abort (); 6734 dw2_asm_output_delta (DWARF_OFFSET_SIZE, sym, 6735 loc_section_label, "%s", name); 6736 } 6737 break; 6738 6739 case dw_val_class_die_ref: 6740 if (AT_ref_external (a)) 6741 { 6742 char *sym = AT_ref (a)->die_symbol; 6743 6744 if (sym == 0) 6745 abort (); 6746 dw2_asm_output_offset (DWARF2_ADDR_SIZE, sym, "%s", name); 6747 } 6748 else if (AT_ref (a)->die_offset == 0) 6749 abort (); 6750 else 6751 dw2_asm_output_data (DWARF_OFFSET_SIZE, AT_ref (a)->die_offset, 6752 "%s", name); 6753 break; 6754 6755 case dw_val_class_fde_ref: 6756 { 6757 char l1[20]; 6758 6759 ASM_GENERATE_INTERNAL_LABEL (l1, FDE_LABEL, 6760 a->dw_attr_val.v.val_fde_index * 2); 6761 dw2_asm_output_offset (DWARF_OFFSET_SIZE, l1, "%s", name); 6762 } 6763 break; 6764 6765 case dw_val_class_lbl_id: 6766 dw2_asm_output_addr (DWARF2_ADDR_SIZE, AT_lbl (a), "%s", name); 6767 break; 6768 6769 case dw_val_class_lbl_offset: 6770 dw2_asm_output_offset (DWARF_OFFSET_SIZE, AT_lbl (a), "%s", name); 6771 break; 6772 6773 case dw_val_class_str: 6774 if (AT_string_form (a) == DW_FORM_strp) 6775 dw2_asm_output_offset (DWARF_OFFSET_SIZE, 6776 a->dw_attr_val.v.val_str->label, 6777 "%s: \"%s\"", name, AT_string (a)); 6778 else 6779 dw2_asm_output_nstring (AT_string (a), -1, "%s", name); 6780 break; 6781 6782 default: 6783 abort (); 6784 } 6785 } 6786 6787 for (c = die->die_child; c != NULL; c = c->die_sib) 6788 output_die (c); 6789 6790 /* Add null byte to terminate sibling list. */ 6791 if (die->die_child != NULL) 6792 dw2_asm_output_data (1, 0, "end of children of DIE 0x%lx", 6793 die->die_offset); 6794} 6795 6796/* Output the compilation unit that appears at the beginning of the 6797 .debug_info section, and precedes the DIE descriptions. */ 6798 6799static void 6800output_compilation_unit_header () 6801{ 6802 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset - DWARF_OFFSET_SIZE, 6803 "Length of Compilation Unit Info"); 6804 dw2_asm_output_data (2, DWARF_VERSION, "DWARF version number"); 6805 dw2_asm_output_offset (DWARF_OFFSET_SIZE, abbrev_section_label, 6806 "Offset Into Abbrev. Section"); 6807 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Pointer Size (in bytes)"); 6808} 6809 6810/* Output the compilation unit DIE and its children. */ 6811 6812static void 6813output_comp_unit (die, output_if_empty) 6814 dw_die_ref die; 6815 int output_if_empty; 6816{ 6817 const char *secname; 6818 char *oldsym, *tmp; 6819 6820 /* Unless we are outputting main CU, we may throw away empty ones. */ 6821 if (!output_if_empty && die->die_child == NULL) 6822 return; 6823 6824 /* Even if there are no children of this DIE, we must output the information 6825 about the compilation unit. Otherwise, on an empty translation unit, we 6826 will generate a present, but empty, .debug_info section. IRIX 6.5 `nm' 6827 will then complain when examining the file. First mark all the DIEs in 6828 this CU so we know which get local refs. */ 6829 mark_dies (die); 6830 6831 build_abbrev_table (die); 6832 6833 /* Initialize the beginning DIE offset - and calculate sizes/offsets. */ 6834 next_die_offset = DWARF_COMPILE_UNIT_HEADER_SIZE; 6835 calc_die_sizes (die); 6836 6837 oldsym = die->die_symbol; 6838 if (oldsym) 6839 { 6840 tmp = (char *) alloca (strlen (oldsym) + 24); 6841 6842 sprintf (tmp, ".gnu.linkonce.wi.%s", oldsym); 6843 secname = tmp; 6844 die->die_symbol = NULL; 6845 } 6846 else 6847 secname = (const char *) DEBUG_INFO_SECTION; 6848 6849 /* Output debugging information. */ 6850 named_section_flags (secname, SECTION_DEBUG); 6851 output_compilation_unit_header (); 6852 output_die (die); 6853 6854 /* Leave the marks on the main CU, so we can check them in 6855 output_pubnames. */ 6856 if (oldsym) 6857 { 6858 unmark_dies (die); 6859 die->die_symbol = oldsym; 6860 } 6861} 6862 6863/* The DWARF2 pubname for a nested thingy looks like "A::f". The 6864 output of lang_hooks.decl_printable_name for C++ looks like 6865 "A::f(int)". Let's drop the argument list, and maybe the scope. */ 6866 6867static const char * 6868dwarf2_name (decl, scope) 6869 tree decl; 6870 int scope; 6871{ 6872 return (*lang_hooks.decl_printable_name) (decl, scope ? 1 : 0); 6873} 6874 6875/* Add a new entry to .debug_pubnames if appropriate. */ 6876 6877static void 6878add_pubname (decl, die) 6879 tree decl; 6880 dw_die_ref die; 6881{ 6882 pubname_ref p; 6883 6884 if (! TREE_PUBLIC (decl)) 6885 return; 6886 6887 if (pubname_table_in_use == pubname_table_allocated) 6888 { 6889 pubname_table_allocated += PUBNAME_TABLE_INCREMENT; 6890 pubname_table 6891 = (pubname_ref) xrealloc (pubname_table, 6892 (pubname_table_allocated 6893 * sizeof (pubname_entry))); 6894 } 6895 6896 p = &pubname_table[pubname_table_in_use++]; 6897 p->die = die; 6898 p->name = xstrdup (dwarf2_name (decl, 1)); 6899} 6900 6901/* Output the public names table used to speed up access to externally 6902 visible names. For now, only generate entries for externally 6903 visible procedures. */ 6904 6905static void 6906output_pubnames () 6907{ 6908 unsigned i; 6909 unsigned long pubnames_length = size_of_pubnames (); 6910 6911 dw2_asm_output_data (DWARF_OFFSET_SIZE, pubnames_length, 6912 "Length of Public Names Info"); 6913 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); 6914 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, 6915 "Offset of Compilation Unit Info"); 6916 dw2_asm_output_data (DWARF_OFFSET_SIZE, next_die_offset, 6917 "Compilation Unit Length"); 6918 6919 for (i = 0; i < pubname_table_in_use; i++) 6920 { 6921 pubname_ref pub = &pubname_table[i]; 6922 6923 /* We shouldn't see pubnames for DIEs outside of the main CU. */ 6924 if (pub->die->die_mark == 0) 6925 abort (); 6926 6927 dw2_asm_output_data (DWARF_OFFSET_SIZE, pub->die->die_offset, 6928 "DIE offset"); 6929 6930 dw2_asm_output_nstring (pub->name, -1, "external name"); 6931 } 6932 6933 dw2_asm_output_data (DWARF_OFFSET_SIZE, 0, NULL); 6934} 6935 6936/* Add a new entry to .debug_aranges if appropriate. */ 6937 6938static void 6939add_arange (decl, die) 6940 tree decl; 6941 dw_die_ref die; 6942{ 6943 if (! DECL_SECTION_NAME (decl)) 6944 return; 6945 6946 if (arange_table_in_use == arange_table_allocated) 6947 { 6948 arange_table_allocated += ARANGE_TABLE_INCREMENT; 6949 arange_table = (dw_die_ref *) 6950 xrealloc (arange_table, arange_table_allocated * sizeof (dw_die_ref)); 6951 } 6952 6953 arange_table[arange_table_in_use++] = die; 6954} 6955 6956/* Output the information that goes into the .debug_aranges table. 6957 Namely, define the beginning and ending address range of the 6958 text section generated for this compilation unit. */ 6959 6960static void 6961output_aranges () 6962{ 6963 unsigned i; 6964 unsigned long aranges_length = size_of_aranges (); 6965 6966 dw2_asm_output_data (DWARF_OFFSET_SIZE, aranges_length, 6967 "Length of Address Ranges Info"); 6968 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); 6969 dw2_asm_output_offset (DWARF_OFFSET_SIZE, debug_info_section_label, 6970 "Offset of Compilation Unit Info"); 6971 dw2_asm_output_data (1, DWARF2_ADDR_SIZE, "Size of Address"); 6972 dw2_asm_output_data (1, 0, "Size of Segment Descriptor"); 6973 6974 /* We need to align to twice the pointer size here. */ 6975 if (DWARF_ARANGES_PAD_SIZE) 6976 { 6977 /* Pad using a 2 byte words so that padding is correct for any 6978 pointer size. */ 6979 dw2_asm_output_data (2, 0, "Pad to %d byte boundary", 6980 2 * DWARF2_ADDR_SIZE); 6981 for (i = 2; i < (unsigned) DWARF_ARANGES_PAD_SIZE; i += 2) 6982 dw2_asm_output_data (2, 0, NULL); 6983 } 6984 6985 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_section_label, "Address"); 6986 dw2_asm_output_delta (DWARF2_ADDR_SIZE, text_end_label, 6987 text_section_label, "Length"); 6988 6989 for (i = 0; i < arange_table_in_use; i++) 6990 { 6991 dw_die_ref die = arange_table[i]; 6992 6993 /* We shouldn't see aranges for DIEs outside of the main CU. */ 6994 if (die->die_mark == 0) 6995 abort (); 6996 6997 if (die->die_tag == DW_TAG_subprogram) 6998 { 6999 dw2_asm_output_addr (DWARF2_ADDR_SIZE, get_AT_low_pc (die), 7000 "Address"); 7001 dw2_asm_output_delta (DWARF2_ADDR_SIZE, get_AT_hi_pc (die), 7002 get_AT_low_pc (die), "Length"); 7003 } 7004 else 7005 { 7006 /* A static variable; extract the symbol from DW_AT_location. 7007 Note that this code isn't currently hit, as we only emit 7008 aranges for functions (jason 9/23/99). */ 7009 dw_attr_ref a = get_AT (die, DW_AT_location); 7010 dw_loc_descr_ref loc; 7011 7012 if (! a || AT_class (a) != dw_val_class_loc) 7013 abort (); 7014 7015 loc = AT_loc (a); 7016 if (loc->dw_loc_opc != DW_OP_addr) 7017 abort (); 7018 7019 dw2_asm_output_addr_rtx (DWARF2_ADDR_SIZE, 7020 loc->dw_loc_oprnd1.v.val_addr, "Address"); 7021 dw2_asm_output_data (DWARF2_ADDR_SIZE, 7022 get_AT_unsigned (die, DW_AT_byte_size), 7023 "Length"); 7024 } 7025 } 7026 7027 /* Output the terminator words. */ 7028 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); 7029 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); 7030} 7031 7032/* Add a new entry to .debug_ranges. Return the offset at which it 7033 was placed. */ 7034 7035static unsigned int 7036add_ranges (block) 7037 tree block; 7038{ 7039 unsigned int in_use = ranges_table_in_use; 7040 7041 if (in_use == ranges_table_allocated) 7042 { 7043 ranges_table_allocated += RANGES_TABLE_INCREMENT; 7044 ranges_table = (dw_ranges_ref) 7045 xrealloc (ranges_table, (ranges_table_allocated 7046 * sizeof (struct dw_ranges_struct))); 7047 } 7048 7049 ranges_table[in_use].block_num = (block ? BLOCK_NUMBER (block) : 0); 7050 ranges_table_in_use = in_use + 1; 7051 7052 return in_use * 2 * DWARF2_ADDR_SIZE; 7053} 7054 7055static void 7056output_ranges () 7057{ 7058 unsigned i; 7059 static const char *const start_fmt = "Offset 0x%x"; 7060 const char *fmt = start_fmt; 7061 7062 for (i = 0; i < ranges_table_in_use; i++) 7063 { 7064 int block_num = ranges_table[i].block_num; 7065 7066 if (block_num) 7067 { 7068 char blabel[MAX_ARTIFICIAL_LABEL_BYTES]; 7069 char elabel[MAX_ARTIFICIAL_LABEL_BYTES]; 7070 7071 ASM_GENERATE_INTERNAL_LABEL (blabel, BLOCK_BEGIN_LABEL, block_num); 7072 ASM_GENERATE_INTERNAL_LABEL (elabel, BLOCK_END_LABEL, block_num); 7073 7074 /* If all code is in the text section, then the compilation 7075 unit base address defaults to DW_AT_low_pc, which is the 7076 base of the text section. */ 7077 if (separate_line_info_table_in_use == 0) 7078 { 7079 dw2_asm_output_delta (DWARF2_ADDR_SIZE, blabel, 7080 text_section_label, 7081 fmt, i * 2 * DWARF2_ADDR_SIZE); 7082 dw2_asm_output_delta (DWARF2_ADDR_SIZE, elabel, 7083 text_section_label, NULL); 7084 } 7085 7086 /* Otherwise, we add a DW_AT_entry_pc attribute to force the 7087 compilation unit base address to zero, which allows us to 7088 use absolute addresses, and not worry about whether the 7089 target supports cross-section arithmetic. */ 7090 else 7091 { 7092 dw2_asm_output_addr (DWARF2_ADDR_SIZE, blabel, 7093 fmt, i * 2 * DWARF2_ADDR_SIZE); 7094 dw2_asm_output_addr (DWARF2_ADDR_SIZE, elabel, NULL); 7095 } 7096 7097 fmt = NULL; 7098 } 7099 else 7100 { 7101 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); 7102 dw2_asm_output_data (DWARF2_ADDR_SIZE, 0, NULL); 7103 fmt = start_fmt; 7104 } 7105 } 7106} 7107 7108/* Data structure containing information about input files. */ 7109struct file_info 7110{ 7111 char *path; /* Complete file name. */ 7112 char *fname; /* File name part. */ 7113 int length; /* Length of entire string. */ 7114 int file_idx; /* Index in input file table. */ 7115 int dir_idx; /* Index in directory table. */ 7116}; 7117 7118/* Data structure containing information about directories with source 7119 files. */ 7120struct dir_info 7121{ 7122 char *path; /* Path including directory name. */ 7123 int length; /* Path length. */ 7124 int prefix; /* Index of directory entry which is a prefix. */ 7125 int count; /* Number of files in this directory. */ 7126 int dir_idx; /* Index of directory used as base. */ 7127 int used; /* Used in the end? */ 7128}; 7129 7130/* Callback function for file_info comparison. We sort by looking at 7131 the directories in the path. */ 7132 7133static int 7134file_info_cmp (p1, p2) 7135 const void *p1; 7136 const void *p2; 7137{ 7138 const struct file_info *s1 = p1; 7139 const struct file_info *s2 = p2; 7140 unsigned char *cp1; 7141 unsigned char *cp2; 7142 7143 /* Take care of file names without directories. We need to make sure that 7144 we return consistent values to qsort since some will get confused if 7145 we return the same value when identical operands are passed in opposite 7146 orders. So if neither has a directory, return 0 and otherwise return 7147 1 or -1 depending on which one has the directory. */ 7148 if ((s1->path == s1->fname || s2->path == s2->fname)) 7149 return (s2->path == s2->fname) - (s1->path == s1->fname); 7150 7151 cp1 = (unsigned char *) s1->path; 7152 cp2 = (unsigned char *) s2->path; 7153 7154 while (1) 7155 { 7156 ++cp1; 7157 ++cp2; 7158 /* Reached the end of the first path? If so, handle like above. */ 7159 if ((cp1 == (unsigned char *) s1->fname) 7160 || (cp2 == (unsigned char *) s2->fname)) 7161 return ((cp2 == (unsigned char *) s2->fname) 7162 - (cp1 == (unsigned char *) s1->fname)); 7163 7164 /* Character of current path component the same? */ 7165 else if (*cp1 != *cp2) 7166 return *cp1 - *cp2; 7167 } 7168} 7169 7170/* Output the directory table and the file name table. We try to minimize 7171 the total amount of memory needed. A heuristic is used to avoid large 7172 slowdowns with many input files. */ 7173 7174static void 7175output_file_names () 7176{ 7177 struct file_info *files; 7178 struct dir_info *dirs; 7179 int *saved; 7180 int *savehere; 7181 int *backmap; 7182 int ndirs; 7183 int idx_offset; 7184 int i; 7185 int idx; 7186 7187 /* Allocate the various arrays we need. */ 7188 files = (struct file_info *) alloca (file_table.in_use 7189 * sizeof (struct file_info)); 7190 dirs = (struct dir_info *) alloca (file_table.in_use 7191 * sizeof (struct dir_info)); 7192 7193 /* Sort the file names. */ 7194 for (i = 1; i < (int) file_table.in_use; i++) 7195 { 7196 char *f; 7197 7198 /* Skip all leading "./". */ 7199 f = file_table.table[i]; 7200 while (f[0] == '.' && f[1] == '/') 7201 f += 2; 7202 7203 /* Create a new array entry. */ 7204 files[i].path = f; 7205 files[i].length = strlen (f); 7206 files[i].file_idx = i; 7207 7208 /* Search for the file name part. */ 7209 f = strrchr (f, '/'); 7210 files[i].fname = f == NULL ? files[i].path : f + 1; 7211 } 7212 7213 qsort (files + 1, file_table.in_use - 1, sizeof (files[0]), file_info_cmp); 7214 7215 /* Find all the different directories used. */ 7216 dirs[0].path = files[1].path; 7217 dirs[0].length = files[1].fname - files[1].path; 7218 dirs[0].prefix = -1; 7219 dirs[0].count = 1; 7220 dirs[0].dir_idx = 0; 7221 dirs[0].used = 0; 7222 files[1].dir_idx = 0; 7223 ndirs = 1; 7224 7225 for (i = 2; i < (int) file_table.in_use; i++) 7226 if (files[i].fname - files[i].path == dirs[ndirs - 1].length 7227 && memcmp (dirs[ndirs - 1].path, files[i].path, 7228 dirs[ndirs - 1].length) == 0) 7229 { 7230 /* Same directory as last entry. */ 7231 files[i].dir_idx = ndirs - 1; 7232 ++dirs[ndirs - 1].count; 7233 } 7234 else 7235 { 7236 int j; 7237 7238 /* This is a new directory. */ 7239 dirs[ndirs].path = files[i].path; 7240 dirs[ndirs].length = files[i].fname - files[i].path; 7241 dirs[ndirs].count = 1; 7242 dirs[ndirs].dir_idx = ndirs; 7243 dirs[ndirs].used = 0; 7244 files[i].dir_idx = ndirs; 7245 7246 /* Search for a prefix. */ 7247 dirs[ndirs].prefix = -1; 7248 for (j = 0; j < ndirs; j++) 7249 if (dirs[j].length < dirs[ndirs].length 7250 && dirs[j].length > 1 7251 && (dirs[ndirs].prefix == -1 7252 || dirs[j].length > dirs[dirs[ndirs].prefix].length) 7253 && memcmp (dirs[j].path, dirs[ndirs].path, dirs[j].length) == 0) 7254 dirs[ndirs].prefix = j; 7255 7256 ++ndirs; 7257 } 7258 7259 /* Now to the actual work. We have to find a subset of the directories which 7260 allow expressing the file name using references to the directory table 7261 with the least amount of characters. We do not do an exhaustive search 7262 where we would have to check out every combination of every single 7263 possible prefix. Instead we use a heuristic which provides nearly optimal 7264 results in most cases and never is much off. */ 7265 saved = (int *) alloca (ndirs * sizeof (int)); 7266 savehere = (int *) alloca (ndirs * sizeof (int)); 7267 7268 memset (saved, '\0', ndirs * sizeof (saved[0])); 7269 for (i = 0; i < ndirs; i++) 7270 { 7271 int j; 7272 int total; 7273 7274 /* We can always save some space for the current directory. But this 7275 does not mean it will be enough to justify adding the directory. */ 7276 savehere[i] = dirs[i].length; 7277 total = (savehere[i] - saved[i]) * dirs[i].count; 7278 7279 for (j = i + 1; j < ndirs; j++) 7280 { 7281 savehere[j] = 0; 7282 if (saved[j] < dirs[i].length) 7283 { 7284 /* Determine whether the dirs[i] path is a prefix of the 7285 dirs[j] path. */ 7286 int k; 7287 7288 k = dirs[j].prefix; 7289 while (k != -1 && k != i) 7290 k = dirs[k].prefix; 7291 7292 if (k == i) 7293 { 7294 /* Yes it is. We can possibly safe some memory but 7295 writing the filenames in dirs[j] relative to 7296 dirs[i]. */ 7297 savehere[j] = dirs[i].length; 7298 total += (savehere[j] - saved[j]) * dirs[j].count; 7299 } 7300 } 7301 } 7302 7303 /* Check whether we can safe enough to justify adding the dirs[i] 7304 directory. */ 7305 if (total > dirs[i].length + 1) 7306 { 7307 /* It's worthwhile adding. */ 7308 for (j = i; j < ndirs; j++) 7309 if (savehere[j] > 0) 7310 { 7311 /* Remember how much we saved for this directory so far. */ 7312 saved[j] = savehere[j]; 7313 7314 /* Remember the prefix directory. */ 7315 dirs[j].dir_idx = i; 7316 } 7317 } 7318 } 7319 7320 /* We have to emit them in the order they appear in the file_table array 7321 since the index is used in the debug info generation. To do this 7322 efficiently we generate a back-mapping of the indices first. */ 7323 backmap = (int *) alloca (file_table.in_use * sizeof (int)); 7324 for (i = 1; i < (int) file_table.in_use; i++) 7325 { 7326 backmap[files[i].file_idx] = i; 7327 7328 /* Mark this directory as used. */ 7329 dirs[dirs[files[i].dir_idx].dir_idx].used = 1; 7330 } 7331 7332 /* That was it. We are ready to emit the information. First emit the 7333 directory name table. We have to make sure the first actually emitted 7334 directory name has index one; zero is reserved for the current working 7335 directory. Make sure we do not confuse these indices with the one for the 7336 constructed table (even though most of the time they are identical). */ 7337 idx = 1; 7338 idx_offset = dirs[0].length > 0 ? 1 : 0; 7339 for (i = 1 - idx_offset; i < ndirs; i++) 7340 if (dirs[i].used != 0) 7341 { 7342 dirs[i].used = idx++; 7343 dw2_asm_output_nstring (dirs[i].path, dirs[i].length - 1, 7344 "Directory Entry: 0x%x", dirs[i].used); 7345 } 7346 7347 dw2_asm_output_data (1, 0, "End directory table"); 7348 7349 /* Correct the index for the current working directory entry if it 7350 exists. */ 7351 if (idx_offset == 0) 7352 dirs[0].used = 0; 7353 7354 /* Now write all the file names. */ 7355 for (i = 1; i < (int) file_table.in_use; i++) 7356 { 7357 int file_idx = backmap[i]; 7358 int dir_idx = dirs[files[file_idx].dir_idx].dir_idx; 7359 7360 dw2_asm_output_nstring (files[file_idx].path + dirs[dir_idx].length, -1, 7361 "File Entry: 0x%x", i); 7362 7363 /* Include directory index. */ 7364 dw2_asm_output_data_uleb128 (dirs[dir_idx].used, NULL); 7365 7366 /* Modification time. */ 7367 dw2_asm_output_data_uleb128 (0, NULL); 7368 7369 /* File length in bytes. */ 7370 dw2_asm_output_data_uleb128 (0, NULL); 7371 } 7372 7373 dw2_asm_output_data (1, 0, "End file name table"); 7374} 7375 7376 7377/* Output the source line number correspondence information. This 7378 information goes into the .debug_line section. */ 7379 7380static void 7381output_line_info () 7382{ 7383 char l1[20], l2[20], p1[20], p2[20]; 7384 char line_label[MAX_ARTIFICIAL_LABEL_BYTES]; 7385 char prev_line_label[MAX_ARTIFICIAL_LABEL_BYTES]; 7386 unsigned opc; 7387 unsigned n_op_args; 7388 unsigned long lt_index; 7389 unsigned long current_line; 7390 long line_offset; 7391 long line_delta; 7392 unsigned long current_file; 7393 unsigned long function; 7394 7395 ASM_GENERATE_INTERNAL_LABEL (l1, LINE_NUMBER_BEGIN_LABEL, 0); 7396 ASM_GENERATE_INTERNAL_LABEL (l2, LINE_NUMBER_END_LABEL, 0); 7397 ASM_GENERATE_INTERNAL_LABEL (p1, LN_PROLOG_AS_LABEL, 0); 7398 ASM_GENERATE_INTERNAL_LABEL (p2, LN_PROLOG_END_LABEL, 0); 7399 7400 dw2_asm_output_delta (DWARF_OFFSET_SIZE, l2, l1, 7401 "Length of Source Line Info"); 7402 ASM_OUTPUT_LABEL (asm_out_file, l1); 7403 7404 dw2_asm_output_data (2, DWARF_VERSION, "DWARF Version"); 7405 dw2_asm_output_delta (DWARF_OFFSET_SIZE, p2, p1, "Prolog Length"); 7406 ASM_OUTPUT_LABEL (asm_out_file, p1); 7407 7408 /* Define the architecture-dependent minimum instruction length (in 7409 bytes). In this implementation of DWARF, this field is used for 7410 information purposes only. Since GCC generates assembly language, 7411 we have no a priori knowledge of how many instruction bytes are 7412 generated for each source line, and therefore can use only the 7413 DW_LNE_set_address and DW_LNS_fixed_advance_pc line information 7414 commands. Accordingly, we fix this as `1', which is "correct 7415 enough" for all architectures, and don't let the target override. */ 7416 dw2_asm_output_data (1, 1, 7417 "Minimum Instruction Length"); 7418 7419 dw2_asm_output_data (1, DWARF_LINE_DEFAULT_IS_STMT_START, 7420 "Default is_stmt_start flag"); 7421 dw2_asm_output_data (1, DWARF_LINE_BASE, 7422 "Line Base Value (Special Opcodes)"); 7423 dw2_asm_output_data (1, DWARF_LINE_RANGE, 7424 "Line Range Value (Special Opcodes)"); 7425 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE, 7426 "Special Opcode Base"); 7427 7428 for (opc = 1; opc < DWARF_LINE_OPCODE_BASE; opc++) 7429 { 7430 switch (opc) 7431 { 7432 case DW_LNS_advance_pc: 7433 case DW_LNS_advance_line: 7434 case DW_LNS_set_file: 7435 case DW_LNS_set_column: 7436 case DW_LNS_fixed_advance_pc: 7437 n_op_args = 1; 7438 break; 7439 default: 7440 n_op_args = 0; 7441 break; 7442 } 7443 7444 dw2_asm_output_data (1, n_op_args, "opcode: 0x%x has %d args", 7445 opc, n_op_args); 7446 } 7447 7448 /* Write out the information about the files we use. */ 7449 output_file_names (); 7450 ASM_OUTPUT_LABEL (asm_out_file, p2); 7451 7452 /* We used to set the address register to the first location in the text 7453 section here, but that didn't accomplish anything since we already 7454 have a line note for the opening brace of the first function. */ 7455 7456 /* Generate the line number to PC correspondence table, encoded as 7457 a series of state machine operations. */ 7458 current_file = 1; 7459 current_line = 1; 7460 strcpy (prev_line_label, text_section_label); 7461 for (lt_index = 1; lt_index < line_info_table_in_use; ++lt_index) 7462 { 7463 dw_line_info_ref line_info = &line_info_table[lt_index]; 7464 7465#if 0 7466 /* Disable this optimization for now; GDB wants to see two line notes 7467 at the beginning of a function so it can find the end of the 7468 prologue. */ 7469 7470 /* Don't emit anything for redundant notes. Just updating the 7471 address doesn't accomplish anything, because we already assume 7472 that anything after the last address is this line. */ 7473 if (line_info->dw_line_num == current_line 7474 && line_info->dw_file_num == current_file) 7475 continue; 7476#endif 7477 7478 /* Emit debug info for the address of the current line. 7479 7480 Unfortunately, we have little choice here currently, and must always 7481 use the most general form. GCC does not know the address delta 7482 itself, so we can't use DW_LNS_advance_pc. Many ports do have length 7483 attributes which will give an upper bound on the address range. We 7484 could perhaps use length attributes to determine when it is safe to 7485 use DW_LNS_fixed_advance_pc. */ 7486 7487 ASM_GENERATE_INTERNAL_LABEL (line_label, LINE_CODE_LABEL, lt_index); 7488 if (0) 7489 { 7490 /* This can handle deltas up to 0xffff. This takes 3 bytes. */ 7491 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, 7492 "DW_LNS_fixed_advance_pc"); 7493 dw2_asm_output_delta (2, line_label, prev_line_label, NULL); 7494 } 7495 else 7496 { 7497 /* This can handle any delta. This takes 7498 4+DWARF2_ADDR_SIZE bytes. */ 7499 dw2_asm_output_data (1, 0, "DW_LNE_set_address"); 7500 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); 7501 dw2_asm_output_data (1, DW_LNE_set_address, NULL); 7502 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); 7503 } 7504 7505 strcpy (prev_line_label, line_label); 7506 7507 /* Emit debug info for the source file of the current line, if 7508 different from the previous line. */ 7509 if (line_info->dw_file_num != current_file) 7510 { 7511 current_file = line_info->dw_file_num; 7512 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); 7513 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", 7514 file_table.table[current_file]); 7515 } 7516 7517 /* Emit debug info for the current line number, choosing the encoding 7518 that uses the least amount of space. */ 7519 if (line_info->dw_line_num != current_line) 7520 { 7521 line_offset = line_info->dw_line_num - current_line; 7522 line_delta = line_offset - DWARF_LINE_BASE; 7523 current_line = line_info->dw_line_num; 7524 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) 7525 /* This can handle deltas from -10 to 234, using the current 7526 definitions of DWARF_LINE_BASE and DWARF_LINE_RANGE. This 7527 takes 1 byte. */ 7528 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, 7529 "line %lu", current_line); 7530 else 7531 { 7532 /* This can handle any delta. This takes at least 4 bytes, 7533 depending on the value being encoded. */ 7534 dw2_asm_output_data (1, DW_LNS_advance_line, 7535 "advance to line %lu", current_line); 7536 dw2_asm_output_data_sleb128 (line_offset, NULL); 7537 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); 7538 } 7539 } 7540 else 7541 /* We still need to start a new row, so output a copy insn. */ 7542 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); 7543 } 7544 7545 /* Emit debug info for the address of the end of the function. */ 7546 if (0) 7547 { 7548 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, 7549 "DW_LNS_fixed_advance_pc"); 7550 dw2_asm_output_delta (2, text_end_label, prev_line_label, NULL); 7551 } 7552 else 7553 { 7554 dw2_asm_output_data (1, 0, "DW_LNE_set_address"); 7555 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); 7556 dw2_asm_output_data (1, DW_LNE_set_address, NULL); 7557 dw2_asm_output_addr (DWARF2_ADDR_SIZE, text_end_label, NULL); 7558 } 7559 7560 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); 7561 dw2_asm_output_data_uleb128 (1, NULL); 7562 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); 7563 7564 function = 0; 7565 current_file = 1; 7566 current_line = 1; 7567 for (lt_index = 0; lt_index < separate_line_info_table_in_use;) 7568 { 7569 dw_separate_line_info_ref line_info 7570 = &separate_line_info_table[lt_index]; 7571 7572#if 0 7573 /* Don't emit anything for redundant notes. */ 7574 if (line_info->dw_line_num == current_line 7575 && line_info->dw_file_num == current_file 7576 && line_info->function == function) 7577 goto cont; 7578#endif 7579 7580 /* Emit debug info for the address of the current line. If this is 7581 a new function, or the first line of a function, then we need 7582 to handle it differently. */ 7583 ASM_GENERATE_INTERNAL_LABEL (line_label, SEPARATE_LINE_CODE_LABEL, 7584 lt_index); 7585 if (function != line_info->function) 7586 { 7587 function = line_info->function; 7588 7589 /* Set the address register to the first line in the function */ 7590 dw2_asm_output_data (1, 0, "DW_LNE_set_address"); 7591 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); 7592 dw2_asm_output_data (1, DW_LNE_set_address, NULL); 7593 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); 7594 } 7595 else 7596 { 7597 /* ??? See the DW_LNS_advance_pc comment above. */ 7598 if (0) 7599 { 7600 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, 7601 "DW_LNS_fixed_advance_pc"); 7602 dw2_asm_output_delta (2, line_label, prev_line_label, NULL); 7603 } 7604 else 7605 { 7606 dw2_asm_output_data (1, 0, "DW_LNE_set_address"); 7607 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); 7608 dw2_asm_output_data (1, DW_LNE_set_address, NULL); 7609 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); 7610 } 7611 } 7612 7613 strcpy (prev_line_label, line_label); 7614 7615 /* Emit debug info for the source file of the current line, if 7616 different from the previous line. */ 7617 if (line_info->dw_file_num != current_file) 7618 { 7619 current_file = line_info->dw_file_num; 7620 dw2_asm_output_data (1, DW_LNS_set_file, "DW_LNS_set_file"); 7621 dw2_asm_output_data_uleb128 (current_file, "(\"%s\")", 7622 file_table.table[current_file]); 7623 } 7624 7625 /* Emit debug info for the current line number, choosing the encoding 7626 that uses the least amount of space. */ 7627 if (line_info->dw_line_num != current_line) 7628 { 7629 line_offset = line_info->dw_line_num - current_line; 7630 line_delta = line_offset - DWARF_LINE_BASE; 7631 current_line = line_info->dw_line_num; 7632 if (line_delta >= 0 && line_delta < (DWARF_LINE_RANGE - 1)) 7633 dw2_asm_output_data (1, DWARF_LINE_OPCODE_BASE + line_delta, 7634 "line %lu", current_line); 7635 else 7636 { 7637 dw2_asm_output_data (1, DW_LNS_advance_line, 7638 "advance to line %lu", current_line); 7639 dw2_asm_output_data_sleb128 (line_offset, NULL); 7640 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); 7641 } 7642 } 7643 else 7644 dw2_asm_output_data (1, DW_LNS_copy, "DW_LNS_copy"); 7645 7646#if 0 7647 cont: 7648#endif 7649 7650 lt_index++; 7651 7652 /* If we're done with a function, end its sequence. */ 7653 if (lt_index == separate_line_info_table_in_use 7654 || separate_line_info_table[lt_index].function != function) 7655 { 7656 current_file = 1; 7657 current_line = 1; 7658 7659 /* Emit debug info for the address of the end of the function. */ 7660 ASM_GENERATE_INTERNAL_LABEL (line_label, FUNC_END_LABEL, function); 7661 if (0) 7662 { 7663 dw2_asm_output_data (1, DW_LNS_fixed_advance_pc, 7664 "DW_LNS_fixed_advance_pc"); 7665 dw2_asm_output_delta (2, line_label, prev_line_label, NULL); 7666 } 7667 else 7668 { 7669 dw2_asm_output_data (1, 0, "DW_LNE_set_address"); 7670 dw2_asm_output_data_uleb128 (1 + DWARF2_ADDR_SIZE, NULL); 7671 dw2_asm_output_data (1, DW_LNE_set_address, NULL); 7672 dw2_asm_output_addr (DWARF2_ADDR_SIZE, line_label, NULL); 7673 } 7674 7675 /* Output the marker for the end of this sequence. */ 7676 dw2_asm_output_data (1, 0, "DW_LNE_end_sequence"); 7677 dw2_asm_output_data_uleb128 (1, NULL); 7678 dw2_asm_output_data (1, DW_LNE_end_sequence, NULL); 7679 } 7680 } 7681 7682 /* Output the marker for the end of the line number info. */ 7683 ASM_OUTPUT_LABEL (asm_out_file, l2); 7684} 7685 7686/* Given a pointer to a tree node for some base type, return a pointer to 7687 a DIE that describes the given type. 7688 7689 This routine must only be called for GCC type nodes that correspond to 7690 Dwarf base (fundamental) types. */ 7691 7692static dw_die_ref 7693base_type_die (type) 7694 tree type; 7695{ 7696 dw_die_ref base_type_result; 7697 const char *type_name; 7698 enum dwarf_type encoding; 7699 tree name = TYPE_NAME (type); 7700 7701 if (TREE_CODE (type) == ERROR_MARK || TREE_CODE (type) == VOID_TYPE) 7702 return 0; 7703 7704 if (name) 7705 { 7706 if (TREE_CODE (name) == TYPE_DECL) 7707 name = DECL_NAME (name); 7708 7709 type_name = IDENTIFIER_POINTER (name); 7710 } 7711 else 7712 type_name = "__unknown__"; 7713 7714 switch (TREE_CODE (type)) 7715 { 7716 case INTEGER_TYPE: 7717 /* Carefully distinguish the C character types, without messing 7718 up if the language is not C. Note that we check only for the names 7719 that contain spaces; other names might occur by coincidence in other 7720 languages. */ 7721 if (! (TYPE_PRECISION (type) == CHAR_TYPE_SIZE 7722 && (type == char_type_node 7723 || ! strcmp (type_name, "signed char") 7724 || ! strcmp (type_name, "unsigned char")))) 7725 { 7726 if (TREE_UNSIGNED (type)) 7727 encoding = DW_ATE_unsigned; 7728 else 7729 encoding = DW_ATE_signed; 7730 break; 7731 } 7732 /* else fall through. */ 7733 7734 case CHAR_TYPE: 7735 /* GNU Pascal/Ada CHAR type. Not used in C. */ 7736 if (TREE_UNSIGNED (type)) 7737 encoding = DW_ATE_unsigned_char; 7738 else 7739 encoding = DW_ATE_signed_char; 7740 break; 7741 7742 case REAL_TYPE: 7743 encoding = DW_ATE_float; 7744 break; 7745 7746 /* Dwarf2 doesn't know anything about complex ints, so use 7747 a user defined type for it. */ 7748 case COMPLEX_TYPE: 7749 if (TREE_CODE (TREE_TYPE (type)) == REAL_TYPE) 7750 encoding = DW_ATE_complex_float; 7751 else 7752 encoding = DW_ATE_lo_user; 7753 break; 7754 7755 case BOOLEAN_TYPE: 7756 /* GNU FORTRAN/Ada/C++ BOOLEAN type. */ 7757 encoding = DW_ATE_boolean; 7758 break; 7759 7760 default: 7761 /* No other TREE_CODEs are Dwarf fundamental types. */ 7762 abort (); 7763 } 7764 7765 base_type_result = new_die (DW_TAG_base_type, comp_unit_die, type); 7766 if (demangle_name_func) 7767 type_name = (*demangle_name_func) (type_name); 7768 7769 add_AT_string (base_type_result, DW_AT_name, type_name); 7770 add_AT_unsigned (base_type_result, DW_AT_byte_size, 7771 int_size_in_bytes (type)); 7772 add_AT_unsigned (base_type_result, DW_AT_encoding, encoding); 7773 7774 return base_type_result; 7775} 7776 7777/* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to 7778 the Dwarf "root" type for the given input type. The Dwarf "root" type of 7779 a given type is generally the same as the given type, except that if the 7780 given type is a pointer or reference type, then the root type of the given 7781 type is the root type of the "basis" type for the pointer or reference 7782 type. (This definition of the "root" type is recursive.) Also, the root 7783 type of a `const' qualified type or a `volatile' qualified type is the 7784 root type of the given type without the qualifiers. */ 7785 7786static tree 7787root_type (type) 7788 tree type; 7789{ 7790 if (TREE_CODE (type) == ERROR_MARK) 7791 return error_mark_node; 7792 7793 switch (TREE_CODE (type)) 7794 { 7795 case ERROR_MARK: 7796 return error_mark_node; 7797 7798 case POINTER_TYPE: 7799 case REFERENCE_TYPE: 7800 return type_main_variant (root_type (TREE_TYPE (type))); 7801 7802 default: 7803 return type_main_variant (type); 7804 } 7805} 7806 7807/* Given a pointer to an arbitrary ..._TYPE tree node, return nonzero if the 7808 given input type is a Dwarf "fundamental" type. Otherwise return null. */ 7809 7810static inline int 7811is_base_type (type) 7812 tree type; 7813{ 7814 switch (TREE_CODE (type)) 7815 { 7816 case ERROR_MARK: 7817 case VOID_TYPE: 7818 case INTEGER_TYPE: 7819 case REAL_TYPE: 7820 case COMPLEX_TYPE: 7821 case BOOLEAN_TYPE: 7822 case CHAR_TYPE: 7823 return 1; 7824 7825 case SET_TYPE: 7826 case ARRAY_TYPE: 7827 case RECORD_TYPE: 7828 case UNION_TYPE: 7829 case QUAL_UNION_TYPE: 7830 case ENUMERAL_TYPE: 7831 case FUNCTION_TYPE: 7832 case METHOD_TYPE: 7833 case POINTER_TYPE: 7834 case REFERENCE_TYPE: 7835 case FILE_TYPE: 7836 case OFFSET_TYPE: 7837 case LANG_TYPE: 7838 case VECTOR_TYPE: 7839 return 0; 7840 7841 default: 7842 abort (); 7843 } 7844 7845 return 0; 7846} 7847 7848/* Given a pointer to an arbitrary ..._TYPE tree node, return a debugging 7849 entry that chains various modifiers in front of the given type. */ 7850 7851static dw_die_ref 7852modified_type_die (type, is_const_type, is_volatile_type, context_die) 7853 tree type; 7854 int is_const_type; 7855 int is_volatile_type; 7856 dw_die_ref context_die; 7857{ 7858 enum tree_code code = TREE_CODE (type); 7859 dw_die_ref mod_type_die = NULL; 7860 dw_die_ref sub_die = NULL; 7861 tree item_type = NULL; 7862 7863 if (code != ERROR_MARK) 7864 { 7865 tree qualified_type; 7866 7867 /* See if we already have the appropriately qualified variant of 7868 this type. */ 7869 qualified_type 7870 = get_qualified_type (type, 7871 ((is_const_type ? TYPE_QUAL_CONST : 0) 7872 | (is_volatile_type 7873 ? TYPE_QUAL_VOLATILE : 0))); 7874 7875 /* If we do, then we can just use its DIE, if it exists. */ 7876 if (qualified_type) 7877 { 7878 mod_type_die = lookup_type_die (qualified_type); 7879 if (mod_type_die) 7880 return mod_type_die; 7881 } 7882 7883 /* Handle C typedef types. */ 7884 if (qualified_type && TYPE_NAME (qualified_type) 7885 && TREE_CODE (TYPE_NAME (qualified_type)) == TYPE_DECL 7886 && DECL_ORIGINAL_TYPE (TYPE_NAME (qualified_type))) 7887 { 7888 tree type_name = TYPE_NAME (qualified_type); 7889 tree dtype = TREE_TYPE (type_name); 7890 7891 if (qualified_type == dtype) 7892 { 7893 /* For a named type, use the typedef. */ 7894 gen_type_die (qualified_type, context_die); 7895 mod_type_die = lookup_type_die (qualified_type); 7896 } 7897 else if (is_const_type < TYPE_READONLY (dtype) 7898 || is_volatile_type < TYPE_VOLATILE (dtype)) 7899 /* cv-unqualified version of named type. Just use the unnamed 7900 type to which it refers. */ 7901 mod_type_die 7902 = modified_type_die (DECL_ORIGINAL_TYPE (type_name), 7903 is_const_type, is_volatile_type, 7904 context_die); 7905 7906 /* Else cv-qualified version of named type; fall through. */ 7907 } 7908 7909 if (mod_type_die) 7910 /* OK. */ 7911 ; 7912 else if (is_const_type) 7913 { 7914 mod_type_die = new_die (DW_TAG_const_type, comp_unit_die, type); 7915 sub_die = modified_type_die (type, 0, is_volatile_type, context_die); 7916 } 7917 else if (is_volatile_type) 7918 { 7919 mod_type_die = new_die (DW_TAG_volatile_type, comp_unit_die, type); 7920 sub_die = modified_type_die (type, 0, 0, context_die); 7921 } 7922 else if (code == POINTER_TYPE) 7923 { 7924 mod_type_die = new_die (DW_TAG_pointer_type, comp_unit_die, type); 7925 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); 7926#if 0 7927 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); 7928#endif 7929 item_type = TREE_TYPE (type); 7930 } 7931 else if (code == REFERENCE_TYPE) 7932 { 7933 mod_type_die = new_die (DW_TAG_reference_type, comp_unit_die, type); 7934 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); 7935#if 0 7936 add_AT_unsigned (mod_type_die, DW_AT_address_class, 0); 7937#endif 7938 item_type = TREE_TYPE (type); 7939 } 7940 else if (is_base_type (type)) 7941 mod_type_die = base_type_die (type); 7942 else 7943 { 7944 gen_type_die (type, context_die); 7945 7946 /* We have to get the type_main_variant here (and pass that to the 7947 `lookup_type_die' routine) because the ..._TYPE node we have 7948 might simply be a *copy* of some original type node (where the 7949 copy was created to help us keep track of typedef names) and 7950 that copy might have a different TYPE_UID from the original 7951 ..._TYPE node. */ 7952 if (TREE_CODE (type) != VECTOR_TYPE) 7953 mod_type_die = lookup_type_die (type_main_variant (type)); 7954 else 7955 /* Vectors have the debugging information in the type, 7956 not the main variant. */ 7957 mod_type_die = lookup_type_die (type); 7958 if (mod_type_die == NULL) 7959 abort (); 7960 } 7961 7962 /* We want to equate the qualified type to the die below. */ 7963 type = qualified_type; 7964 } 7965 7966 if (type) 7967 equate_type_number_to_die (type, mod_type_die); 7968 if (item_type) 7969 /* We must do this after the equate_type_number_to_die call, in case 7970 this is a recursive type. This ensures that the modified_type_die 7971 recursion will terminate even if the type is recursive. Recursive 7972 types are possible in Ada. */ 7973 sub_die = modified_type_die (item_type, 7974 TYPE_READONLY (item_type), 7975 TYPE_VOLATILE (item_type), 7976 context_die); 7977 7978 if (sub_die != NULL) 7979 add_AT_die_ref (mod_type_die, DW_AT_type, sub_die); 7980 7981 return mod_type_die; 7982} 7983 7984/* Given a pointer to an arbitrary ..._TYPE tree node, return true if it is 7985 an enumerated type. */ 7986 7987static inline int 7988type_is_enum (type) 7989 tree type; 7990{ 7991 return TREE_CODE (type) == ENUMERAL_TYPE; 7992} 7993 7994/* Return the register number described by a given RTL node. */ 7995 7996static unsigned int 7997reg_number (rtl) 7998 rtx rtl; 7999{ 8000 unsigned regno = REGNO (rtl); 8001 8002 if (regno >= FIRST_PSEUDO_REGISTER) 8003 abort (); 8004 8005 return DBX_REGISTER_NUMBER (regno); 8006} 8007 8008/* Return a location descriptor that designates a machine register or 8009 zero if there is no such. */ 8010 8011static dw_loc_descr_ref 8012reg_loc_descriptor (rtl) 8013 rtx rtl; 8014{ 8015 dw_loc_descr_ref loc_result = NULL; 8016 unsigned reg; 8017 8018 if (REGNO (rtl) >= FIRST_PSEUDO_REGISTER) 8019 return 0; 8020 8021 reg = reg_number (rtl); 8022 if (reg <= 31) 8023 loc_result = new_loc_descr (DW_OP_reg0 + reg, 0, 0); 8024 else 8025 loc_result = new_loc_descr (DW_OP_regx, reg, 0); 8026 8027 return loc_result; 8028} 8029 8030/* Return a location descriptor that designates a constant. */ 8031 8032static dw_loc_descr_ref 8033int_loc_descriptor (i) 8034 HOST_WIDE_INT i; 8035{ 8036 enum dwarf_location_atom op; 8037 8038 /* Pick the smallest representation of a constant, rather than just 8039 defaulting to the LEB encoding. */ 8040 if (i >= 0) 8041 { 8042 if (i <= 31) 8043 op = DW_OP_lit0 + i; 8044 else if (i <= 0xff) 8045 op = DW_OP_const1u; 8046 else if (i <= 0xffff) 8047 op = DW_OP_const2u; 8048 else if (HOST_BITS_PER_WIDE_INT == 32 8049 || i <= 0xffffffff) 8050 op = DW_OP_const4u; 8051 else 8052 op = DW_OP_constu; 8053 } 8054 else 8055 { 8056 if (i >= -0x80) 8057 op = DW_OP_const1s; 8058 else if (i >= -0x8000) 8059 op = DW_OP_const2s; 8060 else if (HOST_BITS_PER_WIDE_INT == 32 8061 || i >= -0x80000000) 8062 op = DW_OP_const4s; 8063 else 8064 op = DW_OP_consts; 8065 } 8066 8067 return new_loc_descr (op, i, 0); 8068} 8069 8070/* Return a location descriptor that designates a base+offset location. */ 8071 8072static dw_loc_descr_ref 8073based_loc_descr (reg, offset) 8074 unsigned reg; 8075 long int offset; 8076{ 8077 dw_loc_descr_ref loc_result; 8078 /* For the "frame base", we use the frame pointer or stack pointer 8079 registers, since the RTL for local variables is relative to one of 8080 them. */ 8081 unsigned fp_reg = DBX_REGISTER_NUMBER (frame_pointer_needed 8082 ? HARD_FRAME_POINTER_REGNUM 8083 : STACK_POINTER_REGNUM); 8084 8085 if (reg == fp_reg) 8086 loc_result = new_loc_descr (DW_OP_fbreg, offset, 0); 8087 else if (reg <= 31) 8088 loc_result = new_loc_descr (DW_OP_breg0 + reg, offset, 0); 8089 else 8090 loc_result = new_loc_descr (DW_OP_bregx, reg, offset); 8091 8092 return loc_result; 8093} 8094 8095/* Return true if this RTL expression describes a base+offset calculation. */ 8096 8097static inline int 8098is_based_loc (rtl) 8099 rtx rtl; 8100{ 8101 return (GET_CODE (rtl) == PLUS 8102 && ((GET_CODE (XEXP (rtl, 0)) == REG 8103 && REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER 8104 && GET_CODE (XEXP (rtl, 1)) == CONST_INT))); 8105} 8106 8107/* The following routine converts the RTL for a variable or parameter 8108 (resident in memory) into an equivalent Dwarf representation of a 8109 mechanism for getting the address of that same variable onto the top of a 8110 hypothetical "address evaluation" stack. 8111 8112 When creating memory location descriptors, we are effectively transforming 8113 the RTL for a memory-resident object into its Dwarf postfix expression 8114 equivalent. This routine recursively descends an RTL tree, turning 8115 it into Dwarf postfix code as it goes. 8116 8117 MODE is the mode of the memory reference, needed to handle some 8118 autoincrement addressing modes. 8119 8120 Return 0 if we can't represent the location. */ 8121 8122static dw_loc_descr_ref 8123mem_loc_descriptor (rtl, mode) 8124 rtx rtl; 8125 enum machine_mode mode; 8126{ 8127 dw_loc_descr_ref mem_loc_result = NULL; 8128 8129 /* Note that for a dynamically sized array, the location we will generate a 8130 description of here will be the lowest numbered location which is 8131 actually within the array. That's *not* necessarily the same as the 8132 zeroth element of the array. */ 8133 8134#ifdef ASM_SIMPLIFY_DWARF_ADDR 8135 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); 8136#endif 8137 8138 switch (GET_CODE (rtl)) 8139 { 8140 case POST_INC: 8141 case POST_DEC: 8142 case POST_MODIFY: 8143 /* POST_INC and POST_DEC can be handled just like a SUBREG. So we 8144 just fall into the SUBREG code. */ 8145 8146 /* ... fall through ... */ 8147 8148 case SUBREG: 8149 /* The case of a subreg may arise when we have a local (register) 8150 variable or a formal (register) parameter which doesn't quite fill 8151 up an entire register. For now, just assume that it is 8152 legitimate to make the Dwarf info refer to the whole register which 8153 contains the given subreg. */ 8154 rtl = SUBREG_REG (rtl); 8155 8156 /* ... fall through ... */ 8157 8158 case REG: 8159 /* Whenever a register number forms a part of the description of the 8160 method for calculating the (dynamic) address of a memory resident 8161 object, DWARF rules require the register number be referred to as 8162 a "base register". This distinction is not based in any way upon 8163 what category of register the hardware believes the given register 8164 belongs to. This is strictly DWARF terminology we're dealing with 8165 here. Note that in cases where the location of a memory-resident 8166 data object could be expressed as: OP_ADD (OP_BASEREG (basereg), 8167 OP_CONST (0)) the actual DWARF location descriptor that we generate 8168 may just be OP_BASEREG (basereg). This may look deceptively like 8169 the object in question was allocated to a register (rather than in 8170 memory) so DWARF consumers need to be aware of the subtle 8171 distinction between OP_REG and OP_BASEREG. */ 8172 if (REGNO (rtl) < FIRST_PSEUDO_REGISTER) 8173 mem_loc_result = based_loc_descr (reg_number (rtl), 0); 8174 break; 8175 8176 case MEM: 8177 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); 8178 if (mem_loc_result != 0) 8179 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_deref, 0, 0)); 8180 break; 8181 8182 case LO_SUM: 8183 rtl = XEXP (rtl, 1); 8184 8185 /* ... fall through ... */ 8186 8187 case LABEL_REF: 8188 /* Some ports can transform a symbol ref into a label ref, because 8189 the symbol ref is too far away and has to be dumped into a constant 8190 pool. */ 8191 case CONST: 8192 case SYMBOL_REF: 8193 /* Alternatively, the symbol in the constant pool might be referenced 8194 by a different symbol. */ 8195 if (GET_CODE (rtl) == SYMBOL_REF && CONSTANT_POOL_ADDRESS_P (rtl)) 8196 { 8197 bool marked; 8198 rtx tmp = get_pool_constant_mark (rtl, &marked); 8199 8200 if (GET_CODE (tmp) == SYMBOL_REF) 8201 { 8202 rtl = tmp; 8203 if (CONSTANT_POOL_ADDRESS_P (tmp)) 8204 get_pool_constant_mark (tmp, &marked); 8205 else 8206 marked = true; 8207 } 8208 8209 /* If all references to this pool constant were optimized away, 8210 it was not output and thus we can't represent it. 8211 FIXME: might try to use DW_OP_const_value here, though 8212 DW_OP_piece complicates it. */ 8213 if (!marked) 8214 return 0; 8215 } 8216 8217 mem_loc_result = new_loc_descr (DW_OP_addr, 0, 0); 8218 mem_loc_result->dw_loc_oprnd1.val_class = dw_val_class_addr; 8219 mem_loc_result->dw_loc_oprnd1.v.val_addr = rtl; 8220 VARRAY_PUSH_RTX (used_rtx_varray, rtl); 8221 break; 8222 8223 case PRE_MODIFY: 8224 /* Extract the PLUS expression nested inside and fall into 8225 PLUS code below. */ 8226 rtl = XEXP (rtl, 1); 8227 goto plus; 8228 8229 case PRE_INC: 8230 case PRE_DEC: 8231 /* Turn these into a PLUS expression and fall into the PLUS code 8232 below. */ 8233 rtl = gen_rtx_PLUS (word_mode, XEXP (rtl, 0), 8234 GEN_INT (GET_CODE (rtl) == PRE_INC 8235 ? GET_MODE_UNIT_SIZE (mode) 8236 : -GET_MODE_UNIT_SIZE (mode))); 8237 8238 /* ... fall through ... */ 8239 8240 case PLUS: 8241 plus: 8242 if (is_based_loc (rtl)) 8243 mem_loc_result = based_loc_descr (reg_number (XEXP (rtl, 0)), 8244 INTVAL (XEXP (rtl, 1))); 8245 else 8246 { 8247 mem_loc_result = mem_loc_descriptor (XEXP (rtl, 0), mode); 8248 if (mem_loc_result == 0) 8249 break; 8250 8251 if (GET_CODE (XEXP (rtl, 1)) == CONST_INT 8252 && INTVAL (XEXP (rtl, 1)) >= 0) 8253 add_loc_descr (&mem_loc_result, 8254 new_loc_descr (DW_OP_plus_uconst, 8255 INTVAL (XEXP (rtl, 1)), 0)); 8256 else 8257 { 8258 add_loc_descr (&mem_loc_result, 8259 mem_loc_descriptor (XEXP (rtl, 1), mode)); 8260 add_loc_descr (&mem_loc_result, 8261 new_loc_descr (DW_OP_plus, 0, 0)); 8262 } 8263 } 8264 break; 8265 8266 case MULT: 8267 { 8268 /* If a pseudo-reg is optimized away, it is possible for it to 8269 be replaced with a MEM containing a multiply. */ 8270 dw_loc_descr_ref op0 = mem_loc_descriptor (XEXP (rtl, 0), mode); 8271 dw_loc_descr_ref op1 = mem_loc_descriptor (XEXP (rtl, 1), mode); 8272 8273 if (op0 == 0 || op1 == 0) 8274 break; 8275 8276 mem_loc_result = op0; 8277 add_loc_descr (&mem_loc_result, op1); 8278 add_loc_descr (&mem_loc_result, new_loc_descr (DW_OP_mul, 0, 0)); 8279 break; 8280 } 8281 8282 case CONST_INT: 8283 mem_loc_result = int_loc_descriptor (INTVAL (rtl)); 8284 break; 8285 8286 case ADDRESSOF: 8287 /* If this is a MEM, return its address. Otherwise, we can't 8288 represent this. */ 8289 if (GET_CODE (XEXP (rtl, 0)) == MEM) 8290 return mem_loc_descriptor (XEXP (XEXP (rtl, 0), 0), mode); 8291 else 8292 return 0; 8293 8294 default: 8295 abort (); 8296 } 8297 8298 return mem_loc_result; 8299} 8300 8301/* Return a descriptor that describes the concatenation of two locations. 8302 This is typically a complex variable. */ 8303 8304static dw_loc_descr_ref 8305concat_loc_descriptor (x0, x1) 8306 rtx x0, x1; 8307{ 8308 dw_loc_descr_ref cc_loc_result = NULL; 8309 dw_loc_descr_ref x0_ref = loc_descriptor (x0); 8310 dw_loc_descr_ref x1_ref = loc_descriptor (x1); 8311 8312 if (x0_ref == 0 || x1_ref == 0) 8313 return 0; 8314 8315 cc_loc_result = x0_ref; 8316 add_loc_descr (&cc_loc_result, 8317 new_loc_descr (DW_OP_piece, 8318 GET_MODE_SIZE (GET_MODE (x0)), 0)); 8319 8320 add_loc_descr (&cc_loc_result, x1_ref); 8321 add_loc_descr (&cc_loc_result, 8322 new_loc_descr (DW_OP_piece, 8323 GET_MODE_SIZE (GET_MODE (x1)), 0)); 8324 8325 return cc_loc_result; 8326} 8327 8328/* Output a proper Dwarf location descriptor for a variable or parameter 8329 which is either allocated in a register or in a memory location. For a 8330 register, we just generate an OP_REG and the register number. For a 8331 memory location we provide a Dwarf postfix expression describing how to 8332 generate the (dynamic) address of the object onto the address stack. 8333 8334 If we don't know how to describe it, return 0. */ 8335 8336static dw_loc_descr_ref 8337loc_descriptor (rtl) 8338 rtx rtl; 8339{ 8340 dw_loc_descr_ref loc_result = NULL; 8341 8342 switch (GET_CODE (rtl)) 8343 { 8344 case SUBREG: 8345 /* The case of a subreg may arise when we have a local (register) 8346 variable or a formal (register) parameter which doesn't quite fill 8347 up an entire register. For now, just assume that it is 8348 legitimate to make the Dwarf info refer to the whole register which 8349 contains the given subreg. */ 8350 rtl = SUBREG_REG (rtl); 8351 8352 /* ... fall through ... */ 8353 8354 case REG: 8355 loc_result = reg_loc_descriptor (rtl); 8356 break; 8357 8358 case MEM: 8359 loc_result = mem_loc_descriptor (XEXP (rtl, 0), GET_MODE (rtl)); 8360 break; 8361 8362 case CONCAT: 8363 loc_result = concat_loc_descriptor (XEXP (rtl, 0), XEXP (rtl, 1)); 8364 break; 8365 8366 default: 8367 abort (); 8368 } 8369 8370 return loc_result; 8371} 8372 8373/* Similar, but generate the descriptor from trees instead of rtl. This comes 8374 up particularly with variable length arrays. If ADDRESSP is nonzero, we are 8375 looking for an address. Otherwise, we return a value. If we can't make a 8376 descriptor, return 0. */ 8377 8378static dw_loc_descr_ref 8379loc_descriptor_from_tree (loc, addressp) 8380 tree loc; 8381 int addressp; 8382{ 8383 dw_loc_descr_ref ret, ret1; 8384 int indirect_p = 0; 8385 int unsignedp = TREE_UNSIGNED (TREE_TYPE (loc)); 8386 enum dwarf_location_atom op; 8387 8388 /* ??? Most of the time we do not take proper care for sign/zero 8389 extending the values properly. Hopefully this won't be a real 8390 problem... */ 8391 8392 switch (TREE_CODE (loc)) 8393 { 8394 case ERROR_MARK: 8395 return 0; 8396 8397 case WITH_RECORD_EXPR: 8398 case PLACEHOLDER_EXPR: 8399 /* This case involves extracting fields from an object to determine the 8400 position of other fields. We don't try to encode this here. The 8401 only user of this is Ada, which encodes the needed information using 8402 the names of types. */ 8403 return 0; 8404 8405 case CALL_EXPR: 8406 return 0; 8407 8408 case ADDR_EXPR: 8409 /* We can support this only if we can look through conversions and 8410 find an INDIRECT_EXPR. */ 8411 for (loc = TREE_OPERAND (loc, 0); 8412 TREE_CODE (loc) == CONVERT_EXPR || TREE_CODE (loc) == NOP_EXPR 8413 || TREE_CODE (loc) == NON_LVALUE_EXPR 8414 || TREE_CODE (loc) == VIEW_CONVERT_EXPR 8415 || TREE_CODE (loc) == SAVE_EXPR; 8416 loc = TREE_OPERAND (loc, 0)) 8417 ; 8418 8419 return (TREE_CODE (loc) == INDIRECT_REF 8420 ? loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp) 8421 : 0); 8422 8423 case VAR_DECL: 8424 if (DECL_THREAD_LOCAL (loc)) 8425 { 8426 rtx rtl; 8427 8428#ifndef ASM_OUTPUT_DWARF_DTPREL 8429 /* If this is not defined, we have no way to emit the data. */ 8430 return 0; 8431#endif 8432 8433 /* The way DW_OP_GNU_push_tls_address is specified, we can only 8434 look up addresses of objects in the current module. */ 8435 if (DECL_EXTERNAL (loc)) 8436 return 0; 8437 8438 rtl = rtl_for_decl_location (loc); 8439 if (rtl == NULL_RTX) 8440 return 0; 8441 8442 if (GET_CODE (rtl) != MEM) 8443 return 0; 8444 rtl = XEXP (rtl, 0); 8445 if (! CONSTANT_P (rtl)) 8446 return 0; 8447 8448 ret = new_loc_descr (INTERNAL_DW_OP_tls_addr, 0, 0); 8449 ret->dw_loc_oprnd1.val_class = dw_val_class_addr; 8450 ret->dw_loc_oprnd1.v.val_addr = rtl; 8451 8452 ret1 = new_loc_descr (DW_OP_GNU_push_tls_address, 0, 0); 8453 add_loc_descr (&ret, ret1); 8454 8455 indirect_p = 1; 8456 break; 8457 } 8458 /* FALLTHRU */ 8459 8460 case PARM_DECL: 8461 { 8462 rtx rtl = rtl_for_decl_location (loc); 8463 8464 if (rtl == NULL_RTX) 8465 return 0; 8466 else if (CONSTANT_P (rtl)) 8467 { 8468 ret = new_loc_descr (DW_OP_addr, 0, 0); 8469 ret->dw_loc_oprnd1.val_class = dw_val_class_addr; 8470 ret->dw_loc_oprnd1.v.val_addr = rtl; 8471 indirect_p = 1; 8472 } 8473 else 8474 { 8475 enum machine_mode mode = GET_MODE (rtl); 8476 8477 if (GET_CODE (rtl) == MEM) 8478 { 8479 indirect_p = 1; 8480 rtl = XEXP (rtl, 0); 8481 } 8482 8483 ret = mem_loc_descriptor (rtl, mode); 8484 } 8485 } 8486 break; 8487 8488 case INDIRECT_REF: 8489 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); 8490 indirect_p = 1; 8491 break; 8492 8493 case COMPOUND_EXPR: 8494 return loc_descriptor_from_tree (TREE_OPERAND (loc, 1), addressp); 8495 8496 case NOP_EXPR: 8497 case CONVERT_EXPR: 8498 case NON_LVALUE_EXPR: 8499 case VIEW_CONVERT_EXPR: 8500 case SAVE_EXPR: 8501 return loc_descriptor_from_tree (TREE_OPERAND (loc, 0), addressp); 8502 8503 case COMPONENT_REF: 8504 case BIT_FIELD_REF: 8505 case ARRAY_REF: 8506 case ARRAY_RANGE_REF: 8507 { 8508 tree obj, offset; 8509 HOST_WIDE_INT bitsize, bitpos, bytepos; 8510 enum machine_mode mode; 8511 int volatilep; 8512 8513 obj = get_inner_reference (loc, &bitsize, &bitpos, &offset, &mode, 8514 &unsignedp, &volatilep); 8515 8516 if (obj == loc) 8517 return 0; 8518 8519 ret = loc_descriptor_from_tree (obj, 1); 8520 if (ret == 0 8521 || bitpos % BITS_PER_UNIT != 0 || bitsize % BITS_PER_UNIT != 0) 8522 return 0; 8523 8524 if (offset != NULL_TREE) 8525 { 8526 /* Variable offset. */ 8527 add_loc_descr (&ret, loc_descriptor_from_tree (offset, 0)); 8528 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); 8529 } 8530 8531 if (!addressp) 8532 indirect_p = 1; 8533 8534 bytepos = bitpos / BITS_PER_UNIT; 8535 if (bytepos > 0) 8536 add_loc_descr (&ret, new_loc_descr (DW_OP_plus_uconst, bytepos, 0)); 8537 else if (bytepos < 0) 8538 { 8539 add_loc_descr (&ret, int_loc_descriptor (bytepos)); 8540 add_loc_descr (&ret, new_loc_descr (DW_OP_plus, 0, 0)); 8541 } 8542 break; 8543 } 8544 8545 case INTEGER_CST: 8546 if (host_integerp (loc, 0)) 8547 ret = int_loc_descriptor (tree_low_cst (loc, 0)); 8548 else 8549 return 0; 8550 break; 8551 8552 case TRUTH_AND_EXPR: 8553 case TRUTH_ANDIF_EXPR: 8554 case BIT_AND_EXPR: 8555 op = DW_OP_and; 8556 goto do_binop; 8557 8558 case TRUTH_XOR_EXPR: 8559 case BIT_XOR_EXPR: 8560 op = DW_OP_xor; 8561 goto do_binop; 8562 8563 case TRUTH_OR_EXPR: 8564 case TRUTH_ORIF_EXPR: 8565 case BIT_IOR_EXPR: 8566 op = DW_OP_or; 8567 goto do_binop; 8568 8569 case TRUNC_DIV_EXPR: 8570 op = DW_OP_div; 8571 goto do_binop; 8572 8573 case MINUS_EXPR: 8574 op = DW_OP_minus; 8575 goto do_binop; 8576 8577 case TRUNC_MOD_EXPR: 8578 op = DW_OP_mod; 8579 goto do_binop; 8580 8581 case MULT_EXPR: 8582 op = DW_OP_mul; 8583 goto do_binop; 8584 8585 case LSHIFT_EXPR: 8586 op = DW_OP_shl; 8587 goto do_binop; 8588 8589 case RSHIFT_EXPR: 8590 op = (unsignedp ? DW_OP_shr : DW_OP_shra); 8591 goto do_binop; 8592 8593 case PLUS_EXPR: 8594 if (TREE_CODE (TREE_OPERAND (loc, 1)) == INTEGER_CST 8595 && host_integerp (TREE_OPERAND (loc, 1), 0)) 8596 { 8597 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); 8598 if (ret == 0) 8599 return 0; 8600 8601 add_loc_descr (&ret, 8602 new_loc_descr (DW_OP_plus_uconst, 8603 tree_low_cst (TREE_OPERAND (loc, 1), 8604 0), 8605 0)); 8606 break; 8607 } 8608 8609 op = DW_OP_plus; 8610 goto do_binop; 8611 8612 case LE_EXPR: 8613 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) 8614 return 0; 8615 8616 op = DW_OP_le; 8617 goto do_binop; 8618 8619 case GE_EXPR: 8620 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) 8621 return 0; 8622 8623 op = DW_OP_ge; 8624 goto do_binop; 8625 8626 case LT_EXPR: 8627 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) 8628 return 0; 8629 8630 op = DW_OP_lt; 8631 goto do_binop; 8632 8633 case GT_EXPR: 8634 if (TREE_UNSIGNED (TREE_TYPE (TREE_OPERAND (loc, 0)))) 8635 return 0; 8636 8637 op = DW_OP_gt; 8638 goto do_binop; 8639 8640 case EQ_EXPR: 8641 op = DW_OP_eq; 8642 goto do_binop; 8643 8644 case NE_EXPR: 8645 op = DW_OP_ne; 8646 goto do_binop; 8647 8648 do_binop: 8649 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); 8650 ret1 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); 8651 if (ret == 0 || ret1 == 0) 8652 return 0; 8653 8654 add_loc_descr (&ret, ret1); 8655 add_loc_descr (&ret, new_loc_descr (op, 0, 0)); 8656 break; 8657 8658 case TRUTH_NOT_EXPR: 8659 case BIT_NOT_EXPR: 8660 op = DW_OP_not; 8661 goto do_unop; 8662 8663 case ABS_EXPR: 8664 op = DW_OP_abs; 8665 goto do_unop; 8666 8667 case NEGATE_EXPR: 8668 op = DW_OP_neg; 8669 goto do_unop; 8670 8671 do_unop: 8672 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); 8673 if (ret == 0) 8674 return 0; 8675 8676 add_loc_descr (&ret, new_loc_descr (op, 0, 0)); 8677 break; 8678 8679 case MAX_EXPR: 8680 loc = build (COND_EXPR, TREE_TYPE (loc), 8681 build (LT_EXPR, integer_type_node, 8682 TREE_OPERAND (loc, 0), TREE_OPERAND (loc, 1)), 8683 TREE_OPERAND (loc, 1), TREE_OPERAND (loc, 0)); 8684 8685 /* ... fall through ... */ 8686 8687 case COND_EXPR: 8688 { 8689 dw_loc_descr_ref lhs 8690 = loc_descriptor_from_tree (TREE_OPERAND (loc, 1), 0); 8691 dw_loc_descr_ref rhs 8692 = loc_descriptor_from_tree (TREE_OPERAND (loc, 2), 0); 8693 dw_loc_descr_ref bra_node, jump_node, tmp; 8694 8695 ret = loc_descriptor_from_tree (TREE_OPERAND (loc, 0), 0); 8696 if (ret == 0 || lhs == 0 || rhs == 0) 8697 return 0; 8698 8699 bra_node = new_loc_descr (DW_OP_bra, 0, 0); 8700 add_loc_descr (&ret, bra_node); 8701 8702 add_loc_descr (&ret, rhs); 8703 jump_node = new_loc_descr (DW_OP_skip, 0, 0); 8704 add_loc_descr (&ret, jump_node); 8705 8706 add_loc_descr (&ret, lhs); 8707 bra_node->dw_loc_oprnd1.val_class = dw_val_class_loc; 8708 bra_node->dw_loc_oprnd1.v.val_loc = lhs; 8709 8710 /* ??? Need a node to point the skip at. Use a nop. */ 8711 tmp = new_loc_descr (DW_OP_nop, 0, 0); 8712 add_loc_descr (&ret, tmp); 8713 jump_node->dw_loc_oprnd1.val_class = dw_val_class_loc; 8714 jump_node->dw_loc_oprnd1.v.val_loc = tmp; 8715 } 8716 break; 8717 8718 default: 8719 abort (); 8720 } 8721 8722 /* Show if we can't fill the request for an address. */ 8723 if (addressp && indirect_p == 0) 8724 return 0; 8725 8726 /* If we've got an address and don't want one, dereference. */ 8727 if (!addressp && indirect_p > 0) 8728 { 8729 HOST_WIDE_INT size = int_size_in_bytes (TREE_TYPE (loc)); 8730 8731 if (size > DWARF2_ADDR_SIZE || size == -1) 8732 return 0; 8733 else if (size == DWARF2_ADDR_SIZE) 8734 op = DW_OP_deref; 8735 else 8736 op = DW_OP_deref_size; 8737 8738 add_loc_descr (&ret, new_loc_descr (op, size, 0)); 8739 } 8740 8741 return ret; 8742} 8743 8744/* Given a value, round it up to the lowest multiple of `boundary' 8745 which is not less than the value itself. */ 8746 8747static inline HOST_WIDE_INT 8748ceiling (value, boundary) 8749 HOST_WIDE_INT value; 8750 unsigned int boundary; 8751{ 8752 return (((value + boundary - 1) / boundary) * boundary); 8753} 8754 8755/* Given a pointer to what is assumed to be a FIELD_DECL node, return a 8756 pointer to the declared type for the relevant field variable, or return 8757 `integer_type_node' if the given node turns out to be an 8758 ERROR_MARK node. */ 8759 8760static inline tree 8761field_type (decl) 8762 tree decl; 8763{ 8764 tree type; 8765 8766 if (TREE_CODE (decl) == ERROR_MARK) 8767 return integer_type_node; 8768 8769 type = DECL_BIT_FIELD_TYPE (decl); 8770 if (type == NULL_TREE) 8771 type = TREE_TYPE (decl); 8772 8773 return type; 8774} 8775 8776/* Given a pointer to a tree node, return the alignment in bits for 8777 it, or else return BITS_PER_WORD if the node actually turns out to 8778 be an ERROR_MARK node. */ 8779 8780static inline unsigned 8781simple_type_align_in_bits (type) 8782 tree type; 8783{ 8784 return (TREE_CODE (type) != ERROR_MARK) ? TYPE_ALIGN (type) : BITS_PER_WORD; 8785} 8786 8787static inline unsigned 8788simple_decl_align_in_bits (decl) 8789 tree decl; 8790{ 8791 return (TREE_CODE (decl) != ERROR_MARK) ? DECL_ALIGN (decl) : BITS_PER_WORD; 8792} 8793 8794/* Given a pointer to a tree node, assumed to be some kind of a ..._TYPE 8795 node, return the size in bits for the type if it is a constant, or else 8796 return the alignment for the type if the type's size is not constant, or 8797 else return BITS_PER_WORD if the type actually turns out to be an 8798 ERROR_MARK node. */ 8799 8800static inline unsigned HOST_WIDE_INT 8801simple_type_size_in_bits (type) 8802 tree type; 8803{ 8804 8805 if (TREE_CODE (type) == ERROR_MARK) 8806 return BITS_PER_WORD; 8807 else if (TYPE_SIZE (type) == NULL_TREE) 8808 return 0; 8809 else if (host_integerp (TYPE_SIZE (type), 1)) 8810 return tree_low_cst (TYPE_SIZE (type), 1); 8811 else 8812 return TYPE_ALIGN (type); 8813} 8814 8815/* Given a pointer to a FIELD_DECL, compute and return the byte offset of the 8816 lowest addressed byte of the "containing object" for the given FIELD_DECL, 8817 or return 0 if we are unable to determine what that offset is, either 8818 because the argument turns out to be a pointer to an ERROR_MARK node, or 8819 because the offset is actually variable. (We can't handle the latter case 8820 just yet). */ 8821 8822static HOST_WIDE_INT 8823field_byte_offset (decl) 8824 tree decl; 8825{ 8826 unsigned int type_align_in_bits; 8827 unsigned int decl_align_in_bits; 8828 unsigned HOST_WIDE_INT type_size_in_bits; 8829 HOST_WIDE_INT object_offset_in_bits; 8830 tree type; 8831 tree field_size_tree; 8832 HOST_WIDE_INT bitpos_int; 8833 HOST_WIDE_INT deepest_bitpos; 8834 unsigned HOST_WIDE_INT field_size_in_bits; 8835 8836 if (TREE_CODE (decl) == ERROR_MARK) 8837 return 0; 8838 else if (TREE_CODE (decl) != FIELD_DECL) 8839 abort (); 8840 8841 type = field_type (decl); 8842 field_size_tree = DECL_SIZE (decl); 8843 8844 /* The size could be unspecified if there was an error, or for 8845 a flexible array member. */ 8846 if (! field_size_tree) 8847 field_size_tree = bitsize_zero_node; 8848 8849 /* We cannot yet cope with fields whose positions are variable, so 8850 for now, when we see such things, we simply return 0. Someday, we may 8851 be able to handle such cases, but it will be damn difficult. */ 8852 if (! host_integerp (bit_position (decl), 0)) 8853 return 0; 8854 8855 bitpos_int = int_bit_position (decl); 8856 8857 /* If we don't know the size of the field, pretend it's a full word. */ 8858 if (host_integerp (field_size_tree, 1)) 8859 field_size_in_bits = tree_low_cst (field_size_tree, 1); 8860 else 8861 field_size_in_bits = BITS_PER_WORD; 8862 8863 type_size_in_bits = simple_type_size_in_bits (type); 8864 type_align_in_bits = simple_type_align_in_bits (type); 8865 decl_align_in_bits = simple_decl_align_in_bits (decl); 8866 8867 /* The GCC front-end doesn't make any attempt to keep track of the starting 8868 bit offset (relative to the start of the containing structure type) of the 8869 hypothetical "containing object" for a bit-field. Thus, when computing 8870 the byte offset value for the start of the "containing object" of a 8871 bit-field, we must deduce this information on our own. This can be rather 8872 tricky to do in some cases. For example, handling the following structure 8873 type definition when compiling for an i386/i486 target (which only aligns 8874 long long's to 32-bit boundaries) can be very tricky: 8875 8876 struct S { int field1; long long field2:31; }; 8877 8878 Fortunately, there is a simple rule-of-thumb which can be used in such 8879 cases. When compiling for an i386/i486, GCC will allocate 8 bytes for the 8880 structure shown above. It decides to do this based upon one simple rule 8881 for bit-field allocation. GCC allocates each "containing object" for each 8882 bit-field at the first (i.e. lowest addressed) legitimate alignment 8883 boundary (based upon the required minimum alignment for the declared type 8884 of the field) which it can possibly use, subject to the condition that 8885 there is still enough available space remaining in the containing object 8886 (when allocated at the selected point) to fully accommodate all of the 8887 bits of the bit-field itself. 8888 8889 This simple rule makes it obvious why GCC allocates 8 bytes for each 8890 object of the structure type shown above. When looking for a place to 8891 allocate the "containing object" for `field2', the compiler simply tries 8892 to allocate a 64-bit "containing object" at each successive 32-bit 8893 boundary (starting at zero) until it finds a place to allocate that 64- 8894 bit field such that at least 31 contiguous (and previously unallocated) 8895 bits remain within that selected 64 bit field. (As it turns out, for the 8896 example above, the compiler finds it is OK to allocate the "containing 8897 object" 64-bit field at bit-offset zero within the structure type.) 8898 8899 Here we attempt to work backwards from the limited set of facts we're 8900 given, and we try to deduce from those facts, where GCC must have believed 8901 that the containing object started (within the structure type). The value 8902 we deduce is then used (by the callers of this routine) to generate 8903 DW_AT_location and DW_AT_bit_offset attributes for fields (both bit-fields 8904 and, in the case of DW_AT_location, regular fields as well). */ 8905 8906 /* Figure out the bit-distance from the start of the structure to the 8907 "deepest" bit of the bit-field. */ 8908 deepest_bitpos = bitpos_int + field_size_in_bits; 8909 8910 /* This is the tricky part. Use some fancy footwork to deduce where the 8911 lowest addressed bit of the containing object must be. */ 8912 object_offset_in_bits = deepest_bitpos - type_size_in_bits; 8913 8914 /* Round up to type_align by default. This works best for bitfields. */ 8915 object_offset_in_bits += type_align_in_bits - 1; 8916 object_offset_in_bits /= type_align_in_bits; 8917 object_offset_in_bits *= type_align_in_bits; 8918 8919 if (object_offset_in_bits > bitpos_int) 8920 { 8921 /* Sigh, the decl must be packed. */ 8922 object_offset_in_bits = deepest_bitpos - type_size_in_bits; 8923 8924 /* Round up to decl_align instead. */ 8925 object_offset_in_bits += decl_align_in_bits - 1; 8926 object_offset_in_bits /= decl_align_in_bits; 8927 object_offset_in_bits *= decl_align_in_bits; 8928 } 8929 8930 return object_offset_in_bits / BITS_PER_UNIT; 8931} 8932 8933/* The following routines define various Dwarf attributes and any data 8934 associated with them. */ 8935 8936/* Add a location description attribute value to a DIE. 8937 8938 This emits location attributes suitable for whole variables and 8939 whole parameters. Note that the location attributes for struct fields are 8940 generated by the routine `data_member_location_attribute' below. */ 8941 8942static inline void 8943add_AT_location_description (die, attr_kind, descr) 8944 dw_die_ref die; 8945 enum dwarf_attribute attr_kind; 8946 dw_loc_descr_ref descr; 8947{ 8948 if (descr != 0) 8949 add_AT_loc (die, attr_kind, descr); 8950} 8951 8952/* Attach the specialized form of location attribute used for data members of 8953 struct and union types. In the special case of a FIELD_DECL node which 8954 represents a bit-field, the "offset" part of this special location 8955 descriptor must indicate the distance in bytes from the lowest-addressed 8956 byte of the containing struct or union type to the lowest-addressed byte of 8957 the "containing object" for the bit-field. (See the `field_byte_offset' 8958 function above). 8959 8960 For any given bit-field, the "containing object" is a hypothetical object 8961 (of some integral or enum type) within which the given bit-field lives. The 8962 type of this hypothetical "containing object" is always the same as the 8963 declared type of the individual bit-field itself (for GCC anyway... the 8964 DWARF spec doesn't actually mandate this). Note that it is the size (in 8965 bytes) of the hypothetical "containing object" which will be given in the 8966 DW_AT_byte_size attribute for this bit-field. (See the 8967 `byte_size_attribute' function below.) It is also used when calculating the 8968 value of the DW_AT_bit_offset attribute. (See the `bit_offset_attribute' 8969 function below.) */ 8970 8971static void 8972add_data_member_location_attribute (die, decl) 8973 dw_die_ref die; 8974 tree decl; 8975{ 8976 long offset; 8977 dw_loc_descr_ref loc_descr = 0; 8978 8979 if (TREE_CODE (decl) == TREE_VEC) 8980 { 8981 /* We're working on the TAG_inheritance for a base class. */ 8982 if (TREE_VIA_VIRTUAL (decl) && is_cxx ()) 8983 { 8984 /* For C++ virtual bases we can't just use BINFO_OFFSET, as they 8985 aren't at a fixed offset from all (sub)objects of the same 8986 type. We need to extract the appropriate offset from our 8987 vtable. The following dwarf expression means 8988 8989 BaseAddr = ObAddr + *((*ObAddr) - Offset) 8990 8991 This is specific to the V3 ABI, of course. */ 8992 8993 dw_loc_descr_ref tmp; 8994 8995 /* Make a copy of the object address. */ 8996 tmp = new_loc_descr (DW_OP_dup, 0, 0); 8997 add_loc_descr (&loc_descr, tmp); 8998 8999 /* Extract the vtable address. */ 9000 tmp = new_loc_descr (DW_OP_deref, 0, 0); 9001 add_loc_descr (&loc_descr, tmp); 9002 9003 /* Calculate the address of the offset. */ 9004 offset = tree_low_cst (BINFO_VPTR_FIELD (decl), 0); 9005 if (offset >= 0) 9006 abort (); 9007 9008 tmp = int_loc_descriptor (-offset); 9009 add_loc_descr (&loc_descr, tmp); 9010 tmp = new_loc_descr (DW_OP_minus, 0, 0); 9011 add_loc_descr (&loc_descr, tmp); 9012 9013 /* Extract the offset. */ 9014 tmp = new_loc_descr (DW_OP_deref, 0, 0); 9015 add_loc_descr (&loc_descr, tmp); 9016 9017 /* Add it to the object address. */ 9018 tmp = new_loc_descr (DW_OP_plus, 0, 0); 9019 add_loc_descr (&loc_descr, tmp); 9020 } 9021 else 9022 offset = tree_low_cst (BINFO_OFFSET (decl), 0); 9023 } 9024 else 9025 offset = field_byte_offset (decl); 9026 9027 if (! loc_descr) 9028 { 9029 enum dwarf_location_atom op; 9030 9031 /* The DWARF2 standard says that we should assume that the structure 9032 address is already on the stack, so we can specify a structure field 9033 address by using DW_OP_plus_uconst. */ 9034 9035#ifdef MIPS_DEBUGGING_INFO 9036 /* ??? The SGI dwarf reader does not handle the DW_OP_plus_uconst 9037 operator correctly. It works only if we leave the offset on the 9038 stack. */ 9039 op = DW_OP_constu; 9040#else 9041 op = DW_OP_plus_uconst; 9042#endif 9043 9044 loc_descr = new_loc_descr (op, offset, 0); 9045 } 9046 9047 add_AT_loc (die, DW_AT_data_member_location, loc_descr); 9048} 9049 9050/* Attach an DW_AT_const_value attribute for a variable or a parameter which 9051 does not have a "location" either in memory or in a register. These 9052 things can arise in GNU C when a constant is passed as an actual parameter 9053 to an inlined function. They can also arise in C++ where declared 9054 constants do not necessarily get memory "homes". */ 9055 9056static void 9057add_const_value_attribute (die, rtl) 9058 dw_die_ref die; 9059 rtx rtl; 9060{ 9061 switch (GET_CODE (rtl)) 9062 { 9063 case CONST_INT: 9064 /* Note that a CONST_INT rtx could represent either an integer 9065 or a floating-point constant. A CONST_INT is used whenever 9066 the constant will fit into a single word. In all such 9067 cases, the original mode of the constant value is wiped 9068 out, and the CONST_INT rtx is assigned VOIDmode. */ 9069 { 9070 HOST_WIDE_INT val = INTVAL (rtl); 9071 9072 /* ??? We really should be using HOST_WIDE_INT throughout. */ 9073 if (val < 0 && (long) val == val) 9074 add_AT_int (die, DW_AT_const_value, (long) val); 9075 else if ((unsigned long) val == (unsigned HOST_WIDE_INT) val) 9076 add_AT_unsigned (die, DW_AT_const_value, (unsigned long) val); 9077 else 9078 { 9079#if HOST_BITS_PER_LONG * 2 == HOST_BITS_PER_WIDE_INT 9080 add_AT_long_long (die, DW_AT_const_value, 9081 val >> HOST_BITS_PER_LONG, val); 9082#else 9083 abort (); 9084#endif 9085 } 9086 } 9087 break; 9088 9089 case CONST_DOUBLE: 9090 /* Note that a CONST_DOUBLE rtx could represent either an integer or a 9091 floating-point constant. A CONST_DOUBLE is used whenever the 9092 constant requires more than one word in order to be adequately 9093 represented. We output CONST_DOUBLEs as blocks. */ 9094 { 9095 enum machine_mode mode = GET_MODE (rtl); 9096 9097 if (GET_MODE_CLASS (mode) == MODE_FLOAT) 9098 { 9099 unsigned length = GET_MODE_SIZE (mode) / 4; 9100 long *array = (long *) xmalloc (sizeof (long) * length); 9101 REAL_VALUE_TYPE rv; 9102 9103 REAL_VALUE_FROM_CONST_DOUBLE (rv, rtl); 9104 switch (mode) 9105 { 9106 case SFmode: 9107 REAL_VALUE_TO_TARGET_SINGLE (rv, array[0]); 9108 break; 9109 9110 case DFmode: 9111 REAL_VALUE_TO_TARGET_DOUBLE (rv, array); 9112 break; 9113 9114 case XFmode: 9115 case TFmode: 9116 REAL_VALUE_TO_TARGET_LONG_DOUBLE (rv, array); 9117 break; 9118 9119 default: 9120 abort (); 9121 } 9122 9123 add_AT_float (die, DW_AT_const_value, length, array); 9124 } 9125 else 9126 { 9127 /* ??? We really should be using HOST_WIDE_INT throughout. */ 9128 if (HOST_BITS_PER_LONG != HOST_BITS_PER_WIDE_INT) 9129 abort (); 9130 9131 add_AT_long_long (die, DW_AT_const_value, 9132 CONST_DOUBLE_HIGH (rtl), CONST_DOUBLE_LOW (rtl)); 9133 } 9134 } 9135 break; 9136 9137 case CONST_STRING: 9138 add_AT_string (die, DW_AT_const_value, XSTR (rtl, 0)); 9139 break; 9140 9141 case SYMBOL_REF: 9142 case LABEL_REF: 9143 case CONST: 9144 add_AT_addr (die, DW_AT_const_value, rtl); 9145 VARRAY_PUSH_RTX (used_rtx_varray, rtl); 9146 break; 9147 9148 case PLUS: 9149 /* In cases where an inlined instance of an inline function is passed 9150 the address of an `auto' variable (which is local to the caller) we 9151 can get a situation where the DECL_RTL of the artificial local 9152 variable (for the inlining) which acts as a stand-in for the 9153 corresponding formal parameter (of the inline function) will look 9154 like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). This is not 9155 exactly a compile-time constant expression, but it isn't the address 9156 of the (artificial) local variable either. Rather, it represents the 9157 *value* which the artificial local variable always has during its 9158 lifetime. We currently have no way to represent such quasi-constant 9159 values in Dwarf, so for now we just punt and generate nothing. */ 9160 break; 9161 9162 default: 9163 /* No other kinds of rtx should be possible here. */ 9164 abort (); 9165 } 9166 9167} 9168 9169static rtx 9170rtl_for_decl_location (decl) 9171 tree decl; 9172{ 9173 rtx rtl; 9174 9175 /* Here we have to decide where we are going to say the parameter "lives" 9176 (as far as the debugger is concerned). We only have a couple of 9177 choices. GCC provides us with DECL_RTL and with DECL_INCOMING_RTL. 9178 9179 DECL_RTL normally indicates where the parameter lives during most of the 9180 activation of the function. If optimization is enabled however, this 9181 could be either NULL or else a pseudo-reg. Both of those cases indicate 9182 that the parameter doesn't really live anywhere (as far as the code 9183 generation parts of GCC are concerned) during most of the function's 9184 activation. That will happen (for example) if the parameter is never 9185 referenced within the function. 9186 9187 We could just generate a location descriptor here for all non-NULL 9188 non-pseudo values of DECL_RTL and ignore all of the rest, but we can be 9189 a little nicer than that if we also consider DECL_INCOMING_RTL in cases 9190 where DECL_RTL is NULL or is a pseudo-reg. 9191 9192 Note however that we can only get away with using DECL_INCOMING_RTL as 9193 a backup substitute for DECL_RTL in certain limited cases. In cases 9194 where DECL_ARG_TYPE (decl) indicates the same type as TREE_TYPE (decl), 9195 we can be sure that the parameter was passed using the same type as it is 9196 declared to have within the function, and that its DECL_INCOMING_RTL 9197 points us to a place where a value of that type is passed. 9198 9199 In cases where DECL_ARG_TYPE (decl) and TREE_TYPE (decl) are different, 9200 we cannot (in general) use DECL_INCOMING_RTL as a substitute for DECL_RTL 9201 because in these cases DECL_INCOMING_RTL points us to a value of some 9202 type which is *different* from the type of the parameter itself. Thus, 9203 if we tried to use DECL_INCOMING_RTL to generate a location attribute in 9204 such cases, the debugger would end up (for example) trying to fetch a 9205 `float' from a place which actually contains the first part of a 9206 `double'. That would lead to really incorrect and confusing 9207 output at debug-time. 9208 9209 So, in general, we *do not* use DECL_INCOMING_RTL as a backup for DECL_RTL 9210 in cases where DECL_ARG_TYPE (decl) != TREE_TYPE (decl). There 9211 are a couple of exceptions however. On little-endian machines we can 9212 get away with using DECL_INCOMING_RTL even when DECL_ARG_TYPE (decl) is 9213 not the same as TREE_TYPE (decl), but only when DECL_ARG_TYPE (decl) is 9214 an integral type that is smaller than TREE_TYPE (decl). These cases arise 9215 when (on a little-endian machine) a non-prototyped function has a 9216 parameter declared to be of type `short' or `char'. In such cases, 9217 TREE_TYPE (decl) will be `short' or `char', DECL_ARG_TYPE (decl) will 9218 be `int', and DECL_INCOMING_RTL will point to the lowest-order byte of the 9219 passed `int' value. If the debugger then uses that address to fetch 9220 a `short' or a `char' (on a little-endian machine) the result will be 9221 the correct data, so we allow for such exceptional cases below. 9222 9223 Note that our goal here is to describe the place where the given formal 9224 parameter lives during most of the function's activation (i.e. between the 9225 end of the prologue and the start of the epilogue). We'll do that as best 9226 as we can. Note however that if the given formal parameter is modified 9227 sometime during the execution of the function, then a stack backtrace (at 9228 debug-time) will show the function as having been called with the *new* 9229 value rather than the value which was originally passed in. This happens 9230 rarely enough that it is not a major problem, but it *is* a problem, and 9231 I'd like to fix it. 9232 9233 A future version of dwarf2out.c may generate two additional attributes for 9234 any given DW_TAG_formal_parameter DIE which will describe the "passed 9235 type" and the "passed location" for the given formal parameter in addition 9236 to the attributes we now generate to indicate the "declared type" and the 9237 "active location" for each parameter. This additional set of attributes 9238 could be used by debuggers for stack backtraces. Separately, note that 9239 sometimes DECL_RTL can be NULL and DECL_INCOMING_RTL can be NULL also. 9240 This happens (for example) for inlined-instances of inline function formal 9241 parameters which are never referenced. This really shouldn't be 9242 happening. All PARM_DECL nodes should get valid non-NULL 9243 DECL_INCOMING_RTL values, but integrate.c doesn't currently generate these 9244 values for inlined instances of inline function parameters, so when we see 9245 such cases, we are just out-of-luck for the time being (until integrate.c 9246 gets fixed). */ 9247 9248 /* Use DECL_RTL as the "location" unless we find something better. */ 9249 rtl = DECL_RTL_IF_SET (decl); 9250 9251 /* When generating abstract instances, ignore everything except 9252 constants, symbols living in memory, and symbols living in 9253 fixed registers. */ 9254 if (! reload_completed) 9255 { 9256 if (rtl 9257 && (CONSTANT_P (rtl) 9258 || (GET_CODE (rtl) == MEM 9259 && CONSTANT_P (XEXP (rtl, 0))) 9260 || (GET_CODE (rtl) == REG 9261 && TREE_CODE (decl) == VAR_DECL 9262 && TREE_STATIC (decl)))) 9263 { 9264#ifdef ASM_SIMPLIFY_DWARF_ADDR 9265 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); 9266#endif 9267 return rtl; 9268 } 9269 rtl = NULL_RTX; 9270 } 9271 else if (TREE_CODE (decl) == PARM_DECL) 9272 { 9273 if (rtl == NULL_RTX || is_pseudo_reg (rtl)) 9274 { 9275 tree declared_type = type_main_variant (TREE_TYPE (decl)); 9276 tree passed_type = type_main_variant (DECL_ARG_TYPE (decl)); 9277 9278 /* This decl represents a formal parameter which was optimized out. 9279 Note that DECL_INCOMING_RTL may be NULL in here, but we handle 9280 all cases where (rtl == NULL_RTX) just below. */ 9281 if (declared_type == passed_type) 9282 rtl = DECL_INCOMING_RTL (decl); 9283 else if (! BYTES_BIG_ENDIAN 9284 && TREE_CODE (declared_type) == INTEGER_TYPE 9285 && (GET_MODE_SIZE (TYPE_MODE (declared_type)) 9286 <= GET_MODE_SIZE (TYPE_MODE (passed_type)))) 9287 rtl = DECL_INCOMING_RTL (decl); 9288 } 9289 9290 /* If the parm was passed in registers, but lives on the stack, then 9291 make a big endian correction if the mode of the type of the 9292 parameter is not the same as the mode of the rtl. */ 9293 /* ??? This is the same series of checks that are made in dbxout.c before 9294 we reach the big endian correction code there. It isn't clear if all 9295 of these checks are necessary here, but keeping them all is the safe 9296 thing to do. */ 9297 else if (GET_CODE (rtl) == MEM 9298 && XEXP (rtl, 0) != const0_rtx 9299 && ! CONSTANT_P (XEXP (rtl, 0)) 9300 /* Not passed in memory. */ 9301 && GET_CODE (DECL_INCOMING_RTL (decl)) != MEM 9302 /* Not passed by invisible reference. */ 9303 && (GET_CODE (XEXP (rtl, 0)) != REG 9304 || REGNO (XEXP (rtl, 0)) == HARD_FRAME_POINTER_REGNUM 9305 || REGNO (XEXP (rtl, 0)) == STACK_POINTER_REGNUM 9306#if ARG_POINTER_REGNUM != HARD_FRAME_POINTER_REGNUM 9307 || REGNO (XEXP (rtl, 0)) == ARG_POINTER_REGNUM 9308#endif 9309 ) 9310 /* Big endian correction check. */ 9311 && BYTES_BIG_ENDIAN 9312 && TYPE_MODE (TREE_TYPE (decl)) != GET_MODE (rtl) 9313 && (GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl))) 9314 < UNITS_PER_WORD)) 9315 { 9316 int offset = (UNITS_PER_WORD 9317 - GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (decl)))); 9318 9319 rtl = gen_rtx_MEM (TYPE_MODE (TREE_TYPE (decl)), 9320 plus_constant (XEXP (rtl, 0), offset)); 9321 } 9322 } 9323 9324 if (rtl != NULL_RTX) 9325 { 9326 rtl = eliminate_regs (rtl, 0, NULL_RTX); 9327#ifdef LEAF_REG_REMAP 9328 if (current_function_uses_only_leaf_regs) 9329 leaf_renumber_regs_insn (rtl); 9330#endif 9331 } 9332 9333 /* A variable with no DECL_RTL but a DECL_INITIAL is a compile-time constant, 9334 and will have been substituted directly into all expressions that use it. 9335 C does not have such a concept, but C++ and other languages do. */ 9336 else if (TREE_CODE (decl) == VAR_DECL && DECL_INITIAL (decl)) 9337 { 9338 /* If a variable is initialized with a string constant without embedded 9339 zeros, build CONST_STRING. */ 9340 if (TREE_CODE (DECL_INITIAL (decl)) == STRING_CST 9341 && TREE_CODE (TREE_TYPE (decl)) == ARRAY_TYPE) 9342 { 9343 tree arrtype = TREE_TYPE (decl); 9344 tree enttype = TREE_TYPE (arrtype); 9345 tree domain = TYPE_DOMAIN (arrtype); 9346 tree init = DECL_INITIAL (decl); 9347 enum machine_mode mode = TYPE_MODE (enttype); 9348 9349 if (GET_MODE_CLASS (mode) == MODE_INT && GET_MODE_SIZE (mode) == 1 9350 && domain 9351 && integer_zerop (TYPE_MIN_VALUE (domain)) 9352 && compare_tree_int (TYPE_MAX_VALUE (domain), 9353 TREE_STRING_LENGTH (init) - 1) == 0 9354 && ((size_t) TREE_STRING_LENGTH (init) 9355 == strlen (TREE_STRING_POINTER (init)) + 1)) 9356 rtl = gen_rtx_CONST_STRING (VOIDmode, TREE_STRING_POINTER (init)); 9357 } 9358 /* If the initializer is something that we know will expand into an 9359 immediate RTL constant, expand it now. Expanding anything else 9360 tends to produce unresolved symbols; see debug/5770 and c++/6381. */ 9361 else if (TREE_CODE (DECL_INITIAL (decl)) == INTEGER_CST 9362 || TREE_CODE (DECL_INITIAL (decl)) == REAL_CST) 9363 { 9364 rtl = expand_expr (DECL_INITIAL (decl), NULL_RTX, VOIDmode, 9365 EXPAND_INITIALIZER); 9366 /* If expand_expr returns a MEM, it wasn't immediate. */ 9367 if (rtl && GET_CODE (rtl) == MEM) 9368 abort (); 9369 } 9370 } 9371 9372#ifdef ASM_SIMPLIFY_DWARF_ADDR 9373 if (rtl) 9374 rtl = ASM_SIMPLIFY_DWARF_ADDR (rtl); 9375#endif 9376 9377 /* If we don't look past the constant pool, we risk emitting a 9378 reference to a constant pool entry that isn't referenced from 9379 code, and thus is not emitted. */ 9380 if (rtl) 9381 rtl = avoid_constant_pool_reference (rtl); 9382 9383 return rtl; 9384} 9385 9386/* Generate *either* an DW_AT_location attribute or else an DW_AT_const_value 9387 data attribute for a variable or a parameter. We generate the 9388 DW_AT_const_value attribute only in those cases where the given variable 9389 or parameter does not have a true "location" either in memory or in a 9390 register. This can happen (for example) when a constant is passed as an 9391 actual argument in a call to an inline function. (It's possible that 9392 these things can crop up in other ways also.) Note that one type of 9393 constant value which can be passed into an inlined function is a constant 9394 pointer. This can happen for example if an actual argument in an inlined 9395 function call evaluates to a compile-time constant address. */ 9396 9397static void 9398add_location_or_const_value_attribute (die, decl) 9399 dw_die_ref die; 9400 tree decl; 9401{ 9402 rtx rtl; 9403 dw_loc_descr_ref descr; 9404 9405 if (TREE_CODE (decl) == ERROR_MARK) 9406 return; 9407 else if (TREE_CODE (decl) != VAR_DECL && TREE_CODE (decl) != PARM_DECL) 9408 abort (); 9409 9410 rtl = rtl_for_decl_location (decl); 9411 if (rtl == NULL_RTX) 9412 return; 9413 9414 switch (GET_CODE (rtl)) 9415 { 9416 case ADDRESSOF: 9417 /* The address of a variable that was optimized away; 9418 don't emit anything. */ 9419 break; 9420 9421 case CONST_INT: 9422 case CONST_DOUBLE: 9423 case CONST_STRING: 9424 case SYMBOL_REF: 9425 case LABEL_REF: 9426 case CONST: 9427 case PLUS: 9428 /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ 9429 add_const_value_attribute (die, rtl); 9430 break; 9431 9432 case MEM: 9433 if (TREE_CODE (decl) == VAR_DECL && DECL_THREAD_LOCAL (decl)) 9434 { 9435 /* Need loc_descriptor_from_tree since that's where we know 9436 how to handle TLS variables. Want the object's address 9437 since the top-level DW_AT_location assumes such. See 9438 the confusion in loc_descriptor for reference. */ 9439 descr = loc_descriptor_from_tree (decl, 1); 9440 } 9441 else 9442 { 9443 case REG: 9444 case SUBREG: 9445 case CONCAT: 9446 descr = loc_descriptor (rtl); 9447 } 9448 add_AT_location_description (die, DW_AT_location, descr); 9449 break; 9450 9451 default: 9452 abort (); 9453 } 9454} 9455 9456/* If we don't have a copy of this variable in memory for some reason (such 9457 as a C++ member constant that doesn't have an out-of-line definition), 9458 we should tell the debugger about the constant value. */ 9459 9460static void 9461tree_add_const_value_attribute (var_die, decl) 9462 dw_die_ref var_die; 9463 tree decl; 9464{ 9465 tree init = DECL_INITIAL (decl); 9466 tree type = TREE_TYPE (decl); 9467 9468 if (TREE_READONLY (decl) && ! TREE_THIS_VOLATILE (decl) && init 9469 && initializer_constant_valid_p (init, type) == null_pointer_node) 9470 /* OK */; 9471 else 9472 return; 9473 9474 switch (TREE_CODE (type)) 9475 { 9476 case INTEGER_TYPE: 9477 if (host_integerp (init, 0)) 9478 add_AT_unsigned (var_die, DW_AT_const_value, 9479 tree_low_cst (init, 0)); 9480 else 9481 add_AT_long_long (var_die, DW_AT_const_value, 9482 TREE_INT_CST_HIGH (init), 9483 TREE_INT_CST_LOW (init)); 9484 break; 9485 9486 default:; 9487 } 9488} 9489 9490/* Generate an DW_AT_name attribute given some string value to be included as 9491 the value of the attribute. */ 9492 9493static inline void 9494add_name_attribute (die, name_string) 9495 dw_die_ref die; 9496 const char *name_string; 9497{ 9498 if (name_string != NULL && *name_string != 0) 9499 { 9500 if (demangle_name_func) 9501 name_string = (*demangle_name_func) (name_string); 9502 9503 add_AT_string (die, DW_AT_name, name_string); 9504 } 9505} 9506 9507/* Given a tree node describing an array bound (either lower or upper) output 9508 a representation for that bound. */ 9509 9510static void 9511add_bound_info (subrange_die, bound_attr, bound) 9512 dw_die_ref subrange_die; 9513 enum dwarf_attribute bound_attr; 9514 tree bound; 9515{ 9516 switch (TREE_CODE (bound)) 9517 { 9518 case ERROR_MARK: 9519 return; 9520 9521 /* All fixed-bounds are represented by INTEGER_CST nodes. */ 9522 case INTEGER_CST: 9523 if (! host_integerp (bound, 0) 9524 || (bound_attr == DW_AT_lower_bound 9525 && (((is_c_family () || is_java ()) && integer_zerop (bound)) 9526 || (is_fortran () && integer_onep (bound))))) 9527 /* use the default */ 9528 ; 9529 else 9530 add_AT_unsigned (subrange_die, bound_attr, tree_low_cst (bound, 0)); 9531 break; 9532 9533 case CONVERT_EXPR: 9534 case NOP_EXPR: 9535 case NON_LVALUE_EXPR: 9536 case VIEW_CONVERT_EXPR: 9537 add_bound_info (subrange_die, bound_attr, TREE_OPERAND (bound, 0)); 9538 break; 9539 9540 case SAVE_EXPR: 9541 /* If optimization is turned on, the SAVE_EXPRs that describe how to 9542 access the upper bound values may be bogus. If they refer to a 9543 register, they may only describe how to get at these values at the 9544 points in the generated code right after they have just been 9545 computed. Worse yet, in the typical case, the upper bound values 9546 will not even *be* computed in the optimized code (though the 9547 number of elements will), so these SAVE_EXPRs are entirely 9548 bogus. In order to compensate for this fact, we check here to see 9549 if optimization is enabled, and if so, we don't add an attribute 9550 for the (unknown and unknowable) upper bound. This should not 9551 cause too much trouble for existing (stupid?) debuggers because 9552 they have to deal with empty upper bounds location descriptions 9553 anyway in order to be able to deal with incomplete array types. 9554 Of course an intelligent debugger (GDB?) should be able to 9555 comprehend that a missing upper bound specification in an array 9556 type used for a storage class `auto' local array variable 9557 indicates that the upper bound is both unknown (at compile- time) 9558 and unknowable (at run-time) due to optimization. 9559 9560 We assume that a MEM rtx is safe because gcc wouldn't put the 9561 value there unless it was going to be used repeatedly in the 9562 function, i.e. for cleanups. */ 9563 if (SAVE_EXPR_RTL (bound) 9564 && (! optimize || GET_CODE (SAVE_EXPR_RTL (bound)) == MEM)) 9565 { 9566 dw_die_ref ctx = lookup_decl_die (current_function_decl); 9567 dw_die_ref decl_die = new_die (DW_TAG_variable, ctx, bound); 9568 rtx loc = SAVE_EXPR_RTL (bound); 9569 9570 /* If the RTL for the SAVE_EXPR is memory, handle the case where 9571 it references an outer function's frame. */ 9572 if (GET_CODE (loc) == MEM) 9573 { 9574 rtx new_addr = fix_lexical_addr (XEXP (loc, 0), bound); 9575 9576 if (XEXP (loc, 0) != new_addr) 9577 loc = gen_rtx_MEM (GET_MODE (loc), new_addr); 9578 } 9579 9580 add_AT_flag (decl_die, DW_AT_artificial, 1); 9581 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); 9582 add_AT_location_description (decl_die, DW_AT_location, 9583 loc_descriptor (loc)); 9584 add_AT_die_ref (subrange_die, bound_attr, decl_die); 9585 } 9586 9587 /* Else leave out the attribute. */ 9588 break; 9589 9590 case VAR_DECL: 9591 case PARM_DECL: 9592 { 9593 dw_die_ref decl_die = lookup_decl_die (bound); 9594 9595 /* ??? Can this happen, or should the variable have been bound 9596 first? Probably it can, since I imagine that we try to create 9597 the types of parameters in the order in which they exist in 9598 the list, and won't have created a forward reference to a 9599 later parameter. */ 9600 if (decl_die != NULL) 9601 add_AT_die_ref (subrange_die, bound_attr, decl_die); 9602 break; 9603 } 9604 9605 default: 9606 { 9607 /* Otherwise try to create a stack operation procedure to 9608 evaluate the value of the array bound. */ 9609 9610 dw_die_ref ctx, decl_die; 9611 dw_loc_descr_ref loc; 9612 9613 loc = loc_descriptor_from_tree (bound, 0); 9614 if (loc == NULL) 9615 break; 9616 9617 if (current_function_decl == 0) 9618 ctx = comp_unit_die; 9619 else 9620 ctx = lookup_decl_die (current_function_decl); 9621 9622 /* If we weren't able to find a context, it's most likely the case 9623 that we are processing the return type of the function. So 9624 make a SAVE_EXPR to point to it and have the limbo DIE code 9625 find the proper die. The save_expr function doesn't always 9626 make a SAVE_EXPR, so do it ourselves. */ 9627 if (ctx == 0) 9628 bound = build (SAVE_EXPR, TREE_TYPE (bound), bound, 9629 current_function_decl, NULL_TREE); 9630 9631 decl_die = new_die (DW_TAG_variable, ctx, bound); 9632 add_AT_flag (decl_die, DW_AT_artificial, 1); 9633 add_type_attribute (decl_die, TREE_TYPE (bound), 1, 0, ctx); 9634 add_AT_loc (decl_die, DW_AT_location, loc); 9635 9636 add_AT_die_ref (subrange_die, bound_attr, decl_die); 9637 break; 9638 } 9639 } 9640} 9641 9642/* Note that the block of subscript information for an array type also 9643 includes information about the element type of type given array type. */ 9644 9645static void 9646add_subscript_info (type_die, type) 9647 dw_die_ref type_die; 9648 tree type; 9649{ 9650#ifndef MIPS_DEBUGGING_INFO 9651 unsigned dimension_number; 9652#endif 9653 tree lower, upper; 9654 dw_die_ref subrange_die; 9655 9656 /* The GNU compilers represent multidimensional array types as sequences of 9657 one dimensional array types whose element types are themselves array 9658 types. Here we squish that down, so that each multidimensional array 9659 type gets only one array_type DIE in the Dwarf debugging info. The draft 9660 Dwarf specification say that we are allowed to do this kind of 9661 compression in C (because there is no difference between an array or 9662 arrays and a multidimensional array in C) but for other source languages 9663 (e.g. Ada) we probably shouldn't do this. */ 9664 9665 /* ??? The SGI dwarf reader fails for multidimensional arrays with a 9666 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. 9667 We work around this by disabling this feature. See also 9668 gen_array_type_die. */ 9669#ifndef MIPS_DEBUGGING_INFO 9670 for (dimension_number = 0; 9671 TREE_CODE (type) == ARRAY_TYPE; 9672 type = TREE_TYPE (type), dimension_number++) 9673#endif 9674 { 9675 tree domain = TYPE_DOMAIN (type); 9676 9677 /* Arrays come in three flavors: Unspecified bounds, fixed bounds, 9678 and (in GNU C only) variable bounds. Handle all three forms 9679 here. */ 9680 subrange_die = new_die (DW_TAG_subrange_type, type_die, NULL); 9681 if (domain) 9682 { 9683 /* We have an array type with specified bounds. */ 9684 lower = TYPE_MIN_VALUE (domain); 9685 upper = TYPE_MAX_VALUE (domain); 9686 9687 /* define the index type. */ 9688 if (TREE_TYPE (domain)) 9689 { 9690 /* ??? This is probably an Ada unnamed subrange type. Ignore the 9691 TREE_TYPE field. We can't emit debug info for this 9692 because it is an unnamed integral type. */ 9693 if (TREE_CODE (domain) == INTEGER_TYPE 9694 && TYPE_NAME (domain) == NULL_TREE 9695 && TREE_CODE (TREE_TYPE (domain)) == INTEGER_TYPE 9696 && TYPE_NAME (TREE_TYPE (domain)) == NULL_TREE) 9697 ; 9698 else 9699 add_type_attribute (subrange_die, TREE_TYPE (domain), 0, 0, 9700 type_die); 9701 } 9702 9703 /* ??? If upper is NULL, the array has unspecified length, 9704 but it does have a lower bound. This happens with Fortran 9705 dimension arr(N:*) 9706 Since the debugger is definitely going to need to know N 9707 to produce useful results, go ahead and output the lower 9708 bound solo, and hope the debugger can cope. */ 9709 9710 add_bound_info (subrange_die, DW_AT_lower_bound, lower); 9711 if (upper) 9712 add_bound_info (subrange_die, DW_AT_upper_bound, upper); 9713 } 9714 9715 /* Otherwise we have an array type with an unspecified length. The 9716 DWARF-2 spec does not say how to handle this; let's just leave out the 9717 bounds. */ 9718 } 9719} 9720 9721static void 9722add_byte_size_attribute (die, tree_node) 9723 dw_die_ref die; 9724 tree tree_node; 9725{ 9726 unsigned size; 9727 9728 switch (TREE_CODE (tree_node)) 9729 { 9730 case ERROR_MARK: 9731 size = 0; 9732 break; 9733 case ENUMERAL_TYPE: 9734 case RECORD_TYPE: 9735 case UNION_TYPE: 9736 case QUAL_UNION_TYPE: 9737 size = int_size_in_bytes (tree_node); 9738 break; 9739 case FIELD_DECL: 9740 /* For a data member of a struct or union, the DW_AT_byte_size is 9741 generally given as the number of bytes normally allocated for an 9742 object of the *declared* type of the member itself. This is true 9743 even for bit-fields. */ 9744 size = simple_type_size_in_bits (field_type (tree_node)) / BITS_PER_UNIT; 9745 break; 9746 default: 9747 abort (); 9748 } 9749 9750 /* Note that `size' might be -1 when we get to this point. If it is, that 9751 indicates that the byte size of the entity in question is variable. We 9752 have no good way of expressing this fact in Dwarf at the present time, 9753 so just let the -1 pass on through. */ 9754 add_AT_unsigned (die, DW_AT_byte_size, size); 9755} 9756 9757/* For a FIELD_DECL node which represents a bit-field, output an attribute 9758 which specifies the distance in bits from the highest order bit of the 9759 "containing object" for the bit-field to the highest order bit of the 9760 bit-field itself. 9761 9762 For any given bit-field, the "containing object" is a hypothetical object 9763 (of some integral or enum type) within which the given bit-field lives. The 9764 type of this hypothetical "containing object" is always the same as the 9765 declared type of the individual bit-field itself. The determination of the 9766 exact location of the "containing object" for a bit-field is rather 9767 complicated. It's handled by the `field_byte_offset' function (above). 9768 9769 Note that it is the size (in bytes) of the hypothetical "containing object" 9770 which will be given in the DW_AT_byte_size attribute for this bit-field. 9771 (See `byte_size_attribute' above). */ 9772 9773static inline void 9774add_bit_offset_attribute (die, decl) 9775 dw_die_ref die; 9776 tree decl; 9777{ 9778 HOST_WIDE_INT object_offset_in_bytes = field_byte_offset (decl); 9779 tree type = DECL_BIT_FIELD_TYPE (decl); 9780 HOST_WIDE_INT bitpos_int; 9781 HOST_WIDE_INT highest_order_object_bit_offset; 9782 HOST_WIDE_INT highest_order_field_bit_offset; 9783 HOST_WIDE_INT unsigned bit_offset; 9784 9785 /* Must be a field and a bit field. */ 9786 if (!type 9787 || TREE_CODE (decl) != FIELD_DECL) 9788 abort (); 9789 9790 /* We can't yet handle bit-fields whose offsets are variable, so if we 9791 encounter such things, just return without generating any attribute 9792 whatsoever. Likewise for variable or too large size. */ 9793 if (! host_integerp (bit_position (decl), 0) 9794 || ! host_integerp (DECL_SIZE (decl), 1)) 9795 return; 9796 9797 bitpos_int = int_bit_position (decl); 9798 9799 /* Note that the bit offset is always the distance (in bits) from the 9800 highest-order bit of the "containing object" to the highest-order bit of 9801 the bit-field itself. Since the "high-order end" of any object or field 9802 is different on big-endian and little-endian machines, the computation 9803 below must take account of these differences. */ 9804 highest_order_object_bit_offset = object_offset_in_bytes * BITS_PER_UNIT; 9805 highest_order_field_bit_offset = bitpos_int; 9806 9807 if (! BYTES_BIG_ENDIAN) 9808 { 9809 highest_order_field_bit_offset += tree_low_cst (DECL_SIZE (decl), 0); 9810 highest_order_object_bit_offset += simple_type_size_in_bits (type); 9811 } 9812 9813 bit_offset 9814 = (! BYTES_BIG_ENDIAN 9815 ? highest_order_object_bit_offset - highest_order_field_bit_offset 9816 : highest_order_field_bit_offset - highest_order_object_bit_offset); 9817 9818 add_AT_unsigned (die, DW_AT_bit_offset, bit_offset); 9819} 9820 9821/* For a FIELD_DECL node which represents a bit field, output an attribute 9822 which specifies the length in bits of the given field. */ 9823 9824static inline void 9825add_bit_size_attribute (die, decl) 9826 dw_die_ref die; 9827 tree decl; 9828{ 9829 /* Must be a field and a bit field. */ 9830 if (TREE_CODE (decl) != FIELD_DECL 9831 || ! DECL_BIT_FIELD_TYPE (decl)) 9832 abort (); 9833 9834 if (host_integerp (DECL_SIZE (decl), 1)) 9835 add_AT_unsigned (die, DW_AT_bit_size, tree_low_cst (DECL_SIZE (decl), 1)); 9836} 9837 9838/* If the compiled language is ANSI C, then add a 'prototyped' 9839 attribute, if arg types are given for the parameters of a function. */ 9840 9841static inline void 9842add_prototyped_attribute (die, func_type) 9843 dw_die_ref die; 9844 tree func_type; 9845{ 9846 if (get_AT_unsigned (comp_unit_die, DW_AT_language) == DW_LANG_C89 9847 && TYPE_ARG_TYPES (func_type) != NULL) 9848 add_AT_flag (die, DW_AT_prototyped, 1); 9849} 9850 9851/* Add an 'abstract_origin' attribute below a given DIE. The DIE is found 9852 by looking in either the type declaration or object declaration 9853 equate table. */ 9854 9855static inline void 9856add_abstract_origin_attribute (die, origin) 9857 dw_die_ref die; 9858 tree origin; 9859{ 9860 dw_die_ref origin_die = NULL; 9861 9862 if (TREE_CODE (origin) != FUNCTION_DECL) 9863 { 9864 /* We may have gotten separated from the block for the inlined 9865 function, if we're in an exception handler or some such; make 9866 sure that the abstract function has been written out. 9867 9868 Doing this for nested functions is wrong, however; functions are 9869 distinct units, and our context might not even be inline. */ 9870 tree fn = origin; 9871 9872 if (TYPE_P (fn)) 9873 fn = TYPE_STUB_DECL (fn); 9874 9875 fn = decl_function_context (fn); 9876 if (fn) 9877 dwarf2out_abstract_function (fn); 9878 } 9879 9880 if (DECL_P (origin)) 9881 origin_die = lookup_decl_die (origin); 9882 else if (TYPE_P (origin)) 9883 origin_die = lookup_type_die (origin); 9884 9885 if (origin_die == NULL) 9886 abort (); 9887 9888 add_AT_die_ref (die, DW_AT_abstract_origin, origin_die); 9889} 9890 9891/* We do not currently support the pure_virtual attribute. */ 9892 9893static inline void 9894add_pure_or_virtual_attribute (die, func_decl) 9895 dw_die_ref die; 9896 tree func_decl; 9897{ 9898 if (DECL_VINDEX (func_decl)) 9899 { 9900 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); 9901 9902 if (host_integerp (DECL_VINDEX (func_decl), 0)) 9903 add_AT_loc (die, DW_AT_vtable_elem_location, 9904 new_loc_descr (DW_OP_constu, 9905 tree_low_cst (DECL_VINDEX (func_decl), 0), 9906 0)); 9907 9908 /* GNU extension: Record what type this method came from originally. */ 9909 if (debug_info_level > DINFO_LEVEL_TERSE) 9910 add_AT_die_ref (die, DW_AT_containing_type, 9911 lookup_type_die (DECL_CONTEXT (func_decl))); 9912 } 9913} 9914 9915/* Add source coordinate attributes for the given decl. */ 9916 9917static void 9918add_src_coords_attributes (die, decl) 9919 dw_die_ref die; 9920 tree decl; 9921{ 9922 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); 9923 9924 add_AT_unsigned (die, DW_AT_decl_file, file_index); 9925 add_AT_unsigned (die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); 9926} 9927 9928/* Add an DW_AT_name attribute and source coordinate attribute for the 9929 given decl, but only if it actually has a name. */ 9930 9931static void 9932add_name_and_src_coords_attributes (die, decl) 9933 dw_die_ref die; 9934 tree decl; 9935{ 9936 tree decl_name; 9937 9938 decl_name = DECL_NAME (decl); 9939 if (decl_name != NULL && IDENTIFIER_POINTER (decl_name) != NULL) 9940 { 9941 add_name_attribute (die, dwarf2_name (decl, 0)); 9942 if (! DECL_ARTIFICIAL (decl)) 9943 add_src_coords_attributes (die, decl); 9944 9945 if ((TREE_CODE (decl) == FUNCTION_DECL || TREE_CODE (decl) == VAR_DECL) 9946 && TREE_PUBLIC (decl) 9947 && DECL_ASSEMBLER_NAME (decl) != DECL_NAME (decl) 9948 && !DECL_ABSTRACT (decl)) 9949 add_AT_string (die, DW_AT_MIPS_linkage_name, 9950 IDENTIFIER_POINTER (DECL_ASSEMBLER_NAME (decl))); 9951 } 9952 9953#ifdef VMS_DEBUGGING_INFO 9954 /* Get the function's name, as described by its RTL. This may be different 9955 from the DECL_NAME name used in the source file. */ 9956 if (TREE_CODE (decl) == FUNCTION_DECL && TREE_ASM_WRITTEN (decl)) 9957 { 9958 add_AT_addr (die, DW_AT_VMS_rtnbeg_pd_address, 9959 XEXP (DECL_RTL (decl), 0)); 9960 VARRAY_PUSH_RTX (used_rtx_varray, XEXP (DECL_RTL (decl), 0)); 9961 } 9962#endif 9963} 9964 9965/* Push a new declaration scope. */ 9966 9967static void 9968push_decl_scope (scope) 9969 tree scope; 9970{ 9971 VARRAY_PUSH_TREE (decl_scope_table, scope); 9972} 9973 9974/* Pop a declaration scope. */ 9975 9976static inline void 9977pop_decl_scope () 9978{ 9979 if (VARRAY_ACTIVE_SIZE (decl_scope_table) <= 0) 9980 abort (); 9981 9982 VARRAY_POP (decl_scope_table); 9983} 9984 9985/* Return the DIE for the scope that immediately contains this type. 9986 Non-named types get global scope. Named types nested in other 9987 types get their containing scope if it's open, or global scope 9988 otherwise. All other types (i.e. function-local named types) get 9989 the current active scope. */ 9990 9991static dw_die_ref 9992scope_die_for (t, context_die) 9993 tree t; 9994 dw_die_ref context_die; 9995{ 9996 dw_die_ref scope_die = NULL; 9997 tree containing_scope; 9998 int i; 9999 10000 /* Non-types always go in the current scope. */ 10001 if (! TYPE_P (t)) 10002 abort (); 10003 10004 containing_scope = TYPE_CONTEXT (t); 10005 10006 /* Ignore namespaces for the moment. */ 10007 if (containing_scope && TREE_CODE (containing_scope) == NAMESPACE_DECL) 10008 containing_scope = NULL_TREE; 10009 10010 /* Ignore function type "scopes" from the C frontend. They mean that 10011 a tagged type is local to a parmlist of a function declarator, but 10012 that isn't useful to DWARF. */ 10013 if (containing_scope && TREE_CODE (containing_scope) == FUNCTION_TYPE) 10014 containing_scope = NULL_TREE; 10015 10016 if (containing_scope == NULL_TREE) 10017 scope_die = comp_unit_die; 10018 else if (TYPE_P (containing_scope)) 10019 { 10020 /* For types, we can just look up the appropriate DIE. But 10021 first we check to see if we're in the middle of emitting it 10022 so we know where the new DIE should go. */ 10023 for (i = VARRAY_ACTIVE_SIZE (decl_scope_table) - 1; i >= 0; --i) 10024 if (VARRAY_TREE (decl_scope_table, i) == containing_scope) 10025 break; 10026 10027 if (i < 0) 10028 { 10029 if (debug_info_level > DINFO_LEVEL_TERSE 10030 && !TREE_ASM_WRITTEN (containing_scope)) 10031 abort (); 10032 10033 /* If none of the current dies are suitable, we get file scope. */ 10034 scope_die = comp_unit_die; 10035 } 10036 else 10037 scope_die = lookup_type_die (containing_scope); 10038 } 10039 else 10040 scope_die = context_die; 10041 10042 return scope_die; 10043} 10044 10045/* Returns nonzero if CONTEXT_DIE is internal to a function. */ 10046 10047static inline int 10048local_scope_p (context_die) 10049 dw_die_ref context_die; 10050{ 10051 for (; context_die; context_die = context_die->die_parent) 10052 if (context_die->die_tag == DW_TAG_inlined_subroutine 10053 || context_die->die_tag == DW_TAG_subprogram) 10054 return 1; 10055 10056 return 0; 10057} 10058 10059/* Returns nonzero if CONTEXT_DIE is a class. */ 10060 10061static inline int 10062class_scope_p (context_die) 10063 dw_die_ref context_die; 10064{ 10065 return (context_die 10066 && (context_die->die_tag == DW_TAG_structure_type 10067 || context_die->die_tag == DW_TAG_union_type)); 10068} 10069 10070/* Many forms of DIEs require a "type description" attribute. This 10071 routine locates the proper "type descriptor" die for the type given 10072 by 'type', and adds an DW_AT_type attribute below the given die. */ 10073 10074static void 10075add_type_attribute (object_die, type, decl_const, decl_volatile, context_die) 10076 dw_die_ref object_die; 10077 tree type; 10078 int decl_const; 10079 int decl_volatile; 10080 dw_die_ref context_die; 10081{ 10082 enum tree_code code = TREE_CODE (type); 10083 dw_die_ref type_die = NULL; 10084 10085 /* ??? If this type is an unnamed subrange type of an integral or 10086 floating-point type, use the inner type. This is because we have no 10087 support for unnamed types in base_type_die. This can happen if this is 10088 an Ada subrange type. Correct solution is emit a subrange type die. */ 10089 if ((code == INTEGER_TYPE || code == REAL_TYPE) 10090 && TREE_TYPE (type) != 0 && TYPE_NAME (type) == 0) 10091 type = TREE_TYPE (type), code = TREE_CODE (type); 10092 10093 if (code == ERROR_MARK 10094 /* Handle a special case. For functions whose return type is void, we 10095 generate *no* type attribute. (Note that no object may have type 10096 `void', so this only applies to function return types). */ 10097 || code == VOID_TYPE) 10098 return; 10099 10100 type_die = modified_type_die (type, 10101 decl_const || TYPE_READONLY (type), 10102 decl_volatile || TYPE_VOLATILE (type), 10103 context_die); 10104 10105 if (type_die != NULL) 10106 add_AT_die_ref (object_die, DW_AT_type, type_die); 10107} 10108 10109/* Given a tree pointer to a struct, class, union, or enum type node, return 10110 a pointer to the (string) tag name for the given type, or zero if the type 10111 was declared without a tag. */ 10112 10113static const char * 10114type_tag (type) 10115 tree type; 10116{ 10117 const char *name = 0; 10118 10119 if (TYPE_NAME (type) != 0) 10120 { 10121 tree t = 0; 10122 10123 /* Find the IDENTIFIER_NODE for the type name. */ 10124 if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) 10125 t = TYPE_NAME (type); 10126 10127 /* The g++ front end makes the TYPE_NAME of *each* tagged type point to 10128 a TYPE_DECL node, regardless of whether or not a `typedef' was 10129 involved. */ 10130 else if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 10131 && ! DECL_IGNORED_P (TYPE_NAME (type))) 10132 t = DECL_NAME (TYPE_NAME (type)); 10133 10134 /* Now get the name as a string, or invent one. */ 10135 if (t != 0) 10136 name = IDENTIFIER_POINTER (t); 10137 } 10138 10139 return (name == 0 || *name == '\0') ? 0 : name; 10140} 10141 10142/* Return the type associated with a data member, make a special check 10143 for bit field types. */ 10144 10145static inline tree 10146member_declared_type (member) 10147 tree member; 10148{ 10149 return (DECL_BIT_FIELD_TYPE (member) 10150 ? DECL_BIT_FIELD_TYPE (member) : TREE_TYPE (member)); 10151} 10152 10153/* Get the decl's label, as described by its RTL. This may be different 10154 from the DECL_NAME name used in the source file. */ 10155 10156#if 0 10157static const char * 10158decl_start_label (decl) 10159 tree decl; 10160{ 10161 rtx x; 10162 const char *fnname; 10163 10164 x = DECL_RTL (decl); 10165 if (GET_CODE (x) != MEM) 10166 abort (); 10167 10168 x = XEXP (x, 0); 10169 if (GET_CODE (x) != SYMBOL_REF) 10170 abort (); 10171 10172 fnname = XSTR (x, 0); 10173 return fnname; 10174} 10175#endif 10176 10177/* These routines generate the internal representation of the DIE's for 10178 the compilation unit. Debugging information is collected by walking 10179 the declaration trees passed in from dwarf2out_decl(). */ 10180 10181static void 10182gen_array_type_die (type, context_die) 10183 tree type; 10184 dw_die_ref context_die; 10185{ 10186 dw_die_ref scope_die = scope_die_for (type, context_die); 10187 dw_die_ref array_die; 10188 tree element_type; 10189 10190 /* ??? The SGI dwarf reader fails for array of array of enum types unless 10191 the inner array type comes before the outer array type. Thus we must 10192 call gen_type_die before we call new_die. See below also. */ 10193#ifdef MIPS_DEBUGGING_INFO 10194 gen_type_die (TREE_TYPE (type), context_die); 10195#endif 10196 10197 array_die = new_die (DW_TAG_array_type, scope_die, type); 10198 add_name_attribute (array_die, type_tag (type)); 10199 equate_type_number_to_die (type, array_die); 10200 10201 if (TREE_CODE (type) == VECTOR_TYPE) 10202 { 10203 /* The frontend feeds us a representation for the vector as a struct 10204 containing an array. Pull out the array type. */ 10205 type = TREE_TYPE (TYPE_FIELDS (TYPE_DEBUG_REPRESENTATION_TYPE (type))); 10206 add_AT_flag (array_die, DW_AT_GNU_vector, 1); 10207 } 10208 10209#if 0 10210 /* We default the array ordering. SDB will probably do 10211 the right things even if DW_AT_ordering is not present. It's not even 10212 an issue until we start to get into multidimensional arrays anyway. If 10213 SDB is ever caught doing the Wrong Thing for multi-dimensional arrays, 10214 then we'll have to put the DW_AT_ordering attribute back in. (But if 10215 and when we find out that we need to put these in, we will only do so 10216 for multidimensional arrays. */ 10217 add_AT_unsigned (array_die, DW_AT_ordering, DW_ORD_row_major); 10218#endif 10219 10220#ifdef MIPS_DEBUGGING_INFO 10221 /* The SGI compilers handle arrays of unknown bound by setting 10222 AT_declaration and not emitting any subrange DIEs. */ 10223 if (! TYPE_DOMAIN (type)) 10224 add_AT_unsigned (array_die, DW_AT_declaration, 1); 10225 else 10226#endif 10227 add_subscript_info (array_die, type); 10228 10229 /* Add representation of the type of the elements of this array type. */ 10230 element_type = TREE_TYPE (type); 10231 10232 /* ??? The SGI dwarf reader fails for multidimensional arrays with a 10233 const enum type. E.g. const enum machine_mode insn_operand_mode[2][10]. 10234 We work around this by disabling this feature. See also 10235 add_subscript_info. */ 10236#ifndef MIPS_DEBUGGING_INFO 10237 while (TREE_CODE (element_type) == ARRAY_TYPE) 10238 element_type = TREE_TYPE (element_type); 10239 10240 gen_type_die (element_type, context_die); 10241#endif 10242 10243 add_type_attribute (array_die, element_type, 0, 0, context_die); 10244} 10245 10246static void 10247gen_set_type_die (type, context_die) 10248 tree type; 10249 dw_die_ref context_die; 10250{ 10251 dw_die_ref type_die 10252 = new_die (DW_TAG_set_type, scope_die_for (type, context_die), type); 10253 10254 equate_type_number_to_die (type, type_die); 10255 add_type_attribute (type_die, TREE_TYPE (type), 0, 0, context_die); 10256} 10257 10258#if 0 10259static void 10260gen_entry_point_die (decl, context_die) 10261 tree decl; 10262 dw_die_ref context_die; 10263{ 10264 tree origin = decl_ultimate_origin (decl); 10265 dw_die_ref decl_die = new_die (DW_TAG_entry_point, context_die, decl); 10266 10267 if (origin != NULL) 10268 add_abstract_origin_attribute (decl_die, origin); 10269 else 10270 { 10271 add_name_and_src_coords_attributes (decl_die, decl); 10272 add_type_attribute (decl_die, TREE_TYPE (TREE_TYPE (decl)), 10273 0, 0, context_die); 10274 } 10275 10276 if (DECL_ABSTRACT (decl)) 10277 equate_decl_number_to_die (decl, decl_die); 10278 else 10279 add_AT_lbl_id (decl_die, DW_AT_low_pc, decl_start_label (decl)); 10280} 10281#endif 10282 10283/* Walk through the list of incomplete types again, trying once more to 10284 emit full debugging info for them. */ 10285 10286static void 10287retry_incomplete_types () 10288{ 10289 int i; 10290 10291 for (i = VARRAY_ACTIVE_SIZE (incomplete_types) - 1; i >= 0; i--) 10292 gen_type_die (VARRAY_TREE (incomplete_types, i), comp_unit_die); 10293} 10294 10295/* Generate a DIE to represent an inlined instance of an enumeration type. */ 10296 10297static void 10298gen_inlined_enumeration_type_die (type, context_die) 10299 tree type; 10300 dw_die_ref context_die; 10301{ 10302 dw_die_ref type_die = new_die (DW_TAG_enumeration_type, context_die, type); 10303 10304 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may 10305 be incomplete and such types are not marked. */ 10306 add_abstract_origin_attribute (type_die, type); 10307} 10308 10309/* Generate a DIE to represent an inlined instance of a structure type. */ 10310 10311static void 10312gen_inlined_structure_type_die (type, context_die) 10313 tree type; 10314 dw_die_ref context_die; 10315{ 10316 dw_die_ref type_die = new_die (DW_TAG_structure_type, context_die, type); 10317 10318 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may 10319 be incomplete and such types are not marked. */ 10320 add_abstract_origin_attribute (type_die, type); 10321} 10322 10323/* Generate a DIE to represent an inlined instance of a union type. */ 10324 10325static void 10326gen_inlined_union_type_die (type, context_die) 10327 tree type; 10328 dw_die_ref context_die; 10329{ 10330 dw_die_ref type_die = new_die (DW_TAG_union_type, context_die, type); 10331 10332 /* We do not check for TREE_ASM_WRITTEN (type) being set, as the type may 10333 be incomplete and such types are not marked. */ 10334 add_abstract_origin_attribute (type_die, type); 10335} 10336 10337/* Generate a DIE to represent an enumeration type. Note that these DIEs 10338 include all of the information about the enumeration values also. Each 10339 enumerated type name/value is listed as a child of the enumerated type 10340 DIE. */ 10341 10342static void 10343gen_enumeration_type_die (type, context_die) 10344 tree type; 10345 dw_die_ref context_die; 10346{ 10347 dw_die_ref type_die = lookup_type_die (type); 10348 10349 if (type_die == NULL) 10350 { 10351 type_die = new_die (DW_TAG_enumeration_type, 10352 scope_die_for (type, context_die), type); 10353 equate_type_number_to_die (type, type_die); 10354 add_name_attribute (type_die, type_tag (type)); 10355 } 10356 else if (! TYPE_SIZE (type)) 10357 return; 10358 else 10359 remove_AT (type_die, DW_AT_declaration); 10360 10361 /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the 10362 given enum type is incomplete, do not generate the DW_AT_byte_size 10363 attribute or the DW_AT_element_list attribute. */ 10364 if (TYPE_SIZE (type)) 10365 { 10366 tree link; 10367 10368 TREE_ASM_WRITTEN (type) = 1; 10369 add_byte_size_attribute (type_die, type); 10370 if (TYPE_STUB_DECL (type) != NULL_TREE) 10371 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); 10372 10373 /* If the first reference to this type was as the return type of an 10374 inline function, then it may not have a parent. Fix this now. */ 10375 if (type_die->die_parent == NULL) 10376 add_child_die (scope_die_for (type, context_die), type_die); 10377 10378 for (link = TYPE_FIELDS (type); 10379 link != NULL; link = TREE_CHAIN (link)) 10380 { 10381 dw_die_ref enum_die = new_die (DW_TAG_enumerator, type_die, link); 10382 10383 add_name_attribute (enum_die, 10384 IDENTIFIER_POINTER (TREE_PURPOSE (link))); 10385 10386 if (host_integerp (TREE_VALUE (link), 0)) 10387 { 10388 if (tree_int_cst_sgn (TREE_VALUE (link)) < 0) 10389 add_AT_int (enum_die, DW_AT_const_value, 10390 tree_low_cst (TREE_VALUE (link), 0)); 10391 else 10392 add_AT_unsigned (enum_die, DW_AT_const_value, 10393 tree_low_cst (TREE_VALUE (link), 0)); 10394 } 10395 } 10396 } 10397 else 10398 add_AT_flag (type_die, DW_AT_declaration, 1); 10399} 10400 10401/* Generate a DIE to represent either a real live formal parameter decl or to 10402 represent just the type of some formal parameter position in some function 10403 type. 10404 10405 Note that this routine is a bit unusual because its argument may be a 10406 ..._DECL node (i.e. either a PARM_DECL or perhaps a VAR_DECL which 10407 represents an inlining of some PARM_DECL) or else some sort of a ..._TYPE 10408 node. If it's the former then this function is being called to output a 10409 DIE to represent a formal parameter object (or some inlining thereof). If 10410 it's the latter, then this function is only being called to output a 10411 DW_TAG_formal_parameter DIE to stand as a placeholder for some formal 10412 argument type of some subprogram type. */ 10413 10414static dw_die_ref 10415gen_formal_parameter_die (node, context_die) 10416 tree node; 10417 dw_die_ref context_die; 10418{ 10419 dw_die_ref parm_die 10420 = new_die (DW_TAG_formal_parameter, context_die, node); 10421 tree origin; 10422 10423 switch (TREE_CODE_CLASS (TREE_CODE (node))) 10424 { 10425 case 'd': 10426 origin = decl_ultimate_origin (node); 10427 if (origin != NULL) 10428 add_abstract_origin_attribute (parm_die, origin); 10429 else 10430 { 10431 add_name_and_src_coords_attributes (parm_die, node); 10432 add_type_attribute (parm_die, TREE_TYPE (node), 10433 TREE_READONLY (node), 10434 TREE_THIS_VOLATILE (node), 10435 context_die); 10436 if (DECL_ARTIFICIAL (node)) 10437 add_AT_flag (parm_die, DW_AT_artificial, 1); 10438 } 10439 10440 equate_decl_number_to_die (node, parm_die); 10441 if (! DECL_ABSTRACT (node)) 10442 add_location_or_const_value_attribute (parm_die, node); 10443 10444 break; 10445 10446 case 't': 10447 /* We were called with some kind of a ..._TYPE node. */ 10448 add_type_attribute (parm_die, node, 0, 0, context_die); 10449 break; 10450 10451 default: 10452 abort (); 10453 } 10454 10455 return parm_die; 10456} 10457 10458/* Generate a special type of DIE used as a stand-in for a trailing ellipsis 10459 at the end of an (ANSI prototyped) formal parameters list. */ 10460 10461static void 10462gen_unspecified_parameters_die (decl_or_type, context_die) 10463 tree decl_or_type; 10464 dw_die_ref context_die; 10465{ 10466 new_die (DW_TAG_unspecified_parameters, context_die, decl_or_type); 10467} 10468 10469/* Generate a list of nameless DW_TAG_formal_parameter DIEs (and perhaps a 10470 DW_TAG_unspecified_parameters DIE) to represent the types of the formal 10471 parameters as specified in some function type specification (except for 10472 those which appear as part of a function *definition*). */ 10473 10474static void 10475gen_formal_types_die (function_or_method_type, context_die) 10476 tree function_or_method_type; 10477 dw_die_ref context_die; 10478{ 10479 tree link; 10480 tree formal_type = NULL; 10481 tree first_parm_type; 10482 tree arg; 10483 10484 if (TREE_CODE (function_or_method_type) == FUNCTION_DECL) 10485 { 10486 arg = DECL_ARGUMENTS (function_or_method_type); 10487 function_or_method_type = TREE_TYPE (function_or_method_type); 10488 } 10489 else 10490 arg = NULL_TREE; 10491 10492 first_parm_type = TYPE_ARG_TYPES (function_or_method_type); 10493 10494 /* Make our first pass over the list of formal parameter types and output a 10495 DW_TAG_formal_parameter DIE for each one. */ 10496 for (link = first_parm_type; link; ) 10497 { 10498 dw_die_ref parm_die; 10499 10500 formal_type = TREE_VALUE (link); 10501 if (formal_type == void_type_node) 10502 break; 10503 10504 /* Output a (nameless) DIE to represent the formal parameter itself. */ 10505 parm_die = gen_formal_parameter_die (formal_type, context_die); 10506 if ((TREE_CODE (function_or_method_type) == METHOD_TYPE 10507 && link == first_parm_type) 10508 || (arg && DECL_ARTIFICIAL (arg))) 10509 add_AT_flag (parm_die, DW_AT_artificial, 1); 10510 10511 link = TREE_CHAIN (link); 10512 if (arg) 10513 arg = TREE_CHAIN (arg); 10514 } 10515 10516 /* If this function type has an ellipsis, add a 10517 DW_TAG_unspecified_parameters DIE to the end of the parameter list. */ 10518 if (formal_type != void_type_node) 10519 gen_unspecified_parameters_die (function_or_method_type, context_die); 10520 10521 /* Make our second (and final) pass over the list of formal parameter types 10522 and output DIEs to represent those types (as necessary). */ 10523 for (link = TYPE_ARG_TYPES (function_or_method_type); 10524 link && TREE_VALUE (link); 10525 link = TREE_CHAIN (link)) 10526 gen_type_die (TREE_VALUE (link), context_die); 10527} 10528 10529/* We want to generate the DIE for TYPE so that we can generate the 10530 die for MEMBER, which has been defined; we will need to refer back 10531 to the member declaration nested within TYPE. If we're trying to 10532 generate minimal debug info for TYPE, processing TYPE won't do the 10533 trick; we need to attach the member declaration by hand. */ 10534 10535static void 10536gen_type_die_for_member (type, member, context_die) 10537 tree type, member; 10538 dw_die_ref context_die; 10539{ 10540 gen_type_die (type, context_die); 10541 10542 /* If we're trying to avoid duplicate debug info, we may not have 10543 emitted the member decl for this function. Emit it now. */ 10544 if (TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)) 10545 && ! lookup_decl_die (member)) 10546 { 10547 if (decl_ultimate_origin (member)) 10548 abort (); 10549 10550 push_decl_scope (type); 10551 if (TREE_CODE (member) == FUNCTION_DECL) 10552 gen_subprogram_die (member, lookup_type_die (type)); 10553 else 10554 gen_variable_die (member, lookup_type_die (type)); 10555 10556 pop_decl_scope (); 10557 } 10558} 10559 10560/* Generate the DWARF2 info for the "abstract" instance of a function which we 10561 may later generate inlined and/or out-of-line instances of. */ 10562 10563static void 10564dwarf2out_abstract_function (decl) 10565 tree decl; 10566{ 10567 dw_die_ref old_die; 10568 tree save_fn; 10569 tree context; 10570 int was_abstract = DECL_ABSTRACT (decl); 10571 10572 /* Make sure we have the actual abstract inline, not a clone. */ 10573 decl = DECL_ORIGIN (decl); 10574 10575 old_die = lookup_decl_die (decl); 10576 if (old_die && get_AT_unsigned (old_die, DW_AT_inline)) 10577 /* We've already generated the abstract instance. */ 10578 return; 10579 10580 /* Be sure we've emitted the in-class declaration DIE (if any) first, so 10581 we don't get confused by DECL_ABSTRACT. */ 10582 if (debug_info_level > DINFO_LEVEL_TERSE) 10583 { 10584 context = decl_class_context (decl); 10585 if (context) 10586 gen_type_die_for_member 10587 (context, decl, decl_function_context (decl) ? NULL : comp_unit_die); 10588 } 10589 10590 /* Pretend we've just finished compiling this function. */ 10591 save_fn = current_function_decl; 10592 current_function_decl = decl; 10593 10594 set_decl_abstract_flags (decl, 1); 10595 dwarf2out_decl (decl); 10596 if (! was_abstract) 10597 set_decl_abstract_flags (decl, 0); 10598 10599 current_function_decl = save_fn; 10600} 10601 10602/* Generate a DIE to represent a declared function (either file-scope or 10603 block-local). */ 10604 10605static void 10606gen_subprogram_die (decl, context_die) 10607 tree decl; 10608 dw_die_ref context_die; 10609{ 10610 char label_id[MAX_ARTIFICIAL_LABEL_BYTES]; 10611 tree origin = decl_ultimate_origin (decl); 10612 dw_die_ref subr_die; 10613 rtx fp_reg; 10614 tree fn_arg_types; 10615 tree outer_scope; 10616 dw_die_ref old_die = lookup_decl_die (decl); 10617 int declaration = (current_function_decl != decl 10618 || class_scope_p (context_die)); 10619 10620 /* It is possible to have both DECL_ABSTRACT and DECLARATION be true if we 10621 started to generate the abstract instance of an inline, decided to output 10622 its containing class, and proceeded to emit the declaration of the inline 10623 from the member list for the class. If so, DECLARATION takes priority; 10624 we'll get back to the abstract instance when done with the class. */ 10625 10626 /* The class-scope declaration DIE must be the primary DIE. */ 10627 if (origin && declaration && class_scope_p (context_die)) 10628 { 10629 origin = NULL; 10630 if (old_die) 10631 abort (); 10632 } 10633 10634 if (origin != NULL) 10635 { 10636 if (declaration && ! local_scope_p (context_die)) 10637 abort (); 10638 10639 /* Fixup die_parent for the abstract instance of a nested 10640 inline function. */ 10641 if (old_die && old_die->die_parent == NULL) 10642 add_child_die (context_die, old_die); 10643 10644 subr_die = new_die (DW_TAG_subprogram, context_die, decl); 10645 add_abstract_origin_attribute (subr_die, origin); 10646 } 10647 else if (old_die) 10648 { 10649 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); 10650 10651 if (!get_AT_flag (old_die, DW_AT_declaration) 10652 /* We can have a normal definition following an inline one in the 10653 case of redefinition of GNU C extern inlines. 10654 It seems reasonable to use AT_specification in this case. */ 10655 && !get_AT_unsigned (old_die, DW_AT_inline)) 10656 { 10657 /* ??? This can happen if there is a bug in the program, for 10658 instance, if it has duplicate function definitions. Ideally, 10659 we should detect this case and ignore it. For now, if we have 10660 already reported an error, any error at all, then assume that 10661 we got here because of an input error, not a dwarf2 bug. */ 10662 if (errorcount) 10663 return; 10664 abort (); 10665 } 10666 10667 /* If the definition comes from the same place as the declaration, 10668 maybe use the old DIE. We always want the DIE for this function 10669 that has the *_pc attributes to be under comp_unit_die so the 10670 debugger can find it. We also need to do this for abstract 10671 instances of inlines, since the spec requires the out-of-line copy 10672 to have the same parent. For local class methods, this doesn't 10673 apply; we just use the old DIE. */ 10674 if ((old_die->die_parent == comp_unit_die || context_die == NULL) 10675 && (DECL_ARTIFICIAL (decl) 10676 || (get_AT_unsigned (old_die, DW_AT_decl_file) == file_index 10677 && (get_AT_unsigned (old_die, DW_AT_decl_line) 10678 == (unsigned) DECL_SOURCE_LINE (decl))))) 10679 { 10680 subr_die = old_die; 10681 10682 /* Clear out the declaration attribute and the parm types. */ 10683 remove_AT (subr_die, DW_AT_declaration); 10684 remove_children (subr_die); 10685 } 10686 else 10687 { 10688 subr_die = new_die (DW_TAG_subprogram, context_die, decl); 10689 add_AT_die_ref (subr_die, DW_AT_specification, old_die); 10690 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) 10691 add_AT_unsigned (subr_die, DW_AT_decl_file, file_index); 10692 if (get_AT_unsigned (old_die, DW_AT_decl_line) 10693 != (unsigned) DECL_SOURCE_LINE (decl)) 10694 add_AT_unsigned 10695 (subr_die, DW_AT_decl_line, DECL_SOURCE_LINE (decl)); 10696 } 10697 } 10698 else 10699 { 10700 subr_die = new_die (DW_TAG_subprogram, context_die, decl); 10701 10702 if (TREE_PUBLIC (decl)) 10703 add_AT_flag (subr_die, DW_AT_external, 1); 10704 10705 add_name_and_src_coords_attributes (subr_die, decl); 10706 if (debug_info_level > DINFO_LEVEL_TERSE) 10707 { 10708 add_prototyped_attribute (subr_die, TREE_TYPE (decl)); 10709 add_type_attribute (subr_die, TREE_TYPE (TREE_TYPE (decl)), 10710 0, 0, context_die); 10711 } 10712 10713 add_pure_or_virtual_attribute (subr_die, decl); 10714 if (DECL_ARTIFICIAL (decl)) 10715 add_AT_flag (subr_die, DW_AT_artificial, 1); 10716 10717 if (TREE_PROTECTED (decl)) 10718 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_protected); 10719 else if (TREE_PRIVATE (decl)) 10720 add_AT_unsigned (subr_die, DW_AT_accessibility, DW_ACCESS_private); 10721 } 10722 10723 if (declaration) 10724 { 10725 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) 10726 { 10727 add_AT_flag (subr_die, DW_AT_declaration, 1); 10728 10729 /* The first time we see a member function, it is in the context of 10730 the class to which it belongs. We make sure of this by emitting 10731 the class first. The next time is the definition, which is 10732 handled above. The two may come from the same source text. */ 10733 if (DECL_CONTEXT (decl) || DECL_ABSTRACT (decl)) 10734 equate_decl_number_to_die (decl, subr_die); 10735 } 10736 } 10737 else if (DECL_ABSTRACT (decl)) 10738 { 10739 if (DECL_INLINE (decl) && !flag_no_inline) 10740 { 10741 /* ??? Checking DECL_DEFER_OUTPUT is correct for static 10742 inline functions, but not for extern inline functions. 10743 We can't get this completely correct because information 10744 about whether the function was declared inline is not 10745 saved anywhere. */ 10746 if (DECL_DEFER_OUTPUT (decl)) 10747 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_inlined); 10748 else 10749 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_inlined); 10750 } 10751 else 10752 add_AT_unsigned (subr_die, DW_AT_inline, DW_INL_declared_not_inlined); 10753 10754 equate_decl_number_to_die (decl, subr_die); 10755 } 10756 else if (!DECL_EXTERNAL (decl)) 10757 { 10758 if (!old_die || !get_AT_unsigned (old_die, DW_AT_inline)) 10759 equate_decl_number_to_die (decl, subr_die); 10760 10761 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_BEGIN_LABEL, 10762 current_function_funcdef_no); 10763 add_AT_lbl_id (subr_die, DW_AT_low_pc, label_id); 10764 ASM_GENERATE_INTERNAL_LABEL (label_id, FUNC_END_LABEL, 10765 current_function_funcdef_no); 10766 add_AT_lbl_id (subr_die, DW_AT_high_pc, label_id); 10767 10768 add_pubname (decl, subr_die); 10769 add_arange (decl, subr_die); 10770 10771#ifdef MIPS_DEBUGGING_INFO 10772 /* Add a reference to the FDE for this routine. */ 10773 add_AT_fde_ref (subr_die, DW_AT_MIPS_fde, current_funcdef_fde); 10774#endif 10775 10776 /* Define the "frame base" location for this routine. We use the 10777 frame pointer or stack pointer registers, since the RTL for local 10778 variables is relative to one of them. */ 10779 fp_reg 10780 = frame_pointer_needed ? hard_frame_pointer_rtx : stack_pointer_rtx; 10781 add_AT_loc (subr_die, DW_AT_frame_base, reg_loc_descriptor (fp_reg)); 10782 10783#if 0 10784 /* ??? This fails for nested inline functions, because context_display 10785 is not part of the state saved/restored for inline functions. */ 10786 if (current_function_needs_context) 10787 add_AT_location_description (subr_die, DW_AT_static_link, 10788 loc_descriptor (lookup_static_chain (decl))); 10789#endif 10790 } 10791 10792 /* Now output descriptions of the arguments for this function. This gets 10793 (unnecessarily?) complex because of the fact that the DECL_ARGUMENT list 10794 for a FUNCTION_DECL doesn't indicate cases where there was a trailing 10795 `...' at the end of the formal parameter list. In order to find out if 10796 there was a trailing ellipsis or not, we must instead look at the type 10797 associated with the FUNCTION_DECL. This will be a node of type 10798 FUNCTION_TYPE. If the chain of type nodes hanging off of this 10799 FUNCTION_TYPE node ends with a void_type_node then there should *not* be 10800 an ellipsis at the end. */ 10801 10802 /* In the case where we are describing a mere function declaration, all we 10803 need to do here (and all we *can* do here) is to describe the *types* of 10804 its formal parameters. */ 10805 if (debug_info_level <= DINFO_LEVEL_TERSE) 10806 ; 10807 else if (declaration) 10808 gen_formal_types_die (decl, subr_die); 10809 else 10810 { 10811 /* Generate DIEs to represent all known formal parameters */ 10812 tree arg_decls = DECL_ARGUMENTS (decl); 10813 tree parm; 10814 10815 /* When generating DIEs, generate the unspecified_parameters DIE 10816 instead if we come across the arg "__builtin_va_alist" */ 10817 for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) 10818 if (TREE_CODE (parm) == PARM_DECL) 10819 { 10820 if (DECL_NAME (parm) 10821 && !strcmp (IDENTIFIER_POINTER (DECL_NAME (parm)), 10822 "__builtin_va_alist")) 10823 gen_unspecified_parameters_die (parm, subr_die); 10824 else 10825 gen_decl_die (parm, subr_die); 10826 } 10827 10828 /* Decide whether we need an unspecified_parameters DIE at the end. 10829 There are 2 more cases to do this for: 1) the ansi ... declaration - 10830 this is detectable when the end of the arg list is not a 10831 void_type_node 2) an unprototyped function declaration (not a 10832 definition). This just means that we have no info about the 10833 parameters at all. */ 10834 fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); 10835 if (fn_arg_types != NULL) 10836 { 10837 /* this is the prototyped case, check for ... */ 10838 if (TREE_VALUE (tree_last (fn_arg_types)) != void_type_node) 10839 gen_unspecified_parameters_die (decl, subr_die); 10840 } 10841 else if (DECL_INITIAL (decl) == NULL_TREE) 10842 gen_unspecified_parameters_die (decl, subr_die); 10843 } 10844 10845 /* Output Dwarf info for all of the stuff within the body of the function 10846 (if it has one - it may be just a declaration). */ 10847 outer_scope = DECL_INITIAL (decl); 10848 10849 /* OUTER_SCOPE is a pointer to the outermost BLOCK node created to represent 10850 a function. This BLOCK actually represents the outermost binding contour 10851 for the function, i.e. the contour in which the function's formal 10852 parameters and labels get declared. Curiously, it appears that the front 10853 end doesn't actually put the PARM_DECL nodes for the current function onto 10854 the BLOCK_VARS list for this outer scope, but are strung off of the 10855 DECL_ARGUMENTS list for the function instead. 10856 10857 The BLOCK_VARS list for the `outer_scope' does provide us with a list of 10858 the LABEL_DECL nodes for the function however, and we output DWARF info 10859 for those in decls_for_scope. Just within the `outer_scope' there will be 10860 a BLOCK node representing the function's outermost pair of curly braces, 10861 and any blocks used for the base and member initializers of a C++ 10862 constructor function. */ 10863 if (! declaration && TREE_CODE (outer_scope) != ERROR_MARK) 10864 { 10865 current_function_has_inlines = 0; 10866 decls_for_scope (outer_scope, subr_die, 0); 10867 10868#if 0 && defined (MIPS_DEBUGGING_INFO) 10869 if (current_function_has_inlines) 10870 { 10871 add_AT_flag (subr_die, DW_AT_MIPS_has_inlines, 1); 10872 if (! comp_unit_has_inlines) 10873 { 10874 add_AT_flag (comp_unit_die, DW_AT_MIPS_has_inlines, 1); 10875 comp_unit_has_inlines = 1; 10876 } 10877 } 10878#endif 10879 } 10880} 10881 10882/* Generate a DIE to represent a declared data object. */ 10883 10884static void 10885gen_variable_die (decl, context_die) 10886 tree decl; 10887 dw_die_ref context_die; 10888{ 10889 tree origin = decl_ultimate_origin (decl); 10890 dw_die_ref var_die = new_die (DW_TAG_variable, context_die, decl); 10891 10892 dw_die_ref old_die = lookup_decl_die (decl); 10893 int declaration = (DECL_EXTERNAL (decl) 10894 || class_scope_p (context_die)); 10895 10896 if (origin != NULL) 10897 add_abstract_origin_attribute (var_die, origin); 10898 10899 /* Loop unrolling can create multiple blocks that refer to the same 10900 static variable, so we must test for the DW_AT_declaration flag. 10901 10902 ??? Loop unrolling/reorder_blocks should perhaps be rewritten to 10903 copy decls and set the DECL_ABSTRACT flag on them instead of 10904 sharing them. 10905 10906 ??? Duplicated blocks have been rewritten to use .debug_ranges. */ 10907 else if (old_die && TREE_STATIC (decl) 10908 && get_AT_flag (old_die, DW_AT_declaration) == 1) 10909 { 10910 /* This is a definition of a C++ class level static. */ 10911 add_AT_die_ref (var_die, DW_AT_specification, old_die); 10912 if (DECL_NAME (decl)) 10913 { 10914 unsigned file_index = lookup_filename (DECL_SOURCE_FILE (decl)); 10915 10916 if (get_AT_unsigned (old_die, DW_AT_decl_file) != file_index) 10917 add_AT_unsigned (var_die, DW_AT_decl_file, file_index); 10918 10919 if (get_AT_unsigned (old_die, DW_AT_decl_line) 10920 != (unsigned) DECL_SOURCE_LINE (decl)) 10921 10922 add_AT_unsigned (var_die, DW_AT_decl_line, 10923 DECL_SOURCE_LINE (decl)); 10924 } 10925 } 10926 else 10927 { 10928 add_name_and_src_coords_attributes (var_die, decl); 10929 add_type_attribute (var_die, TREE_TYPE (decl), TREE_READONLY (decl), 10930 TREE_THIS_VOLATILE (decl), context_die); 10931 10932 if (TREE_PUBLIC (decl)) 10933 add_AT_flag (var_die, DW_AT_external, 1); 10934 10935 if (DECL_ARTIFICIAL (decl)) 10936 add_AT_flag (var_die, DW_AT_artificial, 1); 10937 10938 if (TREE_PROTECTED (decl)) 10939 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_protected); 10940 else if (TREE_PRIVATE (decl)) 10941 add_AT_unsigned (var_die, DW_AT_accessibility, DW_ACCESS_private); 10942 } 10943 10944 if (declaration) 10945 add_AT_flag (var_die, DW_AT_declaration, 1); 10946 10947 if (class_scope_p (context_die) || DECL_ABSTRACT (decl)) 10948 equate_decl_number_to_die (decl, var_die); 10949 10950 if (! declaration && ! DECL_ABSTRACT (decl)) 10951 { 10952 add_location_or_const_value_attribute (var_die, decl); 10953 add_pubname (decl, var_die); 10954 } 10955 else 10956 tree_add_const_value_attribute (var_die, decl); 10957} 10958 10959/* Generate a DIE to represent a label identifier. */ 10960 10961static void 10962gen_label_die (decl, context_die) 10963 tree decl; 10964 dw_die_ref context_die; 10965{ 10966 tree origin = decl_ultimate_origin (decl); 10967 dw_die_ref lbl_die = new_die (DW_TAG_label, context_die, decl); 10968 rtx insn; 10969 char label[MAX_ARTIFICIAL_LABEL_BYTES]; 10970 10971 if (origin != NULL) 10972 add_abstract_origin_attribute (lbl_die, origin); 10973 else 10974 add_name_and_src_coords_attributes (lbl_die, decl); 10975 10976 if (DECL_ABSTRACT (decl)) 10977 equate_decl_number_to_die (decl, lbl_die); 10978 else 10979 { 10980 insn = DECL_RTL (decl); 10981 10982 /* Deleted labels are programmer specified labels which have been 10983 eliminated because of various optimisations. We still emit them 10984 here so that it is possible to put breakpoints on them. */ 10985 if (GET_CODE (insn) == CODE_LABEL 10986 || ((GET_CODE (insn) == NOTE 10987 && NOTE_LINE_NUMBER (insn) == NOTE_INSN_DELETED_LABEL))) 10988 { 10989 /* When optimization is enabled (via -O) some parts of the compiler 10990 (e.g. jump.c and cse.c) may try to delete CODE_LABEL insns which 10991 represent source-level labels which were explicitly declared by 10992 the user. This really shouldn't be happening though, so catch 10993 it if it ever does happen. */ 10994 if (INSN_DELETED_P (insn)) 10995 abort (); 10996 10997 ASM_GENERATE_INTERNAL_LABEL (label, "L", CODE_LABEL_NUMBER (insn)); 10998 add_AT_lbl_id (lbl_die, DW_AT_low_pc, label); 10999 } 11000 } 11001} 11002 11003/* Generate a DIE for a lexical block. */ 11004 11005static void 11006gen_lexical_block_die (stmt, context_die, depth) 11007 tree stmt; 11008 dw_die_ref context_die; 11009 int depth; 11010{ 11011 dw_die_ref stmt_die = new_die (DW_TAG_lexical_block, context_die, stmt); 11012 char label[MAX_ARTIFICIAL_LABEL_BYTES]; 11013 11014 if (! BLOCK_ABSTRACT (stmt)) 11015 { 11016 if (BLOCK_FRAGMENT_CHAIN (stmt)) 11017 { 11018 tree chain; 11019 11020 add_AT_range_list (stmt_die, DW_AT_ranges, add_ranges (stmt)); 11021 11022 chain = BLOCK_FRAGMENT_CHAIN (stmt); 11023 do 11024 { 11025 add_ranges (chain); 11026 chain = BLOCK_FRAGMENT_CHAIN (chain); 11027 } 11028 while (chain); 11029 add_ranges (NULL); 11030 } 11031 else 11032 { 11033 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, 11034 BLOCK_NUMBER (stmt)); 11035 add_AT_lbl_id (stmt_die, DW_AT_low_pc, label); 11036 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, 11037 BLOCK_NUMBER (stmt)); 11038 add_AT_lbl_id (stmt_die, DW_AT_high_pc, label); 11039 } 11040 } 11041 11042 decls_for_scope (stmt, stmt_die, depth); 11043} 11044 11045/* Generate a DIE for an inlined subprogram. */ 11046 11047static void 11048gen_inlined_subroutine_die (stmt, context_die, depth) 11049 tree stmt; 11050 dw_die_ref context_die; 11051 int depth; 11052{ 11053 if (! BLOCK_ABSTRACT (stmt)) 11054 { 11055 dw_die_ref subr_die 11056 = new_die (DW_TAG_inlined_subroutine, context_die, stmt); 11057 tree decl = block_ultimate_origin (stmt); 11058 char label[MAX_ARTIFICIAL_LABEL_BYTES]; 11059 11060 /* Emit info for the abstract instance first, if we haven't yet. */ 11061 dwarf2out_abstract_function (decl); 11062 11063 add_abstract_origin_attribute (subr_die, decl); 11064 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_BEGIN_LABEL, 11065 BLOCK_NUMBER (stmt)); 11066 add_AT_lbl_id (subr_die, DW_AT_low_pc, label); 11067 ASM_GENERATE_INTERNAL_LABEL (label, BLOCK_END_LABEL, 11068 BLOCK_NUMBER (stmt)); 11069 add_AT_lbl_id (subr_die, DW_AT_high_pc, label); 11070 decls_for_scope (stmt, subr_die, depth); 11071 current_function_has_inlines = 1; 11072 } 11073 else 11074 /* We may get here if we're the outer block of function A that was 11075 inlined into function B that was inlined into function C. When 11076 generating debugging info for C, dwarf2out_abstract_function(B) 11077 would mark all inlined blocks as abstract, including this one. 11078 So, we wouldn't (and shouldn't) expect labels to be generated 11079 for this one. Instead, just emit debugging info for 11080 declarations within the block. This is particularly important 11081 in the case of initializers of arguments passed from B to us: 11082 if they're statement expressions containing declarations, we 11083 wouldn't generate dies for their abstract variables, and then, 11084 when generating dies for the real variables, we'd die (pun 11085 intended :-) */ 11086 gen_lexical_block_die (stmt, context_die, depth); 11087} 11088 11089/* Generate a DIE for a field in a record, or structure. */ 11090 11091static void 11092gen_field_die (decl, context_die) 11093 tree decl; 11094 dw_die_ref context_die; 11095{ 11096 dw_die_ref decl_die; 11097 11098 if (TREE_TYPE (decl) == error_mark_node) 11099 return; 11100 11101 decl_die = new_die (DW_TAG_member, context_die, decl); 11102 add_name_and_src_coords_attributes (decl_die, decl); 11103 add_type_attribute (decl_die, member_declared_type (decl), 11104 TREE_READONLY (decl), TREE_THIS_VOLATILE (decl), 11105 context_die); 11106 11107 if (DECL_BIT_FIELD_TYPE (decl)) 11108 { 11109 add_byte_size_attribute (decl_die, decl); 11110 add_bit_size_attribute (decl_die, decl); 11111 add_bit_offset_attribute (decl_die, decl); 11112 } 11113 11114 if (TREE_CODE (DECL_FIELD_CONTEXT (decl)) != UNION_TYPE) 11115 add_data_member_location_attribute (decl_die, decl); 11116 11117 if (DECL_ARTIFICIAL (decl)) 11118 add_AT_flag (decl_die, DW_AT_artificial, 1); 11119 11120 if (TREE_PROTECTED (decl)) 11121 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_protected); 11122 else if (TREE_PRIVATE (decl)) 11123 add_AT_unsigned (decl_die, DW_AT_accessibility, DW_ACCESS_private); 11124} 11125 11126#if 0 11127/* Don't generate either pointer_type DIEs or reference_type DIEs here. 11128 Use modified_type_die instead. 11129 We keep this code here just in case these types of DIEs may be needed to 11130 represent certain things in other languages (e.g. Pascal) someday. */ 11131 11132static void 11133gen_pointer_type_die (type, context_die) 11134 tree type; 11135 dw_die_ref context_die; 11136{ 11137 dw_die_ref ptr_die 11138 = new_die (DW_TAG_pointer_type, scope_die_for (type, context_die), type); 11139 11140 equate_type_number_to_die (type, ptr_die); 11141 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); 11142 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); 11143} 11144 11145/* Don't generate either pointer_type DIEs or reference_type DIEs here. 11146 Use modified_type_die instead. 11147 We keep this code here just in case these types of DIEs may be needed to 11148 represent certain things in other languages (e.g. Pascal) someday. */ 11149 11150static void 11151gen_reference_type_die (type, context_die) 11152 tree type; 11153 dw_die_ref context_die; 11154{ 11155 dw_die_ref ref_die 11156 = new_die (DW_TAG_reference_type, scope_die_for (type, context_die), type); 11157 11158 equate_type_number_to_die (type, ref_die); 11159 add_type_attribute (ref_die, TREE_TYPE (type), 0, 0, context_die); 11160 add_AT_unsigned (mod_type_die, DW_AT_byte_size, PTR_SIZE); 11161} 11162#endif 11163 11164/* Generate a DIE for a pointer to a member type. */ 11165 11166static void 11167gen_ptr_to_mbr_type_die (type, context_die) 11168 tree type; 11169 dw_die_ref context_die; 11170{ 11171 dw_die_ref ptr_die 11172 = new_die (DW_TAG_ptr_to_member_type, 11173 scope_die_for (type, context_die), type); 11174 11175 equate_type_number_to_die (type, ptr_die); 11176 add_AT_die_ref (ptr_die, DW_AT_containing_type, 11177 lookup_type_die (TYPE_OFFSET_BASETYPE (type))); 11178 add_type_attribute (ptr_die, TREE_TYPE (type), 0, 0, context_die); 11179} 11180 11181/* Generate the DIE for the compilation unit. */ 11182 11183static dw_die_ref 11184gen_compile_unit_die (filename) 11185 const char *filename; 11186{ 11187 dw_die_ref die; 11188 char producer[250]; 11189 const char *wd = getpwd (); 11190 const char *language_string = lang_hooks.name; 11191 int language; 11192 11193 die = new_die (DW_TAG_compile_unit, NULL, NULL); 11194 add_name_attribute (die, filename); 11195 11196 if (wd != NULL && filename[0] != DIR_SEPARATOR) 11197 add_AT_string (die, DW_AT_comp_dir, wd); 11198 11199 sprintf (producer, "%s %s", language_string, version_string); 11200 11201#ifdef MIPS_DEBUGGING_INFO 11202 /* The MIPS/SGI compilers place the 'cc' command line options in the producer 11203 string. The SGI debugger looks for -g, -g1, -g2, or -g3; if they do 11204 not appear in the producer string, the debugger reaches the conclusion 11205 that the object file is stripped and has no debugging information. 11206 To get the MIPS/SGI debugger to believe that there is debugging 11207 information in the object file, we add a -g to the producer string. */ 11208 if (debug_info_level > DINFO_LEVEL_TERSE) 11209 strcat (producer, " -g"); 11210#endif 11211 11212 add_AT_string (die, DW_AT_producer, producer); 11213 11214 if (strcmp (language_string, "GNU C++") == 0) 11215 language = DW_LANG_C_plus_plus; 11216 else if (strcmp (language_string, "GNU Ada") == 0) 11217 language = DW_LANG_Ada83; 11218 else if (strcmp (language_string, "GNU F77") == 0) 11219 language = DW_LANG_Fortran77; 11220 else if (strcmp (language_string, "GNU Pascal") == 0) 11221 language = DW_LANG_Pascal83; 11222 else if (strcmp (language_string, "GNU Java") == 0) 11223 language = DW_LANG_Java; 11224 else 11225 language = DW_LANG_C89; 11226 11227 add_AT_unsigned (die, DW_AT_language, language); 11228 return die; 11229} 11230 11231/* Generate a DIE for a string type. */ 11232 11233static void 11234gen_string_type_die (type, context_die) 11235 tree type; 11236 dw_die_ref context_die; 11237{ 11238 dw_die_ref type_die 11239 = new_die (DW_TAG_string_type, scope_die_for (type, context_die), type); 11240 11241 equate_type_number_to_die (type, type_die); 11242 11243 /* ??? Fudge the string length attribute for now. 11244 TODO: add string length info. */ 11245#if 0 11246 string_length_attribute (TYPE_MAX_VALUE (TYPE_DOMAIN (type))); 11247 bound_representation (upper_bound, 0, 'u'); 11248#endif 11249} 11250 11251/* Generate the DIE for a base class. */ 11252 11253static void 11254gen_inheritance_die (binfo, context_die) 11255 tree binfo; 11256 dw_die_ref context_die; 11257{ 11258 dw_die_ref die = new_die (DW_TAG_inheritance, context_die, binfo); 11259 11260 add_type_attribute (die, BINFO_TYPE (binfo), 0, 0, context_die); 11261 add_data_member_location_attribute (die, binfo); 11262 11263 if (TREE_VIA_VIRTUAL (binfo)) 11264 add_AT_unsigned (die, DW_AT_virtuality, DW_VIRTUALITY_virtual); 11265 11266 if (TREE_VIA_PUBLIC (binfo)) 11267 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_public); 11268 else if (TREE_VIA_PROTECTED (binfo)) 11269 add_AT_unsigned (die, DW_AT_accessibility, DW_ACCESS_protected); 11270} 11271 11272/* Generate a DIE for a class member. */ 11273 11274static void 11275gen_member_die (type, context_die) 11276 tree type; 11277 dw_die_ref context_die; 11278{ 11279 tree member; 11280 dw_die_ref child; 11281 11282 /* If this is not an incomplete type, output descriptions of each of its 11283 members. Note that as we output the DIEs necessary to represent the 11284 members of this record or union type, we will also be trying to output 11285 DIEs to represent the *types* of those members. However the `type' 11286 function (above) will specifically avoid generating type DIEs for member 11287 types *within* the list of member DIEs for this (containing) type except 11288 for those types (of members) which are explicitly marked as also being 11289 members of this (containing) type themselves. The g++ front- end can 11290 force any given type to be treated as a member of some other (containing) 11291 type by setting the TYPE_CONTEXT of the given (member) type to point to 11292 the TREE node representing the appropriate (containing) type. */ 11293 11294 /* First output info about the base classes. */ 11295 if (TYPE_BINFO (type) && TYPE_BINFO_BASETYPES (type)) 11296 { 11297 tree bases = TYPE_BINFO_BASETYPES (type); 11298 int n_bases = TREE_VEC_LENGTH (bases); 11299 int i; 11300 11301 for (i = 0; i < n_bases; i++) 11302 gen_inheritance_die (TREE_VEC_ELT (bases, i), context_die); 11303 } 11304 11305 /* Now output info about the data members and type members. */ 11306 for (member = TYPE_FIELDS (type); member; member = TREE_CHAIN (member)) 11307 { 11308 /* If we thought we were generating minimal debug info for TYPE 11309 and then changed our minds, some of the member declarations 11310 may have already been defined. Don't define them again, but 11311 do put them in the right order. */ 11312 11313 child = lookup_decl_die (member); 11314 if (child) 11315 splice_child_die (context_die, child); 11316 else 11317 gen_decl_die (member, context_die); 11318 } 11319 11320 /* Now output info about the function members (if any). */ 11321 for (member = TYPE_METHODS (type); member; member = TREE_CHAIN (member)) 11322 { 11323 /* Don't include clones in the member list. */ 11324 if (DECL_ABSTRACT_ORIGIN (member)) 11325 continue; 11326 11327 child = lookup_decl_die (member); 11328 if (child) 11329 splice_child_die (context_die, child); 11330 else 11331 gen_decl_die (member, context_die); 11332 } 11333} 11334 11335/* Generate a DIE for a structure or union type. If TYPE_DECL_SUPPRESS_DEBUG 11336 is set, we pretend that the type was never defined, so we only get the 11337 member DIEs needed by later specification DIEs. */ 11338 11339static void 11340gen_struct_or_union_type_die (type, context_die) 11341 tree type; 11342 dw_die_ref context_die; 11343{ 11344 dw_die_ref type_die = lookup_type_die (type); 11345 dw_die_ref scope_die = 0; 11346 int nested = 0; 11347 int complete = (TYPE_SIZE (type) 11348 && (! TYPE_STUB_DECL (type) 11349 || ! TYPE_DECL_SUPPRESS_DEBUG (TYPE_STUB_DECL (type)))); 11350 11351 if (type_die && ! complete) 11352 return; 11353 11354 if (TYPE_CONTEXT (type) != NULL_TREE 11355 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type))) 11356 nested = 1; 11357 11358 scope_die = scope_die_for (type, context_die); 11359 11360 if (! type_die || (nested && scope_die == comp_unit_die)) 11361 /* First occurrence of type or toplevel definition of nested class. */ 11362 { 11363 dw_die_ref old_die = type_die; 11364 11365 type_die = new_die (TREE_CODE (type) == RECORD_TYPE 11366 ? DW_TAG_structure_type : DW_TAG_union_type, 11367 scope_die, type); 11368 equate_type_number_to_die (type, type_die); 11369 if (old_die) 11370 add_AT_die_ref (type_die, DW_AT_specification, old_die); 11371 else 11372 add_name_attribute (type_die, type_tag (type)); 11373 } 11374 else 11375 remove_AT (type_die, DW_AT_declaration); 11376 11377 /* If this type has been completed, then give it a byte_size attribute and 11378 then give a list of members. */ 11379 if (complete) 11380 { 11381 /* Prevent infinite recursion in cases where the type of some member of 11382 this type is expressed in terms of this type itself. */ 11383 TREE_ASM_WRITTEN (type) = 1; 11384 add_byte_size_attribute (type_die, type); 11385 if (TYPE_STUB_DECL (type) != NULL_TREE) 11386 add_src_coords_attributes (type_die, TYPE_STUB_DECL (type)); 11387 11388 /* If the first reference to this type was as the return type of an 11389 inline function, then it may not have a parent. Fix this now. */ 11390 if (type_die->die_parent == NULL) 11391 add_child_die (scope_die, type_die); 11392 11393 push_decl_scope (type); 11394 gen_member_die (type, type_die); 11395 pop_decl_scope (); 11396 11397 /* GNU extension: Record what type our vtable lives in. */ 11398 if (TYPE_VFIELD (type)) 11399 { 11400 tree vtype = DECL_FCONTEXT (TYPE_VFIELD (type)); 11401 11402 gen_type_die (vtype, context_die); 11403 add_AT_die_ref (type_die, DW_AT_containing_type, 11404 lookup_type_die (vtype)); 11405 } 11406 } 11407 else 11408 { 11409 add_AT_flag (type_die, DW_AT_declaration, 1); 11410 11411 /* We don't need to do this for function-local types. */ 11412 if (TYPE_STUB_DECL (type) 11413 && ! decl_function_context (TYPE_STUB_DECL (type))) 11414 VARRAY_PUSH_TREE (incomplete_types, type); 11415 } 11416} 11417 11418/* Generate a DIE for a subroutine _type_. */ 11419 11420static void 11421gen_subroutine_type_die (type, context_die) 11422 tree type; 11423 dw_die_ref context_die; 11424{ 11425 tree return_type = TREE_TYPE (type); 11426 dw_die_ref subr_die 11427 = new_die (DW_TAG_subroutine_type, 11428 scope_die_for (type, context_die), type); 11429 11430 equate_type_number_to_die (type, subr_die); 11431 add_prototyped_attribute (subr_die, type); 11432 add_type_attribute (subr_die, return_type, 0, 0, context_die); 11433 gen_formal_types_die (type, subr_die); 11434} 11435 11436/* Generate a DIE for a type definition */ 11437 11438static void 11439gen_typedef_die (decl, context_die) 11440 tree decl; 11441 dw_die_ref context_die; 11442{ 11443 dw_die_ref type_die; 11444 tree origin; 11445 11446 if (TREE_ASM_WRITTEN (decl)) 11447 return; 11448 11449 TREE_ASM_WRITTEN (decl) = 1; 11450 type_die = new_die (DW_TAG_typedef, context_die, decl); 11451 origin = decl_ultimate_origin (decl); 11452 if (origin != NULL) 11453 add_abstract_origin_attribute (type_die, origin); 11454 else 11455 { 11456 tree type; 11457 11458 add_name_and_src_coords_attributes (type_die, decl); 11459 if (DECL_ORIGINAL_TYPE (decl)) 11460 { 11461 type = DECL_ORIGINAL_TYPE (decl); 11462 11463 if (type == TREE_TYPE (decl)) 11464 abort (); 11465 else 11466 equate_type_number_to_die (TREE_TYPE (decl), type_die); 11467 } 11468 else 11469 type = TREE_TYPE (decl); 11470 11471 add_type_attribute (type_die, type, TREE_READONLY (decl), 11472 TREE_THIS_VOLATILE (decl), context_die); 11473 } 11474 11475 if (DECL_ABSTRACT (decl)) 11476 equate_decl_number_to_die (decl, type_die); 11477} 11478 11479/* Generate a type description DIE. */ 11480 11481static void 11482gen_type_die (type, context_die) 11483 tree type; 11484 dw_die_ref context_die; 11485{ 11486 int need_pop; 11487 11488 if (type == NULL_TREE || type == error_mark_node) 11489 return; 11490 11491 if (TYPE_NAME (type) && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 11492 && DECL_ORIGINAL_TYPE (TYPE_NAME (type))) 11493 { 11494 if (TREE_ASM_WRITTEN (type)) 11495 return; 11496 11497 /* Prevent broken recursion; we can't hand off to the same type. */ 11498 if (DECL_ORIGINAL_TYPE (TYPE_NAME (type)) == type) 11499 abort (); 11500 11501 TREE_ASM_WRITTEN (type) = 1; 11502 gen_decl_die (TYPE_NAME (type), context_die); 11503 return; 11504 } 11505 11506 /* We are going to output a DIE to represent the unqualified version 11507 of this type (i.e. without any const or volatile qualifiers) so 11508 get the main variant (i.e. the unqualified version) of this type 11509 now. (Vectors are special because the debugging info is in the 11510 cloned type itself). */ 11511 if (TREE_CODE (type) != VECTOR_TYPE) 11512 type = type_main_variant (type); 11513 11514 if (TREE_ASM_WRITTEN (type)) 11515 return; 11516 11517 switch (TREE_CODE (type)) 11518 { 11519 case ERROR_MARK: 11520 break; 11521 11522 case POINTER_TYPE: 11523 case REFERENCE_TYPE: 11524 /* We must set TREE_ASM_WRITTEN in case this is a recursive type. This 11525 ensures that the gen_type_die recursion will terminate even if the 11526 type is recursive. Recursive types are possible in Ada. */ 11527 /* ??? We could perhaps do this for all types before the switch 11528 statement. */ 11529 TREE_ASM_WRITTEN (type) = 1; 11530 11531 /* For these types, all that is required is that we output a DIE (or a 11532 set of DIEs) to represent the "basis" type. */ 11533 gen_type_die (TREE_TYPE (type), context_die); 11534 break; 11535 11536 case OFFSET_TYPE: 11537 /* This code is used for C++ pointer-to-data-member types. 11538 Output a description of the relevant class type. */ 11539 gen_type_die (TYPE_OFFSET_BASETYPE (type), context_die); 11540 11541 /* Output a description of the type of the object pointed to. */ 11542 gen_type_die (TREE_TYPE (type), context_die); 11543 11544 /* Now output a DIE to represent this pointer-to-data-member type 11545 itself. */ 11546 gen_ptr_to_mbr_type_die (type, context_die); 11547 break; 11548 11549 case SET_TYPE: 11550 gen_type_die (TYPE_DOMAIN (type), context_die); 11551 gen_set_type_die (type, context_die); 11552 break; 11553 11554 case FILE_TYPE: 11555 gen_type_die (TREE_TYPE (type), context_die); 11556 abort (); /* No way to represent these in Dwarf yet! */ 11557 break; 11558 11559 case FUNCTION_TYPE: 11560 /* Force out return type (in case it wasn't forced out already). */ 11561 gen_type_die (TREE_TYPE (type), context_die); 11562 gen_subroutine_type_die (type, context_die); 11563 break; 11564 11565 case METHOD_TYPE: 11566 /* Force out return type (in case it wasn't forced out already). */ 11567 gen_type_die (TREE_TYPE (type), context_die); 11568 gen_subroutine_type_die (type, context_die); 11569 break; 11570 11571 case ARRAY_TYPE: 11572 if (TYPE_STRING_FLAG (type) && TREE_CODE (TREE_TYPE (type)) == CHAR_TYPE) 11573 { 11574 gen_type_die (TREE_TYPE (type), context_die); 11575 gen_string_type_die (type, context_die); 11576 } 11577 else 11578 gen_array_type_die (type, context_die); 11579 break; 11580 11581 case VECTOR_TYPE: 11582 gen_array_type_die (type, context_die); 11583 break; 11584 11585 case ENUMERAL_TYPE: 11586 case RECORD_TYPE: 11587 case UNION_TYPE: 11588 case QUAL_UNION_TYPE: 11589 /* If this is a nested type whose containing class hasn't been written 11590 out yet, writing it out will cover this one, too. This does not apply 11591 to instantiations of member class templates; they need to be added to 11592 the containing class as they are generated. FIXME: This hurts the 11593 idea of combining type decls from multiple TUs, since we can't predict 11594 what set of template instantiations we'll get. */ 11595 if (TYPE_CONTEXT (type) 11596 && AGGREGATE_TYPE_P (TYPE_CONTEXT (type)) 11597 && ! TREE_ASM_WRITTEN (TYPE_CONTEXT (type))) 11598 { 11599 gen_type_die (TYPE_CONTEXT (type), context_die); 11600 11601 if (TREE_ASM_WRITTEN (type)) 11602 return; 11603 11604 /* If that failed, attach ourselves to the stub. */ 11605 push_decl_scope (TYPE_CONTEXT (type)); 11606 context_die = lookup_type_die (TYPE_CONTEXT (type)); 11607 need_pop = 1; 11608 } 11609 else 11610 need_pop = 0; 11611 11612 if (TREE_CODE (type) == ENUMERAL_TYPE) 11613 gen_enumeration_type_die (type, context_die); 11614 else 11615 gen_struct_or_union_type_die (type, context_die); 11616 11617 if (need_pop) 11618 pop_decl_scope (); 11619 11620 /* Don't set TREE_ASM_WRITTEN on an incomplete struct; we want to fix 11621 it up if it is ever completed. gen_*_type_die will set it for us 11622 when appropriate. */ 11623 return; 11624 11625 case VOID_TYPE: 11626 case INTEGER_TYPE: 11627 case REAL_TYPE: 11628 case COMPLEX_TYPE: 11629 case BOOLEAN_TYPE: 11630 case CHAR_TYPE: 11631 /* No DIEs needed for fundamental types. */ 11632 break; 11633 11634 case LANG_TYPE: 11635 /* No Dwarf representation currently defined. */ 11636 break; 11637 11638 default: 11639 abort (); 11640 } 11641 11642 TREE_ASM_WRITTEN (type) = 1; 11643} 11644 11645/* Generate a DIE for a tagged type instantiation. */ 11646 11647static void 11648gen_tagged_type_instantiation_die (type, context_die) 11649 tree type; 11650 dw_die_ref context_die; 11651{ 11652 if (type == NULL_TREE || type == error_mark_node) 11653 return; 11654 11655 /* We are going to output a DIE to represent the unqualified version of 11656 this type (i.e. without any const or volatile qualifiers) so make sure 11657 that we have the main variant (i.e. the unqualified version) of this 11658 type now. */ 11659 if (type != type_main_variant (type)) 11660 abort (); 11661 11662 /* Do not check TREE_ASM_WRITTEN (type) as it may not be set if this is 11663 an instance of an unresolved type. */ 11664 11665 switch (TREE_CODE (type)) 11666 { 11667 case ERROR_MARK: 11668 break; 11669 11670 case ENUMERAL_TYPE: 11671 gen_inlined_enumeration_type_die (type, context_die); 11672 break; 11673 11674 case RECORD_TYPE: 11675 gen_inlined_structure_type_die (type, context_die); 11676 break; 11677 11678 case UNION_TYPE: 11679 case QUAL_UNION_TYPE: 11680 gen_inlined_union_type_die (type, context_die); 11681 break; 11682 11683 default: 11684 abort (); 11685 } 11686} 11687 11688/* Generate a DW_TAG_lexical_block DIE followed by DIEs to represent all of the 11689 things which are local to the given block. */ 11690 11691static void 11692gen_block_die (stmt, context_die, depth) 11693 tree stmt; 11694 dw_die_ref context_die; 11695 int depth; 11696{ 11697 int must_output_die = 0; 11698 tree origin; 11699 tree decl; 11700 enum tree_code origin_code; 11701 11702 /* Ignore blocks never really used to make RTL. */ 11703 if (stmt == NULL_TREE || !TREE_USED (stmt) 11704 || (!TREE_ASM_WRITTEN (stmt) && !BLOCK_ABSTRACT (stmt))) 11705 return; 11706 11707 /* If the block is one fragment of a non-contiguous block, do not 11708 process the variables, since they will have been done by the 11709 origin block. Do process subblocks. */ 11710 if (BLOCK_FRAGMENT_ORIGIN (stmt)) 11711 { 11712 tree sub; 11713 11714 for (sub = BLOCK_SUBBLOCKS (stmt); sub; sub = BLOCK_CHAIN (sub)) 11715 gen_block_die (sub, context_die, depth + 1); 11716 11717 return; 11718 } 11719 11720 /* Determine the "ultimate origin" of this block. This block may be an 11721 inlined instance of an inlined instance of inline function, so we have 11722 to trace all of the way back through the origin chain to find out what 11723 sort of node actually served as the original seed for the creation of 11724 the current block. */ 11725 origin = block_ultimate_origin (stmt); 11726 origin_code = (origin != NULL) ? TREE_CODE (origin) : ERROR_MARK; 11727 11728 /* Determine if we need to output any Dwarf DIEs at all to represent this 11729 block. */ 11730 if (origin_code == FUNCTION_DECL) 11731 /* The outer scopes for inlinings *must* always be represented. We 11732 generate DW_TAG_inlined_subroutine DIEs for them. (See below.) */ 11733 must_output_die = 1; 11734 else 11735 { 11736 /* In the case where the current block represents an inlining of the 11737 "body block" of an inline function, we must *NOT* output any DIE for 11738 this block because we have already output a DIE to represent the whole 11739 inlined function scope and the "body block" of any function doesn't 11740 really represent a different scope according to ANSI C rules. So we 11741 check here to make sure that this block does not represent a "body 11742 block inlining" before trying to set the MUST_OUTPUT_DIE flag. */ 11743 if (! is_body_block (origin ? origin : stmt)) 11744 { 11745 /* Determine if this block directly contains any "significant" 11746 local declarations which we will need to output DIEs for. */ 11747 if (debug_info_level > DINFO_LEVEL_TERSE) 11748 /* We are not in terse mode so *any* local declaration counts 11749 as being a "significant" one. */ 11750 must_output_die = (BLOCK_VARS (stmt) != NULL); 11751 else 11752 /* We are in terse mode, so only local (nested) function 11753 definitions count as "significant" local declarations. */ 11754 for (decl = BLOCK_VARS (stmt); 11755 decl != NULL; decl = TREE_CHAIN (decl)) 11756 if (TREE_CODE (decl) == FUNCTION_DECL 11757 && DECL_INITIAL (decl)) 11758 { 11759 must_output_die = 1; 11760 break; 11761 } 11762 } 11763 } 11764 11765 /* It would be a waste of space to generate a Dwarf DW_TAG_lexical_block 11766 DIE for any block which contains no significant local declarations at 11767 all. Rather, in such cases we just call `decls_for_scope' so that any 11768 needed Dwarf info for any sub-blocks will get properly generated. Note 11769 that in terse mode, our definition of what constitutes a "significant" 11770 local declaration gets restricted to include only inlined function 11771 instances and local (nested) function definitions. */ 11772 if (must_output_die) 11773 { 11774 if (origin_code == FUNCTION_DECL) 11775 gen_inlined_subroutine_die (stmt, context_die, depth); 11776 else 11777 gen_lexical_block_die (stmt, context_die, depth); 11778 } 11779 else 11780 decls_for_scope (stmt, context_die, depth); 11781} 11782 11783/* Generate all of the decls declared within a given scope and (recursively) 11784 all of its sub-blocks. */ 11785 11786static void 11787decls_for_scope (stmt, context_die, depth) 11788 tree stmt; 11789 dw_die_ref context_die; 11790 int depth; 11791{ 11792 tree decl; 11793 tree subblocks; 11794 11795 /* Ignore blocks never really used to make RTL. */ 11796 if (stmt == NULL_TREE || ! TREE_USED (stmt)) 11797 return; 11798 11799 /* Output the DIEs to represent all of the data objects and typedefs 11800 declared directly within this block but not within any nested 11801 sub-blocks. Also, nested function and tag DIEs have been 11802 generated with a parent of NULL; fix that up now. */ 11803 for (decl = BLOCK_VARS (stmt); decl != NULL; decl = TREE_CHAIN (decl)) 11804 { 11805 dw_die_ref die; 11806 11807 if (TREE_CODE (decl) == FUNCTION_DECL) 11808 die = lookup_decl_die (decl); 11809 else if (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl)) 11810 die = lookup_type_die (TREE_TYPE (decl)); 11811 else 11812 die = NULL; 11813 11814 if (die != NULL && die->die_parent == NULL) 11815 add_child_die (context_die, die); 11816 else 11817 gen_decl_die (decl, context_die); 11818 } 11819 11820 /* If we're at -g1, we're not interested in subblocks. */ 11821 if (debug_info_level <= DINFO_LEVEL_TERSE) 11822 return; 11823 11824 /* Output the DIEs to represent all sub-blocks (and the items declared 11825 therein) of this block. */ 11826 for (subblocks = BLOCK_SUBBLOCKS (stmt); 11827 subblocks != NULL; 11828 subblocks = BLOCK_CHAIN (subblocks)) 11829 gen_block_die (subblocks, context_die, depth + 1); 11830} 11831 11832/* Is this a typedef we can avoid emitting? */ 11833 11834static inline int 11835is_redundant_typedef (decl) 11836 tree decl; 11837{ 11838 if (TYPE_DECL_IS_STUB (decl)) 11839 return 1; 11840 11841 if (DECL_ARTIFICIAL (decl) 11842 && DECL_CONTEXT (decl) 11843 && is_tagged_type (DECL_CONTEXT (decl)) 11844 && TREE_CODE (TYPE_NAME (DECL_CONTEXT (decl))) == TYPE_DECL 11845 && DECL_NAME (decl) == DECL_NAME (TYPE_NAME (DECL_CONTEXT (decl)))) 11846 /* Also ignore the artificial member typedef for the class name. */ 11847 return 1; 11848 11849 return 0; 11850} 11851 11852/* Generate Dwarf debug information for a decl described by DECL. */ 11853 11854static void 11855gen_decl_die (decl, context_die) 11856 tree decl; 11857 dw_die_ref context_die; 11858{ 11859 tree origin; 11860 11861 if (DECL_P (decl) && DECL_IGNORED_P (decl)) 11862 return; 11863 11864 switch (TREE_CODE (decl)) 11865 { 11866 case ERROR_MARK: 11867 break; 11868 11869 case CONST_DECL: 11870 /* The individual enumerators of an enum type get output when we output 11871 the Dwarf representation of the relevant enum type itself. */ 11872 break; 11873 11874 case FUNCTION_DECL: 11875 /* Don't output any DIEs to represent mere function declarations, 11876 unless they are class members or explicit block externs. */ 11877 if (DECL_INITIAL (decl) == NULL_TREE && DECL_CONTEXT (decl) == NULL_TREE 11878 && (current_function_decl == NULL_TREE || DECL_ARTIFICIAL (decl))) 11879 break; 11880 11881 /* If we're emitting a clone, emit info for the abstract instance. */ 11882 if (DECL_ORIGIN (decl) != decl) 11883 dwarf2out_abstract_function (DECL_ABSTRACT_ORIGIN (decl)); 11884 11885 /* If we're emitting an out-of-line copy of an inline function, 11886 emit info for the abstract instance and set up to refer to it. */ 11887 else if (DECL_INLINE (decl) && ! DECL_ABSTRACT (decl) 11888 && ! class_scope_p (context_die) 11889 /* dwarf2out_abstract_function won't emit a die if this is just 11890 a declaration. We must avoid setting DECL_ABSTRACT_ORIGIN in 11891 that case, because that works only if we have a die. */ 11892 && DECL_INITIAL (decl) != NULL_TREE) 11893 { 11894 dwarf2out_abstract_function (decl); 11895 set_decl_origin_self (decl); 11896 } 11897 11898 /* Otherwise we're emitting the primary DIE for this decl. */ 11899 else if (debug_info_level > DINFO_LEVEL_TERSE) 11900 { 11901 /* Before we describe the FUNCTION_DECL itself, make sure that we 11902 have described its return type. */ 11903 gen_type_die (TREE_TYPE (TREE_TYPE (decl)), context_die); 11904 11905 /* And its virtual context. */ 11906 if (DECL_VINDEX (decl) != NULL_TREE) 11907 gen_type_die (DECL_CONTEXT (decl), context_die); 11908 11909 /* And its containing type. */ 11910 origin = decl_class_context (decl); 11911 if (origin != NULL_TREE) 11912 gen_type_die_for_member (origin, decl, context_die); 11913 } 11914 11915 /* Now output a DIE to represent the function itself. */ 11916 gen_subprogram_die (decl, context_die); 11917 break; 11918 11919 case TYPE_DECL: 11920 /* If we are in terse mode, don't generate any DIEs to represent any 11921 actual typedefs. */ 11922 if (debug_info_level <= DINFO_LEVEL_TERSE) 11923 break; 11924 11925 /* In the special case of a TYPE_DECL node representing the declaration 11926 of some type tag, if the given TYPE_DECL is marked as having been 11927 instantiated from some other (original) TYPE_DECL node (e.g. one which 11928 was generated within the original definition of an inline function) we 11929 have to generate a special (abbreviated) DW_TAG_structure_type, 11930 DW_TAG_union_type, or DW_TAG_enumeration_type DIE here. */ 11931 if (TYPE_DECL_IS_STUB (decl) && decl_ultimate_origin (decl) != NULL_TREE) 11932 { 11933 gen_tagged_type_instantiation_die (TREE_TYPE (decl), context_die); 11934 break; 11935 } 11936 11937 if (is_redundant_typedef (decl)) 11938 gen_type_die (TREE_TYPE (decl), context_die); 11939 else 11940 /* Output a DIE to represent the typedef itself. */ 11941 gen_typedef_die (decl, context_die); 11942 break; 11943 11944 case LABEL_DECL: 11945 if (debug_info_level >= DINFO_LEVEL_NORMAL) 11946 gen_label_die (decl, context_die); 11947 break; 11948 11949 case VAR_DECL: 11950 /* If we are in terse mode, don't generate any DIEs to represent any 11951 variable declarations or definitions. */ 11952 if (debug_info_level <= DINFO_LEVEL_TERSE) 11953 break; 11954 11955 /* Output any DIEs that are needed to specify the type of this data 11956 object. */ 11957 gen_type_die (TREE_TYPE (decl), context_die); 11958 11959 /* And its containing type. */ 11960 origin = decl_class_context (decl); 11961 if (origin != NULL_TREE) 11962 gen_type_die_for_member (origin, decl, context_die); 11963 11964 /* Now output the DIE to represent the data object itself. This gets 11965 complicated because of the possibility that the VAR_DECL really 11966 represents an inlined instance of a formal parameter for an inline 11967 function. */ 11968 origin = decl_ultimate_origin (decl); 11969 if (origin != NULL_TREE && TREE_CODE (origin) == PARM_DECL) 11970 gen_formal_parameter_die (decl, context_die); 11971 else 11972 gen_variable_die (decl, context_die); 11973 break; 11974 11975 case FIELD_DECL: 11976 /* Ignore the nameless fields that are used to skip bits but handle C++ 11977 anonymous unions. */ 11978 if (DECL_NAME (decl) != NULL_TREE 11979 || TREE_CODE (TREE_TYPE (decl)) == UNION_TYPE) 11980 { 11981 gen_type_die (member_declared_type (decl), context_die); 11982 gen_field_die (decl, context_die); 11983 } 11984 break; 11985 11986 case PARM_DECL: 11987 gen_type_die (TREE_TYPE (decl), context_die); 11988 gen_formal_parameter_die (decl, context_die); 11989 break; 11990 11991 case NAMESPACE_DECL: 11992 /* Ignore for now. */ 11993 break; 11994 11995 default: 11996 abort (); 11997 } 11998} 11999 12000static void 12001mark_limbo_die_list (ptr) 12002 void *ptr ATTRIBUTE_UNUSED; 12003{ 12004 limbo_die_node *node; 12005 for (node = limbo_die_list; node; node = node->next) 12006 ggc_mark_tree (node->created_for); 12007} 12008 12009/* Add Ada "use" clause information for SGI Workshop debugger. */ 12010 12011void 12012dwarf2out_add_library_unit_info (filename, context_list) 12013 const char *filename; 12014 const char *context_list; 12015{ 12016 unsigned int file_index; 12017 12018 if (filename != NULL) 12019 { 12020 dw_die_ref unit_die = new_die (DW_TAG_module, comp_unit_die, NULL); 12021 tree context_list_decl 12022 = build_decl (LABEL_DECL, get_identifier (context_list), 12023 void_type_node); 12024 12025 TREE_PUBLIC (context_list_decl) = TRUE; 12026 add_name_attribute (unit_die, context_list); 12027 file_index = lookup_filename (filename); 12028 add_AT_unsigned (unit_die, DW_AT_decl_file, file_index); 12029 add_pubname (context_list_decl, unit_die); 12030 } 12031} 12032 12033/* Output debug information for global decl DECL. Called from toplev.c after 12034 compilation proper has finished. */ 12035 12036static void 12037dwarf2out_global_decl (decl) 12038 tree decl; 12039{ 12040 /* Output DWARF2 information for file-scope tentative data object 12041 declarations, file-scope (extern) function declarations (which had no 12042 corresponding body) and file-scope tagged type declarations and 12043 definitions which have not yet been forced out. */ 12044 if (TREE_CODE (decl) != FUNCTION_DECL || !DECL_INITIAL (decl)) 12045 dwarf2out_decl (decl); 12046} 12047 12048/* Write the debugging output for DECL. */ 12049 12050void 12051dwarf2out_decl (decl) 12052 tree decl; 12053{ 12054 dw_die_ref context_die = comp_unit_die; 12055 12056 switch (TREE_CODE (decl)) 12057 { 12058 case ERROR_MARK: 12059 return; 12060 12061 case FUNCTION_DECL: 12062 /* Ignore this FUNCTION_DECL if it refers to a builtin declaration of a 12063 builtin function. Explicit programmer-supplied declarations of 12064 these same functions should NOT be ignored however. */ 12065 if (DECL_EXTERNAL (decl) && DECL_BUILT_IN (decl)) 12066 return; 12067 12068 /* What we would really like to do here is to filter out all mere 12069 file-scope declarations of file-scope functions which are never 12070 referenced later within this translation unit (and keep all of ones 12071 that *are* referenced later on) but we aren't clairvoyant, so we have 12072 no idea which functions will be referenced in the future (i.e. later 12073 on within the current translation unit). So here we just ignore all 12074 file-scope function declarations which are not also definitions. If 12075 and when the debugger needs to know something about these functions, 12076 it will have to hunt around and find the DWARF information associated 12077 with the definition of the function. 12078 12079 We can't just check DECL_EXTERNAL to find out which FUNCTION_DECL 12080 nodes represent definitions and which ones represent mere 12081 declarations. We have to check DECL_INITIAL instead. That's because 12082 the C front-end supports some weird semantics for "extern inline" 12083 function definitions. These can get inlined within the current 12084 translation unit (an thus, we need to generate Dwarf info for their 12085 abstract instances so that the Dwarf info for the concrete inlined 12086 instances can have something to refer to) but the compiler never 12087 generates any out-of-lines instances of such things (despite the fact 12088 that they *are* definitions). 12089 12090 The important point is that the C front-end marks these "extern 12091 inline" functions as DECL_EXTERNAL, but we need to generate DWARF for 12092 them anyway. Note that the C++ front-end also plays some similar games 12093 for inline function definitions appearing within include files which 12094 also contain `#pragma interface' pragmas. */ 12095 if (DECL_INITIAL (decl) == NULL_TREE) 12096 return; 12097 12098 /* If we're a nested function, initially use a parent of NULL; if we're 12099 a plain function, this will be fixed up in decls_for_scope. If 12100 we're a method, it will be ignored, since we already have a DIE. */ 12101 if (decl_function_context (decl) 12102 /* But if we're in terse mode, we don't care about scope. */ 12103 && debug_info_level > DINFO_LEVEL_TERSE) 12104 context_die = NULL; 12105 break; 12106 12107 case VAR_DECL: 12108 /* Ignore this VAR_DECL if it refers to a file-scope extern data object 12109 declaration and if the declaration was never even referenced from 12110 within this entire compilation unit. We suppress these DIEs in 12111 order to save space in the .debug section (by eliminating entries 12112 which are probably useless). Note that we must not suppress 12113 block-local extern declarations (whether used or not) because that 12114 would screw-up the debugger's name lookup mechanism and cause it to 12115 miss things which really ought to be in scope at a given point. */ 12116 if (DECL_EXTERNAL (decl) && !TREE_USED (decl)) 12117 return; 12118 12119 /* If we are in terse mode, don't generate any DIEs to represent any 12120 variable declarations or definitions. */ 12121 if (debug_info_level <= DINFO_LEVEL_TERSE) 12122 return; 12123 break; 12124 12125 case TYPE_DECL: 12126 /* Don't emit stubs for types unless they are needed by other DIEs. */ 12127 if (TYPE_DECL_SUPPRESS_DEBUG (decl)) 12128 return; 12129 12130 /* Don't bother trying to generate any DIEs to represent any of the 12131 normal built-in types for the language we are compiling. */ 12132 if (DECL_SOURCE_LINE (decl) == 0) 12133 { 12134 /* OK, we need to generate one for `bool' so GDB knows what type 12135 comparisons have. */ 12136 if ((get_AT_unsigned (comp_unit_die, DW_AT_language) 12137 == DW_LANG_C_plus_plus) 12138 && TREE_CODE (TREE_TYPE (decl)) == BOOLEAN_TYPE 12139 && ! DECL_IGNORED_P (decl)) 12140 modified_type_die (TREE_TYPE (decl), 0, 0, NULL); 12141 12142 return; 12143 } 12144 12145 /* If we are in terse mode, don't generate any DIEs for types. */ 12146 if (debug_info_level <= DINFO_LEVEL_TERSE) 12147 return; 12148 12149 /* If we're a function-scope tag, initially use a parent of NULL; 12150 this will be fixed up in decls_for_scope. */ 12151 if (decl_function_context (decl)) 12152 context_die = NULL; 12153 12154 break; 12155 12156 default: 12157 return; 12158 } 12159 12160 gen_decl_die (decl, context_die); 12161} 12162 12163/* Output a marker (i.e. a label) for the beginning of the generated code for 12164 a lexical block. */ 12165 12166static void 12167dwarf2out_begin_block (line, blocknum) 12168 unsigned int line ATTRIBUTE_UNUSED; 12169 unsigned int blocknum; 12170{ 12171 function_section (current_function_decl); 12172 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_BEGIN_LABEL, blocknum); 12173} 12174 12175/* Output a marker (i.e. a label) for the end of the generated code for a 12176 lexical block. */ 12177 12178static void 12179dwarf2out_end_block (line, blocknum) 12180 unsigned int line ATTRIBUTE_UNUSED; 12181 unsigned int blocknum; 12182{ 12183 function_section (current_function_decl); 12184 ASM_OUTPUT_DEBUG_LABEL (asm_out_file, BLOCK_END_LABEL, blocknum); 12185} 12186 12187/* Returns nonzero if it is appropriate not to emit any debugging 12188 information for BLOCK, because it doesn't contain any instructions. 12189 12190 Don't allow this for blocks with nested functions or local classes 12191 as we would end up with orphans, and in the presence of scheduling 12192 we may end up calling them anyway. */ 12193 12194static bool 12195dwarf2out_ignore_block (block) 12196 tree block; 12197{ 12198 tree decl; 12199 12200 for (decl = BLOCK_VARS (block); decl; decl = TREE_CHAIN (decl)) 12201 if (TREE_CODE (decl) == FUNCTION_DECL 12202 || (TREE_CODE (decl) == TYPE_DECL && TYPE_DECL_IS_STUB (decl))) 12203 return 0; 12204 12205 return 1; 12206} 12207 12208/* Lookup FILE_NAME (in the list of filenames that we know about here in 12209 dwarf2out.c) and return its "index". The index of each (known) filename is 12210 just a unique number which is associated with only that one filename. We 12211 need such numbers for the sake of generating labels (in the .debug_sfnames 12212 section) and references to those files numbers (in the .debug_srcinfo 12213 and.debug_macinfo sections). If the filename given as an argument is not 12214 found in our current list, add it to the list and assign it the next 12215 available unique index number. In order to speed up searches, we remember 12216 the index of the filename was looked up last. This handles the majority of 12217 all searches. */ 12218 12219static unsigned 12220lookup_filename (file_name) 12221 const char *file_name; 12222{ 12223 unsigned i; 12224 12225 /* ??? Why isn't DECL_SOURCE_FILE left null instead. */ 12226 if (strcmp (file_name, "<internal>") == 0 12227 || strcmp (file_name, "<built-in>") == 0) 12228 return 0; 12229 12230 /* Check to see if the file name that was searched on the previous 12231 call matches this file name. If so, return the index. */ 12232 if (file_table.last_lookup_index != 0) 12233 if (0 == strcmp (file_name, 12234 file_table.table[file_table.last_lookup_index])) 12235 return file_table.last_lookup_index; 12236 12237 /* Didn't match the previous lookup, search the table */ 12238 for (i = 1; i < file_table.in_use; i++) 12239 if (strcmp (file_name, file_table.table[i]) == 0) 12240 { 12241 file_table.last_lookup_index = i; 12242 return i; 12243 } 12244 12245 /* Prepare to add a new table entry by making sure there is enough space in 12246 the table to do so. If not, expand the current table. */ 12247 if (i == file_table.allocated) 12248 { 12249 file_table.allocated = i + FILE_TABLE_INCREMENT; 12250 file_table.table = (char **) 12251 xrealloc (file_table.table, file_table.allocated * sizeof (char *)); 12252 } 12253 12254 /* Add the new entry to the end of the filename table. */ 12255 file_table.table[i] = xstrdup (file_name); 12256 file_table.in_use = i + 1; 12257 file_table.last_lookup_index = i; 12258 12259 if (DWARF2_ASM_LINE_DEBUG_INFO) 12260 { 12261 fprintf (asm_out_file, "\t.file %u ", i); 12262 output_quoted_string (asm_out_file, file_name); 12263 fputc ('\n', asm_out_file); 12264 } 12265 12266 return i; 12267} 12268 12269static void 12270init_file_table () 12271{ 12272 /* Allocate the initial hunk of the file_table. */ 12273 file_table.table = (char **) xcalloc (FILE_TABLE_INCREMENT, sizeof (char *)); 12274 file_table.allocated = FILE_TABLE_INCREMENT; 12275 12276 /* Skip the first entry - file numbers begin at 1. */ 12277 file_table.in_use = 1; 12278 file_table.last_lookup_index = 0; 12279} 12280 12281/* Output a label to mark the beginning of a source code line entry 12282 and record information relating to this source line, in 12283 'line_info_table' for later output of the .debug_line section. */ 12284 12285static void 12286dwarf2out_source_line (line, filename) 12287 unsigned int line; 12288 const char *filename; 12289{ 12290 if (debug_info_level >= DINFO_LEVEL_NORMAL) 12291 { 12292 function_section (current_function_decl); 12293 12294 /* If requested, emit something human-readable. */ 12295 if (flag_debug_asm) 12296 fprintf (asm_out_file, "\t%s %s:%d\n", ASM_COMMENT_START, 12297 filename, line); 12298 12299 if (DWARF2_ASM_LINE_DEBUG_INFO) 12300 { 12301 unsigned file_num = lookup_filename (filename); 12302 12303 /* Emit the .loc directive understood by GNU as. */ 12304 fprintf (asm_out_file, "\t.loc %d %d 0\n", file_num, line); 12305 12306 /* Indicate that line number info exists. */ 12307 line_info_table_in_use++; 12308 12309 /* Indicate that multiple line number tables exist. */ 12310 if (DECL_SECTION_NAME (current_function_decl)) 12311 separate_line_info_table_in_use++; 12312 } 12313 else if (DECL_SECTION_NAME (current_function_decl)) 12314 { 12315 dw_separate_line_info_ref line_info; 12316 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, SEPARATE_LINE_CODE_LABEL, 12317 separate_line_info_table_in_use); 12318 12319 /* expand the line info table if necessary */ 12320 if (separate_line_info_table_in_use 12321 == separate_line_info_table_allocated) 12322 { 12323 separate_line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; 12324 separate_line_info_table 12325 = (dw_separate_line_info_ref) 12326 xrealloc (separate_line_info_table, 12327 separate_line_info_table_allocated 12328 * sizeof (dw_separate_line_info_entry)); 12329 } 12330 12331 /* Add the new entry at the end of the line_info_table. */ 12332 line_info 12333 = &separate_line_info_table[separate_line_info_table_in_use++]; 12334 line_info->dw_file_num = lookup_filename (filename); 12335 line_info->dw_line_num = line; 12336 line_info->function = current_function_funcdef_no; 12337 } 12338 else 12339 { 12340 dw_line_info_ref line_info; 12341 12342 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, LINE_CODE_LABEL, 12343 line_info_table_in_use); 12344 12345 /* Expand the line info table if necessary. */ 12346 if (line_info_table_in_use == line_info_table_allocated) 12347 { 12348 line_info_table_allocated += LINE_INFO_TABLE_INCREMENT; 12349 line_info_table 12350 = (dw_line_info_ref) 12351 xrealloc (line_info_table, 12352 (line_info_table_allocated 12353 * sizeof (dw_line_info_entry))); 12354 } 12355 12356 /* Add the new entry at the end of the line_info_table. */ 12357 line_info = &line_info_table[line_info_table_in_use++]; 12358 line_info->dw_file_num = lookup_filename (filename); 12359 line_info->dw_line_num = line; 12360 } 12361 } 12362} 12363 12364/* Record the beginning of a new source file. */ 12365 12366static void 12367dwarf2out_start_source_file (lineno, filename) 12368 unsigned int lineno; 12369 const char *filename; 12370{ 12371 if (flag_eliminate_dwarf2_dups && !is_main_source) 12372 { 12373 /* Record the beginning of the file for break_out_includes. */ 12374 dw_die_ref bincl_die; 12375 12376 bincl_die = new_die (DW_TAG_GNU_BINCL, comp_unit_die, NULL); 12377 add_AT_string (bincl_die, DW_AT_name, filename); 12378 } 12379 12380 is_main_source = 0; 12381 12382 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12383 { 12384 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); 12385 dw2_asm_output_data (1, DW_MACINFO_start_file, "Start new file"); 12386 dw2_asm_output_data_uleb128 (lineno, "Included from line number %d", 12387 lineno); 12388 dw2_asm_output_data_uleb128 (lookup_filename (filename), 12389 "Filename we just started"); 12390 } 12391} 12392 12393/* Record the end of a source file. */ 12394 12395static void 12396dwarf2out_end_source_file (lineno) 12397 unsigned int lineno ATTRIBUTE_UNUSED; 12398{ 12399 if (flag_eliminate_dwarf2_dups) 12400 /* Record the end of the file for break_out_includes. */ 12401 new_die (DW_TAG_GNU_EINCL, comp_unit_die, NULL); 12402 12403 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12404 { 12405 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); 12406 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); 12407 } 12408} 12409 12410/* Called from debug_define in toplev.c. The `buffer' parameter contains 12411 the tail part of the directive line, i.e. the part which is past the 12412 initial whitespace, #, whitespace, directive-name, whitespace part. */ 12413 12414static void 12415dwarf2out_define (lineno, buffer) 12416 unsigned lineno ATTRIBUTE_UNUSED; 12417 const char *buffer ATTRIBUTE_UNUSED; 12418{ 12419 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12420 { 12421 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); 12422 dw2_asm_output_data (1, DW_MACINFO_define, "Define macro"); 12423 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); 12424 dw2_asm_output_nstring (buffer, -1, "The macro"); 12425 } 12426} 12427 12428/* Called from debug_undef in toplev.c. The `buffer' parameter contains 12429 the tail part of the directive line, i.e. the part which is past the 12430 initial whitespace, #, whitespace, directive-name, whitespace part. */ 12431 12432static void 12433dwarf2out_undef (lineno, buffer) 12434 unsigned lineno ATTRIBUTE_UNUSED; 12435 const char *buffer ATTRIBUTE_UNUSED; 12436{ 12437 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12438 { 12439 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); 12440 dw2_asm_output_data (1, DW_MACINFO_undef, "Undefine macro"); 12441 dw2_asm_output_data_uleb128 (lineno, "At line number %d", lineno); 12442 dw2_asm_output_nstring (buffer, -1, "The macro"); 12443 } 12444} 12445 12446/* Set up for Dwarf output at the start of compilation. */ 12447 12448static void 12449dwarf2out_init (main_input_filename) 12450 const char *main_input_filename; 12451{ 12452 init_file_table (); 12453 12454 /* Remember the name of the primary input file. */ 12455 primary_filename = main_input_filename; 12456 12457 /* Add it to the file table first, under the assumption that we'll 12458 be emitting line number data for it first, which avoids having 12459 to add an initial DW_LNS_set_file. */ 12460 lookup_filename (main_input_filename); 12461 12462 /* Allocate the initial hunk of the decl_die_table. */ 12463 decl_die_table 12464 = (dw_die_ref *) xcalloc (DECL_DIE_TABLE_INCREMENT, sizeof (dw_die_ref)); 12465 decl_die_table_allocated = DECL_DIE_TABLE_INCREMENT; 12466 decl_die_table_in_use = 0; 12467 12468 /* Allocate the initial hunk of the decl_scope_table. */ 12469 VARRAY_TREE_INIT (decl_scope_table, 256, "decl_scope_table"); 12470 12471 /* Allocate the initial hunk of the abbrev_die_table. */ 12472 abbrev_die_table 12473 = (dw_die_ref *) xcalloc (ABBREV_DIE_TABLE_INCREMENT, 12474 sizeof (dw_die_ref)); 12475 abbrev_die_table_allocated = ABBREV_DIE_TABLE_INCREMENT; 12476 /* Zero-th entry is allocated, but unused */ 12477 abbrev_die_table_in_use = 1; 12478 12479 /* Allocate the initial hunk of the line_info_table. */ 12480 line_info_table 12481 = (dw_line_info_ref) xcalloc (LINE_INFO_TABLE_INCREMENT, 12482 sizeof (dw_line_info_entry)); 12483 line_info_table_allocated = LINE_INFO_TABLE_INCREMENT; 12484 12485 /* Zero-th entry is allocated, but unused */ 12486 line_info_table_in_use = 1; 12487 12488 /* Generate the initial DIE for the .debug section. Note that the (string) 12489 value given in the DW_AT_name attribute of the DW_TAG_compile_unit DIE 12490 will (typically) be a relative pathname and that this pathname should be 12491 taken as being relative to the directory from which the compiler was 12492 invoked when the given (base) source file was compiled. */ 12493 comp_unit_die = gen_compile_unit_die (main_input_filename); 12494 is_main_source = 1; 12495 12496 VARRAY_TREE_INIT (incomplete_types, 64, "incomplete_types"); 12497 12498 VARRAY_RTX_INIT (used_rtx_varray, 32, "used_rtx_varray"); 12499 12500 ggc_add_root (&limbo_die_list, 1, 1, mark_limbo_die_list); 12501 12502 ASM_GENERATE_INTERNAL_LABEL (text_end_label, TEXT_END_LABEL, 0); 12503 ASM_GENERATE_INTERNAL_LABEL (abbrev_section_label, 12504 DEBUG_ABBREV_SECTION_LABEL, 0); 12505 if (DWARF2_GENERATE_TEXT_SECTION_LABEL) 12506 ASM_GENERATE_INTERNAL_LABEL (text_section_label, TEXT_SECTION_LABEL, 0); 12507 else 12508 strcpy (text_section_label, stripattributes (TEXT_SECTION_NAME)); 12509 12510 ASM_GENERATE_INTERNAL_LABEL (debug_info_section_label, 12511 DEBUG_INFO_SECTION_LABEL, 0); 12512 ASM_GENERATE_INTERNAL_LABEL (debug_line_section_label, 12513 DEBUG_LINE_SECTION_LABEL, 0); 12514 ASM_GENERATE_INTERNAL_LABEL (ranges_section_label, 12515 DEBUG_RANGES_SECTION_LABEL, 0); 12516 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); 12517 ASM_OUTPUT_LABEL (asm_out_file, abbrev_section_label); 12518 named_section_flags (DEBUG_INFO_SECTION, SECTION_DEBUG); 12519 ASM_OUTPUT_LABEL (asm_out_file, debug_info_section_label); 12520 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); 12521 ASM_OUTPUT_LABEL (asm_out_file, debug_line_section_label); 12522 12523 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12524 { 12525 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); 12526 ASM_GENERATE_INTERNAL_LABEL (macinfo_section_label, 12527 DEBUG_MACINFO_SECTION_LABEL, 0); 12528 ASM_OUTPUT_LABEL (asm_out_file, macinfo_section_label); 12529 } 12530 12531 if (DWARF2_GENERATE_TEXT_SECTION_LABEL) 12532 { 12533 text_section (); 12534 ASM_OUTPUT_LABEL (asm_out_file, text_section_label); 12535 } 12536} 12537 12538/* Allocate a string in .debug_str hash table. */ 12539 12540static hashnode 12541indirect_string_alloc (tab) 12542 hash_table *tab ATTRIBUTE_UNUSED; 12543{ 12544 struct indirect_string_node *node; 12545 12546 node = xmalloc (sizeof (struct indirect_string_node)); 12547 node->refcount = 0; 12548 node->form = 0; 12549 node->label = NULL; 12550 12551 return (hashnode) node; 12552} 12553 12554/* A helper function for dwarf2out_finish called through 12555 ht_forall. Emit one queued .debug_str string. */ 12556 12557static int 12558output_indirect_string (pfile, h, v) 12559 struct cpp_reader *pfile ATTRIBUTE_UNUSED; 12560 hashnode h; 12561 const PTR v ATTRIBUTE_UNUSED; 12562{ 12563 struct indirect_string_node *node = (struct indirect_string_node *) h; 12564 12565 if (node->form == DW_FORM_strp) 12566 { 12567 named_section_flags (DEBUG_STR_SECTION, DEBUG_STR_SECTION_FLAGS); 12568 ASM_OUTPUT_LABEL (asm_out_file, node->label); 12569 assemble_string ((const char *) HT_STR (&node->id), 12570 HT_LEN (&node->id) + 1); 12571 } 12572 12573 return 1; 12574} 12575 12576/* Output stuff that dwarf requires at the end of every file, 12577 and generate the DWARF-2 debugging info. */ 12578 12579static void 12580dwarf2out_finish (input_filename) 12581 const char *input_filename ATTRIBUTE_UNUSED; 12582{ 12583 limbo_die_node *node, *next_node; 12584 dw_die_ref die = 0; 12585 12586 /* Traverse the limbo die list, and add parent/child links. The only 12587 dies without parents that should be here are concrete instances of 12588 inline functions, and the comp_unit_die. We can ignore the comp_unit_die. 12589 For concrete instances, we can get the parent die from the abstract 12590 instance. */ 12591 for (node = limbo_die_list; node; node = next_node) 12592 { 12593 next_node = node->next; 12594 die = node->die; 12595 12596 if (die->die_parent == NULL) 12597 { 12598 dw_die_ref origin = get_AT_ref (die, DW_AT_abstract_origin); 12599 tree context; 12600 12601 if (origin) 12602 add_child_die (origin->die_parent, die); 12603 else if (die == comp_unit_die) 12604 ; 12605 /* If this was an expression for a bound involved in a function 12606 return type, it may be a SAVE_EXPR for which we weren't able 12607 to find a DIE previously. So try now. */ 12608 else if (node->created_for 12609 && TREE_CODE (node->created_for) == SAVE_EXPR 12610 && 0 != (origin = (lookup_decl_die 12611 (SAVE_EXPR_CONTEXT 12612 (node->created_for))))) 12613 add_child_die (origin, die); 12614 else if (errorcount > 0 || sorrycount > 0) 12615 /* It's OK to be confused by errors in the input. */ 12616 add_child_die (comp_unit_die, die); 12617 else if (node->created_for 12618 && ((DECL_P (node->created_for) 12619 && (context = DECL_CONTEXT (node->created_for))) 12620 || (TYPE_P (node->created_for) 12621 && (context = TYPE_CONTEXT (node->created_for)))) 12622 && TREE_CODE (context) == FUNCTION_DECL) 12623 { 12624 /* In certain situations, the lexical block containing a 12625 nested function can be optimized away, which results 12626 in the nested function die being orphaned. Likewise 12627 with the return type of that nested function. Force 12628 this to be a child of the containing function. */ 12629 origin = lookup_decl_die (context); 12630 if (! origin) 12631 abort (); 12632 add_child_die (origin, die); 12633 } 12634 else 12635 abort (); 12636 } 12637 12638 free (node); 12639 } 12640 12641 limbo_die_list = NULL; 12642 12643 /* Walk through the list of incomplete types again, trying once more to 12644 emit full debugging info for them. */ 12645 retry_incomplete_types (); 12646 12647 /* We need to reverse all the dies before break_out_includes, or 12648 we'll see the end of an include file before the beginning. */ 12649 reverse_all_dies (comp_unit_die); 12650 12651 /* Generate separate CUs for each of the include files we've seen. 12652 They will go into limbo_die_list. */ 12653 if (flag_eliminate_dwarf2_dups) 12654 break_out_includes (comp_unit_die); 12655 12656 /* Traverse the DIE's and add add sibling attributes to those DIE's 12657 that have children. */ 12658 add_sibling_attributes (comp_unit_die); 12659 for (node = limbo_die_list; node; node = node->next) 12660 add_sibling_attributes (node->die); 12661 12662 /* Output a terminator label for the .text section. */ 12663 text_section (); 12664 ASM_OUTPUT_INTERNAL_LABEL (asm_out_file, TEXT_END_LABEL, 0); 12665 12666 /* Output the source line correspondence table. We must do this 12667 even if there is no line information. Otherwise, on an empty 12668 translation unit, we will generate a present, but empty, 12669 .debug_info section. IRIX 6.5 `nm' will then complain when 12670 examining the file. */ 12671 if (! DWARF2_ASM_LINE_DEBUG_INFO) 12672 { 12673 named_section_flags (DEBUG_LINE_SECTION, SECTION_DEBUG); 12674 output_line_info (); 12675 } 12676 12677 /* Output location list section if necessary. */ 12678 if (have_location_lists) 12679 { 12680 /* Output the location lists info. */ 12681 named_section_flags (DEBUG_LOC_SECTION, SECTION_DEBUG); 12682 ASM_GENERATE_INTERNAL_LABEL (loc_section_label, 12683 DEBUG_LOC_SECTION_LABEL, 0); 12684 ASM_OUTPUT_LABEL (asm_out_file, loc_section_label); 12685 output_location_lists (die); 12686 have_location_lists = 0; 12687 } 12688 12689 /* We can only use the low/high_pc attributes if all of the code was 12690 in .text. */ 12691 if (separate_line_info_table_in_use == 0) 12692 { 12693 add_AT_lbl_id (comp_unit_die, DW_AT_low_pc, text_section_label); 12694 add_AT_lbl_id (comp_unit_die, DW_AT_high_pc, text_end_label); 12695 } 12696 12697 /* If it wasn't, we need to give .debug_loc and .debug_ranges an appropriate 12698 "base address". Use zero so that these addresses become absolute. */ 12699 else if (have_location_lists || ranges_table_in_use) 12700 add_AT_addr (comp_unit_die, DW_AT_entry_pc, const0_rtx); 12701 12702 if (debug_info_level >= DINFO_LEVEL_NORMAL) 12703 add_AT_lbl_offset (comp_unit_die, DW_AT_stmt_list, 12704 debug_line_section_label); 12705 12706 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12707 add_AT_lbl_offset (comp_unit_die, DW_AT_macro_info, macinfo_section_label); 12708 12709 /* Output all of the compilation units. We put the main one last so that 12710 the offsets are available to output_pubnames. */ 12711 for (node = limbo_die_list; node; node = node->next) 12712 output_comp_unit (node->die, 0); 12713 12714 output_comp_unit (comp_unit_die, 0); 12715 12716 /* Output the abbreviation table. */ 12717 named_section_flags (DEBUG_ABBREV_SECTION, SECTION_DEBUG); 12718 output_abbrev_section (); 12719 12720 /* Output public names table if necessary. */ 12721 if (pubname_table_in_use) 12722 { 12723 named_section_flags (DEBUG_PUBNAMES_SECTION, SECTION_DEBUG); 12724 output_pubnames (); 12725 } 12726 12727 /* Output the address range information. We only put functions in the arange 12728 table, so don't write it out if we don't have any. */ 12729 if (fde_table_in_use) 12730 { 12731 named_section_flags (DEBUG_ARANGES_SECTION, SECTION_DEBUG); 12732 output_aranges (); 12733 } 12734 12735 /* Output ranges section if necessary. */ 12736 if (ranges_table_in_use) 12737 { 12738 named_section_flags (DEBUG_RANGES_SECTION, SECTION_DEBUG); 12739 ASM_OUTPUT_LABEL (asm_out_file, ranges_section_label); 12740 output_ranges (); 12741 } 12742 12743 /* Have to end the primary source file. */ 12744 if (debug_info_level >= DINFO_LEVEL_VERBOSE) 12745 { 12746 named_section_flags (DEBUG_MACINFO_SECTION, SECTION_DEBUG); 12747 dw2_asm_output_data (1, DW_MACINFO_end_file, "End file"); 12748 dw2_asm_output_data (1, 0, "End compilation unit"); 12749 } 12750 12751 /* If we emitted any DW_FORM_strp form attribute, output the string 12752 table too. */ 12753 if (debug_str_hash) 12754 ht_forall (debug_str_hash, output_indirect_string, NULL); 12755} 12756#else 12757 12758/* This should never be used, but its address is needed for comparisons. */ 12759const struct gcc_debug_hooks dwarf2_debug_hooks; 12760 12761#endif /* DWARF2_DEBUGGING_INFO */ 12762 12763#include "gt-dwarf2out.h" 12764