|
|
1.1 root 1: /* This file contains code written by Ron Guilmette ([email protected]) for 2: Network Computing Devices, August, September, October, November 1990. 3: 4: Output Dwarf format symbol table information from the GNU C compiler. 5: Copyright (C) 1992 Free Software Foundation, Inc. 6: 7: This file is part of GNU CC. 8: 9: GNU CC is free software; you can redistribute it and/or modify 10: it under the terms of the GNU General Public License as published by 11: the Free Software Foundation; either version 2, or (at your option) 12: any later version. 13: 14: GNU CC is distributed in the hope that it will be useful, 15: but WITHOUT ANY WARRANTY; without even the implied warranty of 16: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17: GNU General Public License for more details. 18: 19: You should have received a copy of the GNU General Public License 20: along with GNU CC; see the file COPYING. If not, write to 21: the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */ 22: 23: #include "config.h" 24: 25: #ifdef DWARF_DEBUGGING_INFO 26: #include <stdio.h> 27: #include "dwarf.h" 28: #include "tree.h" 29: #include "flags.h" 30: #include "rtl.h" 31: #include "insn-config.h" 32: #include "reload.h" 33: #include "output.h" 34: 35: /* #define NDEBUG 1 */ 36: #include <assert.h> 37: 38: #if defined(DWARF_TIMESTAMPS) 39: #if defined(POSIX) 40: #include <time.h> 41: #else /* !defined(POSIX) */ 42: #include <sys/types.h> 43: #if defined(__STDC__) 44: extern time_t time (time_t *); 45: #else /* !defined(__STDC__) */ 46: extern time_t time (); 47: #endif /* !defined(__STDC__) */ 48: #endif /* !defined(POSIX) */ 49: #endif /* defined(DWARF_TIMESTAMPS) */ 50: 51: #if defined(USG) || defined(POSIX) 52: #include <string.h> 53: #else 54: #include <strings.h> 55: #define strrchr rindex 56: #endif 57: 1.1.1.2 ! root 58: char *getpwd (); ! 59: ! 60: 1.1 root 61: /* IMPORTANT NOTE: Please see the file README.DWARF for important details 62: regarding the GNU implementation of Dwarf. */ 63: 64: /* NOTE: In the comments in this file, many references are made to 65: so called "Debugging Information Entries". For the sake of brevity, 66: this term is abbreviated to `DIE' throughout the remainder of this 67: file. */ 68: 69: /* Note that the implementation of C++ support herein is (as yet) unfinished. 70: If you want to try to complete it, more power to you. */ 71: 72: #if defined(__GNUC__) && (NDEBUG == 1) 73: #define inline static inline 74: #else 75: #define inline static 76: #endif 77: 78: /* How to start an assembler comment. */ 79: #ifndef ASM_COMMENT_START 80: #define ASM_COMMENT_START ";#" 81: #endif 82: 83: /* Define a macro which, when given a pointer to some BLOCK node, returns 84: a pointer to the FUNCTION_DECL node from which the given BLOCK node 85: was instantiated (as an inline expansion). This macro needs to be 86: defined properly in tree.h, however for the moment, we just fake it. */ 87: 88: #define BLOCK_INLINE_FUNCTION(block) 0 89: 90: /* Define a macro which returns non-zero for any tagged type which is 91: used (directly or indirectly) in the specification of either some 92: function's return type or some formal parameter of some function. 93: We use this macro when we are operating in "terse" mode to help us 94: know what tagged types have to be represented in Dwarf (even in 95: terse mode) and which ones don't. 96: 97: A flag bit with this meaning really should be a part of the normal 98: GCC ..._TYPE nodes, but at the moment, there is no such bit defined 99: for these nodes. For now, we have to just fake it. It it safe for 100: us to simply return zero for all complete tagged types (which will 101: get forced out anyway if they were used in the specification of some 102: formal or return type) and non-zero for all incomplete tagged types. 103: */ 104: 105: #define TYPE_USED_FOR_FUNCTION(tagged_type) (TYPE_SIZE (tagged_type) == 0) 106: 107: #define BITFIELD_OFFSET_BITS(DECL) \ 108: ((unsigned) TREE_INT_CST_LOW (DECL_FIELD_BITPOS (DECL))) 109: #define BITFIELD_OFFSET_UNITS(DECL) \ 110: (BITFIELD_OFFSET_BITS(DECL) / (unsigned) BITS_PER_UNIT) 111: #define BITFIELD_OFFSET_WORDS_IN_UNITS(DECL) \ 112: ((BITFIELD_OFFSET_BITS(DECL) / (unsigned) BITS_PER_WORD) * UNITS_PER_WORD) 113: 114: extern int flag_traditional; 115: extern char *version_string; 116: extern char *language_string; 117: 118: /* Maximum size (in bytes) of an artificially generated label. */ 119: 120: #define MAX_ARTIFICIAL_LABEL_BYTES 30 121: 122: /* Make sure we know the sizes of the various types dwarf can describe. 123: These are only defaults. If the sizes are different for your target, 124: you should override these values by defining the appropriate symbols 125: in your tm.h file. */ 126: 127: #ifndef CHAR_TYPE_SIZE 128: #define CHAR_TYPE_SIZE BITS_PER_UNIT 129: #endif 130: 131: #ifndef SHORT_TYPE_SIZE 132: #define SHORT_TYPE_SIZE (BITS_PER_UNIT * 2) 133: #endif 134: 135: #ifndef INT_TYPE_SIZE 136: #define INT_TYPE_SIZE BITS_PER_WORD 137: #endif 138: 139: #ifndef LONG_TYPE_SIZE 140: #define LONG_TYPE_SIZE BITS_PER_WORD 141: #endif 142: 143: #ifndef LONG_LONG_TYPE_SIZE 144: #define LONG_LONG_TYPE_SIZE (BITS_PER_WORD * 2) 145: #endif 146: 147: #ifndef WCHAR_TYPE_SIZE 148: #define WCHAR_TYPE_SIZE INT_TYPE_SIZE 149: #endif 150: 151: #ifndef WCHAR_UNSIGNED 152: #define WCHAR_UNSIGNED 0 153: #endif 154: 155: #ifndef FLOAT_TYPE_SIZE 156: #define FLOAT_TYPE_SIZE BITS_PER_WORD 157: #endif 158: 159: #ifndef DOUBLE_TYPE_SIZE 160: #define DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) 161: #endif 162: 163: #ifndef LONG_DOUBLE_TYPE_SIZE 164: #define LONG_DOUBLE_TYPE_SIZE (BITS_PER_WORD * 2) 165: #endif 166: 167: /* Structure to keep track of source filenames. */ 168: 169: struct filename_entry { 170: unsigned number; 171: char * name; 172: }; 173: 174: typedef struct filename_entry filename_entry; 175: 176: /* Pointer to an array of elements, each one having the structure above. */ 177: 178: static filename_entry *filename_table; 179: 180: /* Total number of entries in the table (i.e. array) pointed to by 181: `filename_table'. This is the *total* and includes both used and 182: unused slots. */ 183: 184: static unsigned ft_entries_allocated; 185: 186: /* Number of entries in the filename_table which are actually in use. */ 187: 188: static unsigned ft_entries; 189: 190: /* Size (in elements) of increments by which we may expand the filename 191: table. Actually, a single hunk of space of this size should be enough 192: for most typical programs. */ 193: 194: #define FT_ENTRIES_INCREMENT 64 195: 196: /* Local pointer to the name of the main input file. Initialized in 197: dwarfout_init. */ 198: 199: static char *primary_filename; 200: 201: /* Pointer to the most recent filename for which we produced some line info. */ 202: 203: static char *last_filename; 204: 205: /* For Dwarf output, we must assign lexical-blocks id numbers 206: in the order in which their beginnings are encountered. 207: We output Dwarf debugging info that refers to the beginnings 208: and ends of the ranges of code for each lexical block with 209: assembler labels ..Bn and ..Bn.e, where n is the block number. 210: The labels themselves are generated in final.c, which assigns 211: numbers to the blocks in the same way. */ 212: 213: static unsigned next_block_number = 2; 214: 215: /* Counter to generate unique names for DIEs. */ 216: 217: static unsigned next_unused_dienum = 1; 218: 219: /* Number of the DIE which is currently being generated. */ 220: 221: static unsigned current_dienum; 222: 223: /* Number to use for the special "pubname" label on the next DIE which 224: represents a function or data object defined in this compilation 225: unit which has "extern" linkage. */ 226: 227: static next_pubname_number = 0; 228: 229: #define NEXT_DIE_NUM pending_sibling_stack[pending_siblings-1] 230: 231: /* Pointer to a dynamically allocated list of pre-reserved and still 232: pending sibling DIE numbers. Note that this list will grow as needed. */ 233: 234: static unsigned *pending_sibling_stack; 235: 236: /* Counter to keep track of the number of pre-reserved and still pending 237: sibling DIE numbers. */ 238: 239: static unsigned pending_siblings; 240: 241: /* The currently allocated size of the above list (expressed in number of 242: list elements). */ 243: 244: static unsigned pending_siblings_allocated; 245: 246: /* Size (in elements) of increments by which we may expand the pending 247: sibling stack. Actually, a single hunk of space of this size should 248: be enough for most typical programs. */ 249: 250: #define PENDING_SIBLINGS_INCREMENT 64 251: 252: /* Non-zero if we are performing our file-scope finalization pass and if 253: we should force out Dwarf decsriptions of any and all file-scope 254: tagged types which are still incomplete types. */ 255: 256: static int finalizing = 0; 257: 258: /* A pointer to the base of a list of pending types which we haven't 259: generated DIEs for yet, but which we will have to come back to 260: later on. */ 261: 262: static tree *pending_types_list; 263: 264: /* Number of elements currently allocated for the pending_types_list. */ 265: 266: static unsigned pending_types_allocated; 267: 268: /* Number of elements of pending_types_list currently in use. */ 269: 270: static unsigned pending_types; 271: 272: /* Size (in elements) of increments by which we may expand the pending 273: types list. Actually, a single hunk of space of this size should 274: be enough for most typical programs. */ 275: 276: #define PENDING_TYPES_INCREMENT 64 277: 278: /* Pointer to an artifical RECORD_TYPE which we create in dwarfout_init. 279: This is used in a hack to help us get the DIEs describing types of 280: formal parameters to come *after* all of the DIEs describing the formal 281: parameters themselves. That's necessary in order to be compatible 282: with what the brain-dammaged svr4 SDB debugger requires. */ 283: 284: static tree fake_containing_scope; 285: 286: /* The number of the current function definition that we are generating 287: debugging information for. These numbers range from 1 up to the maximum 288: number of function definitions contained within the current compilation 289: unit. These numbers are used to create unique labels for various things 290: contained within various function definitions. */ 291: 292: static unsigned current_funcdef_number = 1; 293: 294: /* Forward declarations for functions defined in this file. */ 295: 296: static void output_type (); 297: static void type_attribute (); 298: static void output_decls_for_scope (); 299: static void output_decl (); 300: static unsigned lookup_filename (); 301: 302: /* Definitions of defaults for assembler-dependent names of various 303: pseudo-ops and section names. 304: 305: Theses may be overridden in your tm.h file (if necessary) for your 306: particular assembler. The default values provided here correspond to 307: what is expected by "standard" AT&T System V.4 assemblers. */ 308: 309: #ifndef FILE_ASM_OP 1.1.1.2 ! root 310: #define FILE_ASM_OP ".file" 1.1 root 311: #endif 312: #ifndef VERSION_ASM_OP 1.1.1.2 ! root 313: #define VERSION_ASM_OP ".version" 1.1 root 314: #endif 315: #ifndef SECTION_ASM_OP 1.1.1.2 ! root 316: #define SECTION_ASM_OP ".section" 1.1 root 317: #endif 318: #ifndef UNALIGNED_SHORT_ASM_OP 1.1.1.2 ! root 319: #define UNALIGNED_SHORT_ASM_OP ".2byte" 1.1 root 320: #endif 321: #ifndef UNALIGNED_INT_ASM_OP 1.1.1.2 ! root 322: #define UNALIGNED_INT_ASM_OP ".4byte" 1.1 root 323: #endif 324: #ifndef DEF_ASM_OP 1.1.1.2 ! root 325: #define DEF_ASM_OP ".set" 1.1 root 326: #endif 327: 328: /* This macro is already used elsewhere and has a published default. */ 329: #ifndef ASM_BYTE_OP 330: #define ASM_BYTE_OP "\t.byte" 331: #endif 332: 333: /* Definitions of defaults for formats and names of various special 334: (artificial) labels which may be generated within this file (when 335: the -g options is used and DWARF_DEBUGGING_INFO is in effect. 336: 337: If necessary, these may be overridden from within your tm.h file, 338: but typically, you should never need to override these. */ 339: 340: #ifndef TEXT_BEGIN_LABEL 341: #define TEXT_BEGIN_LABEL "._text_b" 342: #endif 343: #ifndef TEXT_END_LABEL 344: #define TEXT_END_LABEL "._text_e" 345: #endif 346: 347: #ifndef DATA_BEGIN_LABEL 348: #define DATA_BEGIN_LABEL "._data_b" 349: #endif 350: #ifndef DATA_END_LABEL 351: #define DATA_END_LABEL "._data_e" 352: #endif 353: 354: #ifndef DATA1_BEGIN_LABEL 355: #define DATA1_BEGIN_LABEL "._data1_b" 356: #endif 357: #ifndef DATA1_END_LABEL 358: #define DATA1_END_LABEL "._data1_e" 359: #endif 360: 361: #ifndef RODATA_BEGIN_LABEL 362: #define RODATA_BEGIN_LABEL "._rodata_b" 363: #endif 364: #ifndef RODATA_END_LABEL 365: #define RODATA_END_LABEL "._rodata_e" 366: #endif 367: 368: #ifndef RODATA1_BEGIN_LABEL 369: #define RODATA1_BEGIN_LABEL "._rodata1_b" 370: #endif 371: #ifndef RODATA1_END_LABEL 372: #define RODATA1_END_LABEL "._rodata1_e" 373: #endif 374: 375: #ifndef BSS_BEGIN_LABEL 376: #define BSS_BEGIN_LABEL "._bss_b" 377: #endif 378: #ifndef BSS_END_LABEL 379: #define BSS_END_LABEL "._bss_e" 380: #endif 381: 382: #ifndef LINE_BEGIN_LABEL 383: #define LINE_BEGIN_LABEL "._line_b" 384: #endif 385: #ifndef LINE_LAST_ENTRY_LABEL 386: #define LINE_LAST_ENTRY_LABEL "._line_last" 387: #endif 388: #ifndef LINE_END_LABEL 389: #define LINE_END_LABEL "._line_e" 390: #endif 391: 392: #ifndef DEBUG_BEGIN_LABEL 393: #define DEBUG_BEGIN_LABEL "._debug_b" 394: #endif 395: #ifndef SFNAMES_BEGIN_LABEL 396: #define SFNAMES_BEGIN_LABEL "._sfnames_b" 397: #endif 398: #ifndef SRCINFO_BEGIN_LABEL 399: #define SRCINFO_BEGIN_LABEL "._srcinfo_b" 400: #endif 401: #ifndef MACINFO_BEGIN_LABEL 402: #define MACINFO_BEGIN_LABEL "._macinfo_b" 403: #endif 404: 405: #ifndef DIE_BEGIN_LABEL_FMT 406: #define DIE_BEGIN_LABEL_FMT "._D%u" 407: #endif 408: #ifndef DIE_END_LABEL_FMT 409: #define DIE_END_LABEL_FMT "._D%u_e" 410: #endif 411: #ifndef PUB_DIE_LABEL_FMT 412: #define PUB_DIE_LABEL_FMT "._P%u" 413: #endif 414: #ifndef INSN_LABEL_FMT 415: #define INSN_LABEL_FMT "._I%u_%u" 416: #endif 417: #ifndef BLOCK_BEGIN_LABEL_FMT 418: #define BLOCK_BEGIN_LABEL_FMT "._B%u" 419: #endif 420: #ifndef BLOCK_END_LABEL_FMT 421: #define BLOCK_END_LABEL_FMT "._B%u_e" 422: #endif 423: #ifndef SS_BEGIN_LABEL_FMT 424: #define SS_BEGIN_LABEL_FMT "._s%u" 425: #endif 426: #ifndef SS_END_LABEL_FMT 427: #define SS_END_LABEL_FMT "._s%u_e" 428: #endif 429: #ifndef EE_BEGIN_LABEL_FMT 430: #define EE_BEGIN_LABEL_FMT "._e%u" 431: #endif 432: #ifndef EE_END_LABEL_FMT 433: #define EE_END_LABEL_FMT "._e%u_e" 434: #endif 435: #ifndef MT_BEGIN_LABEL_FMT 436: #define MT_BEGIN_LABEL_FMT "._t%u" 437: #endif 438: #ifndef MT_END_LABEL_FMT 439: #define MT_END_LABEL_FMT "._t%u_e" 440: #endif 441: #ifndef LOC_BEGIN_LABEL_FMT 442: #define LOC_BEGIN_LABEL_FMT "._l%u" 443: #endif 444: #ifndef LOC_END_LABEL_FMT 445: #define LOC_END_LABEL_FMT "._l%u_e" 446: #endif 447: #ifndef BOUND_BEGIN_LABEL_FMT 448: #define BOUND_BEGIN_LABEL_FMT "._b%u_%u_%c" 449: #endif 450: #ifndef BOUND_END_LABEL_FMT 451: #define BOUND_END_LABEL_FMT "._b%u_%u_%c_e" 452: #endif 453: #ifndef DERIV_BEGIN_LABEL_FMT 454: #define DERIV_BEGIN_LABEL_FMT "._d%u" 455: #endif 456: #ifndef DERIV_END_LABEL_FMT 457: #define DERIV_END_LABEL_FMT "._d%u_e" 458: #endif 459: #ifndef SL_BEGIN_LABEL_FMT 460: #define SL_BEGIN_LABEL_FMT "._sl%u" 461: #endif 462: #ifndef SL_END_LABEL_FMT 463: #define SL_END_LABEL_FMT "._sl%u_e" 464: #endif 465: #ifndef FUNC_END_LABEL_FMT 466: #define FUNC_END_LABEL_FMT "._f%u_e" 467: #endif 468: #ifndef TYPE_NAME_FMT 469: #define TYPE_NAME_FMT "._T%u" 470: #endif 471: #ifndef LINE_CODE_LABEL_FMT 472: #define LINE_CODE_LABEL_FMT "._LC%u" 473: #endif 474: #ifndef SFNAMES_ENTRY_LABEL_FMT 475: #define SFNAMES_ENTRY_LABEL_FMT "._F%u" 476: #endif 477: #ifndef LINE_ENTRY_LABEL_FMT 478: #define LINE_ENTRY_LABEL_FMT "._LE%u" 479: #endif 480: 481: /* Definitions of defaults for various types of primitive assembly language 482: output operations. 483: 484: If necessary, these may be overridden from within your tm.h file, 485: but typically, you should never need to override these. */ 486: 487: #ifndef ASM_OUTPUT_SOURCE_FILENAME 488: #define ASM_OUTPUT_SOURCE_FILENAME(FILE,NAME) \ 1.1.1.2 ! root 489: fprintf ((FILE), "\t%s\t\"%s\"\n", FILE_ASM_OP, NAME) 1.1 root 490: #endif 491: 492: #ifndef ASM_OUTPUT_DEF 493: #define ASM_OUTPUT_DEF(FILE,LABEL1,LABEL2) \ 1.1.1.2 ! root 494: do { fprintf ((FILE), "\t%s\t", DEF_ASM_OP); \ 1.1 root 495: assemble_name (FILE, LABEL1); \ 496: fprintf (FILE, ","); \ 497: assemble_name (FILE, LABEL2); \ 498: fprintf (FILE, "\n"); \ 499: } while (0) 500: #endif 501: 502: #ifndef ASM_DWARF_DEBUG_SECTION 503: #define ASM_DWARF_DEBUG_SECTION(FILE) \ 504: fprintf ((FILE), "%s\t.debug\n", SECTION_ASM_OP) 505: #endif 506: 507: #ifndef ASM_DWARF_LINE_SECTION 508: #define ASM_DWARF_LINE_SECTION(FILE) \ 509: fprintf ((FILE), "%s\t.line\n", SECTION_ASM_OP) 510: #endif 511: 512: #ifndef ASM_DWARF_SFNAMES_SECTION 513: #define ASM_DWARF_SFNAMES_SECTION(FILE) \ 514: fprintf ((FILE), "%s\t.debug_sfnames\n", SECTION_ASM_OP) 515: #endif 516: 517: #ifndef ASM_DWARF_SRCINFO_SECTION 518: #define ASM_DWARF_SRCINFO_SECTION(FILE) \ 519: fprintf ((FILE), "%s\t.debug_srcinfo\n", SECTION_ASM_OP) 520: #endif 521: 522: #ifndef ASM_DWARF_MACINFO_SECTION 523: #define ASM_DWARF_MACINFO_SECTION(FILE) \ 524: fprintf ((FILE), "%s\t.debug_macinfo\n", SECTION_ASM_OP) 525: #endif 526: 527: #ifndef ASM_DWARF_PUBNAMES_SECTION 528: #define ASM_DWARF_PUBNAMES_SECTION(FILE) \ 529: fprintf ((FILE), "%s\t.debug_pubnames\n", SECTION_ASM_OP) 530: #endif 531: 532: #ifndef ASM_DWARF_ARANGES_SECTION 533: #define ASM_DWARF_ARANGES_SECTION(FILE) \ 534: fprintf ((FILE), "%s\t.debug_aranges\n", SECTION_ASM_OP) 535: #endif 536: 537: #ifndef ASM_DWARF_TEXT_SECTION 538: #define ASM_DWARF_TEXT_SECTION(FILE) \ 539: fprintf ((FILE), "%s\t.text\n", SECTION_ASM_OP) 540: #endif 541: 542: #ifndef ASM_DWARF_DATA_SECTION 543: #define ASM_DWARF_DATA_SECTION(FILE) \ 544: fprintf ((FILE), "%s\t.data\n", SECTION_ASM_OP) 545: #endif 546: 547: #ifndef ASM_DWARF_DATA1_SECTION 548: #define ASM_DWARF_DATA1_SECTION(FILE) \ 549: fprintf ((FILE), "%s\t.data1\n", SECTION_ASM_OP) 550: #endif 551: 552: #ifndef ASM_DWARF_RODATA_SECTION 553: #define ASM_DWARF_RODATA_SECTION(FILE) \ 554: fprintf ((FILE), "%s\t.rodata\n", SECTION_ASM_OP) 555: #endif 556: 557: #ifndef ASM_DWARF_RODATA1_SECTION 558: #define ASM_DWARF_RODATA1_SECTION(FILE) \ 559: fprintf ((FILE), "%s\t.rodata1\n", SECTION_ASM_OP) 560: #endif 561: 562: #ifndef ASM_DWARF_BSS_SECTION 563: #define ASM_DWARF_BSS_SECTION(FILE) \ 564: fprintf ((FILE), "%s\t.bss\n", SECTION_ASM_OP) 565: #endif 566: 567: #ifndef ASM_DWARF_POP_SECTION 568: #define ASM_DWARF_POP_SECTION(FILE) \ 569: fprintf ((FILE), "\t.previous\n") 570: #endif 571: 572: #ifndef ASM_OUTPUT_DWARF_DELTA2 573: #define ASM_OUTPUT_DWARF_DELTA2(FILE,LABEL1,LABEL2) \ 1.1.1.2 ! root 574: do { fprintf ((FILE), "\t%s\t", UNALIGNED_SHORT_ASM_OP); \ 1.1 root 575: assemble_name (FILE, LABEL1); \ 576: fprintf (FILE, "-"); \ 577: assemble_name (FILE, LABEL2); \ 578: fprintf (FILE, "\n"); \ 579: } while (0) 580: #endif 581: 582: #ifndef ASM_OUTPUT_DWARF_DELTA4 583: #define ASM_OUTPUT_DWARF_DELTA4(FILE,LABEL1,LABEL2) \ 1.1.1.2 ! root 584: do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ 1.1 root 585: assemble_name (FILE, LABEL1); \ 586: fprintf (FILE, "-"); \ 587: assemble_name (FILE, LABEL2); \ 588: fprintf (FILE, "\n"); \ 589: } while (0) 590: #endif 591: 592: #ifndef ASM_OUTPUT_DWARF_TAG 593: #define ASM_OUTPUT_DWARF_TAG(FILE,TAG) \ 1.1.1.2 ! root 594: fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP, \ 1.1 root 595: (unsigned) TAG, ASM_COMMENT_START, tag_name (TAG)) 596: #endif 597: 598: #ifndef ASM_OUTPUT_DWARF_ATTRIBUTE 599: #define ASM_OUTPUT_DWARF_ATTRIBUTE(FILE,ATTRIBUTE) \ 1.1.1.2 ! root 600: fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP, \ 1.1 root 601: (unsigned) ATTRIBUTE, ASM_COMMENT_START, attribute_name (ATTRIBUTE)) 602: #endif 603: 604: #ifndef ASM_OUTPUT_DWARF_STACK_OP 605: #define ASM_OUTPUT_DWARF_STACK_OP(FILE,OP) \ 606: fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP, \ 607: (unsigned) OP, ASM_COMMENT_START, stack_op_name (OP)) 608: #endif 609: 610: #ifndef ASM_OUTPUT_DWARF_FUND_TYPE 611: #define ASM_OUTPUT_DWARF_FUND_TYPE(FILE,FT) \ 1.1.1.2 ! root 612: fprintf ((FILE), "\t%s\t0x%x\t%s %s\n", UNALIGNED_SHORT_ASM_OP, \ 1.1 root 613: (unsigned) FT, ASM_COMMENT_START, fundamental_type_name (FT)) 614: #endif 615: 616: #ifndef ASM_OUTPUT_DWARF_FMT_BYTE 617: #define ASM_OUTPUT_DWARF_FMT_BYTE(FILE,FMT) \ 618: fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP, \ 619: (unsigned) FMT, ASM_COMMENT_START, format_byte_name (FMT)) 620: #endif 621: 622: #ifndef ASM_OUTPUT_DWARF_TYPE_MODIFIER 623: #define ASM_OUTPUT_DWARF_TYPE_MODIFIER(FILE,MOD) \ 624: fprintf ((FILE), "%s\t0x%x\t%s %s\n", ASM_BYTE_OP, \ 625: (unsigned) MOD, ASM_COMMENT_START, modifier_name (MOD)) 626: #endif 627: 628: #ifndef ASM_OUTPUT_DWARF_ADDR 629: #define ASM_OUTPUT_DWARF_ADDR(FILE,LABEL) \ 1.1.1.2 ! root 630: do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ 1.1 root 631: assemble_name (FILE, LABEL); \ 632: fprintf (FILE, "\n"); \ 633: } while (0) 634: #endif 635: 636: #ifndef ASM_OUTPUT_DWARF_ADDR_CONST 637: #define ASM_OUTPUT_DWARF_ADDR_CONST(FILE,RTX) \ 1.1.1.2 ! root 638: fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ 1.1 root 639: output_addr_const ((FILE), (RTX)); \ 640: fputc ('\n', (FILE)) 641: #endif 642: 643: #ifndef ASM_OUTPUT_DWARF_REF 644: #define ASM_OUTPUT_DWARF_REF(FILE,LABEL) \ 1.1.1.2 ! root 645: do { fprintf ((FILE), "\t%s\t", UNALIGNED_INT_ASM_OP); \ 1.1 root 646: assemble_name (FILE, LABEL); \ 647: fprintf (FILE, "\n"); \ 648: } while (0) 649: #endif 650: 651: #ifndef ASM_OUTPUT_DWARF_DATA1 652: #define ASM_OUTPUT_DWARF_DATA1(FILE,VALUE) \ 653: fprintf ((FILE), "%s\t0x%x\n", ASM_BYTE_OP, VALUE) 654: #endif 655: 656: #ifndef ASM_OUTPUT_DWARF_DATA2 657: #define ASM_OUTPUT_DWARF_DATA2(FILE,VALUE) \ 1.1.1.2 ! root 658: fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_SHORT_ASM_OP, (unsigned) VALUE) 1.1 root 659: #endif 660: 661: #ifndef ASM_OUTPUT_DWARF_DATA4 662: #define ASM_OUTPUT_DWARF_DATA4(FILE,VALUE) \ 1.1.1.2 ! root 663: fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, (unsigned) VALUE) 1.1 root 664: #endif 665: 666: #ifndef ASM_OUTPUT_DWARF_DATA8 667: #define ASM_OUTPUT_DWARF_DATA8(FILE,HIGH_VALUE,LOW_VALUE) \ 668: do { \ 669: if (WORDS_BIG_ENDIAN) \ 670: { \ 1.1.1.2 ! root 671: fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ ! 672: fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ 1.1 root 673: } \ 674: else \ 675: { \ 1.1.1.2 ! root 676: fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, LOW_VALUE);\ ! 677: fprintf ((FILE), "\t%s\t0x%x\n", UNALIGNED_INT_ASM_OP, HIGH_VALUE); \ 1.1 root 678: } \ 679: } while (0) 680: #endif 681: 682: #ifndef ASM_OUTPUT_DWARF_STRING 683: #define ASM_OUTPUT_DWARF_STRING(FILE,P) \ 684: ASM_OUTPUT_ASCII ((FILE), P, strlen (P)+1) 685: #endif 686: 687: /************************ general utility functions **************************/ 688: 689: inline char * 690: xstrdup (s) 691: register char *s; 692: { 693: register char *p = (char *) xmalloc (strlen (s) + 1); 694: 695: strcpy (p, s); 696: return p; 697: } 698: 699: static char * 700: tag_name (tag) 701: register unsigned tag; 702: { 703: switch (tag) 704: { 705: case TAG_padding: return "TAG_padding"; 706: case TAG_array_type: return "TAG_array_type"; 707: case TAG_class_type: return "TAG_class_type"; 708: case TAG_entry_point: return "TAG_entry_point"; 709: case TAG_enumeration_type: return "TAG_enumeration_type"; 710: case TAG_formal_parameter: return "TAG_formal_parameter"; 711: case TAG_global_subroutine: return "TAG_global_subroutine"; 712: case TAG_global_variable: return "TAG_global_variable"; 713: case TAG_imported_declaration: return "TAG_imported_declaration"; 714: case TAG_label: return "TAG_label"; 715: case TAG_lexical_block: return "TAG_lexical_block"; 716: case TAG_local_variable: return "TAG_local_variable"; 717: case TAG_member: return "TAG_member"; 718: case TAG_pointer_type: return "TAG_pointer_type"; 719: case TAG_reference_type: return "TAG_reference_type"; 720: case TAG_compile_unit: return "TAG_compile_unit"; 721: case TAG_string_type: return "TAG_string_type"; 722: case TAG_structure_type: return "TAG_structure_type"; 723: case TAG_subroutine: return "TAG_subroutine"; 724: case TAG_subroutine_type: return "TAG_subroutine_type"; 725: case TAG_typedef: return "TAG_typedef"; 726: case TAG_union_type: return "TAG_union_type"; 727: case TAG_unspecified_parameters: return "TAG_unspecified_parameters"; 728: case TAG_variant: return "TAG_variant"; 729: case TAG_format: return "TAG_format"; 730: case TAG_with_stmt: return "TAG_with_stmt"; 731: case TAG_set_type: return "TAG_set_type"; 732: default: return "<unknown tag>"; 733: } 734: } 735: 736: static char * 737: attribute_name (attr) 738: register unsigned attr; 739: { 740: switch (attr) 741: { 742: case AT_sibling: return "AT_sibling"; 743: case AT_location: return "AT_location"; 744: case AT_name: return "AT_name"; 745: case AT_fund_type: return "AT_fund_type"; 746: case AT_mod_fund_type: return "AT_mod_fund_type"; 747: case AT_user_def_type: return "AT_user_def_type"; 748: case AT_mod_u_d_type: return "AT_mod_u_d_type"; 749: case AT_ordering: return "AT_ordering"; 750: case AT_subscr_data: return "AT_subscr_data"; 751: case AT_byte_size: return "AT_byte_size"; 752: case AT_bit_offset: return "AT_bit_offset"; 753: case AT_bit_size: return "AT_bit_size"; 754: case AT_element_list: return "AT_element_list"; 755: case AT_stmt_list: return "AT_stmt_list"; 756: case AT_low_pc: return "AT_low_pc"; 757: case AT_high_pc: return "AT_high_pc"; 758: case AT_language: return "AT_language"; 759: case AT_member: return "AT_member"; 760: case AT_discr: return "AT_discr"; 761: case AT_discr_value: return "AT_discr_value"; 762: case AT_visibility: return "AT_visibility"; 763: case AT_import: return "AT_import"; 764: case AT_string_length: return "AT_string_length"; 765: case AT_comp_dir: return "AT_comp_dir"; 766: case AT_producer: return "AT_producer"; 767: case AT_frame_base: return "AT_frame_base"; 768: case AT_start_scope: return "AT_start_scope"; 769: case AT_stride_size: return "AT_stride_size"; 770: case AT_src_info: return "AT_src_info"; 771: case AT_prototyped: return "AT_prototyped"; 772: case AT_const_value_block4: return "AT_const_value_block4"; 773: case AT_sf_names: return "AT_sf_names"; 774: case AT_mac_info: return "AT_mac_info"; 775: default: return "<unknown attribute>"; 776: } 777: } 778: 779: static char * 780: stack_op_name (op) 781: register unsigned op; 782: { 783: switch (op) 784: { 785: case OP_REG: return "OP_REG"; 786: case OP_BASEREG: return "OP_BASEREG"; 787: case OP_ADDR: return "OP_ADDR"; 788: case OP_CONST: return "OP_CONST"; 789: case OP_DEREF2: return "OP_DEREF2"; 790: case OP_DEREF4: return "OP_DEREF4"; 791: case OP_ADD: return "OP_ADD"; 792: default: return "<unknown stack operator>"; 793: } 794: } 795: 796: static char * 797: modifier_name (mod) 798: register unsigned mod; 799: { 800: switch (mod) 801: { 802: case MOD_pointer_to: return "MOD_pointer_to"; 803: case MOD_reference_to: return "MOD_reference_to"; 804: case MOD_const: return "MOD_const"; 805: case MOD_volatile: return "MOD_volatile"; 806: default: return "<unknown modifier>"; 807: } 808: } 809: 810: static char * 811: format_byte_name (fmt) 812: register unsigned fmt; 813: { 814: switch (fmt) 815: { 816: case FMT_FT_C_C: return "FMT_FT_C_C"; 817: case FMT_FT_C_X: return "FMT_FT_C_X"; 818: case FMT_FT_X_C: return "FMT_FT_X_C"; 819: case FMT_FT_X_X: return "FMT_FT_X_X"; 820: case FMT_UT_C_C: return "FMT_UT_C_C"; 821: case FMT_UT_C_X: return "FMT_UT_C_X"; 822: case FMT_UT_X_C: return "FMT_UT_X_C"; 823: case FMT_UT_X_X: return "FMT_UT_X_X"; 824: case FMT_ET: return "FMT_ET"; 825: default: return "<unknown array bound format byte>"; 826: } 827: } 828: static char * 829: fundamental_type_name (ft) 830: register unsigned ft; 831: { 832: switch (ft) 833: { 834: case FT_char: return "FT_char"; 835: case FT_signed_char: return "FT_signed_char"; 836: case FT_unsigned_char: return "FT_unsigned_char"; 837: case FT_short: return "FT_short"; 838: case FT_signed_short: return "FT_signed_short"; 839: case FT_unsigned_short: return "FT_unsigned_short"; 840: case FT_integer: return "FT_integer"; 841: case FT_signed_integer: return "FT_signed_integer"; 842: case FT_unsigned_integer: return "FT_unsigned_integer"; 843: case FT_long: return "FT_long"; 844: case FT_signed_long: return "FT_signed_long"; 845: case FT_unsigned_long: return "FT_unsigned_long"; 846: case FT_pointer: return "FT_pointer"; 847: case FT_float: return "FT_float"; 848: case FT_dbl_prec_float: return "FT_dbl_prec_float"; 849: case FT_ext_prec_float: return "FT_ext_prec_float"; 850: case FT_complex: return "FT_complex"; 851: case FT_dbl_prec_complex: return "FT_dbl_prec_complex"; 852: case FT_void: return "FT_void"; 853: case FT_boolean: return "FT_boolean"; 854: case FT_long_long: return "FT_long_long"; 855: case FT_signed_long_long: return "FT_signed_long_long"; 856: case FT_unsigned_long_long: return "FT_unsigned_long_long"; 857: default: return "<unknown fundamental type>"; 858: } 859: } 860: 861: /**************** utility functions for attribute functions ******************/ 862: 863: /* Given a pointer to a tree node for some type, return a Dwarf fundamental 864: type code for the given type. 865: 866: This routine must only be called for GCC type nodes that correspond to 867: Dwarf fundamental types. 868: 869: The current Dwarf draft specification calls for Dwarf fundamental types 870: to accurately reflect the fact that a given type was either a "plain" 871: integral type or an explicitly "signed" integral type. Unfortuantely, 872: we can't always do this, because GCC may already have thrown away the 873: information about the precise way in which the type was originally 874: specified, as in: 875: 876: typedef signed int field_type; 877: 878: struct s { field_type f; }; 879: 880: Since we may be stuck here without enought information to do exactly 881: what is called for in the Dwarf draft specification, we do the best 882: that we can under the circumstances and always use the "plain" integral 883: fundamental type codes for int, short, and long types. That's probably 884: good enough. The additional accuracy called for in the current DWARF 885: draft specification is probably never even useful in practice. */ 886: 887: static int 888: fundamental_type_code (type) 889: register tree type; 890: { 891: if (TREE_CODE (type) == ERROR_MARK) 892: return 0; 893: 894: switch (TREE_CODE (type)) 895: { 896: case ERROR_MARK: 897: return FT_void; 898: 899: case VOID_TYPE: 900: return FT_void; 901: 902: case INTEGER_TYPE: 903: /* Carefully distinguish all the standard types of C, 904: without messing up if the language is not C. 905: Note that we check only for the names that contain spaces; 906: other names might occur by coincidence in other languages. */ 907: if (TYPE_NAME (type) != 0 908: && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 909: && DECL_NAME (TYPE_NAME (type)) != 0 910: && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) 911: { 912: char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); 913: 914: if (!strcmp (name, "unsigned char")) 915: return FT_unsigned_char; 916: if (!strcmp (name, "signed char")) 917: return FT_signed_char; 918: if (!strcmp (name, "unsigned int")) 919: return FT_unsigned_integer; 920: if (!strcmp (name, "short int")) 921: return FT_short; 922: if (!strcmp (name, "short unsigned int")) 923: return FT_unsigned_short; 924: if (!strcmp (name, "long int")) 925: return FT_long; 926: if (!strcmp (name, "long unsigned int")) 927: return FT_unsigned_long; 928: if (!strcmp (name, "long long int")) 929: return FT_long_long; /* Not grok'ed by svr4 SDB */ 930: if (!strcmp (name, "long long unsigned int")) 931: return FT_unsigned_long_long; /* Not grok'ed by svr4 SDB */ 932: } 933: 934: /* Most integer types will be sorted out above, however, for the 935: sake of special `array index' integer types, the following code 936: is also provided. */ 937: 938: if (TYPE_PRECISION (type) == INT_TYPE_SIZE) 939: return (TREE_UNSIGNED (type) ? FT_unsigned_integer : FT_integer); 940: 941: if (TYPE_PRECISION (type) == LONG_TYPE_SIZE) 942: return (TREE_UNSIGNED (type) ? FT_unsigned_long : FT_long); 943: 944: if (TYPE_PRECISION (type) == LONG_LONG_TYPE_SIZE) 945: return (TREE_UNSIGNED (type) ? FT_unsigned_long_long : FT_long_long); 946: 947: if (TYPE_PRECISION (type) == SHORT_TYPE_SIZE) 948: return (TREE_UNSIGNED (type) ? FT_unsigned_short : FT_short); 949: 950: if (TYPE_PRECISION (type) == CHAR_TYPE_SIZE) 951: return (TREE_UNSIGNED (type) ? FT_unsigned_char : FT_char); 952: 953: abort (); 954: 955: case REAL_TYPE: 956: /* Carefully distinguish all the standard types of C, 957: without messing up if the language is not C. */ 958: if (TYPE_NAME (type) != 0 959: && TREE_CODE (TYPE_NAME (type)) == TYPE_DECL 960: && DECL_NAME (TYPE_NAME (type)) != 0 961: && TREE_CODE (DECL_NAME (TYPE_NAME (type))) == IDENTIFIER_NODE) 962: { 963: char *name = IDENTIFIER_POINTER (DECL_NAME (TYPE_NAME (type))); 964: 965: /* Note that here we can run afowl of a serious bug in "classic" 966: svr4 SDB debuggers. They don't seem to understand the 967: FT_ext_prec_float type (even though they should). */ 968: 969: if (!strcmp (name, "long double")) 970: return FT_ext_prec_float; 971: } 972: 973: if (TYPE_PRECISION (type) == DOUBLE_TYPE_SIZE) 974: return FT_dbl_prec_float; 975: if (TYPE_PRECISION (type) == FLOAT_TYPE_SIZE) 976: return FT_float; 977: 978: /* Note that here we can run afowl of a serious bug in "classic" 979: svr4 SDB debuggers. They don't seem to understand the 980: FT_ext_prec_float type (even though they should). */ 981: 982: if (TYPE_PRECISION (type) == LONG_DOUBLE_TYPE_SIZE) 983: return FT_ext_prec_float; 984: abort (); 985: 986: case COMPLEX_TYPE: 987: return FT_complex; /* GNU FORTRAN COMPLEX type. */ 988: 989: case CHAR_TYPE: 990: return FT_char; /* GNU Pascal CHAR type. Not used in C. */ 991: 992: case BOOLEAN_TYPE: 993: return FT_boolean; /* GNU FORTRAN BOOLEAN type. */ 994: 995: default: 996: abort (); /* No other TREE_CODEs are Dwarf fundamental types. */ 997: } 998: return 0; 999: } 1000: 1001: /* Given a pointer to an arbitrary ..._TYPE tree node, return a pointer to 1002: the Dwarf "root" type for the given input type. The Dwarf "root" type 1003: of a given type is generally the same as the given type, except that if 1004: the given type is a pointer or reference type, then the root type of 1005: the given type is the root type of the "basis" type for the pointer or 1006: reference type. (This definition of the "root" type is recursive.) 1007: Also, the root type of a `const' qualified type or a `volatile' 1008: qualified type is the root type of the given type without the 1009: qualifiers. */ 1010: 1011: static tree 1012: root_type (type) 1013: register tree type; 1014: { 1015: if (TREE_CODE (type) == ERROR_MARK) 1016: return error_mark_node; 1017: 1018: switch (TREE_CODE (type)) 1019: { 1020: case ERROR_MARK: 1021: return error_mark_node; 1022: 1023: case POINTER_TYPE: 1024: case REFERENCE_TYPE: 1025: return TYPE_MAIN_VARIANT (root_type (TREE_TYPE (type))); 1026: 1027: default: 1028: return TYPE_MAIN_VARIANT (type); 1029: } 1030: } 1031: 1032: /* Given a pointer to an arbitrary ..._TYPE tree node, write out a sequence 1033: of zero or more Dwarf "type-modifier" bytes applicable to the type. */ 1034: 1035: static void 1036: write_modifier_bytes (type, decl_const, decl_volatile) 1037: register tree type; 1038: register int decl_const; 1039: register int decl_volatile; 1040: { 1041: if (TREE_CODE (type) == ERROR_MARK) 1042: return; 1043: 1044: if (TYPE_READONLY (type) || decl_const) 1045: ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_const); 1046: if (TYPE_VOLATILE (type) || decl_volatile) 1047: ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_volatile); 1048: switch (TREE_CODE (type)) 1049: { 1050: case POINTER_TYPE: 1051: ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_pointer_to); 1052: write_modifier_bytes (TREE_TYPE (type), 0, 0); 1053: return; 1054: 1055: case REFERENCE_TYPE: 1056: ASM_OUTPUT_DWARF_TYPE_MODIFIER (asm_out_file, MOD_reference_to); 1057: write_modifier_bytes (TREE_TYPE (type), 0, 0); 1058: return; 1059: 1060: case ERROR_MARK: 1061: default: 1062: return; 1063: } 1064: } 1065: 1066: /* Given a pointer to an arbitrary ..._TYPE tree node, return non-zero if the 1067: given input type is a Dwarf "fundamental" type. Otherwise return zero. */ 1068: 1069: inline int 1070: type_is_fundamental (type) 1071: register tree type; 1072: { 1073: switch (TREE_CODE (type)) 1074: { 1075: case ERROR_MARK: 1076: case VOID_TYPE: 1077: case INTEGER_TYPE: 1078: case REAL_TYPE: 1079: case COMPLEX_TYPE: 1080: case BOOLEAN_TYPE: 1081: case CHAR_TYPE: 1082: return 1; 1083: 1084: case SET_TYPE: 1085: case ARRAY_TYPE: 1086: case RECORD_TYPE: 1087: case UNION_TYPE: 1088: case ENUMERAL_TYPE: 1089: case FUNCTION_TYPE: 1090: case METHOD_TYPE: 1091: case POINTER_TYPE: 1092: case REFERENCE_TYPE: 1093: case STRING_TYPE: 1094: case FILE_TYPE: 1095: case OFFSET_TYPE: 1096: case LANG_TYPE: 1097: return 0; 1098: 1099: default: 1100: abort (); 1101: } 1102: return 0; 1103: } 1104: 1105: /* Given a pointer to some ..._TYPE tree node, generate an assembly language 1106: equate directive which will associate an easily remembered symbolic name 1107: with the current DIE. 1108: 1109: The name used is an artificial label generated from the TYPE_UID number 1110: associated with the given type node. The name it gets equated to is the 1111: symbolic label that we (previously) output at the start of the DIE that 1112: we are currently generating. 1113: 1114: Calling this function while generating some "type related" form of DIE 1115: makes it easy to later refer to the DIE which represents the given type 1116: simply by re-generating the alternative name from the ..._TYPE node's 1117: UID number. */ 1118: 1119: inline void 1120: equate_type_number_to_die_number (type) 1121: register tree type; 1122: { 1123: char type_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1124: char die_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1125: 1126: /* We are generating a DIE to represent the main variant of this type 1127: (i.e the type without any const or volatile qualifiers) so in order 1128: to get the equate to come out right, we need to get the main variant 1129: itself here. */ 1130: 1131: type = TYPE_MAIN_VARIANT (type); 1132: 1133: sprintf (type_label, TYPE_NAME_FMT, TYPE_UID (type)); 1134: sprintf (die_label, DIE_BEGIN_LABEL_FMT, current_dienum); 1135: ASM_OUTPUT_DEF (asm_out_file, type_label, die_label); 1136: } 1137: 1138: /* The following routine is a nice and simple transducer. It converts the 1139: RTL for a variable or parameter (resident in memory) into an equivalent 1140: Dwarf representation of a mechanism for getting the address of that same 1141: variable onto the top of a hypothetical "address evaluation" stack. 1142: 1143: When creating memory location descriptors, we are effectively trans- 1144: forming the RTL for a memory-resident object into its Dwarf postfix 1145: expression equivalent. This routine just recursively descends an 1146: RTL tree, turning it into Dwarf postfix code as it goes. */ 1147: 1148: static void 1149: output_mem_loc_descriptor (rtl) 1150: register rtx rtl; 1151: { 1152: /* Note that for a dynamically sized array, the location we will 1153: generate a description of here will be the lowest numbered location 1154: which is actually within the array. That's *not* necessarily the 1155: same as the zeroth element of the array. */ 1156: 1157: switch (GET_CODE (rtl)) 1158: { 1159: case SUBREG: 1160: 1161: /* The case of a subreg may arise when we have a local (register) 1162: variable or a formal (register) parameter which doesn't quite 1163: fill up an entire register. For now, just assume that it is 1164: legitimate to make the Dwarf info refer to the whole register 1165: which contains the given subreg. */ 1166: 1167: rtl = XEXP (rtl, 0); 1168: /* Drop thru. */ 1169: 1170: case REG: 1171: 1172: /* Whenever a register number forms a part of the description of 1173: the method for calculating the (dynamic) address of a memory 1174: resident object, Dwarf rules require the register number to 1175: be referred to as a "base register". This distinction is not 1176: based in any way upon what category of register the hardware 1177: believes the given register belongs to. This is strictly 1178: Dwarf terminology we're dealing with here. */ 1179: 1180: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_BASEREG); 1181: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 1182: DBX_REGISTER_NUMBER (REGNO (rtl))); 1183: break; 1184: 1185: case MEM: 1186: output_mem_loc_descriptor (XEXP (rtl, 0)); 1187: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_DEREF4); 1188: break; 1189: 1190: case CONST: 1191: case SYMBOL_REF: 1192: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADDR); 1193: ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); 1194: break; 1195: 1196: case PLUS: 1197: output_mem_loc_descriptor (XEXP (rtl, 0)); 1198: output_mem_loc_descriptor (XEXP (rtl, 1)); 1199: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); 1200: break; 1201: 1202: case CONST_INT: 1203: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); 1204: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, INTVAL (rtl)); 1205: break; 1206: 1207: default: 1208: abort (); 1209: } 1210: } 1211: 1212: /* Output a proper Dwarf location descriptor for a variable or parameter 1213: which is either allocated in a register or in a memory location. For 1214: a register, we just generate an OP_REG and the register number. For a 1215: memory location we provide a Dwarf postfix expression describing how to 1216: generate the (dynamic) address of the object onto the address stack. */ 1217: 1218: static void 1219: output_loc_descriptor (rtl) 1220: register rtx rtl; 1221: { 1222: switch (GET_CODE (rtl)) 1223: { 1224: case SUBREG: 1225: 1226: /* The case of a subreg may arise when we have a local (register) 1227: variable or a formal (register) parameter which doesn't quite 1228: fill up an entire register. For now, just assume that it is 1229: legitimate to make the Dwarf info refer to the whole register 1230: which contains the given subreg. */ 1231: 1232: rtl = XEXP (rtl, 0); 1233: /* Drop thru. */ 1234: 1235: case REG: 1236: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_REG); 1237: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 1238: DBX_REGISTER_NUMBER (REGNO (rtl))); 1239: break; 1240: 1241: case MEM: 1242: output_mem_loc_descriptor (XEXP (rtl, 0)); 1243: break; 1244: 1245: default: 1246: abort (); /* Should never happen */ 1247: } 1248: } 1249: 1250: /* Given a tree node describing an array bound (either lower or upper) 1251: output a representation for that bound. */ 1252: 1253: static void 1254: output_bound_representation (bound, dim_num, u_or_l) 1255: register tree bound; 1256: register unsigned dim_num; /* For multi-dimensional arrays. */ 1257: register char u_or_l; /* Designates upper or lower bound. */ 1258: { 1259: switch (TREE_CODE (bound)) 1260: { 1261: 1262: case ERROR_MARK: 1263: return; 1264: 1265: /* All fixed-bounds are represented by INTEGER_CST nodes. */ 1266: 1267: case INTEGER_CST: 1268: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 1269: (unsigned) TREE_INT_CST_LOW (bound)); 1270: break; 1271: 1272: /* Dynamic bounds may be represented by NOP_EXPR nodes containing 1273: SAVE_EXPR nodes. */ 1274: 1275: case NOP_EXPR: 1276: bound = TREE_OPERAND (bound, 0); 1277: /* ... fall thru... */ 1278: 1279: case SAVE_EXPR: 1280: { 1281: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1282: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1283: 1284: sprintf (begin_label, BOUND_BEGIN_LABEL_FMT, 1285: current_dienum, dim_num, u_or_l); 1286: 1287: sprintf (end_label, BOUND_END_LABEL_FMT, 1288: current_dienum, dim_num, u_or_l); 1289: 1290: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1291: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1292: 1293: /* If we are working on a bound for a dynamic dimension in C, 1294: the dynamic dimension in question had better have a static 1295: (zero) lower bound and a dynamic *upper* bound. */ 1296: 1297: if (u_or_l != 'u') 1298: abort (); 1299: 1300: /* If optimization is turned on, the SAVE_EXPRs that describe 1301: how to access the upper bound values are essentially bogus. 1302: They only describe (at best) how to get at these values at 1303: the points in the generated code right after they have just 1304: been computed. Worse yet, in the typical case, the upper 1305: bound values will not even *be* computed in the optimized 1306: code, so these SAVE_EXPRs are entirely bogus. 1307: 1308: In order to compensate for this fact, we check here to see 1309: if optimization is enabled, and if so, we effectively create 1310: an empty location description for the (unknown and unknowable) 1311: upper bound. 1312: 1313: This should not cause too much trouble for existing (stupid?) 1314: debuggers because they have to deal with empty upper bounds 1315: location descriptions anyway in order to be able to deal with 1316: incomplete array types. 1317: 1318: Of course an intelligent debugger (GDB?) should be able to 1319: comprehend that a missing upper bound specification in a 1320: array type used for a storage class `auto' local array variable 1321: indicates that the upper bound is both unknown (at compile- 1322: time) and unknowable (at run-time) due to optimization. 1323: */ 1324: 1325: if (! optimize) 1326: output_loc_descriptor 1327: (eliminate_regs (SAVE_EXPR_RTL (bound), 0, 0)); 1328: 1329: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1330: } 1331: break; 1332: 1333: default: 1334: abort (); 1335: } 1336: } 1337: 1338: /* Recursive function to output a sequence of value/name pairs for 1339: enumeration constants in reversed order. This is called from 1340: enumeration_type_die. */ 1341: 1342: static void 1343: output_enumeral_list (link) 1344: register tree link; 1345: { 1346: if (link) 1347: { 1348: output_enumeral_list (TREE_CHAIN (link)); 1349: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 1350: (unsigned) TREE_INT_CST_LOW (TREE_VALUE (link))); 1351: ASM_OUTPUT_DWARF_STRING (asm_out_file, 1352: IDENTIFIER_POINTER (TREE_PURPOSE (link))); 1353: } 1354: } 1355: 1356: /****************************** attributes *********************************/ 1357: 1358: /* The following routines are responsible for writing out the various types 1359: of Dwarf attributes (and any following data bytes associated with them). 1360: These routines are listed in order based on the numerical codes of their 1361: associated attributes. */ 1362: 1363: /* Generate an AT_sibling attribute. */ 1364: 1365: inline void 1366: sibling_attribute () 1367: { 1368: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 1369: 1370: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sibling); 1371: sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); 1372: ASM_OUTPUT_DWARF_REF (asm_out_file, label); 1373: } 1374: 1375: /* Output the form of location attributes suitable for whole variables and 1376: whole parameters. Note that the location attributes for struct fields 1377: are generated by the routine `data_member_location_attribute' below. */ 1378: 1379: static void 1380: location_attribute (rtl) 1381: register rtx rtl; 1382: { 1383: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1384: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1385: 1386: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); 1387: sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); 1388: sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); 1389: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1390: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1391: 1392: /* Handle a special case. If we are about to output a location descriptor 1.1.1.2 ! root 1393: for a variable or parameter which has been optimized out of existence, 1.1 root 1394: don't do that. Instead we output a zero-length location descriptor 1395: value as part of the location attribute. Note that we cannot simply 1396: suppress the entire location attribute, because the absence of a 1397: location attribute in certain kinds of DIEs is used to indicate some- 1398: thing entirely different... i.e. that the DIE represents an object 1399: declaration, but not a definition. So sayeth the PLSIG. */ 1400: 1401: if (((GET_CODE (rtl) != REG) || (REGNO (rtl) < FIRST_PSEUDO_REGISTER)) 1402: && ((GET_CODE (rtl) != SUBREG) 1403: || (REGNO (XEXP (rtl, 0)) < FIRST_PSEUDO_REGISTER))) 1404: output_loc_descriptor (eliminate_regs (rtl, 0, 0)); 1405: 1406: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1407: } 1408: 1409: /* Output the specialized form of location attribute used for data members 1410: of struct types. */ 1411: 1412: static void 1413: data_member_location_attribute (decl) 1414: register tree decl; 1415: { 1416: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1417: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1418: 1419: if (TREE_CODE (decl) == ERROR_MARK) 1420: return; 1421: 1422: if (TREE_CODE (decl) != FIELD_DECL) 1423: abort (); 1424: 1425: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_location); 1426: sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); 1427: sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); 1428: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1429: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1430: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_CONST); 1431: 1432: /* This is pretty strange, but existing compilers producing DWARF 1433: apparently calculate the byte offset of a field differently 1434: depending upon whether or not it is a bit-field. If the given 1435: field is *not* a bit-field, then the offset is simply the 1436: the byte offset of the given field from the beginning of the 1437: struct. For bit-fields however, the offset is the offset (in 1438: bytes) of the beginning of the *containing word* from the 1439: beginning of the whole struct. */ 1440: 1441: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 1442: (DECL_BIT_FIELD_TYPE (decl)) 1443: ? BITFIELD_OFFSET_WORDS_IN_UNITS (decl) 1444: : BITFIELD_OFFSET_UNITS (decl)); 1445: ASM_OUTPUT_DWARF_STACK_OP (asm_out_file, OP_ADD); 1446: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1447: } 1448: 1449: /* Output an AT_const_value attribute for a variable or a parameter which 1450: does not have a "location" either in memory or in a register. These 1451: things can arise in GNU C when a constant is passed as an actual 1452: parameter to an inlined function. They can also arise in C++ where 1453: declared constants do not necessarily get memory "homes". */ 1454: 1455: static void 1456: const_value_attribute (rtl) 1457: register rtx rtl; 1458: { 1459: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1460: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1461: 1462: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_const_value_block4); 1463: sprintf (begin_label, LOC_BEGIN_LABEL_FMT, current_dienum); 1464: sprintf (end_label, LOC_END_LABEL_FMT, current_dienum); 1465: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); 1466: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1467: 1468: switch (GET_CODE (rtl)) 1469: { 1470: case CONST_INT: 1471: /* Note that a CONST_INT rtx could represent either an integer or 1472: a floating-point constant. A CONST_INT is used whenever the 1473: constant will fit into a single word. In all such cases, the 1474: original mode of the constant value is wiped out, and the 1475: CONST_INT rtx is assigned VOIDmode. Since we no longer have 1476: precise mode information for these constants, we always just 1477: output them using 4 bytes. */ 1478: 1479: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, (unsigned) INTVAL (rtl)); 1480: break; 1481: 1482: case CONST_DOUBLE: 1483: /* Note that a CONST_DOUBLE rtx could represent either an integer 1484: or a floating-point constant. A CONST_DOUBLE is used whenever 1485: the constant requires more than one word in order to be adequately 1486: represented. In all such cases, the original mode of the constant 1487: value is preserved as the mode of the CONST_DOUBLE rtx, but for 1488: simplicity we always just output CONST_DOUBLEs using 8 bytes. */ 1489: 1490: ASM_OUTPUT_DWARF_DATA8 (asm_out_file, 1491: (unsigned) CONST_DOUBLE_HIGH (rtl), 1492: (unsigned) CONST_DOUBLE_LOW (rtl)); 1493: break; 1494: 1495: case CONST_STRING: 1496: ASM_OUTPUT_DWARF_STRING (asm_out_file, XSTR (rtl, 0)); 1497: break; 1498: 1499: case SYMBOL_REF: 1500: case LABEL_REF: 1501: case CONST: 1502: ASM_OUTPUT_DWARF_ADDR_CONST (asm_out_file, rtl); 1503: break; 1.1.1.2 ! root 1504: ! 1505: case PLUS: ! 1506: /* In cases where an inlined instance of an inline function is passed ! 1507: the address of an `auto' variable (which is local to the caller) ! 1508: we can get a situation where the DECL_RTL of the artificial ! 1509: local variable (for the inlining) which acts as a stand-in for ! 1510: the corresponding formal parameter (of the inline function) ! 1511: will look like (plus:SI (reg:SI FRAME_PTR) (const_int ...)). ! 1512: This is not exactly a compile-time constant expression, but it ! 1513: isn't the address of the (artificial) local variable either. ! 1514: Rather, it represents the *value* which the artificial local ! 1515: variable always has during its lifetime. We currently have no ! 1516: way to represent such quasi-constant values in Dwarf, so for now ! 1517: we just punt and generate an AT_const_value attribute with form ! 1518: FORM_BLOCK4 and a length of zero. */ ! 1519: break; 1.1 root 1520: } 1521: 1522: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1523: } 1524: 1525: /* Generate *either* an AT_location attribute or else an AT_const_value 1526: data attribute for a variable or a parameter. We generate the 1527: AT_const_value attribute only in those cases where the given 1528: variable or parameter does not have a true "location" either in 1529: memory or in a register. This can happen (for example) when a 1530: constant is passed as an actual argument in a call to an inline 1531: function. (It's possible that these things can crop up in other 1532: ways also.) Note that one type of constant value which can be 1533: passed into an inlined function is a constant pointer. This can 1534: happen for example if an actual argument in an inlined function 1535: call evaluates to a compile-time constant address. */ 1536: 1537: static void 1538: location_or_const_value_attribute (decl) 1539: register tree decl; 1540: { 1541: register rtx rtl; 1542: 1543: if (TREE_CODE (decl) == ERROR_MARK) 1544: return; 1545: 1546: if ((TREE_CODE (decl) != VAR_DECL) && (TREE_CODE (decl) != PARM_DECL)) 1547: abort (); 1548: 1549: /* It's not really clear what existing Dwarf debuggers need or expect 1550: as regards to location information for formal parameters. A later 1551: version of the Dwarf specification should resolve such issues, but 1552: for the time being, we assume here that debuggers want information 1553: about the location where the parameter was passed into the function. 1554: That seems to be what USL's CI5 compiler generates. Note that this 1555: will probably be different from the place where the parameter actual 1556: resides during function execution. Dwarf Version 2 will provide us 1557: with a means to describe that location also, but for now we can only 1558: describe the "passing" location. */ 1559: 1.1.1.2 ! root 1560: #if 1 /* This is probably right, but it leads to a lot of trouble. 1.1 root 1561: Fixing one problem has been exposing another, 1562: all of which seemed to have no ill effects before. 1.1.1.2 ! root 1563: Let's try it again for now. */ 1.1 root 1564: rtl = (TREE_CODE (decl) == PARM_DECL) 1565: ? DECL_INCOMING_RTL (decl) 1566: : DECL_RTL (decl); 1.1.1.2 ! root 1567: #else 1.1 root 1568: rtl = DECL_RTL (decl); 1.1.1.2 ! root 1569: #endif 1.1 root 1570: 1571: if (rtl == NULL) 1572: return; 1573: 1574: switch (GET_CODE (rtl)) 1575: { 1576: case CONST_INT: 1577: case CONST_DOUBLE: 1578: case CONST_STRING: 1579: case SYMBOL_REF: 1580: case LABEL_REF: 1581: case CONST: 1.1.1.2 ! root 1582: case PLUS: /* DECL_RTL could be (plus (reg ...) (const_int ...)) */ 1.1 root 1583: const_value_attribute (rtl); 1584: break; 1585: 1586: case MEM: 1587: case REG: 1588: case SUBREG: 1589: location_attribute (rtl); 1590: break; 1591: 1592: default: 1593: abort (); /* Should never happen. */ 1594: } 1595: } 1596: 1597: /* Generate an AT_name attribute given some string value to be included as 1598: the value of the attribute. If the name is null, don't do anything. */ 1599: 1600: inline void 1601: name_attribute (name_string) 1602: register char *name_string; 1603: { 1604: if (name_string && *name_string) 1605: { 1606: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_name); 1607: ASM_OUTPUT_DWARF_STRING (asm_out_file, name_string); 1608: } 1609: } 1610: 1611: inline void 1612: fund_type_attribute (ft_code) 1613: register unsigned ft_code; 1614: { 1615: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_fund_type); 1616: ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, ft_code); 1617: } 1618: 1619: static void 1620: mod_fund_type_attribute (type, decl_const, decl_volatile) 1621: register tree type; 1622: register int decl_const; 1623: register int decl_volatile; 1624: { 1625: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1626: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1627: 1628: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_fund_type); 1629: sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); 1630: sprintf (end_label, MT_END_LABEL_FMT, current_dienum); 1631: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1632: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1633: write_modifier_bytes (type, decl_const, decl_volatile); 1634: ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, 1635: fundamental_type_code (root_type (type))); 1636: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1637: } 1638: 1639: inline void 1640: user_def_type_attribute (type) 1641: register tree type; 1642: { 1643: char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; 1644: 1645: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_user_def_type); 1646: sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (type)); 1647: ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); 1648: } 1649: 1650: static void 1651: mod_u_d_type_attribute (type, decl_const, decl_volatile) 1652: register tree type; 1653: register int decl_const; 1654: register int decl_volatile; 1655: { 1656: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1657: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1658: char ud_type_name[MAX_ARTIFICIAL_LABEL_BYTES]; 1659: 1660: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mod_u_d_type); 1661: sprintf (begin_label, MT_BEGIN_LABEL_FMT, current_dienum); 1662: sprintf (end_label, MT_END_LABEL_FMT, current_dienum); 1663: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1664: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1665: write_modifier_bytes (type, decl_const, decl_volatile); 1666: sprintf (ud_type_name, TYPE_NAME_FMT, TYPE_UID (root_type (type))); 1667: ASM_OUTPUT_DWARF_REF (asm_out_file, ud_type_name); 1668: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1669: } 1670: 1671: inline void 1672: ordering_attribute (ordering) 1673: register unsigned ordering; 1674: { 1675: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_ordering); 1676: ASM_OUTPUT_DWARF_DATA2 (asm_out_file, ordering); 1677: } 1678: 1679: /* Note that the block of subscript information for an array type also 1680: includes information about the element type of type given array type. */ 1681: 1682: static void 1683: subscript_data_attribute (type) 1684: register tree type; 1685: { 1686: register unsigned dimension_number; 1687: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1688: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1689: 1690: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_subscr_data); 1691: sprintf (begin_label, SS_BEGIN_LABEL_FMT, current_dienum); 1692: sprintf (end_label, SS_END_LABEL_FMT, current_dienum); 1693: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1694: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1695: 1696: /* The GNU compilers represent multidimensional array types as sequences 1697: of one dimensional array types whose element types are themselves array 1698: types. Here we squish that down, so that each multidimensional array 1699: type gets only one array_type DIE in the Dwarf debugging info. The 1700: draft Dwarf specification say that we are allowed to do this kind 1701: of compression in C (because there is no difference between an 1702: array or arrays and a multidimensional array in C) but for other 1703: source languages (e.g. Ada) we probably shouldn't do this. */ 1704: 1705: for (dimension_number = 0; 1706: TREE_CODE (type) == ARRAY_TYPE; 1707: type = TREE_TYPE (type), dimension_number++) 1708: { 1709: register tree domain = TYPE_DOMAIN (type); 1710: 1711: /* Arrays come in three flavors. Unspecified bounds, fixed 1712: bounds, and (in GNU C only) variable bounds. Handle all 1713: three forms here. */ 1714: 1715: if (domain) 1716: { 1717: /* We have an array type with specified bounds. */ 1718: 1719: register tree lower = TYPE_MIN_VALUE (domain); 1720: register tree upper = TYPE_MAX_VALUE (domain); 1721: 1722: /* Handle only fundamental types as index types for now. */ 1723: 1724: if (! type_is_fundamental (domain)) 1725: abort (); 1726: 1727: /* Output the representation format byte for this dimension. */ 1728: 1729: ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, 1730: FMT_CODE (1, 1731: TREE_CODE (lower) == INTEGER_CST, 1732: TREE_CODE (upper) == INTEGER_CST)); 1733: 1734: /* Output the index type for this dimension. */ 1735: 1736: ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, 1737: fundamental_type_code (domain)); 1738: 1739: /* Output the representation for the lower bound. */ 1740: 1741: output_bound_representation (lower, dimension_number, 'l'); 1742: 1743: /* Output the representation for the upper bound. */ 1744: 1745: output_bound_representation (upper, dimension_number, 'u'); 1746: } 1747: else 1748: { 1749: /* We have an array type with an unspecified length. For C and 1750: C++ we can assume that this really means that (a) the index 1751: type is an integral type, and (b) the lower bound is zero. 1752: Note that Dwarf defines the representation of an unspecified 1753: (upper) bound as being a zero-length location description. */ 1754: 1755: /* Output the array-bounds format byte. */ 1756: 1757: ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_FT_C_X); 1758: 1759: /* Output the (assumed) index type. */ 1760: 1761: ASM_OUTPUT_DWARF_FUND_TYPE (asm_out_file, FT_integer); 1762: 1763: /* Output the (assumed) lower bound (constant) value. */ 1764: 1765: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); 1766: 1767: /* Output the (empty) location description for the upper bound. */ 1768: 1769: ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0); 1770: } 1771: } 1772: 1773: /* Output the prefix byte that says that the element type is comming up. */ 1774: 1775: ASM_OUTPUT_DWARF_FMT_BYTE (asm_out_file, FMT_ET); 1776: 1777: /* Output a representation of the type of the elements of this array type. */ 1778: 1779: type_attribute (type, 0, 0); 1780: 1781: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1782: } 1783: 1784: static void 1785: byte_size_attribute (tree_node) 1786: register tree tree_node; 1787: { 1788: register unsigned size; 1789: 1790: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_byte_size); 1791: switch (TREE_CODE (tree_node)) 1792: { 1793: case ERROR_MARK: 1794: size = 0; 1795: break; 1796: 1797: case ENUMERAL_TYPE: 1798: case RECORD_TYPE: 1799: case UNION_TYPE: 1800: size = int_size_in_bytes (tree_node); 1801: break; 1802: 1803: case FIELD_DECL: 1804: { 1805: register unsigned words; 1806: register unsigned bits; 1807: 1808: bits = TREE_INT_CST_LOW (DECL_SIZE (tree_node)); 1809: words = (bits + (BITS_PER_WORD-1)) / BITS_PER_WORD; 1810: size = words * (BITS_PER_WORD / BITS_PER_UNIT); 1811: } 1812: break; 1813: 1814: default: 1815: abort (); 1816: } 1817: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, size); 1818: } 1819: 1820: /* For a FIELD_DECL node which represents a bit field, output an attribute 1821: which specifies the distance in bits from the start of the *word* 1822: containing the given field to the first bit of the field. */ 1823: 1824: inline void 1825: bit_offset_attribute (decl) 1826: register tree decl; 1827: { 1828: assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ 1829: assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */ 1830: 1831: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_offset); 1832: ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 1833: BITFIELD_OFFSET_BITS (decl) % (unsigned) BITS_PER_WORD); 1834: } 1835: 1836: /* For a FIELD_DECL node which represents a bit field, output an attribute 1837: which specifies the length in bits of the given field. */ 1838: 1839: inline void 1840: bit_size_attribute (decl) 1841: register tree decl; 1842: { 1843: assert (TREE_CODE (decl) == FIELD_DECL); /* Must be a field. */ 1844: assert (DECL_BIT_FIELD_TYPE (decl)); /* Must be a bit field. */ 1845: 1846: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_bit_size); 1847: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 1848: (unsigned) TREE_INT_CST_LOW (DECL_SIZE (decl))); 1849: } 1850: 1851: /* The following routine outputs the `element_list' attribute for enumeration 1852: type DIEs. The element_lits attribute includes the names and values of 1853: all of the enumeration constants associated with the given enumeration 1854: type. */ 1855: 1856: inline void 1857: element_list_attribute (element) 1858: register tree element; 1859: { 1860: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1861: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1862: 1863: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_element_list); 1864: sprintf (begin_label, EE_BEGIN_LABEL_FMT, current_dienum); 1865: sprintf (end_label, EE_END_LABEL_FMT, current_dienum); 1866: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); 1867: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1868: 1869: /* Here we output a list of value/name pairs for each enumeration constant 1870: defined for this enumeration type (as required), but we do it in REVERSE 1871: order. The order is the one required by the draft #5 Dwarf specification 1872: published by the UI/PLSIG. */ 1873: 1874: output_enumeral_list (element); /* Recursively output the whole list. */ 1875: 1876: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1877: } 1878: 1879: /* Generate an AT_stmt_list attribute. These are normally present only in 1880: DIEs with a TAG_compile_unit tag. */ 1881: 1882: inline void 1883: stmt_list_attribute (label) 1884: register char *label; 1885: { 1886: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_stmt_list); 1887: /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ 1888: ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); 1889: } 1890: 1891: /* Generate an AT_low_pc attribute for a label DIE, a lexical_block DIE or 1892: for a subroutine DIE. */ 1893: 1894: inline void 1895: low_pc_attribute (asm_low_label) 1896: register char *asm_low_label; 1897: { 1898: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_low_pc); 1899: ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_low_label); 1900: } 1901: 1902: /* Generate an AT_high_pc attribute for a lexical_block DIE or for a 1903: subroutine DIE. */ 1904: 1905: inline void 1906: high_pc_attribute (asm_high_label) 1907: register char *asm_high_label; 1908: { 1909: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_high_pc); 1910: ASM_OUTPUT_DWARF_ADDR (asm_out_file, asm_high_label); 1911: } 1912: 1913: /* Generate an AT_language attribute given a LANG value. These attributes 1914: are used only within TAG_compile_unit DIEs. */ 1915: 1916: inline void 1917: language_attribute (language_code) 1918: register unsigned language_code; 1919: { 1920: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_language); 1921: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, language_code); 1922: } 1923: 1924: inline void 1925: member_attribute (context) 1926: register tree context; 1927: { 1928: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 1929: 1930: /* Generate this attribute only for members in C++. */ 1931: 1932: if (context != NULL 1933: && (TREE_CODE (context) == RECORD_TYPE 1934: || TREE_CODE (context) == UNION_TYPE)) 1935: { 1936: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_member); 1937: sprintf (label, TYPE_NAME_FMT, TYPE_UID (context)); 1938: ASM_OUTPUT_DWARF_REF (asm_out_file, label); 1939: } 1940: } 1941: 1942: inline void 1943: string_length_attribute (upper_bound) 1944: register tree upper_bound; 1945: { 1946: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1947: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 1948: 1949: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_string_length); 1950: sprintf (begin_label, SL_BEGIN_LABEL_FMT, current_dienum); 1951: sprintf (end_label, SL_END_LABEL_FMT, current_dienum); 1952: ASM_OUTPUT_DWARF_DELTA2 (asm_out_file, end_label, begin_label); 1953: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 1954: output_bound_representation (upper_bound, 0, 'u'); 1955: ASM_OUTPUT_LABEL (asm_out_file, end_label); 1956: } 1957: 1958: inline void 1959: comp_dir_attribute (dirname) 1960: register char *dirname; 1961: { 1962: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_comp_dir); 1963: ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname); 1964: } 1965: 1966: inline void 1967: sf_names_attribute (sf_names_start_label) 1968: register char *sf_names_start_label; 1969: { 1970: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_sf_names); 1971: /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ 1972: ASM_OUTPUT_DWARF_ADDR (asm_out_file, sf_names_start_label); 1973: } 1974: 1975: inline void 1976: src_info_attribute (src_info_start_label) 1977: register char *src_info_start_label; 1978: { 1979: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_src_info); 1980: /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ 1981: ASM_OUTPUT_DWARF_ADDR (asm_out_file, src_info_start_label); 1982: } 1983: 1984: inline void 1985: mac_info_attribute (mac_info_start_label) 1986: register char *mac_info_start_label; 1987: { 1988: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_mac_info); 1989: /* Don't use ASM_OUTPUT_DWARF_DATA4 here. */ 1990: ASM_OUTPUT_DWARF_ADDR (asm_out_file, mac_info_start_label); 1991: } 1992: 1993: inline void 1994: prototyped_attribute (func_type) 1995: register tree func_type; 1996: { 1997: if ((strcmp (language_string, "GNU C") == 0) 1998: && (TYPE_ARG_TYPES (func_type) != NULL)) 1999: { 2000: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_prototyped); 2001: ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); 2002: } 2003: } 2004: 2005: inline void 2006: producer_attribute (producer) 2007: register char *producer; 2008: { 2009: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_producer); 2010: ASM_OUTPUT_DWARF_STRING (asm_out_file, producer); 2011: } 2012: 2013: inline void 2014: inline_attribute (decl) 2015: register tree decl; 2016: { 2017: if (TREE_INLINE (decl)) 2018: { 2019: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_inline); 2020: ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); 2021: } 2022: } 2023: 2024: inline void 2025: containing_type_attribute (containing_type) 2026: register tree containing_type; 2027: { 2028: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 2029: 2030: ASM_OUTPUT_DWARF_ATTRIBUTE (asm_out_file, AT_containing_type); 2031: sprintf (label, TYPE_NAME_FMT, TYPE_UID (containing_type)); 2032: ASM_OUTPUT_DWARF_REF (asm_out_file, label); 2033: } 2034: 2035: /************************* end of attributes *****************************/ 2036: 2037: /********************* utility routines for DIEs *************************/ 2038: 2039: /* Many forms of DIEs contain a "type description" part. The following 2040: routine writes out these "type descriptor" parts. */ 2041: 2042: static void 2043: type_attribute (type, decl_const, decl_volatile) 2044: register tree type; 2045: register int decl_const; 2046: register int decl_volatile; 2047: { 2048: register enum tree_code code = TREE_CODE (type); 2049: register int root_type_modified; 2050: 2051: if (TREE_CODE (type) == ERROR_MARK) 2052: return; 2053: 2054: /* Handle a special case. For functions whose return type is void, 2055: we generate *no* type attribute. (Note that no object may have 2056: type `void', so this only applies to function return types. */ 2057: 2058: if (TREE_CODE (type) == VOID_TYPE) 2059: return; 2060: 2061: root_type_modified = (code == POINTER_TYPE || code == REFERENCE_TYPE 2062: || decl_const || decl_volatile 2063: || TYPE_READONLY (type) || TYPE_VOLATILE (type)); 2064: 2065: if (type_is_fundamental (root_type (type))) 2066: if (root_type_modified) 2067: mod_fund_type_attribute (type, decl_const, decl_volatile); 2068: else 2069: fund_type_attribute (fundamental_type_code (type)); 2070: else 2071: if (root_type_modified) 2072: mod_u_d_type_attribute (type, decl_const, decl_volatile); 2073: else 2074: user_def_type_attribute (type); 2075: } 2076: 2077: /* Given a tree pointer to a struct, class, union, or enum type node, return 2078: a pointer to the (string) tag name for the given type, or zero if the 2079: type was declared without a tag. */ 2080: 2081: static char * 2082: type_tag (type) 2083: register tree type; 2084: { 2085: register char *name = 0; 2086: 2087: if (TYPE_NAME (type) != 0) 2088: { 2089: register tree t = 0; 2090: 2091: /* Find the IDENTIFIER_NODE for the type name. */ 2092: if (TREE_CODE (TYPE_NAME (type)) == IDENTIFIER_NODE) 2093: t = TYPE_NAME (type); 2094: #if 0 2095: /* The g++ front end makes the TYPE_NAME of *each* tagged type point 2096: to a TYPE_DECL node, regardless of whether or not a `typedef' was 2097: involved. This is distinctly different from what the gcc front-end 2098: does. It always makes the TYPE_NAME for each tagged type be either 2099: NULL (signifying an anonymous tagged type) or else a pointer to an 2100: IDENTIFIER_NODE. Obviously, we would like to generate correct Dwarf 2101: for both C and C++, but given this inconsistancy in the TREE 2102: representation of tagged types for C and C++ in the GNU front-ends, 2103: we cannot support both languages correctly unless we introduce some 2104: front-end specific code here, and rms objects to that, so we can 2105: only generate correct Dwarf for one of these two languages. C is 2106: more important, so for now we'll do the right thing for C and let 2107: g++ go fish. */ 2108: 2109: else 2110: if (TREE_CODE (TYPE_NAME (type)) == TYPE_DECL) 2111: t = DECL_NAME (TYPE_NAME (type)); 2112: #endif 2113: /* Now get the name as a string, or invent one. */ 2114: if (t != 0) 2115: name = IDENTIFIER_POINTER (t); 2116: } 2117: 2118: return (name == 0 || *name == '\0') ? 0 : name; 2119: } 2120: 2121: inline void 2122: dienum_push () 2123: { 2124: /* Start by checking if the pending_sibling_stack needs to be expanded. 2125: If necessary, expand it. */ 2126: 2127: if (pending_siblings == pending_siblings_allocated) 2128: { 2129: pending_siblings_allocated += PENDING_SIBLINGS_INCREMENT; 2130: pending_sibling_stack 2131: = (unsigned *) xrealloc (pending_sibling_stack, 2132: pending_siblings_allocated * sizeof(unsigned)); 2133: } 2134: 2135: pending_siblings++; 2136: NEXT_DIE_NUM = next_unused_dienum++; 2137: } 2138: 2139: /* Pop the sibling stack so that the most recently pushed DIEnum becomes the 2140: NEXT_DIE_NUM. */ 2141: 2142: inline void 2143: dienum_pop () 2144: { 2145: pending_siblings--; 2146: } 2147: 2148: inline tree 2149: member_declared_type (member) 2150: register tree member; 2151: { 2152: return (DECL_BIT_FIELD_TYPE (member)) 2153: ? DECL_BIT_FIELD_TYPE (member) 2154: : TREE_TYPE (member); 2155: } 2156: 2157: /******************************* DIEs ************************************/ 2158: 2159: /* Output routines for individual types of DIEs. */ 2160: 2161: /* Note that every type of DIE (except a null DIE) gets a sibling. */ 2162: 2163: static void 2164: output_array_type_die (arg) 2165: register void *arg; 2166: { 2167: register tree type = arg; 2168: 2169: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_array_type); 2170: sibling_attribute (); 2171: equate_type_number_to_die_number (type); 2172: member_attribute (TYPE_CONTEXT (type)); 2173: 2174: /* I believe that we can default the array ordering. SDB will probably 2175: do the right things even if AT_ordering is not present. It's not 2176: even an issue until we start to get into multidimensional arrays 2177: anyway. If SDB is shown to do the wrong thing in those cases, then 2178: we'll have to put the AT_ordering attribute back in, but only for 2179: multidimensional array. (After all, we don't want to waste space 2180: in the .debug section now do we?) */ 2181: 2182: #if 0 2183: ordering_attribute (ORD_row_major); 2184: #endif 2185: 2186: subscript_data_attribute (type); 2187: } 2188: 2189: static void 2190: output_set_type_die (arg) 2191: register void *arg; 2192: { 2193: register tree type = arg; 2194: 2195: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_set_type); 2196: sibling_attribute (); 2197: equate_type_number_to_die_number (type); 2198: member_attribute (TYPE_CONTEXT (type)); 2199: type_attribute (TREE_TYPE (type), 0, 0); 2200: } 2201: 2202: #if 0 2203: /* Implement this when there is a GNU FORTRAN or GNU Ada front end. */ 2204: static void 2205: output_entry_point_die (arg) 2206: register void *arg; 2207: { 2208: register tree decl = arg; 2209: register tree type = TREE_TYPE (decl); 2210: register tree return_type = TREE_TYPE (type); 2211: 2212: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_entry_point); 2213: sibling_attribute (); 2214: dienum_push (); 2215: if (DECL_NAME (decl)) 2216: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2217: member_attribute (DECL_CONTEXT (decl)); 2218: type_attribute (return_type, 0, 0); 2219: } 2220: #endif 2221: 2222: /* Output a DIE to represent an enumeration type. Note that these DIEs 2223: include all of the information about the enumeration values also. 2224: This information is encoded into the element_list attribute. */ 2225: 2226: static void 2227: output_enumeration_type_die (arg) 2228: register void *arg; 2229: { 2230: register tree type = arg; 2231: 2232: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_enumeration_type); 2233: sibling_attribute (); 2234: equate_type_number_to_die_number (type); 2235: name_attribute (type_tag (type)); 2236: member_attribute (TYPE_CONTEXT (type)); 2237: 2238: /* Handle a GNU C/C++ extension, i.e. incomplete enum types. If the 2239: given enum type is incomplete, do not generate the AT_byte_size 2240: attribute or the AT_element_list attribute. */ 2241: 2242: if (TYPE_SIZE (type)) 2243: { 2244: byte_size_attribute (type); 2245: element_list_attribute (TYPE_FIELDS (type)); 2246: } 2247: } 2248: 2249: /* Output a DIE to represent either a real live formal parameter decl or 2250: to represent just the type of some formal parameter position in some 2251: function type. 2252: 2253: Note that this routine is a bit unusual because its argument may be 2254: either a PARM_DECL node or else some sort of a ..._TYPE node. If it's 2255: the formar then this function is being called to output a real live 2256: formal parameter declaration. If it's the latter, then this function 2257: is only being called to output a TAG_formal_parameter DIE to stand as 2258: a placeholder for some formal argument type of some subprogram type. */ 2259: 2260: static void 2261: output_formal_parameter_die (arg) 2262: register void *arg; 2263: { 2264: register tree decl = arg; 2265: register tree type; 2266: 2267: if (TREE_CODE (decl) == PARM_DECL) 2268: type = TREE_TYPE (decl); 2269: else 2270: { 2271: type = decl; /* we were called with a type, not a decl */ 2272: decl = NULL; 2273: } 2274: 2275: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_formal_parameter); 2276: sibling_attribute (); 2277: if (decl) 2278: { 2279: if (DECL_NAME (decl)) 2280: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2281: type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); 2282: location_or_const_value_attribute (decl); 2283: } 2284: else 2285: type_attribute (type, 0, 0); 2286: } 2287: 2288: /* Output a DIE to represent a declared function (either file-scope 2289: or block-local) which has "external linkage" (according to ANSI-C). */ 2290: 2291: static void 2292: output_global_subroutine_die (arg) 2293: register void *arg; 2294: { 2295: register tree decl = arg; 2296: register tree type = TREE_TYPE (decl); 2297: register tree return_type = TREE_TYPE (type); 2298: 2299: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_subroutine); 2300: sibling_attribute (); 2301: dienum_push (); 2302: if (DECL_NAME (decl)) 2303: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2304: inline_attribute (decl); 2305: prototyped_attribute (type); 2306: member_attribute (DECL_CONTEXT (decl)); 2307: type_attribute (return_type, 0, 0); 2308: if (!TREE_EXTERNAL (decl)) 2309: { 2310: char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2311: 2312: low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2313: sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number); 2314: high_pc_attribute (func_end_label); 2315: } 2316: } 2317: 2318: /* Output a DIE to represent a declared data object (either file-scope 2319: or block-local) which has "external linkage" (according to ANSI-C). */ 2320: 2321: static void 2322: output_global_variable_die (arg) 2323: register void *arg; 2324: { 2325: register tree decl = arg; 2326: register tree type = TREE_TYPE (decl); 2327: 2328: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_global_variable); 2329: sibling_attribute (); 2330: if (DECL_NAME (decl)) 2331: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2332: member_attribute (DECL_CONTEXT (decl)); 2333: type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); 2334: if (!TREE_EXTERNAL (decl)) 2335: location_or_const_value_attribute (decl); 2336: } 2337: 2338: #if 0 2339: /* TAG_inline_subroutine has been retired by the UI/PLSIG. We're 2340: now supposed to use either TAG_subroutine or TAG_global_subroutine 2341: (depending on whether or not the function in question has internal 2342: or external linkage) and we're supposed to just put in an AT_inline 2343: attribute. */ 2344: static void 2345: output_inline_subroutine_die (arg) 2346: register void *arg; 2347: { 2348: register tree decl = arg; 2349: register tree type = TREE_TYPE (decl); 2350: register tree return_type = TREE_TYPE (type); 2351: 2352: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inline_subroutine); 2353: sibling_attribute (); 2354: dienum_push (); 2355: if (DECL_NAME (decl)) 2356: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2357: prototyped_attribute (type); 2358: member_attribute (DECL_CONTEXT (decl)); 2359: type_attribute (return_type, 0, 0); 2360: 2361: /* Note: For each inline function which gets an out-of-line body 2362: generated for it, we want to generate AT_low_pc and AT_high_pc 2363: attributes here for the function's out-of-line body. 2364: 2365: Unfortunately, the decision as to whether or not to generate an 2366: out-of-line body for any given inline function may not be made 2367: until we reach the end of the containing scope for the given 2368: inline function (because only then will it be known if the 2369: function was ever even called). 2370: 2371: For this reason, the output of DIEs representing file-scope inline 2372: functions gets delayed until a special post-pass which happens only 2373: after we have reached the end of the compilation unit. Because of 2374: this mechanism, we can always be sure (by the time we reach here) 2375: that TREE_ASM_WRITTEN(decl) will correctly indicate whether or not 2376: there was an out-of-line body generated for this inline function. 2377: */ 2378: 2379: if (!TREE_EXTERNAL (decl)) 2380: { 2381: if (TREE_ASM_WRITTEN (decl)) 2382: { 2383: char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2384: 2385: low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2386: sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number); 2387: high_pc_attribute (func_end_label); 2388: } 2389: } 2390: } 2391: #endif 2392: 2393: static void 2394: output_label_die (arg) 2395: register void *arg; 2396: { 2397: register tree decl = arg; 2398: register rtx insn = DECL_RTL (decl); 2399: 2400: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_label); 2401: sibling_attribute (); 2402: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2403: 2404: /* When optimization is enabled (with -O) the code in jump.c and in flow.c 2405: may cause insns representing one of more of the user's own labels to 2406: be deleted. This happens whenever it is determined that a given label 2407: is unreachable. 2408: 2409: In such cases, we here generate an abbreviated form of a label DIE. 2410: This abbreviated version does *not* have a low_pc attribute. This 2411: should signify to the debugger that the label has been optimized away. 2412: 2413: Note that a CODE_LABEL can get deleted either by begin converted into 2414: a NOTE_INSN_DELETED note, or by simply having its INSN_DELETED_P flag 2415: set to true. We handle both cases here. 2416: */ 2417: 2418: if (GET_CODE (insn) == CODE_LABEL && ! INSN_DELETED_P (insn)) 2419: { 2420: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 2421: 2422: sprintf (label, INSN_LABEL_FMT, current_funcdef_number, 2423: (unsigned) INSN_UID (insn)); 2424: low_pc_attribute (label); 2425: } 2426: } 2427: 2428: static void 2429: output_lexical_block_die (arg) 2430: register void *arg; 2431: { 2432: register tree stmt = arg; 2433: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2434: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2435: 2436: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_lexical_block); 2437: sibling_attribute (); 2438: dienum_push (); 2439: sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number); 2440: low_pc_attribute (begin_label); 2441: sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number); 2442: high_pc_attribute (end_label); 2443: } 2444: 2445: static void 2446: output_inlined_subroutine_die (arg) 2447: register void *arg; 2448: { 2449: register tree stmt = arg; 2450: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2451: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2452: 2453: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_inlined_subroutine); 2454: sibling_attribute (); 2455: dienum_push (); 2456: sprintf (begin_label, BLOCK_BEGIN_LABEL_FMT, next_block_number); 2457: low_pc_attribute (begin_label); 2458: sprintf (end_label, BLOCK_END_LABEL_FMT, next_block_number); 2459: high_pc_attribute (end_label); 2460: } 2461: 2462: /* Output a DIE to represent a declared data object (either file-scope 2463: or block-local) which has "internal linkage" (according to ANSI-C). */ 2464: 2465: static void 2466: output_local_variable_die (arg) 2467: register void *arg; 2468: { 2469: register tree decl = arg; 2470: register tree type = TREE_TYPE (decl); 2471: 2472: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_local_variable); 2473: sibling_attribute (); 2474: if (DECL_NAME (decl)) 2475: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2476: member_attribute (DECL_CONTEXT (decl)); 2477: type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); 2478: location_or_const_value_attribute (decl); 2479: } 2480: 2481: static void 2482: output_member_die (arg) 2483: register void *arg; 2484: { 2485: register tree decl = arg; 2486: 2487: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_member); 2488: sibling_attribute (); 2489: if (DECL_NAME (decl)) 2490: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2491: member_attribute (DECL_CONTEXT (decl)); 2492: type_attribute (member_declared_type (decl), 2493: TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); 2494: if (DECL_BIT_FIELD_TYPE (decl)) /* If this is a bit field... */ 2495: { 2496: byte_size_attribute (decl); 2497: bit_size_attribute (decl); 2498: bit_offset_attribute (decl); 2499: } 2500: data_member_location_attribute (decl); 2501: } 2502: 2503: #if 0 2504: /* Don't generate either pointer_type DIEs or reference_type DIEs. According 2505: to the 4-4-90 Dwarf draft spec (just after requirement #47): 2506: 2507: These two type entries are not currently generated by any compiler. 2508: Since the only way to name a pointer (or reference) type is C or C++ 2509: is via a "typedef", an entry with the "typedef" tag is generated 2510: instead. 2511: 2512: We keep this code here just in case these types of DIEs may be needed 2513: to represent certain things in other languages (e.g. Pascal) someday. 2514: */ 2515: 2516: static void 2517: output_pointer_type_die (arg) 2518: register void *arg; 2519: { 2520: register tree type = arg; 2521: 2522: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_pointer_type); 2523: sibling_attribute (); 2524: equate_type_number_to_die_number (type); 2525: member_attribute (TYPE_CONTEXT (type)); 2526: type_attribute (TREE_TYPE (type), 0, 0); 2527: } 2528: 2529: static void 2530: output_reference_type_die (arg) 2531: register void *arg; 2532: { 2533: register tree type = arg; 2534: 2535: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_reference_type); 2536: sibling_attribute (); 2537: equate_type_number_to_die_number (type); 2538: member_attribute (TYPE_CONTEXT (type)); 2539: type_attribute (TREE_TYPE (type), 0, 0); 2540: } 2541: #endif 2542: 2543: output_ptr_to_mbr_type_die (arg) 2544: register void *arg; 2545: { 2546: register tree type = arg; 2547: 2548: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_ptr_to_member_type); 2549: sibling_attribute (); 2550: equate_type_number_to_die_number (type); 2551: member_attribute (TYPE_CONTEXT (type)); 2552: containing_type_attribute (TYPE_OFFSET_BASETYPE (type)); 2553: type_attribute (TREE_TYPE (type), 0, 0); 2554: } 2555: 2556: static void 2557: output_compile_unit_die (arg) 2558: register void *arg; 2559: { 2560: register char *main_input_filename = arg; 2561: 2562: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_compile_unit); 2563: sibling_attribute (); 2564: dienum_push (); 2565: name_attribute (main_input_filename); 2566: 2567: { 2568: char producer[250]; 2569: 2570: sprintf (producer, "%s %s", language_string, version_string); 2571: producer_attribute (producer); 2572: } 2573: 2574: if (strcmp (language_string, "GNU C++") == 0) 2575: language_attribute (LANG_C_PLUS_PLUS); 2576: else if (flag_traditional) 2577: language_attribute (LANG_C); 2578: else 2579: language_attribute (LANG_C89); 2580: low_pc_attribute (TEXT_BEGIN_LABEL); 2581: high_pc_attribute (TEXT_END_LABEL); 2582: if (debug_info_level >= DINFO_LEVEL_NORMAL) 2583: stmt_list_attribute (LINE_BEGIN_LABEL); 2584: last_filename = xstrdup (main_input_filename); 2585: 2586: { 1.1.1.2 ! root 2587: char *wd = getpwd (); ! 2588: if (wd) ! 2589: comp_dir_attribute (wd); 1.1 root 2590: } 2591: 2592: if (debug_info_level >= DINFO_LEVEL_NORMAL) 2593: { 2594: sf_names_attribute (SFNAMES_BEGIN_LABEL); 2595: src_info_attribute (SRCINFO_BEGIN_LABEL); 2596: if (debug_info_level >= DINFO_LEVEL_VERBOSE) 2597: mac_info_attribute (MACINFO_BEGIN_LABEL); 2598: } 2599: } 2600: 2601: static void 2602: output_string_type_die (arg) 2603: register void *arg; 2604: { 2605: register tree type = arg; 2606: 2607: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_string_type); 2608: sibling_attribute (); 2609: member_attribute (TYPE_CONTEXT (type)); 2610: 2611: /* Fudge the string length attribute for now. */ 2612: 2613: string_length_attribute ( 2614: TYPE_MAX_VALUE (TYPE_DOMAIN (type))); 2615: } 2616: 2617: static void 2618: output_structure_type_die (arg) 2619: register void *arg; 2620: { 2621: register tree type = arg; 2622: 2623: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_structure_type); 2624: sibling_attribute (); 2625: equate_type_number_to_die_number (type); 2626: name_attribute (type_tag (type)); 2627: member_attribute (TYPE_CONTEXT (type)); 2628: 2629: /* If this type has been completed, then give it a byte_size attribute 2630: and prepare to give a list of members. Otherwise, don't do either of 2631: these things. In the latter case, we will not be generating a list 2632: of members (since we don't have any idea what they might be for an 2633: incomplete type). */ 2634: 2635: if (TYPE_SIZE (type)) 2636: { 2637: dienum_push (); 2638: byte_size_attribute (type); 2639: } 2640: } 2641: 2642: /* Output a DIE to represent a declared function (either file-scope 2643: or block-local) which has "internal linkage" (according to ANSI-C). */ 2644: 2645: static void 2646: output_local_subroutine_die (arg) 2647: register void *arg; 2648: { 2649: register tree decl = arg; 2650: register tree type = TREE_TYPE (decl); 2651: register tree return_type = TREE_TYPE (type); 2652: char func_end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2653: 2654: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine); 2655: sibling_attribute (); 2656: dienum_push (); 2657: if (DECL_NAME (decl)) 2658: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2659: inline_attribute (decl); 2660: prototyped_attribute (type); 2661: member_attribute (DECL_CONTEXT (decl)); 2662: type_attribute (return_type, 0, 0); 2663: 2664: /* Avoid getting screwed up in cases where a function was declared static 2665: but where no definition was ever given for it. */ 2666: 2667: if (TREE_ASM_WRITTEN (decl)) 2668: { 2669: low_pc_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2670: sprintf (func_end_label, FUNC_END_LABEL_FMT, current_funcdef_number); 2671: high_pc_attribute (func_end_label); 2672: } 2673: } 2674: 2675: static void 2676: output_subroutine_type_die (arg) 2677: register void *arg; 2678: { 2679: register tree type = arg; 2680: register tree return_type = TREE_TYPE (type); 2681: 2682: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_subroutine_type); 2683: sibling_attribute (); 2684: dienum_push (); 2685: equate_type_number_to_die_number (type); 2686: prototyped_attribute (type); 2687: member_attribute (TYPE_CONTEXT (type)); 2688: type_attribute (return_type, 0, 0); 2689: } 2690: 2691: static void 2692: output_typedef_die (arg) 2693: register void *arg; 2694: { 2695: register tree decl = arg; 2696: register tree type = TREE_TYPE (decl); 2697: 2698: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_typedef); 2699: sibling_attribute (); 2700: if (DECL_NAME (decl)) 2701: name_attribute (IDENTIFIER_POINTER (DECL_NAME (decl))); 2702: member_attribute (DECL_CONTEXT (decl)); 2703: type_attribute (type, TREE_READONLY (decl), TREE_THIS_VOLATILE (decl)); 2704: } 2705: 2706: static void 2707: output_union_type_die (arg) 2708: register void *arg; 2709: { 2710: register tree type = arg; 2711: 2712: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_union_type); 2713: sibling_attribute (); 2714: equate_type_number_to_die_number (type); 2715: name_attribute (type_tag (type)); 2716: member_attribute (TYPE_CONTEXT (type)); 2717: 2718: /* If this type has been completed, then give it a byte_size attribute 2719: and prepare to give a list of members. Otherwise, don't do either of 2720: these things. In the latter case, we will not be generating a list 2721: of members (since we don't have any idea what they might be for an 2722: incomplete type). */ 2723: 2724: if (TYPE_SIZE (type)) 2725: { 2726: dienum_push (); 2727: byte_size_attribute (type); 2728: } 2729: } 2730: 2731: /* Generate a special type of DIE used as a stand-in for a trailing ellipsis 2732: at the end of an (ANSI prototyped) formal parameters list. */ 2733: 2734: static void 2735: output_unspecified_parameters_die (arg) 2736: register void *arg; 2737: { 2738: register tree decl_or_type = arg; 2739: 2740: ASM_OUTPUT_DWARF_TAG (asm_out_file, TAG_unspecified_parameters); 2741: sibling_attribute (); 2742: 2743: /* This kludge is here only for the sake of being compatible with what 2744: the USL CI5 C compiler does. The specification of Dwarf Version 1 2745: doesn't say that TAG_unspecified_parameters DIEs should contain any 2746: attributes other than the AT_sibling attribute, but they are certainly 2747: allowed to contain additional attributes, and the CI5 compiler 2748: generates AT_name, AT_fund_type, and AT_location attributes within 2749: TAG_unspecified_parameters DIEs which appear in the child lists for 2750: DIEs representing function definitions, so we do likewise here. */ 2751: 2752: if (TREE_CODE (decl_or_type) == FUNCTION_DECL && DECL_INITIAL (decl_or_type)) 2753: { 2754: name_attribute ("..."); 2755: fund_type_attribute (FT_pointer); 2756: /* location_attribute (?); */ 2757: } 2758: } 2759: 2760: static void 2761: output_padded_null_die (arg) 2762: register void *arg; 2763: { 2764: ASM_OUTPUT_ALIGN (asm_out_file, 2); /* 2**2 == 4 */ 2765: } 2766: 2767: /*************************** end of DIEs *********************************/ 2768: 2769: /* Generate some type of DIE. This routine generates the generic outer 2770: wrapper stuff which goes around all types of DIE's (regardless of their 2771: TAGs. All forms of DIEs start with a DIE-specific label, followed by a 2772: DIE-length word, followed by the guts of the DIE itself. After the guts 2773: of the DIE, there must always be a terminator label for the DIE. */ 2774: 2775: static void 2776: output_die (die_specific_output_function, param) 2777: register void (*die_specific_output_function)(); 2778: register void *param; 2779: { 2780: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2781: char end_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2782: 2783: current_dienum = NEXT_DIE_NUM; 2784: NEXT_DIE_NUM = next_unused_dienum; 2785: 2786: sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); 2787: sprintf (end_label, DIE_END_LABEL_FMT, current_dienum); 2788: 2789: /* Write a label which will act as the name for the start of this DIE. */ 2790: 2791: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 2792: 2793: /* Write the DIE-length word. */ 2794: 2795: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, end_label, begin_label); 2796: 2797: /* Fill in the guts of the DIE. */ 2798: 2799: next_unused_dienum++; 2800: die_specific_output_function (param); 2801: 2802: /* Write a label which will act as the name for the end of this DIE. */ 2803: 2804: ASM_OUTPUT_LABEL (asm_out_file, end_label); 2805: } 2806: 2807: static void 2808: end_sibling_chain () 2809: { 2810: char begin_label[MAX_ARTIFICIAL_LABEL_BYTES]; 2811: 2812: current_dienum = NEXT_DIE_NUM; 2813: NEXT_DIE_NUM = next_unused_dienum; 2814: 2815: sprintf (begin_label, DIE_BEGIN_LABEL_FMT, current_dienum); 2816: 2817: /* Write a label which will act as the name for the start of this DIE. */ 2818: 2819: ASM_OUTPUT_LABEL (asm_out_file, begin_label); 2820: 2821: /* Write the DIE-length word. */ 2822: 2823: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 4); 2824: 2825: dienum_pop (); 2826: } 2827: 2828: /* Generate a list of nameless TAG_formal_parameter DIEs (and perhaps a 2829: TAG_unspecified_parameters DIE) to represent the types of the formal 2830: parameters as specified in some function type specification (except 2831: for those which appear as part of a function *definition*). 2832: 2833: Note that we must be careful here to output all of the parameter DIEs 2834: *before* we output any DIEs needed to represent the types of the formal 2835: parameters. This keeps svr4 SDB happy because it (incorrectly) thinks 2836: that the first non-parameter DIE it sees ends the formal parameter list. 2837: */ 2838: 2839: static void 2840: output_formal_types (function_or_method_type) 2841: register tree function_or_method_type; 2842: { 2843: register tree link; 2844: register tree formal_type; 2845: register tree first_parm_type = TYPE_ARG_TYPES (function_or_method_type); 2846: 2847: /* In the case where we are generating a formal types list for a C++ 2848: non-static member function type, skip over the first thing on the 2849: TYPE_ARG_TYPES list because it only represents the type of the 2850: hidden `this pointer'. The debugger should be able to figure 2851: out (without being explicitly told) that this non-static member 2852: function type takes a `this pointer' and should be able to figure 2853: what the type of that hidden parameter is from the AT_member 2854: attribute of the parent TAG_subroutine_type DIE. */ 2855: 2856: if (TREE_CODE (function_or_method_type) == METHOD_TYPE) 2857: first_parm_type = TREE_CHAIN (first_parm_type); 2858: 2859: /* Make our first pass over the list of formal parameter types and output 2860: a TAG_formal_parameter DIE for each one. */ 2861: 2862: for (link = first_parm_type; link; link = TREE_CHAIN (link)) 2863: { 2864: formal_type = TREE_VALUE (link); 2865: if (formal_type == void_type_node) 2866: break; 2867: 2868: /* Output a (nameless) DIE to represent the formal parameter itself. */ 2869: 2870: output_die (output_formal_parameter_die, formal_type); 2871: } 2872: 2873: /* If this function type has an ellipsis, add a TAG_unspecified_parameters 2874: DIE to the end of the parameter list. */ 2875: 2876: if (formal_type != void_type_node) 2877: output_die (output_unspecified_parameters_die, function_or_method_type); 2878: 2879: /* Make our second (and final) pass over the list of formal parameter types 2880: and output DIEs to represent those types (as necessary). */ 2881: 2882: for (link = TYPE_ARG_TYPES (function_or_method_type); 2883: link; 2884: link = TREE_CHAIN (link)) 2885: { 2886: formal_type = TREE_VALUE (link); 2887: if (formal_type == void_type_node) 2888: break; 2889: 2890: output_type (formal_type, function_or_method_type); 2891: } 2892: } 2893: 2894: /* Remember a type in the pending_types_list. */ 2895: 2896: static void 2897: pend_type (type) 2898: register tree type; 2899: { 2900: if (pending_types == pending_types_allocated) 2901: { 2902: pending_types_allocated += PENDING_TYPES_INCREMENT; 2903: pending_types_list 2904: = (tree *) xrealloc (pending_types_list, 2905: sizeof (tree) * pending_types_allocated); 2906: } 2907: pending_types_list[pending_types++] = type; 2908: 2909: /* Mark the pending type as having been output already (even though 2910: it hasn't been). This prevents the type from being added to the 2911: pending_types_list more than once. */ 2912: 2913: TREE_ASM_WRITTEN (type) = 1; 2914: } 2915: 2916: /* Return non-zero if it is legitimate to output DIEs to represent a 2917: given type while we are generating the list of child DIEs for some 2918: DIE associated with a given scope. 2919: 2920: This function returns non-zero if *either* of the following two conditions 2921: is satisfied: 2922: 2923: o the type actually belongs to the given scope (as evidenced 2924: by its TYPE_CONTEXT value), or 2925: 2926: o the type is anonymous, and the `scope' in question is *not* 2927: a RECORD_TYPE or UNION_TYPE. 2928: 2929: In theory, we should be able to generate DIEs for anonymous types 2930: *anywhere* (since the scope of an anonymous type is irrelevant) 2931: however svr4 SDB doesn't want to see other type DIEs within the 2932: lists of child DIEs for a TAG_structure_type or TAG_union_type DIE. 2933: 2934: Note that TYPE_CONTEXT(type) may be NULL (to indicate global scope) 2935: or it may point to a BLOCK node (for types local to a block), or to a 2936: FUNCTION_DECL node (for types local to the heading of some function 2937: definition), or to a FUNCTION_TYPE node (for types local to the 2938: prototyped parameter list of a function type specification), or to a 2939: RECORD_TYPE or UNION_TYPE node (in the case of C++ nested types). 2940: 2941: The `scope' parameter should likewise be NULL or should point to a 2942: BLOCK node, a FUNCTION_DECL node, a FUNCTION_TYPE node, a RECORD_TYPE 2943: node, or a UNION_TYPE node. 2944: 2945: This function is used only for deciding when to "pend" and when to 2946: "un-pend" types to/from the pending_types_list. 2947: 2948: Note that we sometimes make use of this "type pending" feature in a 2949: rather twisted way to temporarily delay the production of DIEs for the 2950: types of formal parameters. (We do this just to make svr4 SDB happy.) 2951: It order to delay the production of DIEs representing types of formal 2952: parameters, callers of this function supply `fake_containing_scope' as 2953: the `scope' parameter to this function. Given that fake_containing_scope 2954: is *not* the containing scope for *any* other type, the desired effect 2955: is achieved, i.e. output of DIEs representing types is temporarily 2956: suspended, and any type DIEs which would have been output otherwise 2957: are instead placed onto the pending_types_list. Later on, we can force 2958: these (temporarily pended) types to be output simply by calling 2959: `output_pending_types_for_scope' with an actual argument equal to the 2960: true scope of the types we temporarily pended. 2961: */ 2962: 2963: static int 2964: type_ok_for_scope (type, scope) 2965: register tree type; 2966: register tree scope; 2967: { 2968: return (TYPE_CONTEXT (type) == scope 2969: || (TYPE_NAME (type) == NULL 2970: && TREE_CODE (scope) != RECORD_TYPE 2971: && TREE_CODE (scope) != UNION_TYPE)); 2972: } 2973: 2974: /* Output any pending types (from the pending_types list) which we can output 2975: now (given the limitations of the scope that we are working on now). 2976: 2977: For each type output, remove the given type from the pending_types_list 2978: *before* we try to output it. 2979: 2980: Note that we have to process the list in beginning-to-end order, 2981: because the call made here to output_type may cause yet more types 2982: to be added to the end of the list, and we may have to output some 2983: of them too. 2984: */ 2985: 2986: static void 2987: output_pending_types_for_scope (containing_scope) 2988: register tree containing_scope; 2989: { 2990: register unsigned i; 2991: 2992: for (i = 0; i < pending_types; ) 2993: { 2994: register tree type = pending_types_list[i]; 2995: 2996: if (type_ok_for_scope (type, containing_scope)) 2997: { 2998: register tree *mover; 2999: register tree *limit; 3000: 3001: pending_types--; 3002: limit = &pending_types_list[pending_types]; 3003: for (mover = &pending_types_list[i]; mover < limit; mover++) 3004: *mover = *(mover+1); 3005: 3006: /* Un-mark the type as having been output already (because it 3007: hasn't been, really). Then call output_type to generate a 3008: Dwarf representation of it. */ 3009: 3010: TREE_ASM_WRITTEN (type) = 0; 3011: output_type (type, containing_scope); 3012: 3013: /* Don't increment the loop counter in this case because we 3014: have shifted all of the subsequent pending types down one 3015: element in the pending_types_list array. */ 3016: } 3017: else 3018: i++; 3019: } 3020: } 3021: 3022: static void 3023: output_type (type, containing_scope) 3024: register tree type; 3025: register tree containing_scope; 3026: { 3027: if (type == 0 || type == error_mark_node) 3028: return; 3029: 3030: /* We are going to output a DIE to represent the unqualified version of 3031: of this type (i.e. without any const or volatile qualifiers) so get 3032: the main variant (i.e. the unqualified version) of this type now. */ 3033: 3034: type = TYPE_MAIN_VARIANT (type); 3035: 3036: if (TREE_ASM_WRITTEN (type)) 3037: return; 3038: 3039: /* Don't generate any DIEs for this type now unless it is OK to do so 3040: (based upon what `type_ok_for_scope' tells us). */ 3041: 3042: if (! type_ok_for_scope (type, containing_scope)) 3043: { 3044: pend_type (type); 3045: return; 3046: } 3047: 3048: switch (TREE_CODE (type)) 3049: { 3050: case ERROR_MARK: 3051: break; 3052: 3053: case POINTER_TYPE: 3054: case REFERENCE_TYPE: 3055: /* For these types, all that is required is that we output a DIE 3056: (or a set of DIEs) to represent that "basis" type. */ 3057: output_type (TREE_TYPE (type), containing_scope); 3058: break; 3059: 3060: case OFFSET_TYPE: 3061: /* This code is used for C++ pointer-to-data-member types. */ 3062: /* Output a description of the relevant class type. */ 3063: output_type (TYPE_OFFSET_BASETYPE (type), containing_scope); 3064: /* Output a description of the type of the object pointed to. */ 3065: output_type (TREE_TYPE (type), containing_scope); 3066: /* Now output a DIE to represent this pointer-to-data-member type 3067: itself. */ 3068: output_die (output_ptr_to_mbr_type_die, type); 3069: break; 3070: 3071: case SET_TYPE: 3072: output_type (TREE_TYPE (type), containing_scope); 3073: output_die (output_set_type_die, type); 3074: break; 3075: 3076: case FILE_TYPE: 3077: output_type (TREE_TYPE (type), containing_scope); 3078: abort (); /* No way to reprsent these in Dwarf yet! */ 3079: break; 3080: 3081: case STRING_TYPE: 3082: output_type (TREE_TYPE (type), containing_scope); 3083: output_die (output_string_type_die, type); 3084: break; 3085: 3086: case FUNCTION_TYPE: 3087: /* Force out return type (in case it wasn't forced out already). */ 3088: output_type (TREE_TYPE (type), containing_scope); 3089: output_die (output_subroutine_type_die, type); 3090: output_formal_types (type); 3091: end_sibling_chain (); 3092: break; 3093: 3094: case METHOD_TYPE: 3095: /* Force out return type (in case it wasn't forced out already). */ 3096: output_type (TREE_TYPE (type), containing_scope); 3097: output_die (output_subroutine_type_die, type); 3098: output_formal_types (type); 3099: end_sibling_chain (); 3100: break; 3101: 3102: case ARRAY_TYPE: 3103: { 3104: register tree element_type; 3105: 3106: element_type = TREE_TYPE (type); 3107: while (TREE_CODE (element_type) == ARRAY_TYPE) 3108: element_type = TREE_TYPE (element_type); 3109: 3110: output_type (element_type, containing_scope); 3111: output_die (output_array_type_die, type); 3112: } 3113: break; 3114: 3115: case ENUMERAL_TYPE: 3116: case RECORD_TYPE: 3117: case UNION_TYPE: 3118: 3119: /* For a non-file-scope tagged type, we can always go ahead and 3120: output a Dwarf description of this type right now, even if 3121: the type in question is still incomplete, because if this 3122: local type *was* ever completed anywhere within its scope, 3123: that complete definition would already have been attached to 3124: this RECORD_TYPE, UNION_TYPE or ENUMERAL_TYPE node by the 3125: time we reach this point. That's true because of the way the 3126: front-end does its processing of file-scope declarations (of 3127: functions and class types) within which other types might be 3128: nested. The C and C++ front-ends always gobble up such "local 3129: scope" things en-mass before they try to output *any* debugging 3130: information for any of the stuff contained inside them and thus, 3131: we get the benefit here of what is (in effect) a pre-resolution 3132: of forward references to tagged types in local scopes. 3133: 3134: Note however that for file-scope tagged types we cannot assume 3135: that such pre-resolution of forward references has taken place. 3136: A given file-scope tagged type may appear to be incomplete when 3137: we reach this point, but it may yet be given a full definition 3138: (at file-scope) later on during compilation. In order to avoid 3139: generating a premature (and possibly incorrect) set of Dwarf 3140: DIEs for such (as yet incomplete) file-scope tagged types, we 3141: generate nothing at all for as-yet incomplete file-scope tagged 3142: types here unless we are making our special "finalization" pass 3143: for file-scope things at the very end of compilation. At that 3144: time, we will certainly know as much about each file-scope tagged 3145: type as we are ever going to know, so at that point in time, we 3146: can safely generate correct Dwarf descriptions for these file- 3147: scope tagged types. 3148: */ 3149: 3150: if (TYPE_SIZE (type) == 0 && TYPE_CONTEXT (type) == NULL && !finalizing) 3151: return; /* EARLY EXIT! Avoid setting TREE_ASM_WRITTEN. */ 3152: 3153: /* Prevent infinite recursion in cases where the type of some 3154: member of this type is expressed in terms of this type itself. */ 3155: 3156: TREE_ASM_WRITTEN (type) = 1; 3157: 3158: /* Output a DIE to represent the tagged type itself. */ 3159: 3160: switch (TREE_CODE (type)) 3161: { 3162: case ENUMERAL_TYPE: 3163: output_die (output_enumeration_type_die, type); 3164: return; /* a special case -- nothing left to do so just return */ 3165: 3166: case RECORD_TYPE: 3167: output_die (output_structure_type_die, type); 3168: break; 3169: 3170: case UNION_TYPE: 3171: output_die (output_union_type_die, type); 3172: break; 3173: } 3174: 3175: /* If this is not an incomplete type, output descriptions of 3176: each of its members. 3177: 3178: Note that as we output the DIEs necessary to represent the 3179: members of this record or union type, we will also be trying 3180: to output DIEs to represent the *types* of those members. 3181: However the `output_type' function (above) will specifically 3182: avoid generating type DIEs for member types *within* the list 3183: of member DIEs for this (containing) type execpt for those 3184: types (of members) which are explicitly marked as also being 3185: members of this (containing) type themselves. The g++ front- 3186: end can force any given type to be treated as a member of some 3187: other (containing) type by setting the TYPE_CONTEXT of the 3188: given (member) type to point to the TREE node representing the 3189: appropriate (containing) type. 3190: */ 3191: 3192: if (TYPE_SIZE (type)) 3193: { 3194: register tree member; 3195: 3196: /* First output info about the data members and type members. */ 3197: 3198: for (member = TYPE_FIELDS (type); 3199: member; 3200: member = TREE_CHAIN (member)) 3201: output_decl (member, type); 3202: 3203: /* Now output info about the function members (if any). */ 3204: 3205: if (TYPE_METHODS (type)) 3206: for (member = TREE_VEC_ELT (TYPE_METHODS (type), 0); 3207: member; 3208: member = TREE_CHAIN (member)) 3209: output_decl (member, type); 3210: 3211: end_sibling_chain (); /* Terminate member chain. */ 3212: } 3213: 3214: break; 3215: 3216: case VOID_TYPE: 3217: case INTEGER_TYPE: 3218: case REAL_TYPE: 3219: case COMPLEX_TYPE: 3220: case BOOLEAN_TYPE: 3221: case CHAR_TYPE: 3222: break; /* No DIEs needed for fundamental types. */ 3223: 3224: case LANG_TYPE: /* No Dwarf representation currently defined. */ 3225: break; 3226: 3227: default: 3228: abort (); 3229: } 3230: 3231: TREE_ASM_WRITTEN (type) = 1; 3232: } 3233: 3234: /* Output a TAG_lexical_block DIE followed by DIEs to represent all of 3235: the things which are local to the given block. */ 3236: 3237: static void 3238: output_block (stmt) 3239: register tree stmt; 3240: { 3241: register int have_significant_locals = 0; 3242: 3243: /* Ignore blocks never really used to make RTL. */ 3244: 3245: if (! stmt || ! TREE_USED (stmt)) 3246: return; 3247: 3248: /* Determine if this block contains any "significant" local declarations 3249: which we need to output DIEs for. */ 3250: 3251: if (BLOCK_INLINE_FUNCTION (stmt)) 3252: /* The outer scopes for inlinings *must* always be represented. */ 3253: have_significant_locals = 1; 3254: else 3255: if (debug_info_level > DINFO_LEVEL_TERSE) 3256: have_significant_locals = (BLOCK_VARS (stmt) != NULL); 3257: else 3258: { 3259: register tree decl; 3260: 3261: for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) 3262: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl)) 3263: { 3264: have_significant_locals = 1; 3265: break; 3266: } 3267: } 3268: 3269: /* It would be a waste of space to generate a Dwarf TAG_lexical_block 3270: DIE for any block which contains no significant local declarations 3271: at all. Rather, in such cases we just call `output_decls_for_scope' 3272: so that any needed Dwarf info for any sub-blocks will get properly 3273: generated. Note that in terse mode, our definition of what constitutes 3274: a "significant" local declaration gets restricted to include only 3275: inlined function instances and local (nested) function definitions. */ 3276: 3277: if (have_significant_locals) 3278: { 3279: output_die (BLOCK_INLINE_FUNCTION (stmt) 3280: ? output_inlined_subroutine_die 3281: : output_lexical_block_die, 3282: stmt); 3283: output_decls_for_scope (stmt); 3284: end_sibling_chain (); 3285: } 3286: else 3287: output_decls_for_scope (stmt); 3288: } 3289: 3290: /* Output all of the decls declared within a given scope (also called 3291: a `binding contour') and (recursively) all of it's sub-blocks. */ 3292: 3293: static void 3294: output_decls_for_scope (stmt) 3295: register tree stmt; 3296: { 3297: /* Ignore blocks never really used to make RTL. */ 3298: 3299: if (! stmt || ! TREE_USED (stmt)) 3300: return; 3301: 3302: next_block_number++; 3303: 3304: /* Output the DIEs to represent all of the data objects, functions, 3305: typedefs, and tagged types declared directly within this block 3306: but not within any nested sub-blocks. */ 3307: 3308: { 3309: register tree decl; 3310: 3311: for (decl = BLOCK_VARS (stmt); decl; decl = TREE_CHAIN (decl)) 3312: output_decl (decl, stmt); 3313: } 3314: 3315: output_pending_types_for_scope (stmt); 3316: 3317: /* Output the DIEs to represent all sub-blocks (and the items declared 3318: therein) of this block. */ 3319: 3320: { 3321: register tree subblocks; 3322: 3323: for (subblocks = BLOCK_SUBBLOCKS (stmt); 3324: subblocks; 3325: subblocks = BLOCK_CHAIN (subblocks)) 3326: output_block (subblocks); 3327: } 3328: } 3329: 3330: /* Output Dwarf .debug information for a decl described by DECL. */ 3331: 3332: static void 3333: output_decl (decl, containing_scope) 3334: register tree decl; 3335: register tree containing_scope; 3336: { 3337: switch (TREE_CODE (decl)) 3338: { 3339: case ERROR_MARK: 3340: break; 3341: 3342: case CONST_DECL: 3343: /* The individual enumerators of an enum type get output when we 3344: output the Dwarf representation of the relevant enum type itself. */ 3345: break; 3346: 3347: case FUNCTION_DECL: 3348: /* If we are in terse mode, don't output any DIEs to represent 3349: mere external function declarations. */ 3350: 3351: if (TREE_EXTERNAL (decl) && debug_info_level <= DINFO_LEVEL_TERSE) 3352: break; 3353: 3354: /* Before we describe the FUNCTION_DECL itself, make sure that we 3355: have described its return type. */ 3356: 3357: output_type (TREE_TYPE (TREE_TYPE (decl)), containing_scope); 3358: 3359: /* If the following DIE will represent a function definition for a 3360: function with "extern" linkage, output a special "pubnames" DIE 3361: label just ahead of the actual DIE. A reference to this label 3362: was already generated in the .debug_pubnames section sub-entry 3363: for this function definition. */ 3364: 3365: if (TREE_PUBLIC (decl)) 3366: { 3367: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3368: 3369: sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); 3370: ASM_OUTPUT_LABEL (asm_out_file, label); 3371: } 3372: 3373: /* Now output a DIE to represent the function itself. */ 3374: 3375: output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl) 3376: ? output_global_subroutine_die 3377: : output_local_subroutine_die, 3378: decl); 3379: 3380: /* Now output descriptions of the arguments for this function. 3381: This gets (unnecessarily?) complex because of the fact that 3382: the DECL_ARGUMENT list for a FUNCTION_DECL doesn't indicate 3383: cases where there was a trailing `...' at the end of the formal 3384: parameter list. In order to find out if there was a trailing 3385: ellipsis or not, we must instead look at the type associated 3386: with the FUNCTION_DECL. This will be a node of type FUNCTION_TYPE. 3387: If the chain of type nodes hanging off of this FUNCTION_TYPE node 3388: ends with a void_type_node then there should *not* be an ellipsis 3389: at the end. */ 3390: 3391: /* In the case where we are describing an external function, all 3392: we need to do here (and all we *can* do here) is to describe 3393: the *types* of its formal parameters. */ 3394: 3395: if (TREE_EXTERNAL (decl)) 3396: output_formal_types (TREE_TYPE (decl)); 3397: else 3398: { 3399: register tree arg_decls = DECL_ARGUMENTS (decl); 3400: 3401: /* In the case where the FUNCTION_DECL represents a C++ non-static 3402: member function, skip over the first thing on the DECL_ARGUMENTS 3403: chain. It only represents the hidden `this pointer' parameter 3404: and the debugger should know implicitly that non-static member 3405: functions have such a thing, and should be able to figure out 3406: exactly what the type of each `this pointer' is (from the 3407: AT_member attribute of the parent TAG_subroutine DIE) without 3408: being explicitly told. */ 3409: 3410: if (TREE_CODE (TREE_TYPE (decl)) == METHOD_TYPE) 3411: arg_decls = TREE_CHAIN (arg_decls); 3412: 3413: { 3414: register tree last_arg; 3415: 3416: last_arg = (arg_decls && TREE_CODE (arg_decls) != ERROR_MARK) 3417: ? tree_last (arg_decls) 3418: : NULL; 3419: 3420: /* Generate DIEs to represent all known formal parameters, but 3421: don't do it if this looks like a varargs function. A given 3422: function is considered to be a varargs function if (and only 3423: if) its last named argument is named `__builtin_va_alist'. */ 3424: 3425: if (! last_arg 3426: || ! DECL_NAME (last_arg) 3427: || strcmp (IDENTIFIER_POINTER (DECL_NAME (last_arg)), 3428: "__builtin_va_alist")) 3429: { 3430: register tree parm; 3431: 3432: /* WARNING! Kludge zone ahead! Here we have a special 1.1.1.2 ! root 3433: hack for svr4 SDB compatibility. Instead of passing the 1.1 root 3434: current FUNCTION_DECL node as the second parameter (i.e. 3435: the `containing_scope' parameter) to `output_decl' (as 3436: we ought to) we instead pass a pointer to our own private 3437: fake_containing_scope node. That node is a RECORD_TYPE 3438: node which NO OTHER TYPE may ever actually be a member of. 3439: 3440: This pointer will ultimately get passed into `output_type' 3441: as its `containing_scope' parameter. `Output_type' will 3442: then perform its part in the hack... i.e. it will pend 3443: the type of the formal parameter onto the pending_types 3444: list. Later on, when we are done generating the whole 3445: sequence of formal parameter DIEs for this function 3446: definition, we will un-pend all previously pended types 3447: of formal parameters for this function definition. 3448: 3449: This whole kludge prevents any type DIEs from being 3450: mixed in with the formal parameter DIEs. That's good 3451: because svr4 SDB believes that the list of formal 3452: parameter DIEs for a function ends wherever the first 3453: non-formal-parameter DIE appears. Thus, we have to 3454: keep the formal parameter DIEs segregated. They must 3455: all appear (consecutively) at the start of the list of 3456: children for the DIE representing the function definition. 3457: Then (and only then) may we output any additional DIEs 3458: needed to represent the types of these formal parameters. 3459: */ 3460: 3461: for (parm = arg_decls; parm; parm = TREE_CHAIN (parm)) 3462: if (TREE_CODE (parm) == PARM_DECL) 3463: output_decl (parm, fake_containing_scope); 3464: 3465: /* Now that we have finished generating all of the DIEs to 3466: represent the formal parameters themselves, force out 3467: any DIEs needed to represent their types. We do this 3468: simply by un-pending all previously pended types which 3469: can legitimately go into the chain of children DIEs for 3470: the current FUNCTION_DECL. */ 3471: 3472: output_pending_types_for_scope (decl); 3473: } 3474: } 3475: 3476: /* Now try to decide if we should put an ellipsis at the end. */ 3477: 3478: { 3479: register int has_ellipsis = TRUE; /* default assumption */ 3480: register tree fn_arg_types = TYPE_ARG_TYPES (TREE_TYPE (decl)); 3481: 3482: if (fn_arg_types) 3483: { 3484: /* This function declaration/definition was prototyped. */ 3485: 3486: /* If the list of formal argument types ends with a 3487: void_type_node, then the formals list did *not* end 3488: with an ellipsis. */ 3489: 3490: if (TREE_VALUE (tree_last (fn_arg_types)) == void_type_node) 3491: has_ellipsis = FALSE; 3492: } 3493: else 3494: { 3495: /* This function declaration/definition was not prototyped. */ 3496: 3497: /* Note that all non-prototyped function *declarations* are 3498: assumed to represent varargs functions (until proven 3499: otherwise). */ 3500: 3501: if (DECL_INITIAL (decl)) /* if this is a func definition */ 3502: { 3503: if (!arg_decls) 3504: has_ellipsis = FALSE; /* no args == (void) */ 3505: else 3506: { 3507: /* For a non-prototyped function definition which 3508: declares one or more formal parameters, if the name 3509: of the first formal parameter is *not* 3510: __builtin_va_alist then we must assume that this 3511: is *not* a varargs function. */ 3512: 3513: if (DECL_NAME (arg_decls) 3514: && strcmp (IDENTIFIER_POINTER (DECL_NAME (arg_decls)), 3515: "__builtin_va_alist")) 3516: has_ellipsis = FALSE; 3517: } 3518: } 3519: } 3520: 3521: if (has_ellipsis) 3522: output_die (output_unspecified_parameters_die, decl); 3523: } 3524: } 3525: 3526: /* Output Dwarf info for all of the stuff within the body of the 3527: function (if it has one - it may be just a declaration). */ 3528: 3529: { 3530: register tree outer_scope = DECL_INITIAL (decl); 3531: 3532: if (outer_scope && TREE_CODE (outer_scope) != ERROR_MARK) 3533: { 3534: /* Note that here, `outer_scope' is a pointer to the outermost 3535: BLOCK node created to represent the body of a function. 3536: This outermost BLOCK actually represents the outermost 3537: binding contour for the function, i.e. the contour in which 3538: the function's formal parameters get declared. Just within 3539: this contour, there will be another (nested) BLOCK which 3540: represents the function's outermost block. We don't want 3541: to generate a lexical_block DIE to represent the outermost 3542: block of a function body, because that is not really an 3543: independent scope according to ANSI C rules. Rather, it is 3544: the same scope in which the parameters were declared and 3545: for Dwarf, we do not generate a TAG_lexical_block DIE for 3546: that scope. We must however see to it that the LABEL_DECLs 3547: associated with `outer_scope' get DIEs generated for them. */ 3548: 3549: { 3550: register tree label; 3551: 3552: for (label = BLOCK_VARS (outer_scope); 3553: label; 3554: label = TREE_CHAIN (label)) 3555: output_decl (label, outer_scope); 3556: } 3557: 3558: output_decls_for_scope (BLOCK_SUBBLOCKS (outer_scope)); 3559: 3560: /* Finally, force out any pending types which are local to the 3561: outermost block of this function definition. These will 3562: all have a TYPE_CONTEXT which points to the FUNCTION_DECL 3563: node itself. */ 3564: 3565: output_pending_types_for_scope (decl); 3566: } 3567: } 3568: 3569: /* Generate a terminator for the list of stuff `owned' by this 3570: function. */ 3571: 3572: end_sibling_chain (); 3573: 3574: break; 3575: 3576: case TYPE_DECL: 3577: /* If we are in terse mode, don't generate any DIEs to represent 3578: any actual typedefs. Note that even when we are in terse mode, 3579: we must still output DIEs to represent those tagged types which 3580: are used (directly or indirectly) in the specification of either 3581: a return type or a formal parameter type of some function. */ 3582: 3583: if (debug_info_level <= DINFO_LEVEL_TERSE) 3584: if (DECL_NAME (decl) != NULL 3585: || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) 3586: return; 3587: 3588: output_type (TREE_TYPE (decl), containing_scope); 3589: 3590: /* Note that unlike the gcc front end (which generates a NULL named 3591: TYPE_DECL node for each complete tagged type, each array type, 3592: and each function type node created) the g++ front end generates 3593: a *named* TYPE_DECL node for each tagged type node created. 3594: Unfortunately, these g++ TYPE_DECL nodes cause us to output many 3595: superfluous and unnecessary TAG_typedef DIEs here. When g++ is 3596: fixed to stop generating these superfluous named TYPE_DECL nodes, 3597: the superfluous TAG_typedef DIEs will likewise cease. */ 3598: 3599: if (DECL_NAME (decl)) 3600: /* Output a DIE to represent the typedef itself. */ 3601: output_die (output_typedef_die, decl); 3602: break; 3603: 3604: case LABEL_DECL: 3605: if (debug_info_level >= DINFO_LEVEL_NORMAL) 3606: output_die (output_label_die, decl); 3607: break; 3608: 3609: case VAR_DECL: 3610: /* If we are in terse mode, don't generate any DIEs to represent 3611: any variable declarations or definitions. */ 3612: 3613: if (debug_info_level <= DINFO_LEVEL_TERSE) 3614: break; 3615: 3616: /* Output any DIEs that are needed to specify the type of this data 3617: object. */ 3618: 3619: output_type (TREE_TYPE (decl), containing_scope); 3620: 3621: /* If the following DIE will represent a data object definition for a 3622: data object with "extern" linkage, output a special "pubnames" DIE 3623: label just ahead of the actual DIE. A reference to this label 3624: was already generated in the .debug_pubnames section sub-entry 3625: for this data object definition. */ 3626: 3627: if (TREE_PUBLIC (decl)) 3628: { 3629: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3630: 3631: sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number++); 3632: ASM_OUTPUT_LABEL (asm_out_file, label); 3633: } 3634: 3635: /* Now output the DIE to represent the data object itself. */ 3636: 3637: output_die (TREE_PUBLIC (decl) || TREE_EXTERNAL (decl) 3638: ? output_global_variable_die : output_local_variable_die, 3639: decl); 3640: break; 3641: 3642: case FIELD_DECL: 3643: /* Ignore the nameless fields that are used to skip bits. */ 3644: if (DECL_NAME (decl) != 0) 3645: { 3646: output_type (member_declared_type (decl), containing_scope); 3647: output_die (output_member_die, decl); 3648: } 3649: break; 3650: 3651: case PARM_DECL: 3652: /* Force out the type of this formal, if it was not forced out yet. 3653: Note that here we can run afowl of a bug in "classic" svr4 SDB. 3654: It should be able to grok the presence of type DIEs within a list 3655: of TAG_formal_parameter DIEs, but it doesn't. */ 3656: 3657: output_type (TREE_TYPE (decl), containing_scope); 3658: output_die (output_formal_parameter_die, decl); 3659: break; 3660: 3661: default: 3662: abort (); 3663: } 3664: } 3665: 3666: void 3667: dwarfout_file_scope_decl (decl, set_finalizing) 3668: register tree decl; 3669: register int set_finalizing; 3670: { 3671: switch (TREE_CODE (decl)) 3672: { 3673: case FUNCTION_DECL: 3674: 3675: /* Ignore this FUNCTION_DECL if it refers to a builtin function. */ 3676: 3677: if (TREE_EXTERNAL (decl) && DECL_FUNCTION_CODE (decl)) 3678: return; 3679: 3680: /* Ignore this FUNCTION_DECL if it refers to a file-scope extern 3681: function declaration and if the declaration was never even 3682: referenced from within this entire compilation unit. We 3683: suppress these DIEs in order to save space in the .debug section 3684: (by eliminating entries which are probably useless). Note that 3685: we must not suppress block-local extern declarations (whether 3686: used or not) because that would screw-up the debugger's name 3687: lookup mechanism and cause it to miss things which really ought 3688: to be in scope at a given point. */ 3689: 3690: if (TREE_EXTERNAL (decl) && !TREE_USED (decl)) 3691: return; 3692: 3693: if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl)) 3694: { 3695: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3696: 3697: /* Output a .debug_pubnames entry for a public function 3698: defined in this compilation unit. */ 3699: 3700: fputc ('\n', asm_out_file); 3701: ASM_DWARF_PUBNAMES_SECTION (asm_out_file); 3702: sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); 3703: ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); 3704: ASM_OUTPUT_DWARF_STRING (asm_out_file, 3705: IDENTIFIER_POINTER (DECL_NAME (decl))); 3706: ASM_DWARF_POP_SECTION (asm_out_file); 3707: } 3708: 3709: break; 3710: 3711: case VAR_DECL: 3712: 3713: /* Ignore this VAR_DECL if it refers to a file-scope extern data 3714: object declaration and if the declaration was never even 3715: referenced from within this entire compilation unit. We 3716: suppress these DIEs in order to save space in the .debug section 3717: (by eliminating entries which are probably useless). Note that 3718: we must not suppress block-local extern declarations (whether 3719: used or not) because that would screw-up the debugger's name 3720: lookup mechanism and cause it to miss things which really ought 3721: to be in scope at a given point. */ 3722: 3723: if (TREE_EXTERNAL (decl) && !TREE_USED (decl)) 3724: return; 3725: 3726: if (TREE_PUBLIC (decl) && ! TREE_EXTERNAL (decl)) 3727: { 3728: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3729: 3730: if (debug_info_level >= DINFO_LEVEL_NORMAL) 3731: { 3732: /* Output a .debug_pubnames entry for a public variable 3733: defined in this compilation unit. */ 3734: 3735: fputc ('\n', asm_out_file); 3736: ASM_DWARF_PUBNAMES_SECTION (asm_out_file); 3737: sprintf (label, PUB_DIE_LABEL_FMT, next_pubname_number); 3738: ASM_OUTPUT_DWARF_ADDR (asm_out_file, label); 3739: ASM_OUTPUT_DWARF_STRING (asm_out_file, 3740: IDENTIFIER_POINTER (DECL_NAME (decl))); 3741: ASM_DWARF_POP_SECTION (asm_out_file); 3742: } 3743: 3744: if (DECL_INITIAL (decl) == NULL) 3745: { 3746: /* Output a .debug_aranges entry for a public variable 3747: which is tenatively defined in this compilation unit. */ 3748: 3749: fputc ('\n', asm_out_file); 3750: ASM_DWARF_ARANGES_SECTION (asm_out_file); 3751: ASM_OUTPUT_DWARF_ADDR (asm_out_file, 3752: IDENTIFIER_POINTER (DECL_NAME (decl))); 3753: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 3754: (unsigned) int_size_in_bytes (TREE_TYPE (decl))); 3755: ASM_DWARF_POP_SECTION (asm_out_file); 3756: } 3757: } 3758: 3759: /* If we are in terse mode, don't generate any DIEs to represent 3760: any variable declarations or definitions. */ 3761: 3762: if (debug_info_level <= DINFO_LEVEL_TERSE) 3763: return; 3764: 3765: break; 3766: 3767: case TYPE_DECL: 3768: /* Don't generate any DIEs to represent the standard built-in types. */ 3769: 3770: if (DECL_SOURCE_LINE (decl) == 0) 3771: return; 3772: 3773: /* If we are in terse mode, don't generate any DIEs to represent 3774: any actual typedefs. Note that even when we are in terse mode, 3775: we must still output DIEs to represent those tagged types which 3776: are used (directly or indirectly) in the specification of either 3777: a return type or a formal parameter type of some function. */ 3778: 3779: if (debug_info_level <= DINFO_LEVEL_TERSE) 3780: if (DECL_NAME (decl) != NULL 3781: || ! TYPE_USED_FOR_FUNCTION (TREE_TYPE (decl))) 3782: return; 3783: 3784: break; 3785: 3786: default: 3787: return; 3788: } 3789: 3790: fputc ('\n', asm_out_file); 3791: ASM_DWARF_DEBUG_SECTION (asm_out_file); 3792: finalizing = set_finalizing; 3793: output_decl (decl, NULL); 3794: 3795: /* NOTE: The call above to `output_decl' may have caused one or more 3796: file-scope named types (i.e. tagged types) to be placed onto the 3797: pending_types_list. We have to get those types off of that list 3798: at some point, and this is the perfect time to do it. If we didn't 3799: take them off now, they might still be on the list when cc1 finally 3800: exits. That might be OK if it weren't for the fact that when we put 3801: types onto the pending_types_list, we set the TREE_ASM_WRITTEN flag 3802: for these types, and that causes them never to be output unless 3803: `output_pending_types_for_scope' takes them off of the list and un-sets 3804: their TREE_ASM_WRITTEN flags. */ 3805: 3806: output_pending_types_for_scope (NULL); 3807: 3808: /* The above call should have totally emptied the pending_types_list. */ 3809: 3810: assert (pending_types == 0); 3811: 3812: ASM_DWARF_POP_SECTION (asm_out_file); 3813: 3814: if (TREE_CODE (decl) == FUNCTION_DECL && DECL_INITIAL (decl) != NULL) 3815: current_funcdef_number++; 3816: } 3817: 3818: /* Output a marker (i.e. a label) for the beginning of the generated code 3819: for a lexical block. */ 3820: 3821: void 3822: dwarfout_begin_block (blocknum) 3823: register unsigned blocknum; 3824: { 3825: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3826: 3827: text_section (); 3828: sprintf (label, BLOCK_BEGIN_LABEL_FMT, blocknum); 3829: ASM_OUTPUT_LABEL (asm_out_file, label); 3830: } 3831: 3832: /* Output a marker (i.e. a label) for the end of the generated code 3833: for a lexical block. */ 3834: 3835: void 3836: dwarfout_end_block (blocknum) 3837: register unsigned blocknum; 3838: { 3839: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3840: 3841: text_section (); 3842: sprintf (label, BLOCK_END_LABEL_FMT, blocknum); 3843: ASM_OUTPUT_LABEL (asm_out_file, label); 3844: } 3845: 3846: /* Output a marker (i.e. a label) at a point in the assembly code which 3847: corresponds to a given source level label. */ 3848: 3849: void 3850: dwarfout_label (insn) 3851: register rtx insn; 3852: { 3853: if (debug_info_level >= DINFO_LEVEL_NORMAL) 3854: { 3855: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3856: 3857: text_section (); 3858: sprintf (label, INSN_LABEL_FMT, current_funcdef_number, 3859: (unsigned) INSN_UID (insn)); 3860: ASM_OUTPUT_LABEL (asm_out_file, label); 3861: } 3862: } 3863: 3864: /* Output a marker (i.e. a label) for the absolute end of the generated code 3865: for a function definition. This gets called *after* the epilogue code 3866: has been generated. */ 3867: 3868: void 3869: dwarfout_end_epilogue () 3870: { 3871: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3872: 3873: /* Output a label to mark the endpoint of the code generated for this 3874: function. */ 3875: 3876: sprintf (label, FUNC_END_LABEL_FMT, current_funcdef_number); 3877: ASM_OUTPUT_LABEL (asm_out_file, label); 3878: } 3879: 3880: static void 3881: shuffle_filename_entry (new_zeroth) 3882: register filename_entry *new_zeroth; 3883: { 3884: filename_entry temp_entry; 3885: register filename_entry *limit_p; 3886: register filename_entry *move_p; 3887: 3888: if (new_zeroth == &filename_table[0]) 3889: return; 3890: 3891: temp_entry = *new_zeroth; 3892: 3893: /* Shift entries up in the table to make room at [0]. */ 3894: 3895: limit_p = &filename_table[0]; 3896: for (move_p = new_zeroth; move_p > limit_p; move_p--) 3897: *move_p = *(move_p-1); 3898: 3899: /* Install the found entry at [0]. */ 3900: 3901: filename_table[0] = temp_entry; 3902: } 3903: 3904: /* Create a new (string) entry for the .debug_sfnames section. */ 3905: 3906: static void 3907: generate_new_sfname_entry () 3908: { 3909: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 3910: 3911: fputc ('\n', asm_out_file); 3912: ASM_DWARF_SFNAMES_SECTION (asm_out_file); 3913: sprintf (label, SFNAMES_ENTRY_LABEL_FMT, filename_table[0].number); 3914: ASM_OUTPUT_LABEL (asm_out_file, label); 3915: ASM_OUTPUT_DWARF_STRING (asm_out_file, 3916: filename_table[0].name 3917: ? filename_table[0].name 3918: : ""); 3919: ASM_DWARF_POP_SECTION (asm_out_file); 3920: } 3921: 3922: /* Lookup a filename (in the list of filenames that we know about here in 3923: dwarfout.c) and return its "index". The index of each (known) filename 3924: is just a unique number which is associated with only that one filename. 3925: We need such numbers for the sake of generating labels (in the 3926: .debug_sfnames section) and references to those unique labels (in the 3927: .debug_srcinfo and .debug_macinfo sections). 3928: 3929: If the filename given as an argument is not found in our current list, 3930: add it to the list and assign it the next available unique index number. 3931: 3932: Whatever we do (i.e. whether we find a pre-existing filename or add a new 3933: one), we shuffle the filename found (or added) up to the zeroth entry of 3934: our list of filenames (which is always searched linearly). We do this so 3935: as to optimize the most common case for these filename lookups within 3936: dwarfout.c. The most common case by far is the case where we call 3937: lookup_filename to lookup the very same filename that we did a lookup 3938: on the last time we called lookup_filename. We make sure that this 3939: common case is fast because such cases will constitute 99.9% of the 3940: lookups we ever do (in practice). 3941: 3942: If we add a new filename entry to our table, we go ahead and generate 3943: the corresponding entry in the .debug_sfnames section right away. 3944: Doing so allows us to avoid tickling an assembler bug (present in some 3945: m68k assemblers) which yields assembly-time errors in cases where the 3946: difference of two label addresses is taken and where the two labels 3947: are in a section *other* than the one where the difference is being 3948: calculated, and where at least one of the two symbol references is a 3949: forward reference. (This bug could be tickled by our .debug_srcinfo 3950: entries if we don't output their corresponding .debug_sfnames entries 3951: before them.) 3952: */ 3953: 3954: static unsigned 3955: lookup_filename (file_name) 3956: char *file_name; 3957: { 3958: register filename_entry *search_p; 3959: register filename_entry *limit_p = &filename_table[ft_entries]; 3960: 3961: for (search_p = filename_table; search_p < limit_p; search_p++) 3962: if (!strcmp (file_name, search_p->name)) 3963: { 3964: /* When we get here, we have found the filename that we were 3965: looking for in the filename_table. Now we want to make sure 3966: that it gets moved to the zero'th entry in the table (if it 3967: is not already there) so that subsequent attempts to find the 3968: same filename will find it as quickly as possible. */ 3969: 3970: shuffle_filename_entry (search_p); 3971: return filename_table[0].number; 3972: } 3973: 3974: /* We come here whenever we have a new filename which is not registered 3975: in the current table. Here we add it to the table. */ 3976: 3977: /* Prepare to add a new table entry by making sure there is enough space 3978: in the table to do so. If not, expand the current table. */ 3979: 3980: if (ft_entries == ft_entries_allocated) 3981: { 3982: ft_entries_allocated += FT_ENTRIES_INCREMENT; 3983: filename_table 3984: = (filename_entry *) 3985: xrealloc (filename_table, 3986: ft_entries_allocated * sizeof (filename_entry)); 3987: } 3988: 3989: /* Initially, add the new entry at the end of the filename table. */ 3990: 3991: filename_table[ft_entries].number = ft_entries; 3992: filename_table[ft_entries].name = xstrdup (file_name); 3993: 3994: /* Shuffle the new entry into filename_table[0]. */ 3995: 3996: shuffle_filename_entry (&filename_table[ft_entries]); 3997: 3998: if (debug_info_level >= DINFO_LEVEL_NORMAL) 3999: generate_new_sfname_entry (); 4000: 4001: ft_entries++; 4002: return filename_table[0].number; 4003: } 4004: 4005: static void 4006: generate_srcinfo_entry (line_entry_num, files_entry_num) 4007: unsigned line_entry_num; 4008: unsigned files_entry_num; 4009: { 4010: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 4011: 4012: fputc ('\n', asm_out_file); 4013: ASM_DWARF_SRCINFO_SECTION (asm_out_file); 4014: sprintf (label, LINE_ENTRY_LABEL_FMT, line_entry_num); 4015: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, LINE_BEGIN_LABEL); 4016: sprintf (label, SFNAMES_ENTRY_LABEL_FMT, files_entry_num); 4017: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, SFNAMES_BEGIN_LABEL); 4018: ASM_DWARF_POP_SECTION (asm_out_file); 4019: } 4020: 4021: void 4022: dwarfout_line (filename, line) 4023: register char *filename; 4024: register unsigned line; 4025: { 4026: if (debug_info_level >= DINFO_LEVEL_NORMAL) 4027: { 4028: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 4029: static unsigned last_line_entry_num = 0; 4030: static unsigned prev_file_entry_num = (unsigned) -1; 4031: register unsigned this_file_entry_num = lookup_filename (filename); 4032: 4033: text_section (); 4034: sprintf (label, LINE_CODE_LABEL_FMT, ++last_line_entry_num); 4035: ASM_OUTPUT_LABEL (asm_out_file, label); 4036: 4037: fputc ('\n', asm_out_file); 4038: ASM_DWARF_LINE_SECTION (asm_out_file); 4039: 4040: if (this_file_entry_num != prev_file_entry_num) 4041: { 4042: char line_entry_label[MAX_ARTIFICIAL_LABEL_BYTES]; 4043: 4044: sprintf (line_entry_label, LINE_ENTRY_LABEL_FMT, last_line_entry_num); 4045: ASM_OUTPUT_LABEL (asm_out_file, line_entry_label); 4046: } 4047: 4048: { 4049: register char *tail = strrchr (filename, '/'); 4050: 4051: if (tail != NULL) 4052: filename = tail; 4053: } 4054: 1.1.1.2 ! root 4055: fprintf (asm_out_file, "\t%s\t%u\t%s %s:%u\n", 1.1 root 4056: UNALIGNED_INT_ASM_OP, line, ASM_COMMENT_START, 4057: filename, line); 4058: ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); 4059: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, label, TEXT_BEGIN_LABEL); 4060: ASM_DWARF_POP_SECTION (asm_out_file); 4061: 4062: if (this_file_entry_num != prev_file_entry_num) 4063: generate_srcinfo_entry (last_line_entry_num, this_file_entry_num); 4064: prev_file_entry_num = this_file_entry_num; 4065: } 4066: } 4067: 4068: /* Generate an entry in the .debug_macinfo section. */ 4069: 4070: static void 4071: generate_macinfo_entry (type_and_offset, string) 4072: register char *type_and_offset; 4073: register char *string; 4074: { 4075: fputc ('\n', asm_out_file); 4076: ASM_DWARF_MACINFO_SECTION (asm_out_file); 1.1.1.2 ! root 4077: fprintf (asm_out_file, "\t%s\t%s\n", UNALIGNED_INT_ASM_OP, type_and_offset); 1.1 root 4078: ASM_OUTPUT_DWARF_STRING (asm_out_file, string); 4079: ASM_DWARF_POP_SECTION (asm_out_file); 4080: } 4081: 4082: void 4083: dwarfout_start_new_source_file (filename) 4084: register char *filename; 4085: { 4086: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 4087: char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*3]; 4088: 4089: sprintf (label, SFNAMES_ENTRY_LABEL_FMT, lookup_filename (filename)); 4090: sprintf (type_and_offset, "0x%08x+%s-%s", 4091: ((unsigned) MACINFO_start << 24), label, SFNAMES_BEGIN_LABEL); 4092: generate_macinfo_entry (type_and_offset, ""); 4093: } 4094: 4095: void 4096: dwarfout_resume_previous_source_file (lineno) 4097: register unsigned lineno; 4098: { 4099: char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; 4100: 4101: sprintf (type_and_offset, "0x%08x+%u", 4102: ((unsigned) MACINFO_resume << 24), lineno); 4103: generate_macinfo_entry (type_and_offset, ""); 4104: } 4105: 4106: /* Called from check_newline in c-parse.y. The `buffer' parameter 4107: contains the tail part of the directive line, i.e. the part which 4108: is past the initial whitespace, #, whitespace, directive-name, 4109: whitespace part. */ 4110: 4111: void 4112: dwarfout_define (lineno, buffer) 4113: register unsigned lineno; 4114: register char *buffer; 4115: { 4116: static int initialized = 0; 4117: char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; 4118: 4119: if (!initialized) 4120: { 4121: dwarfout_start_new_source_file (primary_filename); 4122: initialized = 1; 4123: } 4124: sprintf (type_and_offset, "0x%08x+%u", 4125: ((unsigned) MACINFO_define << 24), lineno); 4126: generate_macinfo_entry (type_and_offset, buffer); 4127: } 4128: 4129: /* Called from check_newline in c-parse.y. The `buffer' parameter 4130: contains the tail part of the directive line, i.e. the part which 4131: is past the initial whitespace, #, whitespace, directive-name, 4132: whitespace part. */ 4133: 4134: void 4135: dwarfout_undef (lineno, buffer) 4136: register unsigned lineno; 4137: register char *buffer; 4138: { 4139: char type_and_offset[MAX_ARTIFICIAL_LABEL_BYTES*2]; 4140: 4141: sprintf (type_and_offset, "0x%08x+%u", 4142: ((unsigned) MACINFO_undef << 24), lineno); 4143: generate_macinfo_entry (type_and_offset, buffer); 4144: } 4145: 4146: /* Set up for Dwarf output at the start of compilation. */ 4147: 4148: void 4149: dwarfout_init (asm_out_file, main_input_filename) 4150: register FILE *asm_out_file; 4151: register char *main_input_filename; 4152: { 4153: /* Remember the name of the primary input file. */ 4154: 4155: primary_filename = main_input_filename; 4156: 4157: /* Allocate the initial hunk of the pending_sibling_stack. */ 4158: 4159: pending_sibling_stack 4160: = (unsigned *) 4161: xmalloc (PENDING_SIBLINGS_INCREMENT * sizeof (unsigned)); 4162: pending_siblings_allocated = PENDING_SIBLINGS_INCREMENT; 4163: pending_siblings = 1; 4164: 4165: /* Allocate the initial hunk of the filename_table. */ 4166: 4167: filename_table 4168: = (filename_entry *) 4169: xmalloc (FT_ENTRIES_INCREMENT * sizeof (filename_entry)); 4170: ft_entries_allocated = FT_ENTRIES_INCREMENT; 4171: ft_entries = 0; 4172: 4173: /* Allocate the initial hunk of the pending_types_list. */ 4174: 4175: pending_types_list 4176: = (tree *) xmalloc (PENDING_TYPES_INCREMENT * sizeof (tree)); 4177: pending_types_allocated = PENDING_TYPES_INCREMENT; 4178: pending_types = 0; 4179: 4180: /* Create an artificial RECORD_TYPE node which we can use in our hack 4181: to get the DIEs representing types of formal parameters to come out 4182: only *after* the DIEs for the formal parameters themselves. */ 4183: 4184: fake_containing_scope = make_node (RECORD_TYPE); 4185: 4186: /* Output a starting label for the .text section. */ 4187: 4188: fputc ('\n', asm_out_file); 4189: ASM_DWARF_TEXT_SECTION (asm_out_file); 4190: ASM_OUTPUT_LABEL (asm_out_file, TEXT_BEGIN_LABEL); 4191: ASM_DWARF_POP_SECTION (asm_out_file); 4192: 4193: /* Output a starting label for the .data section. */ 4194: 4195: fputc ('\n', asm_out_file); 4196: ASM_DWARF_DATA_SECTION (asm_out_file); 4197: ASM_OUTPUT_LABEL (asm_out_file, DATA_BEGIN_LABEL); 4198: ASM_DWARF_POP_SECTION (asm_out_file); 4199: 4200: /* Output a starting label for the .data1 section. */ 4201: 4202: fputc ('\n', asm_out_file); 4203: ASM_DWARF_DATA1_SECTION (asm_out_file); 4204: ASM_OUTPUT_LABEL (asm_out_file, DATA1_BEGIN_LABEL); 4205: ASM_DWARF_POP_SECTION (asm_out_file); 4206: 4207: /* Output a starting label for the .rodata section. */ 4208: 4209: fputc ('\n', asm_out_file); 4210: ASM_DWARF_RODATA_SECTION (asm_out_file); 4211: ASM_OUTPUT_LABEL (asm_out_file, RODATA_BEGIN_LABEL); 4212: ASM_DWARF_POP_SECTION (asm_out_file); 4213: 4214: /* Output a starting label for the .rodata1 section. */ 4215: 4216: fputc ('\n', asm_out_file); 4217: ASM_DWARF_RODATA1_SECTION (asm_out_file); 4218: ASM_OUTPUT_LABEL (asm_out_file, RODATA1_BEGIN_LABEL); 4219: ASM_DWARF_POP_SECTION (asm_out_file); 4220: 4221: /* Output a starting label for the .bss section. */ 4222: 4223: fputc ('\n', asm_out_file); 4224: ASM_DWARF_BSS_SECTION (asm_out_file); 4225: ASM_OUTPUT_LABEL (asm_out_file, BSS_BEGIN_LABEL); 4226: ASM_DWARF_POP_SECTION (asm_out_file); 4227: 4228: if (debug_info_level >= DINFO_LEVEL_NORMAL) 4229: { 4230: /* Output a starting label and an initial (compilation directory) 4231: entry for the .debug_sfnames section. The starting label will be 4232: referenced by the initial entry in the .debug_srcinfo section. */ 4233: 4234: fputc ('\n', asm_out_file); 4235: ASM_DWARF_SFNAMES_SECTION (asm_out_file); 4236: ASM_OUTPUT_LABEL (asm_out_file, SFNAMES_BEGIN_LABEL); 4237: { 1.1.1.2 ! root 4238: register char *pwd = getpwd (); ! 4239: register unsigned len = strlen (pwd); ! 4240: register char *dirname = (char *) xmalloc (len + 2); 1.1 root 4241: 1.1.1.2 ! root 4242: strcpy (dirname, pwd); ! 4243: strcpy (dirname + len, "/"); 1.1 root 4244: ASM_OUTPUT_DWARF_STRING (asm_out_file, dirname); 4245: free (dirname); 4246: } 4247: ASM_DWARF_POP_SECTION (asm_out_file); 4248: 4249: if (debug_info_level >= DINFO_LEVEL_VERBOSE) 4250: { 4251: /* Output a starting label for the .debug_macinfo section. This 4252: label will be referenced by the AT_mac_info attribute in the 4253: TAG_compile_unit DIE. */ 4254: 4255: fputc ('\n', asm_out_file); 4256: ASM_DWARF_MACINFO_SECTION (asm_out_file); 4257: ASM_OUTPUT_LABEL (asm_out_file, MACINFO_BEGIN_LABEL); 4258: ASM_DWARF_POP_SECTION (asm_out_file); 4259: } 4260: 4261: /* Generate the initial entry for the .line section. */ 4262: 4263: fputc ('\n', asm_out_file); 4264: ASM_DWARF_LINE_SECTION (asm_out_file); 4265: ASM_OUTPUT_LABEL (asm_out_file, LINE_BEGIN_LABEL); 4266: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, LINE_END_LABEL, LINE_BEGIN_LABEL); 4267: ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); 4268: ASM_DWARF_POP_SECTION (asm_out_file); 4269: 4270: /* Generate the initial entry for the .debug_srcinfo section. */ 4271: 4272: fputc ('\n', asm_out_file); 4273: ASM_DWARF_SRCINFO_SECTION (asm_out_file); 4274: ASM_OUTPUT_LABEL (asm_out_file, SRCINFO_BEGIN_LABEL); 4275: ASM_OUTPUT_DWARF_ADDR (asm_out_file, LINE_BEGIN_LABEL); 4276: ASM_OUTPUT_DWARF_ADDR (asm_out_file, SFNAMES_BEGIN_LABEL); 4277: ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); 4278: ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_END_LABEL); 4279: #ifdef DWARF_TIMESTAMPS 4280: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, time (NULL)); 4281: #else 4282: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); 4283: #endif 4284: ASM_DWARF_POP_SECTION (asm_out_file); 4285: 4286: /* Generate the initial entry for the .debug_pubnames section. */ 4287: 4288: fputc ('\n', asm_out_file); 4289: ASM_DWARF_PUBNAMES_SECTION (asm_out_file); 4290: ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); 4291: ASM_DWARF_POP_SECTION (asm_out_file); 4292: 4293: /* Generate the initial entry for the .debug_aranges section. */ 4294: 4295: fputc ('\n', asm_out_file); 4296: ASM_DWARF_ARANGES_SECTION (asm_out_file); 4297: ASM_OUTPUT_DWARF_ADDR (asm_out_file, DEBUG_BEGIN_LABEL); 4298: ASM_DWARF_POP_SECTION (asm_out_file); 4299: } 4300: 4301: /* Setup first DIE number == 1. */ 4302: NEXT_DIE_NUM = next_unused_dienum++; 4303: 4304: /* Generate the initial DIE for the .debug section. Note that the 4305: (string) value given in the AT_name attribute of the TAG_compile_unit 4306: DIE will (typically) be a relative pathname and that this pathname 4307: should be taken as being relative to the directory from which the 4308: compiler was invoked when the given (base) source file was compiled. */ 4309: 4310: fputc ('\n', asm_out_file); 4311: ASM_DWARF_DEBUG_SECTION (asm_out_file); 4312: ASM_OUTPUT_LABEL (asm_out_file, DEBUG_BEGIN_LABEL); 4313: output_die (output_compile_unit_die, main_input_filename); 4314: ASM_DWARF_POP_SECTION (asm_out_file); 4315: 4316: fputc ('\n', asm_out_file); 4317: } 4318: 4319: /* Output stuff that dwarf requires at the end of every file. */ 4320: 4321: void 4322: dwarfout_finish () 4323: { 4324: char label[MAX_ARTIFICIAL_LABEL_BYTES]; 4325: 4326: fputc ('\n', asm_out_file); 4327: ASM_DWARF_DEBUG_SECTION (asm_out_file); 4328: 4329: /* Mark the end of the chain of siblings which represent all file-scope 4330: declarations in this compilation unit. */ 4331: 4332: /* The (null) DIE which represents the terminator for the (sibling linked) 4333: list of file-scope items is *special*. Normally, we would just call 4334: end_sibling_chain at this point in order to output a word with the 4335: value `4' and that word would act as the terminator for the list of 4336: DIEs describing file-scope items. Unfortunately, if we were to simply 4337: do that, the label that would follow this DIE in the .debug section 4338: (i.e. `..D2') would *not* be properly aligned (as it must be on some 4339: machines) to a 4 byte boundary. 4340: 4341: In order to force the label `..D2' to get aligned to a 4 byte boundary, 4342: the trick used is to insert extra (otherwise useless) padding bytes 4343: into the (null) DIE that we know must preceed the ..D2 label in the 4344: .debug section. The amount of padding required can be anywhere between 4345: 0 and 3 bytes. The length word at the start of this DIE (i.e. the one 4346: with the padding) would normally contain the value 4, but now it will 4347: also have to include the padding bytes, so it will instead have some 4348: value in the range 4..7. 4349: 4350: Fortunately, the rules of Dwarf say that any DIE whose length word 4351: contains *any* value less than 8 should be treated as a null DIE, so 4352: this trick works out nicely. Clever, eh? Don't give me any credit 4353: (or blame). I didn't think of this scheme. I just conformed to it. 4354: */ 4355: 4356: output_die (output_padded_null_die, (void *)0); 4357: dienum_pop (); 4358: 4359: sprintf (label, DIE_BEGIN_LABEL_FMT, NEXT_DIE_NUM); 4360: ASM_OUTPUT_LABEL (asm_out_file, label); /* should be ..D2 */ 4361: ASM_DWARF_POP_SECTION (asm_out_file); 4362: 4363: /* Output a terminator label for the .text section. */ 4364: 4365: fputc ('\n', asm_out_file); 4366: ASM_DWARF_TEXT_SECTION (asm_out_file); 4367: ASM_OUTPUT_LABEL (asm_out_file, TEXT_END_LABEL); 4368: ASM_DWARF_POP_SECTION (asm_out_file); 4369: 4370: /* Output a terminator label for the .data section. */ 4371: 4372: fputc ('\n', asm_out_file); 4373: ASM_DWARF_DATA_SECTION (asm_out_file); 4374: ASM_OUTPUT_LABEL (asm_out_file, DATA_END_LABEL); 4375: ASM_DWARF_POP_SECTION (asm_out_file); 4376: 4377: /* Output a terminator label for the .data1 section. */ 4378: 4379: fputc ('\n', asm_out_file); 4380: ASM_DWARF_DATA1_SECTION (asm_out_file); 4381: ASM_OUTPUT_LABEL (asm_out_file, DATA1_END_LABEL); 4382: ASM_DWARF_POP_SECTION (asm_out_file); 4383: 4384: /* Output a terminator label for the .rodata section. */ 4385: 4386: fputc ('\n', asm_out_file); 4387: ASM_DWARF_RODATA_SECTION (asm_out_file); 4388: ASM_OUTPUT_LABEL (asm_out_file, RODATA_END_LABEL); 4389: ASM_DWARF_POP_SECTION (asm_out_file); 4390: 4391: /* Output a terminator label for the .rodata1 section. */ 4392: 4393: fputc ('\n', asm_out_file); 4394: ASM_DWARF_RODATA1_SECTION (asm_out_file); 4395: ASM_OUTPUT_LABEL (asm_out_file, RODATA1_END_LABEL); 4396: ASM_DWARF_POP_SECTION (asm_out_file); 4397: 4398: /* Output a terminator label for the .bss section. */ 4399: 4400: fputc ('\n', asm_out_file); 4401: ASM_DWARF_BSS_SECTION (asm_out_file); 4402: ASM_OUTPUT_LABEL (asm_out_file, BSS_END_LABEL); 4403: ASM_DWARF_POP_SECTION (asm_out_file); 4404: 4405: if (debug_info_level >= DINFO_LEVEL_NORMAL) 4406: { 4407: /* Output a terminating entry for the .line section. */ 4408: 4409: fputc ('\n', asm_out_file); 4410: ASM_DWARF_LINE_SECTION (asm_out_file); 4411: ASM_OUTPUT_LABEL (asm_out_file, LINE_LAST_ENTRY_LABEL); 4412: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); 4413: ASM_OUTPUT_DWARF_DATA2 (asm_out_file, 0xffff); 4414: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); 4415: ASM_OUTPUT_LABEL (asm_out_file, LINE_END_LABEL); 4416: ASM_DWARF_POP_SECTION (asm_out_file); 4417: 4418: /* Output a terminating entry for the .debug_srcinfo section. */ 4419: 4420: fputc ('\n', asm_out_file); 4421: ASM_DWARF_SRCINFO_SECTION (asm_out_file); 4422: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, 4423: LINE_LAST_ENTRY_LABEL, LINE_BEGIN_LABEL); 4424: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, -1); 4425: ASM_DWARF_POP_SECTION (asm_out_file); 4426: 4427: if (debug_info_level >= DINFO_LEVEL_VERBOSE) 4428: { 4429: /* Output terminating entries for the .debug_macinfo section. */ 4430: 4431: dwarfout_resume_previous_source_file (0); 4432: 4433: fputc ('\n', asm_out_file); 4434: ASM_DWARF_MACINFO_SECTION (asm_out_file); 4435: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); 4436: ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); 4437: ASM_DWARF_POP_SECTION (asm_out_file); 4438: } 4439: 4440: /* Generate the terminating entry for the .debug_pubnames section. */ 4441: 4442: fputc ('\n', asm_out_file); 4443: ASM_DWARF_PUBNAMES_SECTION (asm_out_file); 4444: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); 4445: ASM_OUTPUT_DWARF_STRING (asm_out_file, ""); 4446: ASM_DWARF_POP_SECTION (asm_out_file); 4447: 4448: /* Generate the terminating entries for the .debug_aranges section. 4449: 4450: Note that we want to do this only *after* we have output the end 4451: labels (for the various program sections) which we are going to 4452: refer to here. This allows us to work around a bug in the m68k 4453: svr4 assembler. That assembler gives bogus assembly-time errors 4454: if (within any given section) you try to take the difference of 4455: two relocatable symbols, both of which are located within some 4456: other section, and if one (or both?) of the symbols involved is 4457: being forward-referenced. By generating the .debug_aranges 4458: entries at this late point in the assembly output, we skirt the 4459: issue simply by avoiding forward-references. 4460: */ 4461: 4462: fputc ('\n', asm_out_file); 4463: ASM_DWARF_ARANGES_SECTION (asm_out_file); 4464: 4465: ASM_OUTPUT_DWARF_ADDR (asm_out_file, TEXT_BEGIN_LABEL); 4466: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, TEXT_END_LABEL, TEXT_BEGIN_LABEL); 4467: 4468: ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA_BEGIN_LABEL); 4469: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA_END_LABEL, DATA_BEGIN_LABEL); 4470: 4471: ASM_OUTPUT_DWARF_ADDR (asm_out_file, DATA1_BEGIN_LABEL); 4472: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, DATA1_END_LABEL, 4473: DATA1_BEGIN_LABEL); 4474: 4475: ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA_BEGIN_LABEL); 4476: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA_END_LABEL, 4477: RODATA_BEGIN_LABEL); 4478: 4479: ASM_OUTPUT_DWARF_ADDR (asm_out_file, RODATA1_BEGIN_LABEL); 4480: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, RODATA1_END_LABEL, 4481: RODATA1_BEGIN_LABEL); 4482: 4483: ASM_OUTPUT_DWARF_ADDR (asm_out_file, BSS_BEGIN_LABEL); 4484: ASM_OUTPUT_DWARF_DELTA4 (asm_out_file, BSS_END_LABEL, BSS_BEGIN_LABEL); 4485: 4486: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); 4487: ASM_OUTPUT_DWARF_DATA4 (asm_out_file, 0); 4488: 4489: ASM_DWARF_POP_SECTION (asm_out_file); 4490: } 4491: } 4492: 4493: #endif /* DWARF_DEBUGGING_INFO */
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.