| 1 | /* DWARF 2 debugging format support for GDB. |
| 2 | |
| 3 | Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, |
| 4 | 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011 |
| 5 | Free Software Foundation, Inc. |
| 6 | |
| 7 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, |
| 8 | Inc. with support from Florida State University (under contract |
| 9 | with the Ada Joint Program Office), and Silicon Graphics, Inc. |
| 10 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., |
| 11 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 |
| 12 | support. |
| 13 | |
| 14 | This file is part of GDB. |
| 15 | |
| 16 | This program is free software; you can redistribute it and/or modify |
| 17 | it under the terms of the GNU General Public License as published by |
| 18 | the Free Software Foundation; either version 3 of the License, or |
| 19 | (at your option) any later version. |
| 20 | |
| 21 | This program is distributed in the hope that it will be useful, |
| 22 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 23 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 24 | GNU General Public License for more details. |
| 25 | |
| 26 | You should have received a copy of the GNU General Public License |
| 27 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 28 | |
| 29 | #include "defs.h" |
| 30 | #include "bfd.h" |
| 31 | #include "symtab.h" |
| 32 | #include "gdbtypes.h" |
| 33 | #include "objfiles.h" |
| 34 | #include "dwarf2.h" |
| 35 | #include "buildsym.h" |
| 36 | #include "demangle.h" |
| 37 | #include "expression.h" |
| 38 | #include "filenames.h" /* for DOSish file names */ |
| 39 | #include "macrotab.h" |
| 40 | #include "language.h" |
| 41 | #include "complaints.h" |
| 42 | #include "bcache.h" |
| 43 | #include "dwarf2expr.h" |
| 44 | #include "dwarf2loc.h" |
| 45 | #include "cp-support.h" |
| 46 | #include "hashtab.h" |
| 47 | #include "command.h" |
| 48 | #include "gdbcmd.h" |
| 49 | #include "block.h" |
| 50 | #include "addrmap.h" |
| 51 | #include "typeprint.h" |
| 52 | #include "jv-lang.h" |
| 53 | #include "psympriv.h" |
| 54 | #include "exceptions.h" |
| 55 | #include "gdb_stat.h" |
| 56 | #include "completer.h" |
| 57 | #include "vec.h" |
| 58 | #include "c-lang.h" |
| 59 | #include "valprint.h" |
| 60 | |
| 61 | #include <fcntl.h> |
| 62 | #include "gdb_string.h" |
| 63 | #include "gdb_assert.h" |
| 64 | #include <sys/types.h> |
| 65 | #ifdef HAVE_ZLIB_H |
| 66 | #include <zlib.h> |
| 67 | #endif |
| 68 | #ifdef HAVE_MMAP |
| 69 | #include <sys/mman.h> |
| 70 | #ifndef MAP_FAILED |
| 71 | #define MAP_FAILED ((void *) -1) |
| 72 | #endif |
| 73 | #endif |
| 74 | |
| 75 | typedef struct symbol *symbolp; |
| 76 | DEF_VEC_P (symbolp); |
| 77 | |
| 78 | #if 0 |
| 79 | /* .debug_info header for a compilation unit |
| 80 | Because of alignment constraints, this structure has padding and cannot |
| 81 | be mapped directly onto the beginning of the .debug_info section. */ |
| 82 | typedef struct comp_unit_header |
| 83 | { |
| 84 | unsigned int length; /* length of the .debug_info |
| 85 | contribution */ |
| 86 | unsigned short version; /* version number -- 2 for DWARF |
| 87 | version 2 */ |
| 88 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ |
| 89 | unsigned char addr_size; /* byte size of an address -- 4 */ |
| 90 | } |
| 91 | _COMP_UNIT_HEADER; |
| 92 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 |
| 93 | #endif |
| 94 | |
| 95 | /* .debug_line statement program prologue |
| 96 | Because of alignment constraints, this structure has padding and cannot |
| 97 | be mapped directly onto the beginning of the .debug_info section. */ |
| 98 | typedef struct statement_prologue |
| 99 | { |
| 100 | unsigned int total_length; /* byte length of the statement |
| 101 | information */ |
| 102 | unsigned short version; /* version number -- 2 for DWARF |
| 103 | version 2 */ |
| 104 | unsigned int prologue_length; /* # bytes between prologue & |
| 105 | stmt program */ |
| 106 | unsigned char minimum_instruction_length; /* byte size of |
| 107 | smallest instr */ |
| 108 | unsigned char default_is_stmt; /* initial value of is_stmt |
| 109 | register */ |
| 110 | char line_base; |
| 111 | unsigned char line_range; |
| 112 | unsigned char opcode_base; /* number assigned to first special |
| 113 | opcode */ |
| 114 | unsigned char *standard_opcode_lengths; |
| 115 | } |
| 116 | _STATEMENT_PROLOGUE; |
| 117 | |
| 118 | /* When non-zero, dump DIEs after they are read in. */ |
| 119 | static int dwarf2_die_debug = 0; |
| 120 | |
| 121 | static int pagesize; |
| 122 | |
| 123 | /* When set, the file that we're processing is known to have debugging |
| 124 | info for C++ namespaces. GCC 3.3.x did not produce this information, |
| 125 | but later versions do. */ |
| 126 | |
| 127 | static int processing_has_namespace_info; |
| 128 | |
| 129 | static const struct objfile_data *dwarf2_objfile_data_key; |
| 130 | |
| 131 | struct dwarf2_section_info |
| 132 | { |
| 133 | asection *asection; |
| 134 | gdb_byte *buffer; |
| 135 | bfd_size_type size; |
| 136 | int was_mmapped; |
| 137 | /* True if we have tried to read this section. */ |
| 138 | int readin; |
| 139 | }; |
| 140 | |
| 141 | /* All offsets in the index are of this type. It must be |
| 142 | architecture-independent. */ |
| 143 | typedef uint32_t offset_type; |
| 144 | |
| 145 | DEF_VEC_I (offset_type); |
| 146 | |
| 147 | /* A description of the mapped index. The file format is described in |
| 148 | a comment by the code that writes the index. */ |
| 149 | struct mapped_index |
| 150 | { |
| 151 | /* The total length of the buffer. */ |
| 152 | off_t total_size; |
| 153 | /* A pointer to the address table data. */ |
| 154 | const gdb_byte *address_table; |
| 155 | /* Size of the address table data in bytes. */ |
| 156 | offset_type address_table_size; |
| 157 | /* The symbol table, implemented as a hash table. */ |
| 158 | const offset_type *symbol_table; |
| 159 | /* Size in slots, each slot is 2 offset_types. */ |
| 160 | offset_type symbol_table_slots; |
| 161 | /* A pointer to the constant pool. */ |
| 162 | const char *constant_pool; |
| 163 | }; |
| 164 | |
| 165 | struct dwarf2_per_objfile |
| 166 | { |
| 167 | struct dwarf2_section_info info; |
| 168 | struct dwarf2_section_info abbrev; |
| 169 | struct dwarf2_section_info line; |
| 170 | struct dwarf2_section_info loc; |
| 171 | struct dwarf2_section_info macinfo; |
| 172 | struct dwarf2_section_info str; |
| 173 | struct dwarf2_section_info ranges; |
| 174 | struct dwarf2_section_info types; |
| 175 | struct dwarf2_section_info frame; |
| 176 | struct dwarf2_section_info eh_frame; |
| 177 | struct dwarf2_section_info gdb_index; |
| 178 | |
| 179 | /* Back link. */ |
| 180 | struct objfile *objfile; |
| 181 | |
| 182 | /* A list of all the compilation units. This is used to locate |
| 183 | the target compilation unit of a particular reference. */ |
| 184 | struct dwarf2_per_cu_data **all_comp_units; |
| 185 | |
| 186 | /* The number of compilation units in ALL_COMP_UNITS. */ |
| 187 | int n_comp_units; |
| 188 | |
| 189 | /* The number of .debug_types-related CUs. */ |
| 190 | int n_type_comp_units; |
| 191 | |
| 192 | /* The .debug_types-related CUs. */ |
| 193 | struct dwarf2_per_cu_data **type_comp_units; |
| 194 | |
| 195 | /* A chain of compilation units that are currently read in, so that |
| 196 | they can be freed later. */ |
| 197 | struct dwarf2_per_cu_data *read_in_chain; |
| 198 | |
| 199 | /* A table mapping .debug_types signatures to its signatured_type entry. |
| 200 | This is NULL if the .debug_types section hasn't been read in yet. */ |
| 201 | htab_t signatured_types; |
| 202 | |
| 203 | /* A flag indicating wether this objfile has a section loaded at a |
| 204 | VMA of 0. */ |
| 205 | int has_section_at_zero; |
| 206 | |
| 207 | /* True if we are using the mapped index, |
| 208 | or we are faking it for OBJF_READNOW's sake. */ |
| 209 | unsigned char using_index; |
| 210 | |
| 211 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
| 212 | struct mapped_index *index_table; |
| 213 | |
| 214 | /* When using index_table, this keeps track of all quick_file_names entries. |
| 215 | TUs can share line table entries with CUs or other TUs, and there can be |
| 216 | a lot more TUs than unique line tables, so we maintain a separate table |
| 217 | of all line table entries to support the sharing. */ |
| 218 | htab_t quick_file_names_table; |
| 219 | |
| 220 | /* Set during partial symbol reading, to prevent queueing of full |
| 221 | symbols. */ |
| 222 | int reading_partial_symbols; |
| 223 | |
| 224 | /* Table mapping type .debug_info DIE offsets to types. |
| 225 | This is NULL if not allocated yet. |
| 226 | It (currently) makes sense to allocate debug_types_type_hash lazily. |
| 227 | To keep things simple we allocate both lazily. */ |
| 228 | htab_t debug_info_type_hash; |
| 229 | |
| 230 | /* Table mapping type .debug_types DIE offsets to types. |
| 231 | This is NULL if not allocated yet. */ |
| 232 | htab_t debug_types_type_hash; |
| 233 | }; |
| 234 | |
| 235 | static struct dwarf2_per_objfile *dwarf2_per_objfile; |
| 236 | |
| 237 | /* names of the debugging sections */ |
| 238 | |
| 239 | /* Note that if the debugging section has been compressed, it might |
| 240 | have a name like .zdebug_info. */ |
| 241 | |
| 242 | #define INFO_SECTION "debug_info" |
| 243 | #define ABBREV_SECTION "debug_abbrev" |
| 244 | #define LINE_SECTION "debug_line" |
| 245 | #define LOC_SECTION "debug_loc" |
| 246 | #define MACINFO_SECTION "debug_macinfo" |
| 247 | #define STR_SECTION "debug_str" |
| 248 | #define RANGES_SECTION "debug_ranges" |
| 249 | #define TYPES_SECTION "debug_types" |
| 250 | #define FRAME_SECTION "debug_frame" |
| 251 | #define EH_FRAME_SECTION "eh_frame" |
| 252 | #define GDB_INDEX_SECTION "gdb_index" |
| 253 | |
| 254 | /* local data types */ |
| 255 | |
| 256 | /* We hold several abbreviation tables in memory at the same time. */ |
| 257 | #ifndef ABBREV_HASH_SIZE |
| 258 | #define ABBREV_HASH_SIZE 121 |
| 259 | #endif |
| 260 | |
| 261 | /* The data in a compilation unit header, after target2host |
| 262 | translation, looks like this. */ |
| 263 | struct comp_unit_head |
| 264 | { |
| 265 | unsigned int length; |
| 266 | short version; |
| 267 | unsigned char addr_size; |
| 268 | unsigned char signed_addr_p; |
| 269 | unsigned int abbrev_offset; |
| 270 | |
| 271 | /* Size of file offsets; either 4 or 8. */ |
| 272 | unsigned int offset_size; |
| 273 | |
| 274 | /* Size of the length field; either 4 or 12. */ |
| 275 | unsigned int initial_length_size; |
| 276 | |
| 277 | /* Offset to the first byte of this compilation unit header in the |
| 278 | .debug_info section, for resolving relative reference dies. */ |
| 279 | unsigned int offset; |
| 280 | |
| 281 | /* Offset to first die in this cu from the start of the cu. |
| 282 | This will be the first byte following the compilation unit header. */ |
| 283 | unsigned int first_die_offset; |
| 284 | }; |
| 285 | |
| 286 | /* Type used for delaying computation of method physnames. |
| 287 | See comments for compute_delayed_physnames. */ |
| 288 | struct delayed_method_info |
| 289 | { |
| 290 | /* The type to which the method is attached, i.e., its parent class. */ |
| 291 | struct type *type; |
| 292 | |
| 293 | /* The index of the method in the type's function fieldlists. */ |
| 294 | int fnfield_index; |
| 295 | |
| 296 | /* The index of the method in the fieldlist. */ |
| 297 | int index; |
| 298 | |
| 299 | /* The name of the DIE. */ |
| 300 | const char *name; |
| 301 | |
| 302 | /* The DIE associated with this method. */ |
| 303 | struct die_info *die; |
| 304 | }; |
| 305 | |
| 306 | typedef struct delayed_method_info delayed_method_info; |
| 307 | DEF_VEC_O (delayed_method_info); |
| 308 | |
| 309 | /* Internal state when decoding a particular compilation unit. */ |
| 310 | struct dwarf2_cu |
| 311 | { |
| 312 | /* The objfile containing this compilation unit. */ |
| 313 | struct objfile *objfile; |
| 314 | |
| 315 | /* The header of the compilation unit. */ |
| 316 | struct comp_unit_head header; |
| 317 | |
| 318 | /* Base address of this compilation unit. */ |
| 319 | CORE_ADDR base_address; |
| 320 | |
| 321 | /* Non-zero if base_address has been set. */ |
| 322 | int base_known; |
| 323 | |
| 324 | struct function_range *first_fn, *last_fn, *cached_fn; |
| 325 | |
| 326 | /* The language we are debugging. */ |
| 327 | enum language language; |
| 328 | const struct language_defn *language_defn; |
| 329 | |
| 330 | const char *producer; |
| 331 | |
| 332 | /* The generic symbol table building routines have separate lists for |
| 333 | file scope symbols and all all other scopes (local scopes). So |
| 334 | we need to select the right one to pass to add_symbol_to_list(). |
| 335 | We do it by keeping a pointer to the correct list in list_in_scope. |
| 336 | |
| 337 | FIXME: The original dwarf code just treated the file scope as the |
| 338 | first local scope, and all other local scopes as nested local |
| 339 | scopes, and worked fine. Check to see if we really need to |
| 340 | distinguish these in buildsym.c. */ |
| 341 | struct pending **list_in_scope; |
| 342 | |
| 343 | /* DWARF abbreviation table associated with this compilation unit. */ |
| 344 | struct abbrev_info **dwarf2_abbrevs; |
| 345 | |
| 346 | /* Storage for the abbrev table. */ |
| 347 | struct obstack abbrev_obstack; |
| 348 | |
| 349 | /* Hash table holding all the loaded partial DIEs. */ |
| 350 | htab_t partial_dies; |
| 351 | |
| 352 | /* Storage for things with the same lifetime as this read-in compilation |
| 353 | unit, including partial DIEs. */ |
| 354 | struct obstack comp_unit_obstack; |
| 355 | |
| 356 | /* When multiple dwarf2_cu structures are living in memory, this field |
| 357 | chains them all together, so that they can be released efficiently. |
| 358 | We will probably also want a generation counter so that most-recently-used |
| 359 | compilation units are cached... */ |
| 360 | struct dwarf2_per_cu_data *read_in_chain; |
| 361 | |
| 362 | /* Backchain to our per_cu entry if the tree has been built. */ |
| 363 | struct dwarf2_per_cu_data *per_cu; |
| 364 | |
| 365 | /* How many compilation units ago was this CU last referenced? */ |
| 366 | int last_used; |
| 367 | |
| 368 | /* A hash table of die offsets for following references. */ |
| 369 | htab_t die_hash; |
| 370 | |
| 371 | /* Full DIEs if read in. */ |
| 372 | struct die_info *dies; |
| 373 | |
| 374 | /* A set of pointers to dwarf2_per_cu_data objects for compilation |
| 375 | units referenced by this one. Only set during full symbol processing; |
| 376 | partial symbol tables do not have dependencies. */ |
| 377 | htab_t dependencies; |
| 378 | |
| 379 | /* Header data from the line table, during full symbol processing. */ |
| 380 | struct line_header *line_header; |
| 381 | |
| 382 | /* A list of methods which need to have physnames computed |
| 383 | after all type information has been read. */ |
| 384 | VEC (delayed_method_info) *method_list; |
| 385 | |
| 386 | /* Mark used when releasing cached dies. */ |
| 387 | unsigned int mark : 1; |
| 388 | |
| 389 | /* This flag will be set if this compilation unit might include |
| 390 | inter-compilation-unit references. */ |
| 391 | unsigned int has_form_ref_addr : 1; |
| 392 | |
| 393 | /* This flag will be set if this compilation unit includes any |
| 394 | DW_TAG_namespace DIEs. If we know that there are explicit |
| 395 | DIEs for namespaces, we don't need to try to infer them |
| 396 | from mangled names. */ |
| 397 | unsigned int has_namespace_info : 1; |
| 398 | }; |
| 399 | |
| 400 | /* Persistent data held for a compilation unit, even when not |
| 401 | processing it. We put a pointer to this structure in the |
| 402 | read_symtab_private field of the psymtab. If we encounter |
| 403 | inter-compilation-unit references, we also maintain a sorted |
| 404 | list of all compilation units. */ |
| 405 | |
| 406 | struct dwarf2_per_cu_data |
| 407 | { |
| 408 | /* The start offset and length of this compilation unit. 2**29-1 |
| 409 | bytes should suffice to store the length of any compilation unit |
| 410 | - if it doesn't, GDB will fall over anyway. |
| 411 | NOTE: Unlike comp_unit_head.length, this length includes |
| 412 | initial_length_size. */ |
| 413 | unsigned int offset; |
| 414 | unsigned int length : 29; |
| 415 | |
| 416 | /* Flag indicating this compilation unit will be read in before |
| 417 | any of the current compilation units are processed. */ |
| 418 | unsigned int queued : 1; |
| 419 | |
| 420 | /* This flag will be set if we need to load absolutely all DIEs |
| 421 | for this compilation unit, instead of just the ones we think |
| 422 | are interesting. It gets set if we look for a DIE in the |
| 423 | hash table and don't find it. */ |
| 424 | unsigned int load_all_dies : 1; |
| 425 | |
| 426 | /* Non-zero if this CU is from .debug_types. |
| 427 | Otherwise it's from .debug_info. */ |
| 428 | unsigned int from_debug_types : 1; |
| 429 | |
| 430 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
| 431 | of the CU cache it gets reset to NULL again. */ |
| 432 | struct dwarf2_cu *cu; |
| 433 | |
| 434 | /* The corresponding objfile. */ |
| 435 | struct objfile *objfile; |
| 436 | |
| 437 | /* When using partial symbol tables, the 'psymtab' field is active. |
| 438 | Otherwise the 'quick' field is active. */ |
| 439 | union |
| 440 | { |
| 441 | /* The partial symbol table associated with this compilation unit, |
| 442 | or NULL for partial units (which do not have an associated |
| 443 | symtab). */ |
| 444 | struct partial_symtab *psymtab; |
| 445 | |
| 446 | /* Data needed by the "quick" functions. */ |
| 447 | struct dwarf2_per_cu_quick_data *quick; |
| 448 | } v; |
| 449 | }; |
| 450 | |
| 451 | /* Entry in the signatured_types hash table. */ |
| 452 | |
| 453 | struct signatured_type |
| 454 | { |
| 455 | ULONGEST signature; |
| 456 | |
| 457 | /* Offset in .debug_types of the TU (type_unit) for this type. */ |
| 458 | unsigned int offset; |
| 459 | |
| 460 | /* Offset in .debug_types of the type defined by this TU. */ |
| 461 | unsigned int type_offset; |
| 462 | |
| 463 | /* The CU(/TU) of this type. */ |
| 464 | struct dwarf2_per_cu_data per_cu; |
| 465 | }; |
| 466 | |
| 467 | /* Struct used to pass misc. parameters to read_die_and_children, et |
| 468 | al. which are used for both .debug_info and .debug_types dies. |
| 469 | All parameters here are unchanging for the life of the call. This |
| 470 | struct exists to abstract away the constant parameters of die |
| 471 | reading. */ |
| 472 | |
| 473 | struct die_reader_specs |
| 474 | { |
| 475 | /* The bfd of this objfile. */ |
| 476 | bfd* abfd; |
| 477 | |
| 478 | /* The CU of the DIE we are parsing. */ |
| 479 | struct dwarf2_cu *cu; |
| 480 | |
| 481 | /* Pointer to start of section buffer. |
| 482 | This is either the start of .debug_info or .debug_types. */ |
| 483 | const gdb_byte *buffer; |
| 484 | }; |
| 485 | |
| 486 | /* The line number information for a compilation unit (found in the |
| 487 | .debug_line section) begins with a "statement program header", |
| 488 | which contains the following information. */ |
| 489 | struct line_header |
| 490 | { |
| 491 | unsigned int total_length; |
| 492 | unsigned short version; |
| 493 | unsigned int header_length; |
| 494 | unsigned char minimum_instruction_length; |
| 495 | unsigned char maximum_ops_per_instruction; |
| 496 | unsigned char default_is_stmt; |
| 497 | int line_base; |
| 498 | unsigned char line_range; |
| 499 | unsigned char opcode_base; |
| 500 | |
| 501 | /* standard_opcode_lengths[i] is the number of operands for the |
| 502 | standard opcode whose value is i. This means that |
| 503 | standard_opcode_lengths[0] is unused, and the last meaningful |
| 504 | element is standard_opcode_lengths[opcode_base - 1]. */ |
| 505 | unsigned char *standard_opcode_lengths; |
| 506 | |
| 507 | /* The include_directories table. NOTE! These strings are not |
| 508 | allocated with xmalloc; instead, they are pointers into |
| 509 | debug_line_buffer. If you try to free them, `free' will get |
| 510 | indigestion. */ |
| 511 | unsigned int num_include_dirs, include_dirs_size; |
| 512 | char **include_dirs; |
| 513 | |
| 514 | /* The file_names table. NOTE! These strings are not allocated |
| 515 | with xmalloc; instead, they are pointers into debug_line_buffer. |
| 516 | Don't try to free them directly. */ |
| 517 | unsigned int num_file_names, file_names_size; |
| 518 | struct file_entry |
| 519 | { |
| 520 | char *name; |
| 521 | unsigned int dir_index; |
| 522 | unsigned int mod_time; |
| 523 | unsigned int length; |
| 524 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
| 525 | struct symtab *symtab; /* The associated symbol table, if any. */ |
| 526 | } *file_names; |
| 527 | |
| 528 | /* The start and end of the statement program following this |
| 529 | header. These point into dwarf2_per_objfile->line_buffer. */ |
| 530 | gdb_byte *statement_program_start, *statement_program_end; |
| 531 | }; |
| 532 | |
| 533 | /* When we construct a partial symbol table entry we only |
| 534 | need this much information. */ |
| 535 | struct partial_die_info |
| 536 | { |
| 537 | /* Offset of this DIE. */ |
| 538 | unsigned int offset; |
| 539 | |
| 540 | /* DWARF-2 tag for this DIE. */ |
| 541 | ENUM_BITFIELD(dwarf_tag) tag : 16; |
| 542 | |
| 543 | /* Assorted flags describing the data found in this DIE. */ |
| 544 | unsigned int has_children : 1; |
| 545 | unsigned int is_external : 1; |
| 546 | unsigned int is_declaration : 1; |
| 547 | unsigned int has_type : 1; |
| 548 | unsigned int has_specification : 1; |
| 549 | unsigned int has_pc_info : 1; |
| 550 | |
| 551 | /* Flag set if the SCOPE field of this structure has been |
| 552 | computed. */ |
| 553 | unsigned int scope_set : 1; |
| 554 | |
| 555 | /* Flag set if the DIE has a byte_size attribute. */ |
| 556 | unsigned int has_byte_size : 1; |
| 557 | |
| 558 | /* Flag set if any of the DIE's children are template arguments. */ |
| 559 | unsigned int has_template_arguments : 1; |
| 560 | |
| 561 | /* Flag set if fixup_partial_die has been called on this die. */ |
| 562 | unsigned int fixup_called : 1; |
| 563 | |
| 564 | /* The name of this DIE. Normally the value of DW_AT_name, but |
| 565 | sometimes a default name for unnamed DIEs. */ |
| 566 | char *name; |
| 567 | |
| 568 | /* The linkage name, if present. */ |
| 569 | const char *linkage_name; |
| 570 | |
| 571 | /* The scope to prepend to our children. This is generally |
| 572 | allocated on the comp_unit_obstack, so will disappear |
| 573 | when this compilation unit leaves the cache. */ |
| 574 | char *scope; |
| 575 | |
| 576 | /* The location description associated with this DIE, if any. */ |
| 577 | struct dwarf_block *locdesc; |
| 578 | |
| 579 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ |
| 580 | CORE_ADDR lowpc; |
| 581 | CORE_ADDR highpc; |
| 582 | |
| 583 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
| 584 | DW_AT_sibling, if any. */ |
| 585 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
| 586 | return DW_AT_sibling values to its caller load_partial_dies. */ |
| 587 | gdb_byte *sibling; |
| 588 | |
| 589 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by |
| 590 | DW_AT_specification (or DW_AT_abstract_origin or |
| 591 | DW_AT_extension). */ |
| 592 | unsigned int spec_offset; |
| 593 | |
| 594 | /* Pointers to this DIE's parent, first child, and next sibling, |
| 595 | if any. */ |
| 596 | struct partial_die_info *die_parent, *die_child, *die_sibling; |
| 597 | }; |
| 598 | |
| 599 | /* This data structure holds the information of an abbrev. */ |
| 600 | struct abbrev_info |
| 601 | { |
| 602 | unsigned int number; /* number identifying abbrev */ |
| 603 | enum dwarf_tag tag; /* dwarf tag */ |
| 604 | unsigned short has_children; /* boolean */ |
| 605 | unsigned short num_attrs; /* number of attributes */ |
| 606 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
| 607 | struct abbrev_info *next; /* next in chain */ |
| 608 | }; |
| 609 | |
| 610 | struct attr_abbrev |
| 611 | { |
| 612 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 613 | ENUM_BITFIELD(dwarf_form) form : 16; |
| 614 | }; |
| 615 | |
| 616 | /* Attributes have a name and a value. */ |
| 617 | struct attribute |
| 618 | { |
| 619 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 620 | ENUM_BITFIELD(dwarf_form) form : 15; |
| 621 | |
| 622 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This |
| 623 | field should be in u.str (existing only for DW_STRING) but it is kept |
| 624 | here for better struct attribute alignment. */ |
| 625 | unsigned int string_is_canonical : 1; |
| 626 | |
| 627 | union |
| 628 | { |
| 629 | char *str; |
| 630 | struct dwarf_block *blk; |
| 631 | ULONGEST unsnd; |
| 632 | LONGEST snd; |
| 633 | CORE_ADDR addr; |
| 634 | struct signatured_type *signatured_type; |
| 635 | } |
| 636 | u; |
| 637 | }; |
| 638 | |
| 639 | /* This data structure holds a complete die structure. */ |
| 640 | struct die_info |
| 641 | { |
| 642 | /* DWARF-2 tag for this DIE. */ |
| 643 | ENUM_BITFIELD(dwarf_tag) tag : 16; |
| 644 | |
| 645 | /* Number of attributes */ |
| 646 | unsigned char num_attrs; |
| 647 | |
| 648 | /* True if we're presently building the full type name for the |
| 649 | type derived from this DIE. */ |
| 650 | unsigned char building_fullname : 1; |
| 651 | |
| 652 | /* Abbrev number */ |
| 653 | unsigned int abbrev; |
| 654 | |
| 655 | /* Offset in .debug_info or .debug_types section. */ |
| 656 | unsigned int offset; |
| 657 | |
| 658 | /* The dies in a compilation unit form an n-ary tree. PARENT |
| 659 | points to this die's parent; CHILD points to the first child of |
| 660 | this node; and all the children of a given node are chained |
| 661 | together via their SIBLING fields. */ |
| 662 | struct die_info *child; /* Its first child, if any. */ |
| 663 | struct die_info *sibling; /* Its next sibling, if any. */ |
| 664 | struct die_info *parent; /* Its parent, if any. */ |
| 665 | |
| 666 | /* An array of attributes, with NUM_ATTRS elements. There may be |
| 667 | zero, but it's not common and zero-sized arrays are not |
| 668 | sufficiently portable C. */ |
| 669 | struct attribute attrs[1]; |
| 670 | }; |
| 671 | |
| 672 | struct function_range |
| 673 | { |
| 674 | const char *name; |
| 675 | CORE_ADDR lowpc, highpc; |
| 676 | int seen_line; |
| 677 | struct function_range *next; |
| 678 | }; |
| 679 | |
| 680 | /* Get at parts of an attribute structure. */ |
| 681 | |
| 682 | #define DW_STRING(attr) ((attr)->u.str) |
| 683 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
| 684 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
| 685 | #define DW_BLOCK(attr) ((attr)->u.blk) |
| 686 | #define DW_SND(attr) ((attr)->u.snd) |
| 687 | #define DW_ADDR(attr) ((attr)->u.addr) |
| 688 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
| 689 | |
| 690 | /* Blocks are a bunch of untyped bytes. */ |
| 691 | struct dwarf_block |
| 692 | { |
| 693 | unsigned int size; |
| 694 | gdb_byte *data; |
| 695 | }; |
| 696 | |
| 697 | #ifndef ATTR_ALLOC_CHUNK |
| 698 | #define ATTR_ALLOC_CHUNK 4 |
| 699 | #endif |
| 700 | |
| 701 | /* Allocate fields for structs, unions and enums in this size. */ |
| 702 | #ifndef DW_FIELD_ALLOC_CHUNK |
| 703 | #define DW_FIELD_ALLOC_CHUNK 4 |
| 704 | #endif |
| 705 | |
| 706 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
| 707 | but this would require a corresponding change in unpack_field_as_long |
| 708 | and friends. */ |
| 709 | static int bits_per_byte = 8; |
| 710 | |
| 711 | /* The routines that read and process dies for a C struct or C++ class |
| 712 | pass lists of data member fields and lists of member function fields |
| 713 | in an instance of a field_info structure, as defined below. */ |
| 714 | struct field_info |
| 715 | { |
| 716 | /* List of data member and baseclasses fields. */ |
| 717 | struct nextfield |
| 718 | { |
| 719 | struct nextfield *next; |
| 720 | int accessibility; |
| 721 | int virtuality; |
| 722 | struct field field; |
| 723 | } |
| 724 | *fields, *baseclasses; |
| 725 | |
| 726 | /* Number of fields (including baseclasses). */ |
| 727 | int nfields; |
| 728 | |
| 729 | /* Number of baseclasses. */ |
| 730 | int nbaseclasses; |
| 731 | |
| 732 | /* Set if the accesibility of one of the fields is not public. */ |
| 733 | int non_public_fields; |
| 734 | |
| 735 | /* Member function fields array, entries are allocated in the order they |
| 736 | are encountered in the object file. */ |
| 737 | struct nextfnfield |
| 738 | { |
| 739 | struct nextfnfield *next; |
| 740 | struct fn_field fnfield; |
| 741 | } |
| 742 | *fnfields; |
| 743 | |
| 744 | /* Member function fieldlist array, contains name of possibly overloaded |
| 745 | member function, number of overloaded member functions and a pointer |
| 746 | to the head of the member function field chain. */ |
| 747 | struct fnfieldlist |
| 748 | { |
| 749 | char *name; |
| 750 | int length; |
| 751 | struct nextfnfield *head; |
| 752 | } |
| 753 | *fnfieldlists; |
| 754 | |
| 755 | /* Number of entries in the fnfieldlists array. */ |
| 756 | int nfnfields; |
| 757 | |
| 758 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of |
| 759 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ |
| 760 | struct typedef_field_list |
| 761 | { |
| 762 | struct typedef_field field; |
| 763 | struct typedef_field_list *next; |
| 764 | } |
| 765 | *typedef_field_list; |
| 766 | unsigned typedef_field_list_count; |
| 767 | }; |
| 768 | |
| 769 | /* One item on the queue of compilation units to read in full symbols |
| 770 | for. */ |
| 771 | struct dwarf2_queue_item |
| 772 | { |
| 773 | struct dwarf2_per_cu_data *per_cu; |
| 774 | struct dwarf2_queue_item *next; |
| 775 | }; |
| 776 | |
| 777 | /* The current queue. */ |
| 778 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; |
| 779 | |
| 780 | /* Loaded secondary compilation units are kept in memory until they |
| 781 | have not been referenced for the processing of this many |
| 782 | compilation units. Set this to zero to disable caching. Cache |
| 783 | sizes of up to at least twenty will improve startup time for |
| 784 | typical inter-CU-reference binaries, at an obvious memory cost. */ |
| 785 | static int dwarf2_max_cache_age = 5; |
| 786 | static void |
| 787 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, |
| 788 | struct cmd_list_element *c, const char *value) |
| 789 | { |
| 790 | fprintf_filtered (file, _("The upper bound on the age of cached " |
| 791 | "dwarf2 compilation units is %s.\n"), |
| 792 | value); |
| 793 | } |
| 794 | |
| 795 | |
| 796 | /* Various complaints about symbol reading that don't abort the process. */ |
| 797 | |
| 798 | static void |
| 799 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) |
| 800 | { |
| 801 | complaint (&symfile_complaints, |
| 802 | _("statement list doesn't fit in .debug_line section")); |
| 803 | } |
| 804 | |
| 805 | static void |
| 806 | dwarf2_debug_line_missing_file_complaint (void) |
| 807 | { |
| 808 | complaint (&symfile_complaints, |
| 809 | _(".debug_line section has line data without a file")); |
| 810 | } |
| 811 | |
| 812 | static void |
| 813 | dwarf2_debug_line_missing_end_sequence_complaint (void) |
| 814 | { |
| 815 | complaint (&symfile_complaints, |
| 816 | _(".debug_line section has line " |
| 817 | "program sequence without an end")); |
| 818 | } |
| 819 | |
| 820 | static void |
| 821 | dwarf2_complex_location_expr_complaint (void) |
| 822 | { |
| 823 | complaint (&symfile_complaints, _("location expression too complex")); |
| 824 | } |
| 825 | |
| 826 | static void |
| 827 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, |
| 828 | int arg3) |
| 829 | { |
| 830 | complaint (&symfile_complaints, |
| 831 | _("const value length mismatch for '%s', got %d, expected %d"), |
| 832 | arg1, arg2, arg3); |
| 833 | } |
| 834 | |
| 835 | static void |
| 836 | dwarf2_macros_too_long_complaint (void) |
| 837 | { |
| 838 | complaint (&symfile_complaints, |
| 839 | _("macro info runs off end of `.debug_macinfo' section")); |
| 840 | } |
| 841 | |
| 842 | static void |
| 843 | dwarf2_macro_malformed_definition_complaint (const char *arg1) |
| 844 | { |
| 845 | complaint (&symfile_complaints, |
| 846 | _("macro debug info contains a " |
| 847 | "malformed macro definition:\n`%s'"), |
| 848 | arg1); |
| 849 | } |
| 850 | |
| 851 | static void |
| 852 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) |
| 853 | { |
| 854 | complaint (&symfile_complaints, |
| 855 | _("invalid attribute class or form for '%s' in '%s'"), |
| 856 | arg1, arg2); |
| 857 | } |
| 858 | |
| 859 | /* local function prototypes */ |
| 860 | |
| 861 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
| 862 | |
| 863 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
| 864 | struct objfile *); |
| 865 | |
| 866 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
| 867 | |
| 868 | static void scan_partial_symbols (struct partial_die_info *, |
| 869 | CORE_ADDR *, CORE_ADDR *, |
| 870 | int, struct dwarf2_cu *); |
| 871 | |
| 872 | static void add_partial_symbol (struct partial_die_info *, |
| 873 | struct dwarf2_cu *); |
| 874 | |
| 875 | static void add_partial_namespace (struct partial_die_info *pdi, |
| 876 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 877 | int need_pc, struct dwarf2_cu *cu); |
| 878 | |
| 879 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
| 880 | CORE_ADDR *highpc, int need_pc, |
| 881 | struct dwarf2_cu *cu); |
| 882 | |
| 883 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
| 884 | struct dwarf2_cu *cu); |
| 885 | |
| 886 | static void add_partial_subprogram (struct partial_die_info *pdi, |
| 887 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 888 | int need_pc, struct dwarf2_cu *cu); |
| 889 | |
| 890 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
| 891 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 892 | bfd *abfd, struct dwarf2_cu *cu); |
| 893 | |
| 894 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
| 895 | |
| 896 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
| 897 | |
| 898 | static void dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu); |
| 899 | |
| 900 | static void dwarf2_free_abbrev_table (void *); |
| 901 | |
| 902 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
| 903 | struct dwarf2_cu *); |
| 904 | |
| 905 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
| 906 | struct dwarf2_cu *); |
| 907 | |
| 908 | static struct partial_die_info *load_partial_dies (bfd *, |
| 909 | gdb_byte *, gdb_byte *, |
| 910 | int, struct dwarf2_cu *); |
| 911 | |
| 912 | static gdb_byte *read_partial_die (struct partial_die_info *, |
| 913 | struct abbrev_info *abbrev, |
| 914 | unsigned int, bfd *, |
| 915 | gdb_byte *, gdb_byte *, |
| 916 | struct dwarf2_cu *); |
| 917 | |
| 918 | static struct partial_die_info *find_partial_die (unsigned int, |
| 919 | struct dwarf2_cu *); |
| 920 | |
| 921 | static void fixup_partial_die (struct partial_die_info *, |
| 922 | struct dwarf2_cu *); |
| 923 | |
| 924 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
| 925 | bfd *, gdb_byte *, struct dwarf2_cu *); |
| 926 | |
| 927 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
| 928 | bfd *, gdb_byte *, struct dwarf2_cu *); |
| 929 | |
| 930 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
| 931 | |
| 932 | static int read_1_signed_byte (bfd *, gdb_byte *); |
| 933 | |
| 934 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
| 935 | |
| 936 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
| 937 | |
| 938 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
| 939 | |
| 940 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
| 941 | unsigned int *); |
| 942 | |
| 943 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
| 944 | |
| 945 | static LONGEST read_checked_initial_length_and_offset |
| 946 | (bfd *, gdb_byte *, const struct comp_unit_head *, |
| 947 | unsigned int *, unsigned int *); |
| 948 | |
| 949 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
| 950 | unsigned int *); |
| 951 | |
| 952 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); |
| 953 | |
| 954 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
| 955 | |
| 956 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
| 957 | |
| 958 | static char *read_indirect_string (bfd *, gdb_byte *, |
| 959 | const struct comp_unit_head *, |
| 960 | unsigned int *); |
| 961 | |
| 962 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
| 963 | |
| 964 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
| 965 | |
| 966 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
| 967 | |
| 968 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
| 969 | |
| 970 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
| 971 | struct dwarf2_cu *); |
| 972 | |
| 973 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
| 974 | unsigned int, |
| 975 | struct dwarf2_cu *); |
| 976 | |
| 977 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
| 978 | struct dwarf2_cu *cu); |
| 979 | |
| 980 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
| 981 | |
| 982 | static struct die_info *die_specification (struct die_info *die, |
| 983 | struct dwarf2_cu **); |
| 984 | |
| 985 | static void free_line_header (struct line_header *lh); |
| 986 | |
| 987 | static void add_file_name (struct line_header *, char *, unsigned int, |
| 988 | unsigned int, unsigned int); |
| 989 | |
| 990 | static struct line_header *(dwarf_decode_line_header |
| 991 | (unsigned int offset, |
| 992 | bfd *abfd, struct dwarf2_cu *cu)); |
| 993 | |
| 994 | static void dwarf_decode_lines (struct line_header *, const char *, bfd *, |
| 995 | struct dwarf2_cu *, struct partial_symtab *); |
| 996 | |
| 997 | static void dwarf2_start_subfile (char *, const char *, const char *); |
| 998 | |
| 999 | static struct symbol *new_symbol (struct die_info *, struct type *, |
| 1000 | struct dwarf2_cu *); |
| 1001 | |
| 1002 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
| 1003 | struct dwarf2_cu *, struct symbol *); |
| 1004 | |
| 1005 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
| 1006 | struct dwarf2_cu *); |
| 1007 | |
| 1008 | static void dwarf2_const_value_attr (struct attribute *attr, |
| 1009 | struct type *type, |
| 1010 | const char *name, |
| 1011 | struct obstack *obstack, |
| 1012 | struct dwarf2_cu *cu, long *value, |
| 1013 | gdb_byte **bytes, |
| 1014 | struct dwarf2_locexpr_baton **baton); |
| 1015 | |
| 1016 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
| 1017 | |
| 1018 | static int need_gnat_info (struct dwarf2_cu *); |
| 1019 | |
| 1020 | static struct type *die_descriptive_type (struct die_info *, |
| 1021 | struct dwarf2_cu *); |
| 1022 | |
| 1023 | static void set_descriptive_type (struct type *, struct die_info *, |
| 1024 | struct dwarf2_cu *); |
| 1025 | |
| 1026 | static struct type *die_containing_type (struct die_info *, |
| 1027 | struct dwarf2_cu *); |
| 1028 | |
| 1029 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
| 1030 | struct dwarf2_cu *); |
| 1031 | |
| 1032 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
| 1033 | |
| 1034 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
| 1035 | |
| 1036 | static char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
| 1037 | |
| 1038 | static char *typename_concat (struct obstack *obs, const char *prefix, |
| 1039 | const char *suffix, int physname, |
| 1040 | struct dwarf2_cu *cu); |
| 1041 | |
| 1042 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
| 1043 | |
| 1044 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
| 1045 | |
| 1046 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
| 1047 | |
| 1048 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
| 1049 | |
| 1050 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
| 1051 | struct dwarf2_cu *, struct partial_symtab *); |
| 1052 | |
| 1053 | static int dwarf2_get_pc_bounds (struct die_info *, |
| 1054 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
| 1055 | struct partial_symtab *); |
| 1056 | |
| 1057 | static void get_scope_pc_bounds (struct die_info *, |
| 1058 | CORE_ADDR *, CORE_ADDR *, |
| 1059 | struct dwarf2_cu *); |
| 1060 | |
| 1061 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
| 1062 | CORE_ADDR, struct dwarf2_cu *); |
| 1063 | |
| 1064 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
| 1065 | struct dwarf2_cu *); |
| 1066 | |
| 1067 | static void dwarf2_attach_fields_to_type (struct field_info *, |
| 1068 | struct type *, struct dwarf2_cu *); |
| 1069 | |
| 1070 | static void dwarf2_add_member_fn (struct field_info *, |
| 1071 | struct die_info *, struct type *, |
| 1072 | struct dwarf2_cu *); |
| 1073 | |
| 1074 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
| 1075 | struct type *, |
| 1076 | struct dwarf2_cu *); |
| 1077 | |
| 1078 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
| 1079 | |
| 1080 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
| 1081 | |
| 1082 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
| 1083 | |
| 1084 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
| 1085 | |
| 1086 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
| 1087 | |
| 1088 | static struct type *read_module_type (struct die_info *die, |
| 1089 | struct dwarf2_cu *cu); |
| 1090 | |
| 1091 | static const char *namespace_name (struct die_info *die, |
| 1092 | int *is_anonymous, struct dwarf2_cu *); |
| 1093 | |
| 1094 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
| 1095 | |
| 1096 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
| 1097 | |
| 1098 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
| 1099 | struct dwarf2_cu *); |
| 1100 | |
| 1101 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
| 1102 | |
| 1103 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
| 1104 | gdb_byte *info_ptr, |
| 1105 | gdb_byte **new_info_ptr, |
| 1106 | struct die_info *parent); |
| 1107 | |
| 1108 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
| 1109 | gdb_byte *info_ptr, |
| 1110 | gdb_byte **new_info_ptr, |
| 1111 | struct die_info *parent); |
| 1112 | |
| 1113 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
| 1114 | gdb_byte *info_ptr, |
| 1115 | gdb_byte **new_info_ptr, |
| 1116 | struct die_info *parent); |
| 1117 | |
| 1118 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
| 1119 | struct die_info **, gdb_byte *, |
| 1120 | int *); |
| 1121 | |
| 1122 | static void process_die (struct die_info *, struct dwarf2_cu *); |
| 1123 | |
| 1124 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
| 1125 | struct obstack *); |
| 1126 | |
| 1127 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
| 1128 | |
| 1129 | static const char *dwarf2_full_name (char *name, |
| 1130 | struct die_info *die, |
| 1131 | struct dwarf2_cu *cu); |
| 1132 | |
| 1133 | static struct die_info *dwarf2_extension (struct die_info *die, |
| 1134 | struct dwarf2_cu **); |
| 1135 | |
| 1136 | static char *dwarf_tag_name (unsigned int); |
| 1137 | |
| 1138 | static char *dwarf_attr_name (unsigned int); |
| 1139 | |
| 1140 | static char *dwarf_form_name (unsigned int); |
| 1141 | |
| 1142 | static char *dwarf_bool_name (unsigned int); |
| 1143 | |
| 1144 | static char *dwarf_type_encoding_name (unsigned int); |
| 1145 | |
| 1146 | #if 0 |
| 1147 | static char *dwarf_cfi_name (unsigned int); |
| 1148 | #endif |
| 1149 | |
| 1150 | static struct die_info *sibling_die (struct die_info *); |
| 1151 | |
| 1152 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
| 1153 | |
| 1154 | static void dump_die_for_error (struct die_info *); |
| 1155 | |
| 1156 | static void dump_die_1 (struct ui_file *, int level, int max_level, |
| 1157 | struct die_info *); |
| 1158 | |
| 1159 | /*static*/ void dump_die (struct die_info *, int max_level); |
| 1160 | |
| 1161 | static void store_in_ref_table (struct die_info *, |
| 1162 | struct dwarf2_cu *); |
| 1163 | |
| 1164 | static int is_ref_attr (struct attribute *); |
| 1165 | |
| 1166 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
| 1167 | |
| 1168 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
| 1169 | |
| 1170 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
| 1171 | struct attribute *, |
| 1172 | struct dwarf2_cu **); |
| 1173 | |
| 1174 | static struct die_info *follow_die_ref (struct die_info *, |
| 1175 | struct attribute *, |
| 1176 | struct dwarf2_cu **); |
| 1177 | |
| 1178 | static struct die_info *follow_die_sig (struct die_info *, |
| 1179 | struct attribute *, |
| 1180 | struct dwarf2_cu **); |
| 1181 | |
| 1182 | static void read_signatured_type_at_offset (struct objfile *objfile, |
| 1183 | unsigned int offset); |
| 1184 | |
| 1185 | static void read_signatured_type (struct objfile *, |
| 1186 | struct signatured_type *type_sig); |
| 1187 | |
| 1188 | /* memory allocation interface */ |
| 1189 | |
| 1190 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
| 1191 | |
| 1192 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
| 1193 | |
| 1194 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
| 1195 | |
| 1196 | static void initialize_cu_func_list (struct dwarf2_cu *); |
| 1197 | |
| 1198 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR, |
| 1199 | struct dwarf2_cu *); |
| 1200 | |
| 1201 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
| 1202 | char *, bfd *, struct dwarf2_cu *); |
| 1203 | |
| 1204 | static int attr_form_is_block (struct attribute *); |
| 1205 | |
| 1206 | static int attr_form_is_section_offset (struct attribute *); |
| 1207 | |
| 1208 | static int attr_form_is_constant (struct attribute *); |
| 1209 | |
| 1210 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
| 1211 | struct dwarf2_loclist_baton *baton, |
| 1212 | struct attribute *attr); |
| 1213 | |
| 1214 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
| 1215 | struct symbol *sym, |
| 1216 | struct dwarf2_cu *cu); |
| 1217 | |
| 1218 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
| 1219 | struct abbrev_info *abbrev, |
| 1220 | struct dwarf2_cu *cu); |
| 1221 | |
| 1222 | static void free_stack_comp_unit (void *); |
| 1223 | |
| 1224 | static hashval_t partial_die_hash (const void *item); |
| 1225 | |
| 1226 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); |
| 1227 | |
| 1228 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
| 1229 | (unsigned int offset, struct objfile *objfile); |
| 1230 | |
| 1231 | static struct dwarf2_per_cu_data *dwarf2_find_comp_unit |
| 1232 | (unsigned int offset, struct objfile *objfile); |
| 1233 | |
| 1234 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
| 1235 | struct objfile *objfile); |
| 1236 | |
| 1237 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, |
| 1238 | struct die_info *comp_unit_die); |
| 1239 | |
| 1240 | static void free_one_comp_unit (void *); |
| 1241 | |
| 1242 | static void free_cached_comp_units (void *); |
| 1243 | |
| 1244 | static void age_cached_comp_units (void); |
| 1245 | |
| 1246 | static void free_one_cached_comp_unit (void *); |
| 1247 | |
| 1248 | static struct type *set_die_type (struct die_info *, struct type *, |
| 1249 | struct dwarf2_cu *); |
| 1250 | |
| 1251 | static void create_all_comp_units (struct objfile *); |
| 1252 | |
| 1253 | static int create_debug_types_hash_table (struct objfile *objfile); |
| 1254 | |
| 1255 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
| 1256 | struct objfile *); |
| 1257 | |
| 1258 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); |
| 1259 | |
| 1260 | static void dwarf2_add_dependence (struct dwarf2_cu *, |
| 1261 | struct dwarf2_per_cu_data *); |
| 1262 | |
| 1263 | static void dwarf2_mark (struct dwarf2_cu *); |
| 1264 | |
| 1265 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); |
| 1266 | |
| 1267 | static struct type *get_die_type_at_offset (unsigned int, |
| 1268 | struct dwarf2_per_cu_data *per_cu); |
| 1269 | |
| 1270 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
| 1271 | |
| 1272 | static void dwarf2_release_queue (void *dummy); |
| 1273 | |
| 1274 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
| 1275 | struct objfile *objfile); |
| 1276 | |
| 1277 | static void process_queue (struct objfile *objfile); |
| 1278 | |
| 1279 | static void find_file_and_directory (struct die_info *die, |
| 1280 | struct dwarf2_cu *cu, |
| 1281 | char **name, char **comp_dir); |
| 1282 | |
| 1283 | static char *file_full_name (int file, struct line_header *lh, |
| 1284 | const char *comp_dir); |
| 1285 | |
| 1286 | static gdb_byte *partial_read_comp_unit_head (struct comp_unit_head *header, |
| 1287 | gdb_byte *info_ptr, |
| 1288 | gdb_byte *buffer, |
| 1289 | unsigned int buffer_size, |
| 1290 | bfd *abfd); |
| 1291 | |
| 1292 | static void init_cu_die_reader (struct die_reader_specs *reader, |
| 1293 | struct dwarf2_cu *cu); |
| 1294 | |
| 1295 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
| 1296 | |
| 1297 | #if WORDS_BIGENDIAN |
| 1298 | |
| 1299 | /* Convert VALUE between big- and little-endian. */ |
| 1300 | static offset_type |
| 1301 | byte_swap (offset_type value) |
| 1302 | { |
| 1303 | offset_type result; |
| 1304 | |
| 1305 | result = (value & 0xff) << 24; |
| 1306 | result |= (value & 0xff00) << 8; |
| 1307 | result |= (value & 0xff0000) >> 8; |
| 1308 | result |= (value & 0xff000000) >> 24; |
| 1309 | return result; |
| 1310 | } |
| 1311 | |
| 1312 | #define MAYBE_SWAP(V) byte_swap (V) |
| 1313 | |
| 1314 | #else |
| 1315 | #define MAYBE_SWAP(V) (V) |
| 1316 | #endif /* WORDS_BIGENDIAN */ |
| 1317 | |
| 1318 | /* The suffix for an index file. */ |
| 1319 | #define INDEX_SUFFIX ".gdb-index" |
| 1320 | |
| 1321 | static const char *dwarf2_physname (char *name, struct die_info *die, |
| 1322 | struct dwarf2_cu *cu); |
| 1323 | |
| 1324 | /* Try to locate the sections we need for DWARF 2 debugging |
| 1325 | information and return true if we have enough to do something. */ |
| 1326 | |
| 1327 | int |
| 1328 | dwarf2_has_info (struct objfile *objfile) |
| 1329 | { |
| 1330 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 1331 | if (!dwarf2_per_objfile) |
| 1332 | { |
| 1333 | /* Initialize per-objfile state. */ |
| 1334 | struct dwarf2_per_objfile *data |
| 1335 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); |
| 1336 | |
| 1337 | memset (data, 0, sizeof (*data)); |
| 1338 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); |
| 1339 | dwarf2_per_objfile = data; |
| 1340 | |
| 1341 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, NULL); |
| 1342 | dwarf2_per_objfile->objfile = objfile; |
| 1343 | } |
| 1344 | return (dwarf2_per_objfile->info.asection != NULL |
| 1345 | && dwarf2_per_objfile->abbrev.asection != NULL); |
| 1346 | } |
| 1347 | |
| 1348 | /* When loading sections, we can either look for ".<name>", or for |
| 1349 | * ".z<name>", which indicates a compressed section. */ |
| 1350 | |
| 1351 | static int |
| 1352 | section_is_p (const char *section_name, const char *name) |
| 1353 | { |
| 1354 | return (section_name[0] == '.' |
| 1355 | && (strcmp (section_name + 1, name) == 0 |
| 1356 | || (section_name[1] == 'z' |
| 1357 | && strcmp (section_name + 2, name) == 0))); |
| 1358 | } |
| 1359 | |
| 1360 | /* This function is mapped across the sections and remembers the |
| 1361 | offset and size of each of the debugging sections we are interested |
| 1362 | in. */ |
| 1363 | |
| 1364 | static void |
| 1365 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *ignore_ptr) |
| 1366 | { |
| 1367 | if (section_is_p (sectp->name, INFO_SECTION)) |
| 1368 | { |
| 1369 | dwarf2_per_objfile->info.asection = sectp; |
| 1370 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); |
| 1371 | } |
| 1372 | else if (section_is_p (sectp->name, ABBREV_SECTION)) |
| 1373 | { |
| 1374 | dwarf2_per_objfile->abbrev.asection = sectp; |
| 1375 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); |
| 1376 | } |
| 1377 | else if (section_is_p (sectp->name, LINE_SECTION)) |
| 1378 | { |
| 1379 | dwarf2_per_objfile->line.asection = sectp; |
| 1380 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); |
| 1381 | } |
| 1382 | else if (section_is_p (sectp->name, LOC_SECTION)) |
| 1383 | { |
| 1384 | dwarf2_per_objfile->loc.asection = sectp; |
| 1385 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); |
| 1386 | } |
| 1387 | else if (section_is_p (sectp->name, MACINFO_SECTION)) |
| 1388 | { |
| 1389 | dwarf2_per_objfile->macinfo.asection = sectp; |
| 1390 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); |
| 1391 | } |
| 1392 | else if (section_is_p (sectp->name, STR_SECTION)) |
| 1393 | { |
| 1394 | dwarf2_per_objfile->str.asection = sectp; |
| 1395 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); |
| 1396 | } |
| 1397 | else if (section_is_p (sectp->name, FRAME_SECTION)) |
| 1398 | { |
| 1399 | dwarf2_per_objfile->frame.asection = sectp; |
| 1400 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); |
| 1401 | } |
| 1402 | else if (section_is_p (sectp->name, EH_FRAME_SECTION)) |
| 1403 | { |
| 1404 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
| 1405 | |
| 1406 | if (aflag & SEC_HAS_CONTENTS) |
| 1407 | { |
| 1408 | dwarf2_per_objfile->eh_frame.asection = sectp; |
| 1409 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); |
| 1410 | } |
| 1411 | } |
| 1412 | else if (section_is_p (sectp->name, RANGES_SECTION)) |
| 1413 | { |
| 1414 | dwarf2_per_objfile->ranges.asection = sectp; |
| 1415 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); |
| 1416 | } |
| 1417 | else if (section_is_p (sectp->name, TYPES_SECTION)) |
| 1418 | { |
| 1419 | dwarf2_per_objfile->types.asection = sectp; |
| 1420 | dwarf2_per_objfile->types.size = bfd_get_section_size (sectp); |
| 1421 | } |
| 1422 | else if (section_is_p (sectp->name, GDB_INDEX_SECTION)) |
| 1423 | { |
| 1424 | dwarf2_per_objfile->gdb_index.asection = sectp; |
| 1425 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); |
| 1426 | } |
| 1427 | |
| 1428 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
| 1429 | && bfd_section_vma (abfd, sectp) == 0) |
| 1430 | dwarf2_per_objfile->has_section_at_zero = 1; |
| 1431 | } |
| 1432 | |
| 1433 | /* Decompress a section that was compressed using zlib. Store the |
| 1434 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ |
| 1435 | |
| 1436 | static void |
| 1437 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
| 1438 | gdb_byte **outbuf, bfd_size_type *outsize) |
| 1439 | { |
| 1440 | bfd *abfd = objfile->obfd; |
| 1441 | #ifndef HAVE_ZLIB_H |
| 1442 | error (_("Support for zlib-compressed DWARF data (from '%s') " |
| 1443 | "is disabled in this copy of GDB"), |
| 1444 | bfd_get_filename (abfd)); |
| 1445 | #else |
| 1446 | bfd_size_type compressed_size = bfd_get_section_size (sectp); |
| 1447 | gdb_byte *compressed_buffer = xmalloc (compressed_size); |
| 1448 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
| 1449 | bfd_size_type uncompressed_size; |
| 1450 | gdb_byte *uncompressed_buffer; |
| 1451 | z_stream strm; |
| 1452 | int rc; |
| 1453 | int header_size = 12; |
| 1454 | |
| 1455 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
| 1456 | || bfd_bread (compressed_buffer, |
| 1457 | compressed_size, abfd) != compressed_size) |
| 1458 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
| 1459 | bfd_get_filename (abfd)); |
| 1460 | |
| 1461 | /* Read the zlib header. In this case, it should be "ZLIB" followed |
| 1462 | by the uncompressed section size, 8 bytes in big-endian order. */ |
| 1463 | if (compressed_size < header_size |
| 1464 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) |
| 1465 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), |
| 1466 | bfd_get_filename (abfd)); |
| 1467 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; |
| 1468 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; |
| 1469 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; |
| 1470 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; |
| 1471 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; |
| 1472 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; |
| 1473 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; |
| 1474 | uncompressed_size += compressed_buffer[11]; |
| 1475 | |
| 1476 | /* It is possible the section consists of several compressed |
| 1477 | buffers concatenated together, so we uncompress in a loop. */ |
| 1478 | strm.zalloc = NULL; |
| 1479 | strm.zfree = NULL; |
| 1480 | strm.opaque = NULL; |
| 1481 | strm.avail_in = compressed_size - header_size; |
| 1482 | strm.next_in = (Bytef*) compressed_buffer + header_size; |
| 1483 | strm.avail_out = uncompressed_size; |
| 1484 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, |
| 1485 | uncompressed_size); |
| 1486 | rc = inflateInit (&strm); |
| 1487 | while (strm.avail_in > 0) |
| 1488 | { |
| 1489 | if (rc != Z_OK) |
| 1490 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), |
| 1491 | bfd_get_filename (abfd), rc); |
| 1492 | strm.next_out = ((Bytef*) uncompressed_buffer |
| 1493 | + (uncompressed_size - strm.avail_out)); |
| 1494 | rc = inflate (&strm, Z_FINISH); |
| 1495 | if (rc != Z_STREAM_END) |
| 1496 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), |
| 1497 | bfd_get_filename (abfd), rc); |
| 1498 | rc = inflateReset (&strm); |
| 1499 | } |
| 1500 | rc = inflateEnd (&strm); |
| 1501 | if (rc != Z_OK |
| 1502 | || strm.avail_out != 0) |
| 1503 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), |
| 1504 | bfd_get_filename (abfd), rc); |
| 1505 | |
| 1506 | do_cleanups (cleanup); |
| 1507 | *outbuf = uncompressed_buffer; |
| 1508 | *outsize = uncompressed_size; |
| 1509 | #endif |
| 1510 | } |
| 1511 | |
| 1512 | /* Read the contents of the section SECTP from object file specified by |
| 1513 | OBJFILE, store info about the section into INFO. |
| 1514 | If the section is compressed, uncompress it before returning. */ |
| 1515 | |
| 1516 | static void |
| 1517 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) |
| 1518 | { |
| 1519 | bfd *abfd = objfile->obfd; |
| 1520 | asection *sectp = info->asection; |
| 1521 | gdb_byte *buf, *retbuf; |
| 1522 | unsigned char header[4]; |
| 1523 | |
| 1524 | if (info->readin) |
| 1525 | return; |
| 1526 | info->buffer = NULL; |
| 1527 | info->was_mmapped = 0; |
| 1528 | info->readin = 1; |
| 1529 | |
| 1530 | if (info->asection == NULL || info->size == 0) |
| 1531 | return; |
| 1532 | |
| 1533 | /* Check if the file has a 4-byte header indicating compression. */ |
| 1534 | if (info->size > sizeof (header) |
| 1535 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 |
| 1536 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) |
| 1537 | { |
| 1538 | /* Upon decompression, update the buffer and its size. */ |
| 1539 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) |
| 1540 | { |
| 1541 | zlib_decompress_section (objfile, sectp, &info->buffer, |
| 1542 | &info->size); |
| 1543 | return; |
| 1544 | } |
| 1545 | } |
| 1546 | |
| 1547 | #ifdef HAVE_MMAP |
| 1548 | if (pagesize == 0) |
| 1549 | pagesize = getpagesize (); |
| 1550 | |
| 1551 | /* Only try to mmap sections which are large enough: we don't want to |
| 1552 | waste space due to fragmentation. Also, only try mmap for sections |
| 1553 | without relocations. */ |
| 1554 | |
| 1555 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) |
| 1556 | { |
| 1557 | off_t pg_offset = sectp->filepos & ~(pagesize - 1); |
| 1558 | size_t map_length = info->size + sectp->filepos - pg_offset; |
| 1559 | caddr_t retbuf = bfd_mmap (abfd, 0, map_length, PROT_READ, |
| 1560 | MAP_PRIVATE, pg_offset); |
| 1561 | |
| 1562 | if (retbuf != MAP_FAILED) |
| 1563 | { |
| 1564 | info->was_mmapped = 1; |
| 1565 | info->buffer = retbuf + (sectp->filepos & (pagesize - 1)) ; |
| 1566 | #if HAVE_POSIX_MADVISE |
| 1567 | posix_madvise (retbuf, map_length, POSIX_MADV_WILLNEED); |
| 1568 | #endif |
| 1569 | return; |
| 1570 | } |
| 1571 | } |
| 1572 | #endif |
| 1573 | |
| 1574 | /* If we get here, we are a normal, not-compressed section. */ |
| 1575 | info->buffer = buf |
| 1576 | = obstack_alloc (&objfile->objfile_obstack, info->size); |
| 1577 | |
| 1578 | /* When debugging .o files, we may need to apply relocations; see |
| 1579 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . |
| 1580 | We never compress sections in .o files, so we only need to |
| 1581 | try this when the section is not compressed. */ |
| 1582 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
| 1583 | if (retbuf != NULL) |
| 1584 | { |
| 1585 | info->buffer = retbuf; |
| 1586 | return; |
| 1587 | } |
| 1588 | |
| 1589 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
| 1590 | || bfd_bread (buf, info->size, abfd) != info->size) |
| 1591 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
| 1592 | bfd_get_filename (abfd)); |
| 1593 | } |
| 1594 | |
| 1595 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
| 1596 | SECTION_NAME. */ |
| 1597 | |
| 1598 | void |
| 1599 | dwarf2_get_section_info (struct objfile *objfile, const char *section_name, |
| 1600 | asection **sectp, gdb_byte **bufp, |
| 1601 | bfd_size_type *sizep) |
| 1602 | { |
| 1603 | struct dwarf2_per_objfile *data |
| 1604 | = objfile_data (objfile, dwarf2_objfile_data_key); |
| 1605 | struct dwarf2_section_info *info; |
| 1606 | |
| 1607 | /* We may see an objfile without any DWARF, in which case we just |
| 1608 | return nothing. */ |
| 1609 | if (data == NULL) |
| 1610 | { |
| 1611 | *sectp = NULL; |
| 1612 | *bufp = NULL; |
| 1613 | *sizep = 0; |
| 1614 | return; |
| 1615 | } |
| 1616 | if (section_is_p (section_name, EH_FRAME_SECTION)) |
| 1617 | info = &data->eh_frame; |
| 1618 | else if (section_is_p (section_name, FRAME_SECTION)) |
| 1619 | info = &data->frame; |
| 1620 | else |
| 1621 | gdb_assert_not_reached ("unexpected section"); |
| 1622 | |
| 1623 | if (info->asection != NULL && info->size != 0 && info->buffer == NULL) |
| 1624 | /* We haven't read this section in yet. Do it now. */ |
| 1625 | dwarf2_read_section (objfile, info); |
| 1626 | |
| 1627 | *sectp = info->asection; |
| 1628 | *bufp = info->buffer; |
| 1629 | *sizep = info->size; |
| 1630 | } |
| 1631 | |
| 1632 | \f |
| 1633 | /* DWARF quick_symbols_functions support. */ |
| 1634 | |
| 1635 | /* TUs can share .debug_line entries, and there can be a lot more TUs than |
| 1636 | unique line tables, so we maintain a separate table of all .debug_line |
| 1637 | derived entries to support the sharing. |
| 1638 | All the quick functions need is the list of file names. We discard the |
| 1639 | line_header when we're done and don't need to record it here. */ |
| 1640 | struct quick_file_names |
| 1641 | { |
| 1642 | /* The offset in .debug_line of the line table. We hash on this. */ |
| 1643 | unsigned int offset; |
| 1644 | |
| 1645 | /* The number of entries in file_names, real_names. */ |
| 1646 | unsigned int num_file_names; |
| 1647 | |
| 1648 | /* The file names from the line table, after being run through |
| 1649 | file_full_name. */ |
| 1650 | const char **file_names; |
| 1651 | |
| 1652 | /* The file names from the line table after being run through |
| 1653 | gdb_realpath. These are computed lazily. */ |
| 1654 | const char **real_names; |
| 1655 | }; |
| 1656 | |
| 1657 | /* When using the index (and thus not using psymtabs), each CU has an |
| 1658 | object of this type. This is used to hold information needed by |
| 1659 | the various "quick" methods. */ |
| 1660 | struct dwarf2_per_cu_quick_data |
| 1661 | { |
| 1662 | /* The file table. This can be NULL if there was no file table |
| 1663 | or it's currently not read in. |
| 1664 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ |
| 1665 | struct quick_file_names *file_names; |
| 1666 | |
| 1667 | /* The corresponding symbol table. This is NULL if symbols for this |
| 1668 | CU have not yet been read. */ |
| 1669 | struct symtab *symtab; |
| 1670 | |
| 1671 | /* A temporary mark bit used when iterating over all CUs in |
| 1672 | expand_symtabs_matching. */ |
| 1673 | unsigned int mark : 1; |
| 1674 | |
| 1675 | /* True if we've tried to read the file table and found there isn't one. |
| 1676 | There will be no point in trying to read it again next time. */ |
| 1677 | unsigned int no_file_data : 1; |
| 1678 | }; |
| 1679 | |
| 1680 | /* Hash function for a quick_file_names. */ |
| 1681 | |
| 1682 | static hashval_t |
| 1683 | hash_file_name_entry (const void *e) |
| 1684 | { |
| 1685 | const struct quick_file_names *file_data = e; |
| 1686 | |
| 1687 | return file_data->offset; |
| 1688 | } |
| 1689 | |
| 1690 | /* Equality function for a quick_file_names. */ |
| 1691 | |
| 1692 | static int |
| 1693 | eq_file_name_entry (const void *a, const void *b) |
| 1694 | { |
| 1695 | const struct quick_file_names *ea = a; |
| 1696 | const struct quick_file_names *eb = b; |
| 1697 | |
| 1698 | return ea->offset == eb->offset; |
| 1699 | } |
| 1700 | |
| 1701 | /* Delete function for a quick_file_names. */ |
| 1702 | |
| 1703 | static void |
| 1704 | delete_file_name_entry (void *e) |
| 1705 | { |
| 1706 | struct quick_file_names *file_data = e; |
| 1707 | int i; |
| 1708 | |
| 1709 | for (i = 0; i < file_data->num_file_names; ++i) |
| 1710 | { |
| 1711 | xfree ((void*) file_data->file_names[i]); |
| 1712 | if (file_data->real_names) |
| 1713 | xfree ((void*) file_data->real_names[i]); |
| 1714 | } |
| 1715 | |
| 1716 | /* The space for the struct itself lives on objfile_obstack, |
| 1717 | so we don't free it here. */ |
| 1718 | } |
| 1719 | |
| 1720 | /* Create a quick_file_names hash table. */ |
| 1721 | |
| 1722 | static htab_t |
| 1723 | create_quick_file_names_table (unsigned int nr_initial_entries) |
| 1724 | { |
| 1725 | return htab_create_alloc (nr_initial_entries, |
| 1726 | hash_file_name_entry, eq_file_name_entry, |
| 1727 | delete_file_name_entry, xcalloc, xfree); |
| 1728 | } |
| 1729 | |
| 1730 | /* Read in the symbols for PER_CU. OBJFILE is the objfile from which |
| 1731 | this CU came. */ |
| 1732 | |
| 1733 | static void |
| 1734 | dw2_do_instantiate_symtab (struct objfile *objfile, |
| 1735 | struct dwarf2_per_cu_data *per_cu) |
| 1736 | { |
| 1737 | struct cleanup *back_to; |
| 1738 | |
| 1739 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
| 1740 | |
| 1741 | queue_comp_unit (per_cu, objfile); |
| 1742 | |
| 1743 | if (per_cu->from_debug_types) |
| 1744 | read_signatured_type_at_offset (objfile, per_cu->offset); |
| 1745 | else |
| 1746 | load_full_comp_unit (per_cu, objfile); |
| 1747 | |
| 1748 | process_queue (objfile); |
| 1749 | |
| 1750 | /* Age the cache, releasing compilation units that have not |
| 1751 | been used recently. */ |
| 1752 | age_cached_comp_units (); |
| 1753 | |
| 1754 | do_cleanups (back_to); |
| 1755 | } |
| 1756 | |
| 1757 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is |
| 1758 | the objfile from which this CU came. Returns the resulting symbol |
| 1759 | table. */ |
| 1760 | |
| 1761 | static struct symtab * |
| 1762 | dw2_instantiate_symtab (struct objfile *objfile, |
| 1763 | struct dwarf2_per_cu_data *per_cu) |
| 1764 | { |
| 1765 | if (!per_cu->v.quick->symtab) |
| 1766 | { |
| 1767 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); |
| 1768 | increment_reading_symtab (); |
| 1769 | dw2_do_instantiate_symtab (objfile, per_cu); |
| 1770 | do_cleanups (back_to); |
| 1771 | } |
| 1772 | return per_cu->v.quick->symtab; |
| 1773 | } |
| 1774 | |
| 1775 | /* Return the CU given its index. */ |
| 1776 | |
| 1777 | static struct dwarf2_per_cu_data * |
| 1778 | dw2_get_cu (int index) |
| 1779 | { |
| 1780 | if (index >= dwarf2_per_objfile->n_comp_units) |
| 1781 | { |
| 1782 | index -= dwarf2_per_objfile->n_comp_units; |
| 1783 | return dwarf2_per_objfile->type_comp_units[index]; |
| 1784 | } |
| 1785 | return dwarf2_per_objfile->all_comp_units[index]; |
| 1786 | } |
| 1787 | |
| 1788 | /* A helper function that knows how to read a 64-bit value in a way |
| 1789 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 |
| 1790 | otherwise. */ |
| 1791 | |
| 1792 | static int |
| 1793 | extract_cu_value (const char *bytes, ULONGEST *result) |
| 1794 | { |
| 1795 | if (sizeof (ULONGEST) < 8) |
| 1796 | { |
| 1797 | int i; |
| 1798 | |
| 1799 | /* Ignore the upper 4 bytes if they are all zero. */ |
| 1800 | for (i = 0; i < 4; ++i) |
| 1801 | if (bytes[i + 4] != 0) |
| 1802 | return 0; |
| 1803 | |
| 1804 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); |
| 1805 | } |
| 1806 | else |
| 1807 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); |
| 1808 | return 1; |
| 1809 | } |
| 1810 | |
| 1811 | /* Read the CU list from the mapped index, and use it to create all |
| 1812 | the CU objects for this objfile. Return 0 if something went wrong, |
| 1813 | 1 if everything went ok. */ |
| 1814 | |
| 1815 | static int |
| 1816 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
| 1817 | offset_type cu_list_elements) |
| 1818 | { |
| 1819 | offset_type i; |
| 1820 | |
| 1821 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; |
| 1822 | dwarf2_per_objfile->all_comp_units |
| 1823 | = obstack_alloc (&objfile->objfile_obstack, |
| 1824 | dwarf2_per_objfile->n_comp_units |
| 1825 | * sizeof (struct dwarf2_per_cu_data *)); |
| 1826 | |
| 1827 | for (i = 0; i < cu_list_elements; i += 2) |
| 1828 | { |
| 1829 | struct dwarf2_per_cu_data *the_cu; |
| 1830 | ULONGEST offset, length; |
| 1831 | |
| 1832 | if (!extract_cu_value (cu_list, &offset) |
| 1833 | || !extract_cu_value (cu_list + 8, &length)) |
| 1834 | return 0; |
| 1835 | cu_list += 2 * 8; |
| 1836 | |
| 1837 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1838 | struct dwarf2_per_cu_data); |
| 1839 | the_cu->offset = offset; |
| 1840 | the_cu->length = length; |
| 1841 | the_cu->objfile = objfile; |
| 1842 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1843 | struct dwarf2_per_cu_quick_data); |
| 1844 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; |
| 1845 | } |
| 1846 | |
| 1847 | return 1; |
| 1848 | } |
| 1849 | |
| 1850 | /* Create the signatured type hash table from the index. */ |
| 1851 | |
| 1852 | static int |
| 1853 | create_signatured_type_table_from_index (struct objfile *objfile, |
| 1854 | const gdb_byte *bytes, |
| 1855 | offset_type elements) |
| 1856 | { |
| 1857 | offset_type i; |
| 1858 | htab_t sig_types_hash; |
| 1859 | |
| 1860 | dwarf2_per_objfile->n_type_comp_units = elements / 3; |
| 1861 | dwarf2_per_objfile->type_comp_units |
| 1862 | = obstack_alloc (&objfile->objfile_obstack, |
| 1863 | dwarf2_per_objfile->n_type_comp_units |
| 1864 | * sizeof (struct dwarf2_per_cu_data *)); |
| 1865 | |
| 1866 | sig_types_hash = allocate_signatured_type_table (objfile); |
| 1867 | |
| 1868 | for (i = 0; i < elements; i += 3) |
| 1869 | { |
| 1870 | struct signatured_type *type_sig; |
| 1871 | ULONGEST offset, type_offset, signature; |
| 1872 | void **slot; |
| 1873 | |
| 1874 | if (!extract_cu_value (bytes, &offset) |
| 1875 | || !extract_cu_value (bytes + 8, &type_offset)) |
| 1876 | return 0; |
| 1877 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); |
| 1878 | bytes += 3 * 8; |
| 1879 | |
| 1880 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1881 | struct signatured_type); |
| 1882 | type_sig->signature = signature; |
| 1883 | type_sig->offset = offset; |
| 1884 | type_sig->type_offset = type_offset; |
| 1885 | type_sig->per_cu.from_debug_types = 1; |
| 1886 | type_sig->per_cu.offset = offset; |
| 1887 | type_sig->per_cu.objfile = objfile; |
| 1888 | type_sig->per_cu.v.quick |
| 1889 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1890 | struct dwarf2_per_cu_quick_data); |
| 1891 | |
| 1892 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
| 1893 | *slot = type_sig; |
| 1894 | |
| 1895 | dwarf2_per_objfile->type_comp_units[i / 3] = &type_sig->per_cu; |
| 1896 | } |
| 1897 | |
| 1898 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
| 1899 | |
| 1900 | return 1; |
| 1901 | } |
| 1902 | |
| 1903 | /* Read the address map data from the mapped index, and use it to |
| 1904 | populate the objfile's psymtabs_addrmap. */ |
| 1905 | |
| 1906 | static void |
| 1907 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) |
| 1908 | { |
| 1909 | const gdb_byte *iter, *end; |
| 1910 | struct obstack temp_obstack; |
| 1911 | struct addrmap *mutable_map; |
| 1912 | struct cleanup *cleanup; |
| 1913 | CORE_ADDR baseaddr; |
| 1914 | |
| 1915 | obstack_init (&temp_obstack); |
| 1916 | cleanup = make_cleanup_obstack_free (&temp_obstack); |
| 1917 | mutable_map = addrmap_create_mutable (&temp_obstack); |
| 1918 | |
| 1919 | iter = index->address_table; |
| 1920 | end = iter + index->address_table_size; |
| 1921 | |
| 1922 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 1923 | |
| 1924 | while (iter < end) |
| 1925 | { |
| 1926 | ULONGEST hi, lo, cu_index; |
| 1927 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); |
| 1928 | iter += 8; |
| 1929 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); |
| 1930 | iter += 8; |
| 1931 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); |
| 1932 | iter += 4; |
| 1933 | |
| 1934 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, |
| 1935 | dw2_get_cu (cu_index)); |
| 1936 | } |
| 1937 | |
| 1938 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, |
| 1939 | &objfile->objfile_obstack); |
| 1940 | do_cleanups (cleanup); |
| 1941 | } |
| 1942 | |
| 1943 | /* The hash function for strings in the mapped index. This is the |
| 1944 | same as the hashtab.c hash function, but we keep a separate copy to |
| 1945 | maintain control over the implementation. This is necessary |
| 1946 | because the hash function is tied to the format of the mapped index |
| 1947 | file. */ |
| 1948 | |
| 1949 | static hashval_t |
| 1950 | mapped_index_string_hash (const void *p) |
| 1951 | { |
| 1952 | const unsigned char *str = (const unsigned char *) p; |
| 1953 | hashval_t r = 0; |
| 1954 | unsigned char c; |
| 1955 | |
| 1956 | while ((c = *str++) != 0) |
| 1957 | r = r * 67 + c - 113; |
| 1958 | |
| 1959 | return r; |
| 1960 | } |
| 1961 | |
| 1962 | /* Find a slot in the mapped index INDEX for the object named NAME. |
| 1963 | If NAME is found, set *VEC_OUT to point to the CU vector in the |
| 1964 | constant pool and return 1. If NAME cannot be found, return 0. */ |
| 1965 | |
| 1966 | static int |
| 1967 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, |
| 1968 | offset_type **vec_out) |
| 1969 | { |
| 1970 | offset_type hash = mapped_index_string_hash (name); |
| 1971 | offset_type slot, step; |
| 1972 | |
| 1973 | slot = hash & (index->symbol_table_slots - 1); |
| 1974 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; |
| 1975 | |
| 1976 | for (;;) |
| 1977 | { |
| 1978 | /* Convert a slot number to an offset into the table. */ |
| 1979 | offset_type i = 2 * slot; |
| 1980 | const char *str; |
| 1981 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
| 1982 | return 0; |
| 1983 | |
| 1984 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
| 1985 | if (!strcmp (name, str)) |
| 1986 | { |
| 1987 | *vec_out = (offset_type *) (index->constant_pool |
| 1988 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
| 1989 | return 1; |
| 1990 | } |
| 1991 | |
| 1992 | slot = (slot + step) & (index->symbol_table_slots - 1); |
| 1993 | } |
| 1994 | } |
| 1995 | |
| 1996 | /* Read the index file. If everything went ok, initialize the "quick" |
| 1997 | elements of all the CUs and return 1. Otherwise, return 0. */ |
| 1998 | |
| 1999 | static int |
| 2000 | dwarf2_read_index (struct objfile *objfile) |
| 2001 | { |
| 2002 | char *addr; |
| 2003 | struct mapped_index *map; |
| 2004 | offset_type *metadata; |
| 2005 | const gdb_byte *cu_list; |
| 2006 | const gdb_byte *types_list = NULL; |
| 2007 | offset_type version, cu_list_elements; |
| 2008 | offset_type types_list_elements = 0; |
| 2009 | int i; |
| 2010 | |
| 2011 | if (dwarf2_per_objfile->gdb_index.asection == NULL |
| 2012 | || dwarf2_per_objfile->gdb_index.size == 0) |
| 2013 | return 0; |
| 2014 | |
| 2015 | /* Older elfutils strip versions could keep the section in the main |
| 2016 | executable while splitting it for the separate debug info file. */ |
| 2017 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) |
| 2018 | & SEC_HAS_CONTENTS) == 0) |
| 2019 | return 0; |
| 2020 | |
| 2021 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
| 2022 | |
| 2023 | addr = dwarf2_per_objfile->gdb_index.buffer; |
| 2024 | /* Version check. */ |
| 2025 | version = MAYBE_SWAP (*(offset_type *) addr); |
| 2026 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
| 2027 | causes the index to behave very poorly for certain requests. So, |
| 2028 | it seems better to just ignore such indices. */ |
| 2029 | if (version < 3) |
| 2030 | return 0; |
| 2031 | /* Indexes with higher version than the one supported by GDB may be no |
| 2032 | longer backward compatible. */ |
| 2033 | if (version > 3) |
| 2034 | return 0; |
| 2035 | |
| 2036 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); |
| 2037 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
| 2038 | |
| 2039 | metadata = (offset_type *) (addr + sizeof (offset_type)); |
| 2040 | |
| 2041 | i = 0; |
| 2042 | cu_list = addr + MAYBE_SWAP (metadata[i]); |
| 2043 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) |
| 2044 | / 8); |
| 2045 | ++i; |
| 2046 | |
| 2047 | types_list = addr + MAYBE_SWAP (metadata[i]); |
| 2048 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) |
| 2049 | - MAYBE_SWAP (metadata[i])) |
| 2050 | / 8); |
| 2051 | ++i; |
| 2052 | |
| 2053 | map->address_table = addr + MAYBE_SWAP (metadata[i]); |
| 2054 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) |
| 2055 | - MAYBE_SWAP (metadata[i])); |
| 2056 | ++i; |
| 2057 | |
| 2058 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
| 2059 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) |
| 2060 | - MAYBE_SWAP (metadata[i])) |
| 2061 | / (2 * sizeof (offset_type))); |
| 2062 | ++i; |
| 2063 | |
| 2064 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
| 2065 | |
| 2066 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) |
| 2067 | return 0; |
| 2068 | |
| 2069 | if (types_list_elements |
| 2070 | && !create_signatured_type_table_from_index (objfile, types_list, |
| 2071 | types_list_elements)) |
| 2072 | return 0; |
| 2073 | |
| 2074 | create_addrmap_from_index (objfile, map); |
| 2075 | |
| 2076 | dwarf2_per_objfile->index_table = map; |
| 2077 | dwarf2_per_objfile->using_index = 1; |
| 2078 | dwarf2_per_objfile->quick_file_names_table = |
| 2079 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); |
| 2080 | |
| 2081 | return 1; |
| 2082 | } |
| 2083 | |
| 2084 | /* A helper for the "quick" functions which sets the global |
| 2085 | dwarf2_per_objfile according to OBJFILE. */ |
| 2086 | |
| 2087 | static void |
| 2088 | dw2_setup (struct objfile *objfile) |
| 2089 | { |
| 2090 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 2091 | gdb_assert (dwarf2_per_objfile); |
| 2092 | } |
| 2093 | |
| 2094 | /* A helper for the "quick" functions which attempts to read the line |
| 2095 | table for THIS_CU. */ |
| 2096 | |
| 2097 | static struct quick_file_names * |
| 2098 | dw2_get_file_names (struct objfile *objfile, |
| 2099 | struct dwarf2_per_cu_data *this_cu) |
| 2100 | { |
| 2101 | bfd *abfd = objfile->obfd; |
| 2102 | struct line_header *lh; |
| 2103 | struct attribute *attr; |
| 2104 | struct cleanup *cleanups; |
| 2105 | struct die_info *comp_unit_die; |
| 2106 | struct dwarf2_section_info* sec; |
| 2107 | gdb_byte *beg_of_comp_unit, *info_ptr, *buffer; |
| 2108 | int has_children, i; |
| 2109 | struct dwarf2_cu cu; |
| 2110 | unsigned int bytes_read, buffer_size; |
| 2111 | struct die_reader_specs reader_specs; |
| 2112 | char *name, *comp_dir; |
| 2113 | void **slot; |
| 2114 | struct quick_file_names *qfn; |
| 2115 | unsigned int line_offset; |
| 2116 | |
| 2117 | if (this_cu->v.quick->file_names != NULL) |
| 2118 | return this_cu->v.quick->file_names; |
| 2119 | /* If we know there is no line data, no point in looking again. */ |
| 2120 | if (this_cu->v.quick->no_file_data) |
| 2121 | return NULL; |
| 2122 | |
| 2123 | init_one_comp_unit (&cu, objfile); |
| 2124 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
| 2125 | |
| 2126 | if (this_cu->from_debug_types) |
| 2127 | sec = &dwarf2_per_objfile->types; |
| 2128 | else |
| 2129 | sec = &dwarf2_per_objfile->info; |
| 2130 | dwarf2_read_section (objfile, sec); |
| 2131 | buffer_size = sec->size; |
| 2132 | buffer = sec->buffer; |
| 2133 | info_ptr = buffer + this_cu->offset; |
| 2134 | beg_of_comp_unit = info_ptr; |
| 2135 | |
| 2136 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
| 2137 | buffer, buffer_size, |
| 2138 | abfd); |
| 2139 | |
| 2140 | /* Complete the cu_header. */ |
| 2141 | cu.header.offset = beg_of_comp_unit - buffer; |
| 2142 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; |
| 2143 | |
| 2144 | this_cu->cu = &cu; |
| 2145 | cu.per_cu = this_cu; |
| 2146 | |
| 2147 | dwarf2_read_abbrevs (abfd, &cu); |
| 2148 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
| 2149 | |
| 2150 | if (this_cu->from_debug_types) |
| 2151 | info_ptr += 8 /*signature*/ + cu.header.offset_size; |
| 2152 | init_cu_die_reader (&reader_specs, &cu); |
| 2153 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
| 2154 | &has_children); |
| 2155 | |
| 2156 | lh = NULL; |
| 2157 | slot = NULL; |
| 2158 | line_offset = 0; |
| 2159 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
| 2160 | if (attr) |
| 2161 | { |
| 2162 | struct quick_file_names find_entry; |
| 2163 | |
| 2164 | line_offset = DW_UNSND (attr); |
| 2165 | |
| 2166 | /* We may have already read in this line header (TU line header sharing). |
| 2167 | If we have we're done. */ |
| 2168 | find_entry.offset = line_offset; |
| 2169 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, |
| 2170 | &find_entry, INSERT); |
| 2171 | if (*slot != NULL) |
| 2172 | { |
| 2173 | do_cleanups (cleanups); |
| 2174 | this_cu->v.quick->file_names = *slot; |
| 2175 | return *slot; |
| 2176 | } |
| 2177 | |
| 2178 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
| 2179 | } |
| 2180 | if (lh == NULL) |
| 2181 | { |
| 2182 | do_cleanups (cleanups); |
| 2183 | this_cu->v.quick->no_file_data = 1; |
| 2184 | return NULL; |
| 2185 | } |
| 2186 | |
| 2187 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
| 2188 | qfn->offset = line_offset; |
| 2189 | gdb_assert (slot != NULL); |
| 2190 | *slot = qfn; |
| 2191 | |
| 2192 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
| 2193 | |
| 2194 | qfn->num_file_names = lh->num_file_names; |
| 2195 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, |
| 2196 | lh->num_file_names * sizeof (char *)); |
| 2197 | for (i = 0; i < lh->num_file_names; ++i) |
| 2198 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
| 2199 | qfn->real_names = NULL; |
| 2200 | |
| 2201 | free_line_header (lh); |
| 2202 | do_cleanups (cleanups); |
| 2203 | |
| 2204 | this_cu->v.quick->file_names = qfn; |
| 2205 | return qfn; |
| 2206 | } |
| 2207 | |
| 2208 | /* A helper for the "quick" functions which computes and caches the |
| 2209 | real path for a given file name from the line table. */ |
| 2210 | |
| 2211 | static const char * |
| 2212 | dw2_get_real_path (struct objfile *objfile, |
| 2213 | struct quick_file_names *qfn, int index) |
| 2214 | { |
| 2215 | if (qfn->real_names == NULL) |
| 2216 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, |
| 2217 | qfn->num_file_names, sizeof (char *)); |
| 2218 | |
| 2219 | if (qfn->real_names[index] == NULL) |
| 2220 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); |
| 2221 | |
| 2222 | return qfn->real_names[index]; |
| 2223 | } |
| 2224 | |
| 2225 | static struct symtab * |
| 2226 | dw2_find_last_source_symtab (struct objfile *objfile) |
| 2227 | { |
| 2228 | int index; |
| 2229 | |
| 2230 | dw2_setup (objfile); |
| 2231 | index = dwarf2_per_objfile->n_comp_units - 1; |
| 2232 | return dw2_instantiate_symtab (objfile, dw2_get_cu (index)); |
| 2233 | } |
| 2234 | |
| 2235 | /* Traversal function for dw2_forget_cached_source_info. */ |
| 2236 | |
| 2237 | static int |
| 2238 | dw2_free_cached_file_names (void **slot, void *info) |
| 2239 | { |
| 2240 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
| 2241 | |
| 2242 | if (file_data->real_names) |
| 2243 | { |
| 2244 | int i; |
| 2245 | |
| 2246 | for (i = 0; i < file_data->num_file_names; ++i) |
| 2247 | { |
| 2248 | xfree ((void*) file_data->real_names[i]); |
| 2249 | file_data->real_names[i] = NULL; |
| 2250 | } |
| 2251 | } |
| 2252 | |
| 2253 | return 1; |
| 2254 | } |
| 2255 | |
| 2256 | static void |
| 2257 | dw2_forget_cached_source_info (struct objfile *objfile) |
| 2258 | { |
| 2259 | dw2_setup (objfile); |
| 2260 | |
| 2261 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, |
| 2262 | dw2_free_cached_file_names, NULL); |
| 2263 | } |
| 2264 | |
| 2265 | static int |
| 2266 | dw2_lookup_symtab (struct objfile *objfile, const char *name, |
| 2267 | const char *full_path, const char *real_path, |
| 2268 | struct symtab **result) |
| 2269 | { |
| 2270 | int i; |
| 2271 | int check_basename = lbasename (name) == name; |
| 2272 | struct dwarf2_per_cu_data *base_cu = NULL; |
| 2273 | |
| 2274 | dw2_setup (objfile); |
| 2275 | |
| 2276 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2277 | + dwarf2_per_objfile->n_type_comp_units); ++i) |
| 2278 | { |
| 2279 | int j; |
| 2280 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2281 | struct quick_file_names *file_data; |
| 2282 | |
| 2283 | if (per_cu->v.quick->symtab) |
| 2284 | continue; |
| 2285 | |
| 2286 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2287 | if (file_data == NULL) |
| 2288 | continue; |
| 2289 | |
| 2290 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2291 | { |
| 2292 | const char *this_name = file_data->file_names[j]; |
| 2293 | |
| 2294 | if (FILENAME_CMP (name, this_name) == 0) |
| 2295 | { |
| 2296 | *result = dw2_instantiate_symtab (objfile, per_cu); |
| 2297 | return 1; |
| 2298 | } |
| 2299 | |
| 2300 | if (check_basename && ! base_cu |
| 2301 | && FILENAME_CMP (lbasename (this_name), name) == 0) |
| 2302 | base_cu = per_cu; |
| 2303 | |
| 2304 | if (full_path != NULL) |
| 2305 | { |
| 2306 | const char *this_real_name = dw2_get_real_path (objfile, |
| 2307 | file_data, j); |
| 2308 | |
| 2309 | if (this_real_name != NULL |
| 2310 | && FILENAME_CMP (full_path, this_real_name) == 0) |
| 2311 | { |
| 2312 | *result = dw2_instantiate_symtab (objfile, per_cu); |
| 2313 | return 1; |
| 2314 | } |
| 2315 | } |
| 2316 | |
| 2317 | if (real_path != NULL) |
| 2318 | { |
| 2319 | const char *this_real_name = dw2_get_real_path (objfile, |
| 2320 | file_data, j); |
| 2321 | |
| 2322 | if (this_real_name != NULL |
| 2323 | && FILENAME_CMP (real_path, this_real_name) == 0) |
| 2324 | { |
| 2325 | *result = dw2_instantiate_symtab (objfile, per_cu); |
| 2326 | return 1; |
| 2327 | } |
| 2328 | } |
| 2329 | } |
| 2330 | } |
| 2331 | |
| 2332 | if (base_cu) |
| 2333 | { |
| 2334 | *result = dw2_instantiate_symtab (objfile, base_cu); |
| 2335 | return 1; |
| 2336 | } |
| 2337 | |
| 2338 | return 0; |
| 2339 | } |
| 2340 | |
| 2341 | static struct symtab * |
| 2342 | dw2_lookup_symbol (struct objfile *objfile, int block_index, |
| 2343 | const char *name, domain_enum domain) |
| 2344 | { |
| 2345 | /* We do all the work in the pre_expand_symtabs_matching hook |
| 2346 | instead. */ |
| 2347 | return NULL; |
| 2348 | } |
| 2349 | |
| 2350 | /* A helper function that expands all symtabs that hold an object |
| 2351 | named NAME. */ |
| 2352 | |
| 2353 | static void |
| 2354 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) |
| 2355 | { |
| 2356 | dw2_setup (objfile); |
| 2357 | |
| 2358 | /* index_table is NULL if OBJF_READNOW. */ |
| 2359 | if (dwarf2_per_objfile->index_table) |
| 2360 | { |
| 2361 | offset_type *vec; |
| 2362 | |
| 2363 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, |
| 2364 | name, &vec)) |
| 2365 | { |
| 2366 | offset_type i, len = MAYBE_SWAP (*vec); |
| 2367 | for (i = 0; i < len; ++i) |
| 2368 | { |
| 2369 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); |
| 2370 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
| 2371 | |
| 2372 | dw2_instantiate_symtab (objfile, per_cu); |
| 2373 | } |
| 2374 | } |
| 2375 | } |
| 2376 | } |
| 2377 | |
| 2378 | static void |
| 2379 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, |
| 2380 | int kind, const char *name, |
| 2381 | domain_enum domain) |
| 2382 | { |
| 2383 | dw2_do_expand_symtabs_matching (objfile, name); |
| 2384 | } |
| 2385 | |
| 2386 | static void |
| 2387 | dw2_print_stats (struct objfile *objfile) |
| 2388 | { |
| 2389 | int i, count; |
| 2390 | |
| 2391 | dw2_setup (objfile); |
| 2392 | count = 0; |
| 2393 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2394 | + dwarf2_per_objfile->n_type_comp_units); ++i) |
| 2395 | { |
| 2396 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2397 | |
| 2398 | if (!per_cu->v.quick->symtab) |
| 2399 | ++count; |
| 2400 | } |
| 2401 | printf_filtered (_(" Number of unread CUs: %d\n"), count); |
| 2402 | } |
| 2403 | |
| 2404 | static void |
| 2405 | dw2_dump (struct objfile *objfile) |
| 2406 | { |
| 2407 | /* Nothing worth printing. */ |
| 2408 | } |
| 2409 | |
| 2410 | static void |
| 2411 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, |
| 2412 | struct section_offsets *delta) |
| 2413 | { |
| 2414 | /* There's nothing to relocate here. */ |
| 2415 | } |
| 2416 | |
| 2417 | static void |
| 2418 | dw2_expand_symtabs_for_function (struct objfile *objfile, |
| 2419 | const char *func_name) |
| 2420 | { |
| 2421 | dw2_do_expand_symtabs_matching (objfile, func_name); |
| 2422 | } |
| 2423 | |
| 2424 | static void |
| 2425 | dw2_expand_all_symtabs (struct objfile *objfile) |
| 2426 | { |
| 2427 | int i; |
| 2428 | |
| 2429 | dw2_setup (objfile); |
| 2430 | |
| 2431 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2432 | + dwarf2_per_objfile->n_type_comp_units); ++i) |
| 2433 | { |
| 2434 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2435 | |
| 2436 | dw2_instantiate_symtab (objfile, per_cu); |
| 2437 | } |
| 2438 | } |
| 2439 | |
| 2440 | static void |
| 2441 | dw2_expand_symtabs_with_filename (struct objfile *objfile, |
| 2442 | const char *filename) |
| 2443 | { |
| 2444 | int i; |
| 2445 | |
| 2446 | dw2_setup (objfile); |
| 2447 | |
| 2448 | /* We don't need to consider type units here. |
| 2449 | This is only called for examining code, e.g. expand_line_sal. |
| 2450 | There can be an order of magnitude (or more) more type units |
| 2451 | than comp units, and we avoid them if we can. */ |
| 2452 | |
| 2453 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 2454 | { |
| 2455 | int j; |
| 2456 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2457 | struct quick_file_names *file_data; |
| 2458 | |
| 2459 | if (per_cu->v.quick->symtab) |
| 2460 | continue; |
| 2461 | |
| 2462 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2463 | if (file_data == NULL) |
| 2464 | continue; |
| 2465 | |
| 2466 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2467 | { |
| 2468 | const char *this_name = file_data->file_names[j]; |
| 2469 | if (FILENAME_CMP (this_name, filename) == 0) |
| 2470 | { |
| 2471 | dw2_instantiate_symtab (objfile, per_cu); |
| 2472 | break; |
| 2473 | } |
| 2474 | } |
| 2475 | } |
| 2476 | } |
| 2477 | |
| 2478 | static const char * |
| 2479 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
| 2480 | { |
| 2481 | struct dwarf2_per_cu_data *per_cu; |
| 2482 | offset_type *vec; |
| 2483 | struct quick_file_names *file_data; |
| 2484 | |
| 2485 | dw2_setup (objfile); |
| 2486 | |
| 2487 | /* index_table is NULL if OBJF_READNOW. */ |
| 2488 | if (!dwarf2_per_objfile->index_table) |
| 2489 | return NULL; |
| 2490 | |
| 2491 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, |
| 2492 | name, &vec)) |
| 2493 | return NULL; |
| 2494 | |
| 2495 | /* Note that this just looks at the very first one named NAME -- but |
| 2496 | actually we are looking for a function. find_main_filename |
| 2497 | should be rewritten so that it doesn't require a custom hook. It |
| 2498 | could just use the ordinary symbol tables. */ |
| 2499 | /* vec[0] is the length, which must always be >0. */ |
| 2500 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
| 2501 | |
| 2502 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2503 | if (file_data == NULL) |
| 2504 | return NULL; |
| 2505 | |
| 2506 | return file_data->file_names[file_data->num_file_names - 1]; |
| 2507 | } |
| 2508 | |
| 2509 | static void |
| 2510 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
| 2511 | struct objfile *objfile, int global, |
| 2512 | int (*callback) (struct block *, |
| 2513 | struct symbol *, void *), |
| 2514 | void *data, symbol_compare_ftype *match, |
| 2515 | symbol_compare_ftype *ordered_compare) |
| 2516 | { |
| 2517 | /* Currently unimplemented; used for Ada. The function can be called if the |
| 2518 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
| 2519 | does not look for non-Ada symbols this function should just return. */ |
| 2520 | } |
| 2521 | |
| 2522 | static void |
| 2523 | dw2_expand_symtabs_matching (struct objfile *objfile, |
| 2524 | int (*file_matcher) (const char *, void *), |
| 2525 | int (*name_matcher) (const char *, void *), |
| 2526 | domain_enum kind, |
| 2527 | void *data) |
| 2528 | { |
| 2529 | int i; |
| 2530 | offset_type iter; |
| 2531 | struct mapped_index *index; |
| 2532 | |
| 2533 | dw2_setup (objfile); |
| 2534 | |
| 2535 | /* index_table is NULL if OBJF_READNOW. */ |
| 2536 | if (!dwarf2_per_objfile->index_table) |
| 2537 | return; |
| 2538 | index = dwarf2_per_objfile->index_table; |
| 2539 | |
| 2540 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2541 | + dwarf2_per_objfile->n_type_comp_units); ++i) |
| 2542 | { |
| 2543 | int j; |
| 2544 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2545 | struct quick_file_names *file_data; |
| 2546 | |
| 2547 | per_cu->v.quick->mark = 0; |
| 2548 | if (per_cu->v.quick->symtab) |
| 2549 | continue; |
| 2550 | |
| 2551 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2552 | if (file_data == NULL) |
| 2553 | continue; |
| 2554 | |
| 2555 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2556 | { |
| 2557 | if (file_matcher (file_data->file_names[j], data)) |
| 2558 | { |
| 2559 | per_cu->v.quick->mark = 1; |
| 2560 | break; |
| 2561 | } |
| 2562 | } |
| 2563 | } |
| 2564 | |
| 2565 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
| 2566 | { |
| 2567 | offset_type idx = 2 * iter; |
| 2568 | const char *name; |
| 2569 | offset_type *vec, vec_len, vec_idx; |
| 2570 | |
| 2571 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
| 2572 | continue; |
| 2573 | |
| 2574 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
| 2575 | |
| 2576 | if (! (*name_matcher) (name, data)) |
| 2577 | continue; |
| 2578 | |
| 2579 | /* The name was matched, now expand corresponding CUs that were |
| 2580 | marked. */ |
| 2581 | vec = (offset_type *) (index->constant_pool |
| 2582 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
| 2583 | vec_len = MAYBE_SWAP (vec[0]); |
| 2584 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) |
| 2585 | { |
| 2586 | struct dwarf2_per_cu_data *per_cu; |
| 2587 | |
| 2588 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
| 2589 | if (per_cu->v.quick->mark) |
| 2590 | dw2_instantiate_symtab (objfile, per_cu); |
| 2591 | } |
| 2592 | } |
| 2593 | } |
| 2594 | |
| 2595 | static struct symtab * |
| 2596 | dw2_find_pc_sect_symtab (struct objfile *objfile, |
| 2597 | struct minimal_symbol *msymbol, |
| 2598 | CORE_ADDR pc, |
| 2599 | struct obj_section *section, |
| 2600 | int warn_if_readin) |
| 2601 | { |
| 2602 | struct dwarf2_per_cu_data *data; |
| 2603 | |
| 2604 | dw2_setup (objfile); |
| 2605 | |
| 2606 | if (!objfile->psymtabs_addrmap) |
| 2607 | return NULL; |
| 2608 | |
| 2609 | data = addrmap_find (objfile->psymtabs_addrmap, pc); |
| 2610 | if (!data) |
| 2611 | return NULL; |
| 2612 | |
| 2613 | if (warn_if_readin && data->v.quick->symtab) |
| 2614 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
| 2615 | paddress (get_objfile_arch (objfile), pc)); |
| 2616 | |
| 2617 | return dw2_instantiate_symtab (objfile, data); |
| 2618 | } |
| 2619 | |
| 2620 | static void |
| 2621 | dw2_map_symbol_names (struct objfile *objfile, |
| 2622 | void (*fun) (const char *, void *), |
| 2623 | void *data) |
| 2624 | { |
| 2625 | offset_type iter; |
| 2626 | struct mapped_index *index; |
| 2627 | |
| 2628 | dw2_setup (objfile); |
| 2629 | |
| 2630 | /* index_table is NULL if OBJF_READNOW. */ |
| 2631 | if (!dwarf2_per_objfile->index_table) |
| 2632 | return; |
| 2633 | index = dwarf2_per_objfile->index_table; |
| 2634 | |
| 2635 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
| 2636 | { |
| 2637 | offset_type idx = 2 * iter; |
| 2638 | const char *name; |
| 2639 | offset_type *vec, vec_len, vec_idx; |
| 2640 | |
| 2641 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
| 2642 | continue; |
| 2643 | |
| 2644 | name = (index->constant_pool + MAYBE_SWAP (index->symbol_table[idx])); |
| 2645 | |
| 2646 | (*fun) (name, data); |
| 2647 | } |
| 2648 | } |
| 2649 | |
| 2650 | static void |
| 2651 | dw2_map_symbol_filenames (struct objfile *objfile, |
| 2652 | void (*fun) (const char *, const char *, void *), |
| 2653 | void *data) |
| 2654 | { |
| 2655 | int i; |
| 2656 | |
| 2657 | dw2_setup (objfile); |
| 2658 | |
| 2659 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2660 | + dwarf2_per_objfile->n_type_comp_units); ++i) |
| 2661 | { |
| 2662 | int j; |
| 2663 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2664 | struct quick_file_names *file_data; |
| 2665 | |
| 2666 | if (per_cu->v.quick->symtab) |
| 2667 | continue; |
| 2668 | |
| 2669 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2670 | if (file_data == NULL) |
| 2671 | continue; |
| 2672 | |
| 2673 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2674 | { |
| 2675 | const char *this_real_name = dw2_get_real_path (objfile, file_data, |
| 2676 | j); |
| 2677 | (*fun) (file_data->file_names[j], this_real_name, data); |
| 2678 | } |
| 2679 | } |
| 2680 | } |
| 2681 | |
| 2682 | static int |
| 2683 | dw2_has_symbols (struct objfile *objfile) |
| 2684 | { |
| 2685 | return 1; |
| 2686 | } |
| 2687 | |
| 2688 | const struct quick_symbol_functions dwarf2_gdb_index_functions = |
| 2689 | { |
| 2690 | dw2_has_symbols, |
| 2691 | dw2_find_last_source_symtab, |
| 2692 | dw2_forget_cached_source_info, |
| 2693 | dw2_lookup_symtab, |
| 2694 | dw2_lookup_symbol, |
| 2695 | dw2_pre_expand_symtabs_matching, |
| 2696 | dw2_print_stats, |
| 2697 | dw2_dump, |
| 2698 | dw2_relocate, |
| 2699 | dw2_expand_symtabs_for_function, |
| 2700 | dw2_expand_all_symtabs, |
| 2701 | dw2_expand_symtabs_with_filename, |
| 2702 | dw2_find_symbol_file, |
| 2703 | dw2_map_matching_symbols, |
| 2704 | dw2_expand_symtabs_matching, |
| 2705 | dw2_find_pc_sect_symtab, |
| 2706 | dw2_map_symbol_names, |
| 2707 | dw2_map_symbol_filenames |
| 2708 | }; |
| 2709 | |
| 2710 | /* Initialize for reading DWARF for this objfile. Return 0 if this |
| 2711 | file will use psymtabs, or 1 if using the GNU index. */ |
| 2712 | |
| 2713 | int |
| 2714 | dwarf2_initialize_objfile (struct objfile *objfile) |
| 2715 | { |
| 2716 | /* If we're about to read full symbols, don't bother with the |
| 2717 | indices. In this case we also don't care if some other debug |
| 2718 | format is making psymtabs, because they are all about to be |
| 2719 | expanded anyway. */ |
| 2720 | if ((objfile->flags & OBJF_READNOW)) |
| 2721 | { |
| 2722 | int i; |
| 2723 | |
| 2724 | dwarf2_per_objfile->using_index = 1; |
| 2725 | create_all_comp_units (objfile); |
| 2726 | create_debug_types_hash_table (objfile); |
| 2727 | dwarf2_per_objfile->quick_file_names_table = |
| 2728 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); |
| 2729 | |
| 2730 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2731 | + dwarf2_per_objfile->n_type_comp_units); ++i) |
| 2732 | { |
| 2733 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2734 | |
| 2735 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 2736 | struct dwarf2_per_cu_quick_data); |
| 2737 | } |
| 2738 | |
| 2739 | /* Return 1 so that gdb sees the "quick" functions. However, |
| 2740 | these functions will be no-ops because we will have expanded |
| 2741 | all symtabs. */ |
| 2742 | return 1; |
| 2743 | } |
| 2744 | |
| 2745 | if (dwarf2_read_index (objfile)) |
| 2746 | return 1; |
| 2747 | |
| 2748 | dwarf2_build_psymtabs (objfile); |
| 2749 | return 0; |
| 2750 | } |
| 2751 | |
| 2752 | \f |
| 2753 | |
| 2754 | /* Build a partial symbol table. */ |
| 2755 | |
| 2756 | void |
| 2757 | dwarf2_build_psymtabs (struct objfile *objfile) |
| 2758 | { |
| 2759 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
| 2760 | { |
| 2761 | init_psymbol_list (objfile, 1024); |
| 2762 | } |
| 2763 | |
| 2764 | dwarf2_build_psymtabs_hard (objfile); |
| 2765 | } |
| 2766 | |
| 2767 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
| 2768 | |
| 2769 | static inline int |
| 2770 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) |
| 2771 | { |
| 2772 | unsigned int bottom = cu_header->offset; |
| 2773 | unsigned int top = (cu_header->offset |
| 2774 | + cu_header->length |
| 2775 | + cu_header->initial_length_size); |
| 2776 | |
| 2777 | return (offset >= bottom && offset < top); |
| 2778 | } |
| 2779 | |
| 2780 | /* Read in the comp unit header information from the debug_info at info_ptr. |
| 2781 | NOTE: This leaves members offset, first_die_offset to be filled in |
| 2782 | by the caller. */ |
| 2783 | |
| 2784 | static gdb_byte * |
| 2785 | read_comp_unit_head (struct comp_unit_head *cu_header, |
| 2786 | gdb_byte *info_ptr, bfd *abfd) |
| 2787 | { |
| 2788 | int signed_addr; |
| 2789 | unsigned int bytes_read; |
| 2790 | |
| 2791 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); |
| 2792 | cu_header->initial_length_size = bytes_read; |
| 2793 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; |
| 2794 | info_ptr += bytes_read; |
| 2795 | cu_header->version = read_2_bytes (abfd, info_ptr); |
| 2796 | info_ptr += 2; |
| 2797 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
| 2798 | &bytes_read); |
| 2799 | info_ptr += bytes_read; |
| 2800 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
| 2801 | info_ptr += 1; |
| 2802 | signed_addr = bfd_get_sign_extend_vma (abfd); |
| 2803 | if (signed_addr < 0) |
| 2804 | internal_error (__FILE__, __LINE__, |
| 2805 | _("read_comp_unit_head: dwarf from non elf file")); |
| 2806 | cu_header->signed_addr_p = signed_addr; |
| 2807 | |
| 2808 | return info_ptr; |
| 2809 | } |
| 2810 | |
| 2811 | static gdb_byte * |
| 2812 | partial_read_comp_unit_head (struct comp_unit_head *header, gdb_byte *info_ptr, |
| 2813 | gdb_byte *buffer, unsigned int buffer_size, |
| 2814 | bfd *abfd) |
| 2815 | { |
| 2816 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 2817 | |
| 2818 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
| 2819 | |
| 2820 | if (header->version != 2 && header->version != 3 && header->version != 4) |
| 2821 | error (_("Dwarf Error: wrong version in compilation unit header " |
| 2822 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
| 2823 | bfd_get_filename (abfd)); |
| 2824 | |
| 2825 | if (header->abbrev_offset >= dwarf2_per_objfile->abbrev.size) |
| 2826 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
| 2827 | "(offset 0x%lx + 6) [in module %s]"), |
| 2828 | (long) header->abbrev_offset, |
| 2829 | (long) (beg_of_comp_unit - buffer), |
| 2830 | bfd_get_filename (abfd)); |
| 2831 | |
| 2832 | if (beg_of_comp_unit + header->length + header->initial_length_size |
| 2833 | > buffer + buffer_size) |
| 2834 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
| 2835 | "(offset 0x%lx + 0) [in module %s]"), |
| 2836 | (long) header->length, |
| 2837 | (long) (beg_of_comp_unit - buffer), |
| 2838 | bfd_get_filename (abfd)); |
| 2839 | |
| 2840 | return info_ptr; |
| 2841 | } |
| 2842 | |
| 2843 | /* Read in the types comp unit header information from .debug_types entry at |
| 2844 | types_ptr. The result is a pointer to one past the end of the header. */ |
| 2845 | |
| 2846 | static gdb_byte * |
| 2847 | read_type_comp_unit_head (struct comp_unit_head *cu_header, |
| 2848 | ULONGEST *signature, |
| 2849 | gdb_byte *types_ptr, bfd *abfd) |
| 2850 | { |
| 2851 | gdb_byte *initial_types_ptr = types_ptr; |
| 2852 | |
| 2853 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 2854 | &dwarf2_per_objfile->types); |
| 2855 | cu_header->offset = types_ptr - dwarf2_per_objfile->types.buffer; |
| 2856 | |
| 2857 | types_ptr = read_comp_unit_head (cu_header, types_ptr, abfd); |
| 2858 | |
| 2859 | *signature = read_8_bytes (abfd, types_ptr); |
| 2860 | types_ptr += 8; |
| 2861 | types_ptr += cu_header->offset_size; |
| 2862 | cu_header->first_die_offset = types_ptr - initial_types_ptr; |
| 2863 | |
| 2864 | return types_ptr; |
| 2865 | } |
| 2866 | |
| 2867 | /* Allocate a new partial symtab for file named NAME and mark this new |
| 2868 | partial symtab as being an include of PST. */ |
| 2869 | |
| 2870 | static void |
| 2871 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, |
| 2872 | struct objfile *objfile) |
| 2873 | { |
| 2874 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); |
| 2875 | |
| 2876 | subpst->section_offsets = pst->section_offsets; |
| 2877 | subpst->textlow = 0; |
| 2878 | subpst->texthigh = 0; |
| 2879 | |
| 2880 | subpst->dependencies = (struct partial_symtab **) |
| 2881 | obstack_alloc (&objfile->objfile_obstack, |
| 2882 | sizeof (struct partial_symtab *)); |
| 2883 | subpst->dependencies[0] = pst; |
| 2884 | subpst->number_of_dependencies = 1; |
| 2885 | |
| 2886 | subpst->globals_offset = 0; |
| 2887 | subpst->n_global_syms = 0; |
| 2888 | subpst->statics_offset = 0; |
| 2889 | subpst->n_static_syms = 0; |
| 2890 | subpst->symtab = NULL; |
| 2891 | subpst->read_symtab = pst->read_symtab; |
| 2892 | subpst->readin = 0; |
| 2893 | |
| 2894 | /* No private part is necessary for include psymtabs. This property |
| 2895 | can be used to differentiate between such include psymtabs and |
| 2896 | the regular ones. */ |
| 2897 | subpst->read_symtab_private = NULL; |
| 2898 | } |
| 2899 | |
| 2900 | /* Read the Line Number Program data and extract the list of files |
| 2901 | included by the source file represented by PST. Build an include |
| 2902 | partial symtab for each of these included files. */ |
| 2903 | |
| 2904 | static void |
| 2905 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, |
| 2906 | struct die_info *die, |
| 2907 | struct partial_symtab *pst) |
| 2908 | { |
| 2909 | struct objfile *objfile = cu->objfile; |
| 2910 | bfd *abfd = objfile->obfd; |
| 2911 | struct line_header *lh = NULL; |
| 2912 | struct attribute *attr; |
| 2913 | |
| 2914 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 2915 | if (attr) |
| 2916 | { |
| 2917 | unsigned int line_offset = DW_UNSND (attr); |
| 2918 | |
| 2919 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
| 2920 | } |
| 2921 | if (lh == NULL) |
| 2922 | return; /* No linetable, so no includes. */ |
| 2923 | |
| 2924 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
| 2925 | dwarf_decode_lines (lh, pst->dirname, abfd, cu, pst); |
| 2926 | |
| 2927 | free_line_header (lh); |
| 2928 | } |
| 2929 | |
| 2930 | static hashval_t |
| 2931 | hash_type_signature (const void *item) |
| 2932 | { |
| 2933 | const struct signatured_type *type_sig = item; |
| 2934 | |
| 2935 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
| 2936 | return type_sig->signature; |
| 2937 | } |
| 2938 | |
| 2939 | static int |
| 2940 | eq_type_signature (const void *item_lhs, const void *item_rhs) |
| 2941 | { |
| 2942 | const struct signatured_type *lhs = item_lhs; |
| 2943 | const struct signatured_type *rhs = item_rhs; |
| 2944 | |
| 2945 | return lhs->signature == rhs->signature; |
| 2946 | } |
| 2947 | |
| 2948 | /* Allocate a hash table for signatured types. */ |
| 2949 | |
| 2950 | static htab_t |
| 2951 | allocate_signatured_type_table (struct objfile *objfile) |
| 2952 | { |
| 2953 | return htab_create_alloc_ex (41, |
| 2954 | hash_type_signature, |
| 2955 | eq_type_signature, |
| 2956 | NULL, |
| 2957 | &objfile->objfile_obstack, |
| 2958 | hashtab_obstack_allocate, |
| 2959 | dummy_obstack_deallocate); |
| 2960 | } |
| 2961 | |
| 2962 | /* A helper function to add a signatured type CU to a list. */ |
| 2963 | |
| 2964 | static int |
| 2965 | add_signatured_type_cu_to_list (void **slot, void *datum) |
| 2966 | { |
| 2967 | struct signatured_type *sigt = *slot; |
| 2968 | struct dwarf2_per_cu_data ***datap = datum; |
| 2969 | |
| 2970 | **datap = &sigt->per_cu; |
| 2971 | ++*datap; |
| 2972 | |
| 2973 | return 1; |
| 2974 | } |
| 2975 | |
| 2976 | /* Create the hash table of all entries in the .debug_types section. |
| 2977 | The result is zero if there is an error (e.g. missing .debug_types section), |
| 2978 | otherwise non-zero. */ |
| 2979 | |
| 2980 | static int |
| 2981 | create_debug_types_hash_table (struct objfile *objfile) |
| 2982 | { |
| 2983 | gdb_byte *info_ptr; |
| 2984 | htab_t types_htab; |
| 2985 | struct dwarf2_per_cu_data **iter; |
| 2986 | |
| 2987 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
| 2988 | info_ptr = dwarf2_per_objfile->types.buffer; |
| 2989 | |
| 2990 | if (info_ptr == NULL) |
| 2991 | { |
| 2992 | dwarf2_per_objfile->signatured_types = NULL; |
| 2993 | return 0; |
| 2994 | } |
| 2995 | |
| 2996 | types_htab = allocate_signatured_type_table (objfile); |
| 2997 | |
| 2998 | if (dwarf2_die_debug) |
| 2999 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); |
| 3000 | |
| 3001 | while (info_ptr < dwarf2_per_objfile->types.buffer |
| 3002 | + dwarf2_per_objfile->types.size) |
| 3003 | { |
| 3004 | unsigned int offset; |
| 3005 | unsigned int offset_size; |
| 3006 | unsigned int type_offset; |
| 3007 | unsigned int length, initial_length_size; |
| 3008 | unsigned short version; |
| 3009 | ULONGEST signature; |
| 3010 | struct signatured_type *type_sig; |
| 3011 | void **slot; |
| 3012 | gdb_byte *ptr = info_ptr; |
| 3013 | |
| 3014 | offset = ptr - dwarf2_per_objfile->types.buffer; |
| 3015 | |
| 3016 | /* We need to read the type's signature in order to build the hash |
| 3017 | table, but we don't need to read anything else just yet. */ |
| 3018 | |
| 3019 | /* Sanity check to ensure entire cu is present. */ |
| 3020 | length = read_initial_length (objfile->obfd, ptr, &initial_length_size); |
| 3021 | if (ptr + length + initial_length_size |
| 3022 | > dwarf2_per_objfile->types.buffer + dwarf2_per_objfile->types.size) |
| 3023 | { |
| 3024 | complaint (&symfile_complaints, |
| 3025 | _("debug type entry runs off end " |
| 3026 | "of `.debug_types' section, ignored")); |
| 3027 | break; |
| 3028 | } |
| 3029 | |
| 3030 | offset_size = initial_length_size == 4 ? 4 : 8; |
| 3031 | ptr += initial_length_size; |
| 3032 | version = bfd_get_16 (objfile->obfd, ptr); |
| 3033 | ptr += 2; |
| 3034 | ptr += offset_size; /* abbrev offset */ |
| 3035 | ptr += 1; /* address size */ |
| 3036 | signature = bfd_get_64 (objfile->obfd, ptr); |
| 3037 | ptr += 8; |
| 3038 | type_offset = read_offset_1 (objfile->obfd, ptr, offset_size); |
| 3039 | |
| 3040 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); |
| 3041 | memset (type_sig, 0, sizeof (*type_sig)); |
| 3042 | type_sig->signature = signature; |
| 3043 | type_sig->offset = offset; |
| 3044 | type_sig->type_offset = type_offset; |
| 3045 | type_sig->per_cu.objfile = objfile; |
| 3046 | type_sig->per_cu.from_debug_types = 1; |
| 3047 | |
| 3048 | slot = htab_find_slot (types_htab, type_sig, INSERT); |
| 3049 | gdb_assert (slot != NULL); |
| 3050 | *slot = type_sig; |
| 3051 | |
| 3052 | if (dwarf2_die_debug) |
| 3053 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", |
| 3054 | offset, phex (signature, sizeof (signature))); |
| 3055 | |
| 3056 | info_ptr = info_ptr + initial_length_size + length; |
| 3057 | } |
| 3058 | |
| 3059 | dwarf2_per_objfile->signatured_types = types_htab; |
| 3060 | |
| 3061 | dwarf2_per_objfile->n_type_comp_units = htab_elements (types_htab); |
| 3062 | dwarf2_per_objfile->type_comp_units |
| 3063 | = obstack_alloc (&objfile->objfile_obstack, |
| 3064 | dwarf2_per_objfile->n_type_comp_units |
| 3065 | * sizeof (struct dwarf2_per_cu_data *)); |
| 3066 | iter = &dwarf2_per_objfile->type_comp_units[0]; |
| 3067 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_list, &iter); |
| 3068 | gdb_assert (iter - &dwarf2_per_objfile->type_comp_units[0] |
| 3069 | == dwarf2_per_objfile->n_type_comp_units); |
| 3070 | |
| 3071 | return 1; |
| 3072 | } |
| 3073 | |
| 3074 | /* Lookup a signature based type. |
| 3075 | Returns NULL if SIG is not present in the table. */ |
| 3076 | |
| 3077 | static struct signatured_type * |
| 3078 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) |
| 3079 | { |
| 3080 | struct signatured_type find_entry, *entry; |
| 3081 | |
| 3082 | if (dwarf2_per_objfile->signatured_types == NULL) |
| 3083 | { |
| 3084 | complaint (&symfile_complaints, |
| 3085 | _("missing `.debug_types' section for DW_FORM_sig8 die")); |
| 3086 | return 0; |
| 3087 | } |
| 3088 | |
| 3089 | find_entry.signature = sig; |
| 3090 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
| 3091 | return entry; |
| 3092 | } |
| 3093 | |
| 3094 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
| 3095 | |
| 3096 | static void |
| 3097 | init_cu_die_reader (struct die_reader_specs *reader, |
| 3098 | struct dwarf2_cu *cu) |
| 3099 | { |
| 3100 | reader->abfd = cu->objfile->obfd; |
| 3101 | reader->cu = cu; |
| 3102 | if (cu->per_cu->from_debug_types) |
| 3103 | { |
| 3104 | gdb_assert (dwarf2_per_objfile->types.readin); |
| 3105 | reader->buffer = dwarf2_per_objfile->types.buffer; |
| 3106 | } |
| 3107 | else |
| 3108 | { |
| 3109 | gdb_assert (dwarf2_per_objfile->info.readin); |
| 3110 | reader->buffer = dwarf2_per_objfile->info.buffer; |
| 3111 | } |
| 3112 | } |
| 3113 | |
| 3114 | /* Find the base address of the compilation unit for range lists and |
| 3115 | location lists. It will normally be specified by DW_AT_low_pc. |
| 3116 | In DWARF-3 draft 4, the base address could be overridden by |
| 3117 | DW_AT_entry_pc. It's been removed, but GCC still uses this for |
| 3118 | compilation units with discontinuous ranges. */ |
| 3119 | |
| 3120 | static void |
| 3121 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) |
| 3122 | { |
| 3123 | struct attribute *attr; |
| 3124 | |
| 3125 | cu->base_known = 0; |
| 3126 | cu->base_address = 0; |
| 3127 | |
| 3128 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); |
| 3129 | if (attr) |
| 3130 | { |
| 3131 | cu->base_address = DW_ADDR (attr); |
| 3132 | cu->base_known = 1; |
| 3133 | } |
| 3134 | else |
| 3135 | { |
| 3136 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 3137 | if (attr) |
| 3138 | { |
| 3139 | cu->base_address = DW_ADDR (attr); |
| 3140 | cu->base_known = 1; |
| 3141 | } |
| 3142 | } |
| 3143 | } |
| 3144 | |
| 3145 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
| 3146 | to combine the common parts. |
| 3147 | Process a compilation unit for a psymtab. |
| 3148 | BUFFER is a pointer to the beginning of the dwarf section buffer, |
| 3149 | either .debug_info or debug_types. |
| 3150 | INFO_PTR is a pointer to the start of the CU. |
| 3151 | Returns a pointer to the next CU. */ |
| 3152 | |
| 3153 | static gdb_byte * |
| 3154 | process_psymtab_comp_unit (struct objfile *objfile, |
| 3155 | struct dwarf2_per_cu_data *this_cu, |
| 3156 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 3157 | unsigned int buffer_size) |
| 3158 | { |
| 3159 | bfd *abfd = objfile->obfd; |
| 3160 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 3161 | struct die_info *comp_unit_die; |
| 3162 | struct partial_symtab *pst; |
| 3163 | CORE_ADDR baseaddr; |
| 3164 | struct cleanup *back_to_inner; |
| 3165 | struct dwarf2_cu cu; |
| 3166 | int has_children, has_pc_info; |
| 3167 | struct attribute *attr; |
| 3168 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
| 3169 | struct die_reader_specs reader_specs; |
| 3170 | |
| 3171 | init_one_comp_unit (&cu, objfile); |
| 3172 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
| 3173 | |
| 3174 | info_ptr = partial_read_comp_unit_head (&cu.header, info_ptr, |
| 3175 | buffer, buffer_size, |
| 3176 | abfd); |
| 3177 | |
| 3178 | /* Complete the cu_header. */ |
| 3179 | cu.header.offset = beg_of_comp_unit - buffer; |
| 3180 | cu.header.first_die_offset = info_ptr - beg_of_comp_unit; |
| 3181 | |
| 3182 | cu.list_in_scope = &file_symbols; |
| 3183 | |
| 3184 | /* If this compilation unit was already read in, free the |
| 3185 | cached copy in order to read it in again. This is |
| 3186 | necessary because we skipped some symbols when we first |
| 3187 | read in the compilation unit (see load_partial_dies). |
| 3188 | This problem could be avoided, but the benefit is |
| 3189 | unclear. */ |
| 3190 | if (this_cu->cu != NULL) |
| 3191 | free_one_cached_comp_unit (this_cu->cu); |
| 3192 | |
| 3193 | /* Note that this is a pointer to our stack frame, being |
| 3194 | added to a global data structure. It will be cleaned up |
| 3195 | in free_stack_comp_unit when we finish with this |
| 3196 | compilation unit. */ |
| 3197 | this_cu->cu = &cu; |
| 3198 | cu.per_cu = this_cu; |
| 3199 | |
| 3200 | /* Read the abbrevs for this compilation unit into a table. */ |
| 3201 | dwarf2_read_abbrevs (abfd, &cu); |
| 3202 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
| 3203 | |
| 3204 | /* Read the compilation unit die. */ |
| 3205 | if (this_cu->from_debug_types) |
| 3206 | info_ptr += 8 /*signature*/ + cu.header.offset_size; |
| 3207 | init_cu_die_reader (&reader_specs, &cu); |
| 3208 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
| 3209 | &has_children); |
| 3210 | |
| 3211 | if (this_cu->from_debug_types) |
| 3212 | { |
| 3213 | /* offset,length haven't been set yet for type units. */ |
| 3214 | this_cu->offset = cu.header.offset; |
| 3215 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
| 3216 | } |
| 3217 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
| 3218 | { |
| 3219 | info_ptr = (beg_of_comp_unit + cu.header.length |
| 3220 | + cu.header.initial_length_size); |
| 3221 | do_cleanups (back_to_inner); |
| 3222 | return info_ptr; |
| 3223 | } |
| 3224 | |
| 3225 | prepare_one_comp_unit (&cu, comp_unit_die); |
| 3226 | |
| 3227 | /* Allocate a new partial symbol table structure. */ |
| 3228 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
| 3229 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
| 3230 | (attr != NULL) ? DW_STRING (attr) : "", |
| 3231 | /* TEXTLOW and TEXTHIGH are set below. */ |
| 3232 | 0, |
| 3233 | objfile->global_psymbols.next, |
| 3234 | objfile->static_psymbols.next); |
| 3235 | |
| 3236 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
| 3237 | if (attr != NULL) |
| 3238 | pst->dirname = DW_STRING (attr); |
| 3239 | |
| 3240 | pst->read_symtab_private = this_cu; |
| 3241 | |
| 3242 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 3243 | |
| 3244 | /* Store the function that reads in the rest of the symbol table. */ |
| 3245 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
| 3246 | |
| 3247 | this_cu->v.psymtab = pst; |
| 3248 | |
| 3249 | dwarf2_find_base_address (comp_unit_die, &cu); |
| 3250 | |
| 3251 | /* Possibly set the default values of LOWPC and HIGHPC from |
| 3252 | `DW_AT_ranges'. */ |
| 3253 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
| 3254 | &best_highpc, &cu, pst); |
| 3255 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
| 3256 | /* Store the contiguous range if it is not empty; it can be empty for |
| 3257 | CUs with no code. */ |
| 3258 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 3259 | best_lowpc + baseaddr, |
| 3260 | best_highpc + baseaddr - 1, pst); |
| 3261 | |
| 3262 | /* Check if comp unit has_children. |
| 3263 | If so, read the rest of the partial symbols from this comp unit. |
| 3264 | If not, there's no more debug_info for this comp unit. */ |
| 3265 | if (has_children) |
| 3266 | { |
| 3267 | struct partial_die_info *first_die; |
| 3268 | CORE_ADDR lowpc, highpc; |
| 3269 | |
| 3270 | lowpc = ((CORE_ADDR) -1); |
| 3271 | highpc = ((CORE_ADDR) 0); |
| 3272 | |
| 3273 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
| 3274 | |
| 3275 | scan_partial_symbols (first_die, &lowpc, &highpc, |
| 3276 | ! has_pc_info, &cu); |
| 3277 | |
| 3278 | /* If we didn't find a lowpc, set it to highpc to avoid |
| 3279 | complaints from `maint check'. */ |
| 3280 | if (lowpc == ((CORE_ADDR) -1)) |
| 3281 | lowpc = highpc; |
| 3282 | |
| 3283 | /* If the compilation unit didn't have an explicit address range, |
| 3284 | then use the information extracted from its child dies. */ |
| 3285 | if (! has_pc_info) |
| 3286 | { |
| 3287 | best_lowpc = lowpc; |
| 3288 | best_highpc = highpc; |
| 3289 | } |
| 3290 | } |
| 3291 | pst->textlow = best_lowpc + baseaddr; |
| 3292 | pst->texthigh = best_highpc + baseaddr; |
| 3293 | |
| 3294 | pst->n_global_syms = objfile->global_psymbols.next - |
| 3295 | (objfile->global_psymbols.list + pst->globals_offset); |
| 3296 | pst->n_static_syms = objfile->static_psymbols.next - |
| 3297 | (objfile->static_psymbols.list + pst->statics_offset); |
| 3298 | sort_pst_symbols (pst); |
| 3299 | |
| 3300 | info_ptr = (beg_of_comp_unit + cu.header.length |
| 3301 | + cu.header.initial_length_size); |
| 3302 | |
| 3303 | if (this_cu->from_debug_types) |
| 3304 | { |
| 3305 | /* It's not clear we want to do anything with stmt lists here. |
| 3306 | Waiting to see what gcc ultimately does. */ |
| 3307 | } |
| 3308 | else |
| 3309 | { |
| 3310 | /* Get the list of files included in the current compilation unit, |
| 3311 | and build a psymtab for each of them. */ |
| 3312 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
| 3313 | } |
| 3314 | |
| 3315 | do_cleanups (back_to_inner); |
| 3316 | |
| 3317 | return info_ptr; |
| 3318 | } |
| 3319 | |
| 3320 | /* Traversal function for htab_traverse_noresize. |
| 3321 | Process one .debug_types comp-unit. */ |
| 3322 | |
| 3323 | static int |
| 3324 | process_type_comp_unit (void **slot, void *info) |
| 3325 | { |
| 3326 | struct signatured_type *entry = (struct signatured_type *) *slot; |
| 3327 | struct objfile *objfile = (struct objfile *) info; |
| 3328 | struct dwarf2_per_cu_data *this_cu; |
| 3329 | |
| 3330 | this_cu = &entry->per_cu; |
| 3331 | |
| 3332 | gdb_assert (dwarf2_per_objfile->types.readin); |
| 3333 | process_psymtab_comp_unit (objfile, this_cu, |
| 3334 | dwarf2_per_objfile->types.buffer, |
| 3335 | dwarf2_per_objfile->types.buffer + entry->offset, |
| 3336 | dwarf2_per_objfile->types.size); |
| 3337 | |
| 3338 | return 1; |
| 3339 | } |
| 3340 | |
| 3341 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
| 3342 | Build partial symbol tables for the .debug_types comp-units. */ |
| 3343 | |
| 3344 | static void |
| 3345 | build_type_psymtabs (struct objfile *objfile) |
| 3346 | { |
| 3347 | if (! create_debug_types_hash_table (objfile)) |
| 3348 | return; |
| 3349 | |
| 3350 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, |
| 3351 | process_type_comp_unit, objfile); |
| 3352 | } |
| 3353 | |
| 3354 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
| 3355 | |
| 3356 | static void |
| 3357 | psymtabs_addrmap_cleanup (void *o) |
| 3358 | { |
| 3359 | struct objfile *objfile = o; |
| 3360 | |
| 3361 | objfile->psymtabs_addrmap = NULL; |
| 3362 | } |
| 3363 | |
| 3364 | /* Build the partial symbol table by doing a quick pass through the |
| 3365 | .debug_info and .debug_abbrev sections. */ |
| 3366 | |
| 3367 | static void |
| 3368 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
| 3369 | { |
| 3370 | gdb_byte *info_ptr; |
| 3371 | struct cleanup *back_to, *addrmap_cleanup; |
| 3372 | struct obstack temp_obstack; |
| 3373 | |
| 3374 | dwarf2_per_objfile->reading_partial_symbols = 1; |
| 3375 | |
| 3376 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 3377 | info_ptr = dwarf2_per_objfile->info.buffer; |
| 3378 | |
| 3379 | /* Any cached compilation units will be linked by the per-objfile |
| 3380 | read_in_chain. Make sure to free them when we're done. */ |
| 3381 | back_to = make_cleanup (free_cached_comp_units, NULL); |
| 3382 | |
| 3383 | build_type_psymtabs (objfile); |
| 3384 | |
| 3385 | create_all_comp_units (objfile); |
| 3386 | |
| 3387 | /* Create a temporary address map on a temporary obstack. We later |
| 3388 | copy this to the final obstack. */ |
| 3389 | obstack_init (&temp_obstack); |
| 3390 | make_cleanup_obstack_free (&temp_obstack); |
| 3391 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); |
| 3392 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); |
| 3393 | |
| 3394 | /* Since the objects we're extracting from .debug_info vary in |
| 3395 | length, only the individual functions to extract them (like |
| 3396 | read_comp_unit_head and load_partial_die) can really know whether |
| 3397 | the buffer is large enough to hold another complete object. |
| 3398 | |
| 3399 | At the moment, they don't actually check that. If .debug_info |
| 3400 | holds just one extra byte after the last compilation unit's dies, |
| 3401 | then read_comp_unit_head will happily read off the end of the |
| 3402 | buffer. read_partial_die is similarly casual. Those functions |
| 3403 | should be fixed. |
| 3404 | |
| 3405 | For this loop condition, simply checking whether there's any data |
| 3406 | left at all should be sufficient. */ |
| 3407 | |
| 3408 | while (info_ptr < (dwarf2_per_objfile->info.buffer |
| 3409 | + dwarf2_per_objfile->info.size)) |
| 3410 | { |
| 3411 | struct dwarf2_per_cu_data *this_cu; |
| 3412 | |
| 3413 | this_cu = dwarf2_find_comp_unit (info_ptr |
| 3414 | - dwarf2_per_objfile->info.buffer, |
| 3415 | objfile); |
| 3416 | |
| 3417 | info_ptr = process_psymtab_comp_unit (objfile, this_cu, |
| 3418 | dwarf2_per_objfile->info.buffer, |
| 3419 | info_ptr, |
| 3420 | dwarf2_per_objfile->info.size); |
| 3421 | } |
| 3422 | |
| 3423 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, |
| 3424 | &objfile->objfile_obstack); |
| 3425 | discard_cleanups (addrmap_cleanup); |
| 3426 | |
| 3427 | do_cleanups (back_to); |
| 3428 | } |
| 3429 | |
| 3430 | /* Load the partial DIEs for a secondary CU into memory. */ |
| 3431 | |
| 3432 | static void |
| 3433 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu, |
| 3434 | struct objfile *objfile) |
| 3435 | { |
| 3436 | bfd *abfd = objfile->obfd; |
| 3437 | gdb_byte *info_ptr, *beg_of_comp_unit; |
| 3438 | struct die_info *comp_unit_die; |
| 3439 | struct dwarf2_cu *cu; |
| 3440 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
| 3441 | int has_children; |
| 3442 | struct die_reader_specs reader_specs; |
| 3443 | int read_cu = 0; |
| 3444 | |
| 3445 | gdb_assert (! this_cu->from_debug_types); |
| 3446 | |
| 3447 | gdb_assert (dwarf2_per_objfile->info.readin); |
| 3448 | info_ptr = dwarf2_per_objfile->info.buffer + this_cu->offset; |
| 3449 | beg_of_comp_unit = info_ptr; |
| 3450 | |
| 3451 | if (this_cu->cu == NULL) |
| 3452 | { |
| 3453 | cu = xmalloc (sizeof (*cu)); |
| 3454 | init_one_comp_unit (cu, objfile); |
| 3455 | |
| 3456 | read_cu = 1; |
| 3457 | |
| 3458 | /* If an error occurs while loading, release our storage. */ |
| 3459 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); |
| 3460 | |
| 3461 | info_ptr = partial_read_comp_unit_head (&cu->header, info_ptr, |
| 3462 | dwarf2_per_objfile->info.buffer, |
| 3463 | dwarf2_per_objfile->info.size, |
| 3464 | abfd); |
| 3465 | |
| 3466 | /* Complete the cu_header. */ |
| 3467 | cu->header.offset = this_cu->offset; |
| 3468 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
| 3469 | |
| 3470 | /* Link this compilation unit into the compilation unit tree. */ |
| 3471 | this_cu->cu = cu; |
| 3472 | cu->per_cu = this_cu; |
| 3473 | |
| 3474 | /* Link this CU into read_in_chain. */ |
| 3475 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 3476 | dwarf2_per_objfile->read_in_chain = this_cu; |
| 3477 | } |
| 3478 | else |
| 3479 | { |
| 3480 | cu = this_cu->cu; |
| 3481 | info_ptr += cu->header.first_die_offset; |
| 3482 | } |
| 3483 | |
| 3484 | /* Read the abbrevs for this compilation unit into a table. */ |
| 3485 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
| 3486 | dwarf2_read_abbrevs (abfd, cu); |
| 3487 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 3488 | |
| 3489 | /* Read the compilation unit die. */ |
| 3490 | init_cu_die_reader (&reader_specs, cu); |
| 3491 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
| 3492 | &has_children); |
| 3493 | |
| 3494 | prepare_one_comp_unit (cu, comp_unit_die); |
| 3495 | |
| 3496 | /* Check if comp unit has_children. |
| 3497 | If so, read the rest of the partial symbols from this comp unit. |
| 3498 | If not, there's no more debug_info for this comp unit. */ |
| 3499 | if (has_children) |
| 3500 | load_partial_dies (abfd, dwarf2_per_objfile->info.buffer, info_ptr, 0, cu); |
| 3501 | |
| 3502 | do_cleanups (free_abbrevs_cleanup); |
| 3503 | |
| 3504 | if (read_cu) |
| 3505 | { |
| 3506 | /* We've successfully allocated this compilation unit. Let our |
| 3507 | caller clean it up when finished with it. */ |
| 3508 | discard_cleanups (free_cu_cleanup); |
| 3509 | } |
| 3510 | } |
| 3511 | |
| 3512 | /* Create a list of all compilation units in OBJFILE. We do this only |
| 3513 | if an inter-comp-unit reference is found; presumably if there is one, |
| 3514 | there will be many, and one will occur early in the .debug_info section. |
| 3515 | So there's no point in building this list incrementally. */ |
| 3516 | |
| 3517 | static void |
| 3518 | create_all_comp_units (struct objfile *objfile) |
| 3519 | { |
| 3520 | int n_allocated; |
| 3521 | int n_comp_units; |
| 3522 | struct dwarf2_per_cu_data **all_comp_units; |
| 3523 | gdb_byte *info_ptr; |
| 3524 | |
| 3525 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 3526 | info_ptr = dwarf2_per_objfile->info.buffer; |
| 3527 | |
| 3528 | n_comp_units = 0; |
| 3529 | n_allocated = 10; |
| 3530 | all_comp_units = xmalloc (n_allocated |
| 3531 | * sizeof (struct dwarf2_per_cu_data *)); |
| 3532 | |
| 3533 | while (info_ptr < dwarf2_per_objfile->info.buffer |
| 3534 | + dwarf2_per_objfile->info.size) |
| 3535 | { |
| 3536 | unsigned int length, initial_length_size; |
| 3537 | struct dwarf2_per_cu_data *this_cu; |
| 3538 | unsigned int offset; |
| 3539 | |
| 3540 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
| 3541 | |
| 3542 | /* Read just enough information to find out where the next |
| 3543 | compilation unit is. */ |
| 3544 | length = read_initial_length (objfile->obfd, info_ptr, |
| 3545 | &initial_length_size); |
| 3546 | |
| 3547 | /* Save the compilation unit for later lookup. */ |
| 3548 | this_cu = obstack_alloc (&objfile->objfile_obstack, |
| 3549 | sizeof (struct dwarf2_per_cu_data)); |
| 3550 | memset (this_cu, 0, sizeof (*this_cu)); |
| 3551 | this_cu->offset = offset; |
| 3552 | this_cu->length = length + initial_length_size; |
| 3553 | this_cu->objfile = objfile; |
| 3554 | |
| 3555 | if (n_comp_units == n_allocated) |
| 3556 | { |
| 3557 | n_allocated *= 2; |
| 3558 | all_comp_units = xrealloc (all_comp_units, |
| 3559 | n_allocated |
| 3560 | * sizeof (struct dwarf2_per_cu_data *)); |
| 3561 | } |
| 3562 | all_comp_units[n_comp_units++] = this_cu; |
| 3563 | |
| 3564 | info_ptr = info_ptr + this_cu->length; |
| 3565 | } |
| 3566 | |
| 3567 | dwarf2_per_objfile->all_comp_units |
| 3568 | = obstack_alloc (&objfile->objfile_obstack, |
| 3569 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); |
| 3570 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, |
| 3571 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); |
| 3572 | xfree (all_comp_units); |
| 3573 | dwarf2_per_objfile->n_comp_units = n_comp_units; |
| 3574 | } |
| 3575 | |
| 3576 | /* Process all loaded DIEs for compilation unit CU, starting at |
| 3577 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation |
| 3578 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or |
| 3579 | DW_AT_ranges). If NEED_PC is set, then this function will set |
| 3580 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU |
| 3581 | and record the covered ranges in the addrmap. */ |
| 3582 | |
| 3583 | static void |
| 3584 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, |
| 3585 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
| 3586 | { |
| 3587 | struct partial_die_info *pdi; |
| 3588 | |
| 3589 | /* Now, march along the PDI's, descending into ones which have |
| 3590 | interesting children but skipping the children of the other ones, |
| 3591 | until we reach the end of the compilation unit. */ |
| 3592 | |
| 3593 | pdi = first_die; |
| 3594 | |
| 3595 | while (pdi != NULL) |
| 3596 | { |
| 3597 | fixup_partial_die (pdi, cu); |
| 3598 | |
| 3599 | /* Anonymous namespaces or modules have no name but have interesting |
| 3600 | children, so we need to look at them. Ditto for anonymous |
| 3601 | enums. */ |
| 3602 | |
| 3603 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
| 3604 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
| 3605 | { |
| 3606 | switch (pdi->tag) |
| 3607 | { |
| 3608 | case DW_TAG_subprogram: |
| 3609 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
| 3610 | break; |
| 3611 | case DW_TAG_constant: |
| 3612 | case DW_TAG_variable: |
| 3613 | case DW_TAG_typedef: |
| 3614 | case DW_TAG_union_type: |
| 3615 | if (!pdi->is_declaration) |
| 3616 | { |
| 3617 | add_partial_symbol (pdi, cu); |
| 3618 | } |
| 3619 | break; |
| 3620 | case DW_TAG_class_type: |
| 3621 | case DW_TAG_interface_type: |
| 3622 | case DW_TAG_structure_type: |
| 3623 | if (!pdi->is_declaration) |
| 3624 | { |
| 3625 | add_partial_symbol (pdi, cu); |
| 3626 | } |
| 3627 | break; |
| 3628 | case DW_TAG_enumeration_type: |
| 3629 | if (!pdi->is_declaration) |
| 3630 | add_partial_enumeration (pdi, cu); |
| 3631 | break; |
| 3632 | case DW_TAG_base_type: |
| 3633 | case DW_TAG_subrange_type: |
| 3634 | /* File scope base type definitions are added to the partial |
| 3635 | symbol table. */ |
| 3636 | add_partial_symbol (pdi, cu); |
| 3637 | break; |
| 3638 | case DW_TAG_namespace: |
| 3639 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
| 3640 | break; |
| 3641 | case DW_TAG_module: |
| 3642 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); |
| 3643 | break; |
| 3644 | default: |
| 3645 | break; |
| 3646 | } |
| 3647 | } |
| 3648 | |
| 3649 | /* If the die has a sibling, skip to the sibling. */ |
| 3650 | |
| 3651 | pdi = pdi->die_sibling; |
| 3652 | } |
| 3653 | } |
| 3654 | |
| 3655 | /* Functions used to compute the fully scoped name of a partial DIE. |
| 3656 | |
| 3657 | Normally, this is simple. For C++, the parent DIE's fully scoped |
| 3658 | name is concatenated with "::" and the partial DIE's name. For |
| 3659 | Java, the same thing occurs except that "." is used instead of "::". |
| 3660 | Enumerators are an exception; they use the scope of their parent |
| 3661 | enumeration type, i.e. the name of the enumeration type is not |
| 3662 | prepended to the enumerator. |
| 3663 | |
| 3664 | There are two complexities. One is DW_AT_specification; in this |
| 3665 | case "parent" means the parent of the target of the specification, |
| 3666 | instead of the direct parent of the DIE. The other is compilers |
| 3667 | which do not emit DW_TAG_namespace; in this case we try to guess |
| 3668 | the fully qualified name of structure types from their members' |
| 3669 | linkage names. This must be done using the DIE's children rather |
| 3670 | than the children of any DW_AT_specification target. We only need |
| 3671 | to do this for structures at the top level, i.e. if the target of |
| 3672 | any DW_AT_specification (if any; otherwise the DIE itself) does not |
| 3673 | have a parent. */ |
| 3674 | |
| 3675 | /* Compute the scope prefix associated with PDI's parent, in |
| 3676 | compilation unit CU. The result will be allocated on CU's |
| 3677 | comp_unit_obstack, or a copy of the already allocated PDI->NAME |
| 3678 | field. NULL is returned if no prefix is necessary. */ |
| 3679 | static char * |
| 3680 | partial_die_parent_scope (struct partial_die_info *pdi, |
| 3681 | struct dwarf2_cu *cu) |
| 3682 | { |
| 3683 | char *grandparent_scope; |
| 3684 | struct partial_die_info *parent, *real_pdi; |
| 3685 | |
| 3686 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
| 3687 | then this means the parent of the specification DIE. */ |
| 3688 | |
| 3689 | real_pdi = pdi; |
| 3690 | while (real_pdi->has_specification) |
| 3691 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
| 3692 | |
| 3693 | parent = real_pdi->die_parent; |
| 3694 | if (parent == NULL) |
| 3695 | return NULL; |
| 3696 | |
| 3697 | if (parent->scope_set) |
| 3698 | return parent->scope; |
| 3699 | |
| 3700 | fixup_partial_die (parent, cu); |
| 3701 | |
| 3702 | grandparent_scope = partial_die_parent_scope (parent, cu); |
| 3703 | |
| 3704 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
| 3705 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. |
| 3706 | Work around this problem here. */ |
| 3707 | if (cu->language == language_cplus |
| 3708 | && parent->tag == DW_TAG_namespace |
| 3709 | && strcmp (parent->name, "::") == 0 |
| 3710 | && grandparent_scope == NULL) |
| 3711 | { |
| 3712 | parent->scope = NULL; |
| 3713 | parent->scope_set = 1; |
| 3714 | return NULL; |
| 3715 | } |
| 3716 | |
| 3717 | if (parent->tag == DW_TAG_namespace |
| 3718 | || parent->tag == DW_TAG_module |
| 3719 | || parent->tag == DW_TAG_structure_type |
| 3720 | || parent->tag == DW_TAG_class_type |
| 3721 | || parent->tag == DW_TAG_interface_type |
| 3722 | || parent->tag == DW_TAG_union_type |
| 3723 | || parent->tag == DW_TAG_enumeration_type) |
| 3724 | { |
| 3725 | if (grandparent_scope == NULL) |
| 3726 | parent->scope = parent->name; |
| 3727 | else |
| 3728 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
| 3729 | grandparent_scope, |
| 3730 | parent->name, 0, cu); |
| 3731 | } |
| 3732 | else if (parent->tag == DW_TAG_enumerator) |
| 3733 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
| 3734 | parent->scope = grandparent_scope; |
| 3735 | else |
| 3736 | { |
| 3737 | /* FIXME drow/2004-04-01: What should we be doing with |
| 3738 | function-local names? For partial symbols, we should probably be |
| 3739 | ignoring them. */ |
| 3740 | complaint (&symfile_complaints, |
| 3741 | _("unhandled containing DIE tag %d for DIE at %d"), |
| 3742 | parent->tag, pdi->offset); |
| 3743 | parent->scope = grandparent_scope; |
| 3744 | } |
| 3745 | |
| 3746 | parent->scope_set = 1; |
| 3747 | return parent->scope; |
| 3748 | } |
| 3749 | |
| 3750 | /* Return the fully scoped name associated with PDI, from compilation unit |
| 3751 | CU. The result will be allocated with malloc. */ |
| 3752 | static char * |
| 3753 | partial_die_full_name (struct partial_die_info *pdi, |
| 3754 | struct dwarf2_cu *cu) |
| 3755 | { |
| 3756 | char *parent_scope; |
| 3757 | |
| 3758 | /* If this is a template instantiation, we can not work out the |
| 3759 | template arguments from partial DIEs. So, unfortunately, we have |
| 3760 | to go through the full DIEs. At least any work we do building |
| 3761 | types here will be reused if full symbols are loaded later. */ |
| 3762 | if (pdi->has_template_arguments) |
| 3763 | { |
| 3764 | fixup_partial_die (pdi, cu); |
| 3765 | |
| 3766 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) |
| 3767 | { |
| 3768 | struct die_info *die; |
| 3769 | struct attribute attr; |
| 3770 | struct dwarf2_cu *ref_cu = cu; |
| 3771 | |
| 3772 | attr.name = 0; |
| 3773 | attr.form = DW_FORM_ref_addr; |
| 3774 | attr.u.addr = pdi->offset; |
| 3775 | die = follow_die_ref (NULL, &attr, &ref_cu); |
| 3776 | |
| 3777 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); |
| 3778 | } |
| 3779 | } |
| 3780 | |
| 3781 | parent_scope = partial_die_parent_scope (pdi, cu); |
| 3782 | if (parent_scope == NULL) |
| 3783 | return NULL; |
| 3784 | else |
| 3785 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
| 3786 | } |
| 3787 | |
| 3788 | static void |
| 3789 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
| 3790 | { |
| 3791 | struct objfile *objfile = cu->objfile; |
| 3792 | CORE_ADDR addr = 0; |
| 3793 | char *actual_name = NULL; |
| 3794 | const struct partial_symbol *psym = NULL; |
| 3795 | CORE_ADDR baseaddr; |
| 3796 | int built_actual_name = 0; |
| 3797 | |
| 3798 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 3799 | |
| 3800 | actual_name = partial_die_full_name (pdi, cu); |
| 3801 | if (actual_name) |
| 3802 | built_actual_name = 1; |
| 3803 | |
| 3804 | if (actual_name == NULL) |
| 3805 | actual_name = pdi->name; |
| 3806 | |
| 3807 | switch (pdi->tag) |
| 3808 | { |
| 3809 | case DW_TAG_subprogram: |
| 3810 | if (pdi->is_external || cu->language == language_ada) |
| 3811 | { |
| 3812 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
| 3813 | of the global scope. But in Ada, we want to be able to access |
| 3814 | nested procedures globally. So all Ada subprograms are stored |
| 3815 | in the global scope. */ |
| 3816 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
| 3817 | mst_text, objfile); */ |
| 3818 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3819 | built_actual_name, |
| 3820 | VAR_DOMAIN, LOC_BLOCK, |
| 3821 | &objfile->global_psymbols, |
| 3822 | 0, pdi->lowpc + baseaddr, |
| 3823 | cu->language, objfile); |
| 3824 | } |
| 3825 | else |
| 3826 | { |
| 3827 | /*prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
| 3828 | mst_file_text, objfile); */ |
| 3829 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3830 | built_actual_name, |
| 3831 | VAR_DOMAIN, LOC_BLOCK, |
| 3832 | &objfile->static_psymbols, |
| 3833 | 0, pdi->lowpc + baseaddr, |
| 3834 | cu->language, objfile); |
| 3835 | } |
| 3836 | break; |
| 3837 | case DW_TAG_constant: |
| 3838 | { |
| 3839 | struct psymbol_allocation_list *list; |
| 3840 | |
| 3841 | if (pdi->is_external) |
| 3842 | list = &objfile->global_psymbols; |
| 3843 | else |
| 3844 | list = &objfile->static_psymbols; |
| 3845 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3846 | built_actual_name, VAR_DOMAIN, LOC_STATIC, |
| 3847 | list, 0, 0, cu->language, objfile); |
| 3848 | |
| 3849 | } |
| 3850 | break; |
| 3851 | case DW_TAG_variable: |
| 3852 | if (pdi->locdesc) |
| 3853 | addr = decode_locdesc (pdi->locdesc, cu); |
| 3854 | |
| 3855 | if (pdi->locdesc |
| 3856 | && addr == 0 |
| 3857 | && !dwarf2_per_objfile->has_section_at_zero) |
| 3858 | { |
| 3859 | /* A global or static variable may also have been stripped |
| 3860 | out by the linker if unused, in which case its address |
| 3861 | will be nullified; do not add such variables into partial |
| 3862 | symbol table then. */ |
| 3863 | } |
| 3864 | else if (pdi->is_external) |
| 3865 | { |
| 3866 | /* Global Variable. |
| 3867 | Don't enter into the minimal symbol tables as there is |
| 3868 | a minimal symbol table entry from the ELF symbols already. |
| 3869 | Enter into partial symbol table if it has a location |
| 3870 | descriptor or a type. |
| 3871 | If the location descriptor is missing, new_symbol will create |
| 3872 | a LOC_UNRESOLVED symbol, the address of the variable will then |
| 3873 | be determined from the minimal symbol table whenever the variable |
| 3874 | is referenced. |
| 3875 | The address for the partial symbol table entry is not |
| 3876 | used by GDB, but it comes in handy for debugging partial symbol |
| 3877 | table building. */ |
| 3878 | |
| 3879 | if (pdi->locdesc || pdi->has_type) |
| 3880 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3881 | built_actual_name, |
| 3882 | VAR_DOMAIN, LOC_STATIC, |
| 3883 | &objfile->global_psymbols, |
| 3884 | 0, addr + baseaddr, |
| 3885 | cu->language, objfile); |
| 3886 | } |
| 3887 | else |
| 3888 | { |
| 3889 | /* Static Variable. Skip symbols without location descriptors. */ |
| 3890 | if (pdi->locdesc == NULL) |
| 3891 | { |
| 3892 | if (built_actual_name) |
| 3893 | xfree (actual_name); |
| 3894 | return; |
| 3895 | } |
| 3896 | /*prim_record_minimal_symbol (actual_name, addr + baseaddr, |
| 3897 | mst_file_data, objfile); */ |
| 3898 | psym = add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3899 | built_actual_name, |
| 3900 | VAR_DOMAIN, LOC_STATIC, |
| 3901 | &objfile->static_psymbols, |
| 3902 | 0, addr + baseaddr, |
| 3903 | cu->language, objfile); |
| 3904 | } |
| 3905 | break; |
| 3906 | case DW_TAG_typedef: |
| 3907 | case DW_TAG_base_type: |
| 3908 | case DW_TAG_subrange_type: |
| 3909 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3910 | built_actual_name, |
| 3911 | VAR_DOMAIN, LOC_TYPEDEF, |
| 3912 | &objfile->static_psymbols, |
| 3913 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 3914 | break; |
| 3915 | case DW_TAG_namespace: |
| 3916 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3917 | built_actual_name, |
| 3918 | VAR_DOMAIN, LOC_TYPEDEF, |
| 3919 | &objfile->global_psymbols, |
| 3920 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 3921 | break; |
| 3922 | case DW_TAG_class_type: |
| 3923 | case DW_TAG_interface_type: |
| 3924 | case DW_TAG_structure_type: |
| 3925 | case DW_TAG_union_type: |
| 3926 | case DW_TAG_enumeration_type: |
| 3927 | /* Skip external references. The DWARF standard says in the section |
| 3928 | about "Structure, Union, and Class Type Entries": "An incomplete |
| 3929 | structure, union or class type is represented by a structure, |
| 3930 | union or class entry that does not have a byte size attribute |
| 3931 | and that has a DW_AT_declaration attribute." */ |
| 3932 | if (!pdi->has_byte_size && pdi->is_declaration) |
| 3933 | { |
| 3934 | if (built_actual_name) |
| 3935 | xfree (actual_name); |
| 3936 | return; |
| 3937 | } |
| 3938 | |
| 3939 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
| 3940 | static vs. global. */ |
| 3941 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3942 | built_actual_name, |
| 3943 | STRUCT_DOMAIN, LOC_TYPEDEF, |
| 3944 | (cu->language == language_cplus |
| 3945 | || cu->language == language_java) |
| 3946 | ? &objfile->global_psymbols |
| 3947 | : &objfile->static_psymbols, |
| 3948 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 3949 | |
| 3950 | break; |
| 3951 | case DW_TAG_enumerator: |
| 3952 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 3953 | built_actual_name, |
| 3954 | VAR_DOMAIN, LOC_CONST, |
| 3955 | (cu->language == language_cplus |
| 3956 | || cu->language == language_java) |
| 3957 | ? &objfile->global_psymbols |
| 3958 | : &objfile->static_psymbols, |
| 3959 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 3960 | break; |
| 3961 | default: |
| 3962 | break; |
| 3963 | } |
| 3964 | |
| 3965 | if (built_actual_name) |
| 3966 | xfree (actual_name); |
| 3967 | } |
| 3968 | |
| 3969 | /* Read a partial die corresponding to a namespace; also, add a symbol |
| 3970 | corresponding to that namespace to the symbol table. NAMESPACE is |
| 3971 | the name of the enclosing namespace. */ |
| 3972 | |
| 3973 | static void |
| 3974 | add_partial_namespace (struct partial_die_info *pdi, |
| 3975 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 3976 | int need_pc, struct dwarf2_cu *cu) |
| 3977 | { |
| 3978 | /* Add a symbol for the namespace. */ |
| 3979 | |
| 3980 | add_partial_symbol (pdi, cu); |
| 3981 | |
| 3982 | /* Now scan partial symbols in that namespace. */ |
| 3983 | |
| 3984 | if (pdi->has_children) |
| 3985 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
| 3986 | } |
| 3987 | |
| 3988 | /* Read a partial die corresponding to a Fortran module. */ |
| 3989 | |
| 3990 | static void |
| 3991 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
| 3992 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
| 3993 | { |
| 3994 | /* Now scan partial symbols in that module. */ |
| 3995 | |
| 3996 | if (pdi->has_children) |
| 3997 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
| 3998 | } |
| 3999 | |
| 4000 | /* Read a partial die corresponding to a subprogram and create a partial |
| 4001 | symbol for that subprogram. When the CU language allows it, this |
| 4002 | routine also defines a partial symbol for each nested subprogram |
| 4003 | that this subprogram contains. |
| 4004 | |
| 4005 | DIE my also be a lexical block, in which case we simply search |
| 4006 | recursively for suprograms defined inside that lexical block. |
| 4007 | Again, this is only performed when the CU language allows this |
| 4008 | type of definitions. */ |
| 4009 | |
| 4010 | static void |
| 4011 | add_partial_subprogram (struct partial_die_info *pdi, |
| 4012 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 4013 | int need_pc, struct dwarf2_cu *cu) |
| 4014 | { |
| 4015 | if (pdi->tag == DW_TAG_subprogram) |
| 4016 | { |
| 4017 | if (pdi->has_pc_info) |
| 4018 | { |
| 4019 | if (pdi->lowpc < *lowpc) |
| 4020 | *lowpc = pdi->lowpc; |
| 4021 | if (pdi->highpc > *highpc) |
| 4022 | *highpc = pdi->highpc; |
| 4023 | if (need_pc) |
| 4024 | { |
| 4025 | CORE_ADDR baseaddr; |
| 4026 | struct objfile *objfile = cu->objfile; |
| 4027 | |
| 4028 | baseaddr = ANOFFSET (objfile->section_offsets, |
| 4029 | SECT_OFF_TEXT (objfile)); |
| 4030 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 4031 | pdi->lowpc + baseaddr, |
| 4032 | pdi->highpc - 1 + baseaddr, |
| 4033 | cu->per_cu->v.psymtab); |
| 4034 | } |
| 4035 | if (!pdi->is_declaration) |
| 4036 | /* Ignore subprogram DIEs that do not have a name, they are |
| 4037 | illegal. Do not emit a complaint at this point, we will |
| 4038 | do so when we convert this psymtab into a symtab. */ |
| 4039 | if (pdi->name) |
| 4040 | add_partial_symbol (pdi, cu); |
| 4041 | } |
| 4042 | } |
| 4043 | |
| 4044 | if (! pdi->has_children) |
| 4045 | return; |
| 4046 | |
| 4047 | if (cu->language == language_ada) |
| 4048 | { |
| 4049 | pdi = pdi->die_child; |
| 4050 | while (pdi != NULL) |
| 4051 | { |
| 4052 | fixup_partial_die (pdi, cu); |
| 4053 | if (pdi->tag == DW_TAG_subprogram |
| 4054 | || pdi->tag == DW_TAG_lexical_block) |
| 4055 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
| 4056 | pdi = pdi->die_sibling; |
| 4057 | } |
| 4058 | } |
| 4059 | } |
| 4060 | |
| 4061 | /* Read a partial die corresponding to an enumeration type. */ |
| 4062 | |
| 4063 | static void |
| 4064 | add_partial_enumeration (struct partial_die_info *enum_pdi, |
| 4065 | struct dwarf2_cu *cu) |
| 4066 | { |
| 4067 | struct partial_die_info *pdi; |
| 4068 | |
| 4069 | if (enum_pdi->name != NULL) |
| 4070 | add_partial_symbol (enum_pdi, cu); |
| 4071 | |
| 4072 | pdi = enum_pdi->die_child; |
| 4073 | while (pdi) |
| 4074 | { |
| 4075 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
| 4076 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
| 4077 | else |
| 4078 | add_partial_symbol (pdi, cu); |
| 4079 | pdi = pdi->die_sibling; |
| 4080 | } |
| 4081 | } |
| 4082 | |
| 4083 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
| 4084 | Return the corresponding abbrev, or NULL if the number is zero (indicating |
| 4085 | an empty DIE). In either case *BYTES_READ will be set to the length of |
| 4086 | the initial number. */ |
| 4087 | |
| 4088 | static struct abbrev_info * |
| 4089 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
| 4090 | struct dwarf2_cu *cu) |
| 4091 | { |
| 4092 | bfd *abfd = cu->objfile->obfd; |
| 4093 | unsigned int abbrev_number; |
| 4094 | struct abbrev_info *abbrev; |
| 4095 | |
| 4096 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); |
| 4097 | |
| 4098 | if (abbrev_number == 0) |
| 4099 | return NULL; |
| 4100 | |
| 4101 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
| 4102 | if (!abbrev) |
| 4103 | { |
| 4104 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
| 4105 | abbrev_number, bfd_get_filename (abfd)); |
| 4106 | } |
| 4107 | |
| 4108 | return abbrev; |
| 4109 | } |
| 4110 | |
| 4111 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
| 4112 | Returns a pointer to the end of a series of DIEs, terminated by an empty |
| 4113 | DIE. Any children of the skipped DIEs will also be skipped. */ |
| 4114 | |
| 4115 | static gdb_byte * |
| 4116 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
| 4117 | { |
| 4118 | struct abbrev_info *abbrev; |
| 4119 | unsigned int bytes_read; |
| 4120 | |
| 4121 | while (1) |
| 4122 | { |
| 4123 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); |
| 4124 | if (abbrev == NULL) |
| 4125 | return info_ptr + bytes_read; |
| 4126 | else |
| 4127 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
| 4128 | } |
| 4129 | } |
| 4130 | |
| 4131 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
| 4132 | INFO_PTR should point just after the initial uleb128 of a DIE, and the |
| 4133 | abbrev corresponding to that skipped uleb128 should be passed in |
| 4134 | ABBREV. Returns a pointer to this DIE's sibling, skipping any |
| 4135 | children. */ |
| 4136 | |
| 4137 | static gdb_byte * |
| 4138 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
| 4139 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) |
| 4140 | { |
| 4141 | unsigned int bytes_read; |
| 4142 | struct attribute attr; |
| 4143 | bfd *abfd = cu->objfile->obfd; |
| 4144 | unsigned int form, i; |
| 4145 | |
| 4146 | for (i = 0; i < abbrev->num_attrs; i++) |
| 4147 | { |
| 4148 | /* The only abbrev we care about is DW_AT_sibling. */ |
| 4149 | if (abbrev->attrs[i].name == DW_AT_sibling) |
| 4150 | { |
| 4151 | read_attribute (&attr, &abbrev->attrs[i], |
| 4152 | abfd, info_ptr, cu); |
| 4153 | if (attr.form == DW_FORM_ref_addr) |
| 4154 | complaint (&symfile_complaints, |
| 4155 | _("ignoring absolute DW_AT_sibling")); |
| 4156 | else |
| 4157 | return buffer + dwarf2_get_ref_die_offset (&attr); |
| 4158 | } |
| 4159 | |
| 4160 | /* If it isn't DW_AT_sibling, skip this attribute. */ |
| 4161 | form = abbrev->attrs[i].form; |
| 4162 | skip_attribute: |
| 4163 | switch (form) |
| 4164 | { |
| 4165 | case DW_FORM_ref_addr: |
| 4166 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
| 4167 | and later it is offset sized. */ |
| 4168 | if (cu->header.version == 2) |
| 4169 | info_ptr += cu->header.addr_size; |
| 4170 | else |
| 4171 | info_ptr += cu->header.offset_size; |
| 4172 | break; |
| 4173 | case DW_FORM_addr: |
| 4174 | info_ptr += cu->header.addr_size; |
| 4175 | break; |
| 4176 | case DW_FORM_data1: |
| 4177 | case DW_FORM_ref1: |
| 4178 | case DW_FORM_flag: |
| 4179 | info_ptr += 1; |
| 4180 | break; |
| 4181 | case DW_FORM_flag_present: |
| 4182 | break; |
| 4183 | case DW_FORM_data2: |
| 4184 | case DW_FORM_ref2: |
| 4185 | info_ptr += 2; |
| 4186 | break; |
| 4187 | case DW_FORM_data4: |
| 4188 | case DW_FORM_ref4: |
| 4189 | info_ptr += 4; |
| 4190 | break; |
| 4191 | case DW_FORM_data8: |
| 4192 | case DW_FORM_ref8: |
| 4193 | case DW_FORM_sig8: |
| 4194 | info_ptr += 8; |
| 4195 | break; |
| 4196 | case DW_FORM_string: |
| 4197 | read_direct_string (abfd, info_ptr, &bytes_read); |
| 4198 | info_ptr += bytes_read; |
| 4199 | break; |
| 4200 | case DW_FORM_sec_offset: |
| 4201 | case DW_FORM_strp: |
| 4202 | info_ptr += cu->header.offset_size; |
| 4203 | break; |
| 4204 | case DW_FORM_exprloc: |
| 4205 | case DW_FORM_block: |
| 4206 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4207 | info_ptr += bytes_read; |
| 4208 | break; |
| 4209 | case DW_FORM_block1: |
| 4210 | info_ptr += 1 + read_1_byte (abfd, info_ptr); |
| 4211 | break; |
| 4212 | case DW_FORM_block2: |
| 4213 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); |
| 4214 | break; |
| 4215 | case DW_FORM_block4: |
| 4216 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); |
| 4217 | break; |
| 4218 | case DW_FORM_sdata: |
| 4219 | case DW_FORM_udata: |
| 4220 | case DW_FORM_ref_udata: |
| 4221 | info_ptr = skip_leb128 (abfd, info_ptr); |
| 4222 | break; |
| 4223 | case DW_FORM_indirect: |
| 4224 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4225 | info_ptr += bytes_read; |
| 4226 | /* We need to continue parsing from here, so just go back to |
| 4227 | the top. */ |
| 4228 | goto skip_attribute; |
| 4229 | |
| 4230 | default: |
| 4231 | error (_("Dwarf Error: Cannot handle %s " |
| 4232 | "in DWARF reader [in module %s]"), |
| 4233 | dwarf_form_name (form), |
| 4234 | bfd_get_filename (abfd)); |
| 4235 | } |
| 4236 | } |
| 4237 | |
| 4238 | if (abbrev->has_children) |
| 4239 | return skip_children (buffer, info_ptr, cu); |
| 4240 | else |
| 4241 | return info_ptr; |
| 4242 | } |
| 4243 | |
| 4244 | /* Locate ORIG_PDI's sibling. |
| 4245 | INFO_PTR should point to the start of the next DIE after ORIG_PDI |
| 4246 | in BUFFER. */ |
| 4247 | |
| 4248 | static gdb_byte * |
| 4249 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
| 4250 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 4251 | bfd *abfd, struct dwarf2_cu *cu) |
| 4252 | { |
| 4253 | /* Do we know the sibling already? */ |
| 4254 | |
| 4255 | if (orig_pdi->sibling) |
| 4256 | return orig_pdi->sibling; |
| 4257 | |
| 4258 | /* Are there any children to deal with? */ |
| 4259 | |
| 4260 | if (!orig_pdi->has_children) |
| 4261 | return info_ptr; |
| 4262 | |
| 4263 | /* Skip the children the long way. */ |
| 4264 | |
| 4265 | return skip_children (buffer, info_ptr, cu); |
| 4266 | } |
| 4267 | |
| 4268 | /* Expand this partial symbol table into a full symbol table. */ |
| 4269 | |
| 4270 | static void |
| 4271 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
| 4272 | { |
| 4273 | if (pst != NULL) |
| 4274 | { |
| 4275 | if (pst->readin) |
| 4276 | { |
| 4277 | warning (_("bug: psymtab for %s is already read in."), |
| 4278 | pst->filename); |
| 4279 | } |
| 4280 | else |
| 4281 | { |
| 4282 | if (info_verbose) |
| 4283 | { |
| 4284 | printf_filtered (_("Reading in symbols for %s..."), |
| 4285 | pst->filename); |
| 4286 | gdb_flush (gdb_stdout); |
| 4287 | } |
| 4288 | |
| 4289 | /* Restore our global data. */ |
| 4290 | dwarf2_per_objfile = objfile_data (pst->objfile, |
| 4291 | dwarf2_objfile_data_key); |
| 4292 | |
| 4293 | /* If this psymtab is constructed from a debug-only objfile, the |
| 4294 | has_section_at_zero flag will not necessarily be correct. We |
| 4295 | can get the correct value for this flag by looking at the data |
| 4296 | associated with the (presumably stripped) associated objfile. */ |
| 4297 | if (pst->objfile->separate_debug_objfile_backlink) |
| 4298 | { |
| 4299 | struct dwarf2_per_objfile *dpo_backlink |
| 4300 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, |
| 4301 | dwarf2_objfile_data_key); |
| 4302 | |
| 4303 | dwarf2_per_objfile->has_section_at_zero |
| 4304 | = dpo_backlink->has_section_at_zero; |
| 4305 | } |
| 4306 | |
| 4307 | dwarf2_per_objfile->reading_partial_symbols = 0; |
| 4308 | |
| 4309 | psymtab_to_symtab_1 (pst); |
| 4310 | |
| 4311 | /* Finish up the debug error message. */ |
| 4312 | if (info_verbose) |
| 4313 | printf_filtered (_("done.\n")); |
| 4314 | } |
| 4315 | } |
| 4316 | } |
| 4317 | |
| 4318 | /* Add PER_CU to the queue. */ |
| 4319 | |
| 4320 | static void |
| 4321 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, struct objfile *objfile) |
| 4322 | { |
| 4323 | struct dwarf2_queue_item *item; |
| 4324 | |
| 4325 | per_cu->queued = 1; |
| 4326 | item = xmalloc (sizeof (*item)); |
| 4327 | item->per_cu = per_cu; |
| 4328 | item->next = NULL; |
| 4329 | |
| 4330 | if (dwarf2_queue == NULL) |
| 4331 | dwarf2_queue = item; |
| 4332 | else |
| 4333 | dwarf2_queue_tail->next = item; |
| 4334 | |
| 4335 | dwarf2_queue_tail = item; |
| 4336 | } |
| 4337 | |
| 4338 | /* Process the queue. */ |
| 4339 | |
| 4340 | static void |
| 4341 | process_queue (struct objfile *objfile) |
| 4342 | { |
| 4343 | struct dwarf2_queue_item *item, *next_item; |
| 4344 | |
| 4345 | /* The queue starts out with one item, but following a DIE reference |
| 4346 | may load a new CU, adding it to the end of the queue. */ |
| 4347 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
| 4348 | { |
| 4349 | if (dwarf2_per_objfile->using_index |
| 4350 | ? !item->per_cu->v.quick->symtab |
| 4351 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) |
| 4352 | process_full_comp_unit (item->per_cu); |
| 4353 | |
| 4354 | item->per_cu->queued = 0; |
| 4355 | next_item = item->next; |
| 4356 | xfree (item); |
| 4357 | } |
| 4358 | |
| 4359 | dwarf2_queue_tail = NULL; |
| 4360 | } |
| 4361 | |
| 4362 | /* Free all allocated queue entries. This function only releases anything if |
| 4363 | an error was thrown; if the queue was processed then it would have been |
| 4364 | freed as we went along. */ |
| 4365 | |
| 4366 | static void |
| 4367 | dwarf2_release_queue (void *dummy) |
| 4368 | { |
| 4369 | struct dwarf2_queue_item *item, *last; |
| 4370 | |
| 4371 | item = dwarf2_queue; |
| 4372 | while (item) |
| 4373 | { |
| 4374 | /* Anything still marked queued is likely to be in an |
| 4375 | inconsistent state, so discard it. */ |
| 4376 | if (item->per_cu->queued) |
| 4377 | { |
| 4378 | if (item->per_cu->cu != NULL) |
| 4379 | free_one_cached_comp_unit (item->per_cu->cu); |
| 4380 | item->per_cu->queued = 0; |
| 4381 | } |
| 4382 | |
| 4383 | last = item; |
| 4384 | item = item->next; |
| 4385 | xfree (last); |
| 4386 | } |
| 4387 | |
| 4388 | dwarf2_queue = dwarf2_queue_tail = NULL; |
| 4389 | } |
| 4390 | |
| 4391 | /* Read in full symbols for PST, and anything it depends on. */ |
| 4392 | |
| 4393 | static void |
| 4394 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
| 4395 | { |
| 4396 | struct dwarf2_per_cu_data *per_cu; |
| 4397 | struct cleanup *back_to; |
| 4398 | int i; |
| 4399 | |
| 4400 | for (i = 0; i < pst->number_of_dependencies; i++) |
| 4401 | if (!pst->dependencies[i]->readin) |
| 4402 | { |
| 4403 | /* Inform about additional files that need to be read in. */ |
| 4404 | if (info_verbose) |
| 4405 | { |
| 4406 | /* FIXME: i18n: Need to make this a single string. */ |
| 4407 | fputs_filtered (" ", gdb_stdout); |
| 4408 | wrap_here (""); |
| 4409 | fputs_filtered ("and ", gdb_stdout); |
| 4410 | wrap_here (""); |
| 4411 | printf_filtered ("%s...", pst->dependencies[i]->filename); |
| 4412 | wrap_here (""); /* Flush output. */ |
| 4413 | gdb_flush (gdb_stdout); |
| 4414 | } |
| 4415 | psymtab_to_symtab_1 (pst->dependencies[i]); |
| 4416 | } |
| 4417 | |
| 4418 | per_cu = pst->read_symtab_private; |
| 4419 | |
| 4420 | if (per_cu == NULL) |
| 4421 | { |
| 4422 | /* It's an include file, no symbols to read for it. |
| 4423 | Everything is in the parent symtab. */ |
| 4424 | pst->readin = 1; |
| 4425 | return; |
| 4426 | } |
| 4427 | |
| 4428 | dw2_do_instantiate_symtab (pst->objfile, per_cu); |
| 4429 | } |
| 4430 | |
| 4431 | /* Load the DIEs associated with PER_CU into memory. */ |
| 4432 | |
| 4433 | static void |
| 4434 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
| 4435 | struct objfile *objfile) |
| 4436 | { |
| 4437 | bfd *abfd = objfile->obfd; |
| 4438 | struct dwarf2_cu *cu; |
| 4439 | unsigned int offset; |
| 4440 | gdb_byte *info_ptr, *beg_of_comp_unit; |
| 4441 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
| 4442 | struct attribute *attr; |
| 4443 | int read_cu = 0; |
| 4444 | |
| 4445 | gdb_assert (! per_cu->from_debug_types); |
| 4446 | |
| 4447 | /* Set local variables from the partial symbol table info. */ |
| 4448 | offset = per_cu->offset; |
| 4449 | |
| 4450 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 4451 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
| 4452 | beg_of_comp_unit = info_ptr; |
| 4453 | |
| 4454 | if (per_cu->cu == NULL) |
| 4455 | { |
| 4456 | cu = xmalloc (sizeof (*cu)); |
| 4457 | init_one_comp_unit (cu, objfile); |
| 4458 | |
| 4459 | read_cu = 1; |
| 4460 | |
| 4461 | /* If an error occurs while loading, release our storage. */ |
| 4462 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); |
| 4463 | |
| 4464 | /* Read in the comp_unit header. */ |
| 4465 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
| 4466 | |
| 4467 | /* Complete the cu_header. */ |
| 4468 | cu->header.offset = offset; |
| 4469 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
| 4470 | |
| 4471 | /* Read the abbrevs for this compilation unit. */ |
| 4472 | dwarf2_read_abbrevs (abfd, cu); |
| 4473 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 4474 | |
| 4475 | /* Link this compilation unit into the compilation unit tree. */ |
| 4476 | per_cu->cu = cu; |
| 4477 | cu->per_cu = per_cu; |
| 4478 | |
| 4479 | /* Link this CU into read_in_chain. */ |
| 4480 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 4481 | dwarf2_per_objfile->read_in_chain = per_cu; |
| 4482 | } |
| 4483 | else |
| 4484 | { |
| 4485 | cu = per_cu->cu; |
| 4486 | info_ptr += cu->header.first_die_offset; |
| 4487 | } |
| 4488 | |
| 4489 | cu->dies = read_comp_unit (info_ptr, cu); |
| 4490 | |
| 4491 | /* We try not to read any attributes in this function, because not |
| 4492 | all objfiles needed for references have been loaded yet, and symbol |
| 4493 | table processing isn't initialized. But we have to set the CU language, |
| 4494 | or we won't be able to build types correctly. */ |
| 4495 | prepare_one_comp_unit (cu, cu->dies); |
| 4496 | |
| 4497 | /* Similarly, if we do not read the producer, we can not apply |
| 4498 | producer-specific interpretation. */ |
| 4499 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); |
| 4500 | if (attr) |
| 4501 | cu->producer = DW_STRING (attr); |
| 4502 | |
| 4503 | if (read_cu) |
| 4504 | { |
| 4505 | do_cleanups (free_abbrevs_cleanup); |
| 4506 | |
| 4507 | /* We've successfully allocated this compilation unit. Let our |
| 4508 | caller clean it up when finished with it. */ |
| 4509 | discard_cleanups (free_cu_cleanup); |
| 4510 | } |
| 4511 | } |
| 4512 | |
| 4513 | /* Add a DIE to the delayed physname list. */ |
| 4514 | |
| 4515 | static void |
| 4516 | add_to_method_list (struct type *type, int fnfield_index, int index, |
| 4517 | const char *name, struct die_info *die, |
| 4518 | struct dwarf2_cu *cu) |
| 4519 | { |
| 4520 | struct delayed_method_info mi; |
| 4521 | mi.type = type; |
| 4522 | mi.fnfield_index = fnfield_index; |
| 4523 | mi.index = index; |
| 4524 | mi.name = name; |
| 4525 | mi.die = die; |
| 4526 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); |
| 4527 | } |
| 4528 | |
| 4529 | /* A cleanup for freeing the delayed method list. */ |
| 4530 | |
| 4531 | static void |
| 4532 | free_delayed_list (void *ptr) |
| 4533 | { |
| 4534 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; |
| 4535 | if (cu->method_list != NULL) |
| 4536 | { |
| 4537 | VEC_free (delayed_method_info, cu->method_list); |
| 4538 | cu->method_list = NULL; |
| 4539 | } |
| 4540 | } |
| 4541 | |
| 4542 | /* Compute the physnames of any methods on the CU's method list. |
| 4543 | |
| 4544 | The computation of method physnames is delayed in order to avoid the |
| 4545 | (bad) condition that one of the method's formal parameters is of an as yet |
| 4546 | incomplete type. */ |
| 4547 | |
| 4548 | static void |
| 4549 | compute_delayed_physnames (struct dwarf2_cu *cu) |
| 4550 | { |
| 4551 | int i; |
| 4552 | struct delayed_method_info *mi; |
| 4553 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) |
| 4554 | { |
| 4555 | char *physname; |
| 4556 | struct fn_fieldlist *fn_flp |
| 4557 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); |
| 4558 | physname = (char *) dwarf2_physname ((char *) mi->name, mi->die, cu); |
| 4559 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
| 4560 | } |
| 4561 | } |
| 4562 | |
| 4563 | /* Generate full symbol information for PST and CU, whose DIEs have |
| 4564 | already been loaded into memory. */ |
| 4565 | |
| 4566 | static void |
| 4567 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) |
| 4568 | { |
| 4569 | struct dwarf2_cu *cu = per_cu->cu; |
| 4570 | struct objfile *objfile = per_cu->objfile; |
| 4571 | CORE_ADDR lowpc, highpc; |
| 4572 | struct symtab *symtab; |
| 4573 | struct cleanup *back_to, *delayed_list_cleanup; |
| 4574 | CORE_ADDR baseaddr; |
| 4575 | |
| 4576 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 4577 | |
| 4578 | buildsym_init (); |
| 4579 | back_to = make_cleanup (really_free_pendings, NULL); |
| 4580 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
| 4581 | |
| 4582 | cu->list_in_scope = &file_symbols; |
| 4583 | |
| 4584 | dwarf2_find_base_address (cu->dies, cu); |
| 4585 | |
| 4586 | /* Do line number decoding in read_file_scope () */ |
| 4587 | process_die (cu->dies, cu); |
| 4588 | |
| 4589 | /* Now that we have processed all the DIEs in the CU, all the types |
| 4590 | should be complete, and it should now be safe to compute all of the |
| 4591 | physnames. */ |
| 4592 | compute_delayed_physnames (cu); |
| 4593 | do_cleanups (delayed_list_cleanup); |
| 4594 | |
| 4595 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
| 4596 | compilation unit. If the DW_AT_high_pc is missing, synthesize |
| 4597 | it, by scanning the DIE's below the compilation unit. */ |
| 4598 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
| 4599 | |
| 4600 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
| 4601 | |
| 4602 | /* Set symtab language to language from DW_AT_language. |
| 4603 | If the compilation is from a C file generated by language preprocessors, |
| 4604 | do not set the language if it was already deduced by start_subfile. */ |
| 4605 | if (symtab != NULL |
| 4606 | && !(cu->language == language_c && symtab->language != language_c)) |
| 4607 | { |
| 4608 | symtab->language = cu->language; |
| 4609 | } |
| 4610 | |
| 4611 | if (dwarf2_per_objfile->using_index) |
| 4612 | per_cu->v.quick->symtab = symtab; |
| 4613 | else |
| 4614 | { |
| 4615 | struct partial_symtab *pst = per_cu->v.psymtab; |
| 4616 | pst->symtab = symtab; |
| 4617 | pst->readin = 1; |
| 4618 | } |
| 4619 | |
| 4620 | do_cleanups (back_to); |
| 4621 | } |
| 4622 | |
| 4623 | /* Process a die and its children. */ |
| 4624 | |
| 4625 | static void |
| 4626 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
| 4627 | { |
| 4628 | switch (die->tag) |
| 4629 | { |
| 4630 | case DW_TAG_padding: |
| 4631 | break; |
| 4632 | case DW_TAG_compile_unit: |
| 4633 | read_file_scope (die, cu); |
| 4634 | break; |
| 4635 | case DW_TAG_type_unit: |
| 4636 | read_type_unit_scope (die, cu); |
| 4637 | break; |
| 4638 | case DW_TAG_subprogram: |
| 4639 | case DW_TAG_inlined_subroutine: |
| 4640 | read_func_scope (die, cu); |
| 4641 | break; |
| 4642 | case DW_TAG_lexical_block: |
| 4643 | case DW_TAG_try_block: |
| 4644 | case DW_TAG_catch_block: |
| 4645 | read_lexical_block_scope (die, cu); |
| 4646 | break; |
| 4647 | case DW_TAG_class_type: |
| 4648 | case DW_TAG_interface_type: |
| 4649 | case DW_TAG_structure_type: |
| 4650 | case DW_TAG_union_type: |
| 4651 | process_structure_scope (die, cu); |
| 4652 | break; |
| 4653 | case DW_TAG_enumeration_type: |
| 4654 | process_enumeration_scope (die, cu); |
| 4655 | break; |
| 4656 | |
| 4657 | /* These dies have a type, but processing them does not create |
| 4658 | a symbol or recurse to process the children. Therefore we can |
| 4659 | read them on-demand through read_type_die. */ |
| 4660 | case DW_TAG_subroutine_type: |
| 4661 | case DW_TAG_set_type: |
| 4662 | case DW_TAG_array_type: |
| 4663 | case DW_TAG_pointer_type: |
| 4664 | case DW_TAG_ptr_to_member_type: |
| 4665 | case DW_TAG_reference_type: |
| 4666 | case DW_TAG_string_type: |
| 4667 | break; |
| 4668 | |
| 4669 | case DW_TAG_base_type: |
| 4670 | case DW_TAG_subrange_type: |
| 4671 | case DW_TAG_typedef: |
| 4672 | /* Add a typedef symbol for the type definition, if it has a |
| 4673 | DW_AT_name. */ |
| 4674 | new_symbol (die, read_type_die (die, cu), cu); |
| 4675 | break; |
| 4676 | case DW_TAG_common_block: |
| 4677 | read_common_block (die, cu); |
| 4678 | break; |
| 4679 | case DW_TAG_common_inclusion: |
| 4680 | break; |
| 4681 | case DW_TAG_namespace: |
| 4682 | processing_has_namespace_info = 1; |
| 4683 | read_namespace (die, cu); |
| 4684 | break; |
| 4685 | case DW_TAG_module: |
| 4686 | processing_has_namespace_info = 1; |
| 4687 | read_module (die, cu); |
| 4688 | break; |
| 4689 | case DW_TAG_imported_declaration: |
| 4690 | case DW_TAG_imported_module: |
| 4691 | processing_has_namespace_info = 1; |
| 4692 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
| 4693 | || cu->language != language_fortran)) |
| 4694 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), |
| 4695 | dwarf_tag_name (die->tag)); |
| 4696 | read_import_statement (die, cu); |
| 4697 | break; |
| 4698 | default: |
| 4699 | new_symbol (die, NULL, cu); |
| 4700 | break; |
| 4701 | } |
| 4702 | } |
| 4703 | |
| 4704 | /* A helper function for dwarf2_compute_name which determines whether DIE |
| 4705 | needs to have the name of the scope prepended to the name listed in the |
| 4706 | die. */ |
| 4707 | |
| 4708 | static int |
| 4709 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) |
| 4710 | { |
| 4711 | struct attribute *attr; |
| 4712 | |
| 4713 | switch (die->tag) |
| 4714 | { |
| 4715 | case DW_TAG_namespace: |
| 4716 | case DW_TAG_typedef: |
| 4717 | case DW_TAG_class_type: |
| 4718 | case DW_TAG_interface_type: |
| 4719 | case DW_TAG_structure_type: |
| 4720 | case DW_TAG_union_type: |
| 4721 | case DW_TAG_enumeration_type: |
| 4722 | case DW_TAG_enumerator: |
| 4723 | case DW_TAG_subprogram: |
| 4724 | case DW_TAG_member: |
| 4725 | return 1; |
| 4726 | |
| 4727 | case DW_TAG_variable: |
| 4728 | case DW_TAG_constant: |
| 4729 | /* We only need to prefix "globally" visible variables. These include |
| 4730 | any variable marked with DW_AT_external or any variable that |
| 4731 | lives in a namespace. [Variables in anonymous namespaces |
| 4732 | require prefixing, but they are not DW_AT_external.] */ |
| 4733 | |
| 4734 | if (dwarf2_attr (die, DW_AT_specification, cu)) |
| 4735 | { |
| 4736 | struct dwarf2_cu *spec_cu = cu; |
| 4737 | |
| 4738 | return die_needs_namespace (die_specification (die, &spec_cu), |
| 4739 | spec_cu); |
| 4740 | } |
| 4741 | |
| 4742 | attr = dwarf2_attr (die, DW_AT_external, cu); |
| 4743 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
| 4744 | && die->parent->tag != DW_TAG_module) |
| 4745 | return 0; |
| 4746 | /* A variable in a lexical block of some kind does not need a |
| 4747 | namespace, even though in C++ such variables may be external |
| 4748 | and have a mangled name. */ |
| 4749 | if (die->parent->tag == DW_TAG_lexical_block |
| 4750 | || die->parent->tag == DW_TAG_try_block |
| 4751 | || die->parent->tag == DW_TAG_catch_block |
| 4752 | || die->parent->tag == DW_TAG_subprogram) |
| 4753 | return 0; |
| 4754 | return 1; |
| 4755 | |
| 4756 | default: |
| 4757 | return 0; |
| 4758 | } |
| 4759 | } |
| 4760 | |
| 4761 | /* Retrieve the last character from a mem_file. */ |
| 4762 | |
| 4763 | static void |
| 4764 | do_ui_file_peek_last (void *object, const char *buffer, long length) |
| 4765 | { |
| 4766 | char *last_char_p = (char *) object; |
| 4767 | |
| 4768 | if (length > 0) |
| 4769 | *last_char_p = buffer[length - 1]; |
| 4770 | } |
| 4771 | |
| 4772 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
| 4773 | compute the physname for the object, which include a method's |
| 4774 | formal parameters (C++/Java) and return type (Java). |
| 4775 | |
| 4776 | For Ada, return the DIE's linkage name rather than the fully qualified |
| 4777 | name. PHYSNAME is ignored.. |
| 4778 | |
| 4779 | The result is allocated on the objfile_obstack and canonicalized. */ |
| 4780 | |
| 4781 | static const char * |
| 4782 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, |
| 4783 | int physname) |
| 4784 | { |
| 4785 | if (name == NULL) |
| 4786 | name = dwarf2_name (die, cu); |
| 4787 | |
| 4788 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
| 4789 | compute it by typename_concat inside GDB. */ |
| 4790 | if (cu->language == language_ada |
| 4791 | || (cu->language == language_fortran && physname)) |
| 4792 | { |
| 4793 | /* For Ada unit, we prefer the linkage name over the name, as |
| 4794 | the former contains the exported name, which the user expects |
| 4795 | to be able to reference. Ideally, we want the user to be able |
| 4796 | to reference this entity using either natural or linkage name, |
| 4797 | but we haven't started looking at this enhancement yet. */ |
| 4798 | struct attribute *attr; |
| 4799 | |
| 4800 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 4801 | if (attr == NULL) |
| 4802 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 4803 | if (attr && DW_STRING (attr)) |
| 4804 | return DW_STRING (attr); |
| 4805 | } |
| 4806 | |
| 4807 | /* These are the only languages we know how to qualify names in. */ |
| 4808 | if (name != NULL |
| 4809 | && (cu->language == language_cplus || cu->language == language_java |
| 4810 | || cu->language == language_fortran)) |
| 4811 | { |
| 4812 | if (die_needs_namespace (die, cu)) |
| 4813 | { |
| 4814 | long length; |
| 4815 | char *prefix; |
| 4816 | struct ui_file *buf; |
| 4817 | |
| 4818 | prefix = determine_prefix (die, cu); |
| 4819 | buf = mem_fileopen (); |
| 4820 | if (*prefix != '\0') |
| 4821 | { |
| 4822 | char *prefixed_name = typename_concat (NULL, prefix, name, |
| 4823 | physname, cu); |
| 4824 | |
| 4825 | fputs_unfiltered (prefixed_name, buf); |
| 4826 | xfree (prefixed_name); |
| 4827 | } |
| 4828 | else |
| 4829 | fputs_unfiltered (name ? name : "", buf); |
| 4830 | |
| 4831 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
| 4832 | as children with DW_TAG_template_type_param or |
| 4833 | DW_TAG_value_type_param. If the latter, add them to the name |
| 4834 | here. If the name already has template parameters, then |
| 4835 | skip this step; some versions of GCC emit both, and |
| 4836 | it is more efficient to use the pre-computed name. |
| 4837 | |
| 4838 | Something to keep in mind about this process: it is very |
| 4839 | unlikely, or in some cases downright impossible, to produce |
| 4840 | something that will match the mangled name of a function. |
| 4841 | If the definition of the function has the same debug info, |
| 4842 | we should be able to match up with it anyway. But fallbacks |
| 4843 | using the minimal symbol, for instance to find a method |
| 4844 | implemented in a stripped copy of libstdc++, will not work. |
| 4845 | If we do not have debug info for the definition, we will have to |
| 4846 | match them up some other way. |
| 4847 | |
| 4848 | When we do name matching there is a related problem with function |
| 4849 | templates; two instantiated function templates are allowed to |
| 4850 | differ only by their return types, which we do not add here. */ |
| 4851 | |
| 4852 | if (cu->language == language_cplus && strchr (name, '<') == NULL) |
| 4853 | { |
| 4854 | struct attribute *attr; |
| 4855 | struct die_info *child; |
| 4856 | int first = 1; |
| 4857 | |
| 4858 | die->building_fullname = 1; |
| 4859 | |
| 4860 | for (child = die->child; child != NULL; child = child->sibling) |
| 4861 | { |
| 4862 | struct type *type; |
| 4863 | long value; |
| 4864 | gdb_byte *bytes; |
| 4865 | struct dwarf2_locexpr_baton *baton; |
| 4866 | struct value *v; |
| 4867 | |
| 4868 | if (child->tag != DW_TAG_template_type_param |
| 4869 | && child->tag != DW_TAG_template_value_param) |
| 4870 | continue; |
| 4871 | |
| 4872 | if (first) |
| 4873 | { |
| 4874 | fputs_unfiltered ("<", buf); |
| 4875 | first = 0; |
| 4876 | } |
| 4877 | else |
| 4878 | fputs_unfiltered (", ", buf); |
| 4879 | |
| 4880 | attr = dwarf2_attr (child, DW_AT_type, cu); |
| 4881 | if (attr == NULL) |
| 4882 | { |
| 4883 | complaint (&symfile_complaints, |
| 4884 | _("template parameter missing DW_AT_type")); |
| 4885 | fputs_unfiltered ("UNKNOWN_TYPE", buf); |
| 4886 | continue; |
| 4887 | } |
| 4888 | type = die_type (child, cu); |
| 4889 | |
| 4890 | if (child->tag == DW_TAG_template_type_param) |
| 4891 | { |
| 4892 | c_print_type (type, "", buf, -1, 0); |
| 4893 | continue; |
| 4894 | } |
| 4895 | |
| 4896 | attr = dwarf2_attr (child, DW_AT_const_value, cu); |
| 4897 | if (attr == NULL) |
| 4898 | { |
| 4899 | complaint (&symfile_complaints, |
| 4900 | _("template parameter missing " |
| 4901 | "DW_AT_const_value")); |
| 4902 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
| 4903 | continue; |
| 4904 | } |
| 4905 | |
| 4906 | dwarf2_const_value_attr (attr, type, name, |
| 4907 | &cu->comp_unit_obstack, cu, |
| 4908 | &value, &bytes, &baton); |
| 4909 | |
| 4910 | if (TYPE_NOSIGN (type)) |
| 4911 | /* GDB prints characters as NUMBER 'CHAR'. If that's |
| 4912 | changed, this can use value_print instead. */ |
| 4913 | c_printchar (value, type, buf); |
| 4914 | else |
| 4915 | { |
| 4916 | struct value_print_options opts; |
| 4917 | |
| 4918 | if (baton != NULL) |
| 4919 | v = dwarf2_evaluate_loc_desc (type, NULL, |
| 4920 | baton->data, |
| 4921 | baton->size, |
| 4922 | baton->per_cu); |
| 4923 | else if (bytes != NULL) |
| 4924 | { |
| 4925 | v = allocate_value (type); |
| 4926 | memcpy (value_contents_writeable (v), bytes, |
| 4927 | TYPE_LENGTH (type)); |
| 4928 | } |
| 4929 | else |
| 4930 | v = value_from_longest (type, value); |
| 4931 | |
| 4932 | /* Specify decimal so that we do not depend on |
| 4933 | the radix. */ |
| 4934 | get_formatted_print_options (&opts, 'd'); |
| 4935 | opts.raw = 1; |
| 4936 | value_print (v, buf, &opts); |
| 4937 | release_value (v); |
| 4938 | value_free (v); |
| 4939 | } |
| 4940 | } |
| 4941 | |
| 4942 | die->building_fullname = 0; |
| 4943 | |
| 4944 | if (!first) |
| 4945 | { |
| 4946 | /* Close the argument list, with a space if necessary |
| 4947 | (nested templates). */ |
| 4948 | char last_char = '\0'; |
| 4949 | ui_file_put (buf, do_ui_file_peek_last, &last_char); |
| 4950 | if (last_char == '>') |
| 4951 | fputs_unfiltered (" >", buf); |
| 4952 | else |
| 4953 | fputs_unfiltered (">", buf); |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | /* For Java and C++ methods, append formal parameter type |
| 4958 | information, if PHYSNAME. */ |
| 4959 | |
| 4960 | if (physname && die->tag == DW_TAG_subprogram |
| 4961 | && (cu->language == language_cplus |
| 4962 | || cu->language == language_java)) |
| 4963 | { |
| 4964 | struct type *type = read_type_die (die, cu); |
| 4965 | |
| 4966 | c_type_print_args (type, buf, 0, cu->language); |
| 4967 | |
| 4968 | if (cu->language == language_java) |
| 4969 | { |
| 4970 | /* For java, we must append the return type to method |
| 4971 | names. */ |
| 4972 | if (die->tag == DW_TAG_subprogram) |
| 4973 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, |
| 4974 | 0, 0); |
| 4975 | } |
| 4976 | else if (cu->language == language_cplus) |
| 4977 | { |
| 4978 | /* Assume that an artificial first parameter is |
| 4979 | "this", but do not crash if it is not. RealView |
| 4980 | marks unnamed (and thus unused) parameters as |
| 4981 | artificial; there is no way to differentiate |
| 4982 | the two cases. */ |
| 4983 | if (TYPE_NFIELDS (type) > 0 |
| 4984 | && TYPE_FIELD_ARTIFICIAL (type, 0) |
| 4985 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
| 4986 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
| 4987 | 0)))) |
| 4988 | fputs_unfiltered (" const", buf); |
| 4989 | } |
| 4990 | } |
| 4991 | |
| 4992 | name = ui_file_obsavestring (buf, &cu->objfile->objfile_obstack, |
| 4993 | &length); |
| 4994 | ui_file_delete (buf); |
| 4995 | |
| 4996 | if (cu->language == language_cplus) |
| 4997 | { |
| 4998 | char *cname |
| 4999 | = dwarf2_canonicalize_name (name, cu, |
| 5000 | &cu->objfile->objfile_obstack); |
| 5001 | |
| 5002 | if (cname != NULL) |
| 5003 | name = cname; |
| 5004 | } |
| 5005 | } |
| 5006 | } |
| 5007 | |
| 5008 | return name; |
| 5009 | } |
| 5010 | |
| 5011 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
| 5012 | If scope qualifiers are appropriate they will be added. The result |
| 5013 | will be allocated on the objfile_obstack, or NULL if the DIE does |
| 5014 | not have a name. NAME may either be from a previous call to |
| 5015 | dwarf2_name or NULL. |
| 5016 | |
| 5017 | The output string will be canonicalized (if C++/Java). */ |
| 5018 | |
| 5019 | static const char * |
| 5020 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
| 5021 | { |
| 5022 | return dwarf2_compute_name (name, die, cu, 0); |
| 5023 | } |
| 5024 | |
| 5025 | /* Construct a physname for the given DIE in CU. NAME may either be |
| 5026 | from a previous call to dwarf2_name or NULL. The result will be |
| 5027 | allocated on the objfile_objstack or NULL if the DIE does not have a |
| 5028 | name. |
| 5029 | |
| 5030 | The output string will be canonicalized (if C++/Java). */ |
| 5031 | |
| 5032 | static const char * |
| 5033 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) |
| 5034 | { |
| 5035 | return dwarf2_compute_name (name, die, cu, 1); |
| 5036 | } |
| 5037 | |
| 5038 | /* Read the import statement specified by the given die and record it. */ |
| 5039 | |
| 5040 | static void |
| 5041 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) |
| 5042 | { |
| 5043 | struct attribute *import_attr; |
| 5044 | struct die_info *imported_die; |
| 5045 | struct dwarf2_cu *imported_cu; |
| 5046 | const char *imported_name; |
| 5047 | const char *imported_name_prefix; |
| 5048 | const char *canonical_name; |
| 5049 | const char *import_alias; |
| 5050 | const char *imported_declaration = NULL; |
| 5051 | const char *import_prefix; |
| 5052 | |
| 5053 | char *temp; |
| 5054 | |
| 5055 | import_attr = dwarf2_attr (die, DW_AT_import, cu); |
| 5056 | if (import_attr == NULL) |
| 5057 | { |
| 5058 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), |
| 5059 | dwarf_tag_name (die->tag)); |
| 5060 | return; |
| 5061 | } |
| 5062 | |
| 5063 | imported_cu = cu; |
| 5064 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); |
| 5065 | imported_name = dwarf2_name (imported_die, imported_cu); |
| 5066 | if (imported_name == NULL) |
| 5067 | { |
| 5068 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 |
| 5069 | |
| 5070 | The import in the following code: |
| 5071 | namespace A |
| 5072 | { |
| 5073 | typedef int B; |
| 5074 | } |
| 5075 | |
| 5076 | int main () |
| 5077 | { |
| 5078 | using A::B; |
| 5079 | B b; |
| 5080 | return b; |
| 5081 | } |
| 5082 | |
| 5083 | ... |
| 5084 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) |
| 5085 | <52> DW_AT_decl_file : 1 |
| 5086 | <53> DW_AT_decl_line : 6 |
| 5087 | <54> DW_AT_import : <0x75> |
| 5088 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) |
| 5089 | <59> DW_AT_name : B |
| 5090 | <5b> DW_AT_decl_file : 1 |
| 5091 | <5c> DW_AT_decl_line : 2 |
| 5092 | <5d> DW_AT_type : <0x6e> |
| 5093 | ... |
| 5094 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) |
| 5095 | <76> DW_AT_byte_size : 4 |
| 5096 | <77> DW_AT_encoding : 5 (signed) |
| 5097 | |
| 5098 | imports the wrong die ( 0x75 instead of 0x58 ). |
| 5099 | This case will be ignored until the gcc bug is fixed. */ |
| 5100 | return; |
| 5101 | } |
| 5102 | |
| 5103 | /* Figure out the local name after import. */ |
| 5104 | import_alias = dwarf2_name (die, cu); |
| 5105 | |
| 5106 | /* Figure out where the statement is being imported to. */ |
| 5107 | import_prefix = determine_prefix (die, cu); |
| 5108 | |
| 5109 | /* Figure out what the scope of the imported die is and prepend it |
| 5110 | to the name of the imported die. */ |
| 5111 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
| 5112 | |
| 5113 | if (imported_die->tag != DW_TAG_namespace |
| 5114 | && imported_die->tag != DW_TAG_module) |
| 5115 | { |
| 5116 | imported_declaration = imported_name; |
| 5117 | canonical_name = imported_name_prefix; |
| 5118 | } |
| 5119 | else if (strlen (imported_name_prefix) > 0) |
| 5120 | { |
| 5121 | temp = alloca (strlen (imported_name_prefix) |
| 5122 | + 2 + strlen (imported_name) + 1); |
| 5123 | strcpy (temp, imported_name_prefix); |
| 5124 | strcat (temp, "::"); |
| 5125 | strcat (temp, imported_name); |
| 5126 | canonical_name = temp; |
| 5127 | } |
| 5128 | else |
| 5129 | canonical_name = imported_name; |
| 5130 | |
| 5131 | cp_add_using_directive (import_prefix, |
| 5132 | canonical_name, |
| 5133 | import_alias, |
| 5134 | imported_declaration, |
| 5135 | &cu->objfile->objfile_obstack); |
| 5136 | } |
| 5137 | |
| 5138 | static void |
| 5139 | initialize_cu_func_list (struct dwarf2_cu *cu) |
| 5140 | { |
| 5141 | cu->first_fn = cu->last_fn = cu->cached_fn = NULL; |
| 5142 | } |
| 5143 | |
| 5144 | /* Cleanup function for read_file_scope. */ |
| 5145 | |
| 5146 | static void |
| 5147 | free_cu_line_header (void *arg) |
| 5148 | { |
| 5149 | struct dwarf2_cu *cu = arg; |
| 5150 | |
| 5151 | free_line_header (cu->line_header); |
| 5152 | cu->line_header = NULL; |
| 5153 | } |
| 5154 | |
| 5155 | static void |
| 5156 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, |
| 5157 | char **name, char **comp_dir) |
| 5158 | { |
| 5159 | struct attribute *attr; |
| 5160 | |
| 5161 | *name = NULL; |
| 5162 | *comp_dir = NULL; |
| 5163 | |
| 5164 | /* Find the filename. Do not use dwarf2_name here, since the filename |
| 5165 | is not a source language identifier. */ |
| 5166 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 5167 | if (attr) |
| 5168 | { |
| 5169 | *name = DW_STRING (attr); |
| 5170 | } |
| 5171 | |
| 5172 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
| 5173 | if (attr) |
| 5174 | *comp_dir = DW_STRING (attr); |
| 5175 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) |
| 5176 | { |
| 5177 | *comp_dir = ldirname (*name); |
| 5178 | if (*comp_dir != NULL) |
| 5179 | make_cleanup (xfree, *comp_dir); |
| 5180 | } |
| 5181 | if (*comp_dir != NULL) |
| 5182 | { |
| 5183 | /* Irix 6.2 native cc prepends <machine>.: to the compilation |
| 5184 | directory, get rid of it. */ |
| 5185 | char *cp = strchr (*comp_dir, ':'); |
| 5186 | |
| 5187 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') |
| 5188 | *comp_dir = cp + 1; |
| 5189 | } |
| 5190 | |
| 5191 | if (*name == NULL) |
| 5192 | *name = "<unknown>"; |
| 5193 | } |
| 5194 | |
| 5195 | /* Process DW_TAG_compile_unit. */ |
| 5196 | |
| 5197 | static void |
| 5198 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5199 | { |
| 5200 | struct objfile *objfile = cu->objfile; |
| 5201 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 5202 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
| 5203 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
| 5204 | struct attribute *attr; |
| 5205 | char *name = NULL; |
| 5206 | char *comp_dir = NULL; |
| 5207 | struct die_info *child_die; |
| 5208 | bfd *abfd = objfile->obfd; |
| 5209 | struct line_header *line_header = 0; |
| 5210 | CORE_ADDR baseaddr; |
| 5211 | |
| 5212 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5213 | |
| 5214 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
| 5215 | |
| 5216 | /* If we didn't find a lowpc, set it to highpc to avoid complaints |
| 5217 | from finish_block. */ |
| 5218 | if (lowpc == ((CORE_ADDR) -1)) |
| 5219 | lowpc = highpc; |
| 5220 | lowpc += baseaddr; |
| 5221 | highpc += baseaddr; |
| 5222 | |
| 5223 | find_file_and_directory (die, cu, &name, &comp_dir); |
| 5224 | |
| 5225 | attr = dwarf2_attr (die, DW_AT_language, cu); |
| 5226 | if (attr) |
| 5227 | { |
| 5228 | set_cu_language (DW_UNSND (attr), cu); |
| 5229 | } |
| 5230 | |
| 5231 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
| 5232 | if (attr) |
| 5233 | cu->producer = DW_STRING (attr); |
| 5234 | |
| 5235 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
| 5236 | standardised yet. As a workaround for the language detection we fall |
| 5237 | back to the DW_AT_producer string. */ |
| 5238 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) |
| 5239 | cu->language = language_opencl; |
| 5240 | |
| 5241 | /* We assume that we're processing GCC output. */ |
| 5242 | processing_gcc_compilation = 2; |
| 5243 | |
| 5244 | processing_has_namespace_info = 0; |
| 5245 | |
| 5246 | start_symtab (name, comp_dir, lowpc); |
| 5247 | record_debugformat ("DWARF 2"); |
| 5248 | record_producer (cu->producer); |
| 5249 | |
| 5250 | initialize_cu_func_list (cu); |
| 5251 | |
| 5252 | /* Decode line number information if present. We do this before |
| 5253 | processing child DIEs, so that the line header table is available |
| 5254 | for DW_AT_decl_file. */ |
| 5255 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 5256 | if (attr) |
| 5257 | { |
| 5258 | unsigned int line_offset = DW_UNSND (attr); |
| 5259 | line_header = dwarf_decode_line_header (line_offset, abfd, cu); |
| 5260 | if (line_header) |
| 5261 | { |
| 5262 | cu->line_header = line_header; |
| 5263 | make_cleanup (free_cu_line_header, cu); |
| 5264 | dwarf_decode_lines (line_header, comp_dir, abfd, cu, NULL); |
| 5265 | } |
| 5266 | } |
| 5267 | |
| 5268 | /* Process all dies in compilation unit. */ |
| 5269 | if (die->child != NULL) |
| 5270 | { |
| 5271 | child_die = die->child; |
| 5272 | while (child_die && child_die->tag) |
| 5273 | { |
| 5274 | process_die (child_die, cu); |
| 5275 | child_die = sibling_die (child_die); |
| 5276 | } |
| 5277 | } |
| 5278 | |
| 5279 | /* Decode macro information, if present. Dwarf 2 macro information |
| 5280 | refers to information in the line number info statement program |
| 5281 | header, so we can only read it if we've read the header |
| 5282 | successfully. */ |
| 5283 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
| 5284 | if (attr && line_header) |
| 5285 | { |
| 5286 | unsigned int macro_offset = DW_UNSND (attr); |
| 5287 | |
| 5288 | dwarf_decode_macros (line_header, macro_offset, |
| 5289 | comp_dir, abfd, cu); |
| 5290 | } |
| 5291 | do_cleanups (back_to); |
| 5292 | } |
| 5293 | |
| 5294 | /* Process DW_TAG_type_unit. |
| 5295 | For TUs we want to skip the first top level sibling if it's not the |
| 5296 | actual type being defined by this TU. In this case the first top |
| 5297 | level sibling is there to provide context only. */ |
| 5298 | |
| 5299 | static void |
| 5300 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5301 | { |
| 5302 | struct objfile *objfile = cu->objfile; |
| 5303 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 5304 | CORE_ADDR lowpc; |
| 5305 | struct attribute *attr; |
| 5306 | char *name = NULL; |
| 5307 | char *comp_dir = NULL; |
| 5308 | struct die_info *child_die; |
| 5309 | bfd *abfd = objfile->obfd; |
| 5310 | |
| 5311 | /* start_symtab needs a low pc, but we don't really have one. |
| 5312 | Do what read_file_scope would do in the absence of such info. */ |
| 5313 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5314 | |
| 5315 | /* Find the filename. Do not use dwarf2_name here, since the filename |
| 5316 | is not a source language identifier. */ |
| 5317 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 5318 | if (attr) |
| 5319 | name = DW_STRING (attr); |
| 5320 | |
| 5321 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
| 5322 | if (attr) |
| 5323 | comp_dir = DW_STRING (attr); |
| 5324 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) |
| 5325 | { |
| 5326 | comp_dir = ldirname (name); |
| 5327 | if (comp_dir != NULL) |
| 5328 | make_cleanup (xfree, comp_dir); |
| 5329 | } |
| 5330 | |
| 5331 | if (name == NULL) |
| 5332 | name = "<unknown>"; |
| 5333 | |
| 5334 | attr = dwarf2_attr (die, DW_AT_language, cu); |
| 5335 | if (attr) |
| 5336 | set_cu_language (DW_UNSND (attr), cu); |
| 5337 | |
| 5338 | /* This isn't technically needed today. It is done for symmetry |
| 5339 | with read_file_scope. */ |
| 5340 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
| 5341 | if (attr) |
| 5342 | cu->producer = DW_STRING (attr); |
| 5343 | |
| 5344 | /* We assume that we're processing GCC output. */ |
| 5345 | processing_gcc_compilation = 2; |
| 5346 | |
| 5347 | processing_has_namespace_info = 0; |
| 5348 | |
| 5349 | start_symtab (name, comp_dir, lowpc); |
| 5350 | record_debugformat ("DWARF 2"); |
| 5351 | record_producer (cu->producer); |
| 5352 | |
| 5353 | /* Process the dies in the type unit. */ |
| 5354 | if (die->child == NULL) |
| 5355 | { |
| 5356 | dump_die_for_error (die); |
| 5357 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), |
| 5358 | bfd_get_filename (abfd)); |
| 5359 | } |
| 5360 | |
| 5361 | child_die = die->child; |
| 5362 | |
| 5363 | while (child_die && child_die->tag) |
| 5364 | { |
| 5365 | process_die (child_die, cu); |
| 5366 | |
| 5367 | child_die = sibling_die (child_die); |
| 5368 | } |
| 5369 | |
| 5370 | do_cleanups (back_to); |
| 5371 | } |
| 5372 | |
| 5373 | static void |
| 5374 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc, |
| 5375 | struct dwarf2_cu *cu) |
| 5376 | { |
| 5377 | struct function_range *thisfn; |
| 5378 | |
| 5379 | thisfn = (struct function_range *) |
| 5380 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct function_range)); |
| 5381 | thisfn->name = name; |
| 5382 | thisfn->lowpc = lowpc; |
| 5383 | thisfn->highpc = highpc; |
| 5384 | thisfn->seen_line = 0; |
| 5385 | thisfn->next = NULL; |
| 5386 | |
| 5387 | if (cu->last_fn == NULL) |
| 5388 | cu->first_fn = thisfn; |
| 5389 | else |
| 5390 | cu->last_fn->next = thisfn; |
| 5391 | |
| 5392 | cu->last_fn = thisfn; |
| 5393 | } |
| 5394 | |
| 5395 | /* qsort helper for inherit_abstract_dies. */ |
| 5396 | |
| 5397 | static int |
| 5398 | unsigned_int_compar (const void *ap, const void *bp) |
| 5399 | { |
| 5400 | unsigned int a = *(unsigned int *) ap; |
| 5401 | unsigned int b = *(unsigned int *) bp; |
| 5402 | |
| 5403 | return (a > b) - (b > a); |
| 5404 | } |
| 5405 | |
| 5406 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). |
| 5407 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
| 5408 | already referenced by DW_AT_abstract_origin from the children of the |
| 5409 | current DIE. */ |
| 5410 | |
| 5411 | static void |
| 5412 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) |
| 5413 | { |
| 5414 | struct die_info *child_die; |
| 5415 | unsigned die_children_count; |
| 5416 | /* CU offsets which were referenced by children of the current DIE. */ |
| 5417 | unsigned *offsets; |
| 5418 | unsigned *offsets_end, *offsetp; |
| 5419 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
| 5420 | struct die_info *origin_die; |
| 5421 | /* Iterator of the ORIGIN_DIE children. */ |
| 5422 | struct die_info *origin_child_die; |
| 5423 | struct cleanup *cleanups; |
| 5424 | struct attribute *attr; |
| 5425 | struct dwarf2_cu *origin_cu; |
| 5426 | struct pending **origin_previous_list_in_scope; |
| 5427 | |
| 5428 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); |
| 5429 | if (!attr) |
| 5430 | return; |
| 5431 | |
| 5432 | /* Note that following die references may follow to a die in a |
| 5433 | different cu. */ |
| 5434 | |
| 5435 | origin_cu = cu; |
| 5436 | origin_die = follow_die_ref (die, attr, &origin_cu); |
| 5437 | |
| 5438 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's |
| 5439 | symbols in. */ |
| 5440 | origin_previous_list_in_scope = origin_cu->list_in_scope; |
| 5441 | origin_cu->list_in_scope = cu->list_in_scope; |
| 5442 | |
| 5443 | if (die->tag != origin_die->tag |
| 5444 | && !(die->tag == DW_TAG_inlined_subroutine |
| 5445 | && origin_die->tag == DW_TAG_subprogram)) |
| 5446 | complaint (&symfile_complaints, |
| 5447 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), |
| 5448 | die->offset, origin_die->offset); |
| 5449 | |
| 5450 | child_die = die->child; |
| 5451 | die_children_count = 0; |
| 5452 | while (child_die && child_die->tag) |
| 5453 | { |
| 5454 | child_die = sibling_die (child_die); |
| 5455 | die_children_count++; |
| 5456 | } |
| 5457 | offsets = xmalloc (sizeof (*offsets) * die_children_count); |
| 5458 | cleanups = make_cleanup (xfree, offsets); |
| 5459 | |
| 5460 | offsets_end = offsets; |
| 5461 | child_die = die->child; |
| 5462 | while (child_die && child_die->tag) |
| 5463 | { |
| 5464 | /* For each CHILD_DIE, find the corresponding child of |
| 5465 | ORIGIN_DIE. If there is more than one layer of |
| 5466 | DW_AT_abstract_origin, follow them all; there shouldn't be, |
| 5467 | but GCC versions at least through 4.4 generate this (GCC PR |
| 5468 | 40573). */ |
| 5469 | struct die_info *child_origin_die = child_die; |
| 5470 | struct dwarf2_cu *child_origin_cu = cu; |
| 5471 | |
| 5472 | while (1) |
| 5473 | { |
| 5474 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
| 5475 | child_origin_cu); |
| 5476 | if (attr == NULL) |
| 5477 | break; |
| 5478 | child_origin_die = follow_die_ref (child_origin_die, attr, |
| 5479 | &child_origin_cu); |
| 5480 | } |
| 5481 | |
| 5482 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
| 5483 | counterpart may exist. */ |
| 5484 | if (child_origin_die != child_die) |
| 5485 | { |
| 5486 | if (child_die->tag != child_origin_die->tag |
| 5487 | && !(child_die->tag == DW_TAG_inlined_subroutine |
| 5488 | && child_origin_die->tag == DW_TAG_subprogram)) |
| 5489 | complaint (&symfile_complaints, |
| 5490 | _("Child DIE 0x%x and its abstract origin 0x%x have " |
| 5491 | "different tags"), child_die->offset, |
| 5492 | child_origin_die->offset); |
| 5493 | if (child_origin_die->parent != origin_die) |
| 5494 | complaint (&symfile_complaints, |
| 5495 | _("Child DIE 0x%x and its abstract origin 0x%x have " |
| 5496 | "different parents"), child_die->offset, |
| 5497 | child_origin_die->offset); |
| 5498 | else |
| 5499 | *offsets_end++ = child_origin_die->offset; |
| 5500 | } |
| 5501 | child_die = sibling_die (child_die); |
| 5502 | } |
| 5503 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), |
| 5504 | unsigned_int_compar); |
| 5505 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) |
| 5506 | if (offsetp[-1] == *offsetp) |
| 5507 | complaint (&symfile_complaints, |
| 5508 | _("Multiple children of DIE 0x%x refer " |
| 5509 | "to DIE 0x%x as their abstract origin"), |
| 5510 | die->offset, *offsetp); |
| 5511 | |
| 5512 | offsetp = offsets; |
| 5513 | origin_child_die = origin_die->child; |
| 5514 | while (origin_child_die && origin_child_die->tag) |
| 5515 | { |
| 5516 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ |
| 5517 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) |
| 5518 | offsetp++; |
| 5519 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) |
| 5520 | { |
| 5521 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ |
| 5522 | process_die (origin_child_die, origin_cu); |
| 5523 | } |
| 5524 | origin_child_die = sibling_die (origin_child_die); |
| 5525 | } |
| 5526 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
| 5527 | |
| 5528 | do_cleanups (cleanups); |
| 5529 | } |
| 5530 | |
| 5531 | static void |
| 5532 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5533 | { |
| 5534 | struct objfile *objfile = cu->objfile; |
| 5535 | struct context_stack *new; |
| 5536 | CORE_ADDR lowpc; |
| 5537 | CORE_ADDR highpc; |
| 5538 | struct die_info *child_die; |
| 5539 | struct attribute *attr, *call_line, *call_file; |
| 5540 | char *name; |
| 5541 | CORE_ADDR baseaddr; |
| 5542 | struct block *block; |
| 5543 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
| 5544 | VEC (symbolp) *template_args = NULL; |
| 5545 | struct template_symbol *templ_func = NULL; |
| 5546 | |
| 5547 | if (inlined_func) |
| 5548 | { |
| 5549 | /* If we do not have call site information, we can't show the |
| 5550 | caller of this inlined function. That's too confusing, so |
| 5551 | only use the scope for local variables. */ |
| 5552 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); |
| 5553 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); |
| 5554 | if (call_line == NULL || call_file == NULL) |
| 5555 | { |
| 5556 | read_lexical_block_scope (die, cu); |
| 5557 | return; |
| 5558 | } |
| 5559 | } |
| 5560 | |
| 5561 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5562 | |
| 5563 | name = dwarf2_name (die, cu); |
| 5564 | |
| 5565 | /* Ignore functions with missing or empty names. These are actually |
| 5566 | illegal according to the DWARF standard. */ |
| 5567 | if (name == NULL) |
| 5568 | { |
| 5569 | complaint (&symfile_complaints, |
| 5570 | _("missing name for subprogram DIE at %d"), die->offset); |
| 5571 | return; |
| 5572 | } |
| 5573 | |
| 5574 | /* Ignore functions with missing or invalid low and high pc attributes. */ |
| 5575 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
| 5576 | { |
| 5577 | attr = dwarf2_attr (die, DW_AT_external, cu); |
| 5578 | if (!attr || !DW_UNSND (attr)) |
| 5579 | complaint (&symfile_complaints, |
| 5580 | _("cannot get low and high bounds " |
| 5581 | "for subprogram DIE at %d"), |
| 5582 | die->offset); |
| 5583 | return; |
| 5584 | } |
| 5585 | |
| 5586 | lowpc += baseaddr; |
| 5587 | highpc += baseaddr; |
| 5588 | |
| 5589 | /* Record the function range for dwarf_decode_lines. */ |
| 5590 | add_to_cu_func_list (name, lowpc, highpc, cu); |
| 5591 | |
| 5592 | /* If we have any template arguments, then we must allocate a |
| 5593 | different sort of symbol. */ |
| 5594 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) |
| 5595 | { |
| 5596 | if (child_die->tag == DW_TAG_template_type_param |
| 5597 | || child_die->tag == DW_TAG_template_value_param) |
| 5598 | { |
| 5599 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 5600 | struct template_symbol); |
| 5601 | templ_func->base.is_cplus_template_function = 1; |
| 5602 | break; |
| 5603 | } |
| 5604 | } |
| 5605 | |
| 5606 | new = push_context (0, lowpc); |
| 5607 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
| 5608 | (struct symbol *) templ_func); |
| 5609 | |
| 5610 | /* If there is a location expression for DW_AT_frame_base, record |
| 5611 | it. */ |
| 5612 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
| 5613 | if (attr) |
| 5614 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
| 5615 | expression is being recorded directly in the function's symbol |
| 5616 | and not in a separate frame-base object. I guess this hack is |
| 5617 | to avoid adding some sort of frame-base adjunct/annex to the |
| 5618 | function's symbol :-(. The problem with doing this is that it |
| 5619 | results in a function symbol with a location expression that |
| 5620 | has nothing to do with the location of the function, ouch! The |
| 5621 | relationship should be: a function's symbol has-a frame base; a |
| 5622 | frame-base has-a location expression. */ |
| 5623 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
| 5624 | |
| 5625 | cu->list_in_scope = &local_symbols; |
| 5626 | |
| 5627 | if (die->child != NULL) |
| 5628 | { |
| 5629 | child_die = die->child; |
| 5630 | while (child_die && child_die->tag) |
| 5631 | { |
| 5632 | if (child_die->tag == DW_TAG_template_type_param |
| 5633 | || child_die->tag == DW_TAG_template_value_param) |
| 5634 | { |
| 5635 | struct symbol *arg = new_symbol (child_die, NULL, cu); |
| 5636 | |
| 5637 | if (arg != NULL) |
| 5638 | VEC_safe_push (symbolp, template_args, arg); |
| 5639 | } |
| 5640 | else |
| 5641 | process_die (child_die, cu); |
| 5642 | child_die = sibling_die (child_die); |
| 5643 | } |
| 5644 | } |
| 5645 | |
| 5646 | inherit_abstract_dies (die, cu); |
| 5647 | |
| 5648 | /* If we have a DW_AT_specification, we might need to import using |
| 5649 | directives from the context of the specification DIE. See the |
| 5650 | comment in determine_prefix. */ |
| 5651 | if (cu->language == language_cplus |
| 5652 | && dwarf2_attr (die, DW_AT_specification, cu)) |
| 5653 | { |
| 5654 | struct dwarf2_cu *spec_cu = cu; |
| 5655 | struct die_info *spec_die = die_specification (die, &spec_cu); |
| 5656 | |
| 5657 | while (spec_die) |
| 5658 | { |
| 5659 | child_die = spec_die->child; |
| 5660 | while (child_die && child_die->tag) |
| 5661 | { |
| 5662 | if (child_die->tag == DW_TAG_imported_module) |
| 5663 | process_die (child_die, spec_cu); |
| 5664 | child_die = sibling_die (child_die); |
| 5665 | } |
| 5666 | |
| 5667 | /* In some cases, GCC generates specification DIEs that |
| 5668 | themselves contain DW_AT_specification attributes. */ |
| 5669 | spec_die = die_specification (spec_die, &spec_cu); |
| 5670 | } |
| 5671 | } |
| 5672 | |
| 5673 | new = pop_context (); |
| 5674 | /* Make a block for the local symbols within. */ |
| 5675 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
| 5676 | lowpc, highpc, objfile); |
| 5677 | |
| 5678 | /* For C++, set the block's scope. */ |
| 5679 | if (cu->language == language_cplus || cu->language == language_fortran) |
| 5680 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
| 5681 | determine_prefix (die, cu), |
| 5682 | processing_has_namespace_info); |
| 5683 | |
| 5684 | /* If we have address ranges, record them. */ |
| 5685 | dwarf2_record_block_ranges (die, block, baseaddr, cu); |
| 5686 | |
| 5687 | /* Attach template arguments to function. */ |
| 5688 | if (! VEC_empty (symbolp, template_args)) |
| 5689 | { |
| 5690 | gdb_assert (templ_func != NULL); |
| 5691 | |
| 5692 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); |
| 5693 | templ_func->template_arguments |
| 5694 | = obstack_alloc (&objfile->objfile_obstack, |
| 5695 | (templ_func->n_template_arguments |
| 5696 | * sizeof (struct symbol *))); |
| 5697 | memcpy (templ_func->template_arguments, |
| 5698 | VEC_address (symbolp, template_args), |
| 5699 | (templ_func->n_template_arguments * sizeof (struct symbol *))); |
| 5700 | VEC_free (symbolp, template_args); |
| 5701 | } |
| 5702 | |
| 5703 | /* In C++, we can have functions nested inside functions (e.g., when |
| 5704 | a function declares a class that has methods). This means that |
| 5705 | when we finish processing a function scope, we may need to go |
| 5706 | back to building a containing block's symbol lists. */ |
| 5707 | local_symbols = new->locals; |
| 5708 | param_symbols = new->params; |
| 5709 | using_directives = new->using_directives; |
| 5710 | |
| 5711 | /* If we've finished processing a top-level function, subsequent |
| 5712 | symbols go in the file symbol list. */ |
| 5713 | if (outermost_context_p ()) |
| 5714 | cu->list_in_scope = &file_symbols; |
| 5715 | } |
| 5716 | |
| 5717 | /* Process all the DIES contained within a lexical block scope. Start |
| 5718 | a new scope, process the dies, and then close the scope. */ |
| 5719 | |
| 5720 | static void |
| 5721 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5722 | { |
| 5723 | struct objfile *objfile = cu->objfile; |
| 5724 | struct context_stack *new; |
| 5725 | CORE_ADDR lowpc, highpc; |
| 5726 | struct die_info *child_die; |
| 5727 | CORE_ADDR baseaddr; |
| 5728 | |
| 5729 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5730 | |
| 5731 | /* Ignore blocks with missing or invalid low and high pc attributes. */ |
| 5732 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
| 5733 | as multiple lexical blocks? Handling children in a sane way would |
| 5734 | be nasty. Might be easier to properly extend generic blocks to |
| 5735 | describe ranges. */ |
| 5736 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
| 5737 | return; |
| 5738 | lowpc += baseaddr; |
| 5739 | highpc += baseaddr; |
| 5740 | |
| 5741 | push_context (0, lowpc); |
| 5742 | if (die->child != NULL) |
| 5743 | { |
| 5744 | child_die = die->child; |
| 5745 | while (child_die && child_die->tag) |
| 5746 | { |
| 5747 | process_die (child_die, cu); |
| 5748 | child_die = sibling_die (child_die); |
| 5749 | } |
| 5750 | } |
| 5751 | new = pop_context (); |
| 5752 | |
| 5753 | if (local_symbols != NULL || using_directives != NULL) |
| 5754 | { |
| 5755 | struct block *block |
| 5756 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, |
| 5757 | highpc, objfile); |
| 5758 | |
| 5759 | /* Note that recording ranges after traversing children, as we |
| 5760 | do here, means that recording a parent's ranges entails |
| 5761 | walking across all its children's ranges as they appear in |
| 5762 | the address map, which is quadratic behavior. |
| 5763 | |
| 5764 | It would be nicer to record the parent's ranges before |
| 5765 | traversing its children, simply overriding whatever you find |
| 5766 | there. But since we don't even decide whether to create a |
| 5767 | block until after we've traversed its children, that's hard |
| 5768 | to do. */ |
| 5769 | dwarf2_record_block_ranges (die, block, baseaddr, cu); |
| 5770 | } |
| 5771 | local_symbols = new->locals; |
| 5772 | using_directives = new->using_directives; |
| 5773 | } |
| 5774 | |
| 5775 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
| 5776 | Return 1 if the attributes are present and valid, otherwise, return 0. |
| 5777 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ |
| 5778 | |
| 5779 | static int |
| 5780 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, |
| 5781 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
| 5782 | struct partial_symtab *ranges_pst) |
| 5783 | { |
| 5784 | struct objfile *objfile = cu->objfile; |
| 5785 | struct comp_unit_head *cu_header = &cu->header; |
| 5786 | bfd *obfd = objfile->obfd; |
| 5787 | unsigned int addr_size = cu_header->addr_size; |
| 5788 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 5789 | /* Base address selection entry. */ |
| 5790 | CORE_ADDR base; |
| 5791 | int found_base; |
| 5792 | unsigned int dummy; |
| 5793 | gdb_byte *buffer; |
| 5794 | CORE_ADDR marker; |
| 5795 | int low_set; |
| 5796 | CORE_ADDR low = 0; |
| 5797 | CORE_ADDR high = 0; |
| 5798 | CORE_ADDR baseaddr; |
| 5799 | |
| 5800 | found_base = cu->base_known; |
| 5801 | base = cu->base_address; |
| 5802 | |
| 5803 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
| 5804 | if (offset >= dwarf2_per_objfile->ranges.size) |
| 5805 | { |
| 5806 | complaint (&symfile_complaints, |
| 5807 | _("Offset %d out of bounds for DW_AT_ranges attribute"), |
| 5808 | offset); |
| 5809 | return 0; |
| 5810 | } |
| 5811 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
| 5812 | |
| 5813 | /* Read in the largest possible address. */ |
| 5814 | marker = read_address (obfd, buffer, cu, &dummy); |
| 5815 | if ((marker & mask) == mask) |
| 5816 | { |
| 5817 | /* If we found the largest possible address, then |
| 5818 | read the base address. */ |
| 5819 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
| 5820 | buffer += 2 * addr_size; |
| 5821 | offset += 2 * addr_size; |
| 5822 | found_base = 1; |
| 5823 | } |
| 5824 | |
| 5825 | low_set = 0; |
| 5826 | |
| 5827 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5828 | |
| 5829 | while (1) |
| 5830 | { |
| 5831 | CORE_ADDR range_beginning, range_end; |
| 5832 | |
| 5833 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
| 5834 | buffer += addr_size; |
| 5835 | range_end = read_address (obfd, buffer, cu, &dummy); |
| 5836 | buffer += addr_size; |
| 5837 | offset += 2 * addr_size; |
| 5838 | |
| 5839 | /* An end of list marker is a pair of zero addresses. */ |
| 5840 | if (range_beginning == 0 && range_end == 0) |
| 5841 | /* Found the end of list entry. */ |
| 5842 | break; |
| 5843 | |
| 5844 | /* Each base address selection entry is a pair of 2 values. |
| 5845 | The first is the largest possible address, the second is |
| 5846 | the base address. Check for a base address here. */ |
| 5847 | if ((range_beginning & mask) == mask) |
| 5848 | { |
| 5849 | /* If we found the largest possible address, then |
| 5850 | read the base address. */ |
| 5851 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
| 5852 | found_base = 1; |
| 5853 | continue; |
| 5854 | } |
| 5855 | |
| 5856 | if (!found_base) |
| 5857 | { |
| 5858 | /* We have no valid base address for the ranges |
| 5859 | data. */ |
| 5860 | complaint (&symfile_complaints, |
| 5861 | _("Invalid .debug_ranges data (no base address)")); |
| 5862 | return 0; |
| 5863 | } |
| 5864 | |
| 5865 | range_beginning += base; |
| 5866 | range_end += base; |
| 5867 | |
| 5868 | if (ranges_pst != NULL && range_beginning < range_end) |
| 5869 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 5870 | range_beginning + baseaddr, |
| 5871 | range_end - 1 + baseaddr, |
| 5872 | ranges_pst); |
| 5873 | |
| 5874 | /* FIXME: This is recording everything as a low-high |
| 5875 | segment of consecutive addresses. We should have a |
| 5876 | data structure for discontiguous block ranges |
| 5877 | instead. */ |
| 5878 | if (! low_set) |
| 5879 | { |
| 5880 | low = range_beginning; |
| 5881 | high = range_end; |
| 5882 | low_set = 1; |
| 5883 | } |
| 5884 | else |
| 5885 | { |
| 5886 | if (range_beginning < low) |
| 5887 | low = range_beginning; |
| 5888 | if (range_end > high) |
| 5889 | high = range_end; |
| 5890 | } |
| 5891 | } |
| 5892 | |
| 5893 | if (! low_set) |
| 5894 | /* If the first entry is an end-of-list marker, the range |
| 5895 | describes an empty scope, i.e. no instructions. */ |
| 5896 | return 0; |
| 5897 | |
| 5898 | if (low_return) |
| 5899 | *low_return = low; |
| 5900 | if (high_return) |
| 5901 | *high_return = high; |
| 5902 | return 1; |
| 5903 | } |
| 5904 | |
| 5905 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
| 5906 | are present and valid, otherwise, return 0. Return -1 if the range is |
| 5907 | discontinuous, i.e. derived from DW_AT_ranges information. */ |
| 5908 | static int |
| 5909 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
| 5910 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
| 5911 | struct partial_symtab *pst) |
| 5912 | { |
| 5913 | struct attribute *attr; |
| 5914 | CORE_ADDR low = 0; |
| 5915 | CORE_ADDR high = 0; |
| 5916 | int ret = 0; |
| 5917 | |
| 5918 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
| 5919 | if (attr) |
| 5920 | { |
| 5921 | high = DW_ADDR (attr); |
| 5922 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 5923 | if (attr) |
| 5924 | low = DW_ADDR (attr); |
| 5925 | else |
| 5926 | /* Found high w/o low attribute. */ |
| 5927 | return 0; |
| 5928 | |
| 5929 | /* Found consecutive range of addresses. */ |
| 5930 | ret = 1; |
| 5931 | } |
| 5932 | else |
| 5933 | { |
| 5934 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
| 5935 | if (attr != NULL) |
| 5936 | { |
| 5937 | /* Value of the DW_AT_ranges attribute is the offset in the |
| 5938 | .debug_ranges section. */ |
| 5939 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
| 5940 | return 0; |
| 5941 | /* Found discontinuous range of addresses. */ |
| 5942 | ret = -1; |
| 5943 | } |
| 5944 | } |
| 5945 | |
| 5946 | if (high < low) |
| 5947 | return 0; |
| 5948 | |
| 5949 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 5950 | eliminate duplicate copies of functions and vtables and such. |
| 5951 | The linker will arbitrarily choose one and discard the others. |
| 5952 | The AT_*_pc values for such functions refer to local labels in |
| 5953 | these sections. If the section from that file was discarded, the |
| 5954 | labels are not in the output, so the relocs get a value of 0. |
| 5955 | If this is a discarded function, mark the pc bounds as invalid, |
| 5956 | so that GDB will ignore it. */ |
| 5957 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 5958 | return 0; |
| 5959 | |
| 5960 | *lowpc = low; |
| 5961 | *highpc = high; |
| 5962 | return ret; |
| 5963 | } |
| 5964 | |
| 5965 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
| 5966 | its low and high PC addresses. Do nothing if these addresses could not |
| 5967 | be determined. Otherwise, set LOWPC to the low address if it is smaller, |
| 5968 | and HIGHPC to the high address if greater than HIGHPC. */ |
| 5969 | |
| 5970 | static void |
| 5971 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, |
| 5972 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 5973 | struct dwarf2_cu *cu) |
| 5974 | { |
| 5975 | CORE_ADDR low, high; |
| 5976 | struct die_info *child = die->child; |
| 5977 | |
| 5978 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
| 5979 | { |
| 5980 | *lowpc = min (*lowpc, low); |
| 5981 | *highpc = max (*highpc, high); |
| 5982 | } |
| 5983 | |
| 5984 | /* If the language does not allow nested subprograms (either inside |
| 5985 | subprograms or lexical blocks), we're done. */ |
| 5986 | if (cu->language != language_ada) |
| 5987 | return; |
| 5988 | |
| 5989 | /* Check all the children of the given DIE. If it contains nested |
| 5990 | subprograms, then check their pc bounds. Likewise, we need to |
| 5991 | check lexical blocks as well, as they may also contain subprogram |
| 5992 | definitions. */ |
| 5993 | while (child && child->tag) |
| 5994 | { |
| 5995 | if (child->tag == DW_TAG_subprogram |
| 5996 | || child->tag == DW_TAG_lexical_block) |
| 5997 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); |
| 5998 | child = sibling_die (child); |
| 5999 | } |
| 6000 | } |
| 6001 | |
| 6002 | /* Get the low and high pc's represented by the scope DIE, and store |
| 6003 | them in *LOWPC and *HIGHPC. If the correct values can't be |
| 6004 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ |
| 6005 | |
| 6006 | static void |
| 6007 | get_scope_pc_bounds (struct die_info *die, |
| 6008 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 6009 | struct dwarf2_cu *cu) |
| 6010 | { |
| 6011 | CORE_ADDR best_low = (CORE_ADDR) -1; |
| 6012 | CORE_ADDR best_high = (CORE_ADDR) 0; |
| 6013 | CORE_ADDR current_low, current_high; |
| 6014 | |
| 6015 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
| 6016 | { |
| 6017 | best_low = current_low; |
| 6018 | best_high = current_high; |
| 6019 | } |
| 6020 | else |
| 6021 | { |
| 6022 | struct die_info *child = die->child; |
| 6023 | |
| 6024 | while (child && child->tag) |
| 6025 | { |
| 6026 | switch (child->tag) { |
| 6027 | case DW_TAG_subprogram: |
| 6028 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
| 6029 | break; |
| 6030 | case DW_TAG_namespace: |
| 6031 | case DW_TAG_module: |
| 6032 | /* FIXME: carlton/2004-01-16: Should we do this for |
| 6033 | DW_TAG_class_type/DW_TAG_structure_type, too? I think |
| 6034 | that current GCC's always emit the DIEs corresponding |
| 6035 | to definitions of methods of classes as children of a |
| 6036 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to |
| 6037 | the DIEs giving the declarations, which could be |
| 6038 | anywhere). But I don't see any reason why the |
| 6039 | standards says that they have to be there. */ |
| 6040 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); |
| 6041 | |
| 6042 | if (current_low != ((CORE_ADDR) -1)) |
| 6043 | { |
| 6044 | best_low = min (best_low, current_low); |
| 6045 | best_high = max (best_high, current_high); |
| 6046 | } |
| 6047 | break; |
| 6048 | default: |
| 6049 | /* Ignore. */ |
| 6050 | break; |
| 6051 | } |
| 6052 | |
| 6053 | child = sibling_die (child); |
| 6054 | } |
| 6055 | } |
| 6056 | |
| 6057 | *lowpc = best_low; |
| 6058 | *highpc = best_high; |
| 6059 | } |
| 6060 | |
| 6061 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
| 6062 | in DIE. */ |
| 6063 | static void |
| 6064 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, |
| 6065 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) |
| 6066 | { |
| 6067 | struct attribute *attr; |
| 6068 | |
| 6069 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
| 6070 | if (attr) |
| 6071 | { |
| 6072 | CORE_ADDR high = DW_ADDR (attr); |
| 6073 | |
| 6074 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 6075 | if (attr) |
| 6076 | { |
| 6077 | CORE_ADDR low = DW_ADDR (attr); |
| 6078 | |
| 6079 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
| 6080 | } |
| 6081 | } |
| 6082 | |
| 6083 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
| 6084 | if (attr) |
| 6085 | { |
| 6086 | bfd *obfd = cu->objfile->obfd; |
| 6087 | |
| 6088 | /* The value of the DW_AT_ranges attribute is the offset of the |
| 6089 | address range list in the .debug_ranges section. */ |
| 6090 | unsigned long offset = DW_UNSND (attr); |
| 6091 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
| 6092 | |
| 6093 | /* For some target architectures, but not others, the |
| 6094 | read_address function sign-extends the addresses it returns. |
| 6095 | To recognize base address selection entries, we need a |
| 6096 | mask. */ |
| 6097 | unsigned int addr_size = cu->header.addr_size; |
| 6098 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 6099 | |
| 6100 | /* The base address, to which the next pair is relative. Note |
| 6101 | that this 'base' is a DWARF concept: most entries in a range |
| 6102 | list are relative, to reduce the number of relocs against the |
| 6103 | debugging information. This is separate from this function's |
| 6104 | 'baseaddr' argument, which GDB uses to relocate debugging |
| 6105 | information from a shared library based on the address at |
| 6106 | which the library was loaded. */ |
| 6107 | CORE_ADDR base = cu->base_address; |
| 6108 | int base_known = cu->base_known; |
| 6109 | |
| 6110 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
| 6111 | if (offset >= dwarf2_per_objfile->ranges.size) |
| 6112 | { |
| 6113 | complaint (&symfile_complaints, |
| 6114 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), |
| 6115 | offset); |
| 6116 | return; |
| 6117 | } |
| 6118 | |
| 6119 | for (;;) |
| 6120 | { |
| 6121 | unsigned int bytes_read; |
| 6122 | CORE_ADDR start, end; |
| 6123 | |
| 6124 | start = read_address (obfd, buffer, cu, &bytes_read); |
| 6125 | buffer += bytes_read; |
| 6126 | end = read_address (obfd, buffer, cu, &bytes_read); |
| 6127 | buffer += bytes_read; |
| 6128 | |
| 6129 | /* Did we find the end of the range list? */ |
| 6130 | if (start == 0 && end == 0) |
| 6131 | break; |
| 6132 | |
| 6133 | /* Did we find a base address selection entry? */ |
| 6134 | else if ((start & base_select_mask) == base_select_mask) |
| 6135 | { |
| 6136 | base = end; |
| 6137 | base_known = 1; |
| 6138 | } |
| 6139 | |
| 6140 | /* We found an ordinary address range. */ |
| 6141 | else |
| 6142 | { |
| 6143 | if (!base_known) |
| 6144 | { |
| 6145 | complaint (&symfile_complaints, |
| 6146 | _("Invalid .debug_ranges data " |
| 6147 | "(no base address)")); |
| 6148 | return; |
| 6149 | } |
| 6150 | |
| 6151 | record_block_range (block, |
| 6152 | baseaddr + base + start, |
| 6153 | baseaddr + base + end - 1); |
| 6154 | } |
| 6155 | } |
| 6156 | } |
| 6157 | } |
| 6158 | |
| 6159 | /* Add an aggregate field to the field list. */ |
| 6160 | |
| 6161 | static void |
| 6162 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
| 6163 | struct dwarf2_cu *cu) |
| 6164 | { |
| 6165 | struct objfile *objfile = cu->objfile; |
| 6166 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 6167 | struct nextfield *new_field; |
| 6168 | struct attribute *attr; |
| 6169 | struct field *fp; |
| 6170 | char *fieldname = ""; |
| 6171 | |
| 6172 | /* Allocate a new field list entry and link it in. */ |
| 6173 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 6174 | make_cleanup (xfree, new_field); |
| 6175 | memset (new_field, 0, sizeof (struct nextfield)); |
| 6176 | |
| 6177 | if (die->tag == DW_TAG_inheritance) |
| 6178 | { |
| 6179 | new_field->next = fip->baseclasses; |
| 6180 | fip->baseclasses = new_field; |
| 6181 | } |
| 6182 | else |
| 6183 | { |
| 6184 | new_field->next = fip->fields; |
| 6185 | fip->fields = new_field; |
| 6186 | } |
| 6187 | fip->nfields++; |
| 6188 | |
| 6189 | /* Handle accessibility and virtuality of field. |
| 6190 | The default accessibility for members is public, the default |
| 6191 | accessibility for inheritance is private. */ |
| 6192 | if (die->tag != DW_TAG_inheritance) |
| 6193 | new_field->accessibility = DW_ACCESS_public; |
| 6194 | else |
| 6195 | new_field->accessibility = DW_ACCESS_private; |
| 6196 | new_field->virtuality = DW_VIRTUALITY_none; |
| 6197 | |
| 6198 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
| 6199 | if (attr) |
| 6200 | new_field->accessibility = DW_UNSND (attr); |
| 6201 | if (new_field->accessibility != DW_ACCESS_public) |
| 6202 | fip->non_public_fields = 1; |
| 6203 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
| 6204 | if (attr) |
| 6205 | new_field->virtuality = DW_UNSND (attr); |
| 6206 | |
| 6207 | fp = &new_field->field; |
| 6208 | |
| 6209 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
| 6210 | { |
| 6211 | /* Data member other than a C++ static data member. */ |
| 6212 | |
| 6213 | /* Get type of field. */ |
| 6214 | fp->type = die_type (die, cu); |
| 6215 | |
| 6216 | SET_FIELD_BITPOS (*fp, 0); |
| 6217 | |
| 6218 | /* Get bit size of field (zero if none). */ |
| 6219 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
| 6220 | if (attr) |
| 6221 | { |
| 6222 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); |
| 6223 | } |
| 6224 | else |
| 6225 | { |
| 6226 | FIELD_BITSIZE (*fp) = 0; |
| 6227 | } |
| 6228 | |
| 6229 | /* Get bit offset of field. */ |
| 6230 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
| 6231 | if (attr) |
| 6232 | { |
| 6233 | int byte_offset = 0; |
| 6234 | |
| 6235 | if (attr_form_is_section_offset (attr)) |
| 6236 | dwarf2_complex_location_expr_complaint (); |
| 6237 | else if (attr_form_is_constant (attr)) |
| 6238 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
| 6239 | else if (attr_form_is_block (attr)) |
| 6240 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
| 6241 | else |
| 6242 | dwarf2_complex_location_expr_complaint (); |
| 6243 | |
| 6244 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
| 6245 | } |
| 6246 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
| 6247 | if (attr) |
| 6248 | { |
| 6249 | if (gdbarch_bits_big_endian (gdbarch)) |
| 6250 | { |
| 6251 | /* For big endian bits, the DW_AT_bit_offset gives the |
| 6252 | additional bit offset from the MSB of the containing |
| 6253 | anonymous object to the MSB of the field. We don't |
| 6254 | have to do anything special since we don't need to |
| 6255 | know the size of the anonymous object. */ |
| 6256 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
| 6257 | } |
| 6258 | else |
| 6259 | { |
| 6260 | /* For little endian bits, compute the bit offset to the |
| 6261 | MSB of the anonymous object, subtract off the number of |
| 6262 | bits from the MSB of the field to the MSB of the |
| 6263 | object, and then subtract off the number of bits of |
| 6264 | the field itself. The result is the bit offset of |
| 6265 | the LSB of the field. */ |
| 6266 | int anonymous_size; |
| 6267 | int bit_offset = DW_UNSND (attr); |
| 6268 | |
| 6269 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 6270 | if (attr) |
| 6271 | { |
| 6272 | /* The size of the anonymous object containing |
| 6273 | the bit field is explicit, so use the |
| 6274 | indicated size (in bytes). */ |
| 6275 | anonymous_size = DW_UNSND (attr); |
| 6276 | } |
| 6277 | else |
| 6278 | { |
| 6279 | /* The size of the anonymous object containing |
| 6280 | the bit field must be inferred from the type |
| 6281 | attribute of the data member containing the |
| 6282 | bit field. */ |
| 6283 | anonymous_size = TYPE_LENGTH (fp->type); |
| 6284 | } |
| 6285 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte |
| 6286 | - bit_offset - FIELD_BITSIZE (*fp); |
| 6287 | } |
| 6288 | } |
| 6289 | |
| 6290 | /* Get name of field. */ |
| 6291 | fieldname = dwarf2_name (die, cu); |
| 6292 | if (fieldname == NULL) |
| 6293 | fieldname = ""; |
| 6294 | |
| 6295 | /* The name is already allocated along with this objfile, so we don't |
| 6296 | need to duplicate it for the type. */ |
| 6297 | fp->name = fieldname; |
| 6298 | |
| 6299 | /* Change accessibility for artificial fields (e.g. virtual table |
| 6300 | pointer or virtual base class pointer) to private. */ |
| 6301 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
| 6302 | { |
| 6303 | FIELD_ARTIFICIAL (*fp) = 1; |
| 6304 | new_field->accessibility = DW_ACCESS_private; |
| 6305 | fip->non_public_fields = 1; |
| 6306 | } |
| 6307 | } |
| 6308 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
| 6309 | { |
| 6310 | /* C++ static member. */ |
| 6311 | |
| 6312 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that |
| 6313 | is a declaration, but all versions of G++ as of this writing |
| 6314 | (so through at least 3.2.1) incorrectly generate |
| 6315 | DW_TAG_variable tags. */ |
| 6316 | |
| 6317 | char *physname; |
| 6318 | |
| 6319 | /* Get name of field. */ |
| 6320 | fieldname = dwarf2_name (die, cu); |
| 6321 | if (fieldname == NULL) |
| 6322 | return; |
| 6323 | |
| 6324 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 6325 | if (attr |
| 6326 | /* Only create a symbol if this is an external value. |
| 6327 | new_symbol checks this and puts the value in the global symbol |
| 6328 | table, which we want. If it is not external, new_symbol |
| 6329 | will try to put the value in cu->list_in_scope which is wrong. */ |
| 6330 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) |
| 6331 | { |
| 6332 | /* A static const member, not much different than an enum as far as |
| 6333 | we're concerned, except that we can support more types. */ |
| 6334 | new_symbol (die, NULL, cu); |
| 6335 | } |
| 6336 | |
| 6337 | /* Get physical name. */ |
| 6338 | physname = (char *) dwarf2_physname (fieldname, die, cu); |
| 6339 | |
| 6340 | /* The name is already allocated along with this objfile, so we don't |
| 6341 | need to duplicate it for the type. */ |
| 6342 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); |
| 6343 | FIELD_TYPE (*fp) = die_type (die, cu); |
| 6344 | FIELD_NAME (*fp) = fieldname; |
| 6345 | } |
| 6346 | else if (die->tag == DW_TAG_inheritance) |
| 6347 | { |
| 6348 | /* C++ base class field. */ |
| 6349 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
| 6350 | if (attr) |
| 6351 | { |
| 6352 | int byte_offset = 0; |
| 6353 | |
| 6354 | if (attr_form_is_section_offset (attr)) |
| 6355 | dwarf2_complex_location_expr_complaint (); |
| 6356 | else if (attr_form_is_constant (attr)) |
| 6357 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
| 6358 | else if (attr_form_is_block (attr)) |
| 6359 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
| 6360 | else |
| 6361 | dwarf2_complex_location_expr_complaint (); |
| 6362 | |
| 6363 | SET_FIELD_BITPOS (*fp, byte_offset * bits_per_byte); |
| 6364 | } |
| 6365 | FIELD_BITSIZE (*fp) = 0; |
| 6366 | FIELD_TYPE (*fp) = die_type (die, cu); |
| 6367 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
| 6368 | fip->nbaseclasses++; |
| 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | /* Add a typedef defined in the scope of the FIP's class. */ |
| 6373 | |
| 6374 | static void |
| 6375 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, |
| 6376 | struct dwarf2_cu *cu) |
| 6377 | { |
| 6378 | struct objfile *objfile = cu->objfile; |
| 6379 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 6380 | struct typedef_field_list *new_field; |
| 6381 | struct attribute *attr; |
| 6382 | struct typedef_field *fp; |
| 6383 | char *fieldname = ""; |
| 6384 | |
| 6385 | /* Allocate a new field list entry and link it in. */ |
| 6386 | new_field = xzalloc (sizeof (*new_field)); |
| 6387 | make_cleanup (xfree, new_field); |
| 6388 | |
| 6389 | gdb_assert (die->tag == DW_TAG_typedef); |
| 6390 | |
| 6391 | fp = &new_field->field; |
| 6392 | |
| 6393 | /* Get name of field. */ |
| 6394 | fp->name = dwarf2_name (die, cu); |
| 6395 | if (fp->name == NULL) |
| 6396 | return; |
| 6397 | |
| 6398 | fp->type = read_type_die (die, cu); |
| 6399 | |
| 6400 | new_field->next = fip->typedef_field_list; |
| 6401 | fip->typedef_field_list = new_field; |
| 6402 | fip->typedef_field_list_count++; |
| 6403 | } |
| 6404 | |
| 6405 | /* Create the vector of fields, and attach it to the type. */ |
| 6406 | |
| 6407 | static void |
| 6408 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
| 6409 | struct dwarf2_cu *cu) |
| 6410 | { |
| 6411 | int nfields = fip->nfields; |
| 6412 | |
| 6413 | /* Record the field count, allocate space for the array of fields, |
| 6414 | and create blank accessibility bitfields if necessary. */ |
| 6415 | TYPE_NFIELDS (type) = nfields; |
| 6416 | TYPE_FIELDS (type) = (struct field *) |
| 6417 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
| 6418 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); |
| 6419 | |
| 6420 | if (fip->non_public_fields && cu->language != language_ada) |
| 6421 | { |
| 6422 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 6423 | |
| 6424 | TYPE_FIELD_PRIVATE_BITS (type) = |
| 6425 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 6426 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); |
| 6427 | |
| 6428 | TYPE_FIELD_PROTECTED_BITS (type) = |
| 6429 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 6430 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); |
| 6431 | |
| 6432 | TYPE_FIELD_IGNORE_BITS (type) = |
| 6433 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 6434 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); |
| 6435 | } |
| 6436 | |
| 6437 | /* If the type has baseclasses, allocate and clear a bit vector for |
| 6438 | TYPE_FIELD_VIRTUAL_BITS. */ |
| 6439 | if (fip->nbaseclasses && cu->language != language_ada) |
| 6440 | { |
| 6441 | int num_bytes = B_BYTES (fip->nbaseclasses); |
| 6442 | unsigned char *pointer; |
| 6443 | |
| 6444 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 6445 | pointer = TYPE_ALLOC (type, num_bytes); |
| 6446 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; |
| 6447 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
| 6448 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; |
| 6449 | } |
| 6450 | |
| 6451 | /* Copy the saved-up fields into the field vector. Start from the head of |
| 6452 | the list, adding to the tail of the field array, so that they end up in |
| 6453 | the same order in the array in which they were added to the list. */ |
| 6454 | while (nfields-- > 0) |
| 6455 | { |
| 6456 | struct nextfield *fieldp; |
| 6457 | |
| 6458 | if (fip->fields) |
| 6459 | { |
| 6460 | fieldp = fip->fields; |
| 6461 | fip->fields = fieldp->next; |
| 6462 | } |
| 6463 | else |
| 6464 | { |
| 6465 | fieldp = fip->baseclasses; |
| 6466 | fip->baseclasses = fieldp->next; |
| 6467 | } |
| 6468 | |
| 6469 | TYPE_FIELD (type, nfields) = fieldp->field; |
| 6470 | switch (fieldp->accessibility) |
| 6471 | { |
| 6472 | case DW_ACCESS_private: |
| 6473 | if (cu->language != language_ada) |
| 6474 | SET_TYPE_FIELD_PRIVATE (type, nfields); |
| 6475 | break; |
| 6476 | |
| 6477 | case DW_ACCESS_protected: |
| 6478 | if (cu->language != language_ada) |
| 6479 | SET_TYPE_FIELD_PROTECTED (type, nfields); |
| 6480 | break; |
| 6481 | |
| 6482 | case DW_ACCESS_public: |
| 6483 | break; |
| 6484 | |
| 6485 | default: |
| 6486 | /* Unknown accessibility. Complain and treat it as public. */ |
| 6487 | { |
| 6488 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
| 6489 | fieldp->accessibility); |
| 6490 | } |
| 6491 | break; |
| 6492 | } |
| 6493 | if (nfields < fip->nbaseclasses) |
| 6494 | { |
| 6495 | switch (fieldp->virtuality) |
| 6496 | { |
| 6497 | case DW_VIRTUALITY_virtual: |
| 6498 | case DW_VIRTUALITY_pure_virtual: |
| 6499 | if (cu->language == language_ada) |
| 6500 | error ("unexpected virtuality in component of Ada type"); |
| 6501 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
| 6502 | break; |
| 6503 | } |
| 6504 | } |
| 6505 | } |
| 6506 | } |
| 6507 | |
| 6508 | /* Add a member function to the proper fieldlist. */ |
| 6509 | |
| 6510 | static void |
| 6511 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
| 6512 | struct type *type, struct dwarf2_cu *cu) |
| 6513 | { |
| 6514 | struct objfile *objfile = cu->objfile; |
| 6515 | struct attribute *attr; |
| 6516 | struct fnfieldlist *flp; |
| 6517 | int i; |
| 6518 | struct fn_field *fnp; |
| 6519 | char *fieldname; |
| 6520 | struct nextfnfield *new_fnfield; |
| 6521 | struct type *this_type; |
| 6522 | |
| 6523 | if (cu->language == language_ada) |
| 6524 | error ("unexpected member function in Ada type"); |
| 6525 | |
| 6526 | /* Get name of member function. */ |
| 6527 | fieldname = dwarf2_name (die, cu); |
| 6528 | if (fieldname == NULL) |
| 6529 | return; |
| 6530 | |
| 6531 | /* Look up member function name in fieldlist. */ |
| 6532 | for (i = 0; i < fip->nfnfields; i++) |
| 6533 | { |
| 6534 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
| 6535 | break; |
| 6536 | } |
| 6537 | |
| 6538 | /* Create new list element if necessary. */ |
| 6539 | if (i < fip->nfnfields) |
| 6540 | flp = &fip->fnfieldlists[i]; |
| 6541 | else |
| 6542 | { |
| 6543 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 6544 | { |
| 6545 | fip->fnfieldlists = (struct fnfieldlist *) |
| 6546 | xrealloc (fip->fnfieldlists, |
| 6547 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) |
| 6548 | * sizeof (struct fnfieldlist)); |
| 6549 | if (fip->nfnfields == 0) |
| 6550 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
| 6551 | } |
| 6552 | flp = &fip->fnfieldlists[fip->nfnfields]; |
| 6553 | flp->name = fieldname; |
| 6554 | flp->length = 0; |
| 6555 | flp->head = NULL; |
| 6556 | i = fip->nfnfields++; |
| 6557 | } |
| 6558 | |
| 6559 | /* Create a new member function field and chain it to the field list |
| 6560 | entry. */ |
| 6561 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
| 6562 | make_cleanup (xfree, new_fnfield); |
| 6563 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
| 6564 | new_fnfield->next = flp->head; |
| 6565 | flp->head = new_fnfield; |
| 6566 | flp->length++; |
| 6567 | |
| 6568 | /* Fill in the member function field info. */ |
| 6569 | fnp = &new_fnfield->fnfield; |
| 6570 | |
| 6571 | /* Delay processing of the physname until later. */ |
| 6572 | if (cu->language == language_cplus || cu->language == language_java) |
| 6573 | { |
| 6574 | add_to_method_list (type, i, flp->length - 1, fieldname, |
| 6575 | die, cu); |
| 6576 | } |
| 6577 | else |
| 6578 | { |
| 6579 | char *physname = (char *) dwarf2_physname (fieldname, die, cu); |
| 6580 | fnp->physname = physname ? physname : ""; |
| 6581 | } |
| 6582 | |
| 6583 | fnp->type = alloc_type (objfile); |
| 6584 | this_type = read_type_die (die, cu); |
| 6585 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) |
| 6586 | { |
| 6587 | int nparams = TYPE_NFIELDS (this_type); |
| 6588 | |
| 6589 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
| 6590 | of the method itself (TYPE_CODE_METHOD). */ |
| 6591 | smash_to_method_type (fnp->type, type, |
| 6592 | TYPE_TARGET_TYPE (this_type), |
| 6593 | TYPE_FIELDS (this_type), |
| 6594 | TYPE_NFIELDS (this_type), |
| 6595 | TYPE_VARARGS (this_type)); |
| 6596 | |
| 6597 | /* Handle static member functions. |
| 6598 | Dwarf2 has no clean way to discern C++ static and non-static |
| 6599 | member functions. G++ helps GDB by marking the first |
| 6600 | parameter for non-static member functions (which is the this |
| 6601 | pointer) as artificial. We obtain this information from |
| 6602 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ |
| 6603 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
| 6604 | fnp->voffset = VOFFSET_STATIC; |
| 6605 | } |
| 6606 | else |
| 6607 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
| 6608 | dwarf2_full_name (fieldname, die, cu)); |
| 6609 | |
| 6610 | /* Get fcontext from DW_AT_containing_type if present. */ |
| 6611 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
| 6612 | fnp->fcontext = die_containing_type (die, cu); |
| 6613 | |
| 6614 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
| 6615 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ |
| 6616 | |
| 6617 | /* Get accessibility. */ |
| 6618 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
| 6619 | if (attr) |
| 6620 | { |
| 6621 | switch (DW_UNSND (attr)) |
| 6622 | { |
| 6623 | case DW_ACCESS_private: |
| 6624 | fnp->is_private = 1; |
| 6625 | break; |
| 6626 | case DW_ACCESS_protected: |
| 6627 | fnp->is_protected = 1; |
| 6628 | break; |
| 6629 | } |
| 6630 | } |
| 6631 | |
| 6632 | /* Check for artificial methods. */ |
| 6633 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
| 6634 | if (attr && DW_UNSND (attr) != 0) |
| 6635 | fnp->is_artificial = 1; |
| 6636 | |
| 6637 | /* Get index in virtual function table if it is a virtual member |
| 6638 | function. For older versions of GCC, this is an offset in the |
| 6639 | appropriate virtual table, as specified by DW_AT_containing_type. |
| 6640 | For everyone else, it is an expression to be evaluated relative |
| 6641 | to the object address. */ |
| 6642 | |
| 6643 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
| 6644 | if (attr) |
| 6645 | { |
| 6646 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
| 6647 | { |
| 6648 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
| 6649 | { |
| 6650 | /* Old-style GCC. */ |
| 6651 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
| 6652 | } |
| 6653 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref |
| 6654 | || (DW_BLOCK (attr)->size > 1 |
| 6655 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size |
| 6656 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) |
| 6657 | { |
| 6658 | struct dwarf_block blk; |
| 6659 | int offset; |
| 6660 | |
| 6661 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref |
| 6662 | ? 1 : 2); |
| 6663 | blk.size = DW_BLOCK (attr)->size - offset; |
| 6664 | blk.data = DW_BLOCK (attr)->data + offset; |
| 6665 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); |
| 6666 | if ((fnp->voffset % cu->header.addr_size) != 0) |
| 6667 | dwarf2_complex_location_expr_complaint (); |
| 6668 | else |
| 6669 | fnp->voffset /= cu->header.addr_size; |
| 6670 | fnp->voffset += 2; |
| 6671 | } |
| 6672 | else |
| 6673 | dwarf2_complex_location_expr_complaint (); |
| 6674 | |
| 6675 | if (!fnp->fcontext) |
| 6676 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); |
| 6677 | } |
| 6678 | else if (attr_form_is_section_offset (attr)) |
| 6679 | { |
| 6680 | dwarf2_complex_location_expr_complaint (); |
| 6681 | } |
| 6682 | else |
| 6683 | { |
| 6684 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
| 6685 | fieldname); |
| 6686 | } |
| 6687 | } |
| 6688 | else |
| 6689 | { |
| 6690 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
| 6691 | if (attr && DW_UNSND (attr)) |
| 6692 | { |
| 6693 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ |
| 6694 | complaint (&symfile_complaints, |
| 6695 | _("Member function \"%s\" (offset %d) is virtual " |
| 6696 | "but the vtable offset is not specified"), |
| 6697 | fieldname, die->offset); |
| 6698 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 6699 | TYPE_CPLUS_DYNAMIC (type) = 1; |
| 6700 | } |
| 6701 | } |
| 6702 | } |
| 6703 | |
| 6704 | /* Create the vector of member function fields, and attach it to the type. */ |
| 6705 | |
| 6706 | static void |
| 6707 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
| 6708 | struct dwarf2_cu *cu) |
| 6709 | { |
| 6710 | struct fnfieldlist *flp; |
| 6711 | int total_length = 0; |
| 6712 | int i; |
| 6713 | |
| 6714 | if (cu->language == language_ada) |
| 6715 | error ("unexpected member functions in Ada type"); |
| 6716 | |
| 6717 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 6718 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 6719 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); |
| 6720 | |
| 6721 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) |
| 6722 | { |
| 6723 | struct nextfnfield *nfp = flp->head; |
| 6724 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); |
| 6725 | int k; |
| 6726 | |
| 6727 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; |
| 6728 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; |
| 6729 | fn_flp->fn_fields = (struct fn_field *) |
| 6730 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); |
| 6731 | for (k = flp->length; (k--, nfp); nfp = nfp->next) |
| 6732 | fn_flp->fn_fields[k] = nfp->fnfield; |
| 6733 | |
| 6734 | total_length += flp->length; |
| 6735 | } |
| 6736 | |
| 6737 | TYPE_NFN_FIELDS (type) = fip->nfnfields; |
| 6738 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; |
| 6739 | } |
| 6740 | |
| 6741 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
| 6742 | language, zero otherwise. */ |
| 6743 | static int |
| 6744 | is_vtable_name (const char *name, struct dwarf2_cu *cu) |
| 6745 | { |
| 6746 | static const char vptr[] = "_vptr"; |
| 6747 | static const char vtable[] = "vtable"; |
| 6748 | |
| 6749 | /* Look for the C++ and Java forms of the vtable. */ |
| 6750 | if ((cu->language == language_java |
| 6751 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) |
| 6752 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 |
| 6753 | && is_cplus_marker (name[sizeof (vptr) - 1]))) |
| 6754 | return 1; |
| 6755 | |
| 6756 | return 0; |
| 6757 | } |
| 6758 | |
| 6759 | /* GCC outputs unnamed structures that are really pointers to member |
| 6760 | functions, with the ABI-specified layout. If TYPE describes |
| 6761 | such a structure, smash it into a member function type. |
| 6762 | |
| 6763 | GCC shouldn't do this; it should just output pointer to member DIEs. |
| 6764 | This is GCC PR debug/28767. */ |
| 6765 | |
| 6766 | static void |
| 6767 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) |
| 6768 | { |
| 6769 | struct type *pfn_type, *domain_type, *new_type; |
| 6770 | |
| 6771 | /* Check for a structure with no name and two children. */ |
| 6772 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
| 6773 | return; |
| 6774 | |
| 6775 | /* Check for __pfn and __delta members. */ |
| 6776 | if (TYPE_FIELD_NAME (type, 0) == NULL |
| 6777 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 |
| 6778 | || TYPE_FIELD_NAME (type, 1) == NULL |
| 6779 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) |
| 6780 | return; |
| 6781 | |
| 6782 | /* Find the type of the method. */ |
| 6783 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
| 6784 | if (pfn_type == NULL |
| 6785 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR |
| 6786 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) |
| 6787 | return; |
| 6788 | |
| 6789 | /* Look for the "this" argument. */ |
| 6790 | pfn_type = TYPE_TARGET_TYPE (pfn_type); |
| 6791 | if (TYPE_NFIELDS (pfn_type) == 0 |
| 6792 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
| 6793 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
| 6794 | return; |
| 6795 | |
| 6796 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); |
| 6797 | new_type = alloc_type (objfile); |
| 6798 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), |
| 6799 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
| 6800 | TYPE_VARARGS (pfn_type)); |
| 6801 | smash_to_methodptr_type (type, new_type); |
| 6802 | } |
| 6803 | |
| 6804 | /* Called when we find the DIE that starts a structure or union scope |
| 6805 | (definition) to create a type for the structure or union. Fill in |
| 6806 | the type's name and general properties; the members will not be |
| 6807 | processed until process_structure_type. |
| 6808 | |
| 6809 | NOTE: we need to call these functions regardless of whether or not the |
| 6810 | DIE has a DW_AT_name attribute, since it might be an anonymous |
| 6811 | structure or union. This gets the type entered into our set of |
| 6812 | user defined types. |
| 6813 | |
| 6814 | However, if the structure is incomplete (an opaque struct/union) |
| 6815 | then suppress creating a symbol table entry for it since gdb only |
| 6816 | wants to find the one with the complete definition. Note that if |
| 6817 | it is complete, we just call new_symbol, which does it's own |
| 6818 | checking about whether the struct/union is anonymous or not (and |
| 6819 | suppresses creating a symbol table entry itself). */ |
| 6820 | |
| 6821 | static struct type * |
| 6822 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
| 6823 | { |
| 6824 | struct objfile *objfile = cu->objfile; |
| 6825 | struct type *type; |
| 6826 | struct attribute *attr; |
| 6827 | char *name; |
| 6828 | |
| 6829 | /* If the definition of this type lives in .debug_types, read that type. |
| 6830 | Don't follow DW_AT_specification though, that will take us back up |
| 6831 | the chain and we want to go down. */ |
| 6832 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); |
| 6833 | if (attr) |
| 6834 | { |
| 6835 | struct dwarf2_cu *type_cu = cu; |
| 6836 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 6837 | |
| 6838 | /* We could just recurse on read_structure_type, but we need to call |
| 6839 | get_die_type to ensure only one type for this DIE is created. |
| 6840 | This is important, for example, because for c++ classes we need |
| 6841 | TYPE_NAME set which is only done by new_symbol. Blech. */ |
| 6842 | type = read_type_die (type_die, type_cu); |
| 6843 | |
| 6844 | /* TYPE_CU may not be the same as CU. |
| 6845 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 6846 | return set_die_type (die, type, cu); |
| 6847 | } |
| 6848 | |
| 6849 | type = alloc_type (objfile); |
| 6850 | INIT_CPLUS_SPECIFIC (type); |
| 6851 | |
| 6852 | name = dwarf2_name (die, cu); |
| 6853 | if (name != NULL) |
| 6854 | { |
| 6855 | if (cu->language == language_cplus |
| 6856 | || cu->language == language_java) |
| 6857 | { |
| 6858 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
| 6859 | |
| 6860 | /* dwarf2_full_name might have already finished building the DIE's |
| 6861 | type. If so, there is no need to continue. */ |
| 6862 | if (get_die_type (die, cu) != NULL) |
| 6863 | return get_die_type (die, cu); |
| 6864 | |
| 6865 | TYPE_TAG_NAME (type) = full_name; |
| 6866 | if (die->tag == DW_TAG_structure_type |
| 6867 | || die->tag == DW_TAG_class_type) |
| 6868 | TYPE_NAME (type) = TYPE_TAG_NAME (type); |
| 6869 | } |
| 6870 | else |
| 6871 | { |
| 6872 | /* The name is already allocated along with this objfile, so |
| 6873 | we don't need to duplicate it for the type. */ |
| 6874 | TYPE_TAG_NAME (type) = (char *) name; |
| 6875 | if (die->tag == DW_TAG_class_type) |
| 6876 | TYPE_NAME (type) = TYPE_TAG_NAME (type); |
| 6877 | } |
| 6878 | } |
| 6879 | |
| 6880 | if (die->tag == DW_TAG_structure_type) |
| 6881 | { |
| 6882 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
| 6883 | } |
| 6884 | else if (die->tag == DW_TAG_union_type) |
| 6885 | { |
| 6886 | TYPE_CODE (type) = TYPE_CODE_UNION; |
| 6887 | } |
| 6888 | else |
| 6889 | { |
| 6890 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
| 6891 | } |
| 6892 | |
| 6893 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
| 6894 | TYPE_DECLARED_CLASS (type) = 1; |
| 6895 | |
| 6896 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 6897 | if (attr) |
| 6898 | { |
| 6899 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 6900 | } |
| 6901 | else |
| 6902 | { |
| 6903 | TYPE_LENGTH (type) = 0; |
| 6904 | } |
| 6905 | |
| 6906 | TYPE_STUB_SUPPORTED (type) = 1; |
| 6907 | if (die_is_declaration (die, cu)) |
| 6908 | TYPE_STUB (type) = 1; |
| 6909 | else if (attr == NULL && die->child == NULL |
| 6910 | && producer_is_realview (cu->producer)) |
| 6911 | /* RealView does not output the required DW_AT_declaration |
| 6912 | on incomplete types. */ |
| 6913 | TYPE_STUB (type) = 1; |
| 6914 | |
| 6915 | /* We need to add the type field to the die immediately so we don't |
| 6916 | infinitely recurse when dealing with pointers to the structure |
| 6917 | type within the structure itself. */ |
| 6918 | set_die_type (die, type, cu); |
| 6919 | |
| 6920 | /* set_die_type should be already done. */ |
| 6921 | set_descriptive_type (type, die, cu); |
| 6922 | |
| 6923 | return type; |
| 6924 | } |
| 6925 | |
| 6926 | /* Finish creating a structure or union type, including filling in |
| 6927 | its members and creating a symbol for it. */ |
| 6928 | |
| 6929 | static void |
| 6930 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 6931 | { |
| 6932 | struct objfile *objfile = cu->objfile; |
| 6933 | struct die_info *child_die = die->child; |
| 6934 | struct type *type; |
| 6935 | |
| 6936 | type = get_die_type (die, cu); |
| 6937 | if (type == NULL) |
| 6938 | type = read_structure_type (die, cu); |
| 6939 | |
| 6940 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
| 6941 | { |
| 6942 | struct field_info fi; |
| 6943 | struct die_info *child_die; |
| 6944 | VEC (symbolp) *template_args = NULL; |
| 6945 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 6946 | |
| 6947 | memset (&fi, 0, sizeof (struct field_info)); |
| 6948 | |
| 6949 | child_die = die->child; |
| 6950 | |
| 6951 | while (child_die && child_die->tag) |
| 6952 | { |
| 6953 | if (child_die->tag == DW_TAG_member |
| 6954 | || child_die->tag == DW_TAG_variable) |
| 6955 | { |
| 6956 | /* NOTE: carlton/2002-11-05: A C++ static data member |
| 6957 | should be a DW_TAG_member that is a declaration, but |
| 6958 | all versions of G++ as of this writing (so through at |
| 6959 | least 3.2.1) incorrectly generate DW_TAG_variable |
| 6960 | tags for them instead. */ |
| 6961 | dwarf2_add_field (&fi, child_die, cu); |
| 6962 | } |
| 6963 | else if (child_die->tag == DW_TAG_subprogram) |
| 6964 | { |
| 6965 | /* C++ member function. */ |
| 6966 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
| 6967 | } |
| 6968 | else if (child_die->tag == DW_TAG_inheritance) |
| 6969 | { |
| 6970 | /* C++ base class field. */ |
| 6971 | dwarf2_add_field (&fi, child_die, cu); |
| 6972 | } |
| 6973 | else if (child_die->tag == DW_TAG_typedef) |
| 6974 | dwarf2_add_typedef (&fi, child_die, cu); |
| 6975 | else if (child_die->tag == DW_TAG_template_type_param |
| 6976 | || child_die->tag == DW_TAG_template_value_param) |
| 6977 | { |
| 6978 | struct symbol *arg = new_symbol (child_die, NULL, cu); |
| 6979 | |
| 6980 | if (arg != NULL) |
| 6981 | VEC_safe_push (symbolp, template_args, arg); |
| 6982 | } |
| 6983 | |
| 6984 | child_die = sibling_die (child_die); |
| 6985 | } |
| 6986 | |
| 6987 | /* Attach template arguments to type. */ |
| 6988 | if (! VEC_empty (symbolp, template_args)) |
| 6989 | { |
| 6990 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 6991 | TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 6992 | = VEC_length (symbolp, template_args); |
| 6993 | TYPE_TEMPLATE_ARGUMENTS (type) |
| 6994 | = obstack_alloc (&objfile->objfile_obstack, |
| 6995 | (TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 6996 | * sizeof (struct symbol *))); |
| 6997 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), |
| 6998 | VEC_address (symbolp, template_args), |
| 6999 | (TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 7000 | * sizeof (struct symbol *))); |
| 7001 | VEC_free (symbolp, template_args); |
| 7002 | } |
| 7003 | |
| 7004 | /* Attach fields and member functions to the type. */ |
| 7005 | if (fi.nfields) |
| 7006 | dwarf2_attach_fields_to_type (&fi, type, cu); |
| 7007 | if (fi.nfnfields) |
| 7008 | { |
| 7009 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
| 7010 | |
| 7011 | /* Get the type which refers to the base class (possibly this |
| 7012 | class itself) which contains the vtable pointer for the current |
| 7013 | class from the DW_AT_containing_type attribute. This use of |
| 7014 | DW_AT_containing_type is a GNU extension. */ |
| 7015 | |
| 7016 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
| 7017 | { |
| 7018 | struct type *t = die_containing_type (die, cu); |
| 7019 | |
| 7020 | TYPE_VPTR_BASETYPE (type) = t; |
| 7021 | if (type == t) |
| 7022 | { |
| 7023 | int i; |
| 7024 | |
| 7025 | /* Our own class provides vtbl ptr. */ |
| 7026 | for (i = TYPE_NFIELDS (t) - 1; |
| 7027 | i >= TYPE_N_BASECLASSES (t); |
| 7028 | --i) |
| 7029 | { |
| 7030 | char *fieldname = TYPE_FIELD_NAME (t, i); |
| 7031 | |
| 7032 | if (is_vtable_name (fieldname, cu)) |
| 7033 | { |
| 7034 | TYPE_VPTR_FIELDNO (type) = i; |
| 7035 | break; |
| 7036 | } |
| 7037 | } |
| 7038 | |
| 7039 | /* Complain if virtual function table field not found. */ |
| 7040 | if (i < TYPE_N_BASECLASSES (t)) |
| 7041 | complaint (&symfile_complaints, |
| 7042 | _("virtual function table pointer " |
| 7043 | "not found when defining class '%s'"), |
| 7044 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
| 7045 | ""); |
| 7046 | } |
| 7047 | else |
| 7048 | { |
| 7049 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); |
| 7050 | } |
| 7051 | } |
| 7052 | else if (cu->producer |
| 7053 | && strncmp (cu->producer, |
| 7054 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) |
| 7055 | { |
| 7056 | /* The IBM XLC compiler does not provide direct indication |
| 7057 | of the containing type, but the vtable pointer is |
| 7058 | always named __vfp. */ |
| 7059 | |
| 7060 | int i; |
| 7061 | |
| 7062 | for (i = TYPE_NFIELDS (type) - 1; |
| 7063 | i >= TYPE_N_BASECLASSES (type); |
| 7064 | --i) |
| 7065 | { |
| 7066 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) |
| 7067 | { |
| 7068 | TYPE_VPTR_FIELDNO (type) = i; |
| 7069 | TYPE_VPTR_BASETYPE (type) = type; |
| 7070 | break; |
| 7071 | } |
| 7072 | } |
| 7073 | } |
| 7074 | } |
| 7075 | |
| 7076 | /* Copy fi.typedef_field_list linked list elements content into the |
| 7077 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ |
| 7078 | if (fi.typedef_field_list) |
| 7079 | { |
| 7080 | int i = fi.typedef_field_list_count; |
| 7081 | |
| 7082 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7083 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
| 7084 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); |
| 7085 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; |
| 7086 | |
| 7087 | /* Reverse the list order to keep the debug info elements order. */ |
| 7088 | while (--i >= 0) |
| 7089 | { |
| 7090 | struct typedef_field *dest, *src; |
| 7091 | |
| 7092 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
| 7093 | src = &fi.typedef_field_list->field; |
| 7094 | fi.typedef_field_list = fi.typedef_field_list->next; |
| 7095 | *dest = *src; |
| 7096 | } |
| 7097 | } |
| 7098 | |
| 7099 | do_cleanups (back_to); |
| 7100 | } |
| 7101 | |
| 7102 | quirk_gcc_member_function_pointer (type, cu->objfile); |
| 7103 | |
| 7104 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
| 7105 | snapshots) has been known to create a die giving a declaration |
| 7106 | for a class that has, as a child, a die giving a definition for a |
| 7107 | nested class. So we have to process our children even if the |
| 7108 | current die is a declaration. Normally, of course, a declaration |
| 7109 | won't have any children at all. */ |
| 7110 | |
| 7111 | while (child_die != NULL && child_die->tag) |
| 7112 | { |
| 7113 | if (child_die->tag == DW_TAG_member |
| 7114 | || child_die->tag == DW_TAG_variable |
| 7115 | || child_die->tag == DW_TAG_inheritance |
| 7116 | || child_die->tag == DW_TAG_template_value_param |
| 7117 | || child_die->tag == DW_TAG_template_type_param) |
| 7118 | { |
| 7119 | /* Do nothing. */ |
| 7120 | } |
| 7121 | else |
| 7122 | process_die (child_die, cu); |
| 7123 | |
| 7124 | child_die = sibling_die (child_die); |
| 7125 | } |
| 7126 | |
| 7127 | /* Do not consider external references. According to the DWARF standard, |
| 7128 | these DIEs are identified by the fact that they have no byte_size |
| 7129 | attribute, and a declaration attribute. */ |
| 7130 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL |
| 7131 | || !die_is_declaration (die, cu)) |
| 7132 | new_symbol (die, type, cu); |
| 7133 | } |
| 7134 | |
| 7135 | /* Given a DW_AT_enumeration_type die, set its type. We do not |
| 7136 | complete the type's fields yet, or create any symbols. */ |
| 7137 | |
| 7138 | static struct type * |
| 7139 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7140 | { |
| 7141 | struct objfile *objfile = cu->objfile; |
| 7142 | struct type *type; |
| 7143 | struct attribute *attr; |
| 7144 | const char *name; |
| 7145 | |
| 7146 | /* If the definition of this type lives in .debug_types, read that type. |
| 7147 | Don't follow DW_AT_specification though, that will take us back up |
| 7148 | the chain and we want to go down. */ |
| 7149 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); |
| 7150 | if (attr) |
| 7151 | { |
| 7152 | struct dwarf2_cu *type_cu = cu; |
| 7153 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 7154 | |
| 7155 | type = read_type_die (type_die, type_cu); |
| 7156 | |
| 7157 | /* TYPE_CU may not be the same as CU. |
| 7158 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 7159 | return set_die_type (die, type, cu); |
| 7160 | } |
| 7161 | |
| 7162 | type = alloc_type (objfile); |
| 7163 | |
| 7164 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
| 7165 | name = dwarf2_full_name (NULL, die, cu); |
| 7166 | if (name != NULL) |
| 7167 | TYPE_TAG_NAME (type) = (char *) name; |
| 7168 | |
| 7169 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7170 | if (attr) |
| 7171 | { |
| 7172 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 7173 | } |
| 7174 | else |
| 7175 | { |
| 7176 | TYPE_LENGTH (type) = 0; |
| 7177 | } |
| 7178 | |
| 7179 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
| 7180 | declared as private in the package spec, and then defined only |
| 7181 | inside the package body. Such types are known as Taft Amendment |
| 7182 | Types. When another package uses such a type, an incomplete DIE |
| 7183 | may be generated by the compiler. */ |
| 7184 | if (die_is_declaration (die, cu)) |
| 7185 | TYPE_STUB (type) = 1; |
| 7186 | |
| 7187 | return set_die_type (die, type, cu); |
| 7188 | } |
| 7189 | |
| 7190 | /* Given a pointer to a die which begins an enumeration, process all |
| 7191 | the dies that define the members of the enumeration, and create the |
| 7192 | symbol for the enumeration type. |
| 7193 | |
| 7194 | NOTE: We reverse the order of the element list. */ |
| 7195 | |
| 7196 | static void |
| 7197 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 7198 | { |
| 7199 | struct type *this_type; |
| 7200 | |
| 7201 | this_type = get_die_type (die, cu); |
| 7202 | if (this_type == NULL) |
| 7203 | this_type = read_enumeration_type (die, cu); |
| 7204 | |
| 7205 | if (die->child != NULL) |
| 7206 | { |
| 7207 | struct die_info *child_die; |
| 7208 | struct symbol *sym; |
| 7209 | struct field *fields = NULL; |
| 7210 | int num_fields = 0; |
| 7211 | int unsigned_enum = 1; |
| 7212 | char *name; |
| 7213 | |
| 7214 | child_die = die->child; |
| 7215 | while (child_die && child_die->tag) |
| 7216 | { |
| 7217 | if (child_die->tag != DW_TAG_enumerator) |
| 7218 | { |
| 7219 | process_die (child_die, cu); |
| 7220 | } |
| 7221 | else |
| 7222 | { |
| 7223 | name = dwarf2_name (child_die, cu); |
| 7224 | if (name) |
| 7225 | { |
| 7226 | sym = new_symbol (child_die, this_type, cu); |
| 7227 | if (SYMBOL_VALUE (sym) < 0) |
| 7228 | unsigned_enum = 0; |
| 7229 | |
| 7230 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 7231 | { |
| 7232 | fields = (struct field *) |
| 7233 | xrealloc (fields, |
| 7234 | (num_fields + DW_FIELD_ALLOC_CHUNK) |
| 7235 | * sizeof (struct field)); |
| 7236 | } |
| 7237 | |
| 7238 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
| 7239 | FIELD_TYPE (fields[num_fields]) = NULL; |
| 7240 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
| 7241 | FIELD_BITSIZE (fields[num_fields]) = 0; |
| 7242 | |
| 7243 | num_fields++; |
| 7244 | } |
| 7245 | } |
| 7246 | |
| 7247 | child_die = sibling_die (child_die); |
| 7248 | } |
| 7249 | |
| 7250 | if (num_fields) |
| 7251 | { |
| 7252 | TYPE_NFIELDS (this_type) = num_fields; |
| 7253 | TYPE_FIELDS (this_type) = (struct field *) |
| 7254 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); |
| 7255 | memcpy (TYPE_FIELDS (this_type), fields, |
| 7256 | sizeof (struct field) * num_fields); |
| 7257 | xfree (fields); |
| 7258 | } |
| 7259 | if (unsigned_enum) |
| 7260 | TYPE_UNSIGNED (this_type) = 1; |
| 7261 | } |
| 7262 | |
| 7263 | new_symbol (die, this_type, cu); |
| 7264 | } |
| 7265 | |
| 7266 | /* Extract all information from a DW_TAG_array_type DIE and put it in |
| 7267 | the DIE's type field. For now, this only handles one dimensional |
| 7268 | arrays. */ |
| 7269 | |
| 7270 | static struct type * |
| 7271 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7272 | { |
| 7273 | struct objfile *objfile = cu->objfile; |
| 7274 | struct die_info *child_die; |
| 7275 | struct type *type; |
| 7276 | struct type *element_type, *range_type, *index_type; |
| 7277 | struct type **range_types = NULL; |
| 7278 | struct attribute *attr; |
| 7279 | int ndim = 0; |
| 7280 | struct cleanup *back_to; |
| 7281 | char *name; |
| 7282 | |
| 7283 | element_type = die_type (die, cu); |
| 7284 | |
| 7285 | /* The die_type call above may have already set the type for this DIE. */ |
| 7286 | type = get_die_type (die, cu); |
| 7287 | if (type) |
| 7288 | return type; |
| 7289 | |
| 7290 | /* Irix 6.2 native cc creates array types without children for |
| 7291 | arrays with unspecified length. */ |
| 7292 | if (die->child == NULL) |
| 7293 | { |
| 7294 | index_type = objfile_type (objfile)->builtin_int; |
| 7295 | range_type = create_range_type (NULL, index_type, 0, -1); |
| 7296 | type = create_array_type (NULL, element_type, range_type); |
| 7297 | return set_die_type (die, type, cu); |
| 7298 | } |
| 7299 | |
| 7300 | back_to = make_cleanup (null_cleanup, NULL); |
| 7301 | child_die = die->child; |
| 7302 | while (child_die && child_die->tag) |
| 7303 | { |
| 7304 | if (child_die->tag == DW_TAG_subrange_type) |
| 7305 | { |
| 7306 | struct type *child_type = read_type_die (child_die, cu); |
| 7307 | |
| 7308 | if (child_type != NULL) |
| 7309 | { |
| 7310 | /* The range type was succesfully read. Save it for the |
| 7311 | array type creation. */ |
| 7312 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
| 7313 | { |
| 7314 | range_types = (struct type **) |
| 7315 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) |
| 7316 | * sizeof (struct type *)); |
| 7317 | if (ndim == 0) |
| 7318 | make_cleanup (free_current_contents, &range_types); |
| 7319 | } |
| 7320 | range_types[ndim++] = child_type; |
| 7321 | } |
| 7322 | } |
| 7323 | child_die = sibling_die (child_die); |
| 7324 | } |
| 7325 | |
| 7326 | /* Dwarf2 dimensions are output from left to right, create the |
| 7327 | necessary array types in backwards order. */ |
| 7328 | |
| 7329 | type = element_type; |
| 7330 | |
| 7331 | if (read_array_order (die, cu) == DW_ORD_col_major) |
| 7332 | { |
| 7333 | int i = 0; |
| 7334 | |
| 7335 | while (i < ndim) |
| 7336 | type = create_array_type (NULL, type, range_types[i++]); |
| 7337 | } |
| 7338 | else |
| 7339 | { |
| 7340 | while (ndim-- > 0) |
| 7341 | type = create_array_type (NULL, type, range_types[ndim]); |
| 7342 | } |
| 7343 | |
| 7344 | /* Understand Dwarf2 support for vector types (like they occur on |
| 7345 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the |
| 7346 | array type. This is not part of the Dwarf2/3 standard yet, but a |
| 7347 | custom vendor extension. The main difference between a regular |
| 7348 | array and the vector variant is that vectors are passed by value |
| 7349 | to functions. */ |
| 7350 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
| 7351 | if (attr) |
| 7352 | make_vector_type (type); |
| 7353 | |
| 7354 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
| 7355 | implementation may choose to implement triple vectors using this |
| 7356 | attribute. */ |
| 7357 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7358 | if (attr) |
| 7359 | { |
| 7360 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) |
| 7361 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 7362 | else |
| 7363 | complaint (&symfile_complaints, |
| 7364 | _("DW_AT_byte_size for array type smaller " |
| 7365 | "than the total size of elements")); |
| 7366 | } |
| 7367 | |
| 7368 | name = dwarf2_name (die, cu); |
| 7369 | if (name) |
| 7370 | TYPE_NAME (type) = name; |
| 7371 | |
| 7372 | /* Install the type in the die. */ |
| 7373 | set_die_type (die, type, cu); |
| 7374 | |
| 7375 | /* set_die_type should be already done. */ |
| 7376 | set_descriptive_type (type, die, cu); |
| 7377 | |
| 7378 | do_cleanups (back_to); |
| 7379 | |
| 7380 | return type; |
| 7381 | } |
| 7382 | |
| 7383 | static enum dwarf_array_dim_ordering |
| 7384 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
| 7385 | { |
| 7386 | struct attribute *attr; |
| 7387 | |
| 7388 | attr = dwarf2_attr (die, DW_AT_ordering, cu); |
| 7389 | |
| 7390 | if (attr) return DW_SND (attr); |
| 7391 | |
| 7392 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
| 7393 | opposite order to the dwarf2 specification, but data is still |
| 7394 | laid out as per normal fortran. |
| 7395 | |
| 7396 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
| 7397 | version checking. */ |
| 7398 | |
| 7399 | if (cu->language == language_fortran |
| 7400 | && cu->producer && strstr (cu->producer, "GNU F77")) |
| 7401 | { |
| 7402 | return DW_ORD_row_major; |
| 7403 | } |
| 7404 | |
| 7405 | switch (cu->language_defn->la_array_ordering) |
| 7406 | { |
| 7407 | case array_column_major: |
| 7408 | return DW_ORD_col_major; |
| 7409 | case array_row_major: |
| 7410 | default: |
| 7411 | return DW_ORD_row_major; |
| 7412 | }; |
| 7413 | } |
| 7414 | |
| 7415 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
| 7416 | the DIE's type field. */ |
| 7417 | |
| 7418 | static struct type * |
| 7419 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7420 | { |
| 7421 | struct type *domain_type, *set_type; |
| 7422 | struct attribute *attr; |
| 7423 | |
| 7424 | domain_type = die_type (die, cu); |
| 7425 | |
| 7426 | /* The die_type call above may have already set the type for this DIE. */ |
| 7427 | set_type = get_die_type (die, cu); |
| 7428 | if (set_type) |
| 7429 | return set_type; |
| 7430 | |
| 7431 | set_type = create_set_type (NULL, domain_type); |
| 7432 | |
| 7433 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7434 | if (attr) |
| 7435 | TYPE_LENGTH (set_type) = DW_UNSND (attr); |
| 7436 | |
| 7437 | return set_die_type (die, set_type, cu); |
| 7438 | } |
| 7439 | |
| 7440 | /* First cut: install each common block member as a global variable. */ |
| 7441 | |
| 7442 | static void |
| 7443 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
| 7444 | { |
| 7445 | struct die_info *child_die; |
| 7446 | struct attribute *attr; |
| 7447 | struct symbol *sym; |
| 7448 | CORE_ADDR base = (CORE_ADDR) 0; |
| 7449 | |
| 7450 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 7451 | if (attr) |
| 7452 | { |
| 7453 | /* Support the .debug_loc offsets. */ |
| 7454 | if (attr_form_is_block (attr)) |
| 7455 | { |
| 7456 | base = decode_locdesc (DW_BLOCK (attr), cu); |
| 7457 | } |
| 7458 | else if (attr_form_is_section_offset (attr)) |
| 7459 | { |
| 7460 | dwarf2_complex_location_expr_complaint (); |
| 7461 | } |
| 7462 | else |
| 7463 | { |
| 7464 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 7465 | "common block member"); |
| 7466 | } |
| 7467 | } |
| 7468 | if (die->child != NULL) |
| 7469 | { |
| 7470 | child_die = die->child; |
| 7471 | while (child_die && child_die->tag) |
| 7472 | { |
| 7473 | sym = new_symbol (child_die, NULL, cu); |
| 7474 | attr = dwarf2_attr (child_die, DW_AT_data_member_location, cu); |
| 7475 | if (sym != NULL && attr != NULL) |
| 7476 | { |
| 7477 | CORE_ADDR byte_offset = 0; |
| 7478 | |
| 7479 | if (attr_form_is_section_offset (attr)) |
| 7480 | dwarf2_complex_location_expr_complaint (); |
| 7481 | else if (attr_form_is_constant (attr)) |
| 7482 | byte_offset = dwarf2_get_attr_constant_value (attr, 0); |
| 7483 | else if (attr_form_is_block (attr)) |
| 7484 | byte_offset = decode_locdesc (DW_BLOCK (attr), cu); |
| 7485 | else |
| 7486 | dwarf2_complex_location_expr_complaint (); |
| 7487 | |
| 7488 | SYMBOL_VALUE_ADDRESS (sym) = base + byte_offset; |
| 7489 | add_symbol_to_list (sym, &global_symbols); |
| 7490 | } |
| 7491 | child_die = sibling_die (child_die); |
| 7492 | } |
| 7493 | } |
| 7494 | } |
| 7495 | |
| 7496 | /* Create a type for a C++ namespace. */ |
| 7497 | |
| 7498 | static struct type * |
| 7499 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7500 | { |
| 7501 | struct objfile *objfile = cu->objfile; |
| 7502 | const char *previous_prefix, *name; |
| 7503 | int is_anonymous; |
| 7504 | struct type *type; |
| 7505 | |
| 7506 | /* For extensions, reuse the type of the original namespace. */ |
| 7507 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) |
| 7508 | { |
| 7509 | struct die_info *ext_die; |
| 7510 | struct dwarf2_cu *ext_cu = cu; |
| 7511 | |
| 7512 | ext_die = dwarf2_extension (die, &ext_cu); |
| 7513 | type = read_type_die (ext_die, ext_cu); |
| 7514 | |
| 7515 | /* EXT_CU may not be the same as CU. |
| 7516 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 7517 | return set_die_type (die, type, cu); |
| 7518 | } |
| 7519 | |
| 7520 | name = namespace_name (die, &is_anonymous, cu); |
| 7521 | |
| 7522 | /* Now build the name of the current namespace. */ |
| 7523 | |
| 7524 | previous_prefix = determine_prefix (die, cu); |
| 7525 | if (previous_prefix[0] != '\0') |
| 7526 | name = typename_concat (&objfile->objfile_obstack, |
| 7527 | previous_prefix, name, 0, cu); |
| 7528 | |
| 7529 | /* Create the type. */ |
| 7530 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, |
| 7531 | objfile); |
| 7532 | TYPE_NAME (type) = (char *) name; |
| 7533 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 7534 | |
| 7535 | return set_die_type (die, type, cu); |
| 7536 | } |
| 7537 | |
| 7538 | /* Read a C++ namespace. */ |
| 7539 | |
| 7540 | static void |
| 7541 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
| 7542 | { |
| 7543 | struct objfile *objfile = cu->objfile; |
| 7544 | const char *name; |
| 7545 | int is_anonymous; |
| 7546 | |
| 7547 | /* Add a symbol associated to this if we haven't seen the namespace |
| 7548 | before. Also, add a using directive if it's an anonymous |
| 7549 | namespace. */ |
| 7550 | |
| 7551 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
| 7552 | { |
| 7553 | struct type *type; |
| 7554 | |
| 7555 | type = read_type_die (die, cu); |
| 7556 | new_symbol (die, type, cu); |
| 7557 | |
| 7558 | name = namespace_name (die, &is_anonymous, cu); |
| 7559 | if (is_anonymous) |
| 7560 | { |
| 7561 | const char *previous_prefix = determine_prefix (die, cu); |
| 7562 | |
| 7563 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
| 7564 | NULL, &objfile->objfile_obstack); |
| 7565 | } |
| 7566 | } |
| 7567 | |
| 7568 | if (die->child != NULL) |
| 7569 | { |
| 7570 | struct die_info *child_die = die->child; |
| 7571 | |
| 7572 | while (child_die && child_die->tag) |
| 7573 | { |
| 7574 | process_die (child_die, cu); |
| 7575 | child_die = sibling_die (child_die); |
| 7576 | } |
| 7577 | } |
| 7578 | } |
| 7579 | |
| 7580 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
| 7581 | imported module. Still we need that type as local Fortran "use ... only" |
| 7582 | declaration imports depend on the created type in determine_prefix. */ |
| 7583 | |
| 7584 | static struct type * |
| 7585 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7586 | { |
| 7587 | struct objfile *objfile = cu->objfile; |
| 7588 | char *module_name; |
| 7589 | struct type *type; |
| 7590 | |
| 7591 | module_name = dwarf2_name (die, cu); |
| 7592 | if (!module_name) |
| 7593 | complaint (&symfile_complaints, |
| 7594 | _("DW_TAG_module has no name, offset 0x%x"), |
| 7595 | die->offset); |
| 7596 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
| 7597 | |
| 7598 | /* determine_prefix uses TYPE_TAG_NAME. */ |
| 7599 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 7600 | |
| 7601 | return set_die_type (die, type, cu); |
| 7602 | } |
| 7603 | |
| 7604 | /* Read a Fortran module. */ |
| 7605 | |
| 7606 | static void |
| 7607 | read_module (struct die_info *die, struct dwarf2_cu *cu) |
| 7608 | { |
| 7609 | struct die_info *child_die = die->child; |
| 7610 | |
| 7611 | while (child_die && child_die->tag) |
| 7612 | { |
| 7613 | process_die (child_die, cu); |
| 7614 | child_die = sibling_die (child_die); |
| 7615 | } |
| 7616 | } |
| 7617 | |
| 7618 | /* Return the name of the namespace represented by DIE. Set |
| 7619 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous |
| 7620 | namespace. */ |
| 7621 | |
| 7622 | static const char * |
| 7623 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
| 7624 | { |
| 7625 | struct die_info *current_die; |
| 7626 | const char *name = NULL; |
| 7627 | |
| 7628 | /* Loop through the extensions until we find a name. */ |
| 7629 | |
| 7630 | for (current_die = die; |
| 7631 | current_die != NULL; |
| 7632 | current_die = dwarf2_extension (die, &cu)) |
| 7633 | { |
| 7634 | name = dwarf2_name (current_die, cu); |
| 7635 | if (name != NULL) |
| 7636 | break; |
| 7637 | } |
| 7638 | |
| 7639 | /* Is it an anonymous namespace? */ |
| 7640 | |
| 7641 | *is_anonymous = (name == NULL); |
| 7642 | if (*is_anonymous) |
| 7643 | name = "(anonymous namespace)"; |
| 7644 | |
| 7645 | return name; |
| 7646 | } |
| 7647 | |
| 7648 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
| 7649 | the user defined type vector. */ |
| 7650 | |
| 7651 | static struct type * |
| 7652 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7653 | { |
| 7654 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
| 7655 | struct comp_unit_head *cu_header = &cu->header; |
| 7656 | struct type *type; |
| 7657 | struct attribute *attr_byte_size; |
| 7658 | struct attribute *attr_address_class; |
| 7659 | int byte_size, addr_class; |
| 7660 | struct type *target_type; |
| 7661 | |
| 7662 | target_type = die_type (die, cu); |
| 7663 | |
| 7664 | /* The die_type call above may have already set the type for this DIE. */ |
| 7665 | type = get_die_type (die, cu); |
| 7666 | if (type) |
| 7667 | return type; |
| 7668 | |
| 7669 | type = lookup_pointer_type (target_type); |
| 7670 | |
| 7671 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7672 | if (attr_byte_size) |
| 7673 | byte_size = DW_UNSND (attr_byte_size); |
| 7674 | else |
| 7675 | byte_size = cu_header->addr_size; |
| 7676 | |
| 7677 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
| 7678 | if (attr_address_class) |
| 7679 | addr_class = DW_UNSND (attr_address_class); |
| 7680 | else |
| 7681 | addr_class = DW_ADDR_none; |
| 7682 | |
| 7683 | /* If the pointer size or address class is different than the |
| 7684 | default, create a type variant marked as such and set the |
| 7685 | length accordingly. */ |
| 7686 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) |
| 7687 | { |
| 7688 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
| 7689 | { |
| 7690 | int type_flags; |
| 7691 | |
| 7692 | type_flags = gdbarch_address_class_type_flags |
| 7693 | (gdbarch, byte_size, addr_class); |
| 7694 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
| 7695 | == 0); |
| 7696 | type = make_type_with_address_space (type, type_flags); |
| 7697 | } |
| 7698 | else if (TYPE_LENGTH (type) != byte_size) |
| 7699 | { |
| 7700 | complaint (&symfile_complaints, |
| 7701 | _("invalid pointer size %d"), byte_size); |
| 7702 | } |
| 7703 | else |
| 7704 | { |
| 7705 | /* Should we also complain about unhandled address classes? */ |
| 7706 | } |
| 7707 | } |
| 7708 | |
| 7709 | TYPE_LENGTH (type) = byte_size; |
| 7710 | return set_die_type (die, type, cu); |
| 7711 | } |
| 7712 | |
| 7713 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to |
| 7714 | the user defined type vector. */ |
| 7715 | |
| 7716 | static struct type * |
| 7717 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7718 | { |
| 7719 | struct type *type; |
| 7720 | struct type *to_type; |
| 7721 | struct type *domain; |
| 7722 | |
| 7723 | to_type = die_type (die, cu); |
| 7724 | domain = die_containing_type (die, cu); |
| 7725 | |
| 7726 | /* The calls above may have already set the type for this DIE. */ |
| 7727 | type = get_die_type (die, cu); |
| 7728 | if (type) |
| 7729 | return type; |
| 7730 | |
| 7731 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
| 7732 | type = lookup_methodptr_type (to_type); |
| 7733 | else |
| 7734 | type = lookup_memberptr_type (to_type, domain); |
| 7735 | |
| 7736 | return set_die_type (die, type, cu); |
| 7737 | } |
| 7738 | |
| 7739 | /* Extract all information from a DW_TAG_reference_type DIE and add to |
| 7740 | the user defined type vector. */ |
| 7741 | |
| 7742 | static struct type * |
| 7743 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7744 | { |
| 7745 | struct comp_unit_head *cu_header = &cu->header; |
| 7746 | struct type *type, *target_type; |
| 7747 | struct attribute *attr; |
| 7748 | |
| 7749 | target_type = die_type (die, cu); |
| 7750 | |
| 7751 | /* The die_type call above may have already set the type for this DIE. */ |
| 7752 | type = get_die_type (die, cu); |
| 7753 | if (type) |
| 7754 | return type; |
| 7755 | |
| 7756 | type = lookup_reference_type (target_type); |
| 7757 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7758 | if (attr) |
| 7759 | { |
| 7760 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 7761 | } |
| 7762 | else |
| 7763 | { |
| 7764 | TYPE_LENGTH (type) = cu_header->addr_size; |
| 7765 | } |
| 7766 | return set_die_type (die, type, cu); |
| 7767 | } |
| 7768 | |
| 7769 | static struct type * |
| 7770 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7771 | { |
| 7772 | struct type *base_type, *cv_type; |
| 7773 | |
| 7774 | base_type = die_type (die, cu); |
| 7775 | |
| 7776 | /* The die_type call above may have already set the type for this DIE. */ |
| 7777 | cv_type = get_die_type (die, cu); |
| 7778 | if (cv_type) |
| 7779 | return cv_type; |
| 7780 | |
| 7781 | /* In case the const qualifier is applied to an array type, the element type |
| 7782 | is so qualified, not the array type (section 6.7.3 of C99). */ |
| 7783 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) |
| 7784 | { |
| 7785 | struct type *el_type, *inner_array; |
| 7786 | |
| 7787 | base_type = copy_type (base_type); |
| 7788 | inner_array = base_type; |
| 7789 | |
| 7790 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) |
| 7791 | { |
| 7792 | TYPE_TARGET_TYPE (inner_array) = |
| 7793 | copy_type (TYPE_TARGET_TYPE (inner_array)); |
| 7794 | inner_array = TYPE_TARGET_TYPE (inner_array); |
| 7795 | } |
| 7796 | |
| 7797 | el_type = TYPE_TARGET_TYPE (inner_array); |
| 7798 | TYPE_TARGET_TYPE (inner_array) = |
| 7799 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); |
| 7800 | |
| 7801 | return set_die_type (die, base_type, cu); |
| 7802 | } |
| 7803 | |
| 7804 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
| 7805 | return set_die_type (die, cv_type, cu); |
| 7806 | } |
| 7807 | |
| 7808 | static struct type * |
| 7809 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7810 | { |
| 7811 | struct type *base_type, *cv_type; |
| 7812 | |
| 7813 | base_type = die_type (die, cu); |
| 7814 | |
| 7815 | /* The die_type call above may have already set the type for this DIE. */ |
| 7816 | cv_type = get_die_type (die, cu); |
| 7817 | if (cv_type) |
| 7818 | return cv_type; |
| 7819 | |
| 7820 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
| 7821 | return set_die_type (die, cv_type, cu); |
| 7822 | } |
| 7823 | |
| 7824 | /* Extract all information from a DW_TAG_string_type DIE and add to |
| 7825 | the user defined type vector. It isn't really a user defined type, |
| 7826 | but it behaves like one, with other DIE's using an AT_user_def_type |
| 7827 | attribute to reference it. */ |
| 7828 | |
| 7829 | static struct type * |
| 7830 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7831 | { |
| 7832 | struct objfile *objfile = cu->objfile; |
| 7833 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 7834 | struct type *type, *range_type, *index_type, *char_type; |
| 7835 | struct attribute *attr; |
| 7836 | unsigned int length; |
| 7837 | |
| 7838 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
| 7839 | if (attr) |
| 7840 | { |
| 7841 | length = DW_UNSND (attr); |
| 7842 | } |
| 7843 | else |
| 7844 | { |
| 7845 | /* Check for the DW_AT_byte_size attribute. */ |
| 7846 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7847 | if (attr) |
| 7848 | { |
| 7849 | length = DW_UNSND (attr); |
| 7850 | } |
| 7851 | else |
| 7852 | { |
| 7853 | length = 1; |
| 7854 | } |
| 7855 | } |
| 7856 | |
| 7857 | index_type = objfile_type (objfile)->builtin_int; |
| 7858 | range_type = create_range_type (NULL, index_type, 1, length); |
| 7859 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
| 7860 | type = create_string_type (NULL, char_type, range_type); |
| 7861 | |
| 7862 | return set_die_type (die, type, cu); |
| 7863 | } |
| 7864 | |
| 7865 | /* Handle DIES due to C code like: |
| 7866 | |
| 7867 | struct foo |
| 7868 | { |
| 7869 | int (*funcp)(int a, long l); |
| 7870 | int b; |
| 7871 | }; |
| 7872 | |
| 7873 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
| 7874 | |
| 7875 | static struct type * |
| 7876 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7877 | { |
| 7878 | struct type *type; /* Type that this function returns. */ |
| 7879 | struct type *ftype; /* Function that returns above type. */ |
| 7880 | struct attribute *attr; |
| 7881 | |
| 7882 | type = die_type (die, cu); |
| 7883 | |
| 7884 | /* The die_type call above may have already set the type for this DIE. */ |
| 7885 | ftype = get_die_type (die, cu); |
| 7886 | if (ftype) |
| 7887 | return ftype; |
| 7888 | |
| 7889 | ftype = lookup_function_type (type); |
| 7890 | |
| 7891 | /* All functions in C++, Pascal and Java have prototypes. */ |
| 7892 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
| 7893 | if ((attr && (DW_UNSND (attr) != 0)) |
| 7894 | || cu->language == language_cplus |
| 7895 | || cu->language == language_java |
| 7896 | || cu->language == language_pascal) |
| 7897 | TYPE_PROTOTYPED (ftype) = 1; |
| 7898 | else if (producer_is_realview (cu->producer)) |
| 7899 | /* RealView does not emit DW_AT_prototyped. We can not |
| 7900 | distinguish prototyped and unprototyped functions; default to |
| 7901 | prototyped, since that is more common in modern code (and |
| 7902 | RealView warns about unprototyped functions). */ |
| 7903 | TYPE_PROTOTYPED (ftype) = 1; |
| 7904 | |
| 7905 | /* Store the calling convention in the type if it's available in |
| 7906 | the subroutine die. Otherwise set the calling convention to |
| 7907 | the default value DW_CC_normal. */ |
| 7908 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); |
| 7909 | TYPE_CALLING_CONVENTION (ftype) = attr ? DW_UNSND (attr) : DW_CC_normal; |
| 7910 | |
| 7911 | /* We need to add the subroutine type to the die immediately so |
| 7912 | we don't infinitely recurse when dealing with parameters |
| 7913 | declared as the same subroutine type. */ |
| 7914 | set_die_type (die, ftype, cu); |
| 7915 | |
| 7916 | if (die->child != NULL) |
| 7917 | { |
| 7918 | struct type *void_type = objfile_type (cu->objfile)->builtin_void; |
| 7919 | struct die_info *child_die; |
| 7920 | int nparams, iparams; |
| 7921 | |
| 7922 | /* Count the number of parameters. |
| 7923 | FIXME: GDB currently ignores vararg functions, but knows about |
| 7924 | vararg member functions. */ |
| 7925 | nparams = 0; |
| 7926 | child_die = die->child; |
| 7927 | while (child_die && child_die->tag) |
| 7928 | { |
| 7929 | if (child_die->tag == DW_TAG_formal_parameter) |
| 7930 | nparams++; |
| 7931 | else if (child_die->tag == DW_TAG_unspecified_parameters) |
| 7932 | TYPE_VARARGS (ftype) = 1; |
| 7933 | child_die = sibling_die (child_die); |
| 7934 | } |
| 7935 | |
| 7936 | /* Allocate storage for parameters and fill them in. */ |
| 7937 | TYPE_NFIELDS (ftype) = nparams; |
| 7938 | TYPE_FIELDS (ftype) = (struct field *) |
| 7939 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
| 7940 | |
| 7941 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
| 7942 | even if we error out during the parameters reading below. */ |
| 7943 | for (iparams = 0; iparams < nparams; iparams++) |
| 7944 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; |
| 7945 | |
| 7946 | iparams = 0; |
| 7947 | child_die = die->child; |
| 7948 | while (child_die && child_die->tag) |
| 7949 | { |
| 7950 | if (child_die->tag == DW_TAG_formal_parameter) |
| 7951 | { |
| 7952 | struct type *arg_type; |
| 7953 | |
| 7954 | /* DWARF version 2 has no clean way to discern C++ |
| 7955 | static and non-static member functions. G++ helps |
| 7956 | GDB by marking the first parameter for non-static |
| 7957 | member functions (which is the this pointer) as |
| 7958 | artificial. We pass this information to |
| 7959 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. |
| 7960 | |
| 7961 | DWARF version 3 added DW_AT_object_pointer, which GCC |
| 7962 | 4.5 does not yet generate. */ |
| 7963 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
| 7964 | if (attr) |
| 7965 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); |
| 7966 | else |
| 7967 | { |
| 7968 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
| 7969 | |
| 7970 | /* GCC/43521: In java, the formal parameter |
| 7971 | "this" is sometimes not marked with DW_AT_artificial. */ |
| 7972 | if (cu->language == language_java) |
| 7973 | { |
| 7974 | const char *name = dwarf2_name (child_die, cu); |
| 7975 | |
| 7976 | if (name && !strcmp (name, "this")) |
| 7977 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; |
| 7978 | } |
| 7979 | } |
| 7980 | arg_type = die_type (child_die, cu); |
| 7981 | |
| 7982 | /* RealView does not mark THIS as const, which the testsuite |
| 7983 | expects. GCC marks THIS as const in method definitions, |
| 7984 | but not in the class specifications (GCC PR 43053). */ |
| 7985 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) |
| 7986 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) |
| 7987 | { |
| 7988 | int is_this = 0; |
| 7989 | struct dwarf2_cu *arg_cu = cu; |
| 7990 | const char *name = dwarf2_name (child_die, cu); |
| 7991 | |
| 7992 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); |
| 7993 | if (attr) |
| 7994 | { |
| 7995 | /* If the compiler emits this, use it. */ |
| 7996 | if (follow_die_ref (die, attr, &arg_cu) == child_die) |
| 7997 | is_this = 1; |
| 7998 | } |
| 7999 | else if (name && strcmp (name, "this") == 0) |
| 8000 | /* Function definitions will have the argument names. */ |
| 8001 | is_this = 1; |
| 8002 | else if (name == NULL && iparams == 0) |
| 8003 | /* Declarations may not have the names, so like |
| 8004 | elsewhere in GDB, assume an artificial first |
| 8005 | argument is "this". */ |
| 8006 | is_this = 1; |
| 8007 | |
| 8008 | if (is_this) |
| 8009 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), |
| 8010 | arg_type, 0); |
| 8011 | } |
| 8012 | |
| 8013 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; |
| 8014 | iparams++; |
| 8015 | } |
| 8016 | child_die = sibling_die (child_die); |
| 8017 | } |
| 8018 | } |
| 8019 | |
| 8020 | return ftype; |
| 8021 | } |
| 8022 | |
| 8023 | static struct type * |
| 8024 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
| 8025 | { |
| 8026 | struct objfile *objfile = cu->objfile; |
| 8027 | const char *name = NULL; |
| 8028 | struct type *this_type; |
| 8029 | |
| 8030 | name = dwarf2_full_name (NULL, die, cu); |
| 8031 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
| 8032 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
| 8033 | TYPE_NAME (this_type) = (char *) name; |
| 8034 | set_die_type (die, this_type, cu); |
| 8035 | TYPE_TARGET_TYPE (this_type) = die_type (die, cu); |
| 8036 | return this_type; |
| 8037 | } |
| 8038 | |
| 8039 | /* Find a representation of a given base type and install |
| 8040 | it in the TYPE field of the die. */ |
| 8041 | |
| 8042 | static struct type * |
| 8043 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8044 | { |
| 8045 | struct objfile *objfile = cu->objfile; |
| 8046 | struct type *type; |
| 8047 | struct attribute *attr; |
| 8048 | int encoding = 0, size = 0; |
| 8049 | char *name; |
| 8050 | enum type_code code = TYPE_CODE_INT; |
| 8051 | int type_flags = 0; |
| 8052 | struct type *target_type = NULL; |
| 8053 | |
| 8054 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
| 8055 | if (attr) |
| 8056 | { |
| 8057 | encoding = DW_UNSND (attr); |
| 8058 | } |
| 8059 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8060 | if (attr) |
| 8061 | { |
| 8062 | size = DW_UNSND (attr); |
| 8063 | } |
| 8064 | name = dwarf2_name (die, cu); |
| 8065 | if (!name) |
| 8066 | { |
| 8067 | complaint (&symfile_complaints, |
| 8068 | _("DW_AT_name missing from DW_TAG_base_type")); |
| 8069 | } |
| 8070 | |
| 8071 | switch (encoding) |
| 8072 | { |
| 8073 | case DW_ATE_address: |
| 8074 | /* Turn DW_ATE_address into a void * pointer. */ |
| 8075 | code = TYPE_CODE_PTR; |
| 8076 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8077 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
| 8078 | break; |
| 8079 | case DW_ATE_boolean: |
| 8080 | code = TYPE_CODE_BOOL; |
| 8081 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8082 | break; |
| 8083 | case DW_ATE_complex_float: |
| 8084 | code = TYPE_CODE_COMPLEX; |
| 8085 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); |
| 8086 | break; |
| 8087 | case DW_ATE_decimal_float: |
| 8088 | code = TYPE_CODE_DECFLOAT; |
| 8089 | break; |
| 8090 | case DW_ATE_float: |
| 8091 | code = TYPE_CODE_FLT; |
| 8092 | break; |
| 8093 | case DW_ATE_signed: |
| 8094 | break; |
| 8095 | case DW_ATE_unsigned: |
| 8096 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8097 | break; |
| 8098 | case DW_ATE_signed_char: |
| 8099 | if (cu->language == language_ada || cu->language == language_m2 |
| 8100 | || cu->language == language_pascal) |
| 8101 | code = TYPE_CODE_CHAR; |
| 8102 | break; |
| 8103 | case DW_ATE_unsigned_char: |
| 8104 | if (cu->language == language_ada || cu->language == language_m2 |
| 8105 | || cu->language == language_pascal) |
| 8106 | code = TYPE_CODE_CHAR; |
| 8107 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8108 | break; |
| 8109 | case DW_ATE_UTF: |
| 8110 | /* We just treat this as an integer and then recognize the |
| 8111 | type by name elsewhere. */ |
| 8112 | break; |
| 8113 | |
| 8114 | default: |
| 8115 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), |
| 8116 | dwarf_type_encoding_name (encoding)); |
| 8117 | break; |
| 8118 | } |
| 8119 | |
| 8120 | type = init_type (code, size, type_flags, NULL, objfile); |
| 8121 | TYPE_NAME (type) = name; |
| 8122 | TYPE_TARGET_TYPE (type) = target_type; |
| 8123 | |
| 8124 | if (name && strcmp (name, "char") == 0) |
| 8125 | TYPE_NOSIGN (type) = 1; |
| 8126 | |
| 8127 | return set_die_type (die, type, cu); |
| 8128 | } |
| 8129 | |
| 8130 | /* Read the given DW_AT_subrange DIE. */ |
| 8131 | |
| 8132 | static struct type * |
| 8133 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8134 | { |
| 8135 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
| 8136 | struct type *base_type; |
| 8137 | struct type *range_type; |
| 8138 | struct attribute *attr; |
| 8139 | LONGEST low = 0; |
| 8140 | LONGEST high = -1; |
| 8141 | char *name; |
| 8142 | LONGEST negative_mask; |
| 8143 | |
| 8144 | base_type = die_type (die, cu); |
| 8145 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
| 8146 | check_typedef (base_type); |
| 8147 | |
| 8148 | /* The die_type call above may have already set the type for this DIE. */ |
| 8149 | range_type = get_die_type (die, cu); |
| 8150 | if (range_type) |
| 8151 | return range_type; |
| 8152 | |
| 8153 | if (cu->language == language_fortran) |
| 8154 | { |
| 8155 | /* FORTRAN implies a lower bound of 1, if not given. */ |
| 8156 | low = 1; |
| 8157 | } |
| 8158 | |
| 8159 | /* FIXME: For variable sized arrays either of these could be |
| 8160 | a variable rather than a constant value. We'll allow it, |
| 8161 | but we don't know how to handle it. */ |
| 8162 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
| 8163 | if (attr) |
| 8164 | low = dwarf2_get_attr_constant_value (attr, 0); |
| 8165 | |
| 8166 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
| 8167 | if (attr) |
| 8168 | { |
| 8169 | if (attr->form == DW_FORM_block1 || is_ref_attr (attr)) |
| 8170 | { |
| 8171 | /* GCC encodes arrays with unspecified or dynamic length |
| 8172 | with a DW_FORM_block1 attribute or a reference attribute. |
| 8173 | FIXME: GDB does not yet know how to handle dynamic |
| 8174 | arrays properly, treat them as arrays with unspecified |
| 8175 | length for now. |
| 8176 | |
| 8177 | FIXME: jimb/2003-09-22: GDB does not really know |
| 8178 | how to handle arrays of unspecified length |
| 8179 | either; we just represent them as zero-length |
| 8180 | arrays. Choose an appropriate upper bound given |
| 8181 | the lower bound we've computed above. */ |
| 8182 | high = low - 1; |
| 8183 | } |
| 8184 | else |
| 8185 | high = dwarf2_get_attr_constant_value (attr, 1); |
| 8186 | } |
| 8187 | else |
| 8188 | { |
| 8189 | attr = dwarf2_attr (die, DW_AT_count, cu); |
| 8190 | if (attr) |
| 8191 | { |
| 8192 | int count = dwarf2_get_attr_constant_value (attr, 1); |
| 8193 | high = low + count - 1; |
| 8194 | } |
| 8195 | } |
| 8196 | |
| 8197 | /* Dwarf-2 specifications explicitly allows to create subrange types |
| 8198 | without specifying a base type. |
| 8199 | In that case, the base type must be set to the type of |
| 8200 | the lower bound, upper bound or count, in that order, if any of these |
| 8201 | three attributes references an object that has a type. |
| 8202 | If no base type is found, the Dwarf-2 specifications say that |
| 8203 | a signed integer type of size equal to the size of an address should |
| 8204 | be used. |
| 8205 | For the following C code: `extern char gdb_int [];' |
| 8206 | GCC produces an empty range DIE. |
| 8207 | FIXME: muller/2010-05-28: Possible references to object for low bound, |
| 8208 | high bound or count are not yet handled by this code. */ |
| 8209 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
| 8210 | { |
| 8211 | struct objfile *objfile = cu->objfile; |
| 8212 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 8213 | int addr_size = gdbarch_addr_bit (gdbarch) /8; |
| 8214 | struct type *int_type = objfile_type (objfile)->builtin_int; |
| 8215 | |
| 8216 | /* Test "int", "long int", and "long long int" objfile types, |
| 8217 | and select the first one having a size above or equal to the |
| 8218 | architecture address size. */ |
| 8219 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 8220 | base_type = int_type; |
| 8221 | else |
| 8222 | { |
| 8223 | int_type = objfile_type (objfile)->builtin_long; |
| 8224 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 8225 | base_type = int_type; |
| 8226 | else |
| 8227 | { |
| 8228 | int_type = objfile_type (objfile)->builtin_long_long; |
| 8229 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 8230 | base_type = int_type; |
| 8231 | } |
| 8232 | } |
| 8233 | } |
| 8234 | |
| 8235 | negative_mask = |
| 8236 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
| 8237 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) |
| 8238 | low |= negative_mask; |
| 8239 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) |
| 8240 | high |= negative_mask; |
| 8241 | |
| 8242 | range_type = create_range_type (NULL, base_type, low, high); |
| 8243 | |
| 8244 | /* Mark arrays with dynamic length at least as an array of unspecified |
| 8245 | length. GDB could check the boundary but before it gets implemented at |
| 8246 | least allow accessing the array elements. */ |
| 8247 | if (attr && attr->form == DW_FORM_block1) |
| 8248 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
| 8249 | |
| 8250 | name = dwarf2_name (die, cu); |
| 8251 | if (name) |
| 8252 | TYPE_NAME (range_type) = name; |
| 8253 | |
| 8254 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8255 | if (attr) |
| 8256 | TYPE_LENGTH (range_type) = DW_UNSND (attr); |
| 8257 | |
| 8258 | set_die_type (die, range_type, cu); |
| 8259 | |
| 8260 | /* set_die_type should be already done. */ |
| 8261 | set_descriptive_type (range_type, die, cu); |
| 8262 | |
| 8263 | return range_type; |
| 8264 | } |
| 8265 | |
| 8266 | static struct type * |
| 8267 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8268 | { |
| 8269 | struct type *type; |
| 8270 | |
| 8271 | /* For now, we only support the C meaning of an unspecified type: void. */ |
| 8272 | |
| 8273 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
| 8274 | TYPE_NAME (type) = dwarf2_name (die, cu); |
| 8275 | |
| 8276 | return set_die_type (die, type, cu); |
| 8277 | } |
| 8278 | |
| 8279 | /* Trivial hash function for die_info: the hash value of a DIE |
| 8280 | is its offset in .debug_info for this objfile. */ |
| 8281 | |
| 8282 | static hashval_t |
| 8283 | die_hash (const void *item) |
| 8284 | { |
| 8285 | const struct die_info *die = item; |
| 8286 | |
| 8287 | return die->offset; |
| 8288 | } |
| 8289 | |
| 8290 | /* Trivial comparison function for die_info structures: two DIEs |
| 8291 | are equal if they have the same offset. */ |
| 8292 | |
| 8293 | static int |
| 8294 | die_eq (const void *item_lhs, const void *item_rhs) |
| 8295 | { |
| 8296 | const struct die_info *die_lhs = item_lhs; |
| 8297 | const struct die_info *die_rhs = item_rhs; |
| 8298 | |
| 8299 | return die_lhs->offset == die_rhs->offset; |
| 8300 | } |
| 8301 | |
| 8302 | /* Read a whole compilation unit into a linked list of dies. */ |
| 8303 | |
| 8304 | static struct die_info * |
| 8305 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
| 8306 | { |
| 8307 | struct die_reader_specs reader_specs; |
| 8308 | int read_abbrevs = 0; |
| 8309 | struct cleanup *back_to = NULL; |
| 8310 | struct die_info *die; |
| 8311 | |
| 8312 | if (cu->dwarf2_abbrevs == NULL) |
| 8313 | { |
| 8314 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); |
| 8315 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 8316 | read_abbrevs = 1; |
| 8317 | } |
| 8318 | |
| 8319 | gdb_assert (cu->die_hash == NULL); |
| 8320 | cu->die_hash |
| 8321 | = htab_create_alloc_ex (cu->header.length / 12, |
| 8322 | die_hash, |
| 8323 | die_eq, |
| 8324 | NULL, |
| 8325 | &cu->comp_unit_obstack, |
| 8326 | hashtab_obstack_allocate, |
| 8327 | dummy_obstack_deallocate); |
| 8328 | |
| 8329 | init_cu_die_reader (&reader_specs, cu); |
| 8330 | |
| 8331 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
| 8332 | |
| 8333 | if (read_abbrevs) |
| 8334 | do_cleanups (back_to); |
| 8335 | |
| 8336 | return die; |
| 8337 | } |
| 8338 | |
| 8339 | /* Main entry point for reading a DIE and all children. |
| 8340 | Read the DIE and dump it if requested. */ |
| 8341 | |
| 8342 | static struct die_info * |
| 8343 | read_die_and_children (const struct die_reader_specs *reader, |
| 8344 | gdb_byte *info_ptr, |
| 8345 | gdb_byte **new_info_ptr, |
| 8346 | struct die_info *parent) |
| 8347 | { |
| 8348 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
| 8349 | new_info_ptr, parent); |
| 8350 | |
| 8351 | if (dwarf2_die_debug) |
| 8352 | { |
| 8353 | fprintf_unfiltered (gdb_stdlog, |
| 8354 | "\nRead die from %s of %s:\n", |
| 8355 | reader->buffer == dwarf2_per_objfile->info.buffer |
| 8356 | ? ".debug_info" |
| 8357 | : reader->buffer == dwarf2_per_objfile->types.buffer |
| 8358 | ? ".debug_types" |
| 8359 | : "unknown section", |
| 8360 | reader->abfd->filename); |
| 8361 | dump_die (result, dwarf2_die_debug); |
| 8362 | } |
| 8363 | |
| 8364 | return result; |
| 8365 | } |
| 8366 | |
| 8367 | /* Read a single die and all its descendents. Set the die's sibling |
| 8368 | field to NULL; set other fields in the die correctly, and set all |
| 8369 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the |
| 8370 | location of the info_ptr after reading all of those dies. PARENT |
| 8371 | is the parent of the die in question. */ |
| 8372 | |
| 8373 | static struct die_info * |
| 8374 | read_die_and_children_1 (const struct die_reader_specs *reader, |
| 8375 | gdb_byte *info_ptr, |
| 8376 | gdb_byte **new_info_ptr, |
| 8377 | struct die_info *parent) |
| 8378 | { |
| 8379 | struct die_info *die; |
| 8380 | gdb_byte *cur_ptr; |
| 8381 | int has_children; |
| 8382 | |
| 8383 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
| 8384 | if (die == NULL) |
| 8385 | { |
| 8386 | *new_info_ptr = cur_ptr; |
| 8387 | return NULL; |
| 8388 | } |
| 8389 | store_in_ref_table (die, reader->cu); |
| 8390 | |
| 8391 | if (has_children) |
| 8392 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
| 8393 | else |
| 8394 | { |
| 8395 | die->child = NULL; |
| 8396 | *new_info_ptr = cur_ptr; |
| 8397 | } |
| 8398 | |
| 8399 | die->sibling = NULL; |
| 8400 | die->parent = parent; |
| 8401 | return die; |
| 8402 | } |
| 8403 | |
| 8404 | /* Read a die, all of its descendents, and all of its siblings; set |
| 8405 | all of the fields of all of the dies correctly. Arguments are as |
| 8406 | in read_die_and_children. */ |
| 8407 | |
| 8408 | static struct die_info * |
| 8409 | read_die_and_siblings (const struct die_reader_specs *reader, |
| 8410 | gdb_byte *info_ptr, |
| 8411 | gdb_byte **new_info_ptr, |
| 8412 | struct die_info *parent) |
| 8413 | { |
| 8414 | struct die_info *first_die, *last_sibling; |
| 8415 | gdb_byte *cur_ptr; |
| 8416 | |
| 8417 | cur_ptr = info_ptr; |
| 8418 | first_die = last_sibling = NULL; |
| 8419 | |
| 8420 | while (1) |
| 8421 | { |
| 8422 | struct die_info *die |
| 8423 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
| 8424 | |
| 8425 | if (die == NULL) |
| 8426 | { |
| 8427 | *new_info_ptr = cur_ptr; |
| 8428 | return first_die; |
| 8429 | } |
| 8430 | |
| 8431 | if (!first_die) |
| 8432 | first_die = die; |
| 8433 | else |
| 8434 | last_sibling->sibling = die; |
| 8435 | |
| 8436 | last_sibling = die; |
| 8437 | } |
| 8438 | } |
| 8439 | |
| 8440 | /* Read the die from the .debug_info section buffer. Set DIEP to |
| 8441 | point to a newly allocated die with its information, except for its |
| 8442 | child, sibling, and parent fields. Set HAS_CHILDREN to tell |
| 8443 | whether the die has children or not. */ |
| 8444 | |
| 8445 | static gdb_byte * |
| 8446 | read_full_die (const struct die_reader_specs *reader, |
| 8447 | struct die_info **diep, gdb_byte *info_ptr, |
| 8448 | int *has_children) |
| 8449 | { |
| 8450 | unsigned int abbrev_number, bytes_read, i, offset; |
| 8451 | struct abbrev_info *abbrev; |
| 8452 | struct die_info *die; |
| 8453 | struct dwarf2_cu *cu = reader->cu; |
| 8454 | bfd *abfd = reader->abfd; |
| 8455 | |
| 8456 | offset = info_ptr - reader->buffer; |
| 8457 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 8458 | info_ptr += bytes_read; |
| 8459 | if (!abbrev_number) |
| 8460 | { |
| 8461 | *diep = NULL; |
| 8462 | *has_children = 0; |
| 8463 | return info_ptr; |
| 8464 | } |
| 8465 | |
| 8466 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
| 8467 | if (!abbrev) |
| 8468 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
| 8469 | abbrev_number, |
| 8470 | bfd_get_filename (abfd)); |
| 8471 | |
| 8472 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
| 8473 | die->offset = offset; |
| 8474 | die->tag = abbrev->tag; |
| 8475 | die->abbrev = abbrev_number; |
| 8476 | |
| 8477 | die->num_attrs = abbrev->num_attrs; |
| 8478 | |
| 8479 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 8480 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], |
| 8481 | abfd, info_ptr, cu); |
| 8482 | |
| 8483 | *diep = die; |
| 8484 | *has_children = abbrev->has_children; |
| 8485 | return info_ptr; |
| 8486 | } |
| 8487 | |
| 8488 | /* In DWARF version 2, the description of the debugging information is |
| 8489 | stored in a separate .debug_abbrev section. Before we read any |
| 8490 | dies from a section we read in all abbreviations and install them |
| 8491 | in a hash table. This function also sets flags in CU describing |
| 8492 | the data found in the abbrev table. */ |
| 8493 | |
| 8494 | static void |
| 8495 | dwarf2_read_abbrevs (bfd *abfd, struct dwarf2_cu *cu) |
| 8496 | { |
| 8497 | struct comp_unit_head *cu_header = &cu->header; |
| 8498 | gdb_byte *abbrev_ptr; |
| 8499 | struct abbrev_info *cur_abbrev; |
| 8500 | unsigned int abbrev_number, bytes_read, abbrev_name; |
| 8501 | unsigned int abbrev_form, hash_number; |
| 8502 | struct attr_abbrev *cur_attrs; |
| 8503 | unsigned int allocated_attrs; |
| 8504 | |
| 8505 | /* Initialize dwarf2 abbrevs. */ |
| 8506 | obstack_init (&cu->abbrev_obstack); |
| 8507 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, |
| 8508 | (ABBREV_HASH_SIZE |
| 8509 | * sizeof (struct abbrev_info *))); |
| 8510 | memset (cu->dwarf2_abbrevs, 0, |
| 8511 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); |
| 8512 | |
| 8513 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 8514 | &dwarf2_per_objfile->abbrev); |
| 8515 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
| 8516 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8517 | abbrev_ptr += bytes_read; |
| 8518 | |
| 8519 | allocated_attrs = ATTR_ALLOC_CHUNK; |
| 8520 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); |
| 8521 | |
| 8522 | /* Loop until we reach an abbrev number of 0. */ |
| 8523 | while (abbrev_number) |
| 8524 | { |
| 8525 | cur_abbrev = dwarf_alloc_abbrev (cu); |
| 8526 | |
| 8527 | /* read in abbrev header */ |
| 8528 | cur_abbrev->number = abbrev_number; |
| 8529 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8530 | abbrev_ptr += bytes_read; |
| 8531 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); |
| 8532 | abbrev_ptr += 1; |
| 8533 | |
| 8534 | if (cur_abbrev->tag == DW_TAG_namespace) |
| 8535 | cu->has_namespace_info = 1; |
| 8536 | |
| 8537 | /* now read in declarations */ |
| 8538 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8539 | abbrev_ptr += bytes_read; |
| 8540 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8541 | abbrev_ptr += bytes_read; |
| 8542 | while (abbrev_name) |
| 8543 | { |
| 8544 | if (cur_abbrev->num_attrs == allocated_attrs) |
| 8545 | { |
| 8546 | allocated_attrs += ATTR_ALLOC_CHUNK; |
| 8547 | cur_attrs |
| 8548 | = xrealloc (cur_attrs, (allocated_attrs |
| 8549 | * sizeof (struct attr_abbrev))); |
| 8550 | } |
| 8551 | |
| 8552 | /* Record whether this compilation unit might have |
| 8553 | inter-compilation-unit references. If we don't know what form |
| 8554 | this attribute will have, then it might potentially be a |
| 8555 | DW_FORM_ref_addr, so we conservatively expect inter-CU |
| 8556 | references. */ |
| 8557 | |
| 8558 | if (abbrev_form == DW_FORM_ref_addr |
| 8559 | || abbrev_form == DW_FORM_indirect) |
| 8560 | cu->has_form_ref_addr = 1; |
| 8561 | |
| 8562 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
| 8563 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; |
| 8564 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8565 | abbrev_ptr += bytes_read; |
| 8566 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8567 | abbrev_ptr += bytes_read; |
| 8568 | } |
| 8569 | |
| 8570 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
| 8571 | (cur_abbrev->num_attrs |
| 8572 | * sizeof (struct attr_abbrev))); |
| 8573 | memcpy (cur_abbrev->attrs, cur_attrs, |
| 8574 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); |
| 8575 | |
| 8576 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
| 8577 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
| 8578 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; |
| 8579 | |
| 8580 | /* Get next abbreviation. |
| 8581 | Under Irix6 the abbreviations for a compilation unit are not |
| 8582 | always properly terminated with an abbrev number of 0. |
| 8583 | Exit loop if we encounter an abbreviation which we have |
| 8584 | already read (which means we are about to read the abbreviations |
| 8585 | for the next compile unit) or if the end of the abbreviation |
| 8586 | table is reached. */ |
| 8587 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
| 8588 | >= dwarf2_per_objfile->abbrev.size) |
| 8589 | break; |
| 8590 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 8591 | abbrev_ptr += bytes_read; |
| 8592 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
| 8593 | break; |
| 8594 | } |
| 8595 | |
| 8596 | xfree (cur_attrs); |
| 8597 | } |
| 8598 | |
| 8599 | /* Release the memory used by the abbrev table for a compilation unit. */ |
| 8600 | |
| 8601 | static void |
| 8602 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
| 8603 | { |
| 8604 | struct dwarf2_cu *cu = ptr_to_cu; |
| 8605 | |
| 8606 | obstack_free (&cu->abbrev_obstack, NULL); |
| 8607 | cu->dwarf2_abbrevs = NULL; |
| 8608 | } |
| 8609 | |
| 8610 | /* Lookup an abbrev_info structure in the abbrev hash table. */ |
| 8611 | |
| 8612 | static struct abbrev_info * |
| 8613 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
| 8614 | { |
| 8615 | unsigned int hash_number; |
| 8616 | struct abbrev_info *abbrev; |
| 8617 | |
| 8618 | hash_number = number % ABBREV_HASH_SIZE; |
| 8619 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
| 8620 | |
| 8621 | while (abbrev) |
| 8622 | { |
| 8623 | if (abbrev->number == number) |
| 8624 | return abbrev; |
| 8625 | else |
| 8626 | abbrev = abbrev->next; |
| 8627 | } |
| 8628 | return NULL; |
| 8629 | } |
| 8630 | |
| 8631 | /* Returns nonzero if TAG represents a type that we might generate a partial |
| 8632 | symbol for. */ |
| 8633 | |
| 8634 | static int |
| 8635 | is_type_tag_for_partial (int tag) |
| 8636 | { |
| 8637 | switch (tag) |
| 8638 | { |
| 8639 | #if 0 |
| 8640 | /* Some types that would be reasonable to generate partial symbols for, |
| 8641 | that we don't at present. */ |
| 8642 | case DW_TAG_array_type: |
| 8643 | case DW_TAG_file_type: |
| 8644 | case DW_TAG_ptr_to_member_type: |
| 8645 | case DW_TAG_set_type: |
| 8646 | case DW_TAG_string_type: |
| 8647 | case DW_TAG_subroutine_type: |
| 8648 | #endif |
| 8649 | case DW_TAG_base_type: |
| 8650 | case DW_TAG_class_type: |
| 8651 | case DW_TAG_interface_type: |
| 8652 | case DW_TAG_enumeration_type: |
| 8653 | case DW_TAG_structure_type: |
| 8654 | case DW_TAG_subrange_type: |
| 8655 | case DW_TAG_typedef: |
| 8656 | case DW_TAG_union_type: |
| 8657 | return 1; |
| 8658 | default: |
| 8659 | return 0; |
| 8660 | } |
| 8661 | } |
| 8662 | |
| 8663 | /* Load all DIEs that are interesting for partial symbols into memory. */ |
| 8664 | |
| 8665 | static struct partial_die_info * |
| 8666 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
| 8667 | int building_psymtab, struct dwarf2_cu *cu) |
| 8668 | { |
| 8669 | struct partial_die_info *part_die; |
| 8670 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; |
| 8671 | struct abbrev_info *abbrev; |
| 8672 | unsigned int bytes_read; |
| 8673 | unsigned int load_all = 0; |
| 8674 | |
| 8675 | int nesting_level = 1; |
| 8676 | |
| 8677 | parent_die = NULL; |
| 8678 | last_die = NULL; |
| 8679 | |
| 8680 | if (cu->per_cu && cu->per_cu->load_all_dies) |
| 8681 | load_all = 1; |
| 8682 | |
| 8683 | cu->partial_dies |
| 8684 | = htab_create_alloc_ex (cu->header.length / 12, |
| 8685 | partial_die_hash, |
| 8686 | partial_die_eq, |
| 8687 | NULL, |
| 8688 | &cu->comp_unit_obstack, |
| 8689 | hashtab_obstack_allocate, |
| 8690 | dummy_obstack_deallocate); |
| 8691 | |
| 8692 | part_die = obstack_alloc (&cu->comp_unit_obstack, |
| 8693 | sizeof (struct partial_die_info)); |
| 8694 | |
| 8695 | while (1) |
| 8696 | { |
| 8697 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); |
| 8698 | |
| 8699 | /* A NULL abbrev means the end of a series of children. */ |
| 8700 | if (abbrev == NULL) |
| 8701 | { |
| 8702 | if (--nesting_level == 0) |
| 8703 | { |
| 8704 | /* PART_DIE was probably the last thing allocated on the |
| 8705 | comp_unit_obstack, so we could call obstack_free |
| 8706 | here. We don't do that because the waste is small, |
| 8707 | and will be cleaned up when we're done with this |
| 8708 | compilation unit. This way, we're also more robust |
| 8709 | against other users of the comp_unit_obstack. */ |
| 8710 | return first_die; |
| 8711 | } |
| 8712 | info_ptr += bytes_read; |
| 8713 | last_die = parent_die; |
| 8714 | parent_die = parent_die->die_parent; |
| 8715 | continue; |
| 8716 | } |
| 8717 | |
| 8718 | /* Check for template arguments. We never save these; if |
| 8719 | they're seen, we just mark the parent, and go on our way. */ |
| 8720 | if (parent_die != NULL |
| 8721 | && cu->language == language_cplus |
| 8722 | && (abbrev->tag == DW_TAG_template_type_param |
| 8723 | || abbrev->tag == DW_TAG_template_value_param)) |
| 8724 | { |
| 8725 | parent_die->has_template_arguments = 1; |
| 8726 | |
| 8727 | if (!load_all) |
| 8728 | { |
| 8729 | /* We don't need a partial DIE for the template argument. */ |
| 8730 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, |
| 8731 | cu); |
| 8732 | continue; |
| 8733 | } |
| 8734 | } |
| 8735 | |
| 8736 | /* We only recurse into subprograms looking for template arguments. |
| 8737 | Skip their other children. */ |
| 8738 | if (!load_all |
| 8739 | && cu->language == language_cplus |
| 8740 | && parent_die != NULL |
| 8741 | && parent_die->tag == DW_TAG_subprogram) |
| 8742 | { |
| 8743 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
| 8744 | continue; |
| 8745 | } |
| 8746 | |
| 8747 | /* Check whether this DIE is interesting enough to save. Normally |
| 8748 | we would not be interested in members here, but there may be |
| 8749 | later variables referencing them via DW_AT_specification (for |
| 8750 | static members). */ |
| 8751 | if (!load_all |
| 8752 | && !is_type_tag_for_partial (abbrev->tag) |
| 8753 | && abbrev->tag != DW_TAG_constant |
| 8754 | && abbrev->tag != DW_TAG_enumerator |
| 8755 | && abbrev->tag != DW_TAG_subprogram |
| 8756 | && abbrev->tag != DW_TAG_lexical_block |
| 8757 | && abbrev->tag != DW_TAG_variable |
| 8758 | && abbrev->tag != DW_TAG_namespace |
| 8759 | && abbrev->tag != DW_TAG_module |
| 8760 | && abbrev->tag != DW_TAG_member) |
| 8761 | { |
| 8762 | /* Otherwise we skip to the next sibling, if any. */ |
| 8763 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
| 8764 | continue; |
| 8765 | } |
| 8766 | |
| 8767 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
| 8768 | buffer, info_ptr, cu); |
| 8769 | |
| 8770 | /* This two-pass algorithm for processing partial symbols has a |
| 8771 | high cost in cache pressure. Thus, handle some simple cases |
| 8772 | here which cover the majority of C partial symbols. DIEs |
| 8773 | which neither have specification tags in them, nor could have |
| 8774 | specification tags elsewhere pointing at them, can simply be |
| 8775 | processed and discarded. |
| 8776 | |
| 8777 | This segment is also optional; scan_partial_symbols and |
| 8778 | add_partial_symbol will handle these DIEs if we chain |
| 8779 | them in normally. When compilers which do not emit large |
| 8780 | quantities of duplicate debug information are more common, |
| 8781 | this code can probably be removed. */ |
| 8782 | |
| 8783 | /* Any complete simple types at the top level (pretty much all |
| 8784 | of them, for a language without namespaces), can be processed |
| 8785 | directly. */ |
| 8786 | if (parent_die == NULL |
| 8787 | && part_die->has_specification == 0 |
| 8788 | && part_die->is_declaration == 0 |
| 8789 | && (part_die->tag == DW_TAG_typedef |
| 8790 | || part_die->tag == DW_TAG_base_type |
| 8791 | || part_die->tag == DW_TAG_subrange_type)) |
| 8792 | { |
| 8793 | if (building_psymtab && part_die->name != NULL) |
| 8794 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
| 8795 | VAR_DOMAIN, LOC_TYPEDEF, |
| 8796 | &cu->objfile->static_psymbols, |
| 8797 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); |
| 8798 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
| 8799 | continue; |
| 8800 | } |
| 8801 | |
| 8802 | /* If we're at the second level, and we're an enumerator, and |
| 8803 | our parent has no specification (meaning possibly lives in a |
| 8804 | namespace elsewhere), then we can add the partial symbol now |
| 8805 | instead of queueing it. */ |
| 8806 | if (part_die->tag == DW_TAG_enumerator |
| 8807 | && parent_die != NULL |
| 8808 | && parent_die->die_parent == NULL |
| 8809 | && parent_die->tag == DW_TAG_enumeration_type |
| 8810 | && parent_die->has_specification == 0) |
| 8811 | { |
| 8812 | if (part_die->name == NULL) |
| 8813 | complaint (&symfile_complaints, |
| 8814 | _("malformed enumerator DIE ignored")); |
| 8815 | else if (building_psymtab) |
| 8816 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
| 8817 | VAR_DOMAIN, LOC_CONST, |
| 8818 | (cu->language == language_cplus |
| 8819 | || cu->language == language_java) |
| 8820 | ? &cu->objfile->global_psymbols |
| 8821 | : &cu->objfile->static_psymbols, |
| 8822 | 0, (CORE_ADDR) 0, cu->language, cu->objfile); |
| 8823 | |
| 8824 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
| 8825 | continue; |
| 8826 | } |
| 8827 | |
| 8828 | /* We'll save this DIE so link it in. */ |
| 8829 | part_die->die_parent = parent_die; |
| 8830 | part_die->die_sibling = NULL; |
| 8831 | part_die->die_child = NULL; |
| 8832 | |
| 8833 | if (last_die && last_die == parent_die) |
| 8834 | last_die->die_child = part_die; |
| 8835 | else if (last_die) |
| 8836 | last_die->die_sibling = part_die; |
| 8837 | |
| 8838 | last_die = part_die; |
| 8839 | |
| 8840 | if (first_die == NULL) |
| 8841 | first_die = part_die; |
| 8842 | |
| 8843 | /* Maybe add the DIE to the hash table. Not all DIEs that we |
| 8844 | find interesting need to be in the hash table, because we |
| 8845 | also have the parent/sibling/child chains; only those that we |
| 8846 | might refer to by offset later during partial symbol reading. |
| 8847 | |
| 8848 | For now this means things that might have be the target of a |
| 8849 | DW_AT_specification, DW_AT_abstract_origin, or |
| 8850 | DW_AT_extension. DW_AT_extension will refer only to |
| 8851 | namespaces; DW_AT_abstract_origin refers to functions (and |
| 8852 | many things under the function DIE, but we do not recurse |
| 8853 | into function DIEs during partial symbol reading) and |
| 8854 | possibly variables as well; DW_AT_specification refers to |
| 8855 | declarations. Declarations ought to have the DW_AT_declaration |
| 8856 | flag. It happens that GCC forgets to put it in sometimes, but |
| 8857 | only for functions, not for types. |
| 8858 | |
| 8859 | Adding more things than necessary to the hash table is harmless |
| 8860 | except for the performance cost. Adding too few will result in |
| 8861 | wasted time in find_partial_die, when we reread the compilation |
| 8862 | unit with load_all_dies set. */ |
| 8863 | |
| 8864 | if (load_all |
| 8865 | || abbrev->tag == DW_TAG_constant |
| 8866 | || abbrev->tag == DW_TAG_subprogram |
| 8867 | || abbrev->tag == DW_TAG_variable |
| 8868 | || abbrev->tag == DW_TAG_namespace |
| 8869 | || part_die->is_declaration) |
| 8870 | { |
| 8871 | void **slot; |
| 8872 | |
| 8873 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, |
| 8874 | part_die->offset, INSERT); |
| 8875 | *slot = part_die; |
| 8876 | } |
| 8877 | |
| 8878 | part_die = obstack_alloc (&cu->comp_unit_obstack, |
| 8879 | sizeof (struct partial_die_info)); |
| 8880 | |
| 8881 | /* For some DIEs we want to follow their children (if any). For C |
| 8882 | we have no reason to follow the children of structures; for other |
| 8883 | languages we have to, so that we can get at method physnames |
| 8884 | to infer fully qualified class names, for DW_AT_specification, |
| 8885 | and for C++ template arguments. For C++, we also look one level |
| 8886 | inside functions to find template arguments (if the name of the |
| 8887 | function does not already contain the template arguments). |
| 8888 | |
| 8889 | For Ada, we need to scan the children of subprograms and lexical |
| 8890 | blocks as well because Ada allows the definition of nested |
| 8891 | entities that could be interesting for the debugger, such as |
| 8892 | nested subprograms for instance. */ |
| 8893 | if (last_die->has_children |
| 8894 | && (load_all |
| 8895 | || last_die->tag == DW_TAG_namespace |
| 8896 | || last_die->tag == DW_TAG_module |
| 8897 | || last_die->tag == DW_TAG_enumeration_type |
| 8898 | || (cu->language == language_cplus |
| 8899 | && last_die->tag == DW_TAG_subprogram |
| 8900 | && (last_die->name == NULL |
| 8901 | || strchr (last_die->name, '<') == NULL)) |
| 8902 | || (cu->language != language_c |
| 8903 | && (last_die->tag == DW_TAG_class_type |
| 8904 | || last_die->tag == DW_TAG_interface_type |
| 8905 | || last_die->tag == DW_TAG_structure_type |
| 8906 | || last_die->tag == DW_TAG_union_type)) |
| 8907 | || (cu->language == language_ada |
| 8908 | && (last_die->tag == DW_TAG_subprogram |
| 8909 | || last_die->tag == DW_TAG_lexical_block)))) |
| 8910 | { |
| 8911 | nesting_level++; |
| 8912 | parent_die = last_die; |
| 8913 | continue; |
| 8914 | } |
| 8915 | |
| 8916 | /* Otherwise we skip to the next sibling, if any. */ |
| 8917 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
| 8918 | |
| 8919 | /* Back to the top, do it again. */ |
| 8920 | } |
| 8921 | } |
| 8922 | |
| 8923 | /* Read a minimal amount of information into the minimal die structure. */ |
| 8924 | |
| 8925 | static gdb_byte * |
| 8926 | read_partial_die (struct partial_die_info *part_die, |
| 8927 | struct abbrev_info *abbrev, |
| 8928 | unsigned int abbrev_len, bfd *abfd, |
| 8929 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 8930 | struct dwarf2_cu *cu) |
| 8931 | { |
| 8932 | unsigned int i; |
| 8933 | struct attribute attr; |
| 8934 | int has_low_pc_attr = 0; |
| 8935 | int has_high_pc_attr = 0; |
| 8936 | |
| 8937 | memset (part_die, 0, sizeof (struct partial_die_info)); |
| 8938 | |
| 8939 | part_die->offset = info_ptr - buffer; |
| 8940 | |
| 8941 | info_ptr += abbrev_len; |
| 8942 | |
| 8943 | if (abbrev == NULL) |
| 8944 | return info_ptr; |
| 8945 | |
| 8946 | part_die->tag = abbrev->tag; |
| 8947 | part_die->has_children = abbrev->has_children; |
| 8948 | |
| 8949 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 8950 | { |
| 8951 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
| 8952 | |
| 8953 | /* Store the data if it is of an attribute we want to keep in a |
| 8954 | partial symbol table. */ |
| 8955 | switch (attr.name) |
| 8956 | { |
| 8957 | case DW_AT_name: |
| 8958 | switch (part_die->tag) |
| 8959 | { |
| 8960 | case DW_TAG_compile_unit: |
| 8961 | case DW_TAG_type_unit: |
| 8962 | /* Compilation units have a DW_AT_name that is a filename, not |
| 8963 | a source language identifier. */ |
| 8964 | case DW_TAG_enumeration_type: |
| 8965 | case DW_TAG_enumerator: |
| 8966 | /* These tags always have simple identifiers already; no need |
| 8967 | to canonicalize them. */ |
| 8968 | part_die->name = DW_STRING (&attr); |
| 8969 | break; |
| 8970 | default: |
| 8971 | part_die->name |
| 8972 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, |
| 8973 | &cu->objfile->objfile_obstack); |
| 8974 | break; |
| 8975 | } |
| 8976 | break; |
| 8977 | case DW_AT_linkage_name: |
| 8978 | case DW_AT_MIPS_linkage_name: |
| 8979 | /* Note that both forms of linkage name might appear. We |
| 8980 | assume they will be the same, and we only store the last |
| 8981 | one we see. */ |
| 8982 | if (cu->language == language_ada) |
| 8983 | part_die->name = DW_STRING (&attr); |
| 8984 | part_die->linkage_name = DW_STRING (&attr); |
| 8985 | break; |
| 8986 | case DW_AT_low_pc: |
| 8987 | has_low_pc_attr = 1; |
| 8988 | part_die->lowpc = DW_ADDR (&attr); |
| 8989 | break; |
| 8990 | case DW_AT_high_pc: |
| 8991 | has_high_pc_attr = 1; |
| 8992 | part_die->highpc = DW_ADDR (&attr); |
| 8993 | break; |
| 8994 | case DW_AT_location: |
| 8995 | /* Support the .debug_loc offsets. */ |
| 8996 | if (attr_form_is_block (&attr)) |
| 8997 | { |
| 8998 | part_die->locdesc = DW_BLOCK (&attr); |
| 8999 | } |
| 9000 | else if (attr_form_is_section_offset (&attr)) |
| 9001 | { |
| 9002 | dwarf2_complex_location_expr_complaint (); |
| 9003 | } |
| 9004 | else |
| 9005 | { |
| 9006 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 9007 | "partial symbol information"); |
| 9008 | } |
| 9009 | break; |
| 9010 | case DW_AT_external: |
| 9011 | part_die->is_external = DW_UNSND (&attr); |
| 9012 | break; |
| 9013 | case DW_AT_declaration: |
| 9014 | part_die->is_declaration = DW_UNSND (&attr); |
| 9015 | break; |
| 9016 | case DW_AT_type: |
| 9017 | part_die->has_type = 1; |
| 9018 | break; |
| 9019 | case DW_AT_abstract_origin: |
| 9020 | case DW_AT_specification: |
| 9021 | case DW_AT_extension: |
| 9022 | part_die->has_specification = 1; |
| 9023 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
| 9024 | break; |
| 9025 | case DW_AT_sibling: |
| 9026 | /* Ignore absolute siblings, they might point outside of |
| 9027 | the current compile unit. */ |
| 9028 | if (attr.form == DW_FORM_ref_addr) |
| 9029 | complaint (&symfile_complaints, |
| 9030 | _("ignoring absolute DW_AT_sibling")); |
| 9031 | else |
| 9032 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
| 9033 | break; |
| 9034 | case DW_AT_byte_size: |
| 9035 | part_die->has_byte_size = 1; |
| 9036 | break; |
| 9037 | case DW_AT_calling_convention: |
| 9038 | /* DWARF doesn't provide a way to identify a program's source-level |
| 9039 | entry point. DW_AT_calling_convention attributes are only meant |
| 9040 | to describe functions' calling conventions. |
| 9041 | |
| 9042 | However, because it's a necessary piece of information in |
| 9043 | Fortran, and because DW_CC_program is the only piece of debugging |
| 9044 | information whose definition refers to a 'main program' at all, |
| 9045 | several compilers have begun marking Fortran main programs with |
| 9046 | DW_CC_program --- even when those functions use the standard |
| 9047 | calling conventions. |
| 9048 | |
| 9049 | So until DWARF specifies a way to provide this information and |
| 9050 | compilers pick up the new representation, we'll support this |
| 9051 | practice. */ |
| 9052 | if (DW_UNSND (&attr) == DW_CC_program |
| 9053 | && cu->language == language_fortran) |
| 9054 | { |
| 9055 | set_main_name (part_die->name); |
| 9056 | |
| 9057 | /* As this DIE has a static linkage the name would be difficult |
| 9058 | to look up later. */ |
| 9059 | language_of_main = language_fortran; |
| 9060 | } |
| 9061 | break; |
| 9062 | default: |
| 9063 | break; |
| 9064 | } |
| 9065 | } |
| 9066 | |
| 9067 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 9068 | eliminate duplicate copies of functions and vtables and such. |
| 9069 | The linker will arbitrarily choose one and discard the others. |
| 9070 | The AT_*_pc values for such functions refer to local labels in |
| 9071 | these sections. If the section from that file was discarded, the |
| 9072 | labels are not in the output, so the relocs get a value of 0. |
| 9073 | If this is a discarded function, mark the pc bounds as invalid, |
| 9074 | so that GDB will ignore it. */ |
| 9075 | if (has_low_pc_attr && has_high_pc_attr |
| 9076 | && part_die->lowpc < part_die->highpc |
| 9077 | && (part_die->lowpc != 0 |
| 9078 | || dwarf2_per_objfile->has_section_at_zero)) |
| 9079 | part_die->has_pc_info = 1; |
| 9080 | |
| 9081 | return info_ptr; |
| 9082 | } |
| 9083 | |
| 9084 | /* Find a cached partial DIE at OFFSET in CU. */ |
| 9085 | |
| 9086 | static struct partial_die_info * |
| 9087 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
| 9088 | { |
| 9089 | struct partial_die_info *lookup_die = NULL; |
| 9090 | struct partial_die_info part_die; |
| 9091 | |
| 9092 | part_die.offset = offset; |
| 9093 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); |
| 9094 | |
| 9095 | return lookup_die; |
| 9096 | } |
| 9097 | |
| 9098 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
| 9099 | except in the case of .debug_types DIEs which do not reference |
| 9100 | outside their CU (they do however referencing other types via |
| 9101 | DW_FORM_sig8). */ |
| 9102 | |
| 9103 | static struct partial_die_info * |
| 9104 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
| 9105 | { |
| 9106 | struct dwarf2_per_cu_data *per_cu = NULL; |
| 9107 | struct partial_die_info *pd = NULL; |
| 9108 | |
| 9109 | if (cu->per_cu->from_debug_types) |
| 9110 | { |
| 9111 | pd = find_partial_die_in_comp_unit (offset, cu); |
| 9112 | if (pd != NULL) |
| 9113 | return pd; |
| 9114 | goto not_found; |
| 9115 | } |
| 9116 | |
| 9117 | if (offset_in_cu_p (&cu->header, offset)) |
| 9118 | { |
| 9119 | pd = find_partial_die_in_comp_unit (offset, cu); |
| 9120 | if (pd != NULL) |
| 9121 | return pd; |
| 9122 | } |
| 9123 | |
| 9124 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
| 9125 | |
| 9126 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
| 9127 | load_partial_comp_unit (per_cu, cu->objfile); |
| 9128 | |
| 9129 | per_cu->cu->last_used = 0; |
| 9130 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
| 9131 | |
| 9132 | if (pd == NULL && per_cu->load_all_dies == 0) |
| 9133 | { |
| 9134 | struct cleanup *back_to; |
| 9135 | struct partial_die_info comp_unit_die; |
| 9136 | struct abbrev_info *abbrev; |
| 9137 | unsigned int bytes_read; |
| 9138 | char *info_ptr; |
| 9139 | |
| 9140 | per_cu->load_all_dies = 1; |
| 9141 | |
| 9142 | /* Re-read the DIEs. */ |
| 9143 | back_to = make_cleanup (null_cleanup, 0); |
| 9144 | if (per_cu->cu->dwarf2_abbrevs == NULL) |
| 9145 | { |
| 9146 | dwarf2_read_abbrevs (per_cu->cu->objfile->obfd, per_cu->cu); |
| 9147 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
| 9148 | } |
| 9149 | info_ptr = (dwarf2_per_objfile->info.buffer |
| 9150 | + per_cu->cu->header.offset |
| 9151 | + per_cu->cu->header.first_die_offset); |
| 9152 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
| 9153 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, |
| 9154 | per_cu->cu->objfile->obfd, |
| 9155 | dwarf2_per_objfile->info.buffer, info_ptr, |
| 9156 | per_cu->cu); |
| 9157 | if (comp_unit_die.has_children) |
| 9158 | load_partial_dies (per_cu->cu->objfile->obfd, |
| 9159 | dwarf2_per_objfile->info.buffer, info_ptr, |
| 9160 | 0, per_cu->cu); |
| 9161 | do_cleanups (back_to); |
| 9162 | |
| 9163 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
| 9164 | } |
| 9165 | |
| 9166 | not_found: |
| 9167 | |
| 9168 | if (pd == NULL) |
| 9169 | internal_error (__FILE__, __LINE__, |
| 9170 | _("could not find partial DIE 0x%x " |
| 9171 | "in cache [from module %s]\n"), |
| 9172 | offset, bfd_get_filename (cu->objfile->obfd)); |
| 9173 | return pd; |
| 9174 | } |
| 9175 | |
| 9176 | /* See if we can figure out if the class lives in a namespace. We do |
| 9177 | this by looking for a member function; its demangled name will |
| 9178 | contain namespace info, if there is any. */ |
| 9179 | |
| 9180 | static void |
| 9181 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, |
| 9182 | struct dwarf2_cu *cu) |
| 9183 | { |
| 9184 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
| 9185 | what template types look like, because the demangler |
| 9186 | frequently doesn't give the same name as the debug info. We |
| 9187 | could fix this by only using the demangled name to get the |
| 9188 | prefix (but see comment in read_structure_type). */ |
| 9189 | |
| 9190 | struct partial_die_info *real_pdi; |
| 9191 | struct partial_die_info *child_pdi; |
| 9192 | |
| 9193 | /* If this DIE (this DIE's specification, if any) has a parent, then |
| 9194 | we should not do this. We'll prepend the parent's fully qualified |
| 9195 | name when we create the partial symbol. */ |
| 9196 | |
| 9197 | real_pdi = struct_pdi; |
| 9198 | while (real_pdi->has_specification) |
| 9199 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
| 9200 | |
| 9201 | if (real_pdi->die_parent != NULL) |
| 9202 | return; |
| 9203 | |
| 9204 | for (child_pdi = struct_pdi->die_child; |
| 9205 | child_pdi != NULL; |
| 9206 | child_pdi = child_pdi->die_sibling) |
| 9207 | { |
| 9208 | if (child_pdi->tag == DW_TAG_subprogram |
| 9209 | && child_pdi->linkage_name != NULL) |
| 9210 | { |
| 9211 | char *actual_class_name |
| 9212 | = language_class_name_from_physname (cu->language_defn, |
| 9213 | child_pdi->linkage_name); |
| 9214 | if (actual_class_name != NULL) |
| 9215 | { |
| 9216 | struct_pdi->name |
| 9217 | = obsavestring (actual_class_name, |
| 9218 | strlen (actual_class_name), |
| 9219 | &cu->objfile->objfile_obstack); |
| 9220 | xfree (actual_class_name); |
| 9221 | } |
| 9222 | break; |
| 9223 | } |
| 9224 | } |
| 9225 | } |
| 9226 | |
| 9227 | /* Adjust PART_DIE before generating a symbol for it. This function |
| 9228 | may set the is_external flag or change the DIE's name. */ |
| 9229 | |
| 9230 | static void |
| 9231 | fixup_partial_die (struct partial_die_info *part_die, |
| 9232 | struct dwarf2_cu *cu) |
| 9233 | { |
| 9234 | /* Once we've fixed up a die, there's no point in doing so again. |
| 9235 | This also avoids a memory leak if we were to call |
| 9236 | guess_partial_die_structure_name multiple times. */ |
| 9237 | if (part_die->fixup_called) |
| 9238 | return; |
| 9239 | |
| 9240 | /* If we found a reference attribute and the DIE has no name, try |
| 9241 | to find a name in the referred to DIE. */ |
| 9242 | |
| 9243 | if (part_die->name == NULL && part_die->has_specification) |
| 9244 | { |
| 9245 | struct partial_die_info *spec_die; |
| 9246 | |
| 9247 | spec_die = find_partial_die (part_die->spec_offset, cu); |
| 9248 | |
| 9249 | fixup_partial_die (spec_die, cu); |
| 9250 | |
| 9251 | if (spec_die->name) |
| 9252 | { |
| 9253 | part_die->name = spec_die->name; |
| 9254 | |
| 9255 | /* Copy DW_AT_external attribute if it is set. */ |
| 9256 | if (spec_die->is_external) |
| 9257 | part_die->is_external = spec_die->is_external; |
| 9258 | } |
| 9259 | } |
| 9260 | |
| 9261 | /* Set default names for some unnamed DIEs. */ |
| 9262 | |
| 9263 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) |
| 9264 | part_die->name = "(anonymous namespace)"; |
| 9265 | |
| 9266 | /* If there is no parent die to provide a namespace, and there are |
| 9267 | children, see if we can determine the namespace from their linkage |
| 9268 | name. |
| 9269 | NOTE: We need to do this even if cu->has_namespace_info != 0. |
| 9270 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ |
| 9271 | if (cu->language == language_cplus |
| 9272 | && dwarf2_per_objfile->types.asection != NULL |
| 9273 | && part_die->die_parent == NULL |
| 9274 | && part_die->has_children |
| 9275 | && (part_die->tag == DW_TAG_class_type |
| 9276 | || part_die->tag == DW_TAG_structure_type |
| 9277 | || part_die->tag == DW_TAG_union_type)) |
| 9278 | guess_partial_die_structure_name (part_die, cu); |
| 9279 | |
| 9280 | part_die->fixup_called = 1; |
| 9281 | } |
| 9282 | |
| 9283 | /* Read an attribute value described by an attribute form. */ |
| 9284 | |
| 9285 | static gdb_byte * |
| 9286 | read_attribute_value (struct attribute *attr, unsigned form, |
| 9287 | bfd *abfd, gdb_byte *info_ptr, |
| 9288 | struct dwarf2_cu *cu) |
| 9289 | { |
| 9290 | struct comp_unit_head *cu_header = &cu->header; |
| 9291 | unsigned int bytes_read; |
| 9292 | struct dwarf_block *blk; |
| 9293 | |
| 9294 | attr->form = form; |
| 9295 | switch (form) |
| 9296 | { |
| 9297 | case DW_FORM_ref_addr: |
| 9298 | if (cu->header.version == 2) |
| 9299 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
| 9300 | else |
| 9301 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
| 9302 | &cu->header, &bytes_read); |
| 9303 | info_ptr += bytes_read; |
| 9304 | break; |
| 9305 | case DW_FORM_addr: |
| 9306 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
| 9307 | info_ptr += bytes_read; |
| 9308 | break; |
| 9309 | case DW_FORM_block2: |
| 9310 | blk = dwarf_alloc_block (cu); |
| 9311 | blk->size = read_2_bytes (abfd, info_ptr); |
| 9312 | info_ptr += 2; |
| 9313 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 9314 | info_ptr += blk->size; |
| 9315 | DW_BLOCK (attr) = blk; |
| 9316 | break; |
| 9317 | case DW_FORM_block4: |
| 9318 | blk = dwarf_alloc_block (cu); |
| 9319 | blk->size = read_4_bytes (abfd, info_ptr); |
| 9320 | info_ptr += 4; |
| 9321 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 9322 | info_ptr += blk->size; |
| 9323 | DW_BLOCK (attr) = blk; |
| 9324 | break; |
| 9325 | case DW_FORM_data2: |
| 9326 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); |
| 9327 | info_ptr += 2; |
| 9328 | break; |
| 9329 | case DW_FORM_data4: |
| 9330 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); |
| 9331 | info_ptr += 4; |
| 9332 | break; |
| 9333 | case DW_FORM_data8: |
| 9334 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); |
| 9335 | info_ptr += 8; |
| 9336 | break; |
| 9337 | case DW_FORM_sec_offset: |
| 9338 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); |
| 9339 | info_ptr += bytes_read; |
| 9340 | break; |
| 9341 | case DW_FORM_string: |
| 9342 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
| 9343 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 9344 | info_ptr += bytes_read; |
| 9345 | break; |
| 9346 | case DW_FORM_strp: |
| 9347 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, |
| 9348 | &bytes_read); |
| 9349 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 9350 | info_ptr += bytes_read; |
| 9351 | break; |
| 9352 | case DW_FORM_exprloc: |
| 9353 | case DW_FORM_block: |
| 9354 | blk = dwarf_alloc_block (cu); |
| 9355 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 9356 | info_ptr += bytes_read; |
| 9357 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 9358 | info_ptr += blk->size; |
| 9359 | DW_BLOCK (attr) = blk; |
| 9360 | break; |
| 9361 | case DW_FORM_block1: |
| 9362 | blk = dwarf_alloc_block (cu); |
| 9363 | blk->size = read_1_byte (abfd, info_ptr); |
| 9364 | info_ptr += 1; |
| 9365 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 9366 | info_ptr += blk->size; |
| 9367 | DW_BLOCK (attr) = blk; |
| 9368 | break; |
| 9369 | case DW_FORM_data1: |
| 9370 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 9371 | info_ptr += 1; |
| 9372 | break; |
| 9373 | case DW_FORM_flag: |
| 9374 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 9375 | info_ptr += 1; |
| 9376 | break; |
| 9377 | case DW_FORM_flag_present: |
| 9378 | DW_UNSND (attr) = 1; |
| 9379 | break; |
| 9380 | case DW_FORM_sdata: |
| 9381 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); |
| 9382 | info_ptr += bytes_read; |
| 9383 | break; |
| 9384 | case DW_FORM_udata: |
| 9385 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 9386 | info_ptr += bytes_read; |
| 9387 | break; |
| 9388 | case DW_FORM_ref1: |
| 9389 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
| 9390 | info_ptr += 1; |
| 9391 | break; |
| 9392 | case DW_FORM_ref2: |
| 9393 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
| 9394 | info_ptr += 2; |
| 9395 | break; |
| 9396 | case DW_FORM_ref4: |
| 9397 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
| 9398 | info_ptr += 4; |
| 9399 | break; |
| 9400 | case DW_FORM_ref8: |
| 9401 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
| 9402 | info_ptr += 8; |
| 9403 | break; |
| 9404 | case DW_FORM_sig8: |
| 9405 | /* Convert the signature to something we can record in DW_UNSND |
| 9406 | for later lookup. |
| 9407 | NOTE: This is NULL if the type wasn't found. */ |
| 9408 | DW_SIGNATURED_TYPE (attr) = |
| 9409 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); |
| 9410 | info_ptr += 8; |
| 9411 | break; |
| 9412 | case DW_FORM_ref_udata: |
| 9413 | DW_ADDR (attr) = (cu->header.offset |
| 9414 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); |
| 9415 | info_ptr += bytes_read; |
| 9416 | break; |
| 9417 | case DW_FORM_indirect: |
| 9418 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 9419 | info_ptr += bytes_read; |
| 9420 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
| 9421 | break; |
| 9422 | default: |
| 9423 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
| 9424 | dwarf_form_name (form), |
| 9425 | bfd_get_filename (abfd)); |
| 9426 | } |
| 9427 | |
| 9428 | /* We have seen instances where the compiler tried to emit a byte |
| 9429 | size attribute of -1 which ended up being encoded as an unsigned |
| 9430 | 0xffffffff. Although 0xffffffff is technically a valid size value, |
| 9431 | an object of this size seems pretty unlikely so we can relatively |
| 9432 | safely treat these cases as if the size attribute was invalid and |
| 9433 | treat them as zero by default. */ |
| 9434 | if (attr->name == DW_AT_byte_size |
| 9435 | && form == DW_FORM_data4 |
| 9436 | && DW_UNSND (attr) >= 0xffffffff) |
| 9437 | { |
| 9438 | complaint |
| 9439 | (&symfile_complaints, |
| 9440 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
| 9441 | hex_string (DW_UNSND (attr))); |
| 9442 | DW_UNSND (attr) = 0; |
| 9443 | } |
| 9444 | |
| 9445 | return info_ptr; |
| 9446 | } |
| 9447 | |
| 9448 | /* Read an attribute described by an abbreviated attribute. */ |
| 9449 | |
| 9450 | static gdb_byte * |
| 9451 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
| 9452 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
| 9453 | { |
| 9454 | attr->name = abbrev->name; |
| 9455 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
| 9456 | } |
| 9457 | |
| 9458 | /* Read dwarf information from a buffer. */ |
| 9459 | |
| 9460 | static unsigned int |
| 9461 | read_1_byte (bfd *abfd, gdb_byte *buf) |
| 9462 | { |
| 9463 | return bfd_get_8 (abfd, buf); |
| 9464 | } |
| 9465 | |
| 9466 | static int |
| 9467 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
| 9468 | { |
| 9469 | return bfd_get_signed_8 (abfd, buf); |
| 9470 | } |
| 9471 | |
| 9472 | static unsigned int |
| 9473 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
| 9474 | { |
| 9475 | return bfd_get_16 (abfd, buf); |
| 9476 | } |
| 9477 | |
| 9478 | static int |
| 9479 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
| 9480 | { |
| 9481 | return bfd_get_signed_16 (abfd, buf); |
| 9482 | } |
| 9483 | |
| 9484 | static unsigned int |
| 9485 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
| 9486 | { |
| 9487 | return bfd_get_32 (abfd, buf); |
| 9488 | } |
| 9489 | |
| 9490 | static int |
| 9491 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
| 9492 | { |
| 9493 | return bfd_get_signed_32 (abfd, buf); |
| 9494 | } |
| 9495 | |
| 9496 | static ULONGEST |
| 9497 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
| 9498 | { |
| 9499 | return bfd_get_64 (abfd, buf); |
| 9500 | } |
| 9501 | |
| 9502 | static CORE_ADDR |
| 9503 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
| 9504 | unsigned int *bytes_read) |
| 9505 | { |
| 9506 | struct comp_unit_head *cu_header = &cu->header; |
| 9507 | CORE_ADDR retval = 0; |
| 9508 | |
| 9509 | if (cu_header->signed_addr_p) |
| 9510 | { |
| 9511 | switch (cu_header->addr_size) |
| 9512 | { |
| 9513 | case 2: |
| 9514 | retval = bfd_get_signed_16 (abfd, buf); |
| 9515 | break; |
| 9516 | case 4: |
| 9517 | retval = bfd_get_signed_32 (abfd, buf); |
| 9518 | break; |
| 9519 | case 8: |
| 9520 | retval = bfd_get_signed_64 (abfd, buf); |
| 9521 | break; |
| 9522 | default: |
| 9523 | internal_error (__FILE__, __LINE__, |
| 9524 | _("read_address: bad switch, signed [in module %s]"), |
| 9525 | bfd_get_filename (abfd)); |
| 9526 | } |
| 9527 | } |
| 9528 | else |
| 9529 | { |
| 9530 | switch (cu_header->addr_size) |
| 9531 | { |
| 9532 | case 2: |
| 9533 | retval = bfd_get_16 (abfd, buf); |
| 9534 | break; |
| 9535 | case 4: |
| 9536 | retval = bfd_get_32 (abfd, buf); |
| 9537 | break; |
| 9538 | case 8: |
| 9539 | retval = bfd_get_64 (abfd, buf); |
| 9540 | break; |
| 9541 | default: |
| 9542 | internal_error (__FILE__, __LINE__, |
| 9543 | _("read_address: bad switch, unsigned [in module %s]"), |
| 9544 | bfd_get_filename (abfd)); |
| 9545 | } |
| 9546 | } |
| 9547 | |
| 9548 | *bytes_read = cu_header->addr_size; |
| 9549 | return retval; |
| 9550 | } |
| 9551 | |
| 9552 | /* Read the initial length from a section. The (draft) DWARF 3 |
| 9553 | specification allows the initial length to take up either 4 bytes |
| 9554 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 |
| 9555 | bytes describe the length and all offsets will be 8 bytes in length |
| 9556 | instead of 4. |
| 9557 | |
| 9558 | An older, non-standard 64-bit format is also handled by this |
| 9559 | function. The older format in question stores the initial length |
| 9560 | as an 8-byte quantity without an escape value. Lengths greater |
| 9561 | than 2^32 aren't very common which means that the initial 4 bytes |
| 9562 | is almost always zero. Since a length value of zero doesn't make |
| 9563 | sense for the 32-bit format, this initial zero can be considered to |
| 9564 | be an escape value which indicates the presence of the older 64-bit |
| 9565 | format. As written, the code can't detect (old format) lengths |
| 9566 | greater than 4GB. If it becomes necessary to handle lengths |
| 9567 | somewhat larger than 4GB, we could allow other small values (such |
| 9568 | as the non-sensical values of 1, 2, and 3) to also be used as |
| 9569 | escape values indicating the presence of the old format. |
| 9570 | |
| 9571 | The value returned via bytes_read should be used to increment the |
| 9572 | relevant pointer after calling read_initial_length(). |
| 9573 | |
| 9574 | [ Note: read_initial_length() and read_offset() are based on the |
| 9575 | document entitled "DWARF Debugging Information Format", revision |
| 9576 | 3, draft 8, dated November 19, 2001. This document was obtained |
| 9577 | from: |
| 9578 | |
| 9579 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
| 9580 | |
| 9581 | This document is only a draft and is subject to change. (So beware.) |
| 9582 | |
| 9583 | Details regarding the older, non-standard 64-bit format were |
| 9584 | determined empirically by examining 64-bit ELF files produced by |
| 9585 | the SGI toolchain on an IRIX 6.5 machine. |
| 9586 | |
| 9587 | - Kevin, July 16, 2002 |
| 9588 | ] */ |
| 9589 | |
| 9590 | static LONGEST |
| 9591 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
| 9592 | { |
| 9593 | LONGEST length = bfd_get_32 (abfd, buf); |
| 9594 | |
| 9595 | if (length == 0xffffffff) |
| 9596 | { |
| 9597 | length = bfd_get_64 (abfd, buf + 4); |
| 9598 | *bytes_read = 12; |
| 9599 | } |
| 9600 | else if (length == 0) |
| 9601 | { |
| 9602 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
| 9603 | length = bfd_get_64 (abfd, buf); |
| 9604 | *bytes_read = 8; |
| 9605 | } |
| 9606 | else |
| 9607 | { |
| 9608 | *bytes_read = 4; |
| 9609 | } |
| 9610 | |
| 9611 | return length; |
| 9612 | } |
| 9613 | |
| 9614 | /* Cover function for read_initial_length. |
| 9615 | Returns the length of the object at BUF, and stores the size of the |
| 9616 | initial length in *BYTES_READ and stores the size that offsets will be in |
| 9617 | *OFFSET_SIZE. |
| 9618 | If the initial length size is not equivalent to that specified in |
| 9619 | CU_HEADER then issue a complaint. |
| 9620 | This is useful when reading non-comp-unit headers. */ |
| 9621 | |
| 9622 | static LONGEST |
| 9623 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, |
| 9624 | const struct comp_unit_head *cu_header, |
| 9625 | unsigned int *bytes_read, |
| 9626 | unsigned int *offset_size) |
| 9627 | { |
| 9628 | LONGEST length = read_initial_length (abfd, buf, bytes_read); |
| 9629 | |
| 9630 | gdb_assert (cu_header->initial_length_size == 4 |
| 9631 | || cu_header->initial_length_size == 8 |
| 9632 | || cu_header->initial_length_size == 12); |
| 9633 | |
| 9634 | if (cu_header->initial_length_size != *bytes_read) |
| 9635 | complaint (&symfile_complaints, |
| 9636 | _("intermixed 32-bit and 64-bit DWARF sections")); |
| 9637 | |
| 9638 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
| 9639 | return length; |
| 9640 | } |
| 9641 | |
| 9642 | /* Read an offset from the data stream. The size of the offset is |
| 9643 | given by cu_header->offset_size. */ |
| 9644 | |
| 9645 | static LONGEST |
| 9646 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
| 9647 | unsigned int *bytes_read) |
| 9648 | { |
| 9649 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); |
| 9650 | |
| 9651 | *bytes_read = cu_header->offset_size; |
| 9652 | return offset; |
| 9653 | } |
| 9654 | |
| 9655 | /* Read an offset from the data stream. */ |
| 9656 | |
| 9657 | static LONGEST |
| 9658 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) |
| 9659 | { |
| 9660 | LONGEST retval = 0; |
| 9661 | |
| 9662 | switch (offset_size) |
| 9663 | { |
| 9664 | case 4: |
| 9665 | retval = bfd_get_32 (abfd, buf); |
| 9666 | break; |
| 9667 | case 8: |
| 9668 | retval = bfd_get_64 (abfd, buf); |
| 9669 | break; |
| 9670 | default: |
| 9671 | internal_error (__FILE__, __LINE__, |
| 9672 | _("read_offset_1: bad switch [in module %s]"), |
| 9673 | bfd_get_filename (abfd)); |
| 9674 | } |
| 9675 | |
| 9676 | return retval; |
| 9677 | } |
| 9678 | |
| 9679 | static gdb_byte * |
| 9680 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) |
| 9681 | { |
| 9682 | /* If the size of a host char is 8 bits, we can return a pointer |
| 9683 | to the buffer, otherwise we have to copy the data to a buffer |
| 9684 | allocated on the temporary obstack. */ |
| 9685 | gdb_assert (HOST_CHAR_BIT == 8); |
| 9686 | return buf; |
| 9687 | } |
| 9688 | |
| 9689 | static char * |
| 9690 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 9691 | { |
| 9692 | /* If the size of a host char is 8 bits, we can return a pointer |
| 9693 | to the string, otherwise we have to copy the string to a buffer |
| 9694 | allocated on the temporary obstack. */ |
| 9695 | gdb_assert (HOST_CHAR_BIT == 8); |
| 9696 | if (*buf == '\0') |
| 9697 | { |
| 9698 | *bytes_read_ptr = 1; |
| 9699 | return NULL; |
| 9700 | } |
| 9701 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
| 9702 | return (char *) buf; |
| 9703 | } |
| 9704 | |
| 9705 | static char * |
| 9706 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
| 9707 | const struct comp_unit_head *cu_header, |
| 9708 | unsigned int *bytes_read_ptr) |
| 9709 | { |
| 9710 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
| 9711 | |
| 9712 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
| 9713 | if (dwarf2_per_objfile->str.buffer == NULL) |
| 9714 | { |
| 9715 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
| 9716 | bfd_get_filename (abfd)); |
| 9717 | return NULL; |
| 9718 | } |
| 9719 | if (str_offset >= dwarf2_per_objfile->str.size) |
| 9720 | { |
| 9721 | error (_("DW_FORM_strp pointing outside of " |
| 9722 | ".debug_str section [in module %s]"), |
| 9723 | bfd_get_filename (abfd)); |
| 9724 | return NULL; |
| 9725 | } |
| 9726 | gdb_assert (HOST_CHAR_BIT == 8); |
| 9727 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
| 9728 | return NULL; |
| 9729 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
| 9730 | } |
| 9731 | |
| 9732 | static unsigned long |
| 9733 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 9734 | { |
| 9735 | unsigned long result; |
| 9736 | unsigned int num_read; |
| 9737 | int i, shift; |
| 9738 | unsigned char byte; |
| 9739 | |
| 9740 | result = 0; |
| 9741 | shift = 0; |
| 9742 | num_read = 0; |
| 9743 | i = 0; |
| 9744 | while (1) |
| 9745 | { |
| 9746 | byte = bfd_get_8 (abfd, buf); |
| 9747 | buf++; |
| 9748 | num_read++; |
| 9749 | result |= ((unsigned long)(byte & 127) << shift); |
| 9750 | if ((byte & 128) == 0) |
| 9751 | { |
| 9752 | break; |
| 9753 | } |
| 9754 | shift += 7; |
| 9755 | } |
| 9756 | *bytes_read_ptr = num_read; |
| 9757 | return result; |
| 9758 | } |
| 9759 | |
| 9760 | static long |
| 9761 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 9762 | { |
| 9763 | long result; |
| 9764 | int i, shift, num_read; |
| 9765 | unsigned char byte; |
| 9766 | |
| 9767 | result = 0; |
| 9768 | shift = 0; |
| 9769 | num_read = 0; |
| 9770 | i = 0; |
| 9771 | while (1) |
| 9772 | { |
| 9773 | byte = bfd_get_8 (abfd, buf); |
| 9774 | buf++; |
| 9775 | num_read++; |
| 9776 | result |= ((long)(byte & 127) << shift); |
| 9777 | shift += 7; |
| 9778 | if ((byte & 128) == 0) |
| 9779 | { |
| 9780 | break; |
| 9781 | } |
| 9782 | } |
| 9783 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
| 9784 | result |= -(((long)1) << shift); |
| 9785 | *bytes_read_ptr = num_read; |
| 9786 | return result; |
| 9787 | } |
| 9788 | |
| 9789 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
| 9790 | |
| 9791 | static gdb_byte * |
| 9792 | skip_leb128 (bfd *abfd, gdb_byte *buf) |
| 9793 | { |
| 9794 | int byte; |
| 9795 | |
| 9796 | while (1) |
| 9797 | { |
| 9798 | byte = bfd_get_8 (abfd, buf); |
| 9799 | buf++; |
| 9800 | if ((byte & 128) == 0) |
| 9801 | return buf; |
| 9802 | } |
| 9803 | } |
| 9804 | |
| 9805 | static void |
| 9806 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
| 9807 | { |
| 9808 | switch (lang) |
| 9809 | { |
| 9810 | case DW_LANG_C89: |
| 9811 | case DW_LANG_C99: |
| 9812 | case DW_LANG_C: |
| 9813 | cu->language = language_c; |
| 9814 | break; |
| 9815 | case DW_LANG_C_plus_plus: |
| 9816 | cu->language = language_cplus; |
| 9817 | break; |
| 9818 | case DW_LANG_D: |
| 9819 | cu->language = language_d; |
| 9820 | break; |
| 9821 | case DW_LANG_Fortran77: |
| 9822 | case DW_LANG_Fortran90: |
| 9823 | case DW_LANG_Fortran95: |
| 9824 | cu->language = language_fortran; |
| 9825 | break; |
| 9826 | case DW_LANG_Mips_Assembler: |
| 9827 | cu->language = language_asm; |
| 9828 | break; |
| 9829 | case DW_LANG_Java: |
| 9830 | cu->language = language_java; |
| 9831 | break; |
| 9832 | case DW_LANG_Ada83: |
| 9833 | case DW_LANG_Ada95: |
| 9834 | cu->language = language_ada; |
| 9835 | break; |
| 9836 | case DW_LANG_Modula2: |
| 9837 | cu->language = language_m2; |
| 9838 | break; |
| 9839 | case DW_LANG_Pascal83: |
| 9840 | cu->language = language_pascal; |
| 9841 | break; |
| 9842 | case DW_LANG_ObjC: |
| 9843 | cu->language = language_objc; |
| 9844 | break; |
| 9845 | case DW_LANG_Cobol74: |
| 9846 | case DW_LANG_Cobol85: |
| 9847 | default: |
| 9848 | cu->language = language_minimal; |
| 9849 | break; |
| 9850 | } |
| 9851 | cu->language_defn = language_def (cu->language); |
| 9852 | } |
| 9853 | |
| 9854 | /* Return the named attribute or NULL if not there. */ |
| 9855 | |
| 9856 | static struct attribute * |
| 9857 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
| 9858 | { |
| 9859 | unsigned int i; |
| 9860 | struct attribute *spec = NULL; |
| 9861 | |
| 9862 | for (i = 0; i < die->num_attrs; ++i) |
| 9863 | { |
| 9864 | if (die->attrs[i].name == name) |
| 9865 | return &die->attrs[i]; |
| 9866 | if (die->attrs[i].name == DW_AT_specification |
| 9867 | || die->attrs[i].name == DW_AT_abstract_origin) |
| 9868 | spec = &die->attrs[i]; |
| 9869 | } |
| 9870 | |
| 9871 | if (spec) |
| 9872 | { |
| 9873 | die = follow_die_ref (die, spec, &cu); |
| 9874 | return dwarf2_attr (die, name, cu); |
| 9875 | } |
| 9876 | |
| 9877 | return NULL; |
| 9878 | } |
| 9879 | |
| 9880 | /* Return the named attribute or NULL if not there, |
| 9881 | but do not follow DW_AT_specification, etc. |
| 9882 | This is for use in contexts where we're reading .debug_types dies. |
| 9883 | Following DW_AT_specification, DW_AT_abstract_origin will take us |
| 9884 | back up the chain, and we want to go down. */ |
| 9885 | |
| 9886 | static struct attribute * |
| 9887 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, |
| 9888 | struct dwarf2_cu *cu) |
| 9889 | { |
| 9890 | unsigned int i; |
| 9891 | |
| 9892 | for (i = 0; i < die->num_attrs; ++i) |
| 9893 | if (die->attrs[i].name == name) |
| 9894 | return &die->attrs[i]; |
| 9895 | |
| 9896 | return NULL; |
| 9897 | } |
| 9898 | |
| 9899 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
| 9900 | and holds a non-zero value. This function should only be used for |
| 9901 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
| 9902 | |
| 9903 | static int |
| 9904 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) |
| 9905 | { |
| 9906 | struct attribute *attr = dwarf2_attr (die, name, cu); |
| 9907 | |
| 9908 | return (attr && DW_UNSND (attr)); |
| 9909 | } |
| 9910 | |
| 9911 | static int |
| 9912 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
| 9913 | { |
| 9914 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
| 9915 | which value is non-zero. However, we have to be careful with |
| 9916 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() |
| 9917 | (via dwarf2_flag_true_p) follows this attribute. So we may |
| 9918 | end up accidently finding a declaration attribute that belongs |
| 9919 | to a different DIE referenced by the specification attribute, |
| 9920 | even though the given DIE does not have a declaration attribute. */ |
| 9921 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) |
| 9922 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); |
| 9923 | } |
| 9924 | |
| 9925 | /* Return the die giving the specification for DIE, if there is |
| 9926 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
| 9927 | containing the return value on output. If there is no |
| 9928 | specification, but there is an abstract origin, that is |
| 9929 | returned. */ |
| 9930 | |
| 9931 | static struct die_info * |
| 9932 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
| 9933 | { |
| 9934 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
| 9935 | *spec_cu); |
| 9936 | |
| 9937 | if (spec_attr == NULL) |
| 9938 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); |
| 9939 | |
| 9940 | if (spec_attr == NULL) |
| 9941 | return NULL; |
| 9942 | else |
| 9943 | return follow_die_ref (die, spec_attr, spec_cu); |
| 9944 | } |
| 9945 | |
| 9946 | /* Free the line_header structure *LH, and any arrays and strings it |
| 9947 | refers to. |
| 9948 | NOTE: This is also used as a "cleanup" function. */ |
| 9949 | |
| 9950 | static void |
| 9951 | free_line_header (struct line_header *lh) |
| 9952 | { |
| 9953 | if (lh->standard_opcode_lengths) |
| 9954 | xfree (lh->standard_opcode_lengths); |
| 9955 | |
| 9956 | /* Remember that all the lh->file_names[i].name pointers are |
| 9957 | pointers into debug_line_buffer, and don't need to be freed. */ |
| 9958 | if (lh->file_names) |
| 9959 | xfree (lh->file_names); |
| 9960 | |
| 9961 | /* Similarly for the include directory names. */ |
| 9962 | if (lh->include_dirs) |
| 9963 | xfree (lh->include_dirs); |
| 9964 | |
| 9965 | xfree (lh); |
| 9966 | } |
| 9967 | |
| 9968 | /* Add an entry to LH's include directory table. */ |
| 9969 | |
| 9970 | static void |
| 9971 | add_include_dir (struct line_header *lh, char *include_dir) |
| 9972 | { |
| 9973 | /* Grow the array if necessary. */ |
| 9974 | if (lh->include_dirs_size == 0) |
| 9975 | { |
| 9976 | lh->include_dirs_size = 1; /* for testing */ |
| 9977 | lh->include_dirs = xmalloc (lh->include_dirs_size |
| 9978 | * sizeof (*lh->include_dirs)); |
| 9979 | } |
| 9980 | else if (lh->num_include_dirs >= lh->include_dirs_size) |
| 9981 | { |
| 9982 | lh->include_dirs_size *= 2; |
| 9983 | lh->include_dirs = xrealloc (lh->include_dirs, |
| 9984 | (lh->include_dirs_size |
| 9985 | * sizeof (*lh->include_dirs))); |
| 9986 | } |
| 9987 | |
| 9988 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
| 9989 | } |
| 9990 | |
| 9991 | /* Add an entry to LH's file name table. */ |
| 9992 | |
| 9993 | static void |
| 9994 | add_file_name (struct line_header *lh, |
| 9995 | char *name, |
| 9996 | unsigned int dir_index, |
| 9997 | unsigned int mod_time, |
| 9998 | unsigned int length) |
| 9999 | { |
| 10000 | struct file_entry *fe; |
| 10001 | |
| 10002 | /* Grow the array if necessary. */ |
| 10003 | if (lh->file_names_size == 0) |
| 10004 | { |
| 10005 | lh->file_names_size = 1; /* for testing */ |
| 10006 | lh->file_names = xmalloc (lh->file_names_size |
| 10007 | * sizeof (*lh->file_names)); |
| 10008 | } |
| 10009 | else if (lh->num_file_names >= lh->file_names_size) |
| 10010 | { |
| 10011 | lh->file_names_size *= 2; |
| 10012 | lh->file_names = xrealloc (lh->file_names, |
| 10013 | (lh->file_names_size |
| 10014 | * sizeof (*lh->file_names))); |
| 10015 | } |
| 10016 | |
| 10017 | fe = &lh->file_names[lh->num_file_names++]; |
| 10018 | fe->name = name; |
| 10019 | fe->dir_index = dir_index; |
| 10020 | fe->mod_time = mod_time; |
| 10021 | fe->length = length; |
| 10022 | fe->included_p = 0; |
| 10023 | fe->symtab = NULL; |
| 10024 | } |
| 10025 | |
| 10026 | /* Read the statement program header starting at OFFSET in |
| 10027 | .debug_line, according to the endianness of ABFD. Return a pointer |
| 10028 | to a struct line_header, allocated using xmalloc. |
| 10029 | |
| 10030 | NOTE: the strings in the include directory and file name tables of |
| 10031 | the returned object point into debug_line_buffer, and must not be |
| 10032 | freed. */ |
| 10033 | |
| 10034 | static struct line_header * |
| 10035 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, |
| 10036 | struct dwarf2_cu *cu) |
| 10037 | { |
| 10038 | struct cleanup *back_to; |
| 10039 | struct line_header *lh; |
| 10040 | gdb_byte *line_ptr; |
| 10041 | unsigned int bytes_read, offset_size; |
| 10042 | int i; |
| 10043 | char *cur_dir, *cur_file; |
| 10044 | |
| 10045 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
| 10046 | if (dwarf2_per_objfile->line.buffer == NULL) |
| 10047 | { |
| 10048 | complaint (&symfile_complaints, _("missing .debug_line section")); |
| 10049 | return 0; |
| 10050 | } |
| 10051 | |
| 10052 | /* Make sure that at least there's room for the total_length field. |
| 10053 | That could be 12 bytes long, but we're just going to fudge that. */ |
| 10054 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
| 10055 | { |
| 10056 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 10057 | return 0; |
| 10058 | } |
| 10059 | |
| 10060 | lh = xmalloc (sizeof (*lh)); |
| 10061 | memset (lh, 0, sizeof (*lh)); |
| 10062 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, |
| 10063 | (void *) lh); |
| 10064 | |
| 10065 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
| 10066 | |
| 10067 | /* Read in the header. */ |
| 10068 | lh->total_length = |
| 10069 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
| 10070 | &bytes_read, &offset_size); |
| 10071 | line_ptr += bytes_read; |
| 10072 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
| 10073 | + dwarf2_per_objfile->line.size)) |
| 10074 | { |
| 10075 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 10076 | return 0; |
| 10077 | } |
| 10078 | lh->statement_program_end = line_ptr + lh->total_length; |
| 10079 | lh->version = read_2_bytes (abfd, line_ptr); |
| 10080 | line_ptr += 2; |
| 10081 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
| 10082 | line_ptr += offset_size; |
| 10083 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
| 10084 | line_ptr += 1; |
| 10085 | if (lh->version >= 4) |
| 10086 | { |
| 10087 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); |
| 10088 | line_ptr += 1; |
| 10089 | } |
| 10090 | else |
| 10091 | lh->maximum_ops_per_instruction = 1; |
| 10092 | |
| 10093 | if (lh->maximum_ops_per_instruction == 0) |
| 10094 | { |
| 10095 | lh->maximum_ops_per_instruction = 1; |
| 10096 | complaint (&symfile_complaints, |
| 10097 | _("invalid maximum_ops_per_instruction " |
| 10098 | "in `.debug_line' section")); |
| 10099 | } |
| 10100 | |
| 10101 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
| 10102 | line_ptr += 1; |
| 10103 | lh->line_base = read_1_signed_byte (abfd, line_ptr); |
| 10104 | line_ptr += 1; |
| 10105 | lh->line_range = read_1_byte (abfd, line_ptr); |
| 10106 | line_ptr += 1; |
| 10107 | lh->opcode_base = read_1_byte (abfd, line_ptr); |
| 10108 | line_ptr += 1; |
| 10109 | lh->standard_opcode_lengths |
| 10110 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
| 10111 | |
| 10112 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ |
| 10113 | for (i = 1; i < lh->opcode_base; ++i) |
| 10114 | { |
| 10115 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); |
| 10116 | line_ptr += 1; |
| 10117 | } |
| 10118 | |
| 10119 | /* Read directory table. */ |
| 10120 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 10121 | { |
| 10122 | line_ptr += bytes_read; |
| 10123 | add_include_dir (lh, cur_dir); |
| 10124 | } |
| 10125 | line_ptr += bytes_read; |
| 10126 | |
| 10127 | /* Read file name table. */ |
| 10128 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 10129 | { |
| 10130 | unsigned int dir_index, mod_time, length; |
| 10131 | |
| 10132 | line_ptr += bytes_read; |
| 10133 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10134 | line_ptr += bytes_read; |
| 10135 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10136 | line_ptr += bytes_read; |
| 10137 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10138 | line_ptr += bytes_read; |
| 10139 | |
| 10140 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 10141 | } |
| 10142 | line_ptr += bytes_read; |
| 10143 | lh->statement_program_start = line_ptr; |
| 10144 | |
| 10145 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
| 10146 | + dwarf2_per_objfile->line.size)) |
| 10147 | complaint (&symfile_complaints, |
| 10148 | _("line number info header doesn't " |
| 10149 | "fit in `.debug_line' section")); |
| 10150 | |
| 10151 | discard_cleanups (back_to); |
| 10152 | return lh; |
| 10153 | } |
| 10154 | |
| 10155 | /* This function exists to work around a bug in certain compilers |
| 10156 | (particularly GCC 2.95), in which the first line number marker of a |
| 10157 | function does not show up until after the prologue, right before |
| 10158 | the second line number marker. This function shifts ADDRESS down |
| 10159 | to the beginning of the function if necessary, and is called on |
| 10160 | addresses passed to record_line. */ |
| 10161 | |
| 10162 | static CORE_ADDR |
| 10163 | check_cu_functions (CORE_ADDR address, struct dwarf2_cu *cu) |
| 10164 | { |
| 10165 | struct function_range *fn; |
| 10166 | |
| 10167 | /* Find the function_range containing address. */ |
| 10168 | if (!cu->first_fn) |
| 10169 | return address; |
| 10170 | |
| 10171 | if (!cu->cached_fn) |
| 10172 | cu->cached_fn = cu->first_fn; |
| 10173 | |
| 10174 | fn = cu->cached_fn; |
| 10175 | while (fn) |
| 10176 | if (fn->lowpc <= address && fn->highpc > address) |
| 10177 | goto found; |
| 10178 | else |
| 10179 | fn = fn->next; |
| 10180 | |
| 10181 | fn = cu->first_fn; |
| 10182 | while (fn && fn != cu->cached_fn) |
| 10183 | if (fn->lowpc <= address && fn->highpc > address) |
| 10184 | goto found; |
| 10185 | else |
| 10186 | fn = fn->next; |
| 10187 | |
| 10188 | return address; |
| 10189 | |
| 10190 | found: |
| 10191 | if (fn->seen_line) |
| 10192 | return address; |
| 10193 | if (address != fn->lowpc) |
| 10194 | complaint (&symfile_complaints, |
| 10195 | _("misplaced first line number at 0x%lx for '%s'"), |
| 10196 | (unsigned long) address, fn->name); |
| 10197 | fn->seen_line = 1; |
| 10198 | return fn->lowpc; |
| 10199 | } |
| 10200 | |
| 10201 | /* Subroutine of dwarf_decode_lines to simplify it. |
| 10202 | Return the file name of the psymtab for included file FILE_INDEX |
| 10203 | in line header LH of PST. |
| 10204 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. |
| 10205 | If space for the result is malloc'd, it will be freed by a cleanup. |
| 10206 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ |
| 10207 | |
| 10208 | static char * |
| 10209 | psymtab_include_file_name (const struct line_header *lh, int file_index, |
| 10210 | const struct partial_symtab *pst, |
| 10211 | const char *comp_dir) |
| 10212 | { |
| 10213 | const struct file_entry fe = lh->file_names [file_index]; |
| 10214 | char *include_name = fe.name; |
| 10215 | char *include_name_to_compare = include_name; |
| 10216 | char *dir_name = NULL; |
| 10217 | const char *pst_filename; |
| 10218 | char *copied_name = NULL; |
| 10219 | int file_is_pst; |
| 10220 | |
| 10221 | if (fe.dir_index) |
| 10222 | dir_name = lh->include_dirs[fe.dir_index - 1]; |
| 10223 | |
| 10224 | if (!IS_ABSOLUTE_PATH (include_name) |
| 10225 | && (dir_name != NULL || comp_dir != NULL)) |
| 10226 | { |
| 10227 | /* Avoid creating a duplicate psymtab for PST. |
| 10228 | We do this by comparing INCLUDE_NAME and PST_FILENAME. |
| 10229 | Before we do the comparison, however, we need to account |
| 10230 | for DIR_NAME and COMP_DIR. |
| 10231 | First prepend dir_name (if non-NULL). If we still don't |
| 10232 | have an absolute path prepend comp_dir (if non-NULL). |
| 10233 | However, the directory we record in the include-file's |
| 10234 | psymtab does not contain COMP_DIR (to match the |
| 10235 | corresponding symtab(s)). |
| 10236 | |
| 10237 | Example: |
| 10238 | |
| 10239 | bash$ cd /tmp |
| 10240 | bash$ gcc -g ./hello.c |
| 10241 | include_name = "hello.c" |
| 10242 | dir_name = "." |
| 10243 | DW_AT_comp_dir = comp_dir = "/tmp" |
| 10244 | DW_AT_name = "./hello.c" */ |
| 10245 | |
| 10246 | if (dir_name != NULL) |
| 10247 | { |
| 10248 | include_name = concat (dir_name, SLASH_STRING, |
| 10249 | include_name, (char *)NULL); |
| 10250 | include_name_to_compare = include_name; |
| 10251 | make_cleanup (xfree, include_name); |
| 10252 | } |
| 10253 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) |
| 10254 | { |
| 10255 | include_name_to_compare = concat (comp_dir, SLASH_STRING, |
| 10256 | include_name, (char *)NULL); |
| 10257 | } |
| 10258 | } |
| 10259 | |
| 10260 | pst_filename = pst->filename; |
| 10261 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) |
| 10262 | { |
| 10263 | copied_name = concat (pst->dirname, SLASH_STRING, |
| 10264 | pst_filename, (char *)NULL); |
| 10265 | pst_filename = copied_name; |
| 10266 | } |
| 10267 | |
| 10268 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
| 10269 | |
| 10270 | if (include_name_to_compare != include_name) |
| 10271 | xfree (include_name_to_compare); |
| 10272 | if (copied_name != NULL) |
| 10273 | xfree (copied_name); |
| 10274 | |
| 10275 | if (file_is_pst) |
| 10276 | return NULL; |
| 10277 | return include_name; |
| 10278 | } |
| 10279 | |
| 10280 | /* Decode the Line Number Program (LNP) for the given line_header |
| 10281 | structure and CU. The actual information extracted and the type |
| 10282 | of structures created from the LNP depends on the value of PST. |
| 10283 | |
| 10284 | 1. If PST is NULL, then this procedure uses the data from the program |
| 10285 | to create all necessary symbol tables, and their linetables. |
| 10286 | |
| 10287 | 2. If PST is not NULL, this procedure reads the program to determine |
| 10288 | the list of files included by the unit represented by PST, and |
| 10289 | builds all the associated partial symbol tables. |
| 10290 | |
| 10291 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. |
| 10292 | It is used for relative paths in the line table. |
| 10293 | NOTE: When processing partial symtabs (pst != NULL), |
| 10294 | comp_dir == pst->dirname. |
| 10295 | |
| 10296 | NOTE: It is important that psymtabs have the same file name (via strcmp) |
| 10297 | as the corresponding symtab. Since COMP_DIR is not used in the name of the |
| 10298 | symtab we don't use it in the name of the psymtabs we create. |
| 10299 | E.g. expand_line_sal requires this when finding psymtabs to expand. |
| 10300 | A good testcase for this is mb-inline.exp. */ |
| 10301 | |
| 10302 | static void |
| 10303 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, bfd *abfd, |
| 10304 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
| 10305 | { |
| 10306 | gdb_byte *line_ptr, *extended_end; |
| 10307 | gdb_byte *line_end; |
| 10308 | unsigned int bytes_read, extended_len; |
| 10309 | unsigned char op_code, extended_op, adj_opcode; |
| 10310 | CORE_ADDR baseaddr; |
| 10311 | struct objfile *objfile = cu->objfile; |
| 10312 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 10313 | const int decode_for_pst_p = (pst != NULL); |
| 10314 | struct subfile *last_subfile = NULL, *first_subfile = current_subfile; |
| 10315 | |
| 10316 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 10317 | |
| 10318 | line_ptr = lh->statement_program_start; |
| 10319 | line_end = lh->statement_program_end; |
| 10320 | |
| 10321 | /* Read the statement sequences until there's nothing left. */ |
| 10322 | while (line_ptr < line_end) |
| 10323 | { |
| 10324 | /* state machine registers */ |
| 10325 | CORE_ADDR address = 0; |
| 10326 | unsigned int file = 1; |
| 10327 | unsigned int line = 1; |
| 10328 | unsigned int column = 0; |
| 10329 | int is_stmt = lh->default_is_stmt; |
| 10330 | int basic_block = 0; |
| 10331 | int end_sequence = 0; |
| 10332 | CORE_ADDR addr; |
| 10333 | unsigned char op_index = 0; |
| 10334 | |
| 10335 | if (!decode_for_pst_p && lh->num_file_names >= file) |
| 10336 | { |
| 10337 | /* Start a subfile for the current file of the state machine. */ |
| 10338 | /* lh->include_dirs and lh->file_names are 0-based, but the |
| 10339 | directory and file name numbers in the statement program |
| 10340 | are 1-based. */ |
| 10341 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 10342 | char *dir = NULL; |
| 10343 | |
| 10344 | if (fe->dir_index) |
| 10345 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 10346 | |
| 10347 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 10348 | } |
| 10349 | |
| 10350 | /* Decode the table. */ |
| 10351 | while (!end_sequence) |
| 10352 | { |
| 10353 | op_code = read_1_byte (abfd, line_ptr); |
| 10354 | line_ptr += 1; |
| 10355 | if (line_ptr > line_end) |
| 10356 | { |
| 10357 | dwarf2_debug_line_missing_end_sequence_complaint (); |
| 10358 | break; |
| 10359 | } |
| 10360 | |
| 10361 | if (op_code >= lh->opcode_base) |
| 10362 | { |
| 10363 | /* Special operand. */ |
| 10364 | adj_opcode = op_code - lh->opcode_base; |
| 10365 | address += (((op_index + (adj_opcode / lh->line_range)) |
| 10366 | / lh->maximum_ops_per_instruction) |
| 10367 | * lh->minimum_instruction_length); |
| 10368 | op_index = ((op_index + (adj_opcode / lh->line_range)) |
| 10369 | % lh->maximum_ops_per_instruction); |
| 10370 | line += lh->line_base + (adj_opcode % lh->line_range); |
| 10371 | if (lh->num_file_names < file || file == 0) |
| 10372 | dwarf2_debug_line_missing_file_complaint (); |
| 10373 | /* For now we ignore lines not starting on an |
| 10374 | instruction boundary. */ |
| 10375 | else if (op_index == 0) |
| 10376 | { |
| 10377 | lh->file_names[file - 1].included_p = 1; |
| 10378 | if (!decode_for_pst_p && is_stmt) |
| 10379 | { |
| 10380 | if (last_subfile != current_subfile) |
| 10381 | { |
| 10382 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 10383 | if (last_subfile) |
| 10384 | record_line (last_subfile, 0, addr); |
| 10385 | last_subfile = current_subfile; |
| 10386 | } |
| 10387 | /* Append row to matrix using current values. */ |
| 10388 | addr = check_cu_functions (address, cu); |
| 10389 | addr = gdbarch_addr_bits_remove (gdbarch, addr); |
| 10390 | record_line (current_subfile, line, addr); |
| 10391 | } |
| 10392 | } |
| 10393 | basic_block = 0; |
| 10394 | } |
| 10395 | else switch (op_code) |
| 10396 | { |
| 10397 | case DW_LNS_extended_op: |
| 10398 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
| 10399 | &bytes_read); |
| 10400 | line_ptr += bytes_read; |
| 10401 | extended_end = line_ptr + extended_len; |
| 10402 | extended_op = read_1_byte (abfd, line_ptr); |
| 10403 | line_ptr += 1; |
| 10404 | switch (extended_op) |
| 10405 | { |
| 10406 | case DW_LNE_end_sequence: |
| 10407 | end_sequence = 1; |
| 10408 | break; |
| 10409 | case DW_LNE_set_address: |
| 10410 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
| 10411 | op_index = 0; |
| 10412 | line_ptr += bytes_read; |
| 10413 | address += baseaddr; |
| 10414 | break; |
| 10415 | case DW_LNE_define_file: |
| 10416 | { |
| 10417 | char *cur_file; |
| 10418 | unsigned int dir_index, mod_time, length; |
| 10419 | |
| 10420 | cur_file = read_direct_string (abfd, line_ptr, |
| 10421 | &bytes_read); |
| 10422 | line_ptr += bytes_read; |
| 10423 | dir_index = |
| 10424 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10425 | line_ptr += bytes_read; |
| 10426 | mod_time = |
| 10427 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10428 | line_ptr += bytes_read; |
| 10429 | length = |
| 10430 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10431 | line_ptr += bytes_read; |
| 10432 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 10433 | } |
| 10434 | break; |
| 10435 | case DW_LNE_set_discriminator: |
| 10436 | /* The discriminator is not interesting to the debugger; |
| 10437 | just ignore it. */ |
| 10438 | line_ptr = extended_end; |
| 10439 | break; |
| 10440 | default: |
| 10441 | complaint (&symfile_complaints, |
| 10442 | _("mangled .debug_line section")); |
| 10443 | return; |
| 10444 | } |
| 10445 | /* Make sure that we parsed the extended op correctly. If e.g. |
| 10446 | we expected a different address size than the producer used, |
| 10447 | we may have read the wrong number of bytes. */ |
| 10448 | if (line_ptr != extended_end) |
| 10449 | { |
| 10450 | complaint (&symfile_complaints, |
| 10451 | _("mangled .debug_line section")); |
| 10452 | return; |
| 10453 | } |
| 10454 | break; |
| 10455 | case DW_LNS_copy: |
| 10456 | if (lh->num_file_names < file || file == 0) |
| 10457 | dwarf2_debug_line_missing_file_complaint (); |
| 10458 | else |
| 10459 | { |
| 10460 | lh->file_names[file - 1].included_p = 1; |
| 10461 | if (!decode_for_pst_p && is_stmt) |
| 10462 | { |
| 10463 | if (last_subfile != current_subfile) |
| 10464 | { |
| 10465 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 10466 | if (last_subfile) |
| 10467 | record_line (last_subfile, 0, addr); |
| 10468 | last_subfile = current_subfile; |
| 10469 | } |
| 10470 | addr = check_cu_functions (address, cu); |
| 10471 | addr = gdbarch_addr_bits_remove (gdbarch, addr); |
| 10472 | record_line (current_subfile, line, addr); |
| 10473 | } |
| 10474 | } |
| 10475 | basic_block = 0; |
| 10476 | break; |
| 10477 | case DW_LNS_advance_pc: |
| 10478 | { |
| 10479 | CORE_ADDR adjust |
| 10480 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10481 | |
| 10482 | address += (((op_index + adjust) |
| 10483 | / lh->maximum_ops_per_instruction) |
| 10484 | * lh->minimum_instruction_length); |
| 10485 | op_index = ((op_index + adjust) |
| 10486 | % lh->maximum_ops_per_instruction); |
| 10487 | line_ptr += bytes_read; |
| 10488 | } |
| 10489 | break; |
| 10490 | case DW_LNS_advance_line: |
| 10491 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); |
| 10492 | line_ptr += bytes_read; |
| 10493 | break; |
| 10494 | case DW_LNS_set_file: |
| 10495 | { |
| 10496 | /* The arrays lh->include_dirs and lh->file_names are |
| 10497 | 0-based, but the directory and file name numbers in |
| 10498 | the statement program are 1-based. */ |
| 10499 | struct file_entry *fe; |
| 10500 | char *dir = NULL; |
| 10501 | |
| 10502 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10503 | line_ptr += bytes_read; |
| 10504 | if (lh->num_file_names < file || file == 0) |
| 10505 | dwarf2_debug_line_missing_file_complaint (); |
| 10506 | else |
| 10507 | { |
| 10508 | fe = &lh->file_names[file - 1]; |
| 10509 | if (fe->dir_index) |
| 10510 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 10511 | if (!decode_for_pst_p) |
| 10512 | { |
| 10513 | last_subfile = current_subfile; |
| 10514 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 10515 | } |
| 10516 | } |
| 10517 | } |
| 10518 | break; |
| 10519 | case DW_LNS_set_column: |
| 10520 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10521 | line_ptr += bytes_read; |
| 10522 | break; |
| 10523 | case DW_LNS_negate_stmt: |
| 10524 | is_stmt = (!is_stmt); |
| 10525 | break; |
| 10526 | case DW_LNS_set_basic_block: |
| 10527 | basic_block = 1; |
| 10528 | break; |
| 10529 | /* Add to the address register of the state machine the |
| 10530 | address increment value corresponding to special opcode |
| 10531 | 255. I.e., this value is scaled by the minimum |
| 10532 | instruction length since special opcode 255 would have |
| 10533 | scaled the the increment. */ |
| 10534 | case DW_LNS_const_add_pc: |
| 10535 | { |
| 10536 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; |
| 10537 | |
| 10538 | address += (((op_index + adjust) |
| 10539 | / lh->maximum_ops_per_instruction) |
| 10540 | * lh->minimum_instruction_length); |
| 10541 | op_index = ((op_index + adjust) |
| 10542 | % lh->maximum_ops_per_instruction); |
| 10543 | } |
| 10544 | break; |
| 10545 | case DW_LNS_fixed_advance_pc: |
| 10546 | address += read_2_bytes (abfd, line_ptr); |
| 10547 | op_index = 0; |
| 10548 | line_ptr += 2; |
| 10549 | break; |
| 10550 | default: |
| 10551 | { |
| 10552 | /* Unknown standard opcode, ignore it. */ |
| 10553 | int i; |
| 10554 | |
| 10555 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
| 10556 | { |
| 10557 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 10558 | line_ptr += bytes_read; |
| 10559 | } |
| 10560 | } |
| 10561 | } |
| 10562 | } |
| 10563 | if (lh->num_file_names < file || file == 0) |
| 10564 | dwarf2_debug_line_missing_file_complaint (); |
| 10565 | else |
| 10566 | { |
| 10567 | lh->file_names[file - 1].included_p = 1; |
| 10568 | if (!decode_for_pst_p) |
| 10569 | { |
| 10570 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 10571 | record_line (current_subfile, 0, addr); |
| 10572 | } |
| 10573 | } |
| 10574 | } |
| 10575 | |
| 10576 | if (decode_for_pst_p) |
| 10577 | { |
| 10578 | int file_index; |
| 10579 | |
| 10580 | /* Now that we're done scanning the Line Header Program, we can |
| 10581 | create the psymtab of each included file. */ |
| 10582 | for (file_index = 0; file_index < lh->num_file_names; file_index++) |
| 10583 | if (lh->file_names[file_index].included_p == 1) |
| 10584 | { |
| 10585 | char *include_name = |
| 10586 | psymtab_include_file_name (lh, file_index, pst, comp_dir); |
| 10587 | if (include_name != NULL) |
| 10588 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
| 10589 | } |
| 10590 | } |
| 10591 | else |
| 10592 | { |
| 10593 | /* Make sure a symtab is created for every file, even files |
| 10594 | which contain only variables (i.e. no code with associated |
| 10595 | line numbers). */ |
| 10596 | |
| 10597 | int i; |
| 10598 | struct file_entry *fe; |
| 10599 | |
| 10600 | for (i = 0; i < lh->num_file_names; i++) |
| 10601 | { |
| 10602 | char *dir = NULL; |
| 10603 | |
| 10604 | fe = &lh->file_names[i]; |
| 10605 | if (fe->dir_index) |
| 10606 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 10607 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 10608 | |
| 10609 | /* Skip the main file; we don't need it, and it must be |
| 10610 | allocated last, so that it will show up before the |
| 10611 | non-primary symtabs in the objfile's symtab list. */ |
| 10612 | if (current_subfile == first_subfile) |
| 10613 | continue; |
| 10614 | |
| 10615 | if (current_subfile->symtab == NULL) |
| 10616 | current_subfile->symtab = allocate_symtab (current_subfile->name, |
| 10617 | cu->objfile); |
| 10618 | fe->symtab = current_subfile->symtab; |
| 10619 | } |
| 10620 | } |
| 10621 | } |
| 10622 | |
| 10623 | /* Start a subfile for DWARF. FILENAME is the name of the file and |
| 10624 | DIRNAME the name of the source directory which contains FILENAME |
| 10625 | or NULL if not known. COMP_DIR is the compilation directory for the |
| 10626 | linetable's compilation unit or NULL if not known. |
| 10627 | This routine tries to keep line numbers from identical absolute and |
| 10628 | relative file names in a common subfile. |
| 10629 | |
| 10630 | Using the `list' example from the GDB testsuite, which resides in |
| 10631 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename |
| 10632 | of /srcdir/list0.c yields the following debugging information for list0.c: |
| 10633 | |
| 10634 | DW_AT_name: /srcdir/list0.c |
| 10635 | DW_AT_comp_dir: /compdir |
| 10636 | files.files[0].name: list0.h |
| 10637 | files.files[0].dir: /srcdir |
| 10638 | files.files[1].name: list0.c |
| 10639 | files.files[1].dir: /srcdir |
| 10640 | |
| 10641 | The line number information for list0.c has to end up in a single |
| 10642 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
| 10643 | start_subfile will ensure that this happens provided that we pass the |
| 10644 | concatenation of files.files[1].dir and files.files[1].name as the |
| 10645 | subfile's name. */ |
| 10646 | |
| 10647 | static void |
| 10648 | dwarf2_start_subfile (char *filename, const char *dirname, |
| 10649 | const char *comp_dir) |
| 10650 | { |
| 10651 | char *fullname; |
| 10652 | |
| 10653 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). |
| 10654 | `start_symtab' will always pass the contents of DW_AT_comp_dir as |
| 10655 | second argument to start_subfile. To be consistent, we do the |
| 10656 | same here. In order not to lose the line information directory, |
| 10657 | we concatenate it to the filename when it makes sense. |
| 10658 | Note that the Dwarf3 standard says (speaking of filenames in line |
| 10659 | information): ``The directory index is ignored for file names |
| 10660 | that represent full path names''. Thus ignoring dirname in the |
| 10661 | `else' branch below isn't an issue. */ |
| 10662 | |
| 10663 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
| 10664 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
| 10665 | else |
| 10666 | fullname = filename; |
| 10667 | |
| 10668 | start_subfile (fullname, comp_dir); |
| 10669 | |
| 10670 | if (fullname != filename) |
| 10671 | xfree (fullname); |
| 10672 | } |
| 10673 | |
| 10674 | static void |
| 10675 | var_decode_location (struct attribute *attr, struct symbol *sym, |
| 10676 | struct dwarf2_cu *cu) |
| 10677 | { |
| 10678 | struct objfile *objfile = cu->objfile; |
| 10679 | struct comp_unit_head *cu_header = &cu->header; |
| 10680 | |
| 10681 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
| 10682 | code here to turn a symbol with DW_AT_external and a |
| 10683 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was |
| 10684 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux |
| 10685 | with some versions of binutils) where shared libraries could have |
| 10686 | relocations against symbols in their debug information - the |
| 10687 | minimal symbol would have the right address, but the debug info |
| 10688 | would not. It's no longer necessary, because we will explicitly |
| 10689 | apply relocations when we read in the debug information now. */ |
| 10690 | |
| 10691 | /* A DW_AT_location attribute with no contents indicates that a |
| 10692 | variable has been optimized away. */ |
| 10693 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) |
| 10694 | { |
| 10695 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 10696 | return; |
| 10697 | } |
| 10698 | |
| 10699 | /* Handle one degenerate form of location expression specially, to |
| 10700 | preserve GDB's previous behavior when section offsets are |
| 10701 | specified. If this is just a DW_OP_addr then mark this symbol |
| 10702 | as LOC_STATIC. */ |
| 10703 | |
| 10704 | if (attr_form_is_block (attr) |
| 10705 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size |
| 10706 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) |
| 10707 | { |
| 10708 | unsigned int dummy; |
| 10709 | |
| 10710 | SYMBOL_VALUE_ADDRESS (sym) = |
| 10711 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
| 10712 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 10713 | fixup_symbol_section (sym, objfile); |
| 10714 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, |
| 10715 | SYMBOL_SECTION (sym)); |
| 10716 | return; |
| 10717 | } |
| 10718 | |
| 10719 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static |
| 10720 | expression evaluator, and use LOC_COMPUTED only when necessary |
| 10721 | (i.e. when the value of a register or memory location is |
| 10722 | referenced, or a thread-local block, etc.). Then again, it might |
| 10723 | not be worthwhile. I'm assuming that it isn't unless performance |
| 10724 | or memory numbers show me otherwise. */ |
| 10725 | |
| 10726 | dwarf2_symbol_mark_computed (attr, sym, cu); |
| 10727 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 10728 | } |
| 10729 | |
| 10730 | /* Given a pointer to a DWARF information entry, figure out if we need |
| 10731 | to make a symbol table entry for it, and if so, create a new entry |
| 10732 | and return a pointer to it. |
| 10733 | If TYPE is NULL, determine symbol type from the die, otherwise |
| 10734 | used the passed type. |
| 10735 | If SPACE is not NULL, use it to hold the new symbol. If it is |
| 10736 | NULL, allocate a new symbol on the objfile's obstack. */ |
| 10737 | |
| 10738 | static struct symbol * |
| 10739 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
| 10740 | struct symbol *space) |
| 10741 | { |
| 10742 | struct objfile *objfile = cu->objfile; |
| 10743 | struct symbol *sym = NULL; |
| 10744 | char *name; |
| 10745 | struct attribute *attr = NULL; |
| 10746 | struct attribute *attr2 = NULL; |
| 10747 | CORE_ADDR baseaddr; |
| 10748 | struct pending **list_to_add = NULL; |
| 10749 | |
| 10750 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
| 10751 | |
| 10752 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 10753 | |
| 10754 | name = dwarf2_name (die, cu); |
| 10755 | if (name) |
| 10756 | { |
| 10757 | const char *linkagename; |
| 10758 | int suppress_add = 0; |
| 10759 | |
| 10760 | if (space) |
| 10761 | sym = space; |
| 10762 | else |
| 10763 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); |
| 10764 | OBJSTAT (objfile, n_syms++); |
| 10765 | |
| 10766 | /* Cache this symbol's name and the name's demangled form (if any). */ |
| 10767 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
| 10768 | linkagename = dwarf2_physname (name, die, cu); |
| 10769 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); |
| 10770 | |
| 10771 | /* Fortran does not have mangling standard and the mangling does differ |
| 10772 | between gfortran, iFort etc. */ |
| 10773 | if (cu->language == language_fortran |
| 10774 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
| 10775 | symbol_set_demangled_name (&(sym->ginfo), |
| 10776 | (char *) dwarf2_full_name (name, die, cu), |
| 10777 | NULL); |
| 10778 | |
| 10779 | /* Default assumptions. |
| 10780 | Use the passed type or decode it from the die. */ |
| 10781 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 10782 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 10783 | if (type != NULL) |
| 10784 | SYMBOL_TYPE (sym) = type; |
| 10785 | else |
| 10786 | SYMBOL_TYPE (sym) = die_type (die, cu); |
| 10787 | attr = dwarf2_attr (die, |
| 10788 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, |
| 10789 | cu); |
| 10790 | if (attr) |
| 10791 | { |
| 10792 | SYMBOL_LINE (sym) = DW_UNSND (attr); |
| 10793 | } |
| 10794 | |
| 10795 | attr = dwarf2_attr (die, |
| 10796 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, |
| 10797 | cu); |
| 10798 | if (attr) |
| 10799 | { |
| 10800 | int file_index = DW_UNSND (attr); |
| 10801 | |
| 10802 | if (cu->line_header == NULL |
| 10803 | || file_index > cu->line_header->num_file_names) |
| 10804 | complaint (&symfile_complaints, |
| 10805 | _("file index out of range")); |
| 10806 | else if (file_index > 0) |
| 10807 | { |
| 10808 | struct file_entry *fe; |
| 10809 | |
| 10810 | fe = &cu->line_header->file_names[file_index - 1]; |
| 10811 | SYMBOL_SYMTAB (sym) = fe->symtab; |
| 10812 | } |
| 10813 | } |
| 10814 | |
| 10815 | switch (die->tag) |
| 10816 | { |
| 10817 | case DW_TAG_label: |
| 10818 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 10819 | if (attr) |
| 10820 | { |
| 10821 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; |
| 10822 | } |
| 10823 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
| 10824 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; |
| 10825 | SYMBOL_CLASS (sym) = LOC_LABEL; |
| 10826 | add_symbol_to_list (sym, cu->list_in_scope); |
| 10827 | break; |
| 10828 | case DW_TAG_subprogram: |
| 10829 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 10830 | finish_block. */ |
| 10831 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 10832 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 10833 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
| 10834 | || cu->language == language_ada) |
| 10835 | { |
| 10836 | /* Subprograms marked external are stored as a global symbol. |
| 10837 | Ada subprograms, whether marked external or not, are always |
| 10838 | stored as a global symbol, because we want to be able to |
| 10839 | access them globally. For instance, we want to be able |
| 10840 | to break on a nested subprogram without having to |
| 10841 | specify the context. */ |
| 10842 | list_to_add = &global_symbols; |
| 10843 | } |
| 10844 | else |
| 10845 | { |
| 10846 | list_to_add = cu->list_in_scope; |
| 10847 | } |
| 10848 | break; |
| 10849 | case DW_TAG_inlined_subroutine: |
| 10850 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 10851 | finish_block. */ |
| 10852 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 10853 | SYMBOL_INLINED (sym) = 1; |
| 10854 | /* Do not add the symbol to any lists. It will be found via |
| 10855 | BLOCK_FUNCTION from the blockvector. */ |
| 10856 | break; |
| 10857 | case DW_TAG_template_value_param: |
| 10858 | suppress_add = 1; |
| 10859 | /* Fall through. */ |
| 10860 | case DW_TAG_constant: |
| 10861 | case DW_TAG_variable: |
| 10862 | case DW_TAG_member: |
| 10863 | /* Compilation with minimal debug info may result in |
| 10864 | variables with missing type entries. Change the |
| 10865 | misleading `void' type to something sensible. */ |
| 10866 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
| 10867 | SYMBOL_TYPE (sym) |
| 10868 | = objfile_type (objfile)->nodebug_data_symbol; |
| 10869 | |
| 10870 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 10871 | /* In the case of DW_TAG_member, we should only be called for |
| 10872 | static const members. */ |
| 10873 | if (die->tag == DW_TAG_member) |
| 10874 | { |
| 10875 | /* dwarf2_add_field uses die_is_declaration, |
| 10876 | so we do the same. */ |
| 10877 | gdb_assert (die_is_declaration (die, cu)); |
| 10878 | gdb_assert (attr); |
| 10879 | } |
| 10880 | if (attr) |
| 10881 | { |
| 10882 | dwarf2_const_value (attr, sym, cu); |
| 10883 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 10884 | if (!suppress_add) |
| 10885 | { |
| 10886 | if (attr2 && (DW_UNSND (attr2) != 0)) |
| 10887 | list_to_add = &global_symbols; |
| 10888 | else |
| 10889 | list_to_add = cu->list_in_scope; |
| 10890 | } |
| 10891 | break; |
| 10892 | } |
| 10893 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 10894 | if (attr) |
| 10895 | { |
| 10896 | var_decode_location (attr, sym, cu); |
| 10897 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 10898 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
| 10899 | && SYMBOL_VALUE_ADDRESS (sym) == 0 |
| 10900 | && !dwarf2_per_objfile->has_section_at_zero) |
| 10901 | { |
| 10902 | /* When a static variable is eliminated by the linker, |
| 10903 | the corresponding debug information is not stripped |
| 10904 | out, but the variable address is set to null; |
| 10905 | do not add such variables into symbol table. */ |
| 10906 | } |
| 10907 | else if (attr2 && (DW_UNSND (attr2) != 0)) |
| 10908 | { |
| 10909 | /* Workaround gfortran PR debug/40040 - it uses |
| 10910 | DW_AT_location for variables in -fPIC libraries which may |
| 10911 | get overriden by other libraries/executable and get |
| 10912 | a different address. Resolve it by the minimal symbol |
| 10913 | which may come from inferior's executable using copy |
| 10914 | relocation. Make this workaround only for gfortran as for |
| 10915 | other compilers GDB cannot guess the minimal symbol |
| 10916 | Fortran mangling kind. */ |
| 10917 | if (cu->language == language_fortran && die->parent |
| 10918 | && die->parent->tag == DW_TAG_module |
| 10919 | && cu->producer |
| 10920 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) |
| 10921 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 10922 | |
| 10923 | /* A variable with DW_AT_external is never static, |
| 10924 | but it may be block-scoped. */ |
| 10925 | list_to_add = (cu->list_in_scope == &file_symbols |
| 10926 | ? &global_symbols : cu->list_in_scope); |
| 10927 | } |
| 10928 | else |
| 10929 | list_to_add = cu->list_in_scope; |
| 10930 | } |
| 10931 | else |
| 10932 | { |
| 10933 | /* We do not know the address of this symbol. |
| 10934 | If it is an external symbol and we have type information |
| 10935 | for it, enter the symbol as a LOC_UNRESOLVED symbol. |
| 10936 | The address of the variable will then be determined from |
| 10937 | the minimal symbol table whenever the variable is |
| 10938 | referenced. */ |
| 10939 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 10940 | if (attr2 && (DW_UNSND (attr2) != 0) |
| 10941 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
| 10942 | { |
| 10943 | /* A variable with DW_AT_external is never static, but it |
| 10944 | may be block-scoped. */ |
| 10945 | list_to_add = (cu->list_in_scope == &file_symbols |
| 10946 | ? &global_symbols : cu->list_in_scope); |
| 10947 | |
| 10948 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 10949 | } |
| 10950 | else if (!die_is_declaration (die, cu)) |
| 10951 | { |
| 10952 | /* Use the default LOC_OPTIMIZED_OUT class. */ |
| 10953 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); |
| 10954 | if (!suppress_add) |
| 10955 | list_to_add = cu->list_in_scope; |
| 10956 | } |
| 10957 | } |
| 10958 | break; |
| 10959 | case DW_TAG_formal_parameter: |
| 10960 | /* If we are inside a function, mark this as an argument. If |
| 10961 | not, we might be looking at an argument to an inlined function |
| 10962 | when we do not have enough information to show inlined frames; |
| 10963 | pretend it's a local variable in that case so that the user can |
| 10964 | still see it. */ |
| 10965 | if (context_stack_depth > 0 |
| 10966 | && context_stack[context_stack_depth - 1].name != NULL) |
| 10967 | SYMBOL_IS_ARGUMENT (sym) = 1; |
| 10968 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 10969 | if (attr) |
| 10970 | { |
| 10971 | var_decode_location (attr, sym, cu); |
| 10972 | } |
| 10973 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 10974 | if (attr) |
| 10975 | { |
| 10976 | dwarf2_const_value (attr, sym, cu); |
| 10977 | } |
| 10978 | attr = dwarf2_attr (die, DW_AT_variable_parameter, cu); |
| 10979 | if (attr && DW_UNSND (attr)) |
| 10980 | { |
| 10981 | struct type *ref_type; |
| 10982 | |
| 10983 | ref_type = lookup_reference_type (SYMBOL_TYPE (sym)); |
| 10984 | SYMBOL_TYPE (sym) = ref_type; |
| 10985 | } |
| 10986 | |
| 10987 | list_to_add = cu->list_in_scope; |
| 10988 | break; |
| 10989 | case DW_TAG_unspecified_parameters: |
| 10990 | /* From varargs functions; gdb doesn't seem to have any |
| 10991 | interest in this information, so just ignore it for now. |
| 10992 | (FIXME?) */ |
| 10993 | break; |
| 10994 | case DW_TAG_template_type_param: |
| 10995 | suppress_add = 1; |
| 10996 | /* Fall through. */ |
| 10997 | case DW_TAG_class_type: |
| 10998 | case DW_TAG_interface_type: |
| 10999 | case DW_TAG_structure_type: |
| 11000 | case DW_TAG_union_type: |
| 11001 | case DW_TAG_set_type: |
| 11002 | case DW_TAG_enumeration_type: |
| 11003 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11004 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
| 11005 | |
| 11006 | { |
| 11007 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
| 11008 | really ever be static objects: otherwise, if you try |
| 11009 | to, say, break of a class's method and you're in a file |
| 11010 | which doesn't mention that class, it won't work unless |
| 11011 | the check for all static symbols in lookup_symbol_aux |
| 11012 | saves you. See the OtherFileClass tests in |
| 11013 | gdb.c++/namespace.exp. */ |
| 11014 | |
| 11015 | if (!suppress_add) |
| 11016 | { |
| 11017 | list_to_add = (cu->list_in_scope == &file_symbols |
| 11018 | && (cu->language == language_cplus |
| 11019 | || cu->language == language_java) |
| 11020 | ? &global_symbols : cu->list_in_scope); |
| 11021 | |
| 11022 | /* The semantics of C++ state that "struct foo { |
| 11023 | ... }" also defines a typedef for "foo". A Java |
| 11024 | class declaration also defines a typedef for the |
| 11025 | class. */ |
| 11026 | if (cu->language == language_cplus |
| 11027 | || cu->language == language_java |
| 11028 | || cu->language == language_ada) |
| 11029 | { |
| 11030 | /* The symbol's name is already allocated along |
| 11031 | with this objfile, so we don't need to |
| 11032 | duplicate it for the type. */ |
| 11033 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
| 11034 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
| 11035 | } |
| 11036 | } |
| 11037 | } |
| 11038 | break; |
| 11039 | case DW_TAG_typedef: |
| 11040 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11041 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 11042 | list_to_add = cu->list_in_scope; |
| 11043 | break; |
| 11044 | case DW_TAG_base_type: |
| 11045 | case DW_TAG_subrange_type: |
| 11046 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11047 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 11048 | list_to_add = cu->list_in_scope; |
| 11049 | break; |
| 11050 | case DW_TAG_enumerator: |
| 11051 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 11052 | if (attr) |
| 11053 | { |
| 11054 | dwarf2_const_value (attr, sym, cu); |
| 11055 | } |
| 11056 | { |
| 11057 | /* NOTE: carlton/2003-11-10: See comment above in the |
| 11058 | DW_TAG_class_type, etc. block. */ |
| 11059 | |
| 11060 | list_to_add = (cu->list_in_scope == &file_symbols |
| 11061 | && (cu->language == language_cplus |
| 11062 | || cu->language == language_java) |
| 11063 | ? &global_symbols : cu->list_in_scope); |
| 11064 | } |
| 11065 | break; |
| 11066 | case DW_TAG_namespace: |
| 11067 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11068 | list_to_add = &global_symbols; |
| 11069 | break; |
| 11070 | default: |
| 11071 | /* Not a tag we recognize. Hopefully we aren't processing |
| 11072 | trash data, but since we must specifically ignore things |
| 11073 | we don't recognize, there is nothing else we should do at |
| 11074 | this point. */ |
| 11075 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
| 11076 | dwarf_tag_name (die->tag)); |
| 11077 | break; |
| 11078 | } |
| 11079 | |
| 11080 | if (suppress_add) |
| 11081 | { |
| 11082 | sym->hash_next = objfile->template_symbols; |
| 11083 | objfile->template_symbols = sym; |
| 11084 | list_to_add = NULL; |
| 11085 | } |
| 11086 | |
| 11087 | if (list_to_add != NULL) |
| 11088 | add_symbol_to_list (sym, list_to_add); |
| 11089 | |
| 11090 | /* For the benefit of old versions of GCC, check for anonymous |
| 11091 | namespaces based on the demangled name. */ |
| 11092 | if (!processing_has_namespace_info |
| 11093 | && cu->language == language_cplus) |
| 11094 | cp_scan_for_anonymous_namespaces (sym); |
| 11095 | } |
| 11096 | return (sym); |
| 11097 | } |
| 11098 | |
| 11099 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
| 11100 | |
| 11101 | static struct symbol * |
| 11102 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
| 11103 | { |
| 11104 | return new_symbol_full (die, type, cu, NULL); |
| 11105 | } |
| 11106 | |
| 11107 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
| 11108 | zero-extend it as appropriate for the symbol's type. The DWARF |
| 11109 | standard (v4) is not entirely clear about the meaning of using |
| 11110 | DW_FORM_dataN for a constant with a signed type, where the type is |
| 11111 | wider than the data. The conclusion of a discussion on the DWARF |
| 11112 | list was that this is unspecified. We choose to always zero-extend |
| 11113 | because that is the interpretation long in use by GCC. */ |
| 11114 | |
| 11115 | static gdb_byte * |
| 11116 | dwarf2_const_value_data (struct attribute *attr, struct type *type, |
| 11117 | const char *name, struct obstack *obstack, |
| 11118 | struct dwarf2_cu *cu, long *value, int bits) |
| 11119 | { |
| 11120 | struct objfile *objfile = cu->objfile; |
| 11121 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
| 11122 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; |
| 11123 | LONGEST l = DW_UNSND (attr); |
| 11124 | |
| 11125 | if (bits < sizeof (*value) * 8) |
| 11126 | { |
| 11127 | l &= ((LONGEST) 1 << bits) - 1; |
| 11128 | *value = l; |
| 11129 | } |
| 11130 | else if (bits == sizeof (*value) * 8) |
| 11131 | *value = l; |
| 11132 | else |
| 11133 | { |
| 11134 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); |
| 11135 | store_unsigned_integer (bytes, bits / 8, byte_order, l); |
| 11136 | return bytes; |
| 11137 | } |
| 11138 | |
| 11139 | return NULL; |
| 11140 | } |
| 11141 | |
| 11142 | /* Read a constant value from an attribute. Either set *VALUE, or if |
| 11143 | the value does not fit in *VALUE, set *BYTES - either already |
| 11144 | allocated on the objfile obstack, or newly allocated on OBSTACK, |
| 11145 | or, set *BATON, if we translated the constant to a location |
| 11146 | expression. */ |
| 11147 | |
| 11148 | static void |
| 11149 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, |
| 11150 | const char *name, struct obstack *obstack, |
| 11151 | struct dwarf2_cu *cu, |
| 11152 | long *value, gdb_byte **bytes, |
| 11153 | struct dwarf2_locexpr_baton **baton) |
| 11154 | { |
| 11155 | struct objfile *objfile = cu->objfile; |
| 11156 | struct comp_unit_head *cu_header = &cu->header; |
| 11157 | struct dwarf_block *blk; |
| 11158 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
| 11159 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); |
| 11160 | |
| 11161 | *value = 0; |
| 11162 | *bytes = NULL; |
| 11163 | *baton = NULL; |
| 11164 | |
| 11165 | switch (attr->form) |
| 11166 | { |
| 11167 | case DW_FORM_addr: |
| 11168 | { |
| 11169 | gdb_byte *data; |
| 11170 | |
| 11171 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
| 11172 | dwarf2_const_value_length_mismatch_complaint (name, |
| 11173 | cu_header->addr_size, |
| 11174 | TYPE_LENGTH (type)); |
| 11175 | /* Symbols of this form are reasonably rare, so we just |
| 11176 | piggyback on the existing location code rather than writing |
| 11177 | a new implementation of symbol_computed_ops. */ |
| 11178 | *baton = obstack_alloc (&objfile->objfile_obstack, |
| 11179 | sizeof (struct dwarf2_locexpr_baton)); |
| 11180 | (*baton)->per_cu = cu->per_cu; |
| 11181 | gdb_assert ((*baton)->per_cu); |
| 11182 | |
| 11183 | (*baton)->size = 2 + cu_header->addr_size; |
| 11184 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); |
| 11185 | (*baton)->data = data; |
| 11186 | |
| 11187 | data[0] = DW_OP_addr; |
| 11188 | store_unsigned_integer (&data[1], cu_header->addr_size, |
| 11189 | byte_order, DW_ADDR (attr)); |
| 11190 | data[cu_header->addr_size + 1] = DW_OP_stack_value; |
| 11191 | } |
| 11192 | break; |
| 11193 | case DW_FORM_string: |
| 11194 | case DW_FORM_strp: |
| 11195 | /* DW_STRING is already allocated on the objfile obstack, point |
| 11196 | directly to it. */ |
| 11197 | *bytes = (gdb_byte *) DW_STRING (attr); |
| 11198 | break; |
| 11199 | case DW_FORM_block1: |
| 11200 | case DW_FORM_block2: |
| 11201 | case DW_FORM_block4: |
| 11202 | case DW_FORM_block: |
| 11203 | case DW_FORM_exprloc: |
| 11204 | blk = DW_BLOCK (attr); |
| 11205 | if (TYPE_LENGTH (type) != blk->size) |
| 11206 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, |
| 11207 | TYPE_LENGTH (type)); |
| 11208 | *bytes = blk->data; |
| 11209 | break; |
| 11210 | |
| 11211 | /* The DW_AT_const_value attributes are supposed to carry the |
| 11212 | symbol's value "represented as it would be on the target |
| 11213 | architecture." By the time we get here, it's already been |
| 11214 | converted to host endianness, so we just need to sign- or |
| 11215 | zero-extend it as appropriate. */ |
| 11216 | case DW_FORM_data1: |
| 11217 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 11218 | obstack, cu, value, 8); |
| 11219 | break; |
| 11220 | case DW_FORM_data2: |
| 11221 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 11222 | obstack, cu, value, 16); |
| 11223 | break; |
| 11224 | case DW_FORM_data4: |
| 11225 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 11226 | obstack, cu, value, 32); |
| 11227 | break; |
| 11228 | case DW_FORM_data8: |
| 11229 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 11230 | obstack, cu, value, 64); |
| 11231 | break; |
| 11232 | |
| 11233 | case DW_FORM_sdata: |
| 11234 | *value = DW_SND (attr); |
| 11235 | break; |
| 11236 | |
| 11237 | case DW_FORM_udata: |
| 11238 | *value = DW_UNSND (attr); |
| 11239 | break; |
| 11240 | |
| 11241 | default: |
| 11242 | complaint (&symfile_complaints, |
| 11243 | _("unsupported const value attribute form: '%s'"), |
| 11244 | dwarf_form_name (attr->form)); |
| 11245 | *value = 0; |
| 11246 | break; |
| 11247 | } |
| 11248 | } |
| 11249 | |
| 11250 | |
| 11251 | /* Copy constant value from an attribute to a symbol. */ |
| 11252 | |
| 11253 | static void |
| 11254 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
| 11255 | struct dwarf2_cu *cu) |
| 11256 | { |
| 11257 | struct objfile *objfile = cu->objfile; |
| 11258 | struct comp_unit_head *cu_header = &cu->header; |
| 11259 | long value; |
| 11260 | gdb_byte *bytes; |
| 11261 | struct dwarf2_locexpr_baton *baton; |
| 11262 | |
| 11263 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
| 11264 | SYMBOL_PRINT_NAME (sym), |
| 11265 | &objfile->objfile_obstack, cu, |
| 11266 | &value, &bytes, &baton); |
| 11267 | |
| 11268 | if (baton != NULL) |
| 11269 | { |
| 11270 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 11271 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 11272 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 11273 | } |
| 11274 | else if (bytes != NULL) |
| 11275 | { |
| 11276 | SYMBOL_VALUE_BYTES (sym) = bytes; |
| 11277 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 11278 | } |
| 11279 | else |
| 11280 | { |
| 11281 | SYMBOL_VALUE (sym) = value; |
| 11282 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 11283 | } |
| 11284 | } |
| 11285 | |
| 11286 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
| 11287 | |
| 11288 | static struct type * |
| 11289 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11290 | { |
| 11291 | struct attribute *type_attr; |
| 11292 | |
| 11293 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
| 11294 | if (!type_attr) |
| 11295 | { |
| 11296 | /* A missing DW_AT_type represents a void type. */ |
| 11297 | return objfile_type (cu->objfile)->builtin_void; |
| 11298 | } |
| 11299 | |
| 11300 | return lookup_die_type (die, type_attr, cu); |
| 11301 | } |
| 11302 | |
| 11303 | /* True iff CU's producer generates GNAT Ada auxiliary information |
| 11304 | that allows to find parallel types through that information instead |
| 11305 | of having to do expensive parallel lookups by type name. */ |
| 11306 | |
| 11307 | static int |
| 11308 | need_gnat_info (struct dwarf2_cu *cu) |
| 11309 | { |
| 11310 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version |
| 11311 | of GNAT produces this auxiliary information, without any indication |
| 11312 | that it is produced. Part of enhancing the FSF version of GNAT |
| 11313 | to produce that information will be to put in place an indicator |
| 11314 | that we can use in order to determine whether the descriptive type |
| 11315 | info is available or not. One suggestion that has been made is |
| 11316 | to use a new attribute, attached to the CU die. For now, assume |
| 11317 | that the descriptive type info is not available. */ |
| 11318 | return 0; |
| 11319 | } |
| 11320 | |
| 11321 | /* Return the auxiliary type of the die in question using its |
| 11322 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the |
| 11323 | attribute is not present. */ |
| 11324 | |
| 11325 | static struct type * |
| 11326 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11327 | { |
| 11328 | struct attribute *type_attr; |
| 11329 | |
| 11330 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); |
| 11331 | if (!type_attr) |
| 11332 | return NULL; |
| 11333 | |
| 11334 | return lookup_die_type (die, type_attr, cu); |
| 11335 | } |
| 11336 | |
| 11337 | /* If DIE has a descriptive_type attribute, then set the TYPE's |
| 11338 | descriptive type accordingly. */ |
| 11339 | |
| 11340 | static void |
| 11341 | set_descriptive_type (struct type *type, struct die_info *die, |
| 11342 | struct dwarf2_cu *cu) |
| 11343 | { |
| 11344 | struct type *descriptive_type = die_descriptive_type (die, cu); |
| 11345 | |
| 11346 | if (descriptive_type) |
| 11347 | { |
| 11348 | ALLOCATE_GNAT_AUX_TYPE (type); |
| 11349 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; |
| 11350 | } |
| 11351 | } |
| 11352 | |
| 11353 | /* Return the containing type of the die in question using its |
| 11354 | DW_AT_containing_type attribute. */ |
| 11355 | |
| 11356 | static struct type * |
| 11357 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11358 | { |
| 11359 | struct attribute *type_attr; |
| 11360 | |
| 11361 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
| 11362 | if (!type_attr) |
| 11363 | error (_("Dwarf Error: Problem turning containing type into gdb type " |
| 11364 | "[in module %s]"), cu->objfile->name); |
| 11365 | |
| 11366 | return lookup_die_type (die, type_attr, cu); |
| 11367 | } |
| 11368 | |
| 11369 | /* Look up the type of DIE in CU using its type attribute ATTR. |
| 11370 | If there is no type substitute an error marker. */ |
| 11371 | |
| 11372 | static struct type * |
| 11373 | lookup_die_type (struct die_info *die, struct attribute *attr, |
| 11374 | struct dwarf2_cu *cu) |
| 11375 | { |
| 11376 | struct type *this_type; |
| 11377 | |
| 11378 | /* First see if we have it cached. */ |
| 11379 | |
| 11380 | if (is_ref_attr (attr)) |
| 11381 | { |
| 11382 | unsigned int offset = dwarf2_get_ref_die_offset (attr); |
| 11383 | |
| 11384 | this_type = get_die_type_at_offset (offset, cu->per_cu); |
| 11385 | } |
| 11386 | else if (attr->form == DW_FORM_sig8) |
| 11387 | { |
| 11388 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); |
| 11389 | struct dwarf2_cu *sig_cu; |
| 11390 | unsigned int offset; |
| 11391 | |
| 11392 | /* sig_type will be NULL if the signatured type is missing from |
| 11393 | the debug info. */ |
| 11394 | if (sig_type == NULL) |
| 11395 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " |
| 11396 | "at 0x%x [in module %s]"), |
| 11397 | die->offset, cu->objfile->name); |
| 11398 | |
| 11399 | gdb_assert (sig_type->per_cu.from_debug_types); |
| 11400 | offset = sig_type->offset + sig_type->type_offset; |
| 11401 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
| 11402 | } |
| 11403 | else |
| 11404 | { |
| 11405 | dump_die_for_error (die); |
| 11406 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), |
| 11407 | dwarf_attr_name (attr->name), cu->objfile->name); |
| 11408 | } |
| 11409 | |
| 11410 | /* If not cached we need to read it in. */ |
| 11411 | |
| 11412 | if (this_type == NULL) |
| 11413 | { |
| 11414 | struct die_info *type_die; |
| 11415 | struct dwarf2_cu *type_cu = cu; |
| 11416 | |
| 11417 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 11418 | /* If the type is cached, we should have found it above. */ |
| 11419 | gdb_assert (get_die_type (type_die, type_cu) == NULL); |
| 11420 | this_type = read_type_die_1 (type_die, type_cu); |
| 11421 | } |
| 11422 | |
| 11423 | /* If we still don't have a type use an error marker. */ |
| 11424 | |
| 11425 | if (this_type == NULL) |
| 11426 | { |
| 11427 | char *message, *saved; |
| 11428 | |
| 11429 | /* read_type_die already issued a complaint. */ |
| 11430 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), |
| 11431 | cu->objfile->name, |
| 11432 | cu->header.offset, |
| 11433 | die->offset); |
| 11434 | saved = obstack_copy0 (&cu->objfile->objfile_obstack, |
| 11435 | message, strlen (message)); |
| 11436 | xfree (message); |
| 11437 | |
| 11438 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, cu->objfile); |
| 11439 | } |
| 11440 | |
| 11441 | return this_type; |
| 11442 | } |
| 11443 | |
| 11444 | /* Return the type in DIE, CU. |
| 11445 | Returns NULL for invalid types. |
| 11446 | |
| 11447 | This first does a lookup in the appropriate type_hash table, |
| 11448 | and only reads the die in if necessary. |
| 11449 | |
| 11450 | NOTE: This can be called when reading in partial or full symbols. */ |
| 11451 | |
| 11452 | static struct type * |
| 11453 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
| 11454 | { |
| 11455 | struct type *this_type; |
| 11456 | |
| 11457 | this_type = get_die_type (die, cu); |
| 11458 | if (this_type) |
| 11459 | return this_type; |
| 11460 | |
| 11461 | return read_type_die_1 (die, cu); |
| 11462 | } |
| 11463 | |
| 11464 | /* Read the type in DIE, CU. |
| 11465 | Returns NULL for invalid types. */ |
| 11466 | |
| 11467 | static struct type * |
| 11468 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) |
| 11469 | { |
| 11470 | struct type *this_type = NULL; |
| 11471 | |
| 11472 | switch (die->tag) |
| 11473 | { |
| 11474 | case DW_TAG_class_type: |
| 11475 | case DW_TAG_interface_type: |
| 11476 | case DW_TAG_structure_type: |
| 11477 | case DW_TAG_union_type: |
| 11478 | this_type = read_structure_type (die, cu); |
| 11479 | break; |
| 11480 | case DW_TAG_enumeration_type: |
| 11481 | this_type = read_enumeration_type (die, cu); |
| 11482 | break; |
| 11483 | case DW_TAG_subprogram: |
| 11484 | case DW_TAG_subroutine_type: |
| 11485 | case DW_TAG_inlined_subroutine: |
| 11486 | this_type = read_subroutine_type (die, cu); |
| 11487 | break; |
| 11488 | case DW_TAG_array_type: |
| 11489 | this_type = read_array_type (die, cu); |
| 11490 | break; |
| 11491 | case DW_TAG_set_type: |
| 11492 | this_type = read_set_type (die, cu); |
| 11493 | break; |
| 11494 | case DW_TAG_pointer_type: |
| 11495 | this_type = read_tag_pointer_type (die, cu); |
| 11496 | break; |
| 11497 | case DW_TAG_ptr_to_member_type: |
| 11498 | this_type = read_tag_ptr_to_member_type (die, cu); |
| 11499 | break; |
| 11500 | case DW_TAG_reference_type: |
| 11501 | this_type = read_tag_reference_type (die, cu); |
| 11502 | break; |
| 11503 | case DW_TAG_const_type: |
| 11504 | this_type = read_tag_const_type (die, cu); |
| 11505 | break; |
| 11506 | case DW_TAG_volatile_type: |
| 11507 | this_type = read_tag_volatile_type (die, cu); |
| 11508 | break; |
| 11509 | case DW_TAG_string_type: |
| 11510 | this_type = read_tag_string_type (die, cu); |
| 11511 | break; |
| 11512 | case DW_TAG_typedef: |
| 11513 | this_type = read_typedef (die, cu); |
| 11514 | break; |
| 11515 | case DW_TAG_subrange_type: |
| 11516 | this_type = read_subrange_type (die, cu); |
| 11517 | break; |
| 11518 | case DW_TAG_base_type: |
| 11519 | this_type = read_base_type (die, cu); |
| 11520 | break; |
| 11521 | case DW_TAG_unspecified_type: |
| 11522 | this_type = read_unspecified_type (die, cu); |
| 11523 | break; |
| 11524 | case DW_TAG_namespace: |
| 11525 | this_type = read_namespace_type (die, cu); |
| 11526 | break; |
| 11527 | case DW_TAG_module: |
| 11528 | this_type = read_module_type (die, cu); |
| 11529 | break; |
| 11530 | default: |
| 11531 | complaint (&symfile_complaints, |
| 11532 | _("unexpected tag in read_type_die: '%s'"), |
| 11533 | dwarf_tag_name (die->tag)); |
| 11534 | break; |
| 11535 | } |
| 11536 | |
| 11537 | return this_type; |
| 11538 | } |
| 11539 | |
| 11540 | /* See if we can figure out if the class lives in a namespace. We do |
| 11541 | this by looking for a member function; its demangled name will |
| 11542 | contain namespace info, if there is any. |
| 11543 | Return the computed name or NULL. |
| 11544 | Space for the result is allocated on the objfile's obstack. |
| 11545 | This is the full-die version of guess_partial_die_structure_name. |
| 11546 | In this case we know DIE has no useful parent. */ |
| 11547 | |
| 11548 | static char * |
| 11549 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) |
| 11550 | { |
| 11551 | struct die_info *spec_die; |
| 11552 | struct dwarf2_cu *spec_cu; |
| 11553 | struct die_info *child; |
| 11554 | |
| 11555 | spec_cu = cu; |
| 11556 | spec_die = die_specification (die, &spec_cu); |
| 11557 | if (spec_die != NULL) |
| 11558 | { |
| 11559 | die = spec_die; |
| 11560 | cu = spec_cu; |
| 11561 | } |
| 11562 | |
| 11563 | for (child = die->child; |
| 11564 | child != NULL; |
| 11565 | child = child->sibling) |
| 11566 | { |
| 11567 | if (child->tag == DW_TAG_subprogram) |
| 11568 | { |
| 11569 | struct attribute *attr; |
| 11570 | |
| 11571 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); |
| 11572 | if (attr == NULL) |
| 11573 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); |
| 11574 | if (attr != NULL) |
| 11575 | { |
| 11576 | char *actual_name |
| 11577 | = language_class_name_from_physname (cu->language_defn, |
| 11578 | DW_STRING (attr)); |
| 11579 | char *name = NULL; |
| 11580 | |
| 11581 | if (actual_name != NULL) |
| 11582 | { |
| 11583 | char *die_name = dwarf2_name (die, cu); |
| 11584 | |
| 11585 | if (die_name != NULL |
| 11586 | && strcmp (die_name, actual_name) != 0) |
| 11587 | { |
| 11588 | /* Strip off the class name from the full name. |
| 11589 | We want the prefix. */ |
| 11590 | int die_name_len = strlen (die_name); |
| 11591 | int actual_name_len = strlen (actual_name); |
| 11592 | |
| 11593 | /* Test for '::' as a sanity check. */ |
| 11594 | if (actual_name_len > die_name_len + 2 |
| 11595 | && actual_name[actual_name_len |
| 11596 | - die_name_len - 1] == ':') |
| 11597 | name = |
| 11598 | obsavestring (actual_name, |
| 11599 | actual_name_len - die_name_len - 2, |
| 11600 | &cu->objfile->objfile_obstack); |
| 11601 | } |
| 11602 | } |
| 11603 | xfree (actual_name); |
| 11604 | return name; |
| 11605 | } |
| 11606 | } |
| 11607 | } |
| 11608 | |
| 11609 | return NULL; |
| 11610 | } |
| 11611 | |
| 11612 | /* Return the name of the namespace/class that DIE is defined within, |
| 11613 | or "" if we can't tell. The caller should not xfree the result. |
| 11614 | |
| 11615 | For example, if we're within the method foo() in the following |
| 11616 | code: |
| 11617 | |
| 11618 | namespace N { |
| 11619 | class C { |
| 11620 | void foo () { |
| 11621 | } |
| 11622 | }; |
| 11623 | } |
| 11624 | |
| 11625 | then determine_prefix on foo's die will return "N::C". */ |
| 11626 | |
| 11627 | static char * |
| 11628 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
| 11629 | { |
| 11630 | struct die_info *parent, *spec_die; |
| 11631 | struct dwarf2_cu *spec_cu; |
| 11632 | struct type *parent_type; |
| 11633 | |
| 11634 | if (cu->language != language_cplus && cu->language != language_java |
| 11635 | && cu->language != language_fortran) |
| 11636 | return ""; |
| 11637 | |
| 11638 | /* We have to be careful in the presence of DW_AT_specification. |
| 11639 | For example, with GCC 3.4, given the code |
| 11640 | |
| 11641 | namespace N { |
| 11642 | void foo() { |
| 11643 | // Definition of N::foo. |
| 11644 | } |
| 11645 | } |
| 11646 | |
| 11647 | then we'll have a tree of DIEs like this: |
| 11648 | |
| 11649 | 1: DW_TAG_compile_unit |
| 11650 | 2: DW_TAG_namespace // N |
| 11651 | 3: DW_TAG_subprogram // declaration of N::foo |
| 11652 | 4: DW_TAG_subprogram // definition of N::foo |
| 11653 | DW_AT_specification // refers to die #3 |
| 11654 | |
| 11655 | Thus, when processing die #4, we have to pretend that we're in |
| 11656 | the context of its DW_AT_specification, namely the contex of die |
| 11657 | #3. */ |
| 11658 | spec_cu = cu; |
| 11659 | spec_die = die_specification (die, &spec_cu); |
| 11660 | if (spec_die == NULL) |
| 11661 | parent = die->parent; |
| 11662 | else |
| 11663 | { |
| 11664 | parent = spec_die->parent; |
| 11665 | cu = spec_cu; |
| 11666 | } |
| 11667 | |
| 11668 | if (parent == NULL) |
| 11669 | return ""; |
| 11670 | else if (parent->building_fullname) |
| 11671 | { |
| 11672 | const char *name; |
| 11673 | const char *parent_name; |
| 11674 | |
| 11675 | /* It has been seen on RealView 2.2 built binaries, |
| 11676 | DW_TAG_template_type_param types actually _defined_ as |
| 11677 | children of the parent class: |
| 11678 | |
| 11679 | enum E {}; |
| 11680 | template class <class Enum> Class{}; |
| 11681 | Class<enum E> class_e; |
| 11682 | |
| 11683 | 1: DW_TAG_class_type (Class) |
| 11684 | 2: DW_TAG_enumeration_type (E) |
| 11685 | 3: DW_TAG_enumerator (enum1:0) |
| 11686 | 3: DW_TAG_enumerator (enum2:1) |
| 11687 | ... |
| 11688 | 2: DW_TAG_template_type_param |
| 11689 | DW_AT_type DW_FORM_ref_udata (E) |
| 11690 | |
| 11691 | Besides being broken debug info, it can put GDB into an |
| 11692 | infinite loop. Consider: |
| 11693 | |
| 11694 | When we're building the full name for Class<E>, we'll start |
| 11695 | at Class, and go look over its template type parameters, |
| 11696 | finding E. We'll then try to build the full name of E, and |
| 11697 | reach here. We're now trying to build the full name of E, |
| 11698 | and look over the parent DIE for containing scope. In the |
| 11699 | broken case, if we followed the parent DIE of E, we'd again |
| 11700 | find Class, and once again go look at its template type |
| 11701 | arguments, etc., etc. Simply don't consider such parent die |
| 11702 | as source-level parent of this die (it can't be, the language |
| 11703 | doesn't allow it), and break the loop here. */ |
| 11704 | name = dwarf2_name (die, cu); |
| 11705 | parent_name = dwarf2_name (parent, cu); |
| 11706 | complaint (&symfile_complaints, |
| 11707 | _("template param type '%s' defined within parent '%s'"), |
| 11708 | name ? name : "<unknown>", |
| 11709 | parent_name ? parent_name : "<unknown>"); |
| 11710 | return ""; |
| 11711 | } |
| 11712 | else |
| 11713 | switch (parent->tag) |
| 11714 | { |
| 11715 | case DW_TAG_namespace: |
| 11716 | parent_type = read_type_die (parent, cu); |
| 11717 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
| 11718 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. |
| 11719 | Work around this problem here. */ |
| 11720 | if (cu->language == language_cplus |
| 11721 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) |
| 11722 | return ""; |
| 11723 | /* We give a name to even anonymous namespaces. */ |
| 11724 | return TYPE_TAG_NAME (parent_type); |
| 11725 | case DW_TAG_class_type: |
| 11726 | case DW_TAG_interface_type: |
| 11727 | case DW_TAG_structure_type: |
| 11728 | case DW_TAG_union_type: |
| 11729 | case DW_TAG_module: |
| 11730 | parent_type = read_type_die (parent, cu); |
| 11731 | if (TYPE_TAG_NAME (parent_type) != NULL) |
| 11732 | return TYPE_TAG_NAME (parent_type); |
| 11733 | else |
| 11734 | /* An anonymous structure is only allowed non-static data |
| 11735 | members; no typedefs, no member functions, et cetera. |
| 11736 | So it does not need a prefix. */ |
| 11737 | return ""; |
| 11738 | case DW_TAG_compile_unit: |
| 11739 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ |
| 11740 | if (cu->language == language_cplus |
| 11741 | && dwarf2_per_objfile->types.asection != NULL |
| 11742 | && die->child != NULL |
| 11743 | && (die->tag == DW_TAG_class_type |
| 11744 | || die->tag == DW_TAG_structure_type |
| 11745 | || die->tag == DW_TAG_union_type)) |
| 11746 | { |
| 11747 | char *name = guess_full_die_structure_name (die, cu); |
| 11748 | if (name != NULL) |
| 11749 | return name; |
| 11750 | } |
| 11751 | return ""; |
| 11752 | default: |
| 11753 | return determine_prefix (parent, cu); |
| 11754 | } |
| 11755 | } |
| 11756 | |
| 11757 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
| 11758 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then |
| 11759 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform |
| 11760 | an obconcat, otherwise allocate storage for the result. The CU argument is |
| 11761 | used to determine the language and hence, the appropriate separator. */ |
| 11762 | |
| 11763 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
| 11764 | |
| 11765 | static char * |
| 11766 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
| 11767 | int physname, struct dwarf2_cu *cu) |
| 11768 | { |
| 11769 | const char *lead = ""; |
| 11770 | const char *sep; |
| 11771 | |
| 11772 | if (suffix == NULL || suffix[0] == '\0' |
| 11773 | || prefix == NULL || prefix[0] == '\0') |
| 11774 | sep = ""; |
| 11775 | else if (cu->language == language_java) |
| 11776 | sep = "."; |
| 11777 | else if (cu->language == language_fortran && physname) |
| 11778 | { |
| 11779 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or |
| 11780 | DW_AT_MIPS_linkage_name is preferred and used instead. */ |
| 11781 | |
| 11782 | lead = "__"; |
| 11783 | sep = "_MOD_"; |
| 11784 | } |
| 11785 | else |
| 11786 | sep = "::"; |
| 11787 | |
| 11788 | if (prefix == NULL) |
| 11789 | prefix = ""; |
| 11790 | if (suffix == NULL) |
| 11791 | suffix = ""; |
| 11792 | |
| 11793 | if (obs == NULL) |
| 11794 | { |
| 11795 | char *retval |
| 11796 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); |
| 11797 | |
| 11798 | strcpy (retval, lead); |
| 11799 | strcat (retval, prefix); |
| 11800 | strcat (retval, sep); |
| 11801 | strcat (retval, suffix); |
| 11802 | return retval; |
| 11803 | } |
| 11804 | else |
| 11805 | { |
| 11806 | /* We have an obstack. */ |
| 11807 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
| 11808 | } |
| 11809 | } |
| 11810 | |
| 11811 | /* Return sibling of die, NULL if no sibling. */ |
| 11812 | |
| 11813 | static struct die_info * |
| 11814 | sibling_die (struct die_info *die) |
| 11815 | { |
| 11816 | return die->sibling; |
| 11817 | } |
| 11818 | |
| 11819 | /* Get name of a die, return NULL if not found. */ |
| 11820 | |
| 11821 | static char * |
| 11822 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, |
| 11823 | struct obstack *obstack) |
| 11824 | { |
| 11825 | if (name && cu->language == language_cplus) |
| 11826 | { |
| 11827 | char *canon_name = cp_canonicalize_string (name); |
| 11828 | |
| 11829 | if (canon_name != NULL) |
| 11830 | { |
| 11831 | if (strcmp (canon_name, name) != 0) |
| 11832 | name = obsavestring (canon_name, strlen (canon_name), |
| 11833 | obstack); |
| 11834 | xfree (canon_name); |
| 11835 | } |
| 11836 | } |
| 11837 | |
| 11838 | return name; |
| 11839 | } |
| 11840 | |
| 11841 | /* Get name of a die, return NULL if not found. */ |
| 11842 | |
| 11843 | static char * |
| 11844 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
| 11845 | { |
| 11846 | struct attribute *attr; |
| 11847 | |
| 11848 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 11849 | if (!attr || !DW_STRING (attr)) |
| 11850 | return NULL; |
| 11851 | |
| 11852 | switch (die->tag) |
| 11853 | { |
| 11854 | case DW_TAG_compile_unit: |
| 11855 | /* Compilation units have a DW_AT_name that is a filename, not |
| 11856 | a source language identifier. */ |
| 11857 | case DW_TAG_enumeration_type: |
| 11858 | case DW_TAG_enumerator: |
| 11859 | /* These tags always have simple identifiers already; no need |
| 11860 | to canonicalize them. */ |
| 11861 | return DW_STRING (attr); |
| 11862 | |
| 11863 | case DW_TAG_subprogram: |
| 11864 | /* Java constructors will all be named "<init>", so return |
| 11865 | the class name when we see this special case. */ |
| 11866 | if (cu->language == language_java |
| 11867 | && DW_STRING (attr) != NULL |
| 11868 | && strcmp (DW_STRING (attr), "<init>") == 0) |
| 11869 | { |
| 11870 | struct dwarf2_cu *spec_cu = cu; |
| 11871 | struct die_info *spec_die; |
| 11872 | |
| 11873 | /* GCJ will output '<init>' for Java constructor names. |
| 11874 | For this special case, return the name of the parent class. */ |
| 11875 | |
| 11876 | /* GCJ may output suprogram DIEs with AT_specification set. |
| 11877 | If so, use the name of the specified DIE. */ |
| 11878 | spec_die = die_specification (die, &spec_cu); |
| 11879 | if (spec_die != NULL) |
| 11880 | return dwarf2_name (spec_die, spec_cu); |
| 11881 | |
| 11882 | do |
| 11883 | { |
| 11884 | die = die->parent; |
| 11885 | if (die->tag == DW_TAG_class_type) |
| 11886 | return dwarf2_name (die, cu); |
| 11887 | } |
| 11888 | while (die->tag != DW_TAG_compile_unit); |
| 11889 | } |
| 11890 | break; |
| 11891 | |
| 11892 | case DW_TAG_class_type: |
| 11893 | case DW_TAG_interface_type: |
| 11894 | case DW_TAG_structure_type: |
| 11895 | case DW_TAG_union_type: |
| 11896 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed |
| 11897 | structures or unions. These were of the form "._%d" in GCC 4.1, |
| 11898 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 |
| 11899 | and GCC 4.4. We work around this problem by ignoring these. */ |
| 11900 | if (strncmp (DW_STRING (attr), "._", 2) == 0 |
| 11901 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0) |
| 11902 | return NULL; |
| 11903 | break; |
| 11904 | |
| 11905 | default: |
| 11906 | break; |
| 11907 | } |
| 11908 | |
| 11909 | if (!DW_STRING_IS_CANONICAL (attr)) |
| 11910 | { |
| 11911 | DW_STRING (attr) |
| 11912 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, |
| 11913 | &cu->objfile->objfile_obstack); |
| 11914 | DW_STRING_IS_CANONICAL (attr) = 1; |
| 11915 | } |
| 11916 | return DW_STRING (attr); |
| 11917 | } |
| 11918 | |
| 11919 | /* Return the die that this die in an extension of, or NULL if there |
| 11920 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
| 11921 | containing the return value on output. */ |
| 11922 | |
| 11923 | static struct die_info * |
| 11924 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
| 11925 | { |
| 11926 | struct attribute *attr; |
| 11927 | |
| 11928 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
| 11929 | if (attr == NULL) |
| 11930 | return NULL; |
| 11931 | |
| 11932 | return follow_die_ref (die, attr, ext_cu); |
| 11933 | } |
| 11934 | |
| 11935 | /* Convert a DIE tag into its string name. */ |
| 11936 | |
| 11937 | static char * |
| 11938 | dwarf_tag_name (unsigned tag) |
| 11939 | { |
| 11940 | switch (tag) |
| 11941 | { |
| 11942 | case DW_TAG_padding: |
| 11943 | return "DW_TAG_padding"; |
| 11944 | case DW_TAG_array_type: |
| 11945 | return "DW_TAG_array_type"; |
| 11946 | case DW_TAG_class_type: |
| 11947 | return "DW_TAG_class_type"; |
| 11948 | case DW_TAG_entry_point: |
| 11949 | return "DW_TAG_entry_point"; |
| 11950 | case DW_TAG_enumeration_type: |
| 11951 | return "DW_TAG_enumeration_type"; |
| 11952 | case DW_TAG_formal_parameter: |
| 11953 | return "DW_TAG_formal_parameter"; |
| 11954 | case DW_TAG_imported_declaration: |
| 11955 | return "DW_TAG_imported_declaration"; |
| 11956 | case DW_TAG_label: |
| 11957 | return "DW_TAG_label"; |
| 11958 | case DW_TAG_lexical_block: |
| 11959 | return "DW_TAG_lexical_block"; |
| 11960 | case DW_TAG_member: |
| 11961 | return "DW_TAG_member"; |
| 11962 | case DW_TAG_pointer_type: |
| 11963 | return "DW_TAG_pointer_type"; |
| 11964 | case DW_TAG_reference_type: |
| 11965 | return "DW_TAG_reference_type"; |
| 11966 | case DW_TAG_compile_unit: |
| 11967 | return "DW_TAG_compile_unit"; |
| 11968 | case DW_TAG_string_type: |
| 11969 | return "DW_TAG_string_type"; |
| 11970 | case DW_TAG_structure_type: |
| 11971 | return "DW_TAG_structure_type"; |
| 11972 | case DW_TAG_subroutine_type: |
| 11973 | return "DW_TAG_subroutine_type"; |
| 11974 | case DW_TAG_typedef: |
| 11975 | return "DW_TAG_typedef"; |
| 11976 | case DW_TAG_union_type: |
| 11977 | return "DW_TAG_union_type"; |
| 11978 | case DW_TAG_unspecified_parameters: |
| 11979 | return "DW_TAG_unspecified_parameters"; |
| 11980 | case DW_TAG_variant: |
| 11981 | return "DW_TAG_variant"; |
| 11982 | case DW_TAG_common_block: |
| 11983 | return "DW_TAG_common_block"; |
| 11984 | case DW_TAG_common_inclusion: |
| 11985 | return "DW_TAG_common_inclusion"; |
| 11986 | case DW_TAG_inheritance: |
| 11987 | return "DW_TAG_inheritance"; |
| 11988 | case DW_TAG_inlined_subroutine: |
| 11989 | return "DW_TAG_inlined_subroutine"; |
| 11990 | case DW_TAG_module: |
| 11991 | return "DW_TAG_module"; |
| 11992 | case DW_TAG_ptr_to_member_type: |
| 11993 | return "DW_TAG_ptr_to_member_type"; |
| 11994 | case DW_TAG_set_type: |
| 11995 | return "DW_TAG_set_type"; |
| 11996 | case DW_TAG_subrange_type: |
| 11997 | return "DW_TAG_subrange_type"; |
| 11998 | case DW_TAG_with_stmt: |
| 11999 | return "DW_TAG_with_stmt"; |
| 12000 | case DW_TAG_access_declaration: |
| 12001 | return "DW_TAG_access_declaration"; |
| 12002 | case DW_TAG_base_type: |
| 12003 | return "DW_TAG_base_type"; |
| 12004 | case DW_TAG_catch_block: |
| 12005 | return "DW_TAG_catch_block"; |
| 12006 | case DW_TAG_const_type: |
| 12007 | return "DW_TAG_const_type"; |
| 12008 | case DW_TAG_constant: |
| 12009 | return "DW_TAG_constant"; |
| 12010 | case DW_TAG_enumerator: |
| 12011 | return "DW_TAG_enumerator"; |
| 12012 | case DW_TAG_file_type: |
| 12013 | return "DW_TAG_file_type"; |
| 12014 | case DW_TAG_friend: |
| 12015 | return "DW_TAG_friend"; |
| 12016 | case DW_TAG_namelist: |
| 12017 | return "DW_TAG_namelist"; |
| 12018 | case DW_TAG_namelist_item: |
| 12019 | return "DW_TAG_namelist_item"; |
| 12020 | case DW_TAG_packed_type: |
| 12021 | return "DW_TAG_packed_type"; |
| 12022 | case DW_TAG_subprogram: |
| 12023 | return "DW_TAG_subprogram"; |
| 12024 | case DW_TAG_template_type_param: |
| 12025 | return "DW_TAG_template_type_param"; |
| 12026 | case DW_TAG_template_value_param: |
| 12027 | return "DW_TAG_template_value_param"; |
| 12028 | case DW_TAG_thrown_type: |
| 12029 | return "DW_TAG_thrown_type"; |
| 12030 | case DW_TAG_try_block: |
| 12031 | return "DW_TAG_try_block"; |
| 12032 | case DW_TAG_variant_part: |
| 12033 | return "DW_TAG_variant_part"; |
| 12034 | case DW_TAG_variable: |
| 12035 | return "DW_TAG_variable"; |
| 12036 | case DW_TAG_volatile_type: |
| 12037 | return "DW_TAG_volatile_type"; |
| 12038 | case DW_TAG_dwarf_procedure: |
| 12039 | return "DW_TAG_dwarf_procedure"; |
| 12040 | case DW_TAG_restrict_type: |
| 12041 | return "DW_TAG_restrict_type"; |
| 12042 | case DW_TAG_interface_type: |
| 12043 | return "DW_TAG_interface_type"; |
| 12044 | case DW_TAG_namespace: |
| 12045 | return "DW_TAG_namespace"; |
| 12046 | case DW_TAG_imported_module: |
| 12047 | return "DW_TAG_imported_module"; |
| 12048 | case DW_TAG_unspecified_type: |
| 12049 | return "DW_TAG_unspecified_type"; |
| 12050 | case DW_TAG_partial_unit: |
| 12051 | return "DW_TAG_partial_unit"; |
| 12052 | case DW_TAG_imported_unit: |
| 12053 | return "DW_TAG_imported_unit"; |
| 12054 | case DW_TAG_condition: |
| 12055 | return "DW_TAG_condition"; |
| 12056 | case DW_TAG_shared_type: |
| 12057 | return "DW_TAG_shared_type"; |
| 12058 | case DW_TAG_type_unit: |
| 12059 | return "DW_TAG_type_unit"; |
| 12060 | case DW_TAG_MIPS_loop: |
| 12061 | return "DW_TAG_MIPS_loop"; |
| 12062 | case DW_TAG_HP_array_descriptor: |
| 12063 | return "DW_TAG_HP_array_descriptor"; |
| 12064 | case DW_TAG_format_label: |
| 12065 | return "DW_TAG_format_label"; |
| 12066 | case DW_TAG_function_template: |
| 12067 | return "DW_TAG_function_template"; |
| 12068 | case DW_TAG_class_template: |
| 12069 | return "DW_TAG_class_template"; |
| 12070 | case DW_TAG_GNU_BINCL: |
| 12071 | return "DW_TAG_GNU_BINCL"; |
| 12072 | case DW_TAG_GNU_EINCL: |
| 12073 | return "DW_TAG_GNU_EINCL"; |
| 12074 | case DW_TAG_upc_shared_type: |
| 12075 | return "DW_TAG_upc_shared_type"; |
| 12076 | case DW_TAG_upc_strict_type: |
| 12077 | return "DW_TAG_upc_strict_type"; |
| 12078 | case DW_TAG_upc_relaxed_type: |
| 12079 | return "DW_TAG_upc_relaxed_type"; |
| 12080 | case DW_TAG_PGI_kanji_type: |
| 12081 | return "DW_TAG_PGI_kanji_type"; |
| 12082 | case DW_TAG_PGI_interface_block: |
| 12083 | return "DW_TAG_PGI_interface_block"; |
| 12084 | default: |
| 12085 | return "DW_TAG_<unknown>"; |
| 12086 | } |
| 12087 | } |
| 12088 | |
| 12089 | /* Convert a DWARF attribute code into its string name. */ |
| 12090 | |
| 12091 | static char * |
| 12092 | dwarf_attr_name (unsigned attr) |
| 12093 | { |
| 12094 | switch (attr) |
| 12095 | { |
| 12096 | case DW_AT_sibling: |
| 12097 | return "DW_AT_sibling"; |
| 12098 | case DW_AT_location: |
| 12099 | return "DW_AT_location"; |
| 12100 | case DW_AT_name: |
| 12101 | return "DW_AT_name"; |
| 12102 | case DW_AT_ordering: |
| 12103 | return "DW_AT_ordering"; |
| 12104 | case DW_AT_subscr_data: |
| 12105 | return "DW_AT_subscr_data"; |
| 12106 | case DW_AT_byte_size: |
| 12107 | return "DW_AT_byte_size"; |
| 12108 | case DW_AT_bit_offset: |
| 12109 | return "DW_AT_bit_offset"; |
| 12110 | case DW_AT_bit_size: |
| 12111 | return "DW_AT_bit_size"; |
| 12112 | case DW_AT_element_list: |
| 12113 | return "DW_AT_element_list"; |
| 12114 | case DW_AT_stmt_list: |
| 12115 | return "DW_AT_stmt_list"; |
| 12116 | case DW_AT_low_pc: |
| 12117 | return "DW_AT_low_pc"; |
| 12118 | case DW_AT_high_pc: |
| 12119 | return "DW_AT_high_pc"; |
| 12120 | case DW_AT_language: |
| 12121 | return "DW_AT_language"; |
| 12122 | case DW_AT_member: |
| 12123 | return "DW_AT_member"; |
| 12124 | case DW_AT_discr: |
| 12125 | return "DW_AT_discr"; |
| 12126 | case DW_AT_discr_value: |
| 12127 | return "DW_AT_discr_value"; |
| 12128 | case DW_AT_visibility: |
| 12129 | return "DW_AT_visibility"; |
| 12130 | case DW_AT_import: |
| 12131 | return "DW_AT_import"; |
| 12132 | case DW_AT_string_length: |
| 12133 | return "DW_AT_string_length"; |
| 12134 | case DW_AT_common_reference: |
| 12135 | return "DW_AT_common_reference"; |
| 12136 | case DW_AT_comp_dir: |
| 12137 | return "DW_AT_comp_dir"; |
| 12138 | case DW_AT_const_value: |
| 12139 | return "DW_AT_const_value"; |
| 12140 | case DW_AT_containing_type: |
| 12141 | return "DW_AT_containing_type"; |
| 12142 | case DW_AT_default_value: |
| 12143 | return "DW_AT_default_value"; |
| 12144 | case DW_AT_inline: |
| 12145 | return "DW_AT_inline"; |
| 12146 | case DW_AT_is_optional: |
| 12147 | return "DW_AT_is_optional"; |
| 12148 | case DW_AT_lower_bound: |
| 12149 | return "DW_AT_lower_bound"; |
| 12150 | case DW_AT_producer: |
| 12151 | return "DW_AT_producer"; |
| 12152 | case DW_AT_prototyped: |
| 12153 | return "DW_AT_prototyped"; |
| 12154 | case DW_AT_return_addr: |
| 12155 | return "DW_AT_return_addr"; |
| 12156 | case DW_AT_start_scope: |
| 12157 | return "DW_AT_start_scope"; |
| 12158 | case DW_AT_bit_stride: |
| 12159 | return "DW_AT_bit_stride"; |
| 12160 | case DW_AT_upper_bound: |
| 12161 | return "DW_AT_upper_bound"; |
| 12162 | case DW_AT_abstract_origin: |
| 12163 | return "DW_AT_abstract_origin"; |
| 12164 | case DW_AT_accessibility: |
| 12165 | return "DW_AT_accessibility"; |
| 12166 | case DW_AT_address_class: |
| 12167 | return "DW_AT_address_class"; |
| 12168 | case DW_AT_artificial: |
| 12169 | return "DW_AT_artificial"; |
| 12170 | case DW_AT_base_types: |
| 12171 | return "DW_AT_base_types"; |
| 12172 | case DW_AT_calling_convention: |
| 12173 | return "DW_AT_calling_convention"; |
| 12174 | case DW_AT_count: |
| 12175 | return "DW_AT_count"; |
| 12176 | case DW_AT_data_member_location: |
| 12177 | return "DW_AT_data_member_location"; |
| 12178 | case DW_AT_decl_column: |
| 12179 | return "DW_AT_decl_column"; |
| 12180 | case DW_AT_decl_file: |
| 12181 | return "DW_AT_decl_file"; |
| 12182 | case DW_AT_decl_line: |
| 12183 | return "DW_AT_decl_line"; |
| 12184 | case DW_AT_declaration: |
| 12185 | return "DW_AT_declaration"; |
| 12186 | case DW_AT_discr_list: |
| 12187 | return "DW_AT_discr_list"; |
| 12188 | case DW_AT_encoding: |
| 12189 | return "DW_AT_encoding"; |
| 12190 | case DW_AT_external: |
| 12191 | return "DW_AT_external"; |
| 12192 | case DW_AT_frame_base: |
| 12193 | return "DW_AT_frame_base"; |
| 12194 | case DW_AT_friend: |
| 12195 | return "DW_AT_friend"; |
| 12196 | case DW_AT_identifier_case: |
| 12197 | return "DW_AT_identifier_case"; |
| 12198 | case DW_AT_macro_info: |
| 12199 | return "DW_AT_macro_info"; |
| 12200 | case DW_AT_namelist_items: |
| 12201 | return "DW_AT_namelist_items"; |
| 12202 | case DW_AT_priority: |
| 12203 | return "DW_AT_priority"; |
| 12204 | case DW_AT_segment: |
| 12205 | return "DW_AT_segment"; |
| 12206 | case DW_AT_specification: |
| 12207 | return "DW_AT_specification"; |
| 12208 | case DW_AT_static_link: |
| 12209 | return "DW_AT_static_link"; |
| 12210 | case DW_AT_type: |
| 12211 | return "DW_AT_type"; |
| 12212 | case DW_AT_use_location: |
| 12213 | return "DW_AT_use_location"; |
| 12214 | case DW_AT_variable_parameter: |
| 12215 | return "DW_AT_variable_parameter"; |
| 12216 | case DW_AT_virtuality: |
| 12217 | return "DW_AT_virtuality"; |
| 12218 | case DW_AT_vtable_elem_location: |
| 12219 | return "DW_AT_vtable_elem_location"; |
| 12220 | /* DWARF 3 values. */ |
| 12221 | case DW_AT_allocated: |
| 12222 | return "DW_AT_allocated"; |
| 12223 | case DW_AT_associated: |
| 12224 | return "DW_AT_associated"; |
| 12225 | case DW_AT_data_location: |
| 12226 | return "DW_AT_data_location"; |
| 12227 | case DW_AT_byte_stride: |
| 12228 | return "DW_AT_byte_stride"; |
| 12229 | case DW_AT_entry_pc: |
| 12230 | return "DW_AT_entry_pc"; |
| 12231 | case DW_AT_use_UTF8: |
| 12232 | return "DW_AT_use_UTF8"; |
| 12233 | case DW_AT_extension: |
| 12234 | return "DW_AT_extension"; |
| 12235 | case DW_AT_ranges: |
| 12236 | return "DW_AT_ranges"; |
| 12237 | case DW_AT_trampoline: |
| 12238 | return "DW_AT_trampoline"; |
| 12239 | case DW_AT_call_column: |
| 12240 | return "DW_AT_call_column"; |
| 12241 | case DW_AT_call_file: |
| 12242 | return "DW_AT_call_file"; |
| 12243 | case DW_AT_call_line: |
| 12244 | return "DW_AT_call_line"; |
| 12245 | case DW_AT_description: |
| 12246 | return "DW_AT_description"; |
| 12247 | case DW_AT_binary_scale: |
| 12248 | return "DW_AT_binary_scale"; |
| 12249 | case DW_AT_decimal_scale: |
| 12250 | return "DW_AT_decimal_scale"; |
| 12251 | case DW_AT_small: |
| 12252 | return "DW_AT_small"; |
| 12253 | case DW_AT_decimal_sign: |
| 12254 | return "DW_AT_decimal_sign"; |
| 12255 | case DW_AT_digit_count: |
| 12256 | return "DW_AT_digit_count"; |
| 12257 | case DW_AT_picture_string: |
| 12258 | return "DW_AT_picture_string"; |
| 12259 | case DW_AT_mutable: |
| 12260 | return "DW_AT_mutable"; |
| 12261 | case DW_AT_threads_scaled: |
| 12262 | return "DW_AT_threads_scaled"; |
| 12263 | case DW_AT_explicit: |
| 12264 | return "DW_AT_explicit"; |
| 12265 | case DW_AT_object_pointer: |
| 12266 | return "DW_AT_object_pointer"; |
| 12267 | case DW_AT_endianity: |
| 12268 | return "DW_AT_endianity"; |
| 12269 | case DW_AT_elemental: |
| 12270 | return "DW_AT_elemental"; |
| 12271 | case DW_AT_pure: |
| 12272 | return "DW_AT_pure"; |
| 12273 | case DW_AT_recursive: |
| 12274 | return "DW_AT_recursive"; |
| 12275 | /* DWARF 4 values. */ |
| 12276 | case DW_AT_signature: |
| 12277 | return "DW_AT_signature"; |
| 12278 | case DW_AT_linkage_name: |
| 12279 | return "DW_AT_linkage_name"; |
| 12280 | /* SGI/MIPS extensions. */ |
| 12281 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
| 12282 | case DW_AT_MIPS_fde: |
| 12283 | return "DW_AT_MIPS_fde"; |
| 12284 | #endif |
| 12285 | case DW_AT_MIPS_loop_begin: |
| 12286 | return "DW_AT_MIPS_loop_begin"; |
| 12287 | case DW_AT_MIPS_tail_loop_begin: |
| 12288 | return "DW_AT_MIPS_tail_loop_begin"; |
| 12289 | case DW_AT_MIPS_epilog_begin: |
| 12290 | return "DW_AT_MIPS_epilog_begin"; |
| 12291 | case DW_AT_MIPS_loop_unroll_factor: |
| 12292 | return "DW_AT_MIPS_loop_unroll_factor"; |
| 12293 | case DW_AT_MIPS_software_pipeline_depth: |
| 12294 | return "DW_AT_MIPS_software_pipeline_depth"; |
| 12295 | case DW_AT_MIPS_linkage_name: |
| 12296 | return "DW_AT_MIPS_linkage_name"; |
| 12297 | case DW_AT_MIPS_stride: |
| 12298 | return "DW_AT_MIPS_stride"; |
| 12299 | case DW_AT_MIPS_abstract_name: |
| 12300 | return "DW_AT_MIPS_abstract_name"; |
| 12301 | case DW_AT_MIPS_clone_origin: |
| 12302 | return "DW_AT_MIPS_clone_origin"; |
| 12303 | case DW_AT_MIPS_has_inlines: |
| 12304 | return "DW_AT_MIPS_has_inlines"; |
| 12305 | /* HP extensions. */ |
| 12306 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
| 12307 | case DW_AT_HP_block_index: |
| 12308 | return "DW_AT_HP_block_index"; |
| 12309 | #endif |
| 12310 | case DW_AT_HP_unmodifiable: |
| 12311 | return "DW_AT_HP_unmodifiable"; |
| 12312 | case DW_AT_HP_actuals_stmt_list: |
| 12313 | return "DW_AT_HP_actuals_stmt_list"; |
| 12314 | case DW_AT_HP_proc_per_section: |
| 12315 | return "DW_AT_HP_proc_per_section"; |
| 12316 | case DW_AT_HP_raw_data_ptr: |
| 12317 | return "DW_AT_HP_raw_data_ptr"; |
| 12318 | case DW_AT_HP_pass_by_reference: |
| 12319 | return "DW_AT_HP_pass_by_reference"; |
| 12320 | case DW_AT_HP_opt_level: |
| 12321 | return "DW_AT_HP_opt_level"; |
| 12322 | case DW_AT_HP_prof_version_id: |
| 12323 | return "DW_AT_HP_prof_version_id"; |
| 12324 | case DW_AT_HP_opt_flags: |
| 12325 | return "DW_AT_HP_opt_flags"; |
| 12326 | case DW_AT_HP_cold_region_low_pc: |
| 12327 | return "DW_AT_HP_cold_region_low_pc"; |
| 12328 | case DW_AT_HP_cold_region_high_pc: |
| 12329 | return "DW_AT_HP_cold_region_high_pc"; |
| 12330 | case DW_AT_HP_all_variables_modifiable: |
| 12331 | return "DW_AT_HP_all_variables_modifiable"; |
| 12332 | case DW_AT_HP_linkage_name: |
| 12333 | return "DW_AT_HP_linkage_name"; |
| 12334 | case DW_AT_HP_prof_flags: |
| 12335 | return "DW_AT_HP_prof_flags"; |
| 12336 | /* GNU extensions. */ |
| 12337 | case DW_AT_sf_names: |
| 12338 | return "DW_AT_sf_names"; |
| 12339 | case DW_AT_src_info: |
| 12340 | return "DW_AT_src_info"; |
| 12341 | case DW_AT_mac_info: |
| 12342 | return "DW_AT_mac_info"; |
| 12343 | case DW_AT_src_coords: |
| 12344 | return "DW_AT_src_coords"; |
| 12345 | case DW_AT_body_begin: |
| 12346 | return "DW_AT_body_begin"; |
| 12347 | case DW_AT_body_end: |
| 12348 | return "DW_AT_body_end"; |
| 12349 | case DW_AT_GNU_vector: |
| 12350 | return "DW_AT_GNU_vector"; |
| 12351 | case DW_AT_GNU_odr_signature: |
| 12352 | return "DW_AT_GNU_odr_signature"; |
| 12353 | /* VMS extensions. */ |
| 12354 | case DW_AT_VMS_rtnbeg_pd_address: |
| 12355 | return "DW_AT_VMS_rtnbeg_pd_address"; |
| 12356 | /* UPC extension. */ |
| 12357 | case DW_AT_upc_threads_scaled: |
| 12358 | return "DW_AT_upc_threads_scaled"; |
| 12359 | /* PGI (STMicroelectronics) extensions. */ |
| 12360 | case DW_AT_PGI_lbase: |
| 12361 | return "DW_AT_PGI_lbase"; |
| 12362 | case DW_AT_PGI_soffset: |
| 12363 | return "DW_AT_PGI_soffset"; |
| 12364 | case DW_AT_PGI_lstride: |
| 12365 | return "DW_AT_PGI_lstride"; |
| 12366 | default: |
| 12367 | return "DW_AT_<unknown>"; |
| 12368 | } |
| 12369 | } |
| 12370 | |
| 12371 | /* Convert a DWARF value form code into its string name. */ |
| 12372 | |
| 12373 | static char * |
| 12374 | dwarf_form_name (unsigned form) |
| 12375 | { |
| 12376 | switch (form) |
| 12377 | { |
| 12378 | case DW_FORM_addr: |
| 12379 | return "DW_FORM_addr"; |
| 12380 | case DW_FORM_block2: |
| 12381 | return "DW_FORM_block2"; |
| 12382 | case DW_FORM_block4: |
| 12383 | return "DW_FORM_block4"; |
| 12384 | case DW_FORM_data2: |
| 12385 | return "DW_FORM_data2"; |
| 12386 | case DW_FORM_data4: |
| 12387 | return "DW_FORM_data4"; |
| 12388 | case DW_FORM_data8: |
| 12389 | return "DW_FORM_data8"; |
| 12390 | case DW_FORM_string: |
| 12391 | return "DW_FORM_string"; |
| 12392 | case DW_FORM_block: |
| 12393 | return "DW_FORM_block"; |
| 12394 | case DW_FORM_block1: |
| 12395 | return "DW_FORM_block1"; |
| 12396 | case DW_FORM_data1: |
| 12397 | return "DW_FORM_data1"; |
| 12398 | case DW_FORM_flag: |
| 12399 | return "DW_FORM_flag"; |
| 12400 | case DW_FORM_sdata: |
| 12401 | return "DW_FORM_sdata"; |
| 12402 | case DW_FORM_strp: |
| 12403 | return "DW_FORM_strp"; |
| 12404 | case DW_FORM_udata: |
| 12405 | return "DW_FORM_udata"; |
| 12406 | case DW_FORM_ref_addr: |
| 12407 | return "DW_FORM_ref_addr"; |
| 12408 | case DW_FORM_ref1: |
| 12409 | return "DW_FORM_ref1"; |
| 12410 | case DW_FORM_ref2: |
| 12411 | return "DW_FORM_ref2"; |
| 12412 | case DW_FORM_ref4: |
| 12413 | return "DW_FORM_ref4"; |
| 12414 | case DW_FORM_ref8: |
| 12415 | return "DW_FORM_ref8"; |
| 12416 | case DW_FORM_ref_udata: |
| 12417 | return "DW_FORM_ref_udata"; |
| 12418 | case DW_FORM_indirect: |
| 12419 | return "DW_FORM_indirect"; |
| 12420 | case DW_FORM_sec_offset: |
| 12421 | return "DW_FORM_sec_offset"; |
| 12422 | case DW_FORM_exprloc: |
| 12423 | return "DW_FORM_exprloc"; |
| 12424 | case DW_FORM_flag_present: |
| 12425 | return "DW_FORM_flag_present"; |
| 12426 | case DW_FORM_sig8: |
| 12427 | return "DW_FORM_sig8"; |
| 12428 | default: |
| 12429 | return "DW_FORM_<unknown>"; |
| 12430 | } |
| 12431 | } |
| 12432 | |
| 12433 | /* Convert a DWARF stack opcode into its string name. */ |
| 12434 | |
| 12435 | const char * |
| 12436 | dwarf_stack_op_name (unsigned op, int def) |
| 12437 | { |
| 12438 | switch (op) |
| 12439 | { |
| 12440 | case DW_OP_addr: |
| 12441 | return "DW_OP_addr"; |
| 12442 | case DW_OP_deref: |
| 12443 | return "DW_OP_deref"; |
| 12444 | case DW_OP_const1u: |
| 12445 | return "DW_OP_const1u"; |
| 12446 | case DW_OP_const1s: |
| 12447 | return "DW_OP_const1s"; |
| 12448 | case DW_OP_const2u: |
| 12449 | return "DW_OP_const2u"; |
| 12450 | case DW_OP_const2s: |
| 12451 | return "DW_OP_const2s"; |
| 12452 | case DW_OP_const4u: |
| 12453 | return "DW_OP_const4u"; |
| 12454 | case DW_OP_const4s: |
| 12455 | return "DW_OP_const4s"; |
| 12456 | case DW_OP_const8u: |
| 12457 | return "DW_OP_const8u"; |
| 12458 | case DW_OP_const8s: |
| 12459 | return "DW_OP_const8s"; |
| 12460 | case DW_OP_constu: |
| 12461 | return "DW_OP_constu"; |
| 12462 | case DW_OP_consts: |
| 12463 | return "DW_OP_consts"; |
| 12464 | case DW_OP_dup: |
| 12465 | return "DW_OP_dup"; |
| 12466 | case DW_OP_drop: |
| 12467 | return "DW_OP_drop"; |
| 12468 | case DW_OP_over: |
| 12469 | return "DW_OP_over"; |
| 12470 | case DW_OP_pick: |
| 12471 | return "DW_OP_pick"; |
| 12472 | case DW_OP_swap: |
| 12473 | return "DW_OP_swap"; |
| 12474 | case DW_OP_rot: |
| 12475 | return "DW_OP_rot"; |
| 12476 | case DW_OP_xderef: |
| 12477 | return "DW_OP_xderef"; |
| 12478 | case DW_OP_abs: |
| 12479 | return "DW_OP_abs"; |
| 12480 | case DW_OP_and: |
| 12481 | return "DW_OP_and"; |
| 12482 | case DW_OP_div: |
| 12483 | return "DW_OP_div"; |
| 12484 | case DW_OP_minus: |
| 12485 | return "DW_OP_minus"; |
| 12486 | case DW_OP_mod: |
| 12487 | return "DW_OP_mod"; |
| 12488 | case DW_OP_mul: |
| 12489 | return "DW_OP_mul"; |
| 12490 | case DW_OP_neg: |
| 12491 | return "DW_OP_neg"; |
| 12492 | case DW_OP_not: |
| 12493 | return "DW_OP_not"; |
| 12494 | case DW_OP_or: |
| 12495 | return "DW_OP_or"; |
| 12496 | case DW_OP_plus: |
| 12497 | return "DW_OP_plus"; |
| 12498 | case DW_OP_plus_uconst: |
| 12499 | return "DW_OP_plus_uconst"; |
| 12500 | case DW_OP_shl: |
| 12501 | return "DW_OP_shl"; |
| 12502 | case DW_OP_shr: |
| 12503 | return "DW_OP_shr"; |
| 12504 | case DW_OP_shra: |
| 12505 | return "DW_OP_shra"; |
| 12506 | case DW_OP_xor: |
| 12507 | return "DW_OP_xor"; |
| 12508 | case DW_OP_bra: |
| 12509 | return "DW_OP_bra"; |
| 12510 | case DW_OP_eq: |
| 12511 | return "DW_OP_eq"; |
| 12512 | case DW_OP_ge: |
| 12513 | return "DW_OP_ge"; |
| 12514 | case DW_OP_gt: |
| 12515 | return "DW_OP_gt"; |
| 12516 | case DW_OP_le: |
| 12517 | return "DW_OP_le"; |
| 12518 | case DW_OP_lt: |
| 12519 | return "DW_OP_lt"; |
| 12520 | case DW_OP_ne: |
| 12521 | return "DW_OP_ne"; |
| 12522 | case DW_OP_skip: |
| 12523 | return "DW_OP_skip"; |
| 12524 | case DW_OP_lit0: |
| 12525 | return "DW_OP_lit0"; |
| 12526 | case DW_OP_lit1: |
| 12527 | return "DW_OP_lit1"; |
| 12528 | case DW_OP_lit2: |
| 12529 | return "DW_OP_lit2"; |
| 12530 | case DW_OP_lit3: |
| 12531 | return "DW_OP_lit3"; |
| 12532 | case DW_OP_lit4: |
| 12533 | return "DW_OP_lit4"; |
| 12534 | case DW_OP_lit5: |
| 12535 | return "DW_OP_lit5"; |
| 12536 | case DW_OP_lit6: |
| 12537 | return "DW_OP_lit6"; |
| 12538 | case DW_OP_lit7: |
| 12539 | return "DW_OP_lit7"; |
| 12540 | case DW_OP_lit8: |
| 12541 | return "DW_OP_lit8"; |
| 12542 | case DW_OP_lit9: |
| 12543 | return "DW_OP_lit9"; |
| 12544 | case DW_OP_lit10: |
| 12545 | return "DW_OP_lit10"; |
| 12546 | case DW_OP_lit11: |
| 12547 | return "DW_OP_lit11"; |
| 12548 | case DW_OP_lit12: |
| 12549 | return "DW_OP_lit12"; |
| 12550 | case DW_OP_lit13: |
| 12551 | return "DW_OP_lit13"; |
| 12552 | case DW_OP_lit14: |
| 12553 | return "DW_OP_lit14"; |
| 12554 | case DW_OP_lit15: |
| 12555 | return "DW_OP_lit15"; |
| 12556 | case DW_OP_lit16: |
| 12557 | return "DW_OP_lit16"; |
| 12558 | case DW_OP_lit17: |
| 12559 | return "DW_OP_lit17"; |
| 12560 | case DW_OP_lit18: |
| 12561 | return "DW_OP_lit18"; |
| 12562 | case DW_OP_lit19: |
| 12563 | return "DW_OP_lit19"; |
| 12564 | case DW_OP_lit20: |
| 12565 | return "DW_OP_lit20"; |
| 12566 | case DW_OP_lit21: |
| 12567 | return "DW_OP_lit21"; |
| 12568 | case DW_OP_lit22: |
| 12569 | return "DW_OP_lit22"; |
| 12570 | case DW_OP_lit23: |
| 12571 | return "DW_OP_lit23"; |
| 12572 | case DW_OP_lit24: |
| 12573 | return "DW_OP_lit24"; |
| 12574 | case DW_OP_lit25: |
| 12575 | return "DW_OP_lit25"; |
| 12576 | case DW_OP_lit26: |
| 12577 | return "DW_OP_lit26"; |
| 12578 | case DW_OP_lit27: |
| 12579 | return "DW_OP_lit27"; |
| 12580 | case DW_OP_lit28: |
| 12581 | return "DW_OP_lit28"; |
| 12582 | case DW_OP_lit29: |
| 12583 | return "DW_OP_lit29"; |
| 12584 | case DW_OP_lit30: |
| 12585 | return "DW_OP_lit30"; |
| 12586 | case DW_OP_lit31: |
| 12587 | return "DW_OP_lit31"; |
| 12588 | case DW_OP_reg0: |
| 12589 | return "DW_OP_reg0"; |
| 12590 | case DW_OP_reg1: |
| 12591 | return "DW_OP_reg1"; |
| 12592 | case DW_OP_reg2: |
| 12593 | return "DW_OP_reg2"; |
| 12594 | case DW_OP_reg3: |
| 12595 | return "DW_OP_reg3"; |
| 12596 | case DW_OP_reg4: |
| 12597 | return "DW_OP_reg4"; |
| 12598 | case DW_OP_reg5: |
| 12599 | return "DW_OP_reg5"; |
| 12600 | case DW_OP_reg6: |
| 12601 | return "DW_OP_reg6"; |
| 12602 | case DW_OP_reg7: |
| 12603 | return "DW_OP_reg7"; |
| 12604 | case DW_OP_reg8: |
| 12605 | return "DW_OP_reg8"; |
| 12606 | case DW_OP_reg9: |
| 12607 | return "DW_OP_reg9"; |
| 12608 | case DW_OP_reg10: |
| 12609 | return "DW_OP_reg10"; |
| 12610 | case DW_OP_reg11: |
| 12611 | return "DW_OP_reg11"; |
| 12612 | case DW_OP_reg12: |
| 12613 | return "DW_OP_reg12"; |
| 12614 | case DW_OP_reg13: |
| 12615 | return "DW_OP_reg13"; |
| 12616 | case DW_OP_reg14: |
| 12617 | return "DW_OP_reg14"; |
| 12618 | case DW_OP_reg15: |
| 12619 | return "DW_OP_reg15"; |
| 12620 | case DW_OP_reg16: |
| 12621 | return "DW_OP_reg16"; |
| 12622 | case DW_OP_reg17: |
| 12623 | return "DW_OP_reg17"; |
| 12624 | case DW_OP_reg18: |
| 12625 | return "DW_OP_reg18"; |
| 12626 | case DW_OP_reg19: |
| 12627 | return "DW_OP_reg19"; |
| 12628 | case DW_OP_reg20: |
| 12629 | return "DW_OP_reg20"; |
| 12630 | case DW_OP_reg21: |
| 12631 | return "DW_OP_reg21"; |
| 12632 | case DW_OP_reg22: |
| 12633 | return "DW_OP_reg22"; |
| 12634 | case DW_OP_reg23: |
| 12635 | return "DW_OP_reg23"; |
| 12636 | case DW_OP_reg24: |
| 12637 | return "DW_OP_reg24"; |
| 12638 | case DW_OP_reg25: |
| 12639 | return "DW_OP_reg25"; |
| 12640 | case DW_OP_reg26: |
| 12641 | return "DW_OP_reg26"; |
| 12642 | case DW_OP_reg27: |
| 12643 | return "DW_OP_reg27"; |
| 12644 | case DW_OP_reg28: |
| 12645 | return "DW_OP_reg28"; |
| 12646 | case DW_OP_reg29: |
| 12647 | return "DW_OP_reg29"; |
| 12648 | case DW_OP_reg30: |
| 12649 | return "DW_OP_reg30"; |
| 12650 | case DW_OP_reg31: |
| 12651 | return "DW_OP_reg31"; |
| 12652 | case DW_OP_breg0: |
| 12653 | return "DW_OP_breg0"; |
| 12654 | case DW_OP_breg1: |
| 12655 | return "DW_OP_breg1"; |
| 12656 | case DW_OP_breg2: |
| 12657 | return "DW_OP_breg2"; |
| 12658 | case DW_OP_breg3: |
| 12659 | return "DW_OP_breg3"; |
| 12660 | case DW_OP_breg4: |
| 12661 | return "DW_OP_breg4"; |
| 12662 | case DW_OP_breg5: |
| 12663 | return "DW_OP_breg5"; |
| 12664 | case DW_OP_breg6: |
| 12665 | return "DW_OP_breg6"; |
| 12666 | case DW_OP_breg7: |
| 12667 | return "DW_OP_breg7"; |
| 12668 | case DW_OP_breg8: |
| 12669 | return "DW_OP_breg8"; |
| 12670 | case DW_OP_breg9: |
| 12671 | return "DW_OP_breg9"; |
| 12672 | case DW_OP_breg10: |
| 12673 | return "DW_OP_breg10"; |
| 12674 | case DW_OP_breg11: |
| 12675 | return "DW_OP_breg11"; |
| 12676 | case DW_OP_breg12: |
| 12677 | return "DW_OP_breg12"; |
| 12678 | case DW_OP_breg13: |
| 12679 | return "DW_OP_breg13"; |
| 12680 | case DW_OP_breg14: |
| 12681 | return "DW_OP_breg14"; |
| 12682 | case DW_OP_breg15: |
| 12683 | return "DW_OP_breg15"; |
| 12684 | case DW_OP_breg16: |
| 12685 | return "DW_OP_breg16"; |
| 12686 | case DW_OP_breg17: |
| 12687 | return "DW_OP_breg17"; |
| 12688 | case DW_OP_breg18: |
| 12689 | return "DW_OP_breg18"; |
| 12690 | case DW_OP_breg19: |
| 12691 | return "DW_OP_breg19"; |
| 12692 | case DW_OP_breg20: |
| 12693 | return "DW_OP_breg20"; |
| 12694 | case DW_OP_breg21: |
| 12695 | return "DW_OP_breg21"; |
| 12696 | case DW_OP_breg22: |
| 12697 | return "DW_OP_breg22"; |
| 12698 | case DW_OP_breg23: |
| 12699 | return "DW_OP_breg23"; |
| 12700 | case DW_OP_breg24: |
| 12701 | return "DW_OP_breg24"; |
| 12702 | case DW_OP_breg25: |
| 12703 | return "DW_OP_breg25"; |
| 12704 | case DW_OP_breg26: |
| 12705 | return "DW_OP_breg26"; |
| 12706 | case DW_OP_breg27: |
| 12707 | return "DW_OP_breg27"; |
| 12708 | case DW_OP_breg28: |
| 12709 | return "DW_OP_breg28"; |
| 12710 | case DW_OP_breg29: |
| 12711 | return "DW_OP_breg29"; |
| 12712 | case DW_OP_breg30: |
| 12713 | return "DW_OP_breg30"; |
| 12714 | case DW_OP_breg31: |
| 12715 | return "DW_OP_breg31"; |
| 12716 | case DW_OP_regx: |
| 12717 | return "DW_OP_regx"; |
| 12718 | case DW_OP_fbreg: |
| 12719 | return "DW_OP_fbreg"; |
| 12720 | case DW_OP_bregx: |
| 12721 | return "DW_OP_bregx"; |
| 12722 | case DW_OP_piece: |
| 12723 | return "DW_OP_piece"; |
| 12724 | case DW_OP_deref_size: |
| 12725 | return "DW_OP_deref_size"; |
| 12726 | case DW_OP_xderef_size: |
| 12727 | return "DW_OP_xderef_size"; |
| 12728 | case DW_OP_nop: |
| 12729 | return "DW_OP_nop"; |
| 12730 | /* DWARF 3 extensions. */ |
| 12731 | case DW_OP_push_object_address: |
| 12732 | return "DW_OP_push_object_address"; |
| 12733 | case DW_OP_call2: |
| 12734 | return "DW_OP_call2"; |
| 12735 | case DW_OP_call4: |
| 12736 | return "DW_OP_call4"; |
| 12737 | case DW_OP_call_ref: |
| 12738 | return "DW_OP_call_ref"; |
| 12739 | case DW_OP_form_tls_address: |
| 12740 | return "DW_OP_form_tls_address"; |
| 12741 | case DW_OP_call_frame_cfa: |
| 12742 | return "DW_OP_call_frame_cfa"; |
| 12743 | case DW_OP_bit_piece: |
| 12744 | return "DW_OP_bit_piece"; |
| 12745 | /* DWARF 4 extensions. */ |
| 12746 | case DW_OP_implicit_value: |
| 12747 | return "DW_OP_implicit_value"; |
| 12748 | case DW_OP_stack_value: |
| 12749 | return "DW_OP_stack_value"; |
| 12750 | /* GNU extensions. */ |
| 12751 | case DW_OP_GNU_push_tls_address: |
| 12752 | return "DW_OP_GNU_push_tls_address"; |
| 12753 | case DW_OP_GNU_uninit: |
| 12754 | return "DW_OP_GNU_uninit"; |
| 12755 | case DW_OP_GNU_implicit_pointer: |
| 12756 | return "DW_OP_GNU_implicit_pointer"; |
| 12757 | default: |
| 12758 | return def ? "OP_<unknown>" : NULL; |
| 12759 | } |
| 12760 | } |
| 12761 | |
| 12762 | static char * |
| 12763 | dwarf_bool_name (unsigned mybool) |
| 12764 | { |
| 12765 | if (mybool) |
| 12766 | return "TRUE"; |
| 12767 | else |
| 12768 | return "FALSE"; |
| 12769 | } |
| 12770 | |
| 12771 | /* Convert a DWARF type code into its string name. */ |
| 12772 | |
| 12773 | static char * |
| 12774 | dwarf_type_encoding_name (unsigned enc) |
| 12775 | { |
| 12776 | switch (enc) |
| 12777 | { |
| 12778 | case DW_ATE_void: |
| 12779 | return "DW_ATE_void"; |
| 12780 | case DW_ATE_address: |
| 12781 | return "DW_ATE_address"; |
| 12782 | case DW_ATE_boolean: |
| 12783 | return "DW_ATE_boolean"; |
| 12784 | case DW_ATE_complex_float: |
| 12785 | return "DW_ATE_complex_float"; |
| 12786 | case DW_ATE_float: |
| 12787 | return "DW_ATE_float"; |
| 12788 | case DW_ATE_signed: |
| 12789 | return "DW_ATE_signed"; |
| 12790 | case DW_ATE_signed_char: |
| 12791 | return "DW_ATE_signed_char"; |
| 12792 | case DW_ATE_unsigned: |
| 12793 | return "DW_ATE_unsigned"; |
| 12794 | case DW_ATE_unsigned_char: |
| 12795 | return "DW_ATE_unsigned_char"; |
| 12796 | /* DWARF 3. */ |
| 12797 | case DW_ATE_imaginary_float: |
| 12798 | return "DW_ATE_imaginary_float"; |
| 12799 | case DW_ATE_packed_decimal: |
| 12800 | return "DW_ATE_packed_decimal"; |
| 12801 | case DW_ATE_numeric_string: |
| 12802 | return "DW_ATE_numeric_string"; |
| 12803 | case DW_ATE_edited: |
| 12804 | return "DW_ATE_edited"; |
| 12805 | case DW_ATE_signed_fixed: |
| 12806 | return "DW_ATE_signed_fixed"; |
| 12807 | case DW_ATE_unsigned_fixed: |
| 12808 | return "DW_ATE_unsigned_fixed"; |
| 12809 | case DW_ATE_decimal_float: |
| 12810 | return "DW_ATE_decimal_float"; |
| 12811 | /* DWARF 4. */ |
| 12812 | case DW_ATE_UTF: |
| 12813 | return "DW_ATE_UTF"; |
| 12814 | /* HP extensions. */ |
| 12815 | case DW_ATE_HP_float80: |
| 12816 | return "DW_ATE_HP_float80"; |
| 12817 | case DW_ATE_HP_complex_float80: |
| 12818 | return "DW_ATE_HP_complex_float80"; |
| 12819 | case DW_ATE_HP_float128: |
| 12820 | return "DW_ATE_HP_float128"; |
| 12821 | case DW_ATE_HP_complex_float128: |
| 12822 | return "DW_ATE_HP_complex_float128"; |
| 12823 | case DW_ATE_HP_floathpintel: |
| 12824 | return "DW_ATE_HP_floathpintel"; |
| 12825 | case DW_ATE_HP_imaginary_float80: |
| 12826 | return "DW_ATE_HP_imaginary_float80"; |
| 12827 | case DW_ATE_HP_imaginary_float128: |
| 12828 | return "DW_ATE_HP_imaginary_float128"; |
| 12829 | default: |
| 12830 | return "DW_ATE_<unknown>"; |
| 12831 | } |
| 12832 | } |
| 12833 | |
| 12834 | /* Convert a DWARF call frame info operation to its string name. */ |
| 12835 | |
| 12836 | #if 0 |
| 12837 | static char * |
| 12838 | dwarf_cfi_name (unsigned cfi_opc) |
| 12839 | { |
| 12840 | switch (cfi_opc) |
| 12841 | { |
| 12842 | case DW_CFA_advance_loc: |
| 12843 | return "DW_CFA_advance_loc"; |
| 12844 | case DW_CFA_offset: |
| 12845 | return "DW_CFA_offset"; |
| 12846 | case DW_CFA_restore: |
| 12847 | return "DW_CFA_restore"; |
| 12848 | case DW_CFA_nop: |
| 12849 | return "DW_CFA_nop"; |
| 12850 | case DW_CFA_set_loc: |
| 12851 | return "DW_CFA_set_loc"; |
| 12852 | case DW_CFA_advance_loc1: |
| 12853 | return "DW_CFA_advance_loc1"; |
| 12854 | case DW_CFA_advance_loc2: |
| 12855 | return "DW_CFA_advance_loc2"; |
| 12856 | case DW_CFA_advance_loc4: |
| 12857 | return "DW_CFA_advance_loc4"; |
| 12858 | case DW_CFA_offset_extended: |
| 12859 | return "DW_CFA_offset_extended"; |
| 12860 | case DW_CFA_restore_extended: |
| 12861 | return "DW_CFA_restore_extended"; |
| 12862 | case DW_CFA_undefined: |
| 12863 | return "DW_CFA_undefined"; |
| 12864 | case DW_CFA_same_value: |
| 12865 | return "DW_CFA_same_value"; |
| 12866 | case DW_CFA_register: |
| 12867 | return "DW_CFA_register"; |
| 12868 | case DW_CFA_remember_state: |
| 12869 | return "DW_CFA_remember_state"; |
| 12870 | case DW_CFA_restore_state: |
| 12871 | return "DW_CFA_restore_state"; |
| 12872 | case DW_CFA_def_cfa: |
| 12873 | return "DW_CFA_def_cfa"; |
| 12874 | case DW_CFA_def_cfa_register: |
| 12875 | return "DW_CFA_def_cfa_register"; |
| 12876 | case DW_CFA_def_cfa_offset: |
| 12877 | return "DW_CFA_def_cfa_offset"; |
| 12878 | /* DWARF 3. */ |
| 12879 | case DW_CFA_def_cfa_expression: |
| 12880 | return "DW_CFA_def_cfa_expression"; |
| 12881 | case DW_CFA_expression: |
| 12882 | return "DW_CFA_expression"; |
| 12883 | case DW_CFA_offset_extended_sf: |
| 12884 | return "DW_CFA_offset_extended_sf"; |
| 12885 | case DW_CFA_def_cfa_sf: |
| 12886 | return "DW_CFA_def_cfa_sf"; |
| 12887 | case DW_CFA_def_cfa_offset_sf: |
| 12888 | return "DW_CFA_def_cfa_offset_sf"; |
| 12889 | case DW_CFA_val_offset: |
| 12890 | return "DW_CFA_val_offset"; |
| 12891 | case DW_CFA_val_offset_sf: |
| 12892 | return "DW_CFA_val_offset_sf"; |
| 12893 | case DW_CFA_val_expression: |
| 12894 | return "DW_CFA_val_expression"; |
| 12895 | /* SGI/MIPS specific. */ |
| 12896 | case DW_CFA_MIPS_advance_loc8: |
| 12897 | return "DW_CFA_MIPS_advance_loc8"; |
| 12898 | /* GNU extensions. */ |
| 12899 | case DW_CFA_GNU_window_save: |
| 12900 | return "DW_CFA_GNU_window_save"; |
| 12901 | case DW_CFA_GNU_args_size: |
| 12902 | return "DW_CFA_GNU_args_size"; |
| 12903 | case DW_CFA_GNU_negative_offset_extended: |
| 12904 | return "DW_CFA_GNU_negative_offset_extended"; |
| 12905 | default: |
| 12906 | return "DW_CFA_<unknown>"; |
| 12907 | } |
| 12908 | } |
| 12909 | #endif |
| 12910 | |
| 12911 | static void |
| 12912 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
| 12913 | { |
| 12914 | unsigned int i; |
| 12915 | |
| 12916 | print_spaces (indent, f); |
| 12917 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", |
| 12918 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
| 12919 | |
| 12920 | if (die->parent != NULL) |
| 12921 | { |
| 12922 | print_spaces (indent, f); |
| 12923 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", |
| 12924 | die->parent->offset); |
| 12925 | } |
| 12926 | |
| 12927 | print_spaces (indent, f); |
| 12928 | fprintf_unfiltered (f, " has children: %s\n", |
| 12929 | dwarf_bool_name (die->child != NULL)); |
| 12930 | |
| 12931 | print_spaces (indent, f); |
| 12932 | fprintf_unfiltered (f, " attributes:\n"); |
| 12933 | |
| 12934 | for (i = 0; i < die->num_attrs; ++i) |
| 12935 | { |
| 12936 | print_spaces (indent, f); |
| 12937 | fprintf_unfiltered (f, " %s (%s) ", |
| 12938 | dwarf_attr_name (die->attrs[i].name), |
| 12939 | dwarf_form_name (die->attrs[i].form)); |
| 12940 | |
| 12941 | switch (die->attrs[i].form) |
| 12942 | { |
| 12943 | case DW_FORM_ref_addr: |
| 12944 | case DW_FORM_addr: |
| 12945 | fprintf_unfiltered (f, "address: "); |
| 12946 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
| 12947 | break; |
| 12948 | case DW_FORM_block2: |
| 12949 | case DW_FORM_block4: |
| 12950 | case DW_FORM_block: |
| 12951 | case DW_FORM_block1: |
| 12952 | fprintf_unfiltered (f, "block: size %d", |
| 12953 | DW_BLOCK (&die->attrs[i])->size); |
| 12954 | break; |
| 12955 | case DW_FORM_exprloc: |
| 12956 | fprintf_unfiltered (f, "expression: size %u", |
| 12957 | DW_BLOCK (&die->attrs[i])->size); |
| 12958 | break; |
| 12959 | case DW_FORM_ref1: |
| 12960 | case DW_FORM_ref2: |
| 12961 | case DW_FORM_ref4: |
| 12962 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
| 12963 | (long) (DW_ADDR (&die->attrs[i]))); |
| 12964 | break; |
| 12965 | case DW_FORM_data1: |
| 12966 | case DW_FORM_data2: |
| 12967 | case DW_FORM_data4: |
| 12968 | case DW_FORM_data8: |
| 12969 | case DW_FORM_udata: |
| 12970 | case DW_FORM_sdata: |
| 12971 | fprintf_unfiltered (f, "constant: %s", |
| 12972 | pulongest (DW_UNSND (&die->attrs[i]))); |
| 12973 | break; |
| 12974 | case DW_FORM_sec_offset: |
| 12975 | fprintf_unfiltered (f, "section offset: %s", |
| 12976 | pulongest (DW_UNSND (&die->attrs[i]))); |
| 12977 | break; |
| 12978 | case DW_FORM_sig8: |
| 12979 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
| 12980 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", |
| 12981 | DW_SIGNATURED_TYPE (&die->attrs[i])->offset); |
| 12982 | else |
| 12983 | fprintf_unfiltered (f, "signatured type, offset: unknown"); |
| 12984 | break; |
| 12985 | case DW_FORM_string: |
| 12986 | case DW_FORM_strp: |
| 12987 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
| 12988 | DW_STRING (&die->attrs[i]) |
| 12989 | ? DW_STRING (&die->attrs[i]) : "", |
| 12990 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); |
| 12991 | break; |
| 12992 | case DW_FORM_flag: |
| 12993 | if (DW_UNSND (&die->attrs[i])) |
| 12994 | fprintf_unfiltered (f, "flag: TRUE"); |
| 12995 | else |
| 12996 | fprintf_unfiltered (f, "flag: FALSE"); |
| 12997 | break; |
| 12998 | case DW_FORM_flag_present: |
| 12999 | fprintf_unfiltered (f, "flag: TRUE"); |
| 13000 | break; |
| 13001 | case DW_FORM_indirect: |
| 13002 | /* The reader will have reduced the indirect form to |
| 13003 | the "base form" so this form should not occur. */ |
| 13004 | fprintf_unfiltered (f, |
| 13005 | "unexpected attribute form: DW_FORM_indirect"); |
| 13006 | break; |
| 13007 | default: |
| 13008 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
| 13009 | die->attrs[i].form); |
| 13010 | break; |
| 13011 | } |
| 13012 | fprintf_unfiltered (f, "\n"); |
| 13013 | } |
| 13014 | } |
| 13015 | |
| 13016 | static void |
| 13017 | dump_die_for_error (struct die_info *die) |
| 13018 | { |
| 13019 | dump_die_shallow (gdb_stderr, 0, die); |
| 13020 | } |
| 13021 | |
| 13022 | static void |
| 13023 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) |
| 13024 | { |
| 13025 | int indent = level * 4; |
| 13026 | |
| 13027 | gdb_assert (die != NULL); |
| 13028 | |
| 13029 | if (level >= max_level) |
| 13030 | return; |
| 13031 | |
| 13032 | dump_die_shallow (f, indent, die); |
| 13033 | |
| 13034 | if (die->child != NULL) |
| 13035 | { |
| 13036 | print_spaces (indent, f); |
| 13037 | fprintf_unfiltered (f, " Children:"); |
| 13038 | if (level + 1 < max_level) |
| 13039 | { |
| 13040 | fprintf_unfiltered (f, "\n"); |
| 13041 | dump_die_1 (f, level + 1, max_level, die->child); |
| 13042 | } |
| 13043 | else |
| 13044 | { |
| 13045 | fprintf_unfiltered (f, |
| 13046 | " [not printed, max nesting level reached]\n"); |
| 13047 | } |
| 13048 | } |
| 13049 | |
| 13050 | if (die->sibling != NULL && level > 0) |
| 13051 | { |
| 13052 | dump_die_1 (f, level, max_level, die->sibling); |
| 13053 | } |
| 13054 | } |
| 13055 | |
| 13056 | /* This is called from the pdie macro in gdbinit.in. |
| 13057 | It's not static so gcc will keep a copy callable from gdb. */ |
| 13058 | |
| 13059 | void |
| 13060 | dump_die (struct die_info *die, int max_level) |
| 13061 | { |
| 13062 | dump_die_1 (gdb_stdlog, 0, max_level, die); |
| 13063 | } |
| 13064 | |
| 13065 | static void |
| 13066 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
| 13067 | { |
| 13068 | void **slot; |
| 13069 | |
| 13070 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
| 13071 | |
| 13072 | *slot = die; |
| 13073 | } |
| 13074 | |
| 13075 | static int |
| 13076 | is_ref_attr (struct attribute *attr) |
| 13077 | { |
| 13078 | switch (attr->form) |
| 13079 | { |
| 13080 | case DW_FORM_ref_addr: |
| 13081 | case DW_FORM_ref1: |
| 13082 | case DW_FORM_ref2: |
| 13083 | case DW_FORM_ref4: |
| 13084 | case DW_FORM_ref8: |
| 13085 | case DW_FORM_ref_udata: |
| 13086 | return 1; |
| 13087 | default: |
| 13088 | return 0; |
| 13089 | } |
| 13090 | } |
| 13091 | |
| 13092 | static unsigned int |
| 13093 | dwarf2_get_ref_die_offset (struct attribute *attr) |
| 13094 | { |
| 13095 | if (is_ref_attr (attr)) |
| 13096 | return DW_ADDR (attr); |
| 13097 | |
| 13098 | complaint (&symfile_complaints, |
| 13099 | _("unsupported die ref attribute form: '%s'"), |
| 13100 | dwarf_form_name (attr->form)); |
| 13101 | return 0; |
| 13102 | } |
| 13103 | |
| 13104 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
| 13105 | * the value held by the attribute is not constant. */ |
| 13106 | |
| 13107 | static LONGEST |
| 13108 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
| 13109 | { |
| 13110 | if (attr->form == DW_FORM_sdata) |
| 13111 | return DW_SND (attr); |
| 13112 | else if (attr->form == DW_FORM_udata |
| 13113 | || attr->form == DW_FORM_data1 |
| 13114 | || attr->form == DW_FORM_data2 |
| 13115 | || attr->form == DW_FORM_data4 |
| 13116 | || attr->form == DW_FORM_data8) |
| 13117 | return DW_UNSND (attr); |
| 13118 | else |
| 13119 | { |
| 13120 | complaint (&symfile_complaints, |
| 13121 | _("Attribute value is not a constant (%s)"), |
| 13122 | dwarf_form_name (attr->form)); |
| 13123 | return default_value; |
| 13124 | } |
| 13125 | } |
| 13126 | |
| 13127 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
| 13128 | unit and add it to our queue. |
| 13129 | The result is non-zero if PER_CU was queued, otherwise the result is zero |
| 13130 | meaning either PER_CU is already queued or it is already loaded. */ |
| 13131 | |
| 13132 | static int |
| 13133 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
| 13134 | struct dwarf2_per_cu_data *per_cu) |
| 13135 | { |
| 13136 | /* We may arrive here during partial symbol reading, if we need full |
| 13137 | DIEs to process an unusual case (e.g. template arguments). Do |
| 13138 | not queue PER_CU, just tell our caller to load its DIEs. */ |
| 13139 | if (dwarf2_per_objfile->reading_partial_symbols) |
| 13140 | { |
| 13141 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) |
| 13142 | return 1; |
| 13143 | return 0; |
| 13144 | } |
| 13145 | |
| 13146 | /* Mark the dependence relation so that we don't flush PER_CU |
| 13147 | too early. */ |
| 13148 | dwarf2_add_dependence (this_cu, per_cu); |
| 13149 | |
| 13150 | /* If it's already on the queue, we have nothing to do. */ |
| 13151 | if (per_cu->queued) |
| 13152 | return 0; |
| 13153 | |
| 13154 | /* If the compilation unit is already loaded, just mark it as |
| 13155 | used. */ |
| 13156 | if (per_cu->cu != NULL) |
| 13157 | { |
| 13158 | per_cu->cu->last_used = 0; |
| 13159 | return 0; |
| 13160 | } |
| 13161 | |
| 13162 | /* Add it to the queue. */ |
| 13163 | queue_comp_unit (per_cu, this_cu->objfile); |
| 13164 | |
| 13165 | return 1; |
| 13166 | } |
| 13167 | |
| 13168 | /* Follow reference or signature attribute ATTR of SRC_DIE. |
| 13169 | On entry *REF_CU is the CU of SRC_DIE. |
| 13170 | On exit *REF_CU is the CU of the result. */ |
| 13171 | |
| 13172 | static struct die_info * |
| 13173 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, |
| 13174 | struct dwarf2_cu **ref_cu) |
| 13175 | { |
| 13176 | struct die_info *die; |
| 13177 | |
| 13178 | if (is_ref_attr (attr)) |
| 13179 | die = follow_die_ref (src_die, attr, ref_cu); |
| 13180 | else if (attr->form == DW_FORM_sig8) |
| 13181 | die = follow_die_sig (src_die, attr, ref_cu); |
| 13182 | else |
| 13183 | { |
| 13184 | dump_die_for_error (src_die); |
| 13185 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), |
| 13186 | (*ref_cu)->objfile->name); |
| 13187 | } |
| 13188 | |
| 13189 | return die; |
| 13190 | } |
| 13191 | |
| 13192 | /* Follow reference OFFSET. |
| 13193 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
| 13194 | On exit *REF_CU is the CU of the result. |
| 13195 | Returns NULL if OFFSET is invalid. */ |
| 13196 | |
| 13197 | static struct die_info * |
| 13198 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
| 13199 | { |
| 13200 | struct die_info temp_die; |
| 13201 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
| 13202 | |
| 13203 | gdb_assert (cu->per_cu != NULL); |
| 13204 | |
| 13205 | target_cu = cu; |
| 13206 | |
| 13207 | if (cu->per_cu->from_debug_types) |
| 13208 | { |
| 13209 | /* .debug_types CUs cannot reference anything outside their CU. |
| 13210 | If they need to, they have to reference a signatured type via |
| 13211 | DW_FORM_sig8. */ |
| 13212 | if (! offset_in_cu_p (&cu->header, offset)) |
| 13213 | return NULL; |
| 13214 | } |
| 13215 | else if (! offset_in_cu_p (&cu->header, offset)) |
| 13216 | { |
| 13217 | struct dwarf2_per_cu_data *per_cu; |
| 13218 | |
| 13219 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
| 13220 | |
| 13221 | /* If necessary, add it to the queue and load its DIEs. */ |
| 13222 | if (maybe_queue_comp_unit (cu, per_cu)) |
| 13223 | load_full_comp_unit (per_cu, cu->objfile); |
| 13224 | |
| 13225 | target_cu = per_cu->cu; |
| 13226 | } |
| 13227 | else if (cu->dies == NULL) |
| 13228 | { |
| 13229 | /* We're loading full DIEs during partial symbol reading. */ |
| 13230 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); |
| 13231 | load_full_comp_unit (cu->per_cu, cu->objfile); |
| 13232 | } |
| 13233 | |
| 13234 | *ref_cu = target_cu; |
| 13235 | temp_die.offset = offset; |
| 13236 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
| 13237 | } |
| 13238 | |
| 13239 | /* Follow reference attribute ATTR of SRC_DIE. |
| 13240 | On entry *REF_CU is the CU of SRC_DIE. |
| 13241 | On exit *REF_CU is the CU of the result. */ |
| 13242 | |
| 13243 | static struct die_info * |
| 13244 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
| 13245 | struct dwarf2_cu **ref_cu) |
| 13246 | { |
| 13247 | unsigned int offset = dwarf2_get_ref_die_offset (attr); |
| 13248 | struct dwarf2_cu *cu = *ref_cu; |
| 13249 | struct die_info *die; |
| 13250 | |
| 13251 | die = follow_die_offset (offset, ref_cu); |
| 13252 | if (!die) |
| 13253 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " |
| 13254 | "at 0x%x [in module %s]"), |
| 13255 | offset, src_die->offset, cu->objfile->name); |
| 13256 | |
| 13257 | return die; |
| 13258 | } |
| 13259 | |
| 13260 | /* Return DWARF block and its CU referenced by OFFSET at PER_CU. Returned |
| 13261 | value is intended for DW_OP_call*. */ |
| 13262 | |
| 13263 | struct dwarf2_locexpr_baton |
| 13264 | dwarf2_fetch_die_location_block (unsigned int offset, |
| 13265 | struct dwarf2_per_cu_data *per_cu, |
| 13266 | CORE_ADDR (*get_frame_pc) (void *baton), |
| 13267 | void *baton) |
| 13268 | { |
| 13269 | struct dwarf2_cu *cu = per_cu->cu; |
| 13270 | struct die_info *die; |
| 13271 | struct attribute *attr; |
| 13272 | struct dwarf2_locexpr_baton retval; |
| 13273 | |
| 13274 | dw2_setup (per_cu->objfile); |
| 13275 | |
| 13276 | die = follow_die_offset (offset, &cu); |
| 13277 | if (!die) |
| 13278 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), |
| 13279 | offset, per_cu->cu->objfile->name); |
| 13280 | |
| 13281 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 13282 | if (!attr) |
| 13283 | { |
| 13284 | /* DWARF: "If there is no such attribute, then there is no effect.". */ |
| 13285 | |
| 13286 | retval.data = NULL; |
| 13287 | retval.size = 0; |
| 13288 | } |
| 13289 | else if (attr_form_is_section_offset (attr)) |
| 13290 | { |
| 13291 | struct dwarf2_loclist_baton loclist_baton; |
| 13292 | CORE_ADDR pc = (*get_frame_pc) (baton); |
| 13293 | size_t size; |
| 13294 | |
| 13295 | fill_in_loclist_baton (cu, &loclist_baton, attr); |
| 13296 | |
| 13297 | retval.data = dwarf2_find_location_expression (&loclist_baton, |
| 13298 | &size, pc); |
| 13299 | retval.size = size; |
| 13300 | } |
| 13301 | else |
| 13302 | { |
| 13303 | if (!attr_form_is_block (attr)) |
| 13304 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " |
| 13305 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), |
| 13306 | offset, per_cu->cu->objfile->name); |
| 13307 | |
| 13308 | retval.data = DW_BLOCK (attr)->data; |
| 13309 | retval.size = DW_BLOCK (attr)->size; |
| 13310 | } |
| 13311 | retval.per_cu = cu->per_cu; |
| 13312 | return retval; |
| 13313 | } |
| 13314 | |
| 13315 | /* Follow the signature attribute ATTR in SRC_DIE. |
| 13316 | On entry *REF_CU is the CU of SRC_DIE. |
| 13317 | On exit *REF_CU is the CU of the result. */ |
| 13318 | |
| 13319 | static struct die_info * |
| 13320 | follow_die_sig (struct die_info *src_die, struct attribute *attr, |
| 13321 | struct dwarf2_cu **ref_cu) |
| 13322 | { |
| 13323 | struct objfile *objfile = (*ref_cu)->objfile; |
| 13324 | struct die_info temp_die; |
| 13325 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); |
| 13326 | struct dwarf2_cu *sig_cu; |
| 13327 | struct die_info *die; |
| 13328 | |
| 13329 | /* sig_type will be NULL if the signatured type is missing from |
| 13330 | the debug info. */ |
| 13331 | if (sig_type == NULL) |
| 13332 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " |
| 13333 | "at 0x%x [in module %s]"), |
| 13334 | src_die->offset, objfile->name); |
| 13335 | |
| 13336 | /* If necessary, add it to the queue and load its DIEs. */ |
| 13337 | |
| 13338 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) |
| 13339 | read_signatured_type (objfile, sig_type); |
| 13340 | |
| 13341 | gdb_assert (sig_type->per_cu.cu != NULL); |
| 13342 | |
| 13343 | sig_cu = sig_type->per_cu.cu; |
| 13344 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; |
| 13345 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); |
| 13346 | if (die) |
| 13347 | { |
| 13348 | *ref_cu = sig_cu; |
| 13349 | return die; |
| 13350 | } |
| 13351 | |
| 13352 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
| 13353 | "from DIE at 0x%x [in module %s]"), |
| 13354 | sig_type->type_offset, src_die->offset, objfile->name); |
| 13355 | } |
| 13356 | |
| 13357 | /* Given an offset of a signatured type, return its signatured_type. */ |
| 13358 | |
| 13359 | static struct signatured_type * |
| 13360 | lookup_signatured_type_at_offset (struct objfile *objfile, unsigned int offset) |
| 13361 | { |
| 13362 | gdb_byte *info_ptr = dwarf2_per_objfile->types.buffer + offset; |
| 13363 | unsigned int length, initial_length_size; |
| 13364 | unsigned int sig_offset; |
| 13365 | struct signatured_type find_entry, *type_sig; |
| 13366 | |
| 13367 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); |
| 13368 | sig_offset = (initial_length_size |
| 13369 | + 2 /*version*/ |
| 13370 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ |
| 13371 | + 1 /*address_size*/); |
| 13372 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); |
| 13373 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
| 13374 | |
| 13375 | /* This is only used to lookup previously recorded types. |
| 13376 | If we didn't find it, it's our bug. */ |
| 13377 | gdb_assert (type_sig != NULL); |
| 13378 | gdb_assert (offset == type_sig->offset); |
| 13379 | |
| 13380 | return type_sig; |
| 13381 | } |
| 13382 | |
| 13383 | /* Read in signatured type at OFFSET and build its CU and die(s). */ |
| 13384 | |
| 13385 | static void |
| 13386 | read_signatured_type_at_offset (struct objfile *objfile, |
| 13387 | unsigned int offset) |
| 13388 | { |
| 13389 | struct signatured_type *type_sig; |
| 13390 | |
| 13391 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
| 13392 | |
| 13393 | /* We have the section offset, but we need the signature to do the |
| 13394 | hash table lookup. */ |
| 13395 | type_sig = lookup_signatured_type_at_offset (objfile, offset); |
| 13396 | |
| 13397 | gdb_assert (type_sig->per_cu.cu == NULL); |
| 13398 | |
| 13399 | read_signatured_type (objfile, type_sig); |
| 13400 | |
| 13401 | gdb_assert (type_sig->per_cu.cu != NULL); |
| 13402 | } |
| 13403 | |
| 13404 | /* Read in a signatured type and build its CU and DIEs. */ |
| 13405 | |
| 13406 | static void |
| 13407 | read_signatured_type (struct objfile *objfile, |
| 13408 | struct signatured_type *type_sig) |
| 13409 | { |
| 13410 | gdb_byte *types_ptr; |
| 13411 | struct die_reader_specs reader_specs; |
| 13412 | struct dwarf2_cu *cu; |
| 13413 | ULONGEST signature; |
| 13414 | struct cleanup *back_to, *free_cu_cleanup; |
| 13415 | |
| 13416 | dwarf2_read_section (objfile, &dwarf2_per_objfile->types); |
| 13417 | types_ptr = dwarf2_per_objfile->types.buffer + type_sig->offset; |
| 13418 | |
| 13419 | gdb_assert (type_sig->per_cu.cu == NULL); |
| 13420 | |
| 13421 | cu = xmalloc (sizeof (*cu)); |
| 13422 | init_one_comp_unit (cu, objfile); |
| 13423 | |
| 13424 | type_sig->per_cu.cu = cu; |
| 13425 | cu->per_cu = &type_sig->per_cu; |
| 13426 | |
| 13427 | /* If an error occurs while loading, release our storage. */ |
| 13428 | free_cu_cleanup = make_cleanup (free_one_comp_unit, cu); |
| 13429 | |
| 13430 | types_ptr = read_type_comp_unit_head (&cu->header, &signature, |
| 13431 | types_ptr, objfile->obfd); |
| 13432 | gdb_assert (signature == type_sig->signature); |
| 13433 | |
| 13434 | cu->die_hash |
| 13435 | = htab_create_alloc_ex (cu->header.length / 12, |
| 13436 | die_hash, |
| 13437 | die_eq, |
| 13438 | NULL, |
| 13439 | &cu->comp_unit_obstack, |
| 13440 | hashtab_obstack_allocate, |
| 13441 | dummy_obstack_deallocate); |
| 13442 | |
| 13443 | dwarf2_read_abbrevs (cu->objfile->obfd, cu); |
| 13444 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 13445 | |
| 13446 | init_cu_die_reader (&reader_specs, cu); |
| 13447 | |
| 13448 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, |
| 13449 | NULL /*parent*/); |
| 13450 | |
| 13451 | /* We try not to read any attributes in this function, because not |
| 13452 | all objfiles needed for references have been loaded yet, and symbol |
| 13453 | table processing isn't initialized. But we have to set the CU language, |
| 13454 | or we won't be able to build types correctly. */ |
| 13455 | prepare_one_comp_unit (cu, cu->dies); |
| 13456 | |
| 13457 | do_cleanups (back_to); |
| 13458 | |
| 13459 | /* We've successfully allocated this compilation unit. Let our caller |
| 13460 | clean it up when finished with it. */ |
| 13461 | discard_cleanups (free_cu_cleanup); |
| 13462 | |
| 13463 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 13464 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; |
| 13465 | } |
| 13466 | |
| 13467 | /* Decode simple location descriptions. |
| 13468 | Given a pointer to a dwarf block that defines a location, compute |
| 13469 | the location and return the value. |
| 13470 | |
| 13471 | NOTE drow/2003-11-18: This function is called in two situations |
| 13472 | now: for the address of static or global variables (partial symbols |
| 13473 | only) and for offsets into structures which are expected to be |
| 13474 | (more or less) constant. The partial symbol case should go away, |
| 13475 | and only the constant case should remain. That will let this |
| 13476 | function complain more accurately. A few special modes are allowed |
| 13477 | without complaint for global variables (for instance, global |
| 13478 | register values and thread-local values). |
| 13479 | |
| 13480 | A location description containing no operations indicates that the |
| 13481 | object is optimized out. The return value is 0 for that case. |
| 13482 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
| 13483 | callers will only want a very basic result and this can become a |
| 13484 | complaint. |
| 13485 | |
| 13486 | Note that stack[0] is unused except as a default error return. */ |
| 13487 | |
| 13488 | static CORE_ADDR |
| 13489 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
| 13490 | { |
| 13491 | struct objfile *objfile = cu->objfile; |
| 13492 | int i; |
| 13493 | int size = blk->size; |
| 13494 | gdb_byte *data = blk->data; |
| 13495 | CORE_ADDR stack[64]; |
| 13496 | int stacki; |
| 13497 | unsigned int bytes_read, unsnd; |
| 13498 | gdb_byte op; |
| 13499 | |
| 13500 | i = 0; |
| 13501 | stacki = 0; |
| 13502 | stack[stacki] = 0; |
| 13503 | stack[++stacki] = 0; |
| 13504 | |
| 13505 | while (i < size) |
| 13506 | { |
| 13507 | op = data[i++]; |
| 13508 | switch (op) |
| 13509 | { |
| 13510 | case DW_OP_lit0: |
| 13511 | case DW_OP_lit1: |
| 13512 | case DW_OP_lit2: |
| 13513 | case DW_OP_lit3: |
| 13514 | case DW_OP_lit4: |
| 13515 | case DW_OP_lit5: |
| 13516 | case DW_OP_lit6: |
| 13517 | case DW_OP_lit7: |
| 13518 | case DW_OP_lit8: |
| 13519 | case DW_OP_lit9: |
| 13520 | case DW_OP_lit10: |
| 13521 | case DW_OP_lit11: |
| 13522 | case DW_OP_lit12: |
| 13523 | case DW_OP_lit13: |
| 13524 | case DW_OP_lit14: |
| 13525 | case DW_OP_lit15: |
| 13526 | case DW_OP_lit16: |
| 13527 | case DW_OP_lit17: |
| 13528 | case DW_OP_lit18: |
| 13529 | case DW_OP_lit19: |
| 13530 | case DW_OP_lit20: |
| 13531 | case DW_OP_lit21: |
| 13532 | case DW_OP_lit22: |
| 13533 | case DW_OP_lit23: |
| 13534 | case DW_OP_lit24: |
| 13535 | case DW_OP_lit25: |
| 13536 | case DW_OP_lit26: |
| 13537 | case DW_OP_lit27: |
| 13538 | case DW_OP_lit28: |
| 13539 | case DW_OP_lit29: |
| 13540 | case DW_OP_lit30: |
| 13541 | case DW_OP_lit31: |
| 13542 | stack[++stacki] = op - DW_OP_lit0; |
| 13543 | break; |
| 13544 | |
| 13545 | case DW_OP_reg0: |
| 13546 | case DW_OP_reg1: |
| 13547 | case DW_OP_reg2: |
| 13548 | case DW_OP_reg3: |
| 13549 | case DW_OP_reg4: |
| 13550 | case DW_OP_reg5: |
| 13551 | case DW_OP_reg6: |
| 13552 | case DW_OP_reg7: |
| 13553 | case DW_OP_reg8: |
| 13554 | case DW_OP_reg9: |
| 13555 | case DW_OP_reg10: |
| 13556 | case DW_OP_reg11: |
| 13557 | case DW_OP_reg12: |
| 13558 | case DW_OP_reg13: |
| 13559 | case DW_OP_reg14: |
| 13560 | case DW_OP_reg15: |
| 13561 | case DW_OP_reg16: |
| 13562 | case DW_OP_reg17: |
| 13563 | case DW_OP_reg18: |
| 13564 | case DW_OP_reg19: |
| 13565 | case DW_OP_reg20: |
| 13566 | case DW_OP_reg21: |
| 13567 | case DW_OP_reg22: |
| 13568 | case DW_OP_reg23: |
| 13569 | case DW_OP_reg24: |
| 13570 | case DW_OP_reg25: |
| 13571 | case DW_OP_reg26: |
| 13572 | case DW_OP_reg27: |
| 13573 | case DW_OP_reg28: |
| 13574 | case DW_OP_reg29: |
| 13575 | case DW_OP_reg30: |
| 13576 | case DW_OP_reg31: |
| 13577 | stack[++stacki] = op - DW_OP_reg0; |
| 13578 | if (i < size) |
| 13579 | dwarf2_complex_location_expr_complaint (); |
| 13580 | break; |
| 13581 | |
| 13582 | case DW_OP_regx: |
| 13583 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
| 13584 | i += bytes_read; |
| 13585 | stack[++stacki] = unsnd; |
| 13586 | if (i < size) |
| 13587 | dwarf2_complex_location_expr_complaint (); |
| 13588 | break; |
| 13589 | |
| 13590 | case DW_OP_addr: |
| 13591 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
| 13592 | cu, &bytes_read); |
| 13593 | i += bytes_read; |
| 13594 | break; |
| 13595 | |
| 13596 | case DW_OP_const1u: |
| 13597 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); |
| 13598 | i += 1; |
| 13599 | break; |
| 13600 | |
| 13601 | case DW_OP_const1s: |
| 13602 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); |
| 13603 | i += 1; |
| 13604 | break; |
| 13605 | |
| 13606 | case DW_OP_const2u: |
| 13607 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); |
| 13608 | i += 2; |
| 13609 | break; |
| 13610 | |
| 13611 | case DW_OP_const2s: |
| 13612 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); |
| 13613 | i += 2; |
| 13614 | break; |
| 13615 | |
| 13616 | case DW_OP_const4u: |
| 13617 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); |
| 13618 | i += 4; |
| 13619 | break; |
| 13620 | |
| 13621 | case DW_OP_const4s: |
| 13622 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); |
| 13623 | i += 4; |
| 13624 | break; |
| 13625 | |
| 13626 | case DW_OP_constu: |
| 13627 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), |
| 13628 | &bytes_read); |
| 13629 | i += bytes_read; |
| 13630 | break; |
| 13631 | |
| 13632 | case DW_OP_consts: |
| 13633 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 13634 | i += bytes_read; |
| 13635 | break; |
| 13636 | |
| 13637 | case DW_OP_dup: |
| 13638 | stack[stacki + 1] = stack[stacki]; |
| 13639 | stacki++; |
| 13640 | break; |
| 13641 | |
| 13642 | case DW_OP_plus: |
| 13643 | stack[stacki - 1] += stack[stacki]; |
| 13644 | stacki--; |
| 13645 | break; |
| 13646 | |
| 13647 | case DW_OP_plus_uconst: |
| 13648 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), |
| 13649 | &bytes_read); |
| 13650 | i += bytes_read; |
| 13651 | break; |
| 13652 | |
| 13653 | case DW_OP_minus: |
| 13654 | stack[stacki - 1] -= stack[stacki]; |
| 13655 | stacki--; |
| 13656 | break; |
| 13657 | |
| 13658 | case DW_OP_deref: |
| 13659 | /* If we're not the last op, then we definitely can't encode |
| 13660 | this using GDB's address_class enum. This is valid for partial |
| 13661 | global symbols, although the variable's address will be bogus |
| 13662 | in the psymtab. */ |
| 13663 | if (i < size) |
| 13664 | dwarf2_complex_location_expr_complaint (); |
| 13665 | break; |
| 13666 | |
| 13667 | case DW_OP_GNU_push_tls_address: |
| 13668 | /* The top of the stack has the offset from the beginning |
| 13669 | of the thread control block at which the variable is located. */ |
| 13670 | /* Nothing should follow this operator, so the top of stack would |
| 13671 | be returned. */ |
| 13672 | /* This is valid for partial global symbols, but the variable's |
| 13673 | address will be bogus in the psymtab. */ |
| 13674 | if (i < size) |
| 13675 | dwarf2_complex_location_expr_complaint (); |
| 13676 | break; |
| 13677 | |
| 13678 | case DW_OP_GNU_uninit: |
| 13679 | break; |
| 13680 | |
| 13681 | default: |
| 13682 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
| 13683 | dwarf_stack_op_name (op, 1)); |
| 13684 | return (stack[stacki]); |
| 13685 | } |
| 13686 | |
| 13687 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
| 13688 | outside of the allocated space. Also enforce minimum>0. */ |
| 13689 | if (stacki >= ARRAY_SIZE (stack) - 1) |
| 13690 | { |
| 13691 | complaint (&symfile_complaints, |
| 13692 | _("location description stack overflow")); |
| 13693 | return 0; |
| 13694 | } |
| 13695 | |
| 13696 | if (stacki <= 0) |
| 13697 | { |
| 13698 | complaint (&symfile_complaints, |
| 13699 | _("location description stack underflow")); |
| 13700 | return 0; |
| 13701 | } |
| 13702 | } |
| 13703 | return (stack[stacki]); |
| 13704 | } |
| 13705 | |
| 13706 | /* memory allocation interface */ |
| 13707 | |
| 13708 | static struct dwarf_block * |
| 13709 | dwarf_alloc_block (struct dwarf2_cu *cu) |
| 13710 | { |
| 13711 | struct dwarf_block *blk; |
| 13712 | |
| 13713 | blk = (struct dwarf_block *) |
| 13714 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
| 13715 | return (blk); |
| 13716 | } |
| 13717 | |
| 13718 | static struct abbrev_info * |
| 13719 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
| 13720 | { |
| 13721 | struct abbrev_info *abbrev; |
| 13722 | |
| 13723 | abbrev = (struct abbrev_info *) |
| 13724 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); |
| 13725 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
| 13726 | return (abbrev); |
| 13727 | } |
| 13728 | |
| 13729 | static struct die_info * |
| 13730 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
| 13731 | { |
| 13732 | struct die_info *die; |
| 13733 | size_t size = sizeof (struct die_info); |
| 13734 | |
| 13735 | if (num_attrs > 1) |
| 13736 | size += (num_attrs - 1) * sizeof (struct attribute); |
| 13737 | |
| 13738 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
| 13739 | memset (die, 0, sizeof (struct die_info)); |
| 13740 | return (die); |
| 13741 | } |
| 13742 | |
| 13743 | \f |
| 13744 | /* Macro support. */ |
| 13745 | |
| 13746 | /* Return the full name of file number I in *LH's file name table. |
| 13747 | Use COMP_DIR as the name of the current directory of the |
| 13748 | compilation. The result is allocated using xmalloc; the caller is |
| 13749 | responsible for freeing it. */ |
| 13750 | static char * |
| 13751 | file_full_name (int file, struct line_header *lh, const char *comp_dir) |
| 13752 | { |
| 13753 | /* Is the file number a valid index into the line header's file name |
| 13754 | table? Remember that file numbers start with one, not zero. */ |
| 13755 | if (1 <= file && file <= lh->num_file_names) |
| 13756 | { |
| 13757 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 13758 | |
| 13759 | if (IS_ABSOLUTE_PATH (fe->name)) |
| 13760 | return xstrdup (fe->name); |
| 13761 | else |
| 13762 | { |
| 13763 | const char *dir; |
| 13764 | int dir_len; |
| 13765 | char *full_name; |
| 13766 | |
| 13767 | if (fe->dir_index) |
| 13768 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 13769 | else |
| 13770 | dir = comp_dir; |
| 13771 | |
| 13772 | if (dir) |
| 13773 | { |
| 13774 | dir_len = strlen (dir); |
| 13775 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); |
| 13776 | strcpy (full_name, dir); |
| 13777 | full_name[dir_len] = '/'; |
| 13778 | strcpy (full_name + dir_len + 1, fe->name); |
| 13779 | return full_name; |
| 13780 | } |
| 13781 | else |
| 13782 | return xstrdup (fe->name); |
| 13783 | } |
| 13784 | } |
| 13785 | else |
| 13786 | { |
| 13787 | /* The compiler produced a bogus file number. We can at least |
| 13788 | record the macro definitions made in the file, even if we |
| 13789 | won't be able to find the file by name. */ |
| 13790 | char fake_name[80]; |
| 13791 | |
| 13792 | sprintf (fake_name, "<bad macro file number %d>", file); |
| 13793 | |
| 13794 | complaint (&symfile_complaints, |
| 13795 | _("bad file number in macro information (%d)"), |
| 13796 | file); |
| 13797 | |
| 13798 | return xstrdup (fake_name); |
| 13799 | } |
| 13800 | } |
| 13801 | |
| 13802 | |
| 13803 | static struct macro_source_file * |
| 13804 | macro_start_file (int file, int line, |
| 13805 | struct macro_source_file *current_file, |
| 13806 | const char *comp_dir, |
| 13807 | struct line_header *lh, struct objfile *objfile) |
| 13808 | { |
| 13809 | /* The full name of this source file. */ |
| 13810 | char *full_name = file_full_name (file, lh, comp_dir); |
| 13811 | |
| 13812 | /* We don't create a macro table for this compilation unit |
| 13813 | at all until we actually get a filename. */ |
| 13814 | if (! pending_macros) |
| 13815 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
| 13816 | objfile->macro_cache); |
| 13817 | |
| 13818 | if (! current_file) |
| 13819 | /* If we have no current file, then this must be the start_file |
| 13820 | directive for the compilation unit's main source file. */ |
| 13821 | current_file = macro_set_main (pending_macros, full_name); |
| 13822 | else |
| 13823 | current_file = macro_include (current_file, line, full_name); |
| 13824 | |
| 13825 | xfree (full_name); |
| 13826 | |
| 13827 | return current_file; |
| 13828 | } |
| 13829 | |
| 13830 | |
| 13831 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, |
| 13832 | followed by a null byte. */ |
| 13833 | static char * |
| 13834 | copy_string (const char *buf, int len) |
| 13835 | { |
| 13836 | char *s = xmalloc (len + 1); |
| 13837 | |
| 13838 | memcpy (s, buf, len); |
| 13839 | s[len] = '\0'; |
| 13840 | return s; |
| 13841 | } |
| 13842 | |
| 13843 | |
| 13844 | static const char * |
| 13845 | consume_improper_spaces (const char *p, const char *body) |
| 13846 | { |
| 13847 | if (*p == ' ') |
| 13848 | { |
| 13849 | complaint (&symfile_complaints, |
| 13850 | _("macro definition contains spaces " |
| 13851 | "in formal argument list:\n`%s'"), |
| 13852 | body); |
| 13853 | |
| 13854 | while (*p == ' ') |
| 13855 | p++; |
| 13856 | } |
| 13857 | |
| 13858 | return p; |
| 13859 | } |
| 13860 | |
| 13861 | |
| 13862 | static void |
| 13863 | parse_macro_definition (struct macro_source_file *file, int line, |
| 13864 | const char *body) |
| 13865 | { |
| 13866 | const char *p; |
| 13867 | |
| 13868 | /* The body string takes one of two forms. For object-like macro |
| 13869 | definitions, it should be: |
| 13870 | |
| 13871 | <macro name> " " <definition> |
| 13872 | |
| 13873 | For function-like macro definitions, it should be: |
| 13874 | |
| 13875 | <macro name> "() " <definition> |
| 13876 | or |
| 13877 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> |
| 13878 | |
| 13879 | Spaces may appear only where explicitly indicated, and in the |
| 13880 | <definition>. |
| 13881 | |
| 13882 | The Dwarf 2 spec says that an object-like macro's name is always |
| 13883 | followed by a space, but versions of GCC around March 2002 omit |
| 13884 | the space when the macro's definition is the empty string. |
| 13885 | |
| 13886 | The Dwarf 2 spec says that there should be no spaces between the |
| 13887 | formal arguments in a function-like macro's formal argument list, |
| 13888 | but versions of GCC around March 2002 include spaces after the |
| 13889 | commas. */ |
| 13890 | |
| 13891 | |
| 13892 | /* Find the extent of the macro name. The macro name is terminated |
| 13893 | by either a space or null character (for an object-like macro) or |
| 13894 | an opening paren (for a function-like macro). */ |
| 13895 | for (p = body; *p; p++) |
| 13896 | if (*p == ' ' || *p == '(') |
| 13897 | break; |
| 13898 | |
| 13899 | if (*p == ' ' || *p == '\0') |
| 13900 | { |
| 13901 | /* It's an object-like macro. */ |
| 13902 | int name_len = p - body; |
| 13903 | char *name = copy_string (body, name_len); |
| 13904 | const char *replacement; |
| 13905 | |
| 13906 | if (*p == ' ') |
| 13907 | replacement = body + name_len + 1; |
| 13908 | else |
| 13909 | { |
| 13910 | dwarf2_macro_malformed_definition_complaint (body); |
| 13911 | replacement = body + name_len; |
| 13912 | } |
| 13913 | |
| 13914 | macro_define_object (file, line, name, replacement); |
| 13915 | |
| 13916 | xfree (name); |
| 13917 | } |
| 13918 | else if (*p == '(') |
| 13919 | { |
| 13920 | /* It's a function-like macro. */ |
| 13921 | char *name = copy_string (body, p - body); |
| 13922 | int argc = 0; |
| 13923 | int argv_size = 1; |
| 13924 | char **argv = xmalloc (argv_size * sizeof (*argv)); |
| 13925 | |
| 13926 | p++; |
| 13927 | |
| 13928 | p = consume_improper_spaces (p, body); |
| 13929 | |
| 13930 | /* Parse the formal argument list. */ |
| 13931 | while (*p && *p != ')') |
| 13932 | { |
| 13933 | /* Find the extent of the current argument name. */ |
| 13934 | const char *arg_start = p; |
| 13935 | |
| 13936 | while (*p && *p != ',' && *p != ')' && *p != ' ') |
| 13937 | p++; |
| 13938 | |
| 13939 | if (! *p || p == arg_start) |
| 13940 | dwarf2_macro_malformed_definition_complaint (body); |
| 13941 | else |
| 13942 | { |
| 13943 | /* Make sure argv has room for the new argument. */ |
| 13944 | if (argc >= argv_size) |
| 13945 | { |
| 13946 | argv_size *= 2; |
| 13947 | argv = xrealloc (argv, argv_size * sizeof (*argv)); |
| 13948 | } |
| 13949 | |
| 13950 | argv[argc++] = copy_string (arg_start, p - arg_start); |
| 13951 | } |
| 13952 | |
| 13953 | p = consume_improper_spaces (p, body); |
| 13954 | |
| 13955 | /* Consume the comma, if present. */ |
| 13956 | if (*p == ',') |
| 13957 | { |
| 13958 | p++; |
| 13959 | |
| 13960 | p = consume_improper_spaces (p, body); |
| 13961 | } |
| 13962 | } |
| 13963 | |
| 13964 | if (*p == ')') |
| 13965 | { |
| 13966 | p++; |
| 13967 | |
| 13968 | if (*p == ' ') |
| 13969 | /* Perfectly formed definition, no complaints. */ |
| 13970 | macro_define_function (file, line, name, |
| 13971 | argc, (const char **) argv, |
| 13972 | p + 1); |
| 13973 | else if (*p == '\0') |
| 13974 | { |
| 13975 | /* Complain, but do define it. */ |
| 13976 | dwarf2_macro_malformed_definition_complaint (body); |
| 13977 | macro_define_function (file, line, name, |
| 13978 | argc, (const char **) argv, |
| 13979 | p); |
| 13980 | } |
| 13981 | else |
| 13982 | /* Just complain. */ |
| 13983 | dwarf2_macro_malformed_definition_complaint (body); |
| 13984 | } |
| 13985 | else |
| 13986 | /* Just complain. */ |
| 13987 | dwarf2_macro_malformed_definition_complaint (body); |
| 13988 | |
| 13989 | xfree (name); |
| 13990 | { |
| 13991 | int i; |
| 13992 | |
| 13993 | for (i = 0; i < argc; i++) |
| 13994 | xfree (argv[i]); |
| 13995 | } |
| 13996 | xfree (argv); |
| 13997 | } |
| 13998 | else |
| 13999 | dwarf2_macro_malformed_definition_complaint (body); |
| 14000 | } |
| 14001 | |
| 14002 | |
| 14003 | static void |
| 14004 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, |
| 14005 | char *comp_dir, bfd *abfd, |
| 14006 | struct dwarf2_cu *cu) |
| 14007 | { |
| 14008 | gdb_byte *mac_ptr, *mac_end; |
| 14009 | struct macro_source_file *current_file = 0; |
| 14010 | enum dwarf_macinfo_record_type macinfo_type; |
| 14011 | int at_commandline; |
| 14012 | |
| 14013 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 14014 | &dwarf2_per_objfile->macinfo); |
| 14015 | if (dwarf2_per_objfile->macinfo.buffer == NULL) |
| 14016 | { |
| 14017 | complaint (&symfile_complaints, _("missing .debug_macinfo section")); |
| 14018 | return; |
| 14019 | } |
| 14020 | |
| 14021 | /* First pass: Find the name of the base filename. |
| 14022 | This filename is needed in order to process all macros whose definition |
| 14023 | (or undefinition) comes from the command line. These macros are defined |
| 14024 | before the first DW_MACINFO_start_file entry, and yet still need to be |
| 14025 | associated to the base file. |
| 14026 | |
| 14027 | To determine the base file name, we scan the macro definitions until we |
| 14028 | reach the first DW_MACINFO_start_file entry. We then initialize |
| 14029 | CURRENT_FILE accordingly so that any macro definition found before the |
| 14030 | first DW_MACINFO_start_file can still be associated to the base file. */ |
| 14031 | |
| 14032 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
| 14033 | mac_end = dwarf2_per_objfile->macinfo.buffer |
| 14034 | + dwarf2_per_objfile->macinfo.size; |
| 14035 | |
| 14036 | do |
| 14037 | { |
| 14038 | /* Do we at least have room for a macinfo type byte? */ |
| 14039 | if (mac_ptr >= mac_end) |
| 14040 | { |
| 14041 | /* Complaint is printed during the second pass as GDB will probably |
| 14042 | stop the first pass earlier upon finding |
| 14043 | DW_MACINFO_start_file. */ |
| 14044 | break; |
| 14045 | } |
| 14046 | |
| 14047 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 14048 | mac_ptr++; |
| 14049 | |
| 14050 | switch (macinfo_type) |
| 14051 | { |
| 14052 | /* A zero macinfo type indicates the end of the macro |
| 14053 | information. */ |
| 14054 | case 0: |
| 14055 | break; |
| 14056 | |
| 14057 | case DW_MACINFO_define: |
| 14058 | case DW_MACINFO_undef: |
| 14059 | /* Only skip the data by MAC_PTR. */ |
| 14060 | { |
| 14061 | unsigned int bytes_read; |
| 14062 | |
| 14063 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14064 | mac_ptr += bytes_read; |
| 14065 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 14066 | mac_ptr += bytes_read; |
| 14067 | } |
| 14068 | break; |
| 14069 | |
| 14070 | case DW_MACINFO_start_file: |
| 14071 | { |
| 14072 | unsigned int bytes_read; |
| 14073 | int line, file; |
| 14074 | |
| 14075 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14076 | mac_ptr += bytes_read; |
| 14077 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14078 | mac_ptr += bytes_read; |
| 14079 | |
| 14080 | current_file = macro_start_file (file, line, current_file, |
| 14081 | comp_dir, lh, cu->objfile); |
| 14082 | } |
| 14083 | break; |
| 14084 | |
| 14085 | case DW_MACINFO_end_file: |
| 14086 | /* No data to skip by MAC_PTR. */ |
| 14087 | break; |
| 14088 | |
| 14089 | case DW_MACINFO_vendor_ext: |
| 14090 | /* Only skip the data by MAC_PTR. */ |
| 14091 | { |
| 14092 | unsigned int bytes_read; |
| 14093 | |
| 14094 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14095 | mac_ptr += bytes_read; |
| 14096 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 14097 | mac_ptr += bytes_read; |
| 14098 | } |
| 14099 | break; |
| 14100 | |
| 14101 | default: |
| 14102 | break; |
| 14103 | } |
| 14104 | } while (macinfo_type != 0 && current_file == NULL); |
| 14105 | |
| 14106 | /* Second pass: Process all entries. |
| 14107 | |
| 14108 | Use the AT_COMMAND_LINE flag to determine whether we are still processing |
| 14109 | command-line macro definitions/undefinitions. This flag is unset when we |
| 14110 | reach the first DW_MACINFO_start_file entry. */ |
| 14111 | |
| 14112 | mac_ptr = dwarf2_per_objfile->macinfo.buffer + offset; |
| 14113 | |
| 14114 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true |
| 14115 | GDB is still reading the definitions from command line. First |
| 14116 | DW_MACINFO_start_file will need to be ignored as it was already executed |
| 14117 | to create CURRENT_FILE for the main source holding also the command line |
| 14118 | definitions. On first met DW_MACINFO_start_file this flag is reset to |
| 14119 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ |
| 14120 | |
| 14121 | at_commandline = 1; |
| 14122 | |
| 14123 | do |
| 14124 | { |
| 14125 | /* Do we at least have room for a macinfo type byte? */ |
| 14126 | if (mac_ptr >= mac_end) |
| 14127 | { |
| 14128 | dwarf2_macros_too_long_complaint (); |
| 14129 | break; |
| 14130 | } |
| 14131 | |
| 14132 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 14133 | mac_ptr++; |
| 14134 | |
| 14135 | switch (macinfo_type) |
| 14136 | { |
| 14137 | /* A zero macinfo type indicates the end of the macro |
| 14138 | information. */ |
| 14139 | case 0: |
| 14140 | break; |
| 14141 | |
| 14142 | case DW_MACINFO_define: |
| 14143 | case DW_MACINFO_undef: |
| 14144 | { |
| 14145 | unsigned int bytes_read; |
| 14146 | int line; |
| 14147 | char *body; |
| 14148 | |
| 14149 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14150 | mac_ptr += bytes_read; |
| 14151 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
| 14152 | mac_ptr += bytes_read; |
| 14153 | |
| 14154 | if (! current_file) |
| 14155 | { |
| 14156 | /* DWARF violation as no main source is present. */ |
| 14157 | complaint (&symfile_complaints, |
| 14158 | _("debug info with no main source gives macro %s " |
| 14159 | "on line %d: %s"), |
| 14160 | macinfo_type == DW_MACINFO_define ? |
| 14161 | _("definition") : |
| 14162 | macinfo_type == DW_MACINFO_undef ? |
| 14163 | _("undefinition") : |
| 14164 | _("something-or-other"), line, body); |
| 14165 | break; |
| 14166 | } |
| 14167 | if ((line == 0 && !at_commandline) |
| 14168 | || (line != 0 && at_commandline)) |
| 14169 | complaint (&symfile_complaints, |
| 14170 | _("debug info gives %s macro %s with %s line %d: %s"), |
| 14171 | at_commandline ? _("command-line") : _("in-file"), |
| 14172 | macinfo_type == DW_MACINFO_define ? |
| 14173 | _("definition") : |
| 14174 | macinfo_type == DW_MACINFO_undef ? |
| 14175 | _("undefinition") : |
| 14176 | _("something-or-other"), |
| 14177 | line == 0 ? _("zero") : _("non-zero"), line, body); |
| 14178 | |
| 14179 | if (macinfo_type == DW_MACINFO_define) |
| 14180 | parse_macro_definition (current_file, line, body); |
| 14181 | else if (macinfo_type == DW_MACINFO_undef) |
| 14182 | macro_undef (current_file, line, body); |
| 14183 | } |
| 14184 | break; |
| 14185 | |
| 14186 | case DW_MACINFO_start_file: |
| 14187 | { |
| 14188 | unsigned int bytes_read; |
| 14189 | int line, file; |
| 14190 | |
| 14191 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14192 | mac_ptr += bytes_read; |
| 14193 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14194 | mac_ptr += bytes_read; |
| 14195 | |
| 14196 | if ((line == 0 && !at_commandline) |
| 14197 | || (line != 0 && at_commandline)) |
| 14198 | complaint (&symfile_complaints, |
| 14199 | _("debug info gives source %d included " |
| 14200 | "from %s at %s line %d"), |
| 14201 | file, at_commandline ? _("command-line") : _("file"), |
| 14202 | line == 0 ? _("zero") : _("non-zero"), line); |
| 14203 | |
| 14204 | if (at_commandline) |
| 14205 | { |
| 14206 | /* This DW_MACINFO_start_file was executed in the pass one. */ |
| 14207 | at_commandline = 0; |
| 14208 | } |
| 14209 | else |
| 14210 | current_file = macro_start_file (file, line, |
| 14211 | current_file, comp_dir, |
| 14212 | lh, cu->objfile); |
| 14213 | } |
| 14214 | break; |
| 14215 | |
| 14216 | case DW_MACINFO_end_file: |
| 14217 | if (! current_file) |
| 14218 | complaint (&symfile_complaints, |
| 14219 | _("macro debug info has an unmatched " |
| 14220 | "`close_file' directive")); |
| 14221 | else |
| 14222 | { |
| 14223 | current_file = current_file->included_by; |
| 14224 | if (! current_file) |
| 14225 | { |
| 14226 | enum dwarf_macinfo_record_type next_type; |
| 14227 | |
| 14228 | /* GCC circa March 2002 doesn't produce the zero |
| 14229 | type byte marking the end of the compilation |
| 14230 | unit. Complain if it's not there, but exit no |
| 14231 | matter what. */ |
| 14232 | |
| 14233 | /* Do we at least have room for a macinfo type byte? */ |
| 14234 | if (mac_ptr >= mac_end) |
| 14235 | { |
| 14236 | dwarf2_macros_too_long_complaint (); |
| 14237 | return; |
| 14238 | } |
| 14239 | |
| 14240 | /* We don't increment mac_ptr here, so this is just |
| 14241 | a look-ahead. */ |
| 14242 | next_type = read_1_byte (abfd, mac_ptr); |
| 14243 | if (next_type != 0) |
| 14244 | complaint (&symfile_complaints, |
| 14245 | _("no terminating 0-type entry for " |
| 14246 | "macros in `.debug_macinfo' section")); |
| 14247 | |
| 14248 | return; |
| 14249 | } |
| 14250 | } |
| 14251 | break; |
| 14252 | |
| 14253 | case DW_MACINFO_vendor_ext: |
| 14254 | { |
| 14255 | unsigned int bytes_read; |
| 14256 | int constant; |
| 14257 | char *string; |
| 14258 | |
| 14259 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 14260 | mac_ptr += bytes_read; |
| 14261 | string = read_direct_string (abfd, mac_ptr, &bytes_read); |
| 14262 | mac_ptr += bytes_read; |
| 14263 | |
| 14264 | /* We don't recognize any vendor extensions. */ |
| 14265 | } |
| 14266 | break; |
| 14267 | } |
| 14268 | } while (macinfo_type != 0); |
| 14269 | } |
| 14270 | |
| 14271 | /* Check if the attribute's form is a DW_FORM_block* |
| 14272 | if so return true else false. */ |
| 14273 | static int |
| 14274 | attr_form_is_block (struct attribute *attr) |
| 14275 | { |
| 14276 | return (attr == NULL ? 0 : |
| 14277 | attr->form == DW_FORM_block1 |
| 14278 | || attr->form == DW_FORM_block2 |
| 14279 | || attr->form == DW_FORM_block4 |
| 14280 | || attr->form == DW_FORM_block |
| 14281 | || attr->form == DW_FORM_exprloc); |
| 14282 | } |
| 14283 | |
| 14284 | /* Return non-zero if ATTR's value is a section offset --- classes |
| 14285 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. |
| 14286 | You may use DW_UNSND (attr) to retrieve such offsets. |
| 14287 | |
| 14288 | Section 7.5.4, "Attribute Encodings", explains that no attribute |
| 14289 | may have a value that belongs to more than one of these classes; it |
| 14290 | would be ambiguous if we did, because we use the same forms for all |
| 14291 | of them. */ |
| 14292 | static int |
| 14293 | attr_form_is_section_offset (struct attribute *attr) |
| 14294 | { |
| 14295 | return (attr->form == DW_FORM_data4 |
| 14296 | || attr->form == DW_FORM_data8 |
| 14297 | || attr->form == DW_FORM_sec_offset); |
| 14298 | } |
| 14299 | |
| 14300 | |
| 14301 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
| 14302 | zero otherwise. When this function returns true, you can apply |
| 14303 | dwarf2_get_attr_constant_value to it. |
| 14304 | |
| 14305 | However, note that for some attributes you must check |
| 14306 | attr_form_is_section_offset before using this test. DW_FORM_data4 |
| 14307 | and DW_FORM_data8 are members of both the constant class, and of |
| 14308 | the classes that contain offsets into other debug sections |
| 14309 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says |
| 14310 | that, if an attribute's can be either a constant or one of the |
| 14311 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be |
| 14312 | taken as section offsets, not constants. */ |
| 14313 | static int |
| 14314 | attr_form_is_constant (struct attribute *attr) |
| 14315 | { |
| 14316 | switch (attr->form) |
| 14317 | { |
| 14318 | case DW_FORM_sdata: |
| 14319 | case DW_FORM_udata: |
| 14320 | case DW_FORM_data1: |
| 14321 | case DW_FORM_data2: |
| 14322 | case DW_FORM_data4: |
| 14323 | case DW_FORM_data8: |
| 14324 | return 1; |
| 14325 | default: |
| 14326 | return 0; |
| 14327 | } |
| 14328 | } |
| 14329 | |
| 14330 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
| 14331 | |
| 14332 | static void |
| 14333 | fill_in_loclist_baton (struct dwarf2_cu *cu, |
| 14334 | struct dwarf2_loclist_baton *baton, |
| 14335 | struct attribute *attr) |
| 14336 | { |
| 14337 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 14338 | &dwarf2_per_objfile->loc); |
| 14339 | |
| 14340 | baton->per_cu = cu->per_cu; |
| 14341 | gdb_assert (baton->per_cu); |
| 14342 | /* We don't know how long the location list is, but make sure we |
| 14343 | don't run off the edge of the section. */ |
| 14344 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
| 14345 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); |
| 14346 | baton->base_address = cu->base_address; |
| 14347 | } |
| 14348 | |
| 14349 | static void |
| 14350 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, |
| 14351 | struct dwarf2_cu *cu) |
| 14352 | { |
| 14353 | if (attr_form_is_section_offset (attr) |
| 14354 | /* ".debug_loc" may not exist at all, or the offset may be outside |
| 14355 | the section. If so, fall through to the complaint in the |
| 14356 | other branch. */ |
| 14357 | && DW_UNSND (attr) < dwarf2_per_objfile->loc.size) |
| 14358 | { |
| 14359 | struct dwarf2_loclist_baton *baton; |
| 14360 | |
| 14361 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
| 14362 | sizeof (struct dwarf2_loclist_baton)); |
| 14363 | |
| 14364 | fill_in_loclist_baton (cu, baton, attr); |
| 14365 | |
| 14366 | if (cu->base_known == 0) |
| 14367 | complaint (&symfile_complaints, |
| 14368 | _("Location list used without " |
| 14369 | "specifying the CU base address.")); |
| 14370 | |
| 14371 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
| 14372 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 14373 | } |
| 14374 | else |
| 14375 | { |
| 14376 | struct dwarf2_locexpr_baton *baton; |
| 14377 | |
| 14378 | baton = obstack_alloc (&cu->objfile->objfile_obstack, |
| 14379 | sizeof (struct dwarf2_locexpr_baton)); |
| 14380 | baton->per_cu = cu->per_cu; |
| 14381 | gdb_assert (baton->per_cu); |
| 14382 | |
| 14383 | if (attr_form_is_block (attr)) |
| 14384 | { |
| 14385 | /* Note that we're just copying the block's data pointer |
| 14386 | here, not the actual data. We're still pointing into the |
| 14387 | info_buffer for SYM's objfile; right now we never release |
| 14388 | that buffer, but when we do clean up properly this may |
| 14389 | need to change. */ |
| 14390 | baton->size = DW_BLOCK (attr)->size; |
| 14391 | baton->data = DW_BLOCK (attr)->data; |
| 14392 | } |
| 14393 | else |
| 14394 | { |
| 14395 | dwarf2_invalid_attrib_class_complaint ("location description", |
| 14396 | SYMBOL_NATURAL_NAME (sym)); |
| 14397 | baton->size = 0; |
| 14398 | baton->data = NULL; |
| 14399 | } |
| 14400 | |
| 14401 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 14402 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 14403 | } |
| 14404 | } |
| 14405 | |
| 14406 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
| 14407 | came from a separate debuginfo file, then the master objfile is |
| 14408 | returned. */ |
| 14409 | |
| 14410 | struct objfile * |
| 14411 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) |
| 14412 | { |
| 14413 | struct objfile *objfile = per_cu->objfile; |
| 14414 | |
| 14415 | /* Return the master objfile, so that we can report and look up the |
| 14416 | correct file containing this variable. */ |
| 14417 | if (objfile->separate_debug_objfile_backlink) |
| 14418 | objfile = objfile->separate_debug_objfile_backlink; |
| 14419 | |
| 14420 | return objfile; |
| 14421 | } |
| 14422 | |
| 14423 | /* Return the address size given in the compilation unit header for CU. */ |
| 14424 | |
| 14425 | CORE_ADDR |
| 14426 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
| 14427 | { |
| 14428 | if (per_cu->cu) |
| 14429 | return per_cu->cu->header.addr_size; |
| 14430 | else |
| 14431 | { |
| 14432 | /* If the CU is not currently read in, we re-read its header. */ |
| 14433 | struct objfile *objfile = per_cu->objfile; |
| 14434 | struct dwarf2_per_objfile *per_objfile |
| 14435 | = objfile_data (objfile, dwarf2_objfile_data_key); |
| 14436 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
| 14437 | struct comp_unit_head cu_header; |
| 14438 | |
| 14439 | memset (&cu_header, 0, sizeof cu_header); |
| 14440 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); |
| 14441 | return cu_header.addr_size; |
| 14442 | } |
| 14443 | } |
| 14444 | |
| 14445 | /* Return the offset size given in the compilation unit header for CU. */ |
| 14446 | |
| 14447 | int |
| 14448 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) |
| 14449 | { |
| 14450 | if (per_cu->cu) |
| 14451 | return per_cu->cu->header.offset_size; |
| 14452 | else |
| 14453 | { |
| 14454 | /* If the CU is not currently read in, we re-read its header. */ |
| 14455 | struct objfile *objfile = per_cu->objfile; |
| 14456 | struct dwarf2_per_objfile *per_objfile |
| 14457 | = objfile_data (objfile, dwarf2_objfile_data_key); |
| 14458 | gdb_byte *info_ptr = per_objfile->info.buffer + per_cu->offset; |
| 14459 | struct comp_unit_head cu_header; |
| 14460 | |
| 14461 | memset (&cu_header, 0, sizeof cu_header); |
| 14462 | read_comp_unit_head (&cu_header, info_ptr, objfile->obfd); |
| 14463 | return cu_header.offset_size; |
| 14464 | } |
| 14465 | } |
| 14466 | |
| 14467 | /* Return the text offset of the CU. The returned offset comes from |
| 14468 | this CU's objfile. If this objfile came from a separate debuginfo |
| 14469 | file, then the offset may be different from the corresponding |
| 14470 | offset in the parent objfile. */ |
| 14471 | |
| 14472 | CORE_ADDR |
| 14473 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) |
| 14474 | { |
| 14475 | struct objfile *objfile = per_cu->objfile; |
| 14476 | |
| 14477 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 14478 | } |
| 14479 | |
| 14480 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
| 14481 | the DIE at OFFSET. Raises an error on failure. */ |
| 14482 | |
| 14483 | static struct dwarf2_per_cu_data * |
| 14484 | dwarf2_find_containing_comp_unit (unsigned int offset, |
| 14485 | struct objfile *objfile) |
| 14486 | { |
| 14487 | struct dwarf2_per_cu_data *this_cu; |
| 14488 | int low, high; |
| 14489 | |
| 14490 | low = 0; |
| 14491 | high = dwarf2_per_objfile->n_comp_units - 1; |
| 14492 | while (high > low) |
| 14493 | { |
| 14494 | int mid = low + (high - low) / 2; |
| 14495 | |
| 14496 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
| 14497 | high = mid; |
| 14498 | else |
| 14499 | low = mid + 1; |
| 14500 | } |
| 14501 | gdb_assert (low == high); |
| 14502 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) |
| 14503 | { |
| 14504 | if (low == 0) |
| 14505 | error (_("Dwarf Error: could not find partial DIE containing " |
| 14506 | "offset 0x%lx [in module %s]"), |
| 14507 | (long) offset, bfd_get_filename (objfile->obfd)); |
| 14508 | |
| 14509 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
| 14510 | return dwarf2_per_objfile->all_comp_units[low-1]; |
| 14511 | } |
| 14512 | else |
| 14513 | { |
| 14514 | this_cu = dwarf2_per_objfile->all_comp_units[low]; |
| 14515 | if (low == dwarf2_per_objfile->n_comp_units - 1 |
| 14516 | && offset >= this_cu->offset + this_cu->length) |
| 14517 | error (_("invalid dwarf2 offset %u"), offset); |
| 14518 | gdb_assert (offset < this_cu->offset + this_cu->length); |
| 14519 | return this_cu; |
| 14520 | } |
| 14521 | } |
| 14522 | |
| 14523 | /* Locate the compilation unit from OBJFILE which is located at exactly |
| 14524 | OFFSET. Raises an error on failure. */ |
| 14525 | |
| 14526 | static struct dwarf2_per_cu_data * |
| 14527 | dwarf2_find_comp_unit (unsigned int offset, struct objfile *objfile) |
| 14528 | { |
| 14529 | struct dwarf2_per_cu_data *this_cu; |
| 14530 | |
| 14531 | this_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
| 14532 | if (this_cu->offset != offset) |
| 14533 | error (_("no compilation unit with offset %u."), offset); |
| 14534 | return this_cu; |
| 14535 | } |
| 14536 | |
| 14537 | /* Initialize dwarf2_cu CU for OBJFILE in a pre-allocated space. */ |
| 14538 | |
| 14539 | static void |
| 14540 | init_one_comp_unit (struct dwarf2_cu *cu, struct objfile *objfile) |
| 14541 | { |
| 14542 | memset (cu, 0, sizeof (*cu)); |
| 14543 | cu->objfile = objfile; |
| 14544 | obstack_init (&cu->comp_unit_obstack); |
| 14545 | } |
| 14546 | |
| 14547 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ |
| 14548 | |
| 14549 | static void |
| 14550 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) |
| 14551 | { |
| 14552 | struct attribute *attr; |
| 14553 | |
| 14554 | /* Set the language we're debugging. */ |
| 14555 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
| 14556 | if (attr) |
| 14557 | set_cu_language (DW_UNSND (attr), cu); |
| 14558 | else |
| 14559 | set_cu_language (language_minimal, cu); |
| 14560 | } |
| 14561 | |
| 14562 | /* Release one cached compilation unit, CU. We unlink it from the tree |
| 14563 | of compilation units, but we don't remove it from the read_in_chain; |
| 14564 | the caller is responsible for that. |
| 14565 | NOTE: DATA is a void * because this function is also used as a |
| 14566 | cleanup routine. */ |
| 14567 | |
| 14568 | static void |
| 14569 | free_one_comp_unit (void *data) |
| 14570 | { |
| 14571 | struct dwarf2_cu *cu = data; |
| 14572 | |
| 14573 | if (cu->per_cu != NULL) |
| 14574 | cu->per_cu->cu = NULL; |
| 14575 | cu->per_cu = NULL; |
| 14576 | |
| 14577 | obstack_free (&cu->comp_unit_obstack, NULL); |
| 14578 | |
| 14579 | xfree (cu); |
| 14580 | } |
| 14581 | |
| 14582 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
| 14583 | when we're finished with it. We can't free the pointer itself, but be |
| 14584 | sure to unlink it from the cache. Also release any associated storage |
| 14585 | and perform cache maintenance. |
| 14586 | |
| 14587 | Only used during partial symbol parsing. */ |
| 14588 | |
| 14589 | static void |
| 14590 | free_stack_comp_unit (void *data) |
| 14591 | { |
| 14592 | struct dwarf2_cu *cu = data; |
| 14593 | |
| 14594 | obstack_free (&cu->comp_unit_obstack, NULL); |
| 14595 | cu->partial_dies = NULL; |
| 14596 | |
| 14597 | if (cu->per_cu != NULL) |
| 14598 | { |
| 14599 | /* This compilation unit is on the stack in our caller, so we |
| 14600 | should not xfree it. Just unlink it. */ |
| 14601 | cu->per_cu->cu = NULL; |
| 14602 | cu->per_cu = NULL; |
| 14603 | |
| 14604 | /* If we had a per-cu pointer, then we may have other compilation |
| 14605 | units loaded, so age them now. */ |
| 14606 | age_cached_comp_units (); |
| 14607 | } |
| 14608 | } |
| 14609 | |
| 14610 | /* Free all cached compilation units. */ |
| 14611 | |
| 14612 | static void |
| 14613 | free_cached_comp_units (void *data) |
| 14614 | { |
| 14615 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 14616 | |
| 14617 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 14618 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 14619 | while (per_cu != NULL) |
| 14620 | { |
| 14621 | struct dwarf2_per_cu_data *next_cu; |
| 14622 | |
| 14623 | next_cu = per_cu->cu->read_in_chain; |
| 14624 | |
| 14625 | free_one_comp_unit (per_cu->cu); |
| 14626 | *last_chain = next_cu; |
| 14627 | |
| 14628 | per_cu = next_cu; |
| 14629 | } |
| 14630 | } |
| 14631 | |
| 14632 | /* Increase the age counter on each cached compilation unit, and free |
| 14633 | any that are too old. */ |
| 14634 | |
| 14635 | static void |
| 14636 | age_cached_comp_units (void) |
| 14637 | { |
| 14638 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 14639 | |
| 14640 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); |
| 14641 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 14642 | while (per_cu != NULL) |
| 14643 | { |
| 14644 | per_cu->cu->last_used ++; |
| 14645 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) |
| 14646 | dwarf2_mark (per_cu->cu); |
| 14647 | per_cu = per_cu->cu->read_in_chain; |
| 14648 | } |
| 14649 | |
| 14650 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 14651 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 14652 | while (per_cu != NULL) |
| 14653 | { |
| 14654 | struct dwarf2_per_cu_data *next_cu; |
| 14655 | |
| 14656 | next_cu = per_cu->cu->read_in_chain; |
| 14657 | |
| 14658 | if (!per_cu->cu->mark) |
| 14659 | { |
| 14660 | free_one_comp_unit (per_cu->cu); |
| 14661 | *last_chain = next_cu; |
| 14662 | } |
| 14663 | else |
| 14664 | last_chain = &per_cu->cu->read_in_chain; |
| 14665 | |
| 14666 | per_cu = next_cu; |
| 14667 | } |
| 14668 | } |
| 14669 | |
| 14670 | /* Remove a single compilation unit from the cache. */ |
| 14671 | |
| 14672 | static void |
| 14673 | free_one_cached_comp_unit (void *target_cu) |
| 14674 | { |
| 14675 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 14676 | |
| 14677 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 14678 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 14679 | while (per_cu != NULL) |
| 14680 | { |
| 14681 | struct dwarf2_per_cu_data *next_cu; |
| 14682 | |
| 14683 | next_cu = per_cu->cu->read_in_chain; |
| 14684 | |
| 14685 | if (per_cu->cu == target_cu) |
| 14686 | { |
| 14687 | free_one_comp_unit (per_cu->cu); |
| 14688 | *last_chain = next_cu; |
| 14689 | break; |
| 14690 | } |
| 14691 | else |
| 14692 | last_chain = &per_cu->cu->read_in_chain; |
| 14693 | |
| 14694 | per_cu = next_cu; |
| 14695 | } |
| 14696 | } |
| 14697 | |
| 14698 | /* Release all extra memory associated with OBJFILE. */ |
| 14699 | |
| 14700 | void |
| 14701 | dwarf2_free_objfile (struct objfile *objfile) |
| 14702 | { |
| 14703 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 14704 | |
| 14705 | if (dwarf2_per_objfile == NULL) |
| 14706 | return; |
| 14707 | |
| 14708 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ |
| 14709 | free_cached_comp_units (NULL); |
| 14710 | |
| 14711 | if (dwarf2_per_objfile->quick_file_names_table) |
| 14712 | htab_delete (dwarf2_per_objfile->quick_file_names_table); |
| 14713 | |
| 14714 | /* Everything else should be on the objfile obstack. */ |
| 14715 | } |
| 14716 | |
| 14717 | /* A pair of DIE offset and GDB type pointer. We store these |
| 14718 | in a hash table separate from the DIEs, and preserve them |
| 14719 | when the DIEs are flushed out of cache. */ |
| 14720 | |
| 14721 | struct dwarf2_offset_and_type |
| 14722 | { |
| 14723 | unsigned int offset; |
| 14724 | struct type *type; |
| 14725 | }; |
| 14726 | |
| 14727 | /* Hash function for a dwarf2_offset_and_type. */ |
| 14728 | |
| 14729 | static hashval_t |
| 14730 | offset_and_type_hash (const void *item) |
| 14731 | { |
| 14732 | const struct dwarf2_offset_and_type *ofs = item; |
| 14733 | |
| 14734 | return ofs->offset; |
| 14735 | } |
| 14736 | |
| 14737 | /* Equality function for a dwarf2_offset_and_type. */ |
| 14738 | |
| 14739 | static int |
| 14740 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
| 14741 | { |
| 14742 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; |
| 14743 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; |
| 14744 | |
| 14745 | return ofs_lhs->offset == ofs_rhs->offset; |
| 14746 | } |
| 14747 | |
| 14748 | /* Set the type associated with DIE to TYPE. Save it in CU's hash |
| 14749 | table if necessary. For convenience, return TYPE. |
| 14750 | |
| 14751 | The DIEs reading must have careful ordering to: |
| 14752 | * Not cause infite loops trying to read in DIEs as a prerequisite for |
| 14753 | reading current DIE. |
| 14754 | * Not trying to dereference contents of still incompletely read in types |
| 14755 | while reading in other DIEs. |
| 14756 | * Enable referencing still incompletely read in types just by a pointer to |
| 14757 | the type without accessing its fields. |
| 14758 | |
| 14759 | Therefore caller should follow these rules: |
| 14760 | * Try to fetch any prerequisite types we may need to build this DIE type |
| 14761 | before building the type and calling set_die_type. |
| 14762 | * After building type call set_die_type for current DIE as soon as |
| 14763 | possible before fetching more types to complete the current type. |
| 14764 | * Make the type as complete as possible before fetching more types. */ |
| 14765 | |
| 14766 | static struct type * |
| 14767 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
| 14768 | { |
| 14769 | struct dwarf2_offset_and_type **slot, ofs; |
| 14770 | struct objfile *objfile = cu->objfile; |
| 14771 | htab_t *type_hash_ptr; |
| 14772 | |
| 14773 | /* For Ada types, make sure that the gnat-specific data is always |
| 14774 | initialized (if not already set). There are a few types where |
| 14775 | we should not be doing so, because the type-specific area is |
| 14776 | already used to hold some other piece of info (eg: TYPE_CODE_FLT |
| 14777 | where the type-specific area is used to store the floatformat). |
| 14778 | But this is not a problem, because the gnat-specific information |
| 14779 | is actually not needed for these types. */ |
| 14780 | if (need_gnat_info (cu) |
| 14781 | && TYPE_CODE (type) != TYPE_CODE_FUNC |
| 14782 | && TYPE_CODE (type) != TYPE_CODE_FLT |
| 14783 | && !HAVE_GNAT_AUX_INFO (type)) |
| 14784 | INIT_GNAT_SPECIFIC (type); |
| 14785 | |
| 14786 | if (cu->per_cu->from_debug_types) |
| 14787 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; |
| 14788 | else |
| 14789 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; |
| 14790 | |
| 14791 | if (*type_hash_ptr == NULL) |
| 14792 | { |
| 14793 | *type_hash_ptr |
| 14794 | = htab_create_alloc_ex (127, |
| 14795 | offset_and_type_hash, |
| 14796 | offset_and_type_eq, |
| 14797 | NULL, |
| 14798 | &objfile->objfile_obstack, |
| 14799 | hashtab_obstack_allocate, |
| 14800 | dummy_obstack_deallocate); |
| 14801 | } |
| 14802 | |
| 14803 | ofs.offset = die->offset; |
| 14804 | ofs.type = type; |
| 14805 | slot = (struct dwarf2_offset_and_type **) |
| 14806 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
| 14807 | if (*slot) |
| 14808 | complaint (&symfile_complaints, |
| 14809 | _("A problem internal to GDB: DIE 0x%x has type already set"), |
| 14810 | die->offset); |
| 14811 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
| 14812 | **slot = ofs; |
| 14813 | return type; |
| 14814 | } |
| 14815 | |
| 14816 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
| 14817 | table, or return NULL if the die does not have a saved type. */ |
| 14818 | |
| 14819 | static struct type * |
| 14820 | get_die_type_at_offset (unsigned int offset, |
| 14821 | struct dwarf2_per_cu_data *per_cu) |
| 14822 | { |
| 14823 | struct dwarf2_offset_and_type *slot, ofs; |
| 14824 | htab_t type_hash; |
| 14825 | |
| 14826 | if (per_cu->from_debug_types) |
| 14827 | type_hash = dwarf2_per_objfile->debug_types_type_hash; |
| 14828 | else |
| 14829 | type_hash = dwarf2_per_objfile->debug_info_type_hash; |
| 14830 | if (type_hash == NULL) |
| 14831 | return NULL; |
| 14832 | |
| 14833 | ofs.offset = offset; |
| 14834 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
| 14835 | if (slot) |
| 14836 | return slot->type; |
| 14837 | else |
| 14838 | return NULL; |
| 14839 | } |
| 14840 | |
| 14841 | /* Look up the type for DIE in the appropriate type_hash table, |
| 14842 | or return NULL if DIE does not have a saved type. */ |
| 14843 | |
| 14844 | static struct type * |
| 14845 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
| 14846 | { |
| 14847 | return get_die_type_at_offset (die->offset, cu->per_cu); |
| 14848 | } |
| 14849 | |
| 14850 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
| 14851 | |
| 14852 | static void |
| 14853 | dwarf2_add_dependence (struct dwarf2_cu *cu, |
| 14854 | struct dwarf2_per_cu_data *ref_per_cu) |
| 14855 | { |
| 14856 | void **slot; |
| 14857 | |
| 14858 | if (cu->dependencies == NULL) |
| 14859 | cu->dependencies |
| 14860 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, |
| 14861 | NULL, &cu->comp_unit_obstack, |
| 14862 | hashtab_obstack_allocate, |
| 14863 | dummy_obstack_deallocate); |
| 14864 | |
| 14865 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); |
| 14866 | if (*slot == NULL) |
| 14867 | *slot = ref_per_cu; |
| 14868 | } |
| 14869 | |
| 14870 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
| 14871 | Set the mark field in every compilation unit in the |
| 14872 | cache that we must keep because we are keeping CU. */ |
| 14873 | |
| 14874 | static int |
| 14875 | dwarf2_mark_helper (void **slot, void *data) |
| 14876 | { |
| 14877 | struct dwarf2_per_cu_data *per_cu; |
| 14878 | |
| 14879 | per_cu = (struct dwarf2_per_cu_data *) *slot; |
| 14880 | if (per_cu->cu->mark) |
| 14881 | return 1; |
| 14882 | per_cu->cu->mark = 1; |
| 14883 | |
| 14884 | if (per_cu->cu->dependencies != NULL) |
| 14885 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); |
| 14886 | |
| 14887 | return 1; |
| 14888 | } |
| 14889 | |
| 14890 | /* Set the mark field in CU and in every other compilation unit in the |
| 14891 | cache that we must keep because we are keeping CU. */ |
| 14892 | |
| 14893 | static void |
| 14894 | dwarf2_mark (struct dwarf2_cu *cu) |
| 14895 | { |
| 14896 | if (cu->mark) |
| 14897 | return; |
| 14898 | cu->mark = 1; |
| 14899 | if (cu->dependencies != NULL) |
| 14900 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); |
| 14901 | } |
| 14902 | |
| 14903 | static void |
| 14904 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) |
| 14905 | { |
| 14906 | while (per_cu) |
| 14907 | { |
| 14908 | per_cu->cu->mark = 0; |
| 14909 | per_cu = per_cu->cu->read_in_chain; |
| 14910 | } |
| 14911 | } |
| 14912 | |
| 14913 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
| 14914 | is its offset in .debug_info for this objfile. */ |
| 14915 | |
| 14916 | static hashval_t |
| 14917 | partial_die_hash (const void *item) |
| 14918 | { |
| 14919 | const struct partial_die_info *part_die = item; |
| 14920 | |
| 14921 | return part_die->offset; |
| 14922 | } |
| 14923 | |
| 14924 | /* Trivial comparison function for partial_die_info structures: two DIEs |
| 14925 | are equal if they have the same offset. */ |
| 14926 | |
| 14927 | static int |
| 14928 | partial_die_eq (const void *item_lhs, const void *item_rhs) |
| 14929 | { |
| 14930 | const struct partial_die_info *part_die_lhs = item_lhs; |
| 14931 | const struct partial_die_info *part_die_rhs = item_rhs; |
| 14932 | |
| 14933 | return part_die_lhs->offset == part_die_rhs->offset; |
| 14934 | } |
| 14935 | |
| 14936 | static struct cmd_list_element *set_dwarf2_cmdlist; |
| 14937 | static struct cmd_list_element *show_dwarf2_cmdlist; |
| 14938 | |
| 14939 | static void |
| 14940 | set_dwarf2_cmd (char *args, int from_tty) |
| 14941 | { |
| 14942 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); |
| 14943 | } |
| 14944 | |
| 14945 | static void |
| 14946 | show_dwarf2_cmd (char *args, int from_tty) |
| 14947 | { |
| 14948 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
| 14949 | } |
| 14950 | |
| 14951 | /* If section described by INFO was mmapped, munmap it now. */ |
| 14952 | |
| 14953 | static void |
| 14954 | munmap_section_buffer (struct dwarf2_section_info *info) |
| 14955 | { |
| 14956 | if (info->was_mmapped) |
| 14957 | { |
| 14958 | #ifdef HAVE_MMAP |
| 14959 | intptr_t begin = (intptr_t) info->buffer; |
| 14960 | intptr_t map_begin = begin & ~(pagesize - 1); |
| 14961 | size_t map_length = info->size + begin - map_begin; |
| 14962 | |
| 14963 | gdb_assert (munmap ((void *) map_begin, map_length) == 0); |
| 14964 | #else |
| 14965 | /* Without HAVE_MMAP, we should never be here to begin with. */ |
| 14966 | gdb_assert_not_reached ("no mmap support"); |
| 14967 | #endif |
| 14968 | } |
| 14969 | } |
| 14970 | |
| 14971 | /* munmap debug sections for OBJFILE, if necessary. */ |
| 14972 | |
| 14973 | static void |
| 14974 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
| 14975 | { |
| 14976 | struct dwarf2_per_objfile *data = d; |
| 14977 | |
| 14978 | /* This is sorted according to the order they're defined in to make it easier |
| 14979 | to keep in sync. */ |
| 14980 | munmap_section_buffer (&data->info); |
| 14981 | munmap_section_buffer (&data->abbrev); |
| 14982 | munmap_section_buffer (&data->line); |
| 14983 | munmap_section_buffer (&data->loc); |
| 14984 | munmap_section_buffer (&data->macinfo); |
| 14985 | munmap_section_buffer (&data->str); |
| 14986 | munmap_section_buffer (&data->ranges); |
| 14987 | munmap_section_buffer (&data->types); |
| 14988 | munmap_section_buffer (&data->frame); |
| 14989 | munmap_section_buffer (&data->eh_frame); |
| 14990 | munmap_section_buffer (&data->gdb_index); |
| 14991 | } |
| 14992 | |
| 14993 | \f |
| 14994 | /* The "save gdb-index" command. */ |
| 14995 | |
| 14996 | /* The contents of the hash table we create when building the string |
| 14997 | table. */ |
| 14998 | struct strtab_entry |
| 14999 | { |
| 15000 | offset_type offset; |
| 15001 | const char *str; |
| 15002 | }; |
| 15003 | |
| 15004 | /* Hash function for a strtab_entry. */ |
| 15005 | |
| 15006 | static hashval_t |
| 15007 | hash_strtab_entry (const void *e) |
| 15008 | { |
| 15009 | const struct strtab_entry *entry = e; |
| 15010 | return mapped_index_string_hash (entry->str); |
| 15011 | } |
| 15012 | |
| 15013 | /* Equality function for a strtab_entry. */ |
| 15014 | |
| 15015 | static int |
| 15016 | eq_strtab_entry (const void *a, const void *b) |
| 15017 | { |
| 15018 | const struct strtab_entry *ea = a; |
| 15019 | const struct strtab_entry *eb = b; |
| 15020 | return !strcmp (ea->str, eb->str); |
| 15021 | } |
| 15022 | |
| 15023 | /* Create a strtab_entry hash table. */ |
| 15024 | |
| 15025 | static htab_t |
| 15026 | create_strtab (void) |
| 15027 | { |
| 15028 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, |
| 15029 | xfree, xcalloc, xfree); |
| 15030 | } |
| 15031 | |
| 15032 | /* Add a string to the constant pool. Return the string's offset in |
| 15033 | host order. */ |
| 15034 | |
| 15035 | static offset_type |
| 15036 | add_string (htab_t table, struct obstack *cpool, const char *str) |
| 15037 | { |
| 15038 | void **slot; |
| 15039 | struct strtab_entry entry; |
| 15040 | struct strtab_entry *result; |
| 15041 | |
| 15042 | entry.str = str; |
| 15043 | slot = htab_find_slot (table, &entry, INSERT); |
| 15044 | if (*slot) |
| 15045 | result = *slot; |
| 15046 | else |
| 15047 | { |
| 15048 | result = XNEW (struct strtab_entry); |
| 15049 | result->offset = obstack_object_size (cpool); |
| 15050 | result->str = str; |
| 15051 | obstack_grow_str0 (cpool, str); |
| 15052 | *slot = result; |
| 15053 | } |
| 15054 | return result->offset; |
| 15055 | } |
| 15056 | |
| 15057 | /* An entry in the symbol table. */ |
| 15058 | struct symtab_index_entry |
| 15059 | { |
| 15060 | /* The name of the symbol. */ |
| 15061 | const char *name; |
| 15062 | /* The offset of the name in the constant pool. */ |
| 15063 | offset_type index_offset; |
| 15064 | /* A sorted vector of the indices of all the CUs that hold an object |
| 15065 | of this name. */ |
| 15066 | VEC (offset_type) *cu_indices; |
| 15067 | }; |
| 15068 | |
| 15069 | /* The symbol table. This is a power-of-2-sized hash table. */ |
| 15070 | struct mapped_symtab |
| 15071 | { |
| 15072 | offset_type n_elements; |
| 15073 | offset_type size; |
| 15074 | struct symtab_index_entry **data; |
| 15075 | }; |
| 15076 | |
| 15077 | /* Hash function for a symtab_index_entry. */ |
| 15078 | |
| 15079 | static hashval_t |
| 15080 | hash_symtab_entry (const void *e) |
| 15081 | { |
| 15082 | const struct symtab_index_entry *entry = e; |
| 15083 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), |
| 15084 | sizeof (offset_type) * VEC_length (offset_type, |
| 15085 | entry->cu_indices), |
| 15086 | 0); |
| 15087 | } |
| 15088 | |
| 15089 | /* Equality function for a symtab_index_entry. */ |
| 15090 | |
| 15091 | static int |
| 15092 | eq_symtab_entry (const void *a, const void *b) |
| 15093 | { |
| 15094 | const struct symtab_index_entry *ea = a; |
| 15095 | const struct symtab_index_entry *eb = b; |
| 15096 | int len = VEC_length (offset_type, ea->cu_indices); |
| 15097 | if (len != VEC_length (offset_type, eb->cu_indices)) |
| 15098 | return 0; |
| 15099 | return !memcmp (VEC_address (offset_type, ea->cu_indices), |
| 15100 | VEC_address (offset_type, eb->cu_indices), |
| 15101 | sizeof (offset_type) * len); |
| 15102 | } |
| 15103 | |
| 15104 | /* Destroy a symtab_index_entry. */ |
| 15105 | |
| 15106 | static void |
| 15107 | delete_symtab_entry (void *p) |
| 15108 | { |
| 15109 | struct symtab_index_entry *entry = p; |
| 15110 | VEC_free (offset_type, entry->cu_indices); |
| 15111 | xfree (entry); |
| 15112 | } |
| 15113 | |
| 15114 | /* Create a hash table holding symtab_index_entry objects. */ |
| 15115 | |
| 15116 | static htab_t |
| 15117 | create_symbol_hash_table (void) |
| 15118 | { |
| 15119 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, |
| 15120 | delete_symtab_entry, xcalloc, xfree); |
| 15121 | } |
| 15122 | |
| 15123 | /* Create a new mapped symtab object. */ |
| 15124 | |
| 15125 | static struct mapped_symtab * |
| 15126 | create_mapped_symtab (void) |
| 15127 | { |
| 15128 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); |
| 15129 | symtab->n_elements = 0; |
| 15130 | symtab->size = 1024; |
| 15131 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); |
| 15132 | return symtab; |
| 15133 | } |
| 15134 | |
| 15135 | /* Destroy a mapped_symtab. */ |
| 15136 | |
| 15137 | static void |
| 15138 | cleanup_mapped_symtab (void *p) |
| 15139 | { |
| 15140 | struct mapped_symtab *symtab = p; |
| 15141 | /* The contents of the array are freed when the other hash table is |
| 15142 | destroyed. */ |
| 15143 | xfree (symtab->data); |
| 15144 | xfree (symtab); |
| 15145 | } |
| 15146 | |
| 15147 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to |
| 15148 | the slot. */ |
| 15149 | |
| 15150 | static struct symtab_index_entry ** |
| 15151 | find_slot (struct mapped_symtab *symtab, const char *name) |
| 15152 | { |
| 15153 | offset_type index, step, hash = mapped_index_string_hash (name); |
| 15154 | |
| 15155 | index = hash & (symtab->size - 1); |
| 15156 | step = ((hash * 17) & (symtab->size - 1)) | 1; |
| 15157 | |
| 15158 | for (;;) |
| 15159 | { |
| 15160 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) |
| 15161 | return &symtab->data[index]; |
| 15162 | index = (index + step) & (symtab->size - 1); |
| 15163 | } |
| 15164 | } |
| 15165 | |
| 15166 | /* Expand SYMTAB's hash table. */ |
| 15167 | |
| 15168 | static void |
| 15169 | hash_expand (struct mapped_symtab *symtab) |
| 15170 | { |
| 15171 | offset_type old_size = symtab->size; |
| 15172 | offset_type i; |
| 15173 | struct symtab_index_entry **old_entries = symtab->data; |
| 15174 | |
| 15175 | symtab->size *= 2; |
| 15176 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); |
| 15177 | |
| 15178 | for (i = 0; i < old_size; ++i) |
| 15179 | { |
| 15180 | if (old_entries[i]) |
| 15181 | { |
| 15182 | struct symtab_index_entry **slot = find_slot (symtab, |
| 15183 | old_entries[i]->name); |
| 15184 | *slot = old_entries[i]; |
| 15185 | } |
| 15186 | } |
| 15187 | |
| 15188 | xfree (old_entries); |
| 15189 | } |
| 15190 | |
| 15191 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX |
| 15192 | is the index of the CU in which the symbol appears. */ |
| 15193 | |
| 15194 | static void |
| 15195 | add_index_entry (struct mapped_symtab *symtab, const char *name, |
| 15196 | offset_type cu_index) |
| 15197 | { |
| 15198 | struct symtab_index_entry **slot; |
| 15199 | |
| 15200 | ++symtab->n_elements; |
| 15201 | if (4 * symtab->n_elements / 3 >= symtab->size) |
| 15202 | hash_expand (symtab); |
| 15203 | |
| 15204 | slot = find_slot (symtab, name); |
| 15205 | if (!*slot) |
| 15206 | { |
| 15207 | *slot = XNEW (struct symtab_index_entry); |
| 15208 | (*slot)->name = name; |
| 15209 | (*slot)->cu_indices = NULL; |
| 15210 | } |
| 15211 | /* Don't push an index twice. Due to how we add entries we only |
| 15212 | have to check the last one. */ |
| 15213 | if (VEC_empty (offset_type, (*slot)->cu_indices) |
| 15214 | || VEC_length (offset_type, (*slot)->cu_indices) != cu_index) |
| 15215 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
| 15216 | } |
| 15217 | |
| 15218 | /* Add a vector of indices to the constant pool. */ |
| 15219 | |
| 15220 | static offset_type |
| 15221 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
| 15222 | struct symtab_index_entry *entry) |
| 15223 | { |
| 15224 | void **slot; |
| 15225 | |
| 15226 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
| 15227 | if (!*slot) |
| 15228 | { |
| 15229 | offset_type len = VEC_length (offset_type, entry->cu_indices); |
| 15230 | offset_type val = MAYBE_SWAP (len); |
| 15231 | offset_type iter; |
| 15232 | int i; |
| 15233 | |
| 15234 | *slot = entry; |
| 15235 | entry->index_offset = obstack_object_size (cpool); |
| 15236 | |
| 15237 | obstack_grow (cpool, &val, sizeof (val)); |
| 15238 | for (i = 0; |
| 15239 | VEC_iterate (offset_type, entry->cu_indices, i, iter); |
| 15240 | ++i) |
| 15241 | { |
| 15242 | val = MAYBE_SWAP (iter); |
| 15243 | obstack_grow (cpool, &val, sizeof (val)); |
| 15244 | } |
| 15245 | } |
| 15246 | else |
| 15247 | { |
| 15248 | struct symtab_index_entry *old_entry = *slot; |
| 15249 | entry->index_offset = old_entry->index_offset; |
| 15250 | entry = old_entry; |
| 15251 | } |
| 15252 | return entry->index_offset; |
| 15253 | } |
| 15254 | |
| 15255 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with |
| 15256 | constant pool entries going into the obstack CPOOL. */ |
| 15257 | |
| 15258 | static void |
| 15259 | write_hash_table (struct mapped_symtab *symtab, |
| 15260 | struct obstack *output, struct obstack *cpool) |
| 15261 | { |
| 15262 | offset_type i; |
| 15263 | htab_t symbol_hash_table; |
| 15264 | htab_t str_table; |
| 15265 | |
| 15266 | symbol_hash_table = create_symbol_hash_table (); |
| 15267 | str_table = create_strtab (); |
| 15268 | |
| 15269 | /* We add all the index vectors to the constant pool first, to |
| 15270 | ensure alignment is ok. */ |
| 15271 | for (i = 0; i < symtab->size; ++i) |
| 15272 | { |
| 15273 | if (symtab->data[i]) |
| 15274 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
| 15275 | } |
| 15276 | |
| 15277 | /* Now write out the hash table. */ |
| 15278 | for (i = 0; i < symtab->size; ++i) |
| 15279 | { |
| 15280 | offset_type str_off, vec_off; |
| 15281 | |
| 15282 | if (symtab->data[i]) |
| 15283 | { |
| 15284 | str_off = add_string (str_table, cpool, symtab->data[i]->name); |
| 15285 | vec_off = symtab->data[i]->index_offset; |
| 15286 | } |
| 15287 | else |
| 15288 | { |
| 15289 | /* While 0 is a valid constant pool index, it is not valid |
| 15290 | to have 0 for both offsets. */ |
| 15291 | str_off = 0; |
| 15292 | vec_off = 0; |
| 15293 | } |
| 15294 | |
| 15295 | str_off = MAYBE_SWAP (str_off); |
| 15296 | vec_off = MAYBE_SWAP (vec_off); |
| 15297 | |
| 15298 | obstack_grow (output, &str_off, sizeof (str_off)); |
| 15299 | obstack_grow (output, &vec_off, sizeof (vec_off)); |
| 15300 | } |
| 15301 | |
| 15302 | htab_delete (str_table); |
| 15303 | htab_delete (symbol_hash_table); |
| 15304 | } |
| 15305 | |
| 15306 | /* Struct to map psymtab to CU index in the index file. */ |
| 15307 | struct psymtab_cu_index_map |
| 15308 | { |
| 15309 | struct partial_symtab *psymtab; |
| 15310 | unsigned int cu_index; |
| 15311 | }; |
| 15312 | |
| 15313 | static hashval_t |
| 15314 | hash_psymtab_cu_index (const void *item) |
| 15315 | { |
| 15316 | const struct psymtab_cu_index_map *map = item; |
| 15317 | |
| 15318 | return htab_hash_pointer (map->psymtab); |
| 15319 | } |
| 15320 | |
| 15321 | static int |
| 15322 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) |
| 15323 | { |
| 15324 | const struct psymtab_cu_index_map *lhs = item_lhs; |
| 15325 | const struct psymtab_cu_index_map *rhs = item_rhs; |
| 15326 | |
| 15327 | return lhs->psymtab == rhs->psymtab; |
| 15328 | } |
| 15329 | |
| 15330 | /* Helper struct for building the address table. */ |
| 15331 | struct addrmap_index_data |
| 15332 | { |
| 15333 | struct objfile *objfile; |
| 15334 | struct obstack *addr_obstack; |
| 15335 | htab_t cu_index_htab; |
| 15336 | |
| 15337 | /* Non-zero if the previous_* fields are valid. |
| 15338 | We can't write an entry until we see the next entry (since it is only then |
| 15339 | that we know the end of the entry). */ |
| 15340 | int previous_valid; |
| 15341 | /* Index of the CU in the table of all CUs in the index file. */ |
| 15342 | unsigned int previous_cu_index; |
| 15343 | /* Start address of the CU. */ |
| 15344 | CORE_ADDR previous_cu_start; |
| 15345 | }; |
| 15346 | |
| 15347 | /* Write an address entry to OBSTACK. */ |
| 15348 | |
| 15349 | static void |
| 15350 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
| 15351 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) |
| 15352 | { |
| 15353 | offset_type cu_index_to_write; |
| 15354 | char addr[8]; |
| 15355 | CORE_ADDR baseaddr; |
| 15356 | |
| 15357 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 15358 | |
| 15359 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
| 15360 | obstack_grow (obstack, addr, 8); |
| 15361 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); |
| 15362 | obstack_grow (obstack, addr, 8); |
| 15363 | cu_index_to_write = MAYBE_SWAP (cu_index); |
| 15364 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); |
| 15365 | } |
| 15366 | |
| 15367 | /* Worker function for traversing an addrmap to build the address table. */ |
| 15368 | |
| 15369 | static int |
| 15370 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) |
| 15371 | { |
| 15372 | struct addrmap_index_data *data = datap; |
| 15373 | struct partial_symtab *pst = obj; |
| 15374 | offset_type cu_index; |
| 15375 | void **slot; |
| 15376 | |
| 15377 | if (data->previous_valid) |
| 15378 | add_address_entry (data->objfile, data->addr_obstack, |
| 15379 | data->previous_cu_start, start_addr, |
| 15380 | data->previous_cu_index); |
| 15381 | |
| 15382 | data->previous_cu_start = start_addr; |
| 15383 | if (pst != NULL) |
| 15384 | { |
| 15385 | struct psymtab_cu_index_map find_map, *map; |
| 15386 | find_map.psymtab = pst; |
| 15387 | map = htab_find (data->cu_index_htab, &find_map); |
| 15388 | gdb_assert (map != NULL); |
| 15389 | data->previous_cu_index = map->cu_index; |
| 15390 | data->previous_valid = 1; |
| 15391 | } |
| 15392 | else |
| 15393 | data->previous_valid = 0; |
| 15394 | |
| 15395 | return 0; |
| 15396 | } |
| 15397 | |
| 15398 | /* Write OBJFILE's address map to OBSTACK. |
| 15399 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices |
| 15400 | in the index file. */ |
| 15401 | |
| 15402 | static void |
| 15403 | write_address_map (struct objfile *objfile, struct obstack *obstack, |
| 15404 | htab_t cu_index_htab) |
| 15405 | { |
| 15406 | struct addrmap_index_data addrmap_index_data; |
| 15407 | |
| 15408 | /* When writing the address table, we have to cope with the fact that |
| 15409 | the addrmap iterator only provides the start of a region; we have to |
| 15410 | wait until the next invocation to get the start of the next region. */ |
| 15411 | |
| 15412 | addrmap_index_data.objfile = objfile; |
| 15413 | addrmap_index_data.addr_obstack = obstack; |
| 15414 | addrmap_index_data.cu_index_htab = cu_index_htab; |
| 15415 | addrmap_index_data.previous_valid = 0; |
| 15416 | |
| 15417 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, |
| 15418 | &addrmap_index_data); |
| 15419 | |
| 15420 | /* It's highly unlikely the last entry (end address = 0xff...ff) |
| 15421 | is valid, but we should still handle it. |
| 15422 | The end address is recorded as the start of the next region, but that |
| 15423 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation |
| 15424 | anyway. */ |
| 15425 | if (addrmap_index_data.previous_valid) |
| 15426 | add_address_entry (objfile, obstack, |
| 15427 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, |
| 15428 | addrmap_index_data.previous_cu_index); |
| 15429 | } |
| 15430 | |
| 15431 | /* Add a list of partial symbols to SYMTAB. */ |
| 15432 | |
| 15433 | static void |
| 15434 | write_psymbols (struct mapped_symtab *symtab, |
| 15435 | htab_t psyms_seen, |
| 15436 | struct partial_symbol **psymp, |
| 15437 | int count, |
| 15438 | offset_type cu_index, |
| 15439 | int is_static) |
| 15440 | { |
| 15441 | for (; count-- > 0; ++psymp) |
| 15442 | { |
| 15443 | void **slot, *lookup; |
| 15444 | |
| 15445 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
| 15446 | error (_("Ada is not currently supported by the index")); |
| 15447 | |
| 15448 | /* We only want to add a given psymbol once. However, we also |
| 15449 | want to account for whether it is global or static. So, we |
| 15450 | may add it twice, using slightly different values. */ |
| 15451 | if (is_static) |
| 15452 | { |
| 15453 | uintptr_t val = 1 | (uintptr_t) *psymp; |
| 15454 | |
| 15455 | lookup = (void *) val; |
| 15456 | } |
| 15457 | else |
| 15458 | lookup = *psymp; |
| 15459 | |
| 15460 | /* Only add a given psymbol once. */ |
| 15461 | slot = htab_find_slot (psyms_seen, lookup, INSERT); |
| 15462 | if (!*slot) |
| 15463 | { |
| 15464 | *slot = lookup; |
| 15465 | add_index_entry (symtab, SYMBOL_NATURAL_NAME (*psymp), cu_index); |
| 15466 | } |
| 15467 | } |
| 15468 | } |
| 15469 | |
| 15470 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an |
| 15471 | exception if there is an error. */ |
| 15472 | |
| 15473 | static void |
| 15474 | write_obstack (FILE *file, struct obstack *obstack) |
| 15475 | { |
| 15476 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), |
| 15477 | file) |
| 15478 | != obstack_object_size (obstack)) |
| 15479 | error (_("couldn't data write to file")); |
| 15480 | } |
| 15481 | |
| 15482 | /* Unlink a file if the argument is not NULL. */ |
| 15483 | |
| 15484 | static void |
| 15485 | unlink_if_set (void *p) |
| 15486 | { |
| 15487 | char **filename = p; |
| 15488 | if (*filename) |
| 15489 | unlink (*filename); |
| 15490 | } |
| 15491 | |
| 15492 | /* A helper struct used when iterating over debug_types. */ |
| 15493 | struct signatured_type_index_data |
| 15494 | { |
| 15495 | struct objfile *objfile; |
| 15496 | struct mapped_symtab *symtab; |
| 15497 | struct obstack *types_list; |
| 15498 | htab_t psyms_seen; |
| 15499 | int cu_index; |
| 15500 | }; |
| 15501 | |
| 15502 | /* A helper function that writes a single signatured_type to an |
| 15503 | obstack. */ |
| 15504 | |
| 15505 | static int |
| 15506 | write_one_signatured_type (void **slot, void *d) |
| 15507 | { |
| 15508 | struct signatured_type_index_data *info = d; |
| 15509 | struct signatured_type *entry = (struct signatured_type *) *slot; |
| 15510 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
| 15511 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
| 15512 | gdb_byte val[8]; |
| 15513 | |
| 15514 | write_psymbols (info->symtab, |
| 15515 | info->psyms_seen, |
| 15516 | info->objfile->global_psymbols.list |
| 15517 | + psymtab->globals_offset, |
| 15518 | psymtab->n_global_syms, info->cu_index, |
| 15519 | 0); |
| 15520 | write_psymbols (info->symtab, |
| 15521 | info->psyms_seen, |
| 15522 | info->objfile->static_psymbols.list |
| 15523 | + psymtab->statics_offset, |
| 15524 | psymtab->n_static_syms, info->cu_index, |
| 15525 | 1); |
| 15526 | |
| 15527 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->offset); |
| 15528 | obstack_grow (info->types_list, val, 8); |
| 15529 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); |
| 15530 | obstack_grow (info->types_list, val, 8); |
| 15531 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); |
| 15532 | obstack_grow (info->types_list, val, 8); |
| 15533 | |
| 15534 | ++info->cu_index; |
| 15535 | |
| 15536 | return 1; |
| 15537 | } |
| 15538 | |
| 15539 | /* A cleanup function for an htab_t. */ |
| 15540 | |
| 15541 | static void |
| 15542 | cleanup_htab (void *arg) |
| 15543 | { |
| 15544 | htab_delete (arg); |
| 15545 | } |
| 15546 | |
| 15547 | /* Create an index file for OBJFILE in the directory DIR. */ |
| 15548 | |
| 15549 | static void |
| 15550 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) |
| 15551 | { |
| 15552 | struct cleanup *cleanup; |
| 15553 | char *filename, *cleanup_filename; |
| 15554 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
| 15555 | struct obstack cu_list, types_cu_list; |
| 15556 | int i; |
| 15557 | FILE *out_file; |
| 15558 | struct mapped_symtab *symtab; |
| 15559 | offset_type val, size_of_contents, total_len; |
| 15560 | struct stat st; |
| 15561 | char buf[8]; |
| 15562 | htab_t psyms_seen; |
| 15563 | htab_t cu_index_htab; |
| 15564 | struct psymtab_cu_index_map *psymtab_cu_index_map; |
| 15565 | |
| 15566 | if (!objfile->psymtabs) |
| 15567 | return; |
| 15568 | if (dwarf2_per_objfile->using_index) |
| 15569 | error (_("Cannot use an index to create the index")); |
| 15570 | |
| 15571 | if (stat (objfile->name, &st) < 0) |
| 15572 | perror_with_name (objfile->name); |
| 15573 | |
| 15574 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), |
| 15575 | INDEX_SUFFIX, (char *) NULL); |
| 15576 | cleanup = make_cleanup (xfree, filename); |
| 15577 | |
| 15578 | out_file = fopen (filename, "wb"); |
| 15579 | if (!out_file) |
| 15580 | error (_("Can't open `%s' for writing"), filename); |
| 15581 | |
| 15582 | cleanup_filename = filename; |
| 15583 | make_cleanup (unlink_if_set, &cleanup_filename); |
| 15584 | |
| 15585 | symtab = create_mapped_symtab (); |
| 15586 | make_cleanup (cleanup_mapped_symtab, symtab); |
| 15587 | |
| 15588 | obstack_init (&addr_obstack); |
| 15589 | make_cleanup_obstack_free (&addr_obstack); |
| 15590 | |
| 15591 | obstack_init (&cu_list); |
| 15592 | make_cleanup_obstack_free (&cu_list); |
| 15593 | |
| 15594 | obstack_init (&types_cu_list); |
| 15595 | make_cleanup_obstack_free (&types_cu_list); |
| 15596 | |
| 15597 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
| 15598 | NULL, xcalloc, xfree); |
| 15599 | make_cleanup (cleanup_htab, psyms_seen); |
| 15600 | |
| 15601 | /* While we're scanning CU's create a table that maps a psymtab pointer |
| 15602 | (which is what addrmap records) to its index (which is what is recorded |
| 15603 | in the index file). This will later be needed to write the address |
| 15604 | table. */ |
| 15605 | cu_index_htab = htab_create_alloc (100, |
| 15606 | hash_psymtab_cu_index, |
| 15607 | eq_psymtab_cu_index, |
| 15608 | NULL, xcalloc, xfree); |
| 15609 | make_cleanup (cleanup_htab, cu_index_htab); |
| 15610 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
| 15611 | xmalloc (sizeof (struct psymtab_cu_index_map) |
| 15612 | * dwarf2_per_objfile->n_comp_units); |
| 15613 | make_cleanup (xfree, psymtab_cu_index_map); |
| 15614 | |
| 15615 | /* The CU list is already sorted, so we don't need to do additional |
| 15616 | work here. Also, the debug_types entries do not appear in |
| 15617 | all_comp_units, but only in their own hash table. */ |
| 15618 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 15619 | { |
| 15620 | struct dwarf2_per_cu_data *per_cu |
| 15621 | = dwarf2_per_objfile->all_comp_units[i]; |
| 15622 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
| 15623 | gdb_byte val[8]; |
| 15624 | struct psymtab_cu_index_map *map; |
| 15625 | void **slot; |
| 15626 | |
| 15627 | write_psymbols (symtab, |
| 15628 | psyms_seen, |
| 15629 | objfile->global_psymbols.list + psymtab->globals_offset, |
| 15630 | psymtab->n_global_syms, i, |
| 15631 | 0); |
| 15632 | write_psymbols (symtab, |
| 15633 | psyms_seen, |
| 15634 | objfile->static_psymbols.list + psymtab->statics_offset, |
| 15635 | psymtab->n_static_syms, i, |
| 15636 | 1); |
| 15637 | |
| 15638 | map = &psymtab_cu_index_map[i]; |
| 15639 | map->psymtab = psymtab; |
| 15640 | map->cu_index = i; |
| 15641 | slot = htab_find_slot (cu_index_htab, map, INSERT); |
| 15642 | gdb_assert (slot != NULL); |
| 15643 | gdb_assert (*slot == NULL); |
| 15644 | *slot = map; |
| 15645 | |
| 15646 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
| 15647 | obstack_grow (&cu_list, val, 8); |
| 15648 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
| 15649 | obstack_grow (&cu_list, val, 8); |
| 15650 | } |
| 15651 | |
| 15652 | /* Dump the address map. */ |
| 15653 | write_address_map (objfile, &addr_obstack, cu_index_htab); |
| 15654 | |
| 15655 | /* Write out the .debug_type entries, if any. */ |
| 15656 | if (dwarf2_per_objfile->signatured_types) |
| 15657 | { |
| 15658 | struct signatured_type_index_data sig_data; |
| 15659 | |
| 15660 | sig_data.objfile = objfile; |
| 15661 | sig_data.symtab = symtab; |
| 15662 | sig_data.types_list = &types_cu_list; |
| 15663 | sig_data.psyms_seen = psyms_seen; |
| 15664 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
| 15665 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, |
| 15666 | write_one_signatured_type, &sig_data); |
| 15667 | } |
| 15668 | |
| 15669 | obstack_init (&constant_pool); |
| 15670 | make_cleanup_obstack_free (&constant_pool); |
| 15671 | obstack_init (&symtab_obstack); |
| 15672 | make_cleanup_obstack_free (&symtab_obstack); |
| 15673 | write_hash_table (symtab, &symtab_obstack, &constant_pool); |
| 15674 | |
| 15675 | obstack_init (&contents); |
| 15676 | make_cleanup_obstack_free (&contents); |
| 15677 | size_of_contents = 6 * sizeof (offset_type); |
| 15678 | total_len = size_of_contents; |
| 15679 | |
| 15680 | /* The version number. */ |
| 15681 | val = MAYBE_SWAP (3); |
| 15682 | obstack_grow (&contents, &val, sizeof (val)); |
| 15683 | |
| 15684 | /* The offset of the CU list from the start of the file. */ |
| 15685 | val = MAYBE_SWAP (total_len); |
| 15686 | obstack_grow (&contents, &val, sizeof (val)); |
| 15687 | total_len += obstack_object_size (&cu_list); |
| 15688 | |
| 15689 | /* The offset of the types CU list from the start of the file. */ |
| 15690 | val = MAYBE_SWAP (total_len); |
| 15691 | obstack_grow (&contents, &val, sizeof (val)); |
| 15692 | total_len += obstack_object_size (&types_cu_list); |
| 15693 | |
| 15694 | /* The offset of the address table from the start of the file. */ |
| 15695 | val = MAYBE_SWAP (total_len); |
| 15696 | obstack_grow (&contents, &val, sizeof (val)); |
| 15697 | total_len += obstack_object_size (&addr_obstack); |
| 15698 | |
| 15699 | /* The offset of the symbol table from the start of the file. */ |
| 15700 | val = MAYBE_SWAP (total_len); |
| 15701 | obstack_grow (&contents, &val, sizeof (val)); |
| 15702 | total_len += obstack_object_size (&symtab_obstack); |
| 15703 | |
| 15704 | /* The offset of the constant pool from the start of the file. */ |
| 15705 | val = MAYBE_SWAP (total_len); |
| 15706 | obstack_grow (&contents, &val, sizeof (val)); |
| 15707 | total_len += obstack_object_size (&constant_pool); |
| 15708 | |
| 15709 | gdb_assert (obstack_object_size (&contents) == size_of_contents); |
| 15710 | |
| 15711 | write_obstack (out_file, &contents); |
| 15712 | write_obstack (out_file, &cu_list); |
| 15713 | write_obstack (out_file, &types_cu_list); |
| 15714 | write_obstack (out_file, &addr_obstack); |
| 15715 | write_obstack (out_file, &symtab_obstack); |
| 15716 | write_obstack (out_file, &constant_pool); |
| 15717 | |
| 15718 | fclose (out_file); |
| 15719 | |
| 15720 | /* We want to keep the file, so we set cleanup_filename to NULL |
| 15721 | here. See unlink_if_set. */ |
| 15722 | cleanup_filename = NULL; |
| 15723 | |
| 15724 | do_cleanups (cleanup); |
| 15725 | } |
| 15726 | |
| 15727 | /* The mapped index file format is designed to be directly mmap()able |
| 15728 | on any architecture. In most cases, a datum is represented using a |
| 15729 | little-endian 32-bit integer value, called an offset_type. Big |
| 15730 | endian machines must byte-swap the values before using them. |
| 15731 | Exceptions to this rule are noted. The data is laid out such that |
| 15732 | alignment is always respected. |
| 15733 | |
| 15734 | A mapped index consists of several sections. |
| 15735 | |
| 15736 | 1. The file header. This is a sequence of values, of offset_type |
| 15737 | unless otherwise noted: |
| 15738 | |
| 15739 | [0] The version number, currently 3. Versions 1 and 2 are |
| 15740 | obsolete. |
| 15741 | [1] The offset, from the start of the file, of the CU list. |
| 15742 | [2] The offset, from the start of the file, of the types CU list. |
| 15743 | Note that this section can be empty, in which case this offset will |
| 15744 | be equal to the next offset. |
| 15745 | [3] The offset, from the start of the file, of the address section. |
| 15746 | [4] The offset, from the start of the file, of the symbol table. |
| 15747 | [5] The offset, from the start of the file, of the constant pool. |
| 15748 | |
| 15749 | 2. The CU list. This is a sequence of pairs of 64-bit |
| 15750 | little-endian values, sorted by the CU offset. The first element |
| 15751 | in each pair is the offset of a CU in the .debug_info section. The |
| 15752 | second element in each pair is the length of that CU. References |
| 15753 | to a CU elsewhere in the map are done using a CU index, which is |
| 15754 | just the 0-based index into this table. Note that if there are |
| 15755 | type CUs, then conceptually CUs and type CUs form a single list for |
| 15756 | the purposes of CU indices. |
| 15757 | |
| 15758 | 3. The types CU list. This is a sequence of triplets of 64-bit |
| 15759 | little-endian values. In a triplet, the first value is the CU |
| 15760 | offset, the second value is the type offset in the CU, and the |
| 15761 | third value is the type signature. The types CU list is not |
| 15762 | sorted. |
| 15763 | |
| 15764 | 4. The address section. The address section consists of a sequence |
| 15765 | of address entries. Each address entry has three elements. |
| 15766 | [0] The low address. This is a 64-bit little-endian value. |
| 15767 | [1] The high address. This is a 64-bit little-endian value. |
| 15768 | Like DW_AT_high_pc, the value is one byte beyond the end. |
| 15769 | [2] The CU index. This is an offset_type value. |
| 15770 | |
| 15771 | 5. The symbol table. This is a hash table. The size of the hash |
| 15772 | table is always a power of 2. The initial hash and the step are |
| 15773 | currently defined by the `find_slot' function. |
| 15774 | |
| 15775 | Each slot in the hash table consists of a pair of offset_type |
| 15776 | values. The first value is the offset of the symbol's name in the |
| 15777 | constant pool. The second value is the offset of the CU vector in |
| 15778 | the constant pool. |
| 15779 | |
| 15780 | If both values are 0, then this slot in the hash table is empty. |
| 15781 | This is ok because while 0 is a valid constant pool index, it |
| 15782 | cannot be a valid index for both a string and a CU vector. |
| 15783 | |
| 15784 | A string in the constant pool is stored as a \0-terminated string, |
| 15785 | as you'd expect. |
| 15786 | |
| 15787 | A CU vector in the constant pool is a sequence of offset_type |
| 15788 | values. The first value is the number of CU indices in the vector. |
| 15789 | Each subsequent value is the index of a CU in the CU list. This |
| 15790 | element in the hash table is used to indicate which CUs define the |
| 15791 | symbol. |
| 15792 | |
| 15793 | 6. The constant pool. This is simply a bunch of bytes. It is |
| 15794 | organized so that alignment is correct: CU vectors are stored |
| 15795 | first, followed by strings. */ |
| 15796 | |
| 15797 | static void |
| 15798 | save_gdb_index_command (char *arg, int from_tty) |
| 15799 | { |
| 15800 | struct objfile *objfile; |
| 15801 | |
| 15802 | if (!arg || !*arg) |
| 15803 | error (_("usage: save gdb-index DIRECTORY")); |
| 15804 | |
| 15805 | ALL_OBJFILES (objfile) |
| 15806 | { |
| 15807 | struct stat st; |
| 15808 | |
| 15809 | /* If the objfile does not correspond to an actual file, skip it. */ |
| 15810 | if (stat (objfile->name, &st) < 0) |
| 15811 | continue; |
| 15812 | |
| 15813 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 15814 | if (dwarf2_per_objfile) |
| 15815 | { |
| 15816 | volatile struct gdb_exception except; |
| 15817 | |
| 15818 | TRY_CATCH (except, RETURN_MASK_ERROR) |
| 15819 | { |
| 15820 | write_psymtabs_to_index (objfile, arg); |
| 15821 | } |
| 15822 | if (except.reason < 0) |
| 15823 | exception_fprintf (gdb_stderr, except, |
| 15824 | _("Error while writing index for `%s': "), |
| 15825 | objfile->name); |
| 15826 | } |
| 15827 | } |
| 15828 | } |
| 15829 | |
| 15830 | \f |
| 15831 | |
| 15832 | int dwarf2_always_disassemble; |
| 15833 | |
| 15834 | static void |
| 15835 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, |
| 15836 | struct cmd_list_element *c, const char *value) |
| 15837 | { |
| 15838 | fprintf_filtered (file, |
| 15839 | _("Whether to always disassemble " |
| 15840 | "DWARF expressions is %s.\n"), |
| 15841 | value); |
| 15842 | } |
| 15843 | |
| 15844 | void _initialize_dwarf2_read (void); |
| 15845 | |
| 15846 | void |
| 15847 | _initialize_dwarf2_read (void) |
| 15848 | { |
| 15849 | struct cmd_list_element *c; |
| 15850 | |
| 15851 | dwarf2_objfile_data_key |
| 15852 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
| 15853 | |
| 15854 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
| 15855 | Set DWARF 2 specific variables.\n\ |
| 15856 | Configure DWARF 2 variables such as the cache size"), |
| 15857 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
| 15858 | 0/*allow-unknown*/, &maintenance_set_cmdlist); |
| 15859 | |
| 15860 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
| 15861 | Show DWARF 2 specific variables\n\ |
| 15862 | Show DWARF 2 variables such as the cache size"), |
| 15863 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
| 15864 | 0/*allow-unknown*/, &maintenance_show_cmdlist); |
| 15865 | |
| 15866 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, |
| 15867 | &dwarf2_max_cache_age, _("\ |
| 15868 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ |
| 15869 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ |
| 15870 | A higher limit means that cached compilation units will be stored\n\ |
| 15871 | in memory longer, and more total memory will be used. Zero disables\n\ |
| 15872 | caching, which can slow down startup."), |
| 15873 | NULL, |
| 15874 | show_dwarf2_max_cache_age, |
| 15875 | &set_dwarf2_cmdlist, |
| 15876 | &show_dwarf2_cmdlist); |
| 15877 | |
| 15878 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
| 15879 | &dwarf2_always_disassemble, _("\ |
| 15880 | Set whether `info address' always disassembles DWARF expressions."), _("\ |
| 15881 | Show whether `info address' always disassembles DWARF expressions."), _("\ |
| 15882 | When enabled, DWARF expressions are always printed in an assembly-like\n\ |
| 15883 | syntax. When disabled, expressions will be printed in a more\n\ |
| 15884 | conversational style, when possible."), |
| 15885 | NULL, |
| 15886 | show_dwarf2_always_disassemble, |
| 15887 | &set_dwarf2_cmdlist, |
| 15888 | &show_dwarf2_cmdlist); |
| 15889 | |
| 15890 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
| 15891 | Set debugging of the dwarf2 DIE reader."), _("\ |
| 15892 | Show debugging of the dwarf2 DIE reader."), _("\ |
| 15893 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ |
| 15894 | The value is the maximum depth to print."), |
| 15895 | NULL, |
| 15896 | NULL, |
| 15897 | &setdebuglist, &showdebuglist); |
| 15898 | |
| 15899 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
| 15900 | _("\ |
| 15901 | Save a gdb-index file.\n\ |
| 15902 | Usage: save gdb-index DIRECTORY"), |
| 15903 | &save_cmdlist); |
| 15904 | set_cmd_completer (c, filename_completer); |
| 15905 | } |