| 1 | /* DWARF 2 debugging format support for GDB. |
| 2 | |
| 3 | Copyright (C) 1994-2012 Free Software Foundation, Inc. |
| 4 | |
| 5 | Adapted by Gary Funck (gary@intrepid.com), Intrepid Technology, |
| 6 | Inc. with support from Florida State University (under contract |
| 7 | with the Ada Joint Program Office), and Silicon Graphics, Inc. |
| 8 | Initial contribution by Brent Benson, Harris Computer Systems, Inc., |
| 9 | based on Fred Fish's (Cygnus Support) implementation of DWARF 1 |
| 10 | support. |
| 11 | |
| 12 | This file is part of GDB. |
| 13 | |
| 14 | This program is free software; you can redistribute it and/or modify |
| 15 | it under the terms of the GNU General Public License as published by |
| 16 | the Free Software Foundation; either version 3 of the License, or |
| 17 | (at your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, |
| 20 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | GNU General Public License for more details. |
| 23 | |
| 24 | You should have received a copy of the GNU General Public License |
| 25 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
| 26 | |
| 27 | /* FIXME: Various die-reading functions need to be more careful with |
| 28 | reading off the end of the section. |
| 29 | E.g., load_partial_dies, read_partial_die. */ |
| 30 | |
| 31 | #include "defs.h" |
| 32 | #include "bfd.h" |
| 33 | #include "symtab.h" |
| 34 | #include "gdbtypes.h" |
| 35 | #include "objfiles.h" |
| 36 | #include "dwarf2.h" |
| 37 | #include "buildsym.h" |
| 38 | #include "demangle.h" |
| 39 | #include "gdb-demangle.h" |
| 40 | #include "expression.h" |
| 41 | #include "filenames.h" /* for DOSish file names */ |
| 42 | #include "macrotab.h" |
| 43 | #include "language.h" |
| 44 | #include "complaints.h" |
| 45 | #include "bcache.h" |
| 46 | #include "dwarf2expr.h" |
| 47 | #include "dwarf2loc.h" |
| 48 | #include "cp-support.h" |
| 49 | #include "hashtab.h" |
| 50 | #include "command.h" |
| 51 | #include "gdbcmd.h" |
| 52 | #include "block.h" |
| 53 | #include "addrmap.h" |
| 54 | #include "typeprint.h" |
| 55 | #include "jv-lang.h" |
| 56 | #include "psympriv.h" |
| 57 | #include "exceptions.h" |
| 58 | #include "gdb_stat.h" |
| 59 | #include "completer.h" |
| 60 | #include "vec.h" |
| 61 | #include "c-lang.h" |
| 62 | #include "valprint.h" |
| 63 | #include <ctype.h> |
| 64 | |
| 65 | #include <fcntl.h> |
| 66 | #include "gdb_string.h" |
| 67 | #include "gdb_assert.h" |
| 68 | #include <sys/types.h> |
| 69 | #ifdef HAVE_ZLIB_H |
| 70 | #include <zlib.h> |
| 71 | #endif |
| 72 | #ifdef HAVE_MMAP |
| 73 | #include <sys/mman.h> |
| 74 | #ifndef MAP_FAILED |
| 75 | #define MAP_FAILED ((void *) -1) |
| 76 | #endif |
| 77 | #endif |
| 78 | |
| 79 | typedef struct symbol *symbolp; |
| 80 | DEF_VEC_P (symbolp); |
| 81 | |
| 82 | /* When non-zero, dump DIEs after they are read in. */ |
| 83 | static int dwarf2_die_debug = 0; |
| 84 | |
| 85 | /* When non-zero, cross-check physname against demangler. */ |
| 86 | static int check_physname = 0; |
| 87 | |
| 88 | static int pagesize; |
| 89 | |
| 90 | /* When set, the file that we're processing is known to have debugging |
| 91 | info for C++ namespaces. GCC 3.3.x did not produce this information, |
| 92 | but later versions do. */ |
| 93 | |
| 94 | static int processing_has_namespace_info; |
| 95 | |
| 96 | static const struct objfile_data *dwarf2_objfile_data_key; |
| 97 | |
| 98 | struct dwarf2_section_info |
| 99 | { |
| 100 | asection *asection; |
| 101 | gdb_byte *buffer; |
| 102 | bfd_size_type size; |
| 103 | /* Not NULL if the section was actually mmapped. */ |
| 104 | void *map_addr; |
| 105 | /* Page aligned size of mmapped area. */ |
| 106 | bfd_size_type map_len; |
| 107 | /* True if we have tried to read this section. */ |
| 108 | int readin; |
| 109 | }; |
| 110 | |
| 111 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
| 112 | DEF_VEC_O (dwarf2_section_info_def); |
| 113 | |
| 114 | /* All offsets in the index are of this type. It must be |
| 115 | architecture-independent. */ |
| 116 | typedef uint32_t offset_type; |
| 117 | |
| 118 | DEF_VEC_I (offset_type); |
| 119 | |
| 120 | /* A description of the mapped index. The file format is described in |
| 121 | a comment by the code that writes the index. */ |
| 122 | struct mapped_index |
| 123 | { |
| 124 | /* Index data format version. */ |
| 125 | int version; |
| 126 | |
| 127 | /* The total length of the buffer. */ |
| 128 | off_t total_size; |
| 129 | |
| 130 | /* A pointer to the address table data. */ |
| 131 | const gdb_byte *address_table; |
| 132 | |
| 133 | /* Size of the address table data in bytes. */ |
| 134 | offset_type address_table_size; |
| 135 | |
| 136 | /* The symbol table, implemented as a hash table. */ |
| 137 | const offset_type *symbol_table; |
| 138 | |
| 139 | /* Size in slots, each slot is 2 offset_types. */ |
| 140 | offset_type symbol_table_slots; |
| 141 | |
| 142 | /* A pointer to the constant pool. */ |
| 143 | const char *constant_pool; |
| 144 | }; |
| 145 | |
| 146 | /* Collection of data recorded per objfile. |
| 147 | This hangs off of dwarf2_objfile_data_key. */ |
| 148 | |
| 149 | struct dwarf2_per_objfile |
| 150 | { |
| 151 | struct dwarf2_section_info info; |
| 152 | struct dwarf2_section_info abbrev; |
| 153 | struct dwarf2_section_info line; |
| 154 | struct dwarf2_section_info loc; |
| 155 | struct dwarf2_section_info macinfo; |
| 156 | struct dwarf2_section_info macro; |
| 157 | struct dwarf2_section_info str; |
| 158 | struct dwarf2_section_info ranges; |
| 159 | struct dwarf2_section_info frame; |
| 160 | struct dwarf2_section_info eh_frame; |
| 161 | struct dwarf2_section_info gdb_index; |
| 162 | |
| 163 | VEC (dwarf2_section_info_def) *types; |
| 164 | |
| 165 | /* Back link. */ |
| 166 | struct objfile *objfile; |
| 167 | |
| 168 | /* Table of all the compilation units. This is used to locate |
| 169 | the target compilation unit of a particular reference. */ |
| 170 | struct dwarf2_per_cu_data **all_comp_units; |
| 171 | |
| 172 | /* The number of compilation units in ALL_COMP_UNITS. */ |
| 173 | int n_comp_units; |
| 174 | |
| 175 | /* The number of .debug_types-related CUs. */ |
| 176 | int n_type_units; |
| 177 | |
| 178 | /* The .debug_types-related CUs (TUs). */ |
| 179 | struct dwarf2_per_cu_data **all_type_units; |
| 180 | |
| 181 | /* A chain of compilation units that are currently read in, so that |
| 182 | they can be freed later. */ |
| 183 | struct dwarf2_per_cu_data *read_in_chain; |
| 184 | |
| 185 | /* A table mapping .debug_types signatures to its signatured_type entry. |
| 186 | This is NULL if the .debug_types section hasn't been read in yet. */ |
| 187 | htab_t signatured_types; |
| 188 | |
| 189 | /* A flag indicating wether this objfile has a section loaded at a |
| 190 | VMA of 0. */ |
| 191 | int has_section_at_zero; |
| 192 | |
| 193 | /* True if we are using the mapped index, |
| 194 | or we are faking it for OBJF_READNOW's sake. */ |
| 195 | unsigned char using_index; |
| 196 | |
| 197 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
| 198 | struct mapped_index *index_table; |
| 199 | |
| 200 | /* When using index_table, this keeps track of all quick_file_names entries. |
| 201 | TUs can share line table entries with CUs or other TUs, and there can be |
| 202 | a lot more TUs than unique line tables, so we maintain a separate table |
| 203 | of all line table entries to support the sharing. */ |
| 204 | htab_t quick_file_names_table; |
| 205 | |
| 206 | /* Set during partial symbol reading, to prevent queueing of full |
| 207 | symbols. */ |
| 208 | int reading_partial_symbols; |
| 209 | |
| 210 | /* Table mapping type .debug_info DIE offsets to types. |
| 211 | This is NULL if not allocated yet. |
| 212 | It (currently) makes sense to allocate debug_types_type_hash lazily. |
| 213 | To keep things simple we allocate both lazily. */ |
| 214 | htab_t debug_info_type_hash; |
| 215 | |
| 216 | /* Table mapping type .debug_types DIE offsets to types. |
| 217 | This is NULL if not allocated yet. */ |
| 218 | htab_t debug_types_type_hash; |
| 219 | }; |
| 220 | |
| 221 | static struct dwarf2_per_objfile *dwarf2_per_objfile; |
| 222 | |
| 223 | /* Default names of the debugging sections. */ |
| 224 | |
| 225 | /* Note that if the debugging section has been compressed, it might |
| 226 | have a name like .zdebug_info. */ |
| 227 | |
| 228 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
| 229 | { |
| 230 | { ".debug_info", ".zdebug_info" }, |
| 231 | { ".debug_abbrev", ".zdebug_abbrev" }, |
| 232 | { ".debug_line", ".zdebug_line" }, |
| 233 | { ".debug_loc", ".zdebug_loc" }, |
| 234 | { ".debug_macinfo", ".zdebug_macinfo" }, |
| 235 | { ".debug_macro", ".zdebug_macro" }, |
| 236 | { ".debug_str", ".zdebug_str" }, |
| 237 | { ".debug_ranges", ".zdebug_ranges" }, |
| 238 | { ".debug_types", ".zdebug_types" }, |
| 239 | { ".debug_frame", ".zdebug_frame" }, |
| 240 | { ".eh_frame", NULL }, |
| 241 | { ".gdb_index", ".zgdb_index" }, |
| 242 | 23 |
| 243 | }; |
| 244 | |
| 245 | /* local data types */ |
| 246 | |
| 247 | /* We hold several abbreviation tables in memory at the same time. */ |
| 248 | #ifndef ABBREV_HASH_SIZE |
| 249 | #define ABBREV_HASH_SIZE 121 |
| 250 | #endif |
| 251 | |
| 252 | /* The data in a compilation unit header, after target2host |
| 253 | translation, looks like this. */ |
| 254 | struct comp_unit_head |
| 255 | { |
| 256 | unsigned int length; |
| 257 | short version; |
| 258 | unsigned char addr_size; |
| 259 | unsigned char signed_addr_p; |
| 260 | unsigned int abbrev_offset; |
| 261 | |
| 262 | /* Size of file offsets; either 4 or 8. */ |
| 263 | unsigned int offset_size; |
| 264 | |
| 265 | /* Size of the length field; either 4 or 12. */ |
| 266 | unsigned int initial_length_size; |
| 267 | |
| 268 | /* Offset to the first byte of this compilation unit header in the |
| 269 | .debug_info section, for resolving relative reference dies. */ |
| 270 | unsigned int offset; |
| 271 | |
| 272 | /* Offset to first die in this cu from the start of the cu. |
| 273 | This will be the first byte following the compilation unit header. */ |
| 274 | unsigned int first_die_offset; |
| 275 | }; |
| 276 | |
| 277 | /* Type used for delaying computation of method physnames. |
| 278 | See comments for compute_delayed_physnames. */ |
| 279 | struct delayed_method_info |
| 280 | { |
| 281 | /* The type to which the method is attached, i.e., its parent class. */ |
| 282 | struct type *type; |
| 283 | |
| 284 | /* The index of the method in the type's function fieldlists. */ |
| 285 | int fnfield_index; |
| 286 | |
| 287 | /* The index of the method in the fieldlist. */ |
| 288 | int index; |
| 289 | |
| 290 | /* The name of the DIE. */ |
| 291 | const char *name; |
| 292 | |
| 293 | /* The DIE associated with this method. */ |
| 294 | struct die_info *die; |
| 295 | }; |
| 296 | |
| 297 | typedef struct delayed_method_info delayed_method_info; |
| 298 | DEF_VEC_O (delayed_method_info); |
| 299 | |
| 300 | /* Internal state when decoding a particular compilation unit. */ |
| 301 | struct dwarf2_cu |
| 302 | { |
| 303 | /* The objfile containing this compilation unit. */ |
| 304 | struct objfile *objfile; |
| 305 | |
| 306 | /* The header of the compilation unit. */ |
| 307 | struct comp_unit_head header; |
| 308 | |
| 309 | /* Base address of this compilation unit. */ |
| 310 | CORE_ADDR base_address; |
| 311 | |
| 312 | /* Non-zero if base_address has been set. */ |
| 313 | int base_known; |
| 314 | |
| 315 | /* The language we are debugging. */ |
| 316 | enum language language; |
| 317 | const struct language_defn *language_defn; |
| 318 | |
| 319 | const char *producer; |
| 320 | |
| 321 | /* The generic symbol table building routines have separate lists for |
| 322 | file scope symbols and all all other scopes (local scopes). So |
| 323 | we need to select the right one to pass to add_symbol_to_list(). |
| 324 | We do it by keeping a pointer to the correct list in list_in_scope. |
| 325 | |
| 326 | FIXME: The original dwarf code just treated the file scope as the |
| 327 | first local scope, and all other local scopes as nested local |
| 328 | scopes, and worked fine. Check to see if we really need to |
| 329 | distinguish these in buildsym.c. */ |
| 330 | struct pending **list_in_scope; |
| 331 | |
| 332 | /* DWARF abbreviation table associated with this compilation unit. */ |
| 333 | struct abbrev_info **dwarf2_abbrevs; |
| 334 | |
| 335 | /* Storage for the abbrev table. */ |
| 336 | struct obstack abbrev_obstack; |
| 337 | |
| 338 | /* Hash table holding all the loaded partial DIEs. */ |
| 339 | htab_t partial_dies; |
| 340 | |
| 341 | /* Storage for things with the same lifetime as this read-in compilation |
| 342 | unit, including partial DIEs. */ |
| 343 | struct obstack comp_unit_obstack; |
| 344 | |
| 345 | /* When multiple dwarf2_cu structures are living in memory, this field |
| 346 | chains them all together, so that they can be released efficiently. |
| 347 | We will probably also want a generation counter so that most-recently-used |
| 348 | compilation units are cached... */ |
| 349 | struct dwarf2_per_cu_data *read_in_chain; |
| 350 | |
| 351 | /* Backchain to our per_cu entry if the tree has been built. */ |
| 352 | struct dwarf2_per_cu_data *per_cu; |
| 353 | |
| 354 | /* How many compilation units ago was this CU last referenced? */ |
| 355 | int last_used; |
| 356 | |
| 357 | /* A hash table of die offsets for following references. */ |
| 358 | htab_t die_hash; |
| 359 | |
| 360 | /* Full DIEs if read in. */ |
| 361 | struct die_info *dies; |
| 362 | |
| 363 | /* A set of pointers to dwarf2_per_cu_data objects for compilation |
| 364 | units referenced by this one. Only set during full symbol processing; |
| 365 | partial symbol tables do not have dependencies. */ |
| 366 | htab_t dependencies; |
| 367 | |
| 368 | /* Header data from the line table, during full symbol processing. */ |
| 369 | struct line_header *line_header; |
| 370 | |
| 371 | /* A list of methods which need to have physnames computed |
| 372 | after all type information has been read. */ |
| 373 | VEC (delayed_method_info) *method_list; |
| 374 | |
| 375 | /* To be copied to symtab->call_site_htab. */ |
| 376 | htab_t call_site_htab; |
| 377 | |
| 378 | /* Mark used when releasing cached dies. */ |
| 379 | unsigned int mark : 1; |
| 380 | |
| 381 | /* This flag will be set if this compilation unit might include |
| 382 | inter-compilation-unit references. */ |
| 383 | unsigned int has_form_ref_addr : 1; |
| 384 | |
| 385 | /* This flag will be set if this compilation unit includes any |
| 386 | DW_TAG_namespace DIEs. If we know that there are explicit |
| 387 | DIEs for namespaces, we don't need to try to infer them |
| 388 | from mangled names. */ |
| 389 | unsigned int has_namespace_info : 1; |
| 390 | |
| 391 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
| 392 | This test is imperfect as there may exist optimized debug code not using |
| 393 | any location list and still facing inlining issues if handled as |
| 394 | unoptimized code. For a future better test see GCC PR other/32998. */ |
| 395 | unsigned int has_loclist : 1; |
| 396 | }; |
| 397 | |
| 398 | /* Persistent data held for a compilation unit, even when not |
| 399 | processing it. We put a pointer to this structure in the |
| 400 | read_symtab_private field of the psymtab. */ |
| 401 | |
| 402 | struct dwarf2_per_cu_data |
| 403 | { |
| 404 | /* The start offset and length of this compilation unit. 2**29-1 |
| 405 | bytes should suffice to store the length of any compilation unit |
| 406 | - if it doesn't, GDB will fall over anyway. |
| 407 | NOTE: Unlike comp_unit_head.length, this length includes |
| 408 | initial_length_size. */ |
| 409 | unsigned int offset; |
| 410 | unsigned int length : 29; |
| 411 | |
| 412 | /* Flag indicating this compilation unit will be read in before |
| 413 | any of the current compilation units are processed. */ |
| 414 | unsigned int queued : 1; |
| 415 | |
| 416 | /* This flag will be set if we need to load absolutely all DIEs |
| 417 | for this compilation unit, instead of just the ones we think |
| 418 | are interesting. It gets set if we look for a DIE in the |
| 419 | hash table and don't find it. */ |
| 420 | unsigned int load_all_dies : 1; |
| 421 | |
| 422 | /* Non-null if this CU is from .debug_types; in which case it points |
| 423 | to the section. Otherwise it's from .debug_info. */ |
| 424 | struct dwarf2_section_info *debug_types_section; |
| 425 | |
| 426 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
| 427 | of the CU cache it gets reset to NULL again. */ |
| 428 | struct dwarf2_cu *cu; |
| 429 | |
| 430 | /* The corresponding objfile. |
| 431 | Normally we can get the objfile from dwarf2_per_objfile. |
| 432 | However we can enter this file with just a "per_cu" handle. */ |
| 433 | struct objfile *objfile; |
| 434 | |
| 435 | /* When using partial symbol tables, the 'psymtab' field is active. |
| 436 | Otherwise the 'quick' field is active. */ |
| 437 | union |
| 438 | { |
| 439 | /* The partial symbol table associated with this compilation unit, |
| 440 | or NULL for partial units (which do not have an associated |
| 441 | symtab). */ |
| 442 | struct partial_symtab *psymtab; |
| 443 | |
| 444 | /* Data needed by the "quick" functions. */ |
| 445 | struct dwarf2_per_cu_quick_data *quick; |
| 446 | } v; |
| 447 | }; |
| 448 | |
| 449 | /* Entry in the signatured_types hash table. */ |
| 450 | |
| 451 | struct signatured_type |
| 452 | { |
| 453 | ULONGEST signature; |
| 454 | |
| 455 | /* Offset in .debug_types of the type defined by this TU. */ |
| 456 | unsigned int type_offset; |
| 457 | |
| 458 | /* The CU(/TU) of this type. */ |
| 459 | struct dwarf2_per_cu_data per_cu; |
| 460 | }; |
| 461 | |
| 462 | /* Struct used to pass misc. parameters to read_die_and_children, et |
| 463 | al. which are used for both .debug_info and .debug_types dies. |
| 464 | All parameters here are unchanging for the life of the call. This |
| 465 | struct exists to abstract away the constant parameters of die |
| 466 | reading. */ |
| 467 | |
| 468 | struct die_reader_specs |
| 469 | { |
| 470 | /* The bfd of this objfile. */ |
| 471 | bfd* abfd; |
| 472 | |
| 473 | /* The CU of the DIE we are parsing. */ |
| 474 | struct dwarf2_cu *cu; |
| 475 | |
| 476 | /* Pointer to start of section buffer. |
| 477 | This is either the start of .debug_info or .debug_types. */ |
| 478 | const gdb_byte *buffer; |
| 479 | }; |
| 480 | |
| 481 | /* The line number information for a compilation unit (found in the |
| 482 | .debug_line section) begins with a "statement program header", |
| 483 | which contains the following information. */ |
| 484 | struct line_header |
| 485 | { |
| 486 | unsigned int total_length; |
| 487 | unsigned short version; |
| 488 | unsigned int header_length; |
| 489 | unsigned char minimum_instruction_length; |
| 490 | unsigned char maximum_ops_per_instruction; |
| 491 | unsigned char default_is_stmt; |
| 492 | int line_base; |
| 493 | unsigned char line_range; |
| 494 | unsigned char opcode_base; |
| 495 | |
| 496 | /* standard_opcode_lengths[i] is the number of operands for the |
| 497 | standard opcode whose value is i. This means that |
| 498 | standard_opcode_lengths[0] is unused, and the last meaningful |
| 499 | element is standard_opcode_lengths[opcode_base - 1]. */ |
| 500 | unsigned char *standard_opcode_lengths; |
| 501 | |
| 502 | /* The include_directories table. NOTE! These strings are not |
| 503 | allocated with xmalloc; instead, they are pointers into |
| 504 | debug_line_buffer. If you try to free them, `free' will get |
| 505 | indigestion. */ |
| 506 | unsigned int num_include_dirs, include_dirs_size; |
| 507 | char **include_dirs; |
| 508 | |
| 509 | /* The file_names table. NOTE! These strings are not allocated |
| 510 | with xmalloc; instead, they are pointers into debug_line_buffer. |
| 511 | Don't try to free them directly. */ |
| 512 | unsigned int num_file_names, file_names_size; |
| 513 | struct file_entry |
| 514 | { |
| 515 | char *name; |
| 516 | unsigned int dir_index; |
| 517 | unsigned int mod_time; |
| 518 | unsigned int length; |
| 519 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
| 520 | struct symtab *symtab; /* The associated symbol table, if any. */ |
| 521 | } *file_names; |
| 522 | |
| 523 | /* The start and end of the statement program following this |
| 524 | header. These point into dwarf2_per_objfile->line_buffer. */ |
| 525 | gdb_byte *statement_program_start, *statement_program_end; |
| 526 | }; |
| 527 | |
| 528 | /* When we construct a partial symbol table entry we only |
| 529 | need this much information. */ |
| 530 | struct partial_die_info |
| 531 | { |
| 532 | /* Offset of this DIE. */ |
| 533 | unsigned int offset; |
| 534 | |
| 535 | /* DWARF-2 tag for this DIE. */ |
| 536 | ENUM_BITFIELD(dwarf_tag) tag : 16; |
| 537 | |
| 538 | /* Assorted flags describing the data found in this DIE. */ |
| 539 | unsigned int has_children : 1; |
| 540 | unsigned int is_external : 1; |
| 541 | unsigned int is_declaration : 1; |
| 542 | unsigned int has_type : 1; |
| 543 | unsigned int has_specification : 1; |
| 544 | unsigned int has_pc_info : 1; |
| 545 | |
| 546 | /* Flag set if the SCOPE field of this structure has been |
| 547 | computed. */ |
| 548 | unsigned int scope_set : 1; |
| 549 | |
| 550 | /* Flag set if the DIE has a byte_size attribute. */ |
| 551 | unsigned int has_byte_size : 1; |
| 552 | |
| 553 | /* Flag set if any of the DIE's children are template arguments. */ |
| 554 | unsigned int has_template_arguments : 1; |
| 555 | |
| 556 | /* Flag set if fixup_partial_die has been called on this die. */ |
| 557 | unsigned int fixup_called : 1; |
| 558 | |
| 559 | /* The name of this DIE. Normally the value of DW_AT_name, but |
| 560 | sometimes a default name for unnamed DIEs. */ |
| 561 | char *name; |
| 562 | |
| 563 | /* The linkage name, if present. */ |
| 564 | const char *linkage_name; |
| 565 | |
| 566 | /* The scope to prepend to our children. This is generally |
| 567 | allocated on the comp_unit_obstack, so will disappear |
| 568 | when this compilation unit leaves the cache. */ |
| 569 | char *scope; |
| 570 | |
| 571 | /* The location description associated with this DIE, if any. */ |
| 572 | struct dwarf_block *locdesc; |
| 573 | |
| 574 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ |
| 575 | CORE_ADDR lowpc; |
| 576 | CORE_ADDR highpc; |
| 577 | |
| 578 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
| 579 | DW_AT_sibling, if any. */ |
| 580 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
| 581 | return DW_AT_sibling values to its caller load_partial_dies. */ |
| 582 | gdb_byte *sibling; |
| 583 | |
| 584 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by |
| 585 | DW_AT_specification (or DW_AT_abstract_origin or |
| 586 | DW_AT_extension). */ |
| 587 | unsigned int spec_offset; |
| 588 | |
| 589 | /* Pointers to this DIE's parent, first child, and next sibling, |
| 590 | if any. */ |
| 591 | struct partial_die_info *die_parent, *die_child, *die_sibling; |
| 592 | }; |
| 593 | |
| 594 | /* This data structure holds the information of an abbrev. */ |
| 595 | struct abbrev_info |
| 596 | { |
| 597 | unsigned int number; /* number identifying abbrev */ |
| 598 | enum dwarf_tag tag; /* dwarf tag */ |
| 599 | unsigned short has_children; /* boolean */ |
| 600 | unsigned short num_attrs; /* number of attributes */ |
| 601 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
| 602 | struct abbrev_info *next; /* next in chain */ |
| 603 | }; |
| 604 | |
| 605 | struct attr_abbrev |
| 606 | { |
| 607 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 608 | ENUM_BITFIELD(dwarf_form) form : 16; |
| 609 | }; |
| 610 | |
| 611 | /* Attributes have a name and a value. */ |
| 612 | struct attribute |
| 613 | { |
| 614 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 615 | ENUM_BITFIELD(dwarf_form) form : 15; |
| 616 | |
| 617 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This |
| 618 | field should be in u.str (existing only for DW_STRING) but it is kept |
| 619 | here for better struct attribute alignment. */ |
| 620 | unsigned int string_is_canonical : 1; |
| 621 | |
| 622 | union |
| 623 | { |
| 624 | char *str; |
| 625 | struct dwarf_block *blk; |
| 626 | ULONGEST unsnd; |
| 627 | LONGEST snd; |
| 628 | CORE_ADDR addr; |
| 629 | struct signatured_type *signatured_type; |
| 630 | } |
| 631 | u; |
| 632 | }; |
| 633 | |
| 634 | /* This data structure holds a complete die structure. */ |
| 635 | struct die_info |
| 636 | { |
| 637 | /* DWARF-2 tag for this DIE. */ |
| 638 | ENUM_BITFIELD(dwarf_tag) tag : 16; |
| 639 | |
| 640 | /* Number of attributes */ |
| 641 | unsigned char num_attrs; |
| 642 | |
| 643 | /* True if we're presently building the full type name for the |
| 644 | type derived from this DIE. */ |
| 645 | unsigned char building_fullname : 1; |
| 646 | |
| 647 | /* Abbrev number */ |
| 648 | unsigned int abbrev; |
| 649 | |
| 650 | /* Offset in .debug_info or .debug_types section. */ |
| 651 | unsigned int offset; |
| 652 | |
| 653 | /* The dies in a compilation unit form an n-ary tree. PARENT |
| 654 | points to this die's parent; CHILD points to the first child of |
| 655 | this node; and all the children of a given node are chained |
| 656 | together via their SIBLING fields. */ |
| 657 | struct die_info *child; /* Its first child, if any. */ |
| 658 | struct die_info *sibling; /* Its next sibling, if any. */ |
| 659 | struct die_info *parent; /* Its parent, if any. */ |
| 660 | |
| 661 | /* An array of attributes, with NUM_ATTRS elements. There may be |
| 662 | zero, but it's not common and zero-sized arrays are not |
| 663 | sufficiently portable C. */ |
| 664 | struct attribute attrs[1]; |
| 665 | }; |
| 666 | |
| 667 | /* Get at parts of an attribute structure. */ |
| 668 | |
| 669 | #define DW_STRING(attr) ((attr)->u.str) |
| 670 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
| 671 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
| 672 | #define DW_BLOCK(attr) ((attr)->u.blk) |
| 673 | #define DW_SND(attr) ((attr)->u.snd) |
| 674 | #define DW_ADDR(attr) ((attr)->u.addr) |
| 675 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
| 676 | |
| 677 | /* Blocks are a bunch of untyped bytes. */ |
| 678 | struct dwarf_block |
| 679 | { |
| 680 | unsigned int size; |
| 681 | |
| 682 | /* Valid only if SIZE is not zero. */ |
| 683 | gdb_byte *data; |
| 684 | }; |
| 685 | |
| 686 | #ifndef ATTR_ALLOC_CHUNK |
| 687 | #define ATTR_ALLOC_CHUNK 4 |
| 688 | #endif |
| 689 | |
| 690 | /* Allocate fields for structs, unions and enums in this size. */ |
| 691 | #ifndef DW_FIELD_ALLOC_CHUNK |
| 692 | #define DW_FIELD_ALLOC_CHUNK 4 |
| 693 | #endif |
| 694 | |
| 695 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
| 696 | but this would require a corresponding change in unpack_field_as_long |
| 697 | and friends. */ |
| 698 | static int bits_per_byte = 8; |
| 699 | |
| 700 | /* The routines that read and process dies for a C struct or C++ class |
| 701 | pass lists of data member fields and lists of member function fields |
| 702 | in an instance of a field_info structure, as defined below. */ |
| 703 | struct field_info |
| 704 | { |
| 705 | /* List of data member and baseclasses fields. */ |
| 706 | struct nextfield |
| 707 | { |
| 708 | struct nextfield *next; |
| 709 | int accessibility; |
| 710 | int virtuality; |
| 711 | struct field field; |
| 712 | } |
| 713 | *fields, *baseclasses; |
| 714 | |
| 715 | /* Number of fields (including baseclasses). */ |
| 716 | int nfields; |
| 717 | |
| 718 | /* Number of baseclasses. */ |
| 719 | int nbaseclasses; |
| 720 | |
| 721 | /* Set if the accesibility of one of the fields is not public. */ |
| 722 | int non_public_fields; |
| 723 | |
| 724 | /* Member function fields array, entries are allocated in the order they |
| 725 | are encountered in the object file. */ |
| 726 | struct nextfnfield |
| 727 | { |
| 728 | struct nextfnfield *next; |
| 729 | struct fn_field fnfield; |
| 730 | } |
| 731 | *fnfields; |
| 732 | |
| 733 | /* Member function fieldlist array, contains name of possibly overloaded |
| 734 | member function, number of overloaded member functions and a pointer |
| 735 | to the head of the member function field chain. */ |
| 736 | struct fnfieldlist |
| 737 | { |
| 738 | char *name; |
| 739 | int length; |
| 740 | struct nextfnfield *head; |
| 741 | } |
| 742 | *fnfieldlists; |
| 743 | |
| 744 | /* Number of entries in the fnfieldlists array. */ |
| 745 | int nfnfields; |
| 746 | |
| 747 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of |
| 748 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ |
| 749 | struct typedef_field_list |
| 750 | { |
| 751 | struct typedef_field field; |
| 752 | struct typedef_field_list *next; |
| 753 | } |
| 754 | *typedef_field_list; |
| 755 | unsigned typedef_field_list_count; |
| 756 | }; |
| 757 | |
| 758 | /* One item on the queue of compilation units to read in full symbols |
| 759 | for. */ |
| 760 | struct dwarf2_queue_item |
| 761 | { |
| 762 | struct dwarf2_per_cu_data *per_cu; |
| 763 | struct dwarf2_queue_item *next; |
| 764 | }; |
| 765 | |
| 766 | /* The current queue. */ |
| 767 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; |
| 768 | |
| 769 | /* Loaded secondary compilation units are kept in memory until they |
| 770 | have not been referenced for the processing of this many |
| 771 | compilation units. Set this to zero to disable caching. Cache |
| 772 | sizes of up to at least twenty will improve startup time for |
| 773 | typical inter-CU-reference binaries, at an obvious memory cost. */ |
| 774 | static int dwarf2_max_cache_age = 5; |
| 775 | static void |
| 776 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, |
| 777 | struct cmd_list_element *c, const char *value) |
| 778 | { |
| 779 | fprintf_filtered (file, _("The upper bound on the age of cached " |
| 780 | "dwarf2 compilation units is %s.\n"), |
| 781 | value); |
| 782 | } |
| 783 | |
| 784 | |
| 785 | /* Various complaints about symbol reading that don't abort the process. */ |
| 786 | |
| 787 | static void |
| 788 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) |
| 789 | { |
| 790 | complaint (&symfile_complaints, |
| 791 | _("statement list doesn't fit in .debug_line section")); |
| 792 | } |
| 793 | |
| 794 | static void |
| 795 | dwarf2_debug_line_missing_file_complaint (void) |
| 796 | { |
| 797 | complaint (&symfile_complaints, |
| 798 | _(".debug_line section has line data without a file")); |
| 799 | } |
| 800 | |
| 801 | static void |
| 802 | dwarf2_debug_line_missing_end_sequence_complaint (void) |
| 803 | { |
| 804 | complaint (&symfile_complaints, |
| 805 | _(".debug_line section has line " |
| 806 | "program sequence without an end")); |
| 807 | } |
| 808 | |
| 809 | static void |
| 810 | dwarf2_complex_location_expr_complaint (void) |
| 811 | { |
| 812 | complaint (&symfile_complaints, _("location expression too complex")); |
| 813 | } |
| 814 | |
| 815 | static void |
| 816 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, |
| 817 | int arg3) |
| 818 | { |
| 819 | complaint (&symfile_complaints, |
| 820 | _("const value length mismatch for '%s', got %d, expected %d"), |
| 821 | arg1, arg2, arg3); |
| 822 | } |
| 823 | |
| 824 | static void |
| 825 | dwarf2_macros_too_long_complaint (struct dwarf2_section_info *section) |
| 826 | { |
| 827 | complaint (&symfile_complaints, |
| 828 | _("macro info runs off end of `%s' section"), |
| 829 | section->asection->name); |
| 830 | } |
| 831 | |
| 832 | static void |
| 833 | dwarf2_macro_malformed_definition_complaint (const char *arg1) |
| 834 | { |
| 835 | complaint (&symfile_complaints, |
| 836 | _("macro debug info contains a " |
| 837 | "malformed macro definition:\n`%s'"), |
| 838 | arg1); |
| 839 | } |
| 840 | |
| 841 | static void |
| 842 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) |
| 843 | { |
| 844 | complaint (&symfile_complaints, |
| 845 | _("invalid attribute class or form for '%s' in '%s'"), |
| 846 | arg1, arg2); |
| 847 | } |
| 848 | |
| 849 | /* local function prototypes */ |
| 850 | |
| 851 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
| 852 | |
| 853 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
| 854 | struct objfile *); |
| 855 | |
| 856 | static void dwarf2_find_base_address (struct die_info *die, |
| 857 | struct dwarf2_cu *cu); |
| 858 | |
| 859 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
| 860 | |
| 861 | static void scan_partial_symbols (struct partial_die_info *, |
| 862 | CORE_ADDR *, CORE_ADDR *, |
| 863 | int, struct dwarf2_cu *); |
| 864 | |
| 865 | static void add_partial_symbol (struct partial_die_info *, |
| 866 | struct dwarf2_cu *); |
| 867 | |
| 868 | static void add_partial_namespace (struct partial_die_info *pdi, |
| 869 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 870 | int need_pc, struct dwarf2_cu *cu); |
| 871 | |
| 872 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
| 873 | CORE_ADDR *highpc, int need_pc, |
| 874 | struct dwarf2_cu *cu); |
| 875 | |
| 876 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
| 877 | struct dwarf2_cu *cu); |
| 878 | |
| 879 | static void add_partial_subprogram (struct partial_die_info *pdi, |
| 880 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 881 | int need_pc, struct dwarf2_cu *cu); |
| 882 | |
| 883 | static gdb_byte *locate_pdi_sibling (struct partial_die_info *orig_pdi, |
| 884 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 885 | bfd *abfd, struct dwarf2_cu *cu); |
| 886 | |
| 887 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
| 888 | |
| 889 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
| 890 | |
| 891 | static void dwarf2_read_abbrevs (struct dwarf2_cu *cu); |
| 892 | |
| 893 | static void dwarf2_free_abbrev_table (void *); |
| 894 | |
| 895 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
| 896 | |
| 897 | static struct abbrev_info *peek_die_abbrev (gdb_byte *, unsigned int *, |
| 898 | struct dwarf2_cu *); |
| 899 | |
| 900 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
| 901 | struct dwarf2_cu *); |
| 902 | |
| 903 | static struct partial_die_info *load_partial_dies (bfd *, |
| 904 | gdb_byte *, gdb_byte *, |
| 905 | int, struct dwarf2_cu *); |
| 906 | |
| 907 | static gdb_byte *read_partial_die (struct partial_die_info *, |
| 908 | struct abbrev_info *abbrev, |
| 909 | unsigned int, bfd *, |
| 910 | gdb_byte *, gdb_byte *, |
| 911 | struct dwarf2_cu *); |
| 912 | |
| 913 | static struct partial_die_info *find_partial_die (unsigned int, |
| 914 | struct dwarf2_cu *); |
| 915 | |
| 916 | static void fixup_partial_die (struct partial_die_info *, |
| 917 | struct dwarf2_cu *); |
| 918 | |
| 919 | static gdb_byte *read_attribute (struct attribute *, struct attr_abbrev *, |
| 920 | bfd *, gdb_byte *, struct dwarf2_cu *); |
| 921 | |
| 922 | static gdb_byte *read_attribute_value (struct attribute *, unsigned, |
| 923 | bfd *, gdb_byte *, struct dwarf2_cu *); |
| 924 | |
| 925 | static unsigned int read_1_byte (bfd *, gdb_byte *); |
| 926 | |
| 927 | static int read_1_signed_byte (bfd *, gdb_byte *); |
| 928 | |
| 929 | static unsigned int read_2_bytes (bfd *, gdb_byte *); |
| 930 | |
| 931 | static unsigned int read_4_bytes (bfd *, gdb_byte *); |
| 932 | |
| 933 | static ULONGEST read_8_bytes (bfd *, gdb_byte *); |
| 934 | |
| 935 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
| 936 | unsigned int *); |
| 937 | |
| 938 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
| 939 | |
| 940 | static LONGEST read_checked_initial_length_and_offset |
| 941 | (bfd *, gdb_byte *, const struct comp_unit_head *, |
| 942 | unsigned int *, unsigned int *); |
| 943 | |
| 944 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
| 945 | unsigned int *); |
| 946 | |
| 947 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); |
| 948 | |
| 949 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
| 950 | |
| 951 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
| 952 | |
| 953 | static char *read_indirect_string (bfd *, gdb_byte *, |
| 954 | const struct comp_unit_head *, |
| 955 | unsigned int *); |
| 956 | |
| 957 | static unsigned long read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
| 958 | |
| 959 | static long read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
| 960 | |
| 961 | static gdb_byte *skip_leb128 (bfd *, gdb_byte *); |
| 962 | |
| 963 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
| 964 | |
| 965 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
| 966 | struct dwarf2_cu *); |
| 967 | |
| 968 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
| 969 | unsigned int, |
| 970 | struct dwarf2_cu *); |
| 971 | |
| 972 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
| 973 | struct dwarf2_cu *cu); |
| 974 | |
| 975 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
| 976 | |
| 977 | static struct die_info *die_specification (struct die_info *die, |
| 978 | struct dwarf2_cu **); |
| 979 | |
| 980 | static void free_line_header (struct line_header *lh); |
| 981 | |
| 982 | static void add_file_name (struct line_header *, char *, unsigned int, |
| 983 | unsigned int, unsigned int); |
| 984 | |
| 985 | static struct line_header *(dwarf_decode_line_header |
| 986 | (unsigned int offset, |
| 987 | bfd *abfd, struct dwarf2_cu *cu)); |
| 988 | |
| 989 | static void dwarf_decode_lines (struct line_header *, const char *, |
| 990 | struct dwarf2_cu *, struct partial_symtab *, |
| 991 | int); |
| 992 | |
| 993 | static void dwarf2_start_subfile (char *, const char *, const char *); |
| 994 | |
| 995 | static struct symbol *new_symbol (struct die_info *, struct type *, |
| 996 | struct dwarf2_cu *); |
| 997 | |
| 998 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
| 999 | struct dwarf2_cu *, struct symbol *); |
| 1000 | |
| 1001 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
| 1002 | struct dwarf2_cu *); |
| 1003 | |
| 1004 | static void dwarf2_const_value_attr (struct attribute *attr, |
| 1005 | struct type *type, |
| 1006 | const char *name, |
| 1007 | struct obstack *obstack, |
| 1008 | struct dwarf2_cu *cu, long *value, |
| 1009 | gdb_byte **bytes, |
| 1010 | struct dwarf2_locexpr_baton **baton); |
| 1011 | |
| 1012 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
| 1013 | |
| 1014 | static int need_gnat_info (struct dwarf2_cu *); |
| 1015 | |
| 1016 | static struct type *die_descriptive_type (struct die_info *, |
| 1017 | struct dwarf2_cu *); |
| 1018 | |
| 1019 | static void set_descriptive_type (struct type *, struct die_info *, |
| 1020 | struct dwarf2_cu *); |
| 1021 | |
| 1022 | static struct type *die_containing_type (struct die_info *, |
| 1023 | struct dwarf2_cu *); |
| 1024 | |
| 1025 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
| 1026 | struct dwarf2_cu *); |
| 1027 | |
| 1028 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
| 1029 | |
| 1030 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
| 1031 | |
| 1032 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
| 1033 | |
| 1034 | static char *typename_concat (struct obstack *obs, const char *prefix, |
| 1035 | const char *suffix, int physname, |
| 1036 | struct dwarf2_cu *cu); |
| 1037 | |
| 1038 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
| 1039 | |
| 1040 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
| 1041 | |
| 1042 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
| 1043 | |
| 1044 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
| 1045 | |
| 1046 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
| 1047 | |
| 1048 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
| 1049 | struct dwarf2_cu *, struct partial_symtab *); |
| 1050 | |
| 1051 | static int dwarf2_get_pc_bounds (struct die_info *, |
| 1052 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
| 1053 | struct partial_symtab *); |
| 1054 | |
| 1055 | static void get_scope_pc_bounds (struct die_info *, |
| 1056 | CORE_ADDR *, CORE_ADDR *, |
| 1057 | struct dwarf2_cu *); |
| 1058 | |
| 1059 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
| 1060 | CORE_ADDR, struct dwarf2_cu *); |
| 1061 | |
| 1062 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
| 1063 | struct dwarf2_cu *); |
| 1064 | |
| 1065 | static void dwarf2_attach_fields_to_type (struct field_info *, |
| 1066 | struct type *, struct dwarf2_cu *); |
| 1067 | |
| 1068 | static void dwarf2_add_member_fn (struct field_info *, |
| 1069 | struct die_info *, struct type *, |
| 1070 | struct dwarf2_cu *); |
| 1071 | |
| 1072 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
| 1073 | struct type *, |
| 1074 | struct dwarf2_cu *); |
| 1075 | |
| 1076 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
| 1077 | |
| 1078 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
| 1079 | |
| 1080 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
| 1081 | |
| 1082 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
| 1083 | |
| 1084 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
| 1085 | |
| 1086 | static struct type *read_module_type (struct die_info *die, |
| 1087 | struct dwarf2_cu *cu); |
| 1088 | |
| 1089 | static const char *namespace_name (struct die_info *die, |
| 1090 | int *is_anonymous, struct dwarf2_cu *); |
| 1091 | |
| 1092 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
| 1093 | |
| 1094 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
| 1095 | |
| 1096 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
| 1097 | struct dwarf2_cu *); |
| 1098 | |
| 1099 | static struct die_info *read_comp_unit (gdb_byte *, struct dwarf2_cu *); |
| 1100 | |
| 1101 | static struct die_info *read_die_and_children_1 (const struct die_reader_specs *reader, |
| 1102 | gdb_byte *info_ptr, |
| 1103 | gdb_byte **new_info_ptr, |
| 1104 | struct die_info *parent); |
| 1105 | |
| 1106 | static struct die_info *read_die_and_children (const struct die_reader_specs *reader, |
| 1107 | gdb_byte *info_ptr, |
| 1108 | gdb_byte **new_info_ptr, |
| 1109 | struct die_info *parent); |
| 1110 | |
| 1111 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *reader, |
| 1112 | gdb_byte *info_ptr, |
| 1113 | gdb_byte **new_info_ptr, |
| 1114 | struct die_info *parent); |
| 1115 | |
| 1116 | static gdb_byte *read_full_die (const struct die_reader_specs *reader, |
| 1117 | struct die_info **, gdb_byte *, |
| 1118 | int *); |
| 1119 | |
| 1120 | static void process_die (struct die_info *, struct dwarf2_cu *); |
| 1121 | |
| 1122 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
| 1123 | struct obstack *); |
| 1124 | |
| 1125 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
| 1126 | |
| 1127 | static const char *dwarf2_full_name (char *name, |
| 1128 | struct die_info *die, |
| 1129 | struct dwarf2_cu *cu); |
| 1130 | |
| 1131 | static struct die_info *dwarf2_extension (struct die_info *die, |
| 1132 | struct dwarf2_cu **); |
| 1133 | |
| 1134 | static char *dwarf_tag_name (unsigned int); |
| 1135 | |
| 1136 | static char *dwarf_attr_name (unsigned int); |
| 1137 | |
| 1138 | static char *dwarf_form_name (unsigned int); |
| 1139 | |
| 1140 | static char *dwarf_bool_name (unsigned int); |
| 1141 | |
| 1142 | static char *dwarf_type_encoding_name (unsigned int); |
| 1143 | |
| 1144 | #if 0 |
| 1145 | static char *dwarf_cfi_name (unsigned int); |
| 1146 | #endif |
| 1147 | |
| 1148 | static struct die_info *sibling_die (struct die_info *); |
| 1149 | |
| 1150 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
| 1151 | |
| 1152 | static void dump_die_for_error (struct die_info *); |
| 1153 | |
| 1154 | static void dump_die_1 (struct ui_file *, int level, int max_level, |
| 1155 | struct die_info *); |
| 1156 | |
| 1157 | /*static*/ void dump_die (struct die_info *, int max_level); |
| 1158 | |
| 1159 | static void store_in_ref_table (struct die_info *, |
| 1160 | struct dwarf2_cu *); |
| 1161 | |
| 1162 | static int is_ref_attr (struct attribute *); |
| 1163 | |
| 1164 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
| 1165 | |
| 1166 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
| 1167 | |
| 1168 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
| 1169 | struct attribute *, |
| 1170 | struct dwarf2_cu **); |
| 1171 | |
| 1172 | static struct die_info *follow_die_ref (struct die_info *, |
| 1173 | struct attribute *, |
| 1174 | struct dwarf2_cu **); |
| 1175 | |
| 1176 | static struct die_info *follow_die_sig (struct die_info *, |
| 1177 | struct attribute *, |
| 1178 | struct dwarf2_cu **); |
| 1179 | |
| 1180 | static struct signatured_type *lookup_signatured_type_at_offset |
| 1181 | (struct objfile *objfile, |
| 1182 | struct dwarf2_section_info *section, |
| 1183 | unsigned int offset); |
| 1184 | |
| 1185 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
| 1186 | |
| 1187 | static void read_signatured_type (struct signatured_type *type_sig); |
| 1188 | |
| 1189 | /* memory allocation interface */ |
| 1190 | |
| 1191 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
| 1192 | |
| 1193 | static struct abbrev_info *dwarf_alloc_abbrev (struct dwarf2_cu *); |
| 1194 | |
| 1195 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
| 1196 | |
| 1197 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
| 1198 | char *, bfd *, struct dwarf2_cu *, |
| 1199 | struct dwarf2_section_info *, |
| 1200 | int); |
| 1201 | |
| 1202 | static int attr_form_is_block (struct attribute *); |
| 1203 | |
| 1204 | static int attr_form_is_section_offset (struct attribute *); |
| 1205 | |
| 1206 | static int attr_form_is_constant (struct attribute *); |
| 1207 | |
| 1208 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
| 1209 | struct dwarf2_loclist_baton *baton, |
| 1210 | struct attribute *attr); |
| 1211 | |
| 1212 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
| 1213 | struct symbol *sym, |
| 1214 | struct dwarf2_cu *cu); |
| 1215 | |
| 1216 | static gdb_byte *skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
| 1217 | struct abbrev_info *abbrev, |
| 1218 | struct dwarf2_cu *cu); |
| 1219 | |
| 1220 | static void free_stack_comp_unit (void *); |
| 1221 | |
| 1222 | static hashval_t partial_die_hash (const void *item); |
| 1223 | |
| 1224 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); |
| 1225 | |
| 1226 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
| 1227 | (unsigned int offset, struct objfile *objfile); |
| 1228 | |
| 1229 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
| 1230 | struct dwarf2_per_cu_data *per_cu); |
| 1231 | |
| 1232 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, |
| 1233 | struct die_info *comp_unit_die); |
| 1234 | |
| 1235 | static void free_heap_comp_unit (void *); |
| 1236 | |
| 1237 | static void free_cached_comp_units (void *); |
| 1238 | |
| 1239 | static void age_cached_comp_units (void); |
| 1240 | |
| 1241 | static void free_one_cached_comp_unit (void *); |
| 1242 | |
| 1243 | static struct type *set_die_type (struct die_info *, struct type *, |
| 1244 | struct dwarf2_cu *); |
| 1245 | |
| 1246 | static void create_all_comp_units (struct objfile *); |
| 1247 | |
| 1248 | static int create_debug_types_hash_table (struct objfile *objfile); |
| 1249 | |
| 1250 | static void load_full_comp_unit (struct dwarf2_per_cu_data *); |
| 1251 | |
| 1252 | static void process_full_comp_unit (struct dwarf2_per_cu_data *); |
| 1253 | |
| 1254 | static void dwarf2_add_dependence (struct dwarf2_cu *, |
| 1255 | struct dwarf2_per_cu_data *); |
| 1256 | |
| 1257 | static void dwarf2_mark (struct dwarf2_cu *); |
| 1258 | |
| 1259 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); |
| 1260 | |
| 1261 | static struct type *get_die_type_at_offset (unsigned int, |
| 1262 | struct dwarf2_per_cu_data *per_cu); |
| 1263 | |
| 1264 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
| 1265 | |
| 1266 | static void dwarf2_release_queue (void *dummy); |
| 1267 | |
| 1268 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu); |
| 1269 | |
| 1270 | static void process_queue (void); |
| 1271 | |
| 1272 | static void find_file_and_directory (struct die_info *die, |
| 1273 | struct dwarf2_cu *cu, |
| 1274 | char **name, char **comp_dir); |
| 1275 | |
| 1276 | static char *file_full_name (int file, struct line_header *lh, |
| 1277 | const char *comp_dir); |
| 1278 | |
| 1279 | static gdb_byte *read_and_check_comp_unit_head |
| 1280 | (struct comp_unit_head *header, |
| 1281 | struct dwarf2_section_info *section, gdb_byte *info_ptr, |
| 1282 | int is_debug_types_section); |
| 1283 | |
| 1284 | static void init_cu_die_reader (struct die_reader_specs *reader, |
| 1285 | struct dwarf2_cu *cu); |
| 1286 | |
| 1287 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
| 1288 | |
| 1289 | #if WORDS_BIGENDIAN |
| 1290 | |
| 1291 | /* Convert VALUE between big- and little-endian. */ |
| 1292 | static offset_type |
| 1293 | byte_swap (offset_type value) |
| 1294 | { |
| 1295 | offset_type result; |
| 1296 | |
| 1297 | result = (value & 0xff) << 24; |
| 1298 | result |= (value & 0xff00) << 8; |
| 1299 | result |= (value & 0xff0000) >> 8; |
| 1300 | result |= (value & 0xff000000) >> 24; |
| 1301 | return result; |
| 1302 | } |
| 1303 | |
| 1304 | #define MAYBE_SWAP(V) byte_swap (V) |
| 1305 | |
| 1306 | #else |
| 1307 | #define MAYBE_SWAP(V) (V) |
| 1308 | #endif /* WORDS_BIGENDIAN */ |
| 1309 | |
| 1310 | /* The suffix for an index file. */ |
| 1311 | #define INDEX_SUFFIX ".gdb-index" |
| 1312 | |
| 1313 | static const char *dwarf2_physname (char *name, struct die_info *die, |
| 1314 | struct dwarf2_cu *cu); |
| 1315 | |
| 1316 | /* Try to locate the sections we need for DWARF 2 debugging |
| 1317 | information and return true if we have enough to do something. |
| 1318 | NAMES points to the dwarf2 section names, or is NULL if the standard |
| 1319 | ELF names are used. */ |
| 1320 | |
| 1321 | int |
| 1322 | dwarf2_has_info (struct objfile *objfile, |
| 1323 | const struct dwarf2_debug_sections *names) |
| 1324 | { |
| 1325 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 1326 | if (!dwarf2_per_objfile) |
| 1327 | { |
| 1328 | /* Initialize per-objfile state. */ |
| 1329 | struct dwarf2_per_objfile *data |
| 1330 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); |
| 1331 | |
| 1332 | memset (data, 0, sizeof (*data)); |
| 1333 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); |
| 1334 | dwarf2_per_objfile = data; |
| 1335 | |
| 1336 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
| 1337 | (void *) names); |
| 1338 | dwarf2_per_objfile->objfile = objfile; |
| 1339 | } |
| 1340 | return (dwarf2_per_objfile->info.asection != NULL |
| 1341 | && dwarf2_per_objfile->abbrev.asection != NULL); |
| 1342 | } |
| 1343 | |
| 1344 | /* When loading sections, we look either for uncompressed section or for |
| 1345 | compressed section names. */ |
| 1346 | |
| 1347 | static int |
| 1348 | section_is_p (const char *section_name, |
| 1349 | const struct dwarf2_section_names *names) |
| 1350 | { |
| 1351 | if (names->normal != NULL |
| 1352 | && strcmp (section_name, names->normal) == 0) |
| 1353 | return 1; |
| 1354 | if (names->compressed != NULL |
| 1355 | && strcmp (section_name, names->compressed) == 0) |
| 1356 | return 1; |
| 1357 | return 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 *vnames) |
| 1366 | { |
| 1367 | const struct dwarf2_debug_sections *names; |
| 1368 | |
| 1369 | if (vnames == NULL) |
| 1370 | names = &dwarf2_elf_names; |
| 1371 | else |
| 1372 | names = (const struct dwarf2_debug_sections *) vnames; |
| 1373 | |
| 1374 | if (section_is_p (sectp->name, &names->info)) |
| 1375 | { |
| 1376 | dwarf2_per_objfile->info.asection = sectp; |
| 1377 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); |
| 1378 | } |
| 1379 | else if (section_is_p (sectp->name, &names->abbrev)) |
| 1380 | { |
| 1381 | dwarf2_per_objfile->abbrev.asection = sectp; |
| 1382 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); |
| 1383 | } |
| 1384 | else if (section_is_p (sectp->name, &names->line)) |
| 1385 | { |
| 1386 | dwarf2_per_objfile->line.asection = sectp; |
| 1387 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); |
| 1388 | } |
| 1389 | else if (section_is_p (sectp->name, &names->loc)) |
| 1390 | { |
| 1391 | dwarf2_per_objfile->loc.asection = sectp; |
| 1392 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); |
| 1393 | } |
| 1394 | else if (section_is_p (sectp->name, &names->macinfo)) |
| 1395 | { |
| 1396 | dwarf2_per_objfile->macinfo.asection = sectp; |
| 1397 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); |
| 1398 | } |
| 1399 | else if (section_is_p (sectp->name, &names->macro)) |
| 1400 | { |
| 1401 | dwarf2_per_objfile->macro.asection = sectp; |
| 1402 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); |
| 1403 | } |
| 1404 | else if (section_is_p (sectp->name, &names->str)) |
| 1405 | { |
| 1406 | dwarf2_per_objfile->str.asection = sectp; |
| 1407 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); |
| 1408 | } |
| 1409 | else if (section_is_p (sectp->name, &names->frame)) |
| 1410 | { |
| 1411 | dwarf2_per_objfile->frame.asection = sectp; |
| 1412 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); |
| 1413 | } |
| 1414 | else if (section_is_p (sectp->name, &names->eh_frame)) |
| 1415 | { |
| 1416 | flagword aflag = bfd_get_section_flags (ignore_abfd, sectp); |
| 1417 | |
| 1418 | if (aflag & SEC_HAS_CONTENTS) |
| 1419 | { |
| 1420 | dwarf2_per_objfile->eh_frame.asection = sectp; |
| 1421 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); |
| 1422 | } |
| 1423 | } |
| 1424 | else if (section_is_p (sectp->name, &names->ranges)) |
| 1425 | { |
| 1426 | dwarf2_per_objfile->ranges.asection = sectp; |
| 1427 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); |
| 1428 | } |
| 1429 | else if (section_is_p (sectp->name, &names->types)) |
| 1430 | { |
| 1431 | struct dwarf2_section_info type_section; |
| 1432 | |
| 1433 | memset (&type_section, 0, sizeof (type_section)); |
| 1434 | type_section.asection = sectp; |
| 1435 | type_section.size = bfd_get_section_size (sectp); |
| 1436 | |
| 1437 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, |
| 1438 | &type_section); |
| 1439 | } |
| 1440 | else if (section_is_p (sectp->name, &names->gdb_index)) |
| 1441 | { |
| 1442 | dwarf2_per_objfile->gdb_index.asection = sectp; |
| 1443 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); |
| 1444 | } |
| 1445 | |
| 1446 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
| 1447 | && bfd_section_vma (abfd, sectp) == 0) |
| 1448 | dwarf2_per_objfile->has_section_at_zero = 1; |
| 1449 | } |
| 1450 | |
| 1451 | /* Decompress a section that was compressed using zlib. Store the |
| 1452 | decompressed buffer, and its size, in OUTBUF and OUTSIZE. */ |
| 1453 | |
| 1454 | static void |
| 1455 | zlib_decompress_section (struct objfile *objfile, asection *sectp, |
| 1456 | gdb_byte **outbuf, bfd_size_type *outsize) |
| 1457 | { |
| 1458 | bfd *abfd = objfile->obfd; |
| 1459 | #ifndef HAVE_ZLIB_H |
| 1460 | error (_("Support for zlib-compressed DWARF data (from '%s') " |
| 1461 | "is disabled in this copy of GDB"), |
| 1462 | bfd_get_filename (abfd)); |
| 1463 | #else |
| 1464 | bfd_size_type compressed_size = bfd_get_section_size (sectp); |
| 1465 | gdb_byte *compressed_buffer = xmalloc (compressed_size); |
| 1466 | struct cleanup *cleanup = make_cleanup (xfree, compressed_buffer); |
| 1467 | bfd_size_type uncompressed_size; |
| 1468 | gdb_byte *uncompressed_buffer; |
| 1469 | z_stream strm; |
| 1470 | int rc; |
| 1471 | int header_size = 12; |
| 1472 | |
| 1473 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
| 1474 | || bfd_bread (compressed_buffer, |
| 1475 | compressed_size, abfd) != compressed_size) |
| 1476 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
| 1477 | bfd_get_filename (abfd)); |
| 1478 | |
| 1479 | /* Read the zlib header. In this case, it should be "ZLIB" followed |
| 1480 | by the uncompressed section size, 8 bytes in big-endian order. */ |
| 1481 | if (compressed_size < header_size |
| 1482 | || strncmp (compressed_buffer, "ZLIB", 4) != 0) |
| 1483 | error (_("Dwarf Error: Corrupt DWARF ZLIB header from '%s'"), |
| 1484 | bfd_get_filename (abfd)); |
| 1485 | uncompressed_size = compressed_buffer[4]; uncompressed_size <<= 8; |
| 1486 | uncompressed_size += compressed_buffer[5]; uncompressed_size <<= 8; |
| 1487 | uncompressed_size += compressed_buffer[6]; uncompressed_size <<= 8; |
| 1488 | uncompressed_size += compressed_buffer[7]; uncompressed_size <<= 8; |
| 1489 | uncompressed_size += compressed_buffer[8]; uncompressed_size <<= 8; |
| 1490 | uncompressed_size += compressed_buffer[9]; uncompressed_size <<= 8; |
| 1491 | uncompressed_size += compressed_buffer[10]; uncompressed_size <<= 8; |
| 1492 | uncompressed_size += compressed_buffer[11]; |
| 1493 | |
| 1494 | /* It is possible the section consists of several compressed |
| 1495 | buffers concatenated together, so we uncompress in a loop. */ |
| 1496 | strm.zalloc = NULL; |
| 1497 | strm.zfree = NULL; |
| 1498 | strm.opaque = NULL; |
| 1499 | strm.avail_in = compressed_size - header_size; |
| 1500 | strm.next_in = (Bytef*) compressed_buffer + header_size; |
| 1501 | strm.avail_out = uncompressed_size; |
| 1502 | uncompressed_buffer = obstack_alloc (&objfile->objfile_obstack, |
| 1503 | uncompressed_size); |
| 1504 | rc = inflateInit (&strm); |
| 1505 | while (strm.avail_in > 0) |
| 1506 | { |
| 1507 | if (rc != Z_OK) |
| 1508 | error (_("Dwarf Error: setting up DWARF uncompression in '%s': %d"), |
| 1509 | bfd_get_filename (abfd), rc); |
| 1510 | strm.next_out = ((Bytef*) uncompressed_buffer |
| 1511 | + (uncompressed_size - strm.avail_out)); |
| 1512 | rc = inflate (&strm, Z_FINISH); |
| 1513 | if (rc != Z_STREAM_END) |
| 1514 | error (_("Dwarf Error: zlib error uncompressing from '%s': %d"), |
| 1515 | bfd_get_filename (abfd), rc); |
| 1516 | rc = inflateReset (&strm); |
| 1517 | } |
| 1518 | rc = inflateEnd (&strm); |
| 1519 | if (rc != Z_OK |
| 1520 | || strm.avail_out != 0) |
| 1521 | error (_("Dwarf Error: concluding DWARF uncompression in '%s': %d"), |
| 1522 | bfd_get_filename (abfd), rc); |
| 1523 | |
| 1524 | do_cleanups (cleanup); |
| 1525 | *outbuf = uncompressed_buffer; |
| 1526 | *outsize = uncompressed_size; |
| 1527 | #endif |
| 1528 | } |
| 1529 | |
| 1530 | /* A helper function that decides whether a section is empty. */ |
| 1531 | |
| 1532 | static int |
| 1533 | dwarf2_section_empty_p (struct dwarf2_section_info *info) |
| 1534 | { |
| 1535 | return info->asection == NULL || info->size == 0; |
| 1536 | } |
| 1537 | |
| 1538 | /* Read the contents of the section INFO from object file specified by |
| 1539 | OBJFILE, store info about the section into INFO. |
| 1540 | If the section is compressed, uncompress it before returning. */ |
| 1541 | |
| 1542 | static void |
| 1543 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) |
| 1544 | { |
| 1545 | bfd *abfd = objfile->obfd; |
| 1546 | asection *sectp = info->asection; |
| 1547 | gdb_byte *buf, *retbuf; |
| 1548 | unsigned char header[4]; |
| 1549 | |
| 1550 | if (info->readin) |
| 1551 | return; |
| 1552 | info->buffer = NULL; |
| 1553 | info->map_addr = NULL; |
| 1554 | info->readin = 1; |
| 1555 | |
| 1556 | if (dwarf2_section_empty_p (info)) |
| 1557 | return; |
| 1558 | |
| 1559 | /* Check if the file has a 4-byte header indicating compression. */ |
| 1560 | if (info->size > sizeof (header) |
| 1561 | && bfd_seek (abfd, sectp->filepos, SEEK_SET) == 0 |
| 1562 | && bfd_bread (header, sizeof (header), abfd) == sizeof (header)) |
| 1563 | { |
| 1564 | /* Upon decompression, update the buffer and its size. */ |
| 1565 | if (strncmp (header, "ZLIB", sizeof (header)) == 0) |
| 1566 | { |
| 1567 | zlib_decompress_section (objfile, sectp, &info->buffer, |
| 1568 | &info->size); |
| 1569 | return; |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | #ifdef HAVE_MMAP |
| 1574 | if (pagesize == 0) |
| 1575 | pagesize = getpagesize (); |
| 1576 | |
| 1577 | /* Only try to mmap sections which are large enough: we don't want to |
| 1578 | waste space due to fragmentation. Also, only try mmap for sections |
| 1579 | without relocations. */ |
| 1580 | |
| 1581 | if (info->size > 4 * pagesize && (sectp->flags & SEC_RELOC) == 0) |
| 1582 | { |
| 1583 | info->buffer = bfd_mmap (abfd, 0, info->size, PROT_READ, |
| 1584 | MAP_PRIVATE, sectp->filepos, |
| 1585 | &info->map_addr, &info->map_len); |
| 1586 | |
| 1587 | if ((caddr_t)info->buffer != MAP_FAILED) |
| 1588 | { |
| 1589 | #if HAVE_POSIX_MADVISE |
| 1590 | posix_madvise (info->map_addr, info->map_len, POSIX_MADV_WILLNEED); |
| 1591 | #endif |
| 1592 | return; |
| 1593 | } |
| 1594 | } |
| 1595 | #endif |
| 1596 | |
| 1597 | /* If we get here, we are a normal, not-compressed section. */ |
| 1598 | info->buffer = buf |
| 1599 | = obstack_alloc (&objfile->objfile_obstack, info->size); |
| 1600 | |
| 1601 | /* When debugging .o files, we may need to apply relocations; see |
| 1602 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . |
| 1603 | We never compress sections in .o files, so we only need to |
| 1604 | try this when the section is not compressed. */ |
| 1605 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
| 1606 | if (retbuf != NULL) |
| 1607 | { |
| 1608 | info->buffer = retbuf; |
| 1609 | return; |
| 1610 | } |
| 1611 | |
| 1612 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
| 1613 | || bfd_bread (buf, info->size, abfd) != info->size) |
| 1614 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
| 1615 | bfd_get_filename (abfd)); |
| 1616 | } |
| 1617 | |
| 1618 | /* A helper function that returns the size of a section in a safe way. |
| 1619 | If you are positive that the section has been read before using the |
| 1620 | size, then it is safe to refer to the dwarf2_section_info object's |
| 1621 | "size" field directly. In other cases, you must call this |
| 1622 | function, because for compressed sections the size field is not set |
| 1623 | correctly until the section has been read. */ |
| 1624 | |
| 1625 | static bfd_size_type |
| 1626 | dwarf2_section_size (struct objfile *objfile, |
| 1627 | struct dwarf2_section_info *info) |
| 1628 | { |
| 1629 | if (!info->readin) |
| 1630 | dwarf2_read_section (objfile, info); |
| 1631 | return info->size; |
| 1632 | } |
| 1633 | |
| 1634 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
| 1635 | SECTION_NAME. */ |
| 1636 | |
| 1637 | void |
| 1638 | dwarf2_get_section_info (struct objfile *objfile, |
| 1639 | enum dwarf2_section_enum sect, |
| 1640 | asection **sectp, gdb_byte **bufp, |
| 1641 | bfd_size_type *sizep) |
| 1642 | { |
| 1643 | struct dwarf2_per_objfile *data |
| 1644 | = objfile_data (objfile, dwarf2_objfile_data_key); |
| 1645 | struct dwarf2_section_info *info; |
| 1646 | |
| 1647 | /* We may see an objfile without any DWARF, in which case we just |
| 1648 | return nothing. */ |
| 1649 | if (data == NULL) |
| 1650 | { |
| 1651 | *sectp = NULL; |
| 1652 | *bufp = NULL; |
| 1653 | *sizep = 0; |
| 1654 | return; |
| 1655 | } |
| 1656 | switch (sect) |
| 1657 | { |
| 1658 | case DWARF2_DEBUG_FRAME: |
| 1659 | info = &data->frame; |
| 1660 | break; |
| 1661 | case DWARF2_EH_FRAME: |
| 1662 | info = &data->eh_frame; |
| 1663 | break; |
| 1664 | default: |
| 1665 | gdb_assert_not_reached ("unexpected section"); |
| 1666 | } |
| 1667 | |
| 1668 | dwarf2_read_section (objfile, info); |
| 1669 | |
| 1670 | *sectp = info->asection; |
| 1671 | *bufp = info->buffer; |
| 1672 | *sizep = info->size; |
| 1673 | } |
| 1674 | |
| 1675 | \f |
| 1676 | /* DWARF quick_symbols_functions support. */ |
| 1677 | |
| 1678 | /* TUs can share .debug_line entries, and there can be a lot more TUs than |
| 1679 | unique line tables, so we maintain a separate table of all .debug_line |
| 1680 | derived entries to support the sharing. |
| 1681 | All the quick functions need is the list of file names. We discard the |
| 1682 | line_header when we're done and don't need to record it here. */ |
| 1683 | struct quick_file_names |
| 1684 | { |
| 1685 | /* The offset in .debug_line of the line table. We hash on this. */ |
| 1686 | unsigned int offset; |
| 1687 | |
| 1688 | /* The number of entries in file_names, real_names. */ |
| 1689 | unsigned int num_file_names; |
| 1690 | |
| 1691 | /* The file names from the line table, after being run through |
| 1692 | file_full_name. */ |
| 1693 | const char **file_names; |
| 1694 | |
| 1695 | /* The file names from the line table after being run through |
| 1696 | gdb_realpath. These are computed lazily. */ |
| 1697 | const char **real_names; |
| 1698 | }; |
| 1699 | |
| 1700 | /* When using the index (and thus not using psymtabs), each CU has an |
| 1701 | object of this type. This is used to hold information needed by |
| 1702 | the various "quick" methods. */ |
| 1703 | struct dwarf2_per_cu_quick_data |
| 1704 | { |
| 1705 | /* The file table. This can be NULL if there was no file table |
| 1706 | or it's currently not read in. |
| 1707 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ |
| 1708 | struct quick_file_names *file_names; |
| 1709 | |
| 1710 | /* The corresponding symbol table. This is NULL if symbols for this |
| 1711 | CU have not yet been read. */ |
| 1712 | struct symtab *symtab; |
| 1713 | |
| 1714 | /* A temporary mark bit used when iterating over all CUs in |
| 1715 | expand_symtabs_matching. */ |
| 1716 | unsigned int mark : 1; |
| 1717 | |
| 1718 | /* True if we've tried to read the file table and found there isn't one. |
| 1719 | There will be no point in trying to read it again next time. */ |
| 1720 | unsigned int no_file_data : 1; |
| 1721 | }; |
| 1722 | |
| 1723 | /* Hash function for a quick_file_names. */ |
| 1724 | |
| 1725 | static hashval_t |
| 1726 | hash_file_name_entry (const void *e) |
| 1727 | { |
| 1728 | const struct quick_file_names *file_data = e; |
| 1729 | |
| 1730 | return file_data->offset; |
| 1731 | } |
| 1732 | |
| 1733 | /* Equality function for a quick_file_names. */ |
| 1734 | |
| 1735 | static int |
| 1736 | eq_file_name_entry (const void *a, const void *b) |
| 1737 | { |
| 1738 | const struct quick_file_names *ea = a; |
| 1739 | const struct quick_file_names *eb = b; |
| 1740 | |
| 1741 | return ea->offset == eb->offset; |
| 1742 | } |
| 1743 | |
| 1744 | /* Delete function for a quick_file_names. */ |
| 1745 | |
| 1746 | static void |
| 1747 | delete_file_name_entry (void *e) |
| 1748 | { |
| 1749 | struct quick_file_names *file_data = e; |
| 1750 | int i; |
| 1751 | |
| 1752 | for (i = 0; i < file_data->num_file_names; ++i) |
| 1753 | { |
| 1754 | xfree ((void*) file_data->file_names[i]); |
| 1755 | if (file_data->real_names) |
| 1756 | xfree ((void*) file_data->real_names[i]); |
| 1757 | } |
| 1758 | |
| 1759 | /* The space for the struct itself lives on objfile_obstack, |
| 1760 | so we don't free it here. */ |
| 1761 | } |
| 1762 | |
| 1763 | /* Create a quick_file_names hash table. */ |
| 1764 | |
| 1765 | static htab_t |
| 1766 | create_quick_file_names_table (unsigned int nr_initial_entries) |
| 1767 | { |
| 1768 | return htab_create_alloc (nr_initial_entries, |
| 1769 | hash_file_name_entry, eq_file_name_entry, |
| 1770 | delete_file_name_entry, xcalloc, xfree); |
| 1771 | } |
| 1772 | |
| 1773 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
| 1774 | have to be created afterwards. You should call age_cached_comp_units after |
| 1775 | processing PER_CU->CU. dw2_setup must have been already called. */ |
| 1776 | |
| 1777 | static void |
| 1778 | load_cu (struct dwarf2_per_cu_data *per_cu) |
| 1779 | { |
| 1780 | if (per_cu->debug_types_section) |
| 1781 | load_full_type_unit (per_cu); |
| 1782 | else |
| 1783 | load_full_comp_unit (per_cu); |
| 1784 | |
| 1785 | gdb_assert (per_cu->cu != NULL); |
| 1786 | |
| 1787 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); |
| 1788 | } |
| 1789 | |
| 1790 | /* Read in the symbols for PER_CU. */ |
| 1791 | |
| 1792 | static void |
| 1793 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
| 1794 | { |
| 1795 | struct cleanup *back_to; |
| 1796 | |
| 1797 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
| 1798 | |
| 1799 | queue_comp_unit (per_cu); |
| 1800 | |
| 1801 | load_cu (per_cu); |
| 1802 | |
| 1803 | process_queue (); |
| 1804 | |
| 1805 | /* Age the cache, releasing compilation units that have not |
| 1806 | been used recently. */ |
| 1807 | age_cached_comp_units (); |
| 1808 | |
| 1809 | do_cleanups (back_to); |
| 1810 | } |
| 1811 | |
| 1812 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is |
| 1813 | the objfile from which this CU came. Returns the resulting symbol |
| 1814 | table. */ |
| 1815 | |
| 1816 | static struct symtab * |
| 1817 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
| 1818 | { |
| 1819 | if (!per_cu->v.quick->symtab) |
| 1820 | { |
| 1821 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); |
| 1822 | increment_reading_symtab (); |
| 1823 | dw2_do_instantiate_symtab (per_cu); |
| 1824 | do_cleanups (back_to); |
| 1825 | } |
| 1826 | return per_cu->v.quick->symtab; |
| 1827 | } |
| 1828 | |
| 1829 | /* Return the CU given its index. */ |
| 1830 | |
| 1831 | static struct dwarf2_per_cu_data * |
| 1832 | dw2_get_cu (int index) |
| 1833 | { |
| 1834 | if (index >= dwarf2_per_objfile->n_comp_units) |
| 1835 | { |
| 1836 | index -= dwarf2_per_objfile->n_comp_units; |
| 1837 | return dwarf2_per_objfile->all_type_units[index]; |
| 1838 | } |
| 1839 | return dwarf2_per_objfile->all_comp_units[index]; |
| 1840 | } |
| 1841 | |
| 1842 | /* A helper function that knows how to read a 64-bit value in a way |
| 1843 | that doesn't make gdb die. Returns 1 if the conversion went ok, 0 |
| 1844 | otherwise. */ |
| 1845 | |
| 1846 | static int |
| 1847 | extract_cu_value (const char *bytes, ULONGEST *result) |
| 1848 | { |
| 1849 | if (sizeof (ULONGEST) < 8) |
| 1850 | { |
| 1851 | int i; |
| 1852 | |
| 1853 | /* Ignore the upper 4 bytes if they are all zero. */ |
| 1854 | for (i = 0; i < 4; ++i) |
| 1855 | if (bytes[i + 4] != 0) |
| 1856 | return 0; |
| 1857 | |
| 1858 | *result = extract_unsigned_integer (bytes, 4, BFD_ENDIAN_LITTLE); |
| 1859 | } |
| 1860 | else |
| 1861 | *result = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); |
| 1862 | return 1; |
| 1863 | } |
| 1864 | |
| 1865 | /* Read the CU list from the mapped index, and use it to create all |
| 1866 | the CU objects for this objfile. Return 0 if something went wrong, |
| 1867 | 1 if everything went ok. */ |
| 1868 | |
| 1869 | static int |
| 1870 | create_cus_from_index (struct objfile *objfile, const gdb_byte *cu_list, |
| 1871 | offset_type cu_list_elements) |
| 1872 | { |
| 1873 | offset_type i; |
| 1874 | |
| 1875 | dwarf2_per_objfile->n_comp_units = cu_list_elements / 2; |
| 1876 | dwarf2_per_objfile->all_comp_units |
| 1877 | = obstack_alloc (&objfile->objfile_obstack, |
| 1878 | dwarf2_per_objfile->n_comp_units |
| 1879 | * sizeof (struct dwarf2_per_cu_data *)); |
| 1880 | |
| 1881 | for (i = 0; i < cu_list_elements; i += 2) |
| 1882 | { |
| 1883 | struct dwarf2_per_cu_data *the_cu; |
| 1884 | ULONGEST offset, length; |
| 1885 | |
| 1886 | if (!extract_cu_value (cu_list, &offset) |
| 1887 | || !extract_cu_value (cu_list + 8, &length)) |
| 1888 | return 0; |
| 1889 | cu_list += 2 * 8; |
| 1890 | |
| 1891 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1892 | struct dwarf2_per_cu_data); |
| 1893 | the_cu->offset = offset; |
| 1894 | the_cu->length = length; |
| 1895 | the_cu->objfile = objfile; |
| 1896 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1897 | struct dwarf2_per_cu_quick_data); |
| 1898 | dwarf2_per_objfile->all_comp_units[i / 2] = the_cu; |
| 1899 | } |
| 1900 | |
| 1901 | return 1; |
| 1902 | } |
| 1903 | |
| 1904 | /* Create the signatured type hash table from the index. */ |
| 1905 | |
| 1906 | static int |
| 1907 | create_signatured_type_table_from_index (struct objfile *objfile, |
| 1908 | struct dwarf2_section_info *section, |
| 1909 | const gdb_byte *bytes, |
| 1910 | offset_type elements) |
| 1911 | { |
| 1912 | offset_type i; |
| 1913 | htab_t sig_types_hash; |
| 1914 | |
| 1915 | dwarf2_per_objfile->n_type_units = elements / 3; |
| 1916 | dwarf2_per_objfile->all_type_units |
| 1917 | = obstack_alloc (&objfile->objfile_obstack, |
| 1918 | dwarf2_per_objfile->n_type_units |
| 1919 | * sizeof (struct dwarf2_per_cu_data *)); |
| 1920 | |
| 1921 | sig_types_hash = allocate_signatured_type_table (objfile); |
| 1922 | |
| 1923 | for (i = 0; i < elements; i += 3) |
| 1924 | { |
| 1925 | struct signatured_type *type_sig; |
| 1926 | ULONGEST offset, type_offset, signature; |
| 1927 | void **slot; |
| 1928 | |
| 1929 | if (!extract_cu_value (bytes, &offset) |
| 1930 | || !extract_cu_value (bytes + 8, &type_offset)) |
| 1931 | return 0; |
| 1932 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); |
| 1933 | bytes += 3 * 8; |
| 1934 | |
| 1935 | type_sig = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1936 | struct signatured_type); |
| 1937 | type_sig->signature = signature; |
| 1938 | type_sig->type_offset = type_offset; |
| 1939 | type_sig->per_cu.debug_types_section = section; |
| 1940 | type_sig->per_cu.offset = offset; |
| 1941 | type_sig->per_cu.objfile = objfile; |
| 1942 | type_sig->per_cu.v.quick |
| 1943 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 1944 | struct dwarf2_per_cu_quick_data); |
| 1945 | |
| 1946 | slot = htab_find_slot (sig_types_hash, type_sig, INSERT); |
| 1947 | *slot = type_sig; |
| 1948 | |
| 1949 | dwarf2_per_objfile->all_type_units[i / 3] = &type_sig->per_cu; |
| 1950 | } |
| 1951 | |
| 1952 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
| 1953 | |
| 1954 | return 1; |
| 1955 | } |
| 1956 | |
| 1957 | /* Read the address map data from the mapped index, and use it to |
| 1958 | populate the objfile's psymtabs_addrmap. */ |
| 1959 | |
| 1960 | static void |
| 1961 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) |
| 1962 | { |
| 1963 | const gdb_byte *iter, *end; |
| 1964 | struct obstack temp_obstack; |
| 1965 | struct addrmap *mutable_map; |
| 1966 | struct cleanup *cleanup; |
| 1967 | CORE_ADDR baseaddr; |
| 1968 | |
| 1969 | obstack_init (&temp_obstack); |
| 1970 | cleanup = make_cleanup_obstack_free (&temp_obstack); |
| 1971 | mutable_map = addrmap_create_mutable (&temp_obstack); |
| 1972 | |
| 1973 | iter = index->address_table; |
| 1974 | end = iter + index->address_table_size; |
| 1975 | |
| 1976 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 1977 | |
| 1978 | while (iter < end) |
| 1979 | { |
| 1980 | ULONGEST hi, lo, cu_index; |
| 1981 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); |
| 1982 | iter += 8; |
| 1983 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); |
| 1984 | iter += 8; |
| 1985 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); |
| 1986 | iter += 4; |
| 1987 | |
| 1988 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, |
| 1989 | dw2_get_cu (cu_index)); |
| 1990 | } |
| 1991 | |
| 1992 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, |
| 1993 | &objfile->objfile_obstack); |
| 1994 | do_cleanups (cleanup); |
| 1995 | } |
| 1996 | |
| 1997 | /* The hash function for strings in the mapped index. This is the same as |
| 1998 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the |
| 1999 | implementation. This is necessary because the hash function is tied to the |
| 2000 | format of the mapped index file. The hash values do not have to match with |
| 2001 | SYMBOL_HASH_NEXT. |
| 2002 | |
| 2003 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ |
| 2004 | |
| 2005 | static hashval_t |
| 2006 | mapped_index_string_hash (int index_version, const void *p) |
| 2007 | { |
| 2008 | const unsigned char *str = (const unsigned char *) p; |
| 2009 | hashval_t r = 0; |
| 2010 | unsigned char c; |
| 2011 | |
| 2012 | while ((c = *str++) != 0) |
| 2013 | { |
| 2014 | if (index_version >= 5) |
| 2015 | c = tolower (c); |
| 2016 | r = r * 67 + c - 113; |
| 2017 | } |
| 2018 | |
| 2019 | return r; |
| 2020 | } |
| 2021 | |
| 2022 | /* Find a slot in the mapped index INDEX for the object named NAME. |
| 2023 | If NAME is found, set *VEC_OUT to point to the CU vector in the |
| 2024 | constant pool and return 1. If NAME cannot be found, return 0. */ |
| 2025 | |
| 2026 | static int |
| 2027 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, |
| 2028 | offset_type **vec_out) |
| 2029 | { |
| 2030 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 2031 | offset_type hash; |
| 2032 | offset_type slot, step; |
| 2033 | int (*cmp) (const char *, const char *); |
| 2034 | |
| 2035 | if (current_language->la_language == language_cplus |
| 2036 | || current_language->la_language == language_java |
| 2037 | || current_language->la_language == language_fortran) |
| 2038 | { |
| 2039 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does |
| 2040 | not contain any. */ |
| 2041 | const char *paren = strchr (name, '('); |
| 2042 | |
| 2043 | if (paren) |
| 2044 | { |
| 2045 | char *dup; |
| 2046 | |
| 2047 | dup = xmalloc (paren - name + 1); |
| 2048 | memcpy (dup, name, paren - name); |
| 2049 | dup[paren - name] = 0; |
| 2050 | |
| 2051 | make_cleanup (xfree, dup); |
| 2052 | name = dup; |
| 2053 | } |
| 2054 | } |
| 2055 | |
| 2056 | /* Index version 4 did not support case insensitive searches. But the |
| 2057 | indexes for case insensitive languages are built in lowercase, therefore |
| 2058 | simulate our NAME being searched is also lowercased. */ |
| 2059 | hash = mapped_index_string_hash ((index->version == 4 |
| 2060 | && case_sensitivity == case_sensitive_off |
| 2061 | ? 5 : index->version), |
| 2062 | name); |
| 2063 | |
| 2064 | slot = hash & (index->symbol_table_slots - 1); |
| 2065 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; |
| 2066 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
| 2067 | |
| 2068 | for (;;) |
| 2069 | { |
| 2070 | /* Convert a slot number to an offset into the table. */ |
| 2071 | offset_type i = 2 * slot; |
| 2072 | const char *str; |
| 2073 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
| 2074 | { |
| 2075 | do_cleanups (back_to); |
| 2076 | return 0; |
| 2077 | } |
| 2078 | |
| 2079 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
| 2080 | if (!cmp (name, str)) |
| 2081 | { |
| 2082 | *vec_out = (offset_type *) (index->constant_pool |
| 2083 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
| 2084 | do_cleanups (back_to); |
| 2085 | return 1; |
| 2086 | } |
| 2087 | |
| 2088 | slot = (slot + step) & (index->symbol_table_slots - 1); |
| 2089 | } |
| 2090 | } |
| 2091 | |
| 2092 | /* Read the index file. If everything went ok, initialize the "quick" |
| 2093 | elements of all the CUs and return 1. Otherwise, return 0. */ |
| 2094 | |
| 2095 | static int |
| 2096 | dwarf2_read_index (struct objfile *objfile) |
| 2097 | { |
| 2098 | char *addr; |
| 2099 | struct mapped_index *map; |
| 2100 | offset_type *metadata; |
| 2101 | const gdb_byte *cu_list; |
| 2102 | const gdb_byte *types_list = NULL; |
| 2103 | offset_type version, cu_list_elements; |
| 2104 | offset_type types_list_elements = 0; |
| 2105 | int i; |
| 2106 | |
| 2107 | if (dwarf2_section_empty_p (&dwarf2_per_objfile->gdb_index)) |
| 2108 | return 0; |
| 2109 | |
| 2110 | /* Older elfutils strip versions could keep the section in the main |
| 2111 | executable while splitting it for the separate debug info file. */ |
| 2112 | if ((bfd_get_file_flags (dwarf2_per_objfile->gdb_index.asection) |
| 2113 | & SEC_HAS_CONTENTS) == 0) |
| 2114 | return 0; |
| 2115 | |
| 2116 | dwarf2_read_section (objfile, &dwarf2_per_objfile->gdb_index); |
| 2117 | |
| 2118 | addr = dwarf2_per_objfile->gdb_index.buffer; |
| 2119 | /* Version check. */ |
| 2120 | version = MAYBE_SWAP (*(offset_type *) addr); |
| 2121 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
| 2122 | causes the index to behave very poorly for certain requests. Version 3 |
| 2123 | contained incomplete addrmap. So, it seems better to just ignore such |
| 2124 | indices. Index version 4 uses a different hash function than index |
| 2125 | version 5 and later. */ |
| 2126 | if (version < 4) |
| 2127 | return 0; |
| 2128 | /* Indexes with higher version than the one supported by GDB may be no |
| 2129 | longer backward compatible. */ |
| 2130 | if (version > 5) |
| 2131 | return 0; |
| 2132 | |
| 2133 | map = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct mapped_index); |
| 2134 | map->version = version; |
| 2135 | map->total_size = dwarf2_per_objfile->gdb_index.size; |
| 2136 | |
| 2137 | metadata = (offset_type *) (addr + sizeof (offset_type)); |
| 2138 | |
| 2139 | i = 0; |
| 2140 | cu_list = addr + MAYBE_SWAP (metadata[i]); |
| 2141 | cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) |
| 2142 | / 8); |
| 2143 | ++i; |
| 2144 | |
| 2145 | types_list = addr + MAYBE_SWAP (metadata[i]); |
| 2146 | types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) |
| 2147 | - MAYBE_SWAP (metadata[i])) |
| 2148 | / 8); |
| 2149 | ++i; |
| 2150 | |
| 2151 | map->address_table = addr + MAYBE_SWAP (metadata[i]); |
| 2152 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) |
| 2153 | - MAYBE_SWAP (metadata[i])); |
| 2154 | ++i; |
| 2155 | |
| 2156 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
| 2157 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) |
| 2158 | - MAYBE_SWAP (metadata[i])) |
| 2159 | / (2 * sizeof (offset_type))); |
| 2160 | ++i; |
| 2161 | |
| 2162 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
| 2163 | |
| 2164 | if (!create_cus_from_index (objfile, cu_list, cu_list_elements)) |
| 2165 | return 0; |
| 2166 | |
| 2167 | if (types_list_elements) |
| 2168 | { |
| 2169 | struct dwarf2_section_info *section; |
| 2170 | |
| 2171 | /* We can only handle a single .debug_types when we have an |
| 2172 | index. */ |
| 2173 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) |
| 2174 | return 0; |
| 2175 | |
| 2176 | section = VEC_index (dwarf2_section_info_def, |
| 2177 | dwarf2_per_objfile->types, 0); |
| 2178 | |
| 2179 | if (!create_signatured_type_table_from_index (objfile, section, |
| 2180 | types_list, |
| 2181 | types_list_elements)) |
| 2182 | return 0; |
| 2183 | } |
| 2184 | |
| 2185 | create_addrmap_from_index (objfile, map); |
| 2186 | |
| 2187 | dwarf2_per_objfile->index_table = map; |
| 2188 | dwarf2_per_objfile->using_index = 1; |
| 2189 | dwarf2_per_objfile->quick_file_names_table = |
| 2190 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); |
| 2191 | |
| 2192 | return 1; |
| 2193 | } |
| 2194 | |
| 2195 | /* A helper for the "quick" functions which sets the global |
| 2196 | dwarf2_per_objfile according to OBJFILE. */ |
| 2197 | |
| 2198 | static void |
| 2199 | dw2_setup (struct objfile *objfile) |
| 2200 | { |
| 2201 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 2202 | gdb_assert (dwarf2_per_objfile); |
| 2203 | } |
| 2204 | |
| 2205 | /* A helper for the "quick" functions which attempts to read the line |
| 2206 | table for THIS_CU. */ |
| 2207 | |
| 2208 | static struct quick_file_names * |
| 2209 | dw2_get_file_names (struct objfile *objfile, |
| 2210 | struct dwarf2_per_cu_data *this_cu) |
| 2211 | { |
| 2212 | bfd *abfd = objfile->obfd; |
| 2213 | struct line_header *lh; |
| 2214 | struct attribute *attr; |
| 2215 | struct cleanup *cleanups; |
| 2216 | struct die_info *comp_unit_die; |
| 2217 | struct dwarf2_section_info* sec; |
| 2218 | gdb_byte *info_ptr; |
| 2219 | int has_children, i; |
| 2220 | struct dwarf2_cu cu; |
| 2221 | unsigned int bytes_read; |
| 2222 | struct die_reader_specs reader_specs; |
| 2223 | char *name, *comp_dir; |
| 2224 | void **slot; |
| 2225 | struct quick_file_names *qfn; |
| 2226 | unsigned int line_offset; |
| 2227 | |
| 2228 | if (this_cu->v.quick->file_names != NULL) |
| 2229 | return this_cu->v.quick->file_names; |
| 2230 | /* If we know there is no line data, no point in looking again. */ |
| 2231 | if (this_cu->v.quick->no_file_data) |
| 2232 | return NULL; |
| 2233 | |
| 2234 | init_one_comp_unit (&cu, this_cu); |
| 2235 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
| 2236 | |
| 2237 | if (this_cu->debug_types_section) |
| 2238 | sec = this_cu->debug_types_section; |
| 2239 | else |
| 2240 | sec = &dwarf2_per_objfile->info; |
| 2241 | dwarf2_read_section (objfile, sec); |
| 2242 | info_ptr = sec->buffer + this_cu->offset; |
| 2243 | |
| 2244 | info_ptr = read_and_check_comp_unit_head (&cu.header, sec, info_ptr, |
| 2245 | this_cu->debug_types_section != NULL); |
| 2246 | |
| 2247 | /* Skip dummy compilation units. */ |
| 2248 | if (info_ptr >= (sec->buffer + sec->size) |
| 2249 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 2250 | { |
| 2251 | do_cleanups (cleanups); |
| 2252 | return NULL; |
| 2253 | } |
| 2254 | |
| 2255 | dwarf2_read_abbrevs (&cu); |
| 2256 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
| 2257 | |
| 2258 | init_cu_die_reader (&reader_specs, &cu); |
| 2259 | read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
| 2260 | &has_children); |
| 2261 | |
| 2262 | lh = NULL; |
| 2263 | slot = NULL; |
| 2264 | line_offset = 0; |
| 2265 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, &cu); |
| 2266 | if (attr) |
| 2267 | { |
| 2268 | struct quick_file_names find_entry; |
| 2269 | |
| 2270 | line_offset = DW_UNSND (attr); |
| 2271 | |
| 2272 | /* We may have already read in this line header (TU line header sharing). |
| 2273 | If we have we're done. */ |
| 2274 | find_entry.offset = line_offset; |
| 2275 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, |
| 2276 | &find_entry, INSERT); |
| 2277 | if (*slot != NULL) |
| 2278 | { |
| 2279 | do_cleanups (cleanups); |
| 2280 | this_cu->v.quick->file_names = *slot; |
| 2281 | return *slot; |
| 2282 | } |
| 2283 | |
| 2284 | lh = dwarf_decode_line_header (line_offset, abfd, &cu); |
| 2285 | } |
| 2286 | if (lh == NULL) |
| 2287 | { |
| 2288 | do_cleanups (cleanups); |
| 2289 | this_cu->v.quick->no_file_data = 1; |
| 2290 | return NULL; |
| 2291 | } |
| 2292 | |
| 2293 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
| 2294 | qfn->offset = line_offset; |
| 2295 | gdb_assert (slot != NULL); |
| 2296 | *slot = qfn; |
| 2297 | |
| 2298 | find_file_and_directory (comp_unit_die, &cu, &name, &comp_dir); |
| 2299 | |
| 2300 | qfn->num_file_names = lh->num_file_names; |
| 2301 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, |
| 2302 | lh->num_file_names * sizeof (char *)); |
| 2303 | for (i = 0; i < lh->num_file_names; ++i) |
| 2304 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
| 2305 | qfn->real_names = NULL; |
| 2306 | |
| 2307 | free_line_header (lh); |
| 2308 | do_cleanups (cleanups); |
| 2309 | |
| 2310 | this_cu->v.quick->file_names = qfn; |
| 2311 | return qfn; |
| 2312 | } |
| 2313 | |
| 2314 | /* A helper for the "quick" functions which computes and caches the |
| 2315 | real path for a given file name from the line table. */ |
| 2316 | |
| 2317 | static const char * |
| 2318 | dw2_get_real_path (struct objfile *objfile, |
| 2319 | struct quick_file_names *qfn, int index) |
| 2320 | { |
| 2321 | if (qfn->real_names == NULL) |
| 2322 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, |
| 2323 | qfn->num_file_names, sizeof (char *)); |
| 2324 | |
| 2325 | if (qfn->real_names[index] == NULL) |
| 2326 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); |
| 2327 | |
| 2328 | return qfn->real_names[index]; |
| 2329 | } |
| 2330 | |
| 2331 | static struct symtab * |
| 2332 | dw2_find_last_source_symtab (struct objfile *objfile) |
| 2333 | { |
| 2334 | int index; |
| 2335 | |
| 2336 | dw2_setup (objfile); |
| 2337 | index = dwarf2_per_objfile->n_comp_units - 1; |
| 2338 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
| 2339 | } |
| 2340 | |
| 2341 | /* Traversal function for dw2_forget_cached_source_info. */ |
| 2342 | |
| 2343 | static int |
| 2344 | dw2_free_cached_file_names (void **slot, void *info) |
| 2345 | { |
| 2346 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
| 2347 | |
| 2348 | if (file_data->real_names) |
| 2349 | { |
| 2350 | int i; |
| 2351 | |
| 2352 | for (i = 0; i < file_data->num_file_names; ++i) |
| 2353 | { |
| 2354 | xfree ((void*) file_data->real_names[i]); |
| 2355 | file_data->real_names[i] = NULL; |
| 2356 | } |
| 2357 | } |
| 2358 | |
| 2359 | return 1; |
| 2360 | } |
| 2361 | |
| 2362 | static void |
| 2363 | dw2_forget_cached_source_info (struct objfile *objfile) |
| 2364 | { |
| 2365 | dw2_setup (objfile); |
| 2366 | |
| 2367 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, |
| 2368 | dw2_free_cached_file_names, NULL); |
| 2369 | } |
| 2370 | |
| 2371 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
| 2372 | the symtabs and calls the iterator. */ |
| 2373 | |
| 2374 | static int |
| 2375 | dw2_map_expand_apply (struct objfile *objfile, |
| 2376 | struct dwarf2_per_cu_data *per_cu, |
| 2377 | const char *name, |
| 2378 | const char *full_path, const char *real_path, |
| 2379 | int (*callback) (struct symtab *, void *), |
| 2380 | void *data) |
| 2381 | { |
| 2382 | struct symtab *last_made = objfile->symtabs; |
| 2383 | |
| 2384 | /* Don't visit already-expanded CUs. */ |
| 2385 | if (per_cu->v.quick->symtab) |
| 2386 | return 0; |
| 2387 | |
| 2388 | /* This may expand more than one symtab, and we want to iterate over |
| 2389 | all of them. */ |
| 2390 | dw2_instantiate_symtab (per_cu); |
| 2391 | |
| 2392 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, |
| 2393 | objfile->symtabs, last_made); |
| 2394 | } |
| 2395 | |
| 2396 | /* Implementation of the map_symtabs_matching_filename method. */ |
| 2397 | |
| 2398 | static int |
| 2399 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
| 2400 | const char *full_path, const char *real_path, |
| 2401 | int (*callback) (struct symtab *, void *), |
| 2402 | void *data) |
| 2403 | { |
| 2404 | int i; |
| 2405 | const char *name_basename = lbasename (name); |
| 2406 | int name_len = strlen (name); |
| 2407 | int is_abs = IS_ABSOLUTE_PATH (name); |
| 2408 | |
| 2409 | dw2_setup (objfile); |
| 2410 | |
| 2411 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2412 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2413 | { |
| 2414 | int j; |
| 2415 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2416 | struct quick_file_names *file_data; |
| 2417 | |
| 2418 | /* We only need to look at symtabs not already expanded. */ |
| 2419 | if (per_cu->v.quick->symtab) |
| 2420 | continue; |
| 2421 | |
| 2422 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2423 | if (file_data == NULL) |
| 2424 | continue; |
| 2425 | |
| 2426 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2427 | { |
| 2428 | const char *this_name = file_data->file_names[j]; |
| 2429 | |
| 2430 | if (FILENAME_CMP (name, this_name) == 0 |
| 2431 | || (!is_abs && compare_filenames_for_search (this_name, |
| 2432 | name, name_len))) |
| 2433 | { |
| 2434 | if (dw2_map_expand_apply (objfile, per_cu, |
| 2435 | name, full_path, real_path, |
| 2436 | callback, data)) |
| 2437 | return 1; |
| 2438 | } |
| 2439 | |
| 2440 | /* Before we invoke realpath, which can get expensive when many |
| 2441 | files are involved, do a quick comparison of the basenames. */ |
| 2442 | if (! basenames_may_differ |
| 2443 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) |
| 2444 | continue; |
| 2445 | |
| 2446 | if (full_path != NULL) |
| 2447 | { |
| 2448 | const char *this_real_name = dw2_get_real_path (objfile, |
| 2449 | file_data, j); |
| 2450 | |
| 2451 | if (this_real_name != NULL |
| 2452 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
| 2453 | || (!is_abs |
| 2454 | && compare_filenames_for_search (this_real_name, |
| 2455 | name, name_len)))) |
| 2456 | { |
| 2457 | if (dw2_map_expand_apply (objfile, per_cu, |
| 2458 | name, full_path, real_path, |
| 2459 | callback, data)) |
| 2460 | return 1; |
| 2461 | } |
| 2462 | } |
| 2463 | |
| 2464 | if (real_path != NULL) |
| 2465 | { |
| 2466 | const char *this_real_name = dw2_get_real_path (objfile, |
| 2467 | file_data, j); |
| 2468 | |
| 2469 | if (this_real_name != NULL |
| 2470 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
| 2471 | || (!is_abs |
| 2472 | && compare_filenames_for_search (this_real_name, |
| 2473 | name, name_len)))) |
| 2474 | { |
| 2475 | if (dw2_map_expand_apply (objfile, per_cu, |
| 2476 | name, full_path, real_path, |
| 2477 | callback, data)) |
| 2478 | return 1; |
| 2479 | } |
| 2480 | } |
| 2481 | } |
| 2482 | } |
| 2483 | |
| 2484 | return 0; |
| 2485 | } |
| 2486 | |
| 2487 | static struct symtab * |
| 2488 | dw2_lookup_symbol (struct objfile *objfile, int block_index, |
| 2489 | const char *name, domain_enum domain) |
| 2490 | { |
| 2491 | /* We do all the work in the pre_expand_symtabs_matching hook |
| 2492 | instead. */ |
| 2493 | return NULL; |
| 2494 | } |
| 2495 | |
| 2496 | /* A helper function that expands all symtabs that hold an object |
| 2497 | named NAME. */ |
| 2498 | |
| 2499 | static void |
| 2500 | dw2_do_expand_symtabs_matching (struct objfile *objfile, const char *name) |
| 2501 | { |
| 2502 | dw2_setup (objfile); |
| 2503 | |
| 2504 | /* index_table is NULL if OBJF_READNOW. */ |
| 2505 | if (dwarf2_per_objfile->index_table) |
| 2506 | { |
| 2507 | offset_type *vec; |
| 2508 | |
| 2509 | if (find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, |
| 2510 | name, &vec)) |
| 2511 | { |
| 2512 | offset_type i, len = MAYBE_SWAP (*vec); |
| 2513 | for (i = 0; i < len; ++i) |
| 2514 | { |
| 2515 | offset_type cu_index = MAYBE_SWAP (vec[i + 1]); |
| 2516 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
| 2517 | |
| 2518 | dw2_instantiate_symtab (per_cu); |
| 2519 | } |
| 2520 | } |
| 2521 | } |
| 2522 | } |
| 2523 | |
| 2524 | static void |
| 2525 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, |
| 2526 | enum block_enum block_kind, const char *name, |
| 2527 | domain_enum domain) |
| 2528 | { |
| 2529 | dw2_do_expand_symtabs_matching (objfile, name); |
| 2530 | } |
| 2531 | |
| 2532 | static void |
| 2533 | dw2_print_stats (struct objfile *objfile) |
| 2534 | { |
| 2535 | int i, count; |
| 2536 | |
| 2537 | dw2_setup (objfile); |
| 2538 | count = 0; |
| 2539 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2540 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2541 | { |
| 2542 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2543 | |
| 2544 | if (!per_cu->v.quick->symtab) |
| 2545 | ++count; |
| 2546 | } |
| 2547 | printf_filtered (_(" Number of unread CUs: %d\n"), count); |
| 2548 | } |
| 2549 | |
| 2550 | static void |
| 2551 | dw2_dump (struct objfile *objfile) |
| 2552 | { |
| 2553 | /* Nothing worth printing. */ |
| 2554 | } |
| 2555 | |
| 2556 | static void |
| 2557 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, |
| 2558 | struct section_offsets *delta) |
| 2559 | { |
| 2560 | /* There's nothing to relocate here. */ |
| 2561 | } |
| 2562 | |
| 2563 | static void |
| 2564 | dw2_expand_symtabs_for_function (struct objfile *objfile, |
| 2565 | const char *func_name) |
| 2566 | { |
| 2567 | dw2_do_expand_symtabs_matching (objfile, func_name); |
| 2568 | } |
| 2569 | |
| 2570 | static void |
| 2571 | dw2_expand_all_symtabs (struct objfile *objfile) |
| 2572 | { |
| 2573 | int i; |
| 2574 | |
| 2575 | dw2_setup (objfile); |
| 2576 | |
| 2577 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2578 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2579 | { |
| 2580 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2581 | |
| 2582 | dw2_instantiate_symtab (per_cu); |
| 2583 | } |
| 2584 | } |
| 2585 | |
| 2586 | static void |
| 2587 | dw2_expand_symtabs_with_filename (struct objfile *objfile, |
| 2588 | const char *filename) |
| 2589 | { |
| 2590 | int i; |
| 2591 | |
| 2592 | dw2_setup (objfile); |
| 2593 | |
| 2594 | /* We don't need to consider type units here. |
| 2595 | This is only called for examining code, e.g. expand_line_sal. |
| 2596 | There can be an order of magnitude (or more) more type units |
| 2597 | than comp units, and we avoid them if we can. */ |
| 2598 | |
| 2599 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 2600 | { |
| 2601 | int j; |
| 2602 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2603 | struct quick_file_names *file_data; |
| 2604 | |
| 2605 | /* We only need to look at symtabs not already expanded. */ |
| 2606 | if (per_cu->v.quick->symtab) |
| 2607 | continue; |
| 2608 | |
| 2609 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2610 | if (file_data == NULL) |
| 2611 | continue; |
| 2612 | |
| 2613 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2614 | { |
| 2615 | const char *this_name = file_data->file_names[j]; |
| 2616 | if (FILENAME_CMP (this_name, filename) == 0) |
| 2617 | { |
| 2618 | dw2_instantiate_symtab (per_cu); |
| 2619 | break; |
| 2620 | } |
| 2621 | } |
| 2622 | } |
| 2623 | } |
| 2624 | |
| 2625 | static const char * |
| 2626 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
| 2627 | { |
| 2628 | struct dwarf2_per_cu_data *per_cu; |
| 2629 | offset_type *vec; |
| 2630 | struct quick_file_names *file_data; |
| 2631 | |
| 2632 | dw2_setup (objfile); |
| 2633 | |
| 2634 | /* index_table is NULL if OBJF_READNOW. */ |
| 2635 | if (!dwarf2_per_objfile->index_table) |
| 2636 | { |
| 2637 | struct symtab *s; |
| 2638 | |
| 2639 | ALL_OBJFILE_SYMTABS (objfile, s) |
| 2640 | if (s->primary) |
| 2641 | { |
| 2642 | struct blockvector *bv = BLOCKVECTOR (s); |
| 2643 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 2644 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); |
| 2645 | |
| 2646 | if (sym) |
| 2647 | return sym->symtab->filename; |
| 2648 | } |
| 2649 | return NULL; |
| 2650 | } |
| 2651 | |
| 2652 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, |
| 2653 | name, &vec)) |
| 2654 | return NULL; |
| 2655 | |
| 2656 | /* Note that this just looks at the very first one named NAME -- but |
| 2657 | actually we are looking for a function. find_main_filename |
| 2658 | should be rewritten so that it doesn't require a custom hook. It |
| 2659 | could just use the ordinary symbol tables. */ |
| 2660 | /* vec[0] is the length, which must always be >0. */ |
| 2661 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[1])); |
| 2662 | |
| 2663 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2664 | if (file_data == NULL) |
| 2665 | return NULL; |
| 2666 | |
| 2667 | return file_data->file_names[file_data->num_file_names - 1]; |
| 2668 | } |
| 2669 | |
| 2670 | static void |
| 2671 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
| 2672 | struct objfile *objfile, int global, |
| 2673 | int (*callback) (struct block *, |
| 2674 | struct symbol *, void *), |
| 2675 | void *data, symbol_compare_ftype *match, |
| 2676 | symbol_compare_ftype *ordered_compare) |
| 2677 | { |
| 2678 | /* Currently unimplemented; used for Ada. The function can be called if the |
| 2679 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
| 2680 | does not look for non-Ada symbols this function should just return. */ |
| 2681 | } |
| 2682 | |
| 2683 | static void |
| 2684 | dw2_expand_symtabs_matching |
| 2685 | (struct objfile *objfile, |
| 2686 | int (*file_matcher) (const char *, void *), |
| 2687 | int (*name_matcher) (const char *, void *), |
| 2688 | enum search_domain kind, |
| 2689 | void *data) |
| 2690 | { |
| 2691 | int i; |
| 2692 | offset_type iter; |
| 2693 | struct mapped_index *index; |
| 2694 | |
| 2695 | dw2_setup (objfile); |
| 2696 | |
| 2697 | /* index_table is NULL if OBJF_READNOW. */ |
| 2698 | if (!dwarf2_per_objfile->index_table) |
| 2699 | return; |
| 2700 | index = dwarf2_per_objfile->index_table; |
| 2701 | |
| 2702 | if (file_matcher != NULL) |
| 2703 | { |
| 2704 | struct cleanup *cleanup; |
| 2705 | htab_t visited_found, visited_not_found; |
| 2706 | |
| 2707 | visited_found = htab_create_alloc (10, |
| 2708 | htab_hash_pointer, htab_eq_pointer, |
| 2709 | NULL, xcalloc, xfree); |
| 2710 | cleanup = make_cleanup_htab_delete (visited_found); |
| 2711 | visited_not_found = htab_create_alloc (10, |
| 2712 | htab_hash_pointer, htab_eq_pointer, |
| 2713 | NULL, xcalloc, xfree); |
| 2714 | make_cleanup_htab_delete (visited_not_found); |
| 2715 | |
| 2716 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2717 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2718 | { |
| 2719 | int j; |
| 2720 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2721 | struct quick_file_names *file_data; |
| 2722 | void **slot; |
| 2723 | |
| 2724 | per_cu->v.quick->mark = 0; |
| 2725 | |
| 2726 | /* We only need to look at symtabs not already expanded. */ |
| 2727 | if (per_cu->v.quick->symtab) |
| 2728 | continue; |
| 2729 | |
| 2730 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2731 | if (file_data == NULL) |
| 2732 | continue; |
| 2733 | |
| 2734 | if (htab_find (visited_not_found, file_data) != NULL) |
| 2735 | continue; |
| 2736 | else if (htab_find (visited_found, file_data) != NULL) |
| 2737 | { |
| 2738 | per_cu->v.quick->mark = 1; |
| 2739 | continue; |
| 2740 | } |
| 2741 | |
| 2742 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2743 | { |
| 2744 | if (file_matcher (file_data->file_names[j], data)) |
| 2745 | { |
| 2746 | per_cu->v.quick->mark = 1; |
| 2747 | break; |
| 2748 | } |
| 2749 | } |
| 2750 | |
| 2751 | slot = htab_find_slot (per_cu->v.quick->mark |
| 2752 | ? visited_found |
| 2753 | : visited_not_found, |
| 2754 | file_data, INSERT); |
| 2755 | *slot = file_data; |
| 2756 | } |
| 2757 | |
| 2758 | do_cleanups (cleanup); |
| 2759 | } |
| 2760 | |
| 2761 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
| 2762 | { |
| 2763 | offset_type idx = 2 * iter; |
| 2764 | const char *name; |
| 2765 | offset_type *vec, vec_len, vec_idx; |
| 2766 | |
| 2767 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
| 2768 | continue; |
| 2769 | |
| 2770 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
| 2771 | |
| 2772 | if (! (*name_matcher) (name, data)) |
| 2773 | continue; |
| 2774 | |
| 2775 | /* The name was matched, now expand corresponding CUs that were |
| 2776 | marked. */ |
| 2777 | vec = (offset_type *) (index->constant_pool |
| 2778 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
| 2779 | vec_len = MAYBE_SWAP (vec[0]); |
| 2780 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) |
| 2781 | { |
| 2782 | struct dwarf2_per_cu_data *per_cu; |
| 2783 | |
| 2784 | per_cu = dw2_get_cu (MAYBE_SWAP (vec[vec_idx + 1])); |
| 2785 | if (file_matcher == NULL || per_cu->v.quick->mark) |
| 2786 | dw2_instantiate_symtab (per_cu); |
| 2787 | } |
| 2788 | } |
| 2789 | } |
| 2790 | |
| 2791 | static struct symtab * |
| 2792 | dw2_find_pc_sect_symtab (struct objfile *objfile, |
| 2793 | struct minimal_symbol *msymbol, |
| 2794 | CORE_ADDR pc, |
| 2795 | struct obj_section *section, |
| 2796 | int warn_if_readin) |
| 2797 | { |
| 2798 | struct dwarf2_per_cu_data *data; |
| 2799 | |
| 2800 | dw2_setup (objfile); |
| 2801 | |
| 2802 | if (!objfile->psymtabs_addrmap) |
| 2803 | return NULL; |
| 2804 | |
| 2805 | data = addrmap_find (objfile->psymtabs_addrmap, pc); |
| 2806 | if (!data) |
| 2807 | return NULL; |
| 2808 | |
| 2809 | if (warn_if_readin && data->v.quick->symtab) |
| 2810 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
| 2811 | paddress (get_objfile_arch (objfile), pc)); |
| 2812 | |
| 2813 | return dw2_instantiate_symtab (data); |
| 2814 | } |
| 2815 | |
| 2816 | static void |
| 2817 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
| 2818 | void *data, int need_fullname) |
| 2819 | { |
| 2820 | int i; |
| 2821 | struct cleanup *cleanup; |
| 2822 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, |
| 2823 | NULL, xcalloc, xfree); |
| 2824 | |
| 2825 | cleanup = make_cleanup_htab_delete (visited); |
| 2826 | dw2_setup (objfile); |
| 2827 | |
| 2828 | /* We can ignore file names coming from already-expanded CUs. */ |
| 2829 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2830 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2831 | { |
| 2832 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2833 | |
| 2834 | if (per_cu->v.quick->symtab) |
| 2835 | { |
| 2836 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, |
| 2837 | INSERT); |
| 2838 | |
| 2839 | *slot = per_cu->v.quick->file_names; |
| 2840 | } |
| 2841 | } |
| 2842 | |
| 2843 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2844 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2845 | { |
| 2846 | int j; |
| 2847 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2848 | struct quick_file_names *file_data; |
| 2849 | void **slot; |
| 2850 | |
| 2851 | /* We only need to look at symtabs not already expanded. */ |
| 2852 | if (per_cu->v.quick->symtab) |
| 2853 | continue; |
| 2854 | |
| 2855 | file_data = dw2_get_file_names (objfile, per_cu); |
| 2856 | if (file_data == NULL) |
| 2857 | continue; |
| 2858 | |
| 2859 | slot = htab_find_slot (visited, file_data, INSERT); |
| 2860 | if (*slot) |
| 2861 | { |
| 2862 | /* Already visited. */ |
| 2863 | continue; |
| 2864 | } |
| 2865 | *slot = file_data; |
| 2866 | |
| 2867 | for (j = 0; j < file_data->num_file_names; ++j) |
| 2868 | { |
| 2869 | const char *this_real_name; |
| 2870 | |
| 2871 | if (need_fullname) |
| 2872 | this_real_name = dw2_get_real_path (objfile, file_data, j); |
| 2873 | else |
| 2874 | this_real_name = NULL; |
| 2875 | (*fun) (file_data->file_names[j], this_real_name, data); |
| 2876 | } |
| 2877 | } |
| 2878 | |
| 2879 | do_cleanups (cleanup); |
| 2880 | } |
| 2881 | |
| 2882 | static int |
| 2883 | dw2_has_symbols (struct objfile *objfile) |
| 2884 | { |
| 2885 | return 1; |
| 2886 | } |
| 2887 | |
| 2888 | const struct quick_symbol_functions dwarf2_gdb_index_functions = |
| 2889 | { |
| 2890 | dw2_has_symbols, |
| 2891 | dw2_find_last_source_symtab, |
| 2892 | dw2_forget_cached_source_info, |
| 2893 | dw2_map_symtabs_matching_filename, |
| 2894 | dw2_lookup_symbol, |
| 2895 | dw2_pre_expand_symtabs_matching, |
| 2896 | dw2_print_stats, |
| 2897 | dw2_dump, |
| 2898 | dw2_relocate, |
| 2899 | dw2_expand_symtabs_for_function, |
| 2900 | dw2_expand_all_symtabs, |
| 2901 | dw2_expand_symtabs_with_filename, |
| 2902 | dw2_find_symbol_file, |
| 2903 | dw2_map_matching_symbols, |
| 2904 | dw2_expand_symtabs_matching, |
| 2905 | dw2_find_pc_sect_symtab, |
| 2906 | dw2_map_symbol_filenames |
| 2907 | }; |
| 2908 | |
| 2909 | /* Initialize for reading DWARF for this objfile. Return 0 if this |
| 2910 | file will use psymtabs, or 1 if using the GNU index. */ |
| 2911 | |
| 2912 | int |
| 2913 | dwarf2_initialize_objfile (struct objfile *objfile) |
| 2914 | { |
| 2915 | /* If we're about to read full symbols, don't bother with the |
| 2916 | indices. In this case we also don't care if some other debug |
| 2917 | format is making psymtabs, because they are all about to be |
| 2918 | expanded anyway. */ |
| 2919 | if ((objfile->flags & OBJF_READNOW)) |
| 2920 | { |
| 2921 | int i; |
| 2922 | |
| 2923 | dwarf2_per_objfile->using_index = 1; |
| 2924 | create_all_comp_units (objfile); |
| 2925 | create_debug_types_hash_table (objfile); |
| 2926 | dwarf2_per_objfile->quick_file_names_table = |
| 2927 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); |
| 2928 | |
| 2929 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2930 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2931 | { |
| 2932 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2933 | |
| 2934 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 2935 | struct dwarf2_per_cu_quick_data); |
| 2936 | } |
| 2937 | |
| 2938 | /* Return 1 so that gdb sees the "quick" functions. However, |
| 2939 | these functions will be no-ops because we will have expanded |
| 2940 | all symtabs. */ |
| 2941 | return 1; |
| 2942 | } |
| 2943 | |
| 2944 | if (dwarf2_read_index (objfile)) |
| 2945 | return 1; |
| 2946 | |
| 2947 | return 0; |
| 2948 | } |
| 2949 | |
| 2950 | \f |
| 2951 | |
| 2952 | /* Build a partial symbol table. */ |
| 2953 | |
| 2954 | void |
| 2955 | dwarf2_build_psymtabs (struct objfile *objfile) |
| 2956 | { |
| 2957 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
| 2958 | { |
| 2959 | init_psymbol_list (objfile, 1024); |
| 2960 | } |
| 2961 | |
| 2962 | dwarf2_build_psymtabs_hard (objfile); |
| 2963 | } |
| 2964 | |
| 2965 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
| 2966 | |
| 2967 | static inline int |
| 2968 | offset_in_cu_p (const struct comp_unit_head *cu_header, unsigned int offset) |
| 2969 | { |
| 2970 | unsigned int bottom = cu_header->offset; |
| 2971 | unsigned int top = (cu_header->offset |
| 2972 | + cu_header->length |
| 2973 | + cu_header->initial_length_size); |
| 2974 | |
| 2975 | return (offset >= bottom && offset < top); |
| 2976 | } |
| 2977 | |
| 2978 | /* Read in the comp unit header information from the debug_info at info_ptr. |
| 2979 | NOTE: This leaves members offset, first_die_offset to be filled in |
| 2980 | by the caller. */ |
| 2981 | |
| 2982 | static gdb_byte * |
| 2983 | read_comp_unit_head (struct comp_unit_head *cu_header, |
| 2984 | gdb_byte *info_ptr, bfd *abfd) |
| 2985 | { |
| 2986 | int signed_addr; |
| 2987 | unsigned int bytes_read; |
| 2988 | |
| 2989 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); |
| 2990 | cu_header->initial_length_size = bytes_read; |
| 2991 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; |
| 2992 | info_ptr += bytes_read; |
| 2993 | cu_header->version = read_2_bytes (abfd, info_ptr); |
| 2994 | info_ptr += 2; |
| 2995 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
| 2996 | &bytes_read); |
| 2997 | info_ptr += bytes_read; |
| 2998 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
| 2999 | info_ptr += 1; |
| 3000 | signed_addr = bfd_get_sign_extend_vma (abfd); |
| 3001 | if (signed_addr < 0) |
| 3002 | internal_error (__FILE__, __LINE__, |
| 3003 | _("read_comp_unit_head: dwarf from non elf file")); |
| 3004 | cu_header->signed_addr_p = signed_addr; |
| 3005 | |
| 3006 | return info_ptr; |
| 3007 | } |
| 3008 | |
| 3009 | /* Subroutine of read_and_check_comp_unit_head and |
| 3010 | read_and_check_type_unit_head to simplify them. |
| 3011 | Perform various error checking on the header. */ |
| 3012 | |
| 3013 | static void |
| 3014 | error_check_comp_unit_head (struct comp_unit_head *header, |
| 3015 | struct dwarf2_section_info *section) |
| 3016 | { |
| 3017 | bfd *abfd = section->asection->owner; |
| 3018 | const char *filename = bfd_get_filename (abfd); |
| 3019 | |
| 3020 | if (header->version != 2 && header->version != 3 && header->version != 4) |
| 3021 | error (_("Dwarf Error: wrong version in compilation unit header " |
| 3022 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
| 3023 | filename); |
| 3024 | |
| 3025 | if (header->abbrev_offset |
| 3026 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, |
| 3027 | &dwarf2_per_objfile->abbrev)) |
| 3028 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
| 3029 | "(offset 0x%lx + 6) [in module %s]"), |
| 3030 | (long) header->abbrev_offset, (long) header->offset, |
| 3031 | filename); |
| 3032 | |
| 3033 | /* Cast to unsigned long to use 64-bit arithmetic when possible to |
| 3034 | avoid potential 32-bit overflow. */ |
| 3035 | if (((unsigned long) header->offset |
| 3036 | + header->length + header->initial_length_size) |
| 3037 | > section->size) |
| 3038 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
| 3039 | "(offset 0x%lx + 0) [in module %s]"), |
| 3040 | (long) header->length, (long) header->offset, |
| 3041 | filename); |
| 3042 | } |
| 3043 | |
| 3044 | /* Read in a CU/TU header and perform some basic error checking. |
| 3045 | The contents of the header are stored in HEADER. |
| 3046 | The result is a pointer to the start of the first DIE. */ |
| 3047 | |
| 3048 | static gdb_byte * |
| 3049 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
| 3050 | struct dwarf2_section_info *section, |
| 3051 | gdb_byte *info_ptr, |
| 3052 | int is_debug_types_section) |
| 3053 | { |
| 3054 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 3055 | bfd *abfd = section->asection->owner; |
| 3056 | |
| 3057 | header->offset = beg_of_comp_unit - section->buffer; |
| 3058 | |
| 3059 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
| 3060 | |
| 3061 | /* If we're reading a type unit, skip over the signature and |
| 3062 | type_offset fields. */ |
| 3063 | if (is_debug_types_section) |
| 3064 | info_ptr += 8 /*signature*/ + header->offset_size; |
| 3065 | |
| 3066 | header->first_die_offset = info_ptr - beg_of_comp_unit; |
| 3067 | |
| 3068 | error_check_comp_unit_head (header, section); |
| 3069 | |
| 3070 | return info_ptr; |
| 3071 | } |
| 3072 | |
| 3073 | /* Read in the types comp unit header information from .debug_types entry at |
| 3074 | types_ptr. The result is a pointer to one past the end of the header. */ |
| 3075 | |
| 3076 | static gdb_byte * |
| 3077 | read_and_check_type_unit_head (struct comp_unit_head *header, |
| 3078 | struct dwarf2_section_info *section, |
| 3079 | gdb_byte *info_ptr, |
| 3080 | ULONGEST *signature, unsigned int *type_offset) |
| 3081 | { |
| 3082 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 3083 | bfd *abfd = section->asection->owner; |
| 3084 | |
| 3085 | header->offset = beg_of_comp_unit - section->buffer; |
| 3086 | |
| 3087 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
| 3088 | |
| 3089 | /* If we're reading a type unit, skip over the signature and |
| 3090 | type_offset fields. */ |
| 3091 | if (signature != NULL) |
| 3092 | *signature = read_8_bytes (abfd, info_ptr); |
| 3093 | info_ptr += 8; |
| 3094 | if (type_offset != NULL) |
| 3095 | *type_offset = read_offset_1 (abfd, info_ptr, header->offset_size); |
| 3096 | info_ptr += header->offset_size; |
| 3097 | |
| 3098 | header->first_die_offset = info_ptr - beg_of_comp_unit; |
| 3099 | |
| 3100 | error_check_comp_unit_head (header, section); |
| 3101 | |
| 3102 | return info_ptr; |
| 3103 | } |
| 3104 | |
| 3105 | /* Allocate a new partial symtab for file named NAME and mark this new |
| 3106 | partial symtab as being an include of PST. */ |
| 3107 | |
| 3108 | static void |
| 3109 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, |
| 3110 | struct objfile *objfile) |
| 3111 | { |
| 3112 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); |
| 3113 | |
| 3114 | subpst->section_offsets = pst->section_offsets; |
| 3115 | subpst->textlow = 0; |
| 3116 | subpst->texthigh = 0; |
| 3117 | |
| 3118 | subpst->dependencies = (struct partial_symtab **) |
| 3119 | obstack_alloc (&objfile->objfile_obstack, |
| 3120 | sizeof (struct partial_symtab *)); |
| 3121 | subpst->dependencies[0] = pst; |
| 3122 | subpst->number_of_dependencies = 1; |
| 3123 | |
| 3124 | subpst->globals_offset = 0; |
| 3125 | subpst->n_global_syms = 0; |
| 3126 | subpst->statics_offset = 0; |
| 3127 | subpst->n_static_syms = 0; |
| 3128 | subpst->symtab = NULL; |
| 3129 | subpst->read_symtab = pst->read_symtab; |
| 3130 | subpst->readin = 0; |
| 3131 | |
| 3132 | /* No private part is necessary for include psymtabs. This property |
| 3133 | can be used to differentiate between such include psymtabs and |
| 3134 | the regular ones. */ |
| 3135 | subpst->read_symtab_private = NULL; |
| 3136 | } |
| 3137 | |
| 3138 | /* Read the Line Number Program data and extract the list of files |
| 3139 | included by the source file represented by PST. Build an include |
| 3140 | partial symtab for each of these included files. */ |
| 3141 | |
| 3142 | static void |
| 3143 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, |
| 3144 | struct die_info *die, |
| 3145 | struct partial_symtab *pst) |
| 3146 | { |
| 3147 | struct objfile *objfile = cu->objfile; |
| 3148 | bfd *abfd = objfile->obfd; |
| 3149 | struct line_header *lh = NULL; |
| 3150 | struct attribute *attr; |
| 3151 | |
| 3152 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 3153 | if (attr) |
| 3154 | { |
| 3155 | unsigned int line_offset = DW_UNSND (attr); |
| 3156 | |
| 3157 | lh = dwarf_decode_line_header (line_offset, abfd, cu); |
| 3158 | } |
| 3159 | if (lh == NULL) |
| 3160 | return; /* No linetable, so no includes. */ |
| 3161 | |
| 3162 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
| 3163 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
| 3164 | |
| 3165 | free_line_header (lh); |
| 3166 | } |
| 3167 | |
| 3168 | static hashval_t |
| 3169 | hash_type_signature (const void *item) |
| 3170 | { |
| 3171 | const struct signatured_type *type_sig = item; |
| 3172 | |
| 3173 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
| 3174 | return type_sig->signature; |
| 3175 | } |
| 3176 | |
| 3177 | static int |
| 3178 | eq_type_signature (const void *item_lhs, const void *item_rhs) |
| 3179 | { |
| 3180 | const struct signatured_type *lhs = item_lhs; |
| 3181 | const struct signatured_type *rhs = item_rhs; |
| 3182 | |
| 3183 | return lhs->signature == rhs->signature; |
| 3184 | } |
| 3185 | |
| 3186 | /* Allocate a hash table for signatured types. */ |
| 3187 | |
| 3188 | static htab_t |
| 3189 | allocate_signatured_type_table (struct objfile *objfile) |
| 3190 | { |
| 3191 | return htab_create_alloc_ex (41, |
| 3192 | hash_type_signature, |
| 3193 | eq_type_signature, |
| 3194 | NULL, |
| 3195 | &objfile->objfile_obstack, |
| 3196 | hashtab_obstack_allocate, |
| 3197 | dummy_obstack_deallocate); |
| 3198 | } |
| 3199 | |
| 3200 | /* A helper function to add a signatured type CU to a table. */ |
| 3201 | |
| 3202 | static int |
| 3203 | add_signatured_type_cu_to_table (void **slot, void *datum) |
| 3204 | { |
| 3205 | struct signatured_type *sigt = *slot; |
| 3206 | struct dwarf2_per_cu_data ***datap = datum; |
| 3207 | |
| 3208 | **datap = &sigt->per_cu; |
| 3209 | ++*datap; |
| 3210 | |
| 3211 | return 1; |
| 3212 | } |
| 3213 | |
| 3214 | /* Create the hash table of all entries in the .debug_types section(s). |
| 3215 | The result is zero if there is an error (e.g. missing .debug_types section), |
| 3216 | otherwise non-zero. */ |
| 3217 | |
| 3218 | static int |
| 3219 | create_debug_types_hash_table (struct objfile *objfile) |
| 3220 | { |
| 3221 | htab_t types_htab = NULL; |
| 3222 | struct dwarf2_per_cu_data **iter; |
| 3223 | int ix; |
| 3224 | struct dwarf2_section_info *section; |
| 3225 | |
| 3226 | if (VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types)) |
| 3227 | { |
| 3228 | dwarf2_per_objfile->signatured_types = NULL; |
| 3229 | return 0; |
| 3230 | } |
| 3231 | |
| 3232 | for (ix = 0; |
| 3233 | VEC_iterate (dwarf2_section_info_def, dwarf2_per_objfile->types, |
| 3234 | ix, section); |
| 3235 | ++ix) |
| 3236 | { |
| 3237 | gdb_byte *info_ptr, *end_ptr; |
| 3238 | |
| 3239 | dwarf2_read_section (objfile, section); |
| 3240 | info_ptr = section->buffer; |
| 3241 | |
| 3242 | if (info_ptr == NULL) |
| 3243 | continue; |
| 3244 | |
| 3245 | if (types_htab == NULL) |
| 3246 | types_htab = allocate_signatured_type_table (objfile); |
| 3247 | |
| 3248 | if (dwarf2_die_debug) |
| 3249 | fprintf_unfiltered (gdb_stdlog, "Signatured types:\n"); |
| 3250 | |
| 3251 | end_ptr = info_ptr + section->size; |
| 3252 | while (info_ptr < end_ptr) |
| 3253 | { |
| 3254 | unsigned int offset; |
| 3255 | unsigned int type_offset; |
| 3256 | ULONGEST signature; |
| 3257 | struct signatured_type *type_sig; |
| 3258 | void **slot; |
| 3259 | gdb_byte *ptr = info_ptr; |
| 3260 | struct comp_unit_head header; |
| 3261 | |
| 3262 | offset = ptr - section->buffer; |
| 3263 | |
| 3264 | /* We need to read the type's signature in order to build the hash |
| 3265 | table, but we don't need anything else just yet. */ |
| 3266 | |
| 3267 | ptr = read_and_check_type_unit_head (&header, section, ptr, |
| 3268 | &signature, &type_offset); |
| 3269 | |
| 3270 | /* Skip dummy type units. */ |
| 3271 | if (ptr >= end_ptr || peek_abbrev_code (objfile->obfd, ptr) == 0) |
| 3272 | { |
| 3273 | info_ptr = info_ptr + header.initial_length_size + header.length; |
| 3274 | continue; |
| 3275 | } |
| 3276 | |
| 3277 | type_sig = obstack_alloc (&objfile->objfile_obstack, sizeof (*type_sig)); |
| 3278 | memset (type_sig, 0, sizeof (*type_sig)); |
| 3279 | type_sig->signature = signature; |
| 3280 | type_sig->type_offset = type_offset; |
| 3281 | type_sig->per_cu.objfile = objfile; |
| 3282 | type_sig->per_cu.debug_types_section = section; |
| 3283 | type_sig->per_cu.offset = offset; |
| 3284 | |
| 3285 | slot = htab_find_slot (types_htab, type_sig, INSERT); |
| 3286 | gdb_assert (slot != NULL); |
| 3287 | if (*slot != NULL) |
| 3288 | { |
| 3289 | const struct signatured_type *dup_sig = *slot; |
| 3290 | |
| 3291 | complaint (&symfile_complaints, |
| 3292 | _("debug type entry at offset 0x%x is duplicate to the " |
| 3293 | "entry at offset 0x%x, signature 0x%s"), |
| 3294 | offset, dup_sig->per_cu.offset, |
| 3295 | phex (signature, sizeof (signature))); |
| 3296 | gdb_assert (signature == dup_sig->signature); |
| 3297 | } |
| 3298 | *slot = type_sig; |
| 3299 | |
| 3300 | if (dwarf2_die_debug) |
| 3301 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", |
| 3302 | offset, phex (signature, sizeof (signature))); |
| 3303 | |
| 3304 | info_ptr = info_ptr + header.initial_length_size + header.length; |
| 3305 | } |
| 3306 | } |
| 3307 | |
| 3308 | dwarf2_per_objfile->signatured_types = types_htab; |
| 3309 | |
| 3310 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
| 3311 | dwarf2_per_objfile->all_type_units |
| 3312 | = obstack_alloc (&objfile->objfile_obstack, |
| 3313 | dwarf2_per_objfile->n_type_units |
| 3314 | * sizeof (struct dwarf2_per_cu_data *)); |
| 3315 | iter = &dwarf2_per_objfile->all_type_units[0]; |
| 3316 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); |
| 3317 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] |
| 3318 | == dwarf2_per_objfile->n_type_units); |
| 3319 | |
| 3320 | return 1; |
| 3321 | } |
| 3322 | |
| 3323 | /* Lookup a signature based type. |
| 3324 | Returns NULL if SIG is not present in the table. */ |
| 3325 | |
| 3326 | static struct signatured_type * |
| 3327 | lookup_signatured_type (struct objfile *objfile, ULONGEST sig) |
| 3328 | { |
| 3329 | struct signatured_type find_entry, *entry; |
| 3330 | |
| 3331 | if (dwarf2_per_objfile->signatured_types == NULL) |
| 3332 | { |
| 3333 | complaint (&symfile_complaints, |
| 3334 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
| 3335 | return 0; |
| 3336 | } |
| 3337 | |
| 3338 | find_entry.signature = sig; |
| 3339 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
| 3340 | return entry; |
| 3341 | } |
| 3342 | |
| 3343 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
| 3344 | |
| 3345 | static void |
| 3346 | init_cu_die_reader (struct die_reader_specs *reader, |
| 3347 | struct dwarf2_cu *cu) |
| 3348 | { |
| 3349 | reader->abfd = cu->objfile->obfd; |
| 3350 | reader->cu = cu; |
| 3351 | if (cu->per_cu->debug_types_section) |
| 3352 | { |
| 3353 | gdb_assert (cu->per_cu->debug_types_section->readin); |
| 3354 | reader->buffer = cu->per_cu->debug_types_section->buffer; |
| 3355 | } |
| 3356 | else |
| 3357 | { |
| 3358 | gdb_assert (dwarf2_per_objfile->info.readin); |
| 3359 | reader->buffer = dwarf2_per_objfile->info.buffer; |
| 3360 | } |
| 3361 | } |
| 3362 | |
| 3363 | /* Find the base address of the compilation unit for range lists and |
| 3364 | location lists. It will normally be specified by DW_AT_low_pc. |
| 3365 | In DWARF-3 draft 4, the base address could be overridden by |
| 3366 | DW_AT_entry_pc. It's been removed, but GCC still uses this for |
| 3367 | compilation units with discontinuous ranges. */ |
| 3368 | |
| 3369 | static void |
| 3370 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) |
| 3371 | { |
| 3372 | struct attribute *attr; |
| 3373 | |
| 3374 | cu->base_known = 0; |
| 3375 | cu->base_address = 0; |
| 3376 | |
| 3377 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); |
| 3378 | if (attr) |
| 3379 | { |
| 3380 | cu->base_address = DW_ADDR (attr); |
| 3381 | cu->base_known = 1; |
| 3382 | } |
| 3383 | else |
| 3384 | { |
| 3385 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 3386 | if (attr) |
| 3387 | { |
| 3388 | cu->base_address = DW_ADDR (attr); |
| 3389 | cu->base_known = 1; |
| 3390 | } |
| 3391 | } |
| 3392 | } |
| 3393 | |
| 3394 | /* Subroutine of process_type_comp_unit and dwarf2_build_psymtabs_hard |
| 3395 | to combine the common parts. |
| 3396 | Process compilation unit THIS_CU for a psymtab. |
| 3397 | SECTION is the section the CU/TU comes from, |
| 3398 | either .debug_info or .debug_types. */ |
| 3399 | |
| 3400 | void |
| 3401 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
| 3402 | struct dwarf2_section_info *section, |
| 3403 | int is_debug_types_section) |
| 3404 | { |
| 3405 | struct objfile *objfile = this_cu->objfile; |
| 3406 | bfd *abfd = objfile->obfd; |
| 3407 | gdb_byte *buffer = section->buffer; |
| 3408 | gdb_byte *info_ptr = buffer + this_cu->offset; |
| 3409 | unsigned int buffer_size = section->size; |
| 3410 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 3411 | struct die_info *comp_unit_die; |
| 3412 | struct partial_symtab *pst; |
| 3413 | CORE_ADDR baseaddr; |
| 3414 | struct cleanup *back_to_inner; |
| 3415 | struct dwarf2_cu cu; |
| 3416 | int has_children, has_pc_info; |
| 3417 | struct attribute *attr; |
| 3418 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
| 3419 | struct die_reader_specs reader_specs; |
| 3420 | const char *filename; |
| 3421 | |
| 3422 | /* If this compilation unit was already read in, free the |
| 3423 | cached copy in order to read it in again. This is |
| 3424 | necessary because we skipped some symbols when we first |
| 3425 | read in the compilation unit (see load_partial_dies). |
| 3426 | This problem could be avoided, but the benefit is |
| 3427 | unclear. */ |
| 3428 | if (this_cu->cu != NULL) |
| 3429 | free_one_cached_comp_unit (this_cu->cu); |
| 3430 | |
| 3431 | /* Note that this is a pointer to our stack frame, being |
| 3432 | added to a global data structure. It will be cleaned up |
| 3433 | in free_stack_comp_unit when we finish with this |
| 3434 | compilation unit. */ |
| 3435 | init_one_comp_unit (&cu, this_cu); |
| 3436 | back_to_inner = make_cleanup (free_stack_comp_unit, &cu); |
| 3437 | |
| 3438 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, info_ptr, |
| 3439 | is_debug_types_section); |
| 3440 | |
| 3441 | /* Skip dummy compilation units. */ |
| 3442 | if (info_ptr >= buffer + buffer_size |
| 3443 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 3444 | { |
| 3445 | do_cleanups (back_to_inner); |
| 3446 | return; |
| 3447 | } |
| 3448 | |
| 3449 | cu.list_in_scope = &file_symbols; |
| 3450 | |
| 3451 | /* Read the abbrevs for this compilation unit into a table. */ |
| 3452 | dwarf2_read_abbrevs (&cu); |
| 3453 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
| 3454 | |
| 3455 | /* Read the compilation unit die. */ |
| 3456 | init_cu_die_reader (&reader_specs, &cu); |
| 3457 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
| 3458 | &has_children); |
| 3459 | |
| 3460 | if (is_debug_types_section) |
| 3461 | { |
| 3462 | /* LENGTH has not been set yet for type units. */ |
| 3463 | gdb_assert (this_cu->offset == cu.header.offset); |
| 3464 | this_cu->length = cu.header.length + cu.header.initial_length_size; |
| 3465 | } |
| 3466 | else if (comp_unit_die->tag == DW_TAG_partial_unit) |
| 3467 | { |
| 3468 | do_cleanups (back_to_inner); |
| 3469 | return; |
| 3470 | } |
| 3471 | |
| 3472 | prepare_one_comp_unit (&cu, comp_unit_die); |
| 3473 | |
| 3474 | /* Allocate a new partial symbol table structure. */ |
| 3475 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, &cu); |
| 3476 | if (attr == NULL || !DW_STRING (attr)) |
| 3477 | filename = ""; |
| 3478 | else |
| 3479 | filename = DW_STRING (attr); |
| 3480 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
| 3481 | filename, |
| 3482 | /* TEXTLOW and TEXTHIGH are set below. */ |
| 3483 | 0, |
| 3484 | objfile->global_psymbols.next, |
| 3485 | objfile->static_psymbols.next); |
| 3486 | pst->psymtabs_addrmap_supported = 1; |
| 3487 | |
| 3488 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, &cu); |
| 3489 | if (attr != NULL) |
| 3490 | pst->dirname = DW_STRING (attr); |
| 3491 | |
| 3492 | pst->read_symtab_private = this_cu; |
| 3493 | |
| 3494 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 3495 | |
| 3496 | /* Store the function that reads in the rest of the symbol table. */ |
| 3497 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
| 3498 | |
| 3499 | this_cu->v.psymtab = pst; |
| 3500 | |
| 3501 | dwarf2_find_base_address (comp_unit_die, &cu); |
| 3502 | |
| 3503 | /* Possibly set the default values of LOWPC and HIGHPC from |
| 3504 | `DW_AT_ranges'. */ |
| 3505 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
| 3506 | &best_highpc, &cu, pst); |
| 3507 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
| 3508 | /* Store the contiguous range if it is not empty; it can be empty for |
| 3509 | CUs with no code. */ |
| 3510 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 3511 | best_lowpc + baseaddr, |
| 3512 | best_highpc + baseaddr - 1, pst); |
| 3513 | |
| 3514 | /* Check if comp unit has_children. |
| 3515 | If so, read the rest of the partial symbols from this comp unit. |
| 3516 | If not, there's no more debug_info for this comp unit. */ |
| 3517 | if (has_children) |
| 3518 | { |
| 3519 | struct partial_die_info *first_die; |
| 3520 | CORE_ADDR lowpc, highpc; |
| 3521 | |
| 3522 | lowpc = ((CORE_ADDR) -1); |
| 3523 | highpc = ((CORE_ADDR) 0); |
| 3524 | |
| 3525 | first_die = load_partial_dies (abfd, buffer, info_ptr, 1, &cu); |
| 3526 | |
| 3527 | scan_partial_symbols (first_die, &lowpc, &highpc, |
| 3528 | ! has_pc_info, &cu); |
| 3529 | |
| 3530 | /* If we didn't find a lowpc, set it to highpc to avoid |
| 3531 | complaints from `maint check'. */ |
| 3532 | if (lowpc == ((CORE_ADDR) -1)) |
| 3533 | lowpc = highpc; |
| 3534 | |
| 3535 | /* If the compilation unit didn't have an explicit address range, |
| 3536 | then use the information extracted from its child dies. */ |
| 3537 | if (! has_pc_info) |
| 3538 | { |
| 3539 | best_lowpc = lowpc; |
| 3540 | best_highpc = highpc; |
| 3541 | } |
| 3542 | } |
| 3543 | pst->textlow = best_lowpc + baseaddr; |
| 3544 | pst->texthigh = best_highpc + baseaddr; |
| 3545 | |
| 3546 | pst->n_global_syms = objfile->global_psymbols.next - |
| 3547 | (objfile->global_psymbols.list + pst->globals_offset); |
| 3548 | pst->n_static_syms = objfile->static_psymbols.next - |
| 3549 | (objfile->static_psymbols.list + pst->statics_offset); |
| 3550 | sort_pst_symbols (pst); |
| 3551 | |
| 3552 | if (is_debug_types_section) |
| 3553 | { |
| 3554 | /* It's not clear we want to do anything with stmt lists here. |
| 3555 | Waiting to see what gcc ultimately does. */ |
| 3556 | } |
| 3557 | else |
| 3558 | { |
| 3559 | /* Get the list of files included in the current compilation unit, |
| 3560 | and build a psymtab for each of them. */ |
| 3561 | dwarf2_build_include_psymtabs (&cu, comp_unit_die, pst); |
| 3562 | } |
| 3563 | |
| 3564 | do_cleanups (back_to_inner); |
| 3565 | } |
| 3566 | |
| 3567 | /* Traversal function for htab_traverse_noresize. |
| 3568 | Process one .debug_types comp-unit. */ |
| 3569 | |
| 3570 | static int |
| 3571 | process_type_comp_unit (void **slot, void *info) |
| 3572 | { |
| 3573 | struct signatured_type *entry = (struct signatured_type *) *slot; |
| 3574 | struct dwarf2_per_cu_data *this_cu; |
| 3575 | |
| 3576 | gdb_assert (info == NULL); |
| 3577 | this_cu = &entry->per_cu; |
| 3578 | |
| 3579 | gdb_assert (this_cu->debug_types_section->readin); |
| 3580 | process_psymtab_comp_unit (this_cu, this_cu->debug_types_section, 1); |
| 3581 | |
| 3582 | return 1; |
| 3583 | } |
| 3584 | |
| 3585 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
| 3586 | Build partial symbol tables for the .debug_types comp-units. */ |
| 3587 | |
| 3588 | static void |
| 3589 | build_type_psymtabs (struct objfile *objfile) |
| 3590 | { |
| 3591 | if (! create_debug_types_hash_table (objfile)) |
| 3592 | return; |
| 3593 | |
| 3594 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, |
| 3595 | process_type_comp_unit, NULL); |
| 3596 | } |
| 3597 | |
| 3598 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
| 3599 | |
| 3600 | static void |
| 3601 | psymtabs_addrmap_cleanup (void *o) |
| 3602 | { |
| 3603 | struct objfile *objfile = o; |
| 3604 | |
| 3605 | objfile->psymtabs_addrmap = NULL; |
| 3606 | } |
| 3607 | |
| 3608 | /* Build the partial symbol table by doing a quick pass through the |
| 3609 | .debug_info and .debug_abbrev sections. */ |
| 3610 | |
| 3611 | static void |
| 3612 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
| 3613 | { |
| 3614 | struct cleanup *back_to, *addrmap_cleanup; |
| 3615 | struct obstack temp_obstack; |
| 3616 | int i; |
| 3617 | |
| 3618 | dwarf2_per_objfile->reading_partial_symbols = 1; |
| 3619 | |
| 3620 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 3621 | |
| 3622 | /* Any cached compilation units will be linked by the per-objfile |
| 3623 | read_in_chain. Make sure to free them when we're done. */ |
| 3624 | back_to = make_cleanup (free_cached_comp_units, NULL); |
| 3625 | |
| 3626 | build_type_psymtabs (objfile); |
| 3627 | |
| 3628 | create_all_comp_units (objfile); |
| 3629 | |
| 3630 | /* Create a temporary address map on a temporary obstack. We later |
| 3631 | copy this to the final obstack. */ |
| 3632 | obstack_init (&temp_obstack); |
| 3633 | make_cleanup_obstack_free (&temp_obstack); |
| 3634 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); |
| 3635 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); |
| 3636 | |
| 3637 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 3638 | { |
| 3639 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 3640 | |
| 3641 | process_psymtab_comp_unit (per_cu, &dwarf2_per_objfile->info, 0); |
| 3642 | } |
| 3643 | |
| 3644 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, |
| 3645 | &objfile->objfile_obstack); |
| 3646 | discard_cleanups (addrmap_cleanup); |
| 3647 | |
| 3648 | do_cleanups (back_to); |
| 3649 | } |
| 3650 | |
| 3651 | /* Load the partial DIEs for a secondary CU into memory. */ |
| 3652 | |
| 3653 | static void |
| 3654 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) |
| 3655 | { |
| 3656 | struct objfile *objfile = this_cu->objfile; |
| 3657 | bfd *abfd = objfile->obfd; |
| 3658 | gdb_byte *info_ptr; |
| 3659 | struct die_info *comp_unit_die; |
| 3660 | struct dwarf2_cu *cu; |
| 3661 | struct cleanup *free_abbrevs_cleanup, *free_cu_cleanup = NULL; |
| 3662 | int has_children; |
| 3663 | struct die_reader_specs reader_specs; |
| 3664 | int read_cu = 0; |
| 3665 | struct dwarf2_section_info *section = &dwarf2_per_objfile->info; |
| 3666 | |
| 3667 | gdb_assert (! this_cu->debug_types_section); |
| 3668 | |
| 3669 | gdb_assert (section->readin); |
| 3670 | info_ptr = section->buffer + this_cu->offset; |
| 3671 | |
| 3672 | if (this_cu->cu == NULL) |
| 3673 | { |
| 3674 | cu = xmalloc (sizeof (*cu)); |
| 3675 | init_one_comp_unit (cu, this_cu); |
| 3676 | |
| 3677 | read_cu = 1; |
| 3678 | |
| 3679 | /* If an error occurs while loading, release our storage. */ |
| 3680 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
| 3681 | |
| 3682 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, info_ptr, |
| 3683 | 0); |
| 3684 | |
| 3685 | /* Skip dummy compilation units. */ |
| 3686 | if (info_ptr >= (section->buffer + section->size) |
| 3687 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 3688 | { |
| 3689 | do_cleanups (free_cu_cleanup); |
| 3690 | return; |
| 3691 | } |
| 3692 | |
| 3693 | /* Link this CU into read_in_chain. */ |
| 3694 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 3695 | dwarf2_per_objfile->read_in_chain = this_cu; |
| 3696 | } |
| 3697 | else |
| 3698 | { |
| 3699 | cu = this_cu->cu; |
| 3700 | info_ptr += cu->header.first_die_offset; |
| 3701 | } |
| 3702 | |
| 3703 | /* Read the abbrevs for this compilation unit into a table. */ |
| 3704 | gdb_assert (cu->dwarf2_abbrevs == NULL); |
| 3705 | dwarf2_read_abbrevs (cu); |
| 3706 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 3707 | |
| 3708 | /* Read the compilation unit die. */ |
| 3709 | init_cu_die_reader (&reader_specs, cu); |
| 3710 | info_ptr = read_full_die (&reader_specs, &comp_unit_die, info_ptr, |
| 3711 | &has_children); |
| 3712 | |
| 3713 | prepare_one_comp_unit (cu, comp_unit_die); |
| 3714 | |
| 3715 | /* Check if comp unit has_children. |
| 3716 | If so, read the rest of the partial symbols from this comp unit. |
| 3717 | If not, there's no more debug_info for this comp unit. */ |
| 3718 | if (has_children) |
| 3719 | load_partial_dies (abfd, section->buffer, info_ptr, 0, cu); |
| 3720 | |
| 3721 | do_cleanups (free_abbrevs_cleanup); |
| 3722 | |
| 3723 | if (read_cu) |
| 3724 | { |
| 3725 | /* We've successfully allocated this compilation unit. Let our |
| 3726 | caller clean it up when finished with it. */ |
| 3727 | discard_cleanups (free_cu_cleanup); |
| 3728 | } |
| 3729 | } |
| 3730 | |
| 3731 | /* Create a list of all compilation units in OBJFILE. |
| 3732 | This is only done for -readnow and building partial symtabs. */ |
| 3733 | |
| 3734 | static void |
| 3735 | create_all_comp_units (struct objfile *objfile) |
| 3736 | { |
| 3737 | int n_allocated; |
| 3738 | int n_comp_units; |
| 3739 | struct dwarf2_per_cu_data **all_comp_units; |
| 3740 | gdb_byte *info_ptr; |
| 3741 | |
| 3742 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 3743 | info_ptr = dwarf2_per_objfile->info.buffer; |
| 3744 | |
| 3745 | n_comp_units = 0; |
| 3746 | n_allocated = 10; |
| 3747 | all_comp_units = xmalloc (n_allocated |
| 3748 | * sizeof (struct dwarf2_per_cu_data *)); |
| 3749 | |
| 3750 | while (info_ptr < dwarf2_per_objfile->info.buffer |
| 3751 | + dwarf2_per_objfile->info.size) |
| 3752 | { |
| 3753 | unsigned int length, initial_length_size; |
| 3754 | struct dwarf2_per_cu_data *this_cu; |
| 3755 | unsigned int offset; |
| 3756 | |
| 3757 | offset = info_ptr - dwarf2_per_objfile->info.buffer; |
| 3758 | |
| 3759 | /* Read just enough information to find out where the next |
| 3760 | compilation unit is. */ |
| 3761 | length = read_initial_length (objfile->obfd, info_ptr, |
| 3762 | &initial_length_size); |
| 3763 | |
| 3764 | /* Save the compilation unit for later lookup. */ |
| 3765 | this_cu = obstack_alloc (&objfile->objfile_obstack, |
| 3766 | sizeof (struct dwarf2_per_cu_data)); |
| 3767 | memset (this_cu, 0, sizeof (*this_cu)); |
| 3768 | this_cu->offset = offset; |
| 3769 | this_cu->length = length + initial_length_size; |
| 3770 | this_cu->objfile = objfile; |
| 3771 | |
| 3772 | if (n_comp_units == n_allocated) |
| 3773 | { |
| 3774 | n_allocated *= 2; |
| 3775 | all_comp_units = xrealloc (all_comp_units, |
| 3776 | n_allocated |
| 3777 | * sizeof (struct dwarf2_per_cu_data *)); |
| 3778 | } |
| 3779 | all_comp_units[n_comp_units++] = this_cu; |
| 3780 | |
| 3781 | info_ptr = info_ptr + this_cu->length; |
| 3782 | } |
| 3783 | |
| 3784 | dwarf2_per_objfile->all_comp_units |
| 3785 | = obstack_alloc (&objfile->objfile_obstack, |
| 3786 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); |
| 3787 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, |
| 3788 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); |
| 3789 | xfree (all_comp_units); |
| 3790 | dwarf2_per_objfile->n_comp_units = n_comp_units; |
| 3791 | } |
| 3792 | |
| 3793 | /* Process all loaded DIEs for compilation unit CU, starting at |
| 3794 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation |
| 3795 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or |
| 3796 | DW_AT_ranges). If NEED_PC is set, then this function will set |
| 3797 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU |
| 3798 | and record the covered ranges in the addrmap. */ |
| 3799 | |
| 3800 | static void |
| 3801 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, |
| 3802 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
| 3803 | { |
| 3804 | struct partial_die_info *pdi; |
| 3805 | |
| 3806 | /* Now, march along the PDI's, descending into ones which have |
| 3807 | interesting children but skipping the children of the other ones, |
| 3808 | until we reach the end of the compilation unit. */ |
| 3809 | |
| 3810 | pdi = first_die; |
| 3811 | |
| 3812 | while (pdi != NULL) |
| 3813 | { |
| 3814 | fixup_partial_die (pdi, cu); |
| 3815 | |
| 3816 | /* Anonymous namespaces or modules have no name but have interesting |
| 3817 | children, so we need to look at them. Ditto for anonymous |
| 3818 | enums. */ |
| 3819 | |
| 3820 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
| 3821 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type) |
| 3822 | { |
| 3823 | switch (pdi->tag) |
| 3824 | { |
| 3825 | case DW_TAG_subprogram: |
| 3826 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
| 3827 | break; |
| 3828 | case DW_TAG_constant: |
| 3829 | case DW_TAG_variable: |
| 3830 | case DW_TAG_typedef: |
| 3831 | case DW_TAG_union_type: |
| 3832 | if (!pdi->is_declaration) |
| 3833 | { |
| 3834 | add_partial_symbol (pdi, cu); |
| 3835 | } |
| 3836 | break; |
| 3837 | case DW_TAG_class_type: |
| 3838 | case DW_TAG_interface_type: |
| 3839 | case DW_TAG_structure_type: |
| 3840 | if (!pdi->is_declaration) |
| 3841 | { |
| 3842 | add_partial_symbol (pdi, cu); |
| 3843 | } |
| 3844 | break; |
| 3845 | case DW_TAG_enumeration_type: |
| 3846 | if (!pdi->is_declaration) |
| 3847 | add_partial_enumeration (pdi, cu); |
| 3848 | break; |
| 3849 | case DW_TAG_base_type: |
| 3850 | case DW_TAG_subrange_type: |
| 3851 | /* File scope base type definitions are added to the partial |
| 3852 | symbol table. */ |
| 3853 | add_partial_symbol (pdi, cu); |
| 3854 | break; |
| 3855 | case DW_TAG_namespace: |
| 3856 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
| 3857 | break; |
| 3858 | case DW_TAG_module: |
| 3859 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); |
| 3860 | break; |
| 3861 | default: |
| 3862 | break; |
| 3863 | } |
| 3864 | } |
| 3865 | |
| 3866 | /* If the die has a sibling, skip to the sibling. */ |
| 3867 | |
| 3868 | pdi = pdi->die_sibling; |
| 3869 | } |
| 3870 | } |
| 3871 | |
| 3872 | /* Functions used to compute the fully scoped name of a partial DIE. |
| 3873 | |
| 3874 | Normally, this is simple. For C++, the parent DIE's fully scoped |
| 3875 | name is concatenated with "::" and the partial DIE's name. For |
| 3876 | Java, the same thing occurs except that "." is used instead of "::". |
| 3877 | Enumerators are an exception; they use the scope of their parent |
| 3878 | enumeration type, i.e. the name of the enumeration type is not |
| 3879 | prepended to the enumerator. |
| 3880 | |
| 3881 | There are two complexities. One is DW_AT_specification; in this |
| 3882 | case "parent" means the parent of the target of the specification, |
| 3883 | instead of the direct parent of the DIE. The other is compilers |
| 3884 | which do not emit DW_TAG_namespace; in this case we try to guess |
| 3885 | the fully qualified name of structure types from their members' |
| 3886 | linkage names. This must be done using the DIE's children rather |
| 3887 | than the children of any DW_AT_specification target. We only need |
| 3888 | to do this for structures at the top level, i.e. if the target of |
| 3889 | any DW_AT_specification (if any; otherwise the DIE itself) does not |
| 3890 | have a parent. */ |
| 3891 | |
| 3892 | /* Compute the scope prefix associated with PDI's parent, in |
| 3893 | compilation unit CU. The result will be allocated on CU's |
| 3894 | comp_unit_obstack, or a copy of the already allocated PDI->NAME |
| 3895 | field. NULL is returned if no prefix is necessary. */ |
| 3896 | static char * |
| 3897 | partial_die_parent_scope (struct partial_die_info *pdi, |
| 3898 | struct dwarf2_cu *cu) |
| 3899 | { |
| 3900 | char *grandparent_scope; |
| 3901 | struct partial_die_info *parent, *real_pdi; |
| 3902 | |
| 3903 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
| 3904 | then this means the parent of the specification DIE. */ |
| 3905 | |
| 3906 | real_pdi = pdi; |
| 3907 | while (real_pdi->has_specification) |
| 3908 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
| 3909 | |
| 3910 | parent = real_pdi->die_parent; |
| 3911 | if (parent == NULL) |
| 3912 | return NULL; |
| 3913 | |
| 3914 | if (parent->scope_set) |
| 3915 | return parent->scope; |
| 3916 | |
| 3917 | fixup_partial_die (parent, cu); |
| 3918 | |
| 3919 | grandparent_scope = partial_die_parent_scope (parent, cu); |
| 3920 | |
| 3921 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
| 3922 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. |
| 3923 | Work around this problem here. */ |
| 3924 | if (cu->language == language_cplus |
| 3925 | && parent->tag == DW_TAG_namespace |
| 3926 | && strcmp (parent->name, "::") == 0 |
| 3927 | && grandparent_scope == NULL) |
| 3928 | { |
| 3929 | parent->scope = NULL; |
| 3930 | parent->scope_set = 1; |
| 3931 | return NULL; |
| 3932 | } |
| 3933 | |
| 3934 | if (pdi->tag == DW_TAG_enumerator) |
| 3935 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
| 3936 | parent->scope = grandparent_scope; |
| 3937 | else if (parent->tag == DW_TAG_namespace |
| 3938 | || parent->tag == DW_TAG_module |
| 3939 | || parent->tag == DW_TAG_structure_type |
| 3940 | || parent->tag == DW_TAG_class_type |
| 3941 | || parent->tag == DW_TAG_interface_type |
| 3942 | || parent->tag == DW_TAG_union_type |
| 3943 | || parent->tag == DW_TAG_enumeration_type) |
| 3944 | { |
| 3945 | if (grandparent_scope == NULL) |
| 3946 | parent->scope = parent->name; |
| 3947 | else |
| 3948 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
| 3949 | grandparent_scope, |
| 3950 | parent->name, 0, cu); |
| 3951 | } |
| 3952 | else |
| 3953 | { |
| 3954 | /* FIXME drow/2004-04-01: What should we be doing with |
| 3955 | function-local names? For partial symbols, we should probably be |
| 3956 | ignoring them. */ |
| 3957 | complaint (&symfile_complaints, |
| 3958 | _("unhandled containing DIE tag %d for DIE at %d"), |
| 3959 | parent->tag, pdi->offset); |
| 3960 | parent->scope = grandparent_scope; |
| 3961 | } |
| 3962 | |
| 3963 | parent->scope_set = 1; |
| 3964 | return parent->scope; |
| 3965 | } |
| 3966 | |
| 3967 | /* Return the fully scoped name associated with PDI, from compilation unit |
| 3968 | CU. The result will be allocated with malloc. */ |
| 3969 | static char * |
| 3970 | partial_die_full_name (struct partial_die_info *pdi, |
| 3971 | struct dwarf2_cu *cu) |
| 3972 | { |
| 3973 | char *parent_scope; |
| 3974 | |
| 3975 | /* If this is a template instantiation, we can not work out the |
| 3976 | template arguments from partial DIEs. So, unfortunately, we have |
| 3977 | to go through the full DIEs. At least any work we do building |
| 3978 | types here will be reused if full symbols are loaded later. */ |
| 3979 | if (pdi->has_template_arguments) |
| 3980 | { |
| 3981 | fixup_partial_die (pdi, cu); |
| 3982 | |
| 3983 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) |
| 3984 | { |
| 3985 | struct die_info *die; |
| 3986 | struct attribute attr; |
| 3987 | struct dwarf2_cu *ref_cu = cu; |
| 3988 | |
| 3989 | attr.name = 0; |
| 3990 | attr.form = DW_FORM_ref_addr; |
| 3991 | attr.u.addr = pdi->offset; |
| 3992 | die = follow_die_ref (NULL, &attr, &ref_cu); |
| 3993 | |
| 3994 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); |
| 3995 | } |
| 3996 | } |
| 3997 | |
| 3998 | parent_scope = partial_die_parent_scope (pdi, cu); |
| 3999 | if (parent_scope == NULL) |
| 4000 | return NULL; |
| 4001 | else |
| 4002 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
| 4003 | } |
| 4004 | |
| 4005 | static void |
| 4006 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
| 4007 | { |
| 4008 | struct objfile *objfile = cu->objfile; |
| 4009 | CORE_ADDR addr = 0; |
| 4010 | char *actual_name = NULL; |
| 4011 | CORE_ADDR baseaddr; |
| 4012 | int built_actual_name = 0; |
| 4013 | |
| 4014 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 4015 | |
| 4016 | actual_name = partial_die_full_name (pdi, cu); |
| 4017 | if (actual_name) |
| 4018 | built_actual_name = 1; |
| 4019 | |
| 4020 | if (actual_name == NULL) |
| 4021 | actual_name = pdi->name; |
| 4022 | |
| 4023 | switch (pdi->tag) |
| 4024 | { |
| 4025 | case DW_TAG_subprogram: |
| 4026 | if (pdi->is_external || cu->language == language_ada) |
| 4027 | { |
| 4028 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
| 4029 | of the global scope. But in Ada, we want to be able to access |
| 4030 | nested procedures globally. So all Ada subprograms are stored |
| 4031 | in the global scope. */ |
| 4032 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
| 4033 | mst_text, objfile); */ |
| 4034 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4035 | built_actual_name, |
| 4036 | VAR_DOMAIN, LOC_BLOCK, |
| 4037 | &objfile->global_psymbols, |
| 4038 | 0, pdi->lowpc + baseaddr, |
| 4039 | cu->language, objfile); |
| 4040 | } |
| 4041 | else |
| 4042 | { |
| 4043 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
| 4044 | mst_file_text, objfile); */ |
| 4045 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4046 | built_actual_name, |
| 4047 | VAR_DOMAIN, LOC_BLOCK, |
| 4048 | &objfile->static_psymbols, |
| 4049 | 0, pdi->lowpc + baseaddr, |
| 4050 | cu->language, objfile); |
| 4051 | } |
| 4052 | break; |
| 4053 | case DW_TAG_constant: |
| 4054 | { |
| 4055 | struct psymbol_allocation_list *list; |
| 4056 | |
| 4057 | if (pdi->is_external) |
| 4058 | list = &objfile->global_psymbols; |
| 4059 | else |
| 4060 | list = &objfile->static_psymbols; |
| 4061 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4062 | built_actual_name, VAR_DOMAIN, LOC_STATIC, |
| 4063 | list, 0, 0, cu->language, objfile); |
| 4064 | } |
| 4065 | break; |
| 4066 | case DW_TAG_variable: |
| 4067 | if (pdi->locdesc) |
| 4068 | addr = decode_locdesc (pdi->locdesc, cu); |
| 4069 | |
| 4070 | if (pdi->locdesc |
| 4071 | && addr == 0 |
| 4072 | && !dwarf2_per_objfile->has_section_at_zero) |
| 4073 | { |
| 4074 | /* A global or static variable may also have been stripped |
| 4075 | out by the linker if unused, in which case its address |
| 4076 | will be nullified; do not add such variables into partial |
| 4077 | symbol table then. */ |
| 4078 | } |
| 4079 | else if (pdi->is_external) |
| 4080 | { |
| 4081 | /* Global Variable. |
| 4082 | Don't enter into the minimal symbol tables as there is |
| 4083 | a minimal symbol table entry from the ELF symbols already. |
| 4084 | Enter into partial symbol table if it has a location |
| 4085 | descriptor or a type. |
| 4086 | If the location descriptor is missing, new_symbol will create |
| 4087 | a LOC_UNRESOLVED symbol, the address of the variable will then |
| 4088 | be determined from the minimal symbol table whenever the variable |
| 4089 | is referenced. |
| 4090 | The address for the partial symbol table entry is not |
| 4091 | used by GDB, but it comes in handy for debugging partial symbol |
| 4092 | table building. */ |
| 4093 | |
| 4094 | if (pdi->locdesc || pdi->has_type) |
| 4095 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4096 | built_actual_name, |
| 4097 | VAR_DOMAIN, LOC_STATIC, |
| 4098 | &objfile->global_psymbols, |
| 4099 | 0, addr + baseaddr, |
| 4100 | cu->language, objfile); |
| 4101 | } |
| 4102 | else |
| 4103 | { |
| 4104 | /* Static Variable. Skip symbols without location descriptors. */ |
| 4105 | if (pdi->locdesc == NULL) |
| 4106 | { |
| 4107 | if (built_actual_name) |
| 4108 | xfree (actual_name); |
| 4109 | return; |
| 4110 | } |
| 4111 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
| 4112 | mst_file_data, objfile); */ |
| 4113 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4114 | built_actual_name, |
| 4115 | VAR_DOMAIN, LOC_STATIC, |
| 4116 | &objfile->static_psymbols, |
| 4117 | 0, addr + baseaddr, |
| 4118 | cu->language, objfile); |
| 4119 | } |
| 4120 | break; |
| 4121 | case DW_TAG_typedef: |
| 4122 | case DW_TAG_base_type: |
| 4123 | case DW_TAG_subrange_type: |
| 4124 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4125 | built_actual_name, |
| 4126 | VAR_DOMAIN, LOC_TYPEDEF, |
| 4127 | &objfile->static_psymbols, |
| 4128 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 4129 | break; |
| 4130 | case DW_TAG_namespace: |
| 4131 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4132 | built_actual_name, |
| 4133 | VAR_DOMAIN, LOC_TYPEDEF, |
| 4134 | &objfile->global_psymbols, |
| 4135 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 4136 | break; |
| 4137 | case DW_TAG_class_type: |
| 4138 | case DW_TAG_interface_type: |
| 4139 | case DW_TAG_structure_type: |
| 4140 | case DW_TAG_union_type: |
| 4141 | case DW_TAG_enumeration_type: |
| 4142 | /* Skip external references. The DWARF standard says in the section |
| 4143 | about "Structure, Union, and Class Type Entries": "An incomplete |
| 4144 | structure, union or class type is represented by a structure, |
| 4145 | union or class entry that does not have a byte size attribute |
| 4146 | and that has a DW_AT_declaration attribute." */ |
| 4147 | if (!pdi->has_byte_size && pdi->is_declaration) |
| 4148 | { |
| 4149 | if (built_actual_name) |
| 4150 | xfree (actual_name); |
| 4151 | return; |
| 4152 | } |
| 4153 | |
| 4154 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
| 4155 | static vs. global. */ |
| 4156 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4157 | built_actual_name, |
| 4158 | STRUCT_DOMAIN, LOC_TYPEDEF, |
| 4159 | (cu->language == language_cplus |
| 4160 | || cu->language == language_java) |
| 4161 | ? &objfile->global_psymbols |
| 4162 | : &objfile->static_psymbols, |
| 4163 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 4164 | |
| 4165 | break; |
| 4166 | case DW_TAG_enumerator: |
| 4167 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 4168 | built_actual_name, |
| 4169 | VAR_DOMAIN, LOC_CONST, |
| 4170 | (cu->language == language_cplus |
| 4171 | || cu->language == language_java) |
| 4172 | ? &objfile->global_psymbols |
| 4173 | : &objfile->static_psymbols, |
| 4174 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 4175 | break; |
| 4176 | default: |
| 4177 | break; |
| 4178 | } |
| 4179 | |
| 4180 | if (built_actual_name) |
| 4181 | xfree (actual_name); |
| 4182 | } |
| 4183 | |
| 4184 | /* Read a partial die corresponding to a namespace; also, add a symbol |
| 4185 | corresponding to that namespace to the symbol table. NAMESPACE is |
| 4186 | the name of the enclosing namespace. */ |
| 4187 | |
| 4188 | static void |
| 4189 | add_partial_namespace (struct partial_die_info *pdi, |
| 4190 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 4191 | int need_pc, struct dwarf2_cu *cu) |
| 4192 | { |
| 4193 | /* Add a symbol for the namespace. */ |
| 4194 | |
| 4195 | add_partial_symbol (pdi, cu); |
| 4196 | |
| 4197 | /* Now scan partial symbols in that namespace. */ |
| 4198 | |
| 4199 | if (pdi->has_children) |
| 4200 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
| 4201 | } |
| 4202 | |
| 4203 | /* Read a partial die corresponding to a Fortran module. */ |
| 4204 | |
| 4205 | static void |
| 4206 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
| 4207 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
| 4208 | { |
| 4209 | /* Now scan partial symbols in that module. */ |
| 4210 | |
| 4211 | if (pdi->has_children) |
| 4212 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
| 4213 | } |
| 4214 | |
| 4215 | /* Read a partial die corresponding to a subprogram and create a partial |
| 4216 | symbol for that subprogram. When the CU language allows it, this |
| 4217 | routine also defines a partial symbol for each nested subprogram |
| 4218 | that this subprogram contains. |
| 4219 | |
| 4220 | DIE my also be a lexical block, in which case we simply search |
| 4221 | recursively for suprograms defined inside that lexical block. |
| 4222 | Again, this is only performed when the CU language allows this |
| 4223 | type of definitions. */ |
| 4224 | |
| 4225 | static void |
| 4226 | add_partial_subprogram (struct partial_die_info *pdi, |
| 4227 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 4228 | int need_pc, struct dwarf2_cu *cu) |
| 4229 | { |
| 4230 | if (pdi->tag == DW_TAG_subprogram) |
| 4231 | { |
| 4232 | if (pdi->has_pc_info) |
| 4233 | { |
| 4234 | if (pdi->lowpc < *lowpc) |
| 4235 | *lowpc = pdi->lowpc; |
| 4236 | if (pdi->highpc > *highpc) |
| 4237 | *highpc = pdi->highpc; |
| 4238 | if (need_pc) |
| 4239 | { |
| 4240 | CORE_ADDR baseaddr; |
| 4241 | struct objfile *objfile = cu->objfile; |
| 4242 | |
| 4243 | baseaddr = ANOFFSET (objfile->section_offsets, |
| 4244 | SECT_OFF_TEXT (objfile)); |
| 4245 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 4246 | pdi->lowpc + baseaddr, |
| 4247 | pdi->highpc - 1 + baseaddr, |
| 4248 | cu->per_cu->v.psymtab); |
| 4249 | } |
| 4250 | if (!pdi->is_declaration) |
| 4251 | /* Ignore subprogram DIEs that do not have a name, they are |
| 4252 | illegal. Do not emit a complaint at this point, we will |
| 4253 | do so when we convert this psymtab into a symtab. */ |
| 4254 | if (pdi->name) |
| 4255 | add_partial_symbol (pdi, cu); |
| 4256 | } |
| 4257 | } |
| 4258 | |
| 4259 | if (! pdi->has_children) |
| 4260 | return; |
| 4261 | |
| 4262 | if (cu->language == language_ada) |
| 4263 | { |
| 4264 | pdi = pdi->die_child; |
| 4265 | while (pdi != NULL) |
| 4266 | { |
| 4267 | fixup_partial_die (pdi, cu); |
| 4268 | if (pdi->tag == DW_TAG_subprogram |
| 4269 | || pdi->tag == DW_TAG_lexical_block) |
| 4270 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
| 4271 | pdi = pdi->die_sibling; |
| 4272 | } |
| 4273 | } |
| 4274 | } |
| 4275 | |
| 4276 | /* Read a partial die corresponding to an enumeration type. */ |
| 4277 | |
| 4278 | static void |
| 4279 | add_partial_enumeration (struct partial_die_info *enum_pdi, |
| 4280 | struct dwarf2_cu *cu) |
| 4281 | { |
| 4282 | struct partial_die_info *pdi; |
| 4283 | |
| 4284 | if (enum_pdi->name != NULL) |
| 4285 | add_partial_symbol (enum_pdi, cu); |
| 4286 | |
| 4287 | pdi = enum_pdi->die_child; |
| 4288 | while (pdi) |
| 4289 | { |
| 4290 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
| 4291 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
| 4292 | else |
| 4293 | add_partial_symbol (pdi, cu); |
| 4294 | pdi = pdi->die_sibling; |
| 4295 | } |
| 4296 | } |
| 4297 | |
| 4298 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
| 4299 | |
| 4300 | static unsigned int |
| 4301 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) |
| 4302 | { |
| 4303 | unsigned int bytes_read; |
| 4304 | |
| 4305 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4306 | } |
| 4307 | |
| 4308 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
| 4309 | Return the corresponding abbrev, or NULL if the number is zero (indicating |
| 4310 | an empty DIE). In either case *BYTES_READ will be set to the length of |
| 4311 | the initial number. */ |
| 4312 | |
| 4313 | static struct abbrev_info * |
| 4314 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
| 4315 | struct dwarf2_cu *cu) |
| 4316 | { |
| 4317 | bfd *abfd = cu->objfile->obfd; |
| 4318 | unsigned int abbrev_number; |
| 4319 | struct abbrev_info *abbrev; |
| 4320 | |
| 4321 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); |
| 4322 | |
| 4323 | if (abbrev_number == 0) |
| 4324 | return NULL; |
| 4325 | |
| 4326 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
| 4327 | if (!abbrev) |
| 4328 | { |
| 4329 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
| 4330 | abbrev_number, bfd_get_filename (abfd)); |
| 4331 | } |
| 4332 | |
| 4333 | return abbrev; |
| 4334 | } |
| 4335 | |
| 4336 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
| 4337 | Returns a pointer to the end of a series of DIEs, terminated by an empty |
| 4338 | DIE. Any children of the skipped DIEs will also be skipped. */ |
| 4339 | |
| 4340 | static gdb_byte * |
| 4341 | skip_children (gdb_byte *buffer, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
| 4342 | { |
| 4343 | struct abbrev_info *abbrev; |
| 4344 | unsigned int bytes_read; |
| 4345 | |
| 4346 | while (1) |
| 4347 | { |
| 4348 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); |
| 4349 | if (abbrev == NULL) |
| 4350 | return info_ptr + bytes_read; |
| 4351 | else |
| 4352 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
| 4353 | } |
| 4354 | } |
| 4355 | |
| 4356 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
| 4357 | INFO_PTR should point just after the initial uleb128 of a DIE, and the |
| 4358 | abbrev corresponding to that skipped uleb128 should be passed in |
| 4359 | ABBREV. Returns a pointer to this DIE's sibling, skipping any |
| 4360 | children. */ |
| 4361 | |
| 4362 | static gdb_byte * |
| 4363 | skip_one_die (gdb_byte *buffer, gdb_byte *info_ptr, |
| 4364 | struct abbrev_info *abbrev, struct dwarf2_cu *cu) |
| 4365 | { |
| 4366 | unsigned int bytes_read; |
| 4367 | struct attribute attr; |
| 4368 | bfd *abfd = cu->objfile->obfd; |
| 4369 | unsigned int form, i; |
| 4370 | |
| 4371 | for (i = 0; i < abbrev->num_attrs; i++) |
| 4372 | { |
| 4373 | /* The only abbrev we care about is DW_AT_sibling. */ |
| 4374 | if (abbrev->attrs[i].name == DW_AT_sibling) |
| 4375 | { |
| 4376 | read_attribute (&attr, &abbrev->attrs[i], |
| 4377 | abfd, info_ptr, cu); |
| 4378 | if (attr.form == DW_FORM_ref_addr) |
| 4379 | complaint (&symfile_complaints, |
| 4380 | _("ignoring absolute DW_AT_sibling")); |
| 4381 | else |
| 4382 | return buffer + dwarf2_get_ref_die_offset (&attr); |
| 4383 | } |
| 4384 | |
| 4385 | /* If it isn't DW_AT_sibling, skip this attribute. */ |
| 4386 | form = abbrev->attrs[i].form; |
| 4387 | skip_attribute: |
| 4388 | switch (form) |
| 4389 | { |
| 4390 | case DW_FORM_ref_addr: |
| 4391 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
| 4392 | and later it is offset sized. */ |
| 4393 | if (cu->header.version == 2) |
| 4394 | info_ptr += cu->header.addr_size; |
| 4395 | else |
| 4396 | info_ptr += cu->header.offset_size; |
| 4397 | break; |
| 4398 | case DW_FORM_addr: |
| 4399 | info_ptr += cu->header.addr_size; |
| 4400 | break; |
| 4401 | case DW_FORM_data1: |
| 4402 | case DW_FORM_ref1: |
| 4403 | case DW_FORM_flag: |
| 4404 | info_ptr += 1; |
| 4405 | break; |
| 4406 | case DW_FORM_flag_present: |
| 4407 | break; |
| 4408 | case DW_FORM_data2: |
| 4409 | case DW_FORM_ref2: |
| 4410 | info_ptr += 2; |
| 4411 | break; |
| 4412 | case DW_FORM_data4: |
| 4413 | case DW_FORM_ref4: |
| 4414 | info_ptr += 4; |
| 4415 | break; |
| 4416 | case DW_FORM_data8: |
| 4417 | case DW_FORM_ref8: |
| 4418 | case DW_FORM_ref_sig8: |
| 4419 | info_ptr += 8; |
| 4420 | break; |
| 4421 | case DW_FORM_string: |
| 4422 | read_direct_string (abfd, info_ptr, &bytes_read); |
| 4423 | info_ptr += bytes_read; |
| 4424 | break; |
| 4425 | case DW_FORM_sec_offset: |
| 4426 | case DW_FORM_strp: |
| 4427 | info_ptr += cu->header.offset_size; |
| 4428 | break; |
| 4429 | case DW_FORM_exprloc: |
| 4430 | case DW_FORM_block: |
| 4431 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4432 | info_ptr += bytes_read; |
| 4433 | break; |
| 4434 | case DW_FORM_block1: |
| 4435 | info_ptr += 1 + read_1_byte (abfd, info_ptr); |
| 4436 | break; |
| 4437 | case DW_FORM_block2: |
| 4438 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); |
| 4439 | break; |
| 4440 | case DW_FORM_block4: |
| 4441 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); |
| 4442 | break; |
| 4443 | case DW_FORM_sdata: |
| 4444 | case DW_FORM_udata: |
| 4445 | case DW_FORM_ref_udata: |
| 4446 | info_ptr = skip_leb128 (abfd, info_ptr); |
| 4447 | break; |
| 4448 | case DW_FORM_indirect: |
| 4449 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4450 | info_ptr += bytes_read; |
| 4451 | /* We need to continue parsing from here, so just go back to |
| 4452 | the top. */ |
| 4453 | goto skip_attribute; |
| 4454 | |
| 4455 | default: |
| 4456 | error (_("Dwarf Error: Cannot handle %s " |
| 4457 | "in DWARF reader [in module %s]"), |
| 4458 | dwarf_form_name (form), |
| 4459 | bfd_get_filename (abfd)); |
| 4460 | } |
| 4461 | } |
| 4462 | |
| 4463 | if (abbrev->has_children) |
| 4464 | return skip_children (buffer, info_ptr, cu); |
| 4465 | else |
| 4466 | return info_ptr; |
| 4467 | } |
| 4468 | |
| 4469 | /* Locate ORIG_PDI's sibling. |
| 4470 | INFO_PTR should point to the start of the next DIE after ORIG_PDI |
| 4471 | in BUFFER. */ |
| 4472 | |
| 4473 | static gdb_byte * |
| 4474 | locate_pdi_sibling (struct partial_die_info *orig_pdi, |
| 4475 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 4476 | bfd *abfd, struct dwarf2_cu *cu) |
| 4477 | { |
| 4478 | /* Do we know the sibling already? */ |
| 4479 | |
| 4480 | if (orig_pdi->sibling) |
| 4481 | return orig_pdi->sibling; |
| 4482 | |
| 4483 | /* Are there any children to deal with? */ |
| 4484 | |
| 4485 | if (!orig_pdi->has_children) |
| 4486 | return info_ptr; |
| 4487 | |
| 4488 | /* Skip the children the long way. */ |
| 4489 | |
| 4490 | return skip_children (buffer, info_ptr, cu); |
| 4491 | } |
| 4492 | |
| 4493 | /* Expand this partial symbol table into a full symbol table. */ |
| 4494 | |
| 4495 | static void |
| 4496 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
| 4497 | { |
| 4498 | if (pst != NULL) |
| 4499 | { |
| 4500 | if (pst->readin) |
| 4501 | { |
| 4502 | warning (_("bug: psymtab for %s is already read in."), |
| 4503 | pst->filename); |
| 4504 | } |
| 4505 | else |
| 4506 | { |
| 4507 | if (info_verbose) |
| 4508 | { |
| 4509 | printf_filtered (_("Reading in symbols for %s..."), |
| 4510 | pst->filename); |
| 4511 | gdb_flush (gdb_stdout); |
| 4512 | } |
| 4513 | |
| 4514 | /* Restore our global data. */ |
| 4515 | dwarf2_per_objfile = objfile_data (pst->objfile, |
| 4516 | dwarf2_objfile_data_key); |
| 4517 | |
| 4518 | /* If this psymtab is constructed from a debug-only objfile, the |
| 4519 | has_section_at_zero flag will not necessarily be correct. We |
| 4520 | can get the correct value for this flag by looking at the data |
| 4521 | associated with the (presumably stripped) associated objfile. */ |
| 4522 | if (pst->objfile->separate_debug_objfile_backlink) |
| 4523 | { |
| 4524 | struct dwarf2_per_objfile *dpo_backlink |
| 4525 | = objfile_data (pst->objfile->separate_debug_objfile_backlink, |
| 4526 | dwarf2_objfile_data_key); |
| 4527 | |
| 4528 | dwarf2_per_objfile->has_section_at_zero |
| 4529 | = dpo_backlink->has_section_at_zero; |
| 4530 | } |
| 4531 | |
| 4532 | dwarf2_per_objfile->reading_partial_symbols = 0; |
| 4533 | |
| 4534 | psymtab_to_symtab_1 (pst); |
| 4535 | |
| 4536 | /* Finish up the debug error message. */ |
| 4537 | if (info_verbose) |
| 4538 | printf_filtered (_("done.\n")); |
| 4539 | } |
| 4540 | } |
| 4541 | } |
| 4542 | \f |
| 4543 | /* Reading in full CUs. */ |
| 4544 | |
| 4545 | /* Add PER_CU to the queue. */ |
| 4546 | |
| 4547 | static void |
| 4548 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu) |
| 4549 | { |
| 4550 | struct dwarf2_queue_item *item; |
| 4551 | |
| 4552 | per_cu->queued = 1; |
| 4553 | item = xmalloc (sizeof (*item)); |
| 4554 | item->per_cu = per_cu; |
| 4555 | item->next = NULL; |
| 4556 | |
| 4557 | if (dwarf2_queue == NULL) |
| 4558 | dwarf2_queue = item; |
| 4559 | else |
| 4560 | dwarf2_queue_tail->next = item; |
| 4561 | |
| 4562 | dwarf2_queue_tail = item; |
| 4563 | } |
| 4564 | |
| 4565 | /* Process the queue. */ |
| 4566 | |
| 4567 | static void |
| 4568 | process_queue (void) |
| 4569 | { |
| 4570 | struct dwarf2_queue_item *item, *next_item; |
| 4571 | |
| 4572 | /* The queue starts out with one item, but following a DIE reference |
| 4573 | may load a new CU, adding it to the end of the queue. */ |
| 4574 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
| 4575 | { |
| 4576 | if (dwarf2_per_objfile->using_index |
| 4577 | ? !item->per_cu->v.quick->symtab |
| 4578 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) |
| 4579 | process_full_comp_unit (item->per_cu); |
| 4580 | |
| 4581 | item->per_cu->queued = 0; |
| 4582 | next_item = item->next; |
| 4583 | xfree (item); |
| 4584 | } |
| 4585 | |
| 4586 | dwarf2_queue_tail = NULL; |
| 4587 | } |
| 4588 | |
| 4589 | /* Free all allocated queue entries. This function only releases anything if |
| 4590 | an error was thrown; if the queue was processed then it would have been |
| 4591 | freed as we went along. */ |
| 4592 | |
| 4593 | static void |
| 4594 | dwarf2_release_queue (void *dummy) |
| 4595 | { |
| 4596 | struct dwarf2_queue_item *item, *last; |
| 4597 | |
| 4598 | item = dwarf2_queue; |
| 4599 | while (item) |
| 4600 | { |
| 4601 | /* Anything still marked queued is likely to be in an |
| 4602 | inconsistent state, so discard it. */ |
| 4603 | if (item->per_cu->queued) |
| 4604 | { |
| 4605 | if (item->per_cu->cu != NULL) |
| 4606 | free_one_cached_comp_unit (item->per_cu->cu); |
| 4607 | item->per_cu->queued = 0; |
| 4608 | } |
| 4609 | |
| 4610 | last = item; |
| 4611 | item = item->next; |
| 4612 | xfree (last); |
| 4613 | } |
| 4614 | |
| 4615 | dwarf2_queue = dwarf2_queue_tail = NULL; |
| 4616 | } |
| 4617 | |
| 4618 | /* Read in full symbols for PST, and anything it depends on. */ |
| 4619 | |
| 4620 | static void |
| 4621 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
| 4622 | { |
| 4623 | struct dwarf2_per_cu_data *per_cu; |
| 4624 | struct cleanup *back_to; |
| 4625 | int i; |
| 4626 | |
| 4627 | for (i = 0; i < pst->number_of_dependencies; i++) |
| 4628 | if (!pst->dependencies[i]->readin) |
| 4629 | { |
| 4630 | /* Inform about additional files that need to be read in. */ |
| 4631 | if (info_verbose) |
| 4632 | { |
| 4633 | /* FIXME: i18n: Need to make this a single string. */ |
| 4634 | fputs_filtered (" ", gdb_stdout); |
| 4635 | wrap_here (""); |
| 4636 | fputs_filtered ("and ", gdb_stdout); |
| 4637 | wrap_here (""); |
| 4638 | printf_filtered ("%s...", pst->dependencies[i]->filename); |
| 4639 | wrap_here (""); /* Flush output. */ |
| 4640 | gdb_flush (gdb_stdout); |
| 4641 | } |
| 4642 | psymtab_to_symtab_1 (pst->dependencies[i]); |
| 4643 | } |
| 4644 | |
| 4645 | per_cu = pst->read_symtab_private; |
| 4646 | |
| 4647 | if (per_cu == NULL) |
| 4648 | { |
| 4649 | /* It's an include file, no symbols to read for it. |
| 4650 | Everything is in the parent symtab. */ |
| 4651 | pst->readin = 1; |
| 4652 | return; |
| 4653 | } |
| 4654 | |
| 4655 | dw2_do_instantiate_symtab (per_cu); |
| 4656 | } |
| 4657 | |
| 4658 | /* Load the DIEs associated with PER_CU into memory. */ |
| 4659 | |
| 4660 | static void |
| 4661 | load_full_comp_unit (struct dwarf2_per_cu_data *per_cu) |
| 4662 | { |
| 4663 | struct objfile *objfile = per_cu->objfile; |
| 4664 | bfd *abfd = objfile->obfd; |
| 4665 | struct dwarf2_cu *cu; |
| 4666 | unsigned int offset; |
| 4667 | gdb_byte *info_ptr, *beg_of_comp_unit; |
| 4668 | struct cleanup *free_abbrevs_cleanup = NULL, *free_cu_cleanup = NULL; |
| 4669 | struct attribute *attr; |
| 4670 | int read_cu = 0; |
| 4671 | |
| 4672 | gdb_assert (! per_cu->debug_types_section); |
| 4673 | |
| 4674 | /* Set local variables from the partial symbol table info. */ |
| 4675 | offset = per_cu->offset; |
| 4676 | |
| 4677 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 4678 | info_ptr = dwarf2_per_objfile->info.buffer + offset; |
| 4679 | beg_of_comp_unit = info_ptr; |
| 4680 | |
| 4681 | if (per_cu->cu == NULL) |
| 4682 | { |
| 4683 | cu = xmalloc (sizeof (*cu)); |
| 4684 | init_one_comp_unit (cu, per_cu); |
| 4685 | |
| 4686 | read_cu = 1; |
| 4687 | |
| 4688 | /* If an error occurs while loading, release our storage. */ |
| 4689 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
| 4690 | |
| 4691 | /* Read in the comp_unit header. */ |
| 4692 | info_ptr = read_comp_unit_head (&cu->header, info_ptr, abfd); |
| 4693 | |
| 4694 | /* Skip dummy compilation units. */ |
| 4695 | if (info_ptr >= (dwarf2_per_objfile->info.buffer |
| 4696 | + dwarf2_per_objfile->info.size) |
| 4697 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 4698 | { |
| 4699 | do_cleanups (free_cu_cleanup); |
| 4700 | return; |
| 4701 | } |
| 4702 | |
| 4703 | /* Complete the cu_header. */ |
| 4704 | cu->header.offset = offset; |
| 4705 | cu->header.first_die_offset = info_ptr - beg_of_comp_unit; |
| 4706 | |
| 4707 | /* Read the abbrevs for this compilation unit. */ |
| 4708 | dwarf2_read_abbrevs (cu); |
| 4709 | free_abbrevs_cleanup = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 4710 | |
| 4711 | /* Link this CU into read_in_chain. */ |
| 4712 | per_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 4713 | dwarf2_per_objfile->read_in_chain = per_cu; |
| 4714 | } |
| 4715 | else |
| 4716 | { |
| 4717 | cu = per_cu->cu; |
| 4718 | info_ptr += cu->header.first_die_offset; |
| 4719 | } |
| 4720 | |
| 4721 | cu->dies = read_comp_unit (info_ptr, cu); |
| 4722 | |
| 4723 | /* We try not to read any attributes in this function, because not |
| 4724 | all CUs needed for references have been loaded yet, and symbol |
| 4725 | table processing isn't initialized. But we have to set the CU language, |
| 4726 | or we won't be able to build types correctly. */ |
| 4727 | prepare_one_comp_unit (cu, cu->dies); |
| 4728 | |
| 4729 | /* Similarly, if we do not read the producer, we can not apply |
| 4730 | producer-specific interpretation. */ |
| 4731 | attr = dwarf2_attr (cu->dies, DW_AT_producer, cu); |
| 4732 | if (attr) |
| 4733 | cu->producer = DW_STRING (attr); |
| 4734 | |
| 4735 | if (read_cu) |
| 4736 | { |
| 4737 | do_cleanups (free_abbrevs_cleanup); |
| 4738 | |
| 4739 | /* We've successfully allocated this compilation unit. Let our |
| 4740 | caller clean it up when finished with it. */ |
| 4741 | discard_cleanups (free_cu_cleanup); |
| 4742 | } |
| 4743 | } |
| 4744 | |
| 4745 | /* Add a DIE to the delayed physname list. */ |
| 4746 | |
| 4747 | static void |
| 4748 | add_to_method_list (struct type *type, int fnfield_index, int index, |
| 4749 | const char *name, struct die_info *die, |
| 4750 | struct dwarf2_cu *cu) |
| 4751 | { |
| 4752 | struct delayed_method_info mi; |
| 4753 | mi.type = type; |
| 4754 | mi.fnfield_index = fnfield_index; |
| 4755 | mi.index = index; |
| 4756 | mi.name = name; |
| 4757 | mi.die = die; |
| 4758 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); |
| 4759 | } |
| 4760 | |
| 4761 | /* A cleanup for freeing the delayed method list. */ |
| 4762 | |
| 4763 | static void |
| 4764 | free_delayed_list (void *ptr) |
| 4765 | { |
| 4766 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; |
| 4767 | if (cu->method_list != NULL) |
| 4768 | { |
| 4769 | VEC_free (delayed_method_info, cu->method_list); |
| 4770 | cu->method_list = NULL; |
| 4771 | } |
| 4772 | } |
| 4773 | |
| 4774 | /* Compute the physnames of any methods on the CU's method list. |
| 4775 | |
| 4776 | The computation of method physnames is delayed in order to avoid the |
| 4777 | (bad) condition that one of the method's formal parameters is of an as yet |
| 4778 | incomplete type. */ |
| 4779 | |
| 4780 | static void |
| 4781 | compute_delayed_physnames (struct dwarf2_cu *cu) |
| 4782 | { |
| 4783 | int i; |
| 4784 | struct delayed_method_info *mi; |
| 4785 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) |
| 4786 | { |
| 4787 | const char *physname; |
| 4788 | struct fn_fieldlist *fn_flp |
| 4789 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); |
| 4790 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
| 4791 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
| 4792 | } |
| 4793 | } |
| 4794 | |
| 4795 | /* Generate full symbol information for PER_CU, whose DIEs have |
| 4796 | already been loaded into memory. */ |
| 4797 | |
| 4798 | static void |
| 4799 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu) |
| 4800 | { |
| 4801 | struct dwarf2_cu *cu = per_cu->cu; |
| 4802 | struct objfile *objfile = per_cu->objfile; |
| 4803 | CORE_ADDR lowpc, highpc; |
| 4804 | struct symtab *symtab; |
| 4805 | struct cleanup *back_to, *delayed_list_cleanup; |
| 4806 | CORE_ADDR baseaddr; |
| 4807 | |
| 4808 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 4809 | |
| 4810 | buildsym_init (); |
| 4811 | back_to = make_cleanup (really_free_pendings, NULL); |
| 4812 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
| 4813 | |
| 4814 | cu->list_in_scope = &file_symbols; |
| 4815 | |
| 4816 | /* Do line number decoding in read_file_scope () */ |
| 4817 | process_die (cu->dies, cu); |
| 4818 | |
| 4819 | /* Now that we have processed all the DIEs in the CU, all the types |
| 4820 | should be complete, and it should now be safe to compute all of the |
| 4821 | physnames. */ |
| 4822 | compute_delayed_physnames (cu); |
| 4823 | do_cleanups (delayed_list_cleanup); |
| 4824 | |
| 4825 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
| 4826 | compilation unit. If the DW_AT_high_pc is missing, synthesize |
| 4827 | it, by scanning the DIE's below the compilation unit. */ |
| 4828 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
| 4829 | |
| 4830 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
| 4831 | |
| 4832 | if (symtab != NULL) |
| 4833 | { |
| 4834 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
| 4835 | |
| 4836 | /* Set symtab language to language from DW_AT_language. If the |
| 4837 | compilation is from a C file generated by language preprocessors, do |
| 4838 | not set the language if it was already deduced by start_subfile. */ |
| 4839 | if (!(cu->language == language_c && symtab->language != language_c)) |
| 4840 | symtab->language = cu->language; |
| 4841 | |
| 4842 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can |
| 4843 | produce DW_AT_location with location lists but it can be possibly |
| 4844 | invalid without -fvar-tracking. |
| 4845 | |
| 4846 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not |
| 4847 | needed, it would be wrong due to missing DW_AT_producer there. |
| 4848 | |
| 4849 | Still one can confuse GDB by using non-standard GCC compilation |
| 4850 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). |
| 4851 | */ |
| 4852 | if (cu->has_loclist && gcc_4_minor >= 0) |
| 4853 | symtab->locations_valid = 1; |
| 4854 | |
| 4855 | if (gcc_4_minor >= 5) |
| 4856 | symtab->epilogue_unwind_valid = 1; |
| 4857 | |
| 4858 | symtab->call_site_htab = cu->call_site_htab; |
| 4859 | } |
| 4860 | |
| 4861 | if (dwarf2_per_objfile->using_index) |
| 4862 | per_cu->v.quick->symtab = symtab; |
| 4863 | else |
| 4864 | { |
| 4865 | struct partial_symtab *pst = per_cu->v.psymtab; |
| 4866 | pst->symtab = symtab; |
| 4867 | pst->readin = 1; |
| 4868 | } |
| 4869 | |
| 4870 | do_cleanups (back_to); |
| 4871 | } |
| 4872 | |
| 4873 | /* Process a die and its children. */ |
| 4874 | |
| 4875 | static void |
| 4876 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
| 4877 | { |
| 4878 | switch (die->tag) |
| 4879 | { |
| 4880 | case DW_TAG_padding: |
| 4881 | break; |
| 4882 | case DW_TAG_compile_unit: |
| 4883 | read_file_scope (die, cu); |
| 4884 | break; |
| 4885 | case DW_TAG_type_unit: |
| 4886 | read_type_unit_scope (die, cu); |
| 4887 | break; |
| 4888 | case DW_TAG_subprogram: |
| 4889 | case DW_TAG_inlined_subroutine: |
| 4890 | read_func_scope (die, cu); |
| 4891 | break; |
| 4892 | case DW_TAG_lexical_block: |
| 4893 | case DW_TAG_try_block: |
| 4894 | case DW_TAG_catch_block: |
| 4895 | read_lexical_block_scope (die, cu); |
| 4896 | break; |
| 4897 | case DW_TAG_GNU_call_site: |
| 4898 | read_call_site_scope (die, cu); |
| 4899 | break; |
| 4900 | case DW_TAG_class_type: |
| 4901 | case DW_TAG_interface_type: |
| 4902 | case DW_TAG_structure_type: |
| 4903 | case DW_TAG_union_type: |
| 4904 | process_structure_scope (die, cu); |
| 4905 | break; |
| 4906 | case DW_TAG_enumeration_type: |
| 4907 | process_enumeration_scope (die, cu); |
| 4908 | break; |
| 4909 | |
| 4910 | /* These dies have a type, but processing them does not create |
| 4911 | a symbol or recurse to process the children. Therefore we can |
| 4912 | read them on-demand through read_type_die. */ |
| 4913 | case DW_TAG_subroutine_type: |
| 4914 | case DW_TAG_set_type: |
| 4915 | case DW_TAG_array_type: |
| 4916 | case DW_TAG_pointer_type: |
| 4917 | case DW_TAG_ptr_to_member_type: |
| 4918 | case DW_TAG_reference_type: |
| 4919 | case DW_TAG_string_type: |
| 4920 | break; |
| 4921 | |
| 4922 | case DW_TAG_base_type: |
| 4923 | case DW_TAG_subrange_type: |
| 4924 | case DW_TAG_typedef: |
| 4925 | /* Add a typedef symbol for the type definition, if it has a |
| 4926 | DW_AT_name. */ |
| 4927 | new_symbol (die, read_type_die (die, cu), cu); |
| 4928 | break; |
| 4929 | case DW_TAG_common_block: |
| 4930 | read_common_block (die, cu); |
| 4931 | break; |
| 4932 | case DW_TAG_common_inclusion: |
| 4933 | break; |
| 4934 | case DW_TAG_namespace: |
| 4935 | processing_has_namespace_info = 1; |
| 4936 | read_namespace (die, cu); |
| 4937 | break; |
| 4938 | case DW_TAG_module: |
| 4939 | processing_has_namespace_info = 1; |
| 4940 | read_module (die, cu); |
| 4941 | break; |
| 4942 | case DW_TAG_imported_declaration: |
| 4943 | case DW_TAG_imported_module: |
| 4944 | processing_has_namespace_info = 1; |
| 4945 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
| 4946 | || cu->language != language_fortran)) |
| 4947 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), |
| 4948 | dwarf_tag_name (die->tag)); |
| 4949 | read_import_statement (die, cu); |
| 4950 | break; |
| 4951 | default: |
| 4952 | new_symbol (die, NULL, cu); |
| 4953 | break; |
| 4954 | } |
| 4955 | } |
| 4956 | |
| 4957 | /* A helper function for dwarf2_compute_name which determines whether DIE |
| 4958 | needs to have the name of the scope prepended to the name listed in the |
| 4959 | die. */ |
| 4960 | |
| 4961 | static int |
| 4962 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) |
| 4963 | { |
| 4964 | struct attribute *attr; |
| 4965 | |
| 4966 | switch (die->tag) |
| 4967 | { |
| 4968 | case DW_TAG_namespace: |
| 4969 | case DW_TAG_typedef: |
| 4970 | case DW_TAG_class_type: |
| 4971 | case DW_TAG_interface_type: |
| 4972 | case DW_TAG_structure_type: |
| 4973 | case DW_TAG_union_type: |
| 4974 | case DW_TAG_enumeration_type: |
| 4975 | case DW_TAG_enumerator: |
| 4976 | case DW_TAG_subprogram: |
| 4977 | case DW_TAG_member: |
| 4978 | return 1; |
| 4979 | |
| 4980 | case DW_TAG_variable: |
| 4981 | case DW_TAG_constant: |
| 4982 | /* We only need to prefix "globally" visible variables. These include |
| 4983 | any variable marked with DW_AT_external or any variable that |
| 4984 | lives in a namespace. [Variables in anonymous namespaces |
| 4985 | require prefixing, but they are not DW_AT_external.] */ |
| 4986 | |
| 4987 | if (dwarf2_attr (die, DW_AT_specification, cu)) |
| 4988 | { |
| 4989 | struct dwarf2_cu *spec_cu = cu; |
| 4990 | |
| 4991 | return die_needs_namespace (die_specification (die, &spec_cu), |
| 4992 | spec_cu); |
| 4993 | } |
| 4994 | |
| 4995 | attr = dwarf2_attr (die, DW_AT_external, cu); |
| 4996 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
| 4997 | && die->parent->tag != DW_TAG_module) |
| 4998 | return 0; |
| 4999 | /* A variable in a lexical block of some kind does not need a |
| 5000 | namespace, even though in C++ such variables may be external |
| 5001 | and have a mangled name. */ |
| 5002 | if (die->parent->tag == DW_TAG_lexical_block |
| 5003 | || die->parent->tag == DW_TAG_try_block |
| 5004 | || die->parent->tag == DW_TAG_catch_block |
| 5005 | || die->parent->tag == DW_TAG_subprogram) |
| 5006 | return 0; |
| 5007 | return 1; |
| 5008 | |
| 5009 | default: |
| 5010 | return 0; |
| 5011 | } |
| 5012 | } |
| 5013 | |
| 5014 | /* Retrieve the last character from a mem_file. */ |
| 5015 | |
| 5016 | static void |
| 5017 | do_ui_file_peek_last (void *object, const char *buffer, long length) |
| 5018 | { |
| 5019 | char *last_char_p = (char *) object; |
| 5020 | |
| 5021 | if (length > 0) |
| 5022 | *last_char_p = buffer[length - 1]; |
| 5023 | } |
| 5024 | |
| 5025 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
| 5026 | compute the physname for the object, which include a method's |
| 5027 | formal parameters (C++/Java) and return type (Java). |
| 5028 | |
| 5029 | For Ada, return the DIE's linkage name rather than the fully qualified |
| 5030 | name. PHYSNAME is ignored.. |
| 5031 | |
| 5032 | The result is allocated on the objfile_obstack and canonicalized. */ |
| 5033 | |
| 5034 | static const char * |
| 5035 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, |
| 5036 | int physname) |
| 5037 | { |
| 5038 | struct objfile *objfile = cu->objfile; |
| 5039 | |
| 5040 | if (name == NULL) |
| 5041 | name = dwarf2_name (die, cu); |
| 5042 | |
| 5043 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
| 5044 | compute it by typename_concat inside GDB. */ |
| 5045 | if (cu->language == language_ada |
| 5046 | || (cu->language == language_fortran && physname)) |
| 5047 | { |
| 5048 | /* For Ada unit, we prefer the linkage name over the name, as |
| 5049 | the former contains the exported name, which the user expects |
| 5050 | to be able to reference. Ideally, we want the user to be able |
| 5051 | to reference this entity using either natural or linkage name, |
| 5052 | but we haven't started looking at this enhancement yet. */ |
| 5053 | struct attribute *attr; |
| 5054 | |
| 5055 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 5056 | if (attr == NULL) |
| 5057 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 5058 | if (attr && DW_STRING (attr)) |
| 5059 | return DW_STRING (attr); |
| 5060 | } |
| 5061 | |
| 5062 | /* These are the only languages we know how to qualify names in. */ |
| 5063 | if (name != NULL |
| 5064 | && (cu->language == language_cplus || cu->language == language_java |
| 5065 | || cu->language == language_fortran)) |
| 5066 | { |
| 5067 | if (die_needs_namespace (die, cu)) |
| 5068 | { |
| 5069 | long length; |
| 5070 | const char *prefix; |
| 5071 | struct ui_file *buf; |
| 5072 | |
| 5073 | prefix = determine_prefix (die, cu); |
| 5074 | buf = mem_fileopen (); |
| 5075 | if (*prefix != '\0') |
| 5076 | { |
| 5077 | char *prefixed_name = typename_concat (NULL, prefix, name, |
| 5078 | physname, cu); |
| 5079 | |
| 5080 | fputs_unfiltered (prefixed_name, buf); |
| 5081 | xfree (prefixed_name); |
| 5082 | } |
| 5083 | else |
| 5084 | fputs_unfiltered (name, buf); |
| 5085 | |
| 5086 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
| 5087 | as children with DW_TAG_template_type_param or |
| 5088 | DW_TAG_value_type_param. If the latter, add them to the name |
| 5089 | here. If the name already has template parameters, then |
| 5090 | skip this step; some versions of GCC emit both, and |
| 5091 | it is more efficient to use the pre-computed name. |
| 5092 | |
| 5093 | Something to keep in mind about this process: it is very |
| 5094 | unlikely, or in some cases downright impossible, to produce |
| 5095 | something that will match the mangled name of a function. |
| 5096 | If the definition of the function has the same debug info, |
| 5097 | we should be able to match up with it anyway. But fallbacks |
| 5098 | using the minimal symbol, for instance to find a method |
| 5099 | implemented in a stripped copy of libstdc++, will not work. |
| 5100 | If we do not have debug info for the definition, we will have to |
| 5101 | match them up some other way. |
| 5102 | |
| 5103 | When we do name matching there is a related problem with function |
| 5104 | templates; two instantiated function templates are allowed to |
| 5105 | differ only by their return types, which we do not add here. */ |
| 5106 | |
| 5107 | if (cu->language == language_cplus && strchr (name, '<') == NULL) |
| 5108 | { |
| 5109 | struct attribute *attr; |
| 5110 | struct die_info *child; |
| 5111 | int first = 1; |
| 5112 | |
| 5113 | die->building_fullname = 1; |
| 5114 | |
| 5115 | for (child = die->child; child != NULL; child = child->sibling) |
| 5116 | { |
| 5117 | struct type *type; |
| 5118 | long value; |
| 5119 | gdb_byte *bytes; |
| 5120 | struct dwarf2_locexpr_baton *baton; |
| 5121 | struct value *v; |
| 5122 | |
| 5123 | if (child->tag != DW_TAG_template_type_param |
| 5124 | && child->tag != DW_TAG_template_value_param) |
| 5125 | continue; |
| 5126 | |
| 5127 | if (first) |
| 5128 | { |
| 5129 | fputs_unfiltered ("<", buf); |
| 5130 | first = 0; |
| 5131 | } |
| 5132 | else |
| 5133 | fputs_unfiltered (", ", buf); |
| 5134 | |
| 5135 | attr = dwarf2_attr (child, DW_AT_type, cu); |
| 5136 | if (attr == NULL) |
| 5137 | { |
| 5138 | complaint (&symfile_complaints, |
| 5139 | _("template parameter missing DW_AT_type")); |
| 5140 | fputs_unfiltered ("UNKNOWN_TYPE", buf); |
| 5141 | continue; |
| 5142 | } |
| 5143 | type = die_type (child, cu); |
| 5144 | |
| 5145 | if (child->tag == DW_TAG_template_type_param) |
| 5146 | { |
| 5147 | c_print_type (type, "", buf, -1, 0); |
| 5148 | continue; |
| 5149 | } |
| 5150 | |
| 5151 | attr = dwarf2_attr (child, DW_AT_const_value, cu); |
| 5152 | if (attr == NULL) |
| 5153 | { |
| 5154 | complaint (&symfile_complaints, |
| 5155 | _("template parameter missing " |
| 5156 | "DW_AT_const_value")); |
| 5157 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
| 5158 | continue; |
| 5159 | } |
| 5160 | |
| 5161 | dwarf2_const_value_attr (attr, type, name, |
| 5162 | &cu->comp_unit_obstack, cu, |
| 5163 | &value, &bytes, &baton); |
| 5164 | |
| 5165 | if (TYPE_NOSIGN (type)) |
| 5166 | /* GDB prints characters as NUMBER 'CHAR'. If that's |
| 5167 | changed, this can use value_print instead. */ |
| 5168 | c_printchar (value, type, buf); |
| 5169 | else |
| 5170 | { |
| 5171 | struct value_print_options opts; |
| 5172 | |
| 5173 | if (baton != NULL) |
| 5174 | v = dwarf2_evaluate_loc_desc (type, NULL, |
| 5175 | baton->data, |
| 5176 | baton->size, |
| 5177 | baton->per_cu); |
| 5178 | else if (bytes != NULL) |
| 5179 | { |
| 5180 | v = allocate_value (type); |
| 5181 | memcpy (value_contents_writeable (v), bytes, |
| 5182 | TYPE_LENGTH (type)); |
| 5183 | } |
| 5184 | else |
| 5185 | v = value_from_longest (type, value); |
| 5186 | |
| 5187 | /* Specify decimal so that we do not depend on |
| 5188 | the radix. */ |
| 5189 | get_formatted_print_options (&opts, 'd'); |
| 5190 | opts.raw = 1; |
| 5191 | value_print (v, buf, &opts); |
| 5192 | release_value (v); |
| 5193 | value_free (v); |
| 5194 | } |
| 5195 | } |
| 5196 | |
| 5197 | die->building_fullname = 0; |
| 5198 | |
| 5199 | if (!first) |
| 5200 | { |
| 5201 | /* Close the argument list, with a space if necessary |
| 5202 | (nested templates). */ |
| 5203 | char last_char = '\0'; |
| 5204 | ui_file_put (buf, do_ui_file_peek_last, &last_char); |
| 5205 | if (last_char == '>') |
| 5206 | fputs_unfiltered (" >", buf); |
| 5207 | else |
| 5208 | fputs_unfiltered (">", buf); |
| 5209 | } |
| 5210 | } |
| 5211 | |
| 5212 | /* For Java and C++ methods, append formal parameter type |
| 5213 | information, if PHYSNAME. */ |
| 5214 | |
| 5215 | if (physname && die->tag == DW_TAG_subprogram |
| 5216 | && (cu->language == language_cplus |
| 5217 | || cu->language == language_java)) |
| 5218 | { |
| 5219 | struct type *type = read_type_die (die, cu); |
| 5220 | |
| 5221 | c_type_print_args (type, buf, 1, cu->language); |
| 5222 | |
| 5223 | if (cu->language == language_java) |
| 5224 | { |
| 5225 | /* For java, we must append the return type to method |
| 5226 | names. */ |
| 5227 | if (die->tag == DW_TAG_subprogram) |
| 5228 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, |
| 5229 | 0, 0); |
| 5230 | } |
| 5231 | else if (cu->language == language_cplus) |
| 5232 | { |
| 5233 | /* Assume that an artificial first parameter is |
| 5234 | "this", but do not crash if it is not. RealView |
| 5235 | marks unnamed (and thus unused) parameters as |
| 5236 | artificial; there is no way to differentiate |
| 5237 | the two cases. */ |
| 5238 | if (TYPE_NFIELDS (type) > 0 |
| 5239 | && TYPE_FIELD_ARTIFICIAL (type, 0) |
| 5240 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
| 5241 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
| 5242 | 0)))) |
| 5243 | fputs_unfiltered (" const", buf); |
| 5244 | } |
| 5245 | } |
| 5246 | |
| 5247 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
| 5248 | &length); |
| 5249 | ui_file_delete (buf); |
| 5250 | |
| 5251 | if (cu->language == language_cplus) |
| 5252 | { |
| 5253 | char *cname |
| 5254 | = dwarf2_canonicalize_name (name, cu, |
| 5255 | &objfile->objfile_obstack); |
| 5256 | |
| 5257 | if (cname != NULL) |
| 5258 | name = cname; |
| 5259 | } |
| 5260 | } |
| 5261 | } |
| 5262 | |
| 5263 | return name; |
| 5264 | } |
| 5265 | |
| 5266 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
| 5267 | If scope qualifiers are appropriate they will be added. The result |
| 5268 | will be allocated on the objfile_obstack, or NULL if the DIE does |
| 5269 | not have a name. NAME may either be from a previous call to |
| 5270 | dwarf2_name or NULL. |
| 5271 | |
| 5272 | The output string will be canonicalized (if C++/Java). */ |
| 5273 | |
| 5274 | static const char * |
| 5275 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
| 5276 | { |
| 5277 | return dwarf2_compute_name (name, die, cu, 0); |
| 5278 | } |
| 5279 | |
| 5280 | /* Construct a physname for the given DIE in CU. NAME may either be |
| 5281 | from a previous call to dwarf2_name or NULL. The result will be |
| 5282 | allocated on the objfile_objstack or NULL if the DIE does not have a |
| 5283 | name. |
| 5284 | |
| 5285 | The output string will be canonicalized (if C++/Java). */ |
| 5286 | |
| 5287 | static const char * |
| 5288 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) |
| 5289 | { |
| 5290 | struct objfile *objfile = cu->objfile; |
| 5291 | struct attribute *attr; |
| 5292 | const char *retval, *mangled = NULL, *canon = NULL; |
| 5293 | struct cleanup *back_to; |
| 5294 | int need_copy = 1; |
| 5295 | |
| 5296 | /* In this case dwarf2_compute_name is just a shortcut not building anything |
| 5297 | on its own. */ |
| 5298 | if (!die_needs_namespace (die, cu)) |
| 5299 | return dwarf2_compute_name (name, die, cu, 1); |
| 5300 | |
| 5301 | back_to = make_cleanup (null_cleanup, NULL); |
| 5302 | |
| 5303 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 5304 | if (!attr) |
| 5305 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 5306 | |
| 5307 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB |
| 5308 | has computed. */ |
| 5309 | if (attr && DW_STRING (attr)) |
| 5310 | { |
| 5311 | char *demangled; |
| 5312 | |
| 5313 | mangled = DW_STRING (attr); |
| 5314 | |
| 5315 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return |
| 5316 | type. It is easier for GDB users to search for such functions as |
| 5317 | `name(params)' than `long name(params)'. In such case the minimal |
| 5318 | symbol names do not match the full symbol names but for template |
| 5319 | functions there is never a need to look up their definition from their |
| 5320 | declaration so the only disadvantage remains the minimal symbol |
| 5321 | variant `long name(params)' does not have the proper inferior type. |
| 5322 | */ |
| 5323 | |
| 5324 | demangled = cplus_demangle (mangled, (DMGL_PARAMS | DMGL_ANSI |
| 5325 | | (cu->language == language_java |
| 5326 | ? DMGL_JAVA | DMGL_RET_POSTFIX |
| 5327 | : DMGL_RET_DROP))); |
| 5328 | if (demangled) |
| 5329 | { |
| 5330 | make_cleanup (xfree, demangled); |
| 5331 | canon = demangled; |
| 5332 | } |
| 5333 | else |
| 5334 | { |
| 5335 | canon = mangled; |
| 5336 | need_copy = 0; |
| 5337 | } |
| 5338 | } |
| 5339 | |
| 5340 | if (canon == NULL || check_physname) |
| 5341 | { |
| 5342 | const char *physname = dwarf2_compute_name (name, die, cu, 1); |
| 5343 | |
| 5344 | if (canon != NULL && strcmp (physname, canon) != 0) |
| 5345 | { |
| 5346 | /* It may not mean a bug in GDB. The compiler could also |
| 5347 | compute DW_AT_linkage_name incorrectly. But in such case |
| 5348 | GDB would need to be bug-to-bug compatible. */ |
| 5349 | |
| 5350 | complaint (&symfile_complaints, |
| 5351 | _("Computed physname <%s> does not match demangled <%s> " |
| 5352 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), |
| 5353 | physname, canon, mangled, die->offset, objfile->name); |
| 5354 | |
| 5355 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it |
| 5356 | is available here - over computed PHYSNAME. It is safer |
| 5357 | against both buggy GDB and buggy compilers. */ |
| 5358 | |
| 5359 | retval = canon; |
| 5360 | } |
| 5361 | else |
| 5362 | { |
| 5363 | retval = physname; |
| 5364 | need_copy = 0; |
| 5365 | } |
| 5366 | } |
| 5367 | else |
| 5368 | retval = canon; |
| 5369 | |
| 5370 | if (need_copy) |
| 5371 | retval = obsavestring (retval, strlen (retval), |
| 5372 | &objfile->objfile_obstack); |
| 5373 | |
| 5374 | do_cleanups (back_to); |
| 5375 | return retval; |
| 5376 | } |
| 5377 | |
| 5378 | /* Read the import statement specified by the given die and record it. */ |
| 5379 | |
| 5380 | static void |
| 5381 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) |
| 5382 | { |
| 5383 | struct objfile *objfile = cu->objfile; |
| 5384 | struct attribute *import_attr; |
| 5385 | struct die_info *imported_die, *child_die; |
| 5386 | struct dwarf2_cu *imported_cu; |
| 5387 | const char *imported_name; |
| 5388 | const char *imported_name_prefix; |
| 5389 | const char *canonical_name; |
| 5390 | const char *import_alias; |
| 5391 | const char *imported_declaration = NULL; |
| 5392 | const char *import_prefix; |
| 5393 | VEC (const_char_ptr) *excludes = NULL; |
| 5394 | struct cleanup *cleanups; |
| 5395 | |
| 5396 | char *temp; |
| 5397 | |
| 5398 | import_attr = dwarf2_attr (die, DW_AT_import, cu); |
| 5399 | if (import_attr == NULL) |
| 5400 | { |
| 5401 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), |
| 5402 | dwarf_tag_name (die->tag)); |
| 5403 | return; |
| 5404 | } |
| 5405 | |
| 5406 | imported_cu = cu; |
| 5407 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); |
| 5408 | imported_name = dwarf2_name (imported_die, imported_cu); |
| 5409 | if (imported_name == NULL) |
| 5410 | { |
| 5411 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 |
| 5412 | |
| 5413 | The import in the following code: |
| 5414 | namespace A |
| 5415 | { |
| 5416 | typedef int B; |
| 5417 | } |
| 5418 | |
| 5419 | int main () |
| 5420 | { |
| 5421 | using A::B; |
| 5422 | B b; |
| 5423 | return b; |
| 5424 | } |
| 5425 | |
| 5426 | ... |
| 5427 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) |
| 5428 | <52> DW_AT_decl_file : 1 |
| 5429 | <53> DW_AT_decl_line : 6 |
| 5430 | <54> DW_AT_import : <0x75> |
| 5431 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) |
| 5432 | <59> DW_AT_name : B |
| 5433 | <5b> DW_AT_decl_file : 1 |
| 5434 | <5c> DW_AT_decl_line : 2 |
| 5435 | <5d> DW_AT_type : <0x6e> |
| 5436 | ... |
| 5437 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) |
| 5438 | <76> DW_AT_byte_size : 4 |
| 5439 | <77> DW_AT_encoding : 5 (signed) |
| 5440 | |
| 5441 | imports the wrong die ( 0x75 instead of 0x58 ). |
| 5442 | This case will be ignored until the gcc bug is fixed. */ |
| 5443 | return; |
| 5444 | } |
| 5445 | |
| 5446 | /* Figure out the local name after import. */ |
| 5447 | import_alias = dwarf2_name (die, cu); |
| 5448 | |
| 5449 | /* Figure out where the statement is being imported to. */ |
| 5450 | import_prefix = determine_prefix (die, cu); |
| 5451 | |
| 5452 | /* Figure out what the scope of the imported die is and prepend it |
| 5453 | to the name of the imported die. */ |
| 5454 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
| 5455 | |
| 5456 | if (imported_die->tag != DW_TAG_namespace |
| 5457 | && imported_die->tag != DW_TAG_module) |
| 5458 | { |
| 5459 | imported_declaration = imported_name; |
| 5460 | canonical_name = imported_name_prefix; |
| 5461 | } |
| 5462 | else if (strlen (imported_name_prefix) > 0) |
| 5463 | { |
| 5464 | temp = alloca (strlen (imported_name_prefix) |
| 5465 | + 2 + strlen (imported_name) + 1); |
| 5466 | strcpy (temp, imported_name_prefix); |
| 5467 | strcat (temp, "::"); |
| 5468 | strcat (temp, imported_name); |
| 5469 | canonical_name = temp; |
| 5470 | } |
| 5471 | else |
| 5472 | canonical_name = imported_name; |
| 5473 | |
| 5474 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
| 5475 | |
| 5476 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) |
| 5477 | for (child_die = die->child; child_die && child_die->tag; |
| 5478 | child_die = sibling_die (child_die)) |
| 5479 | { |
| 5480 | /* DWARF-4: A Fortran use statement with a “rename list” may be |
| 5481 | represented by an imported module entry with an import attribute |
| 5482 | referring to the module and owned entries corresponding to those |
| 5483 | entities that are renamed as part of being imported. */ |
| 5484 | |
| 5485 | if (child_die->tag != DW_TAG_imported_declaration) |
| 5486 | { |
| 5487 | complaint (&symfile_complaints, |
| 5488 | _("child DW_TAG_imported_declaration expected " |
| 5489 | "- DIE at 0x%x [in module %s]"), |
| 5490 | child_die->offset, objfile->name); |
| 5491 | continue; |
| 5492 | } |
| 5493 | |
| 5494 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); |
| 5495 | if (import_attr == NULL) |
| 5496 | { |
| 5497 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), |
| 5498 | dwarf_tag_name (child_die->tag)); |
| 5499 | continue; |
| 5500 | } |
| 5501 | |
| 5502 | imported_cu = cu; |
| 5503 | imported_die = follow_die_ref_or_sig (child_die, import_attr, |
| 5504 | &imported_cu); |
| 5505 | imported_name = dwarf2_name (imported_die, imported_cu); |
| 5506 | if (imported_name == NULL) |
| 5507 | { |
| 5508 | complaint (&symfile_complaints, |
| 5509 | _("child DW_TAG_imported_declaration has unknown " |
| 5510 | "imported name - DIE at 0x%x [in module %s]"), |
| 5511 | child_die->offset, objfile->name); |
| 5512 | continue; |
| 5513 | } |
| 5514 | |
| 5515 | VEC_safe_push (const_char_ptr, excludes, imported_name); |
| 5516 | |
| 5517 | process_die (child_die, cu); |
| 5518 | } |
| 5519 | |
| 5520 | cp_add_using_directive (import_prefix, |
| 5521 | canonical_name, |
| 5522 | import_alias, |
| 5523 | imported_declaration, |
| 5524 | excludes, |
| 5525 | &objfile->objfile_obstack); |
| 5526 | |
| 5527 | do_cleanups (cleanups); |
| 5528 | } |
| 5529 | |
| 5530 | /* Cleanup function for read_file_scope. */ |
| 5531 | |
| 5532 | static void |
| 5533 | free_cu_line_header (void *arg) |
| 5534 | { |
| 5535 | struct dwarf2_cu *cu = arg; |
| 5536 | |
| 5537 | free_line_header (cu->line_header); |
| 5538 | cu->line_header = NULL; |
| 5539 | } |
| 5540 | |
| 5541 | static void |
| 5542 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, |
| 5543 | char **name, char **comp_dir) |
| 5544 | { |
| 5545 | struct attribute *attr; |
| 5546 | |
| 5547 | *name = NULL; |
| 5548 | *comp_dir = NULL; |
| 5549 | |
| 5550 | /* Find the filename. Do not use dwarf2_name here, since the filename |
| 5551 | is not a source language identifier. */ |
| 5552 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 5553 | if (attr) |
| 5554 | { |
| 5555 | *name = DW_STRING (attr); |
| 5556 | } |
| 5557 | |
| 5558 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
| 5559 | if (attr) |
| 5560 | *comp_dir = DW_STRING (attr); |
| 5561 | else if (*name != NULL && IS_ABSOLUTE_PATH (*name)) |
| 5562 | { |
| 5563 | *comp_dir = ldirname (*name); |
| 5564 | if (*comp_dir != NULL) |
| 5565 | make_cleanup (xfree, *comp_dir); |
| 5566 | } |
| 5567 | if (*comp_dir != NULL) |
| 5568 | { |
| 5569 | /* Irix 6.2 native cc prepends <machine>.: to the compilation |
| 5570 | directory, get rid of it. */ |
| 5571 | char *cp = strchr (*comp_dir, ':'); |
| 5572 | |
| 5573 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') |
| 5574 | *comp_dir = cp + 1; |
| 5575 | } |
| 5576 | |
| 5577 | if (*name == NULL) |
| 5578 | *name = "<unknown>"; |
| 5579 | } |
| 5580 | |
| 5581 | /* Handle DW_AT_stmt_list for a compilation unit or type unit. |
| 5582 | DIE is the DW_TAG_compile_unit or DW_TAG_type_unit die for CU. |
| 5583 | COMP_DIR is the compilation directory. |
| 5584 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ |
| 5585 | |
| 5586 | static void |
| 5587 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, |
| 5588 | const char *comp_dir, int want_line_info) |
| 5589 | { |
| 5590 | struct attribute *attr; |
| 5591 | struct objfile *objfile = cu->objfile; |
| 5592 | bfd *abfd = objfile->obfd; |
| 5593 | |
| 5594 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 5595 | if (attr) |
| 5596 | { |
| 5597 | unsigned int line_offset = DW_UNSND (attr); |
| 5598 | struct line_header *line_header |
| 5599 | = dwarf_decode_line_header (line_offset, abfd, cu); |
| 5600 | |
| 5601 | if (line_header) |
| 5602 | { |
| 5603 | cu->line_header = line_header; |
| 5604 | make_cleanup (free_cu_line_header, cu); |
| 5605 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, want_line_info); |
| 5606 | } |
| 5607 | } |
| 5608 | } |
| 5609 | |
| 5610 | /* Process DW_TAG_compile_unit. */ |
| 5611 | |
| 5612 | static void |
| 5613 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5614 | { |
| 5615 | struct objfile *objfile = cu->objfile; |
| 5616 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 5617 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
| 5618 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
| 5619 | struct attribute *attr; |
| 5620 | char *name = NULL; |
| 5621 | char *comp_dir = NULL; |
| 5622 | struct die_info *child_die; |
| 5623 | bfd *abfd = objfile->obfd; |
| 5624 | CORE_ADDR baseaddr; |
| 5625 | |
| 5626 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5627 | |
| 5628 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
| 5629 | |
| 5630 | /* If we didn't find a lowpc, set it to highpc to avoid complaints |
| 5631 | from finish_block. */ |
| 5632 | if (lowpc == ((CORE_ADDR) -1)) |
| 5633 | lowpc = highpc; |
| 5634 | lowpc += baseaddr; |
| 5635 | highpc += baseaddr; |
| 5636 | |
| 5637 | find_file_and_directory (die, cu, &name, &comp_dir); |
| 5638 | |
| 5639 | attr = dwarf2_attr (die, DW_AT_language, cu); |
| 5640 | if (attr) |
| 5641 | { |
| 5642 | set_cu_language (DW_UNSND (attr), cu); |
| 5643 | } |
| 5644 | |
| 5645 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
| 5646 | if (attr) |
| 5647 | cu->producer = DW_STRING (attr); |
| 5648 | |
| 5649 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
| 5650 | standardised yet. As a workaround for the language detection we fall |
| 5651 | back to the DW_AT_producer string. */ |
| 5652 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) |
| 5653 | cu->language = language_opencl; |
| 5654 | |
| 5655 | /* We assume that we're processing GCC output. */ |
| 5656 | processing_gcc_compilation = 2; |
| 5657 | |
| 5658 | processing_has_namespace_info = 0; |
| 5659 | |
| 5660 | start_symtab (name, comp_dir, lowpc); |
| 5661 | record_debugformat ("DWARF 2"); |
| 5662 | record_producer (cu->producer); |
| 5663 | |
| 5664 | /* Decode line number information if present. We do this before |
| 5665 | processing child DIEs, so that the line header table is available |
| 5666 | for DW_AT_decl_file. */ |
| 5667 | handle_DW_AT_stmt_list (die, cu, comp_dir, 1); |
| 5668 | |
| 5669 | /* Process all dies in compilation unit. */ |
| 5670 | if (die->child != NULL) |
| 5671 | { |
| 5672 | child_die = die->child; |
| 5673 | while (child_die && child_die->tag) |
| 5674 | { |
| 5675 | process_die (child_die, cu); |
| 5676 | child_die = sibling_die (child_die); |
| 5677 | } |
| 5678 | } |
| 5679 | |
| 5680 | /* Decode macro information, if present. Dwarf 2 macro information |
| 5681 | refers to information in the line number info statement program |
| 5682 | header, so we can only read it if we've read the header |
| 5683 | successfully. */ |
| 5684 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
| 5685 | if (attr && cu->line_header) |
| 5686 | { |
| 5687 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
| 5688 | complaint (&symfile_complaints, |
| 5689 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); |
| 5690 | |
| 5691 | dwarf_decode_macros (cu->line_header, DW_UNSND (attr), |
| 5692 | comp_dir, abfd, cu, |
| 5693 | &dwarf2_per_objfile->macro, 1); |
| 5694 | } |
| 5695 | else |
| 5696 | { |
| 5697 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
| 5698 | if (attr && cu->line_header) |
| 5699 | { |
| 5700 | unsigned int macro_offset = DW_UNSND (attr); |
| 5701 | |
| 5702 | dwarf_decode_macros (cu->line_header, macro_offset, |
| 5703 | comp_dir, abfd, cu, |
| 5704 | &dwarf2_per_objfile->macinfo, 0); |
| 5705 | } |
| 5706 | } |
| 5707 | |
| 5708 | do_cleanups (back_to); |
| 5709 | } |
| 5710 | |
| 5711 | /* Process DW_TAG_type_unit. |
| 5712 | For TUs we want to skip the first top level sibling if it's not the |
| 5713 | actual type being defined by this TU. In this case the first top |
| 5714 | level sibling is there to provide context only. */ |
| 5715 | |
| 5716 | static void |
| 5717 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5718 | { |
| 5719 | struct objfile *objfile = cu->objfile; |
| 5720 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 5721 | CORE_ADDR lowpc; |
| 5722 | struct attribute *attr; |
| 5723 | char *name = NULL; |
| 5724 | char *comp_dir = NULL; |
| 5725 | struct die_info *child_die; |
| 5726 | bfd *abfd = objfile->obfd; |
| 5727 | |
| 5728 | /* start_symtab needs a low pc, but we don't really have one. |
| 5729 | Do what read_file_scope would do in the absence of such info. */ |
| 5730 | lowpc = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5731 | |
| 5732 | /* Find the filename. Do not use dwarf2_name here, since the filename |
| 5733 | is not a source language identifier. */ |
| 5734 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 5735 | if (attr) |
| 5736 | name = DW_STRING (attr); |
| 5737 | |
| 5738 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
| 5739 | if (attr) |
| 5740 | comp_dir = DW_STRING (attr); |
| 5741 | else if (name != NULL && IS_ABSOLUTE_PATH (name)) |
| 5742 | { |
| 5743 | comp_dir = ldirname (name); |
| 5744 | if (comp_dir != NULL) |
| 5745 | make_cleanup (xfree, comp_dir); |
| 5746 | } |
| 5747 | |
| 5748 | if (name == NULL) |
| 5749 | name = "<unknown>"; |
| 5750 | |
| 5751 | attr = dwarf2_attr (die, DW_AT_language, cu); |
| 5752 | if (attr) |
| 5753 | set_cu_language (DW_UNSND (attr), cu); |
| 5754 | |
| 5755 | /* This isn't technically needed today. It is done for symmetry |
| 5756 | with read_file_scope. */ |
| 5757 | attr = dwarf2_attr (die, DW_AT_producer, cu); |
| 5758 | if (attr) |
| 5759 | cu->producer = DW_STRING (attr); |
| 5760 | |
| 5761 | /* We assume that we're processing GCC output. */ |
| 5762 | processing_gcc_compilation = 2; |
| 5763 | |
| 5764 | processing_has_namespace_info = 0; |
| 5765 | |
| 5766 | start_symtab (name, comp_dir, lowpc); |
| 5767 | record_debugformat ("DWARF 2"); |
| 5768 | record_producer (cu->producer); |
| 5769 | |
| 5770 | /* Decode line number information if present. We do this before |
| 5771 | processing child DIEs, so that the line header table is available |
| 5772 | for DW_AT_decl_file. |
| 5773 | We don't need the pc/line-number mapping for type units. */ |
| 5774 | handle_DW_AT_stmt_list (die, cu, comp_dir, 0); |
| 5775 | |
| 5776 | /* Process the dies in the type unit. */ |
| 5777 | if (die->child == NULL) |
| 5778 | { |
| 5779 | dump_die_for_error (die); |
| 5780 | error (_("Dwarf Error: Missing children for type unit [in module %s]"), |
| 5781 | bfd_get_filename (abfd)); |
| 5782 | } |
| 5783 | |
| 5784 | child_die = die->child; |
| 5785 | |
| 5786 | while (child_die && child_die->tag) |
| 5787 | { |
| 5788 | process_die (child_die, cu); |
| 5789 | |
| 5790 | child_die = sibling_die (child_die); |
| 5791 | } |
| 5792 | |
| 5793 | do_cleanups (back_to); |
| 5794 | } |
| 5795 | |
| 5796 | /* qsort helper for inherit_abstract_dies. */ |
| 5797 | |
| 5798 | static int |
| 5799 | unsigned_int_compar (const void *ap, const void *bp) |
| 5800 | { |
| 5801 | unsigned int a = *(unsigned int *) ap; |
| 5802 | unsigned int b = *(unsigned int *) bp; |
| 5803 | |
| 5804 | return (a > b) - (b > a); |
| 5805 | } |
| 5806 | |
| 5807 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). |
| 5808 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
| 5809 | already referenced by DW_AT_abstract_origin from the children of the |
| 5810 | current DIE. */ |
| 5811 | |
| 5812 | static void |
| 5813 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) |
| 5814 | { |
| 5815 | struct die_info *child_die; |
| 5816 | unsigned die_children_count; |
| 5817 | /* CU offsets which were referenced by children of the current DIE. */ |
| 5818 | unsigned *offsets; |
| 5819 | unsigned *offsets_end, *offsetp; |
| 5820 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
| 5821 | struct die_info *origin_die; |
| 5822 | /* Iterator of the ORIGIN_DIE children. */ |
| 5823 | struct die_info *origin_child_die; |
| 5824 | struct cleanup *cleanups; |
| 5825 | struct attribute *attr; |
| 5826 | struct dwarf2_cu *origin_cu; |
| 5827 | struct pending **origin_previous_list_in_scope; |
| 5828 | |
| 5829 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); |
| 5830 | if (!attr) |
| 5831 | return; |
| 5832 | |
| 5833 | /* Note that following die references may follow to a die in a |
| 5834 | different cu. */ |
| 5835 | |
| 5836 | origin_cu = cu; |
| 5837 | origin_die = follow_die_ref (die, attr, &origin_cu); |
| 5838 | |
| 5839 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's |
| 5840 | symbols in. */ |
| 5841 | origin_previous_list_in_scope = origin_cu->list_in_scope; |
| 5842 | origin_cu->list_in_scope = cu->list_in_scope; |
| 5843 | |
| 5844 | if (die->tag != origin_die->tag |
| 5845 | && !(die->tag == DW_TAG_inlined_subroutine |
| 5846 | && origin_die->tag == DW_TAG_subprogram)) |
| 5847 | complaint (&symfile_complaints, |
| 5848 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), |
| 5849 | die->offset, origin_die->offset); |
| 5850 | |
| 5851 | child_die = die->child; |
| 5852 | die_children_count = 0; |
| 5853 | while (child_die && child_die->tag) |
| 5854 | { |
| 5855 | child_die = sibling_die (child_die); |
| 5856 | die_children_count++; |
| 5857 | } |
| 5858 | offsets = xmalloc (sizeof (*offsets) * die_children_count); |
| 5859 | cleanups = make_cleanup (xfree, offsets); |
| 5860 | |
| 5861 | offsets_end = offsets; |
| 5862 | child_die = die->child; |
| 5863 | while (child_die && child_die->tag) |
| 5864 | { |
| 5865 | /* For each CHILD_DIE, find the corresponding child of |
| 5866 | ORIGIN_DIE. If there is more than one layer of |
| 5867 | DW_AT_abstract_origin, follow them all; there shouldn't be, |
| 5868 | but GCC versions at least through 4.4 generate this (GCC PR |
| 5869 | 40573). */ |
| 5870 | struct die_info *child_origin_die = child_die; |
| 5871 | struct dwarf2_cu *child_origin_cu = cu; |
| 5872 | |
| 5873 | while (1) |
| 5874 | { |
| 5875 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
| 5876 | child_origin_cu); |
| 5877 | if (attr == NULL) |
| 5878 | break; |
| 5879 | child_origin_die = follow_die_ref (child_origin_die, attr, |
| 5880 | &child_origin_cu); |
| 5881 | } |
| 5882 | |
| 5883 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
| 5884 | counterpart may exist. */ |
| 5885 | if (child_origin_die != child_die) |
| 5886 | { |
| 5887 | if (child_die->tag != child_origin_die->tag |
| 5888 | && !(child_die->tag == DW_TAG_inlined_subroutine |
| 5889 | && child_origin_die->tag == DW_TAG_subprogram)) |
| 5890 | complaint (&symfile_complaints, |
| 5891 | _("Child DIE 0x%x and its abstract origin 0x%x have " |
| 5892 | "different tags"), child_die->offset, |
| 5893 | child_origin_die->offset); |
| 5894 | if (child_origin_die->parent != origin_die) |
| 5895 | complaint (&symfile_complaints, |
| 5896 | _("Child DIE 0x%x and its abstract origin 0x%x have " |
| 5897 | "different parents"), child_die->offset, |
| 5898 | child_origin_die->offset); |
| 5899 | else |
| 5900 | *offsets_end++ = child_origin_die->offset; |
| 5901 | } |
| 5902 | child_die = sibling_die (child_die); |
| 5903 | } |
| 5904 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), |
| 5905 | unsigned_int_compar); |
| 5906 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) |
| 5907 | if (offsetp[-1] == *offsetp) |
| 5908 | complaint (&symfile_complaints, |
| 5909 | _("Multiple children of DIE 0x%x refer " |
| 5910 | "to DIE 0x%x as their abstract origin"), |
| 5911 | die->offset, *offsetp); |
| 5912 | |
| 5913 | offsetp = offsets; |
| 5914 | origin_child_die = origin_die->child; |
| 5915 | while (origin_child_die && origin_child_die->tag) |
| 5916 | { |
| 5917 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ |
| 5918 | while (offsetp < offsets_end && *offsetp < origin_child_die->offset) |
| 5919 | offsetp++; |
| 5920 | if (offsetp >= offsets_end || *offsetp > origin_child_die->offset) |
| 5921 | { |
| 5922 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ |
| 5923 | process_die (origin_child_die, origin_cu); |
| 5924 | } |
| 5925 | origin_child_die = sibling_die (origin_child_die); |
| 5926 | } |
| 5927 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
| 5928 | |
| 5929 | do_cleanups (cleanups); |
| 5930 | } |
| 5931 | |
| 5932 | static void |
| 5933 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 5934 | { |
| 5935 | struct objfile *objfile = cu->objfile; |
| 5936 | struct context_stack *new; |
| 5937 | CORE_ADDR lowpc; |
| 5938 | CORE_ADDR highpc; |
| 5939 | struct die_info *child_die; |
| 5940 | struct attribute *attr, *call_line, *call_file; |
| 5941 | char *name; |
| 5942 | CORE_ADDR baseaddr; |
| 5943 | struct block *block; |
| 5944 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
| 5945 | VEC (symbolp) *template_args = NULL; |
| 5946 | struct template_symbol *templ_func = NULL; |
| 5947 | |
| 5948 | if (inlined_func) |
| 5949 | { |
| 5950 | /* If we do not have call site information, we can't show the |
| 5951 | caller of this inlined function. That's too confusing, so |
| 5952 | only use the scope for local variables. */ |
| 5953 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); |
| 5954 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); |
| 5955 | if (call_line == NULL || call_file == NULL) |
| 5956 | { |
| 5957 | read_lexical_block_scope (die, cu); |
| 5958 | return; |
| 5959 | } |
| 5960 | } |
| 5961 | |
| 5962 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5963 | |
| 5964 | name = dwarf2_name (die, cu); |
| 5965 | |
| 5966 | /* Ignore functions with missing or empty names. These are actually |
| 5967 | illegal according to the DWARF standard. */ |
| 5968 | if (name == NULL) |
| 5969 | { |
| 5970 | complaint (&symfile_complaints, |
| 5971 | _("missing name for subprogram DIE at %d"), die->offset); |
| 5972 | return; |
| 5973 | } |
| 5974 | |
| 5975 | /* Ignore functions with missing or invalid low and high pc attributes. */ |
| 5976 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
| 5977 | { |
| 5978 | attr = dwarf2_attr (die, DW_AT_external, cu); |
| 5979 | if (!attr || !DW_UNSND (attr)) |
| 5980 | complaint (&symfile_complaints, |
| 5981 | _("cannot get low and high bounds " |
| 5982 | "for subprogram DIE at %d"), |
| 5983 | die->offset); |
| 5984 | return; |
| 5985 | } |
| 5986 | |
| 5987 | lowpc += baseaddr; |
| 5988 | highpc += baseaddr; |
| 5989 | |
| 5990 | /* If we have any template arguments, then we must allocate a |
| 5991 | different sort of symbol. */ |
| 5992 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) |
| 5993 | { |
| 5994 | if (child_die->tag == DW_TAG_template_type_param |
| 5995 | || child_die->tag == DW_TAG_template_value_param) |
| 5996 | { |
| 5997 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 5998 | struct template_symbol); |
| 5999 | templ_func->base.is_cplus_template_function = 1; |
| 6000 | break; |
| 6001 | } |
| 6002 | } |
| 6003 | |
| 6004 | new = push_context (0, lowpc); |
| 6005 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
| 6006 | (struct symbol *) templ_func); |
| 6007 | |
| 6008 | /* If there is a location expression for DW_AT_frame_base, record |
| 6009 | it. */ |
| 6010 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
| 6011 | if (attr) |
| 6012 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
| 6013 | expression is being recorded directly in the function's symbol |
| 6014 | and not in a separate frame-base object. I guess this hack is |
| 6015 | to avoid adding some sort of frame-base adjunct/annex to the |
| 6016 | function's symbol :-(. The problem with doing this is that it |
| 6017 | results in a function symbol with a location expression that |
| 6018 | has nothing to do with the location of the function, ouch! The |
| 6019 | relationship should be: a function's symbol has-a frame base; a |
| 6020 | frame-base has-a location expression. */ |
| 6021 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
| 6022 | |
| 6023 | cu->list_in_scope = &local_symbols; |
| 6024 | |
| 6025 | if (die->child != NULL) |
| 6026 | { |
| 6027 | child_die = die->child; |
| 6028 | while (child_die && child_die->tag) |
| 6029 | { |
| 6030 | if (child_die->tag == DW_TAG_template_type_param |
| 6031 | || child_die->tag == DW_TAG_template_value_param) |
| 6032 | { |
| 6033 | struct symbol *arg = new_symbol (child_die, NULL, cu); |
| 6034 | |
| 6035 | if (arg != NULL) |
| 6036 | VEC_safe_push (symbolp, template_args, arg); |
| 6037 | } |
| 6038 | else |
| 6039 | process_die (child_die, cu); |
| 6040 | child_die = sibling_die (child_die); |
| 6041 | } |
| 6042 | } |
| 6043 | |
| 6044 | inherit_abstract_dies (die, cu); |
| 6045 | |
| 6046 | /* If we have a DW_AT_specification, we might need to import using |
| 6047 | directives from the context of the specification DIE. See the |
| 6048 | comment in determine_prefix. */ |
| 6049 | if (cu->language == language_cplus |
| 6050 | && dwarf2_attr (die, DW_AT_specification, cu)) |
| 6051 | { |
| 6052 | struct dwarf2_cu *spec_cu = cu; |
| 6053 | struct die_info *spec_die = die_specification (die, &spec_cu); |
| 6054 | |
| 6055 | while (spec_die) |
| 6056 | { |
| 6057 | child_die = spec_die->child; |
| 6058 | while (child_die && child_die->tag) |
| 6059 | { |
| 6060 | if (child_die->tag == DW_TAG_imported_module) |
| 6061 | process_die (child_die, spec_cu); |
| 6062 | child_die = sibling_die (child_die); |
| 6063 | } |
| 6064 | |
| 6065 | /* In some cases, GCC generates specification DIEs that |
| 6066 | themselves contain DW_AT_specification attributes. */ |
| 6067 | spec_die = die_specification (spec_die, &spec_cu); |
| 6068 | } |
| 6069 | } |
| 6070 | |
| 6071 | new = pop_context (); |
| 6072 | /* Make a block for the local symbols within. */ |
| 6073 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
| 6074 | lowpc, highpc, objfile); |
| 6075 | |
| 6076 | /* For C++, set the block's scope. */ |
| 6077 | if (cu->language == language_cplus || cu->language == language_fortran) |
| 6078 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
| 6079 | determine_prefix (die, cu), |
| 6080 | processing_has_namespace_info); |
| 6081 | |
| 6082 | /* If we have address ranges, record them. */ |
| 6083 | dwarf2_record_block_ranges (die, block, baseaddr, cu); |
| 6084 | |
| 6085 | /* Attach template arguments to function. */ |
| 6086 | if (! VEC_empty (symbolp, template_args)) |
| 6087 | { |
| 6088 | gdb_assert (templ_func != NULL); |
| 6089 | |
| 6090 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); |
| 6091 | templ_func->template_arguments |
| 6092 | = obstack_alloc (&objfile->objfile_obstack, |
| 6093 | (templ_func->n_template_arguments |
| 6094 | * sizeof (struct symbol *))); |
| 6095 | memcpy (templ_func->template_arguments, |
| 6096 | VEC_address (symbolp, template_args), |
| 6097 | (templ_func->n_template_arguments * sizeof (struct symbol *))); |
| 6098 | VEC_free (symbolp, template_args); |
| 6099 | } |
| 6100 | |
| 6101 | /* In C++, we can have functions nested inside functions (e.g., when |
| 6102 | a function declares a class that has methods). This means that |
| 6103 | when we finish processing a function scope, we may need to go |
| 6104 | back to building a containing block's symbol lists. */ |
| 6105 | local_symbols = new->locals; |
| 6106 | param_symbols = new->params; |
| 6107 | using_directives = new->using_directives; |
| 6108 | |
| 6109 | /* If we've finished processing a top-level function, subsequent |
| 6110 | symbols go in the file symbol list. */ |
| 6111 | if (outermost_context_p ()) |
| 6112 | cu->list_in_scope = &file_symbols; |
| 6113 | } |
| 6114 | |
| 6115 | /* Process all the DIES contained within a lexical block scope. Start |
| 6116 | a new scope, process the dies, and then close the scope. */ |
| 6117 | |
| 6118 | static void |
| 6119 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 6120 | { |
| 6121 | struct objfile *objfile = cu->objfile; |
| 6122 | struct context_stack *new; |
| 6123 | CORE_ADDR lowpc, highpc; |
| 6124 | struct die_info *child_die; |
| 6125 | CORE_ADDR baseaddr; |
| 6126 | |
| 6127 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 6128 | |
| 6129 | /* Ignore blocks with missing or invalid low and high pc attributes. */ |
| 6130 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
| 6131 | as multiple lexical blocks? Handling children in a sane way would |
| 6132 | be nasty. Might be easier to properly extend generic blocks to |
| 6133 | describe ranges. */ |
| 6134 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
| 6135 | return; |
| 6136 | lowpc += baseaddr; |
| 6137 | highpc += baseaddr; |
| 6138 | |
| 6139 | push_context (0, lowpc); |
| 6140 | if (die->child != NULL) |
| 6141 | { |
| 6142 | child_die = die->child; |
| 6143 | while (child_die && child_die->tag) |
| 6144 | { |
| 6145 | process_die (child_die, cu); |
| 6146 | child_die = sibling_die (child_die); |
| 6147 | } |
| 6148 | } |
| 6149 | new = pop_context (); |
| 6150 | |
| 6151 | if (local_symbols != NULL || using_directives != NULL) |
| 6152 | { |
| 6153 | struct block *block |
| 6154 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, |
| 6155 | highpc, objfile); |
| 6156 | |
| 6157 | /* Note that recording ranges after traversing children, as we |
| 6158 | do here, means that recording a parent's ranges entails |
| 6159 | walking across all its children's ranges as they appear in |
| 6160 | the address map, which is quadratic behavior. |
| 6161 | |
| 6162 | It would be nicer to record the parent's ranges before |
| 6163 | traversing its children, simply overriding whatever you find |
| 6164 | there. But since we don't even decide whether to create a |
| 6165 | block until after we've traversed its children, that's hard |
| 6166 | to do. */ |
| 6167 | dwarf2_record_block_ranges (die, block, baseaddr, cu); |
| 6168 | } |
| 6169 | local_symbols = new->locals; |
| 6170 | using_directives = new->using_directives; |
| 6171 | } |
| 6172 | |
| 6173 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
| 6174 | |
| 6175 | static void |
| 6176 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 6177 | { |
| 6178 | struct objfile *objfile = cu->objfile; |
| 6179 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 6180 | CORE_ADDR pc, baseaddr; |
| 6181 | struct attribute *attr; |
| 6182 | struct call_site *call_site, call_site_local; |
| 6183 | void **slot; |
| 6184 | int nparams; |
| 6185 | struct die_info *child_die; |
| 6186 | |
| 6187 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 6188 | |
| 6189 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 6190 | if (!attr) |
| 6191 | { |
| 6192 | complaint (&symfile_complaints, |
| 6193 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " |
| 6194 | "DIE 0x%x [in module %s]"), |
| 6195 | die->offset, objfile->name); |
| 6196 | return; |
| 6197 | } |
| 6198 | pc = DW_ADDR (attr) + baseaddr; |
| 6199 | |
| 6200 | if (cu->call_site_htab == NULL) |
| 6201 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, |
| 6202 | NULL, &objfile->objfile_obstack, |
| 6203 | hashtab_obstack_allocate, NULL); |
| 6204 | call_site_local.pc = pc; |
| 6205 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); |
| 6206 | if (*slot != NULL) |
| 6207 | { |
| 6208 | complaint (&symfile_complaints, |
| 6209 | _("Duplicate PC %s for DW_TAG_GNU_call_site " |
| 6210 | "DIE 0x%x [in module %s]"), |
| 6211 | paddress (gdbarch, pc), die->offset, objfile->name); |
| 6212 | return; |
| 6213 | } |
| 6214 | |
| 6215 | /* Count parameters at the caller. */ |
| 6216 | |
| 6217 | nparams = 0; |
| 6218 | for (child_die = die->child; child_die && child_die->tag; |
| 6219 | child_die = sibling_die (child_die)) |
| 6220 | { |
| 6221 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) |
| 6222 | { |
| 6223 | complaint (&symfile_complaints, |
| 6224 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " |
| 6225 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 6226 | child_die->tag, child_die->offset, objfile->name); |
| 6227 | continue; |
| 6228 | } |
| 6229 | |
| 6230 | nparams++; |
| 6231 | } |
| 6232 | |
| 6233 | call_site = obstack_alloc (&objfile->objfile_obstack, |
| 6234 | (sizeof (*call_site) |
| 6235 | + (sizeof (*call_site->parameter) |
| 6236 | * (nparams - 1)))); |
| 6237 | *slot = call_site; |
| 6238 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); |
| 6239 | call_site->pc = pc; |
| 6240 | |
| 6241 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) |
| 6242 | { |
| 6243 | struct die_info *func_die; |
| 6244 | |
| 6245 | /* Skip also over DW_TAG_inlined_subroutine. */ |
| 6246 | for (func_die = die->parent; |
| 6247 | func_die && func_die->tag != DW_TAG_subprogram |
| 6248 | && func_die->tag != DW_TAG_subroutine_type; |
| 6249 | func_die = func_die->parent); |
| 6250 | |
| 6251 | /* DW_AT_GNU_all_call_sites is a superset |
| 6252 | of DW_AT_GNU_all_tail_call_sites. */ |
| 6253 | if (func_die |
| 6254 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) |
| 6255 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) |
| 6256 | { |
| 6257 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is |
| 6258 | not complete. But keep CALL_SITE for look ups via call_site_htab, |
| 6259 | both the initial caller containing the real return address PC and |
| 6260 | the final callee containing the current PC of a chain of tail |
| 6261 | calls do not need to have the tail call list complete. But any |
| 6262 | function candidate for a virtual tail call frame searched via |
| 6263 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be |
| 6264 | determined unambiguously. */ |
| 6265 | } |
| 6266 | else |
| 6267 | { |
| 6268 | struct type *func_type = NULL; |
| 6269 | |
| 6270 | if (func_die) |
| 6271 | func_type = get_die_type (func_die, cu); |
| 6272 | if (func_type != NULL) |
| 6273 | { |
| 6274 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); |
| 6275 | |
| 6276 | /* Enlist this call site to the function. */ |
| 6277 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); |
| 6278 | TYPE_TAIL_CALL_LIST (func_type) = call_site; |
| 6279 | } |
| 6280 | else |
| 6281 | complaint (&symfile_complaints, |
| 6282 | _("Cannot find function owning DW_TAG_GNU_call_site " |
| 6283 | "DIE 0x%x [in module %s]"), |
| 6284 | die->offset, objfile->name); |
| 6285 | } |
| 6286 | } |
| 6287 | |
| 6288 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); |
| 6289 | if (attr == NULL) |
| 6290 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); |
| 6291 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); |
| 6292 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) |
| 6293 | /* Keep NULL DWARF_BLOCK. */; |
| 6294 | else if (attr_form_is_block (attr)) |
| 6295 | { |
| 6296 | struct dwarf2_locexpr_baton *dlbaton; |
| 6297 | |
| 6298 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); |
| 6299 | dlbaton->data = DW_BLOCK (attr)->data; |
| 6300 | dlbaton->size = DW_BLOCK (attr)->size; |
| 6301 | dlbaton->per_cu = cu->per_cu; |
| 6302 | |
| 6303 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); |
| 6304 | } |
| 6305 | else if (is_ref_attr (attr)) |
| 6306 | { |
| 6307 | struct dwarf2_cu *target_cu = cu; |
| 6308 | struct die_info *target_die; |
| 6309 | |
| 6310 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); |
| 6311 | gdb_assert (target_cu->objfile == objfile); |
| 6312 | if (die_is_declaration (target_die, target_cu)) |
| 6313 | { |
| 6314 | const char *target_physname; |
| 6315 | |
| 6316 | target_physname = dwarf2_physname (NULL, target_die, target_cu); |
| 6317 | if (target_physname == NULL) |
| 6318 | complaint (&symfile_complaints, |
| 6319 | _("DW_AT_GNU_call_site_target target DIE has invalid " |
| 6320 | "physname, for referencing DIE 0x%x [in module %s]"), |
| 6321 | die->offset, objfile->name); |
| 6322 | else |
| 6323 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); |
| 6324 | } |
| 6325 | else |
| 6326 | { |
| 6327 | CORE_ADDR lowpc; |
| 6328 | |
| 6329 | /* DW_AT_entry_pc should be preferred. */ |
| 6330 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) |
| 6331 | complaint (&symfile_complaints, |
| 6332 | _("DW_AT_GNU_call_site_target target DIE has invalid " |
| 6333 | "low pc, for referencing DIE 0x%x [in module %s]"), |
| 6334 | die->offset, objfile->name); |
| 6335 | else |
| 6336 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); |
| 6337 | } |
| 6338 | } |
| 6339 | else |
| 6340 | complaint (&symfile_complaints, |
| 6341 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " |
| 6342 | "block nor reference, for DIE 0x%x [in module %s]"), |
| 6343 | die->offset, objfile->name); |
| 6344 | |
| 6345 | call_site->per_cu = cu->per_cu; |
| 6346 | |
| 6347 | for (child_die = die->child; |
| 6348 | child_die && child_die->tag; |
| 6349 | child_die = sibling_die (child_die)) |
| 6350 | { |
| 6351 | struct dwarf2_locexpr_baton *dlbaton; |
| 6352 | struct call_site_parameter *parameter; |
| 6353 | |
| 6354 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) |
| 6355 | { |
| 6356 | /* Already printed the complaint above. */ |
| 6357 | continue; |
| 6358 | } |
| 6359 | |
| 6360 | gdb_assert (call_site->parameter_count < nparams); |
| 6361 | parameter = &call_site->parameter[call_site->parameter_count]; |
| 6362 | |
| 6363 | /* DW_AT_location specifies the register number. Value of the data |
| 6364 | assumed for the register is contained in DW_AT_GNU_call_site_value. */ |
| 6365 | |
| 6366 | attr = dwarf2_attr (child_die, DW_AT_location, cu); |
| 6367 | if (!attr || !attr_form_is_block (attr)) |
| 6368 | { |
| 6369 | complaint (&symfile_complaints, |
| 6370 | _("No DW_FORM_block* DW_AT_location for " |
| 6371 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 6372 | child_die->offset, objfile->name); |
| 6373 | continue; |
| 6374 | } |
| 6375 | parameter->dwarf_reg = dwarf_block_to_dwarf_reg (DW_BLOCK (attr)->data, |
| 6376 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size]); |
| 6377 | if (parameter->dwarf_reg == -1 |
| 6378 | && !dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (attr)->data, |
| 6379 | &DW_BLOCK (attr)->data[DW_BLOCK (attr)->size], |
| 6380 | ¶meter->fb_offset)) |
| 6381 | { |
| 6382 | complaint (&symfile_complaints, |
| 6383 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " |
| 6384 | "for DW_FORM_block* DW_AT_location for " |
| 6385 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 6386 | child_die->offset, objfile->name); |
| 6387 | continue; |
| 6388 | } |
| 6389 | |
| 6390 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); |
| 6391 | if (!attr_form_is_block (attr)) |
| 6392 | { |
| 6393 | complaint (&symfile_complaints, |
| 6394 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " |
| 6395 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 6396 | child_die->offset, objfile->name); |
| 6397 | continue; |
| 6398 | } |
| 6399 | parameter->value = DW_BLOCK (attr)->data; |
| 6400 | parameter->value_size = DW_BLOCK (attr)->size; |
| 6401 | |
| 6402 | /* Parameters are not pre-cleared by memset above. */ |
| 6403 | parameter->data_value = NULL; |
| 6404 | parameter->data_value_size = 0; |
| 6405 | call_site->parameter_count++; |
| 6406 | |
| 6407 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); |
| 6408 | if (attr) |
| 6409 | { |
| 6410 | if (!attr_form_is_block (attr)) |
| 6411 | complaint (&symfile_complaints, |
| 6412 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " |
| 6413 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 6414 | child_die->offset, objfile->name); |
| 6415 | else |
| 6416 | { |
| 6417 | parameter->data_value = DW_BLOCK (attr)->data; |
| 6418 | parameter->data_value_size = DW_BLOCK (attr)->size; |
| 6419 | } |
| 6420 | } |
| 6421 | } |
| 6422 | } |
| 6423 | |
| 6424 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
| 6425 | Return 1 if the attributes are present and valid, otherwise, return 0. |
| 6426 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ |
| 6427 | |
| 6428 | static int |
| 6429 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, |
| 6430 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
| 6431 | struct partial_symtab *ranges_pst) |
| 6432 | { |
| 6433 | struct objfile *objfile = cu->objfile; |
| 6434 | struct comp_unit_head *cu_header = &cu->header; |
| 6435 | bfd *obfd = objfile->obfd; |
| 6436 | unsigned int addr_size = cu_header->addr_size; |
| 6437 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 6438 | /* Base address selection entry. */ |
| 6439 | CORE_ADDR base; |
| 6440 | int found_base; |
| 6441 | unsigned int dummy; |
| 6442 | gdb_byte *buffer; |
| 6443 | CORE_ADDR marker; |
| 6444 | int low_set; |
| 6445 | CORE_ADDR low = 0; |
| 6446 | CORE_ADDR high = 0; |
| 6447 | CORE_ADDR baseaddr; |
| 6448 | |
| 6449 | found_base = cu->base_known; |
| 6450 | base = cu->base_address; |
| 6451 | |
| 6452 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
| 6453 | if (offset >= dwarf2_per_objfile->ranges.size) |
| 6454 | { |
| 6455 | complaint (&symfile_complaints, |
| 6456 | _("Offset %d out of bounds for DW_AT_ranges attribute"), |
| 6457 | offset); |
| 6458 | return 0; |
| 6459 | } |
| 6460 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
| 6461 | |
| 6462 | /* Read in the largest possible address. */ |
| 6463 | marker = read_address (obfd, buffer, cu, &dummy); |
| 6464 | if ((marker & mask) == mask) |
| 6465 | { |
| 6466 | /* If we found the largest possible address, then |
| 6467 | read the base address. */ |
| 6468 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
| 6469 | buffer += 2 * addr_size; |
| 6470 | offset += 2 * addr_size; |
| 6471 | found_base = 1; |
| 6472 | } |
| 6473 | |
| 6474 | low_set = 0; |
| 6475 | |
| 6476 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 6477 | |
| 6478 | while (1) |
| 6479 | { |
| 6480 | CORE_ADDR range_beginning, range_end; |
| 6481 | |
| 6482 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
| 6483 | buffer += addr_size; |
| 6484 | range_end = read_address (obfd, buffer, cu, &dummy); |
| 6485 | buffer += addr_size; |
| 6486 | offset += 2 * addr_size; |
| 6487 | |
| 6488 | /* An end of list marker is a pair of zero addresses. */ |
| 6489 | if (range_beginning == 0 && range_end == 0) |
| 6490 | /* Found the end of list entry. */ |
| 6491 | break; |
| 6492 | |
| 6493 | /* Each base address selection entry is a pair of 2 values. |
| 6494 | The first is the largest possible address, the second is |
| 6495 | the base address. Check for a base address here. */ |
| 6496 | if ((range_beginning & mask) == mask) |
| 6497 | { |
| 6498 | /* If we found the largest possible address, then |
| 6499 | read the base address. */ |
| 6500 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
| 6501 | found_base = 1; |
| 6502 | continue; |
| 6503 | } |
| 6504 | |
| 6505 | if (!found_base) |
| 6506 | { |
| 6507 | /* We have no valid base address for the ranges |
| 6508 | data. */ |
| 6509 | complaint (&symfile_complaints, |
| 6510 | _("Invalid .debug_ranges data (no base address)")); |
| 6511 | return 0; |
| 6512 | } |
| 6513 | |
| 6514 | if (range_beginning > range_end) |
| 6515 | { |
| 6516 | /* Inverted range entries are invalid. */ |
| 6517 | complaint (&symfile_complaints, |
| 6518 | _("Invalid .debug_ranges data (inverted range)")); |
| 6519 | return 0; |
| 6520 | } |
| 6521 | |
| 6522 | /* Empty range entries have no effect. */ |
| 6523 | if (range_beginning == range_end) |
| 6524 | continue; |
| 6525 | |
| 6526 | range_beginning += base; |
| 6527 | range_end += base; |
| 6528 | |
| 6529 | if (ranges_pst != NULL) |
| 6530 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 6531 | range_beginning + baseaddr, |
| 6532 | range_end - 1 + baseaddr, |
| 6533 | ranges_pst); |
| 6534 | |
| 6535 | /* FIXME: This is recording everything as a low-high |
| 6536 | segment of consecutive addresses. We should have a |
| 6537 | data structure for discontiguous block ranges |
| 6538 | instead. */ |
| 6539 | if (! low_set) |
| 6540 | { |
| 6541 | low = range_beginning; |
| 6542 | high = range_end; |
| 6543 | low_set = 1; |
| 6544 | } |
| 6545 | else |
| 6546 | { |
| 6547 | if (range_beginning < low) |
| 6548 | low = range_beginning; |
| 6549 | if (range_end > high) |
| 6550 | high = range_end; |
| 6551 | } |
| 6552 | } |
| 6553 | |
| 6554 | if (! low_set) |
| 6555 | /* If the first entry is an end-of-list marker, the range |
| 6556 | describes an empty scope, i.e. no instructions. */ |
| 6557 | return 0; |
| 6558 | |
| 6559 | if (low_return) |
| 6560 | *low_return = low; |
| 6561 | if (high_return) |
| 6562 | *high_return = high; |
| 6563 | return 1; |
| 6564 | } |
| 6565 | |
| 6566 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
| 6567 | are present and valid, otherwise, return 0. Return -1 if the range is |
| 6568 | discontinuous, i.e. derived from DW_AT_ranges information. */ |
| 6569 | static int |
| 6570 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
| 6571 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
| 6572 | struct partial_symtab *pst) |
| 6573 | { |
| 6574 | struct attribute *attr; |
| 6575 | CORE_ADDR low = 0; |
| 6576 | CORE_ADDR high = 0; |
| 6577 | int ret = 0; |
| 6578 | |
| 6579 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
| 6580 | if (attr) |
| 6581 | { |
| 6582 | high = DW_ADDR (attr); |
| 6583 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 6584 | if (attr) |
| 6585 | low = DW_ADDR (attr); |
| 6586 | else |
| 6587 | /* Found high w/o low attribute. */ |
| 6588 | return 0; |
| 6589 | |
| 6590 | /* Found consecutive range of addresses. */ |
| 6591 | ret = 1; |
| 6592 | } |
| 6593 | else |
| 6594 | { |
| 6595 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
| 6596 | if (attr != NULL) |
| 6597 | { |
| 6598 | /* Value of the DW_AT_ranges attribute is the offset in the |
| 6599 | .debug_ranges section. */ |
| 6600 | if (!dwarf2_ranges_read (DW_UNSND (attr), &low, &high, cu, pst)) |
| 6601 | return 0; |
| 6602 | /* Found discontinuous range of addresses. */ |
| 6603 | ret = -1; |
| 6604 | } |
| 6605 | } |
| 6606 | |
| 6607 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
| 6608 | if (high <= low) |
| 6609 | return 0; |
| 6610 | |
| 6611 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 6612 | eliminate duplicate copies of functions and vtables and such. |
| 6613 | The linker will arbitrarily choose one and discard the others. |
| 6614 | The AT_*_pc values for such functions refer to local labels in |
| 6615 | these sections. If the section from that file was discarded, the |
| 6616 | labels are not in the output, so the relocs get a value of 0. |
| 6617 | If this is a discarded function, mark the pc bounds as invalid, |
| 6618 | so that GDB will ignore it. */ |
| 6619 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 6620 | return 0; |
| 6621 | |
| 6622 | *lowpc = low; |
| 6623 | if (highpc) |
| 6624 | *highpc = high; |
| 6625 | return ret; |
| 6626 | } |
| 6627 | |
| 6628 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
| 6629 | its low and high PC addresses. Do nothing if these addresses could not |
| 6630 | be determined. Otherwise, set LOWPC to the low address if it is smaller, |
| 6631 | and HIGHPC to the high address if greater than HIGHPC. */ |
| 6632 | |
| 6633 | static void |
| 6634 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, |
| 6635 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 6636 | struct dwarf2_cu *cu) |
| 6637 | { |
| 6638 | CORE_ADDR low, high; |
| 6639 | struct die_info *child = die->child; |
| 6640 | |
| 6641 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
| 6642 | { |
| 6643 | *lowpc = min (*lowpc, low); |
| 6644 | *highpc = max (*highpc, high); |
| 6645 | } |
| 6646 | |
| 6647 | /* If the language does not allow nested subprograms (either inside |
| 6648 | subprograms or lexical blocks), we're done. */ |
| 6649 | if (cu->language != language_ada) |
| 6650 | return; |
| 6651 | |
| 6652 | /* Check all the children of the given DIE. If it contains nested |
| 6653 | subprograms, then check their pc bounds. Likewise, we need to |
| 6654 | check lexical blocks as well, as they may also contain subprogram |
| 6655 | definitions. */ |
| 6656 | while (child && child->tag) |
| 6657 | { |
| 6658 | if (child->tag == DW_TAG_subprogram |
| 6659 | || child->tag == DW_TAG_lexical_block) |
| 6660 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); |
| 6661 | child = sibling_die (child); |
| 6662 | } |
| 6663 | } |
| 6664 | |
| 6665 | /* Get the low and high pc's represented by the scope DIE, and store |
| 6666 | them in *LOWPC and *HIGHPC. If the correct values can't be |
| 6667 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ |
| 6668 | |
| 6669 | static void |
| 6670 | get_scope_pc_bounds (struct die_info *die, |
| 6671 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 6672 | struct dwarf2_cu *cu) |
| 6673 | { |
| 6674 | CORE_ADDR best_low = (CORE_ADDR) -1; |
| 6675 | CORE_ADDR best_high = (CORE_ADDR) 0; |
| 6676 | CORE_ADDR current_low, current_high; |
| 6677 | |
| 6678 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
| 6679 | { |
| 6680 | best_low = current_low; |
| 6681 | best_high = current_high; |
| 6682 | } |
| 6683 | else |
| 6684 | { |
| 6685 | struct die_info *child = die->child; |
| 6686 | |
| 6687 | while (child && child->tag) |
| 6688 | { |
| 6689 | switch (child->tag) { |
| 6690 | case DW_TAG_subprogram: |
| 6691 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
| 6692 | break; |
| 6693 | case DW_TAG_namespace: |
| 6694 | case DW_TAG_module: |
| 6695 | /* FIXME: carlton/2004-01-16: Should we do this for |
| 6696 | DW_TAG_class_type/DW_TAG_structure_type, too? I think |
| 6697 | that current GCC's always emit the DIEs corresponding |
| 6698 | to definitions of methods of classes as children of a |
| 6699 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to |
| 6700 | the DIEs giving the declarations, which could be |
| 6701 | anywhere). But I don't see any reason why the |
| 6702 | standards says that they have to be there. */ |
| 6703 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); |
| 6704 | |
| 6705 | if (current_low != ((CORE_ADDR) -1)) |
| 6706 | { |
| 6707 | best_low = min (best_low, current_low); |
| 6708 | best_high = max (best_high, current_high); |
| 6709 | } |
| 6710 | break; |
| 6711 | default: |
| 6712 | /* Ignore. */ |
| 6713 | break; |
| 6714 | } |
| 6715 | |
| 6716 | child = sibling_die (child); |
| 6717 | } |
| 6718 | } |
| 6719 | |
| 6720 | *lowpc = best_low; |
| 6721 | *highpc = best_high; |
| 6722 | } |
| 6723 | |
| 6724 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
| 6725 | in DIE. */ |
| 6726 | static void |
| 6727 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, |
| 6728 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) |
| 6729 | { |
| 6730 | struct objfile *objfile = cu->objfile; |
| 6731 | struct attribute *attr; |
| 6732 | |
| 6733 | attr = dwarf2_attr (die, DW_AT_high_pc, cu); |
| 6734 | if (attr) |
| 6735 | { |
| 6736 | CORE_ADDR high = DW_ADDR (attr); |
| 6737 | |
| 6738 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 6739 | if (attr) |
| 6740 | { |
| 6741 | CORE_ADDR low = DW_ADDR (attr); |
| 6742 | |
| 6743 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
| 6744 | } |
| 6745 | } |
| 6746 | |
| 6747 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
| 6748 | if (attr) |
| 6749 | { |
| 6750 | bfd *obfd = objfile->obfd; |
| 6751 | |
| 6752 | /* The value of the DW_AT_ranges attribute is the offset of the |
| 6753 | address range list in the .debug_ranges section. */ |
| 6754 | unsigned long offset = DW_UNSND (attr); |
| 6755 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
| 6756 | |
| 6757 | /* For some target architectures, but not others, the |
| 6758 | read_address function sign-extends the addresses it returns. |
| 6759 | To recognize base address selection entries, we need a |
| 6760 | mask. */ |
| 6761 | unsigned int addr_size = cu->header.addr_size; |
| 6762 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 6763 | |
| 6764 | /* The base address, to which the next pair is relative. Note |
| 6765 | that this 'base' is a DWARF concept: most entries in a range |
| 6766 | list are relative, to reduce the number of relocs against the |
| 6767 | debugging information. This is separate from this function's |
| 6768 | 'baseaddr' argument, which GDB uses to relocate debugging |
| 6769 | information from a shared library based on the address at |
| 6770 | which the library was loaded. */ |
| 6771 | CORE_ADDR base = cu->base_address; |
| 6772 | int base_known = cu->base_known; |
| 6773 | |
| 6774 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
| 6775 | if (offset >= dwarf2_per_objfile->ranges.size) |
| 6776 | { |
| 6777 | complaint (&symfile_complaints, |
| 6778 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), |
| 6779 | offset); |
| 6780 | return; |
| 6781 | } |
| 6782 | |
| 6783 | for (;;) |
| 6784 | { |
| 6785 | unsigned int bytes_read; |
| 6786 | CORE_ADDR start, end; |
| 6787 | |
| 6788 | start = read_address (obfd, buffer, cu, &bytes_read); |
| 6789 | buffer += bytes_read; |
| 6790 | end = read_address (obfd, buffer, cu, &bytes_read); |
| 6791 | buffer += bytes_read; |
| 6792 | |
| 6793 | /* Did we find the end of the range list? */ |
| 6794 | if (start == 0 && end == 0) |
| 6795 | break; |
| 6796 | |
| 6797 | /* Did we find a base address selection entry? */ |
| 6798 | else if ((start & base_select_mask) == base_select_mask) |
| 6799 | { |
| 6800 | base = end; |
| 6801 | base_known = 1; |
| 6802 | } |
| 6803 | |
| 6804 | /* We found an ordinary address range. */ |
| 6805 | else |
| 6806 | { |
| 6807 | if (!base_known) |
| 6808 | { |
| 6809 | complaint (&symfile_complaints, |
| 6810 | _("Invalid .debug_ranges data " |
| 6811 | "(no base address)")); |
| 6812 | return; |
| 6813 | } |
| 6814 | |
| 6815 | if (start > end) |
| 6816 | { |
| 6817 | /* Inverted range entries are invalid. */ |
| 6818 | complaint (&symfile_complaints, |
| 6819 | _("Invalid .debug_ranges data " |
| 6820 | "(inverted range)")); |
| 6821 | return; |
| 6822 | } |
| 6823 | |
| 6824 | /* Empty range entries have no effect. */ |
| 6825 | if (start == end) |
| 6826 | continue; |
| 6827 | |
| 6828 | record_block_range (block, |
| 6829 | baseaddr + base + start, |
| 6830 | baseaddr + base + end - 1); |
| 6831 | } |
| 6832 | } |
| 6833 | } |
| 6834 | } |
| 6835 | |
| 6836 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
| 6837 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed |
| 6838 | during 4.6.0 experimental. */ |
| 6839 | |
| 6840 | static int |
| 6841 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) |
| 6842 | { |
| 6843 | const char *cs; |
| 6844 | int major, minor, release; |
| 6845 | |
| 6846 | if (cu->producer == NULL) |
| 6847 | { |
| 6848 | /* For unknown compilers expect their behavior is DWARF version |
| 6849 | compliant. |
| 6850 | |
| 6851 | GCC started to support .debug_types sections by -gdwarf-4 since |
| 6852 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer |
| 6853 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 |
| 6854 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility |
| 6855 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ |
| 6856 | |
| 6857 | return 0; |
| 6858 | } |
| 6859 | |
| 6860 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ |
| 6861 | |
| 6862 | if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) != 0) |
| 6863 | { |
| 6864 | /* For non-GCC compilers expect their behavior is DWARF version |
| 6865 | compliant. */ |
| 6866 | |
| 6867 | return 0; |
| 6868 | } |
| 6869 | cs = &cu->producer[strlen ("GNU ")]; |
| 6870 | while (*cs && !isdigit (*cs)) |
| 6871 | cs++; |
| 6872 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) |
| 6873 | { |
| 6874 | /* Not recognized as GCC. */ |
| 6875 | |
| 6876 | return 0; |
| 6877 | } |
| 6878 | |
| 6879 | return major < 4 || (major == 4 && minor < 6); |
| 6880 | } |
| 6881 | |
| 6882 | /* Return the default accessibility type if it is not overriden by |
| 6883 | DW_AT_accessibility. */ |
| 6884 | |
| 6885 | static enum dwarf_access_attribute |
| 6886 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) |
| 6887 | { |
| 6888 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) |
| 6889 | { |
| 6890 | /* The default DWARF 2 accessibility for members is public, the default |
| 6891 | accessibility for inheritance is private. */ |
| 6892 | |
| 6893 | if (die->tag != DW_TAG_inheritance) |
| 6894 | return DW_ACCESS_public; |
| 6895 | else |
| 6896 | return DW_ACCESS_private; |
| 6897 | } |
| 6898 | else |
| 6899 | { |
| 6900 | /* DWARF 3+ defines the default accessibility a different way. The same |
| 6901 | rules apply now for DW_TAG_inheritance as for the members and it only |
| 6902 | depends on the container kind. */ |
| 6903 | |
| 6904 | if (die->parent->tag == DW_TAG_class_type) |
| 6905 | return DW_ACCESS_private; |
| 6906 | else |
| 6907 | return DW_ACCESS_public; |
| 6908 | } |
| 6909 | } |
| 6910 | |
| 6911 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
| 6912 | offset. If the attribute was not found return 0, otherwise return |
| 6913 | 1. If it was found but could not properly be handled, set *OFFSET |
| 6914 | to 0. */ |
| 6915 | |
| 6916 | static int |
| 6917 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, |
| 6918 | LONGEST *offset) |
| 6919 | { |
| 6920 | struct attribute *attr; |
| 6921 | |
| 6922 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
| 6923 | if (attr != NULL) |
| 6924 | { |
| 6925 | *offset = 0; |
| 6926 | |
| 6927 | /* Note that we do not check for a section offset first here. |
| 6928 | This is because DW_AT_data_member_location is new in DWARF 4, |
| 6929 | so if we see it, we can assume that a constant form is really |
| 6930 | a constant and not a section offset. */ |
| 6931 | if (attr_form_is_constant (attr)) |
| 6932 | *offset = dwarf2_get_attr_constant_value (attr, 0); |
| 6933 | else if (attr_form_is_section_offset (attr)) |
| 6934 | dwarf2_complex_location_expr_complaint (); |
| 6935 | else if (attr_form_is_block (attr)) |
| 6936 | *offset = decode_locdesc (DW_BLOCK (attr), cu); |
| 6937 | else |
| 6938 | dwarf2_complex_location_expr_complaint (); |
| 6939 | |
| 6940 | return 1; |
| 6941 | } |
| 6942 | |
| 6943 | return 0; |
| 6944 | } |
| 6945 | |
| 6946 | /* Add an aggregate field to the field list. */ |
| 6947 | |
| 6948 | static void |
| 6949 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
| 6950 | struct dwarf2_cu *cu) |
| 6951 | { |
| 6952 | struct objfile *objfile = cu->objfile; |
| 6953 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 6954 | struct nextfield *new_field; |
| 6955 | struct attribute *attr; |
| 6956 | struct field *fp; |
| 6957 | char *fieldname = ""; |
| 6958 | |
| 6959 | /* Allocate a new field list entry and link it in. */ |
| 6960 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 6961 | make_cleanup (xfree, new_field); |
| 6962 | memset (new_field, 0, sizeof (struct nextfield)); |
| 6963 | |
| 6964 | if (die->tag == DW_TAG_inheritance) |
| 6965 | { |
| 6966 | new_field->next = fip->baseclasses; |
| 6967 | fip->baseclasses = new_field; |
| 6968 | } |
| 6969 | else |
| 6970 | { |
| 6971 | new_field->next = fip->fields; |
| 6972 | fip->fields = new_field; |
| 6973 | } |
| 6974 | fip->nfields++; |
| 6975 | |
| 6976 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
| 6977 | if (attr) |
| 6978 | new_field->accessibility = DW_UNSND (attr); |
| 6979 | else |
| 6980 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); |
| 6981 | if (new_field->accessibility != DW_ACCESS_public) |
| 6982 | fip->non_public_fields = 1; |
| 6983 | |
| 6984 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
| 6985 | if (attr) |
| 6986 | new_field->virtuality = DW_UNSND (attr); |
| 6987 | else |
| 6988 | new_field->virtuality = DW_VIRTUALITY_none; |
| 6989 | |
| 6990 | fp = &new_field->field; |
| 6991 | |
| 6992 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
| 6993 | { |
| 6994 | LONGEST offset; |
| 6995 | |
| 6996 | /* Data member other than a C++ static data member. */ |
| 6997 | |
| 6998 | /* Get type of field. */ |
| 6999 | fp->type = die_type (die, cu); |
| 7000 | |
| 7001 | SET_FIELD_BITPOS (*fp, 0); |
| 7002 | |
| 7003 | /* Get bit size of field (zero if none). */ |
| 7004 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
| 7005 | if (attr) |
| 7006 | { |
| 7007 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); |
| 7008 | } |
| 7009 | else |
| 7010 | { |
| 7011 | FIELD_BITSIZE (*fp) = 0; |
| 7012 | } |
| 7013 | |
| 7014 | /* Get bit offset of field. */ |
| 7015 | if (handle_data_member_location (die, cu, &offset)) |
| 7016 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); |
| 7017 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
| 7018 | if (attr) |
| 7019 | { |
| 7020 | if (gdbarch_bits_big_endian (gdbarch)) |
| 7021 | { |
| 7022 | /* For big endian bits, the DW_AT_bit_offset gives the |
| 7023 | additional bit offset from the MSB of the containing |
| 7024 | anonymous object to the MSB of the field. We don't |
| 7025 | have to do anything special since we don't need to |
| 7026 | know the size of the anonymous object. */ |
| 7027 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
| 7028 | } |
| 7029 | else |
| 7030 | { |
| 7031 | /* For little endian bits, compute the bit offset to the |
| 7032 | MSB of the anonymous object, subtract off the number of |
| 7033 | bits from the MSB of the field to the MSB of the |
| 7034 | object, and then subtract off the number of bits of |
| 7035 | the field itself. The result is the bit offset of |
| 7036 | the LSB of the field. */ |
| 7037 | int anonymous_size; |
| 7038 | int bit_offset = DW_UNSND (attr); |
| 7039 | |
| 7040 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7041 | if (attr) |
| 7042 | { |
| 7043 | /* The size of the anonymous object containing |
| 7044 | the bit field is explicit, so use the |
| 7045 | indicated size (in bytes). */ |
| 7046 | anonymous_size = DW_UNSND (attr); |
| 7047 | } |
| 7048 | else |
| 7049 | { |
| 7050 | /* The size of the anonymous object containing |
| 7051 | the bit field must be inferred from the type |
| 7052 | attribute of the data member containing the |
| 7053 | bit field. */ |
| 7054 | anonymous_size = TYPE_LENGTH (fp->type); |
| 7055 | } |
| 7056 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte |
| 7057 | - bit_offset - FIELD_BITSIZE (*fp); |
| 7058 | } |
| 7059 | } |
| 7060 | |
| 7061 | /* Get name of field. */ |
| 7062 | fieldname = dwarf2_name (die, cu); |
| 7063 | if (fieldname == NULL) |
| 7064 | fieldname = ""; |
| 7065 | |
| 7066 | /* The name is already allocated along with this objfile, so we don't |
| 7067 | need to duplicate it for the type. */ |
| 7068 | fp->name = fieldname; |
| 7069 | |
| 7070 | /* Change accessibility for artificial fields (e.g. virtual table |
| 7071 | pointer or virtual base class pointer) to private. */ |
| 7072 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
| 7073 | { |
| 7074 | FIELD_ARTIFICIAL (*fp) = 1; |
| 7075 | new_field->accessibility = DW_ACCESS_private; |
| 7076 | fip->non_public_fields = 1; |
| 7077 | } |
| 7078 | } |
| 7079 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
| 7080 | { |
| 7081 | /* C++ static member. */ |
| 7082 | |
| 7083 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that |
| 7084 | is a declaration, but all versions of G++ as of this writing |
| 7085 | (so through at least 3.2.1) incorrectly generate |
| 7086 | DW_TAG_variable tags. */ |
| 7087 | |
| 7088 | const char *physname; |
| 7089 | |
| 7090 | /* Get name of field. */ |
| 7091 | fieldname = dwarf2_name (die, cu); |
| 7092 | if (fieldname == NULL) |
| 7093 | return; |
| 7094 | |
| 7095 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 7096 | if (attr |
| 7097 | /* Only create a symbol if this is an external value. |
| 7098 | new_symbol checks this and puts the value in the global symbol |
| 7099 | table, which we want. If it is not external, new_symbol |
| 7100 | will try to put the value in cu->list_in_scope which is wrong. */ |
| 7101 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) |
| 7102 | { |
| 7103 | /* A static const member, not much different than an enum as far as |
| 7104 | we're concerned, except that we can support more types. */ |
| 7105 | new_symbol (die, NULL, cu); |
| 7106 | } |
| 7107 | |
| 7108 | /* Get physical name. */ |
| 7109 | physname = dwarf2_physname (fieldname, die, cu); |
| 7110 | |
| 7111 | /* The name is already allocated along with this objfile, so we don't |
| 7112 | need to duplicate it for the type. */ |
| 7113 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); |
| 7114 | FIELD_TYPE (*fp) = die_type (die, cu); |
| 7115 | FIELD_NAME (*fp) = fieldname; |
| 7116 | } |
| 7117 | else if (die->tag == DW_TAG_inheritance) |
| 7118 | { |
| 7119 | LONGEST offset; |
| 7120 | |
| 7121 | /* C++ base class field. */ |
| 7122 | if (handle_data_member_location (die, cu, &offset)) |
| 7123 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); |
| 7124 | FIELD_BITSIZE (*fp) = 0; |
| 7125 | FIELD_TYPE (*fp) = die_type (die, cu); |
| 7126 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
| 7127 | fip->nbaseclasses++; |
| 7128 | } |
| 7129 | } |
| 7130 | |
| 7131 | /* Add a typedef defined in the scope of the FIP's class. */ |
| 7132 | |
| 7133 | static void |
| 7134 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, |
| 7135 | struct dwarf2_cu *cu) |
| 7136 | { |
| 7137 | struct objfile *objfile = cu->objfile; |
| 7138 | struct typedef_field_list *new_field; |
| 7139 | struct attribute *attr; |
| 7140 | struct typedef_field *fp; |
| 7141 | char *fieldname = ""; |
| 7142 | |
| 7143 | /* Allocate a new field list entry and link it in. */ |
| 7144 | new_field = xzalloc (sizeof (*new_field)); |
| 7145 | make_cleanup (xfree, new_field); |
| 7146 | |
| 7147 | gdb_assert (die->tag == DW_TAG_typedef); |
| 7148 | |
| 7149 | fp = &new_field->field; |
| 7150 | |
| 7151 | /* Get name of field. */ |
| 7152 | fp->name = dwarf2_name (die, cu); |
| 7153 | if (fp->name == NULL) |
| 7154 | return; |
| 7155 | |
| 7156 | fp->type = read_type_die (die, cu); |
| 7157 | |
| 7158 | new_field->next = fip->typedef_field_list; |
| 7159 | fip->typedef_field_list = new_field; |
| 7160 | fip->typedef_field_list_count++; |
| 7161 | } |
| 7162 | |
| 7163 | /* Create the vector of fields, and attach it to the type. */ |
| 7164 | |
| 7165 | static void |
| 7166 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
| 7167 | struct dwarf2_cu *cu) |
| 7168 | { |
| 7169 | int nfields = fip->nfields; |
| 7170 | |
| 7171 | /* Record the field count, allocate space for the array of fields, |
| 7172 | and create blank accessibility bitfields if necessary. */ |
| 7173 | TYPE_NFIELDS (type) = nfields; |
| 7174 | TYPE_FIELDS (type) = (struct field *) |
| 7175 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
| 7176 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); |
| 7177 | |
| 7178 | if (fip->non_public_fields && cu->language != language_ada) |
| 7179 | { |
| 7180 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7181 | |
| 7182 | TYPE_FIELD_PRIVATE_BITS (type) = |
| 7183 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 7184 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); |
| 7185 | |
| 7186 | TYPE_FIELD_PROTECTED_BITS (type) = |
| 7187 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 7188 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); |
| 7189 | |
| 7190 | TYPE_FIELD_IGNORE_BITS (type) = |
| 7191 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 7192 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); |
| 7193 | } |
| 7194 | |
| 7195 | /* If the type has baseclasses, allocate and clear a bit vector for |
| 7196 | TYPE_FIELD_VIRTUAL_BITS. */ |
| 7197 | if (fip->nbaseclasses && cu->language != language_ada) |
| 7198 | { |
| 7199 | int num_bytes = B_BYTES (fip->nbaseclasses); |
| 7200 | unsigned char *pointer; |
| 7201 | |
| 7202 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7203 | pointer = TYPE_ALLOC (type, num_bytes); |
| 7204 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; |
| 7205 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
| 7206 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; |
| 7207 | } |
| 7208 | |
| 7209 | /* Copy the saved-up fields into the field vector. Start from the head of |
| 7210 | the list, adding to the tail of the field array, so that they end up in |
| 7211 | the same order in the array in which they were added to the list. */ |
| 7212 | while (nfields-- > 0) |
| 7213 | { |
| 7214 | struct nextfield *fieldp; |
| 7215 | |
| 7216 | if (fip->fields) |
| 7217 | { |
| 7218 | fieldp = fip->fields; |
| 7219 | fip->fields = fieldp->next; |
| 7220 | } |
| 7221 | else |
| 7222 | { |
| 7223 | fieldp = fip->baseclasses; |
| 7224 | fip->baseclasses = fieldp->next; |
| 7225 | } |
| 7226 | |
| 7227 | TYPE_FIELD (type, nfields) = fieldp->field; |
| 7228 | switch (fieldp->accessibility) |
| 7229 | { |
| 7230 | case DW_ACCESS_private: |
| 7231 | if (cu->language != language_ada) |
| 7232 | SET_TYPE_FIELD_PRIVATE (type, nfields); |
| 7233 | break; |
| 7234 | |
| 7235 | case DW_ACCESS_protected: |
| 7236 | if (cu->language != language_ada) |
| 7237 | SET_TYPE_FIELD_PROTECTED (type, nfields); |
| 7238 | break; |
| 7239 | |
| 7240 | case DW_ACCESS_public: |
| 7241 | break; |
| 7242 | |
| 7243 | default: |
| 7244 | /* Unknown accessibility. Complain and treat it as public. */ |
| 7245 | { |
| 7246 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
| 7247 | fieldp->accessibility); |
| 7248 | } |
| 7249 | break; |
| 7250 | } |
| 7251 | if (nfields < fip->nbaseclasses) |
| 7252 | { |
| 7253 | switch (fieldp->virtuality) |
| 7254 | { |
| 7255 | case DW_VIRTUALITY_virtual: |
| 7256 | case DW_VIRTUALITY_pure_virtual: |
| 7257 | if (cu->language == language_ada) |
| 7258 | error (_("unexpected virtuality in component of Ada type")); |
| 7259 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
| 7260 | break; |
| 7261 | } |
| 7262 | } |
| 7263 | } |
| 7264 | } |
| 7265 | |
| 7266 | /* Add a member function to the proper fieldlist. */ |
| 7267 | |
| 7268 | static void |
| 7269 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
| 7270 | struct type *type, struct dwarf2_cu *cu) |
| 7271 | { |
| 7272 | struct objfile *objfile = cu->objfile; |
| 7273 | struct attribute *attr; |
| 7274 | struct fnfieldlist *flp; |
| 7275 | int i; |
| 7276 | struct fn_field *fnp; |
| 7277 | char *fieldname; |
| 7278 | struct nextfnfield *new_fnfield; |
| 7279 | struct type *this_type; |
| 7280 | enum dwarf_access_attribute accessibility; |
| 7281 | |
| 7282 | if (cu->language == language_ada) |
| 7283 | error (_("unexpected member function in Ada type")); |
| 7284 | |
| 7285 | /* Get name of member function. */ |
| 7286 | fieldname = dwarf2_name (die, cu); |
| 7287 | if (fieldname == NULL) |
| 7288 | return; |
| 7289 | |
| 7290 | /* Look up member function name in fieldlist. */ |
| 7291 | for (i = 0; i < fip->nfnfields; i++) |
| 7292 | { |
| 7293 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
| 7294 | break; |
| 7295 | } |
| 7296 | |
| 7297 | /* Create new list element if necessary. */ |
| 7298 | if (i < fip->nfnfields) |
| 7299 | flp = &fip->fnfieldlists[i]; |
| 7300 | else |
| 7301 | { |
| 7302 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 7303 | { |
| 7304 | fip->fnfieldlists = (struct fnfieldlist *) |
| 7305 | xrealloc (fip->fnfieldlists, |
| 7306 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) |
| 7307 | * sizeof (struct fnfieldlist)); |
| 7308 | if (fip->nfnfields == 0) |
| 7309 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
| 7310 | } |
| 7311 | flp = &fip->fnfieldlists[fip->nfnfields]; |
| 7312 | flp->name = fieldname; |
| 7313 | flp->length = 0; |
| 7314 | flp->head = NULL; |
| 7315 | i = fip->nfnfields++; |
| 7316 | } |
| 7317 | |
| 7318 | /* Create a new member function field and chain it to the field list |
| 7319 | entry. */ |
| 7320 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
| 7321 | make_cleanup (xfree, new_fnfield); |
| 7322 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
| 7323 | new_fnfield->next = flp->head; |
| 7324 | flp->head = new_fnfield; |
| 7325 | flp->length++; |
| 7326 | |
| 7327 | /* Fill in the member function field info. */ |
| 7328 | fnp = &new_fnfield->fnfield; |
| 7329 | |
| 7330 | /* Delay processing of the physname until later. */ |
| 7331 | if (cu->language == language_cplus || cu->language == language_java) |
| 7332 | { |
| 7333 | add_to_method_list (type, i, flp->length - 1, fieldname, |
| 7334 | die, cu); |
| 7335 | } |
| 7336 | else |
| 7337 | { |
| 7338 | const char *physname = dwarf2_physname (fieldname, die, cu); |
| 7339 | fnp->physname = physname ? physname : ""; |
| 7340 | } |
| 7341 | |
| 7342 | fnp->type = alloc_type (objfile); |
| 7343 | this_type = read_type_die (die, cu); |
| 7344 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) |
| 7345 | { |
| 7346 | int nparams = TYPE_NFIELDS (this_type); |
| 7347 | |
| 7348 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
| 7349 | of the method itself (TYPE_CODE_METHOD). */ |
| 7350 | smash_to_method_type (fnp->type, type, |
| 7351 | TYPE_TARGET_TYPE (this_type), |
| 7352 | TYPE_FIELDS (this_type), |
| 7353 | TYPE_NFIELDS (this_type), |
| 7354 | TYPE_VARARGS (this_type)); |
| 7355 | |
| 7356 | /* Handle static member functions. |
| 7357 | Dwarf2 has no clean way to discern C++ static and non-static |
| 7358 | member functions. G++ helps GDB by marking the first |
| 7359 | parameter for non-static member functions (which is the this |
| 7360 | pointer) as artificial. We obtain this information from |
| 7361 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ |
| 7362 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
| 7363 | fnp->voffset = VOFFSET_STATIC; |
| 7364 | } |
| 7365 | else |
| 7366 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
| 7367 | dwarf2_full_name (fieldname, die, cu)); |
| 7368 | |
| 7369 | /* Get fcontext from DW_AT_containing_type if present. */ |
| 7370 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
| 7371 | fnp->fcontext = die_containing_type (die, cu); |
| 7372 | |
| 7373 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
| 7374 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ |
| 7375 | |
| 7376 | /* Get accessibility. */ |
| 7377 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
| 7378 | if (attr) |
| 7379 | accessibility = DW_UNSND (attr); |
| 7380 | else |
| 7381 | accessibility = dwarf2_default_access_attribute (die, cu); |
| 7382 | switch (accessibility) |
| 7383 | { |
| 7384 | case DW_ACCESS_private: |
| 7385 | fnp->is_private = 1; |
| 7386 | break; |
| 7387 | case DW_ACCESS_protected: |
| 7388 | fnp->is_protected = 1; |
| 7389 | break; |
| 7390 | } |
| 7391 | |
| 7392 | /* Check for artificial methods. */ |
| 7393 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
| 7394 | if (attr && DW_UNSND (attr) != 0) |
| 7395 | fnp->is_artificial = 1; |
| 7396 | |
| 7397 | /* Get index in virtual function table if it is a virtual member |
| 7398 | function. For older versions of GCC, this is an offset in the |
| 7399 | appropriate virtual table, as specified by DW_AT_containing_type. |
| 7400 | For everyone else, it is an expression to be evaluated relative |
| 7401 | to the object address. */ |
| 7402 | |
| 7403 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
| 7404 | if (attr) |
| 7405 | { |
| 7406 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
| 7407 | { |
| 7408 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
| 7409 | { |
| 7410 | /* Old-style GCC. */ |
| 7411 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
| 7412 | } |
| 7413 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref |
| 7414 | || (DW_BLOCK (attr)->size > 1 |
| 7415 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size |
| 7416 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) |
| 7417 | { |
| 7418 | struct dwarf_block blk; |
| 7419 | int offset; |
| 7420 | |
| 7421 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref |
| 7422 | ? 1 : 2); |
| 7423 | blk.size = DW_BLOCK (attr)->size - offset; |
| 7424 | blk.data = DW_BLOCK (attr)->data + offset; |
| 7425 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); |
| 7426 | if ((fnp->voffset % cu->header.addr_size) != 0) |
| 7427 | dwarf2_complex_location_expr_complaint (); |
| 7428 | else |
| 7429 | fnp->voffset /= cu->header.addr_size; |
| 7430 | fnp->voffset += 2; |
| 7431 | } |
| 7432 | else |
| 7433 | dwarf2_complex_location_expr_complaint (); |
| 7434 | |
| 7435 | if (!fnp->fcontext) |
| 7436 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); |
| 7437 | } |
| 7438 | else if (attr_form_is_section_offset (attr)) |
| 7439 | { |
| 7440 | dwarf2_complex_location_expr_complaint (); |
| 7441 | } |
| 7442 | else |
| 7443 | { |
| 7444 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
| 7445 | fieldname); |
| 7446 | } |
| 7447 | } |
| 7448 | else |
| 7449 | { |
| 7450 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
| 7451 | if (attr && DW_UNSND (attr)) |
| 7452 | { |
| 7453 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ |
| 7454 | complaint (&symfile_complaints, |
| 7455 | _("Member function \"%s\" (offset %d) is virtual " |
| 7456 | "but the vtable offset is not specified"), |
| 7457 | fieldname, die->offset); |
| 7458 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7459 | TYPE_CPLUS_DYNAMIC (type) = 1; |
| 7460 | } |
| 7461 | } |
| 7462 | } |
| 7463 | |
| 7464 | /* Create the vector of member function fields, and attach it to the type. */ |
| 7465 | |
| 7466 | static void |
| 7467 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
| 7468 | struct dwarf2_cu *cu) |
| 7469 | { |
| 7470 | struct fnfieldlist *flp; |
| 7471 | int i; |
| 7472 | |
| 7473 | if (cu->language == language_ada) |
| 7474 | error (_("unexpected member functions in Ada type")); |
| 7475 | |
| 7476 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7477 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 7478 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); |
| 7479 | |
| 7480 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) |
| 7481 | { |
| 7482 | struct nextfnfield *nfp = flp->head; |
| 7483 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); |
| 7484 | int k; |
| 7485 | |
| 7486 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; |
| 7487 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; |
| 7488 | fn_flp->fn_fields = (struct fn_field *) |
| 7489 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); |
| 7490 | for (k = flp->length; (k--, nfp); nfp = nfp->next) |
| 7491 | fn_flp->fn_fields[k] = nfp->fnfield; |
| 7492 | } |
| 7493 | |
| 7494 | TYPE_NFN_FIELDS (type) = fip->nfnfields; |
| 7495 | } |
| 7496 | |
| 7497 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
| 7498 | language, zero otherwise. */ |
| 7499 | static int |
| 7500 | is_vtable_name (const char *name, struct dwarf2_cu *cu) |
| 7501 | { |
| 7502 | static const char vptr[] = "_vptr"; |
| 7503 | static const char vtable[] = "vtable"; |
| 7504 | |
| 7505 | /* Look for the C++ and Java forms of the vtable. */ |
| 7506 | if ((cu->language == language_java |
| 7507 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) |
| 7508 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 |
| 7509 | && is_cplus_marker (name[sizeof (vptr) - 1]))) |
| 7510 | return 1; |
| 7511 | |
| 7512 | return 0; |
| 7513 | } |
| 7514 | |
| 7515 | /* GCC outputs unnamed structures that are really pointers to member |
| 7516 | functions, with the ABI-specified layout. If TYPE describes |
| 7517 | such a structure, smash it into a member function type. |
| 7518 | |
| 7519 | GCC shouldn't do this; it should just output pointer to member DIEs. |
| 7520 | This is GCC PR debug/28767. */ |
| 7521 | |
| 7522 | static void |
| 7523 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) |
| 7524 | { |
| 7525 | struct type *pfn_type, *domain_type, *new_type; |
| 7526 | |
| 7527 | /* Check for a structure with no name and two children. */ |
| 7528 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
| 7529 | return; |
| 7530 | |
| 7531 | /* Check for __pfn and __delta members. */ |
| 7532 | if (TYPE_FIELD_NAME (type, 0) == NULL |
| 7533 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 |
| 7534 | || TYPE_FIELD_NAME (type, 1) == NULL |
| 7535 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) |
| 7536 | return; |
| 7537 | |
| 7538 | /* Find the type of the method. */ |
| 7539 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
| 7540 | if (pfn_type == NULL |
| 7541 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR |
| 7542 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) |
| 7543 | return; |
| 7544 | |
| 7545 | /* Look for the "this" argument. */ |
| 7546 | pfn_type = TYPE_TARGET_TYPE (pfn_type); |
| 7547 | if (TYPE_NFIELDS (pfn_type) == 0 |
| 7548 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
| 7549 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
| 7550 | return; |
| 7551 | |
| 7552 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); |
| 7553 | new_type = alloc_type (objfile); |
| 7554 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), |
| 7555 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
| 7556 | TYPE_VARARGS (pfn_type)); |
| 7557 | smash_to_methodptr_type (type, new_type); |
| 7558 | } |
| 7559 | |
| 7560 | /* Called when we find the DIE that starts a structure or union scope |
| 7561 | (definition) to create a type for the structure or union. Fill in |
| 7562 | the type's name and general properties; the members will not be |
| 7563 | processed until process_structure_type. |
| 7564 | |
| 7565 | NOTE: we need to call these functions regardless of whether or not the |
| 7566 | DIE has a DW_AT_name attribute, since it might be an anonymous |
| 7567 | structure or union. This gets the type entered into our set of |
| 7568 | user defined types. |
| 7569 | |
| 7570 | However, if the structure is incomplete (an opaque struct/union) |
| 7571 | then suppress creating a symbol table entry for it since gdb only |
| 7572 | wants to find the one with the complete definition. Note that if |
| 7573 | it is complete, we just call new_symbol, which does it's own |
| 7574 | checking about whether the struct/union is anonymous or not (and |
| 7575 | suppresses creating a symbol table entry itself). */ |
| 7576 | |
| 7577 | static struct type * |
| 7578 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7579 | { |
| 7580 | struct objfile *objfile = cu->objfile; |
| 7581 | struct type *type; |
| 7582 | struct attribute *attr; |
| 7583 | char *name; |
| 7584 | |
| 7585 | /* If the definition of this type lives in .debug_types, read that type. |
| 7586 | Don't follow DW_AT_specification though, that will take us back up |
| 7587 | the chain and we want to go down. */ |
| 7588 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); |
| 7589 | if (attr) |
| 7590 | { |
| 7591 | struct dwarf2_cu *type_cu = cu; |
| 7592 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 7593 | |
| 7594 | /* We could just recurse on read_structure_type, but we need to call |
| 7595 | get_die_type to ensure only one type for this DIE is created. |
| 7596 | This is important, for example, because for c++ classes we need |
| 7597 | TYPE_NAME set which is only done by new_symbol. Blech. */ |
| 7598 | type = read_type_die (type_die, type_cu); |
| 7599 | |
| 7600 | /* TYPE_CU may not be the same as CU. |
| 7601 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 7602 | return set_die_type (die, type, cu); |
| 7603 | } |
| 7604 | |
| 7605 | type = alloc_type (objfile); |
| 7606 | INIT_CPLUS_SPECIFIC (type); |
| 7607 | |
| 7608 | name = dwarf2_name (die, cu); |
| 7609 | if (name != NULL) |
| 7610 | { |
| 7611 | if (cu->language == language_cplus |
| 7612 | || cu->language == language_java) |
| 7613 | { |
| 7614 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
| 7615 | |
| 7616 | /* dwarf2_full_name might have already finished building the DIE's |
| 7617 | type. If so, there is no need to continue. */ |
| 7618 | if (get_die_type (die, cu) != NULL) |
| 7619 | return get_die_type (die, cu); |
| 7620 | |
| 7621 | TYPE_TAG_NAME (type) = full_name; |
| 7622 | if (die->tag == DW_TAG_structure_type |
| 7623 | || die->tag == DW_TAG_class_type) |
| 7624 | TYPE_NAME (type) = TYPE_TAG_NAME (type); |
| 7625 | } |
| 7626 | else |
| 7627 | { |
| 7628 | /* The name is already allocated along with this objfile, so |
| 7629 | we don't need to duplicate it for the type. */ |
| 7630 | TYPE_TAG_NAME (type) = (char *) name; |
| 7631 | if (die->tag == DW_TAG_class_type) |
| 7632 | TYPE_NAME (type) = TYPE_TAG_NAME (type); |
| 7633 | } |
| 7634 | } |
| 7635 | |
| 7636 | if (die->tag == DW_TAG_structure_type) |
| 7637 | { |
| 7638 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
| 7639 | } |
| 7640 | else if (die->tag == DW_TAG_union_type) |
| 7641 | { |
| 7642 | TYPE_CODE (type) = TYPE_CODE_UNION; |
| 7643 | } |
| 7644 | else |
| 7645 | { |
| 7646 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
| 7647 | } |
| 7648 | |
| 7649 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
| 7650 | TYPE_DECLARED_CLASS (type) = 1; |
| 7651 | |
| 7652 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7653 | if (attr) |
| 7654 | { |
| 7655 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 7656 | } |
| 7657 | else |
| 7658 | { |
| 7659 | TYPE_LENGTH (type) = 0; |
| 7660 | } |
| 7661 | |
| 7662 | TYPE_STUB_SUPPORTED (type) = 1; |
| 7663 | if (die_is_declaration (die, cu)) |
| 7664 | TYPE_STUB (type) = 1; |
| 7665 | else if (attr == NULL && die->child == NULL |
| 7666 | && producer_is_realview (cu->producer)) |
| 7667 | /* RealView does not output the required DW_AT_declaration |
| 7668 | on incomplete types. */ |
| 7669 | TYPE_STUB (type) = 1; |
| 7670 | |
| 7671 | /* We need to add the type field to the die immediately so we don't |
| 7672 | infinitely recurse when dealing with pointers to the structure |
| 7673 | type within the structure itself. */ |
| 7674 | set_die_type (die, type, cu); |
| 7675 | |
| 7676 | /* set_die_type should be already done. */ |
| 7677 | set_descriptive_type (type, die, cu); |
| 7678 | |
| 7679 | return type; |
| 7680 | } |
| 7681 | |
| 7682 | /* Finish creating a structure or union type, including filling in |
| 7683 | its members and creating a symbol for it. */ |
| 7684 | |
| 7685 | static void |
| 7686 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 7687 | { |
| 7688 | struct objfile *objfile = cu->objfile; |
| 7689 | struct die_info *child_die = die->child; |
| 7690 | struct type *type; |
| 7691 | |
| 7692 | type = get_die_type (die, cu); |
| 7693 | if (type == NULL) |
| 7694 | type = read_structure_type (die, cu); |
| 7695 | |
| 7696 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
| 7697 | { |
| 7698 | struct field_info fi; |
| 7699 | struct die_info *child_die; |
| 7700 | VEC (symbolp) *template_args = NULL; |
| 7701 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 7702 | |
| 7703 | memset (&fi, 0, sizeof (struct field_info)); |
| 7704 | |
| 7705 | child_die = die->child; |
| 7706 | |
| 7707 | while (child_die && child_die->tag) |
| 7708 | { |
| 7709 | if (child_die->tag == DW_TAG_member |
| 7710 | || child_die->tag == DW_TAG_variable) |
| 7711 | { |
| 7712 | /* NOTE: carlton/2002-11-05: A C++ static data member |
| 7713 | should be a DW_TAG_member that is a declaration, but |
| 7714 | all versions of G++ as of this writing (so through at |
| 7715 | least 3.2.1) incorrectly generate DW_TAG_variable |
| 7716 | tags for them instead. */ |
| 7717 | dwarf2_add_field (&fi, child_die, cu); |
| 7718 | } |
| 7719 | else if (child_die->tag == DW_TAG_subprogram) |
| 7720 | { |
| 7721 | /* C++ member function. */ |
| 7722 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
| 7723 | } |
| 7724 | else if (child_die->tag == DW_TAG_inheritance) |
| 7725 | { |
| 7726 | /* C++ base class field. */ |
| 7727 | dwarf2_add_field (&fi, child_die, cu); |
| 7728 | } |
| 7729 | else if (child_die->tag == DW_TAG_typedef) |
| 7730 | dwarf2_add_typedef (&fi, child_die, cu); |
| 7731 | else if (child_die->tag == DW_TAG_template_type_param |
| 7732 | || child_die->tag == DW_TAG_template_value_param) |
| 7733 | { |
| 7734 | struct symbol *arg = new_symbol (child_die, NULL, cu); |
| 7735 | |
| 7736 | if (arg != NULL) |
| 7737 | VEC_safe_push (symbolp, template_args, arg); |
| 7738 | } |
| 7739 | |
| 7740 | child_die = sibling_die (child_die); |
| 7741 | } |
| 7742 | |
| 7743 | /* Attach template arguments to type. */ |
| 7744 | if (! VEC_empty (symbolp, template_args)) |
| 7745 | { |
| 7746 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7747 | TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 7748 | = VEC_length (symbolp, template_args); |
| 7749 | TYPE_TEMPLATE_ARGUMENTS (type) |
| 7750 | = obstack_alloc (&objfile->objfile_obstack, |
| 7751 | (TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 7752 | * sizeof (struct symbol *))); |
| 7753 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), |
| 7754 | VEC_address (symbolp, template_args), |
| 7755 | (TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 7756 | * sizeof (struct symbol *))); |
| 7757 | VEC_free (symbolp, template_args); |
| 7758 | } |
| 7759 | |
| 7760 | /* Attach fields and member functions to the type. */ |
| 7761 | if (fi.nfields) |
| 7762 | dwarf2_attach_fields_to_type (&fi, type, cu); |
| 7763 | if (fi.nfnfields) |
| 7764 | { |
| 7765 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
| 7766 | |
| 7767 | /* Get the type which refers to the base class (possibly this |
| 7768 | class itself) which contains the vtable pointer for the current |
| 7769 | class from the DW_AT_containing_type attribute. This use of |
| 7770 | DW_AT_containing_type is a GNU extension. */ |
| 7771 | |
| 7772 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
| 7773 | { |
| 7774 | struct type *t = die_containing_type (die, cu); |
| 7775 | |
| 7776 | TYPE_VPTR_BASETYPE (type) = t; |
| 7777 | if (type == t) |
| 7778 | { |
| 7779 | int i; |
| 7780 | |
| 7781 | /* Our own class provides vtbl ptr. */ |
| 7782 | for (i = TYPE_NFIELDS (t) - 1; |
| 7783 | i >= TYPE_N_BASECLASSES (t); |
| 7784 | --i) |
| 7785 | { |
| 7786 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
| 7787 | |
| 7788 | if (is_vtable_name (fieldname, cu)) |
| 7789 | { |
| 7790 | TYPE_VPTR_FIELDNO (type) = i; |
| 7791 | break; |
| 7792 | } |
| 7793 | } |
| 7794 | |
| 7795 | /* Complain if virtual function table field not found. */ |
| 7796 | if (i < TYPE_N_BASECLASSES (t)) |
| 7797 | complaint (&symfile_complaints, |
| 7798 | _("virtual function table pointer " |
| 7799 | "not found when defining class '%s'"), |
| 7800 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
| 7801 | ""); |
| 7802 | } |
| 7803 | else |
| 7804 | { |
| 7805 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); |
| 7806 | } |
| 7807 | } |
| 7808 | else if (cu->producer |
| 7809 | && strncmp (cu->producer, |
| 7810 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) |
| 7811 | { |
| 7812 | /* The IBM XLC compiler does not provide direct indication |
| 7813 | of the containing type, but the vtable pointer is |
| 7814 | always named __vfp. */ |
| 7815 | |
| 7816 | int i; |
| 7817 | |
| 7818 | for (i = TYPE_NFIELDS (type) - 1; |
| 7819 | i >= TYPE_N_BASECLASSES (type); |
| 7820 | --i) |
| 7821 | { |
| 7822 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) |
| 7823 | { |
| 7824 | TYPE_VPTR_FIELDNO (type) = i; |
| 7825 | TYPE_VPTR_BASETYPE (type) = type; |
| 7826 | break; |
| 7827 | } |
| 7828 | } |
| 7829 | } |
| 7830 | } |
| 7831 | |
| 7832 | /* Copy fi.typedef_field_list linked list elements content into the |
| 7833 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ |
| 7834 | if (fi.typedef_field_list) |
| 7835 | { |
| 7836 | int i = fi.typedef_field_list_count; |
| 7837 | |
| 7838 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 7839 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
| 7840 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); |
| 7841 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; |
| 7842 | |
| 7843 | /* Reverse the list order to keep the debug info elements order. */ |
| 7844 | while (--i >= 0) |
| 7845 | { |
| 7846 | struct typedef_field *dest, *src; |
| 7847 | |
| 7848 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
| 7849 | src = &fi.typedef_field_list->field; |
| 7850 | fi.typedef_field_list = fi.typedef_field_list->next; |
| 7851 | *dest = *src; |
| 7852 | } |
| 7853 | } |
| 7854 | |
| 7855 | do_cleanups (back_to); |
| 7856 | |
| 7857 | if (HAVE_CPLUS_STRUCT (type)) |
| 7858 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; |
| 7859 | } |
| 7860 | |
| 7861 | quirk_gcc_member_function_pointer (type, objfile); |
| 7862 | |
| 7863 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
| 7864 | snapshots) has been known to create a die giving a declaration |
| 7865 | for a class that has, as a child, a die giving a definition for a |
| 7866 | nested class. So we have to process our children even if the |
| 7867 | current die is a declaration. Normally, of course, a declaration |
| 7868 | won't have any children at all. */ |
| 7869 | |
| 7870 | while (child_die != NULL && child_die->tag) |
| 7871 | { |
| 7872 | if (child_die->tag == DW_TAG_member |
| 7873 | || child_die->tag == DW_TAG_variable |
| 7874 | || child_die->tag == DW_TAG_inheritance |
| 7875 | || child_die->tag == DW_TAG_template_value_param |
| 7876 | || child_die->tag == DW_TAG_template_type_param) |
| 7877 | { |
| 7878 | /* Do nothing. */ |
| 7879 | } |
| 7880 | else |
| 7881 | process_die (child_die, cu); |
| 7882 | |
| 7883 | child_die = sibling_die (child_die); |
| 7884 | } |
| 7885 | |
| 7886 | /* Do not consider external references. According to the DWARF standard, |
| 7887 | these DIEs are identified by the fact that they have no byte_size |
| 7888 | attribute, and a declaration attribute. */ |
| 7889 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL |
| 7890 | || !die_is_declaration (die, cu)) |
| 7891 | new_symbol (die, type, cu); |
| 7892 | } |
| 7893 | |
| 7894 | /* Given a DW_AT_enumeration_type die, set its type. We do not |
| 7895 | complete the type's fields yet, or create any symbols. */ |
| 7896 | |
| 7897 | static struct type * |
| 7898 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
| 7899 | { |
| 7900 | struct objfile *objfile = cu->objfile; |
| 7901 | struct type *type; |
| 7902 | struct attribute *attr; |
| 7903 | const char *name; |
| 7904 | |
| 7905 | /* If the definition of this type lives in .debug_types, read that type. |
| 7906 | Don't follow DW_AT_specification though, that will take us back up |
| 7907 | the chain and we want to go down. */ |
| 7908 | attr = dwarf2_attr_no_follow (die, DW_AT_signature, cu); |
| 7909 | if (attr) |
| 7910 | { |
| 7911 | struct dwarf2_cu *type_cu = cu; |
| 7912 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 7913 | |
| 7914 | type = read_type_die (type_die, type_cu); |
| 7915 | |
| 7916 | /* TYPE_CU may not be the same as CU. |
| 7917 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 7918 | return set_die_type (die, type, cu); |
| 7919 | } |
| 7920 | |
| 7921 | type = alloc_type (objfile); |
| 7922 | |
| 7923 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
| 7924 | name = dwarf2_full_name (NULL, die, cu); |
| 7925 | if (name != NULL) |
| 7926 | TYPE_TAG_NAME (type) = (char *) name; |
| 7927 | |
| 7928 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 7929 | if (attr) |
| 7930 | { |
| 7931 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 7932 | } |
| 7933 | else |
| 7934 | { |
| 7935 | TYPE_LENGTH (type) = 0; |
| 7936 | } |
| 7937 | |
| 7938 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
| 7939 | declared as private in the package spec, and then defined only |
| 7940 | inside the package body. Such types are known as Taft Amendment |
| 7941 | Types. When another package uses such a type, an incomplete DIE |
| 7942 | may be generated by the compiler. */ |
| 7943 | if (die_is_declaration (die, cu)) |
| 7944 | TYPE_STUB (type) = 1; |
| 7945 | |
| 7946 | return set_die_type (die, type, cu); |
| 7947 | } |
| 7948 | |
| 7949 | /* Given a pointer to a die which begins an enumeration, process all |
| 7950 | the dies that define the members of the enumeration, and create the |
| 7951 | symbol for the enumeration type. |
| 7952 | |
| 7953 | NOTE: We reverse the order of the element list. */ |
| 7954 | |
| 7955 | static void |
| 7956 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 7957 | { |
| 7958 | struct type *this_type; |
| 7959 | |
| 7960 | this_type = get_die_type (die, cu); |
| 7961 | if (this_type == NULL) |
| 7962 | this_type = read_enumeration_type (die, cu); |
| 7963 | |
| 7964 | if (die->child != NULL) |
| 7965 | { |
| 7966 | struct die_info *child_die; |
| 7967 | struct symbol *sym; |
| 7968 | struct field *fields = NULL; |
| 7969 | int num_fields = 0; |
| 7970 | int unsigned_enum = 1; |
| 7971 | char *name; |
| 7972 | int flag_enum = 1; |
| 7973 | ULONGEST mask = 0; |
| 7974 | |
| 7975 | child_die = die->child; |
| 7976 | while (child_die && child_die->tag) |
| 7977 | { |
| 7978 | if (child_die->tag != DW_TAG_enumerator) |
| 7979 | { |
| 7980 | process_die (child_die, cu); |
| 7981 | } |
| 7982 | else |
| 7983 | { |
| 7984 | name = dwarf2_name (child_die, cu); |
| 7985 | if (name) |
| 7986 | { |
| 7987 | sym = new_symbol (child_die, this_type, cu); |
| 7988 | if (SYMBOL_VALUE (sym) < 0) |
| 7989 | { |
| 7990 | unsigned_enum = 0; |
| 7991 | flag_enum = 0; |
| 7992 | } |
| 7993 | else if ((mask & SYMBOL_VALUE (sym)) != 0) |
| 7994 | flag_enum = 0; |
| 7995 | else |
| 7996 | mask |= SYMBOL_VALUE (sym); |
| 7997 | |
| 7998 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 7999 | { |
| 8000 | fields = (struct field *) |
| 8001 | xrealloc (fields, |
| 8002 | (num_fields + DW_FIELD_ALLOC_CHUNK) |
| 8003 | * sizeof (struct field)); |
| 8004 | } |
| 8005 | |
| 8006 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
| 8007 | FIELD_TYPE (fields[num_fields]) = NULL; |
| 8008 | SET_FIELD_BITPOS (fields[num_fields], SYMBOL_VALUE (sym)); |
| 8009 | FIELD_BITSIZE (fields[num_fields]) = 0; |
| 8010 | |
| 8011 | num_fields++; |
| 8012 | } |
| 8013 | } |
| 8014 | |
| 8015 | child_die = sibling_die (child_die); |
| 8016 | } |
| 8017 | |
| 8018 | if (num_fields) |
| 8019 | { |
| 8020 | TYPE_NFIELDS (this_type) = num_fields; |
| 8021 | TYPE_FIELDS (this_type) = (struct field *) |
| 8022 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); |
| 8023 | memcpy (TYPE_FIELDS (this_type), fields, |
| 8024 | sizeof (struct field) * num_fields); |
| 8025 | xfree (fields); |
| 8026 | } |
| 8027 | if (unsigned_enum) |
| 8028 | TYPE_UNSIGNED (this_type) = 1; |
| 8029 | if (flag_enum) |
| 8030 | TYPE_FLAG_ENUM (this_type) = 1; |
| 8031 | } |
| 8032 | |
| 8033 | /* If we are reading an enum from a .debug_types unit, and the enum |
| 8034 | is a declaration, and the enum is not the signatured type in the |
| 8035 | unit, then we do not want to add a symbol for it. Adding a |
| 8036 | symbol would in some cases obscure the true definition of the |
| 8037 | enum, giving users an incomplete type when the definition is |
| 8038 | actually available. Note that we do not want to do this for all |
| 8039 | enums which are just declarations, because C++0x allows forward |
| 8040 | enum declarations. */ |
| 8041 | if (cu->per_cu->debug_types_section |
| 8042 | && die_is_declaration (die, cu)) |
| 8043 | { |
| 8044 | struct signatured_type *type_sig; |
| 8045 | |
| 8046 | type_sig |
| 8047 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, |
| 8048 | cu->per_cu->debug_types_section, |
| 8049 | cu->per_cu->offset); |
| 8050 | if (type_sig->type_offset != die->offset) |
| 8051 | return; |
| 8052 | } |
| 8053 | |
| 8054 | new_symbol (die, this_type, cu); |
| 8055 | } |
| 8056 | |
| 8057 | /* Extract all information from a DW_TAG_array_type DIE and put it in |
| 8058 | the DIE's type field. For now, this only handles one dimensional |
| 8059 | arrays. */ |
| 8060 | |
| 8061 | static struct type * |
| 8062 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8063 | { |
| 8064 | struct objfile *objfile = cu->objfile; |
| 8065 | struct die_info *child_die; |
| 8066 | struct type *type; |
| 8067 | struct type *element_type, *range_type, *index_type; |
| 8068 | struct type **range_types = NULL; |
| 8069 | struct attribute *attr; |
| 8070 | int ndim = 0; |
| 8071 | struct cleanup *back_to; |
| 8072 | char *name; |
| 8073 | |
| 8074 | element_type = die_type (die, cu); |
| 8075 | |
| 8076 | /* The die_type call above may have already set the type for this DIE. */ |
| 8077 | type = get_die_type (die, cu); |
| 8078 | if (type) |
| 8079 | return type; |
| 8080 | |
| 8081 | /* Irix 6.2 native cc creates array types without children for |
| 8082 | arrays with unspecified length. */ |
| 8083 | if (die->child == NULL) |
| 8084 | { |
| 8085 | index_type = objfile_type (objfile)->builtin_int; |
| 8086 | range_type = create_range_type (NULL, index_type, 0, -1); |
| 8087 | type = create_array_type (NULL, element_type, range_type); |
| 8088 | return set_die_type (die, type, cu); |
| 8089 | } |
| 8090 | |
| 8091 | back_to = make_cleanup (null_cleanup, NULL); |
| 8092 | child_die = die->child; |
| 8093 | while (child_die && child_die->tag) |
| 8094 | { |
| 8095 | if (child_die->tag == DW_TAG_subrange_type) |
| 8096 | { |
| 8097 | struct type *child_type = read_type_die (child_die, cu); |
| 8098 | |
| 8099 | if (child_type != NULL) |
| 8100 | { |
| 8101 | /* The range type was succesfully read. Save it for the |
| 8102 | array type creation. */ |
| 8103 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
| 8104 | { |
| 8105 | range_types = (struct type **) |
| 8106 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) |
| 8107 | * sizeof (struct type *)); |
| 8108 | if (ndim == 0) |
| 8109 | make_cleanup (free_current_contents, &range_types); |
| 8110 | } |
| 8111 | range_types[ndim++] = child_type; |
| 8112 | } |
| 8113 | } |
| 8114 | child_die = sibling_die (child_die); |
| 8115 | } |
| 8116 | |
| 8117 | /* Dwarf2 dimensions are output from left to right, create the |
| 8118 | necessary array types in backwards order. */ |
| 8119 | |
| 8120 | type = element_type; |
| 8121 | |
| 8122 | if (read_array_order (die, cu) == DW_ORD_col_major) |
| 8123 | { |
| 8124 | int i = 0; |
| 8125 | |
| 8126 | while (i < ndim) |
| 8127 | type = create_array_type (NULL, type, range_types[i++]); |
| 8128 | } |
| 8129 | else |
| 8130 | { |
| 8131 | while (ndim-- > 0) |
| 8132 | type = create_array_type (NULL, type, range_types[ndim]); |
| 8133 | } |
| 8134 | |
| 8135 | /* Understand Dwarf2 support for vector types (like they occur on |
| 8136 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the |
| 8137 | array type. This is not part of the Dwarf2/3 standard yet, but a |
| 8138 | custom vendor extension. The main difference between a regular |
| 8139 | array and the vector variant is that vectors are passed by value |
| 8140 | to functions. */ |
| 8141 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
| 8142 | if (attr) |
| 8143 | make_vector_type (type); |
| 8144 | |
| 8145 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
| 8146 | implementation may choose to implement triple vectors using this |
| 8147 | attribute. */ |
| 8148 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8149 | if (attr) |
| 8150 | { |
| 8151 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) |
| 8152 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 8153 | else |
| 8154 | complaint (&symfile_complaints, |
| 8155 | _("DW_AT_byte_size for array type smaller " |
| 8156 | "than the total size of elements")); |
| 8157 | } |
| 8158 | |
| 8159 | name = dwarf2_name (die, cu); |
| 8160 | if (name) |
| 8161 | TYPE_NAME (type) = name; |
| 8162 | |
| 8163 | /* Install the type in the die. */ |
| 8164 | set_die_type (die, type, cu); |
| 8165 | |
| 8166 | /* set_die_type should be already done. */ |
| 8167 | set_descriptive_type (type, die, cu); |
| 8168 | |
| 8169 | do_cleanups (back_to); |
| 8170 | |
| 8171 | return type; |
| 8172 | } |
| 8173 | |
| 8174 | static enum dwarf_array_dim_ordering |
| 8175 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
| 8176 | { |
| 8177 | struct attribute *attr; |
| 8178 | |
| 8179 | attr = dwarf2_attr (die, DW_AT_ordering, cu); |
| 8180 | |
| 8181 | if (attr) return DW_SND (attr); |
| 8182 | |
| 8183 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
| 8184 | opposite order to the dwarf2 specification, but data is still |
| 8185 | laid out as per normal fortran. |
| 8186 | |
| 8187 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
| 8188 | version checking. */ |
| 8189 | |
| 8190 | if (cu->language == language_fortran |
| 8191 | && cu->producer && strstr (cu->producer, "GNU F77")) |
| 8192 | { |
| 8193 | return DW_ORD_row_major; |
| 8194 | } |
| 8195 | |
| 8196 | switch (cu->language_defn->la_array_ordering) |
| 8197 | { |
| 8198 | case array_column_major: |
| 8199 | return DW_ORD_col_major; |
| 8200 | case array_row_major: |
| 8201 | default: |
| 8202 | return DW_ORD_row_major; |
| 8203 | }; |
| 8204 | } |
| 8205 | |
| 8206 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
| 8207 | the DIE's type field. */ |
| 8208 | |
| 8209 | static struct type * |
| 8210 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8211 | { |
| 8212 | struct type *domain_type, *set_type; |
| 8213 | struct attribute *attr; |
| 8214 | |
| 8215 | domain_type = die_type (die, cu); |
| 8216 | |
| 8217 | /* The die_type call above may have already set the type for this DIE. */ |
| 8218 | set_type = get_die_type (die, cu); |
| 8219 | if (set_type) |
| 8220 | return set_type; |
| 8221 | |
| 8222 | set_type = create_set_type (NULL, domain_type); |
| 8223 | |
| 8224 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8225 | if (attr) |
| 8226 | TYPE_LENGTH (set_type) = DW_UNSND (attr); |
| 8227 | |
| 8228 | return set_die_type (die, set_type, cu); |
| 8229 | } |
| 8230 | |
| 8231 | /* First cut: install each common block member as a global variable. */ |
| 8232 | |
| 8233 | static void |
| 8234 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
| 8235 | { |
| 8236 | struct die_info *child_die; |
| 8237 | struct attribute *attr; |
| 8238 | struct symbol *sym; |
| 8239 | CORE_ADDR base = (CORE_ADDR) 0; |
| 8240 | |
| 8241 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 8242 | if (attr) |
| 8243 | { |
| 8244 | /* Support the .debug_loc offsets. */ |
| 8245 | if (attr_form_is_block (attr)) |
| 8246 | { |
| 8247 | base = decode_locdesc (DW_BLOCK (attr), cu); |
| 8248 | } |
| 8249 | else if (attr_form_is_section_offset (attr)) |
| 8250 | { |
| 8251 | dwarf2_complex_location_expr_complaint (); |
| 8252 | } |
| 8253 | else |
| 8254 | { |
| 8255 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 8256 | "common block member"); |
| 8257 | } |
| 8258 | } |
| 8259 | if (die->child != NULL) |
| 8260 | { |
| 8261 | child_die = die->child; |
| 8262 | while (child_die && child_die->tag) |
| 8263 | { |
| 8264 | LONGEST offset; |
| 8265 | |
| 8266 | sym = new_symbol (child_die, NULL, cu); |
| 8267 | if (sym != NULL |
| 8268 | && handle_data_member_location (child_die, cu, &offset)) |
| 8269 | { |
| 8270 | SYMBOL_VALUE_ADDRESS (sym) = base + offset; |
| 8271 | add_symbol_to_list (sym, &global_symbols); |
| 8272 | } |
| 8273 | child_die = sibling_die (child_die); |
| 8274 | } |
| 8275 | } |
| 8276 | } |
| 8277 | |
| 8278 | /* Create a type for a C++ namespace. */ |
| 8279 | |
| 8280 | static struct type * |
| 8281 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8282 | { |
| 8283 | struct objfile *objfile = cu->objfile; |
| 8284 | const char *previous_prefix, *name; |
| 8285 | int is_anonymous; |
| 8286 | struct type *type; |
| 8287 | |
| 8288 | /* For extensions, reuse the type of the original namespace. */ |
| 8289 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) |
| 8290 | { |
| 8291 | struct die_info *ext_die; |
| 8292 | struct dwarf2_cu *ext_cu = cu; |
| 8293 | |
| 8294 | ext_die = dwarf2_extension (die, &ext_cu); |
| 8295 | type = read_type_die (ext_die, ext_cu); |
| 8296 | |
| 8297 | /* EXT_CU may not be the same as CU. |
| 8298 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 8299 | return set_die_type (die, type, cu); |
| 8300 | } |
| 8301 | |
| 8302 | name = namespace_name (die, &is_anonymous, cu); |
| 8303 | |
| 8304 | /* Now build the name of the current namespace. */ |
| 8305 | |
| 8306 | previous_prefix = determine_prefix (die, cu); |
| 8307 | if (previous_prefix[0] != '\0') |
| 8308 | name = typename_concat (&objfile->objfile_obstack, |
| 8309 | previous_prefix, name, 0, cu); |
| 8310 | |
| 8311 | /* Create the type. */ |
| 8312 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, |
| 8313 | objfile); |
| 8314 | TYPE_NAME (type) = (char *) name; |
| 8315 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 8316 | |
| 8317 | return set_die_type (die, type, cu); |
| 8318 | } |
| 8319 | |
| 8320 | /* Read a C++ namespace. */ |
| 8321 | |
| 8322 | static void |
| 8323 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
| 8324 | { |
| 8325 | struct objfile *objfile = cu->objfile; |
| 8326 | int is_anonymous; |
| 8327 | |
| 8328 | /* Add a symbol associated to this if we haven't seen the namespace |
| 8329 | before. Also, add a using directive if it's an anonymous |
| 8330 | namespace. */ |
| 8331 | |
| 8332 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
| 8333 | { |
| 8334 | struct type *type; |
| 8335 | |
| 8336 | type = read_type_die (die, cu); |
| 8337 | new_symbol (die, type, cu); |
| 8338 | |
| 8339 | namespace_name (die, &is_anonymous, cu); |
| 8340 | if (is_anonymous) |
| 8341 | { |
| 8342 | const char *previous_prefix = determine_prefix (die, cu); |
| 8343 | |
| 8344 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
| 8345 | NULL, NULL, &objfile->objfile_obstack); |
| 8346 | } |
| 8347 | } |
| 8348 | |
| 8349 | if (die->child != NULL) |
| 8350 | { |
| 8351 | struct die_info *child_die = die->child; |
| 8352 | |
| 8353 | while (child_die && child_die->tag) |
| 8354 | { |
| 8355 | process_die (child_die, cu); |
| 8356 | child_die = sibling_die (child_die); |
| 8357 | } |
| 8358 | } |
| 8359 | } |
| 8360 | |
| 8361 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
| 8362 | imported module. Still we need that type as local Fortran "use ... only" |
| 8363 | declaration imports depend on the created type in determine_prefix. */ |
| 8364 | |
| 8365 | static struct type * |
| 8366 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8367 | { |
| 8368 | struct objfile *objfile = cu->objfile; |
| 8369 | char *module_name; |
| 8370 | struct type *type; |
| 8371 | |
| 8372 | module_name = dwarf2_name (die, cu); |
| 8373 | if (!module_name) |
| 8374 | complaint (&symfile_complaints, |
| 8375 | _("DW_TAG_module has no name, offset 0x%x"), |
| 8376 | die->offset); |
| 8377 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
| 8378 | |
| 8379 | /* determine_prefix uses TYPE_TAG_NAME. */ |
| 8380 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 8381 | |
| 8382 | return set_die_type (die, type, cu); |
| 8383 | } |
| 8384 | |
| 8385 | /* Read a Fortran module. */ |
| 8386 | |
| 8387 | static void |
| 8388 | read_module (struct die_info *die, struct dwarf2_cu *cu) |
| 8389 | { |
| 8390 | struct die_info *child_die = die->child; |
| 8391 | |
| 8392 | while (child_die && child_die->tag) |
| 8393 | { |
| 8394 | process_die (child_die, cu); |
| 8395 | child_die = sibling_die (child_die); |
| 8396 | } |
| 8397 | } |
| 8398 | |
| 8399 | /* Return the name of the namespace represented by DIE. Set |
| 8400 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous |
| 8401 | namespace. */ |
| 8402 | |
| 8403 | static const char * |
| 8404 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
| 8405 | { |
| 8406 | struct die_info *current_die; |
| 8407 | const char *name = NULL; |
| 8408 | |
| 8409 | /* Loop through the extensions until we find a name. */ |
| 8410 | |
| 8411 | for (current_die = die; |
| 8412 | current_die != NULL; |
| 8413 | current_die = dwarf2_extension (die, &cu)) |
| 8414 | { |
| 8415 | name = dwarf2_name (current_die, cu); |
| 8416 | if (name != NULL) |
| 8417 | break; |
| 8418 | } |
| 8419 | |
| 8420 | /* Is it an anonymous namespace? */ |
| 8421 | |
| 8422 | *is_anonymous = (name == NULL); |
| 8423 | if (*is_anonymous) |
| 8424 | name = CP_ANONYMOUS_NAMESPACE_STR; |
| 8425 | |
| 8426 | return name; |
| 8427 | } |
| 8428 | |
| 8429 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
| 8430 | the user defined type vector. */ |
| 8431 | |
| 8432 | static struct type * |
| 8433 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8434 | { |
| 8435 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
| 8436 | struct comp_unit_head *cu_header = &cu->header; |
| 8437 | struct type *type; |
| 8438 | struct attribute *attr_byte_size; |
| 8439 | struct attribute *attr_address_class; |
| 8440 | int byte_size, addr_class; |
| 8441 | struct type *target_type; |
| 8442 | |
| 8443 | target_type = die_type (die, cu); |
| 8444 | |
| 8445 | /* The die_type call above may have already set the type for this DIE. */ |
| 8446 | type = get_die_type (die, cu); |
| 8447 | if (type) |
| 8448 | return type; |
| 8449 | |
| 8450 | type = lookup_pointer_type (target_type); |
| 8451 | |
| 8452 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8453 | if (attr_byte_size) |
| 8454 | byte_size = DW_UNSND (attr_byte_size); |
| 8455 | else |
| 8456 | byte_size = cu_header->addr_size; |
| 8457 | |
| 8458 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
| 8459 | if (attr_address_class) |
| 8460 | addr_class = DW_UNSND (attr_address_class); |
| 8461 | else |
| 8462 | addr_class = DW_ADDR_none; |
| 8463 | |
| 8464 | /* If the pointer size or address class is different than the |
| 8465 | default, create a type variant marked as such and set the |
| 8466 | length accordingly. */ |
| 8467 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) |
| 8468 | { |
| 8469 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
| 8470 | { |
| 8471 | int type_flags; |
| 8472 | |
| 8473 | type_flags = gdbarch_address_class_type_flags |
| 8474 | (gdbarch, byte_size, addr_class); |
| 8475 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
| 8476 | == 0); |
| 8477 | type = make_type_with_address_space (type, type_flags); |
| 8478 | } |
| 8479 | else if (TYPE_LENGTH (type) != byte_size) |
| 8480 | { |
| 8481 | complaint (&symfile_complaints, |
| 8482 | _("invalid pointer size %d"), byte_size); |
| 8483 | } |
| 8484 | else |
| 8485 | { |
| 8486 | /* Should we also complain about unhandled address classes? */ |
| 8487 | } |
| 8488 | } |
| 8489 | |
| 8490 | TYPE_LENGTH (type) = byte_size; |
| 8491 | return set_die_type (die, type, cu); |
| 8492 | } |
| 8493 | |
| 8494 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to |
| 8495 | the user defined type vector. */ |
| 8496 | |
| 8497 | static struct type * |
| 8498 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8499 | { |
| 8500 | struct type *type; |
| 8501 | struct type *to_type; |
| 8502 | struct type *domain; |
| 8503 | |
| 8504 | to_type = die_type (die, cu); |
| 8505 | domain = die_containing_type (die, cu); |
| 8506 | |
| 8507 | /* The calls above may have already set the type for this DIE. */ |
| 8508 | type = get_die_type (die, cu); |
| 8509 | if (type) |
| 8510 | return type; |
| 8511 | |
| 8512 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
| 8513 | type = lookup_methodptr_type (to_type); |
| 8514 | else |
| 8515 | type = lookup_memberptr_type (to_type, domain); |
| 8516 | |
| 8517 | return set_die_type (die, type, cu); |
| 8518 | } |
| 8519 | |
| 8520 | /* Extract all information from a DW_TAG_reference_type DIE and add to |
| 8521 | the user defined type vector. */ |
| 8522 | |
| 8523 | static struct type * |
| 8524 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8525 | { |
| 8526 | struct comp_unit_head *cu_header = &cu->header; |
| 8527 | struct type *type, *target_type; |
| 8528 | struct attribute *attr; |
| 8529 | |
| 8530 | target_type = die_type (die, cu); |
| 8531 | |
| 8532 | /* The die_type call above may have already set the type for this DIE. */ |
| 8533 | type = get_die_type (die, cu); |
| 8534 | if (type) |
| 8535 | return type; |
| 8536 | |
| 8537 | type = lookup_reference_type (target_type); |
| 8538 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8539 | if (attr) |
| 8540 | { |
| 8541 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 8542 | } |
| 8543 | else |
| 8544 | { |
| 8545 | TYPE_LENGTH (type) = cu_header->addr_size; |
| 8546 | } |
| 8547 | return set_die_type (die, type, cu); |
| 8548 | } |
| 8549 | |
| 8550 | static struct type * |
| 8551 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8552 | { |
| 8553 | struct type *base_type, *cv_type; |
| 8554 | |
| 8555 | base_type = die_type (die, cu); |
| 8556 | |
| 8557 | /* The die_type call above may have already set the type for this DIE. */ |
| 8558 | cv_type = get_die_type (die, cu); |
| 8559 | if (cv_type) |
| 8560 | return cv_type; |
| 8561 | |
| 8562 | /* In case the const qualifier is applied to an array type, the element type |
| 8563 | is so qualified, not the array type (section 6.7.3 of C99). */ |
| 8564 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) |
| 8565 | { |
| 8566 | struct type *el_type, *inner_array; |
| 8567 | |
| 8568 | base_type = copy_type (base_type); |
| 8569 | inner_array = base_type; |
| 8570 | |
| 8571 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) |
| 8572 | { |
| 8573 | TYPE_TARGET_TYPE (inner_array) = |
| 8574 | copy_type (TYPE_TARGET_TYPE (inner_array)); |
| 8575 | inner_array = TYPE_TARGET_TYPE (inner_array); |
| 8576 | } |
| 8577 | |
| 8578 | el_type = TYPE_TARGET_TYPE (inner_array); |
| 8579 | TYPE_TARGET_TYPE (inner_array) = |
| 8580 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); |
| 8581 | |
| 8582 | return set_die_type (die, base_type, cu); |
| 8583 | } |
| 8584 | |
| 8585 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
| 8586 | return set_die_type (die, cv_type, cu); |
| 8587 | } |
| 8588 | |
| 8589 | static struct type * |
| 8590 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8591 | { |
| 8592 | struct type *base_type, *cv_type; |
| 8593 | |
| 8594 | base_type = die_type (die, cu); |
| 8595 | |
| 8596 | /* The die_type call above may have already set the type for this DIE. */ |
| 8597 | cv_type = get_die_type (die, cu); |
| 8598 | if (cv_type) |
| 8599 | return cv_type; |
| 8600 | |
| 8601 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
| 8602 | return set_die_type (die, cv_type, cu); |
| 8603 | } |
| 8604 | |
| 8605 | /* Extract all information from a DW_TAG_string_type DIE and add to |
| 8606 | the user defined type vector. It isn't really a user defined type, |
| 8607 | but it behaves like one, with other DIE's using an AT_user_def_type |
| 8608 | attribute to reference it. */ |
| 8609 | |
| 8610 | static struct type * |
| 8611 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8612 | { |
| 8613 | struct objfile *objfile = cu->objfile; |
| 8614 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 8615 | struct type *type, *range_type, *index_type, *char_type; |
| 8616 | struct attribute *attr; |
| 8617 | unsigned int length; |
| 8618 | |
| 8619 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
| 8620 | if (attr) |
| 8621 | { |
| 8622 | length = DW_UNSND (attr); |
| 8623 | } |
| 8624 | else |
| 8625 | { |
| 8626 | /* Check for the DW_AT_byte_size attribute. */ |
| 8627 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8628 | if (attr) |
| 8629 | { |
| 8630 | length = DW_UNSND (attr); |
| 8631 | } |
| 8632 | else |
| 8633 | { |
| 8634 | length = 1; |
| 8635 | } |
| 8636 | } |
| 8637 | |
| 8638 | index_type = objfile_type (objfile)->builtin_int; |
| 8639 | range_type = create_range_type (NULL, index_type, 1, length); |
| 8640 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
| 8641 | type = create_string_type (NULL, char_type, range_type); |
| 8642 | |
| 8643 | return set_die_type (die, type, cu); |
| 8644 | } |
| 8645 | |
| 8646 | /* Handle DIES due to C code like: |
| 8647 | |
| 8648 | struct foo |
| 8649 | { |
| 8650 | int (*funcp)(int a, long l); |
| 8651 | int b; |
| 8652 | }; |
| 8653 | |
| 8654 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
| 8655 | |
| 8656 | static struct type * |
| 8657 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8658 | { |
| 8659 | struct objfile *objfile = cu->objfile; |
| 8660 | struct type *type; /* Type that this function returns. */ |
| 8661 | struct type *ftype; /* Function that returns above type. */ |
| 8662 | struct attribute *attr; |
| 8663 | |
| 8664 | type = die_type (die, cu); |
| 8665 | |
| 8666 | /* The die_type call above may have already set the type for this DIE. */ |
| 8667 | ftype = get_die_type (die, cu); |
| 8668 | if (ftype) |
| 8669 | return ftype; |
| 8670 | |
| 8671 | ftype = lookup_function_type (type); |
| 8672 | |
| 8673 | /* All functions in C++, Pascal and Java have prototypes. */ |
| 8674 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
| 8675 | if ((attr && (DW_UNSND (attr) != 0)) |
| 8676 | || cu->language == language_cplus |
| 8677 | || cu->language == language_java |
| 8678 | || cu->language == language_pascal) |
| 8679 | TYPE_PROTOTYPED (ftype) = 1; |
| 8680 | else if (producer_is_realview (cu->producer)) |
| 8681 | /* RealView does not emit DW_AT_prototyped. We can not |
| 8682 | distinguish prototyped and unprototyped functions; default to |
| 8683 | prototyped, since that is more common in modern code (and |
| 8684 | RealView warns about unprototyped functions). */ |
| 8685 | TYPE_PROTOTYPED (ftype) = 1; |
| 8686 | |
| 8687 | /* Store the calling convention in the type if it's available in |
| 8688 | the subroutine die. Otherwise set the calling convention to |
| 8689 | the default value DW_CC_normal. */ |
| 8690 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); |
| 8691 | if (attr) |
| 8692 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); |
| 8693 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) |
| 8694 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; |
| 8695 | else |
| 8696 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; |
| 8697 | |
| 8698 | /* We need to add the subroutine type to the die immediately so |
| 8699 | we don't infinitely recurse when dealing with parameters |
| 8700 | declared as the same subroutine type. */ |
| 8701 | set_die_type (die, ftype, cu); |
| 8702 | |
| 8703 | if (die->child != NULL) |
| 8704 | { |
| 8705 | struct type *void_type = objfile_type (objfile)->builtin_void; |
| 8706 | struct die_info *child_die; |
| 8707 | int nparams, iparams; |
| 8708 | |
| 8709 | /* Count the number of parameters. |
| 8710 | FIXME: GDB currently ignores vararg functions, but knows about |
| 8711 | vararg member functions. */ |
| 8712 | nparams = 0; |
| 8713 | child_die = die->child; |
| 8714 | while (child_die && child_die->tag) |
| 8715 | { |
| 8716 | if (child_die->tag == DW_TAG_formal_parameter) |
| 8717 | nparams++; |
| 8718 | else if (child_die->tag == DW_TAG_unspecified_parameters) |
| 8719 | TYPE_VARARGS (ftype) = 1; |
| 8720 | child_die = sibling_die (child_die); |
| 8721 | } |
| 8722 | |
| 8723 | /* Allocate storage for parameters and fill them in. */ |
| 8724 | TYPE_NFIELDS (ftype) = nparams; |
| 8725 | TYPE_FIELDS (ftype) = (struct field *) |
| 8726 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
| 8727 | |
| 8728 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
| 8729 | even if we error out during the parameters reading below. */ |
| 8730 | for (iparams = 0; iparams < nparams; iparams++) |
| 8731 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; |
| 8732 | |
| 8733 | iparams = 0; |
| 8734 | child_die = die->child; |
| 8735 | while (child_die && child_die->tag) |
| 8736 | { |
| 8737 | if (child_die->tag == DW_TAG_formal_parameter) |
| 8738 | { |
| 8739 | struct type *arg_type; |
| 8740 | |
| 8741 | /* DWARF version 2 has no clean way to discern C++ |
| 8742 | static and non-static member functions. G++ helps |
| 8743 | GDB by marking the first parameter for non-static |
| 8744 | member functions (which is the this pointer) as |
| 8745 | artificial. We pass this information to |
| 8746 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. |
| 8747 | |
| 8748 | DWARF version 3 added DW_AT_object_pointer, which GCC |
| 8749 | 4.5 does not yet generate. */ |
| 8750 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
| 8751 | if (attr) |
| 8752 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); |
| 8753 | else |
| 8754 | { |
| 8755 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
| 8756 | |
| 8757 | /* GCC/43521: In java, the formal parameter |
| 8758 | "this" is sometimes not marked with DW_AT_artificial. */ |
| 8759 | if (cu->language == language_java) |
| 8760 | { |
| 8761 | const char *name = dwarf2_name (child_die, cu); |
| 8762 | |
| 8763 | if (name && !strcmp (name, "this")) |
| 8764 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; |
| 8765 | } |
| 8766 | } |
| 8767 | arg_type = die_type (child_die, cu); |
| 8768 | |
| 8769 | /* RealView does not mark THIS as const, which the testsuite |
| 8770 | expects. GCC marks THIS as const in method definitions, |
| 8771 | but not in the class specifications (GCC PR 43053). */ |
| 8772 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) |
| 8773 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) |
| 8774 | { |
| 8775 | int is_this = 0; |
| 8776 | struct dwarf2_cu *arg_cu = cu; |
| 8777 | const char *name = dwarf2_name (child_die, cu); |
| 8778 | |
| 8779 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); |
| 8780 | if (attr) |
| 8781 | { |
| 8782 | /* If the compiler emits this, use it. */ |
| 8783 | if (follow_die_ref (die, attr, &arg_cu) == child_die) |
| 8784 | is_this = 1; |
| 8785 | } |
| 8786 | else if (name && strcmp (name, "this") == 0) |
| 8787 | /* Function definitions will have the argument names. */ |
| 8788 | is_this = 1; |
| 8789 | else if (name == NULL && iparams == 0) |
| 8790 | /* Declarations may not have the names, so like |
| 8791 | elsewhere in GDB, assume an artificial first |
| 8792 | argument is "this". */ |
| 8793 | is_this = 1; |
| 8794 | |
| 8795 | if (is_this) |
| 8796 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), |
| 8797 | arg_type, 0); |
| 8798 | } |
| 8799 | |
| 8800 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; |
| 8801 | iparams++; |
| 8802 | } |
| 8803 | child_die = sibling_die (child_die); |
| 8804 | } |
| 8805 | } |
| 8806 | |
| 8807 | return ftype; |
| 8808 | } |
| 8809 | |
| 8810 | static struct type * |
| 8811 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
| 8812 | { |
| 8813 | struct objfile *objfile = cu->objfile; |
| 8814 | const char *name = NULL; |
| 8815 | struct type *this_type, *target_type; |
| 8816 | |
| 8817 | name = dwarf2_full_name (NULL, die, cu); |
| 8818 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
| 8819 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
| 8820 | TYPE_NAME (this_type) = (char *) name; |
| 8821 | set_die_type (die, this_type, cu); |
| 8822 | target_type = die_type (die, cu); |
| 8823 | if (target_type != this_type) |
| 8824 | TYPE_TARGET_TYPE (this_type) = target_type; |
| 8825 | else |
| 8826 | { |
| 8827 | /* Self-referential typedefs are, it seems, not allowed by the DWARF |
| 8828 | spec and cause infinite loops in GDB. */ |
| 8829 | complaint (&symfile_complaints, |
| 8830 | _("Self-referential DW_TAG_typedef " |
| 8831 | "- DIE at 0x%x [in module %s]"), |
| 8832 | die->offset, objfile->name); |
| 8833 | TYPE_TARGET_TYPE (this_type) = NULL; |
| 8834 | } |
| 8835 | return this_type; |
| 8836 | } |
| 8837 | |
| 8838 | /* Find a representation of a given base type and install |
| 8839 | it in the TYPE field of the die. */ |
| 8840 | |
| 8841 | static struct type * |
| 8842 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8843 | { |
| 8844 | struct objfile *objfile = cu->objfile; |
| 8845 | struct type *type; |
| 8846 | struct attribute *attr; |
| 8847 | int encoding = 0, size = 0; |
| 8848 | char *name; |
| 8849 | enum type_code code = TYPE_CODE_INT; |
| 8850 | int type_flags = 0; |
| 8851 | struct type *target_type = NULL; |
| 8852 | |
| 8853 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
| 8854 | if (attr) |
| 8855 | { |
| 8856 | encoding = DW_UNSND (attr); |
| 8857 | } |
| 8858 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 8859 | if (attr) |
| 8860 | { |
| 8861 | size = DW_UNSND (attr); |
| 8862 | } |
| 8863 | name = dwarf2_name (die, cu); |
| 8864 | if (!name) |
| 8865 | { |
| 8866 | complaint (&symfile_complaints, |
| 8867 | _("DW_AT_name missing from DW_TAG_base_type")); |
| 8868 | } |
| 8869 | |
| 8870 | switch (encoding) |
| 8871 | { |
| 8872 | case DW_ATE_address: |
| 8873 | /* Turn DW_ATE_address into a void * pointer. */ |
| 8874 | code = TYPE_CODE_PTR; |
| 8875 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8876 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
| 8877 | break; |
| 8878 | case DW_ATE_boolean: |
| 8879 | code = TYPE_CODE_BOOL; |
| 8880 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8881 | break; |
| 8882 | case DW_ATE_complex_float: |
| 8883 | code = TYPE_CODE_COMPLEX; |
| 8884 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); |
| 8885 | break; |
| 8886 | case DW_ATE_decimal_float: |
| 8887 | code = TYPE_CODE_DECFLOAT; |
| 8888 | break; |
| 8889 | case DW_ATE_float: |
| 8890 | code = TYPE_CODE_FLT; |
| 8891 | break; |
| 8892 | case DW_ATE_signed: |
| 8893 | break; |
| 8894 | case DW_ATE_unsigned: |
| 8895 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8896 | if (cu->language == language_fortran |
| 8897 | && name |
| 8898 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) |
| 8899 | code = TYPE_CODE_CHAR; |
| 8900 | break; |
| 8901 | case DW_ATE_signed_char: |
| 8902 | if (cu->language == language_ada || cu->language == language_m2 |
| 8903 | || cu->language == language_pascal |
| 8904 | || cu->language == language_fortran) |
| 8905 | code = TYPE_CODE_CHAR; |
| 8906 | break; |
| 8907 | case DW_ATE_unsigned_char: |
| 8908 | if (cu->language == language_ada || cu->language == language_m2 |
| 8909 | || cu->language == language_pascal |
| 8910 | || cu->language == language_fortran) |
| 8911 | code = TYPE_CODE_CHAR; |
| 8912 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 8913 | break; |
| 8914 | case DW_ATE_UTF: |
| 8915 | /* We just treat this as an integer and then recognize the |
| 8916 | type by name elsewhere. */ |
| 8917 | break; |
| 8918 | |
| 8919 | default: |
| 8920 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), |
| 8921 | dwarf_type_encoding_name (encoding)); |
| 8922 | break; |
| 8923 | } |
| 8924 | |
| 8925 | type = init_type (code, size, type_flags, NULL, objfile); |
| 8926 | TYPE_NAME (type) = name; |
| 8927 | TYPE_TARGET_TYPE (type) = target_type; |
| 8928 | |
| 8929 | if (name && strcmp (name, "char") == 0) |
| 8930 | TYPE_NOSIGN (type) = 1; |
| 8931 | |
| 8932 | return set_die_type (die, type, cu); |
| 8933 | } |
| 8934 | |
| 8935 | /* Read the given DW_AT_subrange DIE. */ |
| 8936 | |
| 8937 | static struct type * |
| 8938 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
| 8939 | { |
| 8940 | struct type *base_type; |
| 8941 | struct type *range_type; |
| 8942 | struct attribute *attr; |
| 8943 | LONGEST low = 0; |
| 8944 | LONGEST high = -1; |
| 8945 | char *name; |
| 8946 | LONGEST negative_mask; |
| 8947 | |
| 8948 | base_type = die_type (die, cu); |
| 8949 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
| 8950 | check_typedef (base_type); |
| 8951 | |
| 8952 | /* The die_type call above may have already set the type for this DIE. */ |
| 8953 | range_type = get_die_type (die, cu); |
| 8954 | if (range_type) |
| 8955 | return range_type; |
| 8956 | |
| 8957 | if (cu->language == language_fortran) |
| 8958 | { |
| 8959 | /* FORTRAN implies a lower bound of 1, if not given. */ |
| 8960 | low = 1; |
| 8961 | } |
| 8962 | |
| 8963 | /* FIXME: For variable sized arrays either of these could be |
| 8964 | a variable rather than a constant value. We'll allow it, |
| 8965 | but we don't know how to handle it. */ |
| 8966 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
| 8967 | if (attr) |
| 8968 | low = dwarf2_get_attr_constant_value (attr, 0); |
| 8969 | |
| 8970 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
| 8971 | if (attr) |
| 8972 | { |
| 8973 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
| 8974 | { |
| 8975 | /* GCC encodes arrays with unspecified or dynamic length |
| 8976 | with a DW_FORM_block1 attribute or a reference attribute. |
| 8977 | FIXME: GDB does not yet know how to handle dynamic |
| 8978 | arrays properly, treat them as arrays with unspecified |
| 8979 | length for now. |
| 8980 | |
| 8981 | FIXME: jimb/2003-09-22: GDB does not really know |
| 8982 | how to handle arrays of unspecified length |
| 8983 | either; we just represent them as zero-length |
| 8984 | arrays. Choose an appropriate upper bound given |
| 8985 | the lower bound we've computed above. */ |
| 8986 | high = low - 1; |
| 8987 | } |
| 8988 | else |
| 8989 | high = dwarf2_get_attr_constant_value (attr, 1); |
| 8990 | } |
| 8991 | else |
| 8992 | { |
| 8993 | attr = dwarf2_attr (die, DW_AT_count, cu); |
| 8994 | if (attr) |
| 8995 | { |
| 8996 | int count = dwarf2_get_attr_constant_value (attr, 1); |
| 8997 | high = low + count - 1; |
| 8998 | } |
| 8999 | else |
| 9000 | { |
| 9001 | /* Unspecified array length. */ |
| 9002 | high = low - 1; |
| 9003 | } |
| 9004 | } |
| 9005 | |
| 9006 | /* Dwarf-2 specifications explicitly allows to create subrange types |
| 9007 | without specifying a base type. |
| 9008 | In that case, the base type must be set to the type of |
| 9009 | the lower bound, upper bound or count, in that order, if any of these |
| 9010 | three attributes references an object that has a type. |
| 9011 | If no base type is found, the Dwarf-2 specifications say that |
| 9012 | a signed integer type of size equal to the size of an address should |
| 9013 | be used. |
| 9014 | For the following C code: `extern char gdb_int [];' |
| 9015 | GCC produces an empty range DIE. |
| 9016 | FIXME: muller/2010-05-28: Possible references to object for low bound, |
| 9017 | high bound or count are not yet handled by this code. */ |
| 9018 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
| 9019 | { |
| 9020 | struct objfile *objfile = cu->objfile; |
| 9021 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 9022 | int addr_size = gdbarch_addr_bit (gdbarch) /8; |
| 9023 | struct type *int_type = objfile_type (objfile)->builtin_int; |
| 9024 | |
| 9025 | /* Test "int", "long int", and "long long int" objfile types, |
| 9026 | and select the first one having a size above or equal to the |
| 9027 | architecture address size. */ |
| 9028 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 9029 | base_type = int_type; |
| 9030 | else |
| 9031 | { |
| 9032 | int_type = objfile_type (objfile)->builtin_long; |
| 9033 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 9034 | base_type = int_type; |
| 9035 | else |
| 9036 | { |
| 9037 | int_type = objfile_type (objfile)->builtin_long_long; |
| 9038 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 9039 | base_type = int_type; |
| 9040 | } |
| 9041 | } |
| 9042 | } |
| 9043 | |
| 9044 | negative_mask = |
| 9045 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
| 9046 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) |
| 9047 | low |= negative_mask; |
| 9048 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) |
| 9049 | high |= negative_mask; |
| 9050 | |
| 9051 | range_type = create_range_type (NULL, base_type, low, high); |
| 9052 | |
| 9053 | /* Mark arrays with dynamic length at least as an array of unspecified |
| 9054 | length. GDB could check the boundary but before it gets implemented at |
| 9055 | least allow accessing the array elements. */ |
| 9056 | if (attr && attr_form_is_block (attr)) |
| 9057 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
| 9058 | |
| 9059 | /* Ada expects an empty array on no boundary attributes. */ |
| 9060 | if (attr == NULL && cu->language != language_ada) |
| 9061 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
| 9062 | |
| 9063 | name = dwarf2_name (die, cu); |
| 9064 | if (name) |
| 9065 | TYPE_NAME (range_type) = name; |
| 9066 | |
| 9067 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 9068 | if (attr) |
| 9069 | TYPE_LENGTH (range_type) = DW_UNSND (attr); |
| 9070 | |
| 9071 | set_die_type (die, range_type, cu); |
| 9072 | |
| 9073 | /* set_die_type should be already done. */ |
| 9074 | set_descriptive_type (range_type, die, cu); |
| 9075 | |
| 9076 | return range_type; |
| 9077 | } |
| 9078 | |
| 9079 | static struct type * |
| 9080 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
| 9081 | { |
| 9082 | struct type *type; |
| 9083 | |
| 9084 | /* For now, we only support the C meaning of an unspecified type: void. */ |
| 9085 | |
| 9086 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
| 9087 | TYPE_NAME (type) = dwarf2_name (die, cu); |
| 9088 | |
| 9089 | return set_die_type (die, type, cu); |
| 9090 | } |
| 9091 | |
| 9092 | /* Trivial hash function for die_info: the hash value of a DIE |
| 9093 | is its offset in .debug_info for this objfile. */ |
| 9094 | |
| 9095 | static hashval_t |
| 9096 | die_hash (const void *item) |
| 9097 | { |
| 9098 | const struct die_info *die = item; |
| 9099 | |
| 9100 | return die->offset; |
| 9101 | } |
| 9102 | |
| 9103 | /* Trivial comparison function for die_info structures: two DIEs |
| 9104 | are equal if they have the same offset. */ |
| 9105 | |
| 9106 | static int |
| 9107 | die_eq (const void *item_lhs, const void *item_rhs) |
| 9108 | { |
| 9109 | const struct die_info *die_lhs = item_lhs; |
| 9110 | const struct die_info *die_rhs = item_rhs; |
| 9111 | |
| 9112 | return die_lhs->offset == die_rhs->offset; |
| 9113 | } |
| 9114 | |
| 9115 | /* Read a whole compilation unit into a linked list of dies. */ |
| 9116 | |
| 9117 | static struct die_info * |
| 9118 | read_comp_unit (gdb_byte *info_ptr, struct dwarf2_cu *cu) |
| 9119 | { |
| 9120 | struct die_reader_specs reader_specs; |
| 9121 | int read_abbrevs = 0; |
| 9122 | struct cleanup *back_to = NULL; |
| 9123 | struct die_info *die; |
| 9124 | |
| 9125 | if (cu->dwarf2_abbrevs == NULL) |
| 9126 | { |
| 9127 | dwarf2_read_abbrevs (cu); |
| 9128 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 9129 | read_abbrevs = 1; |
| 9130 | } |
| 9131 | |
| 9132 | gdb_assert (cu->die_hash == NULL); |
| 9133 | cu->die_hash |
| 9134 | = htab_create_alloc_ex (cu->header.length / 12, |
| 9135 | die_hash, |
| 9136 | die_eq, |
| 9137 | NULL, |
| 9138 | &cu->comp_unit_obstack, |
| 9139 | hashtab_obstack_allocate, |
| 9140 | dummy_obstack_deallocate); |
| 9141 | |
| 9142 | init_cu_die_reader (&reader_specs, cu); |
| 9143 | |
| 9144 | die = read_die_and_children (&reader_specs, info_ptr, &info_ptr, NULL); |
| 9145 | |
| 9146 | if (read_abbrevs) |
| 9147 | do_cleanups (back_to); |
| 9148 | |
| 9149 | return die; |
| 9150 | } |
| 9151 | |
| 9152 | /* Main entry point for reading a DIE and all children. |
| 9153 | Read the DIE and dump it if requested. */ |
| 9154 | |
| 9155 | static struct die_info * |
| 9156 | read_die_and_children (const struct die_reader_specs *reader, |
| 9157 | gdb_byte *info_ptr, |
| 9158 | gdb_byte **new_info_ptr, |
| 9159 | struct die_info *parent) |
| 9160 | { |
| 9161 | struct die_info *result = read_die_and_children_1 (reader, info_ptr, |
| 9162 | new_info_ptr, parent); |
| 9163 | |
| 9164 | if (dwarf2_die_debug) |
| 9165 | { |
| 9166 | fprintf_unfiltered (gdb_stdlog, |
| 9167 | "\nRead die from %s of %s:\n", |
| 9168 | (reader->cu->per_cu->debug_types_section |
| 9169 | ? ".debug_types" |
| 9170 | : ".debug_info"), |
| 9171 | reader->abfd->filename); |
| 9172 | dump_die (result, dwarf2_die_debug); |
| 9173 | } |
| 9174 | |
| 9175 | return result; |
| 9176 | } |
| 9177 | |
| 9178 | /* Read a single die and all its descendents. Set the die's sibling |
| 9179 | field to NULL; set other fields in the die correctly, and set all |
| 9180 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the |
| 9181 | location of the info_ptr after reading all of those dies. PARENT |
| 9182 | is the parent of the die in question. */ |
| 9183 | |
| 9184 | static struct die_info * |
| 9185 | read_die_and_children_1 (const struct die_reader_specs *reader, |
| 9186 | gdb_byte *info_ptr, |
| 9187 | gdb_byte **new_info_ptr, |
| 9188 | struct die_info *parent) |
| 9189 | { |
| 9190 | struct die_info *die; |
| 9191 | gdb_byte *cur_ptr; |
| 9192 | int has_children; |
| 9193 | |
| 9194 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
| 9195 | if (die == NULL) |
| 9196 | { |
| 9197 | *new_info_ptr = cur_ptr; |
| 9198 | return NULL; |
| 9199 | } |
| 9200 | store_in_ref_table (die, reader->cu); |
| 9201 | |
| 9202 | if (has_children) |
| 9203 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
| 9204 | else |
| 9205 | { |
| 9206 | die->child = NULL; |
| 9207 | *new_info_ptr = cur_ptr; |
| 9208 | } |
| 9209 | |
| 9210 | die->sibling = NULL; |
| 9211 | die->parent = parent; |
| 9212 | return die; |
| 9213 | } |
| 9214 | |
| 9215 | /* Read a die, all of its descendents, and all of its siblings; set |
| 9216 | all of the fields of all of the dies correctly. Arguments are as |
| 9217 | in read_die_and_children. */ |
| 9218 | |
| 9219 | static struct die_info * |
| 9220 | read_die_and_siblings (const struct die_reader_specs *reader, |
| 9221 | gdb_byte *info_ptr, |
| 9222 | gdb_byte **new_info_ptr, |
| 9223 | struct die_info *parent) |
| 9224 | { |
| 9225 | struct die_info *first_die, *last_sibling; |
| 9226 | gdb_byte *cur_ptr; |
| 9227 | |
| 9228 | cur_ptr = info_ptr; |
| 9229 | first_die = last_sibling = NULL; |
| 9230 | |
| 9231 | while (1) |
| 9232 | { |
| 9233 | struct die_info *die |
| 9234 | = read_die_and_children_1 (reader, cur_ptr, &cur_ptr, parent); |
| 9235 | |
| 9236 | if (die == NULL) |
| 9237 | { |
| 9238 | *new_info_ptr = cur_ptr; |
| 9239 | return first_die; |
| 9240 | } |
| 9241 | |
| 9242 | if (!first_die) |
| 9243 | first_die = die; |
| 9244 | else |
| 9245 | last_sibling->sibling = die; |
| 9246 | |
| 9247 | last_sibling = die; |
| 9248 | } |
| 9249 | } |
| 9250 | |
| 9251 | /* Read the die from the .debug_info section buffer. Set DIEP to |
| 9252 | point to a newly allocated die with its information, except for its |
| 9253 | child, sibling, and parent fields. Set HAS_CHILDREN to tell |
| 9254 | whether the die has children or not. */ |
| 9255 | |
| 9256 | static gdb_byte * |
| 9257 | read_full_die (const struct die_reader_specs *reader, |
| 9258 | struct die_info **diep, gdb_byte *info_ptr, |
| 9259 | int *has_children) |
| 9260 | { |
| 9261 | unsigned int abbrev_number, bytes_read, i, offset; |
| 9262 | struct abbrev_info *abbrev; |
| 9263 | struct die_info *die; |
| 9264 | struct dwarf2_cu *cu = reader->cu; |
| 9265 | bfd *abfd = reader->abfd; |
| 9266 | |
| 9267 | offset = info_ptr - reader->buffer; |
| 9268 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 9269 | info_ptr += bytes_read; |
| 9270 | if (!abbrev_number) |
| 9271 | { |
| 9272 | *diep = NULL; |
| 9273 | *has_children = 0; |
| 9274 | return info_ptr; |
| 9275 | } |
| 9276 | |
| 9277 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu); |
| 9278 | if (!abbrev) |
| 9279 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
| 9280 | abbrev_number, |
| 9281 | bfd_get_filename (abfd)); |
| 9282 | |
| 9283 | die = dwarf_alloc_die (cu, abbrev->num_attrs); |
| 9284 | die->offset = offset; |
| 9285 | die->tag = abbrev->tag; |
| 9286 | die->abbrev = abbrev_number; |
| 9287 | |
| 9288 | die->num_attrs = abbrev->num_attrs; |
| 9289 | |
| 9290 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 9291 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], |
| 9292 | abfd, info_ptr, cu); |
| 9293 | |
| 9294 | *diep = die; |
| 9295 | *has_children = abbrev->has_children; |
| 9296 | return info_ptr; |
| 9297 | } |
| 9298 | |
| 9299 | /* In DWARF version 2, the description of the debugging information is |
| 9300 | stored in a separate .debug_abbrev section. Before we read any |
| 9301 | dies from a section we read in all abbreviations and install them |
| 9302 | in a hash table. This function also sets flags in CU describing |
| 9303 | the data found in the abbrev table. */ |
| 9304 | |
| 9305 | static void |
| 9306 | dwarf2_read_abbrevs (struct dwarf2_cu *cu) |
| 9307 | { |
| 9308 | bfd *abfd = cu->objfile->obfd; |
| 9309 | struct comp_unit_head *cu_header = &cu->header; |
| 9310 | gdb_byte *abbrev_ptr; |
| 9311 | struct abbrev_info *cur_abbrev; |
| 9312 | unsigned int abbrev_number, bytes_read, abbrev_name; |
| 9313 | unsigned int abbrev_form, hash_number; |
| 9314 | struct attr_abbrev *cur_attrs; |
| 9315 | unsigned int allocated_attrs; |
| 9316 | |
| 9317 | /* Initialize dwarf2 abbrevs. */ |
| 9318 | obstack_init (&cu->abbrev_obstack); |
| 9319 | cu->dwarf2_abbrevs = obstack_alloc (&cu->abbrev_obstack, |
| 9320 | (ABBREV_HASH_SIZE |
| 9321 | * sizeof (struct abbrev_info *))); |
| 9322 | memset (cu->dwarf2_abbrevs, 0, |
| 9323 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); |
| 9324 | |
| 9325 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 9326 | &dwarf2_per_objfile->abbrev); |
| 9327 | abbrev_ptr = dwarf2_per_objfile->abbrev.buffer + cu_header->abbrev_offset; |
| 9328 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9329 | abbrev_ptr += bytes_read; |
| 9330 | |
| 9331 | allocated_attrs = ATTR_ALLOC_CHUNK; |
| 9332 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); |
| 9333 | |
| 9334 | /* Loop until we reach an abbrev number of 0. */ |
| 9335 | while (abbrev_number) |
| 9336 | { |
| 9337 | cur_abbrev = dwarf_alloc_abbrev (cu); |
| 9338 | |
| 9339 | /* read in abbrev header */ |
| 9340 | cur_abbrev->number = abbrev_number; |
| 9341 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9342 | abbrev_ptr += bytes_read; |
| 9343 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); |
| 9344 | abbrev_ptr += 1; |
| 9345 | |
| 9346 | if (cur_abbrev->tag == DW_TAG_namespace) |
| 9347 | cu->has_namespace_info = 1; |
| 9348 | |
| 9349 | /* now read in declarations */ |
| 9350 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9351 | abbrev_ptr += bytes_read; |
| 9352 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9353 | abbrev_ptr += bytes_read; |
| 9354 | while (abbrev_name) |
| 9355 | { |
| 9356 | if (cur_abbrev->num_attrs == allocated_attrs) |
| 9357 | { |
| 9358 | allocated_attrs += ATTR_ALLOC_CHUNK; |
| 9359 | cur_attrs |
| 9360 | = xrealloc (cur_attrs, (allocated_attrs |
| 9361 | * sizeof (struct attr_abbrev))); |
| 9362 | } |
| 9363 | |
| 9364 | /* Record whether this compilation unit might have |
| 9365 | inter-compilation-unit references. If we don't know what form |
| 9366 | this attribute will have, then it might potentially be a |
| 9367 | DW_FORM_ref_addr, so we conservatively expect inter-CU |
| 9368 | references. */ |
| 9369 | |
| 9370 | if (abbrev_form == DW_FORM_ref_addr |
| 9371 | || abbrev_form == DW_FORM_indirect) |
| 9372 | cu->has_form_ref_addr = 1; |
| 9373 | |
| 9374 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
| 9375 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; |
| 9376 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9377 | abbrev_ptr += bytes_read; |
| 9378 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9379 | abbrev_ptr += bytes_read; |
| 9380 | } |
| 9381 | |
| 9382 | cur_abbrev->attrs = obstack_alloc (&cu->abbrev_obstack, |
| 9383 | (cur_abbrev->num_attrs |
| 9384 | * sizeof (struct attr_abbrev))); |
| 9385 | memcpy (cur_abbrev->attrs, cur_attrs, |
| 9386 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); |
| 9387 | |
| 9388 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
| 9389 | cur_abbrev->next = cu->dwarf2_abbrevs[hash_number]; |
| 9390 | cu->dwarf2_abbrevs[hash_number] = cur_abbrev; |
| 9391 | |
| 9392 | /* Get next abbreviation. |
| 9393 | Under Irix6 the abbreviations for a compilation unit are not |
| 9394 | always properly terminated with an abbrev number of 0. |
| 9395 | Exit loop if we encounter an abbreviation which we have |
| 9396 | already read (which means we are about to read the abbreviations |
| 9397 | for the next compile unit) or if the end of the abbreviation |
| 9398 | table is reached. */ |
| 9399 | if ((unsigned int) (abbrev_ptr - dwarf2_per_objfile->abbrev.buffer) |
| 9400 | >= dwarf2_per_objfile->abbrev.size) |
| 9401 | break; |
| 9402 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 9403 | abbrev_ptr += bytes_read; |
| 9404 | if (dwarf2_lookup_abbrev (abbrev_number, cu) != NULL) |
| 9405 | break; |
| 9406 | } |
| 9407 | |
| 9408 | xfree (cur_attrs); |
| 9409 | } |
| 9410 | |
| 9411 | /* Release the memory used by the abbrev table for a compilation unit. */ |
| 9412 | |
| 9413 | static void |
| 9414 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
| 9415 | { |
| 9416 | struct dwarf2_cu *cu = ptr_to_cu; |
| 9417 | |
| 9418 | obstack_free (&cu->abbrev_obstack, NULL); |
| 9419 | cu->dwarf2_abbrevs = NULL; |
| 9420 | } |
| 9421 | |
| 9422 | /* Lookup an abbrev_info structure in the abbrev hash table. */ |
| 9423 | |
| 9424 | static struct abbrev_info * |
| 9425 | dwarf2_lookup_abbrev (unsigned int number, struct dwarf2_cu *cu) |
| 9426 | { |
| 9427 | unsigned int hash_number; |
| 9428 | struct abbrev_info *abbrev; |
| 9429 | |
| 9430 | hash_number = number % ABBREV_HASH_SIZE; |
| 9431 | abbrev = cu->dwarf2_abbrevs[hash_number]; |
| 9432 | |
| 9433 | while (abbrev) |
| 9434 | { |
| 9435 | if (abbrev->number == number) |
| 9436 | return abbrev; |
| 9437 | else |
| 9438 | abbrev = abbrev->next; |
| 9439 | } |
| 9440 | return NULL; |
| 9441 | } |
| 9442 | |
| 9443 | /* Returns nonzero if TAG represents a type that we might generate a partial |
| 9444 | symbol for. */ |
| 9445 | |
| 9446 | static int |
| 9447 | is_type_tag_for_partial (int tag) |
| 9448 | { |
| 9449 | switch (tag) |
| 9450 | { |
| 9451 | #if 0 |
| 9452 | /* Some types that would be reasonable to generate partial symbols for, |
| 9453 | that we don't at present. */ |
| 9454 | case DW_TAG_array_type: |
| 9455 | case DW_TAG_file_type: |
| 9456 | case DW_TAG_ptr_to_member_type: |
| 9457 | case DW_TAG_set_type: |
| 9458 | case DW_TAG_string_type: |
| 9459 | case DW_TAG_subroutine_type: |
| 9460 | #endif |
| 9461 | case DW_TAG_base_type: |
| 9462 | case DW_TAG_class_type: |
| 9463 | case DW_TAG_interface_type: |
| 9464 | case DW_TAG_enumeration_type: |
| 9465 | case DW_TAG_structure_type: |
| 9466 | case DW_TAG_subrange_type: |
| 9467 | case DW_TAG_typedef: |
| 9468 | case DW_TAG_union_type: |
| 9469 | return 1; |
| 9470 | default: |
| 9471 | return 0; |
| 9472 | } |
| 9473 | } |
| 9474 | |
| 9475 | /* Load all DIEs that are interesting for partial symbols into memory. */ |
| 9476 | |
| 9477 | static struct partial_die_info * |
| 9478 | load_partial_dies (bfd *abfd, gdb_byte *buffer, gdb_byte *info_ptr, |
| 9479 | int building_psymtab, struct dwarf2_cu *cu) |
| 9480 | { |
| 9481 | struct objfile *objfile = cu->objfile; |
| 9482 | struct partial_die_info *part_die; |
| 9483 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; |
| 9484 | struct abbrev_info *abbrev; |
| 9485 | unsigned int bytes_read; |
| 9486 | unsigned int load_all = 0; |
| 9487 | |
| 9488 | int nesting_level = 1; |
| 9489 | |
| 9490 | parent_die = NULL; |
| 9491 | last_die = NULL; |
| 9492 | |
| 9493 | if (cu->per_cu && cu->per_cu->load_all_dies) |
| 9494 | load_all = 1; |
| 9495 | |
| 9496 | cu->partial_dies |
| 9497 | = htab_create_alloc_ex (cu->header.length / 12, |
| 9498 | partial_die_hash, |
| 9499 | partial_die_eq, |
| 9500 | NULL, |
| 9501 | &cu->comp_unit_obstack, |
| 9502 | hashtab_obstack_allocate, |
| 9503 | dummy_obstack_deallocate); |
| 9504 | |
| 9505 | part_die = obstack_alloc (&cu->comp_unit_obstack, |
| 9506 | sizeof (struct partial_die_info)); |
| 9507 | |
| 9508 | while (1) |
| 9509 | { |
| 9510 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); |
| 9511 | |
| 9512 | /* A NULL abbrev means the end of a series of children. */ |
| 9513 | if (abbrev == NULL) |
| 9514 | { |
| 9515 | if (--nesting_level == 0) |
| 9516 | { |
| 9517 | /* PART_DIE was probably the last thing allocated on the |
| 9518 | comp_unit_obstack, so we could call obstack_free |
| 9519 | here. We don't do that because the waste is small, |
| 9520 | and will be cleaned up when we're done with this |
| 9521 | compilation unit. This way, we're also more robust |
| 9522 | against other users of the comp_unit_obstack. */ |
| 9523 | return first_die; |
| 9524 | } |
| 9525 | info_ptr += bytes_read; |
| 9526 | last_die = parent_die; |
| 9527 | parent_die = parent_die->die_parent; |
| 9528 | continue; |
| 9529 | } |
| 9530 | |
| 9531 | /* Check for template arguments. We never save these; if |
| 9532 | they're seen, we just mark the parent, and go on our way. */ |
| 9533 | if (parent_die != NULL |
| 9534 | && cu->language == language_cplus |
| 9535 | && (abbrev->tag == DW_TAG_template_type_param |
| 9536 | || abbrev->tag == DW_TAG_template_value_param)) |
| 9537 | { |
| 9538 | parent_die->has_template_arguments = 1; |
| 9539 | |
| 9540 | if (!load_all) |
| 9541 | { |
| 9542 | /* We don't need a partial DIE for the template argument. */ |
| 9543 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, |
| 9544 | cu); |
| 9545 | continue; |
| 9546 | } |
| 9547 | } |
| 9548 | |
| 9549 | /* We only recurse into subprograms looking for template arguments. |
| 9550 | Skip their other children. */ |
| 9551 | if (!load_all |
| 9552 | && cu->language == language_cplus |
| 9553 | && parent_die != NULL |
| 9554 | && parent_die->tag == DW_TAG_subprogram) |
| 9555 | { |
| 9556 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
| 9557 | continue; |
| 9558 | } |
| 9559 | |
| 9560 | /* Check whether this DIE is interesting enough to save. Normally |
| 9561 | we would not be interested in members here, but there may be |
| 9562 | later variables referencing them via DW_AT_specification (for |
| 9563 | static members). */ |
| 9564 | if (!load_all |
| 9565 | && !is_type_tag_for_partial (abbrev->tag) |
| 9566 | && abbrev->tag != DW_TAG_constant |
| 9567 | && abbrev->tag != DW_TAG_enumerator |
| 9568 | && abbrev->tag != DW_TAG_subprogram |
| 9569 | && abbrev->tag != DW_TAG_lexical_block |
| 9570 | && abbrev->tag != DW_TAG_variable |
| 9571 | && abbrev->tag != DW_TAG_namespace |
| 9572 | && abbrev->tag != DW_TAG_module |
| 9573 | && abbrev->tag != DW_TAG_member) |
| 9574 | { |
| 9575 | /* Otherwise we skip to the next sibling, if any. */ |
| 9576 | info_ptr = skip_one_die (buffer, info_ptr + bytes_read, abbrev, cu); |
| 9577 | continue; |
| 9578 | } |
| 9579 | |
| 9580 | info_ptr = read_partial_die (part_die, abbrev, bytes_read, abfd, |
| 9581 | buffer, info_ptr, cu); |
| 9582 | |
| 9583 | /* This two-pass algorithm for processing partial symbols has a |
| 9584 | high cost in cache pressure. Thus, handle some simple cases |
| 9585 | here which cover the majority of C partial symbols. DIEs |
| 9586 | which neither have specification tags in them, nor could have |
| 9587 | specification tags elsewhere pointing at them, can simply be |
| 9588 | processed and discarded. |
| 9589 | |
| 9590 | This segment is also optional; scan_partial_symbols and |
| 9591 | add_partial_symbol will handle these DIEs if we chain |
| 9592 | them in normally. When compilers which do not emit large |
| 9593 | quantities of duplicate debug information are more common, |
| 9594 | this code can probably be removed. */ |
| 9595 | |
| 9596 | /* Any complete simple types at the top level (pretty much all |
| 9597 | of them, for a language without namespaces), can be processed |
| 9598 | directly. */ |
| 9599 | if (parent_die == NULL |
| 9600 | && part_die->has_specification == 0 |
| 9601 | && part_die->is_declaration == 0 |
| 9602 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
| 9603 | || part_die->tag == DW_TAG_base_type |
| 9604 | || part_die->tag == DW_TAG_subrange_type)) |
| 9605 | { |
| 9606 | if (building_psymtab && part_die->name != NULL) |
| 9607 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
| 9608 | VAR_DOMAIN, LOC_TYPEDEF, |
| 9609 | &objfile->static_psymbols, |
| 9610 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 9611 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
| 9612 | continue; |
| 9613 | } |
| 9614 | |
| 9615 | /* The exception for DW_TAG_typedef with has_children above is |
| 9616 | a workaround of GCC PR debug/47510. In the case of this complaint |
| 9617 | type_name_no_tag_or_error will error on such types later. |
| 9618 | |
| 9619 | GDB skipped children of DW_TAG_typedef by the shortcut above and then |
| 9620 | it could not find the child DIEs referenced later, this is checked |
| 9621 | above. In correct DWARF DW_TAG_typedef should have no children. */ |
| 9622 | |
| 9623 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) |
| 9624 | complaint (&symfile_complaints, |
| 9625 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " |
| 9626 | "- DIE at 0x%x [in module %s]"), |
| 9627 | part_die->offset, objfile->name); |
| 9628 | |
| 9629 | /* If we're at the second level, and we're an enumerator, and |
| 9630 | our parent has no specification (meaning possibly lives in a |
| 9631 | namespace elsewhere), then we can add the partial symbol now |
| 9632 | instead of queueing it. */ |
| 9633 | if (part_die->tag == DW_TAG_enumerator |
| 9634 | && parent_die != NULL |
| 9635 | && parent_die->die_parent == NULL |
| 9636 | && parent_die->tag == DW_TAG_enumeration_type |
| 9637 | && parent_die->has_specification == 0) |
| 9638 | { |
| 9639 | if (part_die->name == NULL) |
| 9640 | complaint (&symfile_complaints, |
| 9641 | _("malformed enumerator DIE ignored")); |
| 9642 | else if (building_psymtab) |
| 9643 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
| 9644 | VAR_DOMAIN, LOC_CONST, |
| 9645 | (cu->language == language_cplus |
| 9646 | || cu->language == language_java) |
| 9647 | ? &objfile->global_psymbols |
| 9648 | : &objfile->static_psymbols, |
| 9649 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 9650 | |
| 9651 | info_ptr = locate_pdi_sibling (part_die, buffer, info_ptr, abfd, cu); |
| 9652 | continue; |
| 9653 | } |
| 9654 | |
| 9655 | /* We'll save this DIE so link it in. */ |
| 9656 | part_die->die_parent = parent_die; |
| 9657 | part_die->die_sibling = NULL; |
| 9658 | part_die->die_child = NULL; |
| 9659 | |
| 9660 | if (last_die && last_die == parent_die) |
| 9661 | last_die->die_child = part_die; |
| 9662 | else if (last_die) |
| 9663 | last_die->die_sibling = part_die; |
| 9664 | |
| 9665 | last_die = part_die; |
| 9666 | |
| 9667 | if (first_die == NULL) |
| 9668 | first_die = part_die; |
| 9669 | |
| 9670 | /* Maybe add the DIE to the hash table. Not all DIEs that we |
| 9671 | find interesting need to be in the hash table, because we |
| 9672 | also have the parent/sibling/child chains; only those that we |
| 9673 | might refer to by offset later during partial symbol reading. |
| 9674 | |
| 9675 | For now this means things that might have be the target of a |
| 9676 | DW_AT_specification, DW_AT_abstract_origin, or |
| 9677 | DW_AT_extension. DW_AT_extension will refer only to |
| 9678 | namespaces; DW_AT_abstract_origin refers to functions (and |
| 9679 | many things under the function DIE, but we do not recurse |
| 9680 | into function DIEs during partial symbol reading) and |
| 9681 | possibly variables as well; DW_AT_specification refers to |
| 9682 | declarations. Declarations ought to have the DW_AT_declaration |
| 9683 | flag. It happens that GCC forgets to put it in sometimes, but |
| 9684 | only for functions, not for types. |
| 9685 | |
| 9686 | Adding more things than necessary to the hash table is harmless |
| 9687 | except for the performance cost. Adding too few will result in |
| 9688 | wasted time in find_partial_die, when we reread the compilation |
| 9689 | unit with load_all_dies set. */ |
| 9690 | |
| 9691 | if (load_all |
| 9692 | || abbrev->tag == DW_TAG_constant |
| 9693 | || abbrev->tag == DW_TAG_subprogram |
| 9694 | || abbrev->tag == DW_TAG_variable |
| 9695 | || abbrev->tag == DW_TAG_namespace |
| 9696 | || part_die->is_declaration) |
| 9697 | { |
| 9698 | void **slot; |
| 9699 | |
| 9700 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, |
| 9701 | part_die->offset, INSERT); |
| 9702 | *slot = part_die; |
| 9703 | } |
| 9704 | |
| 9705 | part_die = obstack_alloc (&cu->comp_unit_obstack, |
| 9706 | sizeof (struct partial_die_info)); |
| 9707 | |
| 9708 | /* For some DIEs we want to follow their children (if any). For C |
| 9709 | we have no reason to follow the children of structures; for other |
| 9710 | languages we have to, so that we can get at method physnames |
| 9711 | to infer fully qualified class names, for DW_AT_specification, |
| 9712 | and for C++ template arguments. For C++, we also look one level |
| 9713 | inside functions to find template arguments (if the name of the |
| 9714 | function does not already contain the template arguments). |
| 9715 | |
| 9716 | For Ada, we need to scan the children of subprograms and lexical |
| 9717 | blocks as well because Ada allows the definition of nested |
| 9718 | entities that could be interesting for the debugger, such as |
| 9719 | nested subprograms for instance. */ |
| 9720 | if (last_die->has_children |
| 9721 | && (load_all |
| 9722 | || last_die->tag == DW_TAG_namespace |
| 9723 | || last_die->tag == DW_TAG_module |
| 9724 | || last_die->tag == DW_TAG_enumeration_type |
| 9725 | || (cu->language == language_cplus |
| 9726 | && last_die->tag == DW_TAG_subprogram |
| 9727 | && (last_die->name == NULL |
| 9728 | || strchr (last_die->name, '<') == NULL)) |
| 9729 | || (cu->language != language_c |
| 9730 | && (last_die->tag == DW_TAG_class_type |
| 9731 | || last_die->tag == DW_TAG_interface_type |
| 9732 | || last_die->tag == DW_TAG_structure_type |
| 9733 | || last_die->tag == DW_TAG_union_type)) |
| 9734 | || (cu->language == language_ada |
| 9735 | && (last_die->tag == DW_TAG_subprogram |
| 9736 | || last_die->tag == DW_TAG_lexical_block)))) |
| 9737 | { |
| 9738 | nesting_level++; |
| 9739 | parent_die = last_die; |
| 9740 | continue; |
| 9741 | } |
| 9742 | |
| 9743 | /* Otherwise we skip to the next sibling, if any. */ |
| 9744 | info_ptr = locate_pdi_sibling (last_die, buffer, info_ptr, abfd, cu); |
| 9745 | |
| 9746 | /* Back to the top, do it again. */ |
| 9747 | } |
| 9748 | } |
| 9749 | |
| 9750 | /* Read a minimal amount of information into the minimal die structure. */ |
| 9751 | |
| 9752 | static gdb_byte * |
| 9753 | read_partial_die (struct partial_die_info *part_die, |
| 9754 | struct abbrev_info *abbrev, |
| 9755 | unsigned int abbrev_len, bfd *abfd, |
| 9756 | gdb_byte *buffer, gdb_byte *info_ptr, |
| 9757 | struct dwarf2_cu *cu) |
| 9758 | { |
| 9759 | struct objfile *objfile = cu->objfile; |
| 9760 | unsigned int i; |
| 9761 | struct attribute attr; |
| 9762 | int has_low_pc_attr = 0; |
| 9763 | int has_high_pc_attr = 0; |
| 9764 | |
| 9765 | memset (part_die, 0, sizeof (struct partial_die_info)); |
| 9766 | |
| 9767 | part_die->offset = info_ptr - buffer; |
| 9768 | |
| 9769 | info_ptr += abbrev_len; |
| 9770 | |
| 9771 | if (abbrev == NULL) |
| 9772 | return info_ptr; |
| 9773 | |
| 9774 | part_die->tag = abbrev->tag; |
| 9775 | part_die->has_children = abbrev->has_children; |
| 9776 | |
| 9777 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 9778 | { |
| 9779 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, info_ptr, cu); |
| 9780 | |
| 9781 | /* Store the data if it is of an attribute we want to keep in a |
| 9782 | partial symbol table. */ |
| 9783 | switch (attr.name) |
| 9784 | { |
| 9785 | case DW_AT_name: |
| 9786 | switch (part_die->tag) |
| 9787 | { |
| 9788 | case DW_TAG_compile_unit: |
| 9789 | case DW_TAG_type_unit: |
| 9790 | /* Compilation units have a DW_AT_name that is a filename, not |
| 9791 | a source language identifier. */ |
| 9792 | case DW_TAG_enumeration_type: |
| 9793 | case DW_TAG_enumerator: |
| 9794 | /* These tags always have simple identifiers already; no need |
| 9795 | to canonicalize them. */ |
| 9796 | part_die->name = DW_STRING (&attr); |
| 9797 | break; |
| 9798 | default: |
| 9799 | part_die->name |
| 9800 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, |
| 9801 | &objfile->objfile_obstack); |
| 9802 | break; |
| 9803 | } |
| 9804 | break; |
| 9805 | case DW_AT_linkage_name: |
| 9806 | case DW_AT_MIPS_linkage_name: |
| 9807 | /* Note that both forms of linkage name might appear. We |
| 9808 | assume they will be the same, and we only store the last |
| 9809 | one we see. */ |
| 9810 | if (cu->language == language_ada) |
| 9811 | part_die->name = DW_STRING (&attr); |
| 9812 | part_die->linkage_name = DW_STRING (&attr); |
| 9813 | break; |
| 9814 | case DW_AT_low_pc: |
| 9815 | has_low_pc_attr = 1; |
| 9816 | part_die->lowpc = DW_ADDR (&attr); |
| 9817 | break; |
| 9818 | case DW_AT_high_pc: |
| 9819 | has_high_pc_attr = 1; |
| 9820 | part_die->highpc = DW_ADDR (&attr); |
| 9821 | break; |
| 9822 | case DW_AT_location: |
| 9823 | /* Support the .debug_loc offsets. */ |
| 9824 | if (attr_form_is_block (&attr)) |
| 9825 | { |
| 9826 | part_die->locdesc = DW_BLOCK (&attr); |
| 9827 | } |
| 9828 | else if (attr_form_is_section_offset (&attr)) |
| 9829 | { |
| 9830 | dwarf2_complex_location_expr_complaint (); |
| 9831 | } |
| 9832 | else |
| 9833 | { |
| 9834 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 9835 | "partial symbol information"); |
| 9836 | } |
| 9837 | break; |
| 9838 | case DW_AT_external: |
| 9839 | part_die->is_external = DW_UNSND (&attr); |
| 9840 | break; |
| 9841 | case DW_AT_declaration: |
| 9842 | part_die->is_declaration = DW_UNSND (&attr); |
| 9843 | break; |
| 9844 | case DW_AT_type: |
| 9845 | part_die->has_type = 1; |
| 9846 | break; |
| 9847 | case DW_AT_abstract_origin: |
| 9848 | case DW_AT_specification: |
| 9849 | case DW_AT_extension: |
| 9850 | part_die->has_specification = 1; |
| 9851 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
| 9852 | break; |
| 9853 | case DW_AT_sibling: |
| 9854 | /* Ignore absolute siblings, they might point outside of |
| 9855 | the current compile unit. */ |
| 9856 | if (attr.form == DW_FORM_ref_addr) |
| 9857 | complaint (&symfile_complaints, |
| 9858 | _("ignoring absolute DW_AT_sibling")); |
| 9859 | else |
| 9860 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr); |
| 9861 | break; |
| 9862 | case DW_AT_byte_size: |
| 9863 | part_die->has_byte_size = 1; |
| 9864 | break; |
| 9865 | case DW_AT_calling_convention: |
| 9866 | /* DWARF doesn't provide a way to identify a program's source-level |
| 9867 | entry point. DW_AT_calling_convention attributes are only meant |
| 9868 | to describe functions' calling conventions. |
| 9869 | |
| 9870 | However, because it's a necessary piece of information in |
| 9871 | Fortran, and because DW_CC_program is the only piece of debugging |
| 9872 | information whose definition refers to a 'main program' at all, |
| 9873 | several compilers have begun marking Fortran main programs with |
| 9874 | DW_CC_program --- even when those functions use the standard |
| 9875 | calling conventions. |
| 9876 | |
| 9877 | So until DWARF specifies a way to provide this information and |
| 9878 | compilers pick up the new representation, we'll support this |
| 9879 | practice. */ |
| 9880 | if (DW_UNSND (&attr) == DW_CC_program |
| 9881 | && cu->language == language_fortran) |
| 9882 | { |
| 9883 | set_main_name (part_die->name); |
| 9884 | |
| 9885 | /* As this DIE has a static linkage the name would be difficult |
| 9886 | to look up later. */ |
| 9887 | language_of_main = language_fortran; |
| 9888 | } |
| 9889 | break; |
| 9890 | default: |
| 9891 | break; |
| 9892 | } |
| 9893 | } |
| 9894 | |
| 9895 | if (has_low_pc_attr && has_high_pc_attr) |
| 9896 | { |
| 9897 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 9898 | eliminate duplicate copies of functions and vtables and such. |
| 9899 | The linker will arbitrarily choose one and discard the others. |
| 9900 | The AT_*_pc values for such functions refer to local labels in |
| 9901 | these sections. If the section from that file was discarded, the |
| 9902 | labels are not in the output, so the relocs get a value of 0. |
| 9903 | If this is a discarded function, mark the pc bounds as invalid, |
| 9904 | so that GDB will ignore it. */ |
| 9905 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 9906 | { |
| 9907 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 9908 | |
| 9909 | complaint (&symfile_complaints, |
| 9910 | _("DW_AT_low_pc %s is zero " |
| 9911 | "for DIE at 0x%x [in module %s]"), |
| 9912 | paddress (gdbarch, part_die->lowpc), |
| 9913 | part_die->offset, objfile->name); |
| 9914 | } |
| 9915 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ |
| 9916 | else if (part_die->lowpc >= part_die->highpc) |
| 9917 | { |
| 9918 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 9919 | |
| 9920 | complaint (&symfile_complaints, |
| 9921 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " |
| 9922 | "for DIE at 0x%x [in module %s]"), |
| 9923 | paddress (gdbarch, part_die->lowpc), |
| 9924 | paddress (gdbarch, part_die->highpc), |
| 9925 | part_die->offset, objfile->name); |
| 9926 | } |
| 9927 | else |
| 9928 | part_die->has_pc_info = 1; |
| 9929 | } |
| 9930 | |
| 9931 | return info_ptr; |
| 9932 | } |
| 9933 | |
| 9934 | /* Find a cached partial DIE at OFFSET in CU. */ |
| 9935 | |
| 9936 | static struct partial_die_info * |
| 9937 | find_partial_die_in_comp_unit (unsigned int offset, struct dwarf2_cu *cu) |
| 9938 | { |
| 9939 | struct partial_die_info *lookup_die = NULL; |
| 9940 | struct partial_die_info part_die; |
| 9941 | |
| 9942 | part_die.offset = offset; |
| 9943 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, offset); |
| 9944 | |
| 9945 | return lookup_die; |
| 9946 | } |
| 9947 | |
| 9948 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
| 9949 | except in the case of .debug_types DIEs which do not reference |
| 9950 | outside their CU (they do however referencing other types via |
| 9951 | DW_FORM_ref_sig8). */ |
| 9952 | |
| 9953 | static struct partial_die_info * |
| 9954 | find_partial_die (unsigned int offset, struct dwarf2_cu *cu) |
| 9955 | { |
| 9956 | struct objfile *objfile = cu->objfile; |
| 9957 | struct dwarf2_per_cu_data *per_cu = NULL; |
| 9958 | struct partial_die_info *pd = NULL; |
| 9959 | |
| 9960 | if (cu->per_cu->debug_types_section) |
| 9961 | { |
| 9962 | pd = find_partial_die_in_comp_unit (offset, cu); |
| 9963 | if (pd != NULL) |
| 9964 | return pd; |
| 9965 | goto not_found; |
| 9966 | } |
| 9967 | |
| 9968 | if (offset_in_cu_p (&cu->header, offset)) |
| 9969 | { |
| 9970 | pd = find_partial_die_in_comp_unit (offset, cu); |
| 9971 | if (pd != NULL) |
| 9972 | return pd; |
| 9973 | } |
| 9974 | |
| 9975 | per_cu = dwarf2_find_containing_comp_unit (offset, objfile); |
| 9976 | |
| 9977 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
| 9978 | load_partial_comp_unit (per_cu); |
| 9979 | |
| 9980 | per_cu->cu->last_used = 0; |
| 9981 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
| 9982 | |
| 9983 | if (pd == NULL && per_cu->load_all_dies == 0) |
| 9984 | { |
| 9985 | struct cleanup *back_to; |
| 9986 | struct partial_die_info comp_unit_die; |
| 9987 | struct abbrev_info *abbrev; |
| 9988 | unsigned int bytes_read; |
| 9989 | char *info_ptr; |
| 9990 | |
| 9991 | per_cu->load_all_dies = 1; |
| 9992 | |
| 9993 | /* Re-read the DIEs. */ |
| 9994 | back_to = make_cleanup (null_cleanup, 0); |
| 9995 | if (per_cu->cu->dwarf2_abbrevs == NULL) |
| 9996 | { |
| 9997 | dwarf2_read_abbrevs (per_cu->cu); |
| 9998 | make_cleanup (dwarf2_free_abbrev_table, per_cu->cu); |
| 9999 | } |
| 10000 | info_ptr = (dwarf2_per_objfile->info.buffer |
| 10001 | + per_cu->cu->header.offset |
| 10002 | + per_cu->cu->header.first_die_offset); |
| 10003 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, per_cu->cu); |
| 10004 | info_ptr = read_partial_die (&comp_unit_die, abbrev, bytes_read, |
| 10005 | objfile->obfd, |
| 10006 | dwarf2_per_objfile->info.buffer, info_ptr, |
| 10007 | per_cu->cu); |
| 10008 | if (comp_unit_die.has_children) |
| 10009 | load_partial_dies (objfile->obfd, |
| 10010 | dwarf2_per_objfile->info.buffer, info_ptr, |
| 10011 | 0, per_cu->cu); |
| 10012 | do_cleanups (back_to); |
| 10013 | |
| 10014 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
| 10015 | } |
| 10016 | |
| 10017 | not_found: |
| 10018 | |
| 10019 | if (pd == NULL) |
| 10020 | internal_error (__FILE__, __LINE__, |
| 10021 | _("could not find partial DIE 0x%x " |
| 10022 | "in cache [from module %s]\n"), |
| 10023 | offset, bfd_get_filename (objfile->obfd)); |
| 10024 | return pd; |
| 10025 | } |
| 10026 | |
| 10027 | /* See if we can figure out if the class lives in a namespace. We do |
| 10028 | this by looking for a member function; its demangled name will |
| 10029 | contain namespace info, if there is any. */ |
| 10030 | |
| 10031 | static void |
| 10032 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, |
| 10033 | struct dwarf2_cu *cu) |
| 10034 | { |
| 10035 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
| 10036 | what template types look like, because the demangler |
| 10037 | frequently doesn't give the same name as the debug info. We |
| 10038 | could fix this by only using the demangled name to get the |
| 10039 | prefix (but see comment in read_structure_type). */ |
| 10040 | |
| 10041 | struct partial_die_info *real_pdi; |
| 10042 | struct partial_die_info *child_pdi; |
| 10043 | |
| 10044 | /* If this DIE (this DIE's specification, if any) has a parent, then |
| 10045 | we should not do this. We'll prepend the parent's fully qualified |
| 10046 | name when we create the partial symbol. */ |
| 10047 | |
| 10048 | real_pdi = struct_pdi; |
| 10049 | while (real_pdi->has_specification) |
| 10050 | real_pdi = find_partial_die (real_pdi->spec_offset, cu); |
| 10051 | |
| 10052 | if (real_pdi->die_parent != NULL) |
| 10053 | return; |
| 10054 | |
| 10055 | for (child_pdi = struct_pdi->die_child; |
| 10056 | child_pdi != NULL; |
| 10057 | child_pdi = child_pdi->die_sibling) |
| 10058 | { |
| 10059 | if (child_pdi->tag == DW_TAG_subprogram |
| 10060 | && child_pdi->linkage_name != NULL) |
| 10061 | { |
| 10062 | char *actual_class_name |
| 10063 | = language_class_name_from_physname (cu->language_defn, |
| 10064 | child_pdi->linkage_name); |
| 10065 | if (actual_class_name != NULL) |
| 10066 | { |
| 10067 | struct_pdi->name |
| 10068 | = obsavestring (actual_class_name, |
| 10069 | strlen (actual_class_name), |
| 10070 | &cu->objfile->objfile_obstack); |
| 10071 | xfree (actual_class_name); |
| 10072 | } |
| 10073 | break; |
| 10074 | } |
| 10075 | } |
| 10076 | } |
| 10077 | |
| 10078 | /* Adjust PART_DIE before generating a symbol for it. This function |
| 10079 | may set the is_external flag or change the DIE's name. */ |
| 10080 | |
| 10081 | static void |
| 10082 | fixup_partial_die (struct partial_die_info *part_die, |
| 10083 | struct dwarf2_cu *cu) |
| 10084 | { |
| 10085 | /* Once we've fixed up a die, there's no point in doing so again. |
| 10086 | This also avoids a memory leak if we were to call |
| 10087 | guess_partial_die_structure_name multiple times. */ |
| 10088 | if (part_die->fixup_called) |
| 10089 | return; |
| 10090 | |
| 10091 | /* If we found a reference attribute and the DIE has no name, try |
| 10092 | to find a name in the referred to DIE. */ |
| 10093 | |
| 10094 | if (part_die->name == NULL && part_die->has_specification) |
| 10095 | { |
| 10096 | struct partial_die_info *spec_die; |
| 10097 | |
| 10098 | spec_die = find_partial_die (part_die->spec_offset, cu); |
| 10099 | |
| 10100 | fixup_partial_die (spec_die, cu); |
| 10101 | |
| 10102 | if (spec_die->name) |
| 10103 | { |
| 10104 | part_die->name = spec_die->name; |
| 10105 | |
| 10106 | /* Copy DW_AT_external attribute if it is set. */ |
| 10107 | if (spec_die->is_external) |
| 10108 | part_die->is_external = spec_die->is_external; |
| 10109 | } |
| 10110 | } |
| 10111 | |
| 10112 | /* Set default names for some unnamed DIEs. */ |
| 10113 | |
| 10114 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) |
| 10115 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
| 10116 | |
| 10117 | /* If there is no parent die to provide a namespace, and there are |
| 10118 | children, see if we can determine the namespace from their linkage |
| 10119 | name. |
| 10120 | NOTE: We need to do this even if cu->has_namespace_info != 0. |
| 10121 | gcc-4.5 -gdwarf-4 can drop the enclosing namespace. */ |
| 10122 | if (cu->language == language_cplus |
| 10123 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
| 10124 | && part_die->die_parent == NULL |
| 10125 | && part_die->has_children |
| 10126 | && (part_die->tag == DW_TAG_class_type |
| 10127 | || part_die->tag == DW_TAG_structure_type |
| 10128 | || part_die->tag == DW_TAG_union_type)) |
| 10129 | guess_partial_die_structure_name (part_die, cu); |
| 10130 | |
| 10131 | /* GCC might emit a nameless struct or union that has a linkage |
| 10132 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ |
| 10133 | if (part_die->name == NULL |
| 10134 | && (part_die->tag == DW_TAG_class_type |
| 10135 | || part_die->tag == DW_TAG_interface_type |
| 10136 | || part_die->tag == DW_TAG_structure_type |
| 10137 | || part_die->tag == DW_TAG_union_type) |
| 10138 | && part_die->linkage_name != NULL) |
| 10139 | { |
| 10140 | char *demangled; |
| 10141 | |
| 10142 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); |
| 10143 | if (demangled) |
| 10144 | { |
| 10145 | const char *base; |
| 10146 | |
| 10147 | /* Strip any leading namespaces/classes, keep only the base name. |
| 10148 | DW_AT_name for named DIEs does not contain the prefixes. */ |
| 10149 | base = strrchr (demangled, ':'); |
| 10150 | if (base && base > demangled && base[-1] == ':') |
| 10151 | base++; |
| 10152 | else |
| 10153 | base = demangled; |
| 10154 | |
| 10155 | part_die->name = obsavestring (base, strlen (base), |
| 10156 | &cu->objfile->objfile_obstack); |
| 10157 | xfree (demangled); |
| 10158 | } |
| 10159 | } |
| 10160 | |
| 10161 | part_die->fixup_called = 1; |
| 10162 | } |
| 10163 | |
| 10164 | /* Read an attribute value described by an attribute form. */ |
| 10165 | |
| 10166 | static gdb_byte * |
| 10167 | read_attribute_value (struct attribute *attr, unsigned form, |
| 10168 | bfd *abfd, gdb_byte *info_ptr, |
| 10169 | struct dwarf2_cu *cu) |
| 10170 | { |
| 10171 | struct comp_unit_head *cu_header = &cu->header; |
| 10172 | unsigned int bytes_read; |
| 10173 | struct dwarf_block *blk; |
| 10174 | |
| 10175 | attr->form = form; |
| 10176 | switch (form) |
| 10177 | { |
| 10178 | case DW_FORM_ref_addr: |
| 10179 | if (cu->header.version == 2) |
| 10180 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
| 10181 | else |
| 10182 | DW_ADDR (attr) = read_offset (abfd, info_ptr, |
| 10183 | &cu->header, &bytes_read); |
| 10184 | info_ptr += bytes_read; |
| 10185 | break; |
| 10186 | case DW_FORM_addr: |
| 10187 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
| 10188 | info_ptr += bytes_read; |
| 10189 | break; |
| 10190 | case DW_FORM_block2: |
| 10191 | blk = dwarf_alloc_block (cu); |
| 10192 | blk->size = read_2_bytes (abfd, info_ptr); |
| 10193 | info_ptr += 2; |
| 10194 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 10195 | info_ptr += blk->size; |
| 10196 | DW_BLOCK (attr) = blk; |
| 10197 | break; |
| 10198 | case DW_FORM_block4: |
| 10199 | blk = dwarf_alloc_block (cu); |
| 10200 | blk->size = read_4_bytes (abfd, info_ptr); |
| 10201 | info_ptr += 4; |
| 10202 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 10203 | info_ptr += blk->size; |
| 10204 | DW_BLOCK (attr) = blk; |
| 10205 | break; |
| 10206 | case DW_FORM_data2: |
| 10207 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); |
| 10208 | info_ptr += 2; |
| 10209 | break; |
| 10210 | case DW_FORM_data4: |
| 10211 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); |
| 10212 | info_ptr += 4; |
| 10213 | break; |
| 10214 | case DW_FORM_data8: |
| 10215 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); |
| 10216 | info_ptr += 8; |
| 10217 | break; |
| 10218 | case DW_FORM_sec_offset: |
| 10219 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); |
| 10220 | info_ptr += bytes_read; |
| 10221 | break; |
| 10222 | case DW_FORM_string: |
| 10223 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
| 10224 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 10225 | info_ptr += bytes_read; |
| 10226 | break; |
| 10227 | case DW_FORM_strp: |
| 10228 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, |
| 10229 | &bytes_read); |
| 10230 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 10231 | info_ptr += bytes_read; |
| 10232 | break; |
| 10233 | case DW_FORM_exprloc: |
| 10234 | case DW_FORM_block: |
| 10235 | blk = dwarf_alloc_block (cu); |
| 10236 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 10237 | info_ptr += bytes_read; |
| 10238 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 10239 | info_ptr += blk->size; |
| 10240 | DW_BLOCK (attr) = blk; |
| 10241 | break; |
| 10242 | case DW_FORM_block1: |
| 10243 | blk = dwarf_alloc_block (cu); |
| 10244 | blk->size = read_1_byte (abfd, info_ptr); |
| 10245 | info_ptr += 1; |
| 10246 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 10247 | info_ptr += blk->size; |
| 10248 | DW_BLOCK (attr) = blk; |
| 10249 | break; |
| 10250 | case DW_FORM_data1: |
| 10251 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 10252 | info_ptr += 1; |
| 10253 | break; |
| 10254 | case DW_FORM_flag: |
| 10255 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 10256 | info_ptr += 1; |
| 10257 | break; |
| 10258 | case DW_FORM_flag_present: |
| 10259 | DW_UNSND (attr) = 1; |
| 10260 | break; |
| 10261 | case DW_FORM_sdata: |
| 10262 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); |
| 10263 | info_ptr += bytes_read; |
| 10264 | break; |
| 10265 | case DW_FORM_udata: |
| 10266 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 10267 | info_ptr += bytes_read; |
| 10268 | break; |
| 10269 | case DW_FORM_ref1: |
| 10270 | DW_ADDR (attr) = cu->header.offset + read_1_byte (abfd, info_ptr); |
| 10271 | info_ptr += 1; |
| 10272 | break; |
| 10273 | case DW_FORM_ref2: |
| 10274 | DW_ADDR (attr) = cu->header.offset + read_2_bytes (abfd, info_ptr); |
| 10275 | info_ptr += 2; |
| 10276 | break; |
| 10277 | case DW_FORM_ref4: |
| 10278 | DW_ADDR (attr) = cu->header.offset + read_4_bytes (abfd, info_ptr); |
| 10279 | info_ptr += 4; |
| 10280 | break; |
| 10281 | case DW_FORM_ref8: |
| 10282 | DW_ADDR (attr) = cu->header.offset + read_8_bytes (abfd, info_ptr); |
| 10283 | info_ptr += 8; |
| 10284 | break; |
| 10285 | case DW_FORM_ref_sig8: |
| 10286 | /* Convert the signature to something we can record in DW_UNSND |
| 10287 | for later lookup. |
| 10288 | NOTE: This is NULL if the type wasn't found. */ |
| 10289 | DW_SIGNATURED_TYPE (attr) = |
| 10290 | lookup_signatured_type (cu->objfile, read_8_bytes (abfd, info_ptr)); |
| 10291 | info_ptr += 8; |
| 10292 | break; |
| 10293 | case DW_FORM_ref_udata: |
| 10294 | DW_ADDR (attr) = (cu->header.offset |
| 10295 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); |
| 10296 | info_ptr += bytes_read; |
| 10297 | break; |
| 10298 | case DW_FORM_indirect: |
| 10299 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 10300 | info_ptr += bytes_read; |
| 10301 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu); |
| 10302 | break; |
| 10303 | default: |
| 10304 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
| 10305 | dwarf_form_name (form), |
| 10306 | bfd_get_filename (abfd)); |
| 10307 | } |
| 10308 | |
| 10309 | /* We have seen instances where the compiler tried to emit a byte |
| 10310 | size attribute of -1 which ended up being encoded as an unsigned |
| 10311 | 0xffffffff. Although 0xffffffff is technically a valid size value, |
| 10312 | an object of this size seems pretty unlikely so we can relatively |
| 10313 | safely treat these cases as if the size attribute was invalid and |
| 10314 | treat them as zero by default. */ |
| 10315 | if (attr->name == DW_AT_byte_size |
| 10316 | && form == DW_FORM_data4 |
| 10317 | && DW_UNSND (attr) >= 0xffffffff) |
| 10318 | { |
| 10319 | complaint |
| 10320 | (&symfile_complaints, |
| 10321 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
| 10322 | hex_string (DW_UNSND (attr))); |
| 10323 | DW_UNSND (attr) = 0; |
| 10324 | } |
| 10325 | |
| 10326 | return info_ptr; |
| 10327 | } |
| 10328 | |
| 10329 | /* Read an attribute described by an abbreviated attribute. */ |
| 10330 | |
| 10331 | static gdb_byte * |
| 10332 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
| 10333 | bfd *abfd, gdb_byte *info_ptr, struct dwarf2_cu *cu) |
| 10334 | { |
| 10335 | attr->name = abbrev->name; |
| 10336 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu); |
| 10337 | } |
| 10338 | |
| 10339 | /* Read dwarf information from a buffer. */ |
| 10340 | |
| 10341 | static unsigned int |
| 10342 | read_1_byte (bfd *abfd, gdb_byte *buf) |
| 10343 | { |
| 10344 | return bfd_get_8 (abfd, buf); |
| 10345 | } |
| 10346 | |
| 10347 | static int |
| 10348 | read_1_signed_byte (bfd *abfd, gdb_byte *buf) |
| 10349 | { |
| 10350 | return bfd_get_signed_8 (abfd, buf); |
| 10351 | } |
| 10352 | |
| 10353 | static unsigned int |
| 10354 | read_2_bytes (bfd *abfd, gdb_byte *buf) |
| 10355 | { |
| 10356 | return bfd_get_16 (abfd, buf); |
| 10357 | } |
| 10358 | |
| 10359 | static int |
| 10360 | read_2_signed_bytes (bfd *abfd, gdb_byte *buf) |
| 10361 | { |
| 10362 | return bfd_get_signed_16 (abfd, buf); |
| 10363 | } |
| 10364 | |
| 10365 | static unsigned int |
| 10366 | read_4_bytes (bfd *abfd, gdb_byte *buf) |
| 10367 | { |
| 10368 | return bfd_get_32 (abfd, buf); |
| 10369 | } |
| 10370 | |
| 10371 | static int |
| 10372 | read_4_signed_bytes (bfd *abfd, gdb_byte *buf) |
| 10373 | { |
| 10374 | return bfd_get_signed_32 (abfd, buf); |
| 10375 | } |
| 10376 | |
| 10377 | static ULONGEST |
| 10378 | read_8_bytes (bfd *abfd, gdb_byte *buf) |
| 10379 | { |
| 10380 | return bfd_get_64 (abfd, buf); |
| 10381 | } |
| 10382 | |
| 10383 | static CORE_ADDR |
| 10384 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
| 10385 | unsigned int *bytes_read) |
| 10386 | { |
| 10387 | struct comp_unit_head *cu_header = &cu->header; |
| 10388 | CORE_ADDR retval = 0; |
| 10389 | |
| 10390 | if (cu_header->signed_addr_p) |
| 10391 | { |
| 10392 | switch (cu_header->addr_size) |
| 10393 | { |
| 10394 | case 2: |
| 10395 | retval = bfd_get_signed_16 (abfd, buf); |
| 10396 | break; |
| 10397 | case 4: |
| 10398 | retval = bfd_get_signed_32 (abfd, buf); |
| 10399 | break; |
| 10400 | case 8: |
| 10401 | retval = bfd_get_signed_64 (abfd, buf); |
| 10402 | break; |
| 10403 | default: |
| 10404 | internal_error (__FILE__, __LINE__, |
| 10405 | _("read_address: bad switch, signed [in module %s]"), |
| 10406 | bfd_get_filename (abfd)); |
| 10407 | } |
| 10408 | } |
| 10409 | else |
| 10410 | { |
| 10411 | switch (cu_header->addr_size) |
| 10412 | { |
| 10413 | case 2: |
| 10414 | retval = bfd_get_16 (abfd, buf); |
| 10415 | break; |
| 10416 | case 4: |
| 10417 | retval = bfd_get_32 (abfd, buf); |
| 10418 | break; |
| 10419 | case 8: |
| 10420 | retval = bfd_get_64 (abfd, buf); |
| 10421 | break; |
| 10422 | default: |
| 10423 | internal_error (__FILE__, __LINE__, |
| 10424 | _("read_address: bad switch, " |
| 10425 | "unsigned [in module %s]"), |
| 10426 | bfd_get_filename (abfd)); |
| 10427 | } |
| 10428 | } |
| 10429 | |
| 10430 | *bytes_read = cu_header->addr_size; |
| 10431 | return retval; |
| 10432 | } |
| 10433 | |
| 10434 | /* Read the initial length from a section. The (draft) DWARF 3 |
| 10435 | specification allows the initial length to take up either 4 bytes |
| 10436 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 |
| 10437 | bytes describe the length and all offsets will be 8 bytes in length |
| 10438 | instead of 4. |
| 10439 | |
| 10440 | An older, non-standard 64-bit format is also handled by this |
| 10441 | function. The older format in question stores the initial length |
| 10442 | as an 8-byte quantity without an escape value. Lengths greater |
| 10443 | than 2^32 aren't very common which means that the initial 4 bytes |
| 10444 | is almost always zero. Since a length value of zero doesn't make |
| 10445 | sense for the 32-bit format, this initial zero can be considered to |
| 10446 | be an escape value which indicates the presence of the older 64-bit |
| 10447 | format. As written, the code can't detect (old format) lengths |
| 10448 | greater than 4GB. If it becomes necessary to handle lengths |
| 10449 | somewhat larger than 4GB, we could allow other small values (such |
| 10450 | as the non-sensical values of 1, 2, and 3) to also be used as |
| 10451 | escape values indicating the presence of the old format. |
| 10452 | |
| 10453 | The value returned via bytes_read should be used to increment the |
| 10454 | relevant pointer after calling read_initial_length(). |
| 10455 | |
| 10456 | [ Note: read_initial_length() and read_offset() are based on the |
| 10457 | document entitled "DWARF Debugging Information Format", revision |
| 10458 | 3, draft 8, dated November 19, 2001. This document was obtained |
| 10459 | from: |
| 10460 | |
| 10461 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
| 10462 | |
| 10463 | This document is only a draft and is subject to change. (So beware.) |
| 10464 | |
| 10465 | Details regarding the older, non-standard 64-bit format were |
| 10466 | determined empirically by examining 64-bit ELF files produced by |
| 10467 | the SGI toolchain on an IRIX 6.5 machine. |
| 10468 | |
| 10469 | - Kevin, July 16, 2002 |
| 10470 | ] */ |
| 10471 | |
| 10472 | static LONGEST |
| 10473 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
| 10474 | { |
| 10475 | LONGEST length = bfd_get_32 (abfd, buf); |
| 10476 | |
| 10477 | if (length == 0xffffffff) |
| 10478 | { |
| 10479 | length = bfd_get_64 (abfd, buf + 4); |
| 10480 | *bytes_read = 12; |
| 10481 | } |
| 10482 | else if (length == 0) |
| 10483 | { |
| 10484 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
| 10485 | length = bfd_get_64 (abfd, buf); |
| 10486 | *bytes_read = 8; |
| 10487 | } |
| 10488 | else |
| 10489 | { |
| 10490 | *bytes_read = 4; |
| 10491 | } |
| 10492 | |
| 10493 | return length; |
| 10494 | } |
| 10495 | |
| 10496 | /* Cover function for read_initial_length. |
| 10497 | Returns the length of the object at BUF, and stores the size of the |
| 10498 | initial length in *BYTES_READ and stores the size that offsets will be in |
| 10499 | *OFFSET_SIZE. |
| 10500 | If the initial length size is not equivalent to that specified in |
| 10501 | CU_HEADER then issue a complaint. |
| 10502 | This is useful when reading non-comp-unit headers. */ |
| 10503 | |
| 10504 | static LONGEST |
| 10505 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, |
| 10506 | const struct comp_unit_head *cu_header, |
| 10507 | unsigned int *bytes_read, |
| 10508 | unsigned int *offset_size) |
| 10509 | { |
| 10510 | LONGEST length = read_initial_length (abfd, buf, bytes_read); |
| 10511 | |
| 10512 | gdb_assert (cu_header->initial_length_size == 4 |
| 10513 | || cu_header->initial_length_size == 8 |
| 10514 | || cu_header->initial_length_size == 12); |
| 10515 | |
| 10516 | if (cu_header->initial_length_size != *bytes_read) |
| 10517 | complaint (&symfile_complaints, |
| 10518 | _("intermixed 32-bit and 64-bit DWARF sections")); |
| 10519 | |
| 10520 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
| 10521 | return length; |
| 10522 | } |
| 10523 | |
| 10524 | /* Read an offset from the data stream. The size of the offset is |
| 10525 | given by cu_header->offset_size. */ |
| 10526 | |
| 10527 | static LONGEST |
| 10528 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
| 10529 | unsigned int *bytes_read) |
| 10530 | { |
| 10531 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); |
| 10532 | |
| 10533 | *bytes_read = cu_header->offset_size; |
| 10534 | return offset; |
| 10535 | } |
| 10536 | |
| 10537 | /* Read an offset from the data stream. */ |
| 10538 | |
| 10539 | static LONGEST |
| 10540 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) |
| 10541 | { |
| 10542 | LONGEST retval = 0; |
| 10543 | |
| 10544 | switch (offset_size) |
| 10545 | { |
| 10546 | case 4: |
| 10547 | retval = bfd_get_32 (abfd, buf); |
| 10548 | break; |
| 10549 | case 8: |
| 10550 | retval = bfd_get_64 (abfd, buf); |
| 10551 | break; |
| 10552 | default: |
| 10553 | internal_error (__FILE__, __LINE__, |
| 10554 | _("read_offset_1: bad switch [in module %s]"), |
| 10555 | bfd_get_filename (abfd)); |
| 10556 | } |
| 10557 | |
| 10558 | return retval; |
| 10559 | } |
| 10560 | |
| 10561 | static gdb_byte * |
| 10562 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) |
| 10563 | { |
| 10564 | /* If the size of a host char is 8 bits, we can return a pointer |
| 10565 | to the buffer, otherwise we have to copy the data to a buffer |
| 10566 | allocated on the temporary obstack. */ |
| 10567 | gdb_assert (HOST_CHAR_BIT == 8); |
| 10568 | return buf; |
| 10569 | } |
| 10570 | |
| 10571 | static char * |
| 10572 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 10573 | { |
| 10574 | /* If the size of a host char is 8 bits, we can return a pointer |
| 10575 | to the string, otherwise we have to copy the string to a buffer |
| 10576 | allocated on the temporary obstack. */ |
| 10577 | gdb_assert (HOST_CHAR_BIT == 8); |
| 10578 | if (*buf == '\0') |
| 10579 | { |
| 10580 | *bytes_read_ptr = 1; |
| 10581 | return NULL; |
| 10582 | } |
| 10583 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
| 10584 | return (char *) buf; |
| 10585 | } |
| 10586 | |
| 10587 | static char * |
| 10588 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
| 10589 | { |
| 10590 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
| 10591 | if (dwarf2_per_objfile->str.buffer == NULL) |
| 10592 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
| 10593 | bfd_get_filename (abfd)); |
| 10594 | if (str_offset >= dwarf2_per_objfile->str.size) |
| 10595 | error (_("DW_FORM_strp pointing outside of " |
| 10596 | ".debug_str section [in module %s]"), |
| 10597 | bfd_get_filename (abfd)); |
| 10598 | gdb_assert (HOST_CHAR_BIT == 8); |
| 10599 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
| 10600 | return NULL; |
| 10601 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
| 10602 | } |
| 10603 | |
| 10604 | static char * |
| 10605 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
| 10606 | const struct comp_unit_head *cu_header, |
| 10607 | unsigned int *bytes_read_ptr) |
| 10608 | { |
| 10609 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
| 10610 | |
| 10611 | return read_indirect_string_at_offset (abfd, str_offset); |
| 10612 | } |
| 10613 | |
| 10614 | static unsigned long |
| 10615 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 10616 | { |
| 10617 | unsigned long result; |
| 10618 | unsigned int num_read; |
| 10619 | int i, shift; |
| 10620 | unsigned char byte; |
| 10621 | |
| 10622 | result = 0; |
| 10623 | shift = 0; |
| 10624 | num_read = 0; |
| 10625 | i = 0; |
| 10626 | while (1) |
| 10627 | { |
| 10628 | byte = bfd_get_8 (abfd, buf); |
| 10629 | buf++; |
| 10630 | num_read++; |
| 10631 | result |= ((unsigned long)(byte & 127) << shift); |
| 10632 | if ((byte & 128) == 0) |
| 10633 | { |
| 10634 | break; |
| 10635 | } |
| 10636 | shift += 7; |
| 10637 | } |
| 10638 | *bytes_read_ptr = num_read; |
| 10639 | return result; |
| 10640 | } |
| 10641 | |
| 10642 | static long |
| 10643 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 10644 | { |
| 10645 | long result; |
| 10646 | int i, shift, num_read; |
| 10647 | unsigned char byte; |
| 10648 | |
| 10649 | result = 0; |
| 10650 | shift = 0; |
| 10651 | num_read = 0; |
| 10652 | i = 0; |
| 10653 | while (1) |
| 10654 | { |
| 10655 | byte = bfd_get_8 (abfd, buf); |
| 10656 | buf++; |
| 10657 | num_read++; |
| 10658 | result |= ((long)(byte & 127) << shift); |
| 10659 | shift += 7; |
| 10660 | if ((byte & 128) == 0) |
| 10661 | { |
| 10662 | break; |
| 10663 | } |
| 10664 | } |
| 10665 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
| 10666 | result |= -(((long)1) << shift); |
| 10667 | *bytes_read_ptr = num_read; |
| 10668 | return result; |
| 10669 | } |
| 10670 | |
| 10671 | /* Return a pointer to just past the end of an LEB128 number in BUF. */ |
| 10672 | |
| 10673 | static gdb_byte * |
| 10674 | skip_leb128 (bfd *abfd, gdb_byte *buf) |
| 10675 | { |
| 10676 | int byte; |
| 10677 | |
| 10678 | while (1) |
| 10679 | { |
| 10680 | byte = bfd_get_8 (abfd, buf); |
| 10681 | buf++; |
| 10682 | if ((byte & 128) == 0) |
| 10683 | return buf; |
| 10684 | } |
| 10685 | } |
| 10686 | |
| 10687 | static void |
| 10688 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
| 10689 | { |
| 10690 | switch (lang) |
| 10691 | { |
| 10692 | case DW_LANG_C89: |
| 10693 | case DW_LANG_C99: |
| 10694 | case DW_LANG_C: |
| 10695 | cu->language = language_c; |
| 10696 | break; |
| 10697 | case DW_LANG_C_plus_plus: |
| 10698 | cu->language = language_cplus; |
| 10699 | break; |
| 10700 | case DW_LANG_D: |
| 10701 | cu->language = language_d; |
| 10702 | break; |
| 10703 | case DW_LANG_Fortran77: |
| 10704 | case DW_LANG_Fortran90: |
| 10705 | case DW_LANG_Fortran95: |
| 10706 | cu->language = language_fortran; |
| 10707 | break; |
| 10708 | case DW_LANG_Mips_Assembler: |
| 10709 | cu->language = language_asm; |
| 10710 | break; |
| 10711 | case DW_LANG_Java: |
| 10712 | cu->language = language_java; |
| 10713 | break; |
| 10714 | case DW_LANG_Ada83: |
| 10715 | case DW_LANG_Ada95: |
| 10716 | cu->language = language_ada; |
| 10717 | break; |
| 10718 | case DW_LANG_Modula2: |
| 10719 | cu->language = language_m2; |
| 10720 | break; |
| 10721 | case DW_LANG_Pascal83: |
| 10722 | cu->language = language_pascal; |
| 10723 | break; |
| 10724 | case DW_LANG_ObjC: |
| 10725 | cu->language = language_objc; |
| 10726 | break; |
| 10727 | case DW_LANG_Cobol74: |
| 10728 | case DW_LANG_Cobol85: |
| 10729 | default: |
| 10730 | cu->language = language_minimal; |
| 10731 | break; |
| 10732 | } |
| 10733 | cu->language_defn = language_def (cu->language); |
| 10734 | } |
| 10735 | |
| 10736 | /* Return the named attribute or NULL if not there. */ |
| 10737 | |
| 10738 | static struct attribute * |
| 10739 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
| 10740 | { |
| 10741 | unsigned int i; |
| 10742 | struct attribute *spec = NULL; |
| 10743 | |
| 10744 | for (i = 0; i < die->num_attrs; ++i) |
| 10745 | { |
| 10746 | if (die->attrs[i].name == name) |
| 10747 | return &die->attrs[i]; |
| 10748 | if (die->attrs[i].name == DW_AT_specification |
| 10749 | || die->attrs[i].name == DW_AT_abstract_origin) |
| 10750 | spec = &die->attrs[i]; |
| 10751 | } |
| 10752 | |
| 10753 | if (spec) |
| 10754 | { |
| 10755 | die = follow_die_ref (die, spec, &cu); |
| 10756 | return dwarf2_attr (die, name, cu); |
| 10757 | } |
| 10758 | |
| 10759 | return NULL; |
| 10760 | } |
| 10761 | |
| 10762 | /* Return the named attribute or NULL if not there, |
| 10763 | but do not follow DW_AT_specification, etc. |
| 10764 | This is for use in contexts where we're reading .debug_types dies. |
| 10765 | Following DW_AT_specification, DW_AT_abstract_origin will take us |
| 10766 | back up the chain, and we want to go down. */ |
| 10767 | |
| 10768 | static struct attribute * |
| 10769 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name, |
| 10770 | struct dwarf2_cu *cu) |
| 10771 | { |
| 10772 | unsigned int i; |
| 10773 | |
| 10774 | for (i = 0; i < die->num_attrs; ++i) |
| 10775 | if (die->attrs[i].name == name) |
| 10776 | return &die->attrs[i]; |
| 10777 | |
| 10778 | return NULL; |
| 10779 | } |
| 10780 | |
| 10781 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
| 10782 | and holds a non-zero value. This function should only be used for |
| 10783 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
| 10784 | |
| 10785 | static int |
| 10786 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) |
| 10787 | { |
| 10788 | struct attribute *attr = dwarf2_attr (die, name, cu); |
| 10789 | |
| 10790 | return (attr && DW_UNSND (attr)); |
| 10791 | } |
| 10792 | |
| 10793 | static int |
| 10794 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
| 10795 | { |
| 10796 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
| 10797 | which value is non-zero. However, we have to be careful with |
| 10798 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() |
| 10799 | (via dwarf2_flag_true_p) follows this attribute. So we may |
| 10800 | end up accidently finding a declaration attribute that belongs |
| 10801 | to a different DIE referenced by the specification attribute, |
| 10802 | even though the given DIE does not have a declaration attribute. */ |
| 10803 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) |
| 10804 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); |
| 10805 | } |
| 10806 | |
| 10807 | /* Return the die giving the specification for DIE, if there is |
| 10808 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
| 10809 | containing the return value on output. If there is no |
| 10810 | specification, but there is an abstract origin, that is |
| 10811 | returned. */ |
| 10812 | |
| 10813 | static struct die_info * |
| 10814 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
| 10815 | { |
| 10816 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
| 10817 | *spec_cu); |
| 10818 | |
| 10819 | if (spec_attr == NULL) |
| 10820 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); |
| 10821 | |
| 10822 | if (spec_attr == NULL) |
| 10823 | return NULL; |
| 10824 | else |
| 10825 | return follow_die_ref (die, spec_attr, spec_cu); |
| 10826 | } |
| 10827 | |
| 10828 | /* Free the line_header structure *LH, and any arrays and strings it |
| 10829 | refers to. |
| 10830 | NOTE: This is also used as a "cleanup" function. */ |
| 10831 | |
| 10832 | static void |
| 10833 | free_line_header (struct line_header *lh) |
| 10834 | { |
| 10835 | if (lh->standard_opcode_lengths) |
| 10836 | xfree (lh->standard_opcode_lengths); |
| 10837 | |
| 10838 | /* Remember that all the lh->file_names[i].name pointers are |
| 10839 | pointers into debug_line_buffer, and don't need to be freed. */ |
| 10840 | if (lh->file_names) |
| 10841 | xfree (lh->file_names); |
| 10842 | |
| 10843 | /* Similarly for the include directory names. */ |
| 10844 | if (lh->include_dirs) |
| 10845 | xfree (lh->include_dirs); |
| 10846 | |
| 10847 | xfree (lh); |
| 10848 | } |
| 10849 | |
| 10850 | /* Add an entry to LH's include directory table. */ |
| 10851 | |
| 10852 | static void |
| 10853 | add_include_dir (struct line_header *lh, char *include_dir) |
| 10854 | { |
| 10855 | /* Grow the array if necessary. */ |
| 10856 | if (lh->include_dirs_size == 0) |
| 10857 | { |
| 10858 | lh->include_dirs_size = 1; /* for testing */ |
| 10859 | lh->include_dirs = xmalloc (lh->include_dirs_size |
| 10860 | * sizeof (*lh->include_dirs)); |
| 10861 | } |
| 10862 | else if (lh->num_include_dirs >= lh->include_dirs_size) |
| 10863 | { |
| 10864 | lh->include_dirs_size *= 2; |
| 10865 | lh->include_dirs = xrealloc (lh->include_dirs, |
| 10866 | (lh->include_dirs_size |
| 10867 | * sizeof (*lh->include_dirs))); |
| 10868 | } |
| 10869 | |
| 10870 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
| 10871 | } |
| 10872 | |
| 10873 | /* Add an entry to LH's file name table. */ |
| 10874 | |
| 10875 | static void |
| 10876 | add_file_name (struct line_header *lh, |
| 10877 | char *name, |
| 10878 | unsigned int dir_index, |
| 10879 | unsigned int mod_time, |
| 10880 | unsigned int length) |
| 10881 | { |
| 10882 | struct file_entry *fe; |
| 10883 | |
| 10884 | /* Grow the array if necessary. */ |
| 10885 | if (lh->file_names_size == 0) |
| 10886 | { |
| 10887 | lh->file_names_size = 1; /* for testing */ |
| 10888 | lh->file_names = xmalloc (lh->file_names_size |
| 10889 | * sizeof (*lh->file_names)); |
| 10890 | } |
| 10891 | else if (lh->num_file_names >= lh->file_names_size) |
| 10892 | { |
| 10893 | lh->file_names_size *= 2; |
| 10894 | lh->file_names = xrealloc (lh->file_names, |
| 10895 | (lh->file_names_size |
| 10896 | * sizeof (*lh->file_names))); |
| 10897 | } |
| 10898 | |
| 10899 | fe = &lh->file_names[lh->num_file_names++]; |
| 10900 | fe->name = name; |
| 10901 | fe->dir_index = dir_index; |
| 10902 | fe->mod_time = mod_time; |
| 10903 | fe->length = length; |
| 10904 | fe->included_p = 0; |
| 10905 | fe->symtab = NULL; |
| 10906 | } |
| 10907 | |
| 10908 | /* Read the statement program header starting at OFFSET in |
| 10909 | .debug_line, according to the endianness of ABFD. Return a pointer |
| 10910 | to a struct line_header, allocated using xmalloc. |
| 10911 | |
| 10912 | NOTE: the strings in the include directory and file name tables of |
| 10913 | the returned object point into debug_line_buffer, and must not be |
| 10914 | freed. */ |
| 10915 | |
| 10916 | static struct line_header * |
| 10917 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, |
| 10918 | struct dwarf2_cu *cu) |
| 10919 | { |
| 10920 | struct cleanup *back_to; |
| 10921 | struct line_header *lh; |
| 10922 | gdb_byte *line_ptr; |
| 10923 | unsigned int bytes_read, offset_size; |
| 10924 | int i; |
| 10925 | char *cur_dir, *cur_file; |
| 10926 | |
| 10927 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->line); |
| 10928 | if (dwarf2_per_objfile->line.buffer == NULL) |
| 10929 | { |
| 10930 | complaint (&symfile_complaints, _("missing .debug_line section")); |
| 10931 | return 0; |
| 10932 | } |
| 10933 | |
| 10934 | /* Make sure that at least there's room for the total_length field. |
| 10935 | That could be 12 bytes long, but we're just going to fudge that. */ |
| 10936 | if (offset + 4 >= dwarf2_per_objfile->line.size) |
| 10937 | { |
| 10938 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 10939 | return 0; |
| 10940 | } |
| 10941 | |
| 10942 | lh = xmalloc (sizeof (*lh)); |
| 10943 | memset (lh, 0, sizeof (*lh)); |
| 10944 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, |
| 10945 | (void *) lh); |
| 10946 | |
| 10947 | line_ptr = dwarf2_per_objfile->line.buffer + offset; |
| 10948 | |
| 10949 | /* Read in the header. */ |
| 10950 | lh->total_length = |
| 10951 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
| 10952 | &bytes_read, &offset_size); |
| 10953 | line_ptr += bytes_read; |
| 10954 | if (line_ptr + lh->total_length > (dwarf2_per_objfile->line.buffer |
| 10955 | + dwarf2_per_objfile->line.size)) |
| 10956 | { |
| 10957 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 10958 | return 0; |
| 10959 | } |
| 10960 | lh->statement_program_end = line_ptr + lh->total_length; |
| 10961 | lh->version = read_2_bytes (abfd, line_ptr); |
| 10962 | line_ptr += 2; |
| 10963 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
| 10964 | line_ptr += offset_size; |
| 10965 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
| 10966 | line_ptr += 1; |
| 10967 | if (lh->version >= 4) |
| 10968 | { |
| 10969 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); |
| 10970 | line_ptr += 1; |
| 10971 | } |
| 10972 | else |
| 10973 | lh->maximum_ops_per_instruction = 1; |
| 10974 | |
| 10975 | if (lh->maximum_ops_per_instruction == 0) |
| 10976 | { |
| 10977 | lh->maximum_ops_per_instruction = 1; |
| 10978 | complaint (&symfile_complaints, |
| 10979 | _("invalid maximum_ops_per_instruction " |
| 10980 | "in `.debug_line' section")); |
| 10981 | } |
| 10982 | |
| 10983 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
| 10984 | line_ptr += 1; |
| 10985 | lh->line_base = read_1_signed_byte (abfd, line_ptr); |
| 10986 | line_ptr += 1; |
| 10987 | lh->line_range = read_1_byte (abfd, line_ptr); |
| 10988 | line_ptr += 1; |
| 10989 | lh->opcode_base = read_1_byte (abfd, line_ptr); |
| 10990 | line_ptr += 1; |
| 10991 | lh->standard_opcode_lengths |
| 10992 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
| 10993 | |
| 10994 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ |
| 10995 | for (i = 1; i < lh->opcode_base; ++i) |
| 10996 | { |
| 10997 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); |
| 10998 | line_ptr += 1; |
| 10999 | } |
| 11000 | |
| 11001 | /* Read directory table. */ |
| 11002 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 11003 | { |
| 11004 | line_ptr += bytes_read; |
| 11005 | add_include_dir (lh, cur_dir); |
| 11006 | } |
| 11007 | line_ptr += bytes_read; |
| 11008 | |
| 11009 | /* Read file name table. */ |
| 11010 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 11011 | { |
| 11012 | unsigned int dir_index, mod_time, length; |
| 11013 | |
| 11014 | line_ptr += bytes_read; |
| 11015 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11016 | line_ptr += bytes_read; |
| 11017 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11018 | line_ptr += bytes_read; |
| 11019 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11020 | line_ptr += bytes_read; |
| 11021 | |
| 11022 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 11023 | } |
| 11024 | line_ptr += bytes_read; |
| 11025 | lh->statement_program_start = line_ptr; |
| 11026 | |
| 11027 | if (line_ptr > (dwarf2_per_objfile->line.buffer |
| 11028 | + dwarf2_per_objfile->line.size)) |
| 11029 | complaint (&symfile_complaints, |
| 11030 | _("line number info header doesn't " |
| 11031 | "fit in `.debug_line' section")); |
| 11032 | |
| 11033 | discard_cleanups (back_to); |
| 11034 | return lh; |
| 11035 | } |
| 11036 | |
| 11037 | /* Subroutine of dwarf_decode_lines to simplify it. |
| 11038 | Return the file name of the psymtab for included file FILE_INDEX |
| 11039 | in line header LH of PST. |
| 11040 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. |
| 11041 | If space for the result is malloc'd, it will be freed by a cleanup. |
| 11042 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ |
| 11043 | |
| 11044 | static char * |
| 11045 | psymtab_include_file_name (const struct line_header *lh, int file_index, |
| 11046 | const struct partial_symtab *pst, |
| 11047 | const char *comp_dir) |
| 11048 | { |
| 11049 | const struct file_entry fe = lh->file_names [file_index]; |
| 11050 | char *include_name = fe.name; |
| 11051 | char *include_name_to_compare = include_name; |
| 11052 | char *dir_name = NULL; |
| 11053 | const char *pst_filename; |
| 11054 | char *copied_name = NULL; |
| 11055 | int file_is_pst; |
| 11056 | |
| 11057 | if (fe.dir_index) |
| 11058 | dir_name = lh->include_dirs[fe.dir_index - 1]; |
| 11059 | |
| 11060 | if (!IS_ABSOLUTE_PATH (include_name) |
| 11061 | && (dir_name != NULL || comp_dir != NULL)) |
| 11062 | { |
| 11063 | /* Avoid creating a duplicate psymtab for PST. |
| 11064 | We do this by comparing INCLUDE_NAME and PST_FILENAME. |
| 11065 | Before we do the comparison, however, we need to account |
| 11066 | for DIR_NAME and COMP_DIR. |
| 11067 | First prepend dir_name (if non-NULL). If we still don't |
| 11068 | have an absolute path prepend comp_dir (if non-NULL). |
| 11069 | However, the directory we record in the include-file's |
| 11070 | psymtab does not contain COMP_DIR (to match the |
| 11071 | corresponding symtab(s)). |
| 11072 | |
| 11073 | Example: |
| 11074 | |
| 11075 | bash$ cd /tmp |
| 11076 | bash$ gcc -g ./hello.c |
| 11077 | include_name = "hello.c" |
| 11078 | dir_name = "." |
| 11079 | DW_AT_comp_dir = comp_dir = "/tmp" |
| 11080 | DW_AT_name = "./hello.c" */ |
| 11081 | |
| 11082 | if (dir_name != NULL) |
| 11083 | { |
| 11084 | include_name = concat (dir_name, SLASH_STRING, |
| 11085 | include_name, (char *)NULL); |
| 11086 | include_name_to_compare = include_name; |
| 11087 | make_cleanup (xfree, include_name); |
| 11088 | } |
| 11089 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) |
| 11090 | { |
| 11091 | include_name_to_compare = concat (comp_dir, SLASH_STRING, |
| 11092 | include_name, (char *)NULL); |
| 11093 | } |
| 11094 | } |
| 11095 | |
| 11096 | pst_filename = pst->filename; |
| 11097 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) |
| 11098 | { |
| 11099 | copied_name = concat (pst->dirname, SLASH_STRING, |
| 11100 | pst_filename, (char *)NULL); |
| 11101 | pst_filename = copied_name; |
| 11102 | } |
| 11103 | |
| 11104 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
| 11105 | |
| 11106 | if (include_name_to_compare != include_name) |
| 11107 | xfree (include_name_to_compare); |
| 11108 | if (copied_name != NULL) |
| 11109 | xfree (copied_name); |
| 11110 | |
| 11111 | if (file_is_pst) |
| 11112 | return NULL; |
| 11113 | return include_name; |
| 11114 | } |
| 11115 | |
| 11116 | /* Ignore this record_line request. */ |
| 11117 | |
| 11118 | static void |
| 11119 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) |
| 11120 | { |
| 11121 | return; |
| 11122 | } |
| 11123 | |
| 11124 | /* Subroutine of dwarf_decode_lines to simplify it. |
| 11125 | Process the line number information in LH. */ |
| 11126 | |
| 11127 | static void |
| 11128 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
| 11129 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
| 11130 | { |
| 11131 | gdb_byte *line_ptr, *extended_end; |
| 11132 | gdb_byte *line_end; |
| 11133 | unsigned int bytes_read, extended_len; |
| 11134 | unsigned char op_code, extended_op, adj_opcode; |
| 11135 | CORE_ADDR baseaddr; |
| 11136 | struct objfile *objfile = cu->objfile; |
| 11137 | bfd *abfd = objfile->obfd; |
| 11138 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 11139 | const int decode_for_pst_p = (pst != NULL); |
| 11140 | struct subfile *last_subfile = NULL; |
| 11141 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
| 11142 | = record_line; |
| 11143 | |
| 11144 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 11145 | |
| 11146 | line_ptr = lh->statement_program_start; |
| 11147 | line_end = lh->statement_program_end; |
| 11148 | |
| 11149 | /* Read the statement sequences until there's nothing left. */ |
| 11150 | while (line_ptr < line_end) |
| 11151 | { |
| 11152 | /* state machine registers */ |
| 11153 | CORE_ADDR address = 0; |
| 11154 | unsigned int file = 1; |
| 11155 | unsigned int line = 1; |
| 11156 | unsigned int column = 0; |
| 11157 | int is_stmt = lh->default_is_stmt; |
| 11158 | int basic_block = 0; |
| 11159 | int end_sequence = 0; |
| 11160 | CORE_ADDR addr; |
| 11161 | unsigned char op_index = 0; |
| 11162 | |
| 11163 | if (!decode_for_pst_p && lh->num_file_names >= file) |
| 11164 | { |
| 11165 | /* Start a subfile for the current file of the state machine. */ |
| 11166 | /* lh->include_dirs and lh->file_names are 0-based, but the |
| 11167 | directory and file name numbers in the statement program |
| 11168 | are 1-based. */ |
| 11169 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 11170 | char *dir = NULL; |
| 11171 | |
| 11172 | if (fe->dir_index) |
| 11173 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 11174 | |
| 11175 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 11176 | } |
| 11177 | |
| 11178 | /* Decode the table. */ |
| 11179 | while (!end_sequence) |
| 11180 | { |
| 11181 | op_code = read_1_byte (abfd, line_ptr); |
| 11182 | line_ptr += 1; |
| 11183 | if (line_ptr > line_end) |
| 11184 | { |
| 11185 | dwarf2_debug_line_missing_end_sequence_complaint (); |
| 11186 | break; |
| 11187 | } |
| 11188 | |
| 11189 | if (op_code >= lh->opcode_base) |
| 11190 | { |
| 11191 | /* Special operand. */ |
| 11192 | adj_opcode = op_code - lh->opcode_base; |
| 11193 | address += (((op_index + (adj_opcode / lh->line_range)) |
| 11194 | / lh->maximum_ops_per_instruction) |
| 11195 | * lh->minimum_instruction_length); |
| 11196 | op_index = ((op_index + (adj_opcode / lh->line_range)) |
| 11197 | % lh->maximum_ops_per_instruction); |
| 11198 | line += lh->line_base + (adj_opcode % lh->line_range); |
| 11199 | if (lh->num_file_names < file || file == 0) |
| 11200 | dwarf2_debug_line_missing_file_complaint (); |
| 11201 | /* For now we ignore lines not starting on an |
| 11202 | instruction boundary. */ |
| 11203 | else if (op_index == 0) |
| 11204 | { |
| 11205 | lh->file_names[file - 1].included_p = 1; |
| 11206 | if (!decode_for_pst_p && is_stmt) |
| 11207 | { |
| 11208 | if (last_subfile != current_subfile) |
| 11209 | { |
| 11210 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 11211 | if (last_subfile) |
| 11212 | (*p_record_line) (last_subfile, 0, addr); |
| 11213 | last_subfile = current_subfile; |
| 11214 | } |
| 11215 | /* Append row to matrix using current values. */ |
| 11216 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 11217 | (*p_record_line) (current_subfile, line, addr); |
| 11218 | } |
| 11219 | } |
| 11220 | basic_block = 0; |
| 11221 | } |
| 11222 | else switch (op_code) |
| 11223 | { |
| 11224 | case DW_LNS_extended_op: |
| 11225 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
| 11226 | &bytes_read); |
| 11227 | line_ptr += bytes_read; |
| 11228 | extended_end = line_ptr + extended_len; |
| 11229 | extended_op = read_1_byte (abfd, line_ptr); |
| 11230 | line_ptr += 1; |
| 11231 | switch (extended_op) |
| 11232 | { |
| 11233 | case DW_LNE_end_sequence: |
| 11234 | p_record_line = record_line; |
| 11235 | end_sequence = 1; |
| 11236 | break; |
| 11237 | case DW_LNE_set_address: |
| 11238 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
| 11239 | |
| 11240 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 11241 | { |
| 11242 | /* This line table is for a function which has been |
| 11243 | GCd by the linker. Ignore it. PR gdb/12528 */ |
| 11244 | |
| 11245 | long line_offset |
| 11246 | = line_ptr - dwarf2_per_objfile->line.buffer; |
| 11247 | |
| 11248 | complaint (&symfile_complaints, |
| 11249 | _(".debug_line address at offset 0x%lx is 0 " |
| 11250 | "[in module %s]"), |
| 11251 | line_offset, objfile->name); |
| 11252 | p_record_line = noop_record_line; |
| 11253 | } |
| 11254 | |
| 11255 | op_index = 0; |
| 11256 | line_ptr += bytes_read; |
| 11257 | address += baseaddr; |
| 11258 | break; |
| 11259 | case DW_LNE_define_file: |
| 11260 | { |
| 11261 | char *cur_file; |
| 11262 | unsigned int dir_index, mod_time, length; |
| 11263 | |
| 11264 | cur_file = read_direct_string (abfd, line_ptr, |
| 11265 | &bytes_read); |
| 11266 | line_ptr += bytes_read; |
| 11267 | dir_index = |
| 11268 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11269 | line_ptr += bytes_read; |
| 11270 | mod_time = |
| 11271 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11272 | line_ptr += bytes_read; |
| 11273 | length = |
| 11274 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11275 | line_ptr += bytes_read; |
| 11276 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 11277 | } |
| 11278 | break; |
| 11279 | case DW_LNE_set_discriminator: |
| 11280 | /* The discriminator is not interesting to the debugger; |
| 11281 | just ignore it. */ |
| 11282 | line_ptr = extended_end; |
| 11283 | break; |
| 11284 | default: |
| 11285 | complaint (&symfile_complaints, |
| 11286 | _("mangled .debug_line section")); |
| 11287 | return; |
| 11288 | } |
| 11289 | /* Make sure that we parsed the extended op correctly. If e.g. |
| 11290 | we expected a different address size than the producer used, |
| 11291 | we may have read the wrong number of bytes. */ |
| 11292 | if (line_ptr != extended_end) |
| 11293 | { |
| 11294 | complaint (&symfile_complaints, |
| 11295 | _("mangled .debug_line section")); |
| 11296 | return; |
| 11297 | } |
| 11298 | break; |
| 11299 | case DW_LNS_copy: |
| 11300 | if (lh->num_file_names < file || file == 0) |
| 11301 | dwarf2_debug_line_missing_file_complaint (); |
| 11302 | else |
| 11303 | { |
| 11304 | lh->file_names[file - 1].included_p = 1; |
| 11305 | if (!decode_for_pst_p && is_stmt) |
| 11306 | { |
| 11307 | if (last_subfile != current_subfile) |
| 11308 | { |
| 11309 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 11310 | if (last_subfile) |
| 11311 | (*p_record_line) (last_subfile, 0, addr); |
| 11312 | last_subfile = current_subfile; |
| 11313 | } |
| 11314 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 11315 | (*p_record_line) (current_subfile, line, addr); |
| 11316 | } |
| 11317 | } |
| 11318 | basic_block = 0; |
| 11319 | break; |
| 11320 | case DW_LNS_advance_pc: |
| 11321 | { |
| 11322 | CORE_ADDR adjust |
| 11323 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11324 | |
| 11325 | address += (((op_index + adjust) |
| 11326 | / lh->maximum_ops_per_instruction) |
| 11327 | * lh->minimum_instruction_length); |
| 11328 | op_index = ((op_index + adjust) |
| 11329 | % lh->maximum_ops_per_instruction); |
| 11330 | line_ptr += bytes_read; |
| 11331 | } |
| 11332 | break; |
| 11333 | case DW_LNS_advance_line: |
| 11334 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); |
| 11335 | line_ptr += bytes_read; |
| 11336 | break; |
| 11337 | case DW_LNS_set_file: |
| 11338 | { |
| 11339 | /* The arrays lh->include_dirs and lh->file_names are |
| 11340 | 0-based, but the directory and file name numbers in |
| 11341 | the statement program are 1-based. */ |
| 11342 | struct file_entry *fe; |
| 11343 | char *dir = NULL; |
| 11344 | |
| 11345 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11346 | line_ptr += bytes_read; |
| 11347 | if (lh->num_file_names < file || file == 0) |
| 11348 | dwarf2_debug_line_missing_file_complaint (); |
| 11349 | else |
| 11350 | { |
| 11351 | fe = &lh->file_names[file - 1]; |
| 11352 | if (fe->dir_index) |
| 11353 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 11354 | if (!decode_for_pst_p) |
| 11355 | { |
| 11356 | last_subfile = current_subfile; |
| 11357 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 11358 | } |
| 11359 | } |
| 11360 | } |
| 11361 | break; |
| 11362 | case DW_LNS_set_column: |
| 11363 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11364 | line_ptr += bytes_read; |
| 11365 | break; |
| 11366 | case DW_LNS_negate_stmt: |
| 11367 | is_stmt = (!is_stmt); |
| 11368 | break; |
| 11369 | case DW_LNS_set_basic_block: |
| 11370 | basic_block = 1; |
| 11371 | break; |
| 11372 | /* Add to the address register of the state machine the |
| 11373 | address increment value corresponding to special opcode |
| 11374 | 255. I.e., this value is scaled by the minimum |
| 11375 | instruction length since special opcode 255 would have |
| 11376 | scaled the increment. */ |
| 11377 | case DW_LNS_const_add_pc: |
| 11378 | { |
| 11379 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; |
| 11380 | |
| 11381 | address += (((op_index + adjust) |
| 11382 | / lh->maximum_ops_per_instruction) |
| 11383 | * lh->minimum_instruction_length); |
| 11384 | op_index = ((op_index + adjust) |
| 11385 | % lh->maximum_ops_per_instruction); |
| 11386 | } |
| 11387 | break; |
| 11388 | case DW_LNS_fixed_advance_pc: |
| 11389 | address += read_2_bytes (abfd, line_ptr); |
| 11390 | op_index = 0; |
| 11391 | line_ptr += 2; |
| 11392 | break; |
| 11393 | default: |
| 11394 | { |
| 11395 | /* Unknown standard opcode, ignore it. */ |
| 11396 | int i; |
| 11397 | |
| 11398 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
| 11399 | { |
| 11400 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 11401 | line_ptr += bytes_read; |
| 11402 | } |
| 11403 | } |
| 11404 | } |
| 11405 | } |
| 11406 | if (lh->num_file_names < file || file == 0) |
| 11407 | dwarf2_debug_line_missing_file_complaint (); |
| 11408 | else |
| 11409 | { |
| 11410 | lh->file_names[file - 1].included_p = 1; |
| 11411 | if (!decode_for_pst_p) |
| 11412 | { |
| 11413 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 11414 | (*p_record_line) (current_subfile, 0, addr); |
| 11415 | } |
| 11416 | } |
| 11417 | } |
| 11418 | } |
| 11419 | |
| 11420 | /* Decode the Line Number Program (LNP) for the given line_header |
| 11421 | structure and CU. The actual information extracted and the type |
| 11422 | of structures created from the LNP depends on the value of PST. |
| 11423 | |
| 11424 | 1. If PST is NULL, then this procedure uses the data from the program |
| 11425 | to create all necessary symbol tables, and their linetables. |
| 11426 | |
| 11427 | 2. If PST is not NULL, this procedure reads the program to determine |
| 11428 | the list of files included by the unit represented by PST, and |
| 11429 | builds all the associated partial symbol tables. |
| 11430 | |
| 11431 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. |
| 11432 | It is used for relative paths in the line table. |
| 11433 | NOTE: When processing partial symtabs (pst != NULL), |
| 11434 | comp_dir == pst->dirname. |
| 11435 | |
| 11436 | NOTE: It is important that psymtabs have the same file name (via strcmp) |
| 11437 | as the corresponding symtab. Since COMP_DIR is not used in the name of the |
| 11438 | symtab we don't use it in the name of the psymtabs we create. |
| 11439 | E.g. expand_line_sal requires this when finding psymtabs to expand. |
| 11440 | A good testcase for this is mb-inline.exp. */ |
| 11441 | |
| 11442 | static void |
| 11443 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, |
| 11444 | struct dwarf2_cu *cu, struct partial_symtab *pst, |
| 11445 | int want_line_info) |
| 11446 | { |
| 11447 | struct objfile *objfile = cu->objfile; |
| 11448 | const int decode_for_pst_p = (pst != NULL); |
| 11449 | struct subfile *first_subfile = current_subfile; |
| 11450 | |
| 11451 | if (want_line_info) |
| 11452 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); |
| 11453 | |
| 11454 | if (decode_for_pst_p) |
| 11455 | { |
| 11456 | int file_index; |
| 11457 | |
| 11458 | /* Now that we're done scanning the Line Header Program, we can |
| 11459 | create the psymtab of each included file. */ |
| 11460 | for (file_index = 0; file_index < lh->num_file_names; file_index++) |
| 11461 | if (lh->file_names[file_index].included_p == 1) |
| 11462 | { |
| 11463 | char *include_name = |
| 11464 | psymtab_include_file_name (lh, file_index, pst, comp_dir); |
| 11465 | if (include_name != NULL) |
| 11466 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
| 11467 | } |
| 11468 | } |
| 11469 | else |
| 11470 | { |
| 11471 | /* Make sure a symtab is created for every file, even files |
| 11472 | which contain only variables (i.e. no code with associated |
| 11473 | line numbers). */ |
| 11474 | int i; |
| 11475 | |
| 11476 | for (i = 0; i < lh->num_file_names; i++) |
| 11477 | { |
| 11478 | char *dir = NULL; |
| 11479 | struct file_entry *fe; |
| 11480 | |
| 11481 | fe = &lh->file_names[i]; |
| 11482 | if (fe->dir_index) |
| 11483 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 11484 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 11485 | |
| 11486 | /* Skip the main file; we don't need it, and it must be |
| 11487 | allocated last, so that it will show up before the |
| 11488 | non-primary symtabs in the objfile's symtab list. */ |
| 11489 | if (current_subfile == first_subfile) |
| 11490 | continue; |
| 11491 | |
| 11492 | if (current_subfile->symtab == NULL) |
| 11493 | current_subfile->symtab = allocate_symtab (current_subfile->name, |
| 11494 | objfile); |
| 11495 | fe->symtab = current_subfile->symtab; |
| 11496 | } |
| 11497 | } |
| 11498 | } |
| 11499 | |
| 11500 | /* Start a subfile for DWARF. FILENAME is the name of the file and |
| 11501 | DIRNAME the name of the source directory which contains FILENAME |
| 11502 | or NULL if not known. COMP_DIR is the compilation directory for the |
| 11503 | linetable's compilation unit or NULL if not known. |
| 11504 | This routine tries to keep line numbers from identical absolute and |
| 11505 | relative file names in a common subfile. |
| 11506 | |
| 11507 | Using the `list' example from the GDB testsuite, which resides in |
| 11508 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename |
| 11509 | of /srcdir/list0.c yields the following debugging information for list0.c: |
| 11510 | |
| 11511 | DW_AT_name: /srcdir/list0.c |
| 11512 | DW_AT_comp_dir: /compdir |
| 11513 | files.files[0].name: list0.h |
| 11514 | files.files[0].dir: /srcdir |
| 11515 | files.files[1].name: list0.c |
| 11516 | files.files[1].dir: /srcdir |
| 11517 | |
| 11518 | The line number information for list0.c has to end up in a single |
| 11519 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
| 11520 | start_subfile will ensure that this happens provided that we pass the |
| 11521 | concatenation of files.files[1].dir and files.files[1].name as the |
| 11522 | subfile's name. */ |
| 11523 | |
| 11524 | static void |
| 11525 | dwarf2_start_subfile (char *filename, const char *dirname, |
| 11526 | const char *comp_dir) |
| 11527 | { |
| 11528 | char *fullname; |
| 11529 | |
| 11530 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). |
| 11531 | `start_symtab' will always pass the contents of DW_AT_comp_dir as |
| 11532 | second argument to start_subfile. To be consistent, we do the |
| 11533 | same here. In order not to lose the line information directory, |
| 11534 | we concatenate it to the filename when it makes sense. |
| 11535 | Note that the Dwarf3 standard says (speaking of filenames in line |
| 11536 | information): ``The directory index is ignored for file names |
| 11537 | that represent full path names''. Thus ignoring dirname in the |
| 11538 | `else' branch below isn't an issue. */ |
| 11539 | |
| 11540 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
| 11541 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
| 11542 | else |
| 11543 | fullname = filename; |
| 11544 | |
| 11545 | start_subfile (fullname, comp_dir); |
| 11546 | |
| 11547 | if (fullname != filename) |
| 11548 | xfree (fullname); |
| 11549 | } |
| 11550 | |
| 11551 | static void |
| 11552 | var_decode_location (struct attribute *attr, struct symbol *sym, |
| 11553 | struct dwarf2_cu *cu) |
| 11554 | { |
| 11555 | struct objfile *objfile = cu->objfile; |
| 11556 | struct comp_unit_head *cu_header = &cu->header; |
| 11557 | |
| 11558 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
| 11559 | code here to turn a symbol with DW_AT_external and a |
| 11560 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was |
| 11561 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux |
| 11562 | with some versions of binutils) where shared libraries could have |
| 11563 | relocations against symbols in their debug information - the |
| 11564 | minimal symbol would have the right address, but the debug info |
| 11565 | would not. It's no longer necessary, because we will explicitly |
| 11566 | apply relocations when we read in the debug information now. */ |
| 11567 | |
| 11568 | /* A DW_AT_location attribute with no contents indicates that a |
| 11569 | variable has been optimized away. */ |
| 11570 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) |
| 11571 | { |
| 11572 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 11573 | return; |
| 11574 | } |
| 11575 | |
| 11576 | /* Handle one degenerate form of location expression specially, to |
| 11577 | preserve GDB's previous behavior when section offsets are |
| 11578 | specified. If this is just a DW_OP_addr then mark this symbol |
| 11579 | as LOC_STATIC. */ |
| 11580 | |
| 11581 | if (attr_form_is_block (attr) |
| 11582 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size |
| 11583 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) |
| 11584 | { |
| 11585 | unsigned int dummy; |
| 11586 | |
| 11587 | SYMBOL_VALUE_ADDRESS (sym) = |
| 11588 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
| 11589 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 11590 | fixup_symbol_section (sym, objfile); |
| 11591 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, |
| 11592 | SYMBOL_SECTION (sym)); |
| 11593 | return; |
| 11594 | } |
| 11595 | |
| 11596 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static |
| 11597 | expression evaluator, and use LOC_COMPUTED only when necessary |
| 11598 | (i.e. when the value of a register or memory location is |
| 11599 | referenced, or a thread-local block, etc.). Then again, it might |
| 11600 | not be worthwhile. I'm assuming that it isn't unless performance |
| 11601 | or memory numbers show me otherwise. */ |
| 11602 | |
| 11603 | dwarf2_symbol_mark_computed (attr, sym, cu); |
| 11604 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 11605 | |
| 11606 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) |
| 11607 | cu->has_loclist = 1; |
| 11608 | } |
| 11609 | |
| 11610 | /* Given a pointer to a DWARF information entry, figure out if we need |
| 11611 | to make a symbol table entry for it, and if so, create a new entry |
| 11612 | and return a pointer to it. |
| 11613 | If TYPE is NULL, determine symbol type from the die, otherwise |
| 11614 | used the passed type. |
| 11615 | If SPACE is not NULL, use it to hold the new symbol. If it is |
| 11616 | NULL, allocate a new symbol on the objfile's obstack. */ |
| 11617 | |
| 11618 | static struct symbol * |
| 11619 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
| 11620 | struct symbol *space) |
| 11621 | { |
| 11622 | struct objfile *objfile = cu->objfile; |
| 11623 | struct symbol *sym = NULL; |
| 11624 | char *name; |
| 11625 | struct attribute *attr = NULL; |
| 11626 | struct attribute *attr2 = NULL; |
| 11627 | CORE_ADDR baseaddr; |
| 11628 | struct pending **list_to_add = NULL; |
| 11629 | |
| 11630 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
| 11631 | |
| 11632 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 11633 | |
| 11634 | name = dwarf2_name (die, cu); |
| 11635 | if (name) |
| 11636 | { |
| 11637 | const char *linkagename; |
| 11638 | int suppress_add = 0; |
| 11639 | |
| 11640 | if (space) |
| 11641 | sym = space; |
| 11642 | else |
| 11643 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); |
| 11644 | OBJSTAT (objfile, n_syms++); |
| 11645 | |
| 11646 | /* Cache this symbol's name and the name's demangled form (if any). */ |
| 11647 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
| 11648 | linkagename = dwarf2_physname (name, die, cu); |
| 11649 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); |
| 11650 | |
| 11651 | /* Fortran does not have mangling standard and the mangling does differ |
| 11652 | between gfortran, iFort etc. */ |
| 11653 | if (cu->language == language_fortran |
| 11654 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
| 11655 | symbol_set_demangled_name (&(sym->ginfo), |
| 11656 | (char *) dwarf2_full_name (name, die, cu), |
| 11657 | NULL); |
| 11658 | |
| 11659 | /* Default assumptions. |
| 11660 | Use the passed type or decode it from the die. */ |
| 11661 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 11662 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 11663 | if (type != NULL) |
| 11664 | SYMBOL_TYPE (sym) = type; |
| 11665 | else |
| 11666 | SYMBOL_TYPE (sym) = die_type (die, cu); |
| 11667 | attr = dwarf2_attr (die, |
| 11668 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, |
| 11669 | cu); |
| 11670 | if (attr) |
| 11671 | { |
| 11672 | SYMBOL_LINE (sym) = DW_UNSND (attr); |
| 11673 | } |
| 11674 | |
| 11675 | attr = dwarf2_attr (die, |
| 11676 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, |
| 11677 | cu); |
| 11678 | if (attr) |
| 11679 | { |
| 11680 | int file_index = DW_UNSND (attr); |
| 11681 | |
| 11682 | if (cu->line_header == NULL |
| 11683 | || file_index > cu->line_header->num_file_names) |
| 11684 | complaint (&symfile_complaints, |
| 11685 | _("file index out of range")); |
| 11686 | else if (file_index > 0) |
| 11687 | { |
| 11688 | struct file_entry *fe; |
| 11689 | |
| 11690 | fe = &cu->line_header->file_names[file_index - 1]; |
| 11691 | SYMBOL_SYMTAB (sym) = fe->symtab; |
| 11692 | } |
| 11693 | } |
| 11694 | |
| 11695 | switch (die->tag) |
| 11696 | { |
| 11697 | case DW_TAG_label: |
| 11698 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 11699 | if (attr) |
| 11700 | { |
| 11701 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; |
| 11702 | } |
| 11703 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
| 11704 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; |
| 11705 | SYMBOL_CLASS (sym) = LOC_LABEL; |
| 11706 | add_symbol_to_list (sym, cu->list_in_scope); |
| 11707 | break; |
| 11708 | case DW_TAG_subprogram: |
| 11709 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 11710 | finish_block. */ |
| 11711 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 11712 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 11713 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
| 11714 | || cu->language == language_ada) |
| 11715 | { |
| 11716 | /* Subprograms marked external are stored as a global symbol. |
| 11717 | Ada subprograms, whether marked external or not, are always |
| 11718 | stored as a global symbol, because we want to be able to |
| 11719 | access them globally. For instance, we want to be able |
| 11720 | to break on a nested subprogram without having to |
| 11721 | specify the context. */ |
| 11722 | list_to_add = &global_symbols; |
| 11723 | } |
| 11724 | else |
| 11725 | { |
| 11726 | list_to_add = cu->list_in_scope; |
| 11727 | } |
| 11728 | break; |
| 11729 | case DW_TAG_inlined_subroutine: |
| 11730 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 11731 | finish_block. */ |
| 11732 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 11733 | SYMBOL_INLINED (sym) = 1; |
| 11734 | /* Do not add the symbol to any lists. It will be found via |
| 11735 | BLOCK_FUNCTION from the blockvector. */ |
| 11736 | break; |
| 11737 | case DW_TAG_template_value_param: |
| 11738 | suppress_add = 1; |
| 11739 | /* Fall through. */ |
| 11740 | case DW_TAG_constant: |
| 11741 | case DW_TAG_variable: |
| 11742 | case DW_TAG_member: |
| 11743 | /* Compilation with minimal debug info may result in |
| 11744 | variables with missing type entries. Change the |
| 11745 | misleading `void' type to something sensible. */ |
| 11746 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
| 11747 | SYMBOL_TYPE (sym) |
| 11748 | = objfile_type (objfile)->nodebug_data_symbol; |
| 11749 | |
| 11750 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 11751 | /* In the case of DW_TAG_member, we should only be called for |
| 11752 | static const members. */ |
| 11753 | if (die->tag == DW_TAG_member) |
| 11754 | { |
| 11755 | /* dwarf2_add_field uses die_is_declaration, |
| 11756 | so we do the same. */ |
| 11757 | gdb_assert (die_is_declaration (die, cu)); |
| 11758 | gdb_assert (attr); |
| 11759 | } |
| 11760 | if (attr) |
| 11761 | { |
| 11762 | dwarf2_const_value (attr, sym, cu); |
| 11763 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 11764 | if (!suppress_add) |
| 11765 | { |
| 11766 | if (attr2 && (DW_UNSND (attr2) != 0)) |
| 11767 | list_to_add = &global_symbols; |
| 11768 | else |
| 11769 | list_to_add = cu->list_in_scope; |
| 11770 | } |
| 11771 | break; |
| 11772 | } |
| 11773 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 11774 | if (attr) |
| 11775 | { |
| 11776 | var_decode_location (attr, sym, cu); |
| 11777 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 11778 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
| 11779 | && SYMBOL_VALUE_ADDRESS (sym) == 0 |
| 11780 | && !dwarf2_per_objfile->has_section_at_zero) |
| 11781 | { |
| 11782 | /* When a static variable is eliminated by the linker, |
| 11783 | the corresponding debug information is not stripped |
| 11784 | out, but the variable address is set to null; |
| 11785 | do not add such variables into symbol table. */ |
| 11786 | } |
| 11787 | else if (attr2 && (DW_UNSND (attr2) != 0)) |
| 11788 | { |
| 11789 | /* Workaround gfortran PR debug/40040 - it uses |
| 11790 | DW_AT_location for variables in -fPIC libraries which may |
| 11791 | get overriden by other libraries/executable and get |
| 11792 | a different address. Resolve it by the minimal symbol |
| 11793 | which may come from inferior's executable using copy |
| 11794 | relocation. Make this workaround only for gfortran as for |
| 11795 | other compilers GDB cannot guess the minimal symbol |
| 11796 | Fortran mangling kind. */ |
| 11797 | if (cu->language == language_fortran && die->parent |
| 11798 | && die->parent->tag == DW_TAG_module |
| 11799 | && cu->producer |
| 11800 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) |
| 11801 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 11802 | |
| 11803 | /* A variable with DW_AT_external is never static, |
| 11804 | but it may be block-scoped. */ |
| 11805 | list_to_add = (cu->list_in_scope == &file_symbols |
| 11806 | ? &global_symbols : cu->list_in_scope); |
| 11807 | } |
| 11808 | else |
| 11809 | list_to_add = cu->list_in_scope; |
| 11810 | } |
| 11811 | else |
| 11812 | { |
| 11813 | /* We do not know the address of this symbol. |
| 11814 | If it is an external symbol and we have type information |
| 11815 | for it, enter the symbol as a LOC_UNRESOLVED symbol. |
| 11816 | The address of the variable will then be determined from |
| 11817 | the minimal symbol table whenever the variable is |
| 11818 | referenced. */ |
| 11819 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 11820 | if (attr2 && (DW_UNSND (attr2) != 0) |
| 11821 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
| 11822 | { |
| 11823 | /* A variable with DW_AT_external is never static, but it |
| 11824 | may be block-scoped. */ |
| 11825 | list_to_add = (cu->list_in_scope == &file_symbols |
| 11826 | ? &global_symbols : cu->list_in_scope); |
| 11827 | |
| 11828 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 11829 | } |
| 11830 | else if (!die_is_declaration (die, cu)) |
| 11831 | { |
| 11832 | /* Use the default LOC_OPTIMIZED_OUT class. */ |
| 11833 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); |
| 11834 | if (!suppress_add) |
| 11835 | list_to_add = cu->list_in_scope; |
| 11836 | } |
| 11837 | } |
| 11838 | break; |
| 11839 | case DW_TAG_formal_parameter: |
| 11840 | /* If we are inside a function, mark this as an argument. If |
| 11841 | not, we might be looking at an argument to an inlined function |
| 11842 | when we do not have enough information to show inlined frames; |
| 11843 | pretend it's a local variable in that case so that the user can |
| 11844 | still see it. */ |
| 11845 | if (context_stack_depth > 0 |
| 11846 | && context_stack[context_stack_depth - 1].name != NULL) |
| 11847 | SYMBOL_IS_ARGUMENT (sym) = 1; |
| 11848 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 11849 | if (attr) |
| 11850 | { |
| 11851 | var_decode_location (attr, sym, cu); |
| 11852 | } |
| 11853 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 11854 | if (attr) |
| 11855 | { |
| 11856 | dwarf2_const_value (attr, sym, cu); |
| 11857 | } |
| 11858 | |
| 11859 | list_to_add = cu->list_in_scope; |
| 11860 | break; |
| 11861 | case DW_TAG_unspecified_parameters: |
| 11862 | /* From varargs functions; gdb doesn't seem to have any |
| 11863 | interest in this information, so just ignore it for now. |
| 11864 | (FIXME?) */ |
| 11865 | break; |
| 11866 | case DW_TAG_template_type_param: |
| 11867 | suppress_add = 1; |
| 11868 | /* Fall through. */ |
| 11869 | case DW_TAG_class_type: |
| 11870 | case DW_TAG_interface_type: |
| 11871 | case DW_TAG_structure_type: |
| 11872 | case DW_TAG_union_type: |
| 11873 | case DW_TAG_set_type: |
| 11874 | case DW_TAG_enumeration_type: |
| 11875 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11876 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
| 11877 | |
| 11878 | { |
| 11879 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
| 11880 | really ever be static objects: otherwise, if you try |
| 11881 | to, say, break of a class's method and you're in a file |
| 11882 | which doesn't mention that class, it won't work unless |
| 11883 | the check for all static symbols in lookup_symbol_aux |
| 11884 | saves you. See the OtherFileClass tests in |
| 11885 | gdb.c++/namespace.exp. */ |
| 11886 | |
| 11887 | if (!suppress_add) |
| 11888 | { |
| 11889 | list_to_add = (cu->list_in_scope == &file_symbols |
| 11890 | && (cu->language == language_cplus |
| 11891 | || cu->language == language_java) |
| 11892 | ? &global_symbols : cu->list_in_scope); |
| 11893 | |
| 11894 | /* The semantics of C++ state that "struct foo { |
| 11895 | ... }" also defines a typedef for "foo". A Java |
| 11896 | class declaration also defines a typedef for the |
| 11897 | class. */ |
| 11898 | if (cu->language == language_cplus |
| 11899 | || cu->language == language_java |
| 11900 | || cu->language == language_ada) |
| 11901 | { |
| 11902 | /* The symbol's name is already allocated along |
| 11903 | with this objfile, so we don't need to |
| 11904 | duplicate it for the type. */ |
| 11905 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
| 11906 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
| 11907 | } |
| 11908 | } |
| 11909 | } |
| 11910 | break; |
| 11911 | case DW_TAG_typedef: |
| 11912 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11913 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 11914 | list_to_add = cu->list_in_scope; |
| 11915 | break; |
| 11916 | case DW_TAG_base_type: |
| 11917 | case DW_TAG_subrange_type: |
| 11918 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11919 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 11920 | list_to_add = cu->list_in_scope; |
| 11921 | break; |
| 11922 | case DW_TAG_enumerator: |
| 11923 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 11924 | if (attr) |
| 11925 | { |
| 11926 | dwarf2_const_value (attr, sym, cu); |
| 11927 | } |
| 11928 | { |
| 11929 | /* NOTE: carlton/2003-11-10: See comment above in the |
| 11930 | DW_TAG_class_type, etc. block. */ |
| 11931 | |
| 11932 | list_to_add = (cu->list_in_scope == &file_symbols |
| 11933 | && (cu->language == language_cplus |
| 11934 | || cu->language == language_java) |
| 11935 | ? &global_symbols : cu->list_in_scope); |
| 11936 | } |
| 11937 | break; |
| 11938 | case DW_TAG_namespace: |
| 11939 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 11940 | list_to_add = &global_symbols; |
| 11941 | break; |
| 11942 | default: |
| 11943 | /* Not a tag we recognize. Hopefully we aren't processing |
| 11944 | trash data, but since we must specifically ignore things |
| 11945 | we don't recognize, there is nothing else we should do at |
| 11946 | this point. */ |
| 11947 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
| 11948 | dwarf_tag_name (die->tag)); |
| 11949 | break; |
| 11950 | } |
| 11951 | |
| 11952 | if (suppress_add) |
| 11953 | { |
| 11954 | sym->hash_next = objfile->template_symbols; |
| 11955 | objfile->template_symbols = sym; |
| 11956 | list_to_add = NULL; |
| 11957 | } |
| 11958 | |
| 11959 | if (list_to_add != NULL) |
| 11960 | add_symbol_to_list (sym, list_to_add); |
| 11961 | |
| 11962 | /* For the benefit of old versions of GCC, check for anonymous |
| 11963 | namespaces based on the demangled name. */ |
| 11964 | if (!processing_has_namespace_info |
| 11965 | && cu->language == language_cplus) |
| 11966 | cp_scan_for_anonymous_namespaces (sym, objfile); |
| 11967 | } |
| 11968 | return (sym); |
| 11969 | } |
| 11970 | |
| 11971 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
| 11972 | |
| 11973 | static struct symbol * |
| 11974 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
| 11975 | { |
| 11976 | return new_symbol_full (die, type, cu, NULL); |
| 11977 | } |
| 11978 | |
| 11979 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
| 11980 | zero-extend it as appropriate for the symbol's type. The DWARF |
| 11981 | standard (v4) is not entirely clear about the meaning of using |
| 11982 | DW_FORM_dataN for a constant with a signed type, where the type is |
| 11983 | wider than the data. The conclusion of a discussion on the DWARF |
| 11984 | list was that this is unspecified. We choose to always zero-extend |
| 11985 | because that is the interpretation long in use by GCC. */ |
| 11986 | |
| 11987 | static gdb_byte * |
| 11988 | dwarf2_const_value_data (struct attribute *attr, struct type *type, |
| 11989 | const char *name, struct obstack *obstack, |
| 11990 | struct dwarf2_cu *cu, long *value, int bits) |
| 11991 | { |
| 11992 | struct objfile *objfile = cu->objfile; |
| 11993 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
| 11994 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; |
| 11995 | LONGEST l = DW_UNSND (attr); |
| 11996 | |
| 11997 | if (bits < sizeof (*value) * 8) |
| 11998 | { |
| 11999 | l &= ((LONGEST) 1 << bits) - 1; |
| 12000 | *value = l; |
| 12001 | } |
| 12002 | else if (bits == sizeof (*value) * 8) |
| 12003 | *value = l; |
| 12004 | else |
| 12005 | { |
| 12006 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); |
| 12007 | store_unsigned_integer (bytes, bits / 8, byte_order, l); |
| 12008 | return bytes; |
| 12009 | } |
| 12010 | |
| 12011 | return NULL; |
| 12012 | } |
| 12013 | |
| 12014 | /* Read a constant value from an attribute. Either set *VALUE, or if |
| 12015 | the value does not fit in *VALUE, set *BYTES - either already |
| 12016 | allocated on the objfile obstack, or newly allocated on OBSTACK, |
| 12017 | or, set *BATON, if we translated the constant to a location |
| 12018 | expression. */ |
| 12019 | |
| 12020 | static void |
| 12021 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, |
| 12022 | const char *name, struct obstack *obstack, |
| 12023 | struct dwarf2_cu *cu, |
| 12024 | long *value, gdb_byte **bytes, |
| 12025 | struct dwarf2_locexpr_baton **baton) |
| 12026 | { |
| 12027 | struct objfile *objfile = cu->objfile; |
| 12028 | struct comp_unit_head *cu_header = &cu->header; |
| 12029 | struct dwarf_block *blk; |
| 12030 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
| 12031 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); |
| 12032 | |
| 12033 | *value = 0; |
| 12034 | *bytes = NULL; |
| 12035 | *baton = NULL; |
| 12036 | |
| 12037 | switch (attr->form) |
| 12038 | { |
| 12039 | case DW_FORM_addr: |
| 12040 | { |
| 12041 | gdb_byte *data; |
| 12042 | |
| 12043 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
| 12044 | dwarf2_const_value_length_mismatch_complaint (name, |
| 12045 | cu_header->addr_size, |
| 12046 | TYPE_LENGTH (type)); |
| 12047 | /* Symbols of this form are reasonably rare, so we just |
| 12048 | piggyback on the existing location code rather than writing |
| 12049 | a new implementation of symbol_computed_ops. */ |
| 12050 | *baton = obstack_alloc (&objfile->objfile_obstack, |
| 12051 | sizeof (struct dwarf2_locexpr_baton)); |
| 12052 | (*baton)->per_cu = cu->per_cu; |
| 12053 | gdb_assert ((*baton)->per_cu); |
| 12054 | |
| 12055 | (*baton)->size = 2 + cu_header->addr_size; |
| 12056 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); |
| 12057 | (*baton)->data = data; |
| 12058 | |
| 12059 | data[0] = DW_OP_addr; |
| 12060 | store_unsigned_integer (&data[1], cu_header->addr_size, |
| 12061 | byte_order, DW_ADDR (attr)); |
| 12062 | data[cu_header->addr_size + 1] = DW_OP_stack_value; |
| 12063 | } |
| 12064 | break; |
| 12065 | case DW_FORM_string: |
| 12066 | case DW_FORM_strp: |
| 12067 | /* DW_STRING is already allocated on the objfile obstack, point |
| 12068 | directly to it. */ |
| 12069 | *bytes = (gdb_byte *) DW_STRING (attr); |
| 12070 | break; |
| 12071 | case DW_FORM_block1: |
| 12072 | case DW_FORM_block2: |
| 12073 | case DW_FORM_block4: |
| 12074 | case DW_FORM_block: |
| 12075 | case DW_FORM_exprloc: |
| 12076 | blk = DW_BLOCK (attr); |
| 12077 | if (TYPE_LENGTH (type) != blk->size) |
| 12078 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, |
| 12079 | TYPE_LENGTH (type)); |
| 12080 | *bytes = blk->data; |
| 12081 | break; |
| 12082 | |
| 12083 | /* The DW_AT_const_value attributes are supposed to carry the |
| 12084 | symbol's value "represented as it would be on the target |
| 12085 | architecture." By the time we get here, it's already been |
| 12086 | converted to host endianness, so we just need to sign- or |
| 12087 | zero-extend it as appropriate. */ |
| 12088 | case DW_FORM_data1: |
| 12089 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 12090 | obstack, cu, value, 8); |
| 12091 | break; |
| 12092 | case DW_FORM_data2: |
| 12093 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 12094 | obstack, cu, value, 16); |
| 12095 | break; |
| 12096 | case DW_FORM_data4: |
| 12097 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 12098 | obstack, cu, value, 32); |
| 12099 | break; |
| 12100 | case DW_FORM_data8: |
| 12101 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 12102 | obstack, cu, value, 64); |
| 12103 | break; |
| 12104 | |
| 12105 | case DW_FORM_sdata: |
| 12106 | *value = DW_SND (attr); |
| 12107 | break; |
| 12108 | |
| 12109 | case DW_FORM_udata: |
| 12110 | *value = DW_UNSND (attr); |
| 12111 | break; |
| 12112 | |
| 12113 | default: |
| 12114 | complaint (&symfile_complaints, |
| 12115 | _("unsupported const value attribute form: '%s'"), |
| 12116 | dwarf_form_name (attr->form)); |
| 12117 | *value = 0; |
| 12118 | break; |
| 12119 | } |
| 12120 | } |
| 12121 | |
| 12122 | |
| 12123 | /* Copy constant value from an attribute to a symbol. */ |
| 12124 | |
| 12125 | static void |
| 12126 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
| 12127 | struct dwarf2_cu *cu) |
| 12128 | { |
| 12129 | struct objfile *objfile = cu->objfile; |
| 12130 | struct comp_unit_head *cu_header = &cu->header; |
| 12131 | long value; |
| 12132 | gdb_byte *bytes; |
| 12133 | struct dwarf2_locexpr_baton *baton; |
| 12134 | |
| 12135 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
| 12136 | SYMBOL_PRINT_NAME (sym), |
| 12137 | &objfile->objfile_obstack, cu, |
| 12138 | &value, &bytes, &baton); |
| 12139 | |
| 12140 | if (baton != NULL) |
| 12141 | { |
| 12142 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 12143 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 12144 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 12145 | } |
| 12146 | else if (bytes != NULL) |
| 12147 | { |
| 12148 | SYMBOL_VALUE_BYTES (sym) = bytes; |
| 12149 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 12150 | } |
| 12151 | else |
| 12152 | { |
| 12153 | SYMBOL_VALUE (sym) = value; |
| 12154 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 12155 | } |
| 12156 | } |
| 12157 | |
| 12158 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
| 12159 | |
| 12160 | static struct type * |
| 12161 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12162 | { |
| 12163 | struct attribute *type_attr; |
| 12164 | |
| 12165 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
| 12166 | if (!type_attr) |
| 12167 | { |
| 12168 | /* A missing DW_AT_type represents a void type. */ |
| 12169 | return objfile_type (cu->objfile)->builtin_void; |
| 12170 | } |
| 12171 | |
| 12172 | return lookup_die_type (die, type_attr, cu); |
| 12173 | } |
| 12174 | |
| 12175 | /* True iff CU's producer generates GNAT Ada auxiliary information |
| 12176 | that allows to find parallel types through that information instead |
| 12177 | of having to do expensive parallel lookups by type name. */ |
| 12178 | |
| 12179 | static int |
| 12180 | need_gnat_info (struct dwarf2_cu *cu) |
| 12181 | { |
| 12182 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version |
| 12183 | of GNAT produces this auxiliary information, without any indication |
| 12184 | that it is produced. Part of enhancing the FSF version of GNAT |
| 12185 | to produce that information will be to put in place an indicator |
| 12186 | that we can use in order to determine whether the descriptive type |
| 12187 | info is available or not. One suggestion that has been made is |
| 12188 | to use a new attribute, attached to the CU die. For now, assume |
| 12189 | that the descriptive type info is not available. */ |
| 12190 | return 0; |
| 12191 | } |
| 12192 | |
| 12193 | /* Return the auxiliary type of the die in question using its |
| 12194 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the |
| 12195 | attribute is not present. */ |
| 12196 | |
| 12197 | static struct type * |
| 12198 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12199 | { |
| 12200 | struct attribute *type_attr; |
| 12201 | |
| 12202 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); |
| 12203 | if (!type_attr) |
| 12204 | return NULL; |
| 12205 | |
| 12206 | return lookup_die_type (die, type_attr, cu); |
| 12207 | } |
| 12208 | |
| 12209 | /* If DIE has a descriptive_type attribute, then set the TYPE's |
| 12210 | descriptive type accordingly. */ |
| 12211 | |
| 12212 | static void |
| 12213 | set_descriptive_type (struct type *type, struct die_info *die, |
| 12214 | struct dwarf2_cu *cu) |
| 12215 | { |
| 12216 | struct type *descriptive_type = die_descriptive_type (die, cu); |
| 12217 | |
| 12218 | if (descriptive_type) |
| 12219 | { |
| 12220 | ALLOCATE_GNAT_AUX_TYPE (type); |
| 12221 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; |
| 12222 | } |
| 12223 | } |
| 12224 | |
| 12225 | /* Return the containing type of the die in question using its |
| 12226 | DW_AT_containing_type attribute. */ |
| 12227 | |
| 12228 | static struct type * |
| 12229 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12230 | { |
| 12231 | struct attribute *type_attr; |
| 12232 | |
| 12233 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
| 12234 | if (!type_attr) |
| 12235 | error (_("Dwarf Error: Problem turning containing type into gdb type " |
| 12236 | "[in module %s]"), cu->objfile->name); |
| 12237 | |
| 12238 | return lookup_die_type (die, type_attr, cu); |
| 12239 | } |
| 12240 | |
| 12241 | /* Look up the type of DIE in CU using its type attribute ATTR. |
| 12242 | If there is no type substitute an error marker. */ |
| 12243 | |
| 12244 | static struct type * |
| 12245 | lookup_die_type (struct die_info *die, struct attribute *attr, |
| 12246 | struct dwarf2_cu *cu) |
| 12247 | { |
| 12248 | struct objfile *objfile = cu->objfile; |
| 12249 | struct type *this_type; |
| 12250 | |
| 12251 | /* First see if we have it cached. */ |
| 12252 | |
| 12253 | if (is_ref_attr (attr)) |
| 12254 | { |
| 12255 | unsigned int offset = dwarf2_get_ref_die_offset (attr); |
| 12256 | |
| 12257 | this_type = get_die_type_at_offset (offset, cu->per_cu); |
| 12258 | } |
| 12259 | else if (attr->form == DW_FORM_ref_sig8) |
| 12260 | { |
| 12261 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); |
| 12262 | struct dwarf2_cu *sig_cu; |
| 12263 | unsigned int offset; |
| 12264 | |
| 12265 | /* sig_type will be NULL if the signatured type is missing from |
| 12266 | the debug info. */ |
| 12267 | if (sig_type == NULL) |
| 12268 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " |
| 12269 | "at 0x%x [in module %s]"), |
| 12270 | die->offset, objfile->name); |
| 12271 | |
| 12272 | gdb_assert (sig_type->per_cu.debug_types_section); |
| 12273 | offset = sig_type->per_cu.offset + sig_type->type_offset; |
| 12274 | this_type = get_die_type_at_offset (offset, &sig_type->per_cu); |
| 12275 | } |
| 12276 | else |
| 12277 | { |
| 12278 | dump_die_for_error (die); |
| 12279 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), |
| 12280 | dwarf_attr_name (attr->name), objfile->name); |
| 12281 | } |
| 12282 | |
| 12283 | /* If not cached we need to read it in. */ |
| 12284 | |
| 12285 | if (this_type == NULL) |
| 12286 | { |
| 12287 | struct die_info *type_die; |
| 12288 | struct dwarf2_cu *type_cu = cu; |
| 12289 | |
| 12290 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 12291 | /* If the type is cached, we should have found it above. */ |
| 12292 | gdb_assert (get_die_type (type_die, type_cu) == NULL); |
| 12293 | this_type = read_type_die_1 (type_die, type_cu); |
| 12294 | } |
| 12295 | |
| 12296 | /* If we still don't have a type use an error marker. */ |
| 12297 | |
| 12298 | if (this_type == NULL) |
| 12299 | { |
| 12300 | char *message, *saved; |
| 12301 | |
| 12302 | /* read_type_die already issued a complaint. */ |
| 12303 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), |
| 12304 | objfile->name, |
| 12305 | cu->header.offset, |
| 12306 | die->offset); |
| 12307 | saved = obstack_copy0 (&objfile->objfile_obstack, |
| 12308 | message, strlen (message)); |
| 12309 | xfree (message); |
| 12310 | |
| 12311 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
| 12312 | } |
| 12313 | |
| 12314 | return this_type; |
| 12315 | } |
| 12316 | |
| 12317 | /* Return the type in DIE, CU. |
| 12318 | Returns NULL for invalid types. |
| 12319 | |
| 12320 | This first does a lookup in the appropriate type_hash table, |
| 12321 | and only reads the die in if necessary. |
| 12322 | |
| 12323 | NOTE: This can be called when reading in partial or full symbols. */ |
| 12324 | |
| 12325 | static struct type * |
| 12326 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
| 12327 | { |
| 12328 | struct type *this_type; |
| 12329 | |
| 12330 | this_type = get_die_type (die, cu); |
| 12331 | if (this_type) |
| 12332 | return this_type; |
| 12333 | |
| 12334 | return read_type_die_1 (die, cu); |
| 12335 | } |
| 12336 | |
| 12337 | /* Read the type in DIE, CU. |
| 12338 | Returns NULL for invalid types. */ |
| 12339 | |
| 12340 | static struct type * |
| 12341 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) |
| 12342 | { |
| 12343 | struct type *this_type = NULL; |
| 12344 | |
| 12345 | switch (die->tag) |
| 12346 | { |
| 12347 | case DW_TAG_class_type: |
| 12348 | case DW_TAG_interface_type: |
| 12349 | case DW_TAG_structure_type: |
| 12350 | case DW_TAG_union_type: |
| 12351 | this_type = read_structure_type (die, cu); |
| 12352 | break; |
| 12353 | case DW_TAG_enumeration_type: |
| 12354 | this_type = read_enumeration_type (die, cu); |
| 12355 | break; |
| 12356 | case DW_TAG_subprogram: |
| 12357 | case DW_TAG_subroutine_type: |
| 12358 | case DW_TAG_inlined_subroutine: |
| 12359 | this_type = read_subroutine_type (die, cu); |
| 12360 | break; |
| 12361 | case DW_TAG_array_type: |
| 12362 | this_type = read_array_type (die, cu); |
| 12363 | break; |
| 12364 | case DW_TAG_set_type: |
| 12365 | this_type = read_set_type (die, cu); |
| 12366 | break; |
| 12367 | case DW_TAG_pointer_type: |
| 12368 | this_type = read_tag_pointer_type (die, cu); |
| 12369 | break; |
| 12370 | case DW_TAG_ptr_to_member_type: |
| 12371 | this_type = read_tag_ptr_to_member_type (die, cu); |
| 12372 | break; |
| 12373 | case DW_TAG_reference_type: |
| 12374 | this_type = read_tag_reference_type (die, cu); |
| 12375 | break; |
| 12376 | case DW_TAG_const_type: |
| 12377 | this_type = read_tag_const_type (die, cu); |
| 12378 | break; |
| 12379 | case DW_TAG_volatile_type: |
| 12380 | this_type = read_tag_volatile_type (die, cu); |
| 12381 | break; |
| 12382 | case DW_TAG_string_type: |
| 12383 | this_type = read_tag_string_type (die, cu); |
| 12384 | break; |
| 12385 | case DW_TAG_typedef: |
| 12386 | this_type = read_typedef (die, cu); |
| 12387 | break; |
| 12388 | case DW_TAG_subrange_type: |
| 12389 | this_type = read_subrange_type (die, cu); |
| 12390 | break; |
| 12391 | case DW_TAG_base_type: |
| 12392 | this_type = read_base_type (die, cu); |
| 12393 | break; |
| 12394 | case DW_TAG_unspecified_type: |
| 12395 | this_type = read_unspecified_type (die, cu); |
| 12396 | break; |
| 12397 | case DW_TAG_namespace: |
| 12398 | this_type = read_namespace_type (die, cu); |
| 12399 | break; |
| 12400 | case DW_TAG_module: |
| 12401 | this_type = read_module_type (die, cu); |
| 12402 | break; |
| 12403 | default: |
| 12404 | complaint (&symfile_complaints, |
| 12405 | _("unexpected tag in read_type_die: '%s'"), |
| 12406 | dwarf_tag_name (die->tag)); |
| 12407 | break; |
| 12408 | } |
| 12409 | |
| 12410 | return this_type; |
| 12411 | } |
| 12412 | |
| 12413 | /* See if we can figure out if the class lives in a namespace. We do |
| 12414 | this by looking for a member function; its demangled name will |
| 12415 | contain namespace info, if there is any. |
| 12416 | Return the computed name or NULL. |
| 12417 | Space for the result is allocated on the objfile's obstack. |
| 12418 | This is the full-die version of guess_partial_die_structure_name. |
| 12419 | In this case we know DIE has no useful parent. */ |
| 12420 | |
| 12421 | static char * |
| 12422 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) |
| 12423 | { |
| 12424 | struct die_info *spec_die; |
| 12425 | struct dwarf2_cu *spec_cu; |
| 12426 | struct die_info *child; |
| 12427 | |
| 12428 | spec_cu = cu; |
| 12429 | spec_die = die_specification (die, &spec_cu); |
| 12430 | if (spec_die != NULL) |
| 12431 | { |
| 12432 | die = spec_die; |
| 12433 | cu = spec_cu; |
| 12434 | } |
| 12435 | |
| 12436 | for (child = die->child; |
| 12437 | child != NULL; |
| 12438 | child = child->sibling) |
| 12439 | { |
| 12440 | if (child->tag == DW_TAG_subprogram) |
| 12441 | { |
| 12442 | struct attribute *attr; |
| 12443 | |
| 12444 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); |
| 12445 | if (attr == NULL) |
| 12446 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); |
| 12447 | if (attr != NULL) |
| 12448 | { |
| 12449 | char *actual_name |
| 12450 | = language_class_name_from_physname (cu->language_defn, |
| 12451 | DW_STRING (attr)); |
| 12452 | char *name = NULL; |
| 12453 | |
| 12454 | if (actual_name != NULL) |
| 12455 | { |
| 12456 | char *die_name = dwarf2_name (die, cu); |
| 12457 | |
| 12458 | if (die_name != NULL |
| 12459 | && strcmp (die_name, actual_name) != 0) |
| 12460 | { |
| 12461 | /* Strip off the class name from the full name. |
| 12462 | We want the prefix. */ |
| 12463 | int die_name_len = strlen (die_name); |
| 12464 | int actual_name_len = strlen (actual_name); |
| 12465 | |
| 12466 | /* Test for '::' as a sanity check. */ |
| 12467 | if (actual_name_len > die_name_len + 2 |
| 12468 | && actual_name[actual_name_len |
| 12469 | - die_name_len - 1] == ':') |
| 12470 | name = |
| 12471 | obsavestring (actual_name, |
| 12472 | actual_name_len - die_name_len - 2, |
| 12473 | &cu->objfile->objfile_obstack); |
| 12474 | } |
| 12475 | } |
| 12476 | xfree (actual_name); |
| 12477 | return name; |
| 12478 | } |
| 12479 | } |
| 12480 | } |
| 12481 | |
| 12482 | return NULL; |
| 12483 | } |
| 12484 | |
| 12485 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
| 12486 | prefix part in such case. See |
| 12487 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ |
| 12488 | |
| 12489 | static char * |
| 12490 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) |
| 12491 | { |
| 12492 | struct attribute *attr; |
| 12493 | char *base; |
| 12494 | |
| 12495 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type |
| 12496 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) |
| 12497 | return NULL; |
| 12498 | |
| 12499 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 12500 | if (attr != NULL && DW_STRING (attr) != NULL) |
| 12501 | return NULL; |
| 12502 | |
| 12503 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 12504 | if (attr == NULL) |
| 12505 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 12506 | if (attr == NULL || DW_STRING (attr) == NULL) |
| 12507 | return NULL; |
| 12508 | |
| 12509 | /* dwarf2_name had to be already called. */ |
| 12510 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); |
| 12511 | |
| 12512 | /* Strip the base name, keep any leading namespaces/classes. */ |
| 12513 | base = strrchr (DW_STRING (attr), ':'); |
| 12514 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') |
| 12515 | return ""; |
| 12516 | |
| 12517 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), |
| 12518 | &cu->objfile->objfile_obstack); |
| 12519 | } |
| 12520 | |
| 12521 | /* Return the name of the namespace/class that DIE is defined within, |
| 12522 | or "" if we can't tell. The caller should not xfree the result. |
| 12523 | |
| 12524 | For example, if we're within the method foo() in the following |
| 12525 | code: |
| 12526 | |
| 12527 | namespace N { |
| 12528 | class C { |
| 12529 | void foo () { |
| 12530 | } |
| 12531 | }; |
| 12532 | } |
| 12533 | |
| 12534 | then determine_prefix on foo's die will return "N::C". */ |
| 12535 | |
| 12536 | static const char * |
| 12537 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
| 12538 | { |
| 12539 | struct die_info *parent, *spec_die; |
| 12540 | struct dwarf2_cu *spec_cu; |
| 12541 | struct type *parent_type; |
| 12542 | char *retval; |
| 12543 | |
| 12544 | if (cu->language != language_cplus && cu->language != language_java |
| 12545 | && cu->language != language_fortran) |
| 12546 | return ""; |
| 12547 | |
| 12548 | retval = anonymous_struct_prefix (die, cu); |
| 12549 | if (retval) |
| 12550 | return retval; |
| 12551 | |
| 12552 | /* We have to be careful in the presence of DW_AT_specification. |
| 12553 | For example, with GCC 3.4, given the code |
| 12554 | |
| 12555 | namespace N { |
| 12556 | void foo() { |
| 12557 | // Definition of N::foo. |
| 12558 | } |
| 12559 | } |
| 12560 | |
| 12561 | then we'll have a tree of DIEs like this: |
| 12562 | |
| 12563 | 1: DW_TAG_compile_unit |
| 12564 | 2: DW_TAG_namespace // N |
| 12565 | 3: DW_TAG_subprogram // declaration of N::foo |
| 12566 | 4: DW_TAG_subprogram // definition of N::foo |
| 12567 | DW_AT_specification // refers to die #3 |
| 12568 | |
| 12569 | Thus, when processing die #4, we have to pretend that we're in |
| 12570 | the context of its DW_AT_specification, namely the contex of die |
| 12571 | #3. */ |
| 12572 | spec_cu = cu; |
| 12573 | spec_die = die_specification (die, &spec_cu); |
| 12574 | if (spec_die == NULL) |
| 12575 | parent = die->parent; |
| 12576 | else |
| 12577 | { |
| 12578 | parent = spec_die->parent; |
| 12579 | cu = spec_cu; |
| 12580 | } |
| 12581 | |
| 12582 | if (parent == NULL) |
| 12583 | return ""; |
| 12584 | else if (parent->building_fullname) |
| 12585 | { |
| 12586 | const char *name; |
| 12587 | const char *parent_name; |
| 12588 | |
| 12589 | /* It has been seen on RealView 2.2 built binaries, |
| 12590 | DW_TAG_template_type_param types actually _defined_ as |
| 12591 | children of the parent class: |
| 12592 | |
| 12593 | enum E {}; |
| 12594 | template class <class Enum> Class{}; |
| 12595 | Class<enum E> class_e; |
| 12596 | |
| 12597 | 1: DW_TAG_class_type (Class) |
| 12598 | 2: DW_TAG_enumeration_type (E) |
| 12599 | 3: DW_TAG_enumerator (enum1:0) |
| 12600 | 3: DW_TAG_enumerator (enum2:1) |
| 12601 | ... |
| 12602 | 2: DW_TAG_template_type_param |
| 12603 | DW_AT_type DW_FORM_ref_udata (E) |
| 12604 | |
| 12605 | Besides being broken debug info, it can put GDB into an |
| 12606 | infinite loop. Consider: |
| 12607 | |
| 12608 | When we're building the full name for Class<E>, we'll start |
| 12609 | at Class, and go look over its template type parameters, |
| 12610 | finding E. We'll then try to build the full name of E, and |
| 12611 | reach here. We're now trying to build the full name of E, |
| 12612 | and look over the parent DIE for containing scope. In the |
| 12613 | broken case, if we followed the parent DIE of E, we'd again |
| 12614 | find Class, and once again go look at its template type |
| 12615 | arguments, etc., etc. Simply don't consider such parent die |
| 12616 | as source-level parent of this die (it can't be, the language |
| 12617 | doesn't allow it), and break the loop here. */ |
| 12618 | name = dwarf2_name (die, cu); |
| 12619 | parent_name = dwarf2_name (parent, cu); |
| 12620 | complaint (&symfile_complaints, |
| 12621 | _("template param type '%s' defined within parent '%s'"), |
| 12622 | name ? name : "<unknown>", |
| 12623 | parent_name ? parent_name : "<unknown>"); |
| 12624 | return ""; |
| 12625 | } |
| 12626 | else |
| 12627 | switch (parent->tag) |
| 12628 | { |
| 12629 | case DW_TAG_namespace: |
| 12630 | parent_type = read_type_die (parent, cu); |
| 12631 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
| 12632 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. |
| 12633 | Work around this problem here. */ |
| 12634 | if (cu->language == language_cplus |
| 12635 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) |
| 12636 | return ""; |
| 12637 | /* We give a name to even anonymous namespaces. */ |
| 12638 | return TYPE_TAG_NAME (parent_type); |
| 12639 | case DW_TAG_class_type: |
| 12640 | case DW_TAG_interface_type: |
| 12641 | case DW_TAG_structure_type: |
| 12642 | case DW_TAG_union_type: |
| 12643 | case DW_TAG_module: |
| 12644 | parent_type = read_type_die (parent, cu); |
| 12645 | if (TYPE_TAG_NAME (parent_type) != NULL) |
| 12646 | return TYPE_TAG_NAME (parent_type); |
| 12647 | else |
| 12648 | /* An anonymous structure is only allowed non-static data |
| 12649 | members; no typedefs, no member functions, et cetera. |
| 12650 | So it does not need a prefix. */ |
| 12651 | return ""; |
| 12652 | case DW_TAG_compile_unit: |
| 12653 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ |
| 12654 | if (cu->language == language_cplus |
| 12655 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
| 12656 | && die->child != NULL |
| 12657 | && (die->tag == DW_TAG_class_type |
| 12658 | || die->tag == DW_TAG_structure_type |
| 12659 | || die->tag == DW_TAG_union_type)) |
| 12660 | { |
| 12661 | char *name = guess_full_die_structure_name (die, cu); |
| 12662 | if (name != NULL) |
| 12663 | return name; |
| 12664 | } |
| 12665 | return ""; |
| 12666 | default: |
| 12667 | return determine_prefix (parent, cu); |
| 12668 | } |
| 12669 | } |
| 12670 | |
| 12671 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
| 12672 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then |
| 12673 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform |
| 12674 | an obconcat, otherwise allocate storage for the result. The CU argument is |
| 12675 | used to determine the language and hence, the appropriate separator. */ |
| 12676 | |
| 12677 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
| 12678 | |
| 12679 | static char * |
| 12680 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
| 12681 | int physname, struct dwarf2_cu *cu) |
| 12682 | { |
| 12683 | const char *lead = ""; |
| 12684 | const char *sep; |
| 12685 | |
| 12686 | if (suffix == NULL || suffix[0] == '\0' |
| 12687 | || prefix == NULL || prefix[0] == '\0') |
| 12688 | sep = ""; |
| 12689 | else if (cu->language == language_java) |
| 12690 | sep = "."; |
| 12691 | else if (cu->language == language_fortran && physname) |
| 12692 | { |
| 12693 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or |
| 12694 | DW_AT_MIPS_linkage_name is preferred and used instead. */ |
| 12695 | |
| 12696 | lead = "__"; |
| 12697 | sep = "_MOD_"; |
| 12698 | } |
| 12699 | else |
| 12700 | sep = "::"; |
| 12701 | |
| 12702 | if (prefix == NULL) |
| 12703 | prefix = ""; |
| 12704 | if (suffix == NULL) |
| 12705 | suffix = ""; |
| 12706 | |
| 12707 | if (obs == NULL) |
| 12708 | { |
| 12709 | char *retval |
| 12710 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); |
| 12711 | |
| 12712 | strcpy (retval, lead); |
| 12713 | strcat (retval, prefix); |
| 12714 | strcat (retval, sep); |
| 12715 | strcat (retval, suffix); |
| 12716 | return retval; |
| 12717 | } |
| 12718 | else |
| 12719 | { |
| 12720 | /* We have an obstack. */ |
| 12721 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
| 12722 | } |
| 12723 | } |
| 12724 | |
| 12725 | /* Return sibling of die, NULL if no sibling. */ |
| 12726 | |
| 12727 | static struct die_info * |
| 12728 | sibling_die (struct die_info *die) |
| 12729 | { |
| 12730 | return die->sibling; |
| 12731 | } |
| 12732 | |
| 12733 | /* Get name of a die, return NULL if not found. */ |
| 12734 | |
| 12735 | static char * |
| 12736 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, |
| 12737 | struct obstack *obstack) |
| 12738 | { |
| 12739 | if (name && cu->language == language_cplus) |
| 12740 | { |
| 12741 | char *canon_name = cp_canonicalize_string (name); |
| 12742 | |
| 12743 | if (canon_name != NULL) |
| 12744 | { |
| 12745 | if (strcmp (canon_name, name) != 0) |
| 12746 | name = obsavestring (canon_name, strlen (canon_name), |
| 12747 | obstack); |
| 12748 | xfree (canon_name); |
| 12749 | } |
| 12750 | } |
| 12751 | |
| 12752 | return name; |
| 12753 | } |
| 12754 | |
| 12755 | /* Get name of a die, return NULL if not found. */ |
| 12756 | |
| 12757 | static char * |
| 12758 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
| 12759 | { |
| 12760 | struct attribute *attr; |
| 12761 | |
| 12762 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 12763 | if ((!attr || !DW_STRING (attr)) |
| 12764 | && die->tag != DW_TAG_class_type |
| 12765 | && die->tag != DW_TAG_interface_type |
| 12766 | && die->tag != DW_TAG_structure_type |
| 12767 | && die->tag != DW_TAG_union_type) |
| 12768 | return NULL; |
| 12769 | |
| 12770 | switch (die->tag) |
| 12771 | { |
| 12772 | case DW_TAG_compile_unit: |
| 12773 | /* Compilation units have a DW_AT_name that is a filename, not |
| 12774 | a source language identifier. */ |
| 12775 | case DW_TAG_enumeration_type: |
| 12776 | case DW_TAG_enumerator: |
| 12777 | /* These tags always have simple identifiers already; no need |
| 12778 | to canonicalize them. */ |
| 12779 | return DW_STRING (attr); |
| 12780 | |
| 12781 | case DW_TAG_subprogram: |
| 12782 | /* Java constructors will all be named "<init>", so return |
| 12783 | the class name when we see this special case. */ |
| 12784 | if (cu->language == language_java |
| 12785 | && DW_STRING (attr) != NULL |
| 12786 | && strcmp (DW_STRING (attr), "<init>") == 0) |
| 12787 | { |
| 12788 | struct dwarf2_cu *spec_cu = cu; |
| 12789 | struct die_info *spec_die; |
| 12790 | |
| 12791 | /* GCJ will output '<init>' for Java constructor names. |
| 12792 | For this special case, return the name of the parent class. */ |
| 12793 | |
| 12794 | /* GCJ may output suprogram DIEs with AT_specification set. |
| 12795 | If so, use the name of the specified DIE. */ |
| 12796 | spec_die = die_specification (die, &spec_cu); |
| 12797 | if (spec_die != NULL) |
| 12798 | return dwarf2_name (spec_die, spec_cu); |
| 12799 | |
| 12800 | do |
| 12801 | { |
| 12802 | die = die->parent; |
| 12803 | if (die->tag == DW_TAG_class_type) |
| 12804 | return dwarf2_name (die, cu); |
| 12805 | } |
| 12806 | while (die->tag != DW_TAG_compile_unit); |
| 12807 | } |
| 12808 | break; |
| 12809 | |
| 12810 | case DW_TAG_class_type: |
| 12811 | case DW_TAG_interface_type: |
| 12812 | case DW_TAG_structure_type: |
| 12813 | case DW_TAG_union_type: |
| 12814 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed |
| 12815 | structures or unions. These were of the form "._%d" in GCC 4.1, |
| 12816 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 |
| 12817 | and GCC 4.4. We work around this problem by ignoring these. */ |
| 12818 | if (attr && DW_STRING (attr) |
| 12819 | && (strncmp (DW_STRING (attr), "._", 2) == 0 |
| 12820 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) |
| 12821 | return NULL; |
| 12822 | |
| 12823 | /* GCC might emit a nameless typedef that has a linkage name. See |
| 12824 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ |
| 12825 | if (!attr || DW_STRING (attr) == NULL) |
| 12826 | { |
| 12827 | char *demangled = NULL; |
| 12828 | |
| 12829 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 12830 | if (attr == NULL) |
| 12831 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 12832 | |
| 12833 | if (attr == NULL || DW_STRING (attr) == NULL) |
| 12834 | return NULL; |
| 12835 | |
| 12836 | /* Avoid demangling DW_STRING (attr) the second time on a second |
| 12837 | call for the same DIE. */ |
| 12838 | if (!DW_STRING_IS_CANONICAL (attr)) |
| 12839 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); |
| 12840 | |
| 12841 | if (demangled) |
| 12842 | { |
| 12843 | char *base; |
| 12844 | |
| 12845 | /* FIXME: we already did this for the partial symbol... */ |
| 12846 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
| 12847 | &cu->objfile->objfile_obstack); |
| 12848 | DW_STRING_IS_CANONICAL (attr) = 1; |
| 12849 | xfree (demangled); |
| 12850 | |
| 12851 | /* Strip any leading namespaces/classes, keep only the base name. |
| 12852 | DW_AT_name for named DIEs does not contain the prefixes. */ |
| 12853 | base = strrchr (DW_STRING (attr), ':'); |
| 12854 | if (base && base > DW_STRING (attr) && base[-1] == ':') |
| 12855 | return &base[1]; |
| 12856 | else |
| 12857 | return DW_STRING (attr); |
| 12858 | } |
| 12859 | } |
| 12860 | break; |
| 12861 | |
| 12862 | default: |
| 12863 | break; |
| 12864 | } |
| 12865 | |
| 12866 | if (!DW_STRING_IS_CANONICAL (attr)) |
| 12867 | { |
| 12868 | DW_STRING (attr) |
| 12869 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, |
| 12870 | &cu->objfile->objfile_obstack); |
| 12871 | DW_STRING_IS_CANONICAL (attr) = 1; |
| 12872 | } |
| 12873 | return DW_STRING (attr); |
| 12874 | } |
| 12875 | |
| 12876 | /* Return the die that this die in an extension of, or NULL if there |
| 12877 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
| 12878 | containing the return value on output. */ |
| 12879 | |
| 12880 | static struct die_info * |
| 12881 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
| 12882 | { |
| 12883 | struct attribute *attr; |
| 12884 | |
| 12885 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
| 12886 | if (attr == NULL) |
| 12887 | return NULL; |
| 12888 | |
| 12889 | return follow_die_ref (die, attr, ext_cu); |
| 12890 | } |
| 12891 | |
| 12892 | /* Convert a DIE tag into its string name. */ |
| 12893 | |
| 12894 | static char * |
| 12895 | dwarf_tag_name (unsigned tag) |
| 12896 | { |
| 12897 | switch (tag) |
| 12898 | { |
| 12899 | case DW_TAG_padding: |
| 12900 | return "DW_TAG_padding"; |
| 12901 | case DW_TAG_array_type: |
| 12902 | return "DW_TAG_array_type"; |
| 12903 | case DW_TAG_class_type: |
| 12904 | return "DW_TAG_class_type"; |
| 12905 | case DW_TAG_entry_point: |
| 12906 | return "DW_TAG_entry_point"; |
| 12907 | case DW_TAG_enumeration_type: |
| 12908 | return "DW_TAG_enumeration_type"; |
| 12909 | case DW_TAG_formal_parameter: |
| 12910 | return "DW_TAG_formal_parameter"; |
| 12911 | case DW_TAG_imported_declaration: |
| 12912 | return "DW_TAG_imported_declaration"; |
| 12913 | case DW_TAG_label: |
| 12914 | return "DW_TAG_label"; |
| 12915 | case DW_TAG_lexical_block: |
| 12916 | return "DW_TAG_lexical_block"; |
| 12917 | case DW_TAG_member: |
| 12918 | return "DW_TAG_member"; |
| 12919 | case DW_TAG_pointer_type: |
| 12920 | return "DW_TAG_pointer_type"; |
| 12921 | case DW_TAG_reference_type: |
| 12922 | return "DW_TAG_reference_type"; |
| 12923 | case DW_TAG_compile_unit: |
| 12924 | return "DW_TAG_compile_unit"; |
| 12925 | case DW_TAG_string_type: |
| 12926 | return "DW_TAG_string_type"; |
| 12927 | case DW_TAG_structure_type: |
| 12928 | return "DW_TAG_structure_type"; |
| 12929 | case DW_TAG_subroutine_type: |
| 12930 | return "DW_TAG_subroutine_type"; |
| 12931 | case DW_TAG_typedef: |
| 12932 | return "DW_TAG_typedef"; |
| 12933 | case DW_TAG_union_type: |
| 12934 | return "DW_TAG_union_type"; |
| 12935 | case DW_TAG_unspecified_parameters: |
| 12936 | return "DW_TAG_unspecified_parameters"; |
| 12937 | case DW_TAG_variant: |
| 12938 | return "DW_TAG_variant"; |
| 12939 | case DW_TAG_common_block: |
| 12940 | return "DW_TAG_common_block"; |
| 12941 | case DW_TAG_common_inclusion: |
| 12942 | return "DW_TAG_common_inclusion"; |
| 12943 | case DW_TAG_inheritance: |
| 12944 | return "DW_TAG_inheritance"; |
| 12945 | case DW_TAG_inlined_subroutine: |
| 12946 | return "DW_TAG_inlined_subroutine"; |
| 12947 | case DW_TAG_module: |
| 12948 | return "DW_TAG_module"; |
| 12949 | case DW_TAG_ptr_to_member_type: |
| 12950 | return "DW_TAG_ptr_to_member_type"; |
| 12951 | case DW_TAG_set_type: |
| 12952 | return "DW_TAG_set_type"; |
| 12953 | case DW_TAG_subrange_type: |
| 12954 | return "DW_TAG_subrange_type"; |
| 12955 | case DW_TAG_with_stmt: |
| 12956 | return "DW_TAG_with_stmt"; |
| 12957 | case DW_TAG_access_declaration: |
| 12958 | return "DW_TAG_access_declaration"; |
| 12959 | case DW_TAG_base_type: |
| 12960 | return "DW_TAG_base_type"; |
| 12961 | case DW_TAG_catch_block: |
| 12962 | return "DW_TAG_catch_block"; |
| 12963 | case DW_TAG_const_type: |
| 12964 | return "DW_TAG_const_type"; |
| 12965 | case DW_TAG_constant: |
| 12966 | return "DW_TAG_constant"; |
| 12967 | case DW_TAG_enumerator: |
| 12968 | return "DW_TAG_enumerator"; |
| 12969 | case DW_TAG_file_type: |
| 12970 | return "DW_TAG_file_type"; |
| 12971 | case DW_TAG_friend: |
| 12972 | return "DW_TAG_friend"; |
| 12973 | case DW_TAG_namelist: |
| 12974 | return "DW_TAG_namelist"; |
| 12975 | case DW_TAG_namelist_item: |
| 12976 | return "DW_TAG_namelist_item"; |
| 12977 | case DW_TAG_packed_type: |
| 12978 | return "DW_TAG_packed_type"; |
| 12979 | case DW_TAG_subprogram: |
| 12980 | return "DW_TAG_subprogram"; |
| 12981 | case DW_TAG_template_type_param: |
| 12982 | return "DW_TAG_template_type_param"; |
| 12983 | case DW_TAG_template_value_param: |
| 12984 | return "DW_TAG_template_value_param"; |
| 12985 | case DW_TAG_thrown_type: |
| 12986 | return "DW_TAG_thrown_type"; |
| 12987 | case DW_TAG_try_block: |
| 12988 | return "DW_TAG_try_block"; |
| 12989 | case DW_TAG_variant_part: |
| 12990 | return "DW_TAG_variant_part"; |
| 12991 | case DW_TAG_variable: |
| 12992 | return "DW_TAG_variable"; |
| 12993 | case DW_TAG_volatile_type: |
| 12994 | return "DW_TAG_volatile_type"; |
| 12995 | case DW_TAG_dwarf_procedure: |
| 12996 | return "DW_TAG_dwarf_procedure"; |
| 12997 | case DW_TAG_restrict_type: |
| 12998 | return "DW_TAG_restrict_type"; |
| 12999 | case DW_TAG_interface_type: |
| 13000 | return "DW_TAG_interface_type"; |
| 13001 | case DW_TAG_namespace: |
| 13002 | return "DW_TAG_namespace"; |
| 13003 | case DW_TAG_imported_module: |
| 13004 | return "DW_TAG_imported_module"; |
| 13005 | case DW_TAG_unspecified_type: |
| 13006 | return "DW_TAG_unspecified_type"; |
| 13007 | case DW_TAG_partial_unit: |
| 13008 | return "DW_TAG_partial_unit"; |
| 13009 | case DW_TAG_imported_unit: |
| 13010 | return "DW_TAG_imported_unit"; |
| 13011 | case DW_TAG_condition: |
| 13012 | return "DW_TAG_condition"; |
| 13013 | case DW_TAG_shared_type: |
| 13014 | return "DW_TAG_shared_type"; |
| 13015 | case DW_TAG_type_unit: |
| 13016 | return "DW_TAG_type_unit"; |
| 13017 | case DW_TAG_MIPS_loop: |
| 13018 | return "DW_TAG_MIPS_loop"; |
| 13019 | case DW_TAG_HP_array_descriptor: |
| 13020 | return "DW_TAG_HP_array_descriptor"; |
| 13021 | case DW_TAG_format_label: |
| 13022 | return "DW_TAG_format_label"; |
| 13023 | case DW_TAG_function_template: |
| 13024 | return "DW_TAG_function_template"; |
| 13025 | case DW_TAG_class_template: |
| 13026 | return "DW_TAG_class_template"; |
| 13027 | case DW_TAG_GNU_BINCL: |
| 13028 | return "DW_TAG_GNU_BINCL"; |
| 13029 | case DW_TAG_GNU_EINCL: |
| 13030 | return "DW_TAG_GNU_EINCL"; |
| 13031 | case DW_TAG_upc_shared_type: |
| 13032 | return "DW_TAG_upc_shared_type"; |
| 13033 | case DW_TAG_upc_strict_type: |
| 13034 | return "DW_TAG_upc_strict_type"; |
| 13035 | case DW_TAG_upc_relaxed_type: |
| 13036 | return "DW_TAG_upc_relaxed_type"; |
| 13037 | case DW_TAG_PGI_kanji_type: |
| 13038 | return "DW_TAG_PGI_kanji_type"; |
| 13039 | case DW_TAG_PGI_interface_block: |
| 13040 | return "DW_TAG_PGI_interface_block"; |
| 13041 | case DW_TAG_GNU_call_site: |
| 13042 | return "DW_TAG_GNU_call_site"; |
| 13043 | default: |
| 13044 | return "DW_TAG_<unknown>"; |
| 13045 | } |
| 13046 | } |
| 13047 | |
| 13048 | /* Convert a DWARF attribute code into its string name. */ |
| 13049 | |
| 13050 | static char * |
| 13051 | dwarf_attr_name (unsigned attr) |
| 13052 | { |
| 13053 | switch (attr) |
| 13054 | { |
| 13055 | case DW_AT_sibling: |
| 13056 | return "DW_AT_sibling"; |
| 13057 | case DW_AT_location: |
| 13058 | return "DW_AT_location"; |
| 13059 | case DW_AT_name: |
| 13060 | return "DW_AT_name"; |
| 13061 | case DW_AT_ordering: |
| 13062 | return "DW_AT_ordering"; |
| 13063 | case DW_AT_subscr_data: |
| 13064 | return "DW_AT_subscr_data"; |
| 13065 | case DW_AT_byte_size: |
| 13066 | return "DW_AT_byte_size"; |
| 13067 | case DW_AT_bit_offset: |
| 13068 | return "DW_AT_bit_offset"; |
| 13069 | case DW_AT_bit_size: |
| 13070 | return "DW_AT_bit_size"; |
| 13071 | case DW_AT_element_list: |
| 13072 | return "DW_AT_element_list"; |
| 13073 | case DW_AT_stmt_list: |
| 13074 | return "DW_AT_stmt_list"; |
| 13075 | case DW_AT_low_pc: |
| 13076 | return "DW_AT_low_pc"; |
| 13077 | case DW_AT_high_pc: |
| 13078 | return "DW_AT_high_pc"; |
| 13079 | case DW_AT_language: |
| 13080 | return "DW_AT_language"; |
| 13081 | case DW_AT_member: |
| 13082 | return "DW_AT_member"; |
| 13083 | case DW_AT_discr: |
| 13084 | return "DW_AT_discr"; |
| 13085 | case DW_AT_discr_value: |
| 13086 | return "DW_AT_discr_value"; |
| 13087 | case DW_AT_visibility: |
| 13088 | return "DW_AT_visibility"; |
| 13089 | case DW_AT_import: |
| 13090 | return "DW_AT_import"; |
| 13091 | case DW_AT_string_length: |
| 13092 | return "DW_AT_string_length"; |
| 13093 | case DW_AT_common_reference: |
| 13094 | return "DW_AT_common_reference"; |
| 13095 | case DW_AT_comp_dir: |
| 13096 | return "DW_AT_comp_dir"; |
| 13097 | case DW_AT_const_value: |
| 13098 | return "DW_AT_const_value"; |
| 13099 | case DW_AT_containing_type: |
| 13100 | return "DW_AT_containing_type"; |
| 13101 | case DW_AT_default_value: |
| 13102 | return "DW_AT_default_value"; |
| 13103 | case DW_AT_inline: |
| 13104 | return "DW_AT_inline"; |
| 13105 | case DW_AT_is_optional: |
| 13106 | return "DW_AT_is_optional"; |
| 13107 | case DW_AT_lower_bound: |
| 13108 | return "DW_AT_lower_bound"; |
| 13109 | case DW_AT_producer: |
| 13110 | return "DW_AT_producer"; |
| 13111 | case DW_AT_prototyped: |
| 13112 | return "DW_AT_prototyped"; |
| 13113 | case DW_AT_return_addr: |
| 13114 | return "DW_AT_return_addr"; |
| 13115 | case DW_AT_start_scope: |
| 13116 | return "DW_AT_start_scope"; |
| 13117 | case DW_AT_bit_stride: |
| 13118 | return "DW_AT_bit_stride"; |
| 13119 | case DW_AT_upper_bound: |
| 13120 | return "DW_AT_upper_bound"; |
| 13121 | case DW_AT_abstract_origin: |
| 13122 | return "DW_AT_abstract_origin"; |
| 13123 | case DW_AT_accessibility: |
| 13124 | return "DW_AT_accessibility"; |
| 13125 | case DW_AT_address_class: |
| 13126 | return "DW_AT_address_class"; |
| 13127 | case DW_AT_artificial: |
| 13128 | return "DW_AT_artificial"; |
| 13129 | case DW_AT_base_types: |
| 13130 | return "DW_AT_base_types"; |
| 13131 | case DW_AT_calling_convention: |
| 13132 | return "DW_AT_calling_convention"; |
| 13133 | case DW_AT_count: |
| 13134 | return "DW_AT_count"; |
| 13135 | case DW_AT_data_member_location: |
| 13136 | return "DW_AT_data_member_location"; |
| 13137 | case DW_AT_decl_column: |
| 13138 | return "DW_AT_decl_column"; |
| 13139 | case DW_AT_decl_file: |
| 13140 | return "DW_AT_decl_file"; |
| 13141 | case DW_AT_decl_line: |
| 13142 | return "DW_AT_decl_line"; |
| 13143 | case DW_AT_declaration: |
| 13144 | return "DW_AT_declaration"; |
| 13145 | case DW_AT_discr_list: |
| 13146 | return "DW_AT_discr_list"; |
| 13147 | case DW_AT_encoding: |
| 13148 | return "DW_AT_encoding"; |
| 13149 | case DW_AT_external: |
| 13150 | return "DW_AT_external"; |
| 13151 | case DW_AT_frame_base: |
| 13152 | return "DW_AT_frame_base"; |
| 13153 | case DW_AT_friend: |
| 13154 | return "DW_AT_friend"; |
| 13155 | case DW_AT_identifier_case: |
| 13156 | return "DW_AT_identifier_case"; |
| 13157 | case DW_AT_macro_info: |
| 13158 | return "DW_AT_macro_info"; |
| 13159 | case DW_AT_namelist_items: |
| 13160 | return "DW_AT_namelist_items"; |
| 13161 | case DW_AT_priority: |
| 13162 | return "DW_AT_priority"; |
| 13163 | case DW_AT_segment: |
| 13164 | return "DW_AT_segment"; |
| 13165 | case DW_AT_specification: |
| 13166 | return "DW_AT_specification"; |
| 13167 | case DW_AT_static_link: |
| 13168 | return "DW_AT_static_link"; |
| 13169 | case DW_AT_type: |
| 13170 | return "DW_AT_type"; |
| 13171 | case DW_AT_use_location: |
| 13172 | return "DW_AT_use_location"; |
| 13173 | case DW_AT_variable_parameter: |
| 13174 | return "DW_AT_variable_parameter"; |
| 13175 | case DW_AT_virtuality: |
| 13176 | return "DW_AT_virtuality"; |
| 13177 | case DW_AT_vtable_elem_location: |
| 13178 | return "DW_AT_vtable_elem_location"; |
| 13179 | /* DWARF 3 values. */ |
| 13180 | case DW_AT_allocated: |
| 13181 | return "DW_AT_allocated"; |
| 13182 | case DW_AT_associated: |
| 13183 | return "DW_AT_associated"; |
| 13184 | case DW_AT_data_location: |
| 13185 | return "DW_AT_data_location"; |
| 13186 | case DW_AT_byte_stride: |
| 13187 | return "DW_AT_byte_stride"; |
| 13188 | case DW_AT_entry_pc: |
| 13189 | return "DW_AT_entry_pc"; |
| 13190 | case DW_AT_use_UTF8: |
| 13191 | return "DW_AT_use_UTF8"; |
| 13192 | case DW_AT_extension: |
| 13193 | return "DW_AT_extension"; |
| 13194 | case DW_AT_ranges: |
| 13195 | return "DW_AT_ranges"; |
| 13196 | case DW_AT_trampoline: |
| 13197 | return "DW_AT_trampoline"; |
| 13198 | case DW_AT_call_column: |
| 13199 | return "DW_AT_call_column"; |
| 13200 | case DW_AT_call_file: |
| 13201 | return "DW_AT_call_file"; |
| 13202 | case DW_AT_call_line: |
| 13203 | return "DW_AT_call_line"; |
| 13204 | case DW_AT_description: |
| 13205 | return "DW_AT_description"; |
| 13206 | case DW_AT_binary_scale: |
| 13207 | return "DW_AT_binary_scale"; |
| 13208 | case DW_AT_decimal_scale: |
| 13209 | return "DW_AT_decimal_scale"; |
| 13210 | case DW_AT_small: |
| 13211 | return "DW_AT_small"; |
| 13212 | case DW_AT_decimal_sign: |
| 13213 | return "DW_AT_decimal_sign"; |
| 13214 | case DW_AT_digit_count: |
| 13215 | return "DW_AT_digit_count"; |
| 13216 | case DW_AT_picture_string: |
| 13217 | return "DW_AT_picture_string"; |
| 13218 | case DW_AT_mutable: |
| 13219 | return "DW_AT_mutable"; |
| 13220 | case DW_AT_threads_scaled: |
| 13221 | return "DW_AT_threads_scaled"; |
| 13222 | case DW_AT_explicit: |
| 13223 | return "DW_AT_explicit"; |
| 13224 | case DW_AT_object_pointer: |
| 13225 | return "DW_AT_object_pointer"; |
| 13226 | case DW_AT_endianity: |
| 13227 | return "DW_AT_endianity"; |
| 13228 | case DW_AT_elemental: |
| 13229 | return "DW_AT_elemental"; |
| 13230 | case DW_AT_pure: |
| 13231 | return "DW_AT_pure"; |
| 13232 | case DW_AT_recursive: |
| 13233 | return "DW_AT_recursive"; |
| 13234 | /* DWARF 4 values. */ |
| 13235 | case DW_AT_signature: |
| 13236 | return "DW_AT_signature"; |
| 13237 | case DW_AT_linkage_name: |
| 13238 | return "DW_AT_linkage_name"; |
| 13239 | /* SGI/MIPS extensions. */ |
| 13240 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
| 13241 | case DW_AT_MIPS_fde: |
| 13242 | return "DW_AT_MIPS_fde"; |
| 13243 | #endif |
| 13244 | case DW_AT_MIPS_loop_begin: |
| 13245 | return "DW_AT_MIPS_loop_begin"; |
| 13246 | case DW_AT_MIPS_tail_loop_begin: |
| 13247 | return "DW_AT_MIPS_tail_loop_begin"; |
| 13248 | case DW_AT_MIPS_epilog_begin: |
| 13249 | return "DW_AT_MIPS_epilog_begin"; |
| 13250 | case DW_AT_MIPS_loop_unroll_factor: |
| 13251 | return "DW_AT_MIPS_loop_unroll_factor"; |
| 13252 | case DW_AT_MIPS_software_pipeline_depth: |
| 13253 | return "DW_AT_MIPS_software_pipeline_depth"; |
| 13254 | case DW_AT_MIPS_linkage_name: |
| 13255 | return "DW_AT_MIPS_linkage_name"; |
| 13256 | case DW_AT_MIPS_stride: |
| 13257 | return "DW_AT_MIPS_stride"; |
| 13258 | case DW_AT_MIPS_abstract_name: |
| 13259 | return "DW_AT_MIPS_abstract_name"; |
| 13260 | case DW_AT_MIPS_clone_origin: |
| 13261 | return "DW_AT_MIPS_clone_origin"; |
| 13262 | case DW_AT_MIPS_has_inlines: |
| 13263 | return "DW_AT_MIPS_has_inlines"; |
| 13264 | /* HP extensions. */ |
| 13265 | #ifndef MIPS /* collides with DW_AT_MIPS_fde */ |
| 13266 | case DW_AT_HP_block_index: |
| 13267 | return "DW_AT_HP_block_index"; |
| 13268 | #endif |
| 13269 | case DW_AT_HP_unmodifiable: |
| 13270 | return "DW_AT_HP_unmodifiable"; |
| 13271 | case DW_AT_HP_actuals_stmt_list: |
| 13272 | return "DW_AT_HP_actuals_stmt_list"; |
| 13273 | case DW_AT_HP_proc_per_section: |
| 13274 | return "DW_AT_HP_proc_per_section"; |
| 13275 | case DW_AT_HP_raw_data_ptr: |
| 13276 | return "DW_AT_HP_raw_data_ptr"; |
| 13277 | case DW_AT_HP_pass_by_reference: |
| 13278 | return "DW_AT_HP_pass_by_reference"; |
| 13279 | case DW_AT_HP_opt_level: |
| 13280 | return "DW_AT_HP_opt_level"; |
| 13281 | case DW_AT_HP_prof_version_id: |
| 13282 | return "DW_AT_HP_prof_version_id"; |
| 13283 | case DW_AT_HP_opt_flags: |
| 13284 | return "DW_AT_HP_opt_flags"; |
| 13285 | case DW_AT_HP_cold_region_low_pc: |
| 13286 | return "DW_AT_HP_cold_region_low_pc"; |
| 13287 | case DW_AT_HP_cold_region_high_pc: |
| 13288 | return "DW_AT_HP_cold_region_high_pc"; |
| 13289 | case DW_AT_HP_all_variables_modifiable: |
| 13290 | return "DW_AT_HP_all_variables_modifiable"; |
| 13291 | case DW_AT_HP_linkage_name: |
| 13292 | return "DW_AT_HP_linkage_name"; |
| 13293 | case DW_AT_HP_prof_flags: |
| 13294 | return "DW_AT_HP_prof_flags"; |
| 13295 | /* GNU extensions. */ |
| 13296 | case DW_AT_sf_names: |
| 13297 | return "DW_AT_sf_names"; |
| 13298 | case DW_AT_src_info: |
| 13299 | return "DW_AT_src_info"; |
| 13300 | case DW_AT_mac_info: |
| 13301 | return "DW_AT_mac_info"; |
| 13302 | case DW_AT_src_coords: |
| 13303 | return "DW_AT_src_coords"; |
| 13304 | case DW_AT_body_begin: |
| 13305 | return "DW_AT_body_begin"; |
| 13306 | case DW_AT_body_end: |
| 13307 | return "DW_AT_body_end"; |
| 13308 | case DW_AT_GNU_vector: |
| 13309 | return "DW_AT_GNU_vector"; |
| 13310 | case DW_AT_GNU_odr_signature: |
| 13311 | return "DW_AT_GNU_odr_signature"; |
| 13312 | /* VMS extensions. */ |
| 13313 | case DW_AT_VMS_rtnbeg_pd_address: |
| 13314 | return "DW_AT_VMS_rtnbeg_pd_address"; |
| 13315 | /* UPC extension. */ |
| 13316 | case DW_AT_upc_threads_scaled: |
| 13317 | return "DW_AT_upc_threads_scaled"; |
| 13318 | /* PGI (STMicroelectronics) extensions. */ |
| 13319 | case DW_AT_PGI_lbase: |
| 13320 | return "DW_AT_PGI_lbase"; |
| 13321 | case DW_AT_PGI_soffset: |
| 13322 | return "DW_AT_PGI_soffset"; |
| 13323 | case DW_AT_PGI_lstride: |
| 13324 | return "DW_AT_PGI_lstride"; |
| 13325 | default: |
| 13326 | return "DW_AT_<unknown>"; |
| 13327 | } |
| 13328 | } |
| 13329 | |
| 13330 | /* Convert a DWARF value form code into its string name. */ |
| 13331 | |
| 13332 | static char * |
| 13333 | dwarf_form_name (unsigned form) |
| 13334 | { |
| 13335 | switch (form) |
| 13336 | { |
| 13337 | case DW_FORM_addr: |
| 13338 | return "DW_FORM_addr"; |
| 13339 | case DW_FORM_block2: |
| 13340 | return "DW_FORM_block2"; |
| 13341 | case DW_FORM_block4: |
| 13342 | return "DW_FORM_block4"; |
| 13343 | case DW_FORM_data2: |
| 13344 | return "DW_FORM_data2"; |
| 13345 | case DW_FORM_data4: |
| 13346 | return "DW_FORM_data4"; |
| 13347 | case DW_FORM_data8: |
| 13348 | return "DW_FORM_data8"; |
| 13349 | case DW_FORM_string: |
| 13350 | return "DW_FORM_string"; |
| 13351 | case DW_FORM_block: |
| 13352 | return "DW_FORM_block"; |
| 13353 | case DW_FORM_block1: |
| 13354 | return "DW_FORM_block1"; |
| 13355 | case DW_FORM_data1: |
| 13356 | return "DW_FORM_data1"; |
| 13357 | case DW_FORM_flag: |
| 13358 | return "DW_FORM_flag"; |
| 13359 | case DW_FORM_sdata: |
| 13360 | return "DW_FORM_sdata"; |
| 13361 | case DW_FORM_strp: |
| 13362 | return "DW_FORM_strp"; |
| 13363 | case DW_FORM_udata: |
| 13364 | return "DW_FORM_udata"; |
| 13365 | case DW_FORM_ref_addr: |
| 13366 | return "DW_FORM_ref_addr"; |
| 13367 | case DW_FORM_ref1: |
| 13368 | return "DW_FORM_ref1"; |
| 13369 | case DW_FORM_ref2: |
| 13370 | return "DW_FORM_ref2"; |
| 13371 | case DW_FORM_ref4: |
| 13372 | return "DW_FORM_ref4"; |
| 13373 | case DW_FORM_ref8: |
| 13374 | return "DW_FORM_ref8"; |
| 13375 | case DW_FORM_ref_udata: |
| 13376 | return "DW_FORM_ref_udata"; |
| 13377 | case DW_FORM_indirect: |
| 13378 | return "DW_FORM_indirect"; |
| 13379 | case DW_FORM_sec_offset: |
| 13380 | return "DW_FORM_sec_offset"; |
| 13381 | case DW_FORM_exprloc: |
| 13382 | return "DW_FORM_exprloc"; |
| 13383 | case DW_FORM_flag_present: |
| 13384 | return "DW_FORM_flag_present"; |
| 13385 | case DW_FORM_ref_sig8: |
| 13386 | return "DW_FORM_ref_sig8"; |
| 13387 | default: |
| 13388 | return "DW_FORM_<unknown>"; |
| 13389 | } |
| 13390 | } |
| 13391 | |
| 13392 | /* Convert a DWARF stack opcode into its string name. */ |
| 13393 | |
| 13394 | const char * |
| 13395 | dwarf_stack_op_name (unsigned op) |
| 13396 | { |
| 13397 | switch (op) |
| 13398 | { |
| 13399 | case DW_OP_addr: |
| 13400 | return "DW_OP_addr"; |
| 13401 | case DW_OP_deref: |
| 13402 | return "DW_OP_deref"; |
| 13403 | case DW_OP_const1u: |
| 13404 | return "DW_OP_const1u"; |
| 13405 | case DW_OP_const1s: |
| 13406 | return "DW_OP_const1s"; |
| 13407 | case DW_OP_const2u: |
| 13408 | return "DW_OP_const2u"; |
| 13409 | case DW_OP_const2s: |
| 13410 | return "DW_OP_const2s"; |
| 13411 | case DW_OP_const4u: |
| 13412 | return "DW_OP_const4u"; |
| 13413 | case DW_OP_const4s: |
| 13414 | return "DW_OP_const4s"; |
| 13415 | case DW_OP_const8u: |
| 13416 | return "DW_OP_const8u"; |
| 13417 | case DW_OP_const8s: |
| 13418 | return "DW_OP_const8s"; |
| 13419 | case DW_OP_constu: |
| 13420 | return "DW_OP_constu"; |
| 13421 | case DW_OP_consts: |
| 13422 | return "DW_OP_consts"; |
| 13423 | case DW_OP_dup: |
| 13424 | return "DW_OP_dup"; |
| 13425 | case DW_OP_drop: |
| 13426 | return "DW_OP_drop"; |
| 13427 | case DW_OP_over: |
| 13428 | return "DW_OP_over"; |
| 13429 | case DW_OP_pick: |
| 13430 | return "DW_OP_pick"; |
| 13431 | case DW_OP_swap: |
| 13432 | return "DW_OP_swap"; |
| 13433 | case DW_OP_rot: |
| 13434 | return "DW_OP_rot"; |
| 13435 | case DW_OP_xderef: |
| 13436 | return "DW_OP_xderef"; |
| 13437 | case DW_OP_abs: |
| 13438 | return "DW_OP_abs"; |
| 13439 | case DW_OP_and: |
| 13440 | return "DW_OP_and"; |
| 13441 | case DW_OP_div: |
| 13442 | return "DW_OP_div"; |
| 13443 | case DW_OP_minus: |
| 13444 | return "DW_OP_minus"; |
| 13445 | case DW_OP_mod: |
| 13446 | return "DW_OP_mod"; |
| 13447 | case DW_OP_mul: |
| 13448 | return "DW_OP_mul"; |
| 13449 | case DW_OP_neg: |
| 13450 | return "DW_OP_neg"; |
| 13451 | case DW_OP_not: |
| 13452 | return "DW_OP_not"; |
| 13453 | case DW_OP_or: |
| 13454 | return "DW_OP_or"; |
| 13455 | case DW_OP_plus: |
| 13456 | return "DW_OP_plus"; |
| 13457 | case DW_OP_plus_uconst: |
| 13458 | return "DW_OP_plus_uconst"; |
| 13459 | case DW_OP_shl: |
| 13460 | return "DW_OP_shl"; |
| 13461 | case DW_OP_shr: |
| 13462 | return "DW_OP_shr"; |
| 13463 | case DW_OP_shra: |
| 13464 | return "DW_OP_shra"; |
| 13465 | case DW_OP_xor: |
| 13466 | return "DW_OP_xor"; |
| 13467 | case DW_OP_bra: |
| 13468 | return "DW_OP_bra"; |
| 13469 | case DW_OP_eq: |
| 13470 | return "DW_OP_eq"; |
| 13471 | case DW_OP_ge: |
| 13472 | return "DW_OP_ge"; |
| 13473 | case DW_OP_gt: |
| 13474 | return "DW_OP_gt"; |
| 13475 | case DW_OP_le: |
| 13476 | return "DW_OP_le"; |
| 13477 | case DW_OP_lt: |
| 13478 | return "DW_OP_lt"; |
| 13479 | case DW_OP_ne: |
| 13480 | return "DW_OP_ne"; |
| 13481 | case DW_OP_skip: |
| 13482 | return "DW_OP_skip"; |
| 13483 | case DW_OP_lit0: |
| 13484 | return "DW_OP_lit0"; |
| 13485 | case DW_OP_lit1: |
| 13486 | return "DW_OP_lit1"; |
| 13487 | case DW_OP_lit2: |
| 13488 | return "DW_OP_lit2"; |
| 13489 | case DW_OP_lit3: |
| 13490 | return "DW_OP_lit3"; |
| 13491 | case DW_OP_lit4: |
| 13492 | return "DW_OP_lit4"; |
| 13493 | case DW_OP_lit5: |
| 13494 | return "DW_OP_lit5"; |
| 13495 | case DW_OP_lit6: |
| 13496 | return "DW_OP_lit6"; |
| 13497 | case DW_OP_lit7: |
| 13498 | return "DW_OP_lit7"; |
| 13499 | case DW_OP_lit8: |
| 13500 | return "DW_OP_lit8"; |
| 13501 | case DW_OP_lit9: |
| 13502 | return "DW_OP_lit9"; |
| 13503 | case DW_OP_lit10: |
| 13504 | return "DW_OP_lit10"; |
| 13505 | case DW_OP_lit11: |
| 13506 | return "DW_OP_lit11"; |
| 13507 | case DW_OP_lit12: |
| 13508 | return "DW_OP_lit12"; |
| 13509 | case DW_OP_lit13: |
| 13510 | return "DW_OP_lit13"; |
| 13511 | case DW_OP_lit14: |
| 13512 | return "DW_OP_lit14"; |
| 13513 | case DW_OP_lit15: |
| 13514 | return "DW_OP_lit15"; |
| 13515 | case DW_OP_lit16: |
| 13516 | return "DW_OP_lit16"; |
| 13517 | case DW_OP_lit17: |
| 13518 | return "DW_OP_lit17"; |
| 13519 | case DW_OP_lit18: |
| 13520 | return "DW_OP_lit18"; |
| 13521 | case DW_OP_lit19: |
| 13522 | return "DW_OP_lit19"; |
| 13523 | case DW_OP_lit20: |
| 13524 | return "DW_OP_lit20"; |
| 13525 | case DW_OP_lit21: |
| 13526 | return "DW_OP_lit21"; |
| 13527 | case DW_OP_lit22: |
| 13528 | return "DW_OP_lit22"; |
| 13529 | case DW_OP_lit23: |
| 13530 | return "DW_OP_lit23"; |
| 13531 | case DW_OP_lit24: |
| 13532 | return "DW_OP_lit24"; |
| 13533 | case DW_OP_lit25: |
| 13534 | return "DW_OP_lit25"; |
| 13535 | case DW_OP_lit26: |
| 13536 | return "DW_OP_lit26"; |
| 13537 | case DW_OP_lit27: |
| 13538 | return "DW_OP_lit27"; |
| 13539 | case DW_OP_lit28: |
| 13540 | return "DW_OP_lit28"; |
| 13541 | case DW_OP_lit29: |
| 13542 | return "DW_OP_lit29"; |
| 13543 | case DW_OP_lit30: |
| 13544 | return "DW_OP_lit30"; |
| 13545 | case DW_OP_lit31: |
| 13546 | return "DW_OP_lit31"; |
| 13547 | case DW_OP_reg0: |
| 13548 | return "DW_OP_reg0"; |
| 13549 | case DW_OP_reg1: |
| 13550 | return "DW_OP_reg1"; |
| 13551 | case DW_OP_reg2: |
| 13552 | return "DW_OP_reg2"; |
| 13553 | case DW_OP_reg3: |
| 13554 | return "DW_OP_reg3"; |
| 13555 | case DW_OP_reg4: |
| 13556 | return "DW_OP_reg4"; |
| 13557 | case DW_OP_reg5: |
| 13558 | return "DW_OP_reg5"; |
| 13559 | case DW_OP_reg6: |
| 13560 | return "DW_OP_reg6"; |
| 13561 | case DW_OP_reg7: |
| 13562 | return "DW_OP_reg7"; |
| 13563 | case DW_OP_reg8: |
| 13564 | return "DW_OP_reg8"; |
| 13565 | case DW_OP_reg9: |
| 13566 | return "DW_OP_reg9"; |
| 13567 | case DW_OP_reg10: |
| 13568 | return "DW_OP_reg10"; |
| 13569 | case DW_OP_reg11: |
| 13570 | return "DW_OP_reg11"; |
| 13571 | case DW_OP_reg12: |
| 13572 | return "DW_OP_reg12"; |
| 13573 | case DW_OP_reg13: |
| 13574 | return "DW_OP_reg13"; |
| 13575 | case DW_OP_reg14: |
| 13576 | return "DW_OP_reg14"; |
| 13577 | case DW_OP_reg15: |
| 13578 | return "DW_OP_reg15"; |
| 13579 | case DW_OP_reg16: |
| 13580 | return "DW_OP_reg16"; |
| 13581 | case DW_OP_reg17: |
| 13582 | return "DW_OP_reg17"; |
| 13583 | case DW_OP_reg18: |
| 13584 | return "DW_OP_reg18"; |
| 13585 | case DW_OP_reg19: |
| 13586 | return "DW_OP_reg19"; |
| 13587 | case DW_OP_reg20: |
| 13588 | return "DW_OP_reg20"; |
| 13589 | case DW_OP_reg21: |
| 13590 | return "DW_OP_reg21"; |
| 13591 | case DW_OP_reg22: |
| 13592 | return "DW_OP_reg22"; |
| 13593 | case DW_OP_reg23: |
| 13594 | return "DW_OP_reg23"; |
| 13595 | case DW_OP_reg24: |
| 13596 | return "DW_OP_reg24"; |
| 13597 | case DW_OP_reg25: |
| 13598 | return "DW_OP_reg25"; |
| 13599 | case DW_OP_reg26: |
| 13600 | return "DW_OP_reg26"; |
| 13601 | case DW_OP_reg27: |
| 13602 | return "DW_OP_reg27"; |
| 13603 | case DW_OP_reg28: |
| 13604 | return "DW_OP_reg28"; |
| 13605 | case DW_OP_reg29: |
| 13606 | return "DW_OP_reg29"; |
| 13607 | case DW_OP_reg30: |
| 13608 | return "DW_OP_reg30"; |
| 13609 | case DW_OP_reg31: |
| 13610 | return "DW_OP_reg31"; |
| 13611 | case DW_OP_breg0: |
| 13612 | return "DW_OP_breg0"; |
| 13613 | case DW_OP_breg1: |
| 13614 | return "DW_OP_breg1"; |
| 13615 | case DW_OP_breg2: |
| 13616 | return "DW_OP_breg2"; |
| 13617 | case DW_OP_breg3: |
| 13618 | return "DW_OP_breg3"; |
| 13619 | case DW_OP_breg4: |
| 13620 | return "DW_OP_breg4"; |
| 13621 | case DW_OP_breg5: |
| 13622 | return "DW_OP_breg5"; |
| 13623 | case DW_OP_breg6: |
| 13624 | return "DW_OP_breg6"; |
| 13625 | case DW_OP_breg7: |
| 13626 | return "DW_OP_breg7"; |
| 13627 | case DW_OP_breg8: |
| 13628 | return "DW_OP_breg8"; |
| 13629 | case DW_OP_breg9: |
| 13630 | return "DW_OP_breg9"; |
| 13631 | case DW_OP_breg10: |
| 13632 | return "DW_OP_breg10"; |
| 13633 | case DW_OP_breg11: |
| 13634 | return "DW_OP_breg11"; |
| 13635 | case DW_OP_breg12: |
| 13636 | return "DW_OP_breg12"; |
| 13637 | case DW_OP_breg13: |
| 13638 | return "DW_OP_breg13"; |
| 13639 | case DW_OP_breg14: |
| 13640 | return "DW_OP_breg14"; |
| 13641 | case DW_OP_breg15: |
| 13642 | return "DW_OP_breg15"; |
| 13643 | case DW_OP_breg16: |
| 13644 | return "DW_OP_breg16"; |
| 13645 | case DW_OP_breg17: |
| 13646 | return "DW_OP_breg17"; |
| 13647 | case DW_OP_breg18: |
| 13648 | return "DW_OP_breg18"; |
| 13649 | case DW_OP_breg19: |
| 13650 | return "DW_OP_breg19"; |
| 13651 | case DW_OP_breg20: |
| 13652 | return "DW_OP_breg20"; |
| 13653 | case DW_OP_breg21: |
| 13654 | return "DW_OP_breg21"; |
| 13655 | case DW_OP_breg22: |
| 13656 | return "DW_OP_breg22"; |
| 13657 | case DW_OP_breg23: |
| 13658 | return "DW_OP_breg23"; |
| 13659 | case DW_OP_breg24: |
| 13660 | return "DW_OP_breg24"; |
| 13661 | case DW_OP_breg25: |
| 13662 | return "DW_OP_breg25"; |
| 13663 | case DW_OP_breg26: |
| 13664 | return "DW_OP_breg26"; |
| 13665 | case DW_OP_breg27: |
| 13666 | return "DW_OP_breg27"; |
| 13667 | case DW_OP_breg28: |
| 13668 | return "DW_OP_breg28"; |
| 13669 | case DW_OP_breg29: |
| 13670 | return "DW_OP_breg29"; |
| 13671 | case DW_OP_breg30: |
| 13672 | return "DW_OP_breg30"; |
| 13673 | case DW_OP_breg31: |
| 13674 | return "DW_OP_breg31"; |
| 13675 | case DW_OP_regx: |
| 13676 | return "DW_OP_regx"; |
| 13677 | case DW_OP_fbreg: |
| 13678 | return "DW_OP_fbreg"; |
| 13679 | case DW_OP_bregx: |
| 13680 | return "DW_OP_bregx"; |
| 13681 | case DW_OP_piece: |
| 13682 | return "DW_OP_piece"; |
| 13683 | case DW_OP_deref_size: |
| 13684 | return "DW_OP_deref_size"; |
| 13685 | case DW_OP_xderef_size: |
| 13686 | return "DW_OP_xderef_size"; |
| 13687 | case DW_OP_nop: |
| 13688 | return "DW_OP_nop"; |
| 13689 | /* DWARF 3 extensions. */ |
| 13690 | case DW_OP_push_object_address: |
| 13691 | return "DW_OP_push_object_address"; |
| 13692 | case DW_OP_call2: |
| 13693 | return "DW_OP_call2"; |
| 13694 | case DW_OP_call4: |
| 13695 | return "DW_OP_call4"; |
| 13696 | case DW_OP_call_ref: |
| 13697 | return "DW_OP_call_ref"; |
| 13698 | case DW_OP_form_tls_address: |
| 13699 | return "DW_OP_form_tls_address"; |
| 13700 | case DW_OP_call_frame_cfa: |
| 13701 | return "DW_OP_call_frame_cfa"; |
| 13702 | case DW_OP_bit_piece: |
| 13703 | return "DW_OP_bit_piece"; |
| 13704 | /* DWARF 4 extensions. */ |
| 13705 | case DW_OP_implicit_value: |
| 13706 | return "DW_OP_implicit_value"; |
| 13707 | case DW_OP_stack_value: |
| 13708 | return "DW_OP_stack_value"; |
| 13709 | /* GNU extensions. */ |
| 13710 | case DW_OP_GNU_push_tls_address: |
| 13711 | return "DW_OP_GNU_push_tls_address"; |
| 13712 | case DW_OP_GNU_uninit: |
| 13713 | return "DW_OP_GNU_uninit"; |
| 13714 | case DW_OP_GNU_implicit_pointer: |
| 13715 | return "DW_OP_GNU_implicit_pointer"; |
| 13716 | case DW_OP_GNU_entry_value: |
| 13717 | return "DW_OP_GNU_entry_value"; |
| 13718 | case DW_OP_GNU_const_type: |
| 13719 | return "DW_OP_GNU_const_type"; |
| 13720 | case DW_OP_GNU_regval_type: |
| 13721 | return "DW_OP_GNU_regval_type"; |
| 13722 | case DW_OP_GNU_deref_type: |
| 13723 | return "DW_OP_GNU_deref_type"; |
| 13724 | case DW_OP_GNU_convert: |
| 13725 | return "DW_OP_GNU_convert"; |
| 13726 | case DW_OP_GNU_reinterpret: |
| 13727 | return "DW_OP_GNU_reinterpret"; |
| 13728 | default: |
| 13729 | return NULL; |
| 13730 | } |
| 13731 | } |
| 13732 | |
| 13733 | static char * |
| 13734 | dwarf_bool_name (unsigned mybool) |
| 13735 | { |
| 13736 | if (mybool) |
| 13737 | return "TRUE"; |
| 13738 | else |
| 13739 | return "FALSE"; |
| 13740 | } |
| 13741 | |
| 13742 | /* Convert a DWARF type code into its string name. */ |
| 13743 | |
| 13744 | static char * |
| 13745 | dwarf_type_encoding_name (unsigned enc) |
| 13746 | { |
| 13747 | switch (enc) |
| 13748 | { |
| 13749 | case DW_ATE_void: |
| 13750 | return "DW_ATE_void"; |
| 13751 | case DW_ATE_address: |
| 13752 | return "DW_ATE_address"; |
| 13753 | case DW_ATE_boolean: |
| 13754 | return "DW_ATE_boolean"; |
| 13755 | case DW_ATE_complex_float: |
| 13756 | return "DW_ATE_complex_float"; |
| 13757 | case DW_ATE_float: |
| 13758 | return "DW_ATE_float"; |
| 13759 | case DW_ATE_signed: |
| 13760 | return "DW_ATE_signed"; |
| 13761 | case DW_ATE_signed_char: |
| 13762 | return "DW_ATE_signed_char"; |
| 13763 | case DW_ATE_unsigned: |
| 13764 | return "DW_ATE_unsigned"; |
| 13765 | case DW_ATE_unsigned_char: |
| 13766 | return "DW_ATE_unsigned_char"; |
| 13767 | /* DWARF 3. */ |
| 13768 | case DW_ATE_imaginary_float: |
| 13769 | return "DW_ATE_imaginary_float"; |
| 13770 | case DW_ATE_packed_decimal: |
| 13771 | return "DW_ATE_packed_decimal"; |
| 13772 | case DW_ATE_numeric_string: |
| 13773 | return "DW_ATE_numeric_string"; |
| 13774 | case DW_ATE_edited: |
| 13775 | return "DW_ATE_edited"; |
| 13776 | case DW_ATE_signed_fixed: |
| 13777 | return "DW_ATE_signed_fixed"; |
| 13778 | case DW_ATE_unsigned_fixed: |
| 13779 | return "DW_ATE_unsigned_fixed"; |
| 13780 | case DW_ATE_decimal_float: |
| 13781 | return "DW_ATE_decimal_float"; |
| 13782 | /* DWARF 4. */ |
| 13783 | case DW_ATE_UTF: |
| 13784 | return "DW_ATE_UTF"; |
| 13785 | /* HP extensions. */ |
| 13786 | case DW_ATE_HP_float80: |
| 13787 | return "DW_ATE_HP_float80"; |
| 13788 | case DW_ATE_HP_complex_float80: |
| 13789 | return "DW_ATE_HP_complex_float80"; |
| 13790 | case DW_ATE_HP_float128: |
| 13791 | return "DW_ATE_HP_float128"; |
| 13792 | case DW_ATE_HP_complex_float128: |
| 13793 | return "DW_ATE_HP_complex_float128"; |
| 13794 | case DW_ATE_HP_floathpintel: |
| 13795 | return "DW_ATE_HP_floathpintel"; |
| 13796 | case DW_ATE_HP_imaginary_float80: |
| 13797 | return "DW_ATE_HP_imaginary_float80"; |
| 13798 | case DW_ATE_HP_imaginary_float128: |
| 13799 | return "DW_ATE_HP_imaginary_float128"; |
| 13800 | default: |
| 13801 | return "DW_ATE_<unknown>"; |
| 13802 | } |
| 13803 | } |
| 13804 | |
| 13805 | /* Convert a DWARF call frame info operation to its string name. */ |
| 13806 | |
| 13807 | #if 0 |
| 13808 | static char * |
| 13809 | dwarf_cfi_name (unsigned cfi_opc) |
| 13810 | { |
| 13811 | switch (cfi_opc) |
| 13812 | { |
| 13813 | case DW_CFA_advance_loc: |
| 13814 | return "DW_CFA_advance_loc"; |
| 13815 | case DW_CFA_offset: |
| 13816 | return "DW_CFA_offset"; |
| 13817 | case DW_CFA_restore: |
| 13818 | return "DW_CFA_restore"; |
| 13819 | case DW_CFA_nop: |
| 13820 | return "DW_CFA_nop"; |
| 13821 | case DW_CFA_set_loc: |
| 13822 | return "DW_CFA_set_loc"; |
| 13823 | case DW_CFA_advance_loc1: |
| 13824 | return "DW_CFA_advance_loc1"; |
| 13825 | case DW_CFA_advance_loc2: |
| 13826 | return "DW_CFA_advance_loc2"; |
| 13827 | case DW_CFA_advance_loc4: |
| 13828 | return "DW_CFA_advance_loc4"; |
| 13829 | case DW_CFA_offset_extended: |
| 13830 | return "DW_CFA_offset_extended"; |
| 13831 | case DW_CFA_restore_extended: |
| 13832 | return "DW_CFA_restore_extended"; |
| 13833 | case DW_CFA_undefined: |
| 13834 | return "DW_CFA_undefined"; |
| 13835 | case DW_CFA_same_value: |
| 13836 | return "DW_CFA_same_value"; |
| 13837 | case DW_CFA_register: |
| 13838 | return "DW_CFA_register"; |
| 13839 | case DW_CFA_remember_state: |
| 13840 | return "DW_CFA_remember_state"; |
| 13841 | case DW_CFA_restore_state: |
| 13842 | return "DW_CFA_restore_state"; |
| 13843 | case DW_CFA_def_cfa: |
| 13844 | return "DW_CFA_def_cfa"; |
| 13845 | case DW_CFA_def_cfa_register: |
| 13846 | return "DW_CFA_def_cfa_register"; |
| 13847 | case DW_CFA_def_cfa_offset: |
| 13848 | return "DW_CFA_def_cfa_offset"; |
| 13849 | /* DWARF 3. */ |
| 13850 | case DW_CFA_def_cfa_expression: |
| 13851 | return "DW_CFA_def_cfa_expression"; |
| 13852 | case DW_CFA_expression: |
| 13853 | return "DW_CFA_expression"; |
| 13854 | case DW_CFA_offset_extended_sf: |
| 13855 | return "DW_CFA_offset_extended_sf"; |
| 13856 | case DW_CFA_def_cfa_sf: |
| 13857 | return "DW_CFA_def_cfa_sf"; |
| 13858 | case DW_CFA_def_cfa_offset_sf: |
| 13859 | return "DW_CFA_def_cfa_offset_sf"; |
| 13860 | case DW_CFA_val_offset: |
| 13861 | return "DW_CFA_val_offset"; |
| 13862 | case DW_CFA_val_offset_sf: |
| 13863 | return "DW_CFA_val_offset_sf"; |
| 13864 | case DW_CFA_val_expression: |
| 13865 | return "DW_CFA_val_expression"; |
| 13866 | /* SGI/MIPS specific. */ |
| 13867 | case DW_CFA_MIPS_advance_loc8: |
| 13868 | return "DW_CFA_MIPS_advance_loc8"; |
| 13869 | /* GNU extensions. */ |
| 13870 | case DW_CFA_GNU_window_save: |
| 13871 | return "DW_CFA_GNU_window_save"; |
| 13872 | case DW_CFA_GNU_args_size: |
| 13873 | return "DW_CFA_GNU_args_size"; |
| 13874 | case DW_CFA_GNU_negative_offset_extended: |
| 13875 | return "DW_CFA_GNU_negative_offset_extended"; |
| 13876 | default: |
| 13877 | return "DW_CFA_<unknown>"; |
| 13878 | } |
| 13879 | } |
| 13880 | #endif |
| 13881 | |
| 13882 | static void |
| 13883 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
| 13884 | { |
| 13885 | unsigned int i; |
| 13886 | |
| 13887 | print_spaces (indent, f); |
| 13888 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", |
| 13889 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
| 13890 | |
| 13891 | if (die->parent != NULL) |
| 13892 | { |
| 13893 | print_spaces (indent, f); |
| 13894 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", |
| 13895 | die->parent->offset); |
| 13896 | } |
| 13897 | |
| 13898 | print_spaces (indent, f); |
| 13899 | fprintf_unfiltered (f, " has children: %s\n", |
| 13900 | dwarf_bool_name (die->child != NULL)); |
| 13901 | |
| 13902 | print_spaces (indent, f); |
| 13903 | fprintf_unfiltered (f, " attributes:\n"); |
| 13904 | |
| 13905 | for (i = 0; i < die->num_attrs; ++i) |
| 13906 | { |
| 13907 | print_spaces (indent, f); |
| 13908 | fprintf_unfiltered (f, " %s (%s) ", |
| 13909 | dwarf_attr_name (die->attrs[i].name), |
| 13910 | dwarf_form_name (die->attrs[i].form)); |
| 13911 | |
| 13912 | switch (die->attrs[i].form) |
| 13913 | { |
| 13914 | case DW_FORM_ref_addr: |
| 13915 | case DW_FORM_addr: |
| 13916 | fprintf_unfiltered (f, "address: "); |
| 13917 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
| 13918 | break; |
| 13919 | case DW_FORM_block2: |
| 13920 | case DW_FORM_block4: |
| 13921 | case DW_FORM_block: |
| 13922 | case DW_FORM_block1: |
| 13923 | fprintf_unfiltered (f, "block: size %d", |
| 13924 | DW_BLOCK (&die->attrs[i])->size); |
| 13925 | break; |
| 13926 | case DW_FORM_exprloc: |
| 13927 | fprintf_unfiltered (f, "expression: size %u", |
| 13928 | DW_BLOCK (&die->attrs[i])->size); |
| 13929 | break; |
| 13930 | case DW_FORM_ref1: |
| 13931 | case DW_FORM_ref2: |
| 13932 | case DW_FORM_ref4: |
| 13933 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
| 13934 | (long) (DW_ADDR (&die->attrs[i]))); |
| 13935 | break; |
| 13936 | case DW_FORM_data1: |
| 13937 | case DW_FORM_data2: |
| 13938 | case DW_FORM_data4: |
| 13939 | case DW_FORM_data8: |
| 13940 | case DW_FORM_udata: |
| 13941 | case DW_FORM_sdata: |
| 13942 | fprintf_unfiltered (f, "constant: %s", |
| 13943 | pulongest (DW_UNSND (&die->attrs[i]))); |
| 13944 | break; |
| 13945 | case DW_FORM_sec_offset: |
| 13946 | fprintf_unfiltered (f, "section offset: %s", |
| 13947 | pulongest (DW_UNSND (&die->attrs[i]))); |
| 13948 | break; |
| 13949 | case DW_FORM_ref_sig8: |
| 13950 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
| 13951 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", |
| 13952 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset); |
| 13953 | else |
| 13954 | fprintf_unfiltered (f, "signatured type, offset: unknown"); |
| 13955 | break; |
| 13956 | case DW_FORM_string: |
| 13957 | case DW_FORM_strp: |
| 13958 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
| 13959 | DW_STRING (&die->attrs[i]) |
| 13960 | ? DW_STRING (&die->attrs[i]) : "", |
| 13961 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); |
| 13962 | break; |
| 13963 | case DW_FORM_flag: |
| 13964 | if (DW_UNSND (&die->attrs[i])) |
| 13965 | fprintf_unfiltered (f, "flag: TRUE"); |
| 13966 | else |
| 13967 | fprintf_unfiltered (f, "flag: FALSE"); |
| 13968 | break; |
| 13969 | case DW_FORM_flag_present: |
| 13970 | fprintf_unfiltered (f, "flag: TRUE"); |
| 13971 | break; |
| 13972 | case DW_FORM_indirect: |
| 13973 | /* The reader will have reduced the indirect form to |
| 13974 | the "base form" so this form should not occur. */ |
| 13975 | fprintf_unfiltered (f, |
| 13976 | "unexpected attribute form: DW_FORM_indirect"); |
| 13977 | break; |
| 13978 | default: |
| 13979 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
| 13980 | die->attrs[i].form); |
| 13981 | break; |
| 13982 | } |
| 13983 | fprintf_unfiltered (f, "\n"); |
| 13984 | } |
| 13985 | } |
| 13986 | |
| 13987 | static void |
| 13988 | dump_die_for_error (struct die_info *die) |
| 13989 | { |
| 13990 | dump_die_shallow (gdb_stderr, 0, die); |
| 13991 | } |
| 13992 | |
| 13993 | static void |
| 13994 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) |
| 13995 | { |
| 13996 | int indent = level * 4; |
| 13997 | |
| 13998 | gdb_assert (die != NULL); |
| 13999 | |
| 14000 | if (level >= max_level) |
| 14001 | return; |
| 14002 | |
| 14003 | dump_die_shallow (f, indent, die); |
| 14004 | |
| 14005 | if (die->child != NULL) |
| 14006 | { |
| 14007 | print_spaces (indent, f); |
| 14008 | fprintf_unfiltered (f, " Children:"); |
| 14009 | if (level + 1 < max_level) |
| 14010 | { |
| 14011 | fprintf_unfiltered (f, "\n"); |
| 14012 | dump_die_1 (f, level + 1, max_level, die->child); |
| 14013 | } |
| 14014 | else |
| 14015 | { |
| 14016 | fprintf_unfiltered (f, |
| 14017 | " [not printed, max nesting level reached]\n"); |
| 14018 | } |
| 14019 | } |
| 14020 | |
| 14021 | if (die->sibling != NULL && level > 0) |
| 14022 | { |
| 14023 | dump_die_1 (f, level, max_level, die->sibling); |
| 14024 | } |
| 14025 | } |
| 14026 | |
| 14027 | /* This is called from the pdie macro in gdbinit.in. |
| 14028 | It's not static so gcc will keep a copy callable from gdb. */ |
| 14029 | |
| 14030 | void |
| 14031 | dump_die (struct die_info *die, int max_level) |
| 14032 | { |
| 14033 | dump_die_1 (gdb_stdlog, 0, max_level, die); |
| 14034 | } |
| 14035 | |
| 14036 | static void |
| 14037 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
| 14038 | { |
| 14039 | void **slot; |
| 14040 | |
| 14041 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset, INSERT); |
| 14042 | |
| 14043 | *slot = die; |
| 14044 | } |
| 14045 | |
| 14046 | static int |
| 14047 | is_ref_attr (struct attribute *attr) |
| 14048 | { |
| 14049 | switch (attr->form) |
| 14050 | { |
| 14051 | case DW_FORM_ref_addr: |
| 14052 | case DW_FORM_ref1: |
| 14053 | case DW_FORM_ref2: |
| 14054 | case DW_FORM_ref4: |
| 14055 | case DW_FORM_ref8: |
| 14056 | case DW_FORM_ref_udata: |
| 14057 | return 1; |
| 14058 | default: |
| 14059 | return 0; |
| 14060 | } |
| 14061 | } |
| 14062 | |
| 14063 | static unsigned int |
| 14064 | dwarf2_get_ref_die_offset (struct attribute *attr) |
| 14065 | { |
| 14066 | if (is_ref_attr (attr)) |
| 14067 | return DW_ADDR (attr); |
| 14068 | |
| 14069 | complaint (&symfile_complaints, |
| 14070 | _("unsupported die ref attribute form: '%s'"), |
| 14071 | dwarf_form_name (attr->form)); |
| 14072 | return 0; |
| 14073 | } |
| 14074 | |
| 14075 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
| 14076 | * the value held by the attribute is not constant. */ |
| 14077 | |
| 14078 | static LONGEST |
| 14079 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
| 14080 | { |
| 14081 | if (attr->form == DW_FORM_sdata) |
| 14082 | return DW_SND (attr); |
| 14083 | else if (attr->form == DW_FORM_udata |
| 14084 | || attr->form == DW_FORM_data1 |
| 14085 | || attr->form == DW_FORM_data2 |
| 14086 | || attr->form == DW_FORM_data4 |
| 14087 | || attr->form == DW_FORM_data8) |
| 14088 | return DW_UNSND (attr); |
| 14089 | else |
| 14090 | { |
| 14091 | complaint (&symfile_complaints, |
| 14092 | _("Attribute value is not a constant (%s)"), |
| 14093 | dwarf_form_name (attr->form)); |
| 14094 | return default_value; |
| 14095 | } |
| 14096 | } |
| 14097 | |
| 14098 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
| 14099 | unit and add it to our queue. |
| 14100 | The result is non-zero if PER_CU was queued, otherwise the result is zero |
| 14101 | meaning either PER_CU is already queued or it is already loaded. */ |
| 14102 | |
| 14103 | static int |
| 14104 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
| 14105 | struct dwarf2_per_cu_data *per_cu) |
| 14106 | { |
| 14107 | /* We may arrive here during partial symbol reading, if we need full |
| 14108 | DIEs to process an unusual case (e.g. template arguments). Do |
| 14109 | not queue PER_CU, just tell our caller to load its DIEs. */ |
| 14110 | if (dwarf2_per_objfile->reading_partial_symbols) |
| 14111 | { |
| 14112 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) |
| 14113 | return 1; |
| 14114 | return 0; |
| 14115 | } |
| 14116 | |
| 14117 | /* Mark the dependence relation so that we don't flush PER_CU |
| 14118 | too early. */ |
| 14119 | dwarf2_add_dependence (this_cu, per_cu); |
| 14120 | |
| 14121 | /* If it's already on the queue, we have nothing to do. */ |
| 14122 | if (per_cu->queued) |
| 14123 | return 0; |
| 14124 | |
| 14125 | /* If the compilation unit is already loaded, just mark it as |
| 14126 | used. */ |
| 14127 | if (per_cu->cu != NULL) |
| 14128 | { |
| 14129 | per_cu->cu->last_used = 0; |
| 14130 | return 0; |
| 14131 | } |
| 14132 | |
| 14133 | /* Add it to the queue. */ |
| 14134 | queue_comp_unit (per_cu); |
| 14135 | |
| 14136 | return 1; |
| 14137 | } |
| 14138 | |
| 14139 | /* Follow reference or signature attribute ATTR of SRC_DIE. |
| 14140 | On entry *REF_CU is the CU of SRC_DIE. |
| 14141 | On exit *REF_CU is the CU of the result. */ |
| 14142 | |
| 14143 | static struct die_info * |
| 14144 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, |
| 14145 | struct dwarf2_cu **ref_cu) |
| 14146 | { |
| 14147 | struct die_info *die; |
| 14148 | |
| 14149 | if (is_ref_attr (attr)) |
| 14150 | die = follow_die_ref (src_die, attr, ref_cu); |
| 14151 | else if (attr->form == DW_FORM_ref_sig8) |
| 14152 | die = follow_die_sig (src_die, attr, ref_cu); |
| 14153 | else |
| 14154 | { |
| 14155 | dump_die_for_error (src_die); |
| 14156 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), |
| 14157 | (*ref_cu)->objfile->name); |
| 14158 | } |
| 14159 | |
| 14160 | return die; |
| 14161 | } |
| 14162 | |
| 14163 | /* Follow reference OFFSET. |
| 14164 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
| 14165 | On exit *REF_CU is the CU of the result. |
| 14166 | Returns NULL if OFFSET is invalid. */ |
| 14167 | |
| 14168 | static struct die_info * |
| 14169 | follow_die_offset (unsigned int offset, struct dwarf2_cu **ref_cu) |
| 14170 | { |
| 14171 | struct die_info temp_die; |
| 14172 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
| 14173 | |
| 14174 | gdb_assert (cu->per_cu != NULL); |
| 14175 | |
| 14176 | target_cu = cu; |
| 14177 | |
| 14178 | if (cu->per_cu->debug_types_section) |
| 14179 | { |
| 14180 | /* .debug_types CUs cannot reference anything outside their CU. |
| 14181 | If they need to, they have to reference a signatured type via |
| 14182 | DW_FORM_ref_sig8. */ |
| 14183 | if (! offset_in_cu_p (&cu->header, offset)) |
| 14184 | return NULL; |
| 14185 | } |
| 14186 | else if (! offset_in_cu_p (&cu->header, offset)) |
| 14187 | { |
| 14188 | struct dwarf2_per_cu_data *per_cu; |
| 14189 | |
| 14190 | per_cu = dwarf2_find_containing_comp_unit (offset, cu->objfile); |
| 14191 | |
| 14192 | /* If necessary, add it to the queue and load its DIEs. */ |
| 14193 | if (maybe_queue_comp_unit (cu, per_cu)) |
| 14194 | load_full_comp_unit (per_cu); |
| 14195 | |
| 14196 | target_cu = per_cu->cu; |
| 14197 | } |
| 14198 | else if (cu->dies == NULL) |
| 14199 | { |
| 14200 | /* We're loading full DIEs during partial symbol reading. */ |
| 14201 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); |
| 14202 | load_full_comp_unit (cu->per_cu); |
| 14203 | } |
| 14204 | |
| 14205 | *ref_cu = target_cu; |
| 14206 | temp_die.offset = offset; |
| 14207 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset); |
| 14208 | } |
| 14209 | |
| 14210 | /* Follow reference attribute ATTR of SRC_DIE. |
| 14211 | On entry *REF_CU is the CU of SRC_DIE. |
| 14212 | On exit *REF_CU is the CU of the result. */ |
| 14213 | |
| 14214 | static struct die_info * |
| 14215 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
| 14216 | struct dwarf2_cu **ref_cu) |
| 14217 | { |
| 14218 | unsigned int offset = dwarf2_get_ref_die_offset (attr); |
| 14219 | struct dwarf2_cu *cu = *ref_cu; |
| 14220 | struct die_info *die; |
| 14221 | |
| 14222 | die = follow_die_offset (offset, ref_cu); |
| 14223 | if (!die) |
| 14224 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " |
| 14225 | "at 0x%x [in module %s]"), |
| 14226 | offset, src_die->offset, cu->objfile->name); |
| 14227 | |
| 14228 | return die; |
| 14229 | } |
| 14230 | |
| 14231 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
| 14232 | Returned value is intended for DW_OP_call*. Returned |
| 14233 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ |
| 14234 | |
| 14235 | struct dwarf2_locexpr_baton |
| 14236 | dwarf2_fetch_die_location_block (unsigned int offset, |
| 14237 | struct dwarf2_per_cu_data *per_cu, |
| 14238 | CORE_ADDR (*get_frame_pc) (void *baton), |
| 14239 | void *baton) |
| 14240 | { |
| 14241 | struct dwarf2_cu *cu; |
| 14242 | struct die_info *die; |
| 14243 | struct attribute *attr; |
| 14244 | struct dwarf2_locexpr_baton retval; |
| 14245 | |
| 14246 | dw2_setup (per_cu->objfile); |
| 14247 | |
| 14248 | if (per_cu->cu == NULL) |
| 14249 | load_cu (per_cu); |
| 14250 | cu = per_cu->cu; |
| 14251 | |
| 14252 | die = follow_die_offset (offset, &cu); |
| 14253 | if (!die) |
| 14254 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), |
| 14255 | offset, per_cu->objfile->name); |
| 14256 | |
| 14257 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 14258 | if (!attr) |
| 14259 | { |
| 14260 | /* DWARF: "If there is no such attribute, then there is no effect.". |
| 14261 | DATA is ignored if SIZE is 0. */ |
| 14262 | |
| 14263 | retval.data = NULL; |
| 14264 | retval.size = 0; |
| 14265 | } |
| 14266 | else if (attr_form_is_section_offset (attr)) |
| 14267 | { |
| 14268 | struct dwarf2_loclist_baton loclist_baton; |
| 14269 | CORE_ADDR pc = (*get_frame_pc) (baton); |
| 14270 | size_t size; |
| 14271 | |
| 14272 | fill_in_loclist_baton (cu, &loclist_baton, attr); |
| 14273 | |
| 14274 | retval.data = dwarf2_find_location_expression (&loclist_baton, |
| 14275 | &size, pc); |
| 14276 | retval.size = size; |
| 14277 | } |
| 14278 | else |
| 14279 | { |
| 14280 | if (!attr_form_is_block (attr)) |
| 14281 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " |
| 14282 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), |
| 14283 | offset, per_cu->objfile->name); |
| 14284 | |
| 14285 | retval.data = DW_BLOCK (attr)->data; |
| 14286 | retval.size = DW_BLOCK (attr)->size; |
| 14287 | } |
| 14288 | retval.per_cu = cu->per_cu; |
| 14289 | |
| 14290 | age_cached_comp_units (); |
| 14291 | |
| 14292 | return retval; |
| 14293 | } |
| 14294 | |
| 14295 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
| 14296 | PER_CU. */ |
| 14297 | |
| 14298 | struct type * |
| 14299 | dwarf2_get_die_type (unsigned int die_offset, |
| 14300 | struct dwarf2_per_cu_data *per_cu) |
| 14301 | { |
| 14302 | dw2_setup (per_cu->objfile); |
| 14303 | return get_die_type_at_offset (die_offset, per_cu); |
| 14304 | } |
| 14305 | |
| 14306 | /* Follow the signature attribute ATTR in SRC_DIE. |
| 14307 | On entry *REF_CU is the CU of SRC_DIE. |
| 14308 | On exit *REF_CU is the CU of the result. */ |
| 14309 | |
| 14310 | static struct die_info * |
| 14311 | follow_die_sig (struct die_info *src_die, struct attribute *attr, |
| 14312 | struct dwarf2_cu **ref_cu) |
| 14313 | { |
| 14314 | struct objfile *objfile = (*ref_cu)->objfile; |
| 14315 | struct die_info temp_die; |
| 14316 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); |
| 14317 | struct dwarf2_cu *sig_cu; |
| 14318 | struct die_info *die; |
| 14319 | |
| 14320 | /* sig_type will be NULL if the signatured type is missing from |
| 14321 | the debug info. */ |
| 14322 | if (sig_type == NULL) |
| 14323 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " |
| 14324 | "at 0x%x [in module %s]"), |
| 14325 | src_die->offset, objfile->name); |
| 14326 | |
| 14327 | /* If necessary, add it to the queue and load its DIEs. */ |
| 14328 | |
| 14329 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu)) |
| 14330 | read_signatured_type (sig_type); |
| 14331 | |
| 14332 | gdb_assert (sig_type->per_cu.cu != NULL); |
| 14333 | |
| 14334 | sig_cu = sig_type->per_cu.cu; |
| 14335 | temp_die.offset = sig_cu->header.offset + sig_type->type_offset; |
| 14336 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, temp_die.offset); |
| 14337 | if (die) |
| 14338 | { |
| 14339 | *ref_cu = sig_cu; |
| 14340 | return die; |
| 14341 | } |
| 14342 | |
| 14343 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
| 14344 | "from DIE at 0x%x [in module %s]"), |
| 14345 | sig_type->type_offset, src_die->offset, objfile->name); |
| 14346 | } |
| 14347 | |
| 14348 | /* Given an offset of a signatured type, return its signatured_type. */ |
| 14349 | |
| 14350 | static struct signatured_type * |
| 14351 | lookup_signatured_type_at_offset (struct objfile *objfile, |
| 14352 | struct dwarf2_section_info *section, |
| 14353 | unsigned int offset) |
| 14354 | { |
| 14355 | gdb_byte *info_ptr = section->buffer + offset; |
| 14356 | unsigned int length, initial_length_size; |
| 14357 | unsigned int sig_offset; |
| 14358 | struct signatured_type find_entry, *type_sig; |
| 14359 | |
| 14360 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); |
| 14361 | sig_offset = (initial_length_size |
| 14362 | + 2 /*version*/ |
| 14363 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ |
| 14364 | + 1 /*address_size*/); |
| 14365 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); |
| 14366 | type_sig = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
| 14367 | |
| 14368 | /* This is only used to lookup previously recorded types. |
| 14369 | If we didn't find it, it's our bug. */ |
| 14370 | gdb_assert (type_sig != NULL); |
| 14371 | gdb_assert (offset == type_sig->per_cu.offset); |
| 14372 | |
| 14373 | return type_sig; |
| 14374 | } |
| 14375 | |
| 14376 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
| 14377 | |
| 14378 | static void |
| 14379 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
| 14380 | { |
| 14381 | struct objfile *objfile = per_cu->objfile; |
| 14382 | struct dwarf2_section_info *sect = per_cu->debug_types_section; |
| 14383 | unsigned int offset = per_cu->offset; |
| 14384 | struct signatured_type *type_sig; |
| 14385 | |
| 14386 | dwarf2_read_section (objfile, sect); |
| 14387 | |
| 14388 | /* We have the section offset, but we need the signature to do the |
| 14389 | hash table lookup. */ |
| 14390 | /* FIXME: This is sorta unnecessary, read_signatured_type only uses |
| 14391 | the signature to assert we found the right one. |
| 14392 | Ok, but it's a lot of work. We should simplify things so any needed |
| 14393 | assert doesn't require all this clumsiness. */ |
| 14394 | type_sig = lookup_signatured_type_at_offset (objfile, sect, offset); |
| 14395 | |
| 14396 | gdb_assert (type_sig->per_cu.cu == NULL); |
| 14397 | |
| 14398 | read_signatured_type (type_sig); |
| 14399 | |
| 14400 | gdb_assert (type_sig->per_cu.cu != NULL); |
| 14401 | } |
| 14402 | |
| 14403 | /* Read in a signatured type and build its CU and DIEs. */ |
| 14404 | |
| 14405 | static void |
| 14406 | read_signatured_type (struct signatured_type *type_sig) |
| 14407 | { |
| 14408 | struct objfile *objfile = type_sig->per_cu.objfile; |
| 14409 | gdb_byte *types_ptr; |
| 14410 | struct die_reader_specs reader_specs; |
| 14411 | struct dwarf2_cu *cu; |
| 14412 | ULONGEST signature; |
| 14413 | struct cleanup *back_to, *free_cu_cleanup; |
| 14414 | struct dwarf2_section_info *section = type_sig->per_cu.debug_types_section; |
| 14415 | |
| 14416 | dwarf2_read_section (objfile, section); |
| 14417 | types_ptr = section->buffer + type_sig->per_cu.offset; |
| 14418 | |
| 14419 | gdb_assert (type_sig->per_cu.cu == NULL); |
| 14420 | |
| 14421 | cu = xmalloc (sizeof (*cu)); |
| 14422 | init_one_comp_unit (cu, &type_sig->per_cu); |
| 14423 | |
| 14424 | /* If an error occurs while loading, release our storage. */ |
| 14425 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
| 14426 | |
| 14427 | types_ptr = read_and_check_type_unit_head (&cu->header, section, types_ptr, |
| 14428 | &signature, NULL); |
| 14429 | gdb_assert (signature == type_sig->signature); |
| 14430 | |
| 14431 | cu->die_hash |
| 14432 | = htab_create_alloc_ex (cu->header.length / 12, |
| 14433 | die_hash, |
| 14434 | die_eq, |
| 14435 | NULL, |
| 14436 | &cu->comp_unit_obstack, |
| 14437 | hashtab_obstack_allocate, |
| 14438 | dummy_obstack_deallocate); |
| 14439 | |
| 14440 | dwarf2_read_abbrevs (cu); |
| 14441 | back_to = make_cleanup (dwarf2_free_abbrev_table, cu); |
| 14442 | |
| 14443 | init_cu_die_reader (&reader_specs, cu); |
| 14444 | |
| 14445 | cu->dies = read_die_and_children (&reader_specs, types_ptr, &types_ptr, |
| 14446 | NULL /*parent*/); |
| 14447 | |
| 14448 | /* We try not to read any attributes in this function, because not |
| 14449 | all CUs needed for references have been loaded yet, and symbol |
| 14450 | table processing isn't initialized. But we have to set the CU language, |
| 14451 | or we won't be able to build types correctly. */ |
| 14452 | prepare_one_comp_unit (cu, cu->dies); |
| 14453 | |
| 14454 | do_cleanups (back_to); |
| 14455 | |
| 14456 | /* We've successfully allocated this compilation unit. Let our caller |
| 14457 | clean it up when finished with it. */ |
| 14458 | discard_cleanups (free_cu_cleanup); |
| 14459 | |
| 14460 | type_sig->per_cu.cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 14461 | dwarf2_per_objfile->read_in_chain = &type_sig->per_cu; |
| 14462 | } |
| 14463 | |
| 14464 | /* Decode simple location descriptions. |
| 14465 | Given a pointer to a dwarf block that defines a location, compute |
| 14466 | the location and return the value. |
| 14467 | |
| 14468 | NOTE drow/2003-11-18: This function is called in two situations |
| 14469 | now: for the address of static or global variables (partial symbols |
| 14470 | only) and for offsets into structures which are expected to be |
| 14471 | (more or less) constant. The partial symbol case should go away, |
| 14472 | and only the constant case should remain. That will let this |
| 14473 | function complain more accurately. A few special modes are allowed |
| 14474 | without complaint for global variables (for instance, global |
| 14475 | register values and thread-local values). |
| 14476 | |
| 14477 | A location description containing no operations indicates that the |
| 14478 | object is optimized out. The return value is 0 for that case. |
| 14479 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
| 14480 | callers will only want a very basic result and this can become a |
| 14481 | complaint. |
| 14482 | |
| 14483 | Note that stack[0] is unused except as a default error return. */ |
| 14484 | |
| 14485 | static CORE_ADDR |
| 14486 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
| 14487 | { |
| 14488 | struct objfile *objfile = cu->objfile; |
| 14489 | int i; |
| 14490 | int size = blk->size; |
| 14491 | gdb_byte *data = blk->data; |
| 14492 | CORE_ADDR stack[64]; |
| 14493 | int stacki; |
| 14494 | unsigned int bytes_read, unsnd; |
| 14495 | gdb_byte op; |
| 14496 | |
| 14497 | i = 0; |
| 14498 | stacki = 0; |
| 14499 | stack[stacki] = 0; |
| 14500 | stack[++stacki] = 0; |
| 14501 | |
| 14502 | while (i < size) |
| 14503 | { |
| 14504 | op = data[i++]; |
| 14505 | switch (op) |
| 14506 | { |
| 14507 | case DW_OP_lit0: |
| 14508 | case DW_OP_lit1: |
| 14509 | case DW_OP_lit2: |
| 14510 | case DW_OP_lit3: |
| 14511 | case DW_OP_lit4: |
| 14512 | case DW_OP_lit5: |
| 14513 | case DW_OP_lit6: |
| 14514 | case DW_OP_lit7: |
| 14515 | case DW_OP_lit8: |
| 14516 | case DW_OP_lit9: |
| 14517 | case DW_OP_lit10: |
| 14518 | case DW_OP_lit11: |
| 14519 | case DW_OP_lit12: |
| 14520 | case DW_OP_lit13: |
| 14521 | case DW_OP_lit14: |
| 14522 | case DW_OP_lit15: |
| 14523 | case DW_OP_lit16: |
| 14524 | case DW_OP_lit17: |
| 14525 | case DW_OP_lit18: |
| 14526 | case DW_OP_lit19: |
| 14527 | case DW_OP_lit20: |
| 14528 | case DW_OP_lit21: |
| 14529 | case DW_OP_lit22: |
| 14530 | case DW_OP_lit23: |
| 14531 | case DW_OP_lit24: |
| 14532 | case DW_OP_lit25: |
| 14533 | case DW_OP_lit26: |
| 14534 | case DW_OP_lit27: |
| 14535 | case DW_OP_lit28: |
| 14536 | case DW_OP_lit29: |
| 14537 | case DW_OP_lit30: |
| 14538 | case DW_OP_lit31: |
| 14539 | stack[++stacki] = op - DW_OP_lit0; |
| 14540 | break; |
| 14541 | |
| 14542 | case DW_OP_reg0: |
| 14543 | case DW_OP_reg1: |
| 14544 | case DW_OP_reg2: |
| 14545 | case DW_OP_reg3: |
| 14546 | case DW_OP_reg4: |
| 14547 | case DW_OP_reg5: |
| 14548 | case DW_OP_reg6: |
| 14549 | case DW_OP_reg7: |
| 14550 | case DW_OP_reg8: |
| 14551 | case DW_OP_reg9: |
| 14552 | case DW_OP_reg10: |
| 14553 | case DW_OP_reg11: |
| 14554 | case DW_OP_reg12: |
| 14555 | case DW_OP_reg13: |
| 14556 | case DW_OP_reg14: |
| 14557 | case DW_OP_reg15: |
| 14558 | case DW_OP_reg16: |
| 14559 | case DW_OP_reg17: |
| 14560 | case DW_OP_reg18: |
| 14561 | case DW_OP_reg19: |
| 14562 | case DW_OP_reg20: |
| 14563 | case DW_OP_reg21: |
| 14564 | case DW_OP_reg22: |
| 14565 | case DW_OP_reg23: |
| 14566 | case DW_OP_reg24: |
| 14567 | case DW_OP_reg25: |
| 14568 | case DW_OP_reg26: |
| 14569 | case DW_OP_reg27: |
| 14570 | case DW_OP_reg28: |
| 14571 | case DW_OP_reg29: |
| 14572 | case DW_OP_reg30: |
| 14573 | case DW_OP_reg31: |
| 14574 | stack[++stacki] = op - DW_OP_reg0; |
| 14575 | if (i < size) |
| 14576 | dwarf2_complex_location_expr_complaint (); |
| 14577 | break; |
| 14578 | |
| 14579 | case DW_OP_regx: |
| 14580 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
| 14581 | i += bytes_read; |
| 14582 | stack[++stacki] = unsnd; |
| 14583 | if (i < size) |
| 14584 | dwarf2_complex_location_expr_complaint (); |
| 14585 | break; |
| 14586 | |
| 14587 | case DW_OP_addr: |
| 14588 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
| 14589 | cu, &bytes_read); |
| 14590 | i += bytes_read; |
| 14591 | break; |
| 14592 | |
| 14593 | case DW_OP_const1u: |
| 14594 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); |
| 14595 | i += 1; |
| 14596 | break; |
| 14597 | |
| 14598 | case DW_OP_const1s: |
| 14599 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); |
| 14600 | i += 1; |
| 14601 | break; |
| 14602 | |
| 14603 | case DW_OP_const2u: |
| 14604 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); |
| 14605 | i += 2; |
| 14606 | break; |
| 14607 | |
| 14608 | case DW_OP_const2s: |
| 14609 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); |
| 14610 | i += 2; |
| 14611 | break; |
| 14612 | |
| 14613 | case DW_OP_const4u: |
| 14614 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); |
| 14615 | i += 4; |
| 14616 | break; |
| 14617 | |
| 14618 | case DW_OP_const4s: |
| 14619 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); |
| 14620 | i += 4; |
| 14621 | break; |
| 14622 | |
| 14623 | case DW_OP_const8u: |
| 14624 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); |
| 14625 | i += 8; |
| 14626 | break; |
| 14627 | |
| 14628 | case DW_OP_constu: |
| 14629 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), |
| 14630 | &bytes_read); |
| 14631 | i += bytes_read; |
| 14632 | break; |
| 14633 | |
| 14634 | case DW_OP_consts: |
| 14635 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 14636 | i += bytes_read; |
| 14637 | break; |
| 14638 | |
| 14639 | case DW_OP_dup: |
| 14640 | stack[stacki + 1] = stack[stacki]; |
| 14641 | stacki++; |
| 14642 | break; |
| 14643 | |
| 14644 | case DW_OP_plus: |
| 14645 | stack[stacki - 1] += stack[stacki]; |
| 14646 | stacki--; |
| 14647 | break; |
| 14648 | |
| 14649 | case DW_OP_plus_uconst: |
| 14650 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), |
| 14651 | &bytes_read); |
| 14652 | i += bytes_read; |
| 14653 | break; |
| 14654 | |
| 14655 | case DW_OP_minus: |
| 14656 | stack[stacki - 1] -= stack[stacki]; |
| 14657 | stacki--; |
| 14658 | break; |
| 14659 | |
| 14660 | case DW_OP_deref: |
| 14661 | /* If we're not the last op, then we definitely can't encode |
| 14662 | this using GDB's address_class enum. This is valid for partial |
| 14663 | global symbols, although the variable's address will be bogus |
| 14664 | in the psymtab. */ |
| 14665 | if (i < size) |
| 14666 | dwarf2_complex_location_expr_complaint (); |
| 14667 | break; |
| 14668 | |
| 14669 | case DW_OP_GNU_push_tls_address: |
| 14670 | /* The top of the stack has the offset from the beginning |
| 14671 | of the thread control block at which the variable is located. */ |
| 14672 | /* Nothing should follow this operator, so the top of stack would |
| 14673 | be returned. */ |
| 14674 | /* This is valid for partial global symbols, but the variable's |
| 14675 | address will be bogus in the psymtab. Make it always at least |
| 14676 | non-zero to not look as a variable garbage collected by linker |
| 14677 | which have DW_OP_addr 0. */ |
| 14678 | if (i < size) |
| 14679 | dwarf2_complex_location_expr_complaint (); |
| 14680 | stack[stacki]++; |
| 14681 | break; |
| 14682 | |
| 14683 | case DW_OP_GNU_uninit: |
| 14684 | break; |
| 14685 | |
| 14686 | default: |
| 14687 | { |
| 14688 | const char *name = dwarf_stack_op_name (op); |
| 14689 | |
| 14690 | if (name) |
| 14691 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
| 14692 | name); |
| 14693 | else |
| 14694 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), |
| 14695 | op); |
| 14696 | } |
| 14697 | |
| 14698 | return (stack[stacki]); |
| 14699 | } |
| 14700 | |
| 14701 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
| 14702 | outside of the allocated space. Also enforce minimum>0. */ |
| 14703 | if (stacki >= ARRAY_SIZE (stack) - 1) |
| 14704 | { |
| 14705 | complaint (&symfile_complaints, |
| 14706 | _("location description stack overflow")); |
| 14707 | return 0; |
| 14708 | } |
| 14709 | |
| 14710 | if (stacki <= 0) |
| 14711 | { |
| 14712 | complaint (&symfile_complaints, |
| 14713 | _("location description stack underflow")); |
| 14714 | return 0; |
| 14715 | } |
| 14716 | } |
| 14717 | return (stack[stacki]); |
| 14718 | } |
| 14719 | |
| 14720 | /* memory allocation interface */ |
| 14721 | |
| 14722 | static struct dwarf_block * |
| 14723 | dwarf_alloc_block (struct dwarf2_cu *cu) |
| 14724 | { |
| 14725 | struct dwarf_block *blk; |
| 14726 | |
| 14727 | blk = (struct dwarf_block *) |
| 14728 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
| 14729 | return (blk); |
| 14730 | } |
| 14731 | |
| 14732 | static struct abbrev_info * |
| 14733 | dwarf_alloc_abbrev (struct dwarf2_cu *cu) |
| 14734 | { |
| 14735 | struct abbrev_info *abbrev; |
| 14736 | |
| 14737 | abbrev = (struct abbrev_info *) |
| 14738 | obstack_alloc (&cu->abbrev_obstack, sizeof (struct abbrev_info)); |
| 14739 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
| 14740 | return (abbrev); |
| 14741 | } |
| 14742 | |
| 14743 | static struct die_info * |
| 14744 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
| 14745 | { |
| 14746 | struct die_info *die; |
| 14747 | size_t size = sizeof (struct die_info); |
| 14748 | |
| 14749 | if (num_attrs > 1) |
| 14750 | size += (num_attrs - 1) * sizeof (struct attribute); |
| 14751 | |
| 14752 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
| 14753 | memset (die, 0, sizeof (struct die_info)); |
| 14754 | return (die); |
| 14755 | } |
| 14756 | |
| 14757 | \f |
| 14758 | /* Macro support. */ |
| 14759 | |
| 14760 | /* Return the full name of file number I in *LH's file name table. |
| 14761 | Use COMP_DIR as the name of the current directory of the |
| 14762 | compilation. The result is allocated using xmalloc; the caller is |
| 14763 | responsible for freeing it. */ |
| 14764 | static char * |
| 14765 | file_full_name (int file, struct line_header *lh, const char *comp_dir) |
| 14766 | { |
| 14767 | /* Is the file number a valid index into the line header's file name |
| 14768 | table? Remember that file numbers start with one, not zero. */ |
| 14769 | if (1 <= file && file <= lh->num_file_names) |
| 14770 | { |
| 14771 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 14772 | |
| 14773 | if (IS_ABSOLUTE_PATH (fe->name)) |
| 14774 | return xstrdup (fe->name); |
| 14775 | else |
| 14776 | { |
| 14777 | const char *dir; |
| 14778 | int dir_len; |
| 14779 | char *full_name; |
| 14780 | |
| 14781 | if (fe->dir_index) |
| 14782 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 14783 | else |
| 14784 | dir = comp_dir; |
| 14785 | |
| 14786 | if (dir) |
| 14787 | { |
| 14788 | dir_len = strlen (dir); |
| 14789 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); |
| 14790 | strcpy (full_name, dir); |
| 14791 | full_name[dir_len] = '/'; |
| 14792 | strcpy (full_name + dir_len + 1, fe->name); |
| 14793 | return full_name; |
| 14794 | } |
| 14795 | else |
| 14796 | return xstrdup (fe->name); |
| 14797 | } |
| 14798 | } |
| 14799 | else |
| 14800 | { |
| 14801 | /* The compiler produced a bogus file number. We can at least |
| 14802 | record the macro definitions made in the file, even if we |
| 14803 | won't be able to find the file by name. */ |
| 14804 | char fake_name[80]; |
| 14805 | |
| 14806 | sprintf (fake_name, "<bad macro file number %d>", file); |
| 14807 | |
| 14808 | complaint (&symfile_complaints, |
| 14809 | _("bad file number in macro information (%d)"), |
| 14810 | file); |
| 14811 | |
| 14812 | return xstrdup (fake_name); |
| 14813 | } |
| 14814 | } |
| 14815 | |
| 14816 | |
| 14817 | static struct macro_source_file * |
| 14818 | macro_start_file (int file, int line, |
| 14819 | struct macro_source_file *current_file, |
| 14820 | const char *comp_dir, |
| 14821 | struct line_header *lh, struct objfile *objfile) |
| 14822 | { |
| 14823 | /* The full name of this source file. */ |
| 14824 | char *full_name = file_full_name (file, lh, comp_dir); |
| 14825 | |
| 14826 | /* We don't create a macro table for this compilation unit |
| 14827 | at all until we actually get a filename. */ |
| 14828 | if (! pending_macros) |
| 14829 | pending_macros = new_macro_table (&objfile->objfile_obstack, |
| 14830 | objfile->macro_cache); |
| 14831 | |
| 14832 | if (! current_file) |
| 14833 | /* If we have no current file, then this must be the start_file |
| 14834 | directive for the compilation unit's main source file. */ |
| 14835 | current_file = macro_set_main (pending_macros, full_name); |
| 14836 | else |
| 14837 | current_file = macro_include (current_file, line, full_name); |
| 14838 | |
| 14839 | xfree (full_name); |
| 14840 | |
| 14841 | return current_file; |
| 14842 | } |
| 14843 | |
| 14844 | |
| 14845 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, |
| 14846 | followed by a null byte. */ |
| 14847 | static char * |
| 14848 | copy_string (const char *buf, int len) |
| 14849 | { |
| 14850 | char *s = xmalloc (len + 1); |
| 14851 | |
| 14852 | memcpy (s, buf, len); |
| 14853 | s[len] = '\0'; |
| 14854 | return s; |
| 14855 | } |
| 14856 | |
| 14857 | |
| 14858 | static const char * |
| 14859 | consume_improper_spaces (const char *p, const char *body) |
| 14860 | { |
| 14861 | if (*p == ' ') |
| 14862 | { |
| 14863 | complaint (&symfile_complaints, |
| 14864 | _("macro definition contains spaces " |
| 14865 | "in formal argument list:\n`%s'"), |
| 14866 | body); |
| 14867 | |
| 14868 | while (*p == ' ') |
| 14869 | p++; |
| 14870 | } |
| 14871 | |
| 14872 | return p; |
| 14873 | } |
| 14874 | |
| 14875 | |
| 14876 | static void |
| 14877 | parse_macro_definition (struct macro_source_file *file, int line, |
| 14878 | const char *body) |
| 14879 | { |
| 14880 | const char *p; |
| 14881 | |
| 14882 | /* The body string takes one of two forms. For object-like macro |
| 14883 | definitions, it should be: |
| 14884 | |
| 14885 | <macro name> " " <definition> |
| 14886 | |
| 14887 | For function-like macro definitions, it should be: |
| 14888 | |
| 14889 | <macro name> "() " <definition> |
| 14890 | or |
| 14891 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> |
| 14892 | |
| 14893 | Spaces may appear only where explicitly indicated, and in the |
| 14894 | <definition>. |
| 14895 | |
| 14896 | The Dwarf 2 spec says that an object-like macro's name is always |
| 14897 | followed by a space, but versions of GCC around March 2002 omit |
| 14898 | the space when the macro's definition is the empty string. |
| 14899 | |
| 14900 | The Dwarf 2 spec says that there should be no spaces between the |
| 14901 | formal arguments in a function-like macro's formal argument list, |
| 14902 | but versions of GCC around March 2002 include spaces after the |
| 14903 | commas. */ |
| 14904 | |
| 14905 | |
| 14906 | /* Find the extent of the macro name. The macro name is terminated |
| 14907 | by either a space or null character (for an object-like macro) or |
| 14908 | an opening paren (for a function-like macro). */ |
| 14909 | for (p = body; *p; p++) |
| 14910 | if (*p == ' ' || *p == '(') |
| 14911 | break; |
| 14912 | |
| 14913 | if (*p == ' ' || *p == '\0') |
| 14914 | { |
| 14915 | /* It's an object-like macro. */ |
| 14916 | int name_len = p - body; |
| 14917 | char *name = copy_string (body, name_len); |
| 14918 | const char *replacement; |
| 14919 | |
| 14920 | if (*p == ' ') |
| 14921 | replacement = body + name_len + 1; |
| 14922 | else |
| 14923 | { |
| 14924 | dwarf2_macro_malformed_definition_complaint (body); |
| 14925 | replacement = body + name_len; |
| 14926 | } |
| 14927 | |
| 14928 | macro_define_object (file, line, name, replacement); |
| 14929 | |
| 14930 | xfree (name); |
| 14931 | } |
| 14932 | else if (*p == '(') |
| 14933 | { |
| 14934 | /* It's a function-like macro. */ |
| 14935 | char *name = copy_string (body, p - body); |
| 14936 | int argc = 0; |
| 14937 | int argv_size = 1; |
| 14938 | char **argv = xmalloc (argv_size * sizeof (*argv)); |
| 14939 | |
| 14940 | p++; |
| 14941 | |
| 14942 | p = consume_improper_spaces (p, body); |
| 14943 | |
| 14944 | /* Parse the formal argument list. */ |
| 14945 | while (*p && *p != ')') |
| 14946 | { |
| 14947 | /* Find the extent of the current argument name. */ |
| 14948 | const char *arg_start = p; |
| 14949 | |
| 14950 | while (*p && *p != ',' && *p != ')' && *p != ' ') |
| 14951 | p++; |
| 14952 | |
| 14953 | if (! *p || p == arg_start) |
| 14954 | dwarf2_macro_malformed_definition_complaint (body); |
| 14955 | else |
| 14956 | { |
| 14957 | /* Make sure argv has room for the new argument. */ |
| 14958 | if (argc >= argv_size) |
| 14959 | { |
| 14960 | argv_size *= 2; |
| 14961 | argv = xrealloc (argv, argv_size * sizeof (*argv)); |
| 14962 | } |
| 14963 | |
| 14964 | argv[argc++] = copy_string (arg_start, p - arg_start); |
| 14965 | } |
| 14966 | |
| 14967 | p = consume_improper_spaces (p, body); |
| 14968 | |
| 14969 | /* Consume the comma, if present. */ |
| 14970 | if (*p == ',') |
| 14971 | { |
| 14972 | p++; |
| 14973 | |
| 14974 | p = consume_improper_spaces (p, body); |
| 14975 | } |
| 14976 | } |
| 14977 | |
| 14978 | if (*p == ')') |
| 14979 | { |
| 14980 | p++; |
| 14981 | |
| 14982 | if (*p == ' ') |
| 14983 | /* Perfectly formed definition, no complaints. */ |
| 14984 | macro_define_function (file, line, name, |
| 14985 | argc, (const char **) argv, |
| 14986 | p + 1); |
| 14987 | else if (*p == '\0') |
| 14988 | { |
| 14989 | /* Complain, but do define it. */ |
| 14990 | dwarf2_macro_malformed_definition_complaint (body); |
| 14991 | macro_define_function (file, line, name, |
| 14992 | argc, (const char **) argv, |
| 14993 | p); |
| 14994 | } |
| 14995 | else |
| 14996 | /* Just complain. */ |
| 14997 | dwarf2_macro_malformed_definition_complaint (body); |
| 14998 | } |
| 14999 | else |
| 15000 | /* Just complain. */ |
| 15001 | dwarf2_macro_malformed_definition_complaint (body); |
| 15002 | |
| 15003 | xfree (name); |
| 15004 | { |
| 15005 | int i; |
| 15006 | |
| 15007 | for (i = 0; i < argc; i++) |
| 15008 | xfree (argv[i]); |
| 15009 | } |
| 15010 | xfree (argv); |
| 15011 | } |
| 15012 | else |
| 15013 | dwarf2_macro_malformed_definition_complaint (body); |
| 15014 | } |
| 15015 | |
| 15016 | /* Skip some bytes from BYTES according to the form given in FORM. |
| 15017 | Returns the new pointer. */ |
| 15018 | |
| 15019 | static gdb_byte * |
| 15020 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, |
| 15021 | enum dwarf_form form, |
| 15022 | unsigned int offset_size, |
| 15023 | struct dwarf2_section_info *section) |
| 15024 | { |
| 15025 | unsigned int bytes_read; |
| 15026 | |
| 15027 | switch (form) |
| 15028 | { |
| 15029 | case DW_FORM_data1: |
| 15030 | case DW_FORM_flag: |
| 15031 | ++bytes; |
| 15032 | break; |
| 15033 | |
| 15034 | case DW_FORM_data2: |
| 15035 | bytes += 2; |
| 15036 | break; |
| 15037 | |
| 15038 | case DW_FORM_data4: |
| 15039 | bytes += 4; |
| 15040 | break; |
| 15041 | |
| 15042 | case DW_FORM_data8: |
| 15043 | bytes += 8; |
| 15044 | break; |
| 15045 | |
| 15046 | case DW_FORM_string: |
| 15047 | read_direct_string (abfd, bytes, &bytes_read); |
| 15048 | bytes += bytes_read; |
| 15049 | break; |
| 15050 | |
| 15051 | case DW_FORM_sec_offset: |
| 15052 | case DW_FORM_strp: |
| 15053 | bytes += offset_size; |
| 15054 | break; |
| 15055 | |
| 15056 | case DW_FORM_block: |
| 15057 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); |
| 15058 | bytes += bytes_read; |
| 15059 | break; |
| 15060 | |
| 15061 | case DW_FORM_block1: |
| 15062 | bytes += 1 + read_1_byte (abfd, bytes); |
| 15063 | break; |
| 15064 | case DW_FORM_block2: |
| 15065 | bytes += 2 + read_2_bytes (abfd, bytes); |
| 15066 | break; |
| 15067 | case DW_FORM_block4: |
| 15068 | bytes += 4 + read_4_bytes (abfd, bytes); |
| 15069 | break; |
| 15070 | |
| 15071 | case DW_FORM_sdata: |
| 15072 | case DW_FORM_udata: |
| 15073 | bytes = skip_leb128 (abfd, bytes); |
| 15074 | break; |
| 15075 | |
| 15076 | default: |
| 15077 | { |
| 15078 | complain: |
| 15079 | complaint (&symfile_complaints, |
| 15080 | _("invalid form 0x%x in `%s'"), |
| 15081 | form, |
| 15082 | section->asection->name); |
| 15083 | return NULL; |
| 15084 | } |
| 15085 | } |
| 15086 | |
| 15087 | return bytes; |
| 15088 | } |
| 15089 | |
| 15090 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
| 15091 | opcode. Returns an updated pointer to the macro data buffer; or, |
| 15092 | on error, issues a complaint and returns NULL. */ |
| 15093 | |
| 15094 | static gdb_byte * |
| 15095 | skip_unknown_opcode (unsigned int opcode, |
| 15096 | gdb_byte **opcode_definitions, |
| 15097 | gdb_byte *mac_ptr, |
| 15098 | bfd *abfd, |
| 15099 | unsigned int offset_size, |
| 15100 | struct dwarf2_section_info *section) |
| 15101 | { |
| 15102 | unsigned int bytes_read, i; |
| 15103 | unsigned long arg; |
| 15104 | gdb_byte *defn; |
| 15105 | |
| 15106 | if (opcode_definitions[opcode] == NULL) |
| 15107 | { |
| 15108 | complaint (&symfile_complaints, |
| 15109 | _("unrecognized DW_MACFINO opcode 0x%x"), |
| 15110 | opcode); |
| 15111 | return NULL; |
| 15112 | } |
| 15113 | |
| 15114 | defn = opcode_definitions[opcode]; |
| 15115 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); |
| 15116 | defn += bytes_read; |
| 15117 | |
| 15118 | for (i = 0; i < arg; ++i) |
| 15119 | { |
| 15120 | mac_ptr = skip_form_bytes (abfd, mac_ptr, defn[i], offset_size, section); |
| 15121 | if (mac_ptr == NULL) |
| 15122 | { |
| 15123 | /* skip_form_bytes already issued the complaint. */ |
| 15124 | return NULL; |
| 15125 | } |
| 15126 | } |
| 15127 | |
| 15128 | return mac_ptr; |
| 15129 | } |
| 15130 | |
| 15131 | /* A helper function which parses the header of a macro section. |
| 15132 | If the macro section is the extended (for now called "GNU") type, |
| 15133 | then this updates *OFFSET_SIZE. Returns a pointer to just after |
| 15134 | the header, or issues a complaint and returns NULL on error. */ |
| 15135 | |
| 15136 | static gdb_byte * |
| 15137 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, |
| 15138 | bfd *abfd, |
| 15139 | gdb_byte *mac_ptr, |
| 15140 | unsigned int *offset_size, |
| 15141 | int section_is_gnu) |
| 15142 | { |
| 15143 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); |
| 15144 | |
| 15145 | if (section_is_gnu) |
| 15146 | { |
| 15147 | unsigned int version, flags; |
| 15148 | |
| 15149 | version = read_2_bytes (abfd, mac_ptr); |
| 15150 | if (version != 4) |
| 15151 | { |
| 15152 | complaint (&symfile_complaints, |
| 15153 | _("unrecognized version `%d' in .debug_macro section"), |
| 15154 | version); |
| 15155 | return NULL; |
| 15156 | } |
| 15157 | mac_ptr += 2; |
| 15158 | |
| 15159 | flags = read_1_byte (abfd, mac_ptr); |
| 15160 | ++mac_ptr; |
| 15161 | *offset_size = (flags & 1) ? 8 : 4; |
| 15162 | |
| 15163 | if ((flags & 2) != 0) |
| 15164 | /* We don't need the line table offset. */ |
| 15165 | mac_ptr += *offset_size; |
| 15166 | |
| 15167 | /* Vendor opcode descriptions. */ |
| 15168 | if ((flags & 4) != 0) |
| 15169 | { |
| 15170 | unsigned int i, count; |
| 15171 | |
| 15172 | count = read_1_byte (abfd, mac_ptr); |
| 15173 | ++mac_ptr; |
| 15174 | for (i = 0; i < count; ++i) |
| 15175 | { |
| 15176 | unsigned int opcode, bytes_read; |
| 15177 | unsigned long arg; |
| 15178 | |
| 15179 | opcode = read_1_byte (abfd, mac_ptr); |
| 15180 | ++mac_ptr; |
| 15181 | opcode_definitions[opcode] = mac_ptr; |
| 15182 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15183 | mac_ptr += bytes_read; |
| 15184 | mac_ptr += arg; |
| 15185 | } |
| 15186 | } |
| 15187 | } |
| 15188 | |
| 15189 | return mac_ptr; |
| 15190 | } |
| 15191 | |
| 15192 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
| 15193 | including DW_MACRO_GNU_transparent_include. */ |
| 15194 | |
| 15195 | static void |
| 15196 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, |
| 15197 | struct macro_source_file *current_file, |
| 15198 | struct line_header *lh, char *comp_dir, |
| 15199 | struct dwarf2_section_info *section, |
| 15200 | int section_is_gnu, |
| 15201 | unsigned int offset_size, |
| 15202 | struct objfile *objfile, |
| 15203 | htab_t include_hash) |
| 15204 | { |
| 15205 | enum dwarf_macro_record_type macinfo_type; |
| 15206 | int at_commandline; |
| 15207 | gdb_byte *opcode_definitions[256]; |
| 15208 | |
| 15209 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
| 15210 | &offset_size, section_is_gnu); |
| 15211 | if (mac_ptr == NULL) |
| 15212 | { |
| 15213 | /* We already issued a complaint. */ |
| 15214 | return; |
| 15215 | } |
| 15216 | |
| 15217 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true |
| 15218 | GDB is still reading the definitions from command line. First |
| 15219 | DW_MACINFO_start_file will need to be ignored as it was already executed |
| 15220 | to create CURRENT_FILE for the main source holding also the command line |
| 15221 | definitions. On first met DW_MACINFO_start_file this flag is reset to |
| 15222 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ |
| 15223 | |
| 15224 | at_commandline = 1; |
| 15225 | |
| 15226 | do |
| 15227 | { |
| 15228 | /* Do we at least have room for a macinfo type byte? */ |
| 15229 | if (mac_ptr >= mac_end) |
| 15230 | { |
| 15231 | dwarf2_macros_too_long_complaint (section); |
| 15232 | break; |
| 15233 | } |
| 15234 | |
| 15235 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 15236 | mac_ptr++; |
| 15237 | |
| 15238 | /* Note that we rely on the fact that the corresponding GNU and |
| 15239 | DWARF constants are the same. */ |
| 15240 | switch (macinfo_type) |
| 15241 | { |
| 15242 | /* A zero macinfo type indicates the end of the macro |
| 15243 | information. */ |
| 15244 | case 0: |
| 15245 | break; |
| 15246 | |
| 15247 | case DW_MACRO_GNU_define: |
| 15248 | case DW_MACRO_GNU_undef: |
| 15249 | case DW_MACRO_GNU_define_indirect: |
| 15250 | case DW_MACRO_GNU_undef_indirect: |
| 15251 | { |
| 15252 | unsigned int bytes_read; |
| 15253 | int line; |
| 15254 | char *body; |
| 15255 | int is_define; |
| 15256 | |
| 15257 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15258 | mac_ptr += bytes_read; |
| 15259 | |
| 15260 | if (macinfo_type == DW_MACRO_GNU_define |
| 15261 | || macinfo_type == DW_MACRO_GNU_undef) |
| 15262 | { |
| 15263 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
| 15264 | mac_ptr += bytes_read; |
| 15265 | } |
| 15266 | else |
| 15267 | { |
| 15268 | LONGEST str_offset; |
| 15269 | |
| 15270 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); |
| 15271 | mac_ptr += offset_size; |
| 15272 | |
| 15273 | body = read_indirect_string_at_offset (abfd, str_offset); |
| 15274 | } |
| 15275 | |
| 15276 | is_define = (macinfo_type == DW_MACRO_GNU_define |
| 15277 | || macinfo_type == DW_MACRO_GNU_define_indirect); |
| 15278 | if (! current_file) |
| 15279 | { |
| 15280 | /* DWARF violation as no main source is present. */ |
| 15281 | complaint (&symfile_complaints, |
| 15282 | _("debug info with no main source gives macro %s " |
| 15283 | "on line %d: %s"), |
| 15284 | is_define ? _("definition") : _("undefinition"), |
| 15285 | line, body); |
| 15286 | break; |
| 15287 | } |
| 15288 | if ((line == 0 && !at_commandline) |
| 15289 | || (line != 0 && at_commandline)) |
| 15290 | complaint (&symfile_complaints, |
| 15291 | _("debug info gives %s macro %s with %s line %d: %s"), |
| 15292 | at_commandline ? _("command-line") : _("in-file"), |
| 15293 | is_define ? _("definition") : _("undefinition"), |
| 15294 | line == 0 ? _("zero") : _("non-zero"), line, body); |
| 15295 | |
| 15296 | if (is_define) |
| 15297 | parse_macro_definition (current_file, line, body); |
| 15298 | else |
| 15299 | { |
| 15300 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef |
| 15301 | || macinfo_type == DW_MACRO_GNU_undef_indirect); |
| 15302 | macro_undef (current_file, line, body); |
| 15303 | } |
| 15304 | } |
| 15305 | break; |
| 15306 | |
| 15307 | case DW_MACRO_GNU_start_file: |
| 15308 | { |
| 15309 | unsigned int bytes_read; |
| 15310 | int line, file; |
| 15311 | |
| 15312 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15313 | mac_ptr += bytes_read; |
| 15314 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15315 | mac_ptr += bytes_read; |
| 15316 | |
| 15317 | if ((line == 0 && !at_commandline) |
| 15318 | || (line != 0 && at_commandline)) |
| 15319 | complaint (&symfile_complaints, |
| 15320 | _("debug info gives source %d included " |
| 15321 | "from %s at %s line %d"), |
| 15322 | file, at_commandline ? _("command-line") : _("file"), |
| 15323 | line == 0 ? _("zero") : _("non-zero"), line); |
| 15324 | |
| 15325 | if (at_commandline) |
| 15326 | { |
| 15327 | /* This DW_MACRO_GNU_start_file was executed in the |
| 15328 | pass one. */ |
| 15329 | at_commandline = 0; |
| 15330 | } |
| 15331 | else |
| 15332 | current_file = macro_start_file (file, line, |
| 15333 | current_file, comp_dir, |
| 15334 | lh, objfile); |
| 15335 | } |
| 15336 | break; |
| 15337 | |
| 15338 | case DW_MACRO_GNU_end_file: |
| 15339 | if (! current_file) |
| 15340 | complaint (&symfile_complaints, |
| 15341 | _("macro debug info has an unmatched " |
| 15342 | "`close_file' directive")); |
| 15343 | else |
| 15344 | { |
| 15345 | current_file = current_file->included_by; |
| 15346 | if (! current_file) |
| 15347 | { |
| 15348 | enum dwarf_macro_record_type next_type; |
| 15349 | |
| 15350 | /* GCC circa March 2002 doesn't produce the zero |
| 15351 | type byte marking the end of the compilation |
| 15352 | unit. Complain if it's not there, but exit no |
| 15353 | matter what. */ |
| 15354 | |
| 15355 | /* Do we at least have room for a macinfo type byte? */ |
| 15356 | if (mac_ptr >= mac_end) |
| 15357 | { |
| 15358 | dwarf2_macros_too_long_complaint (section); |
| 15359 | return; |
| 15360 | } |
| 15361 | |
| 15362 | /* We don't increment mac_ptr here, so this is just |
| 15363 | a look-ahead. */ |
| 15364 | next_type = read_1_byte (abfd, mac_ptr); |
| 15365 | if (next_type != 0) |
| 15366 | complaint (&symfile_complaints, |
| 15367 | _("no terminating 0-type entry for " |
| 15368 | "macros in `.debug_macinfo' section")); |
| 15369 | |
| 15370 | return; |
| 15371 | } |
| 15372 | } |
| 15373 | break; |
| 15374 | |
| 15375 | case DW_MACRO_GNU_transparent_include: |
| 15376 | { |
| 15377 | LONGEST offset; |
| 15378 | void **slot; |
| 15379 | |
| 15380 | offset = read_offset_1 (abfd, mac_ptr, offset_size); |
| 15381 | mac_ptr += offset_size; |
| 15382 | |
| 15383 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
| 15384 | if (*slot != NULL) |
| 15385 | { |
| 15386 | /* This has actually happened; see |
| 15387 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ |
| 15388 | complaint (&symfile_complaints, |
| 15389 | _("recursive DW_MACRO_GNU_transparent_include in " |
| 15390 | ".debug_macro section")); |
| 15391 | } |
| 15392 | else |
| 15393 | { |
| 15394 | *slot = mac_ptr; |
| 15395 | |
| 15396 | dwarf_decode_macro_bytes (abfd, |
| 15397 | section->buffer + offset, |
| 15398 | mac_end, current_file, |
| 15399 | lh, comp_dir, |
| 15400 | section, section_is_gnu, |
| 15401 | offset_size, objfile, include_hash); |
| 15402 | |
| 15403 | htab_remove_elt (include_hash, mac_ptr); |
| 15404 | } |
| 15405 | } |
| 15406 | break; |
| 15407 | |
| 15408 | case DW_MACINFO_vendor_ext: |
| 15409 | if (!section_is_gnu) |
| 15410 | { |
| 15411 | unsigned int bytes_read; |
| 15412 | int constant; |
| 15413 | |
| 15414 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15415 | mac_ptr += bytes_read; |
| 15416 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 15417 | mac_ptr += bytes_read; |
| 15418 | |
| 15419 | /* We don't recognize any vendor extensions. */ |
| 15420 | break; |
| 15421 | } |
| 15422 | /* FALLTHROUGH */ |
| 15423 | |
| 15424 | default: |
| 15425 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, |
| 15426 | mac_ptr, abfd, offset_size, |
| 15427 | section); |
| 15428 | if (mac_ptr == NULL) |
| 15429 | return; |
| 15430 | break; |
| 15431 | } |
| 15432 | } while (macinfo_type != 0); |
| 15433 | } |
| 15434 | |
| 15435 | static void |
| 15436 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, |
| 15437 | char *comp_dir, bfd *abfd, |
| 15438 | struct dwarf2_cu *cu, |
| 15439 | struct dwarf2_section_info *section, |
| 15440 | int section_is_gnu) |
| 15441 | { |
| 15442 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 15443 | gdb_byte *mac_ptr, *mac_end; |
| 15444 | struct macro_source_file *current_file = 0; |
| 15445 | enum dwarf_macro_record_type macinfo_type; |
| 15446 | unsigned int offset_size = cu->header.offset_size; |
| 15447 | gdb_byte *opcode_definitions[256]; |
| 15448 | struct cleanup *cleanup; |
| 15449 | htab_t include_hash; |
| 15450 | void **slot; |
| 15451 | |
| 15452 | dwarf2_read_section (objfile, section); |
| 15453 | if (section->buffer == NULL) |
| 15454 | { |
| 15455 | complaint (&symfile_complaints, _("missing %s section"), |
| 15456 | section->asection->name); |
| 15457 | return; |
| 15458 | } |
| 15459 | |
| 15460 | /* First pass: Find the name of the base filename. |
| 15461 | This filename is needed in order to process all macros whose definition |
| 15462 | (or undefinition) comes from the command line. These macros are defined |
| 15463 | before the first DW_MACINFO_start_file entry, and yet still need to be |
| 15464 | associated to the base file. |
| 15465 | |
| 15466 | To determine the base file name, we scan the macro definitions until we |
| 15467 | reach the first DW_MACINFO_start_file entry. We then initialize |
| 15468 | CURRENT_FILE accordingly so that any macro definition found before the |
| 15469 | first DW_MACINFO_start_file can still be associated to the base file. */ |
| 15470 | |
| 15471 | mac_ptr = section->buffer + offset; |
| 15472 | mac_end = section->buffer + section->size; |
| 15473 | |
| 15474 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
| 15475 | &offset_size, section_is_gnu); |
| 15476 | if (mac_ptr == NULL) |
| 15477 | { |
| 15478 | /* We already issued a complaint. */ |
| 15479 | return; |
| 15480 | } |
| 15481 | |
| 15482 | do |
| 15483 | { |
| 15484 | /* Do we at least have room for a macinfo type byte? */ |
| 15485 | if (mac_ptr >= mac_end) |
| 15486 | { |
| 15487 | /* Complaint is printed during the second pass as GDB will probably |
| 15488 | stop the first pass earlier upon finding |
| 15489 | DW_MACINFO_start_file. */ |
| 15490 | break; |
| 15491 | } |
| 15492 | |
| 15493 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 15494 | mac_ptr++; |
| 15495 | |
| 15496 | /* Note that we rely on the fact that the corresponding GNU and |
| 15497 | DWARF constants are the same. */ |
| 15498 | switch (macinfo_type) |
| 15499 | { |
| 15500 | /* A zero macinfo type indicates the end of the macro |
| 15501 | information. */ |
| 15502 | case 0: |
| 15503 | break; |
| 15504 | |
| 15505 | case DW_MACRO_GNU_define: |
| 15506 | case DW_MACRO_GNU_undef: |
| 15507 | /* Only skip the data by MAC_PTR. */ |
| 15508 | { |
| 15509 | unsigned int bytes_read; |
| 15510 | |
| 15511 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15512 | mac_ptr += bytes_read; |
| 15513 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 15514 | mac_ptr += bytes_read; |
| 15515 | } |
| 15516 | break; |
| 15517 | |
| 15518 | case DW_MACRO_GNU_start_file: |
| 15519 | { |
| 15520 | unsigned int bytes_read; |
| 15521 | int line, file; |
| 15522 | |
| 15523 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15524 | mac_ptr += bytes_read; |
| 15525 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15526 | mac_ptr += bytes_read; |
| 15527 | |
| 15528 | current_file = macro_start_file (file, line, current_file, |
| 15529 | comp_dir, lh, objfile); |
| 15530 | } |
| 15531 | break; |
| 15532 | |
| 15533 | case DW_MACRO_GNU_end_file: |
| 15534 | /* No data to skip by MAC_PTR. */ |
| 15535 | break; |
| 15536 | |
| 15537 | case DW_MACRO_GNU_define_indirect: |
| 15538 | case DW_MACRO_GNU_undef_indirect: |
| 15539 | { |
| 15540 | unsigned int bytes_read; |
| 15541 | |
| 15542 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15543 | mac_ptr += bytes_read; |
| 15544 | mac_ptr += offset_size; |
| 15545 | } |
| 15546 | break; |
| 15547 | |
| 15548 | case DW_MACRO_GNU_transparent_include: |
| 15549 | /* Note that, according to the spec, a transparent include |
| 15550 | chain cannot call DW_MACRO_GNU_start_file. So, we can just |
| 15551 | skip this opcode. */ |
| 15552 | mac_ptr += offset_size; |
| 15553 | break; |
| 15554 | |
| 15555 | case DW_MACINFO_vendor_ext: |
| 15556 | /* Only skip the data by MAC_PTR. */ |
| 15557 | if (!section_is_gnu) |
| 15558 | { |
| 15559 | unsigned int bytes_read; |
| 15560 | |
| 15561 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 15562 | mac_ptr += bytes_read; |
| 15563 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 15564 | mac_ptr += bytes_read; |
| 15565 | } |
| 15566 | /* FALLTHROUGH */ |
| 15567 | |
| 15568 | default: |
| 15569 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, |
| 15570 | mac_ptr, abfd, offset_size, |
| 15571 | section); |
| 15572 | if (mac_ptr == NULL) |
| 15573 | return; |
| 15574 | break; |
| 15575 | } |
| 15576 | } while (macinfo_type != 0 && current_file == NULL); |
| 15577 | |
| 15578 | /* Second pass: Process all entries. |
| 15579 | |
| 15580 | Use the AT_COMMAND_LINE flag to determine whether we are still processing |
| 15581 | command-line macro definitions/undefinitions. This flag is unset when we |
| 15582 | reach the first DW_MACINFO_start_file entry. */ |
| 15583 | |
| 15584 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
| 15585 | NULL, xcalloc, xfree); |
| 15586 | cleanup = make_cleanup_htab_delete (include_hash); |
| 15587 | mac_ptr = section->buffer + offset; |
| 15588 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
| 15589 | *slot = mac_ptr; |
| 15590 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, |
| 15591 | current_file, lh, comp_dir, section, section_is_gnu, |
| 15592 | offset_size, objfile, include_hash); |
| 15593 | do_cleanups (cleanup); |
| 15594 | } |
| 15595 | |
| 15596 | /* Check if the attribute's form is a DW_FORM_block* |
| 15597 | if so return true else false. */ |
| 15598 | static int |
| 15599 | attr_form_is_block (struct attribute *attr) |
| 15600 | { |
| 15601 | return (attr == NULL ? 0 : |
| 15602 | attr->form == DW_FORM_block1 |
| 15603 | || attr->form == DW_FORM_block2 |
| 15604 | || attr->form == DW_FORM_block4 |
| 15605 | || attr->form == DW_FORM_block |
| 15606 | || attr->form == DW_FORM_exprloc); |
| 15607 | } |
| 15608 | |
| 15609 | /* Return non-zero if ATTR's value is a section offset --- classes |
| 15610 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. |
| 15611 | You may use DW_UNSND (attr) to retrieve such offsets. |
| 15612 | |
| 15613 | Section 7.5.4, "Attribute Encodings", explains that no attribute |
| 15614 | may have a value that belongs to more than one of these classes; it |
| 15615 | would be ambiguous if we did, because we use the same forms for all |
| 15616 | of them. */ |
| 15617 | static int |
| 15618 | attr_form_is_section_offset (struct attribute *attr) |
| 15619 | { |
| 15620 | return (attr->form == DW_FORM_data4 |
| 15621 | || attr->form == DW_FORM_data8 |
| 15622 | || attr->form == DW_FORM_sec_offset); |
| 15623 | } |
| 15624 | |
| 15625 | |
| 15626 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
| 15627 | zero otherwise. When this function returns true, you can apply |
| 15628 | dwarf2_get_attr_constant_value to it. |
| 15629 | |
| 15630 | However, note that for some attributes you must check |
| 15631 | attr_form_is_section_offset before using this test. DW_FORM_data4 |
| 15632 | and DW_FORM_data8 are members of both the constant class, and of |
| 15633 | the classes that contain offsets into other debug sections |
| 15634 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says |
| 15635 | that, if an attribute's can be either a constant or one of the |
| 15636 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be |
| 15637 | taken as section offsets, not constants. */ |
| 15638 | static int |
| 15639 | attr_form_is_constant (struct attribute *attr) |
| 15640 | { |
| 15641 | switch (attr->form) |
| 15642 | { |
| 15643 | case DW_FORM_sdata: |
| 15644 | case DW_FORM_udata: |
| 15645 | case DW_FORM_data1: |
| 15646 | case DW_FORM_data2: |
| 15647 | case DW_FORM_data4: |
| 15648 | case DW_FORM_data8: |
| 15649 | return 1; |
| 15650 | default: |
| 15651 | return 0; |
| 15652 | } |
| 15653 | } |
| 15654 | |
| 15655 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
| 15656 | |
| 15657 | static void |
| 15658 | fill_in_loclist_baton (struct dwarf2_cu *cu, |
| 15659 | struct dwarf2_loclist_baton *baton, |
| 15660 | struct attribute *attr) |
| 15661 | { |
| 15662 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 15663 | &dwarf2_per_objfile->loc); |
| 15664 | |
| 15665 | baton->per_cu = cu->per_cu; |
| 15666 | gdb_assert (baton->per_cu); |
| 15667 | /* We don't know how long the location list is, but make sure we |
| 15668 | don't run off the edge of the section. */ |
| 15669 | baton->size = dwarf2_per_objfile->loc.size - DW_UNSND (attr); |
| 15670 | baton->data = dwarf2_per_objfile->loc.buffer + DW_UNSND (attr); |
| 15671 | baton->base_address = cu->base_address; |
| 15672 | } |
| 15673 | |
| 15674 | static void |
| 15675 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, |
| 15676 | struct dwarf2_cu *cu) |
| 15677 | { |
| 15678 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 15679 | |
| 15680 | if (attr_form_is_section_offset (attr) |
| 15681 | /* ".debug_loc" may not exist at all, or the offset may be outside |
| 15682 | the section. If so, fall through to the complaint in the |
| 15683 | other branch. */ |
| 15684 | && DW_UNSND (attr) < dwarf2_section_size (objfile, |
| 15685 | &dwarf2_per_objfile->loc)) |
| 15686 | { |
| 15687 | struct dwarf2_loclist_baton *baton; |
| 15688 | |
| 15689 | baton = obstack_alloc (&objfile->objfile_obstack, |
| 15690 | sizeof (struct dwarf2_loclist_baton)); |
| 15691 | |
| 15692 | fill_in_loclist_baton (cu, baton, attr); |
| 15693 | |
| 15694 | if (cu->base_known == 0) |
| 15695 | complaint (&symfile_complaints, |
| 15696 | _("Location list used without " |
| 15697 | "specifying the CU base address.")); |
| 15698 | |
| 15699 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
| 15700 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 15701 | } |
| 15702 | else |
| 15703 | { |
| 15704 | struct dwarf2_locexpr_baton *baton; |
| 15705 | |
| 15706 | baton = obstack_alloc (&objfile->objfile_obstack, |
| 15707 | sizeof (struct dwarf2_locexpr_baton)); |
| 15708 | baton->per_cu = cu->per_cu; |
| 15709 | gdb_assert (baton->per_cu); |
| 15710 | |
| 15711 | if (attr_form_is_block (attr)) |
| 15712 | { |
| 15713 | /* Note that we're just copying the block's data pointer |
| 15714 | here, not the actual data. We're still pointing into the |
| 15715 | info_buffer for SYM's objfile; right now we never release |
| 15716 | that buffer, but when we do clean up properly this may |
| 15717 | need to change. */ |
| 15718 | baton->size = DW_BLOCK (attr)->size; |
| 15719 | baton->data = DW_BLOCK (attr)->data; |
| 15720 | } |
| 15721 | else |
| 15722 | { |
| 15723 | dwarf2_invalid_attrib_class_complaint ("location description", |
| 15724 | SYMBOL_NATURAL_NAME (sym)); |
| 15725 | baton->size = 0; |
| 15726 | } |
| 15727 | |
| 15728 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 15729 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 15730 | } |
| 15731 | } |
| 15732 | |
| 15733 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
| 15734 | came from a separate debuginfo file, then the master objfile is |
| 15735 | returned. */ |
| 15736 | |
| 15737 | struct objfile * |
| 15738 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) |
| 15739 | { |
| 15740 | struct objfile *objfile = per_cu->objfile; |
| 15741 | |
| 15742 | /* Return the master objfile, so that we can report and look up the |
| 15743 | correct file containing this variable. */ |
| 15744 | if (objfile->separate_debug_objfile_backlink) |
| 15745 | objfile = objfile->separate_debug_objfile_backlink; |
| 15746 | |
| 15747 | return objfile; |
| 15748 | } |
| 15749 | |
| 15750 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
| 15751 | (CU_HEADERP is unused in such case) or prepare a temporary copy at |
| 15752 | CU_HEADERP first. */ |
| 15753 | |
| 15754 | static const struct comp_unit_head * |
| 15755 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, |
| 15756 | struct dwarf2_per_cu_data *per_cu) |
| 15757 | { |
| 15758 | struct objfile *objfile; |
| 15759 | struct dwarf2_per_objfile *per_objfile; |
| 15760 | gdb_byte *info_ptr; |
| 15761 | |
| 15762 | if (per_cu->cu) |
| 15763 | return &per_cu->cu->header; |
| 15764 | |
| 15765 | objfile = per_cu->objfile; |
| 15766 | per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 15767 | info_ptr = per_objfile->info.buffer + per_cu->offset; |
| 15768 | |
| 15769 | memset (cu_headerp, 0, sizeof (*cu_headerp)); |
| 15770 | read_comp_unit_head (cu_headerp, info_ptr, objfile->obfd); |
| 15771 | |
| 15772 | return cu_headerp; |
| 15773 | } |
| 15774 | |
| 15775 | /* Return the address size given in the compilation unit header for CU. */ |
| 15776 | |
| 15777 | int |
| 15778 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
| 15779 | { |
| 15780 | struct comp_unit_head cu_header_local; |
| 15781 | const struct comp_unit_head *cu_headerp; |
| 15782 | |
| 15783 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
| 15784 | |
| 15785 | return cu_headerp->addr_size; |
| 15786 | } |
| 15787 | |
| 15788 | /* Return the offset size given in the compilation unit header for CU. */ |
| 15789 | |
| 15790 | int |
| 15791 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) |
| 15792 | { |
| 15793 | struct comp_unit_head cu_header_local; |
| 15794 | const struct comp_unit_head *cu_headerp; |
| 15795 | |
| 15796 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
| 15797 | |
| 15798 | return cu_headerp->offset_size; |
| 15799 | } |
| 15800 | |
| 15801 | /* See its dwarf2loc.h declaration. */ |
| 15802 | |
| 15803 | int |
| 15804 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) |
| 15805 | { |
| 15806 | struct comp_unit_head cu_header_local; |
| 15807 | const struct comp_unit_head *cu_headerp; |
| 15808 | |
| 15809 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
| 15810 | |
| 15811 | if (cu_headerp->version == 2) |
| 15812 | return cu_headerp->addr_size; |
| 15813 | else |
| 15814 | return cu_headerp->offset_size; |
| 15815 | } |
| 15816 | |
| 15817 | /* Return the text offset of the CU. The returned offset comes from |
| 15818 | this CU's objfile. If this objfile came from a separate debuginfo |
| 15819 | file, then the offset may be different from the corresponding |
| 15820 | offset in the parent objfile. */ |
| 15821 | |
| 15822 | CORE_ADDR |
| 15823 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) |
| 15824 | { |
| 15825 | struct objfile *objfile = per_cu->objfile; |
| 15826 | |
| 15827 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 15828 | } |
| 15829 | |
| 15830 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
| 15831 | the DIE at OFFSET. Raises an error on failure. */ |
| 15832 | |
| 15833 | static struct dwarf2_per_cu_data * |
| 15834 | dwarf2_find_containing_comp_unit (unsigned int offset, |
| 15835 | struct objfile *objfile) |
| 15836 | { |
| 15837 | struct dwarf2_per_cu_data *this_cu; |
| 15838 | int low, high; |
| 15839 | |
| 15840 | low = 0; |
| 15841 | high = dwarf2_per_objfile->n_comp_units - 1; |
| 15842 | while (high > low) |
| 15843 | { |
| 15844 | int mid = low + (high - low) / 2; |
| 15845 | |
| 15846 | if (dwarf2_per_objfile->all_comp_units[mid]->offset >= offset) |
| 15847 | high = mid; |
| 15848 | else |
| 15849 | low = mid + 1; |
| 15850 | } |
| 15851 | gdb_assert (low == high); |
| 15852 | if (dwarf2_per_objfile->all_comp_units[low]->offset > offset) |
| 15853 | { |
| 15854 | if (low == 0) |
| 15855 | error (_("Dwarf Error: could not find partial DIE containing " |
| 15856 | "offset 0x%lx [in module %s]"), |
| 15857 | (long) offset, bfd_get_filename (objfile->obfd)); |
| 15858 | |
| 15859 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset <= offset); |
| 15860 | return dwarf2_per_objfile->all_comp_units[low-1]; |
| 15861 | } |
| 15862 | else |
| 15863 | { |
| 15864 | this_cu = dwarf2_per_objfile->all_comp_units[low]; |
| 15865 | if (low == dwarf2_per_objfile->n_comp_units - 1 |
| 15866 | && offset >= this_cu->offset + this_cu->length) |
| 15867 | error (_("invalid dwarf2 offset %u"), offset); |
| 15868 | gdb_assert (offset < this_cu->offset + this_cu->length); |
| 15869 | return this_cu; |
| 15870 | } |
| 15871 | } |
| 15872 | |
| 15873 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
| 15874 | |
| 15875 | static void |
| 15876 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
| 15877 | { |
| 15878 | memset (cu, 0, sizeof (*cu)); |
| 15879 | per_cu->cu = cu; |
| 15880 | cu->per_cu = per_cu; |
| 15881 | cu->objfile = per_cu->objfile; |
| 15882 | obstack_init (&cu->comp_unit_obstack); |
| 15883 | } |
| 15884 | |
| 15885 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ |
| 15886 | |
| 15887 | static void |
| 15888 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die) |
| 15889 | { |
| 15890 | struct attribute *attr; |
| 15891 | |
| 15892 | /* Set the language we're debugging. */ |
| 15893 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
| 15894 | if (attr) |
| 15895 | set_cu_language (DW_UNSND (attr), cu); |
| 15896 | else |
| 15897 | { |
| 15898 | cu->language = language_minimal; |
| 15899 | cu->language_defn = language_def (cu->language); |
| 15900 | } |
| 15901 | } |
| 15902 | |
| 15903 | /* Release one cached compilation unit, CU. We unlink it from the tree |
| 15904 | of compilation units, but we don't remove it from the read_in_chain; |
| 15905 | the caller is responsible for that. |
| 15906 | NOTE: DATA is a void * because this function is also used as a |
| 15907 | cleanup routine. */ |
| 15908 | |
| 15909 | static void |
| 15910 | free_heap_comp_unit (void *data) |
| 15911 | { |
| 15912 | struct dwarf2_cu *cu = data; |
| 15913 | |
| 15914 | gdb_assert (cu->per_cu != NULL); |
| 15915 | cu->per_cu->cu = NULL; |
| 15916 | cu->per_cu = NULL; |
| 15917 | |
| 15918 | obstack_free (&cu->comp_unit_obstack, NULL); |
| 15919 | |
| 15920 | xfree (cu); |
| 15921 | } |
| 15922 | |
| 15923 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
| 15924 | when we're finished with it. We can't free the pointer itself, but be |
| 15925 | sure to unlink it from the cache. Also release any associated storage |
| 15926 | and perform cache maintenance. |
| 15927 | |
| 15928 | Only used during partial symbol parsing. */ |
| 15929 | |
| 15930 | static void |
| 15931 | free_stack_comp_unit (void *data) |
| 15932 | { |
| 15933 | struct dwarf2_cu *cu = data; |
| 15934 | |
| 15935 | gdb_assert (cu->per_cu != NULL); |
| 15936 | cu->per_cu->cu = NULL; |
| 15937 | cu->per_cu = NULL; |
| 15938 | |
| 15939 | obstack_free (&cu->comp_unit_obstack, NULL); |
| 15940 | cu->partial_dies = NULL; |
| 15941 | |
| 15942 | /* The previous code only did this if per_cu != NULL. |
| 15943 | But that would always succeed, so now we just unconditionally do |
| 15944 | the aging. This seems like the wrong place to do such aging, |
| 15945 | but cleaning that up is left for later. */ |
| 15946 | age_cached_comp_units (); |
| 15947 | } |
| 15948 | |
| 15949 | /* Free all cached compilation units. */ |
| 15950 | |
| 15951 | static void |
| 15952 | free_cached_comp_units (void *data) |
| 15953 | { |
| 15954 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 15955 | |
| 15956 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 15957 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 15958 | while (per_cu != NULL) |
| 15959 | { |
| 15960 | struct dwarf2_per_cu_data *next_cu; |
| 15961 | |
| 15962 | next_cu = per_cu->cu->read_in_chain; |
| 15963 | |
| 15964 | free_heap_comp_unit (per_cu->cu); |
| 15965 | *last_chain = next_cu; |
| 15966 | |
| 15967 | per_cu = next_cu; |
| 15968 | } |
| 15969 | } |
| 15970 | |
| 15971 | /* Increase the age counter on each cached compilation unit, and free |
| 15972 | any that are too old. */ |
| 15973 | |
| 15974 | static void |
| 15975 | age_cached_comp_units (void) |
| 15976 | { |
| 15977 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 15978 | |
| 15979 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); |
| 15980 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 15981 | while (per_cu != NULL) |
| 15982 | { |
| 15983 | per_cu->cu->last_used ++; |
| 15984 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) |
| 15985 | dwarf2_mark (per_cu->cu); |
| 15986 | per_cu = per_cu->cu->read_in_chain; |
| 15987 | } |
| 15988 | |
| 15989 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 15990 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 15991 | while (per_cu != NULL) |
| 15992 | { |
| 15993 | struct dwarf2_per_cu_data *next_cu; |
| 15994 | |
| 15995 | next_cu = per_cu->cu->read_in_chain; |
| 15996 | |
| 15997 | if (!per_cu->cu->mark) |
| 15998 | { |
| 15999 | free_heap_comp_unit (per_cu->cu); |
| 16000 | *last_chain = next_cu; |
| 16001 | } |
| 16002 | else |
| 16003 | last_chain = &per_cu->cu->read_in_chain; |
| 16004 | |
| 16005 | per_cu = next_cu; |
| 16006 | } |
| 16007 | } |
| 16008 | |
| 16009 | /* Remove a single compilation unit from the cache. */ |
| 16010 | |
| 16011 | static void |
| 16012 | free_one_cached_comp_unit (void *target_cu) |
| 16013 | { |
| 16014 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 16015 | |
| 16016 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 16017 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 16018 | while (per_cu != NULL) |
| 16019 | { |
| 16020 | struct dwarf2_per_cu_data *next_cu; |
| 16021 | |
| 16022 | next_cu = per_cu->cu->read_in_chain; |
| 16023 | |
| 16024 | if (per_cu->cu == target_cu) |
| 16025 | { |
| 16026 | free_heap_comp_unit (per_cu->cu); |
| 16027 | *last_chain = next_cu; |
| 16028 | break; |
| 16029 | } |
| 16030 | else |
| 16031 | last_chain = &per_cu->cu->read_in_chain; |
| 16032 | |
| 16033 | per_cu = next_cu; |
| 16034 | } |
| 16035 | } |
| 16036 | |
| 16037 | /* Release all extra memory associated with OBJFILE. */ |
| 16038 | |
| 16039 | void |
| 16040 | dwarf2_free_objfile (struct objfile *objfile) |
| 16041 | { |
| 16042 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 16043 | |
| 16044 | if (dwarf2_per_objfile == NULL) |
| 16045 | return; |
| 16046 | |
| 16047 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ |
| 16048 | free_cached_comp_units (NULL); |
| 16049 | |
| 16050 | if (dwarf2_per_objfile->quick_file_names_table) |
| 16051 | htab_delete (dwarf2_per_objfile->quick_file_names_table); |
| 16052 | |
| 16053 | /* Everything else should be on the objfile obstack. */ |
| 16054 | } |
| 16055 | |
| 16056 | /* A pair of DIE offset and GDB type pointer. We store these |
| 16057 | in a hash table separate from the DIEs, and preserve them |
| 16058 | when the DIEs are flushed out of cache. */ |
| 16059 | |
| 16060 | struct dwarf2_offset_and_type |
| 16061 | { |
| 16062 | unsigned int offset; |
| 16063 | struct type *type; |
| 16064 | }; |
| 16065 | |
| 16066 | /* Hash function for a dwarf2_offset_and_type. */ |
| 16067 | |
| 16068 | static hashval_t |
| 16069 | offset_and_type_hash (const void *item) |
| 16070 | { |
| 16071 | const struct dwarf2_offset_and_type *ofs = item; |
| 16072 | |
| 16073 | return ofs->offset; |
| 16074 | } |
| 16075 | |
| 16076 | /* Equality function for a dwarf2_offset_and_type. */ |
| 16077 | |
| 16078 | static int |
| 16079 | offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
| 16080 | { |
| 16081 | const struct dwarf2_offset_and_type *ofs_lhs = item_lhs; |
| 16082 | const struct dwarf2_offset_and_type *ofs_rhs = item_rhs; |
| 16083 | |
| 16084 | return ofs_lhs->offset == ofs_rhs->offset; |
| 16085 | } |
| 16086 | |
| 16087 | /* Set the type associated with DIE to TYPE. Save it in CU's hash |
| 16088 | table if necessary. For convenience, return TYPE. |
| 16089 | |
| 16090 | The DIEs reading must have careful ordering to: |
| 16091 | * Not cause infite loops trying to read in DIEs as a prerequisite for |
| 16092 | reading current DIE. |
| 16093 | * Not trying to dereference contents of still incompletely read in types |
| 16094 | while reading in other DIEs. |
| 16095 | * Enable referencing still incompletely read in types just by a pointer to |
| 16096 | the type without accessing its fields. |
| 16097 | |
| 16098 | Therefore caller should follow these rules: |
| 16099 | * Try to fetch any prerequisite types we may need to build this DIE type |
| 16100 | before building the type and calling set_die_type. |
| 16101 | * After building type call set_die_type for current DIE as soon as |
| 16102 | possible before fetching more types to complete the current type. |
| 16103 | * Make the type as complete as possible before fetching more types. */ |
| 16104 | |
| 16105 | static struct type * |
| 16106 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
| 16107 | { |
| 16108 | struct dwarf2_offset_and_type **slot, ofs; |
| 16109 | struct objfile *objfile = cu->objfile; |
| 16110 | htab_t *type_hash_ptr; |
| 16111 | |
| 16112 | /* For Ada types, make sure that the gnat-specific data is always |
| 16113 | initialized (if not already set). There are a few types where |
| 16114 | we should not be doing so, because the type-specific area is |
| 16115 | already used to hold some other piece of info (eg: TYPE_CODE_FLT |
| 16116 | where the type-specific area is used to store the floatformat). |
| 16117 | But this is not a problem, because the gnat-specific information |
| 16118 | is actually not needed for these types. */ |
| 16119 | if (need_gnat_info (cu) |
| 16120 | && TYPE_CODE (type) != TYPE_CODE_FUNC |
| 16121 | && TYPE_CODE (type) != TYPE_CODE_FLT |
| 16122 | && !HAVE_GNAT_AUX_INFO (type)) |
| 16123 | INIT_GNAT_SPECIFIC (type); |
| 16124 | |
| 16125 | if (cu->per_cu->debug_types_section) |
| 16126 | type_hash_ptr = &dwarf2_per_objfile->debug_types_type_hash; |
| 16127 | else |
| 16128 | type_hash_ptr = &dwarf2_per_objfile->debug_info_type_hash; |
| 16129 | |
| 16130 | if (*type_hash_ptr == NULL) |
| 16131 | { |
| 16132 | *type_hash_ptr |
| 16133 | = htab_create_alloc_ex (127, |
| 16134 | offset_and_type_hash, |
| 16135 | offset_and_type_eq, |
| 16136 | NULL, |
| 16137 | &objfile->objfile_obstack, |
| 16138 | hashtab_obstack_allocate, |
| 16139 | dummy_obstack_deallocate); |
| 16140 | } |
| 16141 | |
| 16142 | ofs.offset = die->offset; |
| 16143 | ofs.type = type; |
| 16144 | slot = (struct dwarf2_offset_and_type **) |
| 16145 | htab_find_slot_with_hash (*type_hash_ptr, &ofs, ofs.offset, INSERT); |
| 16146 | if (*slot) |
| 16147 | complaint (&symfile_complaints, |
| 16148 | _("A problem internal to GDB: DIE 0x%x has type already set"), |
| 16149 | die->offset); |
| 16150 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
| 16151 | **slot = ofs; |
| 16152 | return type; |
| 16153 | } |
| 16154 | |
| 16155 | /* Look up the type for the die at DIE_OFFSET in the appropriate type_hash |
| 16156 | table, or return NULL if the die does not have a saved type. */ |
| 16157 | |
| 16158 | static struct type * |
| 16159 | get_die_type_at_offset (unsigned int offset, |
| 16160 | struct dwarf2_per_cu_data *per_cu) |
| 16161 | { |
| 16162 | struct dwarf2_offset_and_type *slot, ofs; |
| 16163 | htab_t type_hash; |
| 16164 | |
| 16165 | if (per_cu->debug_types_section) |
| 16166 | type_hash = dwarf2_per_objfile->debug_types_type_hash; |
| 16167 | else |
| 16168 | type_hash = dwarf2_per_objfile->debug_info_type_hash; |
| 16169 | if (type_hash == NULL) |
| 16170 | return NULL; |
| 16171 | |
| 16172 | ofs.offset = offset; |
| 16173 | slot = htab_find_with_hash (type_hash, &ofs, ofs.offset); |
| 16174 | if (slot) |
| 16175 | return slot->type; |
| 16176 | else |
| 16177 | return NULL; |
| 16178 | } |
| 16179 | |
| 16180 | /* Look up the type for DIE in the appropriate type_hash table, |
| 16181 | or return NULL if DIE does not have a saved type. */ |
| 16182 | |
| 16183 | static struct type * |
| 16184 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
| 16185 | { |
| 16186 | return get_die_type_at_offset (die->offset, cu->per_cu); |
| 16187 | } |
| 16188 | |
| 16189 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
| 16190 | |
| 16191 | static void |
| 16192 | dwarf2_add_dependence (struct dwarf2_cu *cu, |
| 16193 | struct dwarf2_per_cu_data *ref_per_cu) |
| 16194 | { |
| 16195 | void **slot; |
| 16196 | |
| 16197 | if (cu->dependencies == NULL) |
| 16198 | cu->dependencies |
| 16199 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, |
| 16200 | NULL, &cu->comp_unit_obstack, |
| 16201 | hashtab_obstack_allocate, |
| 16202 | dummy_obstack_deallocate); |
| 16203 | |
| 16204 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); |
| 16205 | if (*slot == NULL) |
| 16206 | *slot = ref_per_cu; |
| 16207 | } |
| 16208 | |
| 16209 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
| 16210 | Set the mark field in every compilation unit in the |
| 16211 | cache that we must keep because we are keeping CU. */ |
| 16212 | |
| 16213 | static int |
| 16214 | dwarf2_mark_helper (void **slot, void *data) |
| 16215 | { |
| 16216 | struct dwarf2_per_cu_data *per_cu; |
| 16217 | |
| 16218 | per_cu = (struct dwarf2_per_cu_data *) *slot; |
| 16219 | |
| 16220 | /* cu->dependencies references may not yet have been ever read if QUIT aborts |
| 16221 | reading of the chain. As such dependencies remain valid it is not much |
| 16222 | useful to track and undo them during QUIT cleanups. */ |
| 16223 | if (per_cu->cu == NULL) |
| 16224 | return 1; |
| 16225 | |
| 16226 | if (per_cu->cu->mark) |
| 16227 | return 1; |
| 16228 | per_cu->cu->mark = 1; |
| 16229 | |
| 16230 | if (per_cu->cu->dependencies != NULL) |
| 16231 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); |
| 16232 | |
| 16233 | return 1; |
| 16234 | } |
| 16235 | |
| 16236 | /* Set the mark field in CU and in every other compilation unit in the |
| 16237 | cache that we must keep because we are keeping CU. */ |
| 16238 | |
| 16239 | static void |
| 16240 | dwarf2_mark (struct dwarf2_cu *cu) |
| 16241 | { |
| 16242 | if (cu->mark) |
| 16243 | return; |
| 16244 | cu->mark = 1; |
| 16245 | if (cu->dependencies != NULL) |
| 16246 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); |
| 16247 | } |
| 16248 | |
| 16249 | static void |
| 16250 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) |
| 16251 | { |
| 16252 | while (per_cu) |
| 16253 | { |
| 16254 | per_cu->cu->mark = 0; |
| 16255 | per_cu = per_cu->cu->read_in_chain; |
| 16256 | } |
| 16257 | } |
| 16258 | |
| 16259 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
| 16260 | is its offset in .debug_info for this objfile. */ |
| 16261 | |
| 16262 | static hashval_t |
| 16263 | partial_die_hash (const void *item) |
| 16264 | { |
| 16265 | const struct partial_die_info *part_die = item; |
| 16266 | |
| 16267 | return part_die->offset; |
| 16268 | } |
| 16269 | |
| 16270 | /* Trivial comparison function for partial_die_info structures: two DIEs |
| 16271 | are equal if they have the same offset. */ |
| 16272 | |
| 16273 | static int |
| 16274 | partial_die_eq (const void *item_lhs, const void *item_rhs) |
| 16275 | { |
| 16276 | const struct partial_die_info *part_die_lhs = item_lhs; |
| 16277 | const struct partial_die_info *part_die_rhs = item_rhs; |
| 16278 | |
| 16279 | return part_die_lhs->offset == part_die_rhs->offset; |
| 16280 | } |
| 16281 | |
| 16282 | static struct cmd_list_element *set_dwarf2_cmdlist; |
| 16283 | static struct cmd_list_element *show_dwarf2_cmdlist; |
| 16284 | |
| 16285 | static void |
| 16286 | set_dwarf2_cmd (char *args, int from_tty) |
| 16287 | { |
| 16288 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); |
| 16289 | } |
| 16290 | |
| 16291 | static void |
| 16292 | show_dwarf2_cmd (char *args, int from_tty) |
| 16293 | { |
| 16294 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
| 16295 | } |
| 16296 | |
| 16297 | /* If section described by INFO was mmapped, munmap it now. */ |
| 16298 | |
| 16299 | static void |
| 16300 | munmap_section_buffer (struct dwarf2_section_info *info) |
| 16301 | { |
| 16302 | if (info->map_addr != NULL) |
| 16303 | { |
| 16304 | #ifdef HAVE_MMAP |
| 16305 | int res; |
| 16306 | |
| 16307 | res = munmap (info->map_addr, info->map_len); |
| 16308 | gdb_assert (res == 0); |
| 16309 | #else |
| 16310 | /* Without HAVE_MMAP, we should never be here to begin with. */ |
| 16311 | gdb_assert_not_reached ("no mmap support"); |
| 16312 | #endif |
| 16313 | } |
| 16314 | } |
| 16315 | |
| 16316 | /* munmap debug sections for OBJFILE, if necessary. */ |
| 16317 | |
| 16318 | static void |
| 16319 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
| 16320 | { |
| 16321 | struct dwarf2_per_objfile *data = d; |
| 16322 | int ix; |
| 16323 | struct dwarf2_section_info *section; |
| 16324 | |
| 16325 | /* This is sorted according to the order they're defined in to make it easier |
| 16326 | to keep in sync. */ |
| 16327 | munmap_section_buffer (&data->info); |
| 16328 | munmap_section_buffer (&data->abbrev); |
| 16329 | munmap_section_buffer (&data->line); |
| 16330 | munmap_section_buffer (&data->loc); |
| 16331 | munmap_section_buffer (&data->macinfo); |
| 16332 | munmap_section_buffer (&data->macro); |
| 16333 | munmap_section_buffer (&data->str); |
| 16334 | munmap_section_buffer (&data->ranges); |
| 16335 | munmap_section_buffer (&data->frame); |
| 16336 | munmap_section_buffer (&data->eh_frame); |
| 16337 | munmap_section_buffer (&data->gdb_index); |
| 16338 | |
| 16339 | for (ix = 0; |
| 16340 | VEC_iterate (dwarf2_section_info_def, data->types, ix, section); |
| 16341 | ++ix) |
| 16342 | munmap_section_buffer (section); |
| 16343 | |
| 16344 | VEC_free (dwarf2_section_info_def, data->types); |
| 16345 | } |
| 16346 | |
| 16347 | \f |
| 16348 | /* The "save gdb-index" command. */ |
| 16349 | |
| 16350 | /* The contents of the hash table we create when building the string |
| 16351 | table. */ |
| 16352 | struct strtab_entry |
| 16353 | { |
| 16354 | offset_type offset; |
| 16355 | const char *str; |
| 16356 | }; |
| 16357 | |
| 16358 | /* Hash function for a strtab_entry. |
| 16359 | |
| 16360 | Function is used only during write_hash_table so no index format backward |
| 16361 | compatibility is needed. */ |
| 16362 | |
| 16363 | static hashval_t |
| 16364 | hash_strtab_entry (const void *e) |
| 16365 | { |
| 16366 | const struct strtab_entry *entry = e; |
| 16367 | return mapped_index_string_hash (INT_MAX, entry->str); |
| 16368 | } |
| 16369 | |
| 16370 | /* Equality function for a strtab_entry. */ |
| 16371 | |
| 16372 | static int |
| 16373 | eq_strtab_entry (const void *a, const void *b) |
| 16374 | { |
| 16375 | const struct strtab_entry *ea = a; |
| 16376 | const struct strtab_entry *eb = b; |
| 16377 | return !strcmp (ea->str, eb->str); |
| 16378 | } |
| 16379 | |
| 16380 | /* Create a strtab_entry hash table. */ |
| 16381 | |
| 16382 | static htab_t |
| 16383 | create_strtab (void) |
| 16384 | { |
| 16385 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, |
| 16386 | xfree, xcalloc, xfree); |
| 16387 | } |
| 16388 | |
| 16389 | /* Add a string to the constant pool. Return the string's offset in |
| 16390 | host order. */ |
| 16391 | |
| 16392 | static offset_type |
| 16393 | add_string (htab_t table, struct obstack *cpool, const char *str) |
| 16394 | { |
| 16395 | void **slot; |
| 16396 | struct strtab_entry entry; |
| 16397 | struct strtab_entry *result; |
| 16398 | |
| 16399 | entry.str = str; |
| 16400 | slot = htab_find_slot (table, &entry, INSERT); |
| 16401 | if (*slot) |
| 16402 | result = *slot; |
| 16403 | else |
| 16404 | { |
| 16405 | result = XNEW (struct strtab_entry); |
| 16406 | result->offset = obstack_object_size (cpool); |
| 16407 | result->str = str; |
| 16408 | obstack_grow_str0 (cpool, str); |
| 16409 | *slot = result; |
| 16410 | } |
| 16411 | return result->offset; |
| 16412 | } |
| 16413 | |
| 16414 | /* An entry in the symbol table. */ |
| 16415 | struct symtab_index_entry |
| 16416 | { |
| 16417 | /* The name of the symbol. */ |
| 16418 | const char *name; |
| 16419 | /* The offset of the name in the constant pool. */ |
| 16420 | offset_type index_offset; |
| 16421 | /* A sorted vector of the indices of all the CUs that hold an object |
| 16422 | of this name. */ |
| 16423 | VEC (offset_type) *cu_indices; |
| 16424 | }; |
| 16425 | |
| 16426 | /* The symbol table. This is a power-of-2-sized hash table. */ |
| 16427 | struct mapped_symtab |
| 16428 | { |
| 16429 | offset_type n_elements; |
| 16430 | offset_type size; |
| 16431 | struct symtab_index_entry **data; |
| 16432 | }; |
| 16433 | |
| 16434 | /* Hash function for a symtab_index_entry. */ |
| 16435 | |
| 16436 | static hashval_t |
| 16437 | hash_symtab_entry (const void *e) |
| 16438 | { |
| 16439 | const struct symtab_index_entry *entry = e; |
| 16440 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), |
| 16441 | sizeof (offset_type) * VEC_length (offset_type, |
| 16442 | entry->cu_indices), |
| 16443 | 0); |
| 16444 | } |
| 16445 | |
| 16446 | /* Equality function for a symtab_index_entry. */ |
| 16447 | |
| 16448 | static int |
| 16449 | eq_symtab_entry (const void *a, const void *b) |
| 16450 | { |
| 16451 | const struct symtab_index_entry *ea = a; |
| 16452 | const struct symtab_index_entry *eb = b; |
| 16453 | int len = VEC_length (offset_type, ea->cu_indices); |
| 16454 | if (len != VEC_length (offset_type, eb->cu_indices)) |
| 16455 | return 0; |
| 16456 | return !memcmp (VEC_address (offset_type, ea->cu_indices), |
| 16457 | VEC_address (offset_type, eb->cu_indices), |
| 16458 | sizeof (offset_type) * len); |
| 16459 | } |
| 16460 | |
| 16461 | /* Destroy a symtab_index_entry. */ |
| 16462 | |
| 16463 | static void |
| 16464 | delete_symtab_entry (void *p) |
| 16465 | { |
| 16466 | struct symtab_index_entry *entry = p; |
| 16467 | VEC_free (offset_type, entry->cu_indices); |
| 16468 | xfree (entry); |
| 16469 | } |
| 16470 | |
| 16471 | /* Create a hash table holding symtab_index_entry objects. */ |
| 16472 | |
| 16473 | static htab_t |
| 16474 | create_symbol_hash_table (void) |
| 16475 | { |
| 16476 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, |
| 16477 | delete_symtab_entry, xcalloc, xfree); |
| 16478 | } |
| 16479 | |
| 16480 | /* Create a new mapped symtab object. */ |
| 16481 | |
| 16482 | static struct mapped_symtab * |
| 16483 | create_mapped_symtab (void) |
| 16484 | { |
| 16485 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); |
| 16486 | symtab->n_elements = 0; |
| 16487 | symtab->size = 1024; |
| 16488 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); |
| 16489 | return symtab; |
| 16490 | } |
| 16491 | |
| 16492 | /* Destroy a mapped_symtab. */ |
| 16493 | |
| 16494 | static void |
| 16495 | cleanup_mapped_symtab (void *p) |
| 16496 | { |
| 16497 | struct mapped_symtab *symtab = p; |
| 16498 | /* The contents of the array are freed when the other hash table is |
| 16499 | destroyed. */ |
| 16500 | xfree (symtab->data); |
| 16501 | xfree (symtab); |
| 16502 | } |
| 16503 | |
| 16504 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to |
| 16505 | the slot. |
| 16506 | |
| 16507 | Function is used only during write_hash_table so no index format backward |
| 16508 | compatibility is needed. */ |
| 16509 | |
| 16510 | static struct symtab_index_entry ** |
| 16511 | find_slot (struct mapped_symtab *symtab, const char *name) |
| 16512 | { |
| 16513 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
| 16514 | |
| 16515 | index = hash & (symtab->size - 1); |
| 16516 | step = ((hash * 17) & (symtab->size - 1)) | 1; |
| 16517 | |
| 16518 | for (;;) |
| 16519 | { |
| 16520 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) |
| 16521 | return &symtab->data[index]; |
| 16522 | index = (index + step) & (symtab->size - 1); |
| 16523 | } |
| 16524 | } |
| 16525 | |
| 16526 | /* Expand SYMTAB's hash table. */ |
| 16527 | |
| 16528 | static void |
| 16529 | hash_expand (struct mapped_symtab *symtab) |
| 16530 | { |
| 16531 | offset_type old_size = symtab->size; |
| 16532 | offset_type i; |
| 16533 | struct symtab_index_entry **old_entries = symtab->data; |
| 16534 | |
| 16535 | symtab->size *= 2; |
| 16536 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); |
| 16537 | |
| 16538 | for (i = 0; i < old_size; ++i) |
| 16539 | { |
| 16540 | if (old_entries[i]) |
| 16541 | { |
| 16542 | struct symtab_index_entry **slot = find_slot (symtab, |
| 16543 | old_entries[i]->name); |
| 16544 | *slot = old_entries[i]; |
| 16545 | } |
| 16546 | } |
| 16547 | |
| 16548 | xfree (old_entries); |
| 16549 | } |
| 16550 | |
| 16551 | /* Add an entry to SYMTAB. NAME is the name of the symbol. CU_INDEX |
| 16552 | is the index of the CU in which the symbol appears. */ |
| 16553 | |
| 16554 | static void |
| 16555 | add_index_entry (struct mapped_symtab *symtab, const char *name, |
| 16556 | offset_type cu_index) |
| 16557 | { |
| 16558 | struct symtab_index_entry **slot; |
| 16559 | |
| 16560 | ++symtab->n_elements; |
| 16561 | if (4 * symtab->n_elements / 3 >= symtab->size) |
| 16562 | hash_expand (symtab); |
| 16563 | |
| 16564 | slot = find_slot (symtab, name); |
| 16565 | if (!*slot) |
| 16566 | { |
| 16567 | *slot = XNEW (struct symtab_index_entry); |
| 16568 | (*slot)->name = name; |
| 16569 | (*slot)->cu_indices = NULL; |
| 16570 | } |
| 16571 | /* Don't push an index twice. Due to how we add entries we only |
| 16572 | have to check the last one. */ |
| 16573 | if (VEC_empty (offset_type, (*slot)->cu_indices) |
| 16574 | || VEC_last (offset_type, (*slot)->cu_indices) != cu_index) |
| 16575 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index); |
| 16576 | } |
| 16577 | |
| 16578 | /* Add a vector of indices to the constant pool. */ |
| 16579 | |
| 16580 | static offset_type |
| 16581 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
| 16582 | struct symtab_index_entry *entry) |
| 16583 | { |
| 16584 | void **slot; |
| 16585 | |
| 16586 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
| 16587 | if (!*slot) |
| 16588 | { |
| 16589 | offset_type len = VEC_length (offset_type, entry->cu_indices); |
| 16590 | offset_type val = MAYBE_SWAP (len); |
| 16591 | offset_type iter; |
| 16592 | int i; |
| 16593 | |
| 16594 | *slot = entry; |
| 16595 | entry->index_offset = obstack_object_size (cpool); |
| 16596 | |
| 16597 | obstack_grow (cpool, &val, sizeof (val)); |
| 16598 | for (i = 0; |
| 16599 | VEC_iterate (offset_type, entry->cu_indices, i, iter); |
| 16600 | ++i) |
| 16601 | { |
| 16602 | val = MAYBE_SWAP (iter); |
| 16603 | obstack_grow (cpool, &val, sizeof (val)); |
| 16604 | } |
| 16605 | } |
| 16606 | else |
| 16607 | { |
| 16608 | struct symtab_index_entry *old_entry = *slot; |
| 16609 | entry->index_offset = old_entry->index_offset; |
| 16610 | entry = old_entry; |
| 16611 | } |
| 16612 | return entry->index_offset; |
| 16613 | } |
| 16614 | |
| 16615 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with |
| 16616 | constant pool entries going into the obstack CPOOL. */ |
| 16617 | |
| 16618 | static void |
| 16619 | write_hash_table (struct mapped_symtab *symtab, |
| 16620 | struct obstack *output, struct obstack *cpool) |
| 16621 | { |
| 16622 | offset_type i; |
| 16623 | htab_t symbol_hash_table; |
| 16624 | htab_t str_table; |
| 16625 | |
| 16626 | symbol_hash_table = create_symbol_hash_table (); |
| 16627 | str_table = create_strtab (); |
| 16628 | |
| 16629 | /* We add all the index vectors to the constant pool first, to |
| 16630 | ensure alignment is ok. */ |
| 16631 | for (i = 0; i < symtab->size; ++i) |
| 16632 | { |
| 16633 | if (symtab->data[i]) |
| 16634 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
| 16635 | } |
| 16636 | |
| 16637 | /* Now write out the hash table. */ |
| 16638 | for (i = 0; i < symtab->size; ++i) |
| 16639 | { |
| 16640 | offset_type str_off, vec_off; |
| 16641 | |
| 16642 | if (symtab->data[i]) |
| 16643 | { |
| 16644 | str_off = add_string (str_table, cpool, symtab->data[i]->name); |
| 16645 | vec_off = symtab->data[i]->index_offset; |
| 16646 | } |
| 16647 | else |
| 16648 | { |
| 16649 | /* While 0 is a valid constant pool index, it is not valid |
| 16650 | to have 0 for both offsets. */ |
| 16651 | str_off = 0; |
| 16652 | vec_off = 0; |
| 16653 | } |
| 16654 | |
| 16655 | str_off = MAYBE_SWAP (str_off); |
| 16656 | vec_off = MAYBE_SWAP (vec_off); |
| 16657 | |
| 16658 | obstack_grow (output, &str_off, sizeof (str_off)); |
| 16659 | obstack_grow (output, &vec_off, sizeof (vec_off)); |
| 16660 | } |
| 16661 | |
| 16662 | htab_delete (str_table); |
| 16663 | htab_delete (symbol_hash_table); |
| 16664 | } |
| 16665 | |
| 16666 | /* Struct to map psymtab to CU index in the index file. */ |
| 16667 | struct psymtab_cu_index_map |
| 16668 | { |
| 16669 | struct partial_symtab *psymtab; |
| 16670 | unsigned int cu_index; |
| 16671 | }; |
| 16672 | |
| 16673 | static hashval_t |
| 16674 | hash_psymtab_cu_index (const void *item) |
| 16675 | { |
| 16676 | const struct psymtab_cu_index_map *map = item; |
| 16677 | |
| 16678 | return htab_hash_pointer (map->psymtab); |
| 16679 | } |
| 16680 | |
| 16681 | static int |
| 16682 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) |
| 16683 | { |
| 16684 | const struct psymtab_cu_index_map *lhs = item_lhs; |
| 16685 | const struct psymtab_cu_index_map *rhs = item_rhs; |
| 16686 | |
| 16687 | return lhs->psymtab == rhs->psymtab; |
| 16688 | } |
| 16689 | |
| 16690 | /* Helper struct for building the address table. */ |
| 16691 | struct addrmap_index_data |
| 16692 | { |
| 16693 | struct objfile *objfile; |
| 16694 | struct obstack *addr_obstack; |
| 16695 | htab_t cu_index_htab; |
| 16696 | |
| 16697 | /* Non-zero if the previous_* fields are valid. |
| 16698 | We can't write an entry until we see the next entry (since it is only then |
| 16699 | that we know the end of the entry). */ |
| 16700 | int previous_valid; |
| 16701 | /* Index of the CU in the table of all CUs in the index file. */ |
| 16702 | unsigned int previous_cu_index; |
| 16703 | /* Start address of the CU. */ |
| 16704 | CORE_ADDR previous_cu_start; |
| 16705 | }; |
| 16706 | |
| 16707 | /* Write an address entry to OBSTACK. */ |
| 16708 | |
| 16709 | static void |
| 16710 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
| 16711 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) |
| 16712 | { |
| 16713 | offset_type cu_index_to_write; |
| 16714 | char addr[8]; |
| 16715 | CORE_ADDR baseaddr; |
| 16716 | |
| 16717 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 16718 | |
| 16719 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
| 16720 | obstack_grow (obstack, addr, 8); |
| 16721 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); |
| 16722 | obstack_grow (obstack, addr, 8); |
| 16723 | cu_index_to_write = MAYBE_SWAP (cu_index); |
| 16724 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); |
| 16725 | } |
| 16726 | |
| 16727 | /* Worker function for traversing an addrmap to build the address table. */ |
| 16728 | |
| 16729 | static int |
| 16730 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) |
| 16731 | { |
| 16732 | struct addrmap_index_data *data = datap; |
| 16733 | struct partial_symtab *pst = obj; |
| 16734 | offset_type cu_index; |
| 16735 | void **slot; |
| 16736 | |
| 16737 | if (data->previous_valid) |
| 16738 | add_address_entry (data->objfile, data->addr_obstack, |
| 16739 | data->previous_cu_start, start_addr, |
| 16740 | data->previous_cu_index); |
| 16741 | |
| 16742 | data->previous_cu_start = start_addr; |
| 16743 | if (pst != NULL) |
| 16744 | { |
| 16745 | struct psymtab_cu_index_map find_map, *map; |
| 16746 | find_map.psymtab = pst; |
| 16747 | map = htab_find (data->cu_index_htab, &find_map); |
| 16748 | gdb_assert (map != NULL); |
| 16749 | data->previous_cu_index = map->cu_index; |
| 16750 | data->previous_valid = 1; |
| 16751 | } |
| 16752 | else |
| 16753 | data->previous_valid = 0; |
| 16754 | |
| 16755 | return 0; |
| 16756 | } |
| 16757 | |
| 16758 | /* Write OBJFILE's address map to OBSTACK. |
| 16759 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices |
| 16760 | in the index file. */ |
| 16761 | |
| 16762 | static void |
| 16763 | write_address_map (struct objfile *objfile, struct obstack *obstack, |
| 16764 | htab_t cu_index_htab) |
| 16765 | { |
| 16766 | struct addrmap_index_data addrmap_index_data; |
| 16767 | |
| 16768 | /* When writing the address table, we have to cope with the fact that |
| 16769 | the addrmap iterator only provides the start of a region; we have to |
| 16770 | wait until the next invocation to get the start of the next region. */ |
| 16771 | |
| 16772 | addrmap_index_data.objfile = objfile; |
| 16773 | addrmap_index_data.addr_obstack = obstack; |
| 16774 | addrmap_index_data.cu_index_htab = cu_index_htab; |
| 16775 | addrmap_index_data.previous_valid = 0; |
| 16776 | |
| 16777 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, |
| 16778 | &addrmap_index_data); |
| 16779 | |
| 16780 | /* It's highly unlikely the last entry (end address = 0xff...ff) |
| 16781 | is valid, but we should still handle it. |
| 16782 | The end address is recorded as the start of the next region, but that |
| 16783 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation |
| 16784 | anyway. */ |
| 16785 | if (addrmap_index_data.previous_valid) |
| 16786 | add_address_entry (objfile, obstack, |
| 16787 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, |
| 16788 | addrmap_index_data.previous_cu_index); |
| 16789 | } |
| 16790 | |
| 16791 | /* Add a list of partial symbols to SYMTAB. */ |
| 16792 | |
| 16793 | static void |
| 16794 | write_psymbols (struct mapped_symtab *symtab, |
| 16795 | htab_t psyms_seen, |
| 16796 | struct partial_symbol **psymp, |
| 16797 | int count, |
| 16798 | offset_type cu_index, |
| 16799 | int is_static) |
| 16800 | { |
| 16801 | for (; count-- > 0; ++psymp) |
| 16802 | { |
| 16803 | void **slot, *lookup; |
| 16804 | |
| 16805 | if (SYMBOL_LANGUAGE (*psymp) == language_ada) |
| 16806 | error (_("Ada is not currently supported by the index")); |
| 16807 | |
| 16808 | /* We only want to add a given psymbol once. However, we also |
| 16809 | want to account for whether it is global or static. So, we |
| 16810 | may add it twice, using slightly different values. */ |
| 16811 | if (is_static) |
| 16812 | { |
| 16813 | uintptr_t val = 1 | (uintptr_t) *psymp; |
| 16814 | |
| 16815 | lookup = (void *) val; |
| 16816 | } |
| 16817 | else |
| 16818 | lookup = *psymp; |
| 16819 | |
| 16820 | /* Only add a given psymbol once. */ |
| 16821 | slot = htab_find_slot (psyms_seen, lookup, INSERT); |
| 16822 | if (!*slot) |
| 16823 | { |
| 16824 | *slot = lookup; |
| 16825 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (*psymp), cu_index); |
| 16826 | } |
| 16827 | } |
| 16828 | } |
| 16829 | |
| 16830 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an |
| 16831 | exception if there is an error. */ |
| 16832 | |
| 16833 | static void |
| 16834 | write_obstack (FILE *file, struct obstack *obstack) |
| 16835 | { |
| 16836 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), |
| 16837 | file) |
| 16838 | != obstack_object_size (obstack)) |
| 16839 | error (_("couldn't data write to file")); |
| 16840 | } |
| 16841 | |
| 16842 | /* Unlink a file if the argument is not NULL. */ |
| 16843 | |
| 16844 | static void |
| 16845 | unlink_if_set (void *p) |
| 16846 | { |
| 16847 | char **filename = p; |
| 16848 | if (*filename) |
| 16849 | unlink (*filename); |
| 16850 | } |
| 16851 | |
| 16852 | /* A helper struct used when iterating over debug_types. */ |
| 16853 | struct signatured_type_index_data |
| 16854 | { |
| 16855 | struct objfile *objfile; |
| 16856 | struct mapped_symtab *symtab; |
| 16857 | struct obstack *types_list; |
| 16858 | htab_t psyms_seen; |
| 16859 | int cu_index; |
| 16860 | }; |
| 16861 | |
| 16862 | /* A helper function that writes a single signatured_type to an |
| 16863 | obstack. */ |
| 16864 | |
| 16865 | static int |
| 16866 | write_one_signatured_type (void **slot, void *d) |
| 16867 | { |
| 16868 | struct signatured_type_index_data *info = d; |
| 16869 | struct signatured_type *entry = (struct signatured_type *) *slot; |
| 16870 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
| 16871 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
| 16872 | gdb_byte val[8]; |
| 16873 | |
| 16874 | write_psymbols (info->symtab, |
| 16875 | info->psyms_seen, |
| 16876 | info->objfile->global_psymbols.list |
| 16877 | + psymtab->globals_offset, |
| 16878 | psymtab->n_global_syms, info->cu_index, |
| 16879 | 0); |
| 16880 | write_psymbols (info->symtab, |
| 16881 | info->psyms_seen, |
| 16882 | info->objfile->static_psymbols.list |
| 16883 | + psymtab->statics_offset, |
| 16884 | psymtab->n_static_syms, info->cu_index, |
| 16885 | 1); |
| 16886 | |
| 16887 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->per_cu.offset); |
| 16888 | obstack_grow (info->types_list, val, 8); |
| 16889 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->type_offset); |
| 16890 | obstack_grow (info->types_list, val, 8); |
| 16891 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); |
| 16892 | obstack_grow (info->types_list, val, 8); |
| 16893 | |
| 16894 | ++info->cu_index; |
| 16895 | |
| 16896 | return 1; |
| 16897 | } |
| 16898 | |
| 16899 | /* Create an index file for OBJFILE in the directory DIR. */ |
| 16900 | |
| 16901 | static void |
| 16902 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) |
| 16903 | { |
| 16904 | struct cleanup *cleanup; |
| 16905 | char *filename, *cleanup_filename; |
| 16906 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
| 16907 | struct obstack cu_list, types_cu_list; |
| 16908 | int i; |
| 16909 | FILE *out_file; |
| 16910 | struct mapped_symtab *symtab; |
| 16911 | offset_type val, size_of_contents, total_len; |
| 16912 | struct stat st; |
| 16913 | char buf[8]; |
| 16914 | htab_t psyms_seen; |
| 16915 | htab_t cu_index_htab; |
| 16916 | struct psymtab_cu_index_map *psymtab_cu_index_map; |
| 16917 | |
| 16918 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
| 16919 | return; |
| 16920 | |
| 16921 | if (dwarf2_per_objfile->using_index) |
| 16922 | error (_("Cannot use an index to create the index")); |
| 16923 | |
| 16924 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
| 16925 | error (_("Cannot make an index when the file has multiple .debug_types sections")); |
| 16926 | |
| 16927 | if (stat (objfile->name, &st) < 0) |
| 16928 | perror_with_name (objfile->name); |
| 16929 | |
| 16930 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), |
| 16931 | INDEX_SUFFIX, (char *) NULL); |
| 16932 | cleanup = make_cleanup (xfree, filename); |
| 16933 | |
| 16934 | out_file = fopen (filename, "wb"); |
| 16935 | if (!out_file) |
| 16936 | error (_("Can't open `%s' for writing"), filename); |
| 16937 | |
| 16938 | cleanup_filename = filename; |
| 16939 | make_cleanup (unlink_if_set, &cleanup_filename); |
| 16940 | |
| 16941 | symtab = create_mapped_symtab (); |
| 16942 | make_cleanup (cleanup_mapped_symtab, symtab); |
| 16943 | |
| 16944 | obstack_init (&addr_obstack); |
| 16945 | make_cleanup_obstack_free (&addr_obstack); |
| 16946 | |
| 16947 | obstack_init (&cu_list); |
| 16948 | make_cleanup_obstack_free (&cu_list); |
| 16949 | |
| 16950 | obstack_init (&types_cu_list); |
| 16951 | make_cleanup_obstack_free (&types_cu_list); |
| 16952 | |
| 16953 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
| 16954 | NULL, xcalloc, xfree); |
| 16955 | make_cleanup_htab_delete (psyms_seen); |
| 16956 | |
| 16957 | /* While we're scanning CU's create a table that maps a psymtab pointer |
| 16958 | (which is what addrmap records) to its index (which is what is recorded |
| 16959 | in the index file). This will later be needed to write the address |
| 16960 | table. */ |
| 16961 | cu_index_htab = htab_create_alloc (100, |
| 16962 | hash_psymtab_cu_index, |
| 16963 | eq_psymtab_cu_index, |
| 16964 | NULL, xcalloc, xfree); |
| 16965 | make_cleanup_htab_delete (cu_index_htab); |
| 16966 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
| 16967 | xmalloc (sizeof (struct psymtab_cu_index_map) |
| 16968 | * dwarf2_per_objfile->n_comp_units); |
| 16969 | make_cleanup (xfree, psymtab_cu_index_map); |
| 16970 | |
| 16971 | /* The CU list is already sorted, so we don't need to do additional |
| 16972 | work here. Also, the debug_types entries do not appear in |
| 16973 | all_comp_units, but only in their own hash table. */ |
| 16974 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 16975 | { |
| 16976 | struct dwarf2_per_cu_data *per_cu |
| 16977 | = dwarf2_per_objfile->all_comp_units[i]; |
| 16978 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
| 16979 | gdb_byte val[8]; |
| 16980 | struct psymtab_cu_index_map *map; |
| 16981 | void **slot; |
| 16982 | |
| 16983 | write_psymbols (symtab, |
| 16984 | psyms_seen, |
| 16985 | objfile->global_psymbols.list + psymtab->globals_offset, |
| 16986 | psymtab->n_global_syms, i, |
| 16987 | 0); |
| 16988 | write_psymbols (symtab, |
| 16989 | psyms_seen, |
| 16990 | objfile->static_psymbols.list + psymtab->statics_offset, |
| 16991 | psymtab->n_static_syms, i, |
| 16992 | 1); |
| 16993 | |
| 16994 | map = &psymtab_cu_index_map[i]; |
| 16995 | map->psymtab = psymtab; |
| 16996 | map->cu_index = i; |
| 16997 | slot = htab_find_slot (cu_index_htab, map, INSERT); |
| 16998 | gdb_assert (slot != NULL); |
| 16999 | gdb_assert (*slot == NULL); |
| 17000 | *slot = map; |
| 17001 | |
| 17002 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->offset); |
| 17003 | obstack_grow (&cu_list, val, 8); |
| 17004 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
| 17005 | obstack_grow (&cu_list, val, 8); |
| 17006 | } |
| 17007 | |
| 17008 | /* Dump the address map. */ |
| 17009 | write_address_map (objfile, &addr_obstack, cu_index_htab); |
| 17010 | |
| 17011 | /* Write out the .debug_type entries, if any. */ |
| 17012 | if (dwarf2_per_objfile->signatured_types) |
| 17013 | { |
| 17014 | struct signatured_type_index_data sig_data; |
| 17015 | |
| 17016 | sig_data.objfile = objfile; |
| 17017 | sig_data.symtab = symtab; |
| 17018 | sig_data.types_list = &types_cu_list; |
| 17019 | sig_data.psyms_seen = psyms_seen; |
| 17020 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
| 17021 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, |
| 17022 | write_one_signatured_type, &sig_data); |
| 17023 | } |
| 17024 | |
| 17025 | obstack_init (&constant_pool); |
| 17026 | make_cleanup_obstack_free (&constant_pool); |
| 17027 | obstack_init (&symtab_obstack); |
| 17028 | make_cleanup_obstack_free (&symtab_obstack); |
| 17029 | write_hash_table (symtab, &symtab_obstack, &constant_pool); |
| 17030 | |
| 17031 | obstack_init (&contents); |
| 17032 | make_cleanup_obstack_free (&contents); |
| 17033 | size_of_contents = 6 * sizeof (offset_type); |
| 17034 | total_len = size_of_contents; |
| 17035 | |
| 17036 | /* The version number. */ |
| 17037 | val = MAYBE_SWAP (5); |
| 17038 | obstack_grow (&contents, &val, sizeof (val)); |
| 17039 | |
| 17040 | /* The offset of the CU list from the start of the file. */ |
| 17041 | val = MAYBE_SWAP (total_len); |
| 17042 | obstack_grow (&contents, &val, sizeof (val)); |
| 17043 | total_len += obstack_object_size (&cu_list); |
| 17044 | |
| 17045 | /* The offset of the types CU list from the start of the file. */ |
| 17046 | val = MAYBE_SWAP (total_len); |
| 17047 | obstack_grow (&contents, &val, sizeof (val)); |
| 17048 | total_len += obstack_object_size (&types_cu_list); |
| 17049 | |
| 17050 | /* The offset of the address table from the start of the file. */ |
| 17051 | val = MAYBE_SWAP (total_len); |
| 17052 | obstack_grow (&contents, &val, sizeof (val)); |
| 17053 | total_len += obstack_object_size (&addr_obstack); |
| 17054 | |
| 17055 | /* The offset of the symbol table from the start of the file. */ |
| 17056 | val = MAYBE_SWAP (total_len); |
| 17057 | obstack_grow (&contents, &val, sizeof (val)); |
| 17058 | total_len += obstack_object_size (&symtab_obstack); |
| 17059 | |
| 17060 | /* The offset of the constant pool from the start of the file. */ |
| 17061 | val = MAYBE_SWAP (total_len); |
| 17062 | obstack_grow (&contents, &val, sizeof (val)); |
| 17063 | total_len += obstack_object_size (&constant_pool); |
| 17064 | |
| 17065 | gdb_assert (obstack_object_size (&contents) == size_of_contents); |
| 17066 | |
| 17067 | write_obstack (out_file, &contents); |
| 17068 | write_obstack (out_file, &cu_list); |
| 17069 | write_obstack (out_file, &types_cu_list); |
| 17070 | write_obstack (out_file, &addr_obstack); |
| 17071 | write_obstack (out_file, &symtab_obstack); |
| 17072 | write_obstack (out_file, &constant_pool); |
| 17073 | |
| 17074 | fclose (out_file); |
| 17075 | |
| 17076 | /* We want to keep the file, so we set cleanup_filename to NULL |
| 17077 | here. See unlink_if_set. */ |
| 17078 | cleanup_filename = NULL; |
| 17079 | |
| 17080 | do_cleanups (cleanup); |
| 17081 | } |
| 17082 | |
| 17083 | /* Implementation of the `save gdb-index' command. |
| 17084 | |
| 17085 | Note that the file format used by this command is documented in the |
| 17086 | GDB manual. Any changes here must be documented there. */ |
| 17087 | |
| 17088 | static void |
| 17089 | save_gdb_index_command (char *arg, int from_tty) |
| 17090 | { |
| 17091 | struct objfile *objfile; |
| 17092 | |
| 17093 | if (!arg || !*arg) |
| 17094 | error (_("usage: save gdb-index DIRECTORY")); |
| 17095 | |
| 17096 | ALL_OBJFILES (objfile) |
| 17097 | { |
| 17098 | struct stat st; |
| 17099 | |
| 17100 | /* If the objfile does not correspond to an actual file, skip it. */ |
| 17101 | if (stat (objfile->name, &st) < 0) |
| 17102 | continue; |
| 17103 | |
| 17104 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 17105 | if (dwarf2_per_objfile) |
| 17106 | { |
| 17107 | volatile struct gdb_exception except; |
| 17108 | |
| 17109 | TRY_CATCH (except, RETURN_MASK_ERROR) |
| 17110 | { |
| 17111 | write_psymtabs_to_index (objfile, arg); |
| 17112 | } |
| 17113 | if (except.reason < 0) |
| 17114 | exception_fprintf (gdb_stderr, except, |
| 17115 | _("Error while writing index for `%s': "), |
| 17116 | objfile->name); |
| 17117 | } |
| 17118 | } |
| 17119 | } |
| 17120 | |
| 17121 | \f |
| 17122 | |
| 17123 | int dwarf2_always_disassemble; |
| 17124 | |
| 17125 | static void |
| 17126 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, |
| 17127 | struct cmd_list_element *c, const char *value) |
| 17128 | { |
| 17129 | fprintf_filtered (file, |
| 17130 | _("Whether to always disassemble " |
| 17131 | "DWARF expressions is %s.\n"), |
| 17132 | value); |
| 17133 | } |
| 17134 | |
| 17135 | static void |
| 17136 | show_check_physname (struct ui_file *file, int from_tty, |
| 17137 | struct cmd_list_element *c, const char *value) |
| 17138 | { |
| 17139 | fprintf_filtered (file, |
| 17140 | _("Whether to check \"physname\" is %s.\n"), |
| 17141 | value); |
| 17142 | } |
| 17143 | |
| 17144 | void _initialize_dwarf2_read (void); |
| 17145 | |
| 17146 | void |
| 17147 | _initialize_dwarf2_read (void) |
| 17148 | { |
| 17149 | struct cmd_list_element *c; |
| 17150 | |
| 17151 | dwarf2_objfile_data_key |
| 17152 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
| 17153 | |
| 17154 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
| 17155 | Set DWARF 2 specific variables.\n\ |
| 17156 | Configure DWARF 2 variables such as the cache size"), |
| 17157 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
| 17158 | 0/*allow-unknown*/, &maintenance_set_cmdlist); |
| 17159 | |
| 17160 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
| 17161 | Show DWARF 2 specific variables\n\ |
| 17162 | Show DWARF 2 variables such as the cache size"), |
| 17163 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
| 17164 | 0/*allow-unknown*/, &maintenance_show_cmdlist); |
| 17165 | |
| 17166 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, |
| 17167 | &dwarf2_max_cache_age, _("\ |
| 17168 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ |
| 17169 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ |
| 17170 | A higher limit means that cached compilation units will be stored\n\ |
| 17171 | in memory longer, and more total memory will be used. Zero disables\n\ |
| 17172 | caching, which can slow down startup."), |
| 17173 | NULL, |
| 17174 | show_dwarf2_max_cache_age, |
| 17175 | &set_dwarf2_cmdlist, |
| 17176 | &show_dwarf2_cmdlist); |
| 17177 | |
| 17178 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
| 17179 | &dwarf2_always_disassemble, _("\ |
| 17180 | Set whether `info address' always disassembles DWARF expressions."), _("\ |
| 17181 | Show whether `info address' always disassembles DWARF expressions."), _("\ |
| 17182 | When enabled, DWARF expressions are always printed in an assembly-like\n\ |
| 17183 | syntax. When disabled, expressions will be printed in a more\n\ |
| 17184 | conversational style, when possible."), |
| 17185 | NULL, |
| 17186 | show_dwarf2_always_disassemble, |
| 17187 | &set_dwarf2_cmdlist, |
| 17188 | &show_dwarf2_cmdlist); |
| 17189 | |
| 17190 | add_setshow_zinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
| 17191 | Set debugging of the dwarf2 DIE reader."), _("\ |
| 17192 | Show debugging of the dwarf2 DIE reader."), _("\ |
| 17193 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ |
| 17194 | The value is the maximum depth to print."), |
| 17195 | NULL, |
| 17196 | NULL, |
| 17197 | &setdebuglist, &showdebuglist); |
| 17198 | |
| 17199 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
| 17200 | Set cross-checking of \"physname\" code against demangler."), _("\ |
| 17201 | Show cross-checking of \"physname\" code against demangler."), _("\ |
| 17202 | When enabled, GDB's internal \"physname\" code is checked against\n\ |
| 17203 | the demangler."), |
| 17204 | NULL, show_check_physname, |
| 17205 | &setdebuglist, &showdebuglist); |
| 17206 | |
| 17207 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
| 17208 | _("\ |
| 17209 | Save a gdb-index file.\n\ |
| 17210 | Usage: save gdb-index DIRECTORY"), |
| 17211 | &save_cmdlist); |
| 17212 | set_cmd_completer (c, filename_completer); |
| 17213 | } |