| 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 "elf-bfd.h" |
| 34 | #include "symtab.h" |
| 35 | #include "gdbtypes.h" |
| 36 | #include "objfiles.h" |
| 37 | #include "dwarf2.h" |
| 38 | #include "buildsym.h" |
| 39 | #include "demangle.h" |
| 40 | #include "gdb-demangle.h" |
| 41 | #include "expression.h" |
| 42 | #include "filenames.h" /* for DOSish file names */ |
| 43 | #include "macrotab.h" |
| 44 | #include "language.h" |
| 45 | #include "complaints.h" |
| 46 | #include "bcache.h" |
| 47 | #include "dwarf2expr.h" |
| 48 | #include "dwarf2loc.h" |
| 49 | #include "cp-support.h" |
| 50 | #include "hashtab.h" |
| 51 | #include "command.h" |
| 52 | #include "gdbcmd.h" |
| 53 | #include "block.h" |
| 54 | #include "addrmap.h" |
| 55 | #include "typeprint.h" |
| 56 | #include "jv-lang.h" |
| 57 | #include "psympriv.h" |
| 58 | #include "exceptions.h" |
| 59 | #include "gdb_stat.h" |
| 60 | #include "completer.h" |
| 61 | #include "vec.h" |
| 62 | #include "c-lang.h" |
| 63 | #include "go-lang.h" |
| 64 | #include "valprint.h" |
| 65 | #include "gdbcore.h" /* for gnutarget */ |
| 66 | #include "gdb/gdb-index.h" |
| 67 | #include <ctype.h> |
| 68 | #include "gdb_bfd.h" |
| 69 | #include "f-lang.h" |
| 70 | |
| 71 | #include <fcntl.h> |
| 72 | #include "gdb_string.h" |
| 73 | #include "gdb_assert.h" |
| 74 | #include <sys/types.h> |
| 75 | |
| 76 | typedef struct symbol *symbolp; |
| 77 | DEF_VEC_P (symbolp); |
| 78 | |
| 79 | /* When non-zero, print basic high level tracing messages. |
| 80 | This is in contrast to the low level DIE reading of dwarf2_die_debug. */ |
| 81 | static int dwarf2_read_debug = 0; |
| 82 | |
| 83 | /* When non-zero, dump DIEs after they are read in. */ |
| 84 | static unsigned int dwarf2_die_debug = 0; |
| 85 | |
| 86 | /* When non-zero, cross-check physname against demangler. */ |
| 87 | static int check_physname = 0; |
| 88 | |
| 89 | /* When non-zero, do not reject deprecated .gdb_index sections. */ |
| 90 | static int use_deprecated_index_sections = 0; |
| 91 | |
| 92 | /* When set, the file that we're processing is known to have debugging |
| 93 | info for C++ namespaces. GCC 3.3.x did not produce this information, |
| 94 | but later versions do. */ |
| 95 | |
| 96 | static int processing_has_namespace_info; |
| 97 | |
| 98 | static const struct objfile_data *dwarf2_objfile_data_key; |
| 99 | |
| 100 | struct dwarf2_section_info |
| 101 | { |
| 102 | asection *asection; |
| 103 | gdb_byte *buffer; |
| 104 | bfd_size_type size; |
| 105 | /* True if we have tried to read this section. */ |
| 106 | int readin; |
| 107 | }; |
| 108 | |
| 109 | typedef struct dwarf2_section_info dwarf2_section_info_def; |
| 110 | DEF_VEC_O (dwarf2_section_info_def); |
| 111 | |
| 112 | /* All offsets in the index are of this type. It must be |
| 113 | architecture-independent. */ |
| 114 | typedef uint32_t offset_type; |
| 115 | |
| 116 | DEF_VEC_I (offset_type); |
| 117 | |
| 118 | /* Ensure only legit values are used. */ |
| 119 | #define DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE(cu_index, value) \ |
| 120 | do { \ |
| 121 | gdb_assert ((unsigned int) (value) <= 1); \ |
| 122 | GDB_INDEX_SYMBOL_STATIC_SET_VALUE((cu_index), (value)); \ |
| 123 | } while (0) |
| 124 | |
| 125 | /* Ensure only legit values are used. */ |
| 126 | #define DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE(cu_index, value) \ |
| 127 | do { \ |
| 128 | gdb_assert ((value) >= GDB_INDEX_SYMBOL_KIND_TYPE \ |
| 129 | && (value) <= GDB_INDEX_SYMBOL_KIND_OTHER); \ |
| 130 | GDB_INDEX_SYMBOL_KIND_SET_VALUE((cu_index), (value)); \ |
| 131 | } while (0) |
| 132 | |
| 133 | /* Ensure we don't use more than the alloted nuber of bits for the CU. */ |
| 134 | #define DW2_GDB_INDEX_CU_SET_VALUE(cu_index, value) \ |
| 135 | do { \ |
| 136 | gdb_assert (((value) & ~GDB_INDEX_CU_MASK) == 0); \ |
| 137 | GDB_INDEX_CU_SET_VALUE((cu_index), (value)); \ |
| 138 | } while (0) |
| 139 | |
| 140 | /* A description of the mapped index. The file format is described in |
| 141 | a comment by the code that writes the index. */ |
| 142 | struct mapped_index |
| 143 | { |
| 144 | /* Index data format version. */ |
| 145 | int version; |
| 146 | |
| 147 | /* The total length of the buffer. */ |
| 148 | off_t total_size; |
| 149 | |
| 150 | /* A pointer to the address table data. */ |
| 151 | const gdb_byte *address_table; |
| 152 | |
| 153 | /* Size of the address table data in bytes. */ |
| 154 | offset_type address_table_size; |
| 155 | |
| 156 | /* The symbol table, implemented as a hash table. */ |
| 157 | const offset_type *symbol_table; |
| 158 | |
| 159 | /* Size in slots, each slot is 2 offset_types. */ |
| 160 | offset_type symbol_table_slots; |
| 161 | |
| 162 | /* A pointer to the constant pool. */ |
| 163 | const char *constant_pool; |
| 164 | }; |
| 165 | |
| 166 | typedef struct dwarf2_per_cu_data *dwarf2_per_cu_ptr; |
| 167 | DEF_VEC_P (dwarf2_per_cu_ptr); |
| 168 | |
| 169 | /* Collection of data recorded per objfile. |
| 170 | This hangs off of dwarf2_objfile_data_key. */ |
| 171 | |
| 172 | struct dwarf2_per_objfile |
| 173 | { |
| 174 | struct dwarf2_section_info info; |
| 175 | struct dwarf2_section_info abbrev; |
| 176 | struct dwarf2_section_info line; |
| 177 | struct dwarf2_section_info loc; |
| 178 | struct dwarf2_section_info macinfo; |
| 179 | struct dwarf2_section_info macro; |
| 180 | struct dwarf2_section_info str; |
| 181 | struct dwarf2_section_info ranges; |
| 182 | struct dwarf2_section_info addr; |
| 183 | struct dwarf2_section_info frame; |
| 184 | struct dwarf2_section_info eh_frame; |
| 185 | struct dwarf2_section_info gdb_index; |
| 186 | |
| 187 | VEC (dwarf2_section_info_def) *types; |
| 188 | |
| 189 | /* Back link. */ |
| 190 | struct objfile *objfile; |
| 191 | |
| 192 | /* Table of all the compilation units. This is used to locate |
| 193 | the target compilation unit of a particular reference. */ |
| 194 | struct dwarf2_per_cu_data **all_comp_units; |
| 195 | |
| 196 | /* The number of compilation units in ALL_COMP_UNITS. */ |
| 197 | int n_comp_units; |
| 198 | |
| 199 | /* The number of .debug_types-related CUs. */ |
| 200 | int n_type_units; |
| 201 | |
| 202 | /* The .debug_types-related CUs (TUs). */ |
| 203 | struct signatured_type **all_type_units; |
| 204 | |
| 205 | /* The number of entries in all_type_unit_groups. */ |
| 206 | int n_type_unit_groups; |
| 207 | |
| 208 | /* Table of type unit groups. |
| 209 | This exists to make it easy to iterate over all CUs and TU groups. */ |
| 210 | struct type_unit_group **all_type_unit_groups; |
| 211 | |
| 212 | /* Table of struct type_unit_group objects. |
| 213 | The hash key is the DW_AT_stmt_list value. */ |
| 214 | htab_t type_unit_groups; |
| 215 | |
| 216 | /* A table mapping .debug_types signatures to its signatured_type entry. |
| 217 | This is NULL if the .debug_types section hasn't been read in yet. */ |
| 218 | htab_t signatured_types; |
| 219 | |
| 220 | /* Type unit statistics, to see how well the scaling improvements |
| 221 | are doing. */ |
| 222 | struct tu_stats |
| 223 | { |
| 224 | int nr_uniq_abbrev_tables; |
| 225 | int nr_symtabs; |
| 226 | int nr_symtab_sharers; |
| 227 | int nr_stmt_less_type_units; |
| 228 | } tu_stats; |
| 229 | |
| 230 | /* A chain of compilation units that are currently read in, so that |
| 231 | they can be freed later. */ |
| 232 | struct dwarf2_per_cu_data *read_in_chain; |
| 233 | |
| 234 | /* A table mapping DW_AT_dwo_name values to struct dwo_file objects. |
| 235 | This is NULL if the table hasn't been allocated yet. */ |
| 236 | htab_t dwo_files; |
| 237 | |
| 238 | /* Non-zero if we've check for whether there is a DWP file. */ |
| 239 | int dwp_checked; |
| 240 | |
| 241 | /* The DWP file if there is one, or NULL. */ |
| 242 | struct dwp_file *dwp_file; |
| 243 | |
| 244 | /* The shared '.dwz' file, if one exists. This is used when the |
| 245 | original data was compressed using 'dwz -m'. */ |
| 246 | struct dwz_file *dwz_file; |
| 247 | |
| 248 | /* A flag indicating wether this objfile has a section loaded at a |
| 249 | VMA of 0. */ |
| 250 | int has_section_at_zero; |
| 251 | |
| 252 | /* True if we are using the mapped index, |
| 253 | or we are faking it for OBJF_READNOW's sake. */ |
| 254 | unsigned char using_index; |
| 255 | |
| 256 | /* The mapped index, or NULL if .gdb_index is missing or not being used. */ |
| 257 | struct mapped_index *index_table; |
| 258 | |
| 259 | /* When using index_table, this keeps track of all quick_file_names entries. |
| 260 | TUs typically share line table entries with a CU, so we maintain a |
| 261 | separate table of all line table entries to support the sharing. |
| 262 | Note that while there can be way more TUs than CUs, we've already |
| 263 | sorted all the TUs into "type unit groups", grouped by their |
| 264 | DW_AT_stmt_list value. Therefore the only sharing done here is with a |
| 265 | CU and its associated TU group if there is one. */ |
| 266 | htab_t quick_file_names_table; |
| 267 | |
| 268 | /* Set during partial symbol reading, to prevent queueing of full |
| 269 | symbols. */ |
| 270 | int reading_partial_symbols; |
| 271 | |
| 272 | /* Table mapping type DIEs to their struct type *. |
| 273 | This is NULL if not allocated yet. |
| 274 | The mapping is done via (CU/TU signature + DIE offset) -> type. */ |
| 275 | htab_t die_type_hash; |
| 276 | |
| 277 | /* The CUs we recently read. */ |
| 278 | VEC (dwarf2_per_cu_ptr) *just_read_cus; |
| 279 | }; |
| 280 | |
| 281 | static struct dwarf2_per_objfile *dwarf2_per_objfile; |
| 282 | |
| 283 | /* Default names of the debugging sections. */ |
| 284 | |
| 285 | /* Note that if the debugging section has been compressed, it might |
| 286 | have a name like .zdebug_info. */ |
| 287 | |
| 288 | static const struct dwarf2_debug_sections dwarf2_elf_names = |
| 289 | { |
| 290 | { ".debug_info", ".zdebug_info" }, |
| 291 | { ".debug_abbrev", ".zdebug_abbrev" }, |
| 292 | { ".debug_line", ".zdebug_line" }, |
| 293 | { ".debug_loc", ".zdebug_loc" }, |
| 294 | { ".debug_macinfo", ".zdebug_macinfo" }, |
| 295 | { ".debug_macro", ".zdebug_macro" }, |
| 296 | { ".debug_str", ".zdebug_str" }, |
| 297 | { ".debug_ranges", ".zdebug_ranges" }, |
| 298 | { ".debug_types", ".zdebug_types" }, |
| 299 | { ".debug_addr", ".zdebug_addr" }, |
| 300 | { ".debug_frame", ".zdebug_frame" }, |
| 301 | { ".eh_frame", NULL }, |
| 302 | { ".gdb_index", ".zgdb_index" }, |
| 303 | 23 |
| 304 | }; |
| 305 | |
| 306 | /* List of DWO/DWP sections. */ |
| 307 | |
| 308 | static const struct dwop_section_names |
| 309 | { |
| 310 | struct dwarf2_section_names abbrev_dwo; |
| 311 | struct dwarf2_section_names info_dwo; |
| 312 | struct dwarf2_section_names line_dwo; |
| 313 | struct dwarf2_section_names loc_dwo; |
| 314 | struct dwarf2_section_names macinfo_dwo; |
| 315 | struct dwarf2_section_names macro_dwo; |
| 316 | struct dwarf2_section_names str_dwo; |
| 317 | struct dwarf2_section_names str_offsets_dwo; |
| 318 | struct dwarf2_section_names types_dwo; |
| 319 | struct dwarf2_section_names cu_index; |
| 320 | struct dwarf2_section_names tu_index; |
| 321 | } |
| 322 | dwop_section_names = |
| 323 | { |
| 324 | { ".debug_abbrev.dwo", ".zdebug_abbrev.dwo" }, |
| 325 | { ".debug_info.dwo", ".zdebug_info.dwo" }, |
| 326 | { ".debug_line.dwo", ".zdebug_line.dwo" }, |
| 327 | { ".debug_loc.dwo", ".zdebug_loc.dwo" }, |
| 328 | { ".debug_macinfo.dwo", ".zdebug_macinfo.dwo" }, |
| 329 | { ".debug_macro.dwo", ".zdebug_macro.dwo" }, |
| 330 | { ".debug_str.dwo", ".zdebug_str.dwo" }, |
| 331 | { ".debug_str_offsets.dwo", ".zdebug_str_offsets.dwo" }, |
| 332 | { ".debug_types.dwo", ".zdebug_types.dwo" }, |
| 333 | { ".debug_cu_index", ".zdebug_cu_index" }, |
| 334 | { ".debug_tu_index", ".zdebug_tu_index" }, |
| 335 | }; |
| 336 | |
| 337 | /* local data types */ |
| 338 | |
| 339 | /* The data in a compilation unit header, after target2host |
| 340 | translation, looks like this. */ |
| 341 | struct comp_unit_head |
| 342 | { |
| 343 | unsigned int length; |
| 344 | short version; |
| 345 | unsigned char addr_size; |
| 346 | unsigned char signed_addr_p; |
| 347 | sect_offset abbrev_offset; |
| 348 | |
| 349 | /* Size of file offsets; either 4 or 8. */ |
| 350 | unsigned int offset_size; |
| 351 | |
| 352 | /* Size of the length field; either 4 or 12. */ |
| 353 | unsigned int initial_length_size; |
| 354 | |
| 355 | /* Offset to the first byte of this compilation unit header in the |
| 356 | .debug_info section, for resolving relative reference dies. */ |
| 357 | sect_offset offset; |
| 358 | |
| 359 | /* Offset to first die in this cu from the start of the cu. |
| 360 | This will be the first byte following the compilation unit header. */ |
| 361 | cu_offset first_die_offset; |
| 362 | }; |
| 363 | |
| 364 | /* Type used for delaying computation of method physnames. |
| 365 | See comments for compute_delayed_physnames. */ |
| 366 | struct delayed_method_info |
| 367 | { |
| 368 | /* The type to which the method is attached, i.e., its parent class. */ |
| 369 | struct type *type; |
| 370 | |
| 371 | /* The index of the method in the type's function fieldlists. */ |
| 372 | int fnfield_index; |
| 373 | |
| 374 | /* The index of the method in the fieldlist. */ |
| 375 | int index; |
| 376 | |
| 377 | /* The name of the DIE. */ |
| 378 | const char *name; |
| 379 | |
| 380 | /* The DIE associated with this method. */ |
| 381 | struct die_info *die; |
| 382 | }; |
| 383 | |
| 384 | typedef struct delayed_method_info delayed_method_info; |
| 385 | DEF_VEC_O (delayed_method_info); |
| 386 | |
| 387 | /* Internal state when decoding a particular compilation unit. */ |
| 388 | struct dwarf2_cu |
| 389 | { |
| 390 | /* The objfile containing this compilation unit. */ |
| 391 | struct objfile *objfile; |
| 392 | |
| 393 | /* The header of the compilation unit. */ |
| 394 | struct comp_unit_head header; |
| 395 | |
| 396 | /* Base address of this compilation unit. */ |
| 397 | CORE_ADDR base_address; |
| 398 | |
| 399 | /* Non-zero if base_address has been set. */ |
| 400 | int base_known; |
| 401 | |
| 402 | /* The language we are debugging. */ |
| 403 | enum language language; |
| 404 | const struct language_defn *language_defn; |
| 405 | |
| 406 | const char *producer; |
| 407 | |
| 408 | /* The generic symbol table building routines have separate lists for |
| 409 | file scope symbols and all all other scopes (local scopes). So |
| 410 | we need to select the right one to pass to add_symbol_to_list(). |
| 411 | We do it by keeping a pointer to the correct list in list_in_scope. |
| 412 | |
| 413 | FIXME: The original dwarf code just treated the file scope as the |
| 414 | first local scope, and all other local scopes as nested local |
| 415 | scopes, and worked fine. Check to see if we really need to |
| 416 | distinguish these in buildsym.c. */ |
| 417 | struct pending **list_in_scope; |
| 418 | |
| 419 | /* The abbrev table for this CU. |
| 420 | Normally this points to the abbrev table in the objfile. |
| 421 | But if DWO_UNIT is non-NULL this is the abbrev table in the DWO file. */ |
| 422 | struct abbrev_table *abbrev_table; |
| 423 | |
| 424 | /* Hash table holding all the loaded partial DIEs |
| 425 | with partial_die->offset.SECT_OFF as hash. */ |
| 426 | htab_t partial_dies; |
| 427 | |
| 428 | /* Storage for things with the same lifetime as this read-in compilation |
| 429 | unit, including partial DIEs. */ |
| 430 | struct obstack comp_unit_obstack; |
| 431 | |
| 432 | /* When multiple dwarf2_cu structures are living in memory, this field |
| 433 | chains them all together, so that they can be released efficiently. |
| 434 | We will probably also want a generation counter so that most-recently-used |
| 435 | compilation units are cached... */ |
| 436 | struct dwarf2_per_cu_data *read_in_chain; |
| 437 | |
| 438 | /* Backchain to our per_cu entry if the tree has been built. */ |
| 439 | struct dwarf2_per_cu_data *per_cu; |
| 440 | |
| 441 | /* How many compilation units ago was this CU last referenced? */ |
| 442 | int last_used; |
| 443 | |
| 444 | /* A hash table of DIE cu_offset for following references with |
| 445 | die_info->offset.sect_off as hash. */ |
| 446 | htab_t die_hash; |
| 447 | |
| 448 | /* Full DIEs if read in. */ |
| 449 | struct die_info *dies; |
| 450 | |
| 451 | /* A set of pointers to dwarf2_per_cu_data objects for compilation |
| 452 | units referenced by this one. Only set during full symbol processing; |
| 453 | partial symbol tables do not have dependencies. */ |
| 454 | htab_t dependencies; |
| 455 | |
| 456 | /* Header data from the line table, during full symbol processing. */ |
| 457 | struct line_header *line_header; |
| 458 | |
| 459 | /* A list of methods which need to have physnames computed |
| 460 | after all type information has been read. */ |
| 461 | VEC (delayed_method_info) *method_list; |
| 462 | |
| 463 | /* To be copied to symtab->call_site_htab. */ |
| 464 | htab_t call_site_htab; |
| 465 | |
| 466 | /* Non-NULL if this CU came from a DWO file. |
| 467 | There is an invariant here that is important to remember: |
| 468 | Except for attributes copied from the top level DIE in the "main" |
| 469 | (or "stub") file in preparation for reading the DWO file |
| 470 | (e.g., DW_AT_GNU_addr_base), we KISS: there is only *one* CU. |
| 471 | Either there isn't a DWO file (in which case this is NULL and the point |
| 472 | is moot), or there is and either we're not going to read it (in which |
| 473 | case this is NULL) or there is and we are reading it (in which case this |
| 474 | is non-NULL). */ |
| 475 | struct dwo_unit *dwo_unit; |
| 476 | |
| 477 | /* The DW_AT_addr_base attribute if present, zero otherwise |
| 478 | (zero is a valid value though). |
| 479 | Note this value comes from the stub CU/TU's DIE. */ |
| 480 | ULONGEST addr_base; |
| 481 | |
| 482 | /* The DW_AT_ranges_base attribute if present, zero otherwise |
| 483 | (zero is a valid value though). |
| 484 | Note this value comes from the stub CU/TU's DIE. |
| 485 | Also note that the value is zero in the non-DWO case so this value can |
| 486 | be used without needing to know whether DWO files are in use or not. |
| 487 | N.B. This does not apply to DW_AT_ranges appearing in |
| 488 | DW_TAG_compile_unit dies. This is a bit of a wart, consider if ever |
| 489 | DW_AT_ranges appeared in the DW_TAG_compile_unit of DWO DIEs: then |
| 490 | DW_AT_ranges_base *would* have to be applied, and we'd have to care |
| 491 | whether the DW_AT_ranges attribute came from the skeleton or DWO. */ |
| 492 | ULONGEST ranges_base; |
| 493 | |
| 494 | /* Mark used when releasing cached dies. */ |
| 495 | unsigned int mark : 1; |
| 496 | |
| 497 | /* This CU references .debug_loc. See the symtab->locations_valid field. |
| 498 | This test is imperfect as there may exist optimized debug code not using |
| 499 | any location list and still facing inlining issues if handled as |
| 500 | unoptimized code. For a future better test see GCC PR other/32998. */ |
| 501 | unsigned int has_loclist : 1; |
| 502 | |
| 503 | /* These cache the results for producer_is_* fields. CHECKED_PRODUCER is set |
| 504 | if all the producer_is_* fields are valid. This information is cached |
| 505 | because profiling CU expansion showed excessive time spent in |
| 506 | producer_is_gxx_lt_4_6. */ |
| 507 | unsigned int checked_producer : 1; |
| 508 | unsigned int producer_is_gxx_lt_4_6 : 1; |
| 509 | unsigned int producer_is_gcc_lt_4_3 : 1; |
| 510 | unsigned int producer_is_icc : 1; |
| 511 | }; |
| 512 | |
| 513 | /* Persistent data held for a compilation unit, even when not |
| 514 | processing it. We put a pointer to this structure in the |
| 515 | read_symtab_private field of the psymtab. */ |
| 516 | |
| 517 | struct dwarf2_per_cu_data |
| 518 | { |
| 519 | /* The start offset and length of this compilation unit. |
| 520 | NOTE: Unlike comp_unit_head.length, this length includes |
| 521 | initial_length_size. |
| 522 | If the DIE refers to a DWO file, this is always of the original die, |
| 523 | not the DWO file. */ |
| 524 | sect_offset offset; |
| 525 | unsigned int length; |
| 526 | |
| 527 | /* Flag indicating this compilation unit will be read in before |
| 528 | any of the current compilation units are processed. */ |
| 529 | unsigned int queued : 1; |
| 530 | |
| 531 | /* This flag will be set when reading partial DIEs if we need to load |
| 532 | absolutely all DIEs for this compilation unit, instead of just the ones |
| 533 | we think are interesting. It gets set if we look for a DIE in the |
| 534 | hash table and don't find it. */ |
| 535 | unsigned int load_all_dies : 1; |
| 536 | |
| 537 | /* Non-zero if this CU is from .debug_types. */ |
| 538 | unsigned int is_debug_types : 1; |
| 539 | |
| 540 | /* Non-zero if this CU is from the .dwz file. */ |
| 541 | unsigned int is_dwz : 1; |
| 542 | |
| 543 | /* The section this CU/TU lives in. |
| 544 | If the DIE refers to a DWO file, this is always the original die, |
| 545 | not the DWO file. */ |
| 546 | struct dwarf2_section_info *info_or_types_section; |
| 547 | |
| 548 | /* Set to non-NULL iff this CU is currently loaded. When it gets freed out |
| 549 | of the CU cache it gets reset to NULL again. */ |
| 550 | struct dwarf2_cu *cu; |
| 551 | |
| 552 | /* The corresponding objfile. |
| 553 | Normally we can get the objfile from dwarf2_per_objfile. |
| 554 | However we can enter this file with just a "per_cu" handle. */ |
| 555 | struct objfile *objfile; |
| 556 | |
| 557 | /* When using partial symbol tables, the 'psymtab' field is active. |
| 558 | Otherwise the 'quick' field is active. */ |
| 559 | union |
| 560 | { |
| 561 | /* The partial symbol table associated with this compilation unit, |
| 562 | or NULL for unread partial units. */ |
| 563 | struct partial_symtab *psymtab; |
| 564 | |
| 565 | /* Data needed by the "quick" functions. */ |
| 566 | struct dwarf2_per_cu_quick_data *quick; |
| 567 | } v; |
| 568 | |
| 569 | union |
| 570 | { |
| 571 | /* The CUs we import using DW_TAG_imported_unit. This is filled in |
| 572 | while reading psymtabs, used to compute the psymtab dependencies, |
| 573 | and then cleared. Then it is filled in again while reading full |
| 574 | symbols, and only deleted when the objfile is destroyed. */ |
| 575 | VEC (dwarf2_per_cu_ptr) *imported_symtabs; |
| 576 | |
| 577 | /* Type units are grouped by their DW_AT_stmt_list entry so that they |
| 578 | can share them. If this is a TU, this points to the containing |
| 579 | symtab. */ |
| 580 | struct type_unit_group *type_unit_group; |
| 581 | } s; |
| 582 | }; |
| 583 | |
| 584 | /* Entry in the signatured_types hash table. */ |
| 585 | |
| 586 | struct signatured_type |
| 587 | { |
| 588 | /* The "per_cu" object of this type. |
| 589 | N.B.: This is the first member so that it's easy to convert pointers |
| 590 | between them. */ |
| 591 | struct dwarf2_per_cu_data per_cu; |
| 592 | |
| 593 | /* The type's signature. */ |
| 594 | ULONGEST signature; |
| 595 | |
| 596 | /* Offset in the TU of the type's DIE, as read from the TU header. |
| 597 | If the definition lives in a DWO file, this value is unusable. */ |
| 598 | cu_offset type_offset_in_tu; |
| 599 | |
| 600 | /* Offset in the section of the type's DIE. |
| 601 | If the definition lives in a DWO file, this is the offset in the |
| 602 | .debug_types.dwo section. |
| 603 | The value is zero until the actual value is known. |
| 604 | Zero is otherwise not a valid section offset. */ |
| 605 | sect_offset type_offset_in_section; |
| 606 | }; |
| 607 | |
| 608 | /* A struct that can be used as a hash key for tables based on DW_AT_stmt_list. |
| 609 | This includes type_unit_group and quick_file_names. */ |
| 610 | |
| 611 | struct stmt_list_hash |
| 612 | { |
| 613 | /* The DWO unit this table is from or NULL if there is none. */ |
| 614 | struct dwo_unit *dwo_unit; |
| 615 | |
| 616 | /* Offset in .debug_line or .debug_line.dwo. */ |
| 617 | sect_offset line_offset; |
| 618 | }; |
| 619 | |
| 620 | /* Each element of dwarf2_per_objfile->type_unit_groups is a pointer to |
| 621 | an object of this type. */ |
| 622 | |
| 623 | struct type_unit_group |
| 624 | { |
| 625 | /* dwarf2read.c's main "handle" on the symtab. |
| 626 | To simplify things we create an artificial CU that "includes" all the |
| 627 | type units using this stmt_list so that the rest of the code still has |
| 628 | a "per_cu" handle on the symtab. |
| 629 | This PER_CU is recognized by having no section. */ |
| 630 | #define IS_TYPE_UNIT_GROUP(per_cu) ((per_cu)->info_or_types_section == NULL) |
| 631 | struct dwarf2_per_cu_data per_cu; |
| 632 | |
| 633 | union |
| 634 | { |
| 635 | /* The TUs that share this DW_AT_stmt_list entry. |
| 636 | This is added to while parsing type units to build partial symtabs, |
| 637 | and is deleted afterwards and not used again. */ |
| 638 | VEC (dwarf2_per_cu_ptr) *tus; |
| 639 | |
| 640 | /* When reading the line table in "quick" functions, we need a real TU. |
| 641 | Any will do, we know they all share the same DW_AT_stmt_list entry. |
| 642 | For simplicity's sake, we pick the first one. */ |
| 643 | struct dwarf2_per_cu_data *first_tu; |
| 644 | } t; |
| 645 | |
| 646 | /* The primary symtab. |
| 647 | Type units in a group needn't all be defined in the same source file, |
| 648 | so we create an essentially anonymous symtab as the primary symtab. */ |
| 649 | struct symtab *primary_symtab; |
| 650 | |
| 651 | /* The data used to construct the hash key. */ |
| 652 | struct stmt_list_hash hash; |
| 653 | |
| 654 | /* The number of symtabs from the line header. |
| 655 | The value here must match line_header.num_file_names. */ |
| 656 | unsigned int num_symtabs; |
| 657 | |
| 658 | /* The symbol tables for this TU (obtained from the files listed in |
| 659 | DW_AT_stmt_list). |
| 660 | WARNING: The order of entries here must match the order of entries |
| 661 | in the line header. After the first TU using this type_unit_group, the |
| 662 | line header for the subsequent TUs is recreated from this. This is done |
| 663 | because we need to use the same symtabs for each TU using the same |
| 664 | DW_AT_stmt_list value. Also note that symtabs may be repeated here, |
| 665 | there's no guarantee the line header doesn't have duplicate entries. */ |
| 666 | struct symtab **symtabs; |
| 667 | }; |
| 668 | |
| 669 | /* These sections are what may appear in a DWO file. */ |
| 670 | |
| 671 | struct dwo_sections |
| 672 | { |
| 673 | struct dwarf2_section_info abbrev; |
| 674 | struct dwarf2_section_info line; |
| 675 | struct dwarf2_section_info loc; |
| 676 | struct dwarf2_section_info macinfo; |
| 677 | struct dwarf2_section_info macro; |
| 678 | struct dwarf2_section_info str; |
| 679 | struct dwarf2_section_info str_offsets; |
| 680 | /* In the case of a virtual DWO file, these two are unused. */ |
| 681 | struct dwarf2_section_info info; |
| 682 | VEC (dwarf2_section_info_def) *types; |
| 683 | }; |
| 684 | |
| 685 | /* Common bits of DWO CUs/TUs. */ |
| 686 | |
| 687 | struct dwo_unit |
| 688 | { |
| 689 | /* Backlink to the containing struct dwo_file. */ |
| 690 | struct dwo_file *dwo_file; |
| 691 | |
| 692 | /* The "id" that distinguishes this CU/TU. |
| 693 | .debug_info calls this "dwo_id", .debug_types calls this "signature". |
| 694 | Since signatures came first, we stick with it for consistency. */ |
| 695 | ULONGEST signature; |
| 696 | |
| 697 | /* The section this CU/TU lives in, in the DWO file. */ |
| 698 | struct dwarf2_section_info *info_or_types_section; |
| 699 | |
| 700 | /* Same as dwarf2_per_cu_data:{offset,length} but for the DWO section. */ |
| 701 | sect_offset offset; |
| 702 | unsigned int length; |
| 703 | |
| 704 | /* For types, offset in the type's DIE of the type defined by this TU. */ |
| 705 | cu_offset type_offset_in_tu; |
| 706 | }; |
| 707 | |
| 708 | /* Data for one DWO file. |
| 709 | This includes virtual DWO files that have been packaged into a |
| 710 | DWP file. */ |
| 711 | |
| 712 | struct dwo_file |
| 713 | { |
| 714 | /* The DW_AT_GNU_dwo_name attribute. This is the hash key. |
| 715 | For virtual DWO files the name is constructed from the section offsets |
| 716 | of abbrev,line,loc,str_offsets so that we combine virtual DWO files |
| 717 | from related CU+TUs. */ |
| 718 | const char *name; |
| 719 | |
| 720 | /* The bfd, when the file is open. Otherwise this is NULL. |
| 721 | This is unused(NULL) for virtual DWO files where we use dwp_file.dbfd. */ |
| 722 | bfd *dbfd; |
| 723 | |
| 724 | /* Section info for this file. */ |
| 725 | struct dwo_sections sections; |
| 726 | |
| 727 | /* Table of CUs in the file. |
| 728 | Each element is a struct dwo_unit. */ |
| 729 | htab_t cus; |
| 730 | |
| 731 | /* Table of TUs in the file. |
| 732 | Each element is a struct dwo_unit. */ |
| 733 | htab_t tus; |
| 734 | }; |
| 735 | |
| 736 | /* These sections are what may appear in a DWP file. */ |
| 737 | |
| 738 | struct dwp_sections |
| 739 | { |
| 740 | struct dwarf2_section_info str; |
| 741 | struct dwarf2_section_info cu_index; |
| 742 | struct dwarf2_section_info tu_index; |
| 743 | /* The .debug_info.dwo, .debug_types.dwo, and other sections are referenced |
| 744 | by section number. We don't need to record them here. */ |
| 745 | }; |
| 746 | |
| 747 | /* These sections are what may appear in a virtual DWO file. */ |
| 748 | |
| 749 | struct virtual_dwo_sections |
| 750 | { |
| 751 | struct dwarf2_section_info abbrev; |
| 752 | struct dwarf2_section_info line; |
| 753 | struct dwarf2_section_info loc; |
| 754 | struct dwarf2_section_info macinfo; |
| 755 | struct dwarf2_section_info macro; |
| 756 | struct dwarf2_section_info str_offsets; |
| 757 | /* Each DWP hash table entry records one CU or one TU. |
| 758 | That is recorded here, and copied to dwo_unit.info_or_types_section. */ |
| 759 | struct dwarf2_section_info info_or_types; |
| 760 | }; |
| 761 | |
| 762 | /* Contents of DWP hash tables. */ |
| 763 | |
| 764 | struct dwp_hash_table |
| 765 | { |
| 766 | uint32_t nr_units, nr_slots; |
| 767 | const gdb_byte *hash_table, *unit_table, *section_pool; |
| 768 | }; |
| 769 | |
| 770 | /* Data for one DWP file. */ |
| 771 | |
| 772 | struct dwp_file |
| 773 | { |
| 774 | /* Name of the file. */ |
| 775 | const char *name; |
| 776 | |
| 777 | /* The bfd, when the file is open. Otherwise this is NULL. */ |
| 778 | bfd *dbfd; |
| 779 | |
| 780 | /* Section info for this file. */ |
| 781 | struct dwp_sections sections; |
| 782 | |
| 783 | /* Table of CUs in the file. */ |
| 784 | const struct dwp_hash_table *cus; |
| 785 | |
| 786 | /* Table of TUs in the file. */ |
| 787 | const struct dwp_hash_table *tus; |
| 788 | |
| 789 | /* Table of loaded CUs/TUs. Each entry is a struct dwo_unit *. */ |
| 790 | htab_t loaded_cutus; |
| 791 | |
| 792 | /* Table to map ELF section numbers to their sections. */ |
| 793 | unsigned int num_sections; |
| 794 | asection **elf_sections; |
| 795 | }; |
| 796 | |
| 797 | /* This represents a '.dwz' file. */ |
| 798 | |
| 799 | struct dwz_file |
| 800 | { |
| 801 | /* A dwz file can only contain a few sections. */ |
| 802 | struct dwarf2_section_info abbrev; |
| 803 | struct dwarf2_section_info info; |
| 804 | struct dwarf2_section_info str; |
| 805 | struct dwarf2_section_info line; |
| 806 | struct dwarf2_section_info macro; |
| 807 | struct dwarf2_section_info gdb_index; |
| 808 | |
| 809 | /* The dwz's BFD. */ |
| 810 | bfd *dwz_bfd; |
| 811 | }; |
| 812 | |
| 813 | /* Struct used to pass misc. parameters to read_die_and_children, et |
| 814 | al. which are used for both .debug_info and .debug_types dies. |
| 815 | All parameters here are unchanging for the life of the call. This |
| 816 | struct exists to abstract away the constant parameters of die reading. */ |
| 817 | |
| 818 | struct die_reader_specs |
| 819 | { |
| 820 | /* die_section->asection->owner. */ |
| 821 | bfd* abfd; |
| 822 | |
| 823 | /* The CU of the DIE we are parsing. */ |
| 824 | struct dwarf2_cu *cu; |
| 825 | |
| 826 | /* Non-NULL if reading a DWO file (including one packaged into a DWP). */ |
| 827 | struct dwo_file *dwo_file; |
| 828 | |
| 829 | /* The section the die comes from. |
| 830 | This is either .debug_info or .debug_types, or the .dwo variants. */ |
| 831 | struct dwarf2_section_info *die_section; |
| 832 | |
| 833 | /* die_section->buffer. */ |
| 834 | gdb_byte *buffer; |
| 835 | |
| 836 | /* The end of the buffer. */ |
| 837 | const gdb_byte *buffer_end; |
| 838 | }; |
| 839 | |
| 840 | /* Type of function passed to init_cutu_and_read_dies, et.al. */ |
| 841 | typedef void (die_reader_func_ftype) (const struct die_reader_specs *reader, |
| 842 | gdb_byte *info_ptr, |
| 843 | struct die_info *comp_unit_die, |
| 844 | int has_children, |
| 845 | void *data); |
| 846 | |
| 847 | /* The line number information for a compilation unit (found in the |
| 848 | .debug_line section) begins with a "statement program header", |
| 849 | which contains the following information. */ |
| 850 | struct line_header |
| 851 | { |
| 852 | unsigned int total_length; |
| 853 | unsigned short version; |
| 854 | unsigned int header_length; |
| 855 | unsigned char minimum_instruction_length; |
| 856 | unsigned char maximum_ops_per_instruction; |
| 857 | unsigned char default_is_stmt; |
| 858 | int line_base; |
| 859 | unsigned char line_range; |
| 860 | unsigned char opcode_base; |
| 861 | |
| 862 | /* standard_opcode_lengths[i] is the number of operands for the |
| 863 | standard opcode whose value is i. This means that |
| 864 | standard_opcode_lengths[0] is unused, and the last meaningful |
| 865 | element is standard_opcode_lengths[opcode_base - 1]. */ |
| 866 | unsigned char *standard_opcode_lengths; |
| 867 | |
| 868 | /* The include_directories table. NOTE! These strings are not |
| 869 | allocated with xmalloc; instead, they are pointers into |
| 870 | debug_line_buffer. If you try to free them, `free' will get |
| 871 | indigestion. */ |
| 872 | unsigned int num_include_dirs, include_dirs_size; |
| 873 | char **include_dirs; |
| 874 | |
| 875 | /* The file_names table. NOTE! These strings are not allocated |
| 876 | with xmalloc; instead, they are pointers into debug_line_buffer. |
| 877 | Don't try to free them directly. */ |
| 878 | unsigned int num_file_names, file_names_size; |
| 879 | struct file_entry |
| 880 | { |
| 881 | char *name; |
| 882 | unsigned int dir_index; |
| 883 | unsigned int mod_time; |
| 884 | unsigned int length; |
| 885 | int included_p; /* Non-zero if referenced by the Line Number Program. */ |
| 886 | struct symtab *symtab; /* The associated symbol table, if any. */ |
| 887 | } *file_names; |
| 888 | |
| 889 | /* The start and end of the statement program following this |
| 890 | header. These point into dwarf2_per_objfile->line_buffer. */ |
| 891 | gdb_byte *statement_program_start, *statement_program_end; |
| 892 | }; |
| 893 | |
| 894 | /* When we construct a partial symbol table entry we only |
| 895 | need this much information. */ |
| 896 | struct partial_die_info |
| 897 | { |
| 898 | /* Offset of this DIE. */ |
| 899 | sect_offset offset; |
| 900 | |
| 901 | /* DWARF-2 tag for this DIE. */ |
| 902 | ENUM_BITFIELD(dwarf_tag) tag : 16; |
| 903 | |
| 904 | /* Assorted flags describing the data found in this DIE. */ |
| 905 | unsigned int has_children : 1; |
| 906 | unsigned int is_external : 1; |
| 907 | unsigned int is_declaration : 1; |
| 908 | unsigned int has_type : 1; |
| 909 | unsigned int has_specification : 1; |
| 910 | unsigned int has_pc_info : 1; |
| 911 | unsigned int may_be_inlined : 1; |
| 912 | |
| 913 | /* Flag set if the SCOPE field of this structure has been |
| 914 | computed. */ |
| 915 | unsigned int scope_set : 1; |
| 916 | |
| 917 | /* Flag set if the DIE has a byte_size attribute. */ |
| 918 | unsigned int has_byte_size : 1; |
| 919 | |
| 920 | /* Flag set if any of the DIE's children are template arguments. */ |
| 921 | unsigned int has_template_arguments : 1; |
| 922 | |
| 923 | /* Flag set if fixup_partial_die has been called on this die. */ |
| 924 | unsigned int fixup_called : 1; |
| 925 | |
| 926 | /* Flag set if DW_TAG_imported_unit uses DW_FORM_GNU_ref_alt. */ |
| 927 | unsigned int is_dwz : 1; |
| 928 | |
| 929 | /* Flag set if spec_offset uses DW_FORM_GNU_ref_alt. */ |
| 930 | unsigned int spec_is_dwz : 1; |
| 931 | |
| 932 | /* The name of this DIE. Normally the value of DW_AT_name, but |
| 933 | sometimes a default name for unnamed DIEs. */ |
| 934 | char *name; |
| 935 | |
| 936 | /* The linkage name, if present. */ |
| 937 | const char *linkage_name; |
| 938 | |
| 939 | /* The scope to prepend to our children. This is generally |
| 940 | allocated on the comp_unit_obstack, so will disappear |
| 941 | when this compilation unit leaves the cache. */ |
| 942 | char *scope; |
| 943 | |
| 944 | /* Some data associated with the partial DIE. The tag determines |
| 945 | which field is live. */ |
| 946 | union |
| 947 | { |
| 948 | /* The location description associated with this DIE, if any. */ |
| 949 | struct dwarf_block *locdesc; |
| 950 | /* The offset of an import, for DW_TAG_imported_unit. */ |
| 951 | sect_offset offset; |
| 952 | } d; |
| 953 | |
| 954 | /* If HAS_PC_INFO, the PC range associated with this DIE. */ |
| 955 | CORE_ADDR lowpc; |
| 956 | CORE_ADDR highpc; |
| 957 | |
| 958 | /* Pointer into the info_buffer (or types_buffer) pointing at the target of |
| 959 | DW_AT_sibling, if any. */ |
| 960 | /* NOTE: This member isn't strictly necessary, read_partial_die could |
| 961 | return DW_AT_sibling values to its caller load_partial_dies. */ |
| 962 | gdb_byte *sibling; |
| 963 | |
| 964 | /* If HAS_SPECIFICATION, the offset of the DIE referred to by |
| 965 | DW_AT_specification (or DW_AT_abstract_origin or |
| 966 | DW_AT_extension). */ |
| 967 | sect_offset spec_offset; |
| 968 | |
| 969 | /* Pointers to this DIE's parent, first child, and next sibling, |
| 970 | if any. */ |
| 971 | struct partial_die_info *die_parent, *die_child, *die_sibling; |
| 972 | }; |
| 973 | |
| 974 | /* This data structure holds the information of an abbrev. */ |
| 975 | struct abbrev_info |
| 976 | { |
| 977 | unsigned int number; /* number identifying abbrev */ |
| 978 | enum dwarf_tag tag; /* dwarf tag */ |
| 979 | unsigned short has_children; /* boolean */ |
| 980 | unsigned short num_attrs; /* number of attributes */ |
| 981 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
| 982 | struct abbrev_info *next; /* next in chain */ |
| 983 | }; |
| 984 | |
| 985 | struct attr_abbrev |
| 986 | { |
| 987 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 988 | ENUM_BITFIELD(dwarf_form) form : 16; |
| 989 | }; |
| 990 | |
| 991 | /* Size of abbrev_table.abbrev_hash_table. */ |
| 992 | #define ABBREV_HASH_SIZE 121 |
| 993 | |
| 994 | /* Top level data structure to contain an abbreviation table. */ |
| 995 | |
| 996 | struct abbrev_table |
| 997 | { |
| 998 | /* Where the abbrev table came from. |
| 999 | This is used as a sanity check when the table is used. */ |
| 1000 | sect_offset offset; |
| 1001 | |
| 1002 | /* Storage for the abbrev table. */ |
| 1003 | struct obstack abbrev_obstack; |
| 1004 | |
| 1005 | /* Hash table of abbrevs. |
| 1006 | This is an array of size ABBREV_HASH_SIZE allocated in abbrev_obstack. |
| 1007 | It could be statically allocated, but the previous code didn't so we |
| 1008 | don't either. */ |
| 1009 | struct abbrev_info **abbrevs; |
| 1010 | }; |
| 1011 | |
| 1012 | /* Attributes have a name and a value. */ |
| 1013 | struct attribute |
| 1014 | { |
| 1015 | ENUM_BITFIELD(dwarf_attribute) name : 16; |
| 1016 | ENUM_BITFIELD(dwarf_form) form : 15; |
| 1017 | |
| 1018 | /* Has DW_STRING already been updated by dwarf2_canonicalize_name? This |
| 1019 | field should be in u.str (existing only for DW_STRING) but it is kept |
| 1020 | here for better struct attribute alignment. */ |
| 1021 | unsigned int string_is_canonical : 1; |
| 1022 | |
| 1023 | union |
| 1024 | { |
| 1025 | char *str; |
| 1026 | struct dwarf_block *blk; |
| 1027 | ULONGEST unsnd; |
| 1028 | LONGEST snd; |
| 1029 | CORE_ADDR addr; |
| 1030 | struct signatured_type *signatured_type; |
| 1031 | } |
| 1032 | u; |
| 1033 | }; |
| 1034 | |
| 1035 | /* This data structure holds a complete die structure. */ |
| 1036 | struct die_info |
| 1037 | { |
| 1038 | /* DWARF-2 tag for this DIE. */ |
| 1039 | ENUM_BITFIELD(dwarf_tag) tag : 16; |
| 1040 | |
| 1041 | /* Number of attributes */ |
| 1042 | unsigned char num_attrs; |
| 1043 | |
| 1044 | /* True if we're presently building the full type name for the |
| 1045 | type derived from this DIE. */ |
| 1046 | unsigned char building_fullname : 1; |
| 1047 | |
| 1048 | /* Abbrev number */ |
| 1049 | unsigned int abbrev; |
| 1050 | |
| 1051 | /* Offset in .debug_info or .debug_types section. */ |
| 1052 | sect_offset offset; |
| 1053 | |
| 1054 | /* The dies in a compilation unit form an n-ary tree. PARENT |
| 1055 | points to this die's parent; CHILD points to the first child of |
| 1056 | this node; and all the children of a given node are chained |
| 1057 | together via their SIBLING fields. */ |
| 1058 | struct die_info *child; /* Its first child, if any. */ |
| 1059 | struct die_info *sibling; /* Its next sibling, if any. */ |
| 1060 | struct die_info *parent; /* Its parent, if any. */ |
| 1061 | |
| 1062 | /* An array of attributes, with NUM_ATTRS elements. There may be |
| 1063 | zero, but it's not common and zero-sized arrays are not |
| 1064 | sufficiently portable C. */ |
| 1065 | struct attribute attrs[1]; |
| 1066 | }; |
| 1067 | |
| 1068 | /* Get at parts of an attribute structure. */ |
| 1069 | |
| 1070 | #define DW_STRING(attr) ((attr)->u.str) |
| 1071 | #define DW_STRING_IS_CANONICAL(attr) ((attr)->string_is_canonical) |
| 1072 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
| 1073 | #define DW_BLOCK(attr) ((attr)->u.blk) |
| 1074 | #define DW_SND(attr) ((attr)->u.snd) |
| 1075 | #define DW_ADDR(attr) ((attr)->u.addr) |
| 1076 | #define DW_SIGNATURED_TYPE(attr) ((attr)->u.signatured_type) |
| 1077 | |
| 1078 | /* Blocks are a bunch of untyped bytes. */ |
| 1079 | struct dwarf_block |
| 1080 | { |
| 1081 | size_t size; |
| 1082 | |
| 1083 | /* Valid only if SIZE is not zero. */ |
| 1084 | gdb_byte *data; |
| 1085 | }; |
| 1086 | |
| 1087 | #ifndef ATTR_ALLOC_CHUNK |
| 1088 | #define ATTR_ALLOC_CHUNK 4 |
| 1089 | #endif |
| 1090 | |
| 1091 | /* Allocate fields for structs, unions and enums in this size. */ |
| 1092 | #ifndef DW_FIELD_ALLOC_CHUNK |
| 1093 | #define DW_FIELD_ALLOC_CHUNK 4 |
| 1094 | #endif |
| 1095 | |
| 1096 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
| 1097 | but this would require a corresponding change in unpack_field_as_long |
| 1098 | and friends. */ |
| 1099 | static int bits_per_byte = 8; |
| 1100 | |
| 1101 | /* The routines that read and process dies for a C struct or C++ class |
| 1102 | pass lists of data member fields and lists of member function fields |
| 1103 | in an instance of a field_info structure, as defined below. */ |
| 1104 | struct field_info |
| 1105 | { |
| 1106 | /* List of data member and baseclasses fields. */ |
| 1107 | struct nextfield |
| 1108 | { |
| 1109 | struct nextfield *next; |
| 1110 | int accessibility; |
| 1111 | int virtuality; |
| 1112 | struct field field; |
| 1113 | } |
| 1114 | *fields, *baseclasses; |
| 1115 | |
| 1116 | /* Number of fields (including baseclasses). */ |
| 1117 | int nfields; |
| 1118 | |
| 1119 | /* Number of baseclasses. */ |
| 1120 | int nbaseclasses; |
| 1121 | |
| 1122 | /* Set if the accesibility of one of the fields is not public. */ |
| 1123 | int non_public_fields; |
| 1124 | |
| 1125 | /* Member function fields array, entries are allocated in the order they |
| 1126 | are encountered in the object file. */ |
| 1127 | struct nextfnfield |
| 1128 | { |
| 1129 | struct nextfnfield *next; |
| 1130 | struct fn_field fnfield; |
| 1131 | } |
| 1132 | *fnfields; |
| 1133 | |
| 1134 | /* Member function fieldlist array, contains name of possibly overloaded |
| 1135 | member function, number of overloaded member functions and a pointer |
| 1136 | to the head of the member function field chain. */ |
| 1137 | struct fnfieldlist |
| 1138 | { |
| 1139 | char *name; |
| 1140 | int length; |
| 1141 | struct nextfnfield *head; |
| 1142 | } |
| 1143 | *fnfieldlists; |
| 1144 | |
| 1145 | /* Number of entries in the fnfieldlists array. */ |
| 1146 | int nfnfields; |
| 1147 | |
| 1148 | /* typedefs defined inside this class. TYPEDEF_FIELD_LIST contains head of |
| 1149 | a NULL terminated list of TYPEDEF_FIELD_LIST_COUNT elements. */ |
| 1150 | struct typedef_field_list |
| 1151 | { |
| 1152 | struct typedef_field field; |
| 1153 | struct typedef_field_list *next; |
| 1154 | } |
| 1155 | *typedef_field_list; |
| 1156 | unsigned typedef_field_list_count; |
| 1157 | }; |
| 1158 | |
| 1159 | /* One item on the queue of compilation units to read in full symbols |
| 1160 | for. */ |
| 1161 | struct dwarf2_queue_item |
| 1162 | { |
| 1163 | struct dwarf2_per_cu_data *per_cu; |
| 1164 | enum language pretend_language; |
| 1165 | struct dwarf2_queue_item *next; |
| 1166 | }; |
| 1167 | |
| 1168 | /* The current queue. */ |
| 1169 | static struct dwarf2_queue_item *dwarf2_queue, *dwarf2_queue_tail; |
| 1170 | |
| 1171 | /* Loaded secondary compilation units are kept in memory until they |
| 1172 | have not been referenced for the processing of this many |
| 1173 | compilation units. Set this to zero to disable caching. Cache |
| 1174 | sizes of up to at least twenty will improve startup time for |
| 1175 | typical inter-CU-reference binaries, at an obvious memory cost. */ |
| 1176 | static int dwarf2_max_cache_age = 5; |
| 1177 | static void |
| 1178 | show_dwarf2_max_cache_age (struct ui_file *file, int from_tty, |
| 1179 | struct cmd_list_element *c, const char *value) |
| 1180 | { |
| 1181 | fprintf_filtered (file, _("The upper bound on the age of cached " |
| 1182 | "dwarf2 compilation units is %s.\n"), |
| 1183 | value); |
| 1184 | } |
| 1185 | |
| 1186 | |
| 1187 | /* Various complaints about symbol reading that don't abort the process. */ |
| 1188 | |
| 1189 | static void |
| 1190 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) |
| 1191 | { |
| 1192 | complaint (&symfile_complaints, |
| 1193 | _("statement list doesn't fit in .debug_line section")); |
| 1194 | } |
| 1195 | |
| 1196 | static void |
| 1197 | dwarf2_debug_line_missing_file_complaint (void) |
| 1198 | { |
| 1199 | complaint (&symfile_complaints, |
| 1200 | _(".debug_line section has line data without a file")); |
| 1201 | } |
| 1202 | |
| 1203 | static void |
| 1204 | dwarf2_debug_line_missing_end_sequence_complaint (void) |
| 1205 | { |
| 1206 | complaint (&symfile_complaints, |
| 1207 | _(".debug_line section has line " |
| 1208 | "program sequence without an end")); |
| 1209 | } |
| 1210 | |
| 1211 | static void |
| 1212 | dwarf2_complex_location_expr_complaint (void) |
| 1213 | { |
| 1214 | complaint (&symfile_complaints, _("location expression too complex")); |
| 1215 | } |
| 1216 | |
| 1217 | static void |
| 1218 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, |
| 1219 | int arg3) |
| 1220 | { |
| 1221 | complaint (&symfile_complaints, |
| 1222 | _("const value length mismatch for '%s', got %d, expected %d"), |
| 1223 | arg1, arg2, arg3); |
| 1224 | } |
| 1225 | |
| 1226 | static void |
| 1227 | dwarf2_section_buffer_overflow_complaint (struct dwarf2_section_info *section) |
| 1228 | { |
| 1229 | complaint (&symfile_complaints, |
| 1230 | _("debug info runs off end of %s section" |
| 1231 | " [in module %s]"), |
| 1232 | section->asection->name, |
| 1233 | bfd_get_filename (section->asection->owner)); |
| 1234 | } |
| 1235 | |
| 1236 | static void |
| 1237 | dwarf2_macro_malformed_definition_complaint (const char *arg1) |
| 1238 | { |
| 1239 | complaint (&symfile_complaints, |
| 1240 | _("macro debug info contains a " |
| 1241 | "malformed macro definition:\n`%s'"), |
| 1242 | arg1); |
| 1243 | } |
| 1244 | |
| 1245 | static void |
| 1246 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) |
| 1247 | { |
| 1248 | complaint (&symfile_complaints, |
| 1249 | _("invalid attribute class or form for '%s' in '%s'"), |
| 1250 | arg1, arg2); |
| 1251 | } |
| 1252 | |
| 1253 | /* local function prototypes */ |
| 1254 | |
| 1255 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
| 1256 | |
| 1257 | static void dwarf2_create_include_psymtab (char *, struct partial_symtab *, |
| 1258 | struct objfile *); |
| 1259 | |
| 1260 | static void dwarf2_find_base_address (struct die_info *die, |
| 1261 | struct dwarf2_cu *cu); |
| 1262 | |
| 1263 | static void dwarf2_build_psymtabs_hard (struct objfile *); |
| 1264 | |
| 1265 | static void scan_partial_symbols (struct partial_die_info *, |
| 1266 | CORE_ADDR *, CORE_ADDR *, |
| 1267 | int, struct dwarf2_cu *); |
| 1268 | |
| 1269 | static void add_partial_symbol (struct partial_die_info *, |
| 1270 | struct dwarf2_cu *); |
| 1271 | |
| 1272 | static void add_partial_namespace (struct partial_die_info *pdi, |
| 1273 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 1274 | int need_pc, struct dwarf2_cu *cu); |
| 1275 | |
| 1276 | static void add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
| 1277 | CORE_ADDR *highpc, int need_pc, |
| 1278 | struct dwarf2_cu *cu); |
| 1279 | |
| 1280 | static void add_partial_enumeration (struct partial_die_info *enum_pdi, |
| 1281 | struct dwarf2_cu *cu); |
| 1282 | |
| 1283 | static void add_partial_subprogram (struct partial_die_info *pdi, |
| 1284 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 1285 | int need_pc, struct dwarf2_cu *cu); |
| 1286 | |
| 1287 | static void dwarf2_psymtab_to_symtab (struct objfile *, |
| 1288 | struct partial_symtab *); |
| 1289 | |
| 1290 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
| 1291 | |
| 1292 | static struct abbrev_info *abbrev_table_lookup_abbrev |
| 1293 | (const struct abbrev_table *, unsigned int); |
| 1294 | |
| 1295 | static struct abbrev_table *abbrev_table_read_table |
| 1296 | (struct dwarf2_section_info *, sect_offset); |
| 1297 | |
| 1298 | static void abbrev_table_free (struct abbrev_table *); |
| 1299 | |
| 1300 | static void abbrev_table_free_cleanup (void *); |
| 1301 | |
| 1302 | static void dwarf2_read_abbrevs (struct dwarf2_cu *, |
| 1303 | struct dwarf2_section_info *); |
| 1304 | |
| 1305 | static void dwarf2_free_abbrev_table (void *); |
| 1306 | |
| 1307 | static unsigned int peek_abbrev_code (bfd *, gdb_byte *); |
| 1308 | |
| 1309 | static struct partial_die_info *load_partial_dies |
| 1310 | (const struct die_reader_specs *, gdb_byte *, int); |
| 1311 | |
| 1312 | static gdb_byte *read_partial_die (const struct die_reader_specs *, |
| 1313 | struct partial_die_info *, |
| 1314 | struct abbrev_info *, |
| 1315 | unsigned int, |
| 1316 | gdb_byte *); |
| 1317 | |
| 1318 | static struct partial_die_info *find_partial_die (sect_offset, int, |
| 1319 | struct dwarf2_cu *); |
| 1320 | |
| 1321 | static void fixup_partial_die (struct partial_die_info *, |
| 1322 | struct dwarf2_cu *); |
| 1323 | |
| 1324 | static gdb_byte *read_attribute (const struct die_reader_specs *, |
| 1325 | struct attribute *, struct attr_abbrev *, |
| 1326 | gdb_byte *); |
| 1327 | |
| 1328 | static unsigned int read_1_byte (bfd *, const gdb_byte *); |
| 1329 | |
| 1330 | static int read_1_signed_byte (bfd *, const gdb_byte *); |
| 1331 | |
| 1332 | static unsigned int read_2_bytes (bfd *, const gdb_byte *); |
| 1333 | |
| 1334 | static unsigned int read_4_bytes (bfd *, const gdb_byte *); |
| 1335 | |
| 1336 | static ULONGEST read_8_bytes (bfd *, const gdb_byte *); |
| 1337 | |
| 1338 | static CORE_ADDR read_address (bfd *, gdb_byte *ptr, struct dwarf2_cu *, |
| 1339 | unsigned int *); |
| 1340 | |
| 1341 | static LONGEST read_initial_length (bfd *, gdb_byte *, unsigned int *); |
| 1342 | |
| 1343 | static LONGEST read_checked_initial_length_and_offset |
| 1344 | (bfd *, gdb_byte *, const struct comp_unit_head *, |
| 1345 | unsigned int *, unsigned int *); |
| 1346 | |
| 1347 | static LONGEST read_offset (bfd *, gdb_byte *, const struct comp_unit_head *, |
| 1348 | unsigned int *); |
| 1349 | |
| 1350 | static LONGEST read_offset_1 (bfd *, gdb_byte *, unsigned int); |
| 1351 | |
| 1352 | static sect_offset read_abbrev_offset (struct dwarf2_section_info *, |
| 1353 | sect_offset); |
| 1354 | |
| 1355 | static gdb_byte *read_n_bytes (bfd *, gdb_byte *, unsigned int); |
| 1356 | |
| 1357 | static char *read_direct_string (bfd *, gdb_byte *, unsigned int *); |
| 1358 | |
| 1359 | static char *read_indirect_string (bfd *, gdb_byte *, |
| 1360 | const struct comp_unit_head *, |
| 1361 | unsigned int *); |
| 1362 | |
| 1363 | static char *read_indirect_string_from_dwz (struct dwz_file *, LONGEST); |
| 1364 | |
| 1365 | static ULONGEST read_unsigned_leb128 (bfd *, gdb_byte *, unsigned int *); |
| 1366 | |
| 1367 | static LONGEST read_signed_leb128 (bfd *, gdb_byte *, unsigned int *); |
| 1368 | |
| 1369 | static CORE_ADDR read_addr_index_from_leb128 (struct dwarf2_cu *, gdb_byte *, |
| 1370 | unsigned int *); |
| 1371 | |
| 1372 | static char *read_str_index (const struct die_reader_specs *reader, |
| 1373 | struct dwarf2_cu *cu, ULONGEST str_index); |
| 1374 | |
| 1375 | static void set_cu_language (unsigned int, struct dwarf2_cu *); |
| 1376 | |
| 1377 | static struct attribute *dwarf2_attr (struct die_info *, unsigned int, |
| 1378 | struct dwarf2_cu *); |
| 1379 | |
| 1380 | static struct attribute *dwarf2_attr_no_follow (struct die_info *, |
| 1381 | unsigned int); |
| 1382 | |
| 1383 | static int dwarf2_flag_true_p (struct die_info *die, unsigned name, |
| 1384 | struct dwarf2_cu *cu); |
| 1385 | |
| 1386 | static int die_is_declaration (struct die_info *, struct dwarf2_cu *cu); |
| 1387 | |
| 1388 | static struct die_info *die_specification (struct die_info *die, |
| 1389 | struct dwarf2_cu **); |
| 1390 | |
| 1391 | static void free_line_header (struct line_header *lh); |
| 1392 | |
| 1393 | static void add_file_name (struct line_header *, char *, unsigned int, |
| 1394 | unsigned int, unsigned int); |
| 1395 | |
| 1396 | static struct line_header *dwarf_decode_line_header (unsigned int offset, |
| 1397 | struct dwarf2_cu *cu); |
| 1398 | |
| 1399 | static void dwarf_decode_lines (struct line_header *, const char *, |
| 1400 | struct dwarf2_cu *, struct partial_symtab *, |
| 1401 | int); |
| 1402 | |
| 1403 | static void dwarf2_start_subfile (char *, const char *, const char *); |
| 1404 | |
| 1405 | static void dwarf2_start_symtab (struct dwarf2_cu *, |
| 1406 | char *, char *, CORE_ADDR); |
| 1407 | |
| 1408 | static struct symbol *new_symbol (struct die_info *, struct type *, |
| 1409 | struct dwarf2_cu *); |
| 1410 | |
| 1411 | static struct symbol *new_symbol_full (struct die_info *, struct type *, |
| 1412 | struct dwarf2_cu *, struct symbol *); |
| 1413 | |
| 1414 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
| 1415 | struct dwarf2_cu *); |
| 1416 | |
| 1417 | static void dwarf2_const_value_attr (struct attribute *attr, |
| 1418 | struct type *type, |
| 1419 | const char *name, |
| 1420 | struct obstack *obstack, |
| 1421 | struct dwarf2_cu *cu, LONGEST *value, |
| 1422 | gdb_byte **bytes, |
| 1423 | struct dwarf2_locexpr_baton **baton); |
| 1424 | |
| 1425 | static struct type *die_type (struct die_info *, struct dwarf2_cu *); |
| 1426 | |
| 1427 | static int need_gnat_info (struct dwarf2_cu *); |
| 1428 | |
| 1429 | static struct type *die_descriptive_type (struct die_info *, |
| 1430 | struct dwarf2_cu *); |
| 1431 | |
| 1432 | static void set_descriptive_type (struct type *, struct die_info *, |
| 1433 | struct dwarf2_cu *); |
| 1434 | |
| 1435 | static struct type *die_containing_type (struct die_info *, |
| 1436 | struct dwarf2_cu *); |
| 1437 | |
| 1438 | static struct type *lookup_die_type (struct die_info *, struct attribute *, |
| 1439 | struct dwarf2_cu *); |
| 1440 | |
| 1441 | static struct type *read_type_die (struct die_info *, struct dwarf2_cu *); |
| 1442 | |
| 1443 | static struct type *read_type_die_1 (struct die_info *, struct dwarf2_cu *); |
| 1444 | |
| 1445 | static const char *determine_prefix (struct die_info *die, struct dwarf2_cu *); |
| 1446 | |
| 1447 | static char *typename_concat (struct obstack *obs, const char *prefix, |
| 1448 | const char *suffix, int physname, |
| 1449 | struct dwarf2_cu *cu); |
| 1450 | |
| 1451 | static void read_file_scope (struct die_info *, struct dwarf2_cu *); |
| 1452 | |
| 1453 | static void read_type_unit_scope (struct die_info *, struct dwarf2_cu *); |
| 1454 | |
| 1455 | static void read_func_scope (struct die_info *, struct dwarf2_cu *); |
| 1456 | |
| 1457 | static void read_lexical_block_scope (struct die_info *, struct dwarf2_cu *); |
| 1458 | |
| 1459 | static void read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu); |
| 1460 | |
| 1461 | static int dwarf2_ranges_read (unsigned, CORE_ADDR *, CORE_ADDR *, |
| 1462 | struct dwarf2_cu *, struct partial_symtab *); |
| 1463 | |
| 1464 | static int dwarf2_get_pc_bounds (struct die_info *, |
| 1465 | CORE_ADDR *, CORE_ADDR *, struct dwarf2_cu *, |
| 1466 | struct partial_symtab *); |
| 1467 | |
| 1468 | static void get_scope_pc_bounds (struct die_info *, |
| 1469 | CORE_ADDR *, CORE_ADDR *, |
| 1470 | struct dwarf2_cu *); |
| 1471 | |
| 1472 | static void dwarf2_record_block_ranges (struct die_info *, struct block *, |
| 1473 | CORE_ADDR, struct dwarf2_cu *); |
| 1474 | |
| 1475 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
| 1476 | struct dwarf2_cu *); |
| 1477 | |
| 1478 | static void dwarf2_attach_fields_to_type (struct field_info *, |
| 1479 | struct type *, struct dwarf2_cu *); |
| 1480 | |
| 1481 | static void dwarf2_add_member_fn (struct field_info *, |
| 1482 | struct die_info *, struct type *, |
| 1483 | struct dwarf2_cu *); |
| 1484 | |
| 1485 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
| 1486 | struct type *, |
| 1487 | struct dwarf2_cu *); |
| 1488 | |
| 1489 | static void process_structure_scope (struct die_info *, struct dwarf2_cu *); |
| 1490 | |
| 1491 | static void read_common_block (struct die_info *, struct dwarf2_cu *); |
| 1492 | |
| 1493 | static void read_namespace (struct die_info *die, struct dwarf2_cu *); |
| 1494 | |
| 1495 | static void read_module (struct die_info *die, struct dwarf2_cu *cu); |
| 1496 | |
| 1497 | static void read_import_statement (struct die_info *die, struct dwarf2_cu *); |
| 1498 | |
| 1499 | static struct type *read_module_type (struct die_info *die, |
| 1500 | struct dwarf2_cu *cu); |
| 1501 | |
| 1502 | static const char *namespace_name (struct die_info *die, |
| 1503 | int *is_anonymous, struct dwarf2_cu *); |
| 1504 | |
| 1505 | static void process_enumeration_scope (struct die_info *, struct dwarf2_cu *); |
| 1506 | |
| 1507 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct dwarf2_cu *); |
| 1508 | |
| 1509 | static enum dwarf_array_dim_ordering read_array_order (struct die_info *, |
| 1510 | struct dwarf2_cu *); |
| 1511 | |
| 1512 | static struct die_info *read_die_and_children (const struct die_reader_specs *, |
| 1513 | gdb_byte *info_ptr, |
| 1514 | gdb_byte **new_info_ptr, |
| 1515 | struct die_info *parent); |
| 1516 | |
| 1517 | static struct die_info *read_die_and_siblings (const struct die_reader_specs *, |
| 1518 | gdb_byte *info_ptr, |
| 1519 | gdb_byte **new_info_ptr, |
| 1520 | struct die_info *parent); |
| 1521 | |
| 1522 | static gdb_byte *read_full_die_1 (const struct die_reader_specs *, |
| 1523 | struct die_info **, gdb_byte *, int *, int); |
| 1524 | |
| 1525 | static gdb_byte *read_full_die (const struct die_reader_specs *, |
| 1526 | struct die_info **, gdb_byte *, int *); |
| 1527 | |
| 1528 | static void process_die (struct die_info *, struct dwarf2_cu *); |
| 1529 | |
| 1530 | static char *dwarf2_canonicalize_name (char *, struct dwarf2_cu *, |
| 1531 | struct obstack *); |
| 1532 | |
| 1533 | static char *dwarf2_name (struct die_info *die, struct dwarf2_cu *); |
| 1534 | |
| 1535 | static const char *dwarf2_full_name (char *name, |
| 1536 | struct die_info *die, |
| 1537 | struct dwarf2_cu *cu); |
| 1538 | |
| 1539 | static struct die_info *dwarf2_extension (struct die_info *die, |
| 1540 | struct dwarf2_cu **); |
| 1541 | |
| 1542 | static const char *dwarf_tag_name (unsigned int); |
| 1543 | |
| 1544 | static const char *dwarf_attr_name (unsigned int); |
| 1545 | |
| 1546 | static const char *dwarf_form_name (unsigned int); |
| 1547 | |
| 1548 | static char *dwarf_bool_name (unsigned int); |
| 1549 | |
| 1550 | static const char *dwarf_type_encoding_name (unsigned int); |
| 1551 | |
| 1552 | static struct die_info *sibling_die (struct die_info *); |
| 1553 | |
| 1554 | static void dump_die_shallow (struct ui_file *, int indent, struct die_info *); |
| 1555 | |
| 1556 | static void dump_die_for_error (struct die_info *); |
| 1557 | |
| 1558 | static void dump_die_1 (struct ui_file *, int level, int max_level, |
| 1559 | struct die_info *); |
| 1560 | |
| 1561 | /*static*/ void dump_die (struct die_info *, int max_level); |
| 1562 | |
| 1563 | static void store_in_ref_table (struct die_info *, |
| 1564 | struct dwarf2_cu *); |
| 1565 | |
| 1566 | static int is_ref_attr (struct attribute *); |
| 1567 | |
| 1568 | static sect_offset dwarf2_get_ref_die_offset (struct attribute *); |
| 1569 | |
| 1570 | static LONGEST dwarf2_get_attr_constant_value (struct attribute *, int); |
| 1571 | |
| 1572 | static struct die_info *follow_die_ref_or_sig (struct die_info *, |
| 1573 | struct attribute *, |
| 1574 | struct dwarf2_cu **); |
| 1575 | |
| 1576 | static struct die_info *follow_die_ref (struct die_info *, |
| 1577 | struct attribute *, |
| 1578 | struct dwarf2_cu **); |
| 1579 | |
| 1580 | static struct die_info *follow_die_sig (struct die_info *, |
| 1581 | struct attribute *, |
| 1582 | struct dwarf2_cu **); |
| 1583 | |
| 1584 | static struct signatured_type *lookup_signatured_type_at_offset |
| 1585 | (struct objfile *objfile, |
| 1586 | struct dwarf2_section_info *section, sect_offset offset); |
| 1587 | |
| 1588 | static void load_full_type_unit (struct dwarf2_per_cu_data *per_cu); |
| 1589 | |
| 1590 | static void read_signatured_type (struct signatured_type *); |
| 1591 | |
| 1592 | static struct type_unit_group *get_type_unit_group |
| 1593 | (struct dwarf2_cu *, struct attribute *); |
| 1594 | |
| 1595 | static void build_type_unit_groups (die_reader_func_ftype *, void *); |
| 1596 | |
| 1597 | /* memory allocation interface */ |
| 1598 | |
| 1599 | static struct dwarf_block *dwarf_alloc_block (struct dwarf2_cu *); |
| 1600 | |
| 1601 | static struct die_info *dwarf_alloc_die (struct dwarf2_cu *, int); |
| 1602 | |
| 1603 | static void dwarf_decode_macros (struct dwarf2_cu *, unsigned int, |
| 1604 | char *, int); |
| 1605 | |
| 1606 | static int attr_form_is_block (struct attribute *); |
| 1607 | |
| 1608 | static int attr_form_is_section_offset (struct attribute *); |
| 1609 | |
| 1610 | static int attr_form_is_constant (struct attribute *); |
| 1611 | |
| 1612 | static void fill_in_loclist_baton (struct dwarf2_cu *cu, |
| 1613 | struct dwarf2_loclist_baton *baton, |
| 1614 | struct attribute *attr); |
| 1615 | |
| 1616 | static void dwarf2_symbol_mark_computed (struct attribute *attr, |
| 1617 | struct symbol *sym, |
| 1618 | struct dwarf2_cu *cu); |
| 1619 | |
| 1620 | static gdb_byte *skip_one_die (const struct die_reader_specs *reader, |
| 1621 | gdb_byte *info_ptr, |
| 1622 | struct abbrev_info *abbrev); |
| 1623 | |
| 1624 | static void free_stack_comp_unit (void *); |
| 1625 | |
| 1626 | static hashval_t partial_die_hash (const void *item); |
| 1627 | |
| 1628 | static int partial_die_eq (const void *item_lhs, const void *item_rhs); |
| 1629 | |
| 1630 | static struct dwarf2_per_cu_data *dwarf2_find_containing_comp_unit |
| 1631 | (sect_offset offset, unsigned int offset_in_dwz, struct objfile *objfile); |
| 1632 | |
| 1633 | static void init_one_comp_unit (struct dwarf2_cu *cu, |
| 1634 | struct dwarf2_per_cu_data *per_cu); |
| 1635 | |
| 1636 | static void prepare_one_comp_unit (struct dwarf2_cu *cu, |
| 1637 | struct die_info *comp_unit_die, |
| 1638 | enum language pretend_language); |
| 1639 | |
| 1640 | static void free_heap_comp_unit (void *); |
| 1641 | |
| 1642 | static void free_cached_comp_units (void *); |
| 1643 | |
| 1644 | static void age_cached_comp_units (void); |
| 1645 | |
| 1646 | static void free_one_cached_comp_unit (struct dwarf2_per_cu_data *); |
| 1647 | |
| 1648 | static struct type *set_die_type (struct die_info *, struct type *, |
| 1649 | struct dwarf2_cu *); |
| 1650 | |
| 1651 | static void create_all_comp_units (struct objfile *); |
| 1652 | |
| 1653 | static int create_all_type_units (struct objfile *); |
| 1654 | |
| 1655 | static void load_full_comp_unit (struct dwarf2_per_cu_data *, |
| 1656 | enum language); |
| 1657 | |
| 1658 | static void process_full_comp_unit (struct dwarf2_per_cu_data *, |
| 1659 | enum language); |
| 1660 | |
| 1661 | static void process_full_type_unit (struct dwarf2_per_cu_data *, |
| 1662 | enum language); |
| 1663 | |
| 1664 | static void dwarf2_add_dependence (struct dwarf2_cu *, |
| 1665 | struct dwarf2_per_cu_data *); |
| 1666 | |
| 1667 | static void dwarf2_mark (struct dwarf2_cu *); |
| 1668 | |
| 1669 | static void dwarf2_clear_marks (struct dwarf2_per_cu_data *); |
| 1670 | |
| 1671 | static struct type *get_die_type_at_offset (sect_offset, |
| 1672 | struct dwarf2_per_cu_data *per_cu); |
| 1673 | |
| 1674 | static struct type *get_die_type (struct die_info *die, struct dwarf2_cu *cu); |
| 1675 | |
| 1676 | static void dwarf2_release_queue (void *dummy); |
| 1677 | |
| 1678 | static void queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
| 1679 | enum language pretend_language); |
| 1680 | |
| 1681 | static int maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
| 1682 | struct dwarf2_per_cu_data *per_cu, |
| 1683 | enum language pretend_language); |
| 1684 | |
| 1685 | static void process_queue (void); |
| 1686 | |
| 1687 | static void find_file_and_directory (struct die_info *die, |
| 1688 | struct dwarf2_cu *cu, |
| 1689 | char **name, char **comp_dir); |
| 1690 | |
| 1691 | static char *file_full_name (int file, struct line_header *lh, |
| 1692 | const char *comp_dir); |
| 1693 | |
| 1694 | static gdb_byte *read_and_check_comp_unit_head |
| 1695 | (struct comp_unit_head *header, |
| 1696 | struct dwarf2_section_info *section, |
| 1697 | struct dwarf2_section_info *abbrev_section, gdb_byte *info_ptr, |
| 1698 | int is_debug_types_section); |
| 1699 | |
| 1700 | static void init_cutu_and_read_dies |
| 1701 | (struct dwarf2_per_cu_data *this_cu, struct abbrev_table *abbrev_table, |
| 1702 | int use_existing_cu, int keep, |
| 1703 | die_reader_func_ftype *die_reader_func, void *data); |
| 1704 | |
| 1705 | static void init_cutu_and_read_dies_simple |
| 1706 | (struct dwarf2_per_cu_data *this_cu, |
| 1707 | die_reader_func_ftype *die_reader_func, void *data); |
| 1708 | |
| 1709 | static htab_t allocate_signatured_type_table (struct objfile *objfile); |
| 1710 | |
| 1711 | static htab_t allocate_dwo_unit_table (struct objfile *objfile); |
| 1712 | |
| 1713 | static struct dwo_unit *lookup_dwo_comp_unit |
| 1714 | (struct dwarf2_per_cu_data *, const char *, const char *, ULONGEST); |
| 1715 | |
| 1716 | static struct dwo_unit *lookup_dwo_type_unit |
| 1717 | (struct signatured_type *, const char *, const char *); |
| 1718 | |
| 1719 | static void free_dwo_file_cleanup (void *); |
| 1720 | |
| 1721 | static void process_cu_includes (void); |
| 1722 | |
| 1723 | static void check_producer (struct dwarf2_cu *cu); |
| 1724 | |
| 1725 | #if WORDS_BIGENDIAN |
| 1726 | |
| 1727 | /* Convert VALUE between big- and little-endian. */ |
| 1728 | static offset_type |
| 1729 | byte_swap (offset_type value) |
| 1730 | { |
| 1731 | offset_type result; |
| 1732 | |
| 1733 | result = (value & 0xff) << 24; |
| 1734 | result |= (value & 0xff00) << 8; |
| 1735 | result |= (value & 0xff0000) >> 8; |
| 1736 | result |= (value & 0xff000000) >> 24; |
| 1737 | return result; |
| 1738 | } |
| 1739 | |
| 1740 | #define MAYBE_SWAP(V) byte_swap (V) |
| 1741 | |
| 1742 | #else |
| 1743 | #define MAYBE_SWAP(V) (V) |
| 1744 | #endif /* WORDS_BIGENDIAN */ |
| 1745 | |
| 1746 | /* The suffix for an index file. */ |
| 1747 | #define INDEX_SUFFIX ".gdb-index" |
| 1748 | |
| 1749 | static const char *dwarf2_physname (char *name, struct die_info *die, |
| 1750 | struct dwarf2_cu *cu); |
| 1751 | |
| 1752 | /* Try to locate the sections we need for DWARF 2 debugging |
| 1753 | information and return true if we have enough to do something. |
| 1754 | NAMES points to the dwarf2 section names, or is NULL if the standard |
| 1755 | ELF names are used. */ |
| 1756 | |
| 1757 | int |
| 1758 | dwarf2_has_info (struct objfile *objfile, |
| 1759 | const struct dwarf2_debug_sections *names) |
| 1760 | { |
| 1761 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 1762 | if (!dwarf2_per_objfile) |
| 1763 | { |
| 1764 | /* Initialize per-objfile state. */ |
| 1765 | struct dwarf2_per_objfile *data |
| 1766 | = obstack_alloc (&objfile->objfile_obstack, sizeof (*data)); |
| 1767 | |
| 1768 | memset (data, 0, sizeof (*data)); |
| 1769 | set_objfile_data (objfile, dwarf2_objfile_data_key, data); |
| 1770 | dwarf2_per_objfile = data; |
| 1771 | |
| 1772 | bfd_map_over_sections (objfile->obfd, dwarf2_locate_sections, |
| 1773 | (void *) names); |
| 1774 | dwarf2_per_objfile->objfile = objfile; |
| 1775 | } |
| 1776 | return (dwarf2_per_objfile->info.asection != NULL |
| 1777 | && dwarf2_per_objfile->abbrev.asection != NULL); |
| 1778 | } |
| 1779 | |
| 1780 | /* When loading sections, we look either for uncompressed section or for |
| 1781 | compressed section names. */ |
| 1782 | |
| 1783 | static int |
| 1784 | section_is_p (const char *section_name, |
| 1785 | const struct dwarf2_section_names *names) |
| 1786 | { |
| 1787 | if (names->normal != NULL |
| 1788 | && strcmp (section_name, names->normal) == 0) |
| 1789 | return 1; |
| 1790 | if (names->compressed != NULL |
| 1791 | && strcmp (section_name, names->compressed) == 0) |
| 1792 | return 1; |
| 1793 | return 0; |
| 1794 | } |
| 1795 | |
| 1796 | /* This function is mapped across the sections and remembers the |
| 1797 | offset and size of each of the debugging sections we are interested |
| 1798 | in. */ |
| 1799 | |
| 1800 | static void |
| 1801 | dwarf2_locate_sections (bfd *abfd, asection *sectp, void *vnames) |
| 1802 | { |
| 1803 | const struct dwarf2_debug_sections *names; |
| 1804 | flagword aflag = bfd_get_section_flags (abfd, sectp); |
| 1805 | |
| 1806 | if (vnames == NULL) |
| 1807 | names = &dwarf2_elf_names; |
| 1808 | else |
| 1809 | names = (const struct dwarf2_debug_sections *) vnames; |
| 1810 | |
| 1811 | if ((aflag & SEC_HAS_CONTENTS) == 0) |
| 1812 | { |
| 1813 | } |
| 1814 | else if (section_is_p (sectp->name, &names->info)) |
| 1815 | { |
| 1816 | dwarf2_per_objfile->info.asection = sectp; |
| 1817 | dwarf2_per_objfile->info.size = bfd_get_section_size (sectp); |
| 1818 | } |
| 1819 | else if (section_is_p (sectp->name, &names->abbrev)) |
| 1820 | { |
| 1821 | dwarf2_per_objfile->abbrev.asection = sectp; |
| 1822 | dwarf2_per_objfile->abbrev.size = bfd_get_section_size (sectp); |
| 1823 | } |
| 1824 | else if (section_is_p (sectp->name, &names->line)) |
| 1825 | { |
| 1826 | dwarf2_per_objfile->line.asection = sectp; |
| 1827 | dwarf2_per_objfile->line.size = bfd_get_section_size (sectp); |
| 1828 | } |
| 1829 | else if (section_is_p (sectp->name, &names->loc)) |
| 1830 | { |
| 1831 | dwarf2_per_objfile->loc.asection = sectp; |
| 1832 | dwarf2_per_objfile->loc.size = bfd_get_section_size (sectp); |
| 1833 | } |
| 1834 | else if (section_is_p (sectp->name, &names->macinfo)) |
| 1835 | { |
| 1836 | dwarf2_per_objfile->macinfo.asection = sectp; |
| 1837 | dwarf2_per_objfile->macinfo.size = bfd_get_section_size (sectp); |
| 1838 | } |
| 1839 | else if (section_is_p (sectp->name, &names->macro)) |
| 1840 | { |
| 1841 | dwarf2_per_objfile->macro.asection = sectp; |
| 1842 | dwarf2_per_objfile->macro.size = bfd_get_section_size (sectp); |
| 1843 | } |
| 1844 | else if (section_is_p (sectp->name, &names->str)) |
| 1845 | { |
| 1846 | dwarf2_per_objfile->str.asection = sectp; |
| 1847 | dwarf2_per_objfile->str.size = bfd_get_section_size (sectp); |
| 1848 | } |
| 1849 | else if (section_is_p (sectp->name, &names->addr)) |
| 1850 | { |
| 1851 | dwarf2_per_objfile->addr.asection = sectp; |
| 1852 | dwarf2_per_objfile->addr.size = bfd_get_section_size (sectp); |
| 1853 | } |
| 1854 | else if (section_is_p (sectp->name, &names->frame)) |
| 1855 | { |
| 1856 | dwarf2_per_objfile->frame.asection = sectp; |
| 1857 | dwarf2_per_objfile->frame.size = bfd_get_section_size (sectp); |
| 1858 | } |
| 1859 | else if (section_is_p (sectp->name, &names->eh_frame)) |
| 1860 | { |
| 1861 | dwarf2_per_objfile->eh_frame.asection = sectp; |
| 1862 | dwarf2_per_objfile->eh_frame.size = bfd_get_section_size (sectp); |
| 1863 | } |
| 1864 | else if (section_is_p (sectp->name, &names->ranges)) |
| 1865 | { |
| 1866 | dwarf2_per_objfile->ranges.asection = sectp; |
| 1867 | dwarf2_per_objfile->ranges.size = bfd_get_section_size (sectp); |
| 1868 | } |
| 1869 | else if (section_is_p (sectp->name, &names->types)) |
| 1870 | { |
| 1871 | struct dwarf2_section_info type_section; |
| 1872 | |
| 1873 | memset (&type_section, 0, sizeof (type_section)); |
| 1874 | type_section.asection = sectp; |
| 1875 | type_section.size = bfd_get_section_size (sectp); |
| 1876 | |
| 1877 | VEC_safe_push (dwarf2_section_info_def, dwarf2_per_objfile->types, |
| 1878 | &type_section); |
| 1879 | } |
| 1880 | else if (section_is_p (sectp->name, &names->gdb_index)) |
| 1881 | { |
| 1882 | dwarf2_per_objfile->gdb_index.asection = sectp; |
| 1883 | dwarf2_per_objfile->gdb_index.size = bfd_get_section_size (sectp); |
| 1884 | } |
| 1885 | |
| 1886 | if ((bfd_get_section_flags (abfd, sectp) & SEC_LOAD) |
| 1887 | && bfd_section_vma (abfd, sectp) == 0) |
| 1888 | dwarf2_per_objfile->has_section_at_zero = 1; |
| 1889 | } |
| 1890 | |
| 1891 | /* A helper function that decides whether a section is empty, |
| 1892 | or not present. */ |
| 1893 | |
| 1894 | static int |
| 1895 | dwarf2_section_empty_p (struct dwarf2_section_info *info) |
| 1896 | { |
| 1897 | return info->asection == NULL || info->size == 0; |
| 1898 | } |
| 1899 | |
| 1900 | /* Read the contents of the section INFO. |
| 1901 | OBJFILE is the main object file, but not necessarily the file where |
| 1902 | the section comes from. E.g., for DWO files INFO->asection->owner |
| 1903 | is the bfd of the DWO file. |
| 1904 | If the section is compressed, uncompress it before returning. */ |
| 1905 | |
| 1906 | static void |
| 1907 | dwarf2_read_section (struct objfile *objfile, struct dwarf2_section_info *info) |
| 1908 | { |
| 1909 | asection *sectp = info->asection; |
| 1910 | bfd *abfd; |
| 1911 | gdb_byte *buf, *retbuf; |
| 1912 | unsigned char header[4]; |
| 1913 | |
| 1914 | if (info->readin) |
| 1915 | return; |
| 1916 | info->buffer = NULL; |
| 1917 | info->readin = 1; |
| 1918 | |
| 1919 | if (dwarf2_section_empty_p (info)) |
| 1920 | return; |
| 1921 | |
| 1922 | abfd = sectp->owner; |
| 1923 | |
| 1924 | /* If the section has relocations, we must read it ourselves. |
| 1925 | Otherwise we attach it to the BFD. */ |
| 1926 | if ((sectp->flags & SEC_RELOC) == 0) |
| 1927 | { |
| 1928 | const gdb_byte *bytes = gdb_bfd_map_section (sectp, &info->size); |
| 1929 | |
| 1930 | /* We have to cast away const here for historical reasons. |
| 1931 | Fixing dwarf2read to be const-correct would be quite nice. */ |
| 1932 | info->buffer = (gdb_byte *) bytes; |
| 1933 | return; |
| 1934 | } |
| 1935 | |
| 1936 | buf = obstack_alloc (&objfile->objfile_obstack, info->size); |
| 1937 | info->buffer = buf; |
| 1938 | |
| 1939 | /* When debugging .o files, we may need to apply relocations; see |
| 1940 | http://sourceware.org/ml/gdb-patches/2002-04/msg00136.html . |
| 1941 | We never compress sections in .o files, so we only need to |
| 1942 | try this when the section is not compressed. */ |
| 1943 | retbuf = symfile_relocate_debug_section (objfile, sectp, buf); |
| 1944 | if (retbuf != NULL) |
| 1945 | { |
| 1946 | info->buffer = retbuf; |
| 1947 | return; |
| 1948 | } |
| 1949 | |
| 1950 | if (bfd_seek (abfd, sectp->filepos, SEEK_SET) != 0 |
| 1951 | || bfd_bread (buf, info->size, abfd) != info->size) |
| 1952 | error (_("Dwarf Error: Can't read DWARF data from '%s'"), |
| 1953 | bfd_get_filename (abfd)); |
| 1954 | } |
| 1955 | |
| 1956 | /* A helper function that returns the size of a section in a safe way. |
| 1957 | If you are positive that the section has been read before using the |
| 1958 | size, then it is safe to refer to the dwarf2_section_info object's |
| 1959 | "size" field directly. In other cases, you must call this |
| 1960 | function, because for compressed sections the size field is not set |
| 1961 | correctly until the section has been read. */ |
| 1962 | |
| 1963 | static bfd_size_type |
| 1964 | dwarf2_section_size (struct objfile *objfile, |
| 1965 | struct dwarf2_section_info *info) |
| 1966 | { |
| 1967 | if (!info->readin) |
| 1968 | dwarf2_read_section (objfile, info); |
| 1969 | return info->size; |
| 1970 | } |
| 1971 | |
| 1972 | /* Fill in SECTP, BUFP and SIZEP with section info, given OBJFILE and |
| 1973 | SECTION_NAME. */ |
| 1974 | |
| 1975 | void |
| 1976 | dwarf2_get_section_info (struct objfile *objfile, |
| 1977 | enum dwarf2_section_enum sect, |
| 1978 | asection **sectp, gdb_byte **bufp, |
| 1979 | bfd_size_type *sizep) |
| 1980 | { |
| 1981 | struct dwarf2_per_objfile *data |
| 1982 | = objfile_data (objfile, dwarf2_objfile_data_key); |
| 1983 | struct dwarf2_section_info *info; |
| 1984 | |
| 1985 | /* We may see an objfile without any DWARF, in which case we just |
| 1986 | return nothing. */ |
| 1987 | if (data == NULL) |
| 1988 | { |
| 1989 | *sectp = NULL; |
| 1990 | *bufp = NULL; |
| 1991 | *sizep = 0; |
| 1992 | return; |
| 1993 | } |
| 1994 | switch (sect) |
| 1995 | { |
| 1996 | case DWARF2_DEBUG_FRAME: |
| 1997 | info = &data->frame; |
| 1998 | break; |
| 1999 | case DWARF2_EH_FRAME: |
| 2000 | info = &data->eh_frame; |
| 2001 | break; |
| 2002 | default: |
| 2003 | gdb_assert_not_reached ("unexpected section"); |
| 2004 | } |
| 2005 | |
| 2006 | dwarf2_read_section (objfile, info); |
| 2007 | |
| 2008 | *sectp = info->asection; |
| 2009 | *bufp = info->buffer; |
| 2010 | *sizep = info->size; |
| 2011 | } |
| 2012 | |
| 2013 | /* A helper function to find the sections for a .dwz file. */ |
| 2014 | |
| 2015 | static void |
| 2016 | locate_dwz_sections (bfd *abfd, asection *sectp, void *arg) |
| 2017 | { |
| 2018 | struct dwz_file *dwz_file = arg; |
| 2019 | |
| 2020 | /* Note that we only support the standard ELF names, because .dwz |
| 2021 | is ELF-only (at the time of writing). */ |
| 2022 | if (section_is_p (sectp->name, &dwarf2_elf_names.abbrev)) |
| 2023 | { |
| 2024 | dwz_file->abbrev.asection = sectp; |
| 2025 | dwz_file->abbrev.size = bfd_get_section_size (sectp); |
| 2026 | } |
| 2027 | else if (section_is_p (sectp->name, &dwarf2_elf_names.info)) |
| 2028 | { |
| 2029 | dwz_file->info.asection = sectp; |
| 2030 | dwz_file->info.size = bfd_get_section_size (sectp); |
| 2031 | } |
| 2032 | else if (section_is_p (sectp->name, &dwarf2_elf_names.str)) |
| 2033 | { |
| 2034 | dwz_file->str.asection = sectp; |
| 2035 | dwz_file->str.size = bfd_get_section_size (sectp); |
| 2036 | } |
| 2037 | else if (section_is_p (sectp->name, &dwarf2_elf_names.line)) |
| 2038 | { |
| 2039 | dwz_file->line.asection = sectp; |
| 2040 | dwz_file->line.size = bfd_get_section_size (sectp); |
| 2041 | } |
| 2042 | else if (section_is_p (sectp->name, &dwarf2_elf_names.macro)) |
| 2043 | { |
| 2044 | dwz_file->macro.asection = sectp; |
| 2045 | dwz_file->macro.size = bfd_get_section_size (sectp); |
| 2046 | } |
| 2047 | else if (section_is_p (sectp->name, &dwarf2_elf_names.gdb_index)) |
| 2048 | { |
| 2049 | dwz_file->gdb_index.asection = sectp; |
| 2050 | dwz_file->gdb_index.size = bfd_get_section_size (sectp); |
| 2051 | } |
| 2052 | } |
| 2053 | |
| 2054 | /* Open the separate '.dwz' debug file, if needed. Error if the file |
| 2055 | cannot be found. */ |
| 2056 | |
| 2057 | static struct dwz_file * |
| 2058 | dwarf2_get_dwz_file (void) |
| 2059 | { |
| 2060 | bfd *abfd, *dwz_bfd; |
| 2061 | asection *section; |
| 2062 | gdb_byte *data; |
| 2063 | struct cleanup *cleanup; |
| 2064 | const char *filename; |
| 2065 | struct dwz_file *result; |
| 2066 | |
| 2067 | if (dwarf2_per_objfile->dwz_file != NULL) |
| 2068 | return dwarf2_per_objfile->dwz_file; |
| 2069 | |
| 2070 | abfd = dwarf2_per_objfile->objfile->obfd; |
| 2071 | section = bfd_get_section_by_name (abfd, ".gnu_debugaltlink"); |
| 2072 | if (section == NULL) |
| 2073 | error (_("could not find '.gnu_debugaltlink' section")); |
| 2074 | if (!bfd_malloc_and_get_section (abfd, section, &data)) |
| 2075 | error (_("could not read '.gnu_debugaltlink' section: %s"), |
| 2076 | bfd_errmsg (bfd_get_error ())); |
| 2077 | cleanup = make_cleanup (xfree, data); |
| 2078 | |
| 2079 | filename = data; |
| 2080 | if (!IS_ABSOLUTE_PATH (filename)) |
| 2081 | { |
| 2082 | char *abs = gdb_realpath (dwarf2_per_objfile->objfile->name); |
| 2083 | char *rel; |
| 2084 | |
| 2085 | make_cleanup (xfree, abs); |
| 2086 | abs = ldirname (abs); |
| 2087 | make_cleanup (xfree, abs); |
| 2088 | |
| 2089 | rel = concat (abs, SLASH_STRING, filename, (char *) NULL); |
| 2090 | make_cleanup (xfree, rel); |
| 2091 | filename = rel; |
| 2092 | } |
| 2093 | |
| 2094 | /* The format is just a NUL-terminated file name, followed by the |
| 2095 | build-id. For now, though, we ignore the build-id. */ |
| 2096 | dwz_bfd = gdb_bfd_open (filename, gnutarget, -1); |
| 2097 | if (dwz_bfd == NULL) |
| 2098 | error (_("could not read '%s': %s"), filename, |
| 2099 | bfd_errmsg (bfd_get_error ())); |
| 2100 | |
| 2101 | if (!bfd_check_format (dwz_bfd, bfd_object)) |
| 2102 | { |
| 2103 | gdb_bfd_unref (dwz_bfd); |
| 2104 | error (_("file '%s' was not usable: %s"), filename, |
| 2105 | bfd_errmsg (bfd_get_error ())); |
| 2106 | } |
| 2107 | |
| 2108 | result = OBSTACK_ZALLOC (&dwarf2_per_objfile->objfile->objfile_obstack, |
| 2109 | struct dwz_file); |
| 2110 | result->dwz_bfd = dwz_bfd; |
| 2111 | |
| 2112 | bfd_map_over_sections (dwz_bfd, locate_dwz_sections, result); |
| 2113 | |
| 2114 | do_cleanups (cleanup); |
| 2115 | |
| 2116 | dwarf2_per_objfile->dwz_file = result; |
| 2117 | return result; |
| 2118 | } |
| 2119 | \f |
| 2120 | /* DWARF quick_symbols_functions support. */ |
| 2121 | |
| 2122 | /* TUs can share .debug_line entries, and there can be a lot more TUs than |
| 2123 | unique line tables, so we maintain a separate table of all .debug_line |
| 2124 | derived entries to support the sharing. |
| 2125 | All the quick functions need is the list of file names. We discard the |
| 2126 | line_header when we're done and don't need to record it here. */ |
| 2127 | struct quick_file_names |
| 2128 | { |
| 2129 | /* The data used to construct the hash key. */ |
| 2130 | struct stmt_list_hash hash; |
| 2131 | |
| 2132 | /* The number of entries in file_names, real_names. */ |
| 2133 | unsigned int num_file_names; |
| 2134 | |
| 2135 | /* The file names from the line table, after being run through |
| 2136 | file_full_name. */ |
| 2137 | const char **file_names; |
| 2138 | |
| 2139 | /* The file names from the line table after being run through |
| 2140 | gdb_realpath. These are computed lazily. */ |
| 2141 | const char **real_names; |
| 2142 | }; |
| 2143 | |
| 2144 | /* When using the index (and thus not using psymtabs), each CU has an |
| 2145 | object of this type. This is used to hold information needed by |
| 2146 | the various "quick" methods. */ |
| 2147 | struct dwarf2_per_cu_quick_data |
| 2148 | { |
| 2149 | /* The file table. This can be NULL if there was no file table |
| 2150 | or it's currently not read in. |
| 2151 | NOTE: This points into dwarf2_per_objfile->quick_file_names_table. */ |
| 2152 | struct quick_file_names *file_names; |
| 2153 | |
| 2154 | /* The corresponding symbol table. This is NULL if symbols for this |
| 2155 | CU have not yet been read. */ |
| 2156 | struct symtab *symtab; |
| 2157 | |
| 2158 | /* A temporary mark bit used when iterating over all CUs in |
| 2159 | expand_symtabs_matching. */ |
| 2160 | unsigned int mark : 1; |
| 2161 | |
| 2162 | /* True if we've tried to read the file table and found there isn't one. |
| 2163 | There will be no point in trying to read it again next time. */ |
| 2164 | unsigned int no_file_data : 1; |
| 2165 | }; |
| 2166 | |
| 2167 | /* Utility hash function for a stmt_list_hash. */ |
| 2168 | |
| 2169 | static hashval_t |
| 2170 | hash_stmt_list_entry (const struct stmt_list_hash *stmt_list_hash) |
| 2171 | { |
| 2172 | hashval_t v = 0; |
| 2173 | |
| 2174 | if (stmt_list_hash->dwo_unit != NULL) |
| 2175 | v += (uintptr_t) stmt_list_hash->dwo_unit->dwo_file; |
| 2176 | v += stmt_list_hash->line_offset.sect_off; |
| 2177 | return v; |
| 2178 | } |
| 2179 | |
| 2180 | /* Utility equality function for a stmt_list_hash. */ |
| 2181 | |
| 2182 | static int |
| 2183 | eq_stmt_list_entry (const struct stmt_list_hash *lhs, |
| 2184 | const struct stmt_list_hash *rhs) |
| 2185 | { |
| 2186 | if ((lhs->dwo_unit != NULL) != (rhs->dwo_unit != NULL)) |
| 2187 | return 0; |
| 2188 | if (lhs->dwo_unit != NULL |
| 2189 | && lhs->dwo_unit->dwo_file != rhs->dwo_unit->dwo_file) |
| 2190 | return 0; |
| 2191 | |
| 2192 | return lhs->line_offset.sect_off == rhs->line_offset.sect_off; |
| 2193 | } |
| 2194 | |
| 2195 | /* Hash function for a quick_file_names. */ |
| 2196 | |
| 2197 | static hashval_t |
| 2198 | hash_file_name_entry (const void *e) |
| 2199 | { |
| 2200 | const struct quick_file_names *file_data = e; |
| 2201 | |
| 2202 | return hash_stmt_list_entry (&file_data->hash); |
| 2203 | } |
| 2204 | |
| 2205 | /* Equality function for a quick_file_names. */ |
| 2206 | |
| 2207 | static int |
| 2208 | eq_file_name_entry (const void *a, const void *b) |
| 2209 | { |
| 2210 | const struct quick_file_names *ea = a; |
| 2211 | const struct quick_file_names *eb = b; |
| 2212 | |
| 2213 | return eq_stmt_list_entry (&ea->hash, &eb->hash); |
| 2214 | } |
| 2215 | |
| 2216 | /* Delete function for a quick_file_names. */ |
| 2217 | |
| 2218 | static void |
| 2219 | delete_file_name_entry (void *e) |
| 2220 | { |
| 2221 | struct quick_file_names *file_data = e; |
| 2222 | int i; |
| 2223 | |
| 2224 | for (i = 0; i < file_data->num_file_names; ++i) |
| 2225 | { |
| 2226 | xfree ((void*) file_data->file_names[i]); |
| 2227 | if (file_data->real_names) |
| 2228 | xfree ((void*) file_data->real_names[i]); |
| 2229 | } |
| 2230 | |
| 2231 | /* The space for the struct itself lives on objfile_obstack, |
| 2232 | so we don't free it here. */ |
| 2233 | } |
| 2234 | |
| 2235 | /* Create a quick_file_names hash table. */ |
| 2236 | |
| 2237 | static htab_t |
| 2238 | create_quick_file_names_table (unsigned int nr_initial_entries) |
| 2239 | { |
| 2240 | return htab_create_alloc (nr_initial_entries, |
| 2241 | hash_file_name_entry, eq_file_name_entry, |
| 2242 | delete_file_name_entry, xcalloc, xfree); |
| 2243 | } |
| 2244 | |
| 2245 | /* Read in PER_CU->CU. This function is unrelated to symtabs, symtab would |
| 2246 | have to be created afterwards. You should call age_cached_comp_units after |
| 2247 | processing PER_CU->CU. dw2_setup must have been already called. */ |
| 2248 | |
| 2249 | static void |
| 2250 | load_cu (struct dwarf2_per_cu_data *per_cu) |
| 2251 | { |
| 2252 | if (per_cu->is_debug_types) |
| 2253 | load_full_type_unit (per_cu); |
| 2254 | else |
| 2255 | load_full_comp_unit (per_cu, language_minimal); |
| 2256 | |
| 2257 | gdb_assert (per_cu->cu != NULL); |
| 2258 | |
| 2259 | dwarf2_find_base_address (per_cu->cu->dies, per_cu->cu); |
| 2260 | } |
| 2261 | |
| 2262 | /* Read in the symbols for PER_CU. */ |
| 2263 | |
| 2264 | static void |
| 2265 | dw2_do_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
| 2266 | { |
| 2267 | struct cleanup *back_to; |
| 2268 | |
| 2269 | /* Skip type_unit_groups, reading the type units they contain |
| 2270 | is handled elsewhere. */ |
| 2271 | if (IS_TYPE_UNIT_GROUP (per_cu)) |
| 2272 | return; |
| 2273 | |
| 2274 | back_to = make_cleanup (dwarf2_release_queue, NULL); |
| 2275 | |
| 2276 | if (dwarf2_per_objfile->using_index |
| 2277 | ? per_cu->v.quick->symtab == NULL |
| 2278 | : (per_cu->v.psymtab == NULL || !per_cu->v.psymtab->readin)) |
| 2279 | { |
| 2280 | queue_comp_unit (per_cu, language_minimal); |
| 2281 | load_cu (per_cu); |
| 2282 | } |
| 2283 | |
| 2284 | process_queue (); |
| 2285 | |
| 2286 | /* Age the cache, releasing compilation units that have not |
| 2287 | been used recently. */ |
| 2288 | age_cached_comp_units (); |
| 2289 | |
| 2290 | do_cleanups (back_to); |
| 2291 | } |
| 2292 | |
| 2293 | /* Ensure that the symbols for PER_CU have been read in. OBJFILE is |
| 2294 | the objfile from which this CU came. Returns the resulting symbol |
| 2295 | table. */ |
| 2296 | |
| 2297 | static struct symtab * |
| 2298 | dw2_instantiate_symtab (struct dwarf2_per_cu_data *per_cu) |
| 2299 | { |
| 2300 | gdb_assert (dwarf2_per_objfile->using_index); |
| 2301 | if (!per_cu->v.quick->symtab) |
| 2302 | { |
| 2303 | struct cleanup *back_to = make_cleanup (free_cached_comp_units, NULL); |
| 2304 | increment_reading_symtab (); |
| 2305 | dw2_do_instantiate_symtab (per_cu); |
| 2306 | process_cu_includes (); |
| 2307 | do_cleanups (back_to); |
| 2308 | } |
| 2309 | return per_cu->v.quick->symtab; |
| 2310 | } |
| 2311 | |
| 2312 | /* Return the CU given its index. |
| 2313 | |
| 2314 | This is intended for loops like: |
| 2315 | |
| 2316 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2317 | + dwarf2_per_objfile->n_type_units); ++i) |
| 2318 | { |
| 2319 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 2320 | |
| 2321 | ...; |
| 2322 | } |
| 2323 | */ |
| 2324 | |
| 2325 | static struct dwarf2_per_cu_data * |
| 2326 | dw2_get_cu (int index) |
| 2327 | { |
| 2328 | if (index >= dwarf2_per_objfile->n_comp_units) |
| 2329 | { |
| 2330 | index -= dwarf2_per_objfile->n_comp_units; |
| 2331 | gdb_assert (index < dwarf2_per_objfile->n_type_units); |
| 2332 | return &dwarf2_per_objfile->all_type_units[index]->per_cu; |
| 2333 | } |
| 2334 | |
| 2335 | return dwarf2_per_objfile->all_comp_units[index]; |
| 2336 | } |
| 2337 | |
| 2338 | /* Return the primary CU given its index. |
| 2339 | The difference between this function and dw2_get_cu is in the handling |
| 2340 | of type units (TUs). Here we return the type_unit_group object. |
| 2341 | |
| 2342 | This is intended for loops like: |
| 2343 | |
| 2344 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 2345 | + dwarf2_per_objfile->n_type_unit_groups); ++i) |
| 2346 | { |
| 2347 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
| 2348 | |
| 2349 | ...; |
| 2350 | } |
| 2351 | */ |
| 2352 | |
| 2353 | static struct dwarf2_per_cu_data * |
| 2354 | dw2_get_primary_cu (int index) |
| 2355 | { |
| 2356 | if (index >= dwarf2_per_objfile->n_comp_units) |
| 2357 | { |
| 2358 | index -= dwarf2_per_objfile->n_comp_units; |
| 2359 | gdb_assert (index < dwarf2_per_objfile->n_type_unit_groups); |
| 2360 | return &dwarf2_per_objfile->all_type_unit_groups[index]->per_cu; |
| 2361 | } |
| 2362 | |
| 2363 | return dwarf2_per_objfile->all_comp_units[index]; |
| 2364 | } |
| 2365 | |
| 2366 | /* A helper for create_cus_from_index that handles a given list of |
| 2367 | CUs. */ |
| 2368 | |
| 2369 | static void |
| 2370 | create_cus_from_index_list (struct objfile *objfile, |
| 2371 | const gdb_byte *cu_list, offset_type n_elements, |
| 2372 | struct dwarf2_section_info *section, |
| 2373 | int is_dwz, |
| 2374 | int base_offset) |
| 2375 | { |
| 2376 | offset_type i; |
| 2377 | |
| 2378 | for (i = 0; i < n_elements; i += 2) |
| 2379 | { |
| 2380 | struct dwarf2_per_cu_data *the_cu; |
| 2381 | ULONGEST offset, length; |
| 2382 | |
| 2383 | gdb_static_assert (sizeof (ULONGEST) >= 8); |
| 2384 | offset = extract_unsigned_integer (cu_list, 8, BFD_ENDIAN_LITTLE); |
| 2385 | length = extract_unsigned_integer (cu_list + 8, 8, BFD_ENDIAN_LITTLE); |
| 2386 | cu_list += 2 * 8; |
| 2387 | |
| 2388 | the_cu = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 2389 | struct dwarf2_per_cu_data); |
| 2390 | the_cu->offset.sect_off = offset; |
| 2391 | the_cu->length = length; |
| 2392 | the_cu->objfile = objfile; |
| 2393 | the_cu->info_or_types_section = section; |
| 2394 | the_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 2395 | struct dwarf2_per_cu_quick_data); |
| 2396 | the_cu->is_dwz = is_dwz; |
| 2397 | dwarf2_per_objfile->all_comp_units[base_offset + i / 2] = the_cu; |
| 2398 | } |
| 2399 | } |
| 2400 | |
| 2401 | /* Read the CU list from the mapped index, and use it to create all |
| 2402 | the CU objects for this objfile. */ |
| 2403 | |
| 2404 | static void |
| 2405 | create_cus_from_index (struct objfile *objfile, |
| 2406 | const gdb_byte *cu_list, offset_type cu_list_elements, |
| 2407 | const gdb_byte *dwz_list, offset_type dwz_elements) |
| 2408 | { |
| 2409 | struct dwz_file *dwz; |
| 2410 | |
| 2411 | dwarf2_per_objfile->n_comp_units = (cu_list_elements + dwz_elements) / 2; |
| 2412 | dwarf2_per_objfile->all_comp_units |
| 2413 | = obstack_alloc (&objfile->objfile_obstack, |
| 2414 | dwarf2_per_objfile->n_comp_units |
| 2415 | * sizeof (struct dwarf2_per_cu_data *)); |
| 2416 | |
| 2417 | create_cus_from_index_list (objfile, cu_list, cu_list_elements, |
| 2418 | &dwarf2_per_objfile->info, 0, 0); |
| 2419 | |
| 2420 | if (dwz_elements == 0) |
| 2421 | return; |
| 2422 | |
| 2423 | dwz = dwarf2_get_dwz_file (); |
| 2424 | create_cus_from_index_list (objfile, dwz_list, dwz_elements, &dwz->info, 1, |
| 2425 | cu_list_elements / 2); |
| 2426 | } |
| 2427 | |
| 2428 | /* Create the signatured type hash table from the index. */ |
| 2429 | |
| 2430 | static void |
| 2431 | create_signatured_type_table_from_index (struct objfile *objfile, |
| 2432 | struct dwarf2_section_info *section, |
| 2433 | const gdb_byte *bytes, |
| 2434 | offset_type elements) |
| 2435 | { |
| 2436 | offset_type i; |
| 2437 | htab_t sig_types_hash; |
| 2438 | |
| 2439 | dwarf2_per_objfile->n_type_units = elements / 3; |
| 2440 | dwarf2_per_objfile->all_type_units |
| 2441 | = obstack_alloc (&objfile->objfile_obstack, |
| 2442 | dwarf2_per_objfile->n_type_units |
| 2443 | * sizeof (struct signatured_type *)); |
| 2444 | |
| 2445 | sig_types_hash = allocate_signatured_type_table (objfile); |
| 2446 | |
| 2447 | for (i = 0; i < elements; i += 3) |
| 2448 | { |
| 2449 | struct signatured_type *sig_type; |
| 2450 | ULONGEST offset, type_offset_in_tu, signature; |
| 2451 | void **slot; |
| 2452 | |
| 2453 | gdb_static_assert (sizeof (ULONGEST) >= 8); |
| 2454 | offset = extract_unsigned_integer (bytes, 8, BFD_ENDIAN_LITTLE); |
| 2455 | type_offset_in_tu = extract_unsigned_integer (bytes + 8, 8, |
| 2456 | BFD_ENDIAN_LITTLE); |
| 2457 | signature = extract_unsigned_integer (bytes + 16, 8, BFD_ENDIAN_LITTLE); |
| 2458 | bytes += 3 * 8; |
| 2459 | |
| 2460 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 2461 | struct signatured_type); |
| 2462 | sig_type->signature = signature; |
| 2463 | sig_type->type_offset_in_tu.cu_off = type_offset_in_tu; |
| 2464 | sig_type->per_cu.is_debug_types = 1; |
| 2465 | sig_type->per_cu.info_or_types_section = section; |
| 2466 | sig_type->per_cu.offset.sect_off = offset; |
| 2467 | sig_type->per_cu.objfile = objfile; |
| 2468 | sig_type->per_cu.v.quick |
| 2469 | = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 2470 | struct dwarf2_per_cu_quick_data); |
| 2471 | |
| 2472 | slot = htab_find_slot (sig_types_hash, sig_type, INSERT); |
| 2473 | *slot = sig_type; |
| 2474 | |
| 2475 | dwarf2_per_objfile->all_type_units[i / 3] = sig_type; |
| 2476 | } |
| 2477 | |
| 2478 | dwarf2_per_objfile->signatured_types = sig_types_hash; |
| 2479 | } |
| 2480 | |
| 2481 | /* Read the address map data from the mapped index, and use it to |
| 2482 | populate the objfile's psymtabs_addrmap. */ |
| 2483 | |
| 2484 | static void |
| 2485 | create_addrmap_from_index (struct objfile *objfile, struct mapped_index *index) |
| 2486 | { |
| 2487 | const gdb_byte *iter, *end; |
| 2488 | struct obstack temp_obstack; |
| 2489 | struct addrmap *mutable_map; |
| 2490 | struct cleanup *cleanup; |
| 2491 | CORE_ADDR baseaddr; |
| 2492 | |
| 2493 | obstack_init (&temp_obstack); |
| 2494 | cleanup = make_cleanup_obstack_free (&temp_obstack); |
| 2495 | mutable_map = addrmap_create_mutable (&temp_obstack); |
| 2496 | |
| 2497 | iter = index->address_table; |
| 2498 | end = iter + index->address_table_size; |
| 2499 | |
| 2500 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 2501 | |
| 2502 | while (iter < end) |
| 2503 | { |
| 2504 | ULONGEST hi, lo, cu_index; |
| 2505 | lo = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); |
| 2506 | iter += 8; |
| 2507 | hi = extract_unsigned_integer (iter, 8, BFD_ENDIAN_LITTLE); |
| 2508 | iter += 8; |
| 2509 | cu_index = extract_unsigned_integer (iter, 4, BFD_ENDIAN_LITTLE); |
| 2510 | iter += 4; |
| 2511 | |
| 2512 | addrmap_set_empty (mutable_map, lo + baseaddr, hi + baseaddr - 1, |
| 2513 | dw2_get_cu (cu_index)); |
| 2514 | } |
| 2515 | |
| 2516 | objfile->psymtabs_addrmap = addrmap_create_fixed (mutable_map, |
| 2517 | &objfile->objfile_obstack); |
| 2518 | do_cleanups (cleanup); |
| 2519 | } |
| 2520 | |
| 2521 | /* The hash function for strings in the mapped index. This is the same as |
| 2522 | SYMBOL_HASH_NEXT, but we keep a separate copy to maintain control over the |
| 2523 | implementation. This is necessary because the hash function is tied to the |
| 2524 | format of the mapped index file. The hash values do not have to match with |
| 2525 | SYMBOL_HASH_NEXT. |
| 2526 | |
| 2527 | Use INT_MAX for INDEX_VERSION if you generate the current index format. */ |
| 2528 | |
| 2529 | static hashval_t |
| 2530 | mapped_index_string_hash (int index_version, const void *p) |
| 2531 | { |
| 2532 | const unsigned char *str = (const unsigned char *) p; |
| 2533 | hashval_t r = 0; |
| 2534 | unsigned char c; |
| 2535 | |
| 2536 | while ((c = *str++) != 0) |
| 2537 | { |
| 2538 | if (index_version >= 5) |
| 2539 | c = tolower (c); |
| 2540 | r = r * 67 + c - 113; |
| 2541 | } |
| 2542 | |
| 2543 | return r; |
| 2544 | } |
| 2545 | |
| 2546 | /* Find a slot in the mapped index INDEX for the object named NAME. |
| 2547 | If NAME is found, set *VEC_OUT to point to the CU vector in the |
| 2548 | constant pool and return 1. If NAME cannot be found, return 0. */ |
| 2549 | |
| 2550 | static int |
| 2551 | find_slot_in_mapped_hash (struct mapped_index *index, const char *name, |
| 2552 | offset_type **vec_out) |
| 2553 | { |
| 2554 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 2555 | offset_type hash; |
| 2556 | offset_type slot, step; |
| 2557 | int (*cmp) (const char *, const char *); |
| 2558 | |
| 2559 | if (current_language->la_language == language_cplus |
| 2560 | || current_language->la_language == language_java |
| 2561 | || current_language->la_language == language_fortran) |
| 2562 | { |
| 2563 | /* NAME is already canonical. Drop any qualifiers as .gdb_index does |
| 2564 | not contain any. */ |
| 2565 | const char *paren = strchr (name, '('); |
| 2566 | |
| 2567 | if (paren) |
| 2568 | { |
| 2569 | char *dup; |
| 2570 | |
| 2571 | dup = xmalloc (paren - name + 1); |
| 2572 | memcpy (dup, name, paren - name); |
| 2573 | dup[paren - name] = 0; |
| 2574 | |
| 2575 | make_cleanup (xfree, dup); |
| 2576 | name = dup; |
| 2577 | } |
| 2578 | } |
| 2579 | |
| 2580 | /* Index version 4 did not support case insensitive searches. But the |
| 2581 | indices for case insensitive languages are built in lowercase, therefore |
| 2582 | simulate our NAME being searched is also lowercased. */ |
| 2583 | hash = mapped_index_string_hash ((index->version == 4 |
| 2584 | && case_sensitivity == case_sensitive_off |
| 2585 | ? 5 : index->version), |
| 2586 | name); |
| 2587 | |
| 2588 | slot = hash & (index->symbol_table_slots - 1); |
| 2589 | step = ((hash * 17) & (index->symbol_table_slots - 1)) | 1; |
| 2590 | cmp = (case_sensitivity == case_sensitive_on ? strcmp : strcasecmp); |
| 2591 | |
| 2592 | for (;;) |
| 2593 | { |
| 2594 | /* Convert a slot number to an offset into the table. */ |
| 2595 | offset_type i = 2 * slot; |
| 2596 | const char *str; |
| 2597 | if (index->symbol_table[i] == 0 && index->symbol_table[i + 1] == 0) |
| 2598 | { |
| 2599 | do_cleanups (back_to); |
| 2600 | return 0; |
| 2601 | } |
| 2602 | |
| 2603 | str = index->constant_pool + MAYBE_SWAP (index->symbol_table[i]); |
| 2604 | if (!cmp (name, str)) |
| 2605 | { |
| 2606 | *vec_out = (offset_type *) (index->constant_pool |
| 2607 | + MAYBE_SWAP (index->symbol_table[i + 1])); |
| 2608 | do_cleanups (back_to); |
| 2609 | return 1; |
| 2610 | } |
| 2611 | |
| 2612 | slot = (slot + step) & (index->symbol_table_slots - 1); |
| 2613 | } |
| 2614 | } |
| 2615 | |
| 2616 | /* A helper function that reads the .gdb_index from SECTION and fills |
| 2617 | in MAP. FILENAME is the name of the file containing the section; |
| 2618 | it is used for error reporting. DEPRECATED_OK is nonzero if it is |
| 2619 | ok to use deprecated sections. |
| 2620 | |
| 2621 | CU_LIST, CU_LIST_ELEMENTS, TYPES_LIST, and TYPES_LIST_ELEMENTS are |
| 2622 | out parameters that are filled in with information about the CU and |
| 2623 | TU lists in the section. |
| 2624 | |
| 2625 | Returns 1 if all went well, 0 otherwise. */ |
| 2626 | |
| 2627 | static int |
| 2628 | read_index_from_section (struct objfile *objfile, |
| 2629 | const char *filename, |
| 2630 | int deprecated_ok, |
| 2631 | struct dwarf2_section_info *section, |
| 2632 | struct mapped_index *map, |
| 2633 | const gdb_byte **cu_list, |
| 2634 | offset_type *cu_list_elements, |
| 2635 | const gdb_byte **types_list, |
| 2636 | offset_type *types_list_elements) |
| 2637 | { |
| 2638 | char *addr; |
| 2639 | offset_type version; |
| 2640 | offset_type *metadata; |
| 2641 | int i; |
| 2642 | |
| 2643 | if (dwarf2_section_empty_p (section)) |
| 2644 | return 0; |
| 2645 | |
| 2646 | /* Older elfutils strip versions could keep the section in the main |
| 2647 | executable while splitting it for the separate debug info file. */ |
| 2648 | if ((bfd_get_file_flags (section->asection) & SEC_HAS_CONTENTS) == 0) |
| 2649 | return 0; |
| 2650 | |
| 2651 | dwarf2_read_section (objfile, section); |
| 2652 | |
| 2653 | addr = section->buffer; |
| 2654 | /* Version check. */ |
| 2655 | version = MAYBE_SWAP (*(offset_type *) addr); |
| 2656 | /* Versions earlier than 3 emitted every copy of a psymbol. This |
| 2657 | causes the index to behave very poorly for certain requests. Version 3 |
| 2658 | contained incomplete addrmap. So, it seems better to just ignore such |
| 2659 | indices. */ |
| 2660 | if (version < 4) |
| 2661 | { |
| 2662 | static int warning_printed = 0; |
| 2663 | if (!warning_printed) |
| 2664 | { |
| 2665 | warning (_("Skipping obsolete .gdb_index section in %s."), |
| 2666 | filename); |
| 2667 | warning_printed = 1; |
| 2668 | } |
| 2669 | return 0; |
| 2670 | } |
| 2671 | /* Index version 4 uses a different hash function than index version |
| 2672 | 5 and later. |
| 2673 | |
| 2674 | Versions earlier than 6 did not emit psymbols for inlined |
| 2675 | functions. Using these files will cause GDB not to be able to |
| 2676 | set breakpoints on inlined functions by name, so we ignore these |
| 2677 | indices unless the user has done |
| 2678 | "set use-deprecated-index-sections on". */ |
| 2679 | if (version < 6 && !deprecated_ok) |
| 2680 | { |
| 2681 | static int warning_printed = 0; |
| 2682 | if (!warning_printed) |
| 2683 | { |
| 2684 | warning (_("\ |
| 2685 | Skipping deprecated .gdb_index section in %s.\n\ |
| 2686 | Do \"set use-deprecated-index-sections on\" before the file is read\n\ |
| 2687 | to use the section anyway."), |
| 2688 | filename); |
| 2689 | warning_printed = 1; |
| 2690 | } |
| 2691 | return 0; |
| 2692 | } |
| 2693 | /* Indexes with higher version than the one supported by GDB may be no |
| 2694 | longer backward compatible. */ |
| 2695 | if (version > 7) |
| 2696 | return 0; |
| 2697 | |
| 2698 | map->version = version; |
| 2699 | map->total_size = section->size; |
| 2700 | |
| 2701 | metadata = (offset_type *) (addr + sizeof (offset_type)); |
| 2702 | |
| 2703 | i = 0; |
| 2704 | *cu_list = addr + MAYBE_SWAP (metadata[i]); |
| 2705 | *cu_list_elements = ((MAYBE_SWAP (metadata[i + 1]) - MAYBE_SWAP (metadata[i])) |
| 2706 | / 8); |
| 2707 | ++i; |
| 2708 | |
| 2709 | *types_list = addr + MAYBE_SWAP (metadata[i]); |
| 2710 | *types_list_elements = ((MAYBE_SWAP (metadata[i + 1]) |
| 2711 | - MAYBE_SWAP (metadata[i])) |
| 2712 | / 8); |
| 2713 | ++i; |
| 2714 | |
| 2715 | map->address_table = addr + MAYBE_SWAP (metadata[i]); |
| 2716 | map->address_table_size = (MAYBE_SWAP (metadata[i + 1]) |
| 2717 | - MAYBE_SWAP (metadata[i])); |
| 2718 | ++i; |
| 2719 | |
| 2720 | map->symbol_table = (offset_type *) (addr + MAYBE_SWAP (metadata[i])); |
| 2721 | map->symbol_table_slots = ((MAYBE_SWAP (metadata[i + 1]) |
| 2722 | - MAYBE_SWAP (metadata[i])) |
| 2723 | / (2 * sizeof (offset_type))); |
| 2724 | ++i; |
| 2725 | |
| 2726 | map->constant_pool = addr + MAYBE_SWAP (metadata[i]); |
| 2727 | |
| 2728 | return 1; |
| 2729 | } |
| 2730 | |
| 2731 | |
| 2732 | /* Read the index file. If everything went ok, initialize the "quick" |
| 2733 | elements of all the CUs and return 1. Otherwise, return 0. */ |
| 2734 | |
| 2735 | static int |
| 2736 | dwarf2_read_index (struct objfile *objfile) |
| 2737 | { |
| 2738 | struct mapped_index local_map, *map; |
| 2739 | const gdb_byte *cu_list, *types_list, *dwz_list = NULL; |
| 2740 | offset_type cu_list_elements, types_list_elements, dwz_list_elements = 0; |
| 2741 | |
| 2742 | if (!read_index_from_section (objfile, objfile->name, |
| 2743 | use_deprecated_index_sections, |
| 2744 | &dwarf2_per_objfile->gdb_index, &local_map, |
| 2745 | &cu_list, &cu_list_elements, |
| 2746 | &types_list, &types_list_elements)) |
| 2747 | return 0; |
| 2748 | |
| 2749 | /* Don't use the index if it's empty. */ |
| 2750 | if (local_map.symbol_table_slots == 0) |
| 2751 | return 0; |
| 2752 | |
| 2753 | /* If there is a .dwz file, read it so we can get its CU list as |
| 2754 | well. */ |
| 2755 | if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL) |
| 2756 | { |
| 2757 | struct dwz_file *dwz = dwarf2_get_dwz_file (); |
| 2758 | struct mapped_index dwz_map; |
| 2759 | const gdb_byte *dwz_types_ignore; |
| 2760 | offset_type dwz_types_elements_ignore; |
| 2761 | |
| 2762 | if (!read_index_from_section (objfile, bfd_get_filename (dwz->dwz_bfd), |
| 2763 | 1, |
| 2764 | &dwz->gdb_index, &dwz_map, |
| 2765 | &dwz_list, &dwz_list_elements, |
| 2766 | &dwz_types_ignore, |
| 2767 | &dwz_types_elements_ignore)) |
| 2768 | { |
| 2769 | warning (_("could not read '.gdb_index' section from %s; skipping"), |
| 2770 | bfd_get_filename (dwz->dwz_bfd)); |
| 2771 | return 0; |
| 2772 | } |
| 2773 | } |
| 2774 | |
| 2775 | create_cus_from_index (objfile, cu_list, cu_list_elements, dwz_list, |
| 2776 | dwz_list_elements); |
| 2777 | |
| 2778 | if (types_list_elements) |
| 2779 | { |
| 2780 | struct dwarf2_section_info *section; |
| 2781 | |
| 2782 | /* We can only handle a single .debug_types when we have an |
| 2783 | index. */ |
| 2784 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) != 1) |
| 2785 | return 0; |
| 2786 | |
| 2787 | section = VEC_index (dwarf2_section_info_def, |
| 2788 | dwarf2_per_objfile->types, 0); |
| 2789 | |
| 2790 | create_signatured_type_table_from_index (objfile, section, types_list, |
| 2791 | types_list_elements); |
| 2792 | } |
| 2793 | |
| 2794 | create_addrmap_from_index (objfile, &local_map); |
| 2795 | |
| 2796 | map = obstack_alloc (&objfile->objfile_obstack, sizeof (struct mapped_index)); |
| 2797 | *map = local_map; |
| 2798 | |
| 2799 | dwarf2_per_objfile->index_table = map; |
| 2800 | dwarf2_per_objfile->using_index = 1; |
| 2801 | dwarf2_per_objfile->quick_file_names_table = |
| 2802 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); |
| 2803 | |
| 2804 | return 1; |
| 2805 | } |
| 2806 | |
| 2807 | /* A helper for the "quick" functions which sets the global |
| 2808 | dwarf2_per_objfile according to OBJFILE. */ |
| 2809 | |
| 2810 | static void |
| 2811 | dw2_setup (struct objfile *objfile) |
| 2812 | { |
| 2813 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 2814 | gdb_assert (dwarf2_per_objfile); |
| 2815 | } |
| 2816 | |
| 2817 | /* Reader function for dw2_build_type_unit_groups. */ |
| 2818 | |
| 2819 | static void |
| 2820 | dw2_build_type_unit_groups_reader (const struct die_reader_specs *reader, |
| 2821 | gdb_byte *info_ptr, |
| 2822 | struct die_info *type_unit_die, |
| 2823 | int has_children, |
| 2824 | void *data) |
| 2825 | { |
| 2826 | struct dwarf2_cu *cu = reader->cu; |
| 2827 | struct attribute *attr; |
| 2828 | struct type_unit_group *tu_group; |
| 2829 | |
| 2830 | gdb_assert (data == NULL); |
| 2831 | |
| 2832 | if (! has_children) |
| 2833 | return; |
| 2834 | |
| 2835 | attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list); |
| 2836 | /* Call this for its side-effect of creating the associated |
| 2837 | struct type_unit_group if it doesn't already exist. */ |
| 2838 | tu_group = get_type_unit_group (cu, attr); |
| 2839 | } |
| 2840 | |
| 2841 | /* Build dwarf2_per_objfile->type_unit_groups. |
| 2842 | This function may be called multiple times. */ |
| 2843 | |
| 2844 | static void |
| 2845 | dw2_build_type_unit_groups (void) |
| 2846 | { |
| 2847 | if (dwarf2_per_objfile->type_unit_groups == NULL) |
| 2848 | build_type_unit_groups (dw2_build_type_unit_groups_reader, NULL); |
| 2849 | } |
| 2850 | |
| 2851 | /* die_reader_func for dw2_get_file_names. */ |
| 2852 | |
| 2853 | static void |
| 2854 | dw2_get_file_names_reader (const struct die_reader_specs *reader, |
| 2855 | gdb_byte *info_ptr, |
| 2856 | struct die_info *comp_unit_die, |
| 2857 | int has_children, |
| 2858 | void *data) |
| 2859 | { |
| 2860 | struct dwarf2_cu *cu = reader->cu; |
| 2861 | struct dwarf2_per_cu_data *this_cu = cu->per_cu; |
| 2862 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 2863 | struct dwarf2_per_cu_data *lh_cu; |
| 2864 | struct line_header *lh; |
| 2865 | struct attribute *attr; |
| 2866 | int i; |
| 2867 | char *name, *comp_dir; |
| 2868 | void **slot; |
| 2869 | struct quick_file_names *qfn; |
| 2870 | unsigned int line_offset; |
| 2871 | |
| 2872 | /* Our callers never want to match partial units -- instead they |
| 2873 | will match the enclosing full CU. */ |
| 2874 | if (comp_unit_die->tag == DW_TAG_partial_unit) |
| 2875 | { |
| 2876 | this_cu->v.quick->no_file_data = 1; |
| 2877 | return; |
| 2878 | } |
| 2879 | |
| 2880 | /* If we're reading the line header for TUs, store it in the "per_cu" |
| 2881 | for tu_group. */ |
| 2882 | if (this_cu->is_debug_types) |
| 2883 | { |
| 2884 | struct type_unit_group *tu_group = data; |
| 2885 | |
| 2886 | gdb_assert (tu_group != NULL); |
| 2887 | lh_cu = &tu_group->per_cu; |
| 2888 | } |
| 2889 | else |
| 2890 | lh_cu = this_cu; |
| 2891 | |
| 2892 | lh = NULL; |
| 2893 | slot = NULL; |
| 2894 | line_offset = 0; |
| 2895 | |
| 2896 | attr = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); |
| 2897 | if (attr) |
| 2898 | { |
| 2899 | struct quick_file_names find_entry; |
| 2900 | |
| 2901 | line_offset = DW_UNSND (attr); |
| 2902 | |
| 2903 | /* We may have already read in this line header (TU line header sharing). |
| 2904 | If we have we're done. */ |
| 2905 | find_entry.hash.dwo_unit = cu->dwo_unit; |
| 2906 | find_entry.hash.line_offset.sect_off = line_offset; |
| 2907 | slot = htab_find_slot (dwarf2_per_objfile->quick_file_names_table, |
| 2908 | &find_entry, INSERT); |
| 2909 | if (*slot != NULL) |
| 2910 | { |
| 2911 | lh_cu->v.quick->file_names = *slot; |
| 2912 | return; |
| 2913 | } |
| 2914 | |
| 2915 | lh = dwarf_decode_line_header (line_offset, cu); |
| 2916 | } |
| 2917 | if (lh == NULL) |
| 2918 | { |
| 2919 | lh_cu->v.quick->no_file_data = 1; |
| 2920 | return; |
| 2921 | } |
| 2922 | |
| 2923 | qfn = obstack_alloc (&objfile->objfile_obstack, sizeof (*qfn)); |
| 2924 | qfn->hash.dwo_unit = cu->dwo_unit; |
| 2925 | qfn->hash.line_offset.sect_off = line_offset; |
| 2926 | gdb_assert (slot != NULL); |
| 2927 | *slot = qfn; |
| 2928 | |
| 2929 | find_file_and_directory (comp_unit_die, cu, &name, &comp_dir); |
| 2930 | |
| 2931 | qfn->num_file_names = lh->num_file_names; |
| 2932 | qfn->file_names = obstack_alloc (&objfile->objfile_obstack, |
| 2933 | lh->num_file_names * sizeof (char *)); |
| 2934 | for (i = 0; i < lh->num_file_names; ++i) |
| 2935 | qfn->file_names[i] = file_full_name (i + 1, lh, comp_dir); |
| 2936 | qfn->real_names = NULL; |
| 2937 | |
| 2938 | free_line_header (lh); |
| 2939 | |
| 2940 | lh_cu->v.quick->file_names = qfn; |
| 2941 | } |
| 2942 | |
| 2943 | /* A helper for the "quick" functions which attempts to read the line |
| 2944 | table for THIS_CU. */ |
| 2945 | |
| 2946 | static struct quick_file_names * |
| 2947 | dw2_get_file_names (struct objfile *objfile, |
| 2948 | struct dwarf2_per_cu_data *this_cu) |
| 2949 | { |
| 2950 | /* For TUs this should only be called on the parent group. */ |
| 2951 | if (this_cu->is_debug_types) |
| 2952 | gdb_assert (IS_TYPE_UNIT_GROUP (this_cu)); |
| 2953 | |
| 2954 | if (this_cu->v.quick->file_names != NULL) |
| 2955 | return this_cu->v.quick->file_names; |
| 2956 | /* If we know there is no line data, no point in looking again. */ |
| 2957 | if (this_cu->v.quick->no_file_data) |
| 2958 | return NULL; |
| 2959 | |
| 2960 | /* If DWO files are in use, we can still find the DW_AT_stmt_list attribute |
| 2961 | in the stub for CUs, there's is no need to lookup the DWO file. |
| 2962 | However, that's not the case for TUs where DW_AT_stmt_list lives in the |
| 2963 | DWO file. */ |
| 2964 | if (this_cu->is_debug_types) |
| 2965 | { |
| 2966 | struct type_unit_group *tu_group = this_cu->s.type_unit_group; |
| 2967 | |
| 2968 | init_cutu_and_read_dies (tu_group->t.first_tu, NULL, 0, 0, |
| 2969 | dw2_get_file_names_reader, tu_group); |
| 2970 | } |
| 2971 | else |
| 2972 | init_cutu_and_read_dies_simple (this_cu, dw2_get_file_names_reader, NULL); |
| 2973 | |
| 2974 | if (this_cu->v.quick->no_file_data) |
| 2975 | return NULL; |
| 2976 | return this_cu->v.quick->file_names; |
| 2977 | } |
| 2978 | |
| 2979 | /* A helper for the "quick" functions which computes and caches the |
| 2980 | real path for a given file name from the line table. */ |
| 2981 | |
| 2982 | static const char * |
| 2983 | dw2_get_real_path (struct objfile *objfile, |
| 2984 | struct quick_file_names *qfn, int index) |
| 2985 | { |
| 2986 | if (qfn->real_names == NULL) |
| 2987 | qfn->real_names = OBSTACK_CALLOC (&objfile->objfile_obstack, |
| 2988 | qfn->num_file_names, sizeof (char *)); |
| 2989 | |
| 2990 | if (qfn->real_names[index] == NULL) |
| 2991 | qfn->real_names[index] = gdb_realpath (qfn->file_names[index]); |
| 2992 | |
| 2993 | return qfn->real_names[index]; |
| 2994 | } |
| 2995 | |
| 2996 | static struct symtab * |
| 2997 | dw2_find_last_source_symtab (struct objfile *objfile) |
| 2998 | { |
| 2999 | int index; |
| 3000 | |
| 3001 | dw2_setup (objfile); |
| 3002 | index = dwarf2_per_objfile->n_comp_units - 1; |
| 3003 | return dw2_instantiate_symtab (dw2_get_cu (index)); |
| 3004 | } |
| 3005 | |
| 3006 | /* Traversal function for dw2_forget_cached_source_info. */ |
| 3007 | |
| 3008 | static int |
| 3009 | dw2_free_cached_file_names (void **slot, void *info) |
| 3010 | { |
| 3011 | struct quick_file_names *file_data = (struct quick_file_names *) *slot; |
| 3012 | |
| 3013 | if (file_data->real_names) |
| 3014 | { |
| 3015 | int i; |
| 3016 | |
| 3017 | for (i = 0; i < file_data->num_file_names; ++i) |
| 3018 | { |
| 3019 | xfree ((void*) file_data->real_names[i]); |
| 3020 | file_data->real_names[i] = NULL; |
| 3021 | } |
| 3022 | } |
| 3023 | |
| 3024 | return 1; |
| 3025 | } |
| 3026 | |
| 3027 | static void |
| 3028 | dw2_forget_cached_source_info (struct objfile *objfile) |
| 3029 | { |
| 3030 | dw2_setup (objfile); |
| 3031 | |
| 3032 | htab_traverse_noresize (dwarf2_per_objfile->quick_file_names_table, |
| 3033 | dw2_free_cached_file_names, NULL); |
| 3034 | } |
| 3035 | |
| 3036 | /* Helper function for dw2_map_symtabs_matching_filename that expands |
| 3037 | the symtabs and calls the iterator. */ |
| 3038 | |
| 3039 | static int |
| 3040 | dw2_map_expand_apply (struct objfile *objfile, |
| 3041 | struct dwarf2_per_cu_data *per_cu, |
| 3042 | const char *name, |
| 3043 | const char *full_path, const char *real_path, |
| 3044 | int (*callback) (struct symtab *, void *), |
| 3045 | void *data) |
| 3046 | { |
| 3047 | struct symtab *last_made = objfile->symtabs; |
| 3048 | |
| 3049 | /* Don't visit already-expanded CUs. */ |
| 3050 | if (per_cu->v.quick->symtab) |
| 3051 | return 0; |
| 3052 | |
| 3053 | /* This may expand more than one symtab, and we want to iterate over |
| 3054 | all of them. */ |
| 3055 | dw2_instantiate_symtab (per_cu); |
| 3056 | |
| 3057 | return iterate_over_some_symtabs (name, full_path, real_path, callback, data, |
| 3058 | objfile->symtabs, last_made); |
| 3059 | } |
| 3060 | |
| 3061 | /* Implementation of the map_symtabs_matching_filename method. */ |
| 3062 | |
| 3063 | static int |
| 3064 | dw2_map_symtabs_matching_filename (struct objfile *objfile, const char *name, |
| 3065 | const char *full_path, const char *real_path, |
| 3066 | int (*callback) (struct symtab *, void *), |
| 3067 | void *data) |
| 3068 | { |
| 3069 | int i; |
| 3070 | const char *name_basename = lbasename (name); |
| 3071 | int is_abs = IS_ABSOLUTE_PATH (name); |
| 3072 | |
| 3073 | dw2_setup (objfile); |
| 3074 | |
| 3075 | dw2_build_type_unit_groups (); |
| 3076 | |
| 3077 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3078 | + dwarf2_per_objfile->n_type_unit_groups); ++i) |
| 3079 | { |
| 3080 | int j; |
| 3081 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
| 3082 | struct quick_file_names *file_data; |
| 3083 | |
| 3084 | /* We only need to look at symtabs not already expanded. */ |
| 3085 | if (per_cu->v.quick->symtab) |
| 3086 | continue; |
| 3087 | |
| 3088 | file_data = dw2_get_file_names (objfile, per_cu); |
| 3089 | if (file_data == NULL) |
| 3090 | continue; |
| 3091 | |
| 3092 | for (j = 0; j < file_data->num_file_names; ++j) |
| 3093 | { |
| 3094 | const char *this_name = file_data->file_names[j]; |
| 3095 | |
| 3096 | if (FILENAME_CMP (name, this_name) == 0 |
| 3097 | || (!is_abs && compare_filenames_for_search (this_name, name))) |
| 3098 | { |
| 3099 | if (dw2_map_expand_apply (objfile, per_cu, |
| 3100 | name, full_path, real_path, |
| 3101 | callback, data)) |
| 3102 | return 1; |
| 3103 | } |
| 3104 | |
| 3105 | /* Before we invoke realpath, which can get expensive when many |
| 3106 | files are involved, do a quick comparison of the basenames. */ |
| 3107 | if (! basenames_may_differ |
| 3108 | && FILENAME_CMP (lbasename (this_name), name_basename) != 0) |
| 3109 | continue; |
| 3110 | |
| 3111 | if (full_path != NULL) |
| 3112 | { |
| 3113 | const char *this_real_name = dw2_get_real_path (objfile, |
| 3114 | file_data, j); |
| 3115 | |
| 3116 | if (this_real_name != NULL |
| 3117 | && (FILENAME_CMP (full_path, this_real_name) == 0 |
| 3118 | || (!is_abs |
| 3119 | && compare_filenames_for_search (this_real_name, |
| 3120 | name)))) |
| 3121 | { |
| 3122 | if (dw2_map_expand_apply (objfile, per_cu, |
| 3123 | name, full_path, real_path, |
| 3124 | callback, data)) |
| 3125 | return 1; |
| 3126 | } |
| 3127 | } |
| 3128 | |
| 3129 | if (real_path != NULL) |
| 3130 | { |
| 3131 | const char *this_real_name = dw2_get_real_path (objfile, |
| 3132 | file_data, j); |
| 3133 | |
| 3134 | if (this_real_name != NULL |
| 3135 | && (FILENAME_CMP (real_path, this_real_name) == 0 |
| 3136 | || (!is_abs |
| 3137 | && compare_filenames_for_search (this_real_name, |
| 3138 | name)))) |
| 3139 | { |
| 3140 | if (dw2_map_expand_apply (objfile, per_cu, |
| 3141 | name, full_path, real_path, |
| 3142 | callback, data)) |
| 3143 | return 1; |
| 3144 | } |
| 3145 | } |
| 3146 | } |
| 3147 | } |
| 3148 | |
| 3149 | return 0; |
| 3150 | } |
| 3151 | |
| 3152 | static struct symtab * |
| 3153 | dw2_lookup_symbol (struct objfile *objfile, int block_index, |
| 3154 | const char *name, domain_enum domain) |
| 3155 | { |
| 3156 | /* We do all the work in the pre_expand_symtabs_matching hook |
| 3157 | instead. */ |
| 3158 | return NULL; |
| 3159 | } |
| 3160 | |
| 3161 | /* A helper function that expands all symtabs that hold an object |
| 3162 | named NAME. If WANT_SPECIFIC_BLOCK is non-zero, only look for |
| 3163 | symbols in block BLOCK_KIND. */ |
| 3164 | |
| 3165 | static void |
| 3166 | dw2_do_expand_symtabs_matching (struct objfile *objfile, |
| 3167 | int want_specific_block, |
| 3168 | enum block_enum block_kind, |
| 3169 | const char *name, domain_enum domain) |
| 3170 | { |
| 3171 | struct mapped_index *index; |
| 3172 | |
| 3173 | dw2_setup (objfile); |
| 3174 | |
| 3175 | index = dwarf2_per_objfile->index_table; |
| 3176 | |
| 3177 | /* index_table is NULL if OBJF_READNOW. */ |
| 3178 | if (index) |
| 3179 | { |
| 3180 | offset_type *vec; |
| 3181 | |
| 3182 | if (find_slot_in_mapped_hash (index, name, &vec)) |
| 3183 | { |
| 3184 | offset_type i, len = MAYBE_SWAP (*vec); |
| 3185 | for (i = 0; i < len; ++i) |
| 3186 | { |
| 3187 | offset_type cu_index_and_attrs = MAYBE_SWAP (vec[i + 1]); |
| 3188 | offset_type cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); |
| 3189 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (cu_index); |
| 3190 | int want_static = block_kind != GLOBAL_BLOCK; |
| 3191 | /* This value is only valid for index versions >= 7. */ |
| 3192 | int is_static = GDB_INDEX_SYMBOL_STATIC_VALUE (cu_index_and_attrs); |
| 3193 | gdb_index_symbol_kind symbol_kind = |
| 3194 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); |
| 3195 | /* Only check the symbol attributes if they're present. |
| 3196 | Indices prior to version 7 don't record them, |
| 3197 | and indices >= 7 may elide them for certain symbols |
| 3198 | (gold does this). */ |
| 3199 | int attrs_valid = |
| 3200 | (index->version >= 7 |
| 3201 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_NONE); |
| 3202 | |
| 3203 | if (attrs_valid |
| 3204 | && want_specific_block |
| 3205 | && want_static != is_static) |
| 3206 | continue; |
| 3207 | |
| 3208 | /* Only check the symbol's kind if it has one. */ |
| 3209 | if (attrs_valid) |
| 3210 | { |
| 3211 | switch (domain) |
| 3212 | { |
| 3213 | case VAR_DOMAIN: |
| 3214 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE |
| 3215 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION |
| 3216 | /* Some types are also in VAR_DOMAIN. */ |
| 3217 | && symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) |
| 3218 | continue; |
| 3219 | break; |
| 3220 | case STRUCT_DOMAIN: |
| 3221 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) |
| 3222 | continue; |
| 3223 | break; |
| 3224 | case LABEL_DOMAIN: |
| 3225 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_OTHER) |
| 3226 | continue; |
| 3227 | break; |
| 3228 | default: |
| 3229 | break; |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | dw2_instantiate_symtab (per_cu); |
| 3234 | } |
| 3235 | } |
| 3236 | } |
| 3237 | } |
| 3238 | |
| 3239 | static void |
| 3240 | dw2_pre_expand_symtabs_matching (struct objfile *objfile, |
| 3241 | enum block_enum block_kind, const char *name, |
| 3242 | domain_enum domain) |
| 3243 | { |
| 3244 | dw2_do_expand_symtabs_matching (objfile, 1, block_kind, name, domain); |
| 3245 | } |
| 3246 | |
| 3247 | static void |
| 3248 | dw2_print_stats (struct objfile *objfile) |
| 3249 | { |
| 3250 | int i, count; |
| 3251 | |
| 3252 | dw2_setup (objfile); |
| 3253 | count = 0; |
| 3254 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3255 | + dwarf2_per_objfile->n_type_units); ++i) |
| 3256 | { |
| 3257 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 3258 | |
| 3259 | if (!per_cu->v.quick->symtab) |
| 3260 | ++count; |
| 3261 | } |
| 3262 | printf_filtered (_(" Number of unread CUs: %d\n"), count); |
| 3263 | } |
| 3264 | |
| 3265 | static void |
| 3266 | dw2_dump (struct objfile *objfile) |
| 3267 | { |
| 3268 | /* Nothing worth printing. */ |
| 3269 | } |
| 3270 | |
| 3271 | static void |
| 3272 | dw2_relocate (struct objfile *objfile, struct section_offsets *new_offsets, |
| 3273 | struct section_offsets *delta) |
| 3274 | { |
| 3275 | /* There's nothing to relocate here. */ |
| 3276 | } |
| 3277 | |
| 3278 | static void |
| 3279 | dw2_expand_symtabs_for_function (struct objfile *objfile, |
| 3280 | const char *func_name) |
| 3281 | { |
| 3282 | /* Note: It doesn't matter what we pass for block_kind here. */ |
| 3283 | dw2_do_expand_symtabs_matching (objfile, 0, GLOBAL_BLOCK, func_name, |
| 3284 | VAR_DOMAIN); |
| 3285 | } |
| 3286 | |
| 3287 | static void |
| 3288 | dw2_expand_all_symtabs (struct objfile *objfile) |
| 3289 | { |
| 3290 | int i; |
| 3291 | |
| 3292 | dw2_setup (objfile); |
| 3293 | |
| 3294 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3295 | + dwarf2_per_objfile->n_type_units); ++i) |
| 3296 | { |
| 3297 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 3298 | |
| 3299 | dw2_instantiate_symtab (per_cu); |
| 3300 | } |
| 3301 | } |
| 3302 | |
| 3303 | static void |
| 3304 | dw2_expand_symtabs_with_filename (struct objfile *objfile, |
| 3305 | const char *filename) |
| 3306 | { |
| 3307 | int i; |
| 3308 | |
| 3309 | dw2_setup (objfile); |
| 3310 | |
| 3311 | /* We don't need to consider type units here. |
| 3312 | This is only called for examining code, e.g. expand_line_sal. |
| 3313 | There can be an order of magnitude (or more) more type units |
| 3314 | than comp units, and we avoid them if we can. */ |
| 3315 | |
| 3316 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 3317 | { |
| 3318 | int j; |
| 3319 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 3320 | struct quick_file_names *file_data; |
| 3321 | |
| 3322 | /* We only need to look at symtabs not already expanded. */ |
| 3323 | if (per_cu->v.quick->symtab) |
| 3324 | continue; |
| 3325 | |
| 3326 | file_data = dw2_get_file_names (objfile, per_cu); |
| 3327 | if (file_data == NULL) |
| 3328 | continue; |
| 3329 | |
| 3330 | for (j = 0; j < file_data->num_file_names; ++j) |
| 3331 | { |
| 3332 | const char *this_name = file_data->file_names[j]; |
| 3333 | if (FILENAME_CMP (this_name, filename) == 0) |
| 3334 | { |
| 3335 | dw2_instantiate_symtab (per_cu); |
| 3336 | break; |
| 3337 | } |
| 3338 | } |
| 3339 | } |
| 3340 | } |
| 3341 | |
| 3342 | /* A helper function for dw2_find_symbol_file that finds the primary |
| 3343 | file name for a given CU. This is a die_reader_func. */ |
| 3344 | |
| 3345 | static void |
| 3346 | dw2_get_primary_filename_reader (const struct die_reader_specs *reader, |
| 3347 | gdb_byte *info_ptr, |
| 3348 | struct die_info *comp_unit_die, |
| 3349 | int has_children, |
| 3350 | void *data) |
| 3351 | { |
| 3352 | const char **result_ptr = data; |
| 3353 | struct dwarf2_cu *cu = reader->cu; |
| 3354 | struct attribute *attr; |
| 3355 | |
| 3356 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); |
| 3357 | if (attr == NULL) |
| 3358 | *result_ptr = NULL; |
| 3359 | else |
| 3360 | *result_ptr = DW_STRING (attr); |
| 3361 | } |
| 3362 | |
| 3363 | static const char * |
| 3364 | dw2_find_symbol_file (struct objfile *objfile, const char *name) |
| 3365 | { |
| 3366 | struct dwarf2_per_cu_data *per_cu; |
| 3367 | offset_type *vec; |
| 3368 | const char *filename; |
| 3369 | |
| 3370 | dw2_setup (objfile); |
| 3371 | |
| 3372 | /* index_table is NULL if OBJF_READNOW. */ |
| 3373 | if (!dwarf2_per_objfile->index_table) |
| 3374 | { |
| 3375 | struct symtab *s; |
| 3376 | |
| 3377 | ALL_OBJFILE_PRIMARY_SYMTABS (objfile, s) |
| 3378 | { |
| 3379 | struct blockvector *bv = BLOCKVECTOR (s); |
| 3380 | const struct block *block = BLOCKVECTOR_BLOCK (bv, GLOBAL_BLOCK); |
| 3381 | struct symbol *sym = lookup_block_symbol (block, name, VAR_DOMAIN); |
| 3382 | |
| 3383 | if (sym) |
| 3384 | return SYMBOL_SYMTAB (sym)->filename; |
| 3385 | } |
| 3386 | return NULL; |
| 3387 | } |
| 3388 | |
| 3389 | if (!find_slot_in_mapped_hash (dwarf2_per_objfile->index_table, |
| 3390 | name, &vec)) |
| 3391 | return NULL; |
| 3392 | |
| 3393 | /* Note that this just looks at the very first one named NAME -- but |
| 3394 | actually we are looking for a function. find_main_filename |
| 3395 | should be rewritten so that it doesn't require a custom hook. It |
| 3396 | could just use the ordinary symbol tables. */ |
| 3397 | /* vec[0] is the length, which must always be >0. */ |
| 3398 | per_cu = dw2_get_cu (GDB_INDEX_CU_VALUE (MAYBE_SWAP (vec[1]))); |
| 3399 | |
| 3400 | if (per_cu->v.quick->symtab != NULL) |
| 3401 | return per_cu->v.quick->symtab->filename; |
| 3402 | |
| 3403 | init_cutu_and_read_dies (per_cu, NULL, 0, 0, |
| 3404 | dw2_get_primary_filename_reader, &filename); |
| 3405 | |
| 3406 | return filename; |
| 3407 | } |
| 3408 | |
| 3409 | static void |
| 3410 | dw2_map_matching_symbols (const char * name, domain_enum namespace, |
| 3411 | struct objfile *objfile, int global, |
| 3412 | int (*callback) (struct block *, |
| 3413 | struct symbol *, void *), |
| 3414 | void *data, symbol_compare_ftype *match, |
| 3415 | symbol_compare_ftype *ordered_compare) |
| 3416 | { |
| 3417 | /* Currently unimplemented; used for Ada. The function can be called if the |
| 3418 | current language is Ada for a non-Ada objfile using GNU index. As Ada |
| 3419 | does not look for non-Ada symbols this function should just return. */ |
| 3420 | } |
| 3421 | |
| 3422 | static void |
| 3423 | dw2_expand_symtabs_matching |
| 3424 | (struct objfile *objfile, |
| 3425 | int (*file_matcher) (const char *, void *), |
| 3426 | int (*name_matcher) (const char *, void *), |
| 3427 | enum search_domain kind, |
| 3428 | void *data) |
| 3429 | { |
| 3430 | int i; |
| 3431 | offset_type iter; |
| 3432 | struct mapped_index *index; |
| 3433 | |
| 3434 | dw2_setup (objfile); |
| 3435 | |
| 3436 | /* index_table is NULL if OBJF_READNOW. */ |
| 3437 | if (!dwarf2_per_objfile->index_table) |
| 3438 | return; |
| 3439 | index = dwarf2_per_objfile->index_table; |
| 3440 | |
| 3441 | if (file_matcher != NULL) |
| 3442 | { |
| 3443 | struct cleanup *cleanup; |
| 3444 | htab_t visited_found, visited_not_found; |
| 3445 | |
| 3446 | dw2_build_type_unit_groups (); |
| 3447 | |
| 3448 | visited_found = htab_create_alloc (10, |
| 3449 | htab_hash_pointer, htab_eq_pointer, |
| 3450 | NULL, xcalloc, xfree); |
| 3451 | cleanup = make_cleanup_htab_delete (visited_found); |
| 3452 | visited_not_found = htab_create_alloc (10, |
| 3453 | htab_hash_pointer, htab_eq_pointer, |
| 3454 | NULL, xcalloc, xfree); |
| 3455 | make_cleanup_htab_delete (visited_not_found); |
| 3456 | |
| 3457 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3458 | + dwarf2_per_objfile->n_type_unit_groups); ++i) |
| 3459 | { |
| 3460 | int j; |
| 3461 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
| 3462 | struct quick_file_names *file_data; |
| 3463 | void **slot; |
| 3464 | |
| 3465 | per_cu->v.quick->mark = 0; |
| 3466 | |
| 3467 | /* We only need to look at symtabs not already expanded. */ |
| 3468 | if (per_cu->v.quick->symtab) |
| 3469 | continue; |
| 3470 | |
| 3471 | file_data = dw2_get_file_names (objfile, per_cu); |
| 3472 | if (file_data == NULL) |
| 3473 | continue; |
| 3474 | |
| 3475 | if (htab_find (visited_not_found, file_data) != NULL) |
| 3476 | continue; |
| 3477 | else if (htab_find (visited_found, file_data) != NULL) |
| 3478 | { |
| 3479 | per_cu->v.quick->mark = 1; |
| 3480 | continue; |
| 3481 | } |
| 3482 | |
| 3483 | for (j = 0; j < file_data->num_file_names; ++j) |
| 3484 | { |
| 3485 | if (file_matcher (file_data->file_names[j], data)) |
| 3486 | { |
| 3487 | per_cu->v.quick->mark = 1; |
| 3488 | break; |
| 3489 | } |
| 3490 | } |
| 3491 | |
| 3492 | slot = htab_find_slot (per_cu->v.quick->mark |
| 3493 | ? visited_found |
| 3494 | : visited_not_found, |
| 3495 | file_data, INSERT); |
| 3496 | *slot = file_data; |
| 3497 | } |
| 3498 | |
| 3499 | do_cleanups (cleanup); |
| 3500 | } |
| 3501 | |
| 3502 | for (iter = 0; iter < index->symbol_table_slots; ++iter) |
| 3503 | { |
| 3504 | offset_type idx = 2 * iter; |
| 3505 | const char *name; |
| 3506 | offset_type *vec, vec_len, vec_idx; |
| 3507 | |
| 3508 | if (index->symbol_table[idx] == 0 && index->symbol_table[idx + 1] == 0) |
| 3509 | continue; |
| 3510 | |
| 3511 | name = index->constant_pool + MAYBE_SWAP (index->symbol_table[idx]); |
| 3512 | |
| 3513 | if (! (*name_matcher) (name, data)) |
| 3514 | continue; |
| 3515 | |
| 3516 | /* The name was matched, now expand corresponding CUs that were |
| 3517 | marked. */ |
| 3518 | vec = (offset_type *) (index->constant_pool |
| 3519 | + MAYBE_SWAP (index->symbol_table[idx + 1])); |
| 3520 | vec_len = MAYBE_SWAP (vec[0]); |
| 3521 | for (vec_idx = 0; vec_idx < vec_len; ++vec_idx) |
| 3522 | { |
| 3523 | struct dwarf2_per_cu_data *per_cu; |
| 3524 | offset_type cu_index_and_attrs = MAYBE_SWAP (vec[vec_idx + 1]); |
| 3525 | gdb_index_symbol_kind symbol_kind = |
| 3526 | GDB_INDEX_SYMBOL_KIND_VALUE (cu_index_and_attrs); |
| 3527 | int cu_index = GDB_INDEX_CU_VALUE (cu_index_and_attrs); |
| 3528 | |
| 3529 | /* Don't crash on bad data. */ |
| 3530 | if (cu_index >= (dwarf2_per_objfile->n_comp_units |
| 3531 | + dwarf2_per_objfile->n_type_units)) |
| 3532 | continue; |
| 3533 | |
| 3534 | /* Only check the symbol's kind if it has one. |
| 3535 | Indices prior to version 7 don't record it. */ |
| 3536 | if (index->version >= 7) |
| 3537 | { |
| 3538 | switch (kind) |
| 3539 | { |
| 3540 | case VARIABLES_DOMAIN: |
| 3541 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_VARIABLE) |
| 3542 | continue; |
| 3543 | break; |
| 3544 | case FUNCTIONS_DOMAIN: |
| 3545 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_FUNCTION) |
| 3546 | continue; |
| 3547 | break; |
| 3548 | case TYPES_DOMAIN: |
| 3549 | if (symbol_kind != GDB_INDEX_SYMBOL_KIND_TYPE) |
| 3550 | continue; |
| 3551 | break; |
| 3552 | default: |
| 3553 | break; |
| 3554 | } |
| 3555 | } |
| 3556 | |
| 3557 | per_cu = dw2_get_cu (cu_index); |
| 3558 | if (file_matcher == NULL || per_cu->v.quick->mark) |
| 3559 | dw2_instantiate_symtab (per_cu); |
| 3560 | } |
| 3561 | } |
| 3562 | } |
| 3563 | |
| 3564 | /* A helper for dw2_find_pc_sect_symtab which finds the most specific |
| 3565 | symtab. */ |
| 3566 | |
| 3567 | static struct symtab * |
| 3568 | recursively_find_pc_sect_symtab (struct symtab *symtab, CORE_ADDR pc) |
| 3569 | { |
| 3570 | int i; |
| 3571 | |
| 3572 | if (BLOCKVECTOR (symtab) != NULL |
| 3573 | && blockvector_contains_pc (BLOCKVECTOR (symtab), pc)) |
| 3574 | return symtab; |
| 3575 | |
| 3576 | if (symtab->includes == NULL) |
| 3577 | return NULL; |
| 3578 | |
| 3579 | for (i = 0; symtab->includes[i]; ++i) |
| 3580 | { |
| 3581 | struct symtab *s = symtab->includes[i]; |
| 3582 | |
| 3583 | s = recursively_find_pc_sect_symtab (s, pc); |
| 3584 | if (s != NULL) |
| 3585 | return s; |
| 3586 | } |
| 3587 | |
| 3588 | return NULL; |
| 3589 | } |
| 3590 | |
| 3591 | static struct symtab * |
| 3592 | dw2_find_pc_sect_symtab (struct objfile *objfile, |
| 3593 | struct minimal_symbol *msymbol, |
| 3594 | CORE_ADDR pc, |
| 3595 | struct obj_section *section, |
| 3596 | int warn_if_readin) |
| 3597 | { |
| 3598 | struct dwarf2_per_cu_data *data; |
| 3599 | struct symtab *result; |
| 3600 | |
| 3601 | dw2_setup (objfile); |
| 3602 | |
| 3603 | if (!objfile->psymtabs_addrmap) |
| 3604 | return NULL; |
| 3605 | |
| 3606 | data = addrmap_find (objfile->psymtabs_addrmap, pc); |
| 3607 | if (!data) |
| 3608 | return NULL; |
| 3609 | |
| 3610 | if (warn_if_readin && data->v.quick->symtab) |
| 3611 | warning (_("(Internal error: pc %s in read in CU, but not in symtab.)"), |
| 3612 | paddress (get_objfile_arch (objfile), pc)); |
| 3613 | |
| 3614 | result = recursively_find_pc_sect_symtab (dw2_instantiate_symtab (data), pc); |
| 3615 | gdb_assert (result != NULL); |
| 3616 | return result; |
| 3617 | } |
| 3618 | |
| 3619 | static void |
| 3620 | dw2_map_symbol_filenames (struct objfile *objfile, symbol_filename_ftype *fun, |
| 3621 | void *data, int need_fullname) |
| 3622 | { |
| 3623 | int i; |
| 3624 | struct cleanup *cleanup; |
| 3625 | htab_t visited = htab_create_alloc (10, htab_hash_pointer, htab_eq_pointer, |
| 3626 | NULL, xcalloc, xfree); |
| 3627 | |
| 3628 | cleanup = make_cleanup_htab_delete (visited); |
| 3629 | dw2_setup (objfile); |
| 3630 | |
| 3631 | dw2_build_type_unit_groups (); |
| 3632 | |
| 3633 | /* We can ignore file names coming from already-expanded CUs. */ |
| 3634 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3635 | + dwarf2_per_objfile->n_type_units); ++i) |
| 3636 | { |
| 3637 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 3638 | |
| 3639 | if (per_cu->v.quick->symtab) |
| 3640 | { |
| 3641 | void **slot = htab_find_slot (visited, per_cu->v.quick->file_names, |
| 3642 | INSERT); |
| 3643 | |
| 3644 | *slot = per_cu->v.quick->file_names; |
| 3645 | } |
| 3646 | } |
| 3647 | |
| 3648 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3649 | + dwarf2_per_objfile->n_type_unit_groups); ++i) |
| 3650 | { |
| 3651 | int j; |
| 3652 | struct dwarf2_per_cu_data *per_cu = dw2_get_primary_cu (i); |
| 3653 | struct quick_file_names *file_data; |
| 3654 | void **slot; |
| 3655 | |
| 3656 | /* We only need to look at symtabs not already expanded. */ |
| 3657 | if (per_cu->v.quick->symtab) |
| 3658 | continue; |
| 3659 | |
| 3660 | file_data = dw2_get_file_names (objfile, per_cu); |
| 3661 | if (file_data == NULL) |
| 3662 | continue; |
| 3663 | |
| 3664 | slot = htab_find_slot (visited, file_data, INSERT); |
| 3665 | if (*slot) |
| 3666 | { |
| 3667 | /* Already visited. */ |
| 3668 | continue; |
| 3669 | } |
| 3670 | *slot = file_data; |
| 3671 | |
| 3672 | for (j = 0; j < file_data->num_file_names; ++j) |
| 3673 | { |
| 3674 | const char *this_real_name; |
| 3675 | |
| 3676 | if (need_fullname) |
| 3677 | this_real_name = dw2_get_real_path (objfile, file_data, j); |
| 3678 | else |
| 3679 | this_real_name = NULL; |
| 3680 | (*fun) (file_data->file_names[j], this_real_name, data); |
| 3681 | } |
| 3682 | } |
| 3683 | |
| 3684 | do_cleanups (cleanup); |
| 3685 | } |
| 3686 | |
| 3687 | static int |
| 3688 | dw2_has_symbols (struct objfile *objfile) |
| 3689 | { |
| 3690 | return 1; |
| 3691 | } |
| 3692 | |
| 3693 | const struct quick_symbol_functions dwarf2_gdb_index_functions = |
| 3694 | { |
| 3695 | dw2_has_symbols, |
| 3696 | dw2_find_last_source_symtab, |
| 3697 | dw2_forget_cached_source_info, |
| 3698 | dw2_map_symtabs_matching_filename, |
| 3699 | dw2_lookup_symbol, |
| 3700 | dw2_pre_expand_symtabs_matching, |
| 3701 | dw2_print_stats, |
| 3702 | dw2_dump, |
| 3703 | dw2_relocate, |
| 3704 | dw2_expand_symtabs_for_function, |
| 3705 | dw2_expand_all_symtabs, |
| 3706 | dw2_expand_symtabs_with_filename, |
| 3707 | dw2_find_symbol_file, |
| 3708 | dw2_map_matching_symbols, |
| 3709 | dw2_expand_symtabs_matching, |
| 3710 | dw2_find_pc_sect_symtab, |
| 3711 | dw2_map_symbol_filenames |
| 3712 | }; |
| 3713 | |
| 3714 | /* Initialize for reading DWARF for this objfile. Return 0 if this |
| 3715 | file will use psymtabs, or 1 if using the GNU index. */ |
| 3716 | |
| 3717 | int |
| 3718 | dwarf2_initialize_objfile (struct objfile *objfile) |
| 3719 | { |
| 3720 | /* If we're about to read full symbols, don't bother with the |
| 3721 | indices. In this case we also don't care if some other debug |
| 3722 | format is making psymtabs, because they are all about to be |
| 3723 | expanded anyway. */ |
| 3724 | if ((objfile->flags & OBJF_READNOW)) |
| 3725 | { |
| 3726 | int i; |
| 3727 | |
| 3728 | dwarf2_per_objfile->using_index = 1; |
| 3729 | create_all_comp_units (objfile); |
| 3730 | create_all_type_units (objfile); |
| 3731 | dwarf2_per_objfile->quick_file_names_table = |
| 3732 | create_quick_file_names_table (dwarf2_per_objfile->n_comp_units); |
| 3733 | |
| 3734 | for (i = 0; i < (dwarf2_per_objfile->n_comp_units |
| 3735 | + dwarf2_per_objfile->n_type_units); ++i) |
| 3736 | { |
| 3737 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 3738 | |
| 3739 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 3740 | struct dwarf2_per_cu_quick_data); |
| 3741 | } |
| 3742 | |
| 3743 | /* Return 1 so that gdb sees the "quick" functions. However, |
| 3744 | these functions will be no-ops because we will have expanded |
| 3745 | all symtabs. */ |
| 3746 | return 1; |
| 3747 | } |
| 3748 | |
| 3749 | if (dwarf2_read_index (objfile)) |
| 3750 | return 1; |
| 3751 | |
| 3752 | return 0; |
| 3753 | } |
| 3754 | |
| 3755 | \f |
| 3756 | |
| 3757 | /* Build a partial symbol table. */ |
| 3758 | |
| 3759 | void |
| 3760 | dwarf2_build_psymtabs (struct objfile *objfile) |
| 3761 | { |
| 3762 | if (objfile->global_psymbols.size == 0 && objfile->static_psymbols.size == 0) |
| 3763 | { |
| 3764 | init_psymbol_list (objfile, 1024); |
| 3765 | } |
| 3766 | |
| 3767 | dwarf2_build_psymtabs_hard (objfile); |
| 3768 | } |
| 3769 | |
| 3770 | /* Return the total length of the CU described by HEADER. */ |
| 3771 | |
| 3772 | static unsigned int |
| 3773 | get_cu_length (const struct comp_unit_head *header) |
| 3774 | { |
| 3775 | return header->initial_length_size + header->length; |
| 3776 | } |
| 3777 | |
| 3778 | /* Return TRUE if OFFSET is within CU_HEADER. */ |
| 3779 | |
| 3780 | static inline int |
| 3781 | offset_in_cu_p (const struct comp_unit_head *cu_header, sect_offset offset) |
| 3782 | { |
| 3783 | sect_offset bottom = { cu_header->offset.sect_off }; |
| 3784 | sect_offset top = { cu_header->offset.sect_off + get_cu_length (cu_header) }; |
| 3785 | |
| 3786 | return (offset.sect_off >= bottom.sect_off && offset.sect_off < top.sect_off); |
| 3787 | } |
| 3788 | |
| 3789 | /* Find the base address of the compilation unit for range lists and |
| 3790 | location lists. It will normally be specified by DW_AT_low_pc. |
| 3791 | In DWARF-3 draft 4, the base address could be overridden by |
| 3792 | DW_AT_entry_pc. It's been removed, but GCC still uses this for |
| 3793 | compilation units with discontinuous ranges. */ |
| 3794 | |
| 3795 | static void |
| 3796 | dwarf2_find_base_address (struct die_info *die, struct dwarf2_cu *cu) |
| 3797 | { |
| 3798 | struct attribute *attr; |
| 3799 | |
| 3800 | cu->base_known = 0; |
| 3801 | cu->base_address = 0; |
| 3802 | |
| 3803 | attr = dwarf2_attr (die, DW_AT_entry_pc, cu); |
| 3804 | if (attr) |
| 3805 | { |
| 3806 | cu->base_address = DW_ADDR (attr); |
| 3807 | cu->base_known = 1; |
| 3808 | } |
| 3809 | else |
| 3810 | { |
| 3811 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 3812 | if (attr) |
| 3813 | { |
| 3814 | cu->base_address = DW_ADDR (attr); |
| 3815 | cu->base_known = 1; |
| 3816 | } |
| 3817 | } |
| 3818 | } |
| 3819 | |
| 3820 | /* Read in the comp unit header information from the debug_info at info_ptr. |
| 3821 | NOTE: This leaves members offset, first_die_offset to be filled in |
| 3822 | by the caller. */ |
| 3823 | |
| 3824 | static gdb_byte * |
| 3825 | read_comp_unit_head (struct comp_unit_head *cu_header, |
| 3826 | gdb_byte *info_ptr, bfd *abfd) |
| 3827 | { |
| 3828 | int signed_addr; |
| 3829 | unsigned int bytes_read; |
| 3830 | |
| 3831 | cu_header->length = read_initial_length (abfd, info_ptr, &bytes_read); |
| 3832 | cu_header->initial_length_size = bytes_read; |
| 3833 | cu_header->offset_size = (bytes_read == 4) ? 4 : 8; |
| 3834 | info_ptr += bytes_read; |
| 3835 | cu_header->version = read_2_bytes (abfd, info_ptr); |
| 3836 | info_ptr += 2; |
| 3837 | cu_header->abbrev_offset.sect_off = read_offset (abfd, info_ptr, cu_header, |
| 3838 | &bytes_read); |
| 3839 | info_ptr += bytes_read; |
| 3840 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
| 3841 | info_ptr += 1; |
| 3842 | signed_addr = bfd_get_sign_extend_vma (abfd); |
| 3843 | if (signed_addr < 0) |
| 3844 | internal_error (__FILE__, __LINE__, |
| 3845 | _("read_comp_unit_head: dwarf from non elf file")); |
| 3846 | cu_header->signed_addr_p = signed_addr; |
| 3847 | |
| 3848 | return info_ptr; |
| 3849 | } |
| 3850 | |
| 3851 | /* Helper function that returns the proper abbrev section for |
| 3852 | THIS_CU. */ |
| 3853 | |
| 3854 | static struct dwarf2_section_info * |
| 3855 | get_abbrev_section_for_cu (struct dwarf2_per_cu_data *this_cu) |
| 3856 | { |
| 3857 | struct dwarf2_section_info *abbrev; |
| 3858 | |
| 3859 | if (this_cu->is_dwz) |
| 3860 | abbrev = &dwarf2_get_dwz_file ()->abbrev; |
| 3861 | else |
| 3862 | abbrev = &dwarf2_per_objfile->abbrev; |
| 3863 | |
| 3864 | return abbrev; |
| 3865 | } |
| 3866 | |
| 3867 | /* Subroutine of read_and_check_comp_unit_head and |
| 3868 | read_and_check_type_unit_head to simplify them. |
| 3869 | Perform various error checking on the header. */ |
| 3870 | |
| 3871 | static void |
| 3872 | error_check_comp_unit_head (struct comp_unit_head *header, |
| 3873 | struct dwarf2_section_info *section, |
| 3874 | struct dwarf2_section_info *abbrev_section) |
| 3875 | { |
| 3876 | bfd *abfd = section->asection->owner; |
| 3877 | const char *filename = bfd_get_filename (abfd); |
| 3878 | |
| 3879 | if (header->version != 2 && header->version != 3 && header->version != 4) |
| 3880 | error (_("Dwarf Error: wrong version in compilation unit header " |
| 3881 | "(is %d, should be 2, 3, or 4) [in module %s]"), header->version, |
| 3882 | filename); |
| 3883 | |
| 3884 | if (header->abbrev_offset.sect_off |
| 3885 | >= dwarf2_section_size (dwarf2_per_objfile->objfile, abbrev_section)) |
| 3886 | error (_("Dwarf Error: bad offset (0x%lx) in compilation unit header " |
| 3887 | "(offset 0x%lx + 6) [in module %s]"), |
| 3888 | (long) header->abbrev_offset.sect_off, (long) header->offset.sect_off, |
| 3889 | filename); |
| 3890 | |
| 3891 | /* Cast to unsigned long to use 64-bit arithmetic when possible to |
| 3892 | avoid potential 32-bit overflow. */ |
| 3893 | if (((unsigned long) header->offset.sect_off + get_cu_length (header)) |
| 3894 | > section->size) |
| 3895 | error (_("Dwarf Error: bad length (0x%lx) in compilation unit header " |
| 3896 | "(offset 0x%lx + 0) [in module %s]"), |
| 3897 | (long) header->length, (long) header->offset.sect_off, |
| 3898 | filename); |
| 3899 | } |
| 3900 | |
| 3901 | /* Read in a CU/TU header and perform some basic error checking. |
| 3902 | The contents of the header are stored in HEADER. |
| 3903 | The result is a pointer to the start of the first DIE. */ |
| 3904 | |
| 3905 | static gdb_byte * |
| 3906 | read_and_check_comp_unit_head (struct comp_unit_head *header, |
| 3907 | struct dwarf2_section_info *section, |
| 3908 | struct dwarf2_section_info *abbrev_section, |
| 3909 | gdb_byte *info_ptr, |
| 3910 | int is_debug_types_section) |
| 3911 | { |
| 3912 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 3913 | bfd *abfd = section->asection->owner; |
| 3914 | |
| 3915 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
| 3916 | |
| 3917 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
| 3918 | |
| 3919 | /* If we're reading a type unit, skip over the signature and |
| 3920 | type_offset fields. */ |
| 3921 | if (is_debug_types_section) |
| 3922 | info_ptr += 8 /*signature*/ + header->offset_size; |
| 3923 | |
| 3924 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
| 3925 | |
| 3926 | error_check_comp_unit_head (header, section, abbrev_section); |
| 3927 | |
| 3928 | return info_ptr; |
| 3929 | } |
| 3930 | |
| 3931 | /* Read in the types comp unit header information from .debug_types entry at |
| 3932 | types_ptr. The result is a pointer to one past the end of the header. */ |
| 3933 | |
| 3934 | static gdb_byte * |
| 3935 | read_and_check_type_unit_head (struct comp_unit_head *header, |
| 3936 | struct dwarf2_section_info *section, |
| 3937 | struct dwarf2_section_info *abbrev_section, |
| 3938 | gdb_byte *info_ptr, |
| 3939 | ULONGEST *signature, |
| 3940 | cu_offset *type_offset_in_tu) |
| 3941 | { |
| 3942 | gdb_byte *beg_of_comp_unit = info_ptr; |
| 3943 | bfd *abfd = section->asection->owner; |
| 3944 | |
| 3945 | header->offset.sect_off = beg_of_comp_unit - section->buffer; |
| 3946 | |
| 3947 | info_ptr = read_comp_unit_head (header, info_ptr, abfd); |
| 3948 | |
| 3949 | /* If we're reading a type unit, skip over the signature and |
| 3950 | type_offset fields. */ |
| 3951 | if (signature != NULL) |
| 3952 | *signature = read_8_bytes (abfd, info_ptr); |
| 3953 | info_ptr += 8; |
| 3954 | if (type_offset_in_tu != NULL) |
| 3955 | type_offset_in_tu->cu_off = read_offset_1 (abfd, info_ptr, |
| 3956 | header->offset_size); |
| 3957 | info_ptr += header->offset_size; |
| 3958 | |
| 3959 | header->first_die_offset.cu_off = info_ptr - beg_of_comp_unit; |
| 3960 | |
| 3961 | error_check_comp_unit_head (header, section, abbrev_section); |
| 3962 | |
| 3963 | return info_ptr; |
| 3964 | } |
| 3965 | |
| 3966 | /* Fetch the abbreviation table offset from a comp or type unit header. */ |
| 3967 | |
| 3968 | static sect_offset |
| 3969 | read_abbrev_offset (struct dwarf2_section_info *section, |
| 3970 | sect_offset offset) |
| 3971 | { |
| 3972 | bfd *abfd = section->asection->owner; |
| 3973 | gdb_byte *info_ptr; |
| 3974 | unsigned int length, initial_length_size, offset_size; |
| 3975 | sect_offset abbrev_offset; |
| 3976 | |
| 3977 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
| 3978 | info_ptr = section->buffer + offset.sect_off; |
| 3979 | length = read_initial_length (abfd, info_ptr, &initial_length_size); |
| 3980 | offset_size = initial_length_size == 4 ? 4 : 8; |
| 3981 | info_ptr += initial_length_size + 2 /*version*/; |
| 3982 | abbrev_offset.sect_off = read_offset_1 (abfd, info_ptr, offset_size); |
| 3983 | return abbrev_offset; |
| 3984 | } |
| 3985 | |
| 3986 | /* Allocate a new partial symtab for file named NAME and mark this new |
| 3987 | partial symtab as being an include of PST. */ |
| 3988 | |
| 3989 | static void |
| 3990 | dwarf2_create_include_psymtab (char *name, struct partial_symtab *pst, |
| 3991 | struct objfile *objfile) |
| 3992 | { |
| 3993 | struct partial_symtab *subpst = allocate_psymtab (name, objfile); |
| 3994 | |
| 3995 | subpst->section_offsets = pst->section_offsets; |
| 3996 | subpst->textlow = 0; |
| 3997 | subpst->texthigh = 0; |
| 3998 | |
| 3999 | subpst->dependencies = (struct partial_symtab **) |
| 4000 | obstack_alloc (&objfile->objfile_obstack, |
| 4001 | sizeof (struct partial_symtab *)); |
| 4002 | subpst->dependencies[0] = pst; |
| 4003 | subpst->number_of_dependencies = 1; |
| 4004 | |
| 4005 | subpst->globals_offset = 0; |
| 4006 | subpst->n_global_syms = 0; |
| 4007 | subpst->statics_offset = 0; |
| 4008 | subpst->n_static_syms = 0; |
| 4009 | subpst->symtab = NULL; |
| 4010 | subpst->read_symtab = pst->read_symtab; |
| 4011 | subpst->readin = 0; |
| 4012 | |
| 4013 | /* No private part is necessary for include psymtabs. This property |
| 4014 | can be used to differentiate between such include psymtabs and |
| 4015 | the regular ones. */ |
| 4016 | subpst->read_symtab_private = NULL; |
| 4017 | } |
| 4018 | |
| 4019 | /* Read the Line Number Program data and extract the list of files |
| 4020 | included by the source file represented by PST. Build an include |
| 4021 | partial symtab for each of these included files. */ |
| 4022 | |
| 4023 | static void |
| 4024 | dwarf2_build_include_psymtabs (struct dwarf2_cu *cu, |
| 4025 | struct die_info *die, |
| 4026 | struct partial_symtab *pst) |
| 4027 | { |
| 4028 | struct line_header *lh = NULL; |
| 4029 | struct attribute *attr; |
| 4030 | |
| 4031 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 4032 | if (attr) |
| 4033 | lh = dwarf_decode_line_header (DW_UNSND (attr), cu); |
| 4034 | if (lh == NULL) |
| 4035 | return; /* No linetable, so no includes. */ |
| 4036 | |
| 4037 | /* NOTE: pst->dirname is DW_AT_comp_dir (if present). */ |
| 4038 | dwarf_decode_lines (lh, pst->dirname, cu, pst, 1); |
| 4039 | |
| 4040 | free_line_header (lh); |
| 4041 | } |
| 4042 | |
| 4043 | static hashval_t |
| 4044 | hash_signatured_type (const void *item) |
| 4045 | { |
| 4046 | const struct signatured_type *sig_type = item; |
| 4047 | |
| 4048 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
| 4049 | return sig_type->signature; |
| 4050 | } |
| 4051 | |
| 4052 | static int |
| 4053 | eq_signatured_type (const void *item_lhs, const void *item_rhs) |
| 4054 | { |
| 4055 | const struct signatured_type *lhs = item_lhs; |
| 4056 | const struct signatured_type *rhs = item_rhs; |
| 4057 | |
| 4058 | return lhs->signature == rhs->signature; |
| 4059 | } |
| 4060 | |
| 4061 | /* Allocate a hash table for signatured types. */ |
| 4062 | |
| 4063 | static htab_t |
| 4064 | allocate_signatured_type_table (struct objfile *objfile) |
| 4065 | { |
| 4066 | return htab_create_alloc_ex (41, |
| 4067 | hash_signatured_type, |
| 4068 | eq_signatured_type, |
| 4069 | NULL, |
| 4070 | &objfile->objfile_obstack, |
| 4071 | hashtab_obstack_allocate, |
| 4072 | dummy_obstack_deallocate); |
| 4073 | } |
| 4074 | |
| 4075 | /* A helper function to add a signatured type CU to a table. */ |
| 4076 | |
| 4077 | static int |
| 4078 | add_signatured_type_cu_to_table (void **slot, void *datum) |
| 4079 | { |
| 4080 | struct signatured_type *sigt = *slot; |
| 4081 | struct signatured_type ***datap = datum; |
| 4082 | |
| 4083 | **datap = sigt; |
| 4084 | ++*datap; |
| 4085 | |
| 4086 | return 1; |
| 4087 | } |
| 4088 | |
| 4089 | /* Create the hash table of all entries in the .debug_types section. |
| 4090 | DWO_FILE is a pointer to the DWO file for .debug_types.dwo, |
| 4091 | NULL otherwise. |
| 4092 | Note: This function processes DWO files only, not DWP files. |
| 4093 | The result is a pointer to the hash table or NULL if there are |
| 4094 | no types. */ |
| 4095 | |
| 4096 | static htab_t |
| 4097 | create_debug_types_hash_table (struct dwo_file *dwo_file, |
| 4098 | VEC (dwarf2_section_info_def) *types) |
| 4099 | { |
| 4100 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 4101 | htab_t types_htab = NULL; |
| 4102 | int ix; |
| 4103 | struct dwarf2_section_info *section; |
| 4104 | struct dwarf2_section_info *abbrev_section; |
| 4105 | |
| 4106 | if (VEC_empty (dwarf2_section_info_def, types)) |
| 4107 | return NULL; |
| 4108 | |
| 4109 | abbrev_section = (dwo_file != NULL |
| 4110 | ? &dwo_file->sections.abbrev |
| 4111 | : &dwarf2_per_objfile->abbrev); |
| 4112 | |
| 4113 | if (dwarf2_read_debug) |
| 4114 | fprintf_unfiltered (gdb_stdlog, "Reading .debug_types%s for %s:\n", |
| 4115 | dwo_file ? ".dwo" : "", |
| 4116 | bfd_get_filename (abbrev_section->asection->owner)); |
| 4117 | |
| 4118 | for (ix = 0; |
| 4119 | VEC_iterate (dwarf2_section_info_def, types, ix, section); |
| 4120 | ++ix) |
| 4121 | { |
| 4122 | bfd *abfd; |
| 4123 | gdb_byte *info_ptr, *end_ptr; |
| 4124 | struct dwarf2_section_info *abbrev_section; |
| 4125 | |
| 4126 | dwarf2_read_section (objfile, section); |
| 4127 | info_ptr = section->buffer; |
| 4128 | |
| 4129 | if (info_ptr == NULL) |
| 4130 | continue; |
| 4131 | |
| 4132 | /* We can't set abfd until now because the section may be empty or |
| 4133 | not present, in which case section->asection will be NULL. */ |
| 4134 | abfd = section->asection->owner; |
| 4135 | |
| 4136 | if (dwo_file) |
| 4137 | abbrev_section = &dwo_file->sections.abbrev; |
| 4138 | else |
| 4139 | abbrev_section = &dwarf2_per_objfile->abbrev; |
| 4140 | |
| 4141 | if (types_htab == NULL) |
| 4142 | { |
| 4143 | if (dwo_file) |
| 4144 | types_htab = allocate_dwo_unit_table (objfile); |
| 4145 | else |
| 4146 | types_htab = allocate_signatured_type_table (objfile); |
| 4147 | } |
| 4148 | |
| 4149 | /* We don't use init_cutu_and_read_dies_simple, or some such, here |
| 4150 | because we don't need to read any dies: the signature is in the |
| 4151 | header. */ |
| 4152 | |
| 4153 | end_ptr = info_ptr + section->size; |
| 4154 | while (info_ptr < end_ptr) |
| 4155 | { |
| 4156 | sect_offset offset; |
| 4157 | cu_offset type_offset_in_tu; |
| 4158 | ULONGEST signature; |
| 4159 | struct signatured_type *sig_type; |
| 4160 | struct dwo_unit *dwo_tu; |
| 4161 | void **slot; |
| 4162 | gdb_byte *ptr = info_ptr; |
| 4163 | struct comp_unit_head header; |
| 4164 | unsigned int length; |
| 4165 | |
| 4166 | offset.sect_off = ptr - section->buffer; |
| 4167 | |
| 4168 | /* We need to read the type's signature in order to build the hash |
| 4169 | table, but we don't need anything else just yet. */ |
| 4170 | |
| 4171 | ptr = read_and_check_type_unit_head (&header, section, |
| 4172 | abbrev_section, ptr, |
| 4173 | &signature, &type_offset_in_tu); |
| 4174 | |
| 4175 | length = get_cu_length (&header); |
| 4176 | |
| 4177 | /* Skip dummy type units. */ |
| 4178 | if (ptr >= info_ptr + length |
| 4179 | || peek_abbrev_code (abfd, ptr) == 0) |
| 4180 | { |
| 4181 | info_ptr += length; |
| 4182 | continue; |
| 4183 | } |
| 4184 | |
| 4185 | if (dwo_file) |
| 4186 | { |
| 4187 | sig_type = NULL; |
| 4188 | dwo_tu = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 4189 | struct dwo_unit); |
| 4190 | dwo_tu->dwo_file = dwo_file; |
| 4191 | dwo_tu->signature = signature; |
| 4192 | dwo_tu->type_offset_in_tu = type_offset_in_tu; |
| 4193 | dwo_tu->info_or_types_section = section; |
| 4194 | dwo_tu->offset = offset; |
| 4195 | dwo_tu->length = length; |
| 4196 | } |
| 4197 | else |
| 4198 | { |
| 4199 | /* N.B.: type_offset is not usable if this type uses a DWO file. |
| 4200 | The real type_offset is in the DWO file. */ |
| 4201 | dwo_tu = NULL; |
| 4202 | sig_type = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 4203 | struct signatured_type); |
| 4204 | sig_type->signature = signature; |
| 4205 | sig_type->type_offset_in_tu = type_offset_in_tu; |
| 4206 | sig_type->per_cu.objfile = objfile; |
| 4207 | sig_type->per_cu.is_debug_types = 1; |
| 4208 | sig_type->per_cu.info_or_types_section = section; |
| 4209 | sig_type->per_cu.offset = offset; |
| 4210 | sig_type->per_cu.length = length; |
| 4211 | } |
| 4212 | |
| 4213 | slot = htab_find_slot (types_htab, |
| 4214 | dwo_file ? (void*) dwo_tu : (void *) sig_type, |
| 4215 | INSERT); |
| 4216 | gdb_assert (slot != NULL); |
| 4217 | if (*slot != NULL) |
| 4218 | { |
| 4219 | sect_offset dup_offset; |
| 4220 | |
| 4221 | if (dwo_file) |
| 4222 | { |
| 4223 | const struct dwo_unit *dup_tu = *slot; |
| 4224 | |
| 4225 | dup_offset = dup_tu->offset; |
| 4226 | } |
| 4227 | else |
| 4228 | { |
| 4229 | const struct signatured_type *dup_tu = *slot; |
| 4230 | |
| 4231 | dup_offset = dup_tu->per_cu.offset; |
| 4232 | } |
| 4233 | |
| 4234 | complaint (&symfile_complaints, |
| 4235 | _("debug type entry at offset 0x%x is duplicate to the " |
| 4236 | "entry at offset 0x%x, signature 0x%s"), |
| 4237 | offset.sect_off, dup_offset.sect_off, |
| 4238 | phex (signature, sizeof (signature))); |
| 4239 | } |
| 4240 | *slot = dwo_file ? (void *) dwo_tu : (void *) sig_type; |
| 4241 | |
| 4242 | if (dwarf2_read_debug) |
| 4243 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, signature 0x%s\n", |
| 4244 | offset.sect_off, |
| 4245 | phex (signature, sizeof (signature))); |
| 4246 | |
| 4247 | info_ptr += length; |
| 4248 | } |
| 4249 | } |
| 4250 | |
| 4251 | return types_htab; |
| 4252 | } |
| 4253 | |
| 4254 | /* Create the hash table of all entries in the .debug_types section, |
| 4255 | and initialize all_type_units. |
| 4256 | The result is zero if there is an error (e.g. missing .debug_types section), |
| 4257 | otherwise non-zero. */ |
| 4258 | |
| 4259 | static int |
| 4260 | create_all_type_units (struct objfile *objfile) |
| 4261 | { |
| 4262 | htab_t types_htab; |
| 4263 | struct signatured_type **iter; |
| 4264 | |
| 4265 | types_htab = create_debug_types_hash_table (NULL, dwarf2_per_objfile->types); |
| 4266 | if (types_htab == NULL) |
| 4267 | { |
| 4268 | dwarf2_per_objfile->signatured_types = NULL; |
| 4269 | return 0; |
| 4270 | } |
| 4271 | |
| 4272 | dwarf2_per_objfile->signatured_types = types_htab; |
| 4273 | |
| 4274 | dwarf2_per_objfile->n_type_units = htab_elements (types_htab); |
| 4275 | dwarf2_per_objfile->all_type_units |
| 4276 | = obstack_alloc (&objfile->objfile_obstack, |
| 4277 | dwarf2_per_objfile->n_type_units |
| 4278 | * sizeof (struct signatured_type *)); |
| 4279 | iter = &dwarf2_per_objfile->all_type_units[0]; |
| 4280 | htab_traverse_noresize (types_htab, add_signatured_type_cu_to_table, &iter); |
| 4281 | gdb_assert (iter - &dwarf2_per_objfile->all_type_units[0] |
| 4282 | == dwarf2_per_objfile->n_type_units); |
| 4283 | |
| 4284 | return 1; |
| 4285 | } |
| 4286 | |
| 4287 | /* Lookup a signature based type for DW_FORM_ref_sig8. |
| 4288 | Returns NULL if signature SIG is not present in the table. */ |
| 4289 | |
| 4290 | static struct signatured_type * |
| 4291 | lookup_signatured_type (ULONGEST sig) |
| 4292 | { |
| 4293 | struct signatured_type find_entry, *entry; |
| 4294 | |
| 4295 | if (dwarf2_per_objfile->signatured_types == NULL) |
| 4296 | { |
| 4297 | complaint (&symfile_complaints, |
| 4298 | _("missing `.debug_types' section for DW_FORM_ref_sig8 die")); |
| 4299 | return NULL; |
| 4300 | } |
| 4301 | |
| 4302 | find_entry.signature = sig; |
| 4303 | entry = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
| 4304 | return entry; |
| 4305 | } |
| 4306 | \f |
| 4307 | /* Low level DIE reading support. */ |
| 4308 | |
| 4309 | /* Initialize a die_reader_specs struct from a dwarf2_cu struct. */ |
| 4310 | |
| 4311 | static void |
| 4312 | init_cu_die_reader (struct die_reader_specs *reader, |
| 4313 | struct dwarf2_cu *cu, |
| 4314 | struct dwarf2_section_info *section, |
| 4315 | struct dwo_file *dwo_file) |
| 4316 | { |
| 4317 | gdb_assert (section->readin && section->buffer != NULL); |
| 4318 | reader->abfd = section->asection->owner; |
| 4319 | reader->cu = cu; |
| 4320 | reader->dwo_file = dwo_file; |
| 4321 | reader->die_section = section; |
| 4322 | reader->buffer = section->buffer; |
| 4323 | reader->buffer_end = section->buffer + section->size; |
| 4324 | } |
| 4325 | |
| 4326 | /* Initialize a CU (or TU) and read its DIEs. |
| 4327 | If the CU defers to a DWO file, read the DWO file as well. |
| 4328 | |
| 4329 | ABBREV_TABLE, if non-NULL, is the abbreviation table to use. |
| 4330 | Otherwise the table specified in the comp unit header is read in and used. |
| 4331 | This is an optimization for when we already have the abbrev table. |
| 4332 | |
| 4333 | If USE_EXISTING_CU is non-zero, and THIS_CU->cu is non-NULL, then use it. |
| 4334 | Otherwise, a new CU is allocated with xmalloc. |
| 4335 | |
| 4336 | If KEEP is non-zero, then if we allocated a dwarf2_cu we add it to |
| 4337 | read_in_chain. Otherwise the dwarf2_cu data is freed at the end. |
| 4338 | |
| 4339 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental |
| 4340 | linker) then DIE_READER_FUNC will not get called. */ |
| 4341 | |
| 4342 | static void |
| 4343 | init_cutu_and_read_dies (struct dwarf2_per_cu_data *this_cu, |
| 4344 | struct abbrev_table *abbrev_table, |
| 4345 | int use_existing_cu, int keep, |
| 4346 | die_reader_func_ftype *die_reader_func, |
| 4347 | void *data) |
| 4348 | { |
| 4349 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 4350 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
| 4351 | bfd *abfd = section->asection->owner; |
| 4352 | struct dwarf2_cu *cu; |
| 4353 | gdb_byte *begin_info_ptr, *info_ptr; |
| 4354 | struct die_reader_specs reader; |
| 4355 | struct die_info *comp_unit_die; |
| 4356 | int has_children; |
| 4357 | struct attribute *attr; |
| 4358 | struct cleanup *cleanups, *free_cu_cleanup = NULL; |
| 4359 | struct signatured_type *sig_type = NULL; |
| 4360 | struct dwarf2_section_info *abbrev_section; |
| 4361 | /* Non-zero if CU currently points to a DWO file and we need to |
| 4362 | reread it. When this happens we need to reread the skeleton die |
| 4363 | before we can reread the DWO file. */ |
| 4364 | int rereading_dwo_cu = 0; |
| 4365 | |
| 4366 | if (dwarf2_die_debug) |
| 4367 | fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n", |
| 4368 | this_cu->is_debug_types ? "type" : "comp", |
| 4369 | this_cu->offset.sect_off); |
| 4370 | |
| 4371 | if (use_existing_cu) |
| 4372 | gdb_assert (keep); |
| 4373 | |
| 4374 | cleanups = make_cleanup (null_cleanup, NULL); |
| 4375 | |
| 4376 | /* This is cheap if the section is already read in. */ |
| 4377 | dwarf2_read_section (objfile, section); |
| 4378 | |
| 4379 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; |
| 4380 | |
| 4381 | abbrev_section = get_abbrev_section_for_cu (this_cu); |
| 4382 | |
| 4383 | if (use_existing_cu && this_cu->cu != NULL) |
| 4384 | { |
| 4385 | cu = this_cu->cu; |
| 4386 | |
| 4387 | /* If this CU is from a DWO file we need to start over, we need to |
| 4388 | refetch the attributes from the skeleton CU. |
| 4389 | This could be optimized by retrieving those attributes from when we |
| 4390 | were here the first time: the previous comp_unit_die was stored in |
| 4391 | comp_unit_obstack. But there's no data yet that we need this |
| 4392 | optimization. */ |
| 4393 | if (cu->dwo_unit != NULL) |
| 4394 | rereading_dwo_cu = 1; |
| 4395 | } |
| 4396 | else |
| 4397 | { |
| 4398 | /* If !use_existing_cu, this_cu->cu must be NULL. */ |
| 4399 | gdb_assert (this_cu->cu == NULL); |
| 4400 | |
| 4401 | cu = xmalloc (sizeof (*cu)); |
| 4402 | init_one_comp_unit (cu, this_cu); |
| 4403 | |
| 4404 | /* If an error occurs while loading, release our storage. */ |
| 4405 | free_cu_cleanup = make_cleanup (free_heap_comp_unit, cu); |
| 4406 | } |
| 4407 | |
| 4408 | if (cu->header.first_die_offset.cu_off != 0 && ! rereading_dwo_cu) |
| 4409 | { |
| 4410 | /* We already have the header, there's no need to read it in again. */ |
| 4411 | info_ptr += cu->header.first_die_offset.cu_off; |
| 4412 | } |
| 4413 | else |
| 4414 | { |
| 4415 | if (this_cu->is_debug_types) |
| 4416 | { |
| 4417 | ULONGEST signature; |
| 4418 | cu_offset type_offset_in_tu; |
| 4419 | |
| 4420 | info_ptr = read_and_check_type_unit_head (&cu->header, section, |
| 4421 | abbrev_section, info_ptr, |
| 4422 | &signature, |
| 4423 | &type_offset_in_tu); |
| 4424 | |
| 4425 | /* Since per_cu is the first member of struct signatured_type, |
| 4426 | we can go from a pointer to one to a pointer to the other. */ |
| 4427 | sig_type = (struct signatured_type *) this_cu; |
| 4428 | gdb_assert (sig_type->signature == signature); |
| 4429 | gdb_assert (sig_type->type_offset_in_tu.cu_off |
| 4430 | == type_offset_in_tu.cu_off); |
| 4431 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); |
| 4432 | |
| 4433 | /* LENGTH has not been set yet for type units if we're |
| 4434 | using .gdb_index. */ |
| 4435 | this_cu->length = get_cu_length (&cu->header); |
| 4436 | |
| 4437 | /* Establish the type offset that can be used to lookup the type. */ |
| 4438 | sig_type->type_offset_in_section.sect_off = |
| 4439 | this_cu->offset.sect_off + sig_type->type_offset_in_tu.cu_off; |
| 4440 | } |
| 4441 | else |
| 4442 | { |
| 4443 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
| 4444 | abbrev_section, |
| 4445 | info_ptr, 0); |
| 4446 | |
| 4447 | gdb_assert (this_cu->offset.sect_off == cu->header.offset.sect_off); |
| 4448 | gdb_assert (this_cu->length == get_cu_length (&cu->header)); |
| 4449 | } |
| 4450 | } |
| 4451 | |
| 4452 | /* Skip dummy compilation units. */ |
| 4453 | if (info_ptr >= begin_info_ptr + this_cu->length |
| 4454 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 4455 | { |
| 4456 | do_cleanups (cleanups); |
| 4457 | return; |
| 4458 | } |
| 4459 | |
| 4460 | /* If we don't have them yet, read the abbrevs for this compilation unit. |
| 4461 | And if we need to read them now, make sure they're freed when we're |
| 4462 | done. Note that it's important that if the CU had an abbrev table |
| 4463 | on entry we don't free it when we're done: Somewhere up the call stack |
| 4464 | it may be in use. */ |
| 4465 | if (abbrev_table != NULL) |
| 4466 | { |
| 4467 | gdb_assert (cu->abbrev_table == NULL); |
| 4468 | gdb_assert (cu->header.abbrev_offset.sect_off |
| 4469 | == abbrev_table->offset.sect_off); |
| 4470 | cu->abbrev_table = abbrev_table; |
| 4471 | } |
| 4472 | else if (cu->abbrev_table == NULL) |
| 4473 | { |
| 4474 | dwarf2_read_abbrevs (cu, abbrev_section); |
| 4475 | make_cleanup (dwarf2_free_abbrev_table, cu); |
| 4476 | } |
| 4477 | else if (rereading_dwo_cu) |
| 4478 | { |
| 4479 | dwarf2_free_abbrev_table (cu); |
| 4480 | dwarf2_read_abbrevs (cu, abbrev_section); |
| 4481 | } |
| 4482 | |
| 4483 | /* Read the top level CU/TU die. */ |
| 4484 | init_cu_die_reader (&reader, cu, section, NULL); |
| 4485 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
| 4486 | |
| 4487 | /* If we have a DWO stub, process it and then read in the DWO file. |
| 4488 | Note that if USE_EXISTING_OK != 0, and THIS_CU->cu already contains |
| 4489 | a DWO CU, that this test will fail. */ |
| 4490 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_name, cu); |
| 4491 | if (attr) |
| 4492 | { |
| 4493 | char *dwo_name = DW_STRING (attr); |
| 4494 | const char *comp_dir_string; |
| 4495 | struct dwo_unit *dwo_unit; |
| 4496 | ULONGEST signature; /* Or dwo_id. */ |
| 4497 | struct attribute *comp_dir, *stmt_list, *low_pc, *high_pc, *ranges; |
| 4498 | int i,num_extra_attrs; |
| 4499 | struct dwarf2_section_info *dwo_abbrev_section; |
| 4500 | |
| 4501 | if (has_children) |
| 4502 | error (_("Dwarf Error: compilation unit with DW_AT_GNU_dwo_name" |
| 4503 | " has children (offset 0x%x) [in module %s]"), |
| 4504 | this_cu->offset.sect_off, bfd_get_filename (abfd)); |
| 4505 | |
| 4506 | /* These attributes aren't processed until later: |
| 4507 | DW_AT_stmt_list, DW_AT_low_pc, DW_AT_high_pc, DW_AT_ranges. |
| 4508 | However, the attribute is found in the stub which we won't have later. |
| 4509 | In order to not impose this complication on the rest of the code, |
| 4510 | we read them here and copy them to the DWO CU/TU die. */ |
| 4511 | |
| 4512 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the |
| 4513 | DWO file. */ |
| 4514 | stmt_list = NULL; |
| 4515 | if (! this_cu->is_debug_types) |
| 4516 | stmt_list = dwarf2_attr (comp_unit_die, DW_AT_stmt_list, cu); |
| 4517 | low_pc = dwarf2_attr (comp_unit_die, DW_AT_low_pc, cu); |
| 4518 | high_pc = dwarf2_attr (comp_unit_die, DW_AT_high_pc, cu); |
| 4519 | ranges = dwarf2_attr (comp_unit_die, DW_AT_ranges, cu); |
| 4520 | comp_dir = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
| 4521 | |
| 4522 | /* There should be a DW_AT_addr_base attribute here (if needed). |
| 4523 | We need the value before we can process DW_FORM_GNU_addr_index. */ |
| 4524 | cu->addr_base = 0; |
| 4525 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_addr_base, cu); |
| 4526 | if (attr) |
| 4527 | cu->addr_base = DW_UNSND (attr); |
| 4528 | |
| 4529 | /* There should be a DW_AT_ranges_base attribute here (if needed). |
| 4530 | We need the value before we can process DW_AT_ranges. */ |
| 4531 | cu->ranges_base = 0; |
| 4532 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_ranges_base, cu); |
| 4533 | if (attr) |
| 4534 | cu->ranges_base = DW_UNSND (attr); |
| 4535 | |
| 4536 | if (this_cu->is_debug_types) |
| 4537 | { |
| 4538 | gdb_assert (sig_type != NULL); |
| 4539 | signature = sig_type->signature; |
| 4540 | } |
| 4541 | else |
| 4542 | { |
| 4543 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); |
| 4544 | if (! attr) |
| 4545 | error (_("Dwarf Error: missing dwo_id [in module %s]"), |
| 4546 | dwo_name); |
| 4547 | signature = DW_UNSND (attr); |
| 4548 | } |
| 4549 | |
| 4550 | /* We may need the comp_dir in order to find the DWO file. */ |
| 4551 | comp_dir_string = NULL; |
| 4552 | if (comp_dir) |
| 4553 | comp_dir_string = DW_STRING (comp_dir); |
| 4554 | |
| 4555 | if (this_cu->is_debug_types) |
| 4556 | dwo_unit = lookup_dwo_type_unit (sig_type, dwo_name, comp_dir_string); |
| 4557 | else |
| 4558 | dwo_unit = lookup_dwo_comp_unit (this_cu, dwo_name, comp_dir_string, |
| 4559 | signature); |
| 4560 | |
| 4561 | if (dwo_unit == NULL) |
| 4562 | { |
| 4563 | error (_("Dwarf Error: CU at offset 0x%x references unknown DWO" |
| 4564 | " with ID %s [in module %s]"), |
| 4565 | this_cu->offset.sect_off, |
| 4566 | phex (signature, sizeof (signature)), |
| 4567 | objfile->name); |
| 4568 | } |
| 4569 | |
| 4570 | /* Set up for reading the DWO CU/TU. */ |
| 4571 | cu->dwo_unit = dwo_unit; |
| 4572 | section = dwo_unit->info_or_types_section; |
| 4573 | dwarf2_read_section (objfile, section); |
| 4574 | begin_info_ptr = info_ptr = section->buffer + dwo_unit->offset.sect_off; |
| 4575 | dwo_abbrev_section = &dwo_unit->dwo_file->sections.abbrev; |
| 4576 | init_cu_die_reader (&reader, cu, section, dwo_unit->dwo_file); |
| 4577 | |
| 4578 | if (this_cu->is_debug_types) |
| 4579 | { |
| 4580 | ULONGEST signature; |
| 4581 | cu_offset type_offset_in_tu; |
| 4582 | |
| 4583 | info_ptr = read_and_check_type_unit_head (&cu->header, section, |
| 4584 | dwo_abbrev_section, |
| 4585 | info_ptr, |
| 4586 | &signature, |
| 4587 | &type_offset_in_tu); |
| 4588 | gdb_assert (sig_type->signature == signature); |
| 4589 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); |
| 4590 | /* For DWOs coming from DWP files, we don't know the CU length |
| 4591 | nor the type's offset in the TU until now. */ |
| 4592 | dwo_unit->length = get_cu_length (&cu->header); |
| 4593 | dwo_unit->type_offset_in_tu = type_offset_in_tu; |
| 4594 | |
| 4595 | /* Establish the type offset that can be used to lookup the type. |
| 4596 | For DWO files, we don't know it until now. */ |
| 4597 | sig_type->type_offset_in_section.sect_off = |
| 4598 | dwo_unit->offset.sect_off + dwo_unit->type_offset_in_tu.cu_off; |
| 4599 | } |
| 4600 | else |
| 4601 | { |
| 4602 | info_ptr = read_and_check_comp_unit_head (&cu->header, section, |
| 4603 | dwo_abbrev_section, |
| 4604 | info_ptr, 0); |
| 4605 | gdb_assert (dwo_unit->offset.sect_off == cu->header.offset.sect_off); |
| 4606 | /* For DWOs coming from DWP files, we don't know the CU length |
| 4607 | until now. */ |
| 4608 | dwo_unit->length = get_cu_length (&cu->header); |
| 4609 | } |
| 4610 | |
| 4611 | /* Discard the original CU's abbrev table, and read the DWO's. */ |
| 4612 | if (abbrev_table == NULL) |
| 4613 | { |
| 4614 | dwarf2_free_abbrev_table (cu); |
| 4615 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); |
| 4616 | } |
| 4617 | else |
| 4618 | { |
| 4619 | dwarf2_read_abbrevs (cu, dwo_abbrev_section); |
| 4620 | make_cleanup (dwarf2_free_abbrev_table, cu); |
| 4621 | } |
| 4622 | |
| 4623 | /* Read in the die, but leave space to copy over the attributes |
| 4624 | from the stub. This has the benefit of simplifying the rest of |
| 4625 | the code - all the real work is done here. */ |
| 4626 | num_extra_attrs = ((stmt_list != NULL) |
| 4627 | + (low_pc != NULL) |
| 4628 | + (high_pc != NULL) |
| 4629 | + (ranges != NULL) |
| 4630 | + (comp_dir != NULL)); |
| 4631 | info_ptr = read_full_die_1 (&reader, &comp_unit_die, info_ptr, |
| 4632 | &has_children, num_extra_attrs); |
| 4633 | |
| 4634 | /* Copy over the attributes from the stub to the DWO die. */ |
| 4635 | i = comp_unit_die->num_attrs; |
| 4636 | if (stmt_list != NULL) |
| 4637 | comp_unit_die->attrs[i++] = *stmt_list; |
| 4638 | if (low_pc != NULL) |
| 4639 | comp_unit_die->attrs[i++] = *low_pc; |
| 4640 | if (high_pc != NULL) |
| 4641 | comp_unit_die->attrs[i++] = *high_pc; |
| 4642 | if (ranges != NULL) |
| 4643 | comp_unit_die->attrs[i++] = *ranges; |
| 4644 | if (comp_dir != NULL) |
| 4645 | comp_unit_die->attrs[i++] = *comp_dir; |
| 4646 | comp_unit_die->num_attrs += num_extra_attrs; |
| 4647 | |
| 4648 | /* Skip dummy compilation units. */ |
| 4649 | if (info_ptr >= begin_info_ptr + dwo_unit->length |
| 4650 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 4651 | { |
| 4652 | do_cleanups (cleanups); |
| 4653 | return; |
| 4654 | } |
| 4655 | } |
| 4656 | |
| 4657 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
| 4658 | |
| 4659 | if (free_cu_cleanup != NULL) |
| 4660 | { |
| 4661 | if (keep) |
| 4662 | { |
| 4663 | /* We've successfully allocated this compilation unit. Let our |
| 4664 | caller clean it up when finished with it. */ |
| 4665 | discard_cleanups (free_cu_cleanup); |
| 4666 | |
| 4667 | /* We can only discard free_cu_cleanup and all subsequent cleanups. |
| 4668 | So we have to manually free the abbrev table. */ |
| 4669 | dwarf2_free_abbrev_table (cu); |
| 4670 | |
| 4671 | /* Link this CU into read_in_chain. */ |
| 4672 | this_cu->cu->read_in_chain = dwarf2_per_objfile->read_in_chain; |
| 4673 | dwarf2_per_objfile->read_in_chain = this_cu; |
| 4674 | } |
| 4675 | else |
| 4676 | do_cleanups (free_cu_cleanup); |
| 4677 | } |
| 4678 | |
| 4679 | do_cleanups (cleanups); |
| 4680 | } |
| 4681 | |
| 4682 | /* Read CU/TU THIS_CU in section SECTION, |
| 4683 | but do not follow DW_AT_GNU_dwo_name if present. |
| 4684 | DWOP_FILE, if non-NULL, is the DWO/DWP file to read (the caller is assumed |
| 4685 | to have already done the lookup to find the DWO/DWP file). |
| 4686 | |
| 4687 | The caller is required to fill in THIS_CU->section, THIS_CU->offset, and |
| 4688 | THIS_CU->is_debug_types, but nothing else. |
| 4689 | |
| 4690 | We fill in THIS_CU->length. |
| 4691 | |
| 4692 | WARNING: If THIS_CU is a "dummy CU" (used as filler by the incremental |
| 4693 | linker) then DIE_READER_FUNC will not get called. |
| 4694 | |
| 4695 | THIS_CU->cu is always freed when done. |
| 4696 | This is done in order to not leave THIS_CU->cu in a state where we have |
| 4697 | to care whether it refers to the "main" CU or the DWO CU. */ |
| 4698 | |
| 4699 | static void |
| 4700 | init_cutu_and_read_dies_no_follow (struct dwarf2_per_cu_data *this_cu, |
| 4701 | struct dwarf2_section_info *abbrev_section, |
| 4702 | struct dwo_file *dwo_file, |
| 4703 | die_reader_func_ftype *die_reader_func, |
| 4704 | void *data) |
| 4705 | { |
| 4706 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 4707 | struct dwarf2_section_info *section = this_cu->info_or_types_section; |
| 4708 | bfd *abfd = section->asection->owner; |
| 4709 | struct dwarf2_cu cu; |
| 4710 | gdb_byte *begin_info_ptr, *info_ptr; |
| 4711 | struct die_reader_specs reader; |
| 4712 | struct cleanup *cleanups; |
| 4713 | struct die_info *comp_unit_die; |
| 4714 | int has_children; |
| 4715 | |
| 4716 | if (dwarf2_die_debug) |
| 4717 | fprintf_unfiltered (gdb_stdlog, "Reading %s unit at offset 0x%x\n", |
| 4718 | this_cu->is_debug_types ? "type" : "comp", |
| 4719 | this_cu->offset.sect_off); |
| 4720 | |
| 4721 | gdb_assert (this_cu->cu == NULL); |
| 4722 | |
| 4723 | /* This is cheap if the section is already read in. */ |
| 4724 | dwarf2_read_section (objfile, section); |
| 4725 | |
| 4726 | init_one_comp_unit (&cu, this_cu); |
| 4727 | |
| 4728 | cleanups = make_cleanup (free_stack_comp_unit, &cu); |
| 4729 | |
| 4730 | begin_info_ptr = info_ptr = section->buffer + this_cu->offset.sect_off; |
| 4731 | info_ptr = read_and_check_comp_unit_head (&cu.header, section, |
| 4732 | abbrev_section, info_ptr, |
| 4733 | this_cu->is_debug_types); |
| 4734 | |
| 4735 | this_cu->length = get_cu_length (&cu.header); |
| 4736 | |
| 4737 | /* Skip dummy compilation units. */ |
| 4738 | if (info_ptr >= begin_info_ptr + this_cu->length |
| 4739 | || peek_abbrev_code (abfd, info_ptr) == 0) |
| 4740 | { |
| 4741 | do_cleanups (cleanups); |
| 4742 | return; |
| 4743 | } |
| 4744 | |
| 4745 | dwarf2_read_abbrevs (&cu, abbrev_section); |
| 4746 | make_cleanup (dwarf2_free_abbrev_table, &cu); |
| 4747 | |
| 4748 | init_cu_die_reader (&reader, &cu, section, dwo_file); |
| 4749 | info_ptr = read_full_die (&reader, &comp_unit_die, info_ptr, &has_children); |
| 4750 | |
| 4751 | die_reader_func (&reader, info_ptr, comp_unit_die, has_children, data); |
| 4752 | |
| 4753 | do_cleanups (cleanups); |
| 4754 | } |
| 4755 | |
| 4756 | /* Read a CU/TU, except that this does not look for DW_AT_GNU_dwo_name and |
| 4757 | does not lookup the specified DWO file. |
| 4758 | This cannot be used to read DWO files. |
| 4759 | |
| 4760 | THIS_CU->cu is always freed when done. |
| 4761 | This is done in order to not leave THIS_CU->cu in a state where we have |
| 4762 | to care whether it refers to the "main" CU or the DWO CU. |
| 4763 | We can revisit this if the data shows there's a performance issue. */ |
| 4764 | |
| 4765 | static void |
| 4766 | init_cutu_and_read_dies_simple (struct dwarf2_per_cu_data *this_cu, |
| 4767 | die_reader_func_ftype *die_reader_func, |
| 4768 | void *data) |
| 4769 | { |
| 4770 | init_cutu_and_read_dies_no_follow (this_cu, |
| 4771 | get_abbrev_section_for_cu (this_cu), |
| 4772 | NULL, |
| 4773 | die_reader_func, data); |
| 4774 | } |
| 4775 | |
| 4776 | /* Create a psymtab named NAME and assign it to PER_CU. |
| 4777 | |
| 4778 | The caller must fill in the following details: |
| 4779 | dirname, textlow, texthigh. */ |
| 4780 | |
| 4781 | static struct partial_symtab * |
| 4782 | create_partial_symtab (struct dwarf2_per_cu_data *per_cu, const char *name) |
| 4783 | { |
| 4784 | struct objfile *objfile = per_cu->objfile; |
| 4785 | struct partial_symtab *pst; |
| 4786 | |
| 4787 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
| 4788 | name, 0, |
| 4789 | objfile->global_psymbols.next, |
| 4790 | objfile->static_psymbols.next); |
| 4791 | |
| 4792 | pst->psymtabs_addrmap_supported = 1; |
| 4793 | |
| 4794 | /* This is the glue that links PST into GDB's symbol API. */ |
| 4795 | pst->read_symtab_private = per_cu; |
| 4796 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
| 4797 | per_cu->v.psymtab = pst; |
| 4798 | |
| 4799 | return pst; |
| 4800 | } |
| 4801 | |
| 4802 | /* die_reader_func for process_psymtab_comp_unit. */ |
| 4803 | |
| 4804 | static void |
| 4805 | process_psymtab_comp_unit_reader (const struct die_reader_specs *reader, |
| 4806 | gdb_byte *info_ptr, |
| 4807 | struct die_info *comp_unit_die, |
| 4808 | int has_children, |
| 4809 | void *data) |
| 4810 | { |
| 4811 | struct dwarf2_cu *cu = reader->cu; |
| 4812 | struct objfile *objfile = cu->objfile; |
| 4813 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; |
| 4814 | struct attribute *attr; |
| 4815 | CORE_ADDR baseaddr; |
| 4816 | CORE_ADDR best_lowpc = 0, best_highpc = 0; |
| 4817 | struct partial_symtab *pst; |
| 4818 | int has_pc_info; |
| 4819 | const char *filename; |
| 4820 | int *want_partial_unit_ptr = data; |
| 4821 | |
| 4822 | if (comp_unit_die->tag == DW_TAG_partial_unit |
| 4823 | && (want_partial_unit_ptr == NULL |
| 4824 | || !*want_partial_unit_ptr)) |
| 4825 | return; |
| 4826 | |
| 4827 | gdb_assert (! per_cu->is_debug_types); |
| 4828 | |
| 4829 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
| 4830 | |
| 4831 | cu->list_in_scope = &file_symbols; |
| 4832 | |
| 4833 | /* Allocate a new partial symbol table structure. */ |
| 4834 | attr = dwarf2_attr (comp_unit_die, DW_AT_name, cu); |
| 4835 | if (attr == NULL || !DW_STRING (attr)) |
| 4836 | filename = ""; |
| 4837 | else |
| 4838 | filename = DW_STRING (attr); |
| 4839 | |
| 4840 | pst = create_partial_symtab (per_cu, filename); |
| 4841 | |
| 4842 | /* This must be done before calling dwarf2_build_include_psymtabs. */ |
| 4843 | attr = dwarf2_attr (comp_unit_die, DW_AT_comp_dir, cu); |
| 4844 | if (attr != NULL) |
| 4845 | pst->dirname = DW_STRING (attr); |
| 4846 | |
| 4847 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 4848 | |
| 4849 | dwarf2_find_base_address (comp_unit_die, cu); |
| 4850 | |
| 4851 | /* Possibly set the default values of LOWPC and HIGHPC from |
| 4852 | `DW_AT_ranges'. */ |
| 4853 | has_pc_info = dwarf2_get_pc_bounds (comp_unit_die, &best_lowpc, |
| 4854 | &best_highpc, cu, pst); |
| 4855 | if (has_pc_info == 1 && best_lowpc < best_highpc) |
| 4856 | /* Store the contiguous range if it is not empty; it can be empty for |
| 4857 | CUs with no code. */ |
| 4858 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 4859 | best_lowpc + baseaddr, |
| 4860 | best_highpc + baseaddr - 1, pst); |
| 4861 | |
| 4862 | /* Check if comp unit has_children. |
| 4863 | If so, read the rest of the partial symbols from this comp unit. |
| 4864 | If not, there's no more debug_info for this comp unit. */ |
| 4865 | if (has_children) |
| 4866 | { |
| 4867 | struct partial_die_info *first_die; |
| 4868 | CORE_ADDR lowpc, highpc; |
| 4869 | |
| 4870 | lowpc = ((CORE_ADDR) -1); |
| 4871 | highpc = ((CORE_ADDR) 0); |
| 4872 | |
| 4873 | first_die = load_partial_dies (reader, info_ptr, 1); |
| 4874 | |
| 4875 | scan_partial_symbols (first_die, &lowpc, &highpc, |
| 4876 | ! has_pc_info, cu); |
| 4877 | |
| 4878 | /* If we didn't find a lowpc, set it to highpc to avoid |
| 4879 | complaints from `maint check'. */ |
| 4880 | if (lowpc == ((CORE_ADDR) -1)) |
| 4881 | lowpc = highpc; |
| 4882 | |
| 4883 | /* If the compilation unit didn't have an explicit address range, |
| 4884 | then use the information extracted from its child dies. */ |
| 4885 | if (! has_pc_info) |
| 4886 | { |
| 4887 | best_lowpc = lowpc; |
| 4888 | best_highpc = highpc; |
| 4889 | } |
| 4890 | } |
| 4891 | pst->textlow = best_lowpc + baseaddr; |
| 4892 | pst->texthigh = best_highpc + baseaddr; |
| 4893 | |
| 4894 | pst->n_global_syms = objfile->global_psymbols.next - |
| 4895 | (objfile->global_psymbols.list + pst->globals_offset); |
| 4896 | pst->n_static_syms = objfile->static_psymbols.next - |
| 4897 | (objfile->static_psymbols.list + pst->statics_offset); |
| 4898 | sort_pst_symbols (objfile, pst); |
| 4899 | |
| 4900 | if (!VEC_empty (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs)) |
| 4901 | { |
| 4902 | int i; |
| 4903 | int len = VEC_length (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs); |
| 4904 | struct dwarf2_per_cu_data *iter; |
| 4905 | |
| 4906 | /* Fill in 'dependencies' here; we fill in 'users' in a |
| 4907 | post-pass. */ |
| 4908 | pst->number_of_dependencies = len; |
| 4909 | pst->dependencies = obstack_alloc (&objfile->objfile_obstack, |
| 4910 | len * sizeof (struct symtab *)); |
| 4911 | for (i = 0; |
| 4912 | VEC_iterate (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs, |
| 4913 | i, iter); |
| 4914 | ++i) |
| 4915 | pst->dependencies[i] = iter->v.psymtab; |
| 4916 | |
| 4917 | VEC_free (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs); |
| 4918 | } |
| 4919 | |
| 4920 | /* Get the list of files included in the current compilation unit, |
| 4921 | and build a psymtab for each of them. */ |
| 4922 | dwarf2_build_include_psymtabs (cu, comp_unit_die, pst); |
| 4923 | |
| 4924 | if (dwarf2_read_debug) |
| 4925 | { |
| 4926 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 4927 | |
| 4928 | fprintf_unfiltered (gdb_stdlog, |
| 4929 | "Psymtab for %s unit @0x%x: %s - %s" |
| 4930 | ", %d global, %d static syms\n", |
| 4931 | per_cu->is_debug_types ? "type" : "comp", |
| 4932 | per_cu->offset.sect_off, |
| 4933 | paddress (gdbarch, pst->textlow), |
| 4934 | paddress (gdbarch, pst->texthigh), |
| 4935 | pst->n_global_syms, pst->n_static_syms); |
| 4936 | } |
| 4937 | } |
| 4938 | |
| 4939 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
| 4940 | Process compilation unit THIS_CU for a psymtab. */ |
| 4941 | |
| 4942 | static void |
| 4943 | process_psymtab_comp_unit (struct dwarf2_per_cu_data *this_cu, |
| 4944 | int want_partial_unit) |
| 4945 | { |
| 4946 | /* If this compilation unit was already read in, free the |
| 4947 | cached copy in order to read it in again. This is |
| 4948 | necessary because we skipped some symbols when we first |
| 4949 | read in the compilation unit (see load_partial_dies). |
| 4950 | This problem could be avoided, but the benefit is unclear. */ |
| 4951 | if (this_cu->cu != NULL) |
| 4952 | free_one_cached_comp_unit (this_cu); |
| 4953 | |
| 4954 | gdb_assert (! this_cu->is_debug_types); |
| 4955 | init_cutu_and_read_dies (this_cu, NULL, 0, 0, |
| 4956 | process_psymtab_comp_unit_reader, |
| 4957 | &want_partial_unit); |
| 4958 | |
| 4959 | /* Age out any secondary CUs. */ |
| 4960 | age_cached_comp_units (); |
| 4961 | } |
| 4962 | |
| 4963 | static hashval_t |
| 4964 | hash_type_unit_group (const void *item) |
| 4965 | { |
| 4966 | const struct type_unit_group *tu_group = item; |
| 4967 | |
| 4968 | return hash_stmt_list_entry (&tu_group->hash); |
| 4969 | } |
| 4970 | |
| 4971 | static int |
| 4972 | eq_type_unit_group (const void *item_lhs, const void *item_rhs) |
| 4973 | { |
| 4974 | const struct type_unit_group *lhs = item_lhs; |
| 4975 | const struct type_unit_group *rhs = item_rhs; |
| 4976 | |
| 4977 | return eq_stmt_list_entry (&lhs->hash, &rhs->hash); |
| 4978 | } |
| 4979 | |
| 4980 | /* Allocate a hash table for type unit groups. */ |
| 4981 | |
| 4982 | static htab_t |
| 4983 | allocate_type_unit_groups_table (void) |
| 4984 | { |
| 4985 | return htab_create_alloc_ex (3, |
| 4986 | hash_type_unit_group, |
| 4987 | eq_type_unit_group, |
| 4988 | NULL, |
| 4989 | &dwarf2_per_objfile->objfile->objfile_obstack, |
| 4990 | hashtab_obstack_allocate, |
| 4991 | dummy_obstack_deallocate); |
| 4992 | } |
| 4993 | |
| 4994 | /* Type units that don't have DW_AT_stmt_list are grouped into their own |
| 4995 | partial symtabs. We combine several TUs per psymtab to not let the size |
| 4996 | of any one psymtab grow too big. */ |
| 4997 | #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB (1 << 31) |
| 4998 | #define NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE 10 |
| 4999 | |
| 5000 | /* Helper routine for get_type_unit_group. |
| 5001 | Create the type_unit_group object used to hold one or more TUs. */ |
| 5002 | |
| 5003 | static struct type_unit_group * |
| 5004 | create_type_unit_group (struct dwarf2_cu *cu, sect_offset line_offset_struct) |
| 5005 | { |
| 5006 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 5007 | struct dwarf2_per_cu_data *per_cu; |
| 5008 | struct type_unit_group *tu_group; |
| 5009 | |
| 5010 | tu_group = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 5011 | struct type_unit_group); |
| 5012 | per_cu = &tu_group->per_cu; |
| 5013 | per_cu->objfile = objfile; |
| 5014 | per_cu->is_debug_types = 1; |
| 5015 | per_cu->s.type_unit_group = tu_group; |
| 5016 | |
| 5017 | if (dwarf2_per_objfile->using_index) |
| 5018 | { |
| 5019 | per_cu->v.quick = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 5020 | struct dwarf2_per_cu_quick_data); |
| 5021 | tu_group->t.first_tu = cu->per_cu; |
| 5022 | } |
| 5023 | else |
| 5024 | { |
| 5025 | unsigned int line_offset = line_offset_struct.sect_off; |
| 5026 | struct partial_symtab *pst; |
| 5027 | char *name; |
| 5028 | |
| 5029 | /* Give the symtab a useful name for debug purposes. */ |
| 5030 | if ((line_offset & NO_STMT_LIST_TYPE_UNIT_PSYMTAB) != 0) |
| 5031 | name = xstrprintf ("<type_units_%d>", |
| 5032 | (line_offset & ~NO_STMT_LIST_TYPE_UNIT_PSYMTAB)); |
| 5033 | else |
| 5034 | name = xstrprintf ("<type_units_at_0x%x>", line_offset); |
| 5035 | |
| 5036 | pst = create_partial_symtab (per_cu, name); |
| 5037 | pst->anonymous = 1; |
| 5038 | |
| 5039 | xfree (name); |
| 5040 | } |
| 5041 | |
| 5042 | tu_group->hash.dwo_unit = cu->dwo_unit; |
| 5043 | tu_group->hash.line_offset = line_offset_struct; |
| 5044 | |
| 5045 | return tu_group; |
| 5046 | } |
| 5047 | |
| 5048 | /* Look up the type_unit_group for type unit CU, and create it if necessary. |
| 5049 | STMT_LIST is a DW_AT_stmt_list attribute. */ |
| 5050 | |
| 5051 | static struct type_unit_group * |
| 5052 | get_type_unit_group (struct dwarf2_cu *cu, struct attribute *stmt_list) |
| 5053 | { |
| 5054 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; |
| 5055 | struct type_unit_group *tu_group; |
| 5056 | void **slot; |
| 5057 | unsigned int line_offset; |
| 5058 | struct type_unit_group type_unit_group_for_lookup; |
| 5059 | |
| 5060 | if (dwarf2_per_objfile->type_unit_groups == NULL) |
| 5061 | { |
| 5062 | dwarf2_per_objfile->type_unit_groups = |
| 5063 | allocate_type_unit_groups_table (); |
| 5064 | } |
| 5065 | |
| 5066 | /* Do we need to create a new group, or can we use an existing one? */ |
| 5067 | |
| 5068 | if (stmt_list) |
| 5069 | { |
| 5070 | line_offset = DW_UNSND (stmt_list); |
| 5071 | ++tu_stats->nr_symtab_sharers; |
| 5072 | } |
| 5073 | else |
| 5074 | { |
| 5075 | /* Ugh, no stmt_list. Rare, but we have to handle it. |
| 5076 | We can do various things here like create one group per TU or |
| 5077 | spread them over multiple groups to split up the expansion work. |
| 5078 | To avoid worst case scenarios (too many groups or too large groups) |
| 5079 | we, umm, group them in bunches. */ |
| 5080 | line_offset = (NO_STMT_LIST_TYPE_UNIT_PSYMTAB |
| 5081 | | (tu_stats->nr_stmt_less_type_units |
| 5082 | / NO_STMT_LIST_TYPE_UNIT_PSYMTAB_SIZE)); |
| 5083 | ++tu_stats->nr_stmt_less_type_units; |
| 5084 | } |
| 5085 | |
| 5086 | type_unit_group_for_lookup.hash.dwo_unit = cu->dwo_unit; |
| 5087 | type_unit_group_for_lookup.hash.line_offset.sect_off = line_offset; |
| 5088 | slot = htab_find_slot (dwarf2_per_objfile->type_unit_groups, |
| 5089 | &type_unit_group_for_lookup, INSERT); |
| 5090 | if (*slot != NULL) |
| 5091 | { |
| 5092 | tu_group = *slot; |
| 5093 | gdb_assert (tu_group != NULL); |
| 5094 | } |
| 5095 | else |
| 5096 | { |
| 5097 | sect_offset line_offset_struct; |
| 5098 | |
| 5099 | line_offset_struct.sect_off = line_offset; |
| 5100 | tu_group = create_type_unit_group (cu, line_offset_struct); |
| 5101 | *slot = tu_group; |
| 5102 | ++tu_stats->nr_symtabs; |
| 5103 | } |
| 5104 | |
| 5105 | return tu_group; |
| 5106 | } |
| 5107 | |
| 5108 | /* Struct used to sort TUs by their abbreviation table offset. */ |
| 5109 | |
| 5110 | struct tu_abbrev_offset |
| 5111 | { |
| 5112 | struct signatured_type *sig_type; |
| 5113 | sect_offset abbrev_offset; |
| 5114 | }; |
| 5115 | |
| 5116 | /* Helper routine for build_type_unit_groups, passed to qsort. */ |
| 5117 | |
| 5118 | static int |
| 5119 | sort_tu_by_abbrev_offset (const void *ap, const void *bp) |
| 5120 | { |
| 5121 | const struct tu_abbrev_offset * const *a = ap; |
| 5122 | const struct tu_abbrev_offset * const *b = bp; |
| 5123 | unsigned int aoff = (*a)->abbrev_offset.sect_off; |
| 5124 | unsigned int boff = (*b)->abbrev_offset.sect_off; |
| 5125 | |
| 5126 | return (aoff > boff) - (aoff < boff); |
| 5127 | } |
| 5128 | |
| 5129 | /* A helper function to add a type_unit_group to a table. */ |
| 5130 | |
| 5131 | static int |
| 5132 | add_type_unit_group_to_table (void **slot, void *datum) |
| 5133 | { |
| 5134 | struct type_unit_group *tu_group = *slot; |
| 5135 | struct type_unit_group ***datap = datum; |
| 5136 | |
| 5137 | **datap = tu_group; |
| 5138 | ++*datap; |
| 5139 | |
| 5140 | return 1; |
| 5141 | } |
| 5142 | |
| 5143 | /* Efficiently read all the type units, calling init_cutu_and_read_dies on |
| 5144 | each one passing FUNC,DATA. |
| 5145 | |
| 5146 | The efficiency is because we sort TUs by the abbrev table they use and |
| 5147 | only read each abbrev table once. In one program there are 200K TUs |
| 5148 | sharing 8K abbrev tables. |
| 5149 | |
| 5150 | The main purpose of this function is to support building the |
| 5151 | dwarf2_per_objfile->type_unit_groups table. |
| 5152 | TUs typically share the DW_AT_stmt_list of the CU they came from, so we |
| 5153 | can collapse the search space by grouping them by stmt_list. |
| 5154 | The savings can be significant, in the same program from above the 200K TUs |
| 5155 | share 8K stmt_list tables. |
| 5156 | |
| 5157 | FUNC is expected to call get_type_unit_group, which will create the |
| 5158 | struct type_unit_group if necessary and add it to |
| 5159 | dwarf2_per_objfile->type_unit_groups. */ |
| 5160 | |
| 5161 | static void |
| 5162 | build_type_unit_groups (die_reader_func_ftype *func, void *data) |
| 5163 | { |
| 5164 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 5165 | struct tu_stats *tu_stats = &dwarf2_per_objfile->tu_stats; |
| 5166 | struct cleanup *cleanups; |
| 5167 | struct abbrev_table *abbrev_table; |
| 5168 | sect_offset abbrev_offset; |
| 5169 | struct tu_abbrev_offset *sorted_by_abbrev; |
| 5170 | struct type_unit_group **iter; |
| 5171 | int i; |
| 5172 | |
| 5173 | /* It's up to the caller to not call us multiple times. */ |
| 5174 | gdb_assert (dwarf2_per_objfile->type_unit_groups == NULL); |
| 5175 | |
| 5176 | if (dwarf2_per_objfile->n_type_units == 0) |
| 5177 | return; |
| 5178 | |
| 5179 | /* TUs typically share abbrev tables, and there can be way more TUs than |
| 5180 | abbrev tables. Sort by abbrev table to reduce the number of times we |
| 5181 | read each abbrev table in. |
| 5182 | Alternatives are to punt or to maintain a cache of abbrev tables. |
| 5183 | This is simpler and efficient enough for now. |
| 5184 | |
| 5185 | Later we group TUs by their DW_AT_stmt_list value (as this defines the |
| 5186 | symtab to use). Typically TUs with the same abbrev offset have the same |
| 5187 | stmt_list value too so in practice this should work well. |
| 5188 | |
| 5189 | The basic algorithm here is: |
| 5190 | |
| 5191 | sort TUs by abbrev table |
| 5192 | for each TU with same abbrev table: |
| 5193 | read abbrev table if first user |
| 5194 | read TU top level DIE |
| 5195 | [IWBN if DWO skeletons had DW_AT_stmt_list] |
| 5196 | call FUNC */ |
| 5197 | |
| 5198 | if (dwarf2_read_debug) |
| 5199 | fprintf_unfiltered (gdb_stdlog, "Building type unit groups ...\n"); |
| 5200 | |
| 5201 | /* Sort in a separate table to maintain the order of all_type_units |
| 5202 | for .gdb_index: TU indices directly index all_type_units. */ |
| 5203 | sorted_by_abbrev = XNEWVEC (struct tu_abbrev_offset, |
| 5204 | dwarf2_per_objfile->n_type_units); |
| 5205 | for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i) |
| 5206 | { |
| 5207 | struct signatured_type *sig_type = dwarf2_per_objfile->all_type_units[i]; |
| 5208 | |
| 5209 | sorted_by_abbrev[i].sig_type = sig_type; |
| 5210 | sorted_by_abbrev[i].abbrev_offset = |
| 5211 | read_abbrev_offset (sig_type->per_cu.info_or_types_section, |
| 5212 | sig_type->per_cu.offset); |
| 5213 | } |
| 5214 | cleanups = make_cleanup (xfree, sorted_by_abbrev); |
| 5215 | qsort (sorted_by_abbrev, dwarf2_per_objfile->n_type_units, |
| 5216 | sizeof (struct tu_abbrev_offset), sort_tu_by_abbrev_offset); |
| 5217 | |
| 5218 | /* Note: In the .gdb_index case, get_type_unit_group may have already been |
| 5219 | called any number of times, so we don't reset tu_stats here. */ |
| 5220 | |
| 5221 | abbrev_offset.sect_off = ~(unsigned) 0; |
| 5222 | abbrev_table = NULL; |
| 5223 | make_cleanup (abbrev_table_free_cleanup, &abbrev_table); |
| 5224 | |
| 5225 | for (i = 0; i < dwarf2_per_objfile->n_type_units; ++i) |
| 5226 | { |
| 5227 | const struct tu_abbrev_offset *tu = &sorted_by_abbrev[i]; |
| 5228 | |
| 5229 | /* Switch to the next abbrev table if necessary. */ |
| 5230 | if (abbrev_table == NULL |
| 5231 | || tu->abbrev_offset.sect_off != abbrev_offset.sect_off) |
| 5232 | { |
| 5233 | if (abbrev_table != NULL) |
| 5234 | { |
| 5235 | abbrev_table_free (abbrev_table); |
| 5236 | /* Reset to NULL in case abbrev_table_read_table throws |
| 5237 | an error: abbrev_table_free_cleanup will get called. */ |
| 5238 | abbrev_table = NULL; |
| 5239 | } |
| 5240 | abbrev_offset = tu->abbrev_offset; |
| 5241 | abbrev_table = |
| 5242 | abbrev_table_read_table (&dwarf2_per_objfile->abbrev, |
| 5243 | abbrev_offset); |
| 5244 | ++tu_stats->nr_uniq_abbrev_tables; |
| 5245 | } |
| 5246 | |
| 5247 | init_cutu_and_read_dies (&tu->sig_type->per_cu, abbrev_table, 0, 0, |
| 5248 | func, data); |
| 5249 | } |
| 5250 | |
| 5251 | /* Create a vector of pointers to primary type units to make it easy to |
| 5252 | iterate over them and CUs. See dw2_get_primary_cu. */ |
| 5253 | dwarf2_per_objfile->n_type_unit_groups = |
| 5254 | htab_elements (dwarf2_per_objfile->type_unit_groups); |
| 5255 | dwarf2_per_objfile->all_type_unit_groups = |
| 5256 | obstack_alloc (&objfile->objfile_obstack, |
| 5257 | dwarf2_per_objfile->n_type_unit_groups |
| 5258 | * sizeof (struct type_unit_group *)); |
| 5259 | iter = &dwarf2_per_objfile->all_type_unit_groups[0]; |
| 5260 | htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups, |
| 5261 | add_type_unit_group_to_table, &iter); |
| 5262 | gdb_assert (iter - &dwarf2_per_objfile->all_type_unit_groups[0] |
| 5263 | == dwarf2_per_objfile->n_type_unit_groups); |
| 5264 | |
| 5265 | do_cleanups (cleanups); |
| 5266 | |
| 5267 | if (dwarf2_read_debug) |
| 5268 | { |
| 5269 | fprintf_unfiltered (gdb_stdlog, "Done building type unit groups:\n"); |
| 5270 | fprintf_unfiltered (gdb_stdlog, " %d TUs\n", |
| 5271 | dwarf2_per_objfile->n_type_units); |
| 5272 | fprintf_unfiltered (gdb_stdlog, " %d uniq abbrev tables\n", |
| 5273 | tu_stats->nr_uniq_abbrev_tables); |
| 5274 | fprintf_unfiltered (gdb_stdlog, " %d symtabs from stmt_list entries\n", |
| 5275 | tu_stats->nr_symtabs); |
| 5276 | fprintf_unfiltered (gdb_stdlog, " %d symtab sharers\n", |
| 5277 | tu_stats->nr_symtab_sharers); |
| 5278 | fprintf_unfiltered (gdb_stdlog, " %d type units without a stmt_list\n", |
| 5279 | tu_stats->nr_stmt_less_type_units); |
| 5280 | } |
| 5281 | } |
| 5282 | |
| 5283 | /* Reader function for build_type_psymtabs. */ |
| 5284 | |
| 5285 | static void |
| 5286 | build_type_psymtabs_reader (const struct die_reader_specs *reader, |
| 5287 | gdb_byte *info_ptr, |
| 5288 | struct die_info *type_unit_die, |
| 5289 | int has_children, |
| 5290 | void *data) |
| 5291 | { |
| 5292 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 5293 | struct dwarf2_cu *cu = reader->cu; |
| 5294 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; |
| 5295 | struct type_unit_group *tu_group; |
| 5296 | struct attribute *attr; |
| 5297 | struct partial_die_info *first_die; |
| 5298 | CORE_ADDR lowpc, highpc; |
| 5299 | struct partial_symtab *pst; |
| 5300 | |
| 5301 | gdb_assert (data == NULL); |
| 5302 | |
| 5303 | if (! has_children) |
| 5304 | return; |
| 5305 | |
| 5306 | attr = dwarf2_attr_no_follow (type_unit_die, DW_AT_stmt_list); |
| 5307 | tu_group = get_type_unit_group (cu, attr); |
| 5308 | |
| 5309 | VEC_safe_push (dwarf2_per_cu_ptr, tu_group->t.tus, per_cu); |
| 5310 | |
| 5311 | prepare_one_comp_unit (cu, type_unit_die, language_minimal); |
| 5312 | cu->list_in_scope = &file_symbols; |
| 5313 | pst = create_partial_symtab (per_cu, ""); |
| 5314 | pst->anonymous = 1; |
| 5315 | |
| 5316 | first_die = load_partial_dies (reader, info_ptr, 1); |
| 5317 | |
| 5318 | lowpc = (CORE_ADDR) -1; |
| 5319 | highpc = (CORE_ADDR) 0; |
| 5320 | scan_partial_symbols (first_die, &lowpc, &highpc, 0, cu); |
| 5321 | |
| 5322 | pst->n_global_syms = objfile->global_psymbols.next - |
| 5323 | (objfile->global_psymbols.list + pst->globals_offset); |
| 5324 | pst->n_static_syms = objfile->static_psymbols.next - |
| 5325 | (objfile->static_psymbols.list + pst->statics_offset); |
| 5326 | sort_pst_symbols (objfile, pst); |
| 5327 | } |
| 5328 | |
| 5329 | /* Traversal function for build_type_psymtabs. */ |
| 5330 | |
| 5331 | static int |
| 5332 | build_type_psymtab_dependencies (void **slot, void *info) |
| 5333 | { |
| 5334 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 5335 | struct type_unit_group *tu_group = (struct type_unit_group *) *slot; |
| 5336 | struct dwarf2_per_cu_data *per_cu = &tu_group->per_cu; |
| 5337 | struct partial_symtab *pst = per_cu->v.psymtab; |
| 5338 | int len = VEC_length (dwarf2_per_cu_ptr, tu_group->t.tus); |
| 5339 | struct dwarf2_per_cu_data *iter; |
| 5340 | int i; |
| 5341 | |
| 5342 | gdb_assert (len > 0); |
| 5343 | |
| 5344 | pst->number_of_dependencies = len; |
| 5345 | pst->dependencies = obstack_alloc (&objfile->objfile_obstack, |
| 5346 | len * sizeof (struct psymtab *)); |
| 5347 | for (i = 0; |
| 5348 | VEC_iterate (dwarf2_per_cu_ptr, tu_group->t.tus, i, iter); |
| 5349 | ++i) |
| 5350 | { |
| 5351 | pst->dependencies[i] = iter->v.psymtab; |
| 5352 | iter->s.type_unit_group = tu_group; |
| 5353 | } |
| 5354 | |
| 5355 | VEC_free (dwarf2_per_cu_ptr, tu_group->t.tus); |
| 5356 | |
| 5357 | return 1; |
| 5358 | } |
| 5359 | |
| 5360 | /* Subroutine of dwarf2_build_psymtabs_hard to simplify it. |
| 5361 | Build partial symbol tables for the .debug_types comp-units. */ |
| 5362 | |
| 5363 | static void |
| 5364 | build_type_psymtabs (struct objfile *objfile) |
| 5365 | { |
| 5366 | if (! create_all_type_units (objfile)) |
| 5367 | return; |
| 5368 | |
| 5369 | build_type_unit_groups (build_type_psymtabs_reader, NULL); |
| 5370 | |
| 5371 | /* Now that all TUs have been processed we can fill in the dependencies. */ |
| 5372 | htab_traverse_noresize (dwarf2_per_objfile->type_unit_groups, |
| 5373 | build_type_psymtab_dependencies, NULL); |
| 5374 | } |
| 5375 | |
| 5376 | /* A cleanup function that clears objfile's psymtabs_addrmap field. */ |
| 5377 | |
| 5378 | static void |
| 5379 | psymtabs_addrmap_cleanup (void *o) |
| 5380 | { |
| 5381 | struct objfile *objfile = o; |
| 5382 | |
| 5383 | objfile->psymtabs_addrmap = NULL; |
| 5384 | } |
| 5385 | |
| 5386 | /* Compute the 'user' field for each psymtab in OBJFILE. */ |
| 5387 | |
| 5388 | static void |
| 5389 | set_partial_user (struct objfile *objfile) |
| 5390 | { |
| 5391 | int i; |
| 5392 | |
| 5393 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 5394 | { |
| 5395 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 5396 | struct partial_symtab *pst = per_cu->v.psymtab; |
| 5397 | int j; |
| 5398 | |
| 5399 | if (pst == NULL) |
| 5400 | continue; |
| 5401 | |
| 5402 | for (j = 0; j < pst->number_of_dependencies; ++j) |
| 5403 | { |
| 5404 | /* Set the 'user' field only if it is not already set. */ |
| 5405 | if (pst->dependencies[j]->user == NULL) |
| 5406 | pst->dependencies[j]->user = pst; |
| 5407 | } |
| 5408 | } |
| 5409 | } |
| 5410 | |
| 5411 | /* Build the partial symbol table by doing a quick pass through the |
| 5412 | .debug_info and .debug_abbrev sections. */ |
| 5413 | |
| 5414 | static void |
| 5415 | dwarf2_build_psymtabs_hard (struct objfile *objfile) |
| 5416 | { |
| 5417 | struct cleanup *back_to, *addrmap_cleanup; |
| 5418 | struct obstack temp_obstack; |
| 5419 | int i; |
| 5420 | |
| 5421 | if (dwarf2_read_debug) |
| 5422 | { |
| 5423 | fprintf_unfiltered (gdb_stdlog, "Building psymtabs of objfile %s ...\n", |
| 5424 | objfile->name); |
| 5425 | } |
| 5426 | |
| 5427 | dwarf2_per_objfile->reading_partial_symbols = 1; |
| 5428 | |
| 5429 | dwarf2_read_section (objfile, &dwarf2_per_objfile->info); |
| 5430 | |
| 5431 | /* Any cached compilation units will be linked by the per-objfile |
| 5432 | read_in_chain. Make sure to free them when we're done. */ |
| 5433 | back_to = make_cleanup (free_cached_comp_units, NULL); |
| 5434 | |
| 5435 | build_type_psymtabs (objfile); |
| 5436 | |
| 5437 | create_all_comp_units (objfile); |
| 5438 | |
| 5439 | /* Create a temporary address map on a temporary obstack. We later |
| 5440 | copy this to the final obstack. */ |
| 5441 | obstack_init (&temp_obstack); |
| 5442 | make_cleanup_obstack_free (&temp_obstack); |
| 5443 | objfile->psymtabs_addrmap = addrmap_create_mutable (&temp_obstack); |
| 5444 | addrmap_cleanup = make_cleanup (psymtabs_addrmap_cleanup, objfile); |
| 5445 | |
| 5446 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 5447 | { |
| 5448 | struct dwarf2_per_cu_data *per_cu = dw2_get_cu (i); |
| 5449 | |
| 5450 | process_psymtab_comp_unit (per_cu, 0); |
| 5451 | } |
| 5452 | |
| 5453 | set_partial_user (objfile); |
| 5454 | |
| 5455 | objfile->psymtabs_addrmap = addrmap_create_fixed (objfile->psymtabs_addrmap, |
| 5456 | &objfile->objfile_obstack); |
| 5457 | discard_cleanups (addrmap_cleanup); |
| 5458 | |
| 5459 | do_cleanups (back_to); |
| 5460 | |
| 5461 | if (dwarf2_read_debug) |
| 5462 | fprintf_unfiltered (gdb_stdlog, "Done building psymtabs of %s\n", |
| 5463 | objfile->name); |
| 5464 | } |
| 5465 | |
| 5466 | /* die_reader_func for load_partial_comp_unit. */ |
| 5467 | |
| 5468 | static void |
| 5469 | load_partial_comp_unit_reader (const struct die_reader_specs *reader, |
| 5470 | gdb_byte *info_ptr, |
| 5471 | struct die_info *comp_unit_die, |
| 5472 | int has_children, |
| 5473 | void *data) |
| 5474 | { |
| 5475 | struct dwarf2_cu *cu = reader->cu; |
| 5476 | |
| 5477 | prepare_one_comp_unit (cu, comp_unit_die, language_minimal); |
| 5478 | |
| 5479 | /* Check if comp unit has_children. |
| 5480 | If so, read the rest of the partial symbols from this comp unit. |
| 5481 | If not, there's no more debug_info for this comp unit. */ |
| 5482 | if (has_children) |
| 5483 | load_partial_dies (reader, info_ptr, 0); |
| 5484 | } |
| 5485 | |
| 5486 | /* Load the partial DIEs for a secondary CU into memory. |
| 5487 | This is also used when rereading a primary CU with load_all_dies. */ |
| 5488 | |
| 5489 | static void |
| 5490 | load_partial_comp_unit (struct dwarf2_per_cu_data *this_cu) |
| 5491 | { |
| 5492 | init_cutu_and_read_dies (this_cu, NULL, 1, 1, |
| 5493 | load_partial_comp_unit_reader, NULL); |
| 5494 | } |
| 5495 | |
| 5496 | static void |
| 5497 | read_comp_units_from_section (struct objfile *objfile, |
| 5498 | struct dwarf2_section_info *section, |
| 5499 | unsigned int is_dwz, |
| 5500 | int *n_allocated, |
| 5501 | int *n_comp_units, |
| 5502 | struct dwarf2_per_cu_data ***all_comp_units) |
| 5503 | { |
| 5504 | gdb_byte *info_ptr; |
| 5505 | bfd *abfd = section->asection->owner; |
| 5506 | |
| 5507 | dwarf2_read_section (objfile, section); |
| 5508 | |
| 5509 | info_ptr = section->buffer; |
| 5510 | |
| 5511 | while (info_ptr < section->buffer + section->size) |
| 5512 | { |
| 5513 | unsigned int length, initial_length_size; |
| 5514 | struct dwarf2_per_cu_data *this_cu; |
| 5515 | sect_offset offset; |
| 5516 | |
| 5517 | offset.sect_off = info_ptr - section->buffer; |
| 5518 | |
| 5519 | /* Read just enough information to find out where the next |
| 5520 | compilation unit is. */ |
| 5521 | length = read_initial_length (abfd, info_ptr, &initial_length_size); |
| 5522 | |
| 5523 | /* Save the compilation unit for later lookup. */ |
| 5524 | this_cu = obstack_alloc (&objfile->objfile_obstack, |
| 5525 | sizeof (struct dwarf2_per_cu_data)); |
| 5526 | memset (this_cu, 0, sizeof (*this_cu)); |
| 5527 | this_cu->offset = offset; |
| 5528 | this_cu->length = length + initial_length_size; |
| 5529 | this_cu->is_dwz = is_dwz; |
| 5530 | this_cu->objfile = objfile; |
| 5531 | this_cu->info_or_types_section = section; |
| 5532 | |
| 5533 | if (*n_comp_units == *n_allocated) |
| 5534 | { |
| 5535 | *n_allocated *= 2; |
| 5536 | *all_comp_units = xrealloc (*all_comp_units, |
| 5537 | *n_allocated |
| 5538 | * sizeof (struct dwarf2_per_cu_data *)); |
| 5539 | } |
| 5540 | (*all_comp_units)[*n_comp_units] = this_cu; |
| 5541 | ++*n_comp_units; |
| 5542 | |
| 5543 | info_ptr = info_ptr + this_cu->length; |
| 5544 | } |
| 5545 | } |
| 5546 | |
| 5547 | /* Create a list of all compilation units in OBJFILE. |
| 5548 | This is only done for -readnow and building partial symtabs. */ |
| 5549 | |
| 5550 | static void |
| 5551 | create_all_comp_units (struct objfile *objfile) |
| 5552 | { |
| 5553 | int n_allocated; |
| 5554 | int n_comp_units; |
| 5555 | struct dwarf2_per_cu_data **all_comp_units; |
| 5556 | |
| 5557 | n_comp_units = 0; |
| 5558 | n_allocated = 10; |
| 5559 | all_comp_units = xmalloc (n_allocated |
| 5560 | * sizeof (struct dwarf2_per_cu_data *)); |
| 5561 | |
| 5562 | read_comp_units_from_section (objfile, &dwarf2_per_objfile->info, 0, |
| 5563 | &n_allocated, &n_comp_units, &all_comp_units); |
| 5564 | |
| 5565 | if (bfd_get_section_by_name (objfile->obfd, ".gnu_debugaltlink") != NULL) |
| 5566 | { |
| 5567 | struct dwz_file *dwz = dwarf2_get_dwz_file (); |
| 5568 | |
| 5569 | read_comp_units_from_section (objfile, &dwz->info, 1, |
| 5570 | &n_allocated, &n_comp_units, |
| 5571 | &all_comp_units); |
| 5572 | } |
| 5573 | |
| 5574 | dwarf2_per_objfile->all_comp_units |
| 5575 | = obstack_alloc (&objfile->objfile_obstack, |
| 5576 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); |
| 5577 | memcpy (dwarf2_per_objfile->all_comp_units, all_comp_units, |
| 5578 | n_comp_units * sizeof (struct dwarf2_per_cu_data *)); |
| 5579 | xfree (all_comp_units); |
| 5580 | dwarf2_per_objfile->n_comp_units = n_comp_units; |
| 5581 | } |
| 5582 | |
| 5583 | /* Process all loaded DIEs for compilation unit CU, starting at |
| 5584 | FIRST_DIE. The caller should pass NEED_PC == 1 if the compilation |
| 5585 | unit DIE did not have PC info (DW_AT_low_pc and DW_AT_high_pc, or |
| 5586 | DW_AT_ranges). If NEED_PC is set, then this function will set |
| 5587 | *LOWPC and *HIGHPC to the lowest and highest PC values found in CU |
| 5588 | and record the covered ranges in the addrmap. */ |
| 5589 | |
| 5590 | static void |
| 5591 | scan_partial_symbols (struct partial_die_info *first_die, CORE_ADDR *lowpc, |
| 5592 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
| 5593 | { |
| 5594 | struct partial_die_info *pdi; |
| 5595 | |
| 5596 | /* Now, march along the PDI's, descending into ones which have |
| 5597 | interesting children but skipping the children of the other ones, |
| 5598 | until we reach the end of the compilation unit. */ |
| 5599 | |
| 5600 | pdi = first_die; |
| 5601 | |
| 5602 | while (pdi != NULL) |
| 5603 | { |
| 5604 | fixup_partial_die (pdi, cu); |
| 5605 | |
| 5606 | /* Anonymous namespaces or modules have no name but have interesting |
| 5607 | children, so we need to look at them. Ditto for anonymous |
| 5608 | enums. */ |
| 5609 | |
| 5610 | if (pdi->name != NULL || pdi->tag == DW_TAG_namespace |
| 5611 | || pdi->tag == DW_TAG_module || pdi->tag == DW_TAG_enumeration_type |
| 5612 | || pdi->tag == DW_TAG_imported_unit) |
| 5613 | { |
| 5614 | switch (pdi->tag) |
| 5615 | { |
| 5616 | case DW_TAG_subprogram: |
| 5617 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
| 5618 | break; |
| 5619 | case DW_TAG_constant: |
| 5620 | case DW_TAG_variable: |
| 5621 | case DW_TAG_typedef: |
| 5622 | case DW_TAG_union_type: |
| 5623 | if (!pdi->is_declaration) |
| 5624 | { |
| 5625 | add_partial_symbol (pdi, cu); |
| 5626 | } |
| 5627 | break; |
| 5628 | case DW_TAG_class_type: |
| 5629 | case DW_TAG_interface_type: |
| 5630 | case DW_TAG_structure_type: |
| 5631 | if (!pdi->is_declaration) |
| 5632 | { |
| 5633 | add_partial_symbol (pdi, cu); |
| 5634 | } |
| 5635 | break; |
| 5636 | case DW_TAG_enumeration_type: |
| 5637 | if (!pdi->is_declaration) |
| 5638 | add_partial_enumeration (pdi, cu); |
| 5639 | break; |
| 5640 | case DW_TAG_base_type: |
| 5641 | case DW_TAG_subrange_type: |
| 5642 | /* File scope base type definitions are added to the partial |
| 5643 | symbol table. */ |
| 5644 | add_partial_symbol (pdi, cu); |
| 5645 | break; |
| 5646 | case DW_TAG_namespace: |
| 5647 | add_partial_namespace (pdi, lowpc, highpc, need_pc, cu); |
| 5648 | break; |
| 5649 | case DW_TAG_module: |
| 5650 | add_partial_module (pdi, lowpc, highpc, need_pc, cu); |
| 5651 | break; |
| 5652 | case DW_TAG_imported_unit: |
| 5653 | { |
| 5654 | struct dwarf2_per_cu_data *per_cu; |
| 5655 | |
| 5656 | /* For now we don't handle imported units in type units. */ |
| 5657 | if (cu->per_cu->is_debug_types) |
| 5658 | { |
| 5659 | error (_("Dwarf Error: DW_TAG_imported_unit is not" |
| 5660 | " supported in type units [in module %s]"), |
| 5661 | cu->objfile->name); |
| 5662 | } |
| 5663 | |
| 5664 | per_cu = dwarf2_find_containing_comp_unit (pdi->d.offset, |
| 5665 | pdi->is_dwz, |
| 5666 | cu->objfile); |
| 5667 | |
| 5668 | /* Go read the partial unit, if needed. */ |
| 5669 | if (per_cu->v.psymtab == NULL) |
| 5670 | process_psymtab_comp_unit (per_cu, 1); |
| 5671 | |
| 5672 | VEC_safe_push (dwarf2_per_cu_ptr, |
| 5673 | cu->per_cu->s.imported_symtabs, per_cu); |
| 5674 | } |
| 5675 | break; |
| 5676 | default: |
| 5677 | break; |
| 5678 | } |
| 5679 | } |
| 5680 | |
| 5681 | /* If the die has a sibling, skip to the sibling. */ |
| 5682 | |
| 5683 | pdi = pdi->die_sibling; |
| 5684 | } |
| 5685 | } |
| 5686 | |
| 5687 | /* Functions used to compute the fully scoped name of a partial DIE. |
| 5688 | |
| 5689 | Normally, this is simple. For C++, the parent DIE's fully scoped |
| 5690 | name is concatenated with "::" and the partial DIE's name. For |
| 5691 | Java, the same thing occurs except that "." is used instead of "::". |
| 5692 | Enumerators are an exception; they use the scope of their parent |
| 5693 | enumeration type, i.e. the name of the enumeration type is not |
| 5694 | prepended to the enumerator. |
| 5695 | |
| 5696 | There are two complexities. One is DW_AT_specification; in this |
| 5697 | case "parent" means the parent of the target of the specification, |
| 5698 | instead of the direct parent of the DIE. The other is compilers |
| 5699 | which do not emit DW_TAG_namespace; in this case we try to guess |
| 5700 | the fully qualified name of structure types from their members' |
| 5701 | linkage names. This must be done using the DIE's children rather |
| 5702 | than the children of any DW_AT_specification target. We only need |
| 5703 | to do this for structures at the top level, i.e. if the target of |
| 5704 | any DW_AT_specification (if any; otherwise the DIE itself) does not |
| 5705 | have a parent. */ |
| 5706 | |
| 5707 | /* Compute the scope prefix associated with PDI's parent, in |
| 5708 | compilation unit CU. The result will be allocated on CU's |
| 5709 | comp_unit_obstack, or a copy of the already allocated PDI->NAME |
| 5710 | field. NULL is returned if no prefix is necessary. */ |
| 5711 | static char * |
| 5712 | partial_die_parent_scope (struct partial_die_info *pdi, |
| 5713 | struct dwarf2_cu *cu) |
| 5714 | { |
| 5715 | char *grandparent_scope; |
| 5716 | struct partial_die_info *parent, *real_pdi; |
| 5717 | |
| 5718 | /* We need to look at our parent DIE; if we have a DW_AT_specification, |
| 5719 | then this means the parent of the specification DIE. */ |
| 5720 | |
| 5721 | real_pdi = pdi; |
| 5722 | while (real_pdi->has_specification) |
| 5723 | real_pdi = find_partial_die (real_pdi->spec_offset, |
| 5724 | real_pdi->spec_is_dwz, cu); |
| 5725 | |
| 5726 | parent = real_pdi->die_parent; |
| 5727 | if (parent == NULL) |
| 5728 | return NULL; |
| 5729 | |
| 5730 | if (parent->scope_set) |
| 5731 | return parent->scope; |
| 5732 | |
| 5733 | fixup_partial_die (parent, cu); |
| 5734 | |
| 5735 | grandparent_scope = partial_die_parent_scope (parent, cu); |
| 5736 | |
| 5737 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
| 5738 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. |
| 5739 | Work around this problem here. */ |
| 5740 | if (cu->language == language_cplus |
| 5741 | && parent->tag == DW_TAG_namespace |
| 5742 | && strcmp (parent->name, "::") == 0 |
| 5743 | && grandparent_scope == NULL) |
| 5744 | { |
| 5745 | parent->scope = NULL; |
| 5746 | parent->scope_set = 1; |
| 5747 | return NULL; |
| 5748 | } |
| 5749 | |
| 5750 | if (pdi->tag == DW_TAG_enumerator) |
| 5751 | /* Enumerators should not get the name of the enumeration as a prefix. */ |
| 5752 | parent->scope = grandparent_scope; |
| 5753 | else if (parent->tag == DW_TAG_namespace |
| 5754 | || parent->tag == DW_TAG_module |
| 5755 | || parent->tag == DW_TAG_structure_type |
| 5756 | || parent->tag == DW_TAG_class_type |
| 5757 | || parent->tag == DW_TAG_interface_type |
| 5758 | || parent->tag == DW_TAG_union_type |
| 5759 | || parent->tag == DW_TAG_enumeration_type) |
| 5760 | { |
| 5761 | if (grandparent_scope == NULL) |
| 5762 | parent->scope = parent->name; |
| 5763 | else |
| 5764 | parent->scope = typename_concat (&cu->comp_unit_obstack, |
| 5765 | grandparent_scope, |
| 5766 | parent->name, 0, cu); |
| 5767 | } |
| 5768 | else |
| 5769 | { |
| 5770 | /* FIXME drow/2004-04-01: What should we be doing with |
| 5771 | function-local names? For partial symbols, we should probably be |
| 5772 | ignoring them. */ |
| 5773 | complaint (&symfile_complaints, |
| 5774 | _("unhandled containing DIE tag %d for DIE at %d"), |
| 5775 | parent->tag, pdi->offset.sect_off); |
| 5776 | parent->scope = grandparent_scope; |
| 5777 | } |
| 5778 | |
| 5779 | parent->scope_set = 1; |
| 5780 | return parent->scope; |
| 5781 | } |
| 5782 | |
| 5783 | /* Return the fully scoped name associated with PDI, from compilation unit |
| 5784 | CU. The result will be allocated with malloc. */ |
| 5785 | |
| 5786 | static char * |
| 5787 | partial_die_full_name (struct partial_die_info *pdi, |
| 5788 | struct dwarf2_cu *cu) |
| 5789 | { |
| 5790 | char *parent_scope; |
| 5791 | |
| 5792 | /* If this is a template instantiation, we can not work out the |
| 5793 | template arguments from partial DIEs. So, unfortunately, we have |
| 5794 | to go through the full DIEs. At least any work we do building |
| 5795 | types here will be reused if full symbols are loaded later. */ |
| 5796 | if (pdi->has_template_arguments) |
| 5797 | { |
| 5798 | fixup_partial_die (pdi, cu); |
| 5799 | |
| 5800 | if (pdi->name != NULL && strchr (pdi->name, '<') == NULL) |
| 5801 | { |
| 5802 | struct die_info *die; |
| 5803 | struct attribute attr; |
| 5804 | struct dwarf2_cu *ref_cu = cu; |
| 5805 | |
| 5806 | /* DW_FORM_ref_addr is using section offset. */ |
| 5807 | attr.name = 0; |
| 5808 | attr.form = DW_FORM_ref_addr; |
| 5809 | attr.u.unsnd = pdi->offset.sect_off; |
| 5810 | die = follow_die_ref (NULL, &attr, &ref_cu); |
| 5811 | |
| 5812 | return xstrdup (dwarf2_full_name (NULL, die, ref_cu)); |
| 5813 | } |
| 5814 | } |
| 5815 | |
| 5816 | parent_scope = partial_die_parent_scope (pdi, cu); |
| 5817 | if (parent_scope == NULL) |
| 5818 | return NULL; |
| 5819 | else |
| 5820 | return typename_concat (NULL, parent_scope, pdi->name, 0, cu); |
| 5821 | } |
| 5822 | |
| 5823 | static void |
| 5824 | add_partial_symbol (struct partial_die_info *pdi, struct dwarf2_cu *cu) |
| 5825 | { |
| 5826 | struct objfile *objfile = cu->objfile; |
| 5827 | CORE_ADDR addr = 0; |
| 5828 | char *actual_name = NULL; |
| 5829 | CORE_ADDR baseaddr; |
| 5830 | int built_actual_name = 0; |
| 5831 | |
| 5832 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 5833 | |
| 5834 | actual_name = partial_die_full_name (pdi, cu); |
| 5835 | if (actual_name) |
| 5836 | built_actual_name = 1; |
| 5837 | |
| 5838 | if (actual_name == NULL) |
| 5839 | actual_name = pdi->name; |
| 5840 | |
| 5841 | switch (pdi->tag) |
| 5842 | { |
| 5843 | case DW_TAG_subprogram: |
| 5844 | if (pdi->is_external || cu->language == language_ada) |
| 5845 | { |
| 5846 | /* brobecker/2007-12-26: Normally, only "external" DIEs are part |
| 5847 | of the global scope. But in Ada, we want to be able to access |
| 5848 | nested procedures globally. So all Ada subprograms are stored |
| 5849 | in the global scope. */ |
| 5850 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
| 5851 | mst_text, objfile); */ |
| 5852 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5853 | built_actual_name, |
| 5854 | VAR_DOMAIN, LOC_BLOCK, |
| 5855 | &objfile->global_psymbols, |
| 5856 | 0, pdi->lowpc + baseaddr, |
| 5857 | cu->language, objfile); |
| 5858 | } |
| 5859 | else |
| 5860 | { |
| 5861 | /* prim_record_minimal_symbol (actual_name, pdi->lowpc + baseaddr, |
| 5862 | mst_file_text, objfile); */ |
| 5863 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5864 | built_actual_name, |
| 5865 | VAR_DOMAIN, LOC_BLOCK, |
| 5866 | &objfile->static_psymbols, |
| 5867 | 0, pdi->lowpc + baseaddr, |
| 5868 | cu->language, objfile); |
| 5869 | } |
| 5870 | break; |
| 5871 | case DW_TAG_constant: |
| 5872 | { |
| 5873 | struct psymbol_allocation_list *list; |
| 5874 | |
| 5875 | if (pdi->is_external) |
| 5876 | list = &objfile->global_psymbols; |
| 5877 | else |
| 5878 | list = &objfile->static_psymbols; |
| 5879 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5880 | built_actual_name, VAR_DOMAIN, LOC_STATIC, |
| 5881 | list, 0, 0, cu->language, objfile); |
| 5882 | } |
| 5883 | break; |
| 5884 | case DW_TAG_variable: |
| 5885 | if (pdi->d.locdesc) |
| 5886 | addr = decode_locdesc (pdi->d.locdesc, cu); |
| 5887 | |
| 5888 | if (pdi->d.locdesc |
| 5889 | && addr == 0 |
| 5890 | && !dwarf2_per_objfile->has_section_at_zero) |
| 5891 | { |
| 5892 | /* A global or static variable may also have been stripped |
| 5893 | out by the linker if unused, in which case its address |
| 5894 | will be nullified; do not add such variables into partial |
| 5895 | symbol table then. */ |
| 5896 | } |
| 5897 | else if (pdi->is_external) |
| 5898 | { |
| 5899 | /* Global Variable. |
| 5900 | Don't enter into the minimal symbol tables as there is |
| 5901 | a minimal symbol table entry from the ELF symbols already. |
| 5902 | Enter into partial symbol table if it has a location |
| 5903 | descriptor or a type. |
| 5904 | If the location descriptor is missing, new_symbol will create |
| 5905 | a LOC_UNRESOLVED symbol, the address of the variable will then |
| 5906 | be determined from the minimal symbol table whenever the variable |
| 5907 | is referenced. |
| 5908 | The address for the partial symbol table entry is not |
| 5909 | used by GDB, but it comes in handy for debugging partial symbol |
| 5910 | table building. */ |
| 5911 | |
| 5912 | if (pdi->d.locdesc || pdi->has_type) |
| 5913 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5914 | built_actual_name, |
| 5915 | VAR_DOMAIN, LOC_STATIC, |
| 5916 | &objfile->global_psymbols, |
| 5917 | 0, addr + baseaddr, |
| 5918 | cu->language, objfile); |
| 5919 | } |
| 5920 | else |
| 5921 | { |
| 5922 | /* Static Variable. Skip symbols without location descriptors. */ |
| 5923 | if (pdi->d.locdesc == NULL) |
| 5924 | { |
| 5925 | if (built_actual_name) |
| 5926 | xfree (actual_name); |
| 5927 | return; |
| 5928 | } |
| 5929 | /* prim_record_minimal_symbol (actual_name, addr + baseaddr, |
| 5930 | mst_file_data, objfile); */ |
| 5931 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5932 | built_actual_name, |
| 5933 | VAR_DOMAIN, LOC_STATIC, |
| 5934 | &objfile->static_psymbols, |
| 5935 | 0, addr + baseaddr, |
| 5936 | cu->language, objfile); |
| 5937 | } |
| 5938 | break; |
| 5939 | case DW_TAG_typedef: |
| 5940 | case DW_TAG_base_type: |
| 5941 | case DW_TAG_subrange_type: |
| 5942 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5943 | built_actual_name, |
| 5944 | VAR_DOMAIN, LOC_TYPEDEF, |
| 5945 | &objfile->static_psymbols, |
| 5946 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 5947 | break; |
| 5948 | case DW_TAG_namespace: |
| 5949 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5950 | built_actual_name, |
| 5951 | VAR_DOMAIN, LOC_TYPEDEF, |
| 5952 | &objfile->global_psymbols, |
| 5953 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 5954 | break; |
| 5955 | case DW_TAG_class_type: |
| 5956 | case DW_TAG_interface_type: |
| 5957 | case DW_TAG_structure_type: |
| 5958 | case DW_TAG_union_type: |
| 5959 | case DW_TAG_enumeration_type: |
| 5960 | /* Skip external references. The DWARF standard says in the section |
| 5961 | about "Structure, Union, and Class Type Entries": "An incomplete |
| 5962 | structure, union or class type is represented by a structure, |
| 5963 | union or class entry that does not have a byte size attribute |
| 5964 | and that has a DW_AT_declaration attribute." */ |
| 5965 | if (!pdi->has_byte_size && pdi->is_declaration) |
| 5966 | { |
| 5967 | if (built_actual_name) |
| 5968 | xfree (actual_name); |
| 5969 | return; |
| 5970 | } |
| 5971 | |
| 5972 | /* NOTE: carlton/2003-10-07: See comment in new_symbol about |
| 5973 | static vs. global. */ |
| 5974 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5975 | built_actual_name, |
| 5976 | STRUCT_DOMAIN, LOC_TYPEDEF, |
| 5977 | (cu->language == language_cplus |
| 5978 | || cu->language == language_java) |
| 5979 | ? &objfile->global_psymbols |
| 5980 | : &objfile->static_psymbols, |
| 5981 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 5982 | |
| 5983 | break; |
| 5984 | case DW_TAG_enumerator: |
| 5985 | add_psymbol_to_list (actual_name, strlen (actual_name), |
| 5986 | built_actual_name, |
| 5987 | VAR_DOMAIN, LOC_CONST, |
| 5988 | (cu->language == language_cplus |
| 5989 | || cu->language == language_java) |
| 5990 | ? &objfile->global_psymbols |
| 5991 | : &objfile->static_psymbols, |
| 5992 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 5993 | break; |
| 5994 | default: |
| 5995 | break; |
| 5996 | } |
| 5997 | |
| 5998 | if (built_actual_name) |
| 5999 | xfree (actual_name); |
| 6000 | } |
| 6001 | |
| 6002 | /* Read a partial die corresponding to a namespace; also, add a symbol |
| 6003 | corresponding to that namespace to the symbol table. NAMESPACE is |
| 6004 | the name of the enclosing namespace. */ |
| 6005 | |
| 6006 | static void |
| 6007 | add_partial_namespace (struct partial_die_info *pdi, |
| 6008 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 6009 | int need_pc, struct dwarf2_cu *cu) |
| 6010 | { |
| 6011 | /* Add a symbol for the namespace. */ |
| 6012 | |
| 6013 | add_partial_symbol (pdi, cu); |
| 6014 | |
| 6015 | /* Now scan partial symbols in that namespace. */ |
| 6016 | |
| 6017 | if (pdi->has_children) |
| 6018 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
| 6019 | } |
| 6020 | |
| 6021 | /* Read a partial die corresponding to a Fortran module. */ |
| 6022 | |
| 6023 | static void |
| 6024 | add_partial_module (struct partial_die_info *pdi, CORE_ADDR *lowpc, |
| 6025 | CORE_ADDR *highpc, int need_pc, struct dwarf2_cu *cu) |
| 6026 | { |
| 6027 | /* Now scan partial symbols in that module. */ |
| 6028 | |
| 6029 | if (pdi->has_children) |
| 6030 | scan_partial_symbols (pdi->die_child, lowpc, highpc, need_pc, cu); |
| 6031 | } |
| 6032 | |
| 6033 | /* Read a partial die corresponding to a subprogram and create a partial |
| 6034 | symbol for that subprogram. When the CU language allows it, this |
| 6035 | routine also defines a partial symbol for each nested subprogram |
| 6036 | that this subprogram contains. |
| 6037 | |
| 6038 | DIE my also be a lexical block, in which case we simply search |
| 6039 | recursively for suprograms defined inside that lexical block. |
| 6040 | Again, this is only performed when the CU language allows this |
| 6041 | type of definitions. */ |
| 6042 | |
| 6043 | static void |
| 6044 | add_partial_subprogram (struct partial_die_info *pdi, |
| 6045 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 6046 | int need_pc, struct dwarf2_cu *cu) |
| 6047 | { |
| 6048 | if (pdi->tag == DW_TAG_subprogram) |
| 6049 | { |
| 6050 | if (pdi->has_pc_info) |
| 6051 | { |
| 6052 | if (pdi->lowpc < *lowpc) |
| 6053 | *lowpc = pdi->lowpc; |
| 6054 | if (pdi->highpc > *highpc) |
| 6055 | *highpc = pdi->highpc; |
| 6056 | if (need_pc) |
| 6057 | { |
| 6058 | CORE_ADDR baseaddr; |
| 6059 | struct objfile *objfile = cu->objfile; |
| 6060 | |
| 6061 | baseaddr = ANOFFSET (objfile->section_offsets, |
| 6062 | SECT_OFF_TEXT (objfile)); |
| 6063 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 6064 | pdi->lowpc + baseaddr, |
| 6065 | pdi->highpc - 1 + baseaddr, |
| 6066 | cu->per_cu->v.psymtab); |
| 6067 | } |
| 6068 | } |
| 6069 | |
| 6070 | if (pdi->has_pc_info || (!pdi->is_external && pdi->may_be_inlined)) |
| 6071 | { |
| 6072 | if (!pdi->is_declaration) |
| 6073 | /* Ignore subprogram DIEs that do not have a name, they are |
| 6074 | illegal. Do not emit a complaint at this point, we will |
| 6075 | do so when we convert this psymtab into a symtab. */ |
| 6076 | if (pdi->name) |
| 6077 | add_partial_symbol (pdi, cu); |
| 6078 | } |
| 6079 | } |
| 6080 | |
| 6081 | if (! pdi->has_children) |
| 6082 | return; |
| 6083 | |
| 6084 | if (cu->language == language_ada) |
| 6085 | { |
| 6086 | pdi = pdi->die_child; |
| 6087 | while (pdi != NULL) |
| 6088 | { |
| 6089 | fixup_partial_die (pdi, cu); |
| 6090 | if (pdi->tag == DW_TAG_subprogram |
| 6091 | || pdi->tag == DW_TAG_lexical_block) |
| 6092 | add_partial_subprogram (pdi, lowpc, highpc, need_pc, cu); |
| 6093 | pdi = pdi->die_sibling; |
| 6094 | } |
| 6095 | } |
| 6096 | } |
| 6097 | |
| 6098 | /* Read a partial die corresponding to an enumeration type. */ |
| 6099 | |
| 6100 | static void |
| 6101 | add_partial_enumeration (struct partial_die_info *enum_pdi, |
| 6102 | struct dwarf2_cu *cu) |
| 6103 | { |
| 6104 | struct partial_die_info *pdi; |
| 6105 | |
| 6106 | if (enum_pdi->name != NULL) |
| 6107 | add_partial_symbol (enum_pdi, cu); |
| 6108 | |
| 6109 | pdi = enum_pdi->die_child; |
| 6110 | while (pdi) |
| 6111 | { |
| 6112 | if (pdi->tag != DW_TAG_enumerator || pdi->name == NULL) |
| 6113 | complaint (&symfile_complaints, _("malformed enumerator DIE ignored")); |
| 6114 | else |
| 6115 | add_partial_symbol (pdi, cu); |
| 6116 | pdi = pdi->die_sibling; |
| 6117 | } |
| 6118 | } |
| 6119 | |
| 6120 | /* Return the initial uleb128 in the die at INFO_PTR. */ |
| 6121 | |
| 6122 | static unsigned int |
| 6123 | peek_abbrev_code (bfd *abfd, gdb_byte *info_ptr) |
| 6124 | { |
| 6125 | unsigned int bytes_read; |
| 6126 | |
| 6127 | return read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 6128 | } |
| 6129 | |
| 6130 | /* Read the initial uleb128 in the die at INFO_PTR in compilation unit CU. |
| 6131 | Return the corresponding abbrev, or NULL if the number is zero (indicating |
| 6132 | an empty DIE). In either case *BYTES_READ will be set to the length of |
| 6133 | the initial number. */ |
| 6134 | |
| 6135 | static struct abbrev_info * |
| 6136 | peek_die_abbrev (gdb_byte *info_ptr, unsigned int *bytes_read, |
| 6137 | struct dwarf2_cu *cu) |
| 6138 | { |
| 6139 | bfd *abfd = cu->objfile->obfd; |
| 6140 | unsigned int abbrev_number; |
| 6141 | struct abbrev_info *abbrev; |
| 6142 | |
| 6143 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, bytes_read); |
| 6144 | |
| 6145 | if (abbrev_number == 0) |
| 6146 | return NULL; |
| 6147 | |
| 6148 | abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number); |
| 6149 | if (!abbrev) |
| 6150 | { |
| 6151 | error (_("Dwarf Error: Could not find abbrev number %d [in module %s]"), |
| 6152 | abbrev_number, bfd_get_filename (abfd)); |
| 6153 | } |
| 6154 | |
| 6155 | return abbrev; |
| 6156 | } |
| 6157 | |
| 6158 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
| 6159 | Returns a pointer to the end of a series of DIEs, terminated by an empty |
| 6160 | DIE. Any children of the skipped DIEs will also be skipped. */ |
| 6161 | |
| 6162 | static gdb_byte * |
| 6163 | skip_children (const struct die_reader_specs *reader, gdb_byte *info_ptr) |
| 6164 | { |
| 6165 | struct dwarf2_cu *cu = reader->cu; |
| 6166 | struct abbrev_info *abbrev; |
| 6167 | unsigned int bytes_read; |
| 6168 | |
| 6169 | while (1) |
| 6170 | { |
| 6171 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); |
| 6172 | if (abbrev == NULL) |
| 6173 | return info_ptr + bytes_read; |
| 6174 | else |
| 6175 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
| 6176 | } |
| 6177 | } |
| 6178 | |
| 6179 | /* Scan the debug information for CU starting at INFO_PTR in buffer BUFFER. |
| 6180 | INFO_PTR should point just after the initial uleb128 of a DIE, and the |
| 6181 | abbrev corresponding to that skipped uleb128 should be passed in |
| 6182 | ABBREV. Returns a pointer to this DIE's sibling, skipping any |
| 6183 | children. */ |
| 6184 | |
| 6185 | static gdb_byte * |
| 6186 | skip_one_die (const struct die_reader_specs *reader, gdb_byte *info_ptr, |
| 6187 | struct abbrev_info *abbrev) |
| 6188 | { |
| 6189 | unsigned int bytes_read; |
| 6190 | struct attribute attr; |
| 6191 | bfd *abfd = reader->abfd; |
| 6192 | struct dwarf2_cu *cu = reader->cu; |
| 6193 | gdb_byte *buffer = reader->buffer; |
| 6194 | const gdb_byte *buffer_end = reader->buffer_end; |
| 6195 | gdb_byte *start_info_ptr = info_ptr; |
| 6196 | unsigned int form, i; |
| 6197 | |
| 6198 | for (i = 0; i < abbrev->num_attrs; i++) |
| 6199 | { |
| 6200 | /* The only abbrev we care about is DW_AT_sibling. */ |
| 6201 | if (abbrev->attrs[i].name == DW_AT_sibling) |
| 6202 | { |
| 6203 | read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
| 6204 | if (attr.form == DW_FORM_ref_addr) |
| 6205 | complaint (&symfile_complaints, |
| 6206 | _("ignoring absolute DW_AT_sibling")); |
| 6207 | else |
| 6208 | return buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
| 6209 | } |
| 6210 | |
| 6211 | /* If it isn't DW_AT_sibling, skip this attribute. */ |
| 6212 | form = abbrev->attrs[i].form; |
| 6213 | skip_attribute: |
| 6214 | switch (form) |
| 6215 | { |
| 6216 | case DW_FORM_ref_addr: |
| 6217 | /* In DWARF 2, DW_FORM_ref_addr is address sized; in DWARF 3 |
| 6218 | and later it is offset sized. */ |
| 6219 | if (cu->header.version == 2) |
| 6220 | info_ptr += cu->header.addr_size; |
| 6221 | else |
| 6222 | info_ptr += cu->header.offset_size; |
| 6223 | break; |
| 6224 | case DW_FORM_GNU_ref_alt: |
| 6225 | info_ptr += cu->header.offset_size; |
| 6226 | break; |
| 6227 | case DW_FORM_addr: |
| 6228 | info_ptr += cu->header.addr_size; |
| 6229 | break; |
| 6230 | case DW_FORM_data1: |
| 6231 | case DW_FORM_ref1: |
| 6232 | case DW_FORM_flag: |
| 6233 | info_ptr += 1; |
| 6234 | break; |
| 6235 | case DW_FORM_flag_present: |
| 6236 | break; |
| 6237 | case DW_FORM_data2: |
| 6238 | case DW_FORM_ref2: |
| 6239 | info_ptr += 2; |
| 6240 | break; |
| 6241 | case DW_FORM_data4: |
| 6242 | case DW_FORM_ref4: |
| 6243 | info_ptr += 4; |
| 6244 | break; |
| 6245 | case DW_FORM_data8: |
| 6246 | case DW_FORM_ref8: |
| 6247 | case DW_FORM_ref_sig8: |
| 6248 | info_ptr += 8; |
| 6249 | break; |
| 6250 | case DW_FORM_string: |
| 6251 | read_direct_string (abfd, info_ptr, &bytes_read); |
| 6252 | info_ptr += bytes_read; |
| 6253 | break; |
| 6254 | case DW_FORM_sec_offset: |
| 6255 | case DW_FORM_strp: |
| 6256 | case DW_FORM_GNU_strp_alt: |
| 6257 | info_ptr += cu->header.offset_size; |
| 6258 | break; |
| 6259 | case DW_FORM_exprloc: |
| 6260 | case DW_FORM_block: |
| 6261 | info_ptr += read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 6262 | info_ptr += bytes_read; |
| 6263 | break; |
| 6264 | case DW_FORM_block1: |
| 6265 | info_ptr += 1 + read_1_byte (abfd, info_ptr); |
| 6266 | break; |
| 6267 | case DW_FORM_block2: |
| 6268 | info_ptr += 2 + read_2_bytes (abfd, info_ptr); |
| 6269 | break; |
| 6270 | case DW_FORM_block4: |
| 6271 | info_ptr += 4 + read_4_bytes (abfd, info_ptr); |
| 6272 | break; |
| 6273 | case DW_FORM_sdata: |
| 6274 | case DW_FORM_udata: |
| 6275 | case DW_FORM_ref_udata: |
| 6276 | case DW_FORM_GNU_addr_index: |
| 6277 | case DW_FORM_GNU_str_index: |
| 6278 | info_ptr = (gdb_byte *) safe_skip_leb128 (info_ptr, buffer_end); |
| 6279 | break; |
| 6280 | case DW_FORM_indirect: |
| 6281 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 6282 | info_ptr += bytes_read; |
| 6283 | /* We need to continue parsing from here, so just go back to |
| 6284 | the top. */ |
| 6285 | goto skip_attribute; |
| 6286 | |
| 6287 | default: |
| 6288 | error (_("Dwarf Error: Cannot handle %s " |
| 6289 | "in DWARF reader [in module %s]"), |
| 6290 | dwarf_form_name (form), |
| 6291 | bfd_get_filename (abfd)); |
| 6292 | } |
| 6293 | } |
| 6294 | |
| 6295 | if (abbrev->has_children) |
| 6296 | return skip_children (reader, info_ptr); |
| 6297 | else |
| 6298 | return info_ptr; |
| 6299 | } |
| 6300 | |
| 6301 | /* Locate ORIG_PDI's sibling. |
| 6302 | INFO_PTR should point to the start of the next DIE after ORIG_PDI. */ |
| 6303 | |
| 6304 | static gdb_byte * |
| 6305 | locate_pdi_sibling (const struct die_reader_specs *reader, |
| 6306 | struct partial_die_info *orig_pdi, |
| 6307 | gdb_byte *info_ptr) |
| 6308 | { |
| 6309 | /* Do we know the sibling already? */ |
| 6310 | |
| 6311 | if (orig_pdi->sibling) |
| 6312 | return orig_pdi->sibling; |
| 6313 | |
| 6314 | /* Are there any children to deal with? */ |
| 6315 | |
| 6316 | if (!orig_pdi->has_children) |
| 6317 | return info_ptr; |
| 6318 | |
| 6319 | /* Skip the children the long way. */ |
| 6320 | |
| 6321 | return skip_children (reader, info_ptr); |
| 6322 | } |
| 6323 | |
| 6324 | /* Expand this partial symbol table into a full symbol table. */ |
| 6325 | |
| 6326 | static void |
| 6327 | dwarf2_psymtab_to_symtab (struct objfile *objfile, struct partial_symtab *pst) |
| 6328 | { |
| 6329 | if (pst != NULL) |
| 6330 | { |
| 6331 | if (pst->readin) |
| 6332 | { |
| 6333 | warning (_("bug: psymtab for %s is already read in."), |
| 6334 | pst->filename); |
| 6335 | } |
| 6336 | else |
| 6337 | { |
| 6338 | if (info_verbose) |
| 6339 | { |
| 6340 | printf_filtered (_("Reading in symbols for %s..."), |
| 6341 | pst->filename); |
| 6342 | gdb_flush (gdb_stdout); |
| 6343 | } |
| 6344 | |
| 6345 | /* Restore our global data. */ |
| 6346 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 6347 | |
| 6348 | /* If this psymtab is constructed from a debug-only objfile, the |
| 6349 | has_section_at_zero flag will not necessarily be correct. We |
| 6350 | can get the correct value for this flag by looking at the data |
| 6351 | associated with the (presumably stripped) associated objfile. */ |
| 6352 | if (objfile->separate_debug_objfile_backlink) |
| 6353 | { |
| 6354 | struct dwarf2_per_objfile *dpo_backlink |
| 6355 | = objfile_data (objfile->separate_debug_objfile_backlink, |
| 6356 | dwarf2_objfile_data_key); |
| 6357 | |
| 6358 | dwarf2_per_objfile->has_section_at_zero |
| 6359 | = dpo_backlink->has_section_at_zero; |
| 6360 | } |
| 6361 | |
| 6362 | dwarf2_per_objfile->reading_partial_symbols = 0; |
| 6363 | |
| 6364 | psymtab_to_symtab_1 (pst); |
| 6365 | |
| 6366 | /* Finish up the debug error message. */ |
| 6367 | if (info_verbose) |
| 6368 | printf_filtered (_("done.\n")); |
| 6369 | } |
| 6370 | } |
| 6371 | |
| 6372 | process_cu_includes (); |
| 6373 | } |
| 6374 | \f |
| 6375 | /* Reading in full CUs. */ |
| 6376 | |
| 6377 | /* Add PER_CU to the queue. */ |
| 6378 | |
| 6379 | static void |
| 6380 | queue_comp_unit (struct dwarf2_per_cu_data *per_cu, |
| 6381 | enum language pretend_language) |
| 6382 | { |
| 6383 | struct dwarf2_queue_item *item; |
| 6384 | |
| 6385 | per_cu->queued = 1; |
| 6386 | item = xmalloc (sizeof (*item)); |
| 6387 | item->per_cu = per_cu; |
| 6388 | item->pretend_language = pretend_language; |
| 6389 | item->next = NULL; |
| 6390 | |
| 6391 | if (dwarf2_queue == NULL) |
| 6392 | dwarf2_queue = item; |
| 6393 | else |
| 6394 | dwarf2_queue_tail->next = item; |
| 6395 | |
| 6396 | dwarf2_queue_tail = item; |
| 6397 | } |
| 6398 | |
| 6399 | /* THIS_CU has a reference to PER_CU. If necessary, load the new compilation |
| 6400 | unit and add it to our queue. |
| 6401 | The result is non-zero if PER_CU was queued, otherwise the result is zero |
| 6402 | meaning either PER_CU is already queued or it is already loaded. */ |
| 6403 | |
| 6404 | static int |
| 6405 | maybe_queue_comp_unit (struct dwarf2_cu *this_cu, |
| 6406 | struct dwarf2_per_cu_data *per_cu, |
| 6407 | enum language pretend_language) |
| 6408 | { |
| 6409 | /* We may arrive here during partial symbol reading, if we need full |
| 6410 | DIEs to process an unusual case (e.g. template arguments). Do |
| 6411 | not queue PER_CU, just tell our caller to load its DIEs. */ |
| 6412 | if (dwarf2_per_objfile->reading_partial_symbols) |
| 6413 | { |
| 6414 | if (per_cu->cu == NULL || per_cu->cu->dies == NULL) |
| 6415 | return 1; |
| 6416 | return 0; |
| 6417 | } |
| 6418 | |
| 6419 | /* Mark the dependence relation so that we don't flush PER_CU |
| 6420 | too early. */ |
| 6421 | dwarf2_add_dependence (this_cu, per_cu); |
| 6422 | |
| 6423 | /* If it's already on the queue, we have nothing to do. */ |
| 6424 | if (per_cu->queued) |
| 6425 | return 0; |
| 6426 | |
| 6427 | /* If the compilation unit is already loaded, just mark it as |
| 6428 | used. */ |
| 6429 | if (per_cu->cu != NULL) |
| 6430 | { |
| 6431 | per_cu->cu->last_used = 0; |
| 6432 | return 0; |
| 6433 | } |
| 6434 | |
| 6435 | /* Add it to the queue. */ |
| 6436 | queue_comp_unit (per_cu, pretend_language); |
| 6437 | |
| 6438 | return 1; |
| 6439 | } |
| 6440 | |
| 6441 | /* Process the queue. */ |
| 6442 | |
| 6443 | static void |
| 6444 | process_queue (void) |
| 6445 | { |
| 6446 | struct dwarf2_queue_item *item, *next_item; |
| 6447 | |
| 6448 | if (dwarf2_read_debug) |
| 6449 | { |
| 6450 | fprintf_unfiltered (gdb_stdlog, |
| 6451 | "Expanding one or more symtabs of objfile %s ...\n", |
| 6452 | dwarf2_per_objfile->objfile->name); |
| 6453 | } |
| 6454 | |
| 6455 | /* The queue starts out with one item, but following a DIE reference |
| 6456 | may load a new CU, adding it to the end of the queue. */ |
| 6457 | for (item = dwarf2_queue; item != NULL; dwarf2_queue = item = next_item) |
| 6458 | { |
| 6459 | if (dwarf2_per_objfile->using_index |
| 6460 | ? !item->per_cu->v.quick->symtab |
| 6461 | : (item->per_cu->v.psymtab && !item->per_cu->v.psymtab->readin)) |
| 6462 | { |
| 6463 | struct dwarf2_per_cu_data *per_cu = item->per_cu; |
| 6464 | |
| 6465 | if (dwarf2_read_debug) |
| 6466 | { |
| 6467 | fprintf_unfiltered (gdb_stdlog, |
| 6468 | "Expanding symtab of %s at offset 0x%x\n", |
| 6469 | per_cu->is_debug_types ? "TU" : "CU", |
| 6470 | per_cu->offset.sect_off); |
| 6471 | } |
| 6472 | |
| 6473 | if (per_cu->is_debug_types) |
| 6474 | process_full_type_unit (per_cu, item->pretend_language); |
| 6475 | else |
| 6476 | process_full_comp_unit (per_cu, item->pretend_language); |
| 6477 | |
| 6478 | if (dwarf2_read_debug) |
| 6479 | { |
| 6480 | fprintf_unfiltered (gdb_stdlog, |
| 6481 | "Done expanding %s at offset 0x%x\n", |
| 6482 | per_cu->is_debug_types ? "TU" : "CU", |
| 6483 | per_cu->offset.sect_off); |
| 6484 | } |
| 6485 | } |
| 6486 | |
| 6487 | item->per_cu->queued = 0; |
| 6488 | next_item = item->next; |
| 6489 | xfree (item); |
| 6490 | } |
| 6491 | |
| 6492 | dwarf2_queue_tail = NULL; |
| 6493 | |
| 6494 | if (dwarf2_read_debug) |
| 6495 | { |
| 6496 | fprintf_unfiltered (gdb_stdlog, "Done expanding symtabs of %s.\n", |
| 6497 | dwarf2_per_objfile->objfile->name); |
| 6498 | } |
| 6499 | } |
| 6500 | |
| 6501 | /* Free all allocated queue entries. This function only releases anything if |
| 6502 | an error was thrown; if the queue was processed then it would have been |
| 6503 | freed as we went along. */ |
| 6504 | |
| 6505 | static void |
| 6506 | dwarf2_release_queue (void *dummy) |
| 6507 | { |
| 6508 | struct dwarf2_queue_item *item, *last; |
| 6509 | |
| 6510 | item = dwarf2_queue; |
| 6511 | while (item) |
| 6512 | { |
| 6513 | /* Anything still marked queued is likely to be in an |
| 6514 | inconsistent state, so discard it. */ |
| 6515 | if (item->per_cu->queued) |
| 6516 | { |
| 6517 | if (item->per_cu->cu != NULL) |
| 6518 | free_one_cached_comp_unit (item->per_cu); |
| 6519 | item->per_cu->queued = 0; |
| 6520 | } |
| 6521 | |
| 6522 | last = item; |
| 6523 | item = item->next; |
| 6524 | xfree (last); |
| 6525 | } |
| 6526 | |
| 6527 | dwarf2_queue = dwarf2_queue_tail = NULL; |
| 6528 | } |
| 6529 | |
| 6530 | /* Read in full symbols for PST, and anything it depends on. */ |
| 6531 | |
| 6532 | static void |
| 6533 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
| 6534 | { |
| 6535 | struct dwarf2_per_cu_data *per_cu; |
| 6536 | int i; |
| 6537 | |
| 6538 | if (pst->readin) |
| 6539 | return; |
| 6540 | |
| 6541 | for (i = 0; i < pst->number_of_dependencies; i++) |
| 6542 | if (!pst->dependencies[i]->readin |
| 6543 | && pst->dependencies[i]->user == NULL) |
| 6544 | { |
| 6545 | /* Inform about additional files that need to be read in. */ |
| 6546 | if (info_verbose) |
| 6547 | { |
| 6548 | /* FIXME: i18n: Need to make this a single string. */ |
| 6549 | fputs_filtered (" ", gdb_stdout); |
| 6550 | wrap_here (""); |
| 6551 | fputs_filtered ("and ", gdb_stdout); |
| 6552 | wrap_here (""); |
| 6553 | printf_filtered ("%s...", pst->dependencies[i]->filename); |
| 6554 | wrap_here (""); /* Flush output. */ |
| 6555 | gdb_flush (gdb_stdout); |
| 6556 | } |
| 6557 | psymtab_to_symtab_1 (pst->dependencies[i]); |
| 6558 | } |
| 6559 | |
| 6560 | per_cu = pst->read_symtab_private; |
| 6561 | |
| 6562 | if (per_cu == NULL) |
| 6563 | { |
| 6564 | /* It's an include file, no symbols to read for it. |
| 6565 | Everything is in the parent symtab. */ |
| 6566 | pst->readin = 1; |
| 6567 | return; |
| 6568 | } |
| 6569 | |
| 6570 | dw2_do_instantiate_symtab (per_cu); |
| 6571 | } |
| 6572 | |
| 6573 | /* Trivial hash function for die_info: the hash value of a DIE |
| 6574 | is its offset in .debug_info for this objfile. */ |
| 6575 | |
| 6576 | static hashval_t |
| 6577 | die_hash (const void *item) |
| 6578 | { |
| 6579 | const struct die_info *die = item; |
| 6580 | |
| 6581 | return die->offset.sect_off; |
| 6582 | } |
| 6583 | |
| 6584 | /* Trivial comparison function for die_info structures: two DIEs |
| 6585 | are equal if they have the same offset. */ |
| 6586 | |
| 6587 | static int |
| 6588 | die_eq (const void *item_lhs, const void *item_rhs) |
| 6589 | { |
| 6590 | const struct die_info *die_lhs = item_lhs; |
| 6591 | const struct die_info *die_rhs = item_rhs; |
| 6592 | |
| 6593 | return die_lhs->offset.sect_off == die_rhs->offset.sect_off; |
| 6594 | } |
| 6595 | |
| 6596 | /* die_reader_func for load_full_comp_unit. |
| 6597 | This is identical to read_signatured_type_reader, |
| 6598 | but is kept separate for now. */ |
| 6599 | |
| 6600 | static void |
| 6601 | load_full_comp_unit_reader (const struct die_reader_specs *reader, |
| 6602 | gdb_byte *info_ptr, |
| 6603 | struct die_info *comp_unit_die, |
| 6604 | int has_children, |
| 6605 | void *data) |
| 6606 | { |
| 6607 | struct dwarf2_cu *cu = reader->cu; |
| 6608 | enum language *language_ptr = data; |
| 6609 | |
| 6610 | gdb_assert (cu->die_hash == NULL); |
| 6611 | cu->die_hash = |
| 6612 | htab_create_alloc_ex (cu->header.length / 12, |
| 6613 | die_hash, |
| 6614 | die_eq, |
| 6615 | NULL, |
| 6616 | &cu->comp_unit_obstack, |
| 6617 | hashtab_obstack_allocate, |
| 6618 | dummy_obstack_deallocate); |
| 6619 | |
| 6620 | if (has_children) |
| 6621 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, |
| 6622 | &info_ptr, comp_unit_die); |
| 6623 | cu->dies = comp_unit_die; |
| 6624 | /* comp_unit_die is not stored in die_hash, no need. */ |
| 6625 | |
| 6626 | /* We try not to read any attributes in this function, because not |
| 6627 | all CUs needed for references have been loaded yet, and symbol |
| 6628 | table processing isn't initialized. But we have to set the CU language, |
| 6629 | or we won't be able to build types correctly. |
| 6630 | Similarly, if we do not read the producer, we can not apply |
| 6631 | producer-specific interpretation. */ |
| 6632 | prepare_one_comp_unit (cu, cu->dies, *language_ptr); |
| 6633 | } |
| 6634 | |
| 6635 | /* Load the DIEs associated with PER_CU into memory. */ |
| 6636 | |
| 6637 | static void |
| 6638 | load_full_comp_unit (struct dwarf2_per_cu_data *this_cu, |
| 6639 | enum language pretend_language) |
| 6640 | { |
| 6641 | gdb_assert (! this_cu->is_debug_types); |
| 6642 | |
| 6643 | init_cutu_and_read_dies (this_cu, NULL, 1, 1, |
| 6644 | load_full_comp_unit_reader, &pretend_language); |
| 6645 | } |
| 6646 | |
| 6647 | /* Add a DIE to the delayed physname list. */ |
| 6648 | |
| 6649 | static void |
| 6650 | add_to_method_list (struct type *type, int fnfield_index, int index, |
| 6651 | const char *name, struct die_info *die, |
| 6652 | struct dwarf2_cu *cu) |
| 6653 | { |
| 6654 | struct delayed_method_info mi; |
| 6655 | mi.type = type; |
| 6656 | mi.fnfield_index = fnfield_index; |
| 6657 | mi.index = index; |
| 6658 | mi.name = name; |
| 6659 | mi.die = die; |
| 6660 | VEC_safe_push (delayed_method_info, cu->method_list, &mi); |
| 6661 | } |
| 6662 | |
| 6663 | /* A cleanup for freeing the delayed method list. */ |
| 6664 | |
| 6665 | static void |
| 6666 | free_delayed_list (void *ptr) |
| 6667 | { |
| 6668 | struct dwarf2_cu *cu = (struct dwarf2_cu *) ptr; |
| 6669 | if (cu->method_list != NULL) |
| 6670 | { |
| 6671 | VEC_free (delayed_method_info, cu->method_list); |
| 6672 | cu->method_list = NULL; |
| 6673 | } |
| 6674 | } |
| 6675 | |
| 6676 | /* Compute the physnames of any methods on the CU's method list. |
| 6677 | |
| 6678 | The computation of method physnames is delayed in order to avoid the |
| 6679 | (bad) condition that one of the method's formal parameters is of an as yet |
| 6680 | incomplete type. */ |
| 6681 | |
| 6682 | static void |
| 6683 | compute_delayed_physnames (struct dwarf2_cu *cu) |
| 6684 | { |
| 6685 | int i; |
| 6686 | struct delayed_method_info *mi; |
| 6687 | for (i = 0; VEC_iterate (delayed_method_info, cu->method_list, i, mi) ; ++i) |
| 6688 | { |
| 6689 | const char *physname; |
| 6690 | struct fn_fieldlist *fn_flp |
| 6691 | = &TYPE_FN_FIELDLIST (mi->type, mi->fnfield_index); |
| 6692 | physname = dwarf2_physname ((char *) mi->name, mi->die, cu); |
| 6693 | fn_flp->fn_fields[mi->index].physname = physname ? physname : ""; |
| 6694 | } |
| 6695 | } |
| 6696 | |
| 6697 | /* Go objects should be embedded in a DW_TAG_module DIE, |
| 6698 | and it's not clear if/how imported objects will appear. |
| 6699 | To keep Go support simple until that's worked out, |
| 6700 | go back through what we've read and create something usable. |
| 6701 | We could do this while processing each DIE, and feels kinda cleaner, |
| 6702 | but that way is more invasive. |
| 6703 | This is to, for example, allow the user to type "p var" or "b main" |
| 6704 | without having to specify the package name, and allow lookups |
| 6705 | of module.object to work in contexts that use the expression |
| 6706 | parser. */ |
| 6707 | |
| 6708 | static void |
| 6709 | fixup_go_packaging (struct dwarf2_cu *cu) |
| 6710 | { |
| 6711 | char *package_name = NULL; |
| 6712 | struct pending *list; |
| 6713 | int i; |
| 6714 | |
| 6715 | for (list = global_symbols; list != NULL; list = list->next) |
| 6716 | { |
| 6717 | for (i = 0; i < list->nsyms; ++i) |
| 6718 | { |
| 6719 | struct symbol *sym = list->symbol[i]; |
| 6720 | |
| 6721 | if (SYMBOL_LANGUAGE (sym) == language_go |
| 6722 | && SYMBOL_CLASS (sym) == LOC_BLOCK) |
| 6723 | { |
| 6724 | char *this_package_name = go_symbol_package_name (sym); |
| 6725 | |
| 6726 | if (this_package_name == NULL) |
| 6727 | continue; |
| 6728 | if (package_name == NULL) |
| 6729 | package_name = this_package_name; |
| 6730 | else |
| 6731 | { |
| 6732 | if (strcmp (package_name, this_package_name) != 0) |
| 6733 | complaint (&symfile_complaints, |
| 6734 | _("Symtab %s has objects from two different Go packages: %s and %s"), |
| 6735 | (SYMBOL_SYMTAB (sym) |
| 6736 | ? SYMBOL_SYMTAB (sym)->filename |
| 6737 | : cu->objfile->name), |
| 6738 | this_package_name, package_name); |
| 6739 | xfree (this_package_name); |
| 6740 | } |
| 6741 | } |
| 6742 | } |
| 6743 | } |
| 6744 | |
| 6745 | if (package_name != NULL) |
| 6746 | { |
| 6747 | struct objfile *objfile = cu->objfile; |
| 6748 | struct type *type = init_type (TYPE_CODE_MODULE, 0, 0, |
| 6749 | package_name, objfile); |
| 6750 | struct symbol *sym; |
| 6751 | |
| 6752 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 6753 | |
| 6754 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); |
| 6755 | SYMBOL_SET_LANGUAGE (sym, language_go); |
| 6756 | SYMBOL_SET_NAMES (sym, package_name, strlen (package_name), 1, objfile); |
| 6757 | /* This is not VAR_DOMAIN because we want a way to ensure a lookup of, |
| 6758 | e.g., "main" finds the "main" module and not C's main(). */ |
| 6759 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
| 6760 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 6761 | SYMBOL_TYPE (sym) = type; |
| 6762 | |
| 6763 | add_symbol_to_list (sym, &global_symbols); |
| 6764 | |
| 6765 | xfree (package_name); |
| 6766 | } |
| 6767 | } |
| 6768 | |
| 6769 | static void compute_symtab_includes (struct dwarf2_per_cu_data *per_cu); |
| 6770 | |
| 6771 | /* Return the symtab for PER_CU. This works properly regardless of |
| 6772 | whether we're using the index or psymtabs. */ |
| 6773 | |
| 6774 | static struct symtab * |
| 6775 | get_symtab (struct dwarf2_per_cu_data *per_cu) |
| 6776 | { |
| 6777 | return (dwarf2_per_objfile->using_index |
| 6778 | ? per_cu->v.quick->symtab |
| 6779 | : per_cu->v.psymtab->symtab); |
| 6780 | } |
| 6781 | |
| 6782 | /* A helper function for computing the list of all symbol tables |
| 6783 | included by PER_CU. */ |
| 6784 | |
| 6785 | static void |
| 6786 | recursively_compute_inclusions (VEC (dwarf2_per_cu_ptr) **result, |
| 6787 | htab_t all_children, |
| 6788 | struct dwarf2_per_cu_data *per_cu) |
| 6789 | { |
| 6790 | void **slot; |
| 6791 | int ix; |
| 6792 | struct dwarf2_per_cu_data *iter; |
| 6793 | |
| 6794 | slot = htab_find_slot (all_children, per_cu, INSERT); |
| 6795 | if (*slot != NULL) |
| 6796 | { |
| 6797 | /* This inclusion and its children have been processed. */ |
| 6798 | return; |
| 6799 | } |
| 6800 | |
| 6801 | *slot = per_cu; |
| 6802 | /* Only add a CU if it has a symbol table. */ |
| 6803 | if (get_symtab (per_cu) != NULL) |
| 6804 | VEC_safe_push (dwarf2_per_cu_ptr, *result, per_cu); |
| 6805 | |
| 6806 | for (ix = 0; |
| 6807 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->s.imported_symtabs, ix, iter); |
| 6808 | ++ix) |
| 6809 | recursively_compute_inclusions (result, all_children, iter); |
| 6810 | } |
| 6811 | |
| 6812 | /* Compute the symtab 'includes' fields for the symtab related to |
| 6813 | PER_CU. */ |
| 6814 | |
| 6815 | static void |
| 6816 | compute_symtab_includes (struct dwarf2_per_cu_data *per_cu) |
| 6817 | { |
| 6818 | gdb_assert (! per_cu->is_debug_types); |
| 6819 | |
| 6820 | if (!VEC_empty (dwarf2_per_cu_ptr, per_cu->s.imported_symtabs)) |
| 6821 | { |
| 6822 | int ix, len; |
| 6823 | struct dwarf2_per_cu_data *iter; |
| 6824 | VEC (dwarf2_per_cu_ptr) *result_children = NULL; |
| 6825 | htab_t all_children; |
| 6826 | struct symtab *symtab = get_symtab (per_cu); |
| 6827 | |
| 6828 | /* If we don't have a symtab, we can just skip this case. */ |
| 6829 | if (symtab == NULL) |
| 6830 | return; |
| 6831 | |
| 6832 | all_children = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
| 6833 | NULL, xcalloc, xfree); |
| 6834 | |
| 6835 | for (ix = 0; |
| 6836 | VEC_iterate (dwarf2_per_cu_ptr, per_cu->s.imported_symtabs, |
| 6837 | ix, iter); |
| 6838 | ++ix) |
| 6839 | recursively_compute_inclusions (&result_children, all_children, iter); |
| 6840 | |
| 6841 | /* Now we have a transitive closure of all the included CUs, so |
| 6842 | we can convert it to a list of symtabs. */ |
| 6843 | len = VEC_length (dwarf2_per_cu_ptr, result_children); |
| 6844 | symtab->includes |
| 6845 | = obstack_alloc (&dwarf2_per_objfile->objfile->objfile_obstack, |
| 6846 | (len + 1) * sizeof (struct symtab *)); |
| 6847 | for (ix = 0; |
| 6848 | VEC_iterate (dwarf2_per_cu_ptr, result_children, ix, iter); |
| 6849 | ++ix) |
| 6850 | symtab->includes[ix] = get_symtab (iter); |
| 6851 | symtab->includes[len] = NULL; |
| 6852 | |
| 6853 | VEC_free (dwarf2_per_cu_ptr, result_children); |
| 6854 | htab_delete (all_children); |
| 6855 | } |
| 6856 | } |
| 6857 | |
| 6858 | /* Compute the 'includes' field for the symtabs of all the CUs we just |
| 6859 | read. */ |
| 6860 | |
| 6861 | static void |
| 6862 | process_cu_includes (void) |
| 6863 | { |
| 6864 | int ix; |
| 6865 | struct dwarf2_per_cu_data *iter; |
| 6866 | |
| 6867 | for (ix = 0; |
| 6868 | VEC_iterate (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, |
| 6869 | ix, iter); |
| 6870 | ++ix) |
| 6871 | { |
| 6872 | if (! iter->is_debug_types) |
| 6873 | compute_symtab_includes (iter); |
| 6874 | } |
| 6875 | |
| 6876 | VEC_free (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus); |
| 6877 | } |
| 6878 | |
| 6879 | /* Generate full symbol information for PER_CU, whose DIEs have |
| 6880 | already been loaded into memory. */ |
| 6881 | |
| 6882 | static void |
| 6883 | process_full_comp_unit (struct dwarf2_per_cu_data *per_cu, |
| 6884 | enum language pretend_language) |
| 6885 | { |
| 6886 | struct dwarf2_cu *cu = per_cu->cu; |
| 6887 | struct objfile *objfile = per_cu->objfile; |
| 6888 | CORE_ADDR lowpc, highpc; |
| 6889 | struct symtab *symtab; |
| 6890 | struct cleanup *back_to, *delayed_list_cleanup; |
| 6891 | CORE_ADDR baseaddr; |
| 6892 | struct block *static_block; |
| 6893 | |
| 6894 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 6895 | |
| 6896 | buildsym_init (); |
| 6897 | back_to = make_cleanup (really_free_pendings, NULL); |
| 6898 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
| 6899 | |
| 6900 | cu->list_in_scope = &file_symbols; |
| 6901 | |
| 6902 | cu->language = pretend_language; |
| 6903 | cu->language_defn = language_def (cu->language); |
| 6904 | |
| 6905 | /* Do line number decoding in read_file_scope () */ |
| 6906 | process_die (cu->dies, cu); |
| 6907 | |
| 6908 | /* For now fudge the Go package. */ |
| 6909 | if (cu->language == language_go) |
| 6910 | fixup_go_packaging (cu); |
| 6911 | |
| 6912 | /* Now that we have processed all the DIEs in the CU, all the types |
| 6913 | should be complete, and it should now be safe to compute all of the |
| 6914 | physnames. */ |
| 6915 | compute_delayed_physnames (cu); |
| 6916 | do_cleanups (delayed_list_cleanup); |
| 6917 | |
| 6918 | /* Some compilers don't define a DW_AT_high_pc attribute for the |
| 6919 | compilation unit. If the DW_AT_high_pc is missing, synthesize |
| 6920 | it, by scanning the DIE's below the compilation unit. */ |
| 6921 | get_scope_pc_bounds (cu->dies, &lowpc, &highpc, cu); |
| 6922 | |
| 6923 | static_block |
| 6924 | = end_symtab_get_static_block (highpc + baseaddr, objfile, 0, |
| 6925 | per_cu->s.imported_symtabs != NULL); |
| 6926 | |
| 6927 | /* If the comp unit has DW_AT_ranges, it may have discontiguous ranges. |
| 6928 | Also, DW_AT_ranges may record ranges not belonging to any child DIEs |
| 6929 | (such as virtual method tables). Record the ranges in STATIC_BLOCK's |
| 6930 | addrmap to help ensure it has an accurate map of pc values belonging to |
| 6931 | this comp unit. */ |
| 6932 | dwarf2_record_block_ranges (cu->dies, static_block, baseaddr, cu); |
| 6933 | |
| 6934 | symtab = end_symtab_from_static_block (static_block, objfile, |
| 6935 | SECT_OFF_TEXT (objfile), 0); |
| 6936 | |
| 6937 | if (symtab != NULL) |
| 6938 | { |
| 6939 | int gcc_4_minor = producer_is_gcc_ge_4 (cu->producer); |
| 6940 | |
| 6941 | /* Set symtab language to language from DW_AT_language. If the |
| 6942 | compilation is from a C file generated by language preprocessors, do |
| 6943 | not set the language if it was already deduced by start_subfile. */ |
| 6944 | if (!(cu->language == language_c && symtab->language != language_c)) |
| 6945 | symtab->language = cu->language; |
| 6946 | |
| 6947 | /* GCC-4.0 has started to support -fvar-tracking. GCC-3.x still can |
| 6948 | produce DW_AT_location with location lists but it can be possibly |
| 6949 | invalid without -fvar-tracking. Still up to GCC-4.4.x incl. 4.4.0 |
| 6950 | there were bugs in prologue debug info, fixed later in GCC-4.5 |
| 6951 | by "unwind info for epilogues" patch (which is not directly related). |
| 6952 | |
| 6953 | For -gdwarf-4 type units LOCATIONS_VALID indication is fortunately not |
| 6954 | needed, it would be wrong due to missing DW_AT_producer there. |
| 6955 | |
| 6956 | Still one can confuse GDB by using non-standard GCC compilation |
| 6957 | options - this waits on GCC PR other/32998 (-frecord-gcc-switches). |
| 6958 | */ |
| 6959 | if (cu->has_loclist && gcc_4_minor >= 5) |
| 6960 | symtab->locations_valid = 1; |
| 6961 | |
| 6962 | if (gcc_4_minor >= 5) |
| 6963 | symtab->epilogue_unwind_valid = 1; |
| 6964 | |
| 6965 | symtab->call_site_htab = cu->call_site_htab; |
| 6966 | } |
| 6967 | |
| 6968 | if (dwarf2_per_objfile->using_index) |
| 6969 | per_cu->v.quick->symtab = symtab; |
| 6970 | else |
| 6971 | { |
| 6972 | struct partial_symtab *pst = per_cu->v.psymtab; |
| 6973 | pst->symtab = symtab; |
| 6974 | pst->readin = 1; |
| 6975 | } |
| 6976 | |
| 6977 | /* Push it for inclusion processing later. */ |
| 6978 | VEC_safe_push (dwarf2_per_cu_ptr, dwarf2_per_objfile->just_read_cus, per_cu); |
| 6979 | |
| 6980 | do_cleanups (back_to); |
| 6981 | } |
| 6982 | |
| 6983 | /* Generate full symbol information for type unit PER_CU, whose DIEs have |
| 6984 | already been loaded into memory. */ |
| 6985 | |
| 6986 | static void |
| 6987 | process_full_type_unit (struct dwarf2_per_cu_data *per_cu, |
| 6988 | enum language pretend_language) |
| 6989 | { |
| 6990 | struct dwarf2_cu *cu = per_cu->cu; |
| 6991 | struct objfile *objfile = per_cu->objfile; |
| 6992 | struct symtab *symtab; |
| 6993 | struct cleanup *back_to, *delayed_list_cleanup; |
| 6994 | |
| 6995 | buildsym_init (); |
| 6996 | back_to = make_cleanup (really_free_pendings, NULL); |
| 6997 | delayed_list_cleanup = make_cleanup (free_delayed_list, cu); |
| 6998 | |
| 6999 | cu->list_in_scope = &file_symbols; |
| 7000 | |
| 7001 | cu->language = pretend_language; |
| 7002 | cu->language_defn = language_def (cu->language); |
| 7003 | |
| 7004 | /* The symbol tables are set up in read_type_unit_scope. */ |
| 7005 | process_die (cu->dies, cu); |
| 7006 | |
| 7007 | /* For now fudge the Go package. */ |
| 7008 | if (cu->language == language_go) |
| 7009 | fixup_go_packaging (cu); |
| 7010 | |
| 7011 | /* Now that we have processed all the DIEs in the CU, all the types |
| 7012 | should be complete, and it should now be safe to compute all of the |
| 7013 | physnames. */ |
| 7014 | compute_delayed_physnames (cu); |
| 7015 | do_cleanups (delayed_list_cleanup); |
| 7016 | |
| 7017 | /* TUs share symbol tables. |
| 7018 | If this is the first TU to use this symtab, complete the construction |
| 7019 | of it with end_expandable_symtab. Otherwise, complete the addition of |
| 7020 | this TU's symbols to the existing symtab. */ |
| 7021 | if (per_cu->s.type_unit_group->primary_symtab == NULL) |
| 7022 | { |
| 7023 | symtab = end_expandable_symtab (0, objfile, SECT_OFF_TEXT (objfile)); |
| 7024 | per_cu->s.type_unit_group->primary_symtab = symtab; |
| 7025 | |
| 7026 | if (symtab != NULL) |
| 7027 | { |
| 7028 | /* Set symtab language to language from DW_AT_language. If the |
| 7029 | compilation is from a C file generated by language preprocessors, |
| 7030 | do not set the language if it was already deduced by |
| 7031 | start_subfile. */ |
| 7032 | if (!(cu->language == language_c && symtab->language != language_c)) |
| 7033 | symtab->language = cu->language; |
| 7034 | } |
| 7035 | } |
| 7036 | else |
| 7037 | { |
| 7038 | augment_type_symtab (objfile, |
| 7039 | per_cu->s.type_unit_group->primary_symtab); |
| 7040 | symtab = per_cu->s.type_unit_group->primary_symtab; |
| 7041 | } |
| 7042 | |
| 7043 | if (dwarf2_per_objfile->using_index) |
| 7044 | per_cu->v.quick->symtab = symtab; |
| 7045 | else |
| 7046 | { |
| 7047 | struct partial_symtab *pst = per_cu->v.psymtab; |
| 7048 | pst->symtab = symtab; |
| 7049 | pst->readin = 1; |
| 7050 | } |
| 7051 | |
| 7052 | do_cleanups (back_to); |
| 7053 | } |
| 7054 | |
| 7055 | /* Process an imported unit DIE. */ |
| 7056 | |
| 7057 | static void |
| 7058 | process_imported_unit_die (struct die_info *die, struct dwarf2_cu *cu) |
| 7059 | { |
| 7060 | struct attribute *attr; |
| 7061 | |
| 7062 | /* For now we don't handle imported units in type units. */ |
| 7063 | if (cu->per_cu->is_debug_types) |
| 7064 | { |
| 7065 | error (_("Dwarf Error: DW_TAG_imported_unit is not" |
| 7066 | " supported in type units [in module %s]"), |
| 7067 | cu->objfile->name); |
| 7068 | } |
| 7069 | |
| 7070 | attr = dwarf2_attr (die, DW_AT_import, cu); |
| 7071 | if (attr != NULL) |
| 7072 | { |
| 7073 | struct dwarf2_per_cu_data *per_cu; |
| 7074 | struct symtab *imported_symtab; |
| 7075 | sect_offset offset; |
| 7076 | int is_dwz; |
| 7077 | |
| 7078 | offset = dwarf2_get_ref_die_offset (attr); |
| 7079 | is_dwz = (attr->form == DW_FORM_GNU_ref_alt || cu->per_cu->is_dwz); |
| 7080 | per_cu = dwarf2_find_containing_comp_unit (offset, is_dwz, cu->objfile); |
| 7081 | |
| 7082 | /* Queue the unit, if needed. */ |
| 7083 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) |
| 7084 | load_full_comp_unit (per_cu, cu->language); |
| 7085 | |
| 7086 | VEC_safe_push (dwarf2_per_cu_ptr, cu->per_cu->s.imported_symtabs, |
| 7087 | per_cu); |
| 7088 | } |
| 7089 | } |
| 7090 | |
| 7091 | /* Process a die and its children. */ |
| 7092 | |
| 7093 | static void |
| 7094 | process_die (struct die_info *die, struct dwarf2_cu *cu) |
| 7095 | { |
| 7096 | switch (die->tag) |
| 7097 | { |
| 7098 | case DW_TAG_padding: |
| 7099 | break; |
| 7100 | case DW_TAG_compile_unit: |
| 7101 | case DW_TAG_partial_unit: |
| 7102 | read_file_scope (die, cu); |
| 7103 | break; |
| 7104 | case DW_TAG_type_unit: |
| 7105 | read_type_unit_scope (die, cu); |
| 7106 | break; |
| 7107 | case DW_TAG_subprogram: |
| 7108 | case DW_TAG_inlined_subroutine: |
| 7109 | read_func_scope (die, cu); |
| 7110 | break; |
| 7111 | case DW_TAG_lexical_block: |
| 7112 | case DW_TAG_try_block: |
| 7113 | case DW_TAG_catch_block: |
| 7114 | read_lexical_block_scope (die, cu); |
| 7115 | break; |
| 7116 | case DW_TAG_GNU_call_site: |
| 7117 | read_call_site_scope (die, cu); |
| 7118 | break; |
| 7119 | case DW_TAG_class_type: |
| 7120 | case DW_TAG_interface_type: |
| 7121 | case DW_TAG_structure_type: |
| 7122 | case DW_TAG_union_type: |
| 7123 | process_structure_scope (die, cu); |
| 7124 | break; |
| 7125 | case DW_TAG_enumeration_type: |
| 7126 | process_enumeration_scope (die, cu); |
| 7127 | break; |
| 7128 | |
| 7129 | /* These dies have a type, but processing them does not create |
| 7130 | a symbol or recurse to process the children. Therefore we can |
| 7131 | read them on-demand through read_type_die. */ |
| 7132 | case DW_TAG_subroutine_type: |
| 7133 | case DW_TAG_set_type: |
| 7134 | case DW_TAG_array_type: |
| 7135 | case DW_TAG_pointer_type: |
| 7136 | case DW_TAG_ptr_to_member_type: |
| 7137 | case DW_TAG_reference_type: |
| 7138 | case DW_TAG_string_type: |
| 7139 | break; |
| 7140 | |
| 7141 | case DW_TAG_base_type: |
| 7142 | case DW_TAG_subrange_type: |
| 7143 | case DW_TAG_typedef: |
| 7144 | /* Add a typedef symbol for the type definition, if it has a |
| 7145 | DW_AT_name. */ |
| 7146 | new_symbol (die, read_type_die (die, cu), cu); |
| 7147 | break; |
| 7148 | case DW_TAG_common_block: |
| 7149 | read_common_block (die, cu); |
| 7150 | break; |
| 7151 | case DW_TAG_common_inclusion: |
| 7152 | break; |
| 7153 | case DW_TAG_namespace: |
| 7154 | processing_has_namespace_info = 1; |
| 7155 | read_namespace (die, cu); |
| 7156 | break; |
| 7157 | case DW_TAG_module: |
| 7158 | processing_has_namespace_info = 1; |
| 7159 | read_module (die, cu); |
| 7160 | break; |
| 7161 | case DW_TAG_imported_declaration: |
| 7162 | case DW_TAG_imported_module: |
| 7163 | processing_has_namespace_info = 1; |
| 7164 | if (die->child != NULL && (die->tag == DW_TAG_imported_declaration |
| 7165 | || cu->language != language_fortran)) |
| 7166 | complaint (&symfile_complaints, _("Tag '%s' has unexpected children"), |
| 7167 | dwarf_tag_name (die->tag)); |
| 7168 | read_import_statement (die, cu); |
| 7169 | break; |
| 7170 | |
| 7171 | case DW_TAG_imported_unit: |
| 7172 | process_imported_unit_die (die, cu); |
| 7173 | break; |
| 7174 | |
| 7175 | default: |
| 7176 | new_symbol (die, NULL, cu); |
| 7177 | break; |
| 7178 | } |
| 7179 | } |
| 7180 | |
| 7181 | /* A helper function for dwarf2_compute_name which determines whether DIE |
| 7182 | needs to have the name of the scope prepended to the name listed in the |
| 7183 | die. */ |
| 7184 | |
| 7185 | static int |
| 7186 | die_needs_namespace (struct die_info *die, struct dwarf2_cu *cu) |
| 7187 | { |
| 7188 | struct attribute *attr; |
| 7189 | |
| 7190 | switch (die->tag) |
| 7191 | { |
| 7192 | case DW_TAG_namespace: |
| 7193 | case DW_TAG_typedef: |
| 7194 | case DW_TAG_class_type: |
| 7195 | case DW_TAG_interface_type: |
| 7196 | case DW_TAG_structure_type: |
| 7197 | case DW_TAG_union_type: |
| 7198 | case DW_TAG_enumeration_type: |
| 7199 | case DW_TAG_enumerator: |
| 7200 | case DW_TAG_subprogram: |
| 7201 | case DW_TAG_member: |
| 7202 | return 1; |
| 7203 | |
| 7204 | case DW_TAG_variable: |
| 7205 | case DW_TAG_constant: |
| 7206 | /* We only need to prefix "globally" visible variables. These include |
| 7207 | any variable marked with DW_AT_external or any variable that |
| 7208 | lives in a namespace. [Variables in anonymous namespaces |
| 7209 | require prefixing, but they are not DW_AT_external.] */ |
| 7210 | |
| 7211 | if (dwarf2_attr (die, DW_AT_specification, cu)) |
| 7212 | { |
| 7213 | struct dwarf2_cu *spec_cu = cu; |
| 7214 | |
| 7215 | return die_needs_namespace (die_specification (die, &spec_cu), |
| 7216 | spec_cu); |
| 7217 | } |
| 7218 | |
| 7219 | attr = dwarf2_attr (die, DW_AT_external, cu); |
| 7220 | if (attr == NULL && die->parent->tag != DW_TAG_namespace |
| 7221 | && die->parent->tag != DW_TAG_module) |
| 7222 | return 0; |
| 7223 | /* A variable in a lexical block of some kind does not need a |
| 7224 | namespace, even though in C++ such variables may be external |
| 7225 | and have a mangled name. */ |
| 7226 | if (die->parent->tag == DW_TAG_lexical_block |
| 7227 | || die->parent->tag == DW_TAG_try_block |
| 7228 | || die->parent->tag == DW_TAG_catch_block |
| 7229 | || die->parent->tag == DW_TAG_subprogram) |
| 7230 | return 0; |
| 7231 | return 1; |
| 7232 | |
| 7233 | default: |
| 7234 | return 0; |
| 7235 | } |
| 7236 | } |
| 7237 | |
| 7238 | /* Retrieve the last character from a mem_file. */ |
| 7239 | |
| 7240 | static void |
| 7241 | do_ui_file_peek_last (void *object, const char *buffer, long length) |
| 7242 | { |
| 7243 | char *last_char_p = (char *) object; |
| 7244 | |
| 7245 | if (length > 0) |
| 7246 | *last_char_p = buffer[length - 1]; |
| 7247 | } |
| 7248 | |
| 7249 | /* Compute the fully qualified name of DIE in CU. If PHYSNAME is nonzero, |
| 7250 | compute the physname for the object, which include a method's: |
| 7251 | - formal parameters (C++/Java), |
| 7252 | - receiver type (Go), |
| 7253 | - return type (Java). |
| 7254 | |
| 7255 | The term "physname" is a bit confusing. |
| 7256 | For C++, for example, it is the demangled name. |
| 7257 | For Go, for example, it's the mangled name. |
| 7258 | |
| 7259 | For Ada, return the DIE's linkage name rather than the fully qualified |
| 7260 | name. PHYSNAME is ignored.. |
| 7261 | |
| 7262 | The result is allocated on the objfile_obstack and canonicalized. */ |
| 7263 | |
| 7264 | static const char * |
| 7265 | dwarf2_compute_name (char *name, struct die_info *die, struct dwarf2_cu *cu, |
| 7266 | int physname) |
| 7267 | { |
| 7268 | struct objfile *objfile = cu->objfile; |
| 7269 | |
| 7270 | if (name == NULL) |
| 7271 | name = dwarf2_name (die, cu); |
| 7272 | |
| 7273 | /* For Fortran GDB prefers DW_AT_*linkage_name if present but otherwise |
| 7274 | compute it by typename_concat inside GDB. */ |
| 7275 | if (cu->language == language_ada |
| 7276 | || (cu->language == language_fortran && physname)) |
| 7277 | { |
| 7278 | /* For Ada unit, we prefer the linkage name over the name, as |
| 7279 | the former contains the exported name, which the user expects |
| 7280 | to be able to reference. Ideally, we want the user to be able |
| 7281 | to reference this entity using either natural or linkage name, |
| 7282 | but we haven't started looking at this enhancement yet. */ |
| 7283 | struct attribute *attr; |
| 7284 | |
| 7285 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 7286 | if (attr == NULL) |
| 7287 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 7288 | if (attr && DW_STRING (attr)) |
| 7289 | return DW_STRING (attr); |
| 7290 | } |
| 7291 | |
| 7292 | /* These are the only languages we know how to qualify names in. */ |
| 7293 | if (name != NULL |
| 7294 | && (cu->language == language_cplus || cu->language == language_java |
| 7295 | || cu->language == language_fortran)) |
| 7296 | { |
| 7297 | if (die_needs_namespace (die, cu)) |
| 7298 | { |
| 7299 | long length; |
| 7300 | const char *prefix; |
| 7301 | struct ui_file *buf; |
| 7302 | |
| 7303 | prefix = determine_prefix (die, cu); |
| 7304 | buf = mem_fileopen (); |
| 7305 | if (*prefix != '\0') |
| 7306 | { |
| 7307 | char *prefixed_name = typename_concat (NULL, prefix, name, |
| 7308 | physname, cu); |
| 7309 | |
| 7310 | fputs_unfiltered (prefixed_name, buf); |
| 7311 | xfree (prefixed_name); |
| 7312 | } |
| 7313 | else |
| 7314 | fputs_unfiltered (name, buf); |
| 7315 | |
| 7316 | /* Template parameters may be specified in the DIE's DW_AT_name, or |
| 7317 | as children with DW_TAG_template_type_param or |
| 7318 | DW_TAG_value_type_param. If the latter, add them to the name |
| 7319 | here. If the name already has template parameters, then |
| 7320 | skip this step; some versions of GCC emit both, and |
| 7321 | it is more efficient to use the pre-computed name. |
| 7322 | |
| 7323 | Something to keep in mind about this process: it is very |
| 7324 | unlikely, or in some cases downright impossible, to produce |
| 7325 | something that will match the mangled name of a function. |
| 7326 | If the definition of the function has the same debug info, |
| 7327 | we should be able to match up with it anyway. But fallbacks |
| 7328 | using the minimal symbol, for instance to find a method |
| 7329 | implemented in a stripped copy of libstdc++, will not work. |
| 7330 | If we do not have debug info for the definition, we will have to |
| 7331 | match them up some other way. |
| 7332 | |
| 7333 | When we do name matching there is a related problem with function |
| 7334 | templates; two instantiated function templates are allowed to |
| 7335 | differ only by their return types, which we do not add here. */ |
| 7336 | |
| 7337 | if (cu->language == language_cplus && strchr (name, '<') == NULL) |
| 7338 | { |
| 7339 | struct attribute *attr; |
| 7340 | struct die_info *child; |
| 7341 | int first = 1; |
| 7342 | |
| 7343 | die->building_fullname = 1; |
| 7344 | |
| 7345 | for (child = die->child; child != NULL; child = child->sibling) |
| 7346 | { |
| 7347 | struct type *type; |
| 7348 | LONGEST value; |
| 7349 | gdb_byte *bytes; |
| 7350 | struct dwarf2_locexpr_baton *baton; |
| 7351 | struct value *v; |
| 7352 | |
| 7353 | if (child->tag != DW_TAG_template_type_param |
| 7354 | && child->tag != DW_TAG_template_value_param) |
| 7355 | continue; |
| 7356 | |
| 7357 | if (first) |
| 7358 | { |
| 7359 | fputs_unfiltered ("<", buf); |
| 7360 | first = 0; |
| 7361 | } |
| 7362 | else |
| 7363 | fputs_unfiltered (", ", buf); |
| 7364 | |
| 7365 | attr = dwarf2_attr (child, DW_AT_type, cu); |
| 7366 | if (attr == NULL) |
| 7367 | { |
| 7368 | complaint (&symfile_complaints, |
| 7369 | _("template parameter missing DW_AT_type")); |
| 7370 | fputs_unfiltered ("UNKNOWN_TYPE", buf); |
| 7371 | continue; |
| 7372 | } |
| 7373 | type = die_type (child, cu); |
| 7374 | |
| 7375 | if (child->tag == DW_TAG_template_type_param) |
| 7376 | { |
| 7377 | c_print_type (type, "", buf, -1, 0, &type_print_raw_options); |
| 7378 | continue; |
| 7379 | } |
| 7380 | |
| 7381 | attr = dwarf2_attr (child, DW_AT_const_value, cu); |
| 7382 | if (attr == NULL) |
| 7383 | { |
| 7384 | complaint (&symfile_complaints, |
| 7385 | _("template parameter missing " |
| 7386 | "DW_AT_const_value")); |
| 7387 | fputs_unfiltered ("UNKNOWN_VALUE", buf); |
| 7388 | continue; |
| 7389 | } |
| 7390 | |
| 7391 | dwarf2_const_value_attr (attr, type, name, |
| 7392 | &cu->comp_unit_obstack, cu, |
| 7393 | &value, &bytes, &baton); |
| 7394 | |
| 7395 | if (TYPE_NOSIGN (type)) |
| 7396 | /* GDB prints characters as NUMBER 'CHAR'. If that's |
| 7397 | changed, this can use value_print instead. */ |
| 7398 | c_printchar (value, type, buf); |
| 7399 | else |
| 7400 | { |
| 7401 | struct value_print_options opts; |
| 7402 | |
| 7403 | if (baton != NULL) |
| 7404 | v = dwarf2_evaluate_loc_desc (type, NULL, |
| 7405 | baton->data, |
| 7406 | baton->size, |
| 7407 | baton->per_cu); |
| 7408 | else if (bytes != NULL) |
| 7409 | { |
| 7410 | v = allocate_value (type); |
| 7411 | memcpy (value_contents_writeable (v), bytes, |
| 7412 | TYPE_LENGTH (type)); |
| 7413 | } |
| 7414 | else |
| 7415 | v = value_from_longest (type, value); |
| 7416 | |
| 7417 | /* Specify decimal so that we do not depend on |
| 7418 | the radix. */ |
| 7419 | get_formatted_print_options (&opts, 'd'); |
| 7420 | opts.raw = 1; |
| 7421 | value_print (v, buf, &opts); |
| 7422 | release_value (v); |
| 7423 | value_free (v); |
| 7424 | } |
| 7425 | } |
| 7426 | |
| 7427 | die->building_fullname = 0; |
| 7428 | |
| 7429 | if (!first) |
| 7430 | { |
| 7431 | /* Close the argument list, with a space if necessary |
| 7432 | (nested templates). */ |
| 7433 | char last_char = '\0'; |
| 7434 | ui_file_put (buf, do_ui_file_peek_last, &last_char); |
| 7435 | if (last_char == '>') |
| 7436 | fputs_unfiltered (" >", buf); |
| 7437 | else |
| 7438 | fputs_unfiltered (">", buf); |
| 7439 | } |
| 7440 | } |
| 7441 | |
| 7442 | /* For Java and C++ methods, append formal parameter type |
| 7443 | information, if PHYSNAME. */ |
| 7444 | |
| 7445 | if (physname && die->tag == DW_TAG_subprogram |
| 7446 | && (cu->language == language_cplus |
| 7447 | || cu->language == language_java)) |
| 7448 | { |
| 7449 | struct type *type = read_type_die (die, cu); |
| 7450 | |
| 7451 | c_type_print_args (type, buf, 1, cu->language, |
| 7452 | &type_print_raw_options); |
| 7453 | |
| 7454 | if (cu->language == language_java) |
| 7455 | { |
| 7456 | /* For java, we must append the return type to method |
| 7457 | names. */ |
| 7458 | if (die->tag == DW_TAG_subprogram) |
| 7459 | java_print_type (TYPE_TARGET_TYPE (type), "", buf, |
| 7460 | 0, 0, &type_print_raw_options); |
| 7461 | } |
| 7462 | else if (cu->language == language_cplus) |
| 7463 | { |
| 7464 | /* Assume that an artificial first parameter is |
| 7465 | "this", but do not crash if it is not. RealView |
| 7466 | marks unnamed (and thus unused) parameters as |
| 7467 | artificial; there is no way to differentiate |
| 7468 | the two cases. */ |
| 7469 | if (TYPE_NFIELDS (type) > 0 |
| 7470 | && TYPE_FIELD_ARTIFICIAL (type, 0) |
| 7471 | && TYPE_CODE (TYPE_FIELD_TYPE (type, 0)) == TYPE_CODE_PTR |
| 7472 | && TYPE_CONST (TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (type, |
| 7473 | 0)))) |
| 7474 | fputs_unfiltered (" const", buf); |
| 7475 | } |
| 7476 | } |
| 7477 | |
| 7478 | name = ui_file_obsavestring (buf, &objfile->objfile_obstack, |
| 7479 | &length); |
| 7480 | ui_file_delete (buf); |
| 7481 | |
| 7482 | if (cu->language == language_cplus) |
| 7483 | { |
| 7484 | char *cname |
| 7485 | = dwarf2_canonicalize_name (name, cu, |
| 7486 | &objfile->objfile_obstack); |
| 7487 | |
| 7488 | if (cname != NULL) |
| 7489 | name = cname; |
| 7490 | } |
| 7491 | } |
| 7492 | } |
| 7493 | |
| 7494 | return name; |
| 7495 | } |
| 7496 | |
| 7497 | /* Return the fully qualified name of DIE, based on its DW_AT_name. |
| 7498 | If scope qualifiers are appropriate they will be added. The result |
| 7499 | will be allocated on the objfile_obstack, or NULL if the DIE does |
| 7500 | not have a name. NAME may either be from a previous call to |
| 7501 | dwarf2_name or NULL. |
| 7502 | |
| 7503 | The output string will be canonicalized (if C++/Java). */ |
| 7504 | |
| 7505 | static const char * |
| 7506 | dwarf2_full_name (char *name, struct die_info *die, struct dwarf2_cu *cu) |
| 7507 | { |
| 7508 | return dwarf2_compute_name (name, die, cu, 0); |
| 7509 | } |
| 7510 | |
| 7511 | /* Construct a physname for the given DIE in CU. NAME may either be |
| 7512 | from a previous call to dwarf2_name or NULL. The result will be |
| 7513 | allocated on the objfile_objstack or NULL if the DIE does not have a |
| 7514 | name. |
| 7515 | |
| 7516 | The output string will be canonicalized (if C++/Java). */ |
| 7517 | |
| 7518 | static const char * |
| 7519 | dwarf2_physname (char *name, struct die_info *die, struct dwarf2_cu *cu) |
| 7520 | { |
| 7521 | struct objfile *objfile = cu->objfile; |
| 7522 | struct attribute *attr; |
| 7523 | const char *retval, *mangled = NULL, *canon = NULL; |
| 7524 | struct cleanup *back_to; |
| 7525 | int need_copy = 1; |
| 7526 | |
| 7527 | /* In this case dwarf2_compute_name is just a shortcut not building anything |
| 7528 | on its own. */ |
| 7529 | if (!die_needs_namespace (die, cu)) |
| 7530 | return dwarf2_compute_name (name, die, cu, 1); |
| 7531 | |
| 7532 | back_to = make_cleanup (null_cleanup, NULL); |
| 7533 | |
| 7534 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 7535 | if (!attr) |
| 7536 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 7537 | |
| 7538 | /* DW_AT_linkage_name is missing in some cases - depend on what GDB |
| 7539 | has computed. */ |
| 7540 | if (attr && DW_STRING (attr)) |
| 7541 | { |
| 7542 | char *demangled; |
| 7543 | |
| 7544 | mangled = DW_STRING (attr); |
| 7545 | |
| 7546 | /* Use DMGL_RET_DROP for C++ template functions to suppress their return |
| 7547 | type. It is easier for GDB users to search for such functions as |
| 7548 | `name(params)' than `long name(params)'. In such case the minimal |
| 7549 | symbol names do not match the full symbol names but for template |
| 7550 | functions there is never a need to look up their definition from their |
| 7551 | declaration so the only disadvantage remains the minimal symbol |
| 7552 | variant `long name(params)' does not have the proper inferior type. |
| 7553 | */ |
| 7554 | |
| 7555 | if (cu->language == language_go) |
| 7556 | { |
| 7557 | /* This is a lie, but we already lie to the caller new_symbol_full. |
| 7558 | new_symbol_full assumes we return the mangled name. |
| 7559 | This just undoes that lie until things are cleaned up. */ |
| 7560 | demangled = NULL; |
| 7561 | } |
| 7562 | else |
| 7563 | { |
| 7564 | demangled = cplus_demangle (mangled, |
| 7565 | (DMGL_PARAMS | DMGL_ANSI |
| 7566 | | (cu->language == language_java |
| 7567 | ? DMGL_JAVA | DMGL_RET_POSTFIX |
| 7568 | : DMGL_RET_DROP))); |
| 7569 | } |
| 7570 | if (demangled) |
| 7571 | { |
| 7572 | make_cleanup (xfree, demangled); |
| 7573 | canon = demangled; |
| 7574 | } |
| 7575 | else |
| 7576 | { |
| 7577 | canon = mangled; |
| 7578 | need_copy = 0; |
| 7579 | } |
| 7580 | } |
| 7581 | |
| 7582 | if (canon == NULL || check_physname) |
| 7583 | { |
| 7584 | const char *physname = dwarf2_compute_name (name, die, cu, 1); |
| 7585 | |
| 7586 | if (canon != NULL && strcmp (physname, canon) != 0) |
| 7587 | { |
| 7588 | /* It may not mean a bug in GDB. The compiler could also |
| 7589 | compute DW_AT_linkage_name incorrectly. But in such case |
| 7590 | GDB would need to be bug-to-bug compatible. */ |
| 7591 | |
| 7592 | complaint (&symfile_complaints, |
| 7593 | _("Computed physname <%s> does not match demangled <%s> " |
| 7594 | "(from linkage <%s>) - DIE at 0x%x [in module %s]"), |
| 7595 | physname, canon, mangled, die->offset.sect_off, objfile->name); |
| 7596 | |
| 7597 | /* Prefer DW_AT_linkage_name (in the CANON form) - when it |
| 7598 | is available here - over computed PHYSNAME. It is safer |
| 7599 | against both buggy GDB and buggy compilers. */ |
| 7600 | |
| 7601 | retval = canon; |
| 7602 | } |
| 7603 | else |
| 7604 | { |
| 7605 | retval = physname; |
| 7606 | need_copy = 0; |
| 7607 | } |
| 7608 | } |
| 7609 | else |
| 7610 | retval = canon; |
| 7611 | |
| 7612 | if (need_copy) |
| 7613 | retval = obsavestring (retval, strlen (retval), |
| 7614 | &objfile->objfile_obstack); |
| 7615 | |
| 7616 | do_cleanups (back_to); |
| 7617 | return retval; |
| 7618 | } |
| 7619 | |
| 7620 | /* Read the import statement specified by the given die and record it. */ |
| 7621 | |
| 7622 | static void |
| 7623 | read_import_statement (struct die_info *die, struct dwarf2_cu *cu) |
| 7624 | { |
| 7625 | struct objfile *objfile = cu->objfile; |
| 7626 | struct attribute *import_attr; |
| 7627 | struct die_info *imported_die, *child_die; |
| 7628 | struct dwarf2_cu *imported_cu; |
| 7629 | const char *imported_name; |
| 7630 | const char *imported_name_prefix; |
| 7631 | const char *canonical_name; |
| 7632 | const char *import_alias; |
| 7633 | const char *imported_declaration = NULL; |
| 7634 | const char *import_prefix; |
| 7635 | VEC (const_char_ptr) *excludes = NULL; |
| 7636 | struct cleanup *cleanups; |
| 7637 | |
| 7638 | char *temp; |
| 7639 | |
| 7640 | import_attr = dwarf2_attr (die, DW_AT_import, cu); |
| 7641 | if (import_attr == NULL) |
| 7642 | { |
| 7643 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), |
| 7644 | dwarf_tag_name (die->tag)); |
| 7645 | return; |
| 7646 | } |
| 7647 | |
| 7648 | imported_cu = cu; |
| 7649 | imported_die = follow_die_ref_or_sig (die, import_attr, &imported_cu); |
| 7650 | imported_name = dwarf2_name (imported_die, imported_cu); |
| 7651 | if (imported_name == NULL) |
| 7652 | { |
| 7653 | /* GCC bug: https://bugzilla.redhat.com/show_bug.cgi?id=506524 |
| 7654 | |
| 7655 | The import in the following code: |
| 7656 | namespace A |
| 7657 | { |
| 7658 | typedef int B; |
| 7659 | } |
| 7660 | |
| 7661 | int main () |
| 7662 | { |
| 7663 | using A::B; |
| 7664 | B b; |
| 7665 | return b; |
| 7666 | } |
| 7667 | |
| 7668 | ... |
| 7669 | <2><51>: Abbrev Number: 3 (DW_TAG_imported_declaration) |
| 7670 | <52> DW_AT_decl_file : 1 |
| 7671 | <53> DW_AT_decl_line : 6 |
| 7672 | <54> DW_AT_import : <0x75> |
| 7673 | <2><58>: Abbrev Number: 4 (DW_TAG_typedef) |
| 7674 | <59> DW_AT_name : B |
| 7675 | <5b> DW_AT_decl_file : 1 |
| 7676 | <5c> DW_AT_decl_line : 2 |
| 7677 | <5d> DW_AT_type : <0x6e> |
| 7678 | ... |
| 7679 | <1><75>: Abbrev Number: 7 (DW_TAG_base_type) |
| 7680 | <76> DW_AT_byte_size : 4 |
| 7681 | <77> DW_AT_encoding : 5 (signed) |
| 7682 | |
| 7683 | imports the wrong die ( 0x75 instead of 0x58 ). |
| 7684 | This case will be ignored until the gcc bug is fixed. */ |
| 7685 | return; |
| 7686 | } |
| 7687 | |
| 7688 | /* Figure out the local name after import. */ |
| 7689 | import_alias = dwarf2_name (die, cu); |
| 7690 | |
| 7691 | /* Figure out where the statement is being imported to. */ |
| 7692 | import_prefix = determine_prefix (die, cu); |
| 7693 | |
| 7694 | /* Figure out what the scope of the imported die is and prepend it |
| 7695 | to the name of the imported die. */ |
| 7696 | imported_name_prefix = determine_prefix (imported_die, imported_cu); |
| 7697 | |
| 7698 | if (imported_die->tag != DW_TAG_namespace |
| 7699 | && imported_die->tag != DW_TAG_module) |
| 7700 | { |
| 7701 | imported_declaration = imported_name; |
| 7702 | canonical_name = imported_name_prefix; |
| 7703 | } |
| 7704 | else if (strlen (imported_name_prefix) > 0) |
| 7705 | { |
| 7706 | temp = alloca (strlen (imported_name_prefix) |
| 7707 | + 2 + strlen (imported_name) + 1); |
| 7708 | strcpy (temp, imported_name_prefix); |
| 7709 | strcat (temp, "::"); |
| 7710 | strcat (temp, imported_name); |
| 7711 | canonical_name = temp; |
| 7712 | } |
| 7713 | else |
| 7714 | canonical_name = imported_name; |
| 7715 | |
| 7716 | cleanups = make_cleanup (VEC_cleanup (const_char_ptr), &excludes); |
| 7717 | |
| 7718 | if (die->tag == DW_TAG_imported_module && cu->language == language_fortran) |
| 7719 | for (child_die = die->child; child_die && child_die->tag; |
| 7720 | child_die = sibling_die (child_die)) |
| 7721 | { |
| 7722 | /* DWARF-4: A Fortran use statement with a “rename list” may be |
| 7723 | represented by an imported module entry with an import attribute |
| 7724 | referring to the module and owned entries corresponding to those |
| 7725 | entities that are renamed as part of being imported. */ |
| 7726 | |
| 7727 | if (child_die->tag != DW_TAG_imported_declaration) |
| 7728 | { |
| 7729 | complaint (&symfile_complaints, |
| 7730 | _("child DW_TAG_imported_declaration expected " |
| 7731 | "- DIE at 0x%x [in module %s]"), |
| 7732 | child_die->offset.sect_off, objfile->name); |
| 7733 | continue; |
| 7734 | } |
| 7735 | |
| 7736 | import_attr = dwarf2_attr (child_die, DW_AT_import, cu); |
| 7737 | if (import_attr == NULL) |
| 7738 | { |
| 7739 | complaint (&symfile_complaints, _("Tag '%s' has no DW_AT_import"), |
| 7740 | dwarf_tag_name (child_die->tag)); |
| 7741 | continue; |
| 7742 | } |
| 7743 | |
| 7744 | imported_cu = cu; |
| 7745 | imported_die = follow_die_ref_or_sig (child_die, import_attr, |
| 7746 | &imported_cu); |
| 7747 | imported_name = dwarf2_name (imported_die, imported_cu); |
| 7748 | if (imported_name == NULL) |
| 7749 | { |
| 7750 | complaint (&symfile_complaints, |
| 7751 | _("child DW_TAG_imported_declaration has unknown " |
| 7752 | "imported name - DIE at 0x%x [in module %s]"), |
| 7753 | child_die->offset.sect_off, objfile->name); |
| 7754 | continue; |
| 7755 | } |
| 7756 | |
| 7757 | VEC_safe_push (const_char_ptr, excludes, imported_name); |
| 7758 | |
| 7759 | process_die (child_die, cu); |
| 7760 | } |
| 7761 | |
| 7762 | cp_add_using_directive (import_prefix, |
| 7763 | canonical_name, |
| 7764 | import_alias, |
| 7765 | imported_declaration, |
| 7766 | excludes, |
| 7767 | &objfile->objfile_obstack); |
| 7768 | |
| 7769 | do_cleanups (cleanups); |
| 7770 | } |
| 7771 | |
| 7772 | /* Cleanup function for handle_DW_AT_stmt_list. */ |
| 7773 | |
| 7774 | static void |
| 7775 | free_cu_line_header (void *arg) |
| 7776 | { |
| 7777 | struct dwarf2_cu *cu = arg; |
| 7778 | |
| 7779 | free_line_header (cu->line_header); |
| 7780 | cu->line_header = NULL; |
| 7781 | } |
| 7782 | |
| 7783 | /* Check for possibly missing DW_AT_comp_dir with relative .debug_line |
| 7784 | directory paths. GCC SVN r127613 (new option -fdebug-prefix-map) fixed |
| 7785 | this, it was first present in GCC release 4.3.0. */ |
| 7786 | |
| 7787 | static int |
| 7788 | producer_is_gcc_lt_4_3 (struct dwarf2_cu *cu) |
| 7789 | { |
| 7790 | if (!cu->checked_producer) |
| 7791 | check_producer (cu); |
| 7792 | |
| 7793 | return cu->producer_is_gcc_lt_4_3; |
| 7794 | } |
| 7795 | |
| 7796 | static void |
| 7797 | find_file_and_directory (struct die_info *die, struct dwarf2_cu *cu, |
| 7798 | char **name, char **comp_dir) |
| 7799 | { |
| 7800 | struct attribute *attr; |
| 7801 | |
| 7802 | *name = NULL; |
| 7803 | *comp_dir = NULL; |
| 7804 | |
| 7805 | /* Find the filename. Do not use dwarf2_name here, since the filename |
| 7806 | is not a source language identifier. */ |
| 7807 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 7808 | if (attr) |
| 7809 | { |
| 7810 | *name = DW_STRING (attr); |
| 7811 | } |
| 7812 | |
| 7813 | attr = dwarf2_attr (die, DW_AT_comp_dir, cu); |
| 7814 | if (attr) |
| 7815 | *comp_dir = DW_STRING (attr); |
| 7816 | else if (producer_is_gcc_lt_4_3 (cu) && *name != NULL |
| 7817 | && IS_ABSOLUTE_PATH (*name)) |
| 7818 | { |
| 7819 | *comp_dir = ldirname (*name); |
| 7820 | if (*comp_dir != NULL) |
| 7821 | make_cleanup (xfree, *comp_dir); |
| 7822 | } |
| 7823 | if (*comp_dir != NULL) |
| 7824 | { |
| 7825 | /* Irix 6.2 native cc prepends <machine>.: to the compilation |
| 7826 | directory, get rid of it. */ |
| 7827 | char *cp = strchr (*comp_dir, ':'); |
| 7828 | |
| 7829 | if (cp && cp != *comp_dir && cp[-1] == '.' && cp[1] == '/') |
| 7830 | *comp_dir = cp + 1; |
| 7831 | } |
| 7832 | |
| 7833 | if (*name == NULL) |
| 7834 | *name = "<unknown>"; |
| 7835 | } |
| 7836 | |
| 7837 | /* Handle DW_AT_stmt_list for a compilation unit. |
| 7838 | DIE is the DW_TAG_compile_unit die for CU. |
| 7839 | COMP_DIR is the compilation directory. |
| 7840 | WANT_LINE_INFO is non-zero if the pc/line-number mapping is needed. */ |
| 7841 | |
| 7842 | static void |
| 7843 | handle_DW_AT_stmt_list (struct die_info *die, struct dwarf2_cu *cu, |
| 7844 | const char *comp_dir) |
| 7845 | { |
| 7846 | struct attribute *attr; |
| 7847 | |
| 7848 | gdb_assert (! cu->per_cu->is_debug_types); |
| 7849 | |
| 7850 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 7851 | if (attr) |
| 7852 | { |
| 7853 | unsigned int line_offset = DW_UNSND (attr); |
| 7854 | struct line_header *line_header |
| 7855 | = dwarf_decode_line_header (line_offset, cu); |
| 7856 | |
| 7857 | if (line_header) |
| 7858 | { |
| 7859 | cu->line_header = line_header; |
| 7860 | make_cleanup (free_cu_line_header, cu); |
| 7861 | dwarf_decode_lines (line_header, comp_dir, cu, NULL, 1); |
| 7862 | } |
| 7863 | } |
| 7864 | } |
| 7865 | |
| 7866 | /* Process DW_TAG_compile_unit or DW_TAG_partial_unit. */ |
| 7867 | |
| 7868 | static void |
| 7869 | read_file_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 7870 | { |
| 7871 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 7872 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 7873 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
| 7874 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
| 7875 | struct attribute *attr; |
| 7876 | char *name = NULL; |
| 7877 | char *comp_dir = NULL; |
| 7878 | struct die_info *child_die; |
| 7879 | bfd *abfd = objfile->obfd; |
| 7880 | CORE_ADDR baseaddr; |
| 7881 | |
| 7882 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 7883 | |
| 7884 | get_scope_pc_bounds (die, &lowpc, &highpc, cu); |
| 7885 | |
| 7886 | /* If we didn't find a lowpc, set it to highpc to avoid complaints |
| 7887 | from finish_block. */ |
| 7888 | if (lowpc == ((CORE_ADDR) -1)) |
| 7889 | lowpc = highpc; |
| 7890 | lowpc += baseaddr; |
| 7891 | highpc += baseaddr; |
| 7892 | |
| 7893 | find_file_and_directory (die, cu, &name, &comp_dir); |
| 7894 | |
| 7895 | prepare_one_comp_unit (cu, die, cu->language); |
| 7896 | |
| 7897 | /* The XLCL doesn't generate DW_LANG_OpenCL because this attribute is not |
| 7898 | standardised yet. As a workaround for the language detection we fall |
| 7899 | back to the DW_AT_producer string. */ |
| 7900 | if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL") != NULL) |
| 7901 | cu->language = language_opencl; |
| 7902 | |
| 7903 | /* Similar hack for Go. */ |
| 7904 | if (cu->producer && strstr (cu->producer, "GNU Go ") != NULL) |
| 7905 | set_cu_language (DW_LANG_Go, cu); |
| 7906 | |
| 7907 | dwarf2_start_symtab (cu, name, comp_dir, lowpc); |
| 7908 | |
| 7909 | /* Decode line number information if present. We do this before |
| 7910 | processing child DIEs, so that the line header table is available |
| 7911 | for DW_AT_decl_file. */ |
| 7912 | handle_DW_AT_stmt_list (die, cu, comp_dir); |
| 7913 | |
| 7914 | /* Process all dies in compilation unit. */ |
| 7915 | if (die->child != NULL) |
| 7916 | { |
| 7917 | child_die = die->child; |
| 7918 | while (child_die && child_die->tag) |
| 7919 | { |
| 7920 | process_die (child_die, cu); |
| 7921 | child_die = sibling_die (child_die); |
| 7922 | } |
| 7923 | } |
| 7924 | |
| 7925 | /* Decode macro information, if present. Dwarf 2 macro information |
| 7926 | refers to information in the line number info statement program |
| 7927 | header, so we can only read it if we've read the header |
| 7928 | successfully. */ |
| 7929 | attr = dwarf2_attr (die, DW_AT_GNU_macros, cu); |
| 7930 | if (attr && cu->line_header) |
| 7931 | { |
| 7932 | if (dwarf2_attr (die, DW_AT_macro_info, cu)) |
| 7933 | complaint (&symfile_complaints, |
| 7934 | _("CU refers to both DW_AT_GNU_macros and DW_AT_macro_info")); |
| 7935 | |
| 7936 | dwarf_decode_macros (cu, DW_UNSND (attr), comp_dir, 1); |
| 7937 | } |
| 7938 | else |
| 7939 | { |
| 7940 | attr = dwarf2_attr (die, DW_AT_macro_info, cu); |
| 7941 | if (attr && cu->line_header) |
| 7942 | { |
| 7943 | unsigned int macro_offset = DW_UNSND (attr); |
| 7944 | |
| 7945 | dwarf_decode_macros (cu, macro_offset, comp_dir, 0); |
| 7946 | } |
| 7947 | } |
| 7948 | |
| 7949 | do_cleanups (back_to); |
| 7950 | } |
| 7951 | |
| 7952 | /* TU version of handle_DW_AT_stmt_list for read_type_unit_scope. |
| 7953 | Create the set of symtabs used by this TU, or if this TU is sharing |
| 7954 | symtabs with another TU and the symtabs have already been created |
| 7955 | then restore those symtabs in the line header. |
| 7956 | We don't need the pc/line-number mapping for type units. */ |
| 7957 | |
| 7958 | static void |
| 7959 | setup_type_unit_groups (struct die_info *die, struct dwarf2_cu *cu) |
| 7960 | { |
| 7961 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 7962 | struct dwarf2_per_cu_data *per_cu = cu->per_cu; |
| 7963 | struct type_unit_group *tu_group; |
| 7964 | int first_time; |
| 7965 | struct line_header *lh; |
| 7966 | struct attribute *attr; |
| 7967 | unsigned int i, line_offset; |
| 7968 | |
| 7969 | gdb_assert (per_cu->is_debug_types); |
| 7970 | |
| 7971 | attr = dwarf2_attr (die, DW_AT_stmt_list, cu); |
| 7972 | |
| 7973 | /* If we're using .gdb_index (includes -readnow) then |
| 7974 | per_cu->s.type_unit_group may not have been set up yet. */ |
| 7975 | if (per_cu->s.type_unit_group == NULL) |
| 7976 | per_cu->s.type_unit_group = get_type_unit_group (cu, attr); |
| 7977 | tu_group = per_cu->s.type_unit_group; |
| 7978 | |
| 7979 | /* If we've already processed this stmt_list there's no real need to |
| 7980 | do it again, we could fake it and just recreate the part we need |
| 7981 | (file name,index -> symtab mapping). If data shows this optimization |
| 7982 | is useful we can do it then. */ |
| 7983 | first_time = tu_group->primary_symtab == NULL; |
| 7984 | |
| 7985 | /* We have to handle the case of both a missing DW_AT_stmt_list or bad |
| 7986 | debug info. */ |
| 7987 | lh = NULL; |
| 7988 | if (attr != NULL) |
| 7989 | { |
| 7990 | line_offset = DW_UNSND (attr); |
| 7991 | lh = dwarf_decode_line_header (line_offset, cu); |
| 7992 | } |
| 7993 | if (lh == NULL) |
| 7994 | { |
| 7995 | if (first_time) |
| 7996 | dwarf2_start_symtab (cu, "", NULL, 0); |
| 7997 | else |
| 7998 | { |
| 7999 | gdb_assert (tu_group->symtabs == NULL); |
| 8000 | restart_symtab (0); |
| 8001 | } |
| 8002 | /* Note: The primary symtab will get allocated at the end. */ |
| 8003 | return; |
| 8004 | } |
| 8005 | |
| 8006 | cu->line_header = lh; |
| 8007 | make_cleanup (free_cu_line_header, cu); |
| 8008 | |
| 8009 | if (first_time) |
| 8010 | { |
| 8011 | dwarf2_start_symtab (cu, "", NULL, 0); |
| 8012 | |
| 8013 | tu_group->num_symtabs = lh->num_file_names; |
| 8014 | tu_group->symtabs = XNEWVEC (struct symtab *, lh->num_file_names); |
| 8015 | |
| 8016 | for (i = 0; i < lh->num_file_names; ++i) |
| 8017 | { |
| 8018 | char *dir = NULL; |
| 8019 | struct file_entry *fe = &lh->file_names[i]; |
| 8020 | |
| 8021 | if (fe->dir_index) |
| 8022 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 8023 | dwarf2_start_subfile (fe->name, dir, NULL); |
| 8024 | |
| 8025 | /* Note: We don't have to watch for the main subfile here, type units |
| 8026 | don't have DW_AT_name. */ |
| 8027 | |
| 8028 | if (current_subfile->symtab == NULL) |
| 8029 | { |
| 8030 | /* NOTE: start_subfile will recognize when it's been passed |
| 8031 | a file it has already seen. So we can't assume there's a |
| 8032 | simple mapping from lh->file_names to subfiles, |
| 8033 | lh->file_names may contain dups. */ |
| 8034 | current_subfile->symtab = allocate_symtab (current_subfile->name, |
| 8035 | objfile); |
| 8036 | } |
| 8037 | |
| 8038 | fe->symtab = current_subfile->symtab; |
| 8039 | tu_group->symtabs[i] = fe->symtab; |
| 8040 | } |
| 8041 | } |
| 8042 | else |
| 8043 | { |
| 8044 | restart_symtab (0); |
| 8045 | |
| 8046 | for (i = 0; i < lh->num_file_names; ++i) |
| 8047 | { |
| 8048 | struct file_entry *fe = &lh->file_names[i]; |
| 8049 | |
| 8050 | fe->symtab = tu_group->symtabs[i]; |
| 8051 | } |
| 8052 | } |
| 8053 | |
| 8054 | /* The main symtab is allocated last. Type units don't have DW_AT_name |
| 8055 | so they don't have a "real" (so to speak) symtab anyway. |
| 8056 | There is later code that will assign the main symtab to all symbols |
| 8057 | that don't have one. We need to handle the case of a symbol with a |
| 8058 | missing symtab (DW_AT_decl_file) anyway. */ |
| 8059 | } |
| 8060 | |
| 8061 | /* Process DW_TAG_type_unit. |
| 8062 | For TUs we want to skip the first top level sibling if it's not the |
| 8063 | actual type being defined by this TU. In this case the first top |
| 8064 | level sibling is there to provide context only. */ |
| 8065 | |
| 8066 | static void |
| 8067 | read_type_unit_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 8068 | { |
| 8069 | struct die_info *child_die; |
| 8070 | |
| 8071 | prepare_one_comp_unit (cu, die, language_minimal); |
| 8072 | |
| 8073 | /* Initialize (or reinitialize) the machinery for building symtabs. |
| 8074 | We do this before processing child DIEs, so that the line header table |
| 8075 | is available for DW_AT_decl_file. */ |
| 8076 | setup_type_unit_groups (die, cu); |
| 8077 | |
| 8078 | if (die->child != NULL) |
| 8079 | { |
| 8080 | child_die = die->child; |
| 8081 | while (child_die && child_die->tag) |
| 8082 | { |
| 8083 | process_die (child_die, cu); |
| 8084 | child_die = sibling_die (child_die); |
| 8085 | } |
| 8086 | } |
| 8087 | } |
| 8088 | \f |
| 8089 | /* DWO/DWP files. |
| 8090 | |
| 8091 | http://gcc.gnu.org/wiki/DebugFission |
| 8092 | http://gcc.gnu.org/wiki/DebugFissionDWP |
| 8093 | |
| 8094 | To simplify handling of both DWO files ("object" files with the DWARF info) |
| 8095 | and DWP files (a file with the DWOs packaged up into one file), we treat |
| 8096 | DWP files as having a collection of virtual DWO files. */ |
| 8097 | |
| 8098 | static hashval_t |
| 8099 | hash_dwo_file (const void *item) |
| 8100 | { |
| 8101 | const struct dwo_file *dwo_file = item; |
| 8102 | |
| 8103 | return htab_hash_string (dwo_file->name); |
| 8104 | } |
| 8105 | |
| 8106 | static int |
| 8107 | eq_dwo_file (const void *item_lhs, const void *item_rhs) |
| 8108 | { |
| 8109 | const struct dwo_file *lhs = item_lhs; |
| 8110 | const struct dwo_file *rhs = item_rhs; |
| 8111 | |
| 8112 | return strcmp (lhs->name, rhs->name) == 0; |
| 8113 | } |
| 8114 | |
| 8115 | /* Allocate a hash table for DWO files. */ |
| 8116 | |
| 8117 | static htab_t |
| 8118 | allocate_dwo_file_hash_table (void) |
| 8119 | { |
| 8120 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8121 | |
| 8122 | return htab_create_alloc_ex (41, |
| 8123 | hash_dwo_file, |
| 8124 | eq_dwo_file, |
| 8125 | NULL, |
| 8126 | &objfile->objfile_obstack, |
| 8127 | hashtab_obstack_allocate, |
| 8128 | dummy_obstack_deallocate); |
| 8129 | } |
| 8130 | |
| 8131 | /* Lookup DWO file DWO_NAME. */ |
| 8132 | |
| 8133 | static void ** |
| 8134 | lookup_dwo_file_slot (const char *dwo_name) |
| 8135 | { |
| 8136 | struct dwo_file find_entry; |
| 8137 | void **slot; |
| 8138 | |
| 8139 | if (dwarf2_per_objfile->dwo_files == NULL) |
| 8140 | dwarf2_per_objfile->dwo_files = allocate_dwo_file_hash_table (); |
| 8141 | |
| 8142 | memset (&find_entry, 0, sizeof (find_entry)); |
| 8143 | find_entry.name = dwo_name; |
| 8144 | slot = htab_find_slot (dwarf2_per_objfile->dwo_files, &find_entry, INSERT); |
| 8145 | |
| 8146 | return slot; |
| 8147 | } |
| 8148 | |
| 8149 | static hashval_t |
| 8150 | hash_dwo_unit (const void *item) |
| 8151 | { |
| 8152 | const struct dwo_unit *dwo_unit = item; |
| 8153 | |
| 8154 | /* This drops the top 32 bits of the id, but is ok for a hash. */ |
| 8155 | return dwo_unit->signature; |
| 8156 | } |
| 8157 | |
| 8158 | static int |
| 8159 | eq_dwo_unit (const void *item_lhs, const void *item_rhs) |
| 8160 | { |
| 8161 | const struct dwo_unit *lhs = item_lhs; |
| 8162 | const struct dwo_unit *rhs = item_rhs; |
| 8163 | |
| 8164 | /* The signature is assumed to be unique within the DWO file. |
| 8165 | So while object file CU dwo_id's always have the value zero, |
| 8166 | that's OK, assuming each object file DWO file has only one CU, |
| 8167 | and that's the rule for now. */ |
| 8168 | return lhs->signature == rhs->signature; |
| 8169 | } |
| 8170 | |
| 8171 | /* Allocate a hash table for DWO CUs,TUs. |
| 8172 | There is one of these tables for each of CUs,TUs for each DWO file. */ |
| 8173 | |
| 8174 | static htab_t |
| 8175 | allocate_dwo_unit_table (struct objfile *objfile) |
| 8176 | { |
| 8177 | /* Start out with a pretty small number. |
| 8178 | Generally DWO files contain only one CU and maybe some TUs. */ |
| 8179 | return htab_create_alloc_ex (3, |
| 8180 | hash_dwo_unit, |
| 8181 | eq_dwo_unit, |
| 8182 | NULL, |
| 8183 | &objfile->objfile_obstack, |
| 8184 | hashtab_obstack_allocate, |
| 8185 | dummy_obstack_deallocate); |
| 8186 | } |
| 8187 | |
| 8188 | /* Structure used to pass data to create_dwo_debug_info_hash_table_reader. */ |
| 8189 | |
| 8190 | struct create_dwo_info_table_data |
| 8191 | { |
| 8192 | struct dwo_file *dwo_file; |
| 8193 | htab_t cu_htab; |
| 8194 | }; |
| 8195 | |
| 8196 | /* die_reader_func for create_dwo_debug_info_hash_table. */ |
| 8197 | |
| 8198 | static void |
| 8199 | create_dwo_debug_info_hash_table_reader (const struct die_reader_specs *reader, |
| 8200 | gdb_byte *info_ptr, |
| 8201 | struct die_info *comp_unit_die, |
| 8202 | int has_children, |
| 8203 | void *datap) |
| 8204 | { |
| 8205 | struct dwarf2_cu *cu = reader->cu; |
| 8206 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8207 | sect_offset offset = cu->per_cu->offset; |
| 8208 | struct dwarf2_section_info *section = cu->per_cu->info_or_types_section; |
| 8209 | struct create_dwo_info_table_data *data = datap; |
| 8210 | struct dwo_file *dwo_file = data->dwo_file; |
| 8211 | htab_t cu_htab = data->cu_htab; |
| 8212 | void **slot; |
| 8213 | struct attribute *attr; |
| 8214 | struct dwo_unit *dwo_unit; |
| 8215 | |
| 8216 | attr = dwarf2_attr (comp_unit_die, DW_AT_GNU_dwo_id, cu); |
| 8217 | if (attr == NULL) |
| 8218 | { |
| 8219 | error (_("Dwarf Error: debug entry at offset 0x%x is missing" |
| 8220 | " its dwo_id [in module %s]"), |
| 8221 | offset.sect_off, dwo_file->name); |
| 8222 | return; |
| 8223 | } |
| 8224 | |
| 8225 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); |
| 8226 | dwo_unit->dwo_file = dwo_file; |
| 8227 | dwo_unit->signature = DW_UNSND (attr); |
| 8228 | dwo_unit->info_or_types_section = section; |
| 8229 | dwo_unit->offset = offset; |
| 8230 | dwo_unit->length = cu->per_cu->length; |
| 8231 | |
| 8232 | slot = htab_find_slot (cu_htab, dwo_unit, INSERT); |
| 8233 | gdb_assert (slot != NULL); |
| 8234 | if (*slot != NULL) |
| 8235 | { |
| 8236 | const struct dwo_unit *dup_dwo_unit = *slot; |
| 8237 | |
| 8238 | complaint (&symfile_complaints, |
| 8239 | _("debug entry at offset 0x%x is duplicate to the entry at" |
| 8240 | " offset 0x%x, dwo_id 0x%s [in module %s]"), |
| 8241 | offset.sect_off, dup_dwo_unit->offset.sect_off, |
| 8242 | phex (dwo_unit->signature, sizeof (dwo_unit->signature)), |
| 8243 | dwo_file->name); |
| 8244 | } |
| 8245 | else |
| 8246 | *slot = dwo_unit; |
| 8247 | |
| 8248 | if (dwarf2_read_debug) |
| 8249 | fprintf_unfiltered (gdb_stdlog, " offset 0x%x, dwo_id 0x%s\n", |
| 8250 | offset.sect_off, |
| 8251 | phex (dwo_unit->signature, |
| 8252 | sizeof (dwo_unit->signature))); |
| 8253 | } |
| 8254 | |
| 8255 | /* Create a hash table to map DWO IDs to their CU entry in |
| 8256 | .debug_info.dwo in DWO_FILE. |
| 8257 | Note: This function processes DWO files only, not DWP files. */ |
| 8258 | |
| 8259 | static htab_t |
| 8260 | create_dwo_debug_info_hash_table (struct dwo_file *dwo_file) |
| 8261 | { |
| 8262 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8263 | struct dwarf2_section_info *section = &dwo_file->sections.info; |
| 8264 | bfd *abfd; |
| 8265 | htab_t cu_htab; |
| 8266 | gdb_byte *info_ptr, *end_ptr; |
| 8267 | struct create_dwo_info_table_data create_dwo_info_table_data; |
| 8268 | |
| 8269 | dwarf2_read_section (objfile, section); |
| 8270 | info_ptr = section->buffer; |
| 8271 | |
| 8272 | if (info_ptr == NULL) |
| 8273 | return NULL; |
| 8274 | |
| 8275 | /* We can't set abfd until now because the section may be empty or |
| 8276 | not present, in which case section->asection will be NULL. */ |
| 8277 | abfd = section->asection->owner; |
| 8278 | |
| 8279 | if (dwarf2_read_debug) |
| 8280 | fprintf_unfiltered (gdb_stdlog, "Reading .debug_info.dwo for %s:\n", |
| 8281 | bfd_get_filename (abfd)); |
| 8282 | |
| 8283 | cu_htab = allocate_dwo_unit_table (objfile); |
| 8284 | |
| 8285 | create_dwo_info_table_data.dwo_file = dwo_file; |
| 8286 | create_dwo_info_table_data.cu_htab = cu_htab; |
| 8287 | |
| 8288 | end_ptr = info_ptr + section->size; |
| 8289 | while (info_ptr < end_ptr) |
| 8290 | { |
| 8291 | struct dwarf2_per_cu_data per_cu; |
| 8292 | |
| 8293 | memset (&per_cu, 0, sizeof (per_cu)); |
| 8294 | per_cu.objfile = objfile; |
| 8295 | per_cu.is_debug_types = 0; |
| 8296 | per_cu.offset.sect_off = info_ptr - section->buffer; |
| 8297 | per_cu.info_or_types_section = section; |
| 8298 | |
| 8299 | init_cutu_and_read_dies_no_follow (&per_cu, |
| 8300 | &dwo_file->sections.abbrev, |
| 8301 | dwo_file, |
| 8302 | create_dwo_debug_info_hash_table_reader, |
| 8303 | &create_dwo_info_table_data); |
| 8304 | |
| 8305 | info_ptr += per_cu.length; |
| 8306 | } |
| 8307 | |
| 8308 | return cu_htab; |
| 8309 | } |
| 8310 | |
| 8311 | /* DWP file .debug_{cu,tu}_index section format: |
| 8312 | [ref: http://gcc.gnu.org/wiki/DebugFissionDWP] |
| 8313 | |
| 8314 | Both index sections have the same format, and serve to map a 64-bit |
| 8315 | signature to a set of section numbers. Each section begins with a header, |
| 8316 | followed by a hash table of 64-bit signatures, a parallel table of 32-bit |
| 8317 | indexes, and a pool of 32-bit section numbers. The index sections will be |
| 8318 | aligned at 8-byte boundaries in the file. |
| 8319 | |
| 8320 | The index section header contains two unsigned 32-bit values (using the |
| 8321 | byte order of the application binary): |
| 8322 | |
| 8323 | N, the number of compilation units or type units in the index |
| 8324 | M, the number of slots in the hash table |
| 8325 | |
| 8326 | (We assume that N and M will not exceed 2^32 - 1.) |
| 8327 | |
| 8328 | The size of the hash table, M, must be 2^k such that 2^k > 3*N/2. |
| 8329 | |
| 8330 | The hash table begins at offset 8 in the section, and consists of an array |
| 8331 | of M 64-bit slots. Each slot contains a 64-bit signature (using the byte |
| 8332 | order of the application binary). Unused slots in the hash table are 0. |
| 8333 | (We rely on the extreme unlikeliness of a signature being exactly 0.) |
| 8334 | |
| 8335 | The parallel table begins immediately after the hash table |
| 8336 | (at offset 8 + 8 * M from the beginning of the section), and consists of an |
| 8337 | array of 32-bit indexes (using the byte order of the application binary), |
| 8338 | corresponding 1-1 with slots in the hash table. Each entry in the parallel |
| 8339 | table contains a 32-bit index into the pool of section numbers. For unused |
| 8340 | hash table slots, the corresponding entry in the parallel table will be 0. |
| 8341 | |
| 8342 | Given a 64-bit compilation unit signature or a type signature S, an entry |
| 8343 | in the hash table is located as follows: |
| 8344 | |
| 8345 | 1) Calculate a primary hash H = S & MASK(k), where MASK(k) is a mask with |
| 8346 | the low-order k bits all set to 1. |
| 8347 | |
| 8348 | 2) Calculate a secondary hash H' = (((S >> 32) & MASK(k)) | 1). |
| 8349 | |
| 8350 | 3) If the hash table entry at index H matches the signature, use that |
| 8351 | entry. If the hash table entry at index H is unused (all zeroes), |
| 8352 | terminate the search: the signature is not present in the table. |
| 8353 | |
| 8354 | 4) Let H = (H + H') modulo M. Repeat at Step 3. |
| 8355 | |
| 8356 | Because M > N and H' and M are relatively prime, the search is guaranteed |
| 8357 | to stop at an unused slot or find the match. |
| 8358 | |
| 8359 | The pool of section numbers begins immediately following the hash table |
| 8360 | (at offset 8 + 12 * M from the beginning of the section). The pool of |
| 8361 | section numbers consists of an array of 32-bit words (using the byte order |
| 8362 | of the application binary). Each item in the array is indexed starting |
| 8363 | from 0. The hash table entry provides the index of the first section |
| 8364 | number in the set. Additional section numbers in the set follow, and the |
| 8365 | set is terminated by a 0 entry (section number 0 is not used in ELF). |
| 8366 | |
| 8367 | In each set of section numbers, the .debug_info.dwo or .debug_types.dwo |
| 8368 | section must be the first entry in the set, and the .debug_abbrev.dwo must |
| 8369 | be the second entry. Other members of the set may follow in any order. */ |
| 8370 | |
| 8371 | /* Create a hash table to map DWO IDs to their CU/TU entry in |
| 8372 | .debug_{info,types}.dwo in DWP_FILE. |
| 8373 | Returns NULL if there isn't one. |
| 8374 | Note: This function processes DWP files only, not DWO files. */ |
| 8375 | |
| 8376 | static struct dwp_hash_table * |
| 8377 | create_dwp_hash_table (struct dwp_file *dwp_file, int is_debug_types) |
| 8378 | { |
| 8379 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8380 | bfd *dbfd = dwp_file->dbfd; |
| 8381 | char *index_ptr, *index_end; |
| 8382 | struct dwarf2_section_info *index; |
| 8383 | uint32_t version, nr_units, nr_slots; |
| 8384 | struct dwp_hash_table *htab; |
| 8385 | |
| 8386 | if (is_debug_types) |
| 8387 | index = &dwp_file->sections.tu_index; |
| 8388 | else |
| 8389 | index = &dwp_file->sections.cu_index; |
| 8390 | |
| 8391 | if (dwarf2_section_empty_p (index)) |
| 8392 | return NULL; |
| 8393 | dwarf2_read_section (objfile, index); |
| 8394 | |
| 8395 | index_ptr = index->buffer; |
| 8396 | index_end = index_ptr + index->size; |
| 8397 | |
| 8398 | version = read_4_bytes (dbfd, index_ptr); |
| 8399 | index_ptr += 8; /* Skip the unused word. */ |
| 8400 | nr_units = read_4_bytes (dbfd, index_ptr); |
| 8401 | index_ptr += 4; |
| 8402 | nr_slots = read_4_bytes (dbfd, index_ptr); |
| 8403 | index_ptr += 4; |
| 8404 | |
| 8405 | if (version != 1) |
| 8406 | { |
| 8407 | error (_("Dwarf Error: unsupported DWP file version (%u)" |
| 8408 | " [in module %s]"), |
| 8409 | version, dwp_file->name); |
| 8410 | } |
| 8411 | if (nr_slots != (nr_slots & -nr_slots)) |
| 8412 | { |
| 8413 | error (_("Dwarf Error: number of slots in DWP hash table (%u)" |
| 8414 | " is not power of 2 [in module %s]"), |
| 8415 | nr_slots, dwp_file->name); |
| 8416 | } |
| 8417 | |
| 8418 | htab = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_hash_table); |
| 8419 | htab->nr_units = nr_units; |
| 8420 | htab->nr_slots = nr_slots; |
| 8421 | htab->hash_table = index_ptr; |
| 8422 | htab->unit_table = htab->hash_table + sizeof (uint64_t) * nr_slots; |
| 8423 | htab->section_pool = htab->unit_table + sizeof (uint32_t) * nr_slots; |
| 8424 | |
| 8425 | return htab; |
| 8426 | } |
| 8427 | |
| 8428 | /* Update SECTIONS with the data from SECTP. |
| 8429 | |
| 8430 | This function is like the other "locate" section routines that are |
| 8431 | passed to bfd_map_over_sections, but in this context the sections to |
| 8432 | read comes from the DWP hash table, not the full ELF section table. |
| 8433 | |
| 8434 | The result is non-zero for success, or zero if an error was found. */ |
| 8435 | |
| 8436 | static int |
| 8437 | locate_virtual_dwo_sections (asection *sectp, |
| 8438 | struct virtual_dwo_sections *sections) |
| 8439 | { |
| 8440 | const struct dwop_section_names *names = &dwop_section_names; |
| 8441 | |
| 8442 | if (section_is_p (sectp->name, &names->abbrev_dwo)) |
| 8443 | { |
| 8444 | /* There can be only one. */ |
| 8445 | if (sections->abbrev.asection != NULL) |
| 8446 | return 0; |
| 8447 | sections->abbrev.asection = sectp; |
| 8448 | sections->abbrev.size = bfd_get_section_size (sectp); |
| 8449 | } |
| 8450 | else if (section_is_p (sectp->name, &names->info_dwo) |
| 8451 | || section_is_p (sectp->name, &names->types_dwo)) |
| 8452 | { |
| 8453 | /* There can be only one. */ |
| 8454 | if (sections->info_or_types.asection != NULL) |
| 8455 | return 0; |
| 8456 | sections->info_or_types.asection = sectp; |
| 8457 | sections->info_or_types.size = bfd_get_section_size (sectp); |
| 8458 | } |
| 8459 | else if (section_is_p (sectp->name, &names->line_dwo)) |
| 8460 | { |
| 8461 | /* There can be only one. */ |
| 8462 | if (sections->line.asection != NULL) |
| 8463 | return 0; |
| 8464 | sections->line.asection = sectp; |
| 8465 | sections->line.size = bfd_get_section_size (sectp); |
| 8466 | } |
| 8467 | else if (section_is_p (sectp->name, &names->loc_dwo)) |
| 8468 | { |
| 8469 | /* There can be only one. */ |
| 8470 | if (sections->loc.asection != NULL) |
| 8471 | return 0; |
| 8472 | sections->loc.asection = sectp; |
| 8473 | sections->loc.size = bfd_get_section_size (sectp); |
| 8474 | } |
| 8475 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) |
| 8476 | { |
| 8477 | /* There can be only one. */ |
| 8478 | if (sections->macinfo.asection != NULL) |
| 8479 | return 0; |
| 8480 | sections->macinfo.asection = sectp; |
| 8481 | sections->macinfo.size = bfd_get_section_size (sectp); |
| 8482 | } |
| 8483 | else if (section_is_p (sectp->name, &names->macro_dwo)) |
| 8484 | { |
| 8485 | /* There can be only one. */ |
| 8486 | if (sections->macro.asection != NULL) |
| 8487 | return 0; |
| 8488 | sections->macro.asection = sectp; |
| 8489 | sections->macro.size = bfd_get_section_size (sectp); |
| 8490 | } |
| 8491 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) |
| 8492 | { |
| 8493 | /* There can be only one. */ |
| 8494 | if (sections->str_offsets.asection != NULL) |
| 8495 | return 0; |
| 8496 | sections->str_offsets.asection = sectp; |
| 8497 | sections->str_offsets.size = bfd_get_section_size (sectp); |
| 8498 | } |
| 8499 | else |
| 8500 | { |
| 8501 | /* No other kind of section is valid. */ |
| 8502 | return 0; |
| 8503 | } |
| 8504 | |
| 8505 | return 1; |
| 8506 | } |
| 8507 | |
| 8508 | /* Create a dwo_unit object for the DWO with signature SIGNATURE. |
| 8509 | HTAB is the hash table from the DWP file. |
| 8510 | SECTION_INDEX is the index of the DWO in HTAB. */ |
| 8511 | |
| 8512 | static struct dwo_unit * |
| 8513 | create_dwo_in_dwp (struct dwp_file *dwp_file, |
| 8514 | const struct dwp_hash_table *htab, |
| 8515 | uint32_t section_index, |
| 8516 | ULONGEST signature, int is_debug_types) |
| 8517 | { |
| 8518 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8519 | bfd *dbfd = dwp_file->dbfd; |
| 8520 | const char *kind = is_debug_types ? "TU" : "CU"; |
| 8521 | struct dwo_file *dwo_file; |
| 8522 | struct dwo_unit *dwo_unit; |
| 8523 | struct virtual_dwo_sections sections; |
| 8524 | void **dwo_file_slot; |
| 8525 | char *virtual_dwo_name; |
| 8526 | struct dwarf2_section_info *cutu; |
| 8527 | struct cleanup *cleanups; |
| 8528 | int i; |
| 8529 | |
| 8530 | if (dwarf2_read_debug) |
| 8531 | { |
| 8532 | fprintf_unfiltered (gdb_stdlog, "Reading %s %u/0x%s in DWP file: %s\n", |
| 8533 | kind, |
| 8534 | section_index, phex (signature, sizeof (signature)), |
| 8535 | dwp_file->name); |
| 8536 | } |
| 8537 | |
| 8538 | /* Fetch the sections of this DWO. |
| 8539 | Put a limit on the number of sections we look for so that bad data |
| 8540 | doesn't cause us to loop forever. */ |
| 8541 | |
| 8542 | #define MAX_NR_DWO_SECTIONS \ |
| 8543 | (1 /* .debug_info or .debug_types */ \ |
| 8544 | + 1 /* .debug_abbrev */ \ |
| 8545 | + 1 /* .debug_line */ \ |
| 8546 | + 1 /* .debug_loc */ \ |
| 8547 | + 1 /* .debug_str_offsets */ \ |
| 8548 | + 1 /* .debug_macro */ \ |
| 8549 | + 1 /* .debug_macinfo */ \ |
| 8550 | + 1 /* trailing zero */) |
| 8551 | |
| 8552 | memset (§ions, 0, sizeof (sections)); |
| 8553 | cleanups = make_cleanup (null_cleanup, 0); |
| 8554 | |
| 8555 | for (i = 0; i < MAX_NR_DWO_SECTIONS; ++i) |
| 8556 | { |
| 8557 | asection *sectp; |
| 8558 | uint32_t section_nr = |
| 8559 | read_4_bytes (dbfd, |
| 8560 | htab->section_pool |
| 8561 | + (section_index + i) * sizeof (uint32_t)); |
| 8562 | |
| 8563 | if (section_nr == 0) |
| 8564 | break; |
| 8565 | if (section_nr >= dwp_file->num_sections) |
| 8566 | { |
| 8567 | error (_("Dwarf Error: bad DWP hash table, section number too large" |
| 8568 | " [in module %s]"), |
| 8569 | dwp_file->name); |
| 8570 | } |
| 8571 | |
| 8572 | sectp = dwp_file->elf_sections[section_nr]; |
| 8573 | if (! locate_virtual_dwo_sections (sectp, §ions)) |
| 8574 | { |
| 8575 | error (_("Dwarf Error: bad DWP hash table, invalid section found" |
| 8576 | " [in module %s]"), |
| 8577 | dwp_file->name); |
| 8578 | } |
| 8579 | } |
| 8580 | |
| 8581 | if (i < 2 |
| 8582 | || sections.info_or_types.asection == NULL |
| 8583 | || sections.abbrev.asection == NULL) |
| 8584 | { |
| 8585 | error (_("Dwarf Error: bad DWP hash table, missing DWO sections" |
| 8586 | " [in module %s]"), |
| 8587 | dwp_file->name); |
| 8588 | } |
| 8589 | if (i == MAX_NR_DWO_SECTIONS) |
| 8590 | { |
| 8591 | error (_("Dwarf Error: bad DWP hash table, too many DWO sections" |
| 8592 | " [in module %s]"), |
| 8593 | dwp_file->name); |
| 8594 | } |
| 8595 | |
| 8596 | /* It's easier for the rest of the code if we fake a struct dwo_file and |
| 8597 | have dwo_unit "live" in that. At least for now. |
| 8598 | |
| 8599 | The DWP file can be made up of a random collection of CUs and TUs. |
| 8600 | However, for each CU + set of TUs that came from the same original DWO |
| 8601 | file, we want to combine them back into a virtual DWO file to save space |
| 8602 | (fewer struct dwo_file objects to allocated). Remember that for really |
| 8603 | large apps there can be on the order of 8K CUs and 200K TUs, or more. */ |
| 8604 | |
| 8605 | virtual_dwo_name = |
| 8606 | xstrprintf ("virtual-dwo/%d-%d-%d-%d", |
| 8607 | sections.abbrev.asection ? sections.abbrev.asection->id : 0, |
| 8608 | sections.line.asection ? sections.line.asection->id : 0, |
| 8609 | sections.loc.asection ? sections.loc.asection->id : 0, |
| 8610 | (sections.str_offsets.asection |
| 8611 | ? sections.str_offsets.asection->id |
| 8612 | : 0)); |
| 8613 | make_cleanup (xfree, virtual_dwo_name); |
| 8614 | /* Can we use an existing virtual DWO file? */ |
| 8615 | dwo_file_slot = lookup_dwo_file_slot (virtual_dwo_name); |
| 8616 | /* Create one if necessary. */ |
| 8617 | if (*dwo_file_slot == NULL) |
| 8618 | { |
| 8619 | if (dwarf2_read_debug) |
| 8620 | { |
| 8621 | fprintf_unfiltered (gdb_stdlog, "Creating virtual DWO: %s\n", |
| 8622 | virtual_dwo_name); |
| 8623 | } |
| 8624 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); |
| 8625 | dwo_file->name = obstack_copy0 (&objfile->objfile_obstack, |
| 8626 | virtual_dwo_name, |
| 8627 | strlen (virtual_dwo_name)); |
| 8628 | dwo_file->sections.abbrev = sections.abbrev; |
| 8629 | dwo_file->sections.line = sections.line; |
| 8630 | dwo_file->sections.loc = sections.loc; |
| 8631 | dwo_file->sections.macinfo = sections.macinfo; |
| 8632 | dwo_file->sections.macro = sections.macro; |
| 8633 | dwo_file->sections.str_offsets = sections.str_offsets; |
| 8634 | /* The "str" section is global to the entire DWP file. */ |
| 8635 | dwo_file->sections.str = dwp_file->sections.str; |
| 8636 | /* The info or types section is assigned later to dwo_unit, |
| 8637 | there's no need to record it in dwo_file. |
| 8638 | Also, we can't simply record type sections in dwo_file because |
| 8639 | we record a pointer into the vector in dwo_unit. As we collect more |
| 8640 | types we'll grow the vector and eventually have to reallocate space |
| 8641 | for it, invalidating all the pointers into the current copy. */ |
| 8642 | *dwo_file_slot = dwo_file; |
| 8643 | } |
| 8644 | else |
| 8645 | { |
| 8646 | if (dwarf2_read_debug) |
| 8647 | { |
| 8648 | fprintf_unfiltered (gdb_stdlog, "Using existing virtual DWO: %s\n", |
| 8649 | virtual_dwo_name); |
| 8650 | } |
| 8651 | dwo_file = *dwo_file_slot; |
| 8652 | } |
| 8653 | do_cleanups (cleanups); |
| 8654 | |
| 8655 | dwo_unit = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_unit); |
| 8656 | dwo_unit->dwo_file = dwo_file; |
| 8657 | dwo_unit->signature = signature; |
| 8658 | dwo_unit->info_or_types_section = |
| 8659 | obstack_alloc (&objfile->objfile_obstack, |
| 8660 | sizeof (struct dwarf2_section_info)); |
| 8661 | *dwo_unit->info_or_types_section = sections.info_or_types; |
| 8662 | /* offset, length, type_offset_in_tu are set later. */ |
| 8663 | |
| 8664 | return dwo_unit; |
| 8665 | } |
| 8666 | |
| 8667 | /* Lookup the DWO with SIGNATURE in DWP_FILE. */ |
| 8668 | |
| 8669 | static struct dwo_unit * |
| 8670 | lookup_dwo_in_dwp (struct dwp_file *dwp_file, |
| 8671 | const struct dwp_hash_table *htab, |
| 8672 | ULONGEST signature, int is_debug_types) |
| 8673 | { |
| 8674 | bfd *dbfd = dwp_file->dbfd; |
| 8675 | uint32_t mask = htab->nr_slots - 1; |
| 8676 | uint32_t hash = signature & mask; |
| 8677 | uint32_t hash2 = ((signature >> 32) & mask) | 1; |
| 8678 | unsigned int i; |
| 8679 | void **slot; |
| 8680 | struct dwo_unit find_dwo_cu, *dwo_cu; |
| 8681 | |
| 8682 | memset (&find_dwo_cu, 0, sizeof (find_dwo_cu)); |
| 8683 | find_dwo_cu.signature = signature; |
| 8684 | slot = htab_find_slot (dwp_file->loaded_cutus, &find_dwo_cu, INSERT); |
| 8685 | |
| 8686 | if (*slot != NULL) |
| 8687 | return *slot; |
| 8688 | |
| 8689 | /* Use a for loop so that we don't loop forever on bad debug info. */ |
| 8690 | for (i = 0; i < htab->nr_slots; ++i) |
| 8691 | { |
| 8692 | ULONGEST signature_in_table; |
| 8693 | |
| 8694 | signature_in_table = |
| 8695 | read_8_bytes (dbfd, htab->hash_table + hash * sizeof (uint64_t)); |
| 8696 | if (signature_in_table == signature) |
| 8697 | { |
| 8698 | uint32_t section_index = |
| 8699 | read_4_bytes (dbfd, htab->unit_table + hash * sizeof (uint32_t)); |
| 8700 | |
| 8701 | *slot = create_dwo_in_dwp (dwp_file, htab, section_index, |
| 8702 | signature, is_debug_types); |
| 8703 | return *slot; |
| 8704 | } |
| 8705 | if (signature_in_table == 0) |
| 8706 | return NULL; |
| 8707 | hash = (hash + hash2) & mask; |
| 8708 | } |
| 8709 | |
| 8710 | error (_("Dwarf Error: bad DWP hash table, lookup didn't terminate" |
| 8711 | " [in module %s]"), |
| 8712 | dwp_file->name); |
| 8713 | } |
| 8714 | |
| 8715 | /* Subroutine of open_dwop_file to simplify it. |
| 8716 | Open the file specified by FILE_NAME and hand it off to BFD for |
| 8717 | preliminary analysis. Return a newly initialized bfd *, which |
| 8718 | includes a canonicalized copy of FILE_NAME. |
| 8719 | If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file. |
| 8720 | In case of trouble, return NULL. |
| 8721 | NOTE: This function is derived from symfile_bfd_open. */ |
| 8722 | |
| 8723 | static bfd * |
| 8724 | try_open_dwop_file (const char *file_name, int is_dwp) |
| 8725 | { |
| 8726 | bfd *sym_bfd; |
| 8727 | int desc, flags; |
| 8728 | char *absolute_name; |
| 8729 | |
| 8730 | flags = OPF_TRY_CWD_FIRST; |
| 8731 | if (is_dwp) |
| 8732 | flags |= OPF_SEARCH_IN_PATH; |
| 8733 | desc = openp (debug_file_directory, flags, file_name, |
| 8734 | O_RDONLY | O_BINARY, &absolute_name); |
| 8735 | if (desc < 0) |
| 8736 | return NULL; |
| 8737 | |
| 8738 | sym_bfd = gdb_bfd_open (absolute_name, gnutarget, desc); |
| 8739 | if (!sym_bfd) |
| 8740 | { |
| 8741 | xfree (absolute_name); |
| 8742 | return NULL; |
| 8743 | } |
| 8744 | xfree (absolute_name); |
| 8745 | bfd_set_cacheable (sym_bfd, 1); |
| 8746 | |
| 8747 | if (!bfd_check_format (sym_bfd, bfd_object)) |
| 8748 | { |
| 8749 | gdb_bfd_unref (sym_bfd); /* This also closes desc. */ |
| 8750 | return NULL; |
| 8751 | } |
| 8752 | |
| 8753 | return sym_bfd; |
| 8754 | } |
| 8755 | |
| 8756 | /* Try to open DWO/DWP file FILE_NAME. |
| 8757 | COMP_DIR is the DW_AT_comp_dir attribute. |
| 8758 | If IS_DWP is TRUE, we're opening a DWP file, otherwise a DWO file. |
| 8759 | The result is the bfd handle of the file. |
| 8760 | If there is a problem finding or opening the file, return NULL. |
| 8761 | Upon success, the canonicalized path of the file is stored in the bfd, |
| 8762 | same as symfile_bfd_open. */ |
| 8763 | |
| 8764 | static bfd * |
| 8765 | open_dwop_file (const char *file_name, const char *comp_dir, int is_dwp) |
| 8766 | { |
| 8767 | bfd *abfd; |
| 8768 | |
| 8769 | if (IS_ABSOLUTE_PATH (file_name)) |
| 8770 | return try_open_dwop_file (file_name, is_dwp); |
| 8771 | |
| 8772 | /* Before trying the search path, try DWO_NAME in COMP_DIR. */ |
| 8773 | |
| 8774 | if (comp_dir != NULL) |
| 8775 | { |
| 8776 | char *path_to_try = concat (comp_dir, SLASH_STRING, file_name, NULL); |
| 8777 | |
| 8778 | /* NOTE: If comp_dir is a relative path, this will also try the |
| 8779 | search path, which seems useful. */ |
| 8780 | abfd = try_open_dwop_file (path_to_try, is_dwp); |
| 8781 | xfree (path_to_try); |
| 8782 | if (abfd != NULL) |
| 8783 | return abfd; |
| 8784 | } |
| 8785 | |
| 8786 | /* That didn't work, try debug-file-directory, which, despite its name, |
| 8787 | is a list of paths. */ |
| 8788 | |
| 8789 | if (*debug_file_directory == '\0') |
| 8790 | return NULL; |
| 8791 | |
| 8792 | return try_open_dwop_file (file_name, is_dwp); |
| 8793 | } |
| 8794 | |
| 8795 | /* This function is mapped across the sections and remembers the offset and |
| 8796 | size of each of the DWO debugging sections we are interested in. */ |
| 8797 | |
| 8798 | static void |
| 8799 | dwarf2_locate_dwo_sections (bfd *abfd, asection *sectp, void *dwo_sections_ptr) |
| 8800 | { |
| 8801 | struct dwo_sections *dwo_sections = dwo_sections_ptr; |
| 8802 | const struct dwop_section_names *names = &dwop_section_names; |
| 8803 | |
| 8804 | if (section_is_p (sectp->name, &names->abbrev_dwo)) |
| 8805 | { |
| 8806 | dwo_sections->abbrev.asection = sectp; |
| 8807 | dwo_sections->abbrev.size = bfd_get_section_size (sectp); |
| 8808 | } |
| 8809 | else if (section_is_p (sectp->name, &names->info_dwo)) |
| 8810 | { |
| 8811 | dwo_sections->info.asection = sectp; |
| 8812 | dwo_sections->info.size = bfd_get_section_size (sectp); |
| 8813 | } |
| 8814 | else if (section_is_p (sectp->name, &names->line_dwo)) |
| 8815 | { |
| 8816 | dwo_sections->line.asection = sectp; |
| 8817 | dwo_sections->line.size = bfd_get_section_size (sectp); |
| 8818 | } |
| 8819 | else if (section_is_p (sectp->name, &names->loc_dwo)) |
| 8820 | { |
| 8821 | dwo_sections->loc.asection = sectp; |
| 8822 | dwo_sections->loc.size = bfd_get_section_size (sectp); |
| 8823 | } |
| 8824 | else if (section_is_p (sectp->name, &names->macinfo_dwo)) |
| 8825 | { |
| 8826 | dwo_sections->macinfo.asection = sectp; |
| 8827 | dwo_sections->macinfo.size = bfd_get_section_size (sectp); |
| 8828 | } |
| 8829 | else if (section_is_p (sectp->name, &names->macro_dwo)) |
| 8830 | { |
| 8831 | dwo_sections->macro.asection = sectp; |
| 8832 | dwo_sections->macro.size = bfd_get_section_size (sectp); |
| 8833 | } |
| 8834 | else if (section_is_p (sectp->name, &names->str_dwo)) |
| 8835 | { |
| 8836 | dwo_sections->str.asection = sectp; |
| 8837 | dwo_sections->str.size = bfd_get_section_size (sectp); |
| 8838 | } |
| 8839 | else if (section_is_p (sectp->name, &names->str_offsets_dwo)) |
| 8840 | { |
| 8841 | dwo_sections->str_offsets.asection = sectp; |
| 8842 | dwo_sections->str_offsets.size = bfd_get_section_size (sectp); |
| 8843 | } |
| 8844 | else if (section_is_p (sectp->name, &names->types_dwo)) |
| 8845 | { |
| 8846 | struct dwarf2_section_info type_section; |
| 8847 | |
| 8848 | memset (&type_section, 0, sizeof (type_section)); |
| 8849 | type_section.asection = sectp; |
| 8850 | type_section.size = bfd_get_section_size (sectp); |
| 8851 | VEC_safe_push (dwarf2_section_info_def, dwo_sections->types, |
| 8852 | &type_section); |
| 8853 | } |
| 8854 | } |
| 8855 | |
| 8856 | /* Initialize the use of the DWO file specified by DWO_NAME. |
| 8857 | The result is NULL if DWO_NAME can't be found. */ |
| 8858 | |
| 8859 | static struct dwo_file * |
| 8860 | open_and_init_dwo_file (const char *dwo_name, const char *comp_dir) |
| 8861 | { |
| 8862 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8863 | struct dwo_file *dwo_file; |
| 8864 | bfd *dbfd; |
| 8865 | struct cleanup *cleanups; |
| 8866 | |
| 8867 | dbfd = open_dwop_file (dwo_name, comp_dir, 0); |
| 8868 | if (dbfd == NULL) |
| 8869 | { |
| 8870 | if (dwarf2_read_debug) |
| 8871 | fprintf_unfiltered (gdb_stdlog, "DWO file not found: %s\n", dwo_name); |
| 8872 | return NULL; |
| 8873 | } |
| 8874 | dwo_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwo_file); |
| 8875 | dwo_file->name = obstack_copy0 (&objfile->objfile_obstack, |
| 8876 | dwo_name, strlen (dwo_name)); |
| 8877 | dwo_file->dbfd = dbfd; |
| 8878 | |
| 8879 | cleanups = make_cleanup (free_dwo_file_cleanup, dwo_file); |
| 8880 | |
| 8881 | bfd_map_over_sections (dbfd, dwarf2_locate_dwo_sections, &dwo_file->sections); |
| 8882 | |
| 8883 | dwo_file->cus = create_dwo_debug_info_hash_table (dwo_file); |
| 8884 | |
| 8885 | dwo_file->tus = create_debug_types_hash_table (dwo_file, |
| 8886 | dwo_file->sections.types); |
| 8887 | |
| 8888 | discard_cleanups (cleanups); |
| 8889 | |
| 8890 | if (dwarf2_read_debug) |
| 8891 | fprintf_unfiltered (gdb_stdlog, "DWO file found: %s\n", dwo_name); |
| 8892 | |
| 8893 | return dwo_file; |
| 8894 | } |
| 8895 | |
| 8896 | /* This function is mapped across the sections and remembers the offset and |
| 8897 | size of each of the DWP debugging sections we are interested in. */ |
| 8898 | |
| 8899 | static void |
| 8900 | dwarf2_locate_dwp_sections (bfd *abfd, asection *sectp, void *dwp_file_ptr) |
| 8901 | { |
| 8902 | struct dwp_file *dwp_file = dwp_file_ptr; |
| 8903 | const struct dwop_section_names *names = &dwop_section_names; |
| 8904 | unsigned int elf_section_nr = elf_section_data (sectp)->this_idx; |
| 8905 | |
| 8906 | /* Record the ELF section number for later lookup: this is what the |
| 8907 | .debug_cu_index,.debug_tu_index tables use. */ |
| 8908 | gdb_assert (elf_section_nr < dwp_file->num_sections); |
| 8909 | dwp_file->elf_sections[elf_section_nr] = sectp; |
| 8910 | |
| 8911 | /* Look for specific sections that we need. */ |
| 8912 | if (section_is_p (sectp->name, &names->str_dwo)) |
| 8913 | { |
| 8914 | dwp_file->sections.str.asection = sectp; |
| 8915 | dwp_file->sections.str.size = bfd_get_section_size (sectp); |
| 8916 | } |
| 8917 | else if (section_is_p (sectp->name, &names->cu_index)) |
| 8918 | { |
| 8919 | dwp_file->sections.cu_index.asection = sectp; |
| 8920 | dwp_file->sections.cu_index.size = bfd_get_section_size (sectp); |
| 8921 | } |
| 8922 | else if (section_is_p (sectp->name, &names->tu_index)) |
| 8923 | { |
| 8924 | dwp_file->sections.tu_index.asection = sectp; |
| 8925 | dwp_file->sections.tu_index.size = bfd_get_section_size (sectp); |
| 8926 | } |
| 8927 | } |
| 8928 | |
| 8929 | /* Hash function for dwp_file loaded CUs/TUs. */ |
| 8930 | |
| 8931 | static hashval_t |
| 8932 | hash_dwp_loaded_cutus (const void *item) |
| 8933 | { |
| 8934 | const struct dwo_unit *dwo_unit = item; |
| 8935 | |
| 8936 | /* This drops the top 32 bits of the signature, but is ok for a hash. */ |
| 8937 | return dwo_unit->signature; |
| 8938 | } |
| 8939 | |
| 8940 | /* Equality function for dwp_file loaded CUs/TUs. */ |
| 8941 | |
| 8942 | static int |
| 8943 | eq_dwp_loaded_cutus (const void *a, const void *b) |
| 8944 | { |
| 8945 | const struct dwo_unit *dua = a; |
| 8946 | const struct dwo_unit *dub = b; |
| 8947 | |
| 8948 | return dua->signature == dub->signature; |
| 8949 | } |
| 8950 | |
| 8951 | /* Allocate a hash table for dwp_file loaded CUs/TUs. */ |
| 8952 | |
| 8953 | static htab_t |
| 8954 | allocate_dwp_loaded_cutus_table (struct objfile *objfile) |
| 8955 | { |
| 8956 | return htab_create_alloc_ex (3, |
| 8957 | hash_dwp_loaded_cutus, |
| 8958 | eq_dwp_loaded_cutus, |
| 8959 | NULL, |
| 8960 | &objfile->objfile_obstack, |
| 8961 | hashtab_obstack_allocate, |
| 8962 | dummy_obstack_deallocate); |
| 8963 | } |
| 8964 | |
| 8965 | /* Initialize the use of the DWP file for the current objfile. |
| 8966 | By convention the name of the DWP file is ${objfile}.dwp. |
| 8967 | The result is NULL if it can't be found. */ |
| 8968 | |
| 8969 | static struct dwp_file * |
| 8970 | open_and_init_dwp_file (const char *comp_dir) |
| 8971 | { |
| 8972 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 8973 | struct dwp_file *dwp_file; |
| 8974 | char *dwp_name; |
| 8975 | bfd *dbfd; |
| 8976 | struct cleanup *cleanups; |
| 8977 | |
| 8978 | dwp_name = xstrprintf ("%s.dwp", dwarf2_per_objfile->objfile->name); |
| 8979 | cleanups = make_cleanup (xfree, dwp_name); |
| 8980 | |
| 8981 | dbfd = open_dwop_file (dwp_name, comp_dir, 1); |
| 8982 | if (dbfd == NULL) |
| 8983 | { |
| 8984 | if (dwarf2_read_debug) |
| 8985 | fprintf_unfiltered (gdb_stdlog, "DWP file not found: %s\n", dwp_name); |
| 8986 | do_cleanups (cleanups); |
| 8987 | return NULL; |
| 8988 | } |
| 8989 | dwp_file = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct dwp_file); |
| 8990 | dwp_file->name = obstack_copy0 (&objfile->objfile_obstack, |
| 8991 | dwp_name, strlen (dwp_name)); |
| 8992 | dwp_file->dbfd = dbfd; |
| 8993 | do_cleanups (cleanups); |
| 8994 | |
| 8995 | cleanups = make_cleanup (free_dwo_file_cleanup, dwp_file); |
| 8996 | |
| 8997 | /* +1: section 0 is unused */ |
| 8998 | dwp_file->num_sections = bfd_count_sections (dbfd) + 1; |
| 8999 | dwp_file->elf_sections = |
| 9000 | OBSTACK_CALLOC (&objfile->objfile_obstack, |
| 9001 | dwp_file->num_sections, asection *); |
| 9002 | |
| 9003 | bfd_map_over_sections (dbfd, dwarf2_locate_dwp_sections, dwp_file); |
| 9004 | |
| 9005 | dwp_file->cus = create_dwp_hash_table (dwp_file, 0); |
| 9006 | |
| 9007 | dwp_file->tus = create_dwp_hash_table (dwp_file, 1); |
| 9008 | |
| 9009 | dwp_file->loaded_cutus = allocate_dwp_loaded_cutus_table (objfile); |
| 9010 | |
| 9011 | discard_cleanups (cleanups); |
| 9012 | |
| 9013 | if (dwarf2_read_debug) |
| 9014 | { |
| 9015 | fprintf_unfiltered (gdb_stdlog, "DWP file found: %s\n", dwp_file->name); |
| 9016 | fprintf_unfiltered (gdb_stdlog, |
| 9017 | " %u CUs, %u TUs\n", |
| 9018 | dwp_file->cus ? dwp_file->cus->nr_units : 0, |
| 9019 | dwp_file->tus ? dwp_file->tus->nr_units : 0); |
| 9020 | } |
| 9021 | |
| 9022 | return dwp_file; |
| 9023 | } |
| 9024 | |
| 9025 | /* Subroutine of lookup_dwo_comp_unit, lookup_dwo_type_unit. |
| 9026 | Look up the CU/TU with signature SIGNATURE, either in DWO file DWO_NAME |
| 9027 | or in the DWP file for the objfile, referenced by THIS_UNIT. |
| 9028 | If non-NULL, comp_dir is the DW_AT_comp_dir attribute. |
| 9029 | IS_DEBUG_TYPES is non-zero if reading a TU, otherwise read a CU. |
| 9030 | |
| 9031 | This is called, for example, when wanting to read a variable with a |
| 9032 | complex location. Therefore we don't want to do file i/o for every call. |
| 9033 | Therefore we don't want to look for a DWO file on every call. |
| 9034 | Therefore we first see if we've already seen SIGNATURE in a DWP file, |
| 9035 | then we check if we've already seen DWO_NAME, and only THEN do we check |
| 9036 | for a DWO file. |
| 9037 | |
| 9038 | The result is a pointer to the dwo_unit object or NULL if we didn't find it |
| 9039 | (dwo_id mismatch or couldn't find the DWO/DWP file). */ |
| 9040 | |
| 9041 | static struct dwo_unit * |
| 9042 | lookup_dwo_cutu (struct dwarf2_per_cu_data *this_unit, |
| 9043 | const char *dwo_name, const char *comp_dir, |
| 9044 | ULONGEST signature, int is_debug_types) |
| 9045 | { |
| 9046 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 9047 | const char *kind = is_debug_types ? "TU" : "CU"; |
| 9048 | void **dwo_file_slot; |
| 9049 | struct dwo_file *dwo_file; |
| 9050 | struct dwp_file *dwp_file; |
| 9051 | |
| 9052 | /* Have we already read SIGNATURE from a DWP file? */ |
| 9053 | |
| 9054 | if (! dwarf2_per_objfile->dwp_checked) |
| 9055 | { |
| 9056 | dwarf2_per_objfile->dwp_file = open_and_init_dwp_file (comp_dir); |
| 9057 | dwarf2_per_objfile->dwp_checked = 1; |
| 9058 | } |
| 9059 | dwp_file = dwarf2_per_objfile->dwp_file; |
| 9060 | |
| 9061 | if (dwp_file != NULL) |
| 9062 | { |
| 9063 | const struct dwp_hash_table *dwp_htab = |
| 9064 | is_debug_types ? dwp_file->tus : dwp_file->cus; |
| 9065 | |
| 9066 | if (dwp_htab != NULL) |
| 9067 | { |
| 9068 | struct dwo_unit *dwo_cutu = |
| 9069 | lookup_dwo_in_dwp (dwp_file, dwp_htab, signature, is_debug_types); |
| 9070 | |
| 9071 | if (dwo_cutu != NULL) |
| 9072 | { |
| 9073 | if (dwarf2_read_debug) |
| 9074 | { |
| 9075 | fprintf_unfiltered (gdb_stdlog, |
| 9076 | "Virtual DWO %s %s found: @%s\n", |
| 9077 | kind, hex_string (signature), |
| 9078 | host_address_to_string (dwo_cutu)); |
| 9079 | } |
| 9080 | return dwo_cutu; |
| 9081 | } |
| 9082 | } |
| 9083 | } |
| 9084 | |
| 9085 | /* Have we already seen DWO_NAME? */ |
| 9086 | |
| 9087 | dwo_file_slot = lookup_dwo_file_slot (dwo_name); |
| 9088 | if (*dwo_file_slot == NULL) |
| 9089 | { |
| 9090 | /* Read in the file and build a table of the DWOs it contains. */ |
| 9091 | *dwo_file_slot = open_and_init_dwo_file (dwo_name, comp_dir); |
| 9092 | } |
| 9093 | /* NOTE: This will be NULL if unable to open the file. */ |
| 9094 | dwo_file = *dwo_file_slot; |
| 9095 | |
| 9096 | if (dwo_file != NULL) |
| 9097 | { |
| 9098 | htab_t htab = is_debug_types ? dwo_file->tus : dwo_file->cus; |
| 9099 | |
| 9100 | if (htab != NULL) |
| 9101 | { |
| 9102 | struct dwo_unit find_dwo_cutu, *dwo_cutu; |
| 9103 | |
| 9104 | memset (&find_dwo_cutu, 0, sizeof (find_dwo_cutu)); |
| 9105 | find_dwo_cutu.signature = signature; |
| 9106 | dwo_cutu = htab_find (htab, &find_dwo_cutu); |
| 9107 | |
| 9108 | if (dwo_cutu != NULL) |
| 9109 | { |
| 9110 | if (dwarf2_read_debug) |
| 9111 | { |
| 9112 | fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) found: @%s\n", |
| 9113 | kind, dwo_name, hex_string (signature), |
| 9114 | host_address_to_string (dwo_cutu)); |
| 9115 | } |
| 9116 | return dwo_cutu; |
| 9117 | } |
| 9118 | } |
| 9119 | } |
| 9120 | |
| 9121 | /* We didn't find it. This could mean a dwo_id mismatch, or |
| 9122 | someone deleted the DWO/DWP file, or the search path isn't set up |
| 9123 | correctly to find the file. */ |
| 9124 | |
| 9125 | if (dwarf2_read_debug) |
| 9126 | { |
| 9127 | fprintf_unfiltered (gdb_stdlog, "DWO %s %s(%s) not found\n", |
| 9128 | kind, dwo_name, hex_string (signature)); |
| 9129 | } |
| 9130 | |
| 9131 | complaint (&symfile_complaints, |
| 9132 | _("Could not find DWO CU referenced by CU at offset 0x%x" |
| 9133 | " [in module %s]"), |
| 9134 | this_unit->offset.sect_off, objfile->name); |
| 9135 | return NULL; |
| 9136 | } |
| 9137 | |
| 9138 | /* Lookup the DWO CU DWO_NAME/SIGNATURE referenced from THIS_CU. |
| 9139 | See lookup_dwo_cutu_unit for details. */ |
| 9140 | |
| 9141 | static struct dwo_unit * |
| 9142 | lookup_dwo_comp_unit (struct dwarf2_per_cu_data *this_cu, |
| 9143 | const char *dwo_name, const char *comp_dir, |
| 9144 | ULONGEST signature) |
| 9145 | { |
| 9146 | return lookup_dwo_cutu (this_cu, dwo_name, comp_dir, signature, 0); |
| 9147 | } |
| 9148 | |
| 9149 | /* Lookup the DWO TU DWO_NAME/SIGNATURE referenced from THIS_TU. |
| 9150 | See lookup_dwo_cutu_unit for details. */ |
| 9151 | |
| 9152 | static struct dwo_unit * |
| 9153 | lookup_dwo_type_unit (struct signatured_type *this_tu, |
| 9154 | const char *dwo_name, const char *comp_dir) |
| 9155 | { |
| 9156 | return lookup_dwo_cutu (&this_tu->per_cu, dwo_name, comp_dir, this_tu->signature, 1); |
| 9157 | } |
| 9158 | |
| 9159 | /* Free all resources associated with DWO_FILE. |
| 9160 | Close the DWO file and munmap the sections. |
| 9161 | All memory should be on the objfile obstack. */ |
| 9162 | |
| 9163 | static void |
| 9164 | free_dwo_file (struct dwo_file *dwo_file, struct objfile *objfile) |
| 9165 | { |
| 9166 | int ix; |
| 9167 | struct dwarf2_section_info *section; |
| 9168 | |
| 9169 | gdb_assert (dwo_file->dbfd != objfile->obfd); |
| 9170 | gdb_bfd_unref (dwo_file->dbfd); |
| 9171 | |
| 9172 | VEC_free (dwarf2_section_info_def, dwo_file->sections.types); |
| 9173 | } |
| 9174 | |
| 9175 | /* Wrapper for free_dwo_file for use in cleanups. */ |
| 9176 | |
| 9177 | static void |
| 9178 | free_dwo_file_cleanup (void *arg) |
| 9179 | { |
| 9180 | struct dwo_file *dwo_file = (struct dwo_file *) arg; |
| 9181 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 9182 | |
| 9183 | free_dwo_file (dwo_file, objfile); |
| 9184 | } |
| 9185 | |
| 9186 | /* Traversal function for free_dwo_files. */ |
| 9187 | |
| 9188 | static int |
| 9189 | free_dwo_file_from_slot (void **slot, void *info) |
| 9190 | { |
| 9191 | struct dwo_file *dwo_file = (struct dwo_file *) *slot; |
| 9192 | struct objfile *objfile = (struct objfile *) info; |
| 9193 | |
| 9194 | free_dwo_file (dwo_file, objfile); |
| 9195 | |
| 9196 | return 1; |
| 9197 | } |
| 9198 | |
| 9199 | /* Free all resources associated with DWO_FILES. */ |
| 9200 | |
| 9201 | static void |
| 9202 | free_dwo_files (htab_t dwo_files, struct objfile *objfile) |
| 9203 | { |
| 9204 | htab_traverse_noresize (dwo_files, free_dwo_file_from_slot, objfile); |
| 9205 | } |
| 9206 | \f |
| 9207 | /* Read in various DIEs. */ |
| 9208 | |
| 9209 | /* qsort helper for inherit_abstract_dies. */ |
| 9210 | |
| 9211 | static int |
| 9212 | unsigned_int_compar (const void *ap, const void *bp) |
| 9213 | { |
| 9214 | unsigned int a = *(unsigned int *) ap; |
| 9215 | unsigned int b = *(unsigned int *) bp; |
| 9216 | |
| 9217 | return (a > b) - (b > a); |
| 9218 | } |
| 9219 | |
| 9220 | /* DW_AT_abstract_origin inherits whole DIEs (not just their attributes). |
| 9221 | Inherit only the children of the DW_AT_abstract_origin DIE not being |
| 9222 | already referenced by DW_AT_abstract_origin from the children of the |
| 9223 | current DIE. */ |
| 9224 | |
| 9225 | static void |
| 9226 | inherit_abstract_dies (struct die_info *die, struct dwarf2_cu *cu) |
| 9227 | { |
| 9228 | struct die_info *child_die; |
| 9229 | unsigned die_children_count; |
| 9230 | /* CU offsets which were referenced by children of the current DIE. */ |
| 9231 | sect_offset *offsets; |
| 9232 | sect_offset *offsets_end, *offsetp; |
| 9233 | /* Parent of DIE - referenced by DW_AT_abstract_origin. */ |
| 9234 | struct die_info *origin_die; |
| 9235 | /* Iterator of the ORIGIN_DIE children. */ |
| 9236 | struct die_info *origin_child_die; |
| 9237 | struct cleanup *cleanups; |
| 9238 | struct attribute *attr; |
| 9239 | struct dwarf2_cu *origin_cu; |
| 9240 | struct pending **origin_previous_list_in_scope; |
| 9241 | |
| 9242 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); |
| 9243 | if (!attr) |
| 9244 | return; |
| 9245 | |
| 9246 | /* Note that following die references may follow to a die in a |
| 9247 | different cu. */ |
| 9248 | |
| 9249 | origin_cu = cu; |
| 9250 | origin_die = follow_die_ref (die, attr, &origin_cu); |
| 9251 | |
| 9252 | /* We're inheriting ORIGIN's children into the scope we'd put DIE's |
| 9253 | symbols in. */ |
| 9254 | origin_previous_list_in_scope = origin_cu->list_in_scope; |
| 9255 | origin_cu->list_in_scope = cu->list_in_scope; |
| 9256 | |
| 9257 | if (die->tag != origin_die->tag |
| 9258 | && !(die->tag == DW_TAG_inlined_subroutine |
| 9259 | && origin_die->tag == DW_TAG_subprogram)) |
| 9260 | complaint (&symfile_complaints, |
| 9261 | _("DIE 0x%x and its abstract origin 0x%x have different tags"), |
| 9262 | die->offset.sect_off, origin_die->offset.sect_off); |
| 9263 | |
| 9264 | child_die = die->child; |
| 9265 | die_children_count = 0; |
| 9266 | while (child_die && child_die->tag) |
| 9267 | { |
| 9268 | child_die = sibling_die (child_die); |
| 9269 | die_children_count++; |
| 9270 | } |
| 9271 | offsets = xmalloc (sizeof (*offsets) * die_children_count); |
| 9272 | cleanups = make_cleanup (xfree, offsets); |
| 9273 | |
| 9274 | offsets_end = offsets; |
| 9275 | child_die = die->child; |
| 9276 | while (child_die && child_die->tag) |
| 9277 | { |
| 9278 | /* For each CHILD_DIE, find the corresponding child of |
| 9279 | ORIGIN_DIE. If there is more than one layer of |
| 9280 | DW_AT_abstract_origin, follow them all; there shouldn't be, |
| 9281 | but GCC versions at least through 4.4 generate this (GCC PR |
| 9282 | 40573). */ |
| 9283 | struct die_info *child_origin_die = child_die; |
| 9284 | struct dwarf2_cu *child_origin_cu = cu; |
| 9285 | |
| 9286 | while (1) |
| 9287 | { |
| 9288 | attr = dwarf2_attr (child_origin_die, DW_AT_abstract_origin, |
| 9289 | child_origin_cu); |
| 9290 | if (attr == NULL) |
| 9291 | break; |
| 9292 | child_origin_die = follow_die_ref (child_origin_die, attr, |
| 9293 | &child_origin_cu); |
| 9294 | } |
| 9295 | |
| 9296 | /* According to DWARF3 3.3.8.2 #3 new entries without their abstract |
| 9297 | counterpart may exist. */ |
| 9298 | if (child_origin_die != child_die) |
| 9299 | { |
| 9300 | if (child_die->tag != child_origin_die->tag |
| 9301 | && !(child_die->tag == DW_TAG_inlined_subroutine |
| 9302 | && child_origin_die->tag == DW_TAG_subprogram)) |
| 9303 | complaint (&symfile_complaints, |
| 9304 | _("Child DIE 0x%x and its abstract origin 0x%x have " |
| 9305 | "different tags"), child_die->offset.sect_off, |
| 9306 | child_origin_die->offset.sect_off); |
| 9307 | if (child_origin_die->parent != origin_die) |
| 9308 | complaint (&symfile_complaints, |
| 9309 | _("Child DIE 0x%x and its abstract origin 0x%x have " |
| 9310 | "different parents"), child_die->offset.sect_off, |
| 9311 | child_origin_die->offset.sect_off); |
| 9312 | else |
| 9313 | *offsets_end++ = child_origin_die->offset; |
| 9314 | } |
| 9315 | child_die = sibling_die (child_die); |
| 9316 | } |
| 9317 | qsort (offsets, offsets_end - offsets, sizeof (*offsets), |
| 9318 | unsigned_int_compar); |
| 9319 | for (offsetp = offsets + 1; offsetp < offsets_end; offsetp++) |
| 9320 | if (offsetp[-1].sect_off == offsetp->sect_off) |
| 9321 | complaint (&symfile_complaints, |
| 9322 | _("Multiple children of DIE 0x%x refer " |
| 9323 | "to DIE 0x%x as their abstract origin"), |
| 9324 | die->offset.sect_off, offsetp->sect_off); |
| 9325 | |
| 9326 | offsetp = offsets; |
| 9327 | origin_child_die = origin_die->child; |
| 9328 | while (origin_child_die && origin_child_die->tag) |
| 9329 | { |
| 9330 | /* Is ORIGIN_CHILD_DIE referenced by any of the DIE children? */ |
| 9331 | while (offsetp < offsets_end |
| 9332 | && offsetp->sect_off < origin_child_die->offset.sect_off) |
| 9333 | offsetp++; |
| 9334 | if (offsetp >= offsets_end |
| 9335 | || offsetp->sect_off > origin_child_die->offset.sect_off) |
| 9336 | { |
| 9337 | /* Found that ORIGIN_CHILD_DIE is really not referenced. */ |
| 9338 | process_die (origin_child_die, origin_cu); |
| 9339 | } |
| 9340 | origin_child_die = sibling_die (origin_child_die); |
| 9341 | } |
| 9342 | origin_cu->list_in_scope = origin_previous_list_in_scope; |
| 9343 | |
| 9344 | do_cleanups (cleanups); |
| 9345 | } |
| 9346 | |
| 9347 | static void |
| 9348 | read_func_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 9349 | { |
| 9350 | struct objfile *objfile = cu->objfile; |
| 9351 | struct context_stack *new; |
| 9352 | CORE_ADDR lowpc; |
| 9353 | CORE_ADDR highpc; |
| 9354 | struct die_info *child_die; |
| 9355 | struct attribute *attr, *call_line, *call_file; |
| 9356 | char *name; |
| 9357 | CORE_ADDR baseaddr; |
| 9358 | struct block *block; |
| 9359 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
| 9360 | VEC (symbolp) *template_args = NULL; |
| 9361 | struct template_symbol *templ_func = NULL; |
| 9362 | |
| 9363 | if (inlined_func) |
| 9364 | { |
| 9365 | /* If we do not have call site information, we can't show the |
| 9366 | caller of this inlined function. That's too confusing, so |
| 9367 | only use the scope for local variables. */ |
| 9368 | call_line = dwarf2_attr (die, DW_AT_call_line, cu); |
| 9369 | call_file = dwarf2_attr (die, DW_AT_call_file, cu); |
| 9370 | if (call_line == NULL || call_file == NULL) |
| 9371 | { |
| 9372 | read_lexical_block_scope (die, cu); |
| 9373 | return; |
| 9374 | } |
| 9375 | } |
| 9376 | |
| 9377 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 9378 | |
| 9379 | name = dwarf2_name (die, cu); |
| 9380 | |
| 9381 | /* Ignore functions with missing or empty names. These are actually |
| 9382 | illegal according to the DWARF standard. */ |
| 9383 | if (name == NULL) |
| 9384 | { |
| 9385 | complaint (&symfile_complaints, |
| 9386 | _("missing name for subprogram DIE at %d"), |
| 9387 | die->offset.sect_off); |
| 9388 | return; |
| 9389 | } |
| 9390 | |
| 9391 | /* Ignore functions with missing or invalid low and high pc attributes. */ |
| 9392 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
| 9393 | { |
| 9394 | attr = dwarf2_attr (die, DW_AT_external, cu); |
| 9395 | if (!attr || !DW_UNSND (attr)) |
| 9396 | complaint (&symfile_complaints, |
| 9397 | _("cannot get low and high bounds " |
| 9398 | "for subprogram DIE at %d"), |
| 9399 | die->offset.sect_off); |
| 9400 | return; |
| 9401 | } |
| 9402 | |
| 9403 | lowpc += baseaddr; |
| 9404 | highpc += baseaddr; |
| 9405 | |
| 9406 | /* If we have any template arguments, then we must allocate a |
| 9407 | different sort of symbol. */ |
| 9408 | for (child_die = die->child; child_die; child_die = sibling_die (child_die)) |
| 9409 | { |
| 9410 | if (child_die->tag == DW_TAG_template_type_param |
| 9411 | || child_die->tag == DW_TAG_template_value_param) |
| 9412 | { |
| 9413 | templ_func = OBSTACK_ZALLOC (&objfile->objfile_obstack, |
| 9414 | struct template_symbol); |
| 9415 | templ_func->base.is_cplus_template_function = 1; |
| 9416 | break; |
| 9417 | } |
| 9418 | } |
| 9419 | |
| 9420 | new = push_context (0, lowpc); |
| 9421 | new->name = new_symbol_full (die, read_type_die (die, cu), cu, |
| 9422 | (struct symbol *) templ_func); |
| 9423 | |
| 9424 | /* If there is a location expression for DW_AT_frame_base, record |
| 9425 | it. */ |
| 9426 | attr = dwarf2_attr (die, DW_AT_frame_base, cu); |
| 9427 | if (attr) |
| 9428 | /* FIXME: cagney/2004-01-26: The DW_AT_frame_base's location |
| 9429 | expression is being recorded directly in the function's symbol |
| 9430 | and not in a separate frame-base object. I guess this hack is |
| 9431 | to avoid adding some sort of frame-base adjunct/annex to the |
| 9432 | function's symbol :-(. The problem with doing this is that it |
| 9433 | results in a function symbol with a location expression that |
| 9434 | has nothing to do with the location of the function, ouch! The |
| 9435 | relationship should be: a function's symbol has-a frame base; a |
| 9436 | frame-base has-a location expression. */ |
| 9437 | dwarf2_symbol_mark_computed (attr, new->name, cu); |
| 9438 | |
| 9439 | cu->list_in_scope = &local_symbols; |
| 9440 | |
| 9441 | if (die->child != NULL) |
| 9442 | { |
| 9443 | child_die = die->child; |
| 9444 | while (child_die && child_die->tag) |
| 9445 | { |
| 9446 | if (child_die->tag == DW_TAG_template_type_param |
| 9447 | || child_die->tag == DW_TAG_template_value_param) |
| 9448 | { |
| 9449 | struct symbol *arg = new_symbol (child_die, NULL, cu); |
| 9450 | |
| 9451 | if (arg != NULL) |
| 9452 | VEC_safe_push (symbolp, template_args, arg); |
| 9453 | } |
| 9454 | else |
| 9455 | process_die (child_die, cu); |
| 9456 | child_die = sibling_die (child_die); |
| 9457 | } |
| 9458 | } |
| 9459 | |
| 9460 | inherit_abstract_dies (die, cu); |
| 9461 | |
| 9462 | /* If we have a DW_AT_specification, we might need to import using |
| 9463 | directives from the context of the specification DIE. See the |
| 9464 | comment in determine_prefix. */ |
| 9465 | if (cu->language == language_cplus |
| 9466 | && dwarf2_attr (die, DW_AT_specification, cu)) |
| 9467 | { |
| 9468 | struct dwarf2_cu *spec_cu = cu; |
| 9469 | struct die_info *spec_die = die_specification (die, &spec_cu); |
| 9470 | |
| 9471 | while (spec_die) |
| 9472 | { |
| 9473 | child_die = spec_die->child; |
| 9474 | while (child_die && child_die->tag) |
| 9475 | { |
| 9476 | if (child_die->tag == DW_TAG_imported_module) |
| 9477 | process_die (child_die, spec_cu); |
| 9478 | child_die = sibling_die (child_die); |
| 9479 | } |
| 9480 | |
| 9481 | /* In some cases, GCC generates specification DIEs that |
| 9482 | themselves contain DW_AT_specification attributes. */ |
| 9483 | spec_die = die_specification (spec_die, &spec_cu); |
| 9484 | } |
| 9485 | } |
| 9486 | |
| 9487 | new = pop_context (); |
| 9488 | /* Make a block for the local symbols within. */ |
| 9489 | block = finish_block (new->name, &local_symbols, new->old_blocks, |
| 9490 | lowpc, highpc, objfile); |
| 9491 | |
| 9492 | /* For C++, set the block's scope. */ |
| 9493 | if (cu->language == language_cplus || cu->language == language_fortran) |
| 9494 | cp_set_block_scope (new->name, block, &objfile->objfile_obstack, |
| 9495 | determine_prefix (die, cu), |
| 9496 | processing_has_namespace_info); |
| 9497 | |
| 9498 | /* If we have address ranges, record them. */ |
| 9499 | dwarf2_record_block_ranges (die, block, baseaddr, cu); |
| 9500 | |
| 9501 | /* Attach template arguments to function. */ |
| 9502 | if (! VEC_empty (symbolp, template_args)) |
| 9503 | { |
| 9504 | gdb_assert (templ_func != NULL); |
| 9505 | |
| 9506 | templ_func->n_template_arguments = VEC_length (symbolp, template_args); |
| 9507 | templ_func->template_arguments |
| 9508 | = obstack_alloc (&objfile->objfile_obstack, |
| 9509 | (templ_func->n_template_arguments |
| 9510 | * sizeof (struct symbol *))); |
| 9511 | memcpy (templ_func->template_arguments, |
| 9512 | VEC_address (symbolp, template_args), |
| 9513 | (templ_func->n_template_arguments * sizeof (struct symbol *))); |
| 9514 | VEC_free (symbolp, template_args); |
| 9515 | } |
| 9516 | |
| 9517 | /* In C++, we can have functions nested inside functions (e.g., when |
| 9518 | a function declares a class that has methods). This means that |
| 9519 | when we finish processing a function scope, we may need to go |
| 9520 | back to building a containing block's symbol lists. */ |
| 9521 | local_symbols = new->locals; |
| 9522 | using_directives = new->using_directives; |
| 9523 | |
| 9524 | /* If we've finished processing a top-level function, subsequent |
| 9525 | symbols go in the file symbol list. */ |
| 9526 | if (outermost_context_p ()) |
| 9527 | cu->list_in_scope = &file_symbols; |
| 9528 | } |
| 9529 | |
| 9530 | /* Process all the DIES contained within a lexical block scope. Start |
| 9531 | a new scope, process the dies, and then close the scope. */ |
| 9532 | |
| 9533 | static void |
| 9534 | read_lexical_block_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 9535 | { |
| 9536 | struct objfile *objfile = cu->objfile; |
| 9537 | struct context_stack *new; |
| 9538 | CORE_ADDR lowpc, highpc; |
| 9539 | struct die_info *child_die; |
| 9540 | CORE_ADDR baseaddr; |
| 9541 | |
| 9542 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 9543 | |
| 9544 | /* Ignore blocks with missing or invalid low and high pc attributes. */ |
| 9545 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
| 9546 | as multiple lexical blocks? Handling children in a sane way would |
| 9547 | be nasty. Might be easier to properly extend generic blocks to |
| 9548 | describe ranges. */ |
| 9549 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, cu, NULL)) |
| 9550 | return; |
| 9551 | lowpc += baseaddr; |
| 9552 | highpc += baseaddr; |
| 9553 | |
| 9554 | push_context (0, lowpc); |
| 9555 | if (die->child != NULL) |
| 9556 | { |
| 9557 | child_die = die->child; |
| 9558 | while (child_die && child_die->tag) |
| 9559 | { |
| 9560 | process_die (child_die, cu); |
| 9561 | child_die = sibling_die (child_die); |
| 9562 | } |
| 9563 | } |
| 9564 | new = pop_context (); |
| 9565 | |
| 9566 | if (local_symbols != NULL || using_directives != NULL) |
| 9567 | { |
| 9568 | struct block *block |
| 9569 | = finish_block (0, &local_symbols, new->old_blocks, new->start_addr, |
| 9570 | highpc, objfile); |
| 9571 | |
| 9572 | /* Note that recording ranges after traversing children, as we |
| 9573 | do here, means that recording a parent's ranges entails |
| 9574 | walking across all its children's ranges as they appear in |
| 9575 | the address map, which is quadratic behavior. |
| 9576 | |
| 9577 | It would be nicer to record the parent's ranges before |
| 9578 | traversing its children, simply overriding whatever you find |
| 9579 | there. But since we don't even decide whether to create a |
| 9580 | block until after we've traversed its children, that's hard |
| 9581 | to do. */ |
| 9582 | dwarf2_record_block_ranges (die, block, baseaddr, cu); |
| 9583 | } |
| 9584 | local_symbols = new->locals; |
| 9585 | using_directives = new->using_directives; |
| 9586 | } |
| 9587 | |
| 9588 | /* Read in DW_TAG_GNU_call_site and insert it to CU->call_site_htab. */ |
| 9589 | |
| 9590 | static void |
| 9591 | read_call_site_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 9592 | { |
| 9593 | struct objfile *objfile = cu->objfile; |
| 9594 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 9595 | CORE_ADDR pc, baseaddr; |
| 9596 | struct attribute *attr; |
| 9597 | struct call_site *call_site, call_site_local; |
| 9598 | void **slot; |
| 9599 | int nparams; |
| 9600 | struct die_info *child_die; |
| 9601 | |
| 9602 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 9603 | |
| 9604 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 9605 | if (!attr) |
| 9606 | { |
| 9607 | complaint (&symfile_complaints, |
| 9608 | _("missing DW_AT_low_pc for DW_TAG_GNU_call_site " |
| 9609 | "DIE 0x%x [in module %s]"), |
| 9610 | die->offset.sect_off, objfile->name); |
| 9611 | return; |
| 9612 | } |
| 9613 | pc = DW_ADDR (attr) + baseaddr; |
| 9614 | |
| 9615 | if (cu->call_site_htab == NULL) |
| 9616 | cu->call_site_htab = htab_create_alloc_ex (16, core_addr_hash, core_addr_eq, |
| 9617 | NULL, &objfile->objfile_obstack, |
| 9618 | hashtab_obstack_allocate, NULL); |
| 9619 | call_site_local.pc = pc; |
| 9620 | slot = htab_find_slot (cu->call_site_htab, &call_site_local, INSERT); |
| 9621 | if (*slot != NULL) |
| 9622 | { |
| 9623 | complaint (&symfile_complaints, |
| 9624 | _("Duplicate PC %s for DW_TAG_GNU_call_site " |
| 9625 | "DIE 0x%x [in module %s]"), |
| 9626 | paddress (gdbarch, pc), die->offset.sect_off, objfile->name); |
| 9627 | return; |
| 9628 | } |
| 9629 | |
| 9630 | /* Count parameters at the caller. */ |
| 9631 | |
| 9632 | nparams = 0; |
| 9633 | for (child_die = die->child; child_die && child_die->tag; |
| 9634 | child_die = sibling_die (child_die)) |
| 9635 | { |
| 9636 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) |
| 9637 | { |
| 9638 | complaint (&symfile_complaints, |
| 9639 | _("Tag %d is not DW_TAG_GNU_call_site_parameter in " |
| 9640 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 9641 | child_die->tag, child_die->offset.sect_off, objfile->name); |
| 9642 | continue; |
| 9643 | } |
| 9644 | |
| 9645 | nparams++; |
| 9646 | } |
| 9647 | |
| 9648 | call_site = obstack_alloc (&objfile->objfile_obstack, |
| 9649 | (sizeof (*call_site) |
| 9650 | + (sizeof (*call_site->parameter) |
| 9651 | * (nparams - 1)))); |
| 9652 | *slot = call_site; |
| 9653 | memset (call_site, 0, sizeof (*call_site) - sizeof (*call_site->parameter)); |
| 9654 | call_site->pc = pc; |
| 9655 | |
| 9656 | if (dwarf2_flag_true_p (die, DW_AT_GNU_tail_call, cu)) |
| 9657 | { |
| 9658 | struct die_info *func_die; |
| 9659 | |
| 9660 | /* Skip also over DW_TAG_inlined_subroutine. */ |
| 9661 | for (func_die = die->parent; |
| 9662 | func_die && func_die->tag != DW_TAG_subprogram |
| 9663 | && func_die->tag != DW_TAG_subroutine_type; |
| 9664 | func_die = func_die->parent); |
| 9665 | |
| 9666 | /* DW_AT_GNU_all_call_sites is a superset |
| 9667 | of DW_AT_GNU_all_tail_call_sites. */ |
| 9668 | if (func_die |
| 9669 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_call_sites, cu) |
| 9670 | && !dwarf2_flag_true_p (func_die, DW_AT_GNU_all_tail_call_sites, cu)) |
| 9671 | { |
| 9672 | /* TYPE_TAIL_CALL_LIST is not interesting in functions where it is |
| 9673 | not complete. But keep CALL_SITE for look ups via call_site_htab, |
| 9674 | both the initial caller containing the real return address PC and |
| 9675 | the final callee containing the current PC of a chain of tail |
| 9676 | calls do not need to have the tail call list complete. But any |
| 9677 | function candidate for a virtual tail call frame searched via |
| 9678 | TYPE_TAIL_CALL_LIST must have the tail call list complete to be |
| 9679 | determined unambiguously. */ |
| 9680 | } |
| 9681 | else |
| 9682 | { |
| 9683 | struct type *func_type = NULL; |
| 9684 | |
| 9685 | if (func_die) |
| 9686 | func_type = get_die_type (func_die, cu); |
| 9687 | if (func_type != NULL) |
| 9688 | { |
| 9689 | gdb_assert (TYPE_CODE (func_type) == TYPE_CODE_FUNC); |
| 9690 | |
| 9691 | /* Enlist this call site to the function. */ |
| 9692 | call_site->tail_call_next = TYPE_TAIL_CALL_LIST (func_type); |
| 9693 | TYPE_TAIL_CALL_LIST (func_type) = call_site; |
| 9694 | } |
| 9695 | else |
| 9696 | complaint (&symfile_complaints, |
| 9697 | _("Cannot find function owning DW_TAG_GNU_call_site " |
| 9698 | "DIE 0x%x [in module %s]"), |
| 9699 | die->offset.sect_off, objfile->name); |
| 9700 | } |
| 9701 | } |
| 9702 | |
| 9703 | attr = dwarf2_attr (die, DW_AT_GNU_call_site_target, cu); |
| 9704 | if (attr == NULL) |
| 9705 | attr = dwarf2_attr (die, DW_AT_abstract_origin, cu); |
| 9706 | SET_FIELD_DWARF_BLOCK (call_site->target, NULL); |
| 9707 | if (!attr || (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0)) |
| 9708 | /* Keep NULL DWARF_BLOCK. */; |
| 9709 | else if (attr_form_is_block (attr)) |
| 9710 | { |
| 9711 | struct dwarf2_locexpr_baton *dlbaton; |
| 9712 | |
| 9713 | dlbaton = obstack_alloc (&objfile->objfile_obstack, sizeof (*dlbaton)); |
| 9714 | dlbaton->data = DW_BLOCK (attr)->data; |
| 9715 | dlbaton->size = DW_BLOCK (attr)->size; |
| 9716 | dlbaton->per_cu = cu->per_cu; |
| 9717 | |
| 9718 | SET_FIELD_DWARF_BLOCK (call_site->target, dlbaton); |
| 9719 | } |
| 9720 | else if (is_ref_attr (attr)) |
| 9721 | { |
| 9722 | struct dwarf2_cu *target_cu = cu; |
| 9723 | struct die_info *target_die; |
| 9724 | |
| 9725 | target_die = follow_die_ref_or_sig (die, attr, &target_cu); |
| 9726 | gdb_assert (target_cu->objfile == objfile); |
| 9727 | if (die_is_declaration (target_die, target_cu)) |
| 9728 | { |
| 9729 | const char *target_physname; |
| 9730 | |
| 9731 | target_physname = dwarf2_physname (NULL, target_die, target_cu); |
| 9732 | if (target_physname == NULL) |
| 9733 | complaint (&symfile_complaints, |
| 9734 | _("DW_AT_GNU_call_site_target target DIE has invalid " |
| 9735 | "physname, for referencing DIE 0x%x [in module %s]"), |
| 9736 | die->offset.sect_off, objfile->name); |
| 9737 | else |
| 9738 | SET_FIELD_PHYSNAME (call_site->target, (char *) target_physname); |
| 9739 | } |
| 9740 | else |
| 9741 | { |
| 9742 | CORE_ADDR lowpc; |
| 9743 | |
| 9744 | /* DW_AT_entry_pc should be preferred. */ |
| 9745 | if (!dwarf2_get_pc_bounds (target_die, &lowpc, NULL, target_cu, NULL)) |
| 9746 | complaint (&symfile_complaints, |
| 9747 | _("DW_AT_GNU_call_site_target target DIE has invalid " |
| 9748 | "low pc, for referencing DIE 0x%x [in module %s]"), |
| 9749 | die->offset.sect_off, objfile->name); |
| 9750 | else |
| 9751 | SET_FIELD_PHYSADDR (call_site->target, lowpc + baseaddr); |
| 9752 | } |
| 9753 | } |
| 9754 | else |
| 9755 | complaint (&symfile_complaints, |
| 9756 | _("DW_TAG_GNU_call_site DW_AT_GNU_call_site_target is neither " |
| 9757 | "block nor reference, for DIE 0x%x [in module %s]"), |
| 9758 | die->offset.sect_off, objfile->name); |
| 9759 | |
| 9760 | call_site->per_cu = cu->per_cu; |
| 9761 | |
| 9762 | for (child_die = die->child; |
| 9763 | child_die && child_die->tag; |
| 9764 | child_die = sibling_die (child_die)) |
| 9765 | { |
| 9766 | struct call_site_parameter *parameter; |
| 9767 | struct attribute *loc, *origin; |
| 9768 | |
| 9769 | if (child_die->tag != DW_TAG_GNU_call_site_parameter) |
| 9770 | { |
| 9771 | /* Already printed the complaint above. */ |
| 9772 | continue; |
| 9773 | } |
| 9774 | |
| 9775 | gdb_assert (call_site->parameter_count < nparams); |
| 9776 | parameter = &call_site->parameter[call_site->parameter_count]; |
| 9777 | |
| 9778 | /* DW_AT_location specifies the register number or DW_AT_abstract_origin |
| 9779 | specifies DW_TAG_formal_parameter. Value of the data assumed for the |
| 9780 | register is contained in DW_AT_GNU_call_site_value. */ |
| 9781 | |
| 9782 | loc = dwarf2_attr (child_die, DW_AT_location, cu); |
| 9783 | origin = dwarf2_attr (child_die, DW_AT_abstract_origin, cu); |
| 9784 | if (loc == NULL && origin != NULL && is_ref_attr (origin)) |
| 9785 | { |
| 9786 | sect_offset offset; |
| 9787 | |
| 9788 | parameter->kind = CALL_SITE_PARAMETER_PARAM_OFFSET; |
| 9789 | offset = dwarf2_get_ref_die_offset (origin); |
| 9790 | if (!offset_in_cu_p (&cu->header, offset)) |
| 9791 | { |
| 9792 | /* As DW_OP_GNU_parameter_ref uses CU-relative offset this |
| 9793 | binding can be done only inside one CU. Such referenced DIE |
| 9794 | therefore cannot be even moved to DW_TAG_partial_unit. */ |
| 9795 | complaint (&symfile_complaints, |
| 9796 | _("DW_AT_abstract_origin offset is not in CU for " |
| 9797 | "DW_TAG_GNU_call_site child DIE 0x%x " |
| 9798 | "[in module %s]"), |
| 9799 | child_die->offset.sect_off, objfile->name); |
| 9800 | continue; |
| 9801 | } |
| 9802 | parameter->u.param_offset.cu_off = (offset.sect_off |
| 9803 | - cu->header.offset.sect_off); |
| 9804 | } |
| 9805 | else if (loc == NULL || origin != NULL || !attr_form_is_block (loc)) |
| 9806 | { |
| 9807 | complaint (&symfile_complaints, |
| 9808 | _("No DW_FORM_block* DW_AT_location for " |
| 9809 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 9810 | child_die->offset.sect_off, objfile->name); |
| 9811 | continue; |
| 9812 | } |
| 9813 | else |
| 9814 | { |
| 9815 | parameter->u.dwarf_reg = dwarf_block_to_dwarf_reg |
| 9816 | (DW_BLOCK (loc)->data, &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size]); |
| 9817 | if (parameter->u.dwarf_reg != -1) |
| 9818 | parameter->kind = CALL_SITE_PARAMETER_DWARF_REG; |
| 9819 | else if (dwarf_block_to_sp_offset (gdbarch, DW_BLOCK (loc)->data, |
| 9820 | &DW_BLOCK (loc)->data[DW_BLOCK (loc)->size], |
| 9821 | ¶meter->u.fb_offset)) |
| 9822 | parameter->kind = CALL_SITE_PARAMETER_FB_OFFSET; |
| 9823 | else |
| 9824 | { |
| 9825 | complaint (&symfile_complaints, |
| 9826 | _("Only single DW_OP_reg or DW_OP_fbreg is supported " |
| 9827 | "for DW_FORM_block* DW_AT_location is supported for " |
| 9828 | "DW_TAG_GNU_call_site child DIE 0x%x " |
| 9829 | "[in module %s]"), |
| 9830 | child_die->offset.sect_off, objfile->name); |
| 9831 | continue; |
| 9832 | } |
| 9833 | } |
| 9834 | |
| 9835 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_value, cu); |
| 9836 | if (!attr_form_is_block (attr)) |
| 9837 | { |
| 9838 | complaint (&symfile_complaints, |
| 9839 | _("No DW_FORM_block* DW_AT_GNU_call_site_value for " |
| 9840 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 9841 | child_die->offset.sect_off, objfile->name); |
| 9842 | continue; |
| 9843 | } |
| 9844 | parameter->value = DW_BLOCK (attr)->data; |
| 9845 | parameter->value_size = DW_BLOCK (attr)->size; |
| 9846 | |
| 9847 | /* Parameters are not pre-cleared by memset above. */ |
| 9848 | parameter->data_value = NULL; |
| 9849 | parameter->data_value_size = 0; |
| 9850 | call_site->parameter_count++; |
| 9851 | |
| 9852 | attr = dwarf2_attr (child_die, DW_AT_GNU_call_site_data_value, cu); |
| 9853 | if (attr) |
| 9854 | { |
| 9855 | if (!attr_form_is_block (attr)) |
| 9856 | complaint (&symfile_complaints, |
| 9857 | _("No DW_FORM_block* DW_AT_GNU_call_site_data_value for " |
| 9858 | "DW_TAG_GNU_call_site child DIE 0x%x [in module %s]"), |
| 9859 | child_die->offset.sect_off, objfile->name); |
| 9860 | else |
| 9861 | { |
| 9862 | parameter->data_value = DW_BLOCK (attr)->data; |
| 9863 | parameter->data_value_size = DW_BLOCK (attr)->size; |
| 9864 | } |
| 9865 | } |
| 9866 | } |
| 9867 | } |
| 9868 | |
| 9869 | /* Get low and high pc attributes from DW_AT_ranges attribute value OFFSET. |
| 9870 | Return 1 if the attributes are present and valid, otherwise, return 0. |
| 9871 | If RANGES_PST is not NULL we should setup `objfile->psymtabs_addrmap'. */ |
| 9872 | |
| 9873 | static int |
| 9874 | dwarf2_ranges_read (unsigned offset, CORE_ADDR *low_return, |
| 9875 | CORE_ADDR *high_return, struct dwarf2_cu *cu, |
| 9876 | struct partial_symtab *ranges_pst) |
| 9877 | { |
| 9878 | struct objfile *objfile = cu->objfile; |
| 9879 | struct comp_unit_head *cu_header = &cu->header; |
| 9880 | bfd *obfd = objfile->obfd; |
| 9881 | unsigned int addr_size = cu_header->addr_size; |
| 9882 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 9883 | /* Base address selection entry. */ |
| 9884 | CORE_ADDR base; |
| 9885 | int found_base; |
| 9886 | unsigned int dummy; |
| 9887 | gdb_byte *buffer; |
| 9888 | CORE_ADDR marker; |
| 9889 | int low_set; |
| 9890 | CORE_ADDR low = 0; |
| 9891 | CORE_ADDR high = 0; |
| 9892 | CORE_ADDR baseaddr; |
| 9893 | |
| 9894 | found_base = cu->base_known; |
| 9895 | base = cu->base_address; |
| 9896 | |
| 9897 | dwarf2_read_section (objfile, &dwarf2_per_objfile->ranges); |
| 9898 | if (offset >= dwarf2_per_objfile->ranges.size) |
| 9899 | { |
| 9900 | complaint (&symfile_complaints, |
| 9901 | _("Offset %d out of bounds for DW_AT_ranges attribute"), |
| 9902 | offset); |
| 9903 | return 0; |
| 9904 | } |
| 9905 | buffer = dwarf2_per_objfile->ranges.buffer + offset; |
| 9906 | |
| 9907 | /* Read in the largest possible address. */ |
| 9908 | marker = read_address (obfd, buffer, cu, &dummy); |
| 9909 | if ((marker & mask) == mask) |
| 9910 | { |
| 9911 | /* If we found the largest possible address, then |
| 9912 | read the base address. */ |
| 9913 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
| 9914 | buffer += 2 * addr_size; |
| 9915 | offset += 2 * addr_size; |
| 9916 | found_base = 1; |
| 9917 | } |
| 9918 | |
| 9919 | low_set = 0; |
| 9920 | |
| 9921 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 9922 | |
| 9923 | while (1) |
| 9924 | { |
| 9925 | CORE_ADDR range_beginning, range_end; |
| 9926 | |
| 9927 | range_beginning = read_address (obfd, buffer, cu, &dummy); |
| 9928 | buffer += addr_size; |
| 9929 | range_end = read_address (obfd, buffer, cu, &dummy); |
| 9930 | buffer += addr_size; |
| 9931 | offset += 2 * addr_size; |
| 9932 | |
| 9933 | /* An end of list marker is a pair of zero addresses. */ |
| 9934 | if (range_beginning == 0 && range_end == 0) |
| 9935 | /* Found the end of list entry. */ |
| 9936 | break; |
| 9937 | |
| 9938 | /* Each base address selection entry is a pair of 2 values. |
| 9939 | The first is the largest possible address, the second is |
| 9940 | the base address. Check for a base address here. */ |
| 9941 | if ((range_beginning & mask) == mask) |
| 9942 | { |
| 9943 | /* If we found the largest possible address, then |
| 9944 | read the base address. */ |
| 9945 | base = read_address (obfd, buffer + addr_size, cu, &dummy); |
| 9946 | found_base = 1; |
| 9947 | continue; |
| 9948 | } |
| 9949 | |
| 9950 | if (!found_base) |
| 9951 | { |
| 9952 | /* We have no valid base address for the ranges |
| 9953 | data. */ |
| 9954 | complaint (&symfile_complaints, |
| 9955 | _("Invalid .debug_ranges data (no base address)")); |
| 9956 | return 0; |
| 9957 | } |
| 9958 | |
| 9959 | if (range_beginning > range_end) |
| 9960 | { |
| 9961 | /* Inverted range entries are invalid. */ |
| 9962 | complaint (&symfile_complaints, |
| 9963 | _("Invalid .debug_ranges data (inverted range)")); |
| 9964 | return 0; |
| 9965 | } |
| 9966 | |
| 9967 | /* Empty range entries have no effect. */ |
| 9968 | if (range_beginning == range_end) |
| 9969 | continue; |
| 9970 | |
| 9971 | range_beginning += base; |
| 9972 | range_end += base; |
| 9973 | |
| 9974 | /* A not-uncommon case of bad debug info. |
| 9975 | Don't pollute the addrmap with bad data. */ |
| 9976 | if (range_beginning + baseaddr == 0 |
| 9977 | && !dwarf2_per_objfile->has_section_at_zero) |
| 9978 | { |
| 9979 | complaint (&symfile_complaints, |
| 9980 | _(".debug_ranges entry has start address of zero" |
| 9981 | " [in module %s]"), objfile->name); |
| 9982 | continue; |
| 9983 | } |
| 9984 | |
| 9985 | if (ranges_pst != NULL) |
| 9986 | addrmap_set_empty (objfile->psymtabs_addrmap, |
| 9987 | range_beginning + baseaddr, |
| 9988 | range_end - 1 + baseaddr, |
| 9989 | ranges_pst); |
| 9990 | |
| 9991 | /* FIXME: This is recording everything as a low-high |
| 9992 | segment of consecutive addresses. We should have a |
| 9993 | data structure for discontiguous block ranges |
| 9994 | instead. */ |
| 9995 | if (! low_set) |
| 9996 | { |
| 9997 | low = range_beginning; |
| 9998 | high = range_end; |
| 9999 | low_set = 1; |
| 10000 | } |
| 10001 | else |
| 10002 | { |
| 10003 | if (range_beginning < low) |
| 10004 | low = range_beginning; |
| 10005 | if (range_end > high) |
| 10006 | high = range_end; |
| 10007 | } |
| 10008 | } |
| 10009 | |
| 10010 | if (! low_set) |
| 10011 | /* If the first entry is an end-of-list marker, the range |
| 10012 | describes an empty scope, i.e. no instructions. */ |
| 10013 | return 0; |
| 10014 | |
| 10015 | if (low_return) |
| 10016 | *low_return = low; |
| 10017 | if (high_return) |
| 10018 | *high_return = high; |
| 10019 | return 1; |
| 10020 | } |
| 10021 | |
| 10022 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
| 10023 | are present and valid, otherwise, return 0. Return -1 if the range is |
| 10024 | discontinuous, i.e. derived from DW_AT_ranges information. */ |
| 10025 | |
| 10026 | static int |
| 10027 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
| 10028 | CORE_ADDR *highpc, struct dwarf2_cu *cu, |
| 10029 | struct partial_symtab *pst) |
| 10030 | { |
| 10031 | struct attribute *attr; |
| 10032 | struct attribute *attr_high; |
| 10033 | CORE_ADDR low = 0; |
| 10034 | CORE_ADDR high = 0; |
| 10035 | int ret = 0; |
| 10036 | |
| 10037 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
| 10038 | if (attr_high) |
| 10039 | { |
| 10040 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 10041 | if (attr) |
| 10042 | { |
| 10043 | low = DW_ADDR (attr); |
| 10044 | if (attr_high->form == DW_FORM_addr |
| 10045 | || attr_high->form == DW_FORM_GNU_addr_index) |
| 10046 | high = DW_ADDR (attr_high); |
| 10047 | else |
| 10048 | high = low + DW_UNSND (attr_high); |
| 10049 | } |
| 10050 | else |
| 10051 | /* Found high w/o low attribute. */ |
| 10052 | return 0; |
| 10053 | |
| 10054 | /* Found consecutive range of addresses. */ |
| 10055 | ret = 1; |
| 10056 | } |
| 10057 | else |
| 10058 | { |
| 10059 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
| 10060 | if (attr != NULL) |
| 10061 | { |
| 10062 | /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton. |
| 10063 | We take advantage of the fact that DW_AT_ranges does not appear |
| 10064 | in DW_TAG_compile_unit of DWO files. */ |
| 10065 | int need_ranges_base = die->tag != DW_TAG_compile_unit; |
| 10066 | unsigned int ranges_offset = (DW_UNSND (attr) |
| 10067 | + (need_ranges_base |
| 10068 | ? cu->ranges_base |
| 10069 | : 0)); |
| 10070 | |
| 10071 | /* Value of the DW_AT_ranges attribute is the offset in the |
| 10072 | .debug_ranges section. */ |
| 10073 | if (!dwarf2_ranges_read (ranges_offset, &low, &high, cu, pst)) |
| 10074 | return 0; |
| 10075 | /* Found discontinuous range of addresses. */ |
| 10076 | ret = -1; |
| 10077 | } |
| 10078 | } |
| 10079 | |
| 10080 | /* read_partial_die has also the strict LOW < HIGH requirement. */ |
| 10081 | if (high <= low) |
| 10082 | return 0; |
| 10083 | |
| 10084 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 10085 | eliminate duplicate copies of functions and vtables and such. |
| 10086 | The linker will arbitrarily choose one and discard the others. |
| 10087 | The AT_*_pc values for such functions refer to local labels in |
| 10088 | these sections. If the section from that file was discarded, the |
| 10089 | labels are not in the output, so the relocs get a value of 0. |
| 10090 | If this is a discarded function, mark the pc bounds as invalid, |
| 10091 | so that GDB will ignore it. */ |
| 10092 | if (low == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 10093 | return 0; |
| 10094 | |
| 10095 | *lowpc = low; |
| 10096 | if (highpc) |
| 10097 | *highpc = high; |
| 10098 | return ret; |
| 10099 | } |
| 10100 | |
| 10101 | /* Assuming that DIE represents a subprogram DIE or a lexical block, get |
| 10102 | its low and high PC addresses. Do nothing if these addresses could not |
| 10103 | be determined. Otherwise, set LOWPC to the low address if it is smaller, |
| 10104 | and HIGHPC to the high address if greater than HIGHPC. */ |
| 10105 | |
| 10106 | static void |
| 10107 | dwarf2_get_subprogram_pc_bounds (struct die_info *die, |
| 10108 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 10109 | struct dwarf2_cu *cu) |
| 10110 | { |
| 10111 | CORE_ADDR low, high; |
| 10112 | struct die_info *child = die->child; |
| 10113 | |
| 10114 | if (dwarf2_get_pc_bounds (die, &low, &high, cu, NULL)) |
| 10115 | { |
| 10116 | *lowpc = min (*lowpc, low); |
| 10117 | *highpc = max (*highpc, high); |
| 10118 | } |
| 10119 | |
| 10120 | /* If the language does not allow nested subprograms (either inside |
| 10121 | subprograms or lexical blocks), we're done. */ |
| 10122 | if (cu->language != language_ada) |
| 10123 | return; |
| 10124 | |
| 10125 | /* Check all the children of the given DIE. If it contains nested |
| 10126 | subprograms, then check their pc bounds. Likewise, we need to |
| 10127 | check lexical blocks as well, as they may also contain subprogram |
| 10128 | definitions. */ |
| 10129 | while (child && child->tag) |
| 10130 | { |
| 10131 | if (child->tag == DW_TAG_subprogram |
| 10132 | || child->tag == DW_TAG_lexical_block) |
| 10133 | dwarf2_get_subprogram_pc_bounds (child, lowpc, highpc, cu); |
| 10134 | child = sibling_die (child); |
| 10135 | } |
| 10136 | } |
| 10137 | |
| 10138 | /* Get the low and high pc's represented by the scope DIE, and store |
| 10139 | them in *LOWPC and *HIGHPC. If the correct values can't be |
| 10140 | determined, set *LOWPC to -1 and *HIGHPC to 0. */ |
| 10141 | |
| 10142 | static void |
| 10143 | get_scope_pc_bounds (struct die_info *die, |
| 10144 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 10145 | struct dwarf2_cu *cu) |
| 10146 | { |
| 10147 | CORE_ADDR best_low = (CORE_ADDR) -1; |
| 10148 | CORE_ADDR best_high = (CORE_ADDR) 0; |
| 10149 | CORE_ADDR current_low, current_high; |
| 10150 | |
| 10151 | if (dwarf2_get_pc_bounds (die, ¤t_low, ¤t_high, cu, NULL)) |
| 10152 | { |
| 10153 | best_low = current_low; |
| 10154 | best_high = current_high; |
| 10155 | } |
| 10156 | else |
| 10157 | { |
| 10158 | struct die_info *child = die->child; |
| 10159 | |
| 10160 | while (child && child->tag) |
| 10161 | { |
| 10162 | switch (child->tag) { |
| 10163 | case DW_TAG_subprogram: |
| 10164 | dwarf2_get_subprogram_pc_bounds (child, &best_low, &best_high, cu); |
| 10165 | break; |
| 10166 | case DW_TAG_namespace: |
| 10167 | case DW_TAG_module: |
| 10168 | /* FIXME: carlton/2004-01-16: Should we do this for |
| 10169 | DW_TAG_class_type/DW_TAG_structure_type, too? I think |
| 10170 | that current GCC's always emit the DIEs corresponding |
| 10171 | to definitions of methods of classes as children of a |
| 10172 | DW_TAG_compile_unit or DW_TAG_namespace (as opposed to |
| 10173 | the DIEs giving the declarations, which could be |
| 10174 | anywhere). But I don't see any reason why the |
| 10175 | standards says that they have to be there. */ |
| 10176 | get_scope_pc_bounds (child, ¤t_low, ¤t_high, cu); |
| 10177 | |
| 10178 | if (current_low != ((CORE_ADDR) -1)) |
| 10179 | { |
| 10180 | best_low = min (best_low, current_low); |
| 10181 | best_high = max (best_high, current_high); |
| 10182 | } |
| 10183 | break; |
| 10184 | default: |
| 10185 | /* Ignore. */ |
| 10186 | break; |
| 10187 | } |
| 10188 | |
| 10189 | child = sibling_die (child); |
| 10190 | } |
| 10191 | } |
| 10192 | |
| 10193 | *lowpc = best_low; |
| 10194 | *highpc = best_high; |
| 10195 | } |
| 10196 | |
| 10197 | /* Record the address ranges for BLOCK, offset by BASEADDR, as given |
| 10198 | in DIE. */ |
| 10199 | |
| 10200 | static void |
| 10201 | dwarf2_record_block_ranges (struct die_info *die, struct block *block, |
| 10202 | CORE_ADDR baseaddr, struct dwarf2_cu *cu) |
| 10203 | { |
| 10204 | struct objfile *objfile = cu->objfile; |
| 10205 | struct attribute *attr; |
| 10206 | struct attribute *attr_high; |
| 10207 | |
| 10208 | attr_high = dwarf2_attr (die, DW_AT_high_pc, cu); |
| 10209 | if (attr_high) |
| 10210 | { |
| 10211 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 10212 | if (attr) |
| 10213 | { |
| 10214 | CORE_ADDR low = DW_ADDR (attr); |
| 10215 | CORE_ADDR high; |
| 10216 | if (attr_high->form == DW_FORM_addr |
| 10217 | || attr_high->form == DW_FORM_GNU_addr_index) |
| 10218 | high = DW_ADDR (attr_high); |
| 10219 | else |
| 10220 | high = low + DW_UNSND (attr_high); |
| 10221 | |
| 10222 | record_block_range (block, baseaddr + low, baseaddr + high - 1); |
| 10223 | } |
| 10224 | } |
| 10225 | |
| 10226 | attr = dwarf2_attr (die, DW_AT_ranges, cu); |
| 10227 | if (attr) |
| 10228 | { |
| 10229 | bfd *obfd = objfile->obfd; |
| 10230 | /* DW_AT_ranges_base does not apply to DIEs from the DWO skeleton. |
| 10231 | We take advantage of the fact that DW_AT_ranges does not appear |
| 10232 | in DW_TAG_compile_unit of DWO files. */ |
| 10233 | int need_ranges_base = die->tag != DW_TAG_compile_unit; |
| 10234 | |
| 10235 | /* The value of the DW_AT_ranges attribute is the offset of the |
| 10236 | address range list in the .debug_ranges section. */ |
| 10237 | unsigned long offset = (DW_UNSND (attr) |
| 10238 | + (need_ranges_base ? cu->ranges_base : 0)); |
| 10239 | gdb_byte *buffer = dwarf2_per_objfile->ranges.buffer + offset; |
| 10240 | |
| 10241 | /* For some target architectures, but not others, the |
| 10242 | read_address function sign-extends the addresses it returns. |
| 10243 | To recognize base address selection entries, we need a |
| 10244 | mask. */ |
| 10245 | unsigned int addr_size = cu->header.addr_size; |
| 10246 | CORE_ADDR base_select_mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 10247 | |
| 10248 | /* The base address, to which the next pair is relative. Note |
| 10249 | that this 'base' is a DWARF concept: most entries in a range |
| 10250 | list are relative, to reduce the number of relocs against the |
| 10251 | debugging information. This is separate from this function's |
| 10252 | 'baseaddr' argument, which GDB uses to relocate debugging |
| 10253 | information from a shared library based on the address at |
| 10254 | which the library was loaded. */ |
| 10255 | CORE_ADDR base = cu->base_address; |
| 10256 | int base_known = cu->base_known; |
| 10257 | |
| 10258 | gdb_assert (dwarf2_per_objfile->ranges.readin); |
| 10259 | if (offset >= dwarf2_per_objfile->ranges.size) |
| 10260 | { |
| 10261 | complaint (&symfile_complaints, |
| 10262 | _("Offset %lu out of bounds for DW_AT_ranges attribute"), |
| 10263 | offset); |
| 10264 | return; |
| 10265 | } |
| 10266 | |
| 10267 | for (;;) |
| 10268 | { |
| 10269 | unsigned int bytes_read; |
| 10270 | CORE_ADDR start, end; |
| 10271 | |
| 10272 | start = read_address (obfd, buffer, cu, &bytes_read); |
| 10273 | buffer += bytes_read; |
| 10274 | end = read_address (obfd, buffer, cu, &bytes_read); |
| 10275 | buffer += bytes_read; |
| 10276 | |
| 10277 | /* Did we find the end of the range list? */ |
| 10278 | if (start == 0 && end == 0) |
| 10279 | break; |
| 10280 | |
| 10281 | /* Did we find a base address selection entry? */ |
| 10282 | else if ((start & base_select_mask) == base_select_mask) |
| 10283 | { |
| 10284 | base = end; |
| 10285 | base_known = 1; |
| 10286 | } |
| 10287 | |
| 10288 | /* We found an ordinary address range. */ |
| 10289 | else |
| 10290 | { |
| 10291 | if (!base_known) |
| 10292 | { |
| 10293 | complaint (&symfile_complaints, |
| 10294 | _("Invalid .debug_ranges data " |
| 10295 | "(no base address)")); |
| 10296 | return; |
| 10297 | } |
| 10298 | |
| 10299 | if (start > end) |
| 10300 | { |
| 10301 | /* Inverted range entries are invalid. */ |
| 10302 | complaint (&symfile_complaints, |
| 10303 | _("Invalid .debug_ranges data " |
| 10304 | "(inverted range)")); |
| 10305 | return; |
| 10306 | } |
| 10307 | |
| 10308 | /* Empty range entries have no effect. */ |
| 10309 | if (start == end) |
| 10310 | continue; |
| 10311 | |
| 10312 | start += base + baseaddr; |
| 10313 | end += base + baseaddr; |
| 10314 | |
| 10315 | /* A not-uncommon case of bad debug info. |
| 10316 | Don't pollute the addrmap with bad data. */ |
| 10317 | if (start == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 10318 | { |
| 10319 | complaint (&symfile_complaints, |
| 10320 | _(".debug_ranges entry has start address of zero" |
| 10321 | " [in module %s]"), objfile->name); |
| 10322 | continue; |
| 10323 | } |
| 10324 | |
| 10325 | record_block_range (block, start, end - 1); |
| 10326 | } |
| 10327 | } |
| 10328 | } |
| 10329 | } |
| 10330 | |
| 10331 | /* Check whether the producer field indicates either of GCC < 4.6, or the |
| 10332 | Intel C/C++ compiler, and cache the result in CU. */ |
| 10333 | |
| 10334 | static void |
| 10335 | check_producer (struct dwarf2_cu *cu) |
| 10336 | { |
| 10337 | const char *cs; |
| 10338 | int major, minor, release; |
| 10339 | |
| 10340 | if (cu->producer == NULL) |
| 10341 | { |
| 10342 | /* For unknown compilers expect their behavior is DWARF version |
| 10343 | compliant. |
| 10344 | |
| 10345 | GCC started to support .debug_types sections by -gdwarf-4 since |
| 10346 | gcc-4.5.x. As the .debug_types sections are missing DW_AT_producer |
| 10347 | for their space efficiency GDB cannot workaround gcc-4.5.x -gdwarf-4 |
| 10348 | combination. gcc-4.5.x -gdwarf-4 binaries have DW_AT_accessibility |
| 10349 | interpreted incorrectly by GDB now - GCC PR debug/48229. */ |
| 10350 | } |
| 10351 | else if (strncmp (cu->producer, "GNU ", strlen ("GNU ")) == 0) |
| 10352 | { |
| 10353 | /* Skip any identifier after "GNU " - such as "C++" or "Java". */ |
| 10354 | |
| 10355 | cs = &cu->producer[strlen ("GNU ")]; |
| 10356 | while (*cs && !isdigit (*cs)) |
| 10357 | cs++; |
| 10358 | if (sscanf (cs, "%d.%d.%d", &major, &minor, &release) != 3) |
| 10359 | { |
| 10360 | /* Not recognized as GCC. */ |
| 10361 | } |
| 10362 | else |
| 10363 | { |
| 10364 | cu->producer_is_gxx_lt_4_6 = major < 4 || (major == 4 && minor < 6); |
| 10365 | cu->producer_is_gcc_lt_4_3 = major < 4 || (major == 4 && minor < 3); |
| 10366 | } |
| 10367 | } |
| 10368 | else if (strncmp (cu->producer, "Intel(R) C", strlen ("Intel(R) C")) == 0) |
| 10369 | cu->producer_is_icc = 1; |
| 10370 | else |
| 10371 | { |
| 10372 | /* For other non-GCC compilers, expect their behavior is DWARF version |
| 10373 | compliant. */ |
| 10374 | } |
| 10375 | |
| 10376 | cu->checked_producer = 1; |
| 10377 | } |
| 10378 | |
| 10379 | /* Check for GCC PR debug/45124 fix which is not present in any G++ version up |
| 10380 | to 4.5.any while it is present already in G++ 4.6.0 - the PR has been fixed |
| 10381 | during 4.6.0 experimental. */ |
| 10382 | |
| 10383 | static int |
| 10384 | producer_is_gxx_lt_4_6 (struct dwarf2_cu *cu) |
| 10385 | { |
| 10386 | if (!cu->checked_producer) |
| 10387 | check_producer (cu); |
| 10388 | |
| 10389 | return cu->producer_is_gxx_lt_4_6; |
| 10390 | } |
| 10391 | |
| 10392 | /* Return the default accessibility type if it is not overriden by |
| 10393 | DW_AT_accessibility. */ |
| 10394 | |
| 10395 | static enum dwarf_access_attribute |
| 10396 | dwarf2_default_access_attribute (struct die_info *die, struct dwarf2_cu *cu) |
| 10397 | { |
| 10398 | if (cu->header.version < 3 || producer_is_gxx_lt_4_6 (cu)) |
| 10399 | { |
| 10400 | /* The default DWARF 2 accessibility for members is public, the default |
| 10401 | accessibility for inheritance is private. */ |
| 10402 | |
| 10403 | if (die->tag != DW_TAG_inheritance) |
| 10404 | return DW_ACCESS_public; |
| 10405 | else |
| 10406 | return DW_ACCESS_private; |
| 10407 | } |
| 10408 | else |
| 10409 | { |
| 10410 | /* DWARF 3+ defines the default accessibility a different way. The same |
| 10411 | rules apply now for DW_TAG_inheritance as for the members and it only |
| 10412 | depends on the container kind. */ |
| 10413 | |
| 10414 | if (die->parent->tag == DW_TAG_class_type) |
| 10415 | return DW_ACCESS_private; |
| 10416 | else |
| 10417 | return DW_ACCESS_public; |
| 10418 | } |
| 10419 | } |
| 10420 | |
| 10421 | /* Look for DW_AT_data_member_location. Set *OFFSET to the byte |
| 10422 | offset. If the attribute was not found return 0, otherwise return |
| 10423 | 1. If it was found but could not properly be handled, set *OFFSET |
| 10424 | to 0. */ |
| 10425 | |
| 10426 | static int |
| 10427 | handle_data_member_location (struct die_info *die, struct dwarf2_cu *cu, |
| 10428 | LONGEST *offset) |
| 10429 | { |
| 10430 | struct attribute *attr; |
| 10431 | |
| 10432 | attr = dwarf2_attr (die, DW_AT_data_member_location, cu); |
| 10433 | if (attr != NULL) |
| 10434 | { |
| 10435 | *offset = 0; |
| 10436 | |
| 10437 | /* Note that we do not check for a section offset first here. |
| 10438 | This is because DW_AT_data_member_location is new in DWARF 4, |
| 10439 | so if we see it, we can assume that a constant form is really |
| 10440 | a constant and not a section offset. */ |
| 10441 | if (attr_form_is_constant (attr)) |
| 10442 | *offset = dwarf2_get_attr_constant_value (attr, 0); |
| 10443 | else if (attr_form_is_section_offset (attr)) |
| 10444 | dwarf2_complex_location_expr_complaint (); |
| 10445 | else if (attr_form_is_block (attr)) |
| 10446 | *offset = decode_locdesc (DW_BLOCK (attr), cu); |
| 10447 | else |
| 10448 | dwarf2_complex_location_expr_complaint (); |
| 10449 | |
| 10450 | return 1; |
| 10451 | } |
| 10452 | |
| 10453 | return 0; |
| 10454 | } |
| 10455 | |
| 10456 | /* Add an aggregate field to the field list. */ |
| 10457 | |
| 10458 | static void |
| 10459 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
| 10460 | struct dwarf2_cu *cu) |
| 10461 | { |
| 10462 | struct objfile *objfile = cu->objfile; |
| 10463 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 10464 | struct nextfield *new_field; |
| 10465 | struct attribute *attr; |
| 10466 | struct field *fp; |
| 10467 | char *fieldname = ""; |
| 10468 | |
| 10469 | /* Allocate a new field list entry and link it in. */ |
| 10470 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 10471 | make_cleanup (xfree, new_field); |
| 10472 | memset (new_field, 0, sizeof (struct nextfield)); |
| 10473 | |
| 10474 | if (die->tag == DW_TAG_inheritance) |
| 10475 | { |
| 10476 | new_field->next = fip->baseclasses; |
| 10477 | fip->baseclasses = new_field; |
| 10478 | } |
| 10479 | else |
| 10480 | { |
| 10481 | new_field->next = fip->fields; |
| 10482 | fip->fields = new_field; |
| 10483 | } |
| 10484 | fip->nfields++; |
| 10485 | |
| 10486 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
| 10487 | if (attr) |
| 10488 | new_field->accessibility = DW_UNSND (attr); |
| 10489 | else |
| 10490 | new_field->accessibility = dwarf2_default_access_attribute (die, cu); |
| 10491 | if (new_field->accessibility != DW_ACCESS_public) |
| 10492 | fip->non_public_fields = 1; |
| 10493 | |
| 10494 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
| 10495 | if (attr) |
| 10496 | new_field->virtuality = DW_UNSND (attr); |
| 10497 | else |
| 10498 | new_field->virtuality = DW_VIRTUALITY_none; |
| 10499 | |
| 10500 | fp = &new_field->field; |
| 10501 | |
| 10502 | if (die->tag == DW_TAG_member && ! die_is_declaration (die, cu)) |
| 10503 | { |
| 10504 | LONGEST offset; |
| 10505 | |
| 10506 | /* Data member other than a C++ static data member. */ |
| 10507 | |
| 10508 | /* Get type of field. */ |
| 10509 | fp->type = die_type (die, cu); |
| 10510 | |
| 10511 | SET_FIELD_BITPOS (*fp, 0); |
| 10512 | |
| 10513 | /* Get bit size of field (zero if none). */ |
| 10514 | attr = dwarf2_attr (die, DW_AT_bit_size, cu); |
| 10515 | if (attr) |
| 10516 | { |
| 10517 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); |
| 10518 | } |
| 10519 | else |
| 10520 | { |
| 10521 | FIELD_BITSIZE (*fp) = 0; |
| 10522 | } |
| 10523 | |
| 10524 | /* Get bit offset of field. */ |
| 10525 | if (handle_data_member_location (die, cu, &offset)) |
| 10526 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); |
| 10527 | attr = dwarf2_attr (die, DW_AT_bit_offset, cu); |
| 10528 | if (attr) |
| 10529 | { |
| 10530 | if (gdbarch_bits_big_endian (gdbarch)) |
| 10531 | { |
| 10532 | /* For big endian bits, the DW_AT_bit_offset gives the |
| 10533 | additional bit offset from the MSB of the containing |
| 10534 | anonymous object to the MSB of the field. We don't |
| 10535 | have to do anything special since we don't need to |
| 10536 | know the size of the anonymous object. */ |
| 10537 | SET_FIELD_BITPOS (*fp, FIELD_BITPOS (*fp) + DW_UNSND (attr)); |
| 10538 | } |
| 10539 | else |
| 10540 | { |
| 10541 | /* For little endian bits, compute the bit offset to the |
| 10542 | MSB of the anonymous object, subtract off the number of |
| 10543 | bits from the MSB of the field to the MSB of the |
| 10544 | object, and then subtract off the number of bits of |
| 10545 | the field itself. The result is the bit offset of |
| 10546 | the LSB of the field. */ |
| 10547 | int anonymous_size; |
| 10548 | int bit_offset = DW_UNSND (attr); |
| 10549 | |
| 10550 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 10551 | if (attr) |
| 10552 | { |
| 10553 | /* The size of the anonymous object containing |
| 10554 | the bit field is explicit, so use the |
| 10555 | indicated size (in bytes). */ |
| 10556 | anonymous_size = DW_UNSND (attr); |
| 10557 | } |
| 10558 | else |
| 10559 | { |
| 10560 | /* The size of the anonymous object containing |
| 10561 | the bit field must be inferred from the type |
| 10562 | attribute of the data member containing the |
| 10563 | bit field. */ |
| 10564 | anonymous_size = TYPE_LENGTH (fp->type); |
| 10565 | } |
| 10566 | SET_FIELD_BITPOS (*fp, |
| 10567 | (FIELD_BITPOS (*fp) |
| 10568 | + anonymous_size * bits_per_byte |
| 10569 | - bit_offset - FIELD_BITSIZE (*fp))); |
| 10570 | } |
| 10571 | } |
| 10572 | |
| 10573 | /* Get name of field. */ |
| 10574 | fieldname = dwarf2_name (die, cu); |
| 10575 | if (fieldname == NULL) |
| 10576 | fieldname = ""; |
| 10577 | |
| 10578 | /* The name is already allocated along with this objfile, so we don't |
| 10579 | need to duplicate it for the type. */ |
| 10580 | fp->name = fieldname; |
| 10581 | |
| 10582 | /* Change accessibility for artificial fields (e.g. virtual table |
| 10583 | pointer or virtual base class pointer) to private. */ |
| 10584 | if (dwarf2_attr (die, DW_AT_artificial, cu)) |
| 10585 | { |
| 10586 | FIELD_ARTIFICIAL (*fp) = 1; |
| 10587 | new_field->accessibility = DW_ACCESS_private; |
| 10588 | fip->non_public_fields = 1; |
| 10589 | } |
| 10590 | } |
| 10591 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
| 10592 | { |
| 10593 | /* C++ static member. */ |
| 10594 | |
| 10595 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that |
| 10596 | is a declaration, but all versions of G++ as of this writing |
| 10597 | (so through at least 3.2.1) incorrectly generate |
| 10598 | DW_TAG_variable tags. */ |
| 10599 | |
| 10600 | const char *physname; |
| 10601 | |
| 10602 | /* Get name of field. */ |
| 10603 | fieldname = dwarf2_name (die, cu); |
| 10604 | if (fieldname == NULL) |
| 10605 | return; |
| 10606 | |
| 10607 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 10608 | if (attr |
| 10609 | /* Only create a symbol if this is an external value. |
| 10610 | new_symbol checks this and puts the value in the global symbol |
| 10611 | table, which we want. If it is not external, new_symbol |
| 10612 | will try to put the value in cu->list_in_scope which is wrong. */ |
| 10613 | && dwarf2_flag_true_p (die, DW_AT_external, cu)) |
| 10614 | { |
| 10615 | /* A static const member, not much different than an enum as far as |
| 10616 | we're concerned, except that we can support more types. */ |
| 10617 | new_symbol (die, NULL, cu); |
| 10618 | } |
| 10619 | |
| 10620 | /* Get physical name. */ |
| 10621 | physname = dwarf2_physname (fieldname, die, cu); |
| 10622 | |
| 10623 | /* The name is already allocated along with this objfile, so we don't |
| 10624 | need to duplicate it for the type. */ |
| 10625 | SET_FIELD_PHYSNAME (*fp, physname ? physname : ""); |
| 10626 | FIELD_TYPE (*fp) = die_type (die, cu); |
| 10627 | FIELD_NAME (*fp) = fieldname; |
| 10628 | } |
| 10629 | else if (die->tag == DW_TAG_inheritance) |
| 10630 | { |
| 10631 | LONGEST offset; |
| 10632 | |
| 10633 | /* C++ base class field. */ |
| 10634 | if (handle_data_member_location (die, cu, &offset)) |
| 10635 | SET_FIELD_BITPOS (*fp, offset * bits_per_byte); |
| 10636 | FIELD_BITSIZE (*fp) = 0; |
| 10637 | FIELD_TYPE (*fp) = die_type (die, cu); |
| 10638 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
| 10639 | fip->nbaseclasses++; |
| 10640 | } |
| 10641 | } |
| 10642 | |
| 10643 | /* Add a typedef defined in the scope of the FIP's class. */ |
| 10644 | |
| 10645 | static void |
| 10646 | dwarf2_add_typedef (struct field_info *fip, struct die_info *die, |
| 10647 | struct dwarf2_cu *cu) |
| 10648 | { |
| 10649 | struct objfile *objfile = cu->objfile; |
| 10650 | struct typedef_field_list *new_field; |
| 10651 | struct attribute *attr; |
| 10652 | struct typedef_field *fp; |
| 10653 | char *fieldname = ""; |
| 10654 | |
| 10655 | /* Allocate a new field list entry and link it in. */ |
| 10656 | new_field = xzalloc (sizeof (*new_field)); |
| 10657 | make_cleanup (xfree, new_field); |
| 10658 | |
| 10659 | gdb_assert (die->tag == DW_TAG_typedef); |
| 10660 | |
| 10661 | fp = &new_field->field; |
| 10662 | |
| 10663 | /* Get name of field. */ |
| 10664 | fp->name = dwarf2_name (die, cu); |
| 10665 | if (fp->name == NULL) |
| 10666 | return; |
| 10667 | |
| 10668 | fp->type = read_type_die (die, cu); |
| 10669 | |
| 10670 | new_field->next = fip->typedef_field_list; |
| 10671 | fip->typedef_field_list = new_field; |
| 10672 | fip->typedef_field_list_count++; |
| 10673 | } |
| 10674 | |
| 10675 | /* Create the vector of fields, and attach it to the type. */ |
| 10676 | |
| 10677 | static void |
| 10678 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
| 10679 | struct dwarf2_cu *cu) |
| 10680 | { |
| 10681 | int nfields = fip->nfields; |
| 10682 | |
| 10683 | /* Record the field count, allocate space for the array of fields, |
| 10684 | and create blank accessibility bitfields if necessary. */ |
| 10685 | TYPE_NFIELDS (type) = nfields; |
| 10686 | TYPE_FIELDS (type) = (struct field *) |
| 10687 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
| 10688 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); |
| 10689 | |
| 10690 | if (fip->non_public_fields && cu->language != language_ada) |
| 10691 | { |
| 10692 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 10693 | |
| 10694 | TYPE_FIELD_PRIVATE_BITS (type) = |
| 10695 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 10696 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); |
| 10697 | |
| 10698 | TYPE_FIELD_PROTECTED_BITS (type) = |
| 10699 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 10700 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); |
| 10701 | |
| 10702 | TYPE_FIELD_IGNORE_BITS (type) = |
| 10703 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 10704 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); |
| 10705 | } |
| 10706 | |
| 10707 | /* If the type has baseclasses, allocate and clear a bit vector for |
| 10708 | TYPE_FIELD_VIRTUAL_BITS. */ |
| 10709 | if (fip->nbaseclasses && cu->language != language_ada) |
| 10710 | { |
| 10711 | int num_bytes = B_BYTES (fip->nbaseclasses); |
| 10712 | unsigned char *pointer; |
| 10713 | |
| 10714 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 10715 | pointer = TYPE_ALLOC (type, num_bytes); |
| 10716 | TYPE_FIELD_VIRTUAL_BITS (type) = pointer; |
| 10717 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
| 10718 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; |
| 10719 | } |
| 10720 | |
| 10721 | /* Copy the saved-up fields into the field vector. Start from the head of |
| 10722 | the list, adding to the tail of the field array, so that they end up in |
| 10723 | the same order in the array in which they were added to the list. */ |
| 10724 | while (nfields-- > 0) |
| 10725 | { |
| 10726 | struct nextfield *fieldp; |
| 10727 | |
| 10728 | if (fip->fields) |
| 10729 | { |
| 10730 | fieldp = fip->fields; |
| 10731 | fip->fields = fieldp->next; |
| 10732 | } |
| 10733 | else |
| 10734 | { |
| 10735 | fieldp = fip->baseclasses; |
| 10736 | fip->baseclasses = fieldp->next; |
| 10737 | } |
| 10738 | |
| 10739 | TYPE_FIELD (type, nfields) = fieldp->field; |
| 10740 | switch (fieldp->accessibility) |
| 10741 | { |
| 10742 | case DW_ACCESS_private: |
| 10743 | if (cu->language != language_ada) |
| 10744 | SET_TYPE_FIELD_PRIVATE (type, nfields); |
| 10745 | break; |
| 10746 | |
| 10747 | case DW_ACCESS_protected: |
| 10748 | if (cu->language != language_ada) |
| 10749 | SET_TYPE_FIELD_PROTECTED (type, nfields); |
| 10750 | break; |
| 10751 | |
| 10752 | case DW_ACCESS_public: |
| 10753 | break; |
| 10754 | |
| 10755 | default: |
| 10756 | /* Unknown accessibility. Complain and treat it as public. */ |
| 10757 | { |
| 10758 | complaint (&symfile_complaints, _("unsupported accessibility %d"), |
| 10759 | fieldp->accessibility); |
| 10760 | } |
| 10761 | break; |
| 10762 | } |
| 10763 | if (nfields < fip->nbaseclasses) |
| 10764 | { |
| 10765 | switch (fieldp->virtuality) |
| 10766 | { |
| 10767 | case DW_VIRTUALITY_virtual: |
| 10768 | case DW_VIRTUALITY_pure_virtual: |
| 10769 | if (cu->language == language_ada) |
| 10770 | error (_("unexpected virtuality in component of Ada type")); |
| 10771 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
| 10772 | break; |
| 10773 | } |
| 10774 | } |
| 10775 | } |
| 10776 | } |
| 10777 | |
| 10778 | /* Return true if this member function is a constructor, false |
| 10779 | otherwise. */ |
| 10780 | |
| 10781 | static int |
| 10782 | dwarf2_is_constructor (struct die_info *die, struct dwarf2_cu *cu) |
| 10783 | { |
| 10784 | const char *fieldname; |
| 10785 | const char *typename; |
| 10786 | int len; |
| 10787 | |
| 10788 | if (die->parent == NULL) |
| 10789 | return 0; |
| 10790 | |
| 10791 | if (die->parent->tag != DW_TAG_structure_type |
| 10792 | && die->parent->tag != DW_TAG_union_type |
| 10793 | && die->parent->tag != DW_TAG_class_type) |
| 10794 | return 0; |
| 10795 | |
| 10796 | fieldname = dwarf2_name (die, cu); |
| 10797 | typename = dwarf2_name (die->parent, cu); |
| 10798 | if (fieldname == NULL || typename == NULL) |
| 10799 | return 0; |
| 10800 | |
| 10801 | len = strlen (fieldname); |
| 10802 | return (strncmp (fieldname, typename, len) == 0 |
| 10803 | && (typename[len] == '\0' || typename[len] == '<')); |
| 10804 | } |
| 10805 | |
| 10806 | /* Add a member function to the proper fieldlist. */ |
| 10807 | |
| 10808 | static void |
| 10809 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
| 10810 | struct type *type, struct dwarf2_cu *cu) |
| 10811 | { |
| 10812 | struct objfile *objfile = cu->objfile; |
| 10813 | struct attribute *attr; |
| 10814 | struct fnfieldlist *flp; |
| 10815 | int i; |
| 10816 | struct fn_field *fnp; |
| 10817 | char *fieldname; |
| 10818 | struct nextfnfield *new_fnfield; |
| 10819 | struct type *this_type; |
| 10820 | enum dwarf_access_attribute accessibility; |
| 10821 | |
| 10822 | if (cu->language == language_ada) |
| 10823 | error (_("unexpected member function in Ada type")); |
| 10824 | |
| 10825 | /* Get name of member function. */ |
| 10826 | fieldname = dwarf2_name (die, cu); |
| 10827 | if (fieldname == NULL) |
| 10828 | return; |
| 10829 | |
| 10830 | /* Look up member function name in fieldlist. */ |
| 10831 | for (i = 0; i < fip->nfnfields; i++) |
| 10832 | { |
| 10833 | if (strcmp (fip->fnfieldlists[i].name, fieldname) == 0) |
| 10834 | break; |
| 10835 | } |
| 10836 | |
| 10837 | /* Create new list element if necessary. */ |
| 10838 | if (i < fip->nfnfields) |
| 10839 | flp = &fip->fnfieldlists[i]; |
| 10840 | else |
| 10841 | { |
| 10842 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 10843 | { |
| 10844 | fip->fnfieldlists = (struct fnfieldlist *) |
| 10845 | xrealloc (fip->fnfieldlists, |
| 10846 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) |
| 10847 | * sizeof (struct fnfieldlist)); |
| 10848 | if (fip->nfnfields == 0) |
| 10849 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
| 10850 | } |
| 10851 | flp = &fip->fnfieldlists[fip->nfnfields]; |
| 10852 | flp->name = fieldname; |
| 10853 | flp->length = 0; |
| 10854 | flp->head = NULL; |
| 10855 | i = fip->nfnfields++; |
| 10856 | } |
| 10857 | |
| 10858 | /* Create a new member function field and chain it to the field list |
| 10859 | entry. */ |
| 10860 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
| 10861 | make_cleanup (xfree, new_fnfield); |
| 10862 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
| 10863 | new_fnfield->next = flp->head; |
| 10864 | flp->head = new_fnfield; |
| 10865 | flp->length++; |
| 10866 | |
| 10867 | /* Fill in the member function field info. */ |
| 10868 | fnp = &new_fnfield->fnfield; |
| 10869 | |
| 10870 | /* Delay processing of the physname until later. */ |
| 10871 | if (cu->language == language_cplus || cu->language == language_java) |
| 10872 | { |
| 10873 | add_to_method_list (type, i, flp->length - 1, fieldname, |
| 10874 | die, cu); |
| 10875 | } |
| 10876 | else |
| 10877 | { |
| 10878 | const char *physname = dwarf2_physname (fieldname, die, cu); |
| 10879 | fnp->physname = physname ? physname : ""; |
| 10880 | } |
| 10881 | |
| 10882 | fnp->type = alloc_type (objfile); |
| 10883 | this_type = read_type_die (die, cu); |
| 10884 | if (this_type && TYPE_CODE (this_type) == TYPE_CODE_FUNC) |
| 10885 | { |
| 10886 | int nparams = TYPE_NFIELDS (this_type); |
| 10887 | |
| 10888 | /* TYPE is the domain of this method, and THIS_TYPE is the type |
| 10889 | of the method itself (TYPE_CODE_METHOD). */ |
| 10890 | smash_to_method_type (fnp->type, type, |
| 10891 | TYPE_TARGET_TYPE (this_type), |
| 10892 | TYPE_FIELDS (this_type), |
| 10893 | TYPE_NFIELDS (this_type), |
| 10894 | TYPE_VARARGS (this_type)); |
| 10895 | |
| 10896 | /* Handle static member functions. |
| 10897 | Dwarf2 has no clean way to discern C++ static and non-static |
| 10898 | member functions. G++ helps GDB by marking the first |
| 10899 | parameter for non-static member functions (which is the this |
| 10900 | pointer) as artificial. We obtain this information from |
| 10901 | read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ |
| 10902 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (this_type, 0) == 0) |
| 10903 | fnp->voffset = VOFFSET_STATIC; |
| 10904 | } |
| 10905 | else |
| 10906 | complaint (&symfile_complaints, _("member function type missing for '%s'"), |
| 10907 | dwarf2_full_name (fieldname, die, cu)); |
| 10908 | |
| 10909 | /* Get fcontext from DW_AT_containing_type if present. */ |
| 10910 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
| 10911 | fnp->fcontext = die_containing_type (die, cu); |
| 10912 | |
| 10913 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const and |
| 10914 | is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ |
| 10915 | |
| 10916 | /* Get accessibility. */ |
| 10917 | attr = dwarf2_attr (die, DW_AT_accessibility, cu); |
| 10918 | if (attr) |
| 10919 | accessibility = DW_UNSND (attr); |
| 10920 | else |
| 10921 | accessibility = dwarf2_default_access_attribute (die, cu); |
| 10922 | switch (accessibility) |
| 10923 | { |
| 10924 | case DW_ACCESS_private: |
| 10925 | fnp->is_private = 1; |
| 10926 | break; |
| 10927 | case DW_ACCESS_protected: |
| 10928 | fnp->is_protected = 1; |
| 10929 | break; |
| 10930 | } |
| 10931 | |
| 10932 | /* Check for artificial methods. */ |
| 10933 | attr = dwarf2_attr (die, DW_AT_artificial, cu); |
| 10934 | if (attr && DW_UNSND (attr) != 0) |
| 10935 | fnp->is_artificial = 1; |
| 10936 | |
| 10937 | fnp->is_constructor = dwarf2_is_constructor (die, cu); |
| 10938 | |
| 10939 | /* Get index in virtual function table if it is a virtual member |
| 10940 | function. For older versions of GCC, this is an offset in the |
| 10941 | appropriate virtual table, as specified by DW_AT_containing_type. |
| 10942 | For everyone else, it is an expression to be evaluated relative |
| 10943 | to the object address. */ |
| 10944 | |
| 10945 | attr = dwarf2_attr (die, DW_AT_vtable_elem_location, cu); |
| 10946 | if (attr) |
| 10947 | { |
| 10948 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size > 0) |
| 10949 | { |
| 10950 | if (DW_BLOCK (attr)->data[0] == DW_OP_constu) |
| 10951 | { |
| 10952 | /* Old-style GCC. */ |
| 10953 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu) + 2; |
| 10954 | } |
| 10955 | else if (DW_BLOCK (attr)->data[0] == DW_OP_deref |
| 10956 | || (DW_BLOCK (attr)->size > 1 |
| 10957 | && DW_BLOCK (attr)->data[0] == DW_OP_deref_size |
| 10958 | && DW_BLOCK (attr)->data[1] == cu->header.addr_size)) |
| 10959 | { |
| 10960 | struct dwarf_block blk; |
| 10961 | int offset; |
| 10962 | |
| 10963 | offset = (DW_BLOCK (attr)->data[0] == DW_OP_deref |
| 10964 | ? 1 : 2); |
| 10965 | blk.size = DW_BLOCK (attr)->size - offset; |
| 10966 | blk.data = DW_BLOCK (attr)->data + offset; |
| 10967 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), cu); |
| 10968 | if ((fnp->voffset % cu->header.addr_size) != 0) |
| 10969 | dwarf2_complex_location_expr_complaint (); |
| 10970 | else |
| 10971 | fnp->voffset /= cu->header.addr_size; |
| 10972 | fnp->voffset += 2; |
| 10973 | } |
| 10974 | else |
| 10975 | dwarf2_complex_location_expr_complaint (); |
| 10976 | |
| 10977 | if (!fnp->fcontext) |
| 10978 | fnp->fcontext = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (this_type, 0)); |
| 10979 | } |
| 10980 | else if (attr_form_is_section_offset (attr)) |
| 10981 | { |
| 10982 | dwarf2_complex_location_expr_complaint (); |
| 10983 | } |
| 10984 | else |
| 10985 | { |
| 10986 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
| 10987 | fieldname); |
| 10988 | } |
| 10989 | } |
| 10990 | else |
| 10991 | { |
| 10992 | attr = dwarf2_attr (die, DW_AT_virtuality, cu); |
| 10993 | if (attr && DW_UNSND (attr)) |
| 10994 | { |
| 10995 | /* GCC does this, as of 2008-08-25; PR debug/37237. */ |
| 10996 | complaint (&symfile_complaints, |
| 10997 | _("Member function \"%s\" (offset %d) is virtual " |
| 10998 | "but the vtable offset is not specified"), |
| 10999 | fieldname, die->offset.sect_off); |
| 11000 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 11001 | TYPE_CPLUS_DYNAMIC (type) = 1; |
| 11002 | } |
| 11003 | } |
| 11004 | } |
| 11005 | |
| 11006 | /* Create the vector of member function fields, and attach it to the type. */ |
| 11007 | |
| 11008 | static void |
| 11009 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
| 11010 | struct dwarf2_cu *cu) |
| 11011 | { |
| 11012 | struct fnfieldlist *flp; |
| 11013 | int i; |
| 11014 | |
| 11015 | if (cu->language == language_ada) |
| 11016 | error (_("unexpected member functions in Ada type")); |
| 11017 | |
| 11018 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 11019 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 11020 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); |
| 11021 | |
| 11022 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) |
| 11023 | { |
| 11024 | struct nextfnfield *nfp = flp->head; |
| 11025 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); |
| 11026 | int k; |
| 11027 | |
| 11028 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; |
| 11029 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; |
| 11030 | fn_flp->fn_fields = (struct fn_field *) |
| 11031 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); |
| 11032 | for (k = flp->length; (k--, nfp); nfp = nfp->next) |
| 11033 | fn_flp->fn_fields[k] = nfp->fnfield; |
| 11034 | } |
| 11035 | |
| 11036 | TYPE_NFN_FIELDS (type) = fip->nfnfields; |
| 11037 | } |
| 11038 | |
| 11039 | /* Returns non-zero if NAME is the name of a vtable member in CU's |
| 11040 | language, zero otherwise. */ |
| 11041 | static int |
| 11042 | is_vtable_name (const char *name, struct dwarf2_cu *cu) |
| 11043 | { |
| 11044 | static const char vptr[] = "_vptr"; |
| 11045 | static const char vtable[] = "vtable"; |
| 11046 | |
| 11047 | /* Look for the C++ and Java forms of the vtable. */ |
| 11048 | if ((cu->language == language_java |
| 11049 | && strncmp (name, vtable, sizeof (vtable) - 1) == 0) |
| 11050 | || (strncmp (name, vptr, sizeof (vptr) - 1) == 0 |
| 11051 | && is_cplus_marker (name[sizeof (vptr) - 1]))) |
| 11052 | return 1; |
| 11053 | |
| 11054 | return 0; |
| 11055 | } |
| 11056 | |
| 11057 | /* GCC outputs unnamed structures that are really pointers to member |
| 11058 | functions, with the ABI-specified layout. If TYPE describes |
| 11059 | such a structure, smash it into a member function type. |
| 11060 | |
| 11061 | GCC shouldn't do this; it should just output pointer to member DIEs. |
| 11062 | This is GCC PR debug/28767. */ |
| 11063 | |
| 11064 | static void |
| 11065 | quirk_gcc_member_function_pointer (struct type *type, struct objfile *objfile) |
| 11066 | { |
| 11067 | struct type *pfn_type, *domain_type, *new_type; |
| 11068 | |
| 11069 | /* Check for a structure with no name and two children. */ |
| 11070 | if (TYPE_CODE (type) != TYPE_CODE_STRUCT || TYPE_NFIELDS (type) != 2) |
| 11071 | return; |
| 11072 | |
| 11073 | /* Check for __pfn and __delta members. */ |
| 11074 | if (TYPE_FIELD_NAME (type, 0) == NULL |
| 11075 | || strcmp (TYPE_FIELD_NAME (type, 0), "__pfn") != 0 |
| 11076 | || TYPE_FIELD_NAME (type, 1) == NULL |
| 11077 | || strcmp (TYPE_FIELD_NAME (type, 1), "__delta") != 0) |
| 11078 | return; |
| 11079 | |
| 11080 | /* Find the type of the method. */ |
| 11081 | pfn_type = TYPE_FIELD_TYPE (type, 0); |
| 11082 | if (pfn_type == NULL |
| 11083 | || TYPE_CODE (pfn_type) != TYPE_CODE_PTR |
| 11084 | || TYPE_CODE (TYPE_TARGET_TYPE (pfn_type)) != TYPE_CODE_FUNC) |
| 11085 | return; |
| 11086 | |
| 11087 | /* Look for the "this" argument. */ |
| 11088 | pfn_type = TYPE_TARGET_TYPE (pfn_type); |
| 11089 | if (TYPE_NFIELDS (pfn_type) == 0 |
| 11090 | /* || TYPE_FIELD_TYPE (pfn_type, 0) == NULL */ |
| 11091 | || TYPE_CODE (TYPE_FIELD_TYPE (pfn_type, 0)) != TYPE_CODE_PTR) |
| 11092 | return; |
| 11093 | |
| 11094 | domain_type = TYPE_TARGET_TYPE (TYPE_FIELD_TYPE (pfn_type, 0)); |
| 11095 | new_type = alloc_type (objfile); |
| 11096 | smash_to_method_type (new_type, domain_type, TYPE_TARGET_TYPE (pfn_type), |
| 11097 | TYPE_FIELDS (pfn_type), TYPE_NFIELDS (pfn_type), |
| 11098 | TYPE_VARARGS (pfn_type)); |
| 11099 | smash_to_methodptr_type (type, new_type); |
| 11100 | } |
| 11101 | |
| 11102 | /* Return non-zero if the CU's PRODUCER string matches the Intel C/C++ compiler |
| 11103 | (icc). */ |
| 11104 | |
| 11105 | static int |
| 11106 | producer_is_icc (struct dwarf2_cu *cu) |
| 11107 | { |
| 11108 | if (!cu->checked_producer) |
| 11109 | check_producer (cu); |
| 11110 | |
| 11111 | return cu->producer_is_icc; |
| 11112 | } |
| 11113 | |
| 11114 | /* Called when we find the DIE that starts a structure or union scope |
| 11115 | (definition) to create a type for the structure or union. Fill in |
| 11116 | the type's name and general properties; the members will not be |
| 11117 | processed until process_structure_type. |
| 11118 | |
| 11119 | NOTE: we need to call these functions regardless of whether or not the |
| 11120 | DIE has a DW_AT_name attribute, since it might be an anonymous |
| 11121 | structure or union. This gets the type entered into our set of |
| 11122 | user defined types. |
| 11123 | |
| 11124 | However, if the structure is incomplete (an opaque struct/union) |
| 11125 | then suppress creating a symbol table entry for it since gdb only |
| 11126 | wants to find the one with the complete definition. Note that if |
| 11127 | it is complete, we just call new_symbol, which does it's own |
| 11128 | checking about whether the struct/union is anonymous or not (and |
| 11129 | suppresses creating a symbol table entry itself). */ |
| 11130 | |
| 11131 | static struct type * |
| 11132 | read_structure_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11133 | { |
| 11134 | struct objfile *objfile = cu->objfile; |
| 11135 | struct type *type; |
| 11136 | struct attribute *attr; |
| 11137 | char *name; |
| 11138 | |
| 11139 | /* If the definition of this type lives in .debug_types, read that type. |
| 11140 | Don't follow DW_AT_specification though, that will take us back up |
| 11141 | the chain and we want to go down. */ |
| 11142 | attr = dwarf2_attr_no_follow (die, DW_AT_signature); |
| 11143 | if (attr) |
| 11144 | { |
| 11145 | struct dwarf2_cu *type_cu = cu; |
| 11146 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 11147 | |
| 11148 | /* We could just recurse on read_structure_type, but we need to call |
| 11149 | get_die_type to ensure only one type for this DIE is created. |
| 11150 | This is important, for example, because for c++ classes we need |
| 11151 | TYPE_NAME set which is only done by new_symbol. Blech. */ |
| 11152 | type = read_type_die (type_die, type_cu); |
| 11153 | |
| 11154 | /* TYPE_CU may not be the same as CU. |
| 11155 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 11156 | return set_die_type (die, type, cu); |
| 11157 | } |
| 11158 | |
| 11159 | type = alloc_type (objfile); |
| 11160 | INIT_CPLUS_SPECIFIC (type); |
| 11161 | |
| 11162 | name = dwarf2_name (die, cu); |
| 11163 | if (name != NULL) |
| 11164 | { |
| 11165 | if (cu->language == language_cplus |
| 11166 | || cu->language == language_java) |
| 11167 | { |
| 11168 | char *full_name = (char *) dwarf2_full_name (name, die, cu); |
| 11169 | |
| 11170 | /* dwarf2_full_name might have already finished building the DIE's |
| 11171 | type. If so, there is no need to continue. */ |
| 11172 | if (get_die_type (die, cu) != NULL) |
| 11173 | return get_die_type (die, cu); |
| 11174 | |
| 11175 | TYPE_TAG_NAME (type) = full_name; |
| 11176 | if (die->tag == DW_TAG_structure_type |
| 11177 | || die->tag == DW_TAG_class_type) |
| 11178 | TYPE_NAME (type) = TYPE_TAG_NAME (type); |
| 11179 | } |
| 11180 | else |
| 11181 | { |
| 11182 | /* The name is already allocated along with this objfile, so |
| 11183 | we don't need to duplicate it for the type. */ |
| 11184 | TYPE_TAG_NAME (type) = (char *) name; |
| 11185 | if (die->tag == DW_TAG_class_type) |
| 11186 | TYPE_NAME (type) = TYPE_TAG_NAME (type); |
| 11187 | } |
| 11188 | } |
| 11189 | |
| 11190 | if (die->tag == DW_TAG_structure_type) |
| 11191 | { |
| 11192 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
| 11193 | } |
| 11194 | else if (die->tag == DW_TAG_union_type) |
| 11195 | { |
| 11196 | TYPE_CODE (type) = TYPE_CODE_UNION; |
| 11197 | } |
| 11198 | else |
| 11199 | { |
| 11200 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
| 11201 | } |
| 11202 | |
| 11203 | if (cu->language == language_cplus && die->tag == DW_TAG_class_type) |
| 11204 | TYPE_DECLARED_CLASS (type) = 1; |
| 11205 | |
| 11206 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 11207 | if (attr) |
| 11208 | { |
| 11209 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 11210 | } |
| 11211 | else |
| 11212 | { |
| 11213 | TYPE_LENGTH (type) = 0; |
| 11214 | } |
| 11215 | |
| 11216 | if (producer_is_icc (cu)) |
| 11217 | { |
| 11218 | /* ICC does not output the required DW_AT_declaration |
| 11219 | on incomplete types, but gives them a size of zero. */ |
| 11220 | } |
| 11221 | else |
| 11222 | TYPE_STUB_SUPPORTED (type) = 1; |
| 11223 | |
| 11224 | if (die_is_declaration (die, cu)) |
| 11225 | TYPE_STUB (type) = 1; |
| 11226 | else if (attr == NULL && die->child == NULL |
| 11227 | && producer_is_realview (cu->producer)) |
| 11228 | /* RealView does not output the required DW_AT_declaration |
| 11229 | on incomplete types. */ |
| 11230 | TYPE_STUB (type) = 1; |
| 11231 | |
| 11232 | /* We need to add the type field to the die immediately so we don't |
| 11233 | infinitely recurse when dealing with pointers to the structure |
| 11234 | type within the structure itself. */ |
| 11235 | set_die_type (die, type, cu); |
| 11236 | |
| 11237 | /* set_die_type should be already done. */ |
| 11238 | set_descriptive_type (type, die, cu); |
| 11239 | |
| 11240 | return type; |
| 11241 | } |
| 11242 | |
| 11243 | /* Finish creating a structure or union type, including filling in |
| 11244 | its members and creating a symbol for it. */ |
| 11245 | |
| 11246 | static void |
| 11247 | process_structure_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 11248 | { |
| 11249 | struct objfile *objfile = cu->objfile; |
| 11250 | struct die_info *child_die = die->child; |
| 11251 | struct type *type; |
| 11252 | |
| 11253 | type = get_die_type (die, cu); |
| 11254 | if (type == NULL) |
| 11255 | type = read_structure_type (die, cu); |
| 11256 | |
| 11257 | if (die->child != NULL && ! die_is_declaration (die, cu)) |
| 11258 | { |
| 11259 | struct field_info fi; |
| 11260 | struct die_info *child_die; |
| 11261 | VEC (symbolp) *template_args = NULL; |
| 11262 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 11263 | |
| 11264 | memset (&fi, 0, sizeof (struct field_info)); |
| 11265 | |
| 11266 | child_die = die->child; |
| 11267 | |
| 11268 | while (child_die && child_die->tag) |
| 11269 | { |
| 11270 | if (child_die->tag == DW_TAG_member |
| 11271 | || child_die->tag == DW_TAG_variable) |
| 11272 | { |
| 11273 | /* NOTE: carlton/2002-11-05: A C++ static data member |
| 11274 | should be a DW_TAG_member that is a declaration, but |
| 11275 | all versions of G++ as of this writing (so through at |
| 11276 | least 3.2.1) incorrectly generate DW_TAG_variable |
| 11277 | tags for them instead. */ |
| 11278 | dwarf2_add_field (&fi, child_die, cu); |
| 11279 | } |
| 11280 | else if (child_die->tag == DW_TAG_subprogram) |
| 11281 | { |
| 11282 | /* C++ member function. */ |
| 11283 | dwarf2_add_member_fn (&fi, child_die, type, cu); |
| 11284 | } |
| 11285 | else if (child_die->tag == DW_TAG_inheritance) |
| 11286 | { |
| 11287 | /* C++ base class field. */ |
| 11288 | dwarf2_add_field (&fi, child_die, cu); |
| 11289 | } |
| 11290 | else if (child_die->tag == DW_TAG_typedef) |
| 11291 | dwarf2_add_typedef (&fi, child_die, cu); |
| 11292 | else if (child_die->tag == DW_TAG_template_type_param |
| 11293 | || child_die->tag == DW_TAG_template_value_param) |
| 11294 | { |
| 11295 | struct symbol *arg = new_symbol (child_die, NULL, cu); |
| 11296 | |
| 11297 | if (arg != NULL) |
| 11298 | VEC_safe_push (symbolp, template_args, arg); |
| 11299 | } |
| 11300 | |
| 11301 | child_die = sibling_die (child_die); |
| 11302 | } |
| 11303 | |
| 11304 | /* Attach template arguments to type. */ |
| 11305 | if (! VEC_empty (symbolp, template_args)) |
| 11306 | { |
| 11307 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 11308 | TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 11309 | = VEC_length (symbolp, template_args); |
| 11310 | TYPE_TEMPLATE_ARGUMENTS (type) |
| 11311 | = obstack_alloc (&objfile->objfile_obstack, |
| 11312 | (TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 11313 | * sizeof (struct symbol *))); |
| 11314 | memcpy (TYPE_TEMPLATE_ARGUMENTS (type), |
| 11315 | VEC_address (symbolp, template_args), |
| 11316 | (TYPE_N_TEMPLATE_ARGUMENTS (type) |
| 11317 | * sizeof (struct symbol *))); |
| 11318 | VEC_free (symbolp, template_args); |
| 11319 | } |
| 11320 | |
| 11321 | /* Attach fields and member functions to the type. */ |
| 11322 | if (fi.nfields) |
| 11323 | dwarf2_attach_fields_to_type (&fi, type, cu); |
| 11324 | if (fi.nfnfields) |
| 11325 | { |
| 11326 | dwarf2_attach_fn_fields_to_type (&fi, type, cu); |
| 11327 | |
| 11328 | /* Get the type which refers to the base class (possibly this |
| 11329 | class itself) which contains the vtable pointer for the current |
| 11330 | class from the DW_AT_containing_type attribute. This use of |
| 11331 | DW_AT_containing_type is a GNU extension. */ |
| 11332 | |
| 11333 | if (dwarf2_attr (die, DW_AT_containing_type, cu) != NULL) |
| 11334 | { |
| 11335 | struct type *t = die_containing_type (die, cu); |
| 11336 | |
| 11337 | TYPE_VPTR_BASETYPE (type) = t; |
| 11338 | if (type == t) |
| 11339 | { |
| 11340 | int i; |
| 11341 | |
| 11342 | /* Our own class provides vtbl ptr. */ |
| 11343 | for (i = TYPE_NFIELDS (t) - 1; |
| 11344 | i >= TYPE_N_BASECLASSES (t); |
| 11345 | --i) |
| 11346 | { |
| 11347 | const char *fieldname = TYPE_FIELD_NAME (t, i); |
| 11348 | |
| 11349 | if (is_vtable_name (fieldname, cu)) |
| 11350 | { |
| 11351 | TYPE_VPTR_FIELDNO (type) = i; |
| 11352 | break; |
| 11353 | } |
| 11354 | } |
| 11355 | |
| 11356 | /* Complain if virtual function table field not found. */ |
| 11357 | if (i < TYPE_N_BASECLASSES (t)) |
| 11358 | complaint (&symfile_complaints, |
| 11359 | _("virtual function table pointer " |
| 11360 | "not found when defining class '%s'"), |
| 11361 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
| 11362 | ""); |
| 11363 | } |
| 11364 | else |
| 11365 | { |
| 11366 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); |
| 11367 | } |
| 11368 | } |
| 11369 | else if (cu->producer |
| 11370 | && strncmp (cu->producer, |
| 11371 | "IBM(R) XL C/C++ Advanced Edition", 32) == 0) |
| 11372 | { |
| 11373 | /* The IBM XLC compiler does not provide direct indication |
| 11374 | of the containing type, but the vtable pointer is |
| 11375 | always named __vfp. */ |
| 11376 | |
| 11377 | int i; |
| 11378 | |
| 11379 | for (i = TYPE_NFIELDS (type) - 1; |
| 11380 | i >= TYPE_N_BASECLASSES (type); |
| 11381 | --i) |
| 11382 | { |
| 11383 | if (strcmp (TYPE_FIELD_NAME (type, i), "__vfp") == 0) |
| 11384 | { |
| 11385 | TYPE_VPTR_FIELDNO (type) = i; |
| 11386 | TYPE_VPTR_BASETYPE (type) = type; |
| 11387 | break; |
| 11388 | } |
| 11389 | } |
| 11390 | } |
| 11391 | } |
| 11392 | |
| 11393 | /* Copy fi.typedef_field_list linked list elements content into the |
| 11394 | allocated array TYPE_TYPEDEF_FIELD_ARRAY (type). */ |
| 11395 | if (fi.typedef_field_list) |
| 11396 | { |
| 11397 | int i = fi.typedef_field_list_count; |
| 11398 | |
| 11399 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 11400 | TYPE_TYPEDEF_FIELD_ARRAY (type) |
| 11401 | = TYPE_ALLOC (type, sizeof (TYPE_TYPEDEF_FIELD (type, 0)) * i); |
| 11402 | TYPE_TYPEDEF_FIELD_COUNT (type) = i; |
| 11403 | |
| 11404 | /* Reverse the list order to keep the debug info elements order. */ |
| 11405 | while (--i >= 0) |
| 11406 | { |
| 11407 | struct typedef_field *dest, *src; |
| 11408 | |
| 11409 | dest = &TYPE_TYPEDEF_FIELD (type, i); |
| 11410 | src = &fi.typedef_field_list->field; |
| 11411 | fi.typedef_field_list = fi.typedef_field_list->next; |
| 11412 | *dest = *src; |
| 11413 | } |
| 11414 | } |
| 11415 | |
| 11416 | do_cleanups (back_to); |
| 11417 | |
| 11418 | if (HAVE_CPLUS_STRUCT (type)) |
| 11419 | TYPE_CPLUS_REALLY_JAVA (type) = cu->language == language_java; |
| 11420 | } |
| 11421 | |
| 11422 | quirk_gcc_member_function_pointer (type, objfile); |
| 11423 | |
| 11424 | /* NOTE: carlton/2004-03-16: GCC 3.4 (or at least one of its |
| 11425 | snapshots) has been known to create a die giving a declaration |
| 11426 | for a class that has, as a child, a die giving a definition for a |
| 11427 | nested class. So we have to process our children even if the |
| 11428 | current die is a declaration. Normally, of course, a declaration |
| 11429 | won't have any children at all. */ |
| 11430 | |
| 11431 | while (child_die != NULL && child_die->tag) |
| 11432 | { |
| 11433 | if (child_die->tag == DW_TAG_member |
| 11434 | || child_die->tag == DW_TAG_variable |
| 11435 | || child_die->tag == DW_TAG_inheritance |
| 11436 | || child_die->tag == DW_TAG_template_value_param |
| 11437 | || child_die->tag == DW_TAG_template_type_param) |
| 11438 | { |
| 11439 | /* Do nothing. */ |
| 11440 | } |
| 11441 | else |
| 11442 | process_die (child_die, cu); |
| 11443 | |
| 11444 | child_die = sibling_die (child_die); |
| 11445 | } |
| 11446 | |
| 11447 | /* Do not consider external references. According to the DWARF standard, |
| 11448 | these DIEs are identified by the fact that they have no byte_size |
| 11449 | attribute, and a declaration attribute. */ |
| 11450 | if (dwarf2_attr (die, DW_AT_byte_size, cu) != NULL |
| 11451 | || !die_is_declaration (die, cu)) |
| 11452 | new_symbol (die, type, cu); |
| 11453 | } |
| 11454 | |
| 11455 | /* Given a DW_AT_enumeration_type die, set its type. We do not |
| 11456 | complete the type's fields yet, or create any symbols. */ |
| 11457 | |
| 11458 | static struct type * |
| 11459 | read_enumeration_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11460 | { |
| 11461 | struct objfile *objfile = cu->objfile; |
| 11462 | struct type *type; |
| 11463 | struct attribute *attr; |
| 11464 | const char *name; |
| 11465 | |
| 11466 | /* If the definition of this type lives in .debug_types, read that type. |
| 11467 | Don't follow DW_AT_specification though, that will take us back up |
| 11468 | the chain and we want to go down. */ |
| 11469 | attr = dwarf2_attr_no_follow (die, DW_AT_signature); |
| 11470 | if (attr) |
| 11471 | { |
| 11472 | struct dwarf2_cu *type_cu = cu; |
| 11473 | struct die_info *type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 11474 | |
| 11475 | type = read_type_die (type_die, type_cu); |
| 11476 | |
| 11477 | /* TYPE_CU may not be the same as CU. |
| 11478 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 11479 | return set_die_type (die, type, cu); |
| 11480 | } |
| 11481 | |
| 11482 | type = alloc_type (objfile); |
| 11483 | |
| 11484 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
| 11485 | name = dwarf2_full_name (NULL, die, cu); |
| 11486 | if (name != NULL) |
| 11487 | TYPE_TAG_NAME (type) = (char *) name; |
| 11488 | |
| 11489 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 11490 | if (attr) |
| 11491 | { |
| 11492 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 11493 | } |
| 11494 | else |
| 11495 | { |
| 11496 | TYPE_LENGTH (type) = 0; |
| 11497 | } |
| 11498 | |
| 11499 | /* The enumeration DIE can be incomplete. In Ada, any type can be |
| 11500 | declared as private in the package spec, and then defined only |
| 11501 | inside the package body. Such types are known as Taft Amendment |
| 11502 | Types. When another package uses such a type, an incomplete DIE |
| 11503 | may be generated by the compiler. */ |
| 11504 | if (die_is_declaration (die, cu)) |
| 11505 | TYPE_STUB (type) = 1; |
| 11506 | |
| 11507 | return set_die_type (die, type, cu); |
| 11508 | } |
| 11509 | |
| 11510 | /* Given a pointer to a die which begins an enumeration, process all |
| 11511 | the dies that define the members of the enumeration, and create the |
| 11512 | symbol for the enumeration type. |
| 11513 | |
| 11514 | NOTE: We reverse the order of the element list. */ |
| 11515 | |
| 11516 | static void |
| 11517 | process_enumeration_scope (struct die_info *die, struct dwarf2_cu *cu) |
| 11518 | { |
| 11519 | struct type *this_type; |
| 11520 | |
| 11521 | this_type = get_die_type (die, cu); |
| 11522 | if (this_type == NULL) |
| 11523 | this_type = read_enumeration_type (die, cu); |
| 11524 | |
| 11525 | if (die->child != NULL) |
| 11526 | { |
| 11527 | struct die_info *child_die; |
| 11528 | struct symbol *sym; |
| 11529 | struct field *fields = NULL; |
| 11530 | int num_fields = 0; |
| 11531 | int unsigned_enum = 1; |
| 11532 | char *name; |
| 11533 | int flag_enum = 1; |
| 11534 | ULONGEST mask = 0; |
| 11535 | |
| 11536 | child_die = die->child; |
| 11537 | while (child_die && child_die->tag) |
| 11538 | { |
| 11539 | if (child_die->tag != DW_TAG_enumerator) |
| 11540 | { |
| 11541 | process_die (child_die, cu); |
| 11542 | } |
| 11543 | else |
| 11544 | { |
| 11545 | name = dwarf2_name (child_die, cu); |
| 11546 | if (name) |
| 11547 | { |
| 11548 | sym = new_symbol (child_die, this_type, cu); |
| 11549 | if (SYMBOL_VALUE (sym) < 0) |
| 11550 | { |
| 11551 | unsigned_enum = 0; |
| 11552 | flag_enum = 0; |
| 11553 | } |
| 11554 | else if ((mask & SYMBOL_VALUE (sym)) != 0) |
| 11555 | flag_enum = 0; |
| 11556 | else |
| 11557 | mask |= SYMBOL_VALUE (sym); |
| 11558 | |
| 11559 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 11560 | { |
| 11561 | fields = (struct field *) |
| 11562 | xrealloc (fields, |
| 11563 | (num_fields + DW_FIELD_ALLOC_CHUNK) |
| 11564 | * sizeof (struct field)); |
| 11565 | } |
| 11566 | |
| 11567 | FIELD_NAME (fields[num_fields]) = SYMBOL_LINKAGE_NAME (sym); |
| 11568 | FIELD_TYPE (fields[num_fields]) = NULL; |
| 11569 | SET_FIELD_ENUMVAL (fields[num_fields], SYMBOL_VALUE (sym)); |
| 11570 | FIELD_BITSIZE (fields[num_fields]) = 0; |
| 11571 | |
| 11572 | num_fields++; |
| 11573 | } |
| 11574 | } |
| 11575 | |
| 11576 | child_die = sibling_die (child_die); |
| 11577 | } |
| 11578 | |
| 11579 | if (num_fields) |
| 11580 | { |
| 11581 | TYPE_NFIELDS (this_type) = num_fields; |
| 11582 | TYPE_FIELDS (this_type) = (struct field *) |
| 11583 | TYPE_ALLOC (this_type, sizeof (struct field) * num_fields); |
| 11584 | memcpy (TYPE_FIELDS (this_type), fields, |
| 11585 | sizeof (struct field) * num_fields); |
| 11586 | xfree (fields); |
| 11587 | } |
| 11588 | if (unsigned_enum) |
| 11589 | TYPE_UNSIGNED (this_type) = 1; |
| 11590 | if (flag_enum) |
| 11591 | TYPE_FLAG_ENUM (this_type) = 1; |
| 11592 | } |
| 11593 | |
| 11594 | /* If we are reading an enum from a .debug_types unit, and the enum |
| 11595 | is a declaration, and the enum is not the signatured type in the |
| 11596 | unit, then we do not want to add a symbol for it. Adding a |
| 11597 | symbol would in some cases obscure the true definition of the |
| 11598 | enum, giving users an incomplete type when the definition is |
| 11599 | actually available. Note that we do not want to do this for all |
| 11600 | enums which are just declarations, because C++0x allows forward |
| 11601 | enum declarations. */ |
| 11602 | if (cu->per_cu->is_debug_types |
| 11603 | && die_is_declaration (die, cu)) |
| 11604 | { |
| 11605 | struct signatured_type *sig_type; |
| 11606 | |
| 11607 | sig_type |
| 11608 | = lookup_signatured_type_at_offset (dwarf2_per_objfile->objfile, |
| 11609 | cu->per_cu->info_or_types_section, |
| 11610 | cu->per_cu->offset); |
| 11611 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
| 11612 | if (sig_type->type_offset_in_section.sect_off != die->offset.sect_off) |
| 11613 | return; |
| 11614 | } |
| 11615 | |
| 11616 | new_symbol (die, this_type, cu); |
| 11617 | } |
| 11618 | |
| 11619 | /* Extract all information from a DW_TAG_array_type DIE and put it in |
| 11620 | the DIE's type field. For now, this only handles one dimensional |
| 11621 | arrays. */ |
| 11622 | |
| 11623 | static struct type * |
| 11624 | read_array_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11625 | { |
| 11626 | struct objfile *objfile = cu->objfile; |
| 11627 | struct die_info *child_die; |
| 11628 | struct type *type; |
| 11629 | struct type *element_type, *range_type, *index_type; |
| 11630 | struct type **range_types = NULL; |
| 11631 | struct attribute *attr; |
| 11632 | int ndim = 0; |
| 11633 | struct cleanup *back_to; |
| 11634 | char *name; |
| 11635 | |
| 11636 | element_type = die_type (die, cu); |
| 11637 | |
| 11638 | /* The die_type call above may have already set the type for this DIE. */ |
| 11639 | type = get_die_type (die, cu); |
| 11640 | if (type) |
| 11641 | return type; |
| 11642 | |
| 11643 | /* Irix 6.2 native cc creates array types without children for |
| 11644 | arrays with unspecified length. */ |
| 11645 | if (die->child == NULL) |
| 11646 | { |
| 11647 | index_type = objfile_type (objfile)->builtin_int; |
| 11648 | range_type = create_range_type (NULL, index_type, 0, -1); |
| 11649 | type = create_array_type (NULL, element_type, range_type); |
| 11650 | return set_die_type (die, type, cu); |
| 11651 | } |
| 11652 | |
| 11653 | back_to = make_cleanup (null_cleanup, NULL); |
| 11654 | child_die = die->child; |
| 11655 | while (child_die && child_die->tag) |
| 11656 | { |
| 11657 | if (child_die->tag == DW_TAG_subrange_type) |
| 11658 | { |
| 11659 | struct type *child_type = read_type_die (child_die, cu); |
| 11660 | |
| 11661 | if (child_type != NULL) |
| 11662 | { |
| 11663 | /* The range type was succesfully read. Save it for the |
| 11664 | array type creation. */ |
| 11665 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
| 11666 | { |
| 11667 | range_types = (struct type **) |
| 11668 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) |
| 11669 | * sizeof (struct type *)); |
| 11670 | if (ndim == 0) |
| 11671 | make_cleanup (free_current_contents, &range_types); |
| 11672 | } |
| 11673 | range_types[ndim++] = child_type; |
| 11674 | } |
| 11675 | } |
| 11676 | child_die = sibling_die (child_die); |
| 11677 | } |
| 11678 | |
| 11679 | /* Dwarf2 dimensions are output from left to right, create the |
| 11680 | necessary array types in backwards order. */ |
| 11681 | |
| 11682 | type = element_type; |
| 11683 | |
| 11684 | if (read_array_order (die, cu) == DW_ORD_col_major) |
| 11685 | { |
| 11686 | int i = 0; |
| 11687 | |
| 11688 | while (i < ndim) |
| 11689 | type = create_array_type (NULL, type, range_types[i++]); |
| 11690 | } |
| 11691 | else |
| 11692 | { |
| 11693 | while (ndim-- > 0) |
| 11694 | type = create_array_type (NULL, type, range_types[ndim]); |
| 11695 | } |
| 11696 | |
| 11697 | /* Understand Dwarf2 support for vector types (like they occur on |
| 11698 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the |
| 11699 | array type. This is not part of the Dwarf2/3 standard yet, but a |
| 11700 | custom vendor extension. The main difference between a regular |
| 11701 | array and the vector variant is that vectors are passed by value |
| 11702 | to functions. */ |
| 11703 | attr = dwarf2_attr (die, DW_AT_GNU_vector, cu); |
| 11704 | if (attr) |
| 11705 | make_vector_type (type); |
| 11706 | |
| 11707 | /* The DIE may have DW_AT_byte_size set. For example an OpenCL |
| 11708 | implementation may choose to implement triple vectors using this |
| 11709 | attribute. */ |
| 11710 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 11711 | if (attr) |
| 11712 | { |
| 11713 | if (DW_UNSND (attr) >= TYPE_LENGTH (type)) |
| 11714 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 11715 | else |
| 11716 | complaint (&symfile_complaints, |
| 11717 | _("DW_AT_byte_size for array type smaller " |
| 11718 | "than the total size of elements")); |
| 11719 | } |
| 11720 | |
| 11721 | name = dwarf2_name (die, cu); |
| 11722 | if (name) |
| 11723 | TYPE_NAME (type) = name; |
| 11724 | |
| 11725 | /* Install the type in the die. */ |
| 11726 | set_die_type (die, type, cu); |
| 11727 | |
| 11728 | /* set_die_type should be already done. */ |
| 11729 | set_descriptive_type (type, die, cu); |
| 11730 | |
| 11731 | do_cleanups (back_to); |
| 11732 | |
| 11733 | return type; |
| 11734 | } |
| 11735 | |
| 11736 | static enum dwarf_array_dim_ordering |
| 11737 | read_array_order (struct die_info *die, struct dwarf2_cu *cu) |
| 11738 | { |
| 11739 | struct attribute *attr; |
| 11740 | |
| 11741 | attr = dwarf2_attr (die, DW_AT_ordering, cu); |
| 11742 | |
| 11743 | if (attr) return DW_SND (attr); |
| 11744 | |
| 11745 | /* GNU F77 is a special case, as at 08/2004 array type info is the |
| 11746 | opposite order to the dwarf2 specification, but data is still |
| 11747 | laid out as per normal fortran. |
| 11748 | |
| 11749 | FIXME: dsl/2004-8-20: If G77 is ever fixed, this will also need |
| 11750 | version checking. */ |
| 11751 | |
| 11752 | if (cu->language == language_fortran |
| 11753 | && cu->producer && strstr (cu->producer, "GNU F77")) |
| 11754 | { |
| 11755 | return DW_ORD_row_major; |
| 11756 | } |
| 11757 | |
| 11758 | switch (cu->language_defn->la_array_ordering) |
| 11759 | { |
| 11760 | case array_column_major: |
| 11761 | return DW_ORD_col_major; |
| 11762 | case array_row_major: |
| 11763 | default: |
| 11764 | return DW_ORD_row_major; |
| 11765 | }; |
| 11766 | } |
| 11767 | |
| 11768 | /* Extract all information from a DW_TAG_set_type DIE and put it in |
| 11769 | the DIE's type field. */ |
| 11770 | |
| 11771 | static struct type * |
| 11772 | read_set_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11773 | { |
| 11774 | struct type *domain_type, *set_type; |
| 11775 | struct attribute *attr; |
| 11776 | |
| 11777 | domain_type = die_type (die, cu); |
| 11778 | |
| 11779 | /* The die_type call above may have already set the type for this DIE. */ |
| 11780 | set_type = get_die_type (die, cu); |
| 11781 | if (set_type) |
| 11782 | return set_type; |
| 11783 | |
| 11784 | set_type = create_set_type (NULL, domain_type); |
| 11785 | |
| 11786 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 11787 | if (attr) |
| 11788 | TYPE_LENGTH (set_type) = DW_UNSND (attr); |
| 11789 | |
| 11790 | return set_die_type (die, set_type, cu); |
| 11791 | } |
| 11792 | |
| 11793 | /* A helper for read_common_block that creates a locexpr baton. |
| 11794 | SYM is the symbol which we are marking as computed. |
| 11795 | COMMON_DIE is the DIE for the common block. |
| 11796 | COMMON_LOC is the location expression attribute for the common |
| 11797 | block itself. |
| 11798 | MEMBER_LOC is the location expression attribute for the particular |
| 11799 | member of the common block that we are processing. |
| 11800 | CU is the CU from which the above come. */ |
| 11801 | |
| 11802 | static void |
| 11803 | mark_common_block_symbol_computed (struct symbol *sym, |
| 11804 | struct die_info *common_die, |
| 11805 | struct attribute *common_loc, |
| 11806 | struct attribute *member_loc, |
| 11807 | struct dwarf2_cu *cu) |
| 11808 | { |
| 11809 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 11810 | struct dwarf2_locexpr_baton *baton; |
| 11811 | gdb_byte *ptr; |
| 11812 | unsigned int cu_off; |
| 11813 | enum bfd_endian byte_order = gdbarch_byte_order (get_objfile_arch (objfile)); |
| 11814 | LONGEST offset = 0; |
| 11815 | |
| 11816 | gdb_assert (common_loc && member_loc); |
| 11817 | gdb_assert (attr_form_is_block (common_loc)); |
| 11818 | gdb_assert (attr_form_is_block (member_loc) |
| 11819 | || attr_form_is_constant (member_loc)); |
| 11820 | |
| 11821 | baton = obstack_alloc (&objfile->objfile_obstack, |
| 11822 | sizeof (struct dwarf2_locexpr_baton)); |
| 11823 | baton->per_cu = cu->per_cu; |
| 11824 | gdb_assert (baton->per_cu); |
| 11825 | |
| 11826 | baton->size = 5 /* DW_OP_call4 */ + 1 /* DW_OP_plus */; |
| 11827 | |
| 11828 | if (attr_form_is_constant (member_loc)) |
| 11829 | { |
| 11830 | offset = dwarf2_get_attr_constant_value (member_loc, 0); |
| 11831 | baton->size += 1 /* DW_OP_addr */ + cu->header.addr_size; |
| 11832 | } |
| 11833 | else |
| 11834 | baton->size += DW_BLOCK (member_loc)->size; |
| 11835 | |
| 11836 | ptr = obstack_alloc (&objfile->objfile_obstack, baton->size); |
| 11837 | baton->data = ptr; |
| 11838 | |
| 11839 | *ptr++ = DW_OP_call4; |
| 11840 | cu_off = common_die->offset.sect_off - cu->per_cu->offset.sect_off; |
| 11841 | store_unsigned_integer (ptr, 4, byte_order, cu_off); |
| 11842 | ptr += 4; |
| 11843 | |
| 11844 | if (attr_form_is_constant (member_loc)) |
| 11845 | { |
| 11846 | *ptr++ = DW_OP_addr; |
| 11847 | store_unsigned_integer (ptr, cu->header.addr_size, byte_order, offset); |
| 11848 | ptr += cu->header.addr_size; |
| 11849 | } |
| 11850 | else |
| 11851 | { |
| 11852 | /* We have to copy the data here, because DW_OP_call4 will only |
| 11853 | use a DW_AT_location attribute. */ |
| 11854 | memcpy (ptr, DW_BLOCK (member_loc)->data, DW_BLOCK (member_loc)->size); |
| 11855 | ptr += DW_BLOCK (member_loc)->size; |
| 11856 | } |
| 11857 | |
| 11858 | *ptr++ = DW_OP_plus; |
| 11859 | gdb_assert (ptr - baton->data == baton->size); |
| 11860 | |
| 11861 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 11862 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 11863 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 11864 | } |
| 11865 | |
| 11866 | /* Create appropriate locally-scoped variables for all the |
| 11867 | DW_TAG_common_block entries. Also create a struct common_block |
| 11868 | listing all such variables for `info common'. COMMON_BLOCK_DOMAIN |
| 11869 | is used to sepate the common blocks name namespace from regular |
| 11870 | variable names. */ |
| 11871 | |
| 11872 | static void |
| 11873 | read_common_block (struct die_info *die, struct dwarf2_cu *cu) |
| 11874 | { |
| 11875 | struct attribute *attr; |
| 11876 | |
| 11877 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 11878 | if (attr) |
| 11879 | { |
| 11880 | /* Support the .debug_loc offsets. */ |
| 11881 | if (attr_form_is_block (attr)) |
| 11882 | { |
| 11883 | /* Ok. */ |
| 11884 | } |
| 11885 | else if (attr_form_is_section_offset (attr)) |
| 11886 | { |
| 11887 | dwarf2_complex_location_expr_complaint (); |
| 11888 | attr = NULL; |
| 11889 | } |
| 11890 | else |
| 11891 | { |
| 11892 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 11893 | "common block member"); |
| 11894 | attr = NULL; |
| 11895 | } |
| 11896 | } |
| 11897 | |
| 11898 | if (die->child != NULL) |
| 11899 | { |
| 11900 | struct objfile *objfile = cu->objfile; |
| 11901 | struct die_info *child_die; |
| 11902 | size_t n_entries = 0, size; |
| 11903 | struct common_block *common_block; |
| 11904 | struct symbol *sym; |
| 11905 | |
| 11906 | for (child_die = die->child; |
| 11907 | child_die && child_die->tag; |
| 11908 | child_die = sibling_die (child_die)) |
| 11909 | ++n_entries; |
| 11910 | |
| 11911 | size = (sizeof (struct common_block) |
| 11912 | + (n_entries - 1) * sizeof (struct symbol *)); |
| 11913 | common_block = obstack_alloc (&objfile->objfile_obstack, size); |
| 11914 | memset (common_block->contents, 0, n_entries * sizeof (struct symbol *)); |
| 11915 | common_block->n_entries = 0; |
| 11916 | |
| 11917 | for (child_die = die->child; |
| 11918 | child_die && child_die->tag; |
| 11919 | child_die = sibling_die (child_die)) |
| 11920 | { |
| 11921 | /* Create the symbol in the DW_TAG_common_block block in the current |
| 11922 | symbol scope. */ |
| 11923 | sym = new_symbol (child_die, NULL, cu); |
| 11924 | if (sym != NULL) |
| 11925 | { |
| 11926 | struct attribute *member_loc; |
| 11927 | |
| 11928 | common_block->contents[common_block->n_entries++] = sym; |
| 11929 | |
| 11930 | member_loc = dwarf2_attr (child_die, DW_AT_data_member_location, |
| 11931 | cu); |
| 11932 | if (member_loc) |
| 11933 | { |
| 11934 | /* GDB has handled this for a long time, but it is |
| 11935 | not specified by DWARF. It seems to have been |
| 11936 | emitted by gfortran at least as recently as: |
| 11937 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23057. */ |
| 11938 | complaint (&symfile_complaints, |
| 11939 | _("Variable in common block has " |
| 11940 | "DW_AT_data_member_location " |
| 11941 | "- DIE at 0x%x [in module %s]"), |
| 11942 | child_die->offset.sect_off, cu->objfile->name); |
| 11943 | |
| 11944 | if (attr_form_is_section_offset (member_loc)) |
| 11945 | dwarf2_complex_location_expr_complaint (); |
| 11946 | else if (attr_form_is_constant (member_loc) |
| 11947 | || attr_form_is_block (member_loc)) |
| 11948 | { |
| 11949 | if (attr) |
| 11950 | mark_common_block_symbol_computed (sym, die, attr, |
| 11951 | member_loc, cu); |
| 11952 | } |
| 11953 | else |
| 11954 | dwarf2_complex_location_expr_complaint (); |
| 11955 | } |
| 11956 | } |
| 11957 | } |
| 11958 | |
| 11959 | sym = new_symbol (die, objfile_type (objfile)->builtin_void, cu); |
| 11960 | SYMBOL_VALUE_COMMON_BLOCK (sym) = common_block; |
| 11961 | } |
| 11962 | } |
| 11963 | |
| 11964 | /* Create a type for a C++ namespace. */ |
| 11965 | |
| 11966 | static struct type * |
| 11967 | read_namespace_type (struct die_info *die, struct dwarf2_cu *cu) |
| 11968 | { |
| 11969 | struct objfile *objfile = cu->objfile; |
| 11970 | const char *previous_prefix, *name; |
| 11971 | int is_anonymous; |
| 11972 | struct type *type; |
| 11973 | |
| 11974 | /* For extensions, reuse the type of the original namespace. */ |
| 11975 | if (dwarf2_attr (die, DW_AT_extension, cu) != NULL) |
| 11976 | { |
| 11977 | struct die_info *ext_die; |
| 11978 | struct dwarf2_cu *ext_cu = cu; |
| 11979 | |
| 11980 | ext_die = dwarf2_extension (die, &ext_cu); |
| 11981 | type = read_type_die (ext_die, ext_cu); |
| 11982 | |
| 11983 | /* EXT_CU may not be the same as CU. |
| 11984 | Ensure TYPE is recorded in CU's type_hash table. */ |
| 11985 | return set_die_type (die, type, cu); |
| 11986 | } |
| 11987 | |
| 11988 | name = namespace_name (die, &is_anonymous, cu); |
| 11989 | |
| 11990 | /* Now build the name of the current namespace. */ |
| 11991 | |
| 11992 | previous_prefix = determine_prefix (die, cu); |
| 11993 | if (previous_prefix[0] != '\0') |
| 11994 | name = typename_concat (&objfile->objfile_obstack, |
| 11995 | previous_prefix, name, 0, cu); |
| 11996 | |
| 11997 | /* Create the type. */ |
| 11998 | type = init_type (TYPE_CODE_NAMESPACE, 0, 0, NULL, |
| 11999 | objfile); |
| 12000 | TYPE_NAME (type) = (char *) name; |
| 12001 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 12002 | |
| 12003 | return set_die_type (die, type, cu); |
| 12004 | } |
| 12005 | |
| 12006 | /* Read a C++ namespace. */ |
| 12007 | |
| 12008 | static void |
| 12009 | read_namespace (struct die_info *die, struct dwarf2_cu *cu) |
| 12010 | { |
| 12011 | struct objfile *objfile = cu->objfile; |
| 12012 | int is_anonymous; |
| 12013 | |
| 12014 | /* Add a symbol associated to this if we haven't seen the namespace |
| 12015 | before. Also, add a using directive if it's an anonymous |
| 12016 | namespace. */ |
| 12017 | |
| 12018 | if (dwarf2_attr (die, DW_AT_extension, cu) == NULL) |
| 12019 | { |
| 12020 | struct type *type; |
| 12021 | |
| 12022 | type = read_type_die (die, cu); |
| 12023 | new_symbol (die, type, cu); |
| 12024 | |
| 12025 | namespace_name (die, &is_anonymous, cu); |
| 12026 | if (is_anonymous) |
| 12027 | { |
| 12028 | const char *previous_prefix = determine_prefix (die, cu); |
| 12029 | |
| 12030 | cp_add_using_directive (previous_prefix, TYPE_NAME (type), NULL, |
| 12031 | NULL, NULL, &objfile->objfile_obstack); |
| 12032 | } |
| 12033 | } |
| 12034 | |
| 12035 | if (die->child != NULL) |
| 12036 | { |
| 12037 | struct die_info *child_die = die->child; |
| 12038 | |
| 12039 | while (child_die && child_die->tag) |
| 12040 | { |
| 12041 | process_die (child_die, cu); |
| 12042 | child_die = sibling_die (child_die); |
| 12043 | } |
| 12044 | } |
| 12045 | } |
| 12046 | |
| 12047 | /* Read a Fortran module as type. This DIE can be only a declaration used for |
| 12048 | imported module. Still we need that type as local Fortran "use ... only" |
| 12049 | declaration imports depend on the created type in determine_prefix. */ |
| 12050 | |
| 12051 | static struct type * |
| 12052 | read_module_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12053 | { |
| 12054 | struct objfile *objfile = cu->objfile; |
| 12055 | char *module_name; |
| 12056 | struct type *type; |
| 12057 | |
| 12058 | module_name = dwarf2_name (die, cu); |
| 12059 | if (!module_name) |
| 12060 | complaint (&symfile_complaints, |
| 12061 | _("DW_TAG_module has no name, offset 0x%x"), |
| 12062 | die->offset.sect_off); |
| 12063 | type = init_type (TYPE_CODE_MODULE, 0, 0, module_name, objfile); |
| 12064 | |
| 12065 | /* determine_prefix uses TYPE_TAG_NAME. */ |
| 12066 | TYPE_TAG_NAME (type) = TYPE_NAME (type); |
| 12067 | |
| 12068 | return set_die_type (die, type, cu); |
| 12069 | } |
| 12070 | |
| 12071 | /* Read a Fortran module. */ |
| 12072 | |
| 12073 | static void |
| 12074 | read_module (struct die_info *die, struct dwarf2_cu *cu) |
| 12075 | { |
| 12076 | struct die_info *child_die = die->child; |
| 12077 | |
| 12078 | while (child_die && child_die->tag) |
| 12079 | { |
| 12080 | process_die (child_die, cu); |
| 12081 | child_die = sibling_die (child_die); |
| 12082 | } |
| 12083 | } |
| 12084 | |
| 12085 | /* Return the name of the namespace represented by DIE. Set |
| 12086 | *IS_ANONYMOUS to tell whether or not the namespace is an anonymous |
| 12087 | namespace. */ |
| 12088 | |
| 12089 | static const char * |
| 12090 | namespace_name (struct die_info *die, int *is_anonymous, struct dwarf2_cu *cu) |
| 12091 | { |
| 12092 | struct die_info *current_die; |
| 12093 | const char *name = NULL; |
| 12094 | |
| 12095 | /* Loop through the extensions until we find a name. */ |
| 12096 | |
| 12097 | for (current_die = die; |
| 12098 | current_die != NULL; |
| 12099 | current_die = dwarf2_extension (die, &cu)) |
| 12100 | { |
| 12101 | name = dwarf2_name (current_die, cu); |
| 12102 | if (name != NULL) |
| 12103 | break; |
| 12104 | } |
| 12105 | |
| 12106 | /* Is it an anonymous namespace? */ |
| 12107 | |
| 12108 | *is_anonymous = (name == NULL); |
| 12109 | if (*is_anonymous) |
| 12110 | name = CP_ANONYMOUS_NAMESPACE_STR; |
| 12111 | |
| 12112 | return name; |
| 12113 | } |
| 12114 | |
| 12115 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
| 12116 | the user defined type vector. */ |
| 12117 | |
| 12118 | static struct type * |
| 12119 | read_tag_pointer_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12120 | { |
| 12121 | struct gdbarch *gdbarch = get_objfile_arch (cu->objfile); |
| 12122 | struct comp_unit_head *cu_header = &cu->header; |
| 12123 | struct type *type; |
| 12124 | struct attribute *attr_byte_size; |
| 12125 | struct attribute *attr_address_class; |
| 12126 | int byte_size, addr_class; |
| 12127 | struct type *target_type; |
| 12128 | |
| 12129 | target_type = die_type (die, cu); |
| 12130 | |
| 12131 | /* The die_type call above may have already set the type for this DIE. */ |
| 12132 | type = get_die_type (die, cu); |
| 12133 | if (type) |
| 12134 | return type; |
| 12135 | |
| 12136 | type = lookup_pointer_type (target_type); |
| 12137 | |
| 12138 | attr_byte_size = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 12139 | if (attr_byte_size) |
| 12140 | byte_size = DW_UNSND (attr_byte_size); |
| 12141 | else |
| 12142 | byte_size = cu_header->addr_size; |
| 12143 | |
| 12144 | attr_address_class = dwarf2_attr (die, DW_AT_address_class, cu); |
| 12145 | if (attr_address_class) |
| 12146 | addr_class = DW_UNSND (attr_address_class); |
| 12147 | else |
| 12148 | addr_class = DW_ADDR_none; |
| 12149 | |
| 12150 | /* If the pointer size or address class is different than the |
| 12151 | default, create a type variant marked as such and set the |
| 12152 | length accordingly. */ |
| 12153 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) |
| 12154 | { |
| 12155 | if (gdbarch_address_class_type_flags_p (gdbarch)) |
| 12156 | { |
| 12157 | int type_flags; |
| 12158 | |
| 12159 | type_flags = gdbarch_address_class_type_flags |
| 12160 | (gdbarch, byte_size, addr_class); |
| 12161 | gdb_assert ((type_flags & ~TYPE_INSTANCE_FLAG_ADDRESS_CLASS_ALL) |
| 12162 | == 0); |
| 12163 | type = make_type_with_address_space (type, type_flags); |
| 12164 | } |
| 12165 | else if (TYPE_LENGTH (type) != byte_size) |
| 12166 | { |
| 12167 | complaint (&symfile_complaints, |
| 12168 | _("invalid pointer size %d"), byte_size); |
| 12169 | } |
| 12170 | else |
| 12171 | { |
| 12172 | /* Should we also complain about unhandled address classes? */ |
| 12173 | } |
| 12174 | } |
| 12175 | |
| 12176 | TYPE_LENGTH (type) = byte_size; |
| 12177 | return set_die_type (die, type, cu); |
| 12178 | } |
| 12179 | |
| 12180 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to |
| 12181 | the user defined type vector. */ |
| 12182 | |
| 12183 | static struct type * |
| 12184 | read_tag_ptr_to_member_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12185 | { |
| 12186 | struct type *type; |
| 12187 | struct type *to_type; |
| 12188 | struct type *domain; |
| 12189 | |
| 12190 | to_type = die_type (die, cu); |
| 12191 | domain = die_containing_type (die, cu); |
| 12192 | |
| 12193 | /* The calls above may have already set the type for this DIE. */ |
| 12194 | type = get_die_type (die, cu); |
| 12195 | if (type) |
| 12196 | return type; |
| 12197 | |
| 12198 | if (TYPE_CODE (check_typedef (to_type)) == TYPE_CODE_METHOD) |
| 12199 | type = lookup_methodptr_type (to_type); |
| 12200 | else |
| 12201 | type = lookup_memberptr_type (to_type, domain); |
| 12202 | |
| 12203 | return set_die_type (die, type, cu); |
| 12204 | } |
| 12205 | |
| 12206 | /* Extract all information from a DW_TAG_reference_type DIE and add to |
| 12207 | the user defined type vector. */ |
| 12208 | |
| 12209 | static struct type * |
| 12210 | read_tag_reference_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12211 | { |
| 12212 | struct comp_unit_head *cu_header = &cu->header; |
| 12213 | struct type *type, *target_type; |
| 12214 | struct attribute *attr; |
| 12215 | |
| 12216 | target_type = die_type (die, cu); |
| 12217 | |
| 12218 | /* The die_type call above may have already set the type for this DIE. */ |
| 12219 | type = get_die_type (die, cu); |
| 12220 | if (type) |
| 12221 | return type; |
| 12222 | |
| 12223 | type = lookup_reference_type (target_type); |
| 12224 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 12225 | if (attr) |
| 12226 | { |
| 12227 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 12228 | } |
| 12229 | else |
| 12230 | { |
| 12231 | TYPE_LENGTH (type) = cu_header->addr_size; |
| 12232 | } |
| 12233 | return set_die_type (die, type, cu); |
| 12234 | } |
| 12235 | |
| 12236 | static struct type * |
| 12237 | read_tag_const_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12238 | { |
| 12239 | struct type *base_type, *cv_type; |
| 12240 | |
| 12241 | base_type = die_type (die, cu); |
| 12242 | |
| 12243 | /* The die_type call above may have already set the type for this DIE. */ |
| 12244 | cv_type = get_die_type (die, cu); |
| 12245 | if (cv_type) |
| 12246 | return cv_type; |
| 12247 | |
| 12248 | /* In case the const qualifier is applied to an array type, the element type |
| 12249 | is so qualified, not the array type (section 6.7.3 of C99). */ |
| 12250 | if (TYPE_CODE (base_type) == TYPE_CODE_ARRAY) |
| 12251 | { |
| 12252 | struct type *el_type, *inner_array; |
| 12253 | |
| 12254 | base_type = copy_type (base_type); |
| 12255 | inner_array = base_type; |
| 12256 | |
| 12257 | while (TYPE_CODE (TYPE_TARGET_TYPE (inner_array)) == TYPE_CODE_ARRAY) |
| 12258 | { |
| 12259 | TYPE_TARGET_TYPE (inner_array) = |
| 12260 | copy_type (TYPE_TARGET_TYPE (inner_array)); |
| 12261 | inner_array = TYPE_TARGET_TYPE (inner_array); |
| 12262 | } |
| 12263 | |
| 12264 | el_type = TYPE_TARGET_TYPE (inner_array); |
| 12265 | TYPE_TARGET_TYPE (inner_array) = |
| 12266 | make_cv_type (1, TYPE_VOLATILE (el_type), el_type, NULL); |
| 12267 | |
| 12268 | return set_die_type (die, base_type, cu); |
| 12269 | } |
| 12270 | |
| 12271 | cv_type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
| 12272 | return set_die_type (die, cv_type, cu); |
| 12273 | } |
| 12274 | |
| 12275 | static struct type * |
| 12276 | read_tag_volatile_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12277 | { |
| 12278 | struct type *base_type, *cv_type; |
| 12279 | |
| 12280 | base_type = die_type (die, cu); |
| 12281 | |
| 12282 | /* The die_type call above may have already set the type for this DIE. */ |
| 12283 | cv_type = get_die_type (die, cu); |
| 12284 | if (cv_type) |
| 12285 | return cv_type; |
| 12286 | |
| 12287 | cv_type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
| 12288 | return set_die_type (die, cv_type, cu); |
| 12289 | } |
| 12290 | |
| 12291 | /* Extract all information from a DW_TAG_string_type DIE and add to |
| 12292 | the user defined type vector. It isn't really a user defined type, |
| 12293 | but it behaves like one, with other DIE's using an AT_user_def_type |
| 12294 | attribute to reference it. */ |
| 12295 | |
| 12296 | static struct type * |
| 12297 | read_tag_string_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12298 | { |
| 12299 | struct objfile *objfile = cu->objfile; |
| 12300 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 12301 | struct type *type, *range_type, *index_type, *char_type; |
| 12302 | struct attribute *attr; |
| 12303 | unsigned int length; |
| 12304 | |
| 12305 | attr = dwarf2_attr (die, DW_AT_string_length, cu); |
| 12306 | if (attr) |
| 12307 | { |
| 12308 | length = DW_UNSND (attr); |
| 12309 | } |
| 12310 | else |
| 12311 | { |
| 12312 | /* Check for the DW_AT_byte_size attribute. */ |
| 12313 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 12314 | if (attr) |
| 12315 | { |
| 12316 | length = DW_UNSND (attr); |
| 12317 | } |
| 12318 | else |
| 12319 | { |
| 12320 | length = 1; |
| 12321 | } |
| 12322 | } |
| 12323 | |
| 12324 | index_type = objfile_type (objfile)->builtin_int; |
| 12325 | range_type = create_range_type (NULL, index_type, 1, length); |
| 12326 | char_type = language_string_char_type (cu->language_defn, gdbarch); |
| 12327 | type = create_string_type (NULL, char_type, range_type); |
| 12328 | |
| 12329 | return set_die_type (die, type, cu); |
| 12330 | } |
| 12331 | |
| 12332 | /* Handle DIES due to C code like: |
| 12333 | |
| 12334 | struct foo |
| 12335 | { |
| 12336 | int (*funcp)(int a, long l); |
| 12337 | int b; |
| 12338 | }; |
| 12339 | |
| 12340 | ('funcp' generates a DW_TAG_subroutine_type DIE). */ |
| 12341 | |
| 12342 | static struct type * |
| 12343 | read_subroutine_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12344 | { |
| 12345 | struct objfile *objfile = cu->objfile; |
| 12346 | struct type *type; /* Type that this function returns. */ |
| 12347 | struct type *ftype; /* Function that returns above type. */ |
| 12348 | struct attribute *attr; |
| 12349 | |
| 12350 | type = die_type (die, cu); |
| 12351 | |
| 12352 | /* The die_type call above may have already set the type for this DIE. */ |
| 12353 | ftype = get_die_type (die, cu); |
| 12354 | if (ftype) |
| 12355 | return ftype; |
| 12356 | |
| 12357 | ftype = lookup_function_type (type); |
| 12358 | |
| 12359 | /* All functions in C++, Pascal and Java have prototypes. */ |
| 12360 | attr = dwarf2_attr (die, DW_AT_prototyped, cu); |
| 12361 | if ((attr && (DW_UNSND (attr) != 0)) |
| 12362 | || cu->language == language_cplus |
| 12363 | || cu->language == language_java |
| 12364 | || cu->language == language_pascal) |
| 12365 | TYPE_PROTOTYPED (ftype) = 1; |
| 12366 | else if (producer_is_realview (cu->producer)) |
| 12367 | /* RealView does not emit DW_AT_prototyped. We can not |
| 12368 | distinguish prototyped and unprototyped functions; default to |
| 12369 | prototyped, since that is more common in modern code (and |
| 12370 | RealView warns about unprototyped functions). */ |
| 12371 | TYPE_PROTOTYPED (ftype) = 1; |
| 12372 | |
| 12373 | /* Store the calling convention in the type if it's available in |
| 12374 | the subroutine die. Otherwise set the calling convention to |
| 12375 | the default value DW_CC_normal. */ |
| 12376 | attr = dwarf2_attr (die, DW_AT_calling_convention, cu); |
| 12377 | if (attr) |
| 12378 | TYPE_CALLING_CONVENTION (ftype) = DW_UNSND (attr); |
| 12379 | else if (cu->producer && strstr (cu->producer, "IBM XL C for OpenCL")) |
| 12380 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_GDB_IBM_OpenCL; |
| 12381 | else |
| 12382 | TYPE_CALLING_CONVENTION (ftype) = DW_CC_normal; |
| 12383 | |
| 12384 | /* We need to add the subroutine type to the die immediately so |
| 12385 | we don't infinitely recurse when dealing with parameters |
| 12386 | declared as the same subroutine type. */ |
| 12387 | set_die_type (die, ftype, cu); |
| 12388 | |
| 12389 | if (die->child != NULL) |
| 12390 | { |
| 12391 | struct type *void_type = objfile_type (objfile)->builtin_void; |
| 12392 | struct die_info *child_die; |
| 12393 | int nparams, iparams; |
| 12394 | |
| 12395 | /* Count the number of parameters. |
| 12396 | FIXME: GDB currently ignores vararg functions, but knows about |
| 12397 | vararg member functions. */ |
| 12398 | nparams = 0; |
| 12399 | child_die = die->child; |
| 12400 | while (child_die && child_die->tag) |
| 12401 | { |
| 12402 | if (child_die->tag == DW_TAG_formal_parameter) |
| 12403 | nparams++; |
| 12404 | else if (child_die->tag == DW_TAG_unspecified_parameters) |
| 12405 | TYPE_VARARGS (ftype) = 1; |
| 12406 | child_die = sibling_die (child_die); |
| 12407 | } |
| 12408 | |
| 12409 | /* Allocate storage for parameters and fill them in. */ |
| 12410 | TYPE_NFIELDS (ftype) = nparams; |
| 12411 | TYPE_FIELDS (ftype) = (struct field *) |
| 12412 | TYPE_ZALLOC (ftype, nparams * sizeof (struct field)); |
| 12413 | |
| 12414 | /* TYPE_FIELD_TYPE must never be NULL. Pre-fill the array to ensure it |
| 12415 | even if we error out during the parameters reading below. */ |
| 12416 | for (iparams = 0; iparams < nparams; iparams++) |
| 12417 | TYPE_FIELD_TYPE (ftype, iparams) = void_type; |
| 12418 | |
| 12419 | iparams = 0; |
| 12420 | child_die = die->child; |
| 12421 | while (child_die && child_die->tag) |
| 12422 | { |
| 12423 | if (child_die->tag == DW_TAG_formal_parameter) |
| 12424 | { |
| 12425 | struct type *arg_type; |
| 12426 | |
| 12427 | /* DWARF version 2 has no clean way to discern C++ |
| 12428 | static and non-static member functions. G++ helps |
| 12429 | GDB by marking the first parameter for non-static |
| 12430 | member functions (which is the this pointer) as |
| 12431 | artificial. We pass this information to |
| 12432 | dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. |
| 12433 | |
| 12434 | DWARF version 3 added DW_AT_object_pointer, which GCC |
| 12435 | 4.5 does not yet generate. */ |
| 12436 | attr = dwarf2_attr (child_die, DW_AT_artificial, cu); |
| 12437 | if (attr) |
| 12438 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); |
| 12439 | else |
| 12440 | { |
| 12441 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
| 12442 | |
| 12443 | /* GCC/43521: In java, the formal parameter |
| 12444 | "this" is sometimes not marked with DW_AT_artificial. */ |
| 12445 | if (cu->language == language_java) |
| 12446 | { |
| 12447 | const char *name = dwarf2_name (child_die, cu); |
| 12448 | |
| 12449 | if (name && !strcmp (name, "this")) |
| 12450 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 1; |
| 12451 | } |
| 12452 | } |
| 12453 | arg_type = die_type (child_die, cu); |
| 12454 | |
| 12455 | /* RealView does not mark THIS as const, which the testsuite |
| 12456 | expects. GCC marks THIS as const in method definitions, |
| 12457 | but not in the class specifications (GCC PR 43053). */ |
| 12458 | if (cu->language == language_cplus && !TYPE_CONST (arg_type) |
| 12459 | && TYPE_FIELD_ARTIFICIAL (ftype, iparams)) |
| 12460 | { |
| 12461 | int is_this = 0; |
| 12462 | struct dwarf2_cu *arg_cu = cu; |
| 12463 | const char *name = dwarf2_name (child_die, cu); |
| 12464 | |
| 12465 | attr = dwarf2_attr (die, DW_AT_object_pointer, cu); |
| 12466 | if (attr) |
| 12467 | { |
| 12468 | /* If the compiler emits this, use it. */ |
| 12469 | if (follow_die_ref (die, attr, &arg_cu) == child_die) |
| 12470 | is_this = 1; |
| 12471 | } |
| 12472 | else if (name && strcmp (name, "this") == 0) |
| 12473 | /* Function definitions will have the argument names. */ |
| 12474 | is_this = 1; |
| 12475 | else if (name == NULL && iparams == 0) |
| 12476 | /* Declarations may not have the names, so like |
| 12477 | elsewhere in GDB, assume an artificial first |
| 12478 | argument is "this". */ |
| 12479 | is_this = 1; |
| 12480 | |
| 12481 | if (is_this) |
| 12482 | arg_type = make_cv_type (1, TYPE_VOLATILE (arg_type), |
| 12483 | arg_type, 0); |
| 12484 | } |
| 12485 | |
| 12486 | TYPE_FIELD_TYPE (ftype, iparams) = arg_type; |
| 12487 | iparams++; |
| 12488 | } |
| 12489 | child_die = sibling_die (child_die); |
| 12490 | } |
| 12491 | } |
| 12492 | |
| 12493 | return ftype; |
| 12494 | } |
| 12495 | |
| 12496 | static struct type * |
| 12497 | read_typedef (struct die_info *die, struct dwarf2_cu *cu) |
| 12498 | { |
| 12499 | struct objfile *objfile = cu->objfile; |
| 12500 | const char *name = NULL; |
| 12501 | struct type *this_type, *target_type; |
| 12502 | |
| 12503 | name = dwarf2_full_name (NULL, die, cu); |
| 12504 | this_type = init_type (TYPE_CODE_TYPEDEF, 0, |
| 12505 | TYPE_FLAG_TARGET_STUB, NULL, objfile); |
| 12506 | TYPE_NAME (this_type) = (char *) name; |
| 12507 | set_die_type (die, this_type, cu); |
| 12508 | target_type = die_type (die, cu); |
| 12509 | if (target_type != this_type) |
| 12510 | TYPE_TARGET_TYPE (this_type) = target_type; |
| 12511 | else |
| 12512 | { |
| 12513 | /* Self-referential typedefs are, it seems, not allowed by the DWARF |
| 12514 | spec and cause infinite loops in GDB. */ |
| 12515 | complaint (&symfile_complaints, |
| 12516 | _("Self-referential DW_TAG_typedef " |
| 12517 | "- DIE at 0x%x [in module %s]"), |
| 12518 | die->offset.sect_off, objfile->name); |
| 12519 | TYPE_TARGET_TYPE (this_type) = NULL; |
| 12520 | } |
| 12521 | return this_type; |
| 12522 | } |
| 12523 | |
| 12524 | /* Find a representation of a given base type and install |
| 12525 | it in the TYPE field of the die. */ |
| 12526 | |
| 12527 | static struct type * |
| 12528 | read_base_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12529 | { |
| 12530 | struct objfile *objfile = cu->objfile; |
| 12531 | struct type *type; |
| 12532 | struct attribute *attr; |
| 12533 | int encoding = 0, size = 0; |
| 12534 | char *name; |
| 12535 | enum type_code code = TYPE_CODE_INT; |
| 12536 | int type_flags = 0; |
| 12537 | struct type *target_type = NULL; |
| 12538 | |
| 12539 | attr = dwarf2_attr (die, DW_AT_encoding, cu); |
| 12540 | if (attr) |
| 12541 | { |
| 12542 | encoding = DW_UNSND (attr); |
| 12543 | } |
| 12544 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 12545 | if (attr) |
| 12546 | { |
| 12547 | size = DW_UNSND (attr); |
| 12548 | } |
| 12549 | name = dwarf2_name (die, cu); |
| 12550 | if (!name) |
| 12551 | { |
| 12552 | complaint (&symfile_complaints, |
| 12553 | _("DW_AT_name missing from DW_TAG_base_type")); |
| 12554 | } |
| 12555 | |
| 12556 | switch (encoding) |
| 12557 | { |
| 12558 | case DW_ATE_address: |
| 12559 | /* Turn DW_ATE_address into a void * pointer. */ |
| 12560 | code = TYPE_CODE_PTR; |
| 12561 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 12562 | target_type = init_type (TYPE_CODE_VOID, 1, 0, NULL, objfile); |
| 12563 | break; |
| 12564 | case DW_ATE_boolean: |
| 12565 | code = TYPE_CODE_BOOL; |
| 12566 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 12567 | break; |
| 12568 | case DW_ATE_complex_float: |
| 12569 | code = TYPE_CODE_COMPLEX; |
| 12570 | target_type = init_type (TYPE_CODE_FLT, size / 2, 0, NULL, objfile); |
| 12571 | break; |
| 12572 | case DW_ATE_decimal_float: |
| 12573 | code = TYPE_CODE_DECFLOAT; |
| 12574 | break; |
| 12575 | case DW_ATE_float: |
| 12576 | code = TYPE_CODE_FLT; |
| 12577 | break; |
| 12578 | case DW_ATE_signed: |
| 12579 | break; |
| 12580 | case DW_ATE_unsigned: |
| 12581 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 12582 | if (cu->language == language_fortran |
| 12583 | && name |
| 12584 | && strncmp (name, "character(", sizeof ("character(") - 1) == 0) |
| 12585 | code = TYPE_CODE_CHAR; |
| 12586 | break; |
| 12587 | case DW_ATE_signed_char: |
| 12588 | if (cu->language == language_ada || cu->language == language_m2 |
| 12589 | || cu->language == language_pascal |
| 12590 | || cu->language == language_fortran) |
| 12591 | code = TYPE_CODE_CHAR; |
| 12592 | break; |
| 12593 | case DW_ATE_unsigned_char: |
| 12594 | if (cu->language == language_ada || cu->language == language_m2 |
| 12595 | || cu->language == language_pascal |
| 12596 | || cu->language == language_fortran) |
| 12597 | code = TYPE_CODE_CHAR; |
| 12598 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 12599 | break; |
| 12600 | case DW_ATE_UTF: |
| 12601 | /* We just treat this as an integer and then recognize the |
| 12602 | type by name elsewhere. */ |
| 12603 | break; |
| 12604 | |
| 12605 | default: |
| 12606 | complaint (&symfile_complaints, _("unsupported DW_AT_encoding: '%s'"), |
| 12607 | dwarf_type_encoding_name (encoding)); |
| 12608 | break; |
| 12609 | } |
| 12610 | |
| 12611 | type = init_type (code, size, type_flags, NULL, objfile); |
| 12612 | TYPE_NAME (type) = name; |
| 12613 | TYPE_TARGET_TYPE (type) = target_type; |
| 12614 | |
| 12615 | if (name && strcmp (name, "char") == 0) |
| 12616 | TYPE_NOSIGN (type) = 1; |
| 12617 | |
| 12618 | return set_die_type (die, type, cu); |
| 12619 | } |
| 12620 | |
| 12621 | /* Read the given DW_AT_subrange DIE. */ |
| 12622 | |
| 12623 | static struct type * |
| 12624 | read_subrange_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12625 | { |
| 12626 | struct type *base_type; |
| 12627 | struct type *range_type; |
| 12628 | struct attribute *attr; |
| 12629 | LONGEST low, high; |
| 12630 | int low_default_is_valid; |
| 12631 | char *name; |
| 12632 | LONGEST negative_mask; |
| 12633 | |
| 12634 | base_type = die_type (die, cu); |
| 12635 | /* Preserve BASE_TYPE's original type, just set its LENGTH. */ |
| 12636 | check_typedef (base_type); |
| 12637 | |
| 12638 | /* The die_type call above may have already set the type for this DIE. */ |
| 12639 | range_type = get_die_type (die, cu); |
| 12640 | if (range_type) |
| 12641 | return range_type; |
| 12642 | |
| 12643 | /* Set LOW_DEFAULT_IS_VALID if current language and DWARF version allow |
| 12644 | omitting DW_AT_lower_bound. */ |
| 12645 | switch (cu->language) |
| 12646 | { |
| 12647 | case language_c: |
| 12648 | case language_cplus: |
| 12649 | low = 0; |
| 12650 | low_default_is_valid = 1; |
| 12651 | break; |
| 12652 | case language_fortran: |
| 12653 | low = 1; |
| 12654 | low_default_is_valid = 1; |
| 12655 | break; |
| 12656 | case language_d: |
| 12657 | case language_java: |
| 12658 | case language_objc: |
| 12659 | low = 0; |
| 12660 | low_default_is_valid = (cu->header.version >= 4); |
| 12661 | break; |
| 12662 | case language_ada: |
| 12663 | case language_m2: |
| 12664 | case language_pascal: |
| 12665 | low = 1; |
| 12666 | low_default_is_valid = (cu->header.version >= 4); |
| 12667 | break; |
| 12668 | default: |
| 12669 | low = 0; |
| 12670 | low_default_is_valid = 0; |
| 12671 | break; |
| 12672 | } |
| 12673 | |
| 12674 | /* FIXME: For variable sized arrays either of these could be |
| 12675 | a variable rather than a constant value. We'll allow it, |
| 12676 | but we don't know how to handle it. */ |
| 12677 | attr = dwarf2_attr (die, DW_AT_lower_bound, cu); |
| 12678 | if (attr) |
| 12679 | low = dwarf2_get_attr_constant_value (attr, low); |
| 12680 | else if (!low_default_is_valid) |
| 12681 | complaint (&symfile_complaints, _("Missing DW_AT_lower_bound " |
| 12682 | "- DIE at 0x%x [in module %s]"), |
| 12683 | die->offset.sect_off, cu->objfile->name); |
| 12684 | |
| 12685 | attr = dwarf2_attr (die, DW_AT_upper_bound, cu); |
| 12686 | if (attr) |
| 12687 | { |
| 12688 | if (attr_form_is_block (attr) || is_ref_attr (attr)) |
| 12689 | { |
| 12690 | /* GCC encodes arrays with unspecified or dynamic length |
| 12691 | with a DW_FORM_block1 attribute or a reference attribute. |
| 12692 | FIXME: GDB does not yet know how to handle dynamic |
| 12693 | arrays properly, treat them as arrays with unspecified |
| 12694 | length for now. |
| 12695 | |
| 12696 | FIXME: jimb/2003-09-22: GDB does not really know |
| 12697 | how to handle arrays of unspecified length |
| 12698 | either; we just represent them as zero-length |
| 12699 | arrays. Choose an appropriate upper bound given |
| 12700 | the lower bound we've computed above. */ |
| 12701 | high = low - 1; |
| 12702 | } |
| 12703 | else |
| 12704 | high = dwarf2_get_attr_constant_value (attr, 1); |
| 12705 | } |
| 12706 | else |
| 12707 | { |
| 12708 | attr = dwarf2_attr (die, DW_AT_count, cu); |
| 12709 | if (attr) |
| 12710 | { |
| 12711 | int count = dwarf2_get_attr_constant_value (attr, 1); |
| 12712 | high = low + count - 1; |
| 12713 | } |
| 12714 | else |
| 12715 | { |
| 12716 | /* Unspecified array length. */ |
| 12717 | high = low - 1; |
| 12718 | } |
| 12719 | } |
| 12720 | |
| 12721 | /* Dwarf-2 specifications explicitly allows to create subrange types |
| 12722 | without specifying a base type. |
| 12723 | In that case, the base type must be set to the type of |
| 12724 | the lower bound, upper bound or count, in that order, if any of these |
| 12725 | three attributes references an object that has a type. |
| 12726 | If no base type is found, the Dwarf-2 specifications say that |
| 12727 | a signed integer type of size equal to the size of an address should |
| 12728 | be used. |
| 12729 | For the following C code: `extern char gdb_int [];' |
| 12730 | GCC produces an empty range DIE. |
| 12731 | FIXME: muller/2010-05-28: Possible references to object for low bound, |
| 12732 | high bound or count are not yet handled by this code. */ |
| 12733 | if (TYPE_CODE (base_type) == TYPE_CODE_VOID) |
| 12734 | { |
| 12735 | struct objfile *objfile = cu->objfile; |
| 12736 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 12737 | int addr_size = gdbarch_addr_bit (gdbarch) /8; |
| 12738 | struct type *int_type = objfile_type (objfile)->builtin_int; |
| 12739 | |
| 12740 | /* Test "int", "long int", and "long long int" objfile types, |
| 12741 | and select the first one having a size above or equal to the |
| 12742 | architecture address size. */ |
| 12743 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 12744 | base_type = int_type; |
| 12745 | else |
| 12746 | { |
| 12747 | int_type = objfile_type (objfile)->builtin_long; |
| 12748 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 12749 | base_type = int_type; |
| 12750 | else |
| 12751 | { |
| 12752 | int_type = objfile_type (objfile)->builtin_long_long; |
| 12753 | if (int_type && TYPE_LENGTH (int_type) >= addr_size) |
| 12754 | base_type = int_type; |
| 12755 | } |
| 12756 | } |
| 12757 | } |
| 12758 | |
| 12759 | negative_mask = |
| 12760 | (LONGEST) -1 << (TYPE_LENGTH (base_type) * TARGET_CHAR_BIT - 1); |
| 12761 | if (!TYPE_UNSIGNED (base_type) && (low & negative_mask)) |
| 12762 | low |= negative_mask; |
| 12763 | if (!TYPE_UNSIGNED (base_type) && (high & negative_mask)) |
| 12764 | high |= negative_mask; |
| 12765 | |
| 12766 | range_type = create_range_type (NULL, base_type, low, high); |
| 12767 | |
| 12768 | /* Mark arrays with dynamic length at least as an array of unspecified |
| 12769 | length. GDB could check the boundary but before it gets implemented at |
| 12770 | least allow accessing the array elements. */ |
| 12771 | if (attr && attr_form_is_block (attr)) |
| 12772 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
| 12773 | |
| 12774 | /* Ada expects an empty array on no boundary attributes. */ |
| 12775 | if (attr == NULL && cu->language != language_ada) |
| 12776 | TYPE_HIGH_BOUND_UNDEFINED (range_type) = 1; |
| 12777 | |
| 12778 | name = dwarf2_name (die, cu); |
| 12779 | if (name) |
| 12780 | TYPE_NAME (range_type) = name; |
| 12781 | |
| 12782 | attr = dwarf2_attr (die, DW_AT_byte_size, cu); |
| 12783 | if (attr) |
| 12784 | TYPE_LENGTH (range_type) = DW_UNSND (attr); |
| 12785 | |
| 12786 | set_die_type (die, range_type, cu); |
| 12787 | |
| 12788 | /* set_die_type should be already done. */ |
| 12789 | set_descriptive_type (range_type, die, cu); |
| 12790 | |
| 12791 | return range_type; |
| 12792 | } |
| 12793 | |
| 12794 | static struct type * |
| 12795 | read_unspecified_type (struct die_info *die, struct dwarf2_cu *cu) |
| 12796 | { |
| 12797 | struct type *type; |
| 12798 | |
| 12799 | /* For now, we only support the C meaning of an unspecified type: void. */ |
| 12800 | |
| 12801 | type = init_type (TYPE_CODE_VOID, 0, 0, NULL, cu->objfile); |
| 12802 | TYPE_NAME (type) = dwarf2_name (die, cu); |
| 12803 | |
| 12804 | return set_die_type (die, type, cu); |
| 12805 | } |
| 12806 | |
| 12807 | /* Read a single die and all its descendents. Set the die's sibling |
| 12808 | field to NULL; set other fields in the die correctly, and set all |
| 12809 | of the descendents' fields correctly. Set *NEW_INFO_PTR to the |
| 12810 | location of the info_ptr after reading all of those dies. PARENT |
| 12811 | is the parent of the die in question. */ |
| 12812 | |
| 12813 | static struct die_info * |
| 12814 | read_die_and_children (const struct die_reader_specs *reader, |
| 12815 | gdb_byte *info_ptr, |
| 12816 | gdb_byte **new_info_ptr, |
| 12817 | struct die_info *parent) |
| 12818 | { |
| 12819 | struct die_info *die; |
| 12820 | gdb_byte *cur_ptr; |
| 12821 | int has_children; |
| 12822 | |
| 12823 | cur_ptr = read_full_die (reader, &die, info_ptr, &has_children); |
| 12824 | if (die == NULL) |
| 12825 | { |
| 12826 | *new_info_ptr = cur_ptr; |
| 12827 | return NULL; |
| 12828 | } |
| 12829 | store_in_ref_table (die, reader->cu); |
| 12830 | |
| 12831 | if (has_children) |
| 12832 | die->child = read_die_and_siblings (reader, cur_ptr, new_info_ptr, die); |
| 12833 | else |
| 12834 | { |
| 12835 | die->child = NULL; |
| 12836 | *new_info_ptr = cur_ptr; |
| 12837 | } |
| 12838 | |
| 12839 | die->sibling = NULL; |
| 12840 | die->parent = parent; |
| 12841 | return die; |
| 12842 | } |
| 12843 | |
| 12844 | /* Read a die, all of its descendents, and all of its siblings; set |
| 12845 | all of the fields of all of the dies correctly. Arguments are as |
| 12846 | in read_die_and_children. */ |
| 12847 | |
| 12848 | static struct die_info * |
| 12849 | read_die_and_siblings (const struct die_reader_specs *reader, |
| 12850 | gdb_byte *info_ptr, |
| 12851 | gdb_byte **new_info_ptr, |
| 12852 | struct die_info *parent) |
| 12853 | { |
| 12854 | struct die_info *first_die, *last_sibling; |
| 12855 | gdb_byte *cur_ptr; |
| 12856 | |
| 12857 | cur_ptr = info_ptr; |
| 12858 | first_die = last_sibling = NULL; |
| 12859 | |
| 12860 | while (1) |
| 12861 | { |
| 12862 | struct die_info *die |
| 12863 | = read_die_and_children (reader, cur_ptr, &cur_ptr, parent); |
| 12864 | |
| 12865 | if (die == NULL) |
| 12866 | { |
| 12867 | *new_info_ptr = cur_ptr; |
| 12868 | return first_die; |
| 12869 | } |
| 12870 | |
| 12871 | if (!first_die) |
| 12872 | first_die = die; |
| 12873 | else |
| 12874 | last_sibling->sibling = die; |
| 12875 | |
| 12876 | last_sibling = die; |
| 12877 | } |
| 12878 | } |
| 12879 | |
| 12880 | /* Read a die and all its attributes, leave space for NUM_EXTRA_ATTRS |
| 12881 | attributes. |
| 12882 | The caller is responsible for filling in the extra attributes |
| 12883 | and updating (*DIEP)->num_attrs. |
| 12884 | Set DIEP to point to a newly allocated die with its information, |
| 12885 | except for its child, sibling, and parent fields. |
| 12886 | Set HAS_CHILDREN to tell whether the die has children or not. */ |
| 12887 | |
| 12888 | static gdb_byte * |
| 12889 | read_full_die_1 (const struct die_reader_specs *reader, |
| 12890 | struct die_info **diep, gdb_byte *info_ptr, |
| 12891 | int *has_children, int num_extra_attrs) |
| 12892 | { |
| 12893 | unsigned int abbrev_number, bytes_read, i; |
| 12894 | sect_offset offset; |
| 12895 | struct abbrev_info *abbrev; |
| 12896 | struct die_info *die; |
| 12897 | struct dwarf2_cu *cu = reader->cu; |
| 12898 | bfd *abfd = reader->abfd; |
| 12899 | |
| 12900 | offset.sect_off = info_ptr - reader->buffer; |
| 12901 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 12902 | info_ptr += bytes_read; |
| 12903 | if (!abbrev_number) |
| 12904 | { |
| 12905 | *diep = NULL; |
| 12906 | *has_children = 0; |
| 12907 | return info_ptr; |
| 12908 | } |
| 12909 | |
| 12910 | abbrev = abbrev_table_lookup_abbrev (cu->abbrev_table, abbrev_number); |
| 12911 | if (!abbrev) |
| 12912 | error (_("Dwarf Error: could not find abbrev number %d [in module %s]"), |
| 12913 | abbrev_number, |
| 12914 | bfd_get_filename (abfd)); |
| 12915 | |
| 12916 | die = dwarf_alloc_die (cu, abbrev->num_attrs + num_extra_attrs); |
| 12917 | die->offset = offset; |
| 12918 | die->tag = abbrev->tag; |
| 12919 | die->abbrev = abbrev_number; |
| 12920 | |
| 12921 | /* Make the result usable. |
| 12922 | The caller needs to update num_attrs after adding the extra |
| 12923 | attributes. */ |
| 12924 | die->num_attrs = abbrev->num_attrs; |
| 12925 | |
| 12926 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 12927 | info_ptr = read_attribute (reader, &die->attrs[i], &abbrev->attrs[i], |
| 12928 | info_ptr); |
| 12929 | |
| 12930 | *diep = die; |
| 12931 | *has_children = abbrev->has_children; |
| 12932 | return info_ptr; |
| 12933 | } |
| 12934 | |
| 12935 | /* Read a die and all its attributes. |
| 12936 | Set DIEP to point to a newly allocated die with its information, |
| 12937 | except for its child, sibling, and parent fields. |
| 12938 | Set HAS_CHILDREN to tell whether the die has children or not. */ |
| 12939 | |
| 12940 | static gdb_byte * |
| 12941 | read_full_die (const struct die_reader_specs *reader, |
| 12942 | struct die_info **diep, gdb_byte *info_ptr, |
| 12943 | int *has_children) |
| 12944 | { |
| 12945 | return read_full_die_1 (reader, diep, info_ptr, has_children, 0); |
| 12946 | } |
| 12947 | \f |
| 12948 | /* Abbreviation tables. |
| 12949 | |
| 12950 | In DWARF version 2, the description of the debugging information is |
| 12951 | stored in a separate .debug_abbrev section. Before we read any |
| 12952 | dies from a section we read in all abbreviations and install them |
| 12953 | in a hash table. */ |
| 12954 | |
| 12955 | /* Allocate space for a struct abbrev_info object in ABBREV_TABLE. */ |
| 12956 | |
| 12957 | static struct abbrev_info * |
| 12958 | abbrev_table_alloc_abbrev (struct abbrev_table *abbrev_table) |
| 12959 | { |
| 12960 | struct abbrev_info *abbrev; |
| 12961 | |
| 12962 | abbrev = (struct abbrev_info *) |
| 12963 | obstack_alloc (&abbrev_table->abbrev_obstack, sizeof (struct abbrev_info)); |
| 12964 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
| 12965 | return abbrev; |
| 12966 | } |
| 12967 | |
| 12968 | /* Add an abbreviation to the table. */ |
| 12969 | |
| 12970 | static void |
| 12971 | abbrev_table_add_abbrev (struct abbrev_table *abbrev_table, |
| 12972 | unsigned int abbrev_number, |
| 12973 | struct abbrev_info *abbrev) |
| 12974 | { |
| 12975 | unsigned int hash_number; |
| 12976 | |
| 12977 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
| 12978 | abbrev->next = abbrev_table->abbrevs[hash_number]; |
| 12979 | abbrev_table->abbrevs[hash_number] = abbrev; |
| 12980 | } |
| 12981 | |
| 12982 | /* Look up an abbrev in the table. |
| 12983 | Returns NULL if the abbrev is not found. */ |
| 12984 | |
| 12985 | static struct abbrev_info * |
| 12986 | abbrev_table_lookup_abbrev (const struct abbrev_table *abbrev_table, |
| 12987 | unsigned int abbrev_number) |
| 12988 | { |
| 12989 | unsigned int hash_number; |
| 12990 | struct abbrev_info *abbrev; |
| 12991 | |
| 12992 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
| 12993 | abbrev = abbrev_table->abbrevs[hash_number]; |
| 12994 | |
| 12995 | while (abbrev) |
| 12996 | { |
| 12997 | if (abbrev->number == abbrev_number) |
| 12998 | return abbrev; |
| 12999 | abbrev = abbrev->next; |
| 13000 | } |
| 13001 | return NULL; |
| 13002 | } |
| 13003 | |
| 13004 | /* Read in an abbrev table. */ |
| 13005 | |
| 13006 | static struct abbrev_table * |
| 13007 | abbrev_table_read_table (struct dwarf2_section_info *section, |
| 13008 | sect_offset offset) |
| 13009 | { |
| 13010 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 13011 | bfd *abfd = section->asection->owner; |
| 13012 | struct abbrev_table *abbrev_table; |
| 13013 | gdb_byte *abbrev_ptr; |
| 13014 | struct abbrev_info *cur_abbrev; |
| 13015 | unsigned int abbrev_number, bytes_read, abbrev_name; |
| 13016 | unsigned int abbrev_form; |
| 13017 | struct attr_abbrev *cur_attrs; |
| 13018 | unsigned int allocated_attrs; |
| 13019 | |
| 13020 | abbrev_table = XMALLOC (struct abbrev_table); |
| 13021 | abbrev_table->offset = offset; |
| 13022 | obstack_init (&abbrev_table->abbrev_obstack); |
| 13023 | abbrev_table->abbrevs = obstack_alloc (&abbrev_table->abbrev_obstack, |
| 13024 | (ABBREV_HASH_SIZE |
| 13025 | * sizeof (struct abbrev_info *))); |
| 13026 | memset (abbrev_table->abbrevs, 0, |
| 13027 | ABBREV_HASH_SIZE * sizeof (struct abbrev_info *)); |
| 13028 | |
| 13029 | dwarf2_read_section (objfile, section); |
| 13030 | abbrev_ptr = section->buffer + offset.sect_off; |
| 13031 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13032 | abbrev_ptr += bytes_read; |
| 13033 | |
| 13034 | allocated_attrs = ATTR_ALLOC_CHUNK; |
| 13035 | cur_attrs = xmalloc (allocated_attrs * sizeof (struct attr_abbrev)); |
| 13036 | |
| 13037 | /* Loop until we reach an abbrev number of 0. */ |
| 13038 | while (abbrev_number) |
| 13039 | { |
| 13040 | cur_abbrev = abbrev_table_alloc_abbrev (abbrev_table); |
| 13041 | |
| 13042 | /* read in abbrev header */ |
| 13043 | cur_abbrev->number = abbrev_number; |
| 13044 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13045 | abbrev_ptr += bytes_read; |
| 13046 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); |
| 13047 | abbrev_ptr += 1; |
| 13048 | |
| 13049 | /* now read in declarations */ |
| 13050 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13051 | abbrev_ptr += bytes_read; |
| 13052 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13053 | abbrev_ptr += bytes_read; |
| 13054 | while (abbrev_name) |
| 13055 | { |
| 13056 | if (cur_abbrev->num_attrs == allocated_attrs) |
| 13057 | { |
| 13058 | allocated_attrs += ATTR_ALLOC_CHUNK; |
| 13059 | cur_attrs |
| 13060 | = xrealloc (cur_attrs, (allocated_attrs |
| 13061 | * sizeof (struct attr_abbrev))); |
| 13062 | } |
| 13063 | |
| 13064 | cur_attrs[cur_abbrev->num_attrs].name = abbrev_name; |
| 13065 | cur_attrs[cur_abbrev->num_attrs++].form = abbrev_form; |
| 13066 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13067 | abbrev_ptr += bytes_read; |
| 13068 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13069 | abbrev_ptr += bytes_read; |
| 13070 | } |
| 13071 | |
| 13072 | cur_abbrev->attrs = obstack_alloc (&abbrev_table->abbrev_obstack, |
| 13073 | (cur_abbrev->num_attrs |
| 13074 | * sizeof (struct attr_abbrev))); |
| 13075 | memcpy (cur_abbrev->attrs, cur_attrs, |
| 13076 | cur_abbrev->num_attrs * sizeof (struct attr_abbrev)); |
| 13077 | |
| 13078 | abbrev_table_add_abbrev (abbrev_table, abbrev_number, cur_abbrev); |
| 13079 | |
| 13080 | /* Get next abbreviation. |
| 13081 | Under Irix6 the abbreviations for a compilation unit are not |
| 13082 | always properly terminated with an abbrev number of 0. |
| 13083 | Exit loop if we encounter an abbreviation which we have |
| 13084 | already read (which means we are about to read the abbreviations |
| 13085 | for the next compile unit) or if the end of the abbreviation |
| 13086 | table is reached. */ |
| 13087 | if ((unsigned int) (abbrev_ptr - section->buffer) >= section->size) |
| 13088 | break; |
| 13089 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 13090 | abbrev_ptr += bytes_read; |
| 13091 | if (abbrev_table_lookup_abbrev (abbrev_table, abbrev_number) != NULL) |
| 13092 | break; |
| 13093 | } |
| 13094 | |
| 13095 | xfree (cur_attrs); |
| 13096 | return abbrev_table; |
| 13097 | } |
| 13098 | |
| 13099 | /* Free the resources held by ABBREV_TABLE. */ |
| 13100 | |
| 13101 | static void |
| 13102 | abbrev_table_free (struct abbrev_table *abbrev_table) |
| 13103 | { |
| 13104 | obstack_free (&abbrev_table->abbrev_obstack, NULL); |
| 13105 | xfree (abbrev_table); |
| 13106 | } |
| 13107 | |
| 13108 | /* Same as abbrev_table_free but as a cleanup. |
| 13109 | We pass in a pointer to the pointer to the table so that we can |
| 13110 | set the pointer to NULL when we're done. It also simplifies |
| 13111 | build_type_unit_groups. */ |
| 13112 | |
| 13113 | static void |
| 13114 | abbrev_table_free_cleanup (void *table_ptr) |
| 13115 | { |
| 13116 | struct abbrev_table **abbrev_table_ptr = table_ptr; |
| 13117 | |
| 13118 | if (*abbrev_table_ptr != NULL) |
| 13119 | abbrev_table_free (*abbrev_table_ptr); |
| 13120 | *abbrev_table_ptr = NULL; |
| 13121 | } |
| 13122 | |
| 13123 | /* Read the abbrev table for CU from ABBREV_SECTION. */ |
| 13124 | |
| 13125 | static void |
| 13126 | dwarf2_read_abbrevs (struct dwarf2_cu *cu, |
| 13127 | struct dwarf2_section_info *abbrev_section) |
| 13128 | { |
| 13129 | cu->abbrev_table = |
| 13130 | abbrev_table_read_table (abbrev_section, cu->header.abbrev_offset); |
| 13131 | } |
| 13132 | |
| 13133 | /* Release the memory used by the abbrev table for a compilation unit. */ |
| 13134 | |
| 13135 | static void |
| 13136 | dwarf2_free_abbrev_table (void *ptr_to_cu) |
| 13137 | { |
| 13138 | struct dwarf2_cu *cu = ptr_to_cu; |
| 13139 | |
| 13140 | abbrev_table_free (cu->abbrev_table); |
| 13141 | /* Set this to NULL so that we SEGV if we try to read it later, |
| 13142 | and also because free_comp_unit verifies this is NULL. */ |
| 13143 | cu->abbrev_table = NULL; |
| 13144 | } |
| 13145 | \f |
| 13146 | /* Returns nonzero if TAG represents a type that we might generate a partial |
| 13147 | symbol for. */ |
| 13148 | |
| 13149 | static int |
| 13150 | is_type_tag_for_partial (int tag) |
| 13151 | { |
| 13152 | switch (tag) |
| 13153 | { |
| 13154 | #if 0 |
| 13155 | /* Some types that would be reasonable to generate partial symbols for, |
| 13156 | that we don't at present. */ |
| 13157 | case DW_TAG_array_type: |
| 13158 | case DW_TAG_file_type: |
| 13159 | case DW_TAG_ptr_to_member_type: |
| 13160 | case DW_TAG_set_type: |
| 13161 | case DW_TAG_string_type: |
| 13162 | case DW_TAG_subroutine_type: |
| 13163 | #endif |
| 13164 | case DW_TAG_base_type: |
| 13165 | case DW_TAG_class_type: |
| 13166 | case DW_TAG_interface_type: |
| 13167 | case DW_TAG_enumeration_type: |
| 13168 | case DW_TAG_structure_type: |
| 13169 | case DW_TAG_subrange_type: |
| 13170 | case DW_TAG_typedef: |
| 13171 | case DW_TAG_union_type: |
| 13172 | return 1; |
| 13173 | default: |
| 13174 | return 0; |
| 13175 | } |
| 13176 | } |
| 13177 | |
| 13178 | /* Load all DIEs that are interesting for partial symbols into memory. */ |
| 13179 | |
| 13180 | static struct partial_die_info * |
| 13181 | load_partial_dies (const struct die_reader_specs *reader, |
| 13182 | gdb_byte *info_ptr, int building_psymtab) |
| 13183 | { |
| 13184 | struct dwarf2_cu *cu = reader->cu; |
| 13185 | struct objfile *objfile = cu->objfile; |
| 13186 | struct partial_die_info *part_die; |
| 13187 | struct partial_die_info *parent_die, *last_die, *first_die = NULL; |
| 13188 | struct abbrev_info *abbrev; |
| 13189 | unsigned int bytes_read; |
| 13190 | unsigned int load_all = 0; |
| 13191 | int nesting_level = 1; |
| 13192 | |
| 13193 | parent_die = NULL; |
| 13194 | last_die = NULL; |
| 13195 | |
| 13196 | gdb_assert (cu->per_cu != NULL); |
| 13197 | if (cu->per_cu->load_all_dies) |
| 13198 | load_all = 1; |
| 13199 | |
| 13200 | cu->partial_dies |
| 13201 | = htab_create_alloc_ex (cu->header.length / 12, |
| 13202 | partial_die_hash, |
| 13203 | partial_die_eq, |
| 13204 | NULL, |
| 13205 | &cu->comp_unit_obstack, |
| 13206 | hashtab_obstack_allocate, |
| 13207 | dummy_obstack_deallocate); |
| 13208 | |
| 13209 | part_die = obstack_alloc (&cu->comp_unit_obstack, |
| 13210 | sizeof (struct partial_die_info)); |
| 13211 | |
| 13212 | while (1) |
| 13213 | { |
| 13214 | abbrev = peek_die_abbrev (info_ptr, &bytes_read, cu); |
| 13215 | |
| 13216 | /* A NULL abbrev means the end of a series of children. */ |
| 13217 | if (abbrev == NULL) |
| 13218 | { |
| 13219 | if (--nesting_level == 0) |
| 13220 | { |
| 13221 | /* PART_DIE was probably the last thing allocated on the |
| 13222 | comp_unit_obstack, so we could call obstack_free |
| 13223 | here. We don't do that because the waste is small, |
| 13224 | and will be cleaned up when we're done with this |
| 13225 | compilation unit. This way, we're also more robust |
| 13226 | against other users of the comp_unit_obstack. */ |
| 13227 | return first_die; |
| 13228 | } |
| 13229 | info_ptr += bytes_read; |
| 13230 | last_die = parent_die; |
| 13231 | parent_die = parent_die->die_parent; |
| 13232 | continue; |
| 13233 | } |
| 13234 | |
| 13235 | /* Check for template arguments. We never save these; if |
| 13236 | they're seen, we just mark the parent, and go on our way. */ |
| 13237 | if (parent_die != NULL |
| 13238 | && cu->language == language_cplus |
| 13239 | && (abbrev->tag == DW_TAG_template_type_param |
| 13240 | || abbrev->tag == DW_TAG_template_value_param)) |
| 13241 | { |
| 13242 | parent_die->has_template_arguments = 1; |
| 13243 | |
| 13244 | if (!load_all) |
| 13245 | { |
| 13246 | /* We don't need a partial DIE for the template argument. */ |
| 13247 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
| 13248 | continue; |
| 13249 | } |
| 13250 | } |
| 13251 | |
| 13252 | /* We only recurse into c++ subprograms looking for template arguments. |
| 13253 | Skip their other children. */ |
| 13254 | if (!load_all |
| 13255 | && cu->language == language_cplus |
| 13256 | && parent_die != NULL |
| 13257 | && parent_die->tag == DW_TAG_subprogram) |
| 13258 | { |
| 13259 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
| 13260 | continue; |
| 13261 | } |
| 13262 | |
| 13263 | /* Check whether this DIE is interesting enough to save. Normally |
| 13264 | we would not be interested in members here, but there may be |
| 13265 | later variables referencing them via DW_AT_specification (for |
| 13266 | static members). */ |
| 13267 | if (!load_all |
| 13268 | && !is_type_tag_for_partial (abbrev->tag) |
| 13269 | && abbrev->tag != DW_TAG_constant |
| 13270 | && abbrev->tag != DW_TAG_enumerator |
| 13271 | && abbrev->tag != DW_TAG_subprogram |
| 13272 | && abbrev->tag != DW_TAG_lexical_block |
| 13273 | && abbrev->tag != DW_TAG_variable |
| 13274 | && abbrev->tag != DW_TAG_namespace |
| 13275 | && abbrev->tag != DW_TAG_module |
| 13276 | && abbrev->tag != DW_TAG_member |
| 13277 | && abbrev->tag != DW_TAG_imported_unit) |
| 13278 | { |
| 13279 | /* Otherwise we skip to the next sibling, if any. */ |
| 13280 | info_ptr = skip_one_die (reader, info_ptr + bytes_read, abbrev); |
| 13281 | continue; |
| 13282 | } |
| 13283 | |
| 13284 | info_ptr = read_partial_die (reader, part_die, abbrev, bytes_read, |
| 13285 | info_ptr); |
| 13286 | |
| 13287 | /* This two-pass algorithm for processing partial symbols has a |
| 13288 | high cost in cache pressure. Thus, handle some simple cases |
| 13289 | here which cover the majority of C partial symbols. DIEs |
| 13290 | which neither have specification tags in them, nor could have |
| 13291 | specification tags elsewhere pointing at them, can simply be |
| 13292 | processed and discarded. |
| 13293 | |
| 13294 | This segment is also optional; scan_partial_symbols and |
| 13295 | add_partial_symbol will handle these DIEs if we chain |
| 13296 | them in normally. When compilers which do not emit large |
| 13297 | quantities of duplicate debug information are more common, |
| 13298 | this code can probably be removed. */ |
| 13299 | |
| 13300 | /* Any complete simple types at the top level (pretty much all |
| 13301 | of them, for a language without namespaces), can be processed |
| 13302 | directly. */ |
| 13303 | if (parent_die == NULL |
| 13304 | && part_die->has_specification == 0 |
| 13305 | && part_die->is_declaration == 0 |
| 13306 | && ((part_die->tag == DW_TAG_typedef && !part_die->has_children) |
| 13307 | || part_die->tag == DW_TAG_base_type |
| 13308 | || part_die->tag == DW_TAG_subrange_type)) |
| 13309 | { |
| 13310 | if (building_psymtab && part_die->name != NULL) |
| 13311 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
| 13312 | VAR_DOMAIN, LOC_TYPEDEF, |
| 13313 | &objfile->static_psymbols, |
| 13314 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 13315 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
| 13316 | continue; |
| 13317 | } |
| 13318 | |
| 13319 | /* The exception for DW_TAG_typedef with has_children above is |
| 13320 | a workaround of GCC PR debug/47510. In the case of this complaint |
| 13321 | type_name_no_tag_or_error will error on such types later. |
| 13322 | |
| 13323 | GDB skipped children of DW_TAG_typedef by the shortcut above and then |
| 13324 | it could not find the child DIEs referenced later, this is checked |
| 13325 | above. In correct DWARF DW_TAG_typedef should have no children. */ |
| 13326 | |
| 13327 | if (part_die->tag == DW_TAG_typedef && part_die->has_children) |
| 13328 | complaint (&symfile_complaints, |
| 13329 | _("DW_TAG_typedef has childen - GCC PR debug/47510 bug " |
| 13330 | "- DIE at 0x%x [in module %s]"), |
| 13331 | part_die->offset.sect_off, objfile->name); |
| 13332 | |
| 13333 | /* If we're at the second level, and we're an enumerator, and |
| 13334 | our parent has no specification (meaning possibly lives in a |
| 13335 | namespace elsewhere), then we can add the partial symbol now |
| 13336 | instead of queueing it. */ |
| 13337 | if (part_die->tag == DW_TAG_enumerator |
| 13338 | && parent_die != NULL |
| 13339 | && parent_die->die_parent == NULL |
| 13340 | && parent_die->tag == DW_TAG_enumeration_type |
| 13341 | && parent_die->has_specification == 0) |
| 13342 | { |
| 13343 | if (part_die->name == NULL) |
| 13344 | complaint (&symfile_complaints, |
| 13345 | _("malformed enumerator DIE ignored")); |
| 13346 | else if (building_psymtab) |
| 13347 | add_psymbol_to_list (part_die->name, strlen (part_die->name), 0, |
| 13348 | VAR_DOMAIN, LOC_CONST, |
| 13349 | (cu->language == language_cplus |
| 13350 | || cu->language == language_java) |
| 13351 | ? &objfile->global_psymbols |
| 13352 | : &objfile->static_psymbols, |
| 13353 | 0, (CORE_ADDR) 0, cu->language, objfile); |
| 13354 | |
| 13355 | info_ptr = locate_pdi_sibling (reader, part_die, info_ptr); |
| 13356 | continue; |
| 13357 | } |
| 13358 | |
| 13359 | /* We'll save this DIE so link it in. */ |
| 13360 | part_die->die_parent = parent_die; |
| 13361 | part_die->die_sibling = NULL; |
| 13362 | part_die->die_child = NULL; |
| 13363 | |
| 13364 | if (last_die && last_die == parent_die) |
| 13365 | last_die->die_child = part_die; |
| 13366 | else if (last_die) |
| 13367 | last_die->die_sibling = part_die; |
| 13368 | |
| 13369 | last_die = part_die; |
| 13370 | |
| 13371 | if (first_die == NULL) |
| 13372 | first_die = part_die; |
| 13373 | |
| 13374 | /* Maybe add the DIE to the hash table. Not all DIEs that we |
| 13375 | find interesting need to be in the hash table, because we |
| 13376 | also have the parent/sibling/child chains; only those that we |
| 13377 | might refer to by offset later during partial symbol reading. |
| 13378 | |
| 13379 | For now this means things that might have be the target of a |
| 13380 | DW_AT_specification, DW_AT_abstract_origin, or |
| 13381 | DW_AT_extension. DW_AT_extension will refer only to |
| 13382 | namespaces; DW_AT_abstract_origin refers to functions (and |
| 13383 | many things under the function DIE, but we do not recurse |
| 13384 | into function DIEs during partial symbol reading) and |
| 13385 | possibly variables as well; DW_AT_specification refers to |
| 13386 | declarations. Declarations ought to have the DW_AT_declaration |
| 13387 | flag. It happens that GCC forgets to put it in sometimes, but |
| 13388 | only for functions, not for types. |
| 13389 | |
| 13390 | Adding more things than necessary to the hash table is harmless |
| 13391 | except for the performance cost. Adding too few will result in |
| 13392 | wasted time in find_partial_die, when we reread the compilation |
| 13393 | unit with load_all_dies set. */ |
| 13394 | |
| 13395 | if (load_all |
| 13396 | || abbrev->tag == DW_TAG_constant |
| 13397 | || abbrev->tag == DW_TAG_subprogram |
| 13398 | || abbrev->tag == DW_TAG_variable |
| 13399 | || abbrev->tag == DW_TAG_namespace |
| 13400 | || part_die->is_declaration) |
| 13401 | { |
| 13402 | void **slot; |
| 13403 | |
| 13404 | slot = htab_find_slot_with_hash (cu->partial_dies, part_die, |
| 13405 | part_die->offset.sect_off, INSERT); |
| 13406 | *slot = part_die; |
| 13407 | } |
| 13408 | |
| 13409 | part_die = obstack_alloc (&cu->comp_unit_obstack, |
| 13410 | sizeof (struct partial_die_info)); |
| 13411 | |
| 13412 | /* For some DIEs we want to follow their children (if any). For C |
| 13413 | we have no reason to follow the children of structures; for other |
| 13414 | languages we have to, so that we can get at method physnames |
| 13415 | to infer fully qualified class names, for DW_AT_specification, |
| 13416 | and for C++ template arguments. For C++, we also look one level |
| 13417 | inside functions to find template arguments (if the name of the |
| 13418 | function does not already contain the template arguments). |
| 13419 | |
| 13420 | For Ada, we need to scan the children of subprograms and lexical |
| 13421 | blocks as well because Ada allows the definition of nested |
| 13422 | entities that could be interesting for the debugger, such as |
| 13423 | nested subprograms for instance. */ |
| 13424 | if (last_die->has_children |
| 13425 | && (load_all |
| 13426 | || last_die->tag == DW_TAG_namespace |
| 13427 | || last_die->tag == DW_TAG_module |
| 13428 | || last_die->tag == DW_TAG_enumeration_type |
| 13429 | || (cu->language == language_cplus |
| 13430 | && last_die->tag == DW_TAG_subprogram |
| 13431 | && (last_die->name == NULL |
| 13432 | || strchr (last_die->name, '<') == NULL)) |
| 13433 | || (cu->language != language_c |
| 13434 | && (last_die->tag == DW_TAG_class_type |
| 13435 | || last_die->tag == DW_TAG_interface_type |
| 13436 | || last_die->tag == DW_TAG_structure_type |
| 13437 | || last_die->tag == DW_TAG_union_type)) |
| 13438 | || (cu->language == language_ada |
| 13439 | && (last_die->tag == DW_TAG_subprogram |
| 13440 | || last_die->tag == DW_TAG_lexical_block)))) |
| 13441 | { |
| 13442 | nesting_level++; |
| 13443 | parent_die = last_die; |
| 13444 | continue; |
| 13445 | } |
| 13446 | |
| 13447 | /* Otherwise we skip to the next sibling, if any. */ |
| 13448 | info_ptr = locate_pdi_sibling (reader, last_die, info_ptr); |
| 13449 | |
| 13450 | /* Back to the top, do it again. */ |
| 13451 | } |
| 13452 | } |
| 13453 | |
| 13454 | /* Read a minimal amount of information into the minimal die structure. */ |
| 13455 | |
| 13456 | static gdb_byte * |
| 13457 | read_partial_die (const struct die_reader_specs *reader, |
| 13458 | struct partial_die_info *part_die, |
| 13459 | struct abbrev_info *abbrev, unsigned int abbrev_len, |
| 13460 | gdb_byte *info_ptr) |
| 13461 | { |
| 13462 | struct dwarf2_cu *cu = reader->cu; |
| 13463 | struct objfile *objfile = cu->objfile; |
| 13464 | gdb_byte *buffer = reader->buffer; |
| 13465 | unsigned int i; |
| 13466 | struct attribute attr; |
| 13467 | int has_low_pc_attr = 0; |
| 13468 | int has_high_pc_attr = 0; |
| 13469 | int high_pc_relative = 0; |
| 13470 | |
| 13471 | memset (part_die, 0, sizeof (struct partial_die_info)); |
| 13472 | |
| 13473 | part_die->offset.sect_off = info_ptr - buffer; |
| 13474 | |
| 13475 | info_ptr += abbrev_len; |
| 13476 | |
| 13477 | if (abbrev == NULL) |
| 13478 | return info_ptr; |
| 13479 | |
| 13480 | part_die->tag = abbrev->tag; |
| 13481 | part_die->has_children = abbrev->has_children; |
| 13482 | |
| 13483 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 13484 | { |
| 13485 | info_ptr = read_attribute (reader, &attr, &abbrev->attrs[i], info_ptr); |
| 13486 | |
| 13487 | /* Store the data if it is of an attribute we want to keep in a |
| 13488 | partial symbol table. */ |
| 13489 | switch (attr.name) |
| 13490 | { |
| 13491 | case DW_AT_name: |
| 13492 | switch (part_die->tag) |
| 13493 | { |
| 13494 | case DW_TAG_compile_unit: |
| 13495 | case DW_TAG_partial_unit: |
| 13496 | case DW_TAG_type_unit: |
| 13497 | /* Compilation units have a DW_AT_name that is a filename, not |
| 13498 | a source language identifier. */ |
| 13499 | case DW_TAG_enumeration_type: |
| 13500 | case DW_TAG_enumerator: |
| 13501 | /* These tags always have simple identifiers already; no need |
| 13502 | to canonicalize them. */ |
| 13503 | part_die->name = DW_STRING (&attr); |
| 13504 | break; |
| 13505 | default: |
| 13506 | part_die->name |
| 13507 | = dwarf2_canonicalize_name (DW_STRING (&attr), cu, |
| 13508 | &objfile->objfile_obstack); |
| 13509 | break; |
| 13510 | } |
| 13511 | break; |
| 13512 | case DW_AT_linkage_name: |
| 13513 | case DW_AT_MIPS_linkage_name: |
| 13514 | /* Note that both forms of linkage name might appear. We |
| 13515 | assume they will be the same, and we only store the last |
| 13516 | one we see. */ |
| 13517 | if (cu->language == language_ada) |
| 13518 | part_die->name = DW_STRING (&attr); |
| 13519 | part_die->linkage_name = DW_STRING (&attr); |
| 13520 | break; |
| 13521 | case DW_AT_low_pc: |
| 13522 | has_low_pc_attr = 1; |
| 13523 | part_die->lowpc = DW_ADDR (&attr); |
| 13524 | break; |
| 13525 | case DW_AT_high_pc: |
| 13526 | has_high_pc_attr = 1; |
| 13527 | if (attr.form == DW_FORM_addr |
| 13528 | || attr.form == DW_FORM_GNU_addr_index) |
| 13529 | part_die->highpc = DW_ADDR (&attr); |
| 13530 | else |
| 13531 | { |
| 13532 | high_pc_relative = 1; |
| 13533 | part_die->highpc = DW_UNSND (&attr); |
| 13534 | } |
| 13535 | break; |
| 13536 | case DW_AT_location: |
| 13537 | /* Support the .debug_loc offsets. */ |
| 13538 | if (attr_form_is_block (&attr)) |
| 13539 | { |
| 13540 | part_die->d.locdesc = DW_BLOCK (&attr); |
| 13541 | } |
| 13542 | else if (attr_form_is_section_offset (&attr)) |
| 13543 | { |
| 13544 | dwarf2_complex_location_expr_complaint (); |
| 13545 | } |
| 13546 | else |
| 13547 | { |
| 13548 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 13549 | "partial symbol information"); |
| 13550 | } |
| 13551 | break; |
| 13552 | case DW_AT_external: |
| 13553 | part_die->is_external = DW_UNSND (&attr); |
| 13554 | break; |
| 13555 | case DW_AT_declaration: |
| 13556 | part_die->is_declaration = DW_UNSND (&attr); |
| 13557 | break; |
| 13558 | case DW_AT_type: |
| 13559 | part_die->has_type = 1; |
| 13560 | break; |
| 13561 | case DW_AT_abstract_origin: |
| 13562 | case DW_AT_specification: |
| 13563 | case DW_AT_extension: |
| 13564 | part_die->has_specification = 1; |
| 13565 | part_die->spec_offset = dwarf2_get_ref_die_offset (&attr); |
| 13566 | part_die->spec_is_dwz = (attr.form == DW_FORM_GNU_ref_alt |
| 13567 | || cu->per_cu->is_dwz); |
| 13568 | break; |
| 13569 | case DW_AT_sibling: |
| 13570 | /* Ignore absolute siblings, they might point outside of |
| 13571 | the current compile unit. */ |
| 13572 | if (attr.form == DW_FORM_ref_addr) |
| 13573 | complaint (&symfile_complaints, |
| 13574 | _("ignoring absolute DW_AT_sibling")); |
| 13575 | else |
| 13576 | part_die->sibling = buffer + dwarf2_get_ref_die_offset (&attr).sect_off; |
| 13577 | break; |
| 13578 | case DW_AT_byte_size: |
| 13579 | part_die->has_byte_size = 1; |
| 13580 | break; |
| 13581 | case DW_AT_calling_convention: |
| 13582 | /* DWARF doesn't provide a way to identify a program's source-level |
| 13583 | entry point. DW_AT_calling_convention attributes are only meant |
| 13584 | to describe functions' calling conventions. |
| 13585 | |
| 13586 | However, because it's a necessary piece of information in |
| 13587 | Fortran, and because DW_CC_program is the only piece of debugging |
| 13588 | information whose definition refers to a 'main program' at all, |
| 13589 | several compilers have begun marking Fortran main programs with |
| 13590 | DW_CC_program --- even when those functions use the standard |
| 13591 | calling conventions. |
| 13592 | |
| 13593 | So until DWARF specifies a way to provide this information and |
| 13594 | compilers pick up the new representation, we'll support this |
| 13595 | practice. */ |
| 13596 | if (DW_UNSND (&attr) == DW_CC_program |
| 13597 | && cu->language == language_fortran) |
| 13598 | { |
| 13599 | set_main_name (part_die->name); |
| 13600 | |
| 13601 | /* As this DIE has a static linkage the name would be difficult |
| 13602 | to look up later. */ |
| 13603 | language_of_main = language_fortran; |
| 13604 | } |
| 13605 | break; |
| 13606 | case DW_AT_inline: |
| 13607 | if (DW_UNSND (&attr) == DW_INL_inlined |
| 13608 | || DW_UNSND (&attr) == DW_INL_declared_inlined) |
| 13609 | part_die->may_be_inlined = 1; |
| 13610 | break; |
| 13611 | |
| 13612 | case DW_AT_import: |
| 13613 | if (part_die->tag == DW_TAG_imported_unit) |
| 13614 | { |
| 13615 | part_die->d.offset = dwarf2_get_ref_die_offset (&attr); |
| 13616 | part_die->is_dwz = (attr.form == DW_FORM_GNU_ref_alt |
| 13617 | || cu->per_cu->is_dwz); |
| 13618 | } |
| 13619 | break; |
| 13620 | |
| 13621 | default: |
| 13622 | break; |
| 13623 | } |
| 13624 | } |
| 13625 | |
| 13626 | if (high_pc_relative) |
| 13627 | part_die->highpc += part_die->lowpc; |
| 13628 | |
| 13629 | if (has_low_pc_attr && has_high_pc_attr) |
| 13630 | { |
| 13631 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 13632 | eliminate duplicate copies of functions and vtables and such. |
| 13633 | The linker will arbitrarily choose one and discard the others. |
| 13634 | The AT_*_pc values for such functions refer to local labels in |
| 13635 | these sections. If the section from that file was discarded, the |
| 13636 | labels are not in the output, so the relocs get a value of 0. |
| 13637 | If this is a discarded function, mark the pc bounds as invalid, |
| 13638 | so that GDB will ignore it. */ |
| 13639 | if (part_die->lowpc == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 13640 | { |
| 13641 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 13642 | |
| 13643 | complaint (&symfile_complaints, |
| 13644 | _("DW_AT_low_pc %s is zero " |
| 13645 | "for DIE at 0x%x [in module %s]"), |
| 13646 | paddress (gdbarch, part_die->lowpc), |
| 13647 | part_die->offset.sect_off, objfile->name); |
| 13648 | } |
| 13649 | /* dwarf2_get_pc_bounds has also the strict low < high requirement. */ |
| 13650 | else if (part_die->lowpc >= part_die->highpc) |
| 13651 | { |
| 13652 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 13653 | |
| 13654 | complaint (&symfile_complaints, |
| 13655 | _("DW_AT_low_pc %s is not < DW_AT_high_pc %s " |
| 13656 | "for DIE at 0x%x [in module %s]"), |
| 13657 | paddress (gdbarch, part_die->lowpc), |
| 13658 | paddress (gdbarch, part_die->highpc), |
| 13659 | part_die->offset.sect_off, objfile->name); |
| 13660 | } |
| 13661 | else |
| 13662 | part_die->has_pc_info = 1; |
| 13663 | } |
| 13664 | |
| 13665 | return info_ptr; |
| 13666 | } |
| 13667 | |
| 13668 | /* Find a cached partial DIE at OFFSET in CU. */ |
| 13669 | |
| 13670 | static struct partial_die_info * |
| 13671 | find_partial_die_in_comp_unit (sect_offset offset, struct dwarf2_cu *cu) |
| 13672 | { |
| 13673 | struct partial_die_info *lookup_die = NULL; |
| 13674 | struct partial_die_info part_die; |
| 13675 | |
| 13676 | part_die.offset = offset; |
| 13677 | lookup_die = htab_find_with_hash (cu->partial_dies, &part_die, |
| 13678 | offset.sect_off); |
| 13679 | |
| 13680 | return lookup_die; |
| 13681 | } |
| 13682 | |
| 13683 | /* Find a partial DIE at OFFSET, which may or may not be in CU, |
| 13684 | except in the case of .debug_types DIEs which do not reference |
| 13685 | outside their CU (they do however referencing other types via |
| 13686 | DW_FORM_ref_sig8). */ |
| 13687 | |
| 13688 | static struct partial_die_info * |
| 13689 | find_partial_die (sect_offset offset, int offset_in_dwz, struct dwarf2_cu *cu) |
| 13690 | { |
| 13691 | struct objfile *objfile = cu->objfile; |
| 13692 | struct dwarf2_per_cu_data *per_cu = NULL; |
| 13693 | struct partial_die_info *pd = NULL; |
| 13694 | |
| 13695 | if (offset_in_dwz == cu->per_cu->is_dwz |
| 13696 | && offset_in_cu_p (&cu->header, offset)) |
| 13697 | { |
| 13698 | pd = find_partial_die_in_comp_unit (offset, cu); |
| 13699 | if (pd != NULL) |
| 13700 | return pd; |
| 13701 | /* We missed recording what we needed. |
| 13702 | Load all dies and try again. */ |
| 13703 | per_cu = cu->per_cu; |
| 13704 | } |
| 13705 | else |
| 13706 | { |
| 13707 | /* TUs don't reference other CUs/TUs (except via type signatures). */ |
| 13708 | if (cu->per_cu->is_debug_types) |
| 13709 | { |
| 13710 | error (_("Dwarf Error: Type Unit at offset 0x%lx contains" |
| 13711 | " external reference to offset 0x%lx [in module %s].\n"), |
| 13712 | (long) cu->header.offset.sect_off, (long) offset.sect_off, |
| 13713 | bfd_get_filename (objfile->obfd)); |
| 13714 | } |
| 13715 | per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz, |
| 13716 | objfile); |
| 13717 | |
| 13718 | if (per_cu->cu == NULL || per_cu->cu->partial_dies == NULL) |
| 13719 | load_partial_comp_unit (per_cu); |
| 13720 | |
| 13721 | per_cu->cu->last_used = 0; |
| 13722 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
| 13723 | } |
| 13724 | |
| 13725 | /* If we didn't find it, and not all dies have been loaded, |
| 13726 | load them all and try again. */ |
| 13727 | |
| 13728 | if (pd == NULL && per_cu->load_all_dies == 0) |
| 13729 | { |
| 13730 | per_cu->load_all_dies = 1; |
| 13731 | |
| 13732 | /* This is nasty. When we reread the DIEs, somewhere up the call chain |
| 13733 | THIS_CU->cu may already be in use. So we can't just free it and |
| 13734 | replace its DIEs with the ones we read in. Instead, we leave those |
| 13735 | DIEs alone (which can still be in use, e.g. in scan_partial_symbols), |
| 13736 | and clobber THIS_CU->cu->partial_dies with the hash table for the new |
| 13737 | set. */ |
| 13738 | load_partial_comp_unit (per_cu); |
| 13739 | |
| 13740 | pd = find_partial_die_in_comp_unit (offset, per_cu->cu); |
| 13741 | } |
| 13742 | |
| 13743 | if (pd == NULL) |
| 13744 | internal_error (__FILE__, __LINE__, |
| 13745 | _("could not find partial DIE 0x%x " |
| 13746 | "in cache [from module %s]\n"), |
| 13747 | offset.sect_off, bfd_get_filename (objfile->obfd)); |
| 13748 | return pd; |
| 13749 | } |
| 13750 | |
| 13751 | /* See if we can figure out if the class lives in a namespace. We do |
| 13752 | this by looking for a member function; its demangled name will |
| 13753 | contain namespace info, if there is any. */ |
| 13754 | |
| 13755 | static void |
| 13756 | guess_partial_die_structure_name (struct partial_die_info *struct_pdi, |
| 13757 | struct dwarf2_cu *cu) |
| 13758 | { |
| 13759 | /* NOTE: carlton/2003-10-07: Getting the info this way changes |
| 13760 | what template types look like, because the demangler |
| 13761 | frequently doesn't give the same name as the debug info. We |
| 13762 | could fix this by only using the demangled name to get the |
| 13763 | prefix (but see comment in read_structure_type). */ |
| 13764 | |
| 13765 | struct partial_die_info *real_pdi; |
| 13766 | struct partial_die_info *child_pdi; |
| 13767 | |
| 13768 | /* If this DIE (this DIE's specification, if any) has a parent, then |
| 13769 | we should not do this. We'll prepend the parent's fully qualified |
| 13770 | name when we create the partial symbol. */ |
| 13771 | |
| 13772 | real_pdi = struct_pdi; |
| 13773 | while (real_pdi->has_specification) |
| 13774 | real_pdi = find_partial_die (real_pdi->spec_offset, |
| 13775 | real_pdi->spec_is_dwz, cu); |
| 13776 | |
| 13777 | if (real_pdi->die_parent != NULL) |
| 13778 | return; |
| 13779 | |
| 13780 | for (child_pdi = struct_pdi->die_child; |
| 13781 | child_pdi != NULL; |
| 13782 | child_pdi = child_pdi->die_sibling) |
| 13783 | { |
| 13784 | if (child_pdi->tag == DW_TAG_subprogram |
| 13785 | && child_pdi->linkage_name != NULL) |
| 13786 | { |
| 13787 | char *actual_class_name |
| 13788 | = language_class_name_from_physname (cu->language_defn, |
| 13789 | child_pdi->linkage_name); |
| 13790 | if (actual_class_name != NULL) |
| 13791 | { |
| 13792 | struct_pdi->name |
| 13793 | = obsavestring (actual_class_name, |
| 13794 | strlen (actual_class_name), |
| 13795 | &cu->objfile->objfile_obstack); |
| 13796 | xfree (actual_class_name); |
| 13797 | } |
| 13798 | break; |
| 13799 | } |
| 13800 | } |
| 13801 | } |
| 13802 | |
| 13803 | /* Adjust PART_DIE before generating a symbol for it. This function |
| 13804 | may set the is_external flag or change the DIE's name. */ |
| 13805 | |
| 13806 | static void |
| 13807 | fixup_partial_die (struct partial_die_info *part_die, |
| 13808 | struct dwarf2_cu *cu) |
| 13809 | { |
| 13810 | /* Once we've fixed up a die, there's no point in doing so again. |
| 13811 | This also avoids a memory leak if we were to call |
| 13812 | guess_partial_die_structure_name multiple times. */ |
| 13813 | if (part_die->fixup_called) |
| 13814 | return; |
| 13815 | |
| 13816 | /* If we found a reference attribute and the DIE has no name, try |
| 13817 | to find a name in the referred to DIE. */ |
| 13818 | |
| 13819 | if (part_die->name == NULL && part_die->has_specification) |
| 13820 | { |
| 13821 | struct partial_die_info *spec_die; |
| 13822 | |
| 13823 | spec_die = find_partial_die (part_die->spec_offset, |
| 13824 | part_die->spec_is_dwz, cu); |
| 13825 | |
| 13826 | fixup_partial_die (spec_die, cu); |
| 13827 | |
| 13828 | if (spec_die->name) |
| 13829 | { |
| 13830 | part_die->name = spec_die->name; |
| 13831 | |
| 13832 | /* Copy DW_AT_external attribute if it is set. */ |
| 13833 | if (spec_die->is_external) |
| 13834 | part_die->is_external = spec_die->is_external; |
| 13835 | } |
| 13836 | } |
| 13837 | |
| 13838 | /* Set default names for some unnamed DIEs. */ |
| 13839 | |
| 13840 | if (part_die->name == NULL && part_die->tag == DW_TAG_namespace) |
| 13841 | part_die->name = CP_ANONYMOUS_NAMESPACE_STR; |
| 13842 | |
| 13843 | /* If there is no parent die to provide a namespace, and there are |
| 13844 | children, see if we can determine the namespace from their linkage |
| 13845 | name. */ |
| 13846 | if (cu->language == language_cplus |
| 13847 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
| 13848 | && part_die->die_parent == NULL |
| 13849 | && part_die->has_children |
| 13850 | && (part_die->tag == DW_TAG_class_type |
| 13851 | || part_die->tag == DW_TAG_structure_type |
| 13852 | || part_die->tag == DW_TAG_union_type)) |
| 13853 | guess_partial_die_structure_name (part_die, cu); |
| 13854 | |
| 13855 | /* GCC might emit a nameless struct or union that has a linkage |
| 13856 | name. See http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ |
| 13857 | if (part_die->name == NULL |
| 13858 | && (part_die->tag == DW_TAG_class_type |
| 13859 | || part_die->tag == DW_TAG_interface_type |
| 13860 | || part_die->tag == DW_TAG_structure_type |
| 13861 | || part_die->tag == DW_TAG_union_type) |
| 13862 | && part_die->linkage_name != NULL) |
| 13863 | { |
| 13864 | char *demangled; |
| 13865 | |
| 13866 | demangled = cplus_demangle (part_die->linkage_name, DMGL_TYPES); |
| 13867 | if (demangled) |
| 13868 | { |
| 13869 | const char *base; |
| 13870 | |
| 13871 | /* Strip any leading namespaces/classes, keep only the base name. |
| 13872 | DW_AT_name for named DIEs does not contain the prefixes. */ |
| 13873 | base = strrchr (demangled, ':'); |
| 13874 | if (base && base > demangled && base[-1] == ':') |
| 13875 | base++; |
| 13876 | else |
| 13877 | base = demangled; |
| 13878 | |
| 13879 | part_die->name = obsavestring (base, strlen (base), |
| 13880 | &cu->objfile->objfile_obstack); |
| 13881 | xfree (demangled); |
| 13882 | } |
| 13883 | } |
| 13884 | |
| 13885 | part_die->fixup_called = 1; |
| 13886 | } |
| 13887 | |
| 13888 | /* Read an attribute value described by an attribute form. */ |
| 13889 | |
| 13890 | static gdb_byte * |
| 13891 | read_attribute_value (const struct die_reader_specs *reader, |
| 13892 | struct attribute *attr, unsigned form, |
| 13893 | gdb_byte *info_ptr) |
| 13894 | { |
| 13895 | struct dwarf2_cu *cu = reader->cu; |
| 13896 | bfd *abfd = reader->abfd; |
| 13897 | struct comp_unit_head *cu_header = &cu->header; |
| 13898 | unsigned int bytes_read; |
| 13899 | struct dwarf_block *blk; |
| 13900 | |
| 13901 | attr->form = form; |
| 13902 | switch (form) |
| 13903 | { |
| 13904 | case DW_FORM_ref_addr: |
| 13905 | if (cu->header.version == 2) |
| 13906 | DW_UNSND (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
| 13907 | else |
| 13908 | DW_UNSND (attr) = read_offset (abfd, info_ptr, |
| 13909 | &cu->header, &bytes_read); |
| 13910 | info_ptr += bytes_read; |
| 13911 | break; |
| 13912 | case DW_FORM_GNU_ref_alt: |
| 13913 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); |
| 13914 | info_ptr += bytes_read; |
| 13915 | break; |
| 13916 | case DW_FORM_addr: |
| 13917 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu, &bytes_read); |
| 13918 | info_ptr += bytes_read; |
| 13919 | break; |
| 13920 | case DW_FORM_block2: |
| 13921 | blk = dwarf_alloc_block (cu); |
| 13922 | blk->size = read_2_bytes (abfd, info_ptr); |
| 13923 | info_ptr += 2; |
| 13924 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 13925 | info_ptr += blk->size; |
| 13926 | DW_BLOCK (attr) = blk; |
| 13927 | break; |
| 13928 | case DW_FORM_block4: |
| 13929 | blk = dwarf_alloc_block (cu); |
| 13930 | blk->size = read_4_bytes (abfd, info_ptr); |
| 13931 | info_ptr += 4; |
| 13932 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 13933 | info_ptr += blk->size; |
| 13934 | DW_BLOCK (attr) = blk; |
| 13935 | break; |
| 13936 | case DW_FORM_data2: |
| 13937 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); |
| 13938 | info_ptr += 2; |
| 13939 | break; |
| 13940 | case DW_FORM_data4: |
| 13941 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); |
| 13942 | info_ptr += 4; |
| 13943 | break; |
| 13944 | case DW_FORM_data8: |
| 13945 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); |
| 13946 | info_ptr += 8; |
| 13947 | break; |
| 13948 | case DW_FORM_sec_offset: |
| 13949 | DW_UNSND (attr) = read_offset (abfd, info_ptr, &cu->header, &bytes_read); |
| 13950 | info_ptr += bytes_read; |
| 13951 | break; |
| 13952 | case DW_FORM_string: |
| 13953 | DW_STRING (attr) = read_direct_string (abfd, info_ptr, &bytes_read); |
| 13954 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 13955 | info_ptr += bytes_read; |
| 13956 | break; |
| 13957 | case DW_FORM_strp: |
| 13958 | if (!cu->per_cu->is_dwz) |
| 13959 | { |
| 13960 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, |
| 13961 | &bytes_read); |
| 13962 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 13963 | info_ptr += bytes_read; |
| 13964 | break; |
| 13965 | } |
| 13966 | /* FALLTHROUGH */ |
| 13967 | case DW_FORM_GNU_strp_alt: |
| 13968 | { |
| 13969 | struct dwz_file *dwz = dwarf2_get_dwz_file (); |
| 13970 | LONGEST str_offset = read_offset (abfd, info_ptr, cu_header, |
| 13971 | &bytes_read); |
| 13972 | |
| 13973 | DW_STRING (attr) = read_indirect_string_from_dwz (dwz, str_offset); |
| 13974 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 13975 | info_ptr += bytes_read; |
| 13976 | } |
| 13977 | break; |
| 13978 | case DW_FORM_exprloc: |
| 13979 | case DW_FORM_block: |
| 13980 | blk = dwarf_alloc_block (cu); |
| 13981 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 13982 | info_ptr += bytes_read; |
| 13983 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 13984 | info_ptr += blk->size; |
| 13985 | DW_BLOCK (attr) = blk; |
| 13986 | break; |
| 13987 | case DW_FORM_block1: |
| 13988 | blk = dwarf_alloc_block (cu); |
| 13989 | blk->size = read_1_byte (abfd, info_ptr); |
| 13990 | info_ptr += 1; |
| 13991 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 13992 | info_ptr += blk->size; |
| 13993 | DW_BLOCK (attr) = blk; |
| 13994 | break; |
| 13995 | case DW_FORM_data1: |
| 13996 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 13997 | info_ptr += 1; |
| 13998 | break; |
| 13999 | case DW_FORM_flag: |
| 14000 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 14001 | info_ptr += 1; |
| 14002 | break; |
| 14003 | case DW_FORM_flag_present: |
| 14004 | DW_UNSND (attr) = 1; |
| 14005 | break; |
| 14006 | case DW_FORM_sdata: |
| 14007 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); |
| 14008 | info_ptr += bytes_read; |
| 14009 | break; |
| 14010 | case DW_FORM_udata: |
| 14011 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 14012 | info_ptr += bytes_read; |
| 14013 | break; |
| 14014 | case DW_FORM_ref1: |
| 14015 | DW_UNSND (attr) = (cu->header.offset.sect_off |
| 14016 | + read_1_byte (abfd, info_ptr)); |
| 14017 | info_ptr += 1; |
| 14018 | break; |
| 14019 | case DW_FORM_ref2: |
| 14020 | DW_UNSND (attr) = (cu->header.offset.sect_off |
| 14021 | + read_2_bytes (abfd, info_ptr)); |
| 14022 | info_ptr += 2; |
| 14023 | break; |
| 14024 | case DW_FORM_ref4: |
| 14025 | DW_UNSND (attr) = (cu->header.offset.sect_off |
| 14026 | + read_4_bytes (abfd, info_ptr)); |
| 14027 | info_ptr += 4; |
| 14028 | break; |
| 14029 | case DW_FORM_ref8: |
| 14030 | DW_UNSND (attr) = (cu->header.offset.sect_off |
| 14031 | + read_8_bytes (abfd, info_ptr)); |
| 14032 | info_ptr += 8; |
| 14033 | break; |
| 14034 | case DW_FORM_ref_sig8: |
| 14035 | /* Convert the signature to something we can record in DW_UNSND |
| 14036 | for later lookup. |
| 14037 | NOTE: This is NULL if the type wasn't found. */ |
| 14038 | DW_SIGNATURED_TYPE (attr) = |
| 14039 | lookup_signatured_type (read_8_bytes (abfd, info_ptr)); |
| 14040 | info_ptr += 8; |
| 14041 | break; |
| 14042 | case DW_FORM_ref_udata: |
| 14043 | DW_UNSND (attr) = (cu->header.offset.sect_off |
| 14044 | + read_unsigned_leb128 (abfd, info_ptr, &bytes_read)); |
| 14045 | info_ptr += bytes_read; |
| 14046 | break; |
| 14047 | case DW_FORM_indirect: |
| 14048 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 14049 | info_ptr += bytes_read; |
| 14050 | info_ptr = read_attribute_value (reader, attr, form, info_ptr); |
| 14051 | break; |
| 14052 | case DW_FORM_GNU_addr_index: |
| 14053 | if (reader->dwo_file == NULL) |
| 14054 | { |
| 14055 | /* For now flag a hard error. |
| 14056 | Later we can turn this into a complaint. */ |
| 14057 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), |
| 14058 | dwarf_form_name (form), |
| 14059 | bfd_get_filename (abfd)); |
| 14060 | } |
| 14061 | DW_ADDR (attr) = read_addr_index_from_leb128 (cu, info_ptr, &bytes_read); |
| 14062 | info_ptr += bytes_read; |
| 14063 | break; |
| 14064 | case DW_FORM_GNU_str_index: |
| 14065 | if (reader->dwo_file == NULL) |
| 14066 | { |
| 14067 | /* For now flag a hard error. |
| 14068 | Later we can turn this into a complaint if warranted. */ |
| 14069 | error (_("Dwarf Error: %s found in non-DWO CU [in module %s]"), |
| 14070 | dwarf_form_name (form), |
| 14071 | bfd_get_filename (abfd)); |
| 14072 | } |
| 14073 | { |
| 14074 | ULONGEST str_index = |
| 14075 | read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 14076 | |
| 14077 | DW_STRING (attr) = read_str_index (reader, cu, str_index); |
| 14078 | DW_STRING_IS_CANONICAL (attr) = 0; |
| 14079 | info_ptr += bytes_read; |
| 14080 | } |
| 14081 | break; |
| 14082 | default: |
| 14083 | error (_("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]"), |
| 14084 | dwarf_form_name (form), |
| 14085 | bfd_get_filename (abfd)); |
| 14086 | } |
| 14087 | |
| 14088 | /* Super hack. */ |
| 14089 | if (cu->per_cu->is_dwz && is_ref_attr (attr)) |
| 14090 | attr->form = DW_FORM_GNU_ref_alt; |
| 14091 | |
| 14092 | /* We have seen instances where the compiler tried to emit a byte |
| 14093 | size attribute of -1 which ended up being encoded as an unsigned |
| 14094 | 0xffffffff. Although 0xffffffff is technically a valid size value, |
| 14095 | an object of this size seems pretty unlikely so we can relatively |
| 14096 | safely treat these cases as if the size attribute was invalid and |
| 14097 | treat them as zero by default. */ |
| 14098 | if (attr->name == DW_AT_byte_size |
| 14099 | && form == DW_FORM_data4 |
| 14100 | && DW_UNSND (attr) >= 0xffffffff) |
| 14101 | { |
| 14102 | complaint |
| 14103 | (&symfile_complaints, |
| 14104 | _("Suspicious DW_AT_byte_size value treated as zero instead of %s"), |
| 14105 | hex_string (DW_UNSND (attr))); |
| 14106 | DW_UNSND (attr) = 0; |
| 14107 | } |
| 14108 | |
| 14109 | return info_ptr; |
| 14110 | } |
| 14111 | |
| 14112 | /* Read an attribute described by an abbreviated attribute. */ |
| 14113 | |
| 14114 | static gdb_byte * |
| 14115 | read_attribute (const struct die_reader_specs *reader, |
| 14116 | struct attribute *attr, struct attr_abbrev *abbrev, |
| 14117 | gdb_byte *info_ptr) |
| 14118 | { |
| 14119 | attr->name = abbrev->name; |
| 14120 | return read_attribute_value (reader, attr, abbrev->form, info_ptr); |
| 14121 | } |
| 14122 | |
| 14123 | /* Read dwarf information from a buffer. */ |
| 14124 | |
| 14125 | static unsigned int |
| 14126 | read_1_byte (bfd *abfd, const gdb_byte *buf) |
| 14127 | { |
| 14128 | return bfd_get_8 (abfd, buf); |
| 14129 | } |
| 14130 | |
| 14131 | static int |
| 14132 | read_1_signed_byte (bfd *abfd, const gdb_byte *buf) |
| 14133 | { |
| 14134 | return bfd_get_signed_8 (abfd, buf); |
| 14135 | } |
| 14136 | |
| 14137 | static unsigned int |
| 14138 | read_2_bytes (bfd *abfd, const gdb_byte *buf) |
| 14139 | { |
| 14140 | return bfd_get_16 (abfd, buf); |
| 14141 | } |
| 14142 | |
| 14143 | static int |
| 14144 | read_2_signed_bytes (bfd *abfd, const gdb_byte *buf) |
| 14145 | { |
| 14146 | return bfd_get_signed_16 (abfd, buf); |
| 14147 | } |
| 14148 | |
| 14149 | static unsigned int |
| 14150 | read_4_bytes (bfd *abfd, const gdb_byte *buf) |
| 14151 | { |
| 14152 | return bfd_get_32 (abfd, buf); |
| 14153 | } |
| 14154 | |
| 14155 | static int |
| 14156 | read_4_signed_bytes (bfd *abfd, const gdb_byte *buf) |
| 14157 | { |
| 14158 | return bfd_get_signed_32 (abfd, buf); |
| 14159 | } |
| 14160 | |
| 14161 | static ULONGEST |
| 14162 | read_8_bytes (bfd *abfd, const gdb_byte *buf) |
| 14163 | { |
| 14164 | return bfd_get_64 (abfd, buf); |
| 14165 | } |
| 14166 | |
| 14167 | static CORE_ADDR |
| 14168 | read_address (bfd *abfd, gdb_byte *buf, struct dwarf2_cu *cu, |
| 14169 | unsigned int *bytes_read) |
| 14170 | { |
| 14171 | struct comp_unit_head *cu_header = &cu->header; |
| 14172 | CORE_ADDR retval = 0; |
| 14173 | |
| 14174 | if (cu_header->signed_addr_p) |
| 14175 | { |
| 14176 | switch (cu_header->addr_size) |
| 14177 | { |
| 14178 | case 2: |
| 14179 | retval = bfd_get_signed_16 (abfd, buf); |
| 14180 | break; |
| 14181 | case 4: |
| 14182 | retval = bfd_get_signed_32 (abfd, buf); |
| 14183 | break; |
| 14184 | case 8: |
| 14185 | retval = bfd_get_signed_64 (abfd, buf); |
| 14186 | break; |
| 14187 | default: |
| 14188 | internal_error (__FILE__, __LINE__, |
| 14189 | _("read_address: bad switch, signed [in module %s]"), |
| 14190 | bfd_get_filename (abfd)); |
| 14191 | } |
| 14192 | } |
| 14193 | else |
| 14194 | { |
| 14195 | switch (cu_header->addr_size) |
| 14196 | { |
| 14197 | case 2: |
| 14198 | retval = bfd_get_16 (abfd, buf); |
| 14199 | break; |
| 14200 | case 4: |
| 14201 | retval = bfd_get_32 (abfd, buf); |
| 14202 | break; |
| 14203 | case 8: |
| 14204 | retval = bfd_get_64 (abfd, buf); |
| 14205 | break; |
| 14206 | default: |
| 14207 | internal_error (__FILE__, __LINE__, |
| 14208 | _("read_address: bad switch, " |
| 14209 | "unsigned [in module %s]"), |
| 14210 | bfd_get_filename (abfd)); |
| 14211 | } |
| 14212 | } |
| 14213 | |
| 14214 | *bytes_read = cu_header->addr_size; |
| 14215 | return retval; |
| 14216 | } |
| 14217 | |
| 14218 | /* Read the initial length from a section. The (draft) DWARF 3 |
| 14219 | specification allows the initial length to take up either 4 bytes |
| 14220 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 |
| 14221 | bytes describe the length and all offsets will be 8 bytes in length |
| 14222 | instead of 4. |
| 14223 | |
| 14224 | An older, non-standard 64-bit format is also handled by this |
| 14225 | function. The older format in question stores the initial length |
| 14226 | as an 8-byte quantity without an escape value. Lengths greater |
| 14227 | than 2^32 aren't very common which means that the initial 4 bytes |
| 14228 | is almost always zero. Since a length value of zero doesn't make |
| 14229 | sense for the 32-bit format, this initial zero can be considered to |
| 14230 | be an escape value which indicates the presence of the older 64-bit |
| 14231 | format. As written, the code can't detect (old format) lengths |
| 14232 | greater than 4GB. If it becomes necessary to handle lengths |
| 14233 | somewhat larger than 4GB, we could allow other small values (such |
| 14234 | as the non-sensical values of 1, 2, and 3) to also be used as |
| 14235 | escape values indicating the presence of the old format. |
| 14236 | |
| 14237 | The value returned via bytes_read should be used to increment the |
| 14238 | relevant pointer after calling read_initial_length(). |
| 14239 | |
| 14240 | [ Note: read_initial_length() and read_offset() are based on the |
| 14241 | document entitled "DWARF Debugging Information Format", revision |
| 14242 | 3, draft 8, dated November 19, 2001. This document was obtained |
| 14243 | from: |
| 14244 | |
| 14245 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
| 14246 | |
| 14247 | This document is only a draft and is subject to change. (So beware.) |
| 14248 | |
| 14249 | Details regarding the older, non-standard 64-bit format were |
| 14250 | determined empirically by examining 64-bit ELF files produced by |
| 14251 | the SGI toolchain on an IRIX 6.5 machine. |
| 14252 | |
| 14253 | - Kevin, July 16, 2002 |
| 14254 | ] */ |
| 14255 | |
| 14256 | static LONGEST |
| 14257 | read_initial_length (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read) |
| 14258 | { |
| 14259 | LONGEST length = bfd_get_32 (abfd, buf); |
| 14260 | |
| 14261 | if (length == 0xffffffff) |
| 14262 | { |
| 14263 | length = bfd_get_64 (abfd, buf + 4); |
| 14264 | *bytes_read = 12; |
| 14265 | } |
| 14266 | else if (length == 0) |
| 14267 | { |
| 14268 | /* Handle the (non-standard) 64-bit DWARF2 format used by IRIX. */ |
| 14269 | length = bfd_get_64 (abfd, buf); |
| 14270 | *bytes_read = 8; |
| 14271 | } |
| 14272 | else |
| 14273 | { |
| 14274 | *bytes_read = 4; |
| 14275 | } |
| 14276 | |
| 14277 | return length; |
| 14278 | } |
| 14279 | |
| 14280 | /* Cover function for read_initial_length. |
| 14281 | Returns the length of the object at BUF, and stores the size of the |
| 14282 | initial length in *BYTES_READ and stores the size that offsets will be in |
| 14283 | *OFFSET_SIZE. |
| 14284 | If the initial length size is not equivalent to that specified in |
| 14285 | CU_HEADER then issue a complaint. |
| 14286 | This is useful when reading non-comp-unit headers. */ |
| 14287 | |
| 14288 | static LONGEST |
| 14289 | read_checked_initial_length_and_offset (bfd *abfd, gdb_byte *buf, |
| 14290 | const struct comp_unit_head *cu_header, |
| 14291 | unsigned int *bytes_read, |
| 14292 | unsigned int *offset_size) |
| 14293 | { |
| 14294 | LONGEST length = read_initial_length (abfd, buf, bytes_read); |
| 14295 | |
| 14296 | gdb_assert (cu_header->initial_length_size == 4 |
| 14297 | || cu_header->initial_length_size == 8 |
| 14298 | || cu_header->initial_length_size == 12); |
| 14299 | |
| 14300 | if (cu_header->initial_length_size != *bytes_read) |
| 14301 | complaint (&symfile_complaints, |
| 14302 | _("intermixed 32-bit and 64-bit DWARF sections")); |
| 14303 | |
| 14304 | *offset_size = (*bytes_read == 4) ? 4 : 8; |
| 14305 | return length; |
| 14306 | } |
| 14307 | |
| 14308 | /* Read an offset from the data stream. The size of the offset is |
| 14309 | given by cu_header->offset_size. */ |
| 14310 | |
| 14311 | static LONGEST |
| 14312 | read_offset (bfd *abfd, gdb_byte *buf, const struct comp_unit_head *cu_header, |
| 14313 | unsigned int *bytes_read) |
| 14314 | { |
| 14315 | LONGEST offset = read_offset_1 (abfd, buf, cu_header->offset_size); |
| 14316 | |
| 14317 | *bytes_read = cu_header->offset_size; |
| 14318 | return offset; |
| 14319 | } |
| 14320 | |
| 14321 | /* Read an offset from the data stream. */ |
| 14322 | |
| 14323 | static LONGEST |
| 14324 | read_offset_1 (bfd *abfd, gdb_byte *buf, unsigned int offset_size) |
| 14325 | { |
| 14326 | LONGEST retval = 0; |
| 14327 | |
| 14328 | switch (offset_size) |
| 14329 | { |
| 14330 | case 4: |
| 14331 | retval = bfd_get_32 (abfd, buf); |
| 14332 | break; |
| 14333 | case 8: |
| 14334 | retval = bfd_get_64 (abfd, buf); |
| 14335 | break; |
| 14336 | default: |
| 14337 | internal_error (__FILE__, __LINE__, |
| 14338 | _("read_offset_1: bad switch [in module %s]"), |
| 14339 | bfd_get_filename (abfd)); |
| 14340 | } |
| 14341 | |
| 14342 | return retval; |
| 14343 | } |
| 14344 | |
| 14345 | static gdb_byte * |
| 14346 | read_n_bytes (bfd *abfd, gdb_byte *buf, unsigned int size) |
| 14347 | { |
| 14348 | /* If the size of a host char is 8 bits, we can return a pointer |
| 14349 | to the buffer, otherwise we have to copy the data to a buffer |
| 14350 | allocated on the temporary obstack. */ |
| 14351 | gdb_assert (HOST_CHAR_BIT == 8); |
| 14352 | return buf; |
| 14353 | } |
| 14354 | |
| 14355 | static char * |
| 14356 | read_direct_string (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 14357 | { |
| 14358 | /* If the size of a host char is 8 bits, we can return a pointer |
| 14359 | to the string, otherwise we have to copy the string to a buffer |
| 14360 | allocated on the temporary obstack. */ |
| 14361 | gdb_assert (HOST_CHAR_BIT == 8); |
| 14362 | if (*buf == '\0') |
| 14363 | { |
| 14364 | *bytes_read_ptr = 1; |
| 14365 | return NULL; |
| 14366 | } |
| 14367 | *bytes_read_ptr = strlen ((char *) buf) + 1; |
| 14368 | return (char *) buf; |
| 14369 | } |
| 14370 | |
| 14371 | static char * |
| 14372 | read_indirect_string_at_offset (bfd *abfd, LONGEST str_offset) |
| 14373 | { |
| 14374 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwarf2_per_objfile->str); |
| 14375 | if (dwarf2_per_objfile->str.buffer == NULL) |
| 14376 | error (_("DW_FORM_strp used without .debug_str section [in module %s]"), |
| 14377 | bfd_get_filename (abfd)); |
| 14378 | if (str_offset >= dwarf2_per_objfile->str.size) |
| 14379 | error (_("DW_FORM_strp pointing outside of " |
| 14380 | ".debug_str section [in module %s]"), |
| 14381 | bfd_get_filename (abfd)); |
| 14382 | gdb_assert (HOST_CHAR_BIT == 8); |
| 14383 | if (dwarf2_per_objfile->str.buffer[str_offset] == '\0') |
| 14384 | return NULL; |
| 14385 | return (char *) (dwarf2_per_objfile->str.buffer + str_offset); |
| 14386 | } |
| 14387 | |
| 14388 | /* Read a string at offset STR_OFFSET in the .debug_str section from |
| 14389 | the .dwz file DWZ. Throw an error if the offset is too large. If |
| 14390 | the string consists of a single NUL byte, return NULL; otherwise |
| 14391 | return a pointer to the string. */ |
| 14392 | |
| 14393 | static char * |
| 14394 | read_indirect_string_from_dwz (struct dwz_file *dwz, LONGEST str_offset) |
| 14395 | { |
| 14396 | dwarf2_read_section (dwarf2_per_objfile->objfile, &dwz->str); |
| 14397 | |
| 14398 | if (dwz->str.buffer == NULL) |
| 14399 | error (_("DW_FORM_GNU_strp_alt used without .debug_str " |
| 14400 | "section [in module %s]"), |
| 14401 | bfd_get_filename (dwz->dwz_bfd)); |
| 14402 | if (str_offset >= dwz->str.size) |
| 14403 | error (_("DW_FORM_GNU_strp_alt pointing outside of " |
| 14404 | ".debug_str section [in module %s]"), |
| 14405 | bfd_get_filename (dwz->dwz_bfd)); |
| 14406 | gdb_assert (HOST_CHAR_BIT == 8); |
| 14407 | if (dwz->str.buffer[str_offset] == '\0') |
| 14408 | return NULL; |
| 14409 | return (char *) (dwz->str.buffer + str_offset); |
| 14410 | } |
| 14411 | |
| 14412 | static char * |
| 14413 | read_indirect_string (bfd *abfd, gdb_byte *buf, |
| 14414 | const struct comp_unit_head *cu_header, |
| 14415 | unsigned int *bytes_read_ptr) |
| 14416 | { |
| 14417 | LONGEST str_offset = read_offset (abfd, buf, cu_header, bytes_read_ptr); |
| 14418 | |
| 14419 | return read_indirect_string_at_offset (abfd, str_offset); |
| 14420 | } |
| 14421 | |
| 14422 | static ULONGEST |
| 14423 | read_unsigned_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 14424 | { |
| 14425 | ULONGEST result; |
| 14426 | unsigned int num_read; |
| 14427 | int i, shift; |
| 14428 | unsigned char byte; |
| 14429 | |
| 14430 | result = 0; |
| 14431 | shift = 0; |
| 14432 | num_read = 0; |
| 14433 | i = 0; |
| 14434 | while (1) |
| 14435 | { |
| 14436 | byte = bfd_get_8 (abfd, buf); |
| 14437 | buf++; |
| 14438 | num_read++; |
| 14439 | result |= ((ULONGEST) (byte & 127) << shift); |
| 14440 | if ((byte & 128) == 0) |
| 14441 | { |
| 14442 | break; |
| 14443 | } |
| 14444 | shift += 7; |
| 14445 | } |
| 14446 | *bytes_read_ptr = num_read; |
| 14447 | return result; |
| 14448 | } |
| 14449 | |
| 14450 | static LONGEST |
| 14451 | read_signed_leb128 (bfd *abfd, gdb_byte *buf, unsigned int *bytes_read_ptr) |
| 14452 | { |
| 14453 | LONGEST result; |
| 14454 | int i, shift, num_read; |
| 14455 | unsigned char byte; |
| 14456 | |
| 14457 | result = 0; |
| 14458 | shift = 0; |
| 14459 | num_read = 0; |
| 14460 | i = 0; |
| 14461 | while (1) |
| 14462 | { |
| 14463 | byte = bfd_get_8 (abfd, buf); |
| 14464 | buf++; |
| 14465 | num_read++; |
| 14466 | result |= ((LONGEST) (byte & 127) << shift); |
| 14467 | shift += 7; |
| 14468 | if ((byte & 128) == 0) |
| 14469 | { |
| 14470 | break; |
| 14471 | } |
| 14472 | } |
| 14473 | if ((shift < 8 * sizeof (result)) && (byte & 0x40)) |
| 14474 | result |= -(((LONGEST) 1) << shift); |
| 14475 | *bytes_read_ptr = num_read; |
| 14476 | return result; |
| 14477 | } |
| 14478 | |
| 14479 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. |
| 14480 | ADDR_BASE is the DW_AT_GNU_addr_base attribute or zero. |
| 14481 | ADDR_SIZE is the size of addresses from the CU header. */ |
| 14482 | |
| 14483 | static CORE_ADDR |
| 14484 | read_addr_index_1 (unsigned int addr_index, ULONGEST addr_base, int addr_size) |
| 14485 | { |
| 14486 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 14487 | bfd *abfd = objfile->obfd; |
| 14488 | const gdb_byte *info_ptr; |
| 14489 | |
| 14490 | dwarf2_read_section (objfile, &dwarf2_per_objfile->addr); |
| 14491 | if (dwarf2_per_objfile->addr.buffer == NULL) |
| 14492 | error (_("DW_FORM_addr_index used without .debug_addr section [in module %s]"), |
| 14493 | objfile->name); |
| 14494 | if (addr_base + addr_index * addr_size >= dwarf2_per_objfile->addr.size) |
| 14495 | error (_("DW_FORM_addr_index pointing outside of " |
| 14496 | ".debug_addr section [in module %s]"), |
| 14497 | objfile->name); |
| 14498 | info_ptr = (dwarf2_per_objfile->addr.buffer |
| 14499 | + addr_base + addr_index * addr_size); |
| 14500 | if (addr_size == 4) |
| 14501 | return bfd_get_32 (abfd, info_ptr); |
| 14502 | else |
| 14503 | return bfd_get_64 (abfd, info_ptr); |
| 14504 | } |
| 14505 | |
| 14506 | /* Given index ADDR_INDEX in .debug_addr, fetch the value. */ |
| 14507 | |
| 14508 | static CORE_ADDR |
| 14509 | read_addr_index (struct dwarf2_cu *cu, unsigned int addr_index) |
| 14510 | { |
| 14511 | return read_addr_index_1 (addr_index, cu->addr_base, cu->header.addr_size); |
| 14512 | } |
| 14513 | |
| 14514 | /* Given a pointer to an leb128 value, fetch the value from .debug_addr. */ |
| 14515 | |
| 14516 | static CORE_ADDR |
| 14517 | read_addr_index_from_leb128 (struct dwarf2_cu *cu, gdb_byte *info_ptr, |
| 14518 | unsigned int *bytes_read) |
| 14519 | { |
| 14520 | bfd *abfd = cu->objfile->obfd; |
| 14521 | unsigned int addr_index = read_unsigned_leb128 (abfd, info_ptr, bytes_read); |
| 14522 | |
| 14523 | return read_addr_index (cu, addr_index); |
| 14524 | } |
| 14525 | |
| 14526 | /* Data structure to pass results from dwarf2_read_addr_index_reader |
| 14527 | back to dwarf2_read_addr_index. */ |
| 14528 | |
| 14529 | struct dwarf2_read_addr_index_data |
| 14530 | { |
| 14531 | ULONGEST addr_base; |
| 14532 | int addr_size; |
| 14533 | }; |
| 14534 | |
| 14535 | /* die_reader_func for dwarf2_read_addr_index. */ |
| 14536 | |
| 14537 | static void |
| 14538 | dwarf2_read_addr_index_reader (const struct die_reader_specs *reader, |
| 14539 | gdb_byte *info_ptr, |
| 14540 | struct die_info *comp_unit_die, |
| 14541 | int has_children, |
| 14542 | void *data) |
| 14543 | { |
| 14544 | struct dwarf2_cu *cu = reader->cu; |
| 14545 | struct dwarf2_read_addr_index_data *aidata = |
| 14546 | (struct dwarf2_read_addr_index_data *) data; |
| 14547 | |
| 14548 | aidata->addr_base = cu->addr_base; |
| 14549 | aidata->addr_size = cu->header.addr_size; |
| 14550 | } |
| 14551 | |
| 14552 | /* Given an index in .debug_addr, fetch the value. |
| 14553 | NOTE: This can be called during dwarf expression evaluation, |
| 14554 | long after the debug information has been read, and thus per_cu->cu |
| 14555 | may no longer exist. */ |
| 14556 | |
| 14557 | CORE_ADDR |
| 14558 | dwarf2_read_addr_index (struct dwarf2_per_cu_data *per_cu, |
| 14559 | unsigned int addr_index) |
| 14560 | { |
| 14561 | struct objfile *objfile = per_cu->objfile; |
| 14562 | struct dwarf2_cu *cu = per_cu->cu; |
| 14563 | ULONGEST addr_base; |
| 14564 | int addr_size; |
| 14565 | |
| 14566 | /* This is intended to be called from outside this file. */ |
| 14567 | dw2_setup (objfile); |
| 14568 | |
| 14569 | /* We need addr_base and addr_size. |
| 14570 | If we don't have PER_CU->cu, we have to get it. |
| 14571 | Nasty, but the alternative is storing the needed info in PER_CU, |
| 14572 | which at this point doesn't seem justified: it's not clear how frequently |
| 14573 | it would get used and it would increase the size of every PER_CU. |
| 14574 | Entry points like dwarf2_per_cu_addr_size do a similar thing |
| 14575 | so we're not in uncharted territory here. |
| 14576 | Alas we need to be a bit more complicated as addr_base is contained |
| 14577 | in the DIE. |
| 14578 | |
| 14579 | We don't need to read the entire CU(/TU). |
| 14580 | We just need the header and top level die. |
| 14581 | |
| 14582 | IWBN to use the aging mechanism to let us lazily later discard the CU. |
| 14583 | For now we skip this optimization. */ |
| 14584 | |
| 14585 | if (cu != NULL) |
| 14586 | { |
| 14587 | addr_base = cu->addr_base; |
| 14588 | addr_size = cu->header.addr_size; |
| 14589 | } |
| 14590 | else |
| 14591 | { |
| 14592 | struct dwarf2_read_addr_index_data aidata; |
| 14593 | |
| 14594 | /* Note: We can't use init_cutu_and_read_dies_simple here, |
| 14595 | we need addr_base. */ |
| 14596 | init_cutu_and_read_dies (per_cu, NULL, 0, 0, |
| 14597 | dwarf2_read_addr_index_reader, &aidata); |
| 14598 | addr_base = aidata.addr_base; |
| 14599 | addr_size = aidata.addr_size; |
| 14600 | } |
| 14601 | |
| 14602 | return read_addr_index_1 (addr_index, addr_base, addr_size); |
| 14603 | } |
| 14604 | |
| 14605 | /* Given a DW_AT_str_index, fetch the string. */ |
| 14606 | |
| 14607 | static char * |
| 14608 | read_str_index (const struct die_reader_specs *reader, |
| 14609 | struct dwarf2_cu *cu, ULONGEST str_index) |
| 14610 | { |
| 14611 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 14612 | const char *dwo_name = objfile->name; |
| 14613 | bfd *abfd = objfile->obfd; |
| 14614 | struct dwo_sections *sections = &reader->dwo_file->sections; |
| 14615 | gdb_byte *info_ptr; |
| 14616 | ULONGEST str_offset; |
| 14617 | |
| 14618 | dwarf2_read_section (objfile, §ions->str); |
| 14619 | dwarf2_read_section (objfile, §ions->str_offsets); |
| 14620 | if (sections->str.buffer == NULL) |
| 14621 | error (_("DW_FORM_str_index used without .debug_str.dwo section" |
| 14622 | " in CU at offset 0x%lx [in module %s]"), |
| 14623 | (long) cu->header.offset.sect_off, dwo_name); |
| 14624 | if (sections->str_offsets.buffer == NULL) |
| 14625 | error (_("DW_FORM_str_index used without .debug_str_offsets.dwo section" |
| 14626 | " in CU at offset 0x%lx [in module %s]"), |
| 14627 | (long) cu->header.offset.sect_off, dwo_name); |
| 14628 | if (str_index * cu->header.offset_size >= sections->str_offsets.size) |
| 14629 | error (_("DW_FORM_str_index pointing outside of .debug_str_offsets.dwo" |
| 14630 | " section in CU at offset 0x%lx [in module %s]"), |
| 14631 | (long) cu->header.offset.sect_off, dwo_name); |
| 14632 | info_ptr = (sections->str_offsets.buffer |
| 14633 | + str_index * cu->header.offset_size); |
| 14634 | if (cu->header.offset_size == 4) |
| 14635 | str_offset = bfd_get_32 (abfd, info_ptr); |
| 14636 | else |
| 14637 | str_offset = bfd_get_64 (abfd, info_ptr); |
| 14638 | if (str_offset >= sections->str.size) |
| 14639 | error (_("Offset from DW_FORM_str_index pointing outside of" |
| 14640 | " .debug_str.dwo section in CU at offset 0x%lx [in module %s]"), |
| 14641 | (long) cu->header.offset.sect_off, dwo_name); |
| 14642 | return (char *) (sections->str.buffer + str_offset); |
| 14643 | } |
| 14644 | |
| 14645 | /* Return the length of an LEB128 number in BUF. */ |
| 14646 | |
| 14647 | static int |
| 14648 | leb128_size (const gdb_byte *buf) |
| 14649 | { |
| 14650 | const gdb_byte *begin = buf; |
| 14651 | gdb_byte byte; |
| 14652 | |
| 14653 | while (1) |
| 14654 | { |
| 14655 | byte = *buf++; |
| 14656 | if ((byte & 128) == 0) |
| 14657 | return buf - begin; |
| 14658 | } |
| 14659 | } |
| 14660 | |
| 14661 | static void |
| 14662 | set_cu_language (unsigned int lang, struct dwarf2_cu *cu) |
| 14663 | { |
| 14664 | switch (lang) |
| 14665 | { |
| 14666 | case DW_LANG_C89: |
| 14667 | case DW_LANG_C99: |
| 14668 | case DW_LANG_C: |
| 14669 | cu->language = language_c; |
| 14670 | break; |
| 14671 | case DW_LANG_C_plus_plus: |
| 14672 | cu->language = language_cplus; |
| 14673 | break; |
| 14674 | case DW_LANG_D: |
| 14675 | cu->language = language_d; |
| 14676 | break; |
| 14677 | case DW_LANG_Fortran77: |
| 14678 | case DW_LANG_Fortran90: |
| 14679 | case DW_LANG_Fortran95: |
| 14680 | cu->language = language_fortran; |
| 14681 | break; |
| 14682 | case DW_LANG_Go: |
| 14683 | cu->language = language_go; |
| 14684 | break; |
| 14685 | case DW_LANG_Mips_Assembler: |
| 14686 | cu->language = language_asm; |
| 14687 | break; |
| 14688 | case DW_LANG_Java: |
| 14689 | cu->language = language_java; |
| 14690 | break; |
| 14691 | case DW_LANG_Ada83: |
| 14692 | case DW_LANG_Ada95: |
| 14693 | cu->language = language_ada; |
| 14694 | break; |
| 14695 | case DW_LANG_Modula2: |
| 14696 | cu->language = language_m2; |
| 14697 | break; |
| 14698 | case DW_LANG_Pascal83: |
| 14699 | cu->language = language_pascal; |
| 14700 | break; |
| 14701 | case DW_LANG_ObjC: |
| 14702 | cu->language = language_objc; |
| 14703 | break; |
| 14704 | case DW_LANG_Cobol74: |
| 14705 | case DW_LANG_Cobol85: |
| 14706 | default: |
| 14707 | cu->language = language_minimal; |
| 14708 | break; |
| 14709 | } |
| 14710 | cu->language_defn = language_def (cu->language); |
| 14711 | } |
| 14712 | |
| 14713 | /* Return the named attribute or NULL if not there. */ |
| 14714 | |
| 14715 | static struct attribute * |
| 14716 | dwarf2_attr (struct die_info *die, unsigned int name, struct dwarf2_cu *cu) |
| 14717 | { |
| 14718 | for (;;) |
| 14719 | { |
| 14720 | unsigned int i; |
| 14721 | struct attribute *spec = NULL; |
| 14722 | |
| 14723 | for (i = 0; i < die->num_attrs; ++i) |
| 14724 | { |
| 14725 | if (die->attrs[i].name == name) |
| 14726 | return &die->attrs[i]; |
| 14727 | if (die->attrs[i].name == DW_AT_specification |
| 14728 | || die->attrs[i].name == DW_AT_abstract_origin) |
| 14729 | spec = &die->attrs[i]; |
| 14730 | } |
| 14731 | |
| 14732 | if (!spec) |
| 14733 | break; |
| 14734 | |
| 14735 | die = follow_die_ref (die, spec, &cu); |
| 14736 | } |
| 14737 | |
| 14738 | return NULL; |
| 14739 | } |
| 14740 | |
| 14741 | /* Return the named attribute or NULL if not there, |
| 14742 | but do not follow DW_AT_specification, etc. |
| 14743 | This is for use in contexts where we're reading .debug_types dies. |
| 14744 | Following DW_AT_specification, DW_AT_abstract_origin will take us |
| 14745 | back up the chain, and we want to go down. */ |
| 14746 | |
| 14747 | static struct attribute * |
| 14748 | dwarf2_attr_no_follow (struct die_info *die, unsigned int name) |
| 14749 | { |
| 14750 | unsigned int i; |
| 14751 | |
| 14752 | for (i = 0; i < die->num_attrs; ++i) |
| 14753 | if (die->attrs[i].name == name) |
| 14754 | return &die->attrs[i]; |
| 14755 | |
| 14756 | return NULL; |
| 14757 | } |
| 14758 | |
| 14759 | /* Return non-zero iff the attribute NAME is defined for the given DIE, |
| 14760 | and holds a non-zero value. This function should only be used for |
| 14761 | DW_FORM_flag or DW_FORM_flag_present attributes. */ |
| 14762 | |
| 14763 | static int |
| 14764 | dwarf2_flag_true_p (struct die_info *die, unsigned name, struct dwarf2_cu *cu) |
| 14765 | { |
| 14766 | struct attribute *attr = dwarf2_attr (die, name, cu); |
| 14767 | |
| 14768 | return (attr && DW_UNSND (attr)); |
| 14769 | } |
| 14770 | |
| 14771 | static int |
| 14772 | die_is_declaration (struct die_info *die, struct dwarf2_cu *cu) |
| 14773 | { |
| 14774 | /* A DIE is a declaration if it has a DW_AT_declaration attribute |
| 14775 | which value is non-zero. However, we have to be careful with |
| 14776 | DIEs having a DW_AT_specification attribute, because dwarf2_attr() |
| 14777 | (via dwarf2_flag_true_p) follows this attribute. So we may |
| 14778 | end up accidently finding a declaration attribute that belongs |
| 14779 | to a different DIE referenced by the specification attribute, |
| 14780 | even though the given DIE does not have a declaration attribute. */ |
| 14781 | return (dwarf2_flag_true_p (die, DW_AT_declaration, cu) |
| 14782 | && dwarf2_attr (die, DW_AT_specification, cu) == NULL); |
| 14783 | } |
| 14784 | |
| 14785 | /* Return the die giving the specification for DIE, if there is |
| 14786 | one. *SPEC_CU is the CU containing DIE on input, and the CU |
| 14787 | containing the return value on output. If there is no |
| 14788 | specification, but there is an abstract origin, that is |
| 14789 | returned. */ |
| 14790 | |
| 14791 | static struct die_info * |
| 14792 | die_specification (struct die_info *die, struct dwarf2_cu **spec_cu) |
| 14793 | { |
| 14794 | struct attribute *spec_attr = dwarf2_attr (die, DW_AT_specification, |
| 14795 | *spec_cu); |
| 14796 | |
| 14797 | if (spec_attr == NULL) |
| 14798 | spec_attr = dwarf2_attr (die, DW_AT_abstract_origin, *spec_cu); |
| 14799 | |
| 14800 | if (spec_attr == NULL) |
| 14801 | return NULL; |
| 14802 | else |
| 14803 | return follow_die_ref (die, spec_attr, spec_cu); |
| 14804 | } |
| 14805 | |
| 14806 | /* Free the line_header structure *LH, and any arrays and strings it |
| 14807 | refers to. |
| 14808 | NOTE: This is also used as a "cleanup" function. */ |
| 14809 | |
| 14810 | static void |
| 14811 | free_line_header (struct line_header *lh) |
| 14812 | { |
| 14813 | if (lh->standard_opcode_lengths) |
| 14814 | xfree (lh->standard_opcode_lengths); |
| 14815 | |
| 14816 | /* Remember that all the lh->file_names[i].name pointers are |
| 14817 | pointers into debug_line_buffer, and don't need to be freed. */ |
| 14818 | if (lh->file_names) |
| 14819 | xfree (lh->file_names); |
| 14820 | |
| 14821 | /* Similarly for the include directory names. */ |
| 14822 | if (lh->include_dirs) |
| 14823 | xfree (lh->include_dirs); |
| 14824 | |
| 14825 | xfree (lh); |
| 14826 | } |
| 14827 | |
| 14828 | /* Add an entry to LH's include directory table. */ |
| 14829 | |
| 14830 | static void |
| 14831 | add_include_dir (struct line_header *lh, char *include_dir) |
| 14832 | { |
| 14833 | /* Grow the array if necessary. */ |
| 14834 | if (lh->include_dirs_size == 0) |
| 14835 | { |
| 14836 | lh->include_dirs_size = 1; /* for testing */ |
| 14837 | lh->include_dirs = xmalloc (lh->include_dirs_size |
| 14838 | * sizeof (*lh->include_dirs)); |
| 14839 | } |
| 14840 | else if (lh->num_include_dirs >= lh->include_dirs_size) |
| 14841 | { |
| 14842 | lh->include_dirs_size *= 2; |
| 14843 | lh->include_dirs = xrealloc (lh->include_dirs, |
| 14844 | (lh->include_dirs_size |
| 14845 | * sizeof (*lh->include_dirs))); |
| 14846 | } |
| 14847 | |
| 14848 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
| 14849 | } |
| 14850 | |
| 14851 | /* Add an entry to LH's file name table. */ |
| 14852 | |
| 14853 | static void |
| 14854 | add_file_name (struct line_header *lh, |
| 14855 | char *name, |
| 14856 | unsigned int dir_index, |
| 14857 | unsigned int mod_time, |
| 14858 | unsigned int length) |
| 14859 | { |
| 14860 | struct file_entry *fe; |
| 14861 | |
| 14862 | /* Grow the array if necessary. */ |
| 14863 | if (lh->file_names_size == 0) |
| 14864 | { |
| 14865 | lh->file_names_size = 1; /* for testing */ |
| 14866 | lh->file_names = xmalloc (lh->file_names_size |
| 14867 | * sizeof (*lh->file_names)); |
| 14868 | } |
| 14869 | else if (lh->num_file_names >= lh->file_names_size) |
| 14870 | { |
| 14871 | lh->file_names_size *= 2; |
| 14872 | lh->file_names = xrealloc (lh->file_names, |
| 14873 | (lh->file_names_size |
| 14874 | * sizeof (*lh->file_names))); |
| 14875 | } |
| 14876 | |
| 14877 | fe = &lh->file_names[lh->num_file_names++]; |
| 14878 | fe->name = name; |
| 14879 | fe->dir_index = dir_index; |
| 14880 | fe->mod_time = mod_time; |
| 14881 | fe->length = length; |
| 14882 | fe->included_p = 0; |
| 14883 | fe->symtab = NULL; |
| 14884 | } |
| 14885 | |
| 14886 | /* A convenience function to find the proper .debug_line section for a |
| 14887 | CU. */ |
| 14888 | |
| 14889 | static struct dwarf2_section_info * |
| 14890 | get_debug_line_section (struct dwarf2_cu *cu) |
| 14891 | { |
| 14892 | struct dwarf2_section_info *section; |
| 14893 | |
| 14894 | /* For TUs in DWO files, the DW_AT_stmt_list attribute lives in the |
| 14895 | DWO file. */ |
| 14896 | if (cu->dwo_unit && cu->per_cu->is_debug_types) |
| 14897 | section = &cu->dwo_unit->dwo_file->sections.line; |
| 14898 | else if (cu->per_cu->is_dwz) |
| 14899 | { |
| 14900 | struct dwz_file *dwz = dwarf2_get_dwz_file (); |
| 14901 | |
| 14902 | section = &dwz->line; |
| 14903 | } |
| 14904 | else |
| 14905 | section = &dwarf2_per_objfile->line; |
| 14906 | |
| 14907 | return section; |
| 14908 | } |
| 14909 | |
| 14910 | /* Read the statement program header starting at OFFSET in |
| 14911 | .debug_line, or .debug_line.dwo. Return a pointer |
| 14912 | to a struct line_header, allocated using xmalloc. |
| 14913 | |
| 14914 | NOTE: the strings in the include directory and file name tables of |
| 14915 | the returned object point into the dwarf line section buffer, |
| 14916 | and must not be freed. */ |
| 14917 | |
| 14918 | static struct line_header * |
| 14919 | dwarf_decode_line_header (unsigned int offset, struct dwarf2_cu *cu) |
| 14920 | { |
| 14921 | struct cleanup *back_to; |
| 14922 | struct line_header *lh; |
| 14923 | gdb_byte *line_ptr; |
| 14924 | unsigned int bytes_read, offset_size; |
| 14925 | int i; |
| 14926 | char *cur_dir, *cur_file; |
| 14927 | struct dwarf2_section_info *section; |
| 14928 | bfd *abfd; |
| 14929 | |
| 14930 | section = get_debug_line_section (cu); |
| 14931 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
| 14932 | if (section->buffer == NULL) |
| 14933 | { |
| 14934 | if (cu->dwo_unit && cu->per_cu->is_debug_types) |
| 14935 | complaint (&symfile_complaints, _("missing .debug_line.dwo section")); |
| 14936 | else |
| 14937 | complaint (&symfile_complaints, _("missing .debug_line section")); |
| 14938 | return 0; |
| 14939 | } |
| 14940 | |
| 14941 | /* We can't do this until we know the section is non-empty. |
| 14942 | Only then do we know we have such a section. */ |
| 14943 | abfd = section->asection->owner; |
| 14944 | |
| 14945 | /* Make sure that at least there's room for the total_length field. |
| 14946 | That could be 12 bytes long, but we're just going to fudge that. */ |
| 14947 | if (offset + 4 >= section->size) |
| 14948 | { |
| 14949 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 14950 | return 0; |
| 14951 | } |
| 14952 | |
| 14953 | lh = xmalloc (sizeof (*lh)); |
| 14954 | memset (lh, 0, sizeof (*lh)); |
| 14955 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, |
| 14956 | (void *) lh); |
| 14957 | |
| 14958 | line_ptr = section->buffer + offset; |
| 14959 | |
| 14960 | /* Read in the header. */ |
| 14961 | lh->total_length = |
| 14962 | read_checked_initial_length_and_offset (abfd, line_ptr, &cu->header, |
| 14963 | &bytes_read, &offset_size); |
| 14964 | line_ptr += bytes_read; |
| 14965 | if (line_ptr + lh->total_length > (section->buffer + section->size)) |
| 14966 | { |
| 14967 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 14968 | return 0; |
| 14969 | } |
| 14970 | lh->statement_program_end = line_ptr + lh->total_length; |
| 14971 | lh->version = read_2_bytes (abfd, line_ptr); |
| 14972 | line_ptr += 2; |
| 14973 | lh->header_length = read_offset_1 (abfd, line_ptr, offset_size); |
| 14974 | line_ptr += offset_size; |
| 14975 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
| 14976 | line_ptr += 1; |
| 14977 | if (lh->version >= 4) |
| 14978 | { |
| 14979 | lh->maximum_ops_per_instruction = read_1_byte (abfd, line_ptr); |
| 14980 | line_ptr += 1; |
| 14981 | } |
| 14982 | else |
| 14983 | lh->maximum_ops_per_instruction = 1; |
| 14984 | |
| 14985 | if (lh->maximum_ops_per_instruction == 0) |
| 14986 | { |
| 14987 | lh->maximum_ops_per_instruction = 1; |
| 14988 | complaint (&symfile_complaints, |
| 14989 | _("invalid maximum_ops_per_instruction " |
| 14990 | "in `.debug_line' section")); |
| 14991 | } |
| 14992 | |
| 14993 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
| 14994 | line_ptr += 1; |
| 14995 | lh->line_base = read_1_signed_byte (abfd, line_ptr); |
| 14996 | line_ptr += 1; |
| 14997 | lh->line_range = read_1_byte (abfd, line_ptr); |
| 14998 | line_ptr += 1; |
| 14999 | lh->opcode_base = read_1_byte (abfd, line_ptr); |
| 15000 | line_ptr += 1; |
| 15001 | lh->standard_opcode_lengths |
| 15002 | = xmalloc (lh->opcode_base * sizeof (lh->standard_opcode_lengths[0])); |
| 15003 | |
| 15004 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ |
| 15005 | for (i = 1; i < lh->opcode_base; ++i) |
| 15006 | { |
| 15007 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); |
| 15008 | line_ptr += 1; |
| 15009 | } |
| 15010 | |
| 15011 | /* Read directory table. */ |
| 15012 | while ((cur_dir = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 15013 | { |
| 15014 | line_ptr += bytes_read; |
| 15015 | add_include_dir (lh, cur_dir); |
| 15016 | } |
| 15017 | line_ptr += bytes_read; |
| 15018 | |
| 15019 | /* Read file name table. */ |
| 15020 | while ((cur_file = read_direct_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 15021 | { |
| 15022 | unsigned int dir_index, mod_time, length; |
| 15023 | |
| 15024 | line_ptr += bytes_read; |
| 15025 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15026 | line_ptr += bytes_read; |
| 15027 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15028 | line_ptr += bytes_read; |
| 15029 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15030 | line_ptr += bytes_read; |
| 15031 | |
| 15032 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 15033 | } |
| 15034 | line_ptr += bytes_read; |
| 15035 | lh->statement_program_start = line_ptr; |
| 15036 | |
| 15037 | if (line_ptr > (section->buffer + section->size)) |
| 15038 | complaint (&symfile_complaints, |
| 15039 | _("line number info header doesn't " |
| 15040 | "fit in `.debug_line' section")); |
| 15041 | |
| 15042 | discard_cleanups (back_to); |
| 15043 | return lh; |
| 15044 | } |
| 15045 | |
| 15046 | /* Subroutine of dwarf_decode_lines to simplify it. |
| 15047 | Return the file name of the psymtab for included file FILE_INDEX |
| 15048 | in line header LH of PST. |
| 15049 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. |
| 15050 | If space for the result is malloc'd, it will be freed by a cleanup. |
| 15051 | Returns NULL if FILE_INDEX should be ignored, i.e., it is pst->filename. */ |
| 15052 | |
| 15053 | static char * |
| 15054 | psymtab_include_file_name (const struct line_header *lh, int file_index, |
| 15055 | const struct partial_symtab *pst, |
| 15056 | const char *comp_dir) |
| 15057 | { |
| 15058 | const struct file_entry fe = lh->file_names [file_index]; |
| 15059 | char *include_name = fe.name; |
| 15060 | char *include_name_to_compare = include_name; |
| 15061 | char *dir_name = NULL; |
| 15062 | const char *pst_filename; |
| 15063 | char *copied_name = NULL; |
| 15064 | int file_is_pst; |
| 15065 | |
| 15066 | if (fe.dir_index) |
| 15067 | dir_name = lh->include_dirs[fe.dir_index - 1]; |
| 15068 | |
| 15069 | if (!IS_ABSOLUTE_PATH (include_name) |
| 15070 | && (dir_name != NULL || comp_dir != NULL)) |
| 15071 | { |
| 15072 | /* Avoid creating a duplicate psymtab for PST. |
| 15073 | We do this by comparing INCLUDE_NAME and PST_FILENAME. |
| 15074 | Before we do the comparison, however, we need to account |
| 15075 | for DIR_NAME and COMP_DIR. |
| 15076 | First prepend dir_name (if non-NULL). If we still don't |
| 15077 | have an absolute path prepend comp_dir (if non-NULL). |
| 15078 | However, the directory we record in the include-file's |
| 15079 | psymtab does not contain COMP_DIR (to match the |
| 15080 | corresponding symtab(s)). |
| 15081 | |
| 15082 | Example: |
| 15083 | |
| 15084 | bash$ cd /tmp |
| 15085 | bash$ gcc -g ./hello.c |
| 15086 | include_name = "hello.c" |
| 15087 | dir_name = "." |
| 15088 | DW_AT_comp_dir = comp_dir = "/tmp" |
| 15089 | DW_AT_name = "./hello.c" */ |
| 15090 | |
| 15091 | if (dir_name != NULL) |
| 15092 | { |
| 15093 | include_name = concat (dir_name, SLASH_STRING, |
| 15094 | include_name, (char *)NULL); |
| 15095 | include_name_to_compare = include_name; |
| 15096 | make_cleanup (xfree, include_name); |
| 15097 | } |
| 15098 | if (!IS_ABSOLUTE_PATH (include_name) && comp_dir != NULL) |
| 15099 | { |
| 15100 | include_name_to_compare = concat (comp_dir, SLASH_STRING, |
| 15101 | include_name, (char *)NULL); |
| 15102 | } |
| 15103 | } |
| 15104 | |
| 15105 | pst_filename = pst->filename; |
| 15106 | if (!IS_ABSOLUTE_PATH (pst_filename) && pst->dirname != NULL) |
| 15107 | { |
| 15108 | copied_name = concat (pst->dirname, SLASH_STRING, |
| 15109 | pst_filename, (char *)NULL); |
| 15110 | pst_filename = copied_name; |
| 15111 | } |
| 15112 | |
| 15113 | file_is_pst = FILENAME_CMP (include_name_to_compare, pst_filename) == 0; |
| 15114 | |
| 15115 | if (include_name_to_compare != include_name) |
| 15116 | xfree (include_name_to_compare); |
| 15117 | if (copied_name != NULL) |
| 15118 | xfree (copied_name); |
| 15119 | |
| 15120 | if (file_is_pst) |
| 15121 | return NULL; |
| 15122 | return include_name; |
| 15123 | } |
| 15124 | |
| 15125 | /* Ignore this record_line request. */ |
| 15126 | |
| 15127 | static void |
| 15128 | noop_record_line (struct subfile *subfile, int line, CORE_ADDR pc) |
| 15129 | { |
| 15130 | return; |
| 15131 | } |
| 15132 | |
| 15133 | /* Subroutine of dwarf_decode_lines to simplify it. |
| 15134 | Process the line number information in LH. */ |
| 15135 | |
| 15136 | static void |
| 15137 | dwarf_decode_lines_1 (struct line_header *lh, const char *comp_dir, |
| 15138 | struct dwarf2_cu *cu, struct partial_symtab *pst) |
| 15139 | { |
| 15140 | gdb_byte *line_ptr, *extended_end; |
| 15141 | gdb_byte *line_end; |
| 15142 | unsigned int bytes_read, extended_len; |
| 15143 | unsigned char op_code, extended_op, adj_opcode; |
| 15144 | CORE_ADDR baseaddr; |
| 15145 | struct objfile *objfile = cu->objfile; |
| 15146 | bfd *abfd = objfile->obfd; |
| 15147 | struct gdbarch *gdbarch = get_objfile_arch (objfile); |
| 15148 | const int decode_for_pst_p = (pst != NULL); |
| 15149 | struct subfile *last_subfile = NULL; |
| 15150 | void (*p_record_line) (struct subfile *subfile, int line, CORE_ADDR pc) |
| 15151 | = record_line; |
| 15152 | |
| 15153 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 15154 | |
| 15155 | line_ptr = lh->statement_program_start; |
| 15156 | line_end = lh->statement_program_end; |
| 15157 | |
| 15158 | /* Read the statement sequences until there's nothing left. */ |
| 15159 | while (line_ptr < line_end) |
| 15160 | { |
| 15161 | /* state machine registers */ |
| 15162 | CORE_ADDR address = 0; |
| 15163 | unsigned int file = 1; |
| 15164 | unsigned int line = 1; |
| 15165 | unsigned int column = 0; |
| 15166 | int is_stmt = lh->default_is_stmt; |
| 15167 | int basic_block = 0; |
| 15168 | int end_sequence = 0; |
| 15169 | CORE_ADDR addr; |
| 15170 | unsigned char op_index = 0; |
| 15171 | |
| 15172 | if (!decode_for_pst_p && lh->num_file_names >= file) |
| 15173 | { |
| 15174 | /* Start a subfile for the current file of the state machine. */ |
| 15175 | /* lh->include_dirs and lh->file_names are 0-based, but the |
| 15176 | directory and file name numbers in the statement program |
| 15177 | are 1-based. */ |
| 15178 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 15179 | char *dir = NULL; |
| 15180 | |
| 15181 | if (fe->dir_index) |
| 15182 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 15183 | |
| 15184 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 15185 | } |
| 15186 | |
| 15187 | /* Decode the table. */ |
| 15188 | while (!end_sequence) |
| 15189 | { |
| 15190 | op_code = read_1_byte (abfd, line_ptr); |
| 15191 | line_ptr += 1; |
| 15192 | if (line_ptr > line_end) |
| 15193 | { |
| 15194 | dwarf2_debug_line_missing_end_sequence_complaint (); |
| 15195 | break; |
| 15196 | } |
| 15197 | |
| 15198 | if (op_code >= lh->opcode_base) |
| 15199 | { |
| 15200 | /* Special operand. */ |
| 15201 | adj_opcode = op_code - lh->opcode_base; |
| 15202 | address += (((op_index + (adj_opcode / lh->line_range)) |
| 15203 | / lh->maximum_ops_per_instruction) |
| 15204 | * lh->minimum_instruction_length); |
| 15205 | op_index = ((op_index + (adj_opcode / lh->line_range)) |
| 15206 | % lh->maximum_ops_per_instruction); |
| 15207 | line += lh->line_base + (adj_opcode % lh->line_range); |
| 15208 | if (lh->num_file_names < file || file == 0) |
| 15209 | dwarf2_debug_line_missing_file_complaint (); |
| 15210 | /* For now we ignore lines not starting on an |
| 15211 | instruction boundary. */ |
| 15212 | else if (op_index == 0) |
| 15213 | { |
| 15214 | lh->file_names[file - 1].included_p = 1; |
| 15215 | if (!decode_for_pst_p && is_stmt) |
| 15216 | { |
| 15217 | if (last_subfile != current_subfile) |
| 15218 | { |
| 15219 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 15220 | if (last_subfile) |
| 15221 | (*p_record_line) (last_subfile, 0, addr); |
| 15222 | last_subfile = current_subfile; |
| 15223 | } |
| 15224 | /* Append row to matrix using current values. */ |
| 15225 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 15226 | (*p_record_line) (current_subfile, line, addr); |
| 15227 | } |
| 15228 | } |
| 15229 | basic_block = 0; |
| 15230 | } |
| 15231 | else switch (op_code) |
| 15232 | { |
| 15233 | case DW_LNS_extended_op: |
| 15234 | extended_len = read_unsigned_leb128 (abfd, line_ptr, |
| 15235 | &bytes_read); |
| 15236 | line_ptr += bytes_read; |
| 15237 | extended_end = line_ptr + extended_len; |
| 15238 | extended_op = read_1_byte (abfd, line_ptr); |
| 15239 | line_ptr += 1; |
| 15240 | switch (extended_op) |
| 15241 | { |
| 15242 | case DW_LNE_end_sequence: |
| 15243 | p_record_line = record_line; |
| 15244 | end_sequence = 1; |
| 15245 | break; |
| 15246 | case DW_LNE_set_address: |
| 15247 | address = read_address (abfd, line_ptr, cu, &bytes_read); |
| 15248 | |
| 15249 | if (address == 0 && !dwarf2_per_objfile->has_section_at_zero) |
| 15250 | { |
| 15251 | /* This line table is for a function which has been |
| 15252 | GCd by the linker. Ignore it. PR gdb/12528 */ |
| 15253 | |
| 15254 | long line_offset |
| 15255 | = line_ptr - get_debug_line_section (cu)->buffer; |
| 15256 | |
| 15257 | complaint (&symfile_complaints, |
| 15258 | _(".debug_line address at offset 0x%lx is 0 " |
| 15259 | "[in module %s]"), |
| 15260 | line_offset, objfile->name); |
| 15261 | p_record_line = noop_record_line; |
| 15262 | } |
| 15263 | |
| 15264 | op_index = 0; |
| 15265 | line_ptr += bytes_read; |
| 15266 | address += baseaddr; |
| 15267 | break; |
| 15268 | case DW_LNE_define_file: |
| 15269 | { |
| 15270 | char *cur_file; |
| 15271 | unsigned int dir_index, mod_time, length; |
| 15272 | |
| 15273 | cur_file = read_direct_string (abfd, line_ptr, |
| 15274 | &bytes_read); |
| 15275 | line_ptr += bytes_read; |
| 15276 | dir_index = |
| 15277 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15278 | line_ptr += bytes_read; |
| 15279 | mod_time = |
| 15280 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15281 | line_ptr += bytes_read; |
| 15282 | length = |
| 15283 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15284 | line_ptr += bytes_read; |
| 15285 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 15286 | } |
| 15287 | break; |
| 15288 | case DW_LNE_set_discriminator: |
| 15289 | /* The discriminator is not interesting to the debugger; |
| 15290 | just ignore it. */ |
| 15291 | line_ptr = extended_end; |
| 15292 | break; |
| 15293 | default: |
| 15294 | complaint (&symfile_complaints, |
| 15295 | _("mangled .debug_line section")); |
| 15296 | return; |
| 15297 | } |
| 15298 | /* Make sure that we parsed the extended op correctly. If e.g. |
| 15299 | we expected a different address size than the producer used, |
| 15300 | we may have read the wrong number of bytes. */ |
| 15301 | if (line_ptr != extended_end) |
| 15302 | { |
| 15303 | complaint (&symfile_complaints, |
| 15304 | _("mangled .debug_line section")); |
| 15305 | return; |
| 15306 | } |
| 15307 | break; |
| 15308 | case DW_LNS_copy: |
| 15309 | if (lh->num_file_names < file || file == 0) |
| 15310 | dwarf2_debug_line_missing_file_complaint (); |
| 15311 | else |
| 15312 | { |
| 15313 | lh->file_names[file - 1].included_p = 1; |
| 15314 | if (!decode_for_pst_p && is_stmt) |
| 15315 | { |
| 15316 | if (last_subfile != current_subfile) |
| 15317 | { |
| 15318 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 15319 | if (last_subfile) |
| 15320 | (*p_record_line) (last_subfile, 0, addr); |
| 15321 | last_subfile = current_subfile; |
| 15322 | } |
| 15323 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 15324 | (*p_record_line) (current_subfile, line, addr); |
| 15325 | } |
| 15326 | } |
| 15327 | basic_block = 0; |
| 15328 | break; |
| 15329 | case DW_LNS_advance_pc: |
| 15330 | { |
| 15331 | CORE_ADDR adjust |
| 15332 | = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15333 | |
| 15334 | address += (((op_index + adjust) |
| 15335 | / lh->maximum_ops_per_instruction) |
| 15336 | * lh->minimum_instruction_length); |
| 15337 | op_index = ((op_index + adjust) |
| 15338 | % lh->maximum_ops_per_instruction); |
| 15339 | line_ptr += bytes_read; |
| 15340 | } |
| 15341 | break; |
| 15342 | case DW_LNS_advance_line: |
| 15343 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); |
| 15344 | line_ptr += bytes_read; |
| 15345 | break; |
| 15346 | case DW_LNS_set_file: |
| 15347 | { |
| 15348 | /* The arrays lh->include_dirs and lh->file_names are |
| 15349 | 0-based, but the directory and file name numbers in |
| 15350 | the statement program are 1-based. */ |
| 15351 | struct file_entry *fe; |
| 15352 | char *dir = NULL; |
| 15353 | |
| 15354 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15355 | line_ptr += bytes_read; |
| 15356 | if (lh->num_file_names < file || file == 0) |
| 15357 | dwarf2_debug_line_missing_file_complaint (); |
| 15358 | else |
| 15359 | { |
| 15360 | fe = &lh->file_names[file - 1]; |
| 15361 | if (fe->dir_index) |
| 15362 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 15363 | if (!decode_for_pst_p) |
| 15364 | { |
| 15365 | last_subfile = current_subfile; |
| 15366 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 15367 | } |
| 15368 | } |
| 15369 | } |
| 15370 | break; |
| 15371 | case DW_LNS_set_column: |
| 15372 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15373 | line_ptr += bytes_read; |
| 15374 | break; |
| 15375 | case DW_LNS_negate_stmt: |
| 15376 | is_stmt = (!is_stmt); |
| 15377 | break; |
| 15378 | case DW_LNS_set_basic_block: |
| 15379 | basic_block = 1; |
| 15380 | break; |
| 15381 | /* Add to the address register of the state machine the |
| 15382 | address increment value corresponding to special opcode |
| 15383 | 255. I.e., this value is scaled by the minimum |
| 15384 | instruction length since special opcode 255 would have |
| 15385 | scaled the increment. */ |
| 15386 | case DW_LNS_const_add_pc: |
| 15387 | { |
| 15388 | CORE_ADDR adjust = (255 - lh->opcode_base) / lh->line_range; |
| 15389 | |
| 15390 | address += (((op_index + adjust) |
| 15391 | / lh->maximum_ops_per_instruction) |
| 15392 | * lh->minimum_instruction_length); |
| 15393 | op_index = ((op_index + adjust) |
| 15394 | % lh->maximum_ops_per_instruction); |
| 15395 | } |
| 15396 | break; |
| 15397 | case DW_LNS_fixed_advance_pc: |
| 15398 | address += read_2_bytes (abfd, line_ptr); |
| 15399 | op_index = 0; |
| 15400 | line_ptr += 2; |
| 15401 | break; |
| 15402 | default: |
| 15403 | { |
| 15404 | /* Unknown standard opcode, ignore it. */ |
| 15405 | int i; |
| 15406 | |
| 15407 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
| 15408 | { |
| 15409 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 15410 | line_ptr += bytes_read; |
| 15411 | } |
| 15412 | } |
| 15413 | } |
| 15414 | } |
| 15415 | if (lh->num_file_names < file || file == 0) |
| 15416 | dwarf2_debug_line_missing_file_complaint (); |
| 15417 | else |
| 15418 | { |
| 15419 | lh->file_names[file - 1].included_p = 1; |
| 15420 | if (!decode_for_pst_p) |
| 15421 | { |
| 15422 | addr = gdbarch_addr_bits_remove (gdbarch, address); |
| 15423 | (*p_record_line) (current_subfile, 0, addr); |
| 15424 | } |
| 15425 | } |
| 15426 | } |
| 15427 | } |
| 15428 | |
| 15429 | /* Decode the Line Number Program (LNP) for the given line_header |
| 15430 | structure and CU. The actual information extracted and the type |
| 15431 | of structures created from the LNP depends on the value of PST. |
| 15432 | |
| 15433 | 1. If PST is NULL, then this procedure uses the data from the program |
| 15434 | to create all necessary symbol tables, and their linetables. |
| 15435 | |
| 15436 | 2. If PST is not NULL, this procedure reads the program to determine |
| 15437 | the list of files included by the unit represented by PST, and |
| 15438 | builds all the associated partial symbol tables. |
| 15439 | |
| 15440 | COMP_DIR is the compilation directory (DW_AT_comp_dir) or NULL if unknown. |
| 15441 | It is used for relative paths in the line table. |
| 15442 | NOTE: When processing partial symtabs (pst != NULL), |
| 15443 | comp_dir == pst->dirname. |
| 15444 | |
| 15445 | NOTE: It is important that psymtabs have the same file name (via strcmp) |
| 15446 | as the corresponding symtab. Since COMP_DIR is not used in the name of the |
| 15447 | symtab we don't use it in the name of the psymtabs we create. |
| 15448 | E.g. expand_line_sal requires this when finding psymtabs to expand. |
| 15449 | A good testcase for this is mb-inline.exp. */ |
| 15450 | |
| 15451 | static void |
| 15452 | dwarf_decode_lines (struct line_header *lh, const char *comp_dir, |
| 15453 | struct dwarf2_cu *cu, struct partial_symtab *pst, |
| 15454 | int want_line_info) |
| 15455 | { |
| 15456 | struct objfile *objfile = cu->objfile; |
| 15457 | const int decode_for_pst_p = (pst != NULL); |
| 15458 | struct subfile *first_subfile = current_subfile; |
| 15459 | |
| 15460 | if (want_line_info) |
| 15461 | dwarf_decode_lines_1 (lh, comp_dir, cu, pst); |
| 15462 | |
| 15463 | if (decode_for_pst_p) |
| 15464 | { |
| 15465 | int file_index; |
| 15466 | |
| 15467 | /* Now that we're done scanning the Line Header Program, we can |
| 15468 | create the psymtab of each included file. */ |
| 15469 | for (file_index = 0; file_index < lh->num_file_names; file_index++) |
| 15470 | if (lh->file_names[file_index].included_p == 1) |
| 15471 | { |
| 15472 | char *include_name = |
| 15473 | psymtab_include_file_name (lh, file_index, pst, comp_dir); |
| 15474 | if (include_name != NULL) |
| 15475 | dwarf2_create_include_psymtab (include_name, pst, objfile); |
| 15476 | } |
| 15477 | } |
| 15478 | else |
| 15479 | { |
| 15480 | /* Make sure a symtab is created for every file, even files |
| 15481 | which contain only variables (i.e. no code with associated |
| 15482 | line numbers). */ |
| 15483 | int i; |
| 15484 | |
| 15485 | for (i = 0; i < lh->num_file_names; i++) |
| 15486 | { |
| 15487 | char *dir = NULL; |
| 15488 | struct file_entry *fe; |
| 15489 | |
| 15490 | fe = &lh->file_names[i]; |
| 15491 | if (fe->dir_index) |
| 15492 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 15493 | dwarf2_start_subfile (fe->name, dir, comp_dir); |
| 15494 | |
| 15495 | /* Skip the main file; we don't need it, and it must be |
| 15496 | allocated last, so that it will show up before the |
| 15497 | non-primary symtabs in the objfile's symtab list. */ |
| 15498 | if (current_subfile == first_subfile) |
| 15499 | continue; |
| 15500 | |
| 15501 | if (current_subfile->symtab == NULL) |
| 15502 | current_subfile->symtab = allocate_symtab (current_subfile->name, |
| 15503 | objfile); |
| 15504 | fe->symtab = current_subfile->symtab; |
| 15505 | } |
| 15506 | } |
| 15507 | } |
| 15508 | |
| 15509 | /* Start a subfile for DWARF. FILENAME is the name of the file and |
| 15510 | DIRNAME the name of the source directory which contains FILENAME |
| 15511 | or NULL if not known. COMP_DIR is the compilation directory for the |
| 15512 | linetable's compilation unit or NULL if not known. |
| 15513 | This routine tries to keep line numbers from identical absolute and |
| 15514 | relative file names in a common subfile. |
| 15515 | |
| 15516 | Using the `list' example from the GDB testsuite, which resides in |
| 15517 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename |
| 15518 | of /srcdir/list0.c yields the following debugging information for list0.c: |
| 15519 | |
| 15520 | DW_AT_name: /srcdir/list0.c |
| 15521 | DW_AT_comp_dir: /compdir |
| 15522 | files.files[0].name: list0.h |
| 15523 | files.files[0].dir: /srcdir |
| 15524 | files.files[1].name: list0.c |
| 15525 | files.files[1].dir: /srcdir |
| 15526 | |
| 15527 | The line number information for list0.c has to end up in a single |
| 15528 | subfile, so that `break /srcdir/list0.c:1' works as expected. |
| 15529 | start_subfile will ensure that this happens provided that we pass the |
| 15530 | concatenation of files.files[1].dir and files.files[1].name as the |
| 15531 | subfile's name. */ |
| 15532 | |
| 15533 | static void |
| 15534 | dwarf2_start_subfile (char *filename, const char *dirname, |
| 15535 | const char *comp_dir) |
| 15536 | { |
| 15537 | char *fullname; |
| 15538 | |
| 15539 | /* While reading the DIEs, we call start_symtab(DW_AT_name, DW_AT_comp_dir). |
| 15540 | `start_symtab' will always pass the contents of DW_AT_comp_dir as |
| 15541 | second argument to start_subfile. To be consistent, we do the |
| 15542 | same here. In order not to lose the line information directory, |
| 15543 | we concatenate it to the filename when it makes sense. |
| 15544 | Note that the Dwarf3 standard says (speaking of filenames in line |
| 15545 | information): ``The directory index is ignored for file names |
| 15546 | that represent full path names''. Thus ignoring dirname in the |
| 15547 | `else' branch below isn't an issue. */ |
| 15548 | |
| 15549 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
| 15550 | fullname = concat (dirname, SLASH_STRING, filename, (char *)NULL); |
| 15551 | else |
| 15552 | fullname = filename; |
| 15553 | |
| 15554 | start_subfile (fullname, comp_dir); |
| 15555 | |
| 15556 | if (fullname != filename) |
| 15557 | xfree (fullname); |
| 15558 | } |
| 15559 | |
| 15560 | /* Start a symtab for DWARF. |
| 15561 | NAME, COMP_DIR, LOW_PC are passed to start_symtab. */ |
| 15562 | |
| 15563 | static void |
| 15564 | dwarf2_start_symtab (struct dwarf2_cu *cu, |
| 15565 | char *name, char *comp_dir, CORE_ADDR low_pc) |
| 15566 | { |
| 15567 | start_symtab (name, comp_dir, low_pc); |
| 15568 | record_debugformat ("DWARF 2"); |
| 15569 | record_producer (cu->producer); |
| 15570 | |
| 15571 | /* We assume that we're processing GCC output. */ |
| 15572 | processing_gcc_compilation = 2; |
| 15573 | |
| 15574 | processing_has_namespace_info = 0; |
| 15575 | } |
| 15576 | |
| 15577 | static void |
| 15578 | var_decode_location (struct attribute *attr, struct symbol *sym, |
| 15579 | struct dwarf2_cu *cu) |
| 15580 | { |
| 15581 | struct objfile *objfile = cu->objfile; |
| 15582 | struct comp_unit_head *cu_header = &cu->header; |
| 15583 | |
| 15584 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
| 15585 | code here to turn a symbol with DW_AT_external and a |
| 15586 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was |
| 15587 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux |
| 15588 | with some versions of binutils) where shared libraries could have |
| 15589 | relocations against symbols in their debug information - the |
| 15590 | minimal symbol would have the right address, but the debug info |
| 15591 | would not. It's no longer necessary, because we will explicitly |
| 15592 | apply relocations when we read in the debug information now. */ |
| 15593 | |
| 15594 | /* A DW_AT_location attribute with no contents indicates that a |
| 15595 | variable has been optimized away. */ |
| 15596 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) |
| 15597 | { |
| 15598 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 15599 | return; |
| 15600 | } |
| 15601 | |
| 15602 | /* Handle one degenerate form of location expression specially, to |
| 15603 | preserve GDB's previous behavior when section offsets are |
| 15604 | specified. If this is just a DW_OP_addr or DW_OP_GNU_addr_index |
| 15605 | then mark this symbol as LOC_STATIC. */ |
| 15606 | |
| 15607 | if (attr_form_is_block (attr) |
| 15608 | && ((DW_BLOCK (attr)->data[0] == DW_OP_addr |
| 15609 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size) |
| 15610 | || (DW_BLOCK (attr)->data[0] == DW_OP_GNU_addr_index |
| 15611 | && (DW_BLOCK (attr)->size |
| 15612 | == 1 + leb128_size (&DW_BLOCK (attr)->data[1]))))) |
| 15613 | { |
| 15614 | unsigned int dummy; |
| 15615 | |
| 15616 | if (DW_BLOCK (attr)->data[0] == DW_OP_addr) |
| 15617 | SYMBOL_VALUE_ADDRESS (sym) = |
| 15618 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu, &dummy); |
| 15619 | else |
| 15620 | SYMBOL_VALUE_ADDRESS (sym) = |
| 15621 | read_addr_index_from_leb128 (cu, DW_BLOCK (attr)->data + 1, &dummy); |
| 15622 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 15623 | fixup_symbol_section (sym, objfile); |
| 15624 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, |
| 15625 | SYMBOL_SECTION (sym)); |
| 15626 | return; |
| 15627 | } |
| 15628 | |
| 15629 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static |
| 15630 | expression evaluator, and use LOC_COMPUTED only when necessary |
| 15631 | (i.e. when the value of a register or memory location is |
| 15632 | referenced, or a thread-local block, etc.). Then again, it might |
| 15633 | not be worthwhile. I'm assuming that it isn't unless performance |
| 15634 | or memory numbers show me otherwise. */ |
| 15635 | |
| 15636 | dwarf2_symbol_mark_computed (attr, sym, cu); |
| 15637 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 15638 | |
| 15639 | if (SYMBOL_COMPUTED_OPS (sym) == &dwarf2_loclist_funcs) |
| 15640 | cu->has_loclist = 1; |
| 15641 | } |
| 15642 | |
| 15643 | /* Given a pointer to a DWARF information entry, figure out if we need |
| 15644 | to make a symbol table entry for it, and if so, create a new entry |
| 15645 | and return a pointer to it. |
| 15646 | If TYPE is NULL, determine symbol type from the die, otherwise |
| 15647 | used the passed type. |
| 15648 | If SPACE is not NULL, use it to hold the new symbol. If it is |
| 15649 | NULL, allocate a new symbol on the objfile's obstack. */ |
| 15650 | |
| 15651 | static struct symbol * |
| 15652 | new_symbol_full (struct die_info *die, struct type *type, struct dwarf2_cu *cu, |
| 15653 | struct symbol *space) |
| 15654 | { |
| 15655 | struct objfile *objfile = cu->objfile; |
| 15656 | struct symbol *sym = NULL; |
| 15657 | char *name; |
| 15658 | struct attribute *attr = NULL; |
| 15659 | struct attribute *attr2 = NULL; |
| 15660 | CORE_ADDR baseaddr; |
| 15661 | struct pending **list_to_add = NULL; |
| 15662 | |
| 15663 | int inlined_func = (die->tag == DW_TAG_inlined_subroutine); |
| 15664 | |
| 15665 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 15666 | |
| 15667 | name = dwarf2_name (die, cu); |
| 15668 | if (name) |
| 15669 | { |
| 15670 | const char *linkagename; |
| 15671 | int suppress_add = 0; |
| 15672 | |
| 15673 | if (space) |
| 15674 | sym = space; |
| 15675 | else |
| 15676 | sym = OBSTACK_ZALLOC (&objfile->objfile_obstack, struct symbol); |
| 15677 | OBJSTAT (objfile, n_syms++); |
| 15678 | |
| 15679 | /* Cache this symbol's name and the name's demangled form (if any). */ |
| 15680 | SYMBOL_SET_LANGUAGE (sym, cu->language); |
| 15681 | linkagename = dwarf2_physname (name, die, cu); |
| 15682 | SYMBOL_SET_NAMES (sym, linkagename, strlen (linkagename), 0, objfile); |
| 15683 | |
| 15684 | /* Fortran does not have mangling standard and the mangling does differ |
| 15685 | between gfortran, iFort etc. */ |
| 15686 | if (cu->language == language_fortran |
| 15687 | && symbol_get_demangled_name (&(sym->ginfo)) == NULL) |
| 15688 | symbol_set_demangled_name (&(sym->ginfo), |
| 15689 | (char *) dwarf2_full_name (name, die, cu), |
| 15690 | NULL); |
| 15691 | |
| 15692 | /* Default assumptions. |
| 15693 | Use the passed type or decode it from the die. */ |
| 15694 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 15695 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 15696 | if (type != NULL) |
| 15697 | SYMBOL_TYPE (sym) = type; |
| 15698 | else |
| 15699 | SYMBOL_TYPE (sym) = die_type (die, cu); |
| 15700 | attr = dwarf2_attr (die, |
| 15701 | inlined_func ? DW_AT_call_line : DW_AT_decl_line, |
| 15702 | cu); |
| 15703 | if (attr) |
| 15704 | { |
| 15705 | SYMBOL_LINE (sym) = DW_UNSND (attr); |
| 15706 | } |
| 15707 | |
| 15708 | attr = dwarf2_attr (die, |
| 15709 | inlined_func ? DW_AT_call_file : DW_AT_decl_file, |
| 15710 | cu); |
| 15711 | if (attr) |
| 15712 | { |
| 15713 | int file_index = DW_UNSND (attr); |
| 15714 | |
| 15715 | if (cu->line_header == NULL |
| 15716 | || file_index > cu->line_header->num_file_names) |
| 15717 | complaint (&symfile_complaints, |
| 15718 | _("file index out of range")); |
| 15719 | else if (file_index > 0) |
| 15720 | { |
| 15721 | struct file_entry *fe; |
| 15722 | |
| 15723 | fe = &cu->line_header->file_names[file_index - 1]; |
| 15724 | SYMBOL_SYMTAB (sym) = fe->symtab; |
| 15725 | } |
| 15726 | } |
| 15727 | |
| 15728 | switch (die->tag) |
| 15729 | { |
| 15730 | case DW_TAG_label: |
| 15731 | attr = dwarf2_attr (die, DW_AT_low_pc, cu); |
| 15732 | if (attr) |
| 15733 | { |
| 15734 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; |
| 15735 | } |
| 15736 | SYMBOL_TYPE (sym) = objfile_type (objfile)->builtin_core_addr; |
| 15737 | SYMBOL_DOMAIN (sym) = LABEL_DOMAIN; |
| 15738 | SYMBOL_CLASS (sym) = LOC_LABEL; |
| 15739 | add_symbol_to_list (sym, cu->list_in_scope); |
| 15740 | break; |
| 15741 | case DW_TAG_subprogram: |
| 15742 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 15743 | finish_block. */ |
| 15744 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 15745 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 15746 | if ((attr2 && (DW_UNSND (attr2) != 0)) |
| 15747 | || cu->language == language_ada) |
| 15748 | { |
| 15749 | /* Subprograms marked external are stored as a global symbol. |
| 15750 | Ada subprograms, whether marked external or not, are always |
| 15751 | stored as a global symbol, because we want to be able to |
| 15752 | access them globally. For instance, we want to be able |
| 15753 | to break on a nested subprogram without having to |
| 15754 | specify the context. */ |
| 15755 | list_to_add = &global_symbols; |
| 15756 | } |
| 15757 | else |
| 15758 | { |
| 15759 | list_to_add = cu->list_in_scope; |
| 15760 | } |
| 15761 | break; |
| 15762 | case DW_TAG_inlined_subroutine: |
| 15763 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 15764 | finish_block. */ |
| 15765 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 15766 | SYMBOL_INLINED (sym) = 1; |
| 15767 | list_to_add = cu->list_in_scope; |
| 15768 | break; |
| 15769 | case DW_TAG_template_value_param: |
| 15770 | suppress_add = 1; |
| 15771 | /* Fall through. */ |
| 15772 | case DW_TAG_constant: |
| 15773 | case DW_TAG_variable: |
| 15774 | case DW_TAG_member: |
| 15775 | /* Compilation with minimal debug info may result in |
| 15776 | variables with missing type entries. Change the |
| 15777 | misleading `void' type to something sensible. */ |
| 15778 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
| 15779 | SYMBOL_TYPE (sym) |
| 15780 | = objfile_type (objfile)->nodebug_data_symbol; |
| 15781 | |
| 15782 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 15783 | /* In the case of DW_TAG_member, we should only be called for |
| 15784 | static const members. */ |
| 15785 | if (die->tag == DW_TAG_member) |
| 15786 | { |
| 15787 | /* dwarf2_add_field uses die_is_declaration, |
| 15788 | so we do the same. */ |
| 15789 | gdb_assert (die_is_declaration (die, cu)); |
| 15790 | gdb_assert (attr); |
| 15791 | } |
| 15792 | if (attr) |
| 15793 | { |
| 15794 | dwarf2_const_value (attr, sym, cu); |
| 15795 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 15796 | if (!suppress_add) |
| 15797 | { |
| 15798 | if (attr2 && (DW_UNSND (attr2) != 0)) |
| 15799 | list_to_add = &global_symbols; |
| 15800 | else |
| 15801 | list_to_add = cu->list_in_scope; |
| 15802 | } |
| 15803 | break; |
| 15804 | } |
| 15805 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 15806 | if (attr) |
| 15807 | { |
| 15808 | var_decode_location (attr, sym, cu); |
| 15809 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 15810 | |
| 15811 | /* Fortran explicitly imports any global symbols to the local |
| 15812 | scope by DW_TAG_common_block. */ |
| 15813 | if (cu->language == language_fortran && die->parent |
| 15814 | && die->parent->tag == DW_TAG_common_block) |
| 15815 | attr2 = NULL; |
| 15816 | |
| 15817 | if (SYMBOL_CLASS (sym) == LOC_STATIC |
| 15818 | && SYMBOL_VALUE_ADDRESS (sym) == 0 |
| 15819 | && !dwarf2_per_objfile->has_section_at_zero) |
| 15820 | { |
| 15821 | /* When a static variable is eliminated by the linker, |
| 15822 | the corresponding debug information is not stripped |
| 15823 | out, but the variable address is set to null; |
| 15824 | do not add such variables into symbol table. */ |
| 15825 | } |
| 15826 | else if (attr2 && (DW_UNSND (attr2) != 0)) |
| 15827 | { |
| 15828 | /* Workaround gfortran PR debug/40040 - it uses |
| 15829 | DW_AT_location for variables in -fPIC libraries which may |
| 15830 | get overriden by other libraries/executable and get |
| 15831 | a different address. Resolve it by the minimal symbol |
| 15832 | which may come from inferior's executable using copy |
| 15833 | relocation. Make this workaround only for gfortran as for |
| 15834 | other compilers GDB cannot guess the minimal symbol |
| 15835 | Fortran mangling kind. */ |
| 15836 | if (cu->language == language_fortran && die->parent |
| 15837 | && die->parent->tag == DW_TAG_module |
| 15838 | && cu->producer |
| 15839 | && strncmp (cu->producer, "GNU Fortran ", 12) == 0) |
| 15840 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 15841 | |
| 15842 | /* A variable with DW_AT_external is never static, |
| 15843 | but it may be block-scoped. */ |
| 15844 | list_to_add = (cu->list_in_scope == &file_symbols |
| 15845 | ? &global_symbols : cu->list_in_scope); |
| 15846 | } |
| 15847 | else |
| 15848 | list_to_add = cu->list_in_scope; |
| 15849 | } |
| 15850 | else |
| 15851 | { |
| 15852 | /* We do not know the address of this symbol. |
| 15853 | If it is an external symbol and we have type information |
| 15854 | for it, enter the symbol as a LOC_UNRESOLVED symbol. |
| 15855 | The address of the variable will then be determined from |
| 15856 | the minimal symbol table whenever the variable is |
| 15857 | referenced. */ |
| 15858 | attr2 = dwarf2_attr (die, DW_AT_external, cu); |
| 15859 | |
| 15860 | /* Fortran explicitly imports any global symbols to the local |
| 15861 | scope by DW_TAG_common_block. */ |
| 15862 | if (cu->language == language_fortran && die->parent |
| 15863 | && die->parent->tag == DW_TAG_common_block) |
| 15864 | { |
| 15865 | /* SYMBOL_CLASS doesn't matter here because |
| 15866 | read_common_block is going to reset it. */ |
| 15867 | if (!suppress_add) |
| 15868 | list_to_add = cu->list_in_scope; |
| 15869 | } |
| 15870 | else if (attr2 && (DW_UNSND (attr2) != 0) |
| 15871 | && dwarf2_attr (die, DW_AT_type, cu) != NULL) |
| 15872 | { |
| 15873 | /* A variable with DW_AT_external is never static, but it |
| 15874 | may be block-scoped. */ |
| 15875 | list_to_add = (cu->list_in_scope == &file_symbols |
| 15876 | ? &global_symbols : cu->list_in_scope); |
| 15877 | |
| 15878 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 15879 | } |
| 15880 | else if (!die_is_declaration (die, cu)) |
| 15881 | { |
| 15882 | /* Use the default LOC_OPTIMIZED_OUT class. */ |
| 15883 | gdb_assert (SYMBOL_CLASS (sym) == LOC_OPTIMIZED_OUT); |
| 15884 | if (!suppress_add) |
| 15885 | list_to_add = cu->list_in_scope; |
| 15886 | } |
| 15887 | } |
| 15888 | break; |
| 15889 | case DW_TAG_formal_parameter: |
| 15890 | /* If we are inside a function, mark this as an argument. If |
| 15891 | not, we might be looking at an argument to an inlined function |
| 15892 | when we do not have enough information to show inlined frames; |
| 15893 | pretend it's a local variable in that case so that the user can |
| 15894 | still see it. */ |
| 15895 | if (context_stack_depth > 0 |
| 15896 | && context_stack[context_stack_depth - 1].name != NULL) |
| 15897 | SYMBOL_IS_ARGUMENT (sym) = 1; |
| 15898 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 15899 | if (attr) |
| 15900 | { |
| 15901 | var_decode_location (attr, sym, cu); |
| 15902 | } |
| 15903 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 15904 | if (attr) |
| 15905 | { |
| 15906 | dwarf2_const_value (attr, sym, cu); |
| 15907 | } |
| 15908 | |
| 15909 | list_to_add = cu->list_in_scope; |
| 15910 | break; |
| 15911 | case DW_TAG_unspecified_parameters: |
| 15912 | /* From varargs functions; gdb doesn't seem to have any |
| 15913 | interest in this information, so just ignore it for now. |
| 15914 | (FIXME?) */ |
| 15915 | break; |
| 15916 | case DW_TAG_template_type_param: |
| 15917 | suppress_add = 1; |
| 15918 | /* Fall through. */ |
| 15919 | case DW_TAG_class_type: |
| 15920 | case DW_TAG_interface_type: |
| 15921 | case DW_TAG_structure_type: |
| 15922 | case DW_TAG_union_type: |
| 15923 | case DW_TAG_set_type: |
| 15924 | case DW_TAG_enumeration_type: |
| 15925 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 15926 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
| 15927 | |
| 15928 | { |
| 15929 | /* NOTE: carlton/2003-11-10: C++ and Java class symbols shouldn't |
| 15930 | really ever be static objects: otherwise, if you try |
| 15931 | to, say, break of a class's method and you're in a file |
| 15932 | which doesn't mention that class, it won't work unless |
| 15933 | the check for all static symbols in lookup_symbol_aux |
| 15934 | saves you. See the OtherFileClass tests in |
| 15935 | gdb.c++/namespace.exp. */ |
| 15936 | |
| 15937 | if (!suppress_add) |
| 15938 | { |
| 15939 | list_to_add = (cu->list_in_scope == &file_symbols |
| 15940 | && (cu->language == language_cplus |
| 15941 | || cu->language == language_java) |
| 15942 | ? &global_symbols : cu->list_in_scope); |
| 15943 | |
| 15944 | /* The semantics of C++ state that "struct foo { |
| 15945 | ... }" also defines a typedef for "foo". A Java |
| 15946 | class declaration also defines a typedef for the |
| 15947 | class. */ |
| 15948 | if (cu->language == language_cplus |
| 15949 | || cu->language == language_java |
| 15950 | || cu->language == language_ada) |
| 15951 | { |
| 15952 | /* The symbol's name is already allocated along |
| 15953 | with this objfile, so we don't need to |
| 15954 | duplicate it for the type. */ |
| 15955 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
| 15956 | TYPE_NAME (SYMBOL_TYPE (sym)) = SYMBOL_SEARCH_NAME (sym); |
| 15957 | } |
| 15958 | } |
| 15959 | } |
| 15960 | break; |
| 15961 | case DW_TAG_typedef: |
| 15962 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 15963 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 15964 | list_to_add = cu->list_in_scope; |
| 15965 | break; |
| 15966 | case DW_TAG_base_type: |
| 15967 | case DW_TAG_subrange_type: |
| 15968 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 15969 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 15970 | list_to_add = cu->list_in_scope; |
| 15971 | break; |
| 15972 | case DW_TAG_enumerator: |
| 15973 | attr = dwarf2_attr (die, DW_AT_const_value, cu); |
| 15974 | if (attr) |
| 15975 | { |
| 15976 | dwarf2_const_value (attr, sym, cu); |
| 15977 | } |
| 15978 | { |
| 15979 | /* NOTE: carlton/2003-11-10: See comment above in the |
| 15980 | DW_TAG_class_type, etc. block. */ |
| 15981 | |
| 15982 | list_to_add = (cu->list_in_scope == &file_symbols |
| 15983 | && (cu->language == language_cplus |
| 15984 | || cu->language == language_java) |
| 15985 | ? &global_symbols : cu->list_in_scope); |
| 15986 | } |
| 15987 | break; |
| 15988 | case DW_TAG_namespace: |
| 15989 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 15990 | list_to_add = &global_symbols; |
| 15991 | break; |
| 15992 | case DW_TAG_common_block: |
| 15993 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 15994 | SYMBOL_DOMAIN (sym) = COMMON_BLOCK_DOMAIN; |
| 15995 | add_symbol_to_list (sym, cu->list_in_scope); |
| 15996 | break; |
| 15997 | default: |
| 15998 | /* Not a tag we recognize. Hopefully we aren't processing |
| 15999 | trash data, but since we must specifically ignore things |
| 16000 | we don't recognize, there is nothing else we should do at |
| 16001 | this point. */ |
| 16002 | complaint (&symfile_complaints, _("unsupported tag: '%s'"), |
| 16003 | dwarf_tag_name (die->tag)); |
| 16004 | break; |
| 16005 | } |
| 16006 | |
| 16007 | if (suppress_add) |
| 16008 | { |
| 16009 | sym->hash_next = objfile->template_symbols; |
| 16010 | objfile->template_symbols = sym; |
| 16011 | list_to_add = NULL; |
| 16012 | } |
| 16013 | |
| 16014 | if (list_to_add != NULL) |
| 16015 | add_symbol_to_list (sym, list_to_add); |
| 16016 | |
| 16017 | /* For the benefit of old versions of GCC, check for anonymous |
| 16018 | namespaces based on the demangled name. */ |
| 16019 | if (!processing_has_namespace_info |
| 16020 | && cu->language == language_cplus) |
| 16021 | cp_scan_for_anonymous_namespaces (sym, objfile); |
| 16022 | } |
| 16023 | return (sym); |
| 16024 | } |
| 16025 | |
| 16026 | /* A wrapper for new_symbol_full that always allocates a new symbol. */ |
| 16027 | |
| 16028 | static struct symbol * |
| 16029 | new_symbol (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
| 16030 | { |
| 16031 | return new_symbol_full (die, type, cu, NULL); |
| 16032 | } |
| 16033 | |
| 16034 | /* Given an attr with a DW_FORM_dataN value in host byte order, |
| 16035 | zero-extend it as appropriate for the symbol's type. The DWARF |
| 16036 | standard (v4) is not entirely clear about the meaning of using |
| 16037 | DW_FORM_dataN for a constant with a signed type, where the type is |
| 16038 | wider than the data. The conclusion of a discussion on the DWARF |
| 16039 | list was that this is unspecified. We choose to always zero-extend |
| 16040 | because that is the interpretation long in use by GCC. */ |
| 16041 | |
| 16042 | static gdb_byte * |
| 16043 | dwarf2_const_value_data (struct attribute *attr, struct type *type, |
| 16044 | const char *name, struct obstack *obstack, |
| 16045 | struct dwarf2_cu *cu, LONGEST *value, int bits) |
| 16046 | { |
| 16047 | struct objfile *objfile = cu->objfile; |
| 16048 | enum bfd_endian byte_order = bfd_big_endian (objfile->obfd) ? |
| 16049 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE; |
| 16050 | LONGEST l = DW_UNSND (attr); |
| 16051 | |
| 16052 | if (bits < sizeof (*value) * 8) |
| 16053 | { |
| 16054 | l &= ((LONGEST) 1 << bits) - 1; |
| 16055 | *value = l; |
| 16056 | } |
| 16057 | else if (bits == sizeof (*value) * 8) |
| 16058 | *value = l; |
| 16059 | else |
| 16060 | { |
| 16061 | gdb_byte *bytes = obstack_alloc (obstack, bits / 8); |
| 16062 | store_unsigned_integer (bytes, bits / 8, byte_order, l); |
| 16063 | return bytes; |
| 16064 | } |
| 16065 | |
| 16066 | return NULL; |
| 16067 | } |
| 16068 | |
| 16069 | /* Read a constant value from an attribute. Either set *VALUE, or if |
| 16070 | the value does not fit in *VALUE, set *BYTES - either already |
| 16071 | allocated on the objfile obstack, or newly allocated on OBSTACK, |
| 16072 | or, set *BATON, if we translated the constant to a location |
| 16073 | expression. */ |
| 16074 | |
| 16075 | static void |
| 16076 | dwarf2_const_value_attr (struct attribute *attr, struct type *type, |
| 16077 | const char *name, struct obstack *obstack, |
| 16078 | struct dwarf2_cu *cu, |
| 16079 | LONGEST *value, gdb_byte **bytes, |
| 16080 | struct dwarf2_locexpr_baton **baton) |
| 16081 | { |
| 16082 | struct objfile *objfile = cu->objfile; |
| 16083 | struct comp_unit_head *cu_header = &cu->header; |
| 16084 | struct dwarf_block *blk; |
| 16085 | enum bfd_endian byte_order = (bfd_big_endian (objfile->obfd) ? |
| 16086 | BFD_ENDIAN_BIG : BFD_ENDIAN_LITTLE); |
| 16087 | |
| 16088 | *value = 0; |
| 16089 | *bytes = NULL; |
| 16090 | *baton = NULL; |
| 16091 | |
| 16092 | switch (attr->form) |
| 16093 | { |
| 16094 | case DW_FORM_addr: |
| 16095 | case DW_FORM_GNU_addr_index: |
| 16096 | { |
| 16097 | gdb_byte *data; |
| 16098 | |
| 16099 | if (TYPE_LENGTH (type) != cu_header->addr_size) |
| 16100 | dwarf2_const_value_length_mismatch_complaint (name, |
| 16101 | cu_header->addr_size, |
| 16102 | TYPE_LENGTH (type)); |
| 16103 | /* Symbols of this form are reasonably rare, so we just |
| 16104 | piggyback on the existing location code rather than writing |
| 16105 | a new implementation of symbol_computed_ops. */ |
| 16106 | *baton = obstack_alloc (&objfile->objfile_obstack, |
| 16107 | sizeof (struct dwarf2_locexpr_baton)); |
| 16108 | (*baton)->per_cu = cu->per_cu; |
| 16109 | gdb_assert ((*baton)->per_cu); |
| 16110 | |
| 16111 | (*baton)->size = 2 + cu_header->addr_size; |
| 16112 | data = obstack_alloc (&objfile->objfile_obstack, (*baton)->size); |
| 16113 | (*baton)->data = data; |
| 16114 | |
| 16115 | data[0] = DW_OP_addr; |
| 16116 | store_unsigned_integer (&data[1], cu_header->addr_size, |
| 16117 | byte_order, DW_ADDR (attr)); |
| 16118 | data[cu_header->addr_size + 1] = DW_OP_stack_value; |
| 16119 | } |
| 16120 | break; |
| 16121 | case DW_FORM_string: |
| 16122 | case DW_FORM_strp: |
| 16123 | case DW_FORM_GNU_str_index: |
| 16124 | case DW_FORM_GNU_strp_alt: |
| 16125 | /* DW_STRING is already allocated on the objfile obstack, point |
| 16126 | directly to it. */ |
| 16127 | *bytes = (gdb_byte *) DW_STRING (attr); |
| 16128 | break; |
| 16129 | case DW_FORM_block1: |
| 16130 | case DW_FORM_block2: |
| 16131 | case DW_FORM_block4: |
| 16132 | case DW_FORM_block: |
| 16133 | case DW_FORM_exprloc: |
| 16134 | blk = DW_BLOCK (attr); |
| 16135 | if (TYPE_LENGTH (type) != blk->size) |
| 16136 | dwarf2_const_value_length_mismatch_complaint (name, blk->size, |
| 16137 | TYPE_LENGTH (type)); |
| 16138 | *bytes = blk->data; |
| 16139 | break; |
| 16140 | |
| 16141 | /* The DW_AT_const_value attributes are supposed to carry the |
| 16142 | symbol's value "represented as it would be on the target |
| 16143 | architecture." By the time we get here, it's already been |
| 16144 | converted to host endianness, so we just need to sign- or |
| 16145 | zero-extend it as appropriate. */ |
| 16146 | case DW_FORM_data1: |
| 16147 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 16148 | obstack, cu, value, 8); |
| 16149 | break; |
| 16150 | case DW_FORM_data2: |
| 16151 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 16152 | obstack, cu, value, 16); |
| 16153 | break; |
| 16154 | case DW_FORM_data4: |
| 16155 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 16156 | obstack, cu, value, 32); |
| 16157 | break; |
| 16158 | case DW_FORM_data8: |
| 16159 | *bytes = dwarf2_const_value_data (attr, type, name, |
| 16160 | obstack, cu, value, 64); |
| 16161 | break; |
| 16162 | |
| 16163 | case DW_FORM_sdata: |
| 16164 | *value = DW_SND (attr); |
| 16165 | break; |
| 16166 | |
| 16167 | case DW_FORM_udata: |
| 16168 | *value = DW_UNSND (attr); |
| 16169 | break; |
| 16170 | |
| 16171 | default: |
| 16172 | complaint (&symfile_complaints, |
| 16173 | _("unsupported const value attribute form: '%s'"), |
| 16174 | dwarf_form_name (attr->form)); |
| 16175 | *value = 0; |
| 16176 | break; |
| 16177 | } |
| 16178 | } |
| 16179 | |
| 16180 | |
| 16181 | /* Copy constant value from an attribute to a symbol. */ |
| 16182 | |
| 16183 | static void |
| 16184 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
| 16185 | struct dwarf2_cu *cu) |
| 16186 | { |
| 16187 | struct objfile *objfile = cu->objfile; |
| 16188 | struct comp_unit_head *cu_header = &cu->header; |
| 16189 | LONGEST value; |
| 16190 | gdb_byte *bytes; |
| 16191 | struct dwarf2_locexpr_baton *baton; |
| 16192 | |
| 16193 | dwarf2_const_value_attr (attr, SYMBOL_TYPE (sym), |
| 16194 | SYMBOL_PRINT_NAME (sym), |
| 16195 | &objfile->objfile_obstack, cu, |
| 16196 | &value, &bytes, &baton); |
| 16197 | |
| 16198 | if (baton != NULL) |
| 16199 | { |
| 16200 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 16201 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 16202 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 16203 | } |
| 16204 | else if (bytes != NULL) |
| 16205 | { |
| 16206 | SYMBOL_VALUE_BYTES (sym) = bytes; |
| 16207 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 16208 | } |
| 16209 | else |
| 16210 | { |
| 16211 | SYMBOL_VALUE (sym) = value; |
| 16212 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 16213 | } |
| 16214 | } |
| 16215 | |
| 16216 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
| 16217 | |
| 16218 | static struct type * |
| 16219 | die_type (struct die_info *die, struct dwarf2_cu *cu) |
| 16220 | { |
| 16221 | struct attribute *type_attr; |
| 16222 | |
| 16223 | type_attr = dwarf2_attr (die, DW_AT_type, cu); |
| 16224 | if (!type_attr) |
| 16225 | { |
| 16226 | /* A missing DW_AT_type represents a void type. */ |
| 16227 | return objfile_type (cu->objfile)->builtin_void; |
| 16228 | } |
| 16229 | |
| 16230 | return lookup_die_type (die, type_attr, cu); |
| 16231 | } |
| 16232 | |
| 16233 | /* True iff CU's producer generates GNAT Ada auxiliary information |
| 16234 | that allows to find parallel types through that information instead |
| 16235 | of having to do expensive parallel lookups by type name. */ |
| 16236 | |
| 16237 | static int |
| 16238 | need_gnat_info (struct dwarf2_cu *cu) |
| 16239 | { |
| 16240 | /* FIXME: brobecker/2010-10-12: As of now, only the AdaCore version |
| 16241 | of GNAT produces this auxiliary information, without any indication |
| 16242 | that it is produced. Part of enhancing the FSF version of GNAT |
| 16243 | to produce that information will be to put in place an indicator |
| 16244 | that we can use in order to determine whether the descriptive type |
| 16245 | info is available or not. One suggestion that has been made is |
| 16246 | to use a new attribute, attached to the CU die. For now, assume |
| 16247 | that the descriptive type info is not available. */ |
| 16248 | return 0; |
| 16249 | } |
| 16250 | |
| 16251 | /* Return the auxiliary type of the die in question using its |
| 16252 | DW_AT_GNAT_descriptive_type attribute. Returns NULL if the |
| 16253 | attribute is not present. */ |
| 16254 | |
| 16255 | static struct type * |
| 16256 | die_descriptive_type (struct die_info *die, struct dwarf2_cu *cu) |
| 16257 | { |
| 16258 | struct attribute *type_attr; |
| 16259 | |
| 16260 | type_attr = dwarf2_attr (die, DW_AT_GNAT_descriptive_type, cu); |
| 16261 | if (!type_attr) |
| 16262 | return NULL; |
| 16263 | |
| 16264 | return lookup_die_type (die, type_attr, cu); |
| 16265 | } |
| 16266 | |
| 16267 | /* If DIE has a descriptive_type attribute, then set the TYPE's |
| 16268 | descriptive type accordingly. */ |
| 16269 | |
| 16270 | static void |
| 16271 | set_descriptive_type (struct type *type, struct die_info *die, |
| 16272 | struct dwarf2_cu *cu) |
| 16273 | { |
| 16274 | struct type *descriptive_type = die_descriptive_type (die, cu); |
| 16275 | |
| 16276 | if (descriptive_type) |
| 16277 | { |
| 16278 | ALLOCATE_GNAT_AUX_TYPE (type); |
| 16279 | TYPE_DESCRIPTIVE_TYPE (type) = descriptive_type; |
| 16280 | } |
| 16281 | } |
| 16282 | |
| 16283 | /* Return the containing type of the die in question using its |
| 16284 | DW_AT_containing_type attribute. */ |
| 16285 | |
| 16286 | static struct type * |
| 16287 | die_containing_type (struct die_info *die, struct dwarf2_cu *cu) |
| 16288 | { |
| 16289 | struct attribute *type_attr; |
| 16290 | |
| 16291 | type_attr = dwarf2_attr (die, DW_AT_containing_type, cu); |
| 16292 | if (!type_attr) |
| 16293 | error (_("Dwarf Error: Problem turning containing type into gdb type " |
| 16294 | "[in module %s]"), cu->objfile->name); |
| 16295 | |
| 16296 | return lookup_die_type (die, type_attr, cu); |
| 16297 | } |
| 16298 | |
| 16299 | /* Look up the type of DIE in CU using its type attribute ATTR. |
| 16300 | If there is no type substitute an error marker. */ |
| 16301 | |
| 16302 | static struct type * |
| 16303 | lookup_die_type (struct die_info *die, struct attribute *attr, |
| 16304 | struct dwarf2_cu *cu) |
| 16305 | { |
| 16306 | struct objfile *objfile = cu->objfile; |
| 16307 | struct type *this_type; |
| 16308 | |
| 16309 | /* First see if we have it cached. */ |
| 16310 | |
| 16311 | if (attr->form == DW_FORM_GNU_ref_alt) |
| 16312 | { |
| 16313 | struct dwarf2_per_cu_data *per_cu; |
| 16314 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
| 16315 | |
| 16316 | per_cu = dwarf2_find_containing_comp_unit (offset, 1, cu->objfile); |
| 16317 | this_type = get_die_type_at_offset (offset, per_cu); |
| 16318 | } |
| 16319 | else if (is_ref_attr (attr)) |
| 16320 | { |
| 16321 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
| 16322 | |
| 16323 | this_type = get_die_type_at_offset (offset, cu->per_cu); |
| 16324 | } |
| 16325 | else if (attr->form == DW_FORM_ref_sig8) |
| 16326 | { |
| 16327 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); |
| 16328 | |
| 16329 | /* sig_type will be NULL if the signatured type is missing from |
| 16330 | the debug info. */ |
| 16331 | if (sig_type == NULL) |
| 16332 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " |
| 16333 | "at 0x%x [in module %s]"), |
| 16334 | die->offset.sect_off, objfile->name); |
| 16335 | |
| 16336 | gdb_assert (sig_type->per_cu.is_debug_types); |
| 16337 | /* If we haven't filled in type_offset_in_section yet, then we |
| 16338 | haven't read the type in yet. */ |
| 16339 | this_type = NULL; |
| 16340 | if (sig_type->type_offset_in_section.sect_off != 0) |
| 16341 | { |
| 16342 | this_type = |
| 16343 | get_die_type_at_offset (sig_type->type_offset_in_section, |
| 16344 | &sig_type->per_cu); |
| 16345 | } |
| 16346 | } |
| 16347 | else |
| 16348 | { |
| 16349 | dump_die_for_error (die); |
| 16350 | error (_("Dwarf Error: Bad type attribute %s [in module %s]"), |
| 16351 | dwarf_attr_name (attr->name), objfile->name); |
| 16352 | } |
| 16353 | |
| 16354 | /* If not cached we need to read it in. */ |
| 16355 | |
| 16356 | if (this_type == NULL) |
| 16357 | { |
| 16358 | struct die_info *type_die; |
| 16359 | struct dwarf2_cu *type_cu = cu; |
| 16360 | |
| 16361 | type_die = follow_die_ref_or_sig (die, attr, &type_cu); |
| 16362 | /* If we found the type now, it's probably because the type came |
| 16363 | from an inter-CU reference and the type's CU got expanded before |
| 16364 | ours. */ |
| 16365 | this_type = get_die_type (type_die, type_cu); |
| 16366 | if (this_type == NULL) |
| 16367 | this_type = read_type_die_1 (type_die, type_cu); |
| 16368 | } |
| 16369 | |
| 16370 | /* If we still don't have a type use an error marker. */ |
| 16371 | |
| 16372 | if (this_type == NULL) |
| 16373 | { |
| 16374 | char *message, *saved; |
| 16375 | |
| 16376 | /* read_type_die already issued a complaint. */ |
| 16377 | message = xstrprintf (_("<unknown type in %s, CU 0x%x, DIE 0x%x>"), |
| 16378 | objfile->name, |
| 16379 | cu->header.offset.sect_off, |
| 16380 | die->offset.sect_off); |
| 16381 | saved = obstack_copy0 (&objfile->objfile_obstack, |
| 16382 | message, strlen (message)); |
| 16383 | xfree (message); |
| 16384 | |
| 16385 | this_type = init_type (TYPE_CODE_ERROR, 0, 0, saved, objfile); |
| 16386 | } |
| 16387 | |
| 16388 | return this_type; |
| 16389 | } |
| 16390 | |
| 16391 | /* Return the type in DIE, CU. |
| 16392 | Returns NULL for invalid types. |
| 16393 | |
| 16394 | This first does a lookup in the appropriate type_hash table, |
| 16395 | and only reads the die in if necessary. |
| 16396 | |
| 16397 | NOTE: This can be called when reading in partial or full symbols. */ |
| 16398 | |
| 16399 | static struct type * |
| 16400 | read_type_die (struct die_info *die, struct dwarf2_cu *cu) |
| 16401 | { |
| 16402 | struct type *this_type; |
| 16403 | |
| 16404 | this_type = get_die_type (die, cu); |
| 16405 | if (this_type) |
| 16406 | return this_type; |
| 16407 | |
| 16408 | return read_type_die_1 (die, cu); |
| 16409 | } |
| 16410 | |
| 16411 | /* Read the type in DIE, CU. |
| 16412 | Returns NULL for invalid types. */ |
| 16413 | |
| 16414 | static struct type * |
| 16415 | read_type_die_1 (struct die_info *die, struct dwarf2_cu *cu) |
| 16416 | { |
| 16417 | struct type *this_type = NULL; |
| 16418 | |
| 16419 | switch (die->tag) |
| 16420 | { |
| 16421 | case DW_TAG_class_type: |
| 16422 | case DW_TAG_interface_type: |
| 16423 | case DW_TAG_structure_type: |
| 16424 | case DW_TAG_union_type: |
| 16425 | this_type = read_structure_type (die, cu); |
| 16426 | break; |
| 16427 | case DW_TAG_enumeration_type: |
| 16428 | this_type = read_enumeration_type (die, cu); |
| 16429 | break; |
| 16430 | case DW_TAG_subprogram: |
| 16431 | case DW_TAG_subroutine_type: |
| 16432 | case DW_TAG_inlined_subroutine: |
| 16433 | this_type = read_subroutine_type (die, cu); |
| 16434 | break; |
| 16435 | case DW_TAG_array_type: |
| 16436 | this_type = read_array_type (die, cu); |
| 16437 | break; |
| 16438 | case DW_TAG_set_type: |
| 16439 | this_type = read_set_type (die, cu); |
| 16440 | break; |
| 16441 | case DW_TAG_pointer_type: |
| 16442 | this_type = read_tag_pointer_type (die, cu); |
| 16443 | break; |
| 16444 | case DW_TAG_ptr_to_member_type: |
| 16445 | this_type = read_tag_ptr_to_member_type (die, cu); |
| 16446 | break; |
| 16447 | case DW_TAG_reference_type: |
| 16448 | this_type = read_tag_reference_type (die, cu); |
| 16449 | break; |
| 16450 | case DW_TAG_const_type: |
| 16451 | this_type = read_tag_const_type (die, cu); |
| 16452 | break; |
| 16453 | case DW_TAG_volatile_type: |
| 16454 | this_type = read_tag_volatile_type (die, cu); |
| 16455 | break; |
| 16456 | case DW_TAG_string_type: |
| 16457 | this_type = read_tag_string_type (die, cu); |
| 16458 | break; |
| 16459 | case DW_TAG_typedef: |
| 16460 | this_type = read_typedef (die, cu); |
| 16461 | break; |
| 16462 | case DW_TAG_subrange_type: |
| 16463 | this_type = read_subrange_type (die, cu); |
| 16464 | break; |
| 16465 | case DW_TAG_base_type: |
| 16466 | this_type = read_base_type (die, cu); |
| 16467 | break; |
| 16468 | case DW_TAG_unspecified_type: |
| 16469 | this_type = read_unspecified_type (die, cu); |
| 16470 | break; |
| 16471 | case DW_TAG_namespace: |
| 16472 | this_type = read_namespace_type (die, cu); |
| 16473 | break; |
| 16474 | case DW_TAG_module: |
| 16475 | this_type = read_module_type (die, cu); |
| 16476 | break; |
| 16477 | default: |
| 16478 | complaint (&symfile_complaints, |
| 16479 | _("unexpected tag in read_type_die: '%s'"), |
| 16480 | dwarf_tag_name (die->tag)); |
| 16481 | break; |
| 16482 | } |
| 16483 | |
| 16484 | return this_type; |
| 16485 | } |
| 16486 | |
| 16487 | /* See if we can figure out if the class lives in a namespace. We do |
| 16488 | this by looking for a member function; its demangled name will |
| 16489 | contain namespace info, if there is any. |
| 16490 | Return the computed name or NULL. |
| 16491 | Space for the result is allocated on the objfile's obstack. |
| 16492 | This is the full-die version of guess_partial_die_structure_name. |
| 16493 | In this case we know DIE has no useful parent. */ |
| 16494 | |
| 16495 | static char * |
| 16496 | guess_full_die_structure_name (struct die_info *die, struct dwarf2_cu *cu) |
| 16497 | { |
| 16498 | struct die_info *spec_die; |
| 16499 | struct dwarf2_cu *spec_cu; |
| 16500 | struct die_info *child; |
| 16501 | |
| 16502 | spec_cu = cu; |
| 16503 | spec_die = die_specification (die, &spec_cu); |
| 16504 | if (spec_die != NULL) |
| 16505 | { |
| 16506 | die = spec_die; |
| 16507 | cu = spec_cu; |
| 16508 | } |
| 16509 | |
| 16510 | for (child = die->child; |
| 16511 | child != NULL; |
| 16512 | child = child->sibling) |
| 16513 | { |
| 16514 | if (child->tag == DW_TAG_subprogram) |
| 16515 | { |
| 16516 | struct attribute *attr; |
| 16517 | |
| 16518 | attr = dwarf2_attr (child, DW_AT_linkage_name, cu); |
| 16519 | if (attr == NULL) |
| 16520 | attr = dwarf2_attr (child, DW_AT_MIPS_linkage_name, cu); |
| 16521 | if (attr != NULL) |
| 16522 | { |
| 16523 | char *actual_name |
| 16524 | = language_class_name_from_physname (cu->language_defn, |
| 16525 | DW_STRING (attr)); |
| 16526 | char *name = NULL; |
| 16527 | |
| 16528 | if (actual_name != NULL) |
| 16529 | { |
| 16530 | char *die_name = dwarf2_name (die, cu); |
| 16531 | |
| 16532 | if (die_name != NULL |
| 16533 | && strcmp (die_name, actual_name) != 0) |
| 16534 | { |
| 16535 | /* Strip off the class name from the full name. |
| 16536 | We want the prefix. */ |
| 16537 | int die_name_len = strlen (die_name); |
| 16538 | int actual_name_len = strlen (actual_name); |
| 16539 | |
| 16540 | /* Test for '::' as a sanity check. */ |
| 16541 | if (actual_name_len > die_name_len + 2 |
| 16542 | && actual_name[actual_name_len |
| 16543 | - die_name_len - 1] == ':') |
| 16544 | name = |
| 16545 | obsavestring (actual_name, |
| 16546 | actual_name_len - die_name_len - 2, |
| 16547 | &cu->objfile->objfile_obstack); |
| 16548 | } |
| 16549 | } |
| 16550 | xfree (actual_name); |
| 16551 | return name; |
| 16552 | } |
| 16553 | } |
| 16554 | } |
| 16555 | |
| 16556 | return NULL; |
| 16557 | } |
| 16558 | |
| 16559 | /* GCC might emit a nameless typedef that has a linkage name. Determine the |
| 16560 | prefix part in such case. See |
| 16561 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ |
| 16562 | |
| 16563 | static char * |
| 16564 | anonymous_struct_prefix (struct die_info *die, struct dwarf2_cu *cu) |
| 16565 | { |
| 16566 | struct attribute *attr; |
| 16567 | char *base; |
| 16568 | |
| 16569 | if (die->tag != DW_TAG_class_type && die->tag != DW_TAG_interface_type |
| 16570 | && die->tag != DW_TAG_structure_type && die->tag != DW_TAG_union_type) |
| 16571 | return NULL; |
| 16572 | |
| 16573 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 16574 | if (attr != NULL && DW_STRING (attr) != NULL) |
| 16575 | return NULL; |
| 16576 | |
| 16577 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 16578 | if (attr == NULL) |
| 16579 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 16580 | if (attr == NULL || DW_STRING (attr) == NULL) |
| 16581 | return NULL; |
| 16582 | |
| 16583 | /* dwarf2_name had to be already called. */ |
| 16584 | gdb_assert (DW_STRING_IS_CANONICAL (attr)); |
| 16585 | |
| 16586 | /* Strip the base name, keep any leading namespaces/classes. */ |
| 16587 | base = strrchr (DW_STRING (attr), ':'); |
| 16588 | if (base == NULL || base == DW_STRING (attr) || base[-1] != ':') |
| 16589 | return ""; |
| 16590 | |
| 16591 | return obsavestring (DW_STRING (attr), &base[-1] - DW_STRING (attr), |
| 16592 | &cu->objfile->objfile_obstack); |
| 16593 | } |
| 16594 | |
| 16595 | /* Return the name of the namespace/class that DIE is defined within, |
| 16596 | or "" if we can't tell. The caller should not xfree the result. |
| 16597 | |
| 16598 | For example, if we're within the method foo() in the following |
| 16599 | code: |
| 16600 | |
| 16601 | namespace N { |
| 16602 | class C { |
| 16603 | void foo () { |
| 16604 | } |
| 16605 | }; |
| 16606 | } |
| 16607 | |
| 16608 | then determine_prefix on foo's die will return "N::C". */ |
| 16609 | |
| 16610 | static const char * |
| 16611 | determine_prefix (struct die_info *die, struct dwarf2_cu *cu) |
| 16612 | { |
| 16613 | struct die_info *parent, *spec_die; |
| 16614 | struct dwarf2_cu *spec_cu; |
| 16615 | struct type *parent_type; |
| 16616 | char *retval; |
| 16617 | |
| 16618 | if (cu->language != language_cplus && cu->language != language_java |
| 16619 | && cu->language != language_fortran) |
| 16620 | return ""; |
| 16621 | |
| 16622 | retval = anonymous_struct_prefix (die, cu); |
| 16623 | if (retval) |
| 16624 | return retval; |
| 16625 | |
| 16626 | /* We have to be careful in the presence of DW_AT_specification. |
| 16627 | For example, with GCC 3.4, given the code |
| 16628 | |
| 16629 | namespace N { |
| 16630 | void foo() { |
| 16631 | // Definition of N::foo. |
| 16632 | } |
| 16633 | } |
| 16634 | |
| 16635 | then we'll have a tree of DIEs like this: |
| 16636 | |
| 16637 | 1: DW_TAG_compile_unit |
| 16638 | 2: DW_TAG_namespace // N |
| 16639 | 3: DW_TAG_subprogram // declaration of N::foo |
| 16640 | 4: DW_TAG_subprogram // definition of N::foo |
| 16641 | DW_AT_specification // refers to die #3 |
| 16642 | |
| 16643 | Thus, when processing die #4, we have to pretend that we're in |
| 16644 | the context of its DW_AT_specification, namely the contex of die |
| 16645 | #3. */ |
| 16646 | spec_cu = cu; |
| 16647 | spec_die = die_specification (die, &spec_cu); |
| 16648 | if (spec_die == NULL) |
| 16649 | parent = die->parent; |
| 16650 | else |
| 16651 | { |
| 16652 | parent = spec_die->parent; |
| 16653 | cu = spec_cu; |
| 16654 | } |
| 16655 | |
| 16656 | if (parent == NULL) |
| 16657 | return ""; |
| 16658 | else if (parent->building_fullname) |
| 16659 | { |
| 16660 | const char *name; |
| 16661 | const char *parent_name; |
| 16662 | |
| 16663 | /* It has been seen on RealView 2.2 built binaries, |
| 16664 | DW_TAG_template_type_param types actually _defined_ as |
| 16665 | children of the parent class: |
| 16666 | |
| 16667 | enum E {}; |
| 16668 | template class <class Enum> Class{}; |
| 16669 | Class<enum E> class_e; |
| 16670 | |
| 16671 | 1: DW_TAG_class_type (Class) |
| 16672 | 2: DW_TAG_enumeration_type (E) |
| 16673 | 3: DW_TAG_enumerator (enum1:0) |
| 16674 | 3: DW_TAG_enumerator (enum2:1) |
| 16675 | ... |
| 16676 | 2: DW_TAG_template_type_param |
| 16677 | DW_AT_type DW_FORM_ref_udata (E) |
| 16678 | |
| 16679 | Besides being broken debug info, it can put GDB into an |
| 16680 | infinite loop. Consider: |
| 16681 | |
| 16682 | When we're building the full name for Class<E>, we'll start |
| 16683 | at Class, and go look over its template type parameters, |
| 16684 | finding E. We'll then try to build the full name of E, and |
| 16685 | reach here. We're now trying to build the full name of E, |
| 16686 | and look over the parent DIE for containing scope. In the |
| 16687 | broken case, if we followed the parent DIE of E, we'd again |
| 16688 | find Class, and once again go look at its template type |
| 16689 | arguments, etc., etc. Simply don't consider such parent die |
| 16690 | as source-level parent of this die (it can't be, the language |
| 16691 | doesn't allow it), and break the loop here. */ |
| 16692 | name = dwarf2_name (die, cu); |
| 16693 | parent_name = dwarf2_name (parent, cu); |
| 16694 | complaint (&symfile_complaints, |
| 16695 | _("template param type '%s' defined within parent '%s'"), |
| 16696 | name ? name : "<unknown>", |
| 16697 | parent_name ? parent_name : "<unknown>"); |
| 16698 | return ""; |
| 16699 | } |
| 16700 | else |
| 16701 | switch (parent->tag) |
| 16702 | { |
| 16703 | case DW_TAG_namespace: |
| 16704 | parent_type = read_type_die (parent, cu); |
| 16705 | /* GCC 4.0 and 4.1 had a bug (PR c++/28460) where they generated bogus |
| 16706 | DW_TAG_namespace DIEs with a name of "::" for the global namespace. |
| 16707 | Work around this problem here. */ |
| 16708 | if (cu->language == language_cplus |
| 16709 | && strcmp (TYPE_TAG_NAME (parent_type), "::") == 0) |
| 16710 | return ""; |
| 16711 | /* We give a name to even anonymous namespaces. */ |
| 16712 | return TYPE_TAG_NAME (parent_type); |
| 16713 | case DW_TAG_class_type: |
| 16714 | case DW_TAG_interface_type: |
| 16715 | case DW_TAG_structure_type: |
| 16716 | case DW_TAG_union_type: |
| 16717 | case DW_TAG_module: |
| 16718 | parent_type = read_type_die (parent, cu); |
| 16719 | if (TYPE_TAG_NAME (parent_type) != NULL) |
| 16720 | return TYPE_TAG_NAME (parent_type); |
| 16721 | else |
| 16722 | /* An anonymous structure is only allowed non-static data |
| 16723 | members; no typedefs, no member functions, et cetera. |
| 16724 | So it does not need a prefix. */ |
| 16725 | return ""; |
| 16726 | case DW_TAG_compile_unit: |
| 16727 | case DW_TAG_partial_unit: |
| 16728 | /* gcc-4.5 -gdwarf-4 can drop the enclosing namespace. Cope. */ |
| 16729 | if (cu->language == language_cplus |
| 16730 | && !VEC_empty (dwarf2_section_info_def, dwarf2_per_objfile->types) |
| 16731 | && die->child != NULL |
| 16732 | && (die->tag == DW_TAG_class_type |
| 16733 | || die->tag == DW_TAG_structure_type |
| 16734 | || die->tag == DW_TAG_union_type)) |
| 16735 | { |
| 16736 | char *name = guess_full_die_structure_name (die, cu); |
| 16737 | if (name != NULL) |
| 16738 | return name; |
| 16739 | } |
| 16740 | return ""; |
| 16741 | default: |
| 16742 | return determine_prefix (parent, cu); |
| 16743 | } |
| 16744 | } |
| 16745 | |
| 16746 | /* Return a newly-allocated string formed by concatenating PREFIX and SUFFIX |
| 16747 | with appropriate separator. If PREFIX or SUFFIX is NULL or empty, then |
| 16748 | simply copy the SUFFIX or PREFIX, respectively. If OBS is non-null, perform |
| 16749 | an obconcat, otherwise allocate storage for the result. The CU argument is |
| 16750 | used to determine the language and hence, the appropriate separator. */ |
| 16751 | |
| 16752 | #define MAX_SEP_LEN 7 /* strlen ("__") + strlen ("_MOD_") */ |
| 16753 | |
| 16754 | static char * |
| 16755 | typename_concat (struct obstack *obs, const char *prefix, const char *suffix, |
| 16756 | int physname, struct dwarf2_cu *cu) |
| 16757 | { |
| 16758 | const char *lead = ""; |
| 16759 | const char *sep; |
| 16760 | |
| 16761 | if (suffix == NULL || suffix[0] == '\0' |
| 16762 | || prefix == NULL || prefix[0] == '\0') |
| 16763 | sep = ""; |
| 16764 | else if (cu->language == language_java) |
| 16765 | sep = "."; |
| 16766 | else if (cu->language == language_fortran && physname) |
| 16767 | { |
| 16768 | /* This is gfortran specific mangling. Normally DW_AT_linkage_name or |
| 16769 | DW_AT_MIPS_linkage_name is preferred and used instead. */ |
| 16770 | |
| 16771 | lead = "__"; |
| 16772 | sep = "_MOD_"; |
| 16773 | } |
| 16774 | else |
| 16775 | sep = "::"; |
| 16776 | |
| 16777 | if (prefix == NULL) |
| 16778 | prefix = ""; |
| 16779 | if (suffix == NULL) |
| 16780 | suffix = ""; |
| 16781 | |
| 16782 | if (obs == NULL) |
| 16783 | { |
| 16784 | char *retval |
| 16785 | = xmalloc (strlen (prefix) + MAX_SEP_LEN + strlen (suffix) + 1); |
| 16786 | |
| 16787 | strcpy (retval, lead); |
| 16788 | strcat (retval, prefix); |
| 16789 | strcat (retval, sep); |
| 16790 | strcat (retval, suffix); |
| 16791 | return retval; |
| 16792 | } |
| 16793 | else |
| 16794 | { |
| 16795 | /* We have an obstack. */ |
| 16796 | return obconcat (obs, lead, prefix, sep, suffix, (char *) NULL); |
| 16797 | } |
| 16798 | } |
| 16799 | |
| 16800 | /* Return sibling of die, NULL if no sibling. */ |
| 16801 | |
| 16802 | static struct die_info * |
| 16803 | sibling_die (struct die_info *die) |
| 16804 | { |
| 16805 | return die->sibling; |
| 16806 | } |
| 16807 | |
| 16808 | /* Get name of a die, return NULL if not found. */ |
| 16809 | |
| 16810 | static char * |
| 16811 | dwarf2_canonicalize_name (char *name, struct dwarf2_cu *cu, |
| 16812 | struct obstack *obstack) |
| 16813 | { |
| 16814 | if (name && cu->language == language_cplus) |
| 16815 | { |
| 16816 | char *canon_name = cp_canonicalize_string (name); |
| 16817 | |
| 16818 | if (canon_name != NULL) |
| 16819 | { |
| 16820 | if (strcmp (canon_name, name) != 0) |
| 16821 | name = obsavestring (canon_name, strlen (canon_name), |
| 16822 | obstack); |
| 16823 | xfree (canon_name); |
| 16824 | } |
| 16825 | } |
| 16826 | |
| 16827 | return name; |
| 16828 | } |
| 16829 | |
| 16830 | /* Get name of a die, return NULL if not found. */ |
| 16831 | |
| 16832 | static char * |
| 16833 | dwarf2_name (struct die_info *die, struct dwarf2_cu *cu) |
| 16834 | { |
| 16835 | struct attribute *attr; |
| 16836 | |
| 16837 | attr = dwarf2_attr (die, DW_AT_name, cu); |
| 16838 | if ((!attr || !DW_STRING (attr)) |
| 16839 | && die->tag != DW_TAG_class_type |
| 16840 | && die->tag != DW_TAG_interface_type |
| 16841 | && die->tag != DW_TAG_structure_type |
| 16842 | && die->tag != DW_TAG_union_type) |
| 16843 | return NULL; |
| 16844 | |
| 16845 | switch (die->tag) |
| 16846 | { |
| 16847 | case DW_TAG_compile_unit: |
| 16848 | case DW_TAG_partial_unit: |
| 16849 | /* Compilation units have a DW_AT_name that is a filename, not |
| 16850 | a source language identifier. */ |
| 16851 | case DW_TAG_enumeration_type: |
| 16852 | case DW_TAG_enumerator: |
| 16853 | /* These tags always have simple identifiers already; no need |
| 16854 | to canonicalize them. */ |
| 16855 | return DW_STRING (attr); |
| 16856 | |
| 16857 | case DW_TAG_subprogram: |
| 16858 | /* Java constructors will all be named "<init>", so return |
| 16859 | the class name when we see this special case. */ |
| 16860 | if (cu->language == language_java |
| 16861 | && DW_STRING (attr) != NULL |
| 16862 | && strcmp (DW_STRING (attr), "<init>") == 0) |
| 16863 | { |
| 16864 | struct dwarf2_cu *spec_cu = cu; |
| 16865 | struct die_info *spec_die; |
| 16866 | |
| 16867 | /* GCJ will output '<init>' for Java constructor names. |
| 16868 | For this special case, return the name of the parent class. */ |
| 16869 | |
| 16870 | /* GCJ may output suprogram DIEs with AT_specification set. |
| 16871 | If so, use the name of the specified DIE. */ |
| 16872 | spec_die = die_specification (die, &spec_cu); |
| 16873 | if (spec_die != NULL) |
| 16874 | return dwarf2_name (spec_die, spec_cu); |
| 16875 | |
| 16876 | do |
| 16877 | { |
| 16878 | die = die->parent; |
| 16879 | if (die->tag == DW_TAG_class_type) |
| 16880 | return dwarf2_name (die, cu); |
| 16881 | } |
| 16882 | while (die->tag != DW_TAG_compile_unit |
| 16883 | && die->tag != DW_TAG_partial_unit); |
| 16884 | } |
| 16885 | break; |
| 16886 | |
| 16887 | case DW_TAG_class_type: |
| 16888 | case DW_TAG_interface_type: |
| 16889 | case DW_TAG_structure_type: |
| 16890 | case DW_TAG_union_type: |
| 16891 | /* Some GCC versions emit spurious DW_AT_name attributes for unnamed |
| 16892 | structures or unions. These were of the form "._%d" in GCC 4.1, |
| 16893 | or simply "<anonymous struct>" or "<anonymous union>" in GCC 4.3 |
| 16894 | and GCC 4.4. We work around this problem by ignoring these. */ |
| 16895 | if (attr && DW_STRING (attr) |
| 16896 | && (strncmp (DW_STRING (attr), "._", 2) == 0 |
| 16897 | || strncmp (DW_STRING (attr), "<anonymous", 10) == 0)) |
| 16898 | return NULL; |
| 16899 | |
| 16900 | /* GCC might emit a nameless typedef that has a linkage name. See |
| 16901 | http://gcc.gnu.org/bugzilla/show_bug.cgi?id=47510. */ |
| 16902 | if (!attr || DW_STRING (attr) == NULL) |
| 16903 | { |
| 16904 | char *demangled = NULL; |
| 16905 | |
| 16906 | attr = dwarf2_attr (die, DW_AT_linkage_name, cu); |
| 16907 | if (attr == NULL) |
| 16908 | attr = dwarf2_attr (die, DW_AT_MIPS_linkage_name, cu); |
| 16909 | |
| 16910 | if (attr == NULL || DW_STRING (attr) == NULL) |
| 16911 | return NULL; |
| 16912 | |
| 16913 | /* Avoid demangling DW_STRING (attr) the second time on a second |
| 16914 | call for the same DIE. */ |
| 16915 | if (!DW_STRING_IS_CANONICAL (attr)) |
| 16916 | demangled = cplus_demangle (DW_STRING (attr), DMGL_TYPES); |
| 16917 | |
| 16918 | if (demangled) |
| 16919 | { |
| 16920 | char *base; |
| 16921 | |
| 16922 | /* FIXME: we already did this for the partial symbol... */ |
| 16923 | DW_STRING (attr) = obsavestring (demangled, strlen (demangled), |
| 16924 | &cu->objfile->objfile_obstack); |
| 16925 | DW_STRING_IS_CANONICAL (attr) = 1; |
| 16926 | xfree (demangled); |
| 16927 | |
| 16928 | /* Strip any leading namespaces/classes, keep only the base name. |
| 16929 | DW_AT_name for named DIEs does not contain the prefixes. */ |
| 16930 | base = strrchr (DW_STRING (attr), ':'); |
| 16931 | if (base && base > DW_STRING (attr) && base[-1] == ':') |
| 16932 | return &base[1]; |
| 16933 | else |
| 16934 | return DW_STRING (attr); |
| 16935 | } |
| 16936 | } |
| 16937 | break; |
| 16938 | |
| 16939 | default: |
| 16940 | break; |
| 16941 | } |
| 16942 | |
| 16943 | if (!DW_STRING_IS_CANONICAL (attr)) |
| 16944 | { |
| 16945 | DW_STRING (attr) |
| 16946 | = dwarf2_canonicalize_name (DW_STRING (attr), cu, |
| 16947 | &cu->objfile->objfile_obstack); |
| 16948 | DW_STRING_IS_CANONICAL (attr) = 1; |
| 16949 | } |
| 16950 | return DW_STRING (attr); |
| 16951 | } |
| 16952 | |
| 16953 | /* Return the die that this die in an extension of, or NULL if there |
| 16954 | is none. *EXT_CU is the CU containing DIE on input, and the CU |
| 16955 | containing the return value on output. */ |
| 16956 | |
| 16957 | static struct die_info * |
| 16958 | dwarf2_extension (struct die_info *die, struct dwarf2_cu **ext_cu) |
| 16959 | { |
| 16960 | struct attribute *attr; |
| 16961 | |
| 16962 | attr = dwarf2_attr (die, DW_AT_extension, *ext_cu); |
| 16963 | if (attr == NULL) |
| 16964 | return NULL; |
| 16965 | |
| 16966 | return follow_die_ref (die, attr, ext_cu); |
| 16967 | } |
| 16968 | |
| 16969 | /* Convert a DIE tag into its string name. */ |
| 16970 | |
| 16971 | static const char * |
| 16972 | dwarf_tag_name (unsigned tag) |
| 16973 | { |
| 16974 | const char *name = get_DW_TAG_name (tag); |
| 16975 | |
| 16976 | if (name == NULL) |
| 16977 | return "DW_TAG_<unknown>"; |
| 16978 | |
| 16979 | return name; |
| 16980 | } |
| 16981 | |
| 16982 | /* Convert a DWARF attribute code into its string name. */ |
| 16983 | |
| 16984 | static const char * |
| 16985 | dwarf_attr_name (unsigned attr) |
| 16986 | { |
| 16987 | const char *name; |
| 16988 | |
| 16989 | #ifdef MIPS /* collides with DW_AT_HP_block_index */ |
| 16990 | if (attr == DW_AT_MIPS_fde) |
| 16991 | return "DW_AT_MIPS_fde"; |
| 16992 | #else |
| 16993 | if (attr == DW_AT_HP_block_index) |
| 16994 | return "DW_AT_HP_block_index"; |
| 16995 | #endif |
| 16996 | |
| 16997 | name = get_DW_AT_name (attr); |
| 16998 | |
| 16999 | if (name == NULL) |
| 17000 | return "DW_AT_<unknown>"; |
| 17001 | |
| 17002 | return name; |
| 17003 | } |
| 17004 | |
| 17005 | /* Convert a DWARF value form code into its string name. */ |
| 17006 | |
| 17007 | static const char * |
| 17008 | dwarf_form_name (unsigned form) |
| 17009 | { |
| 17010 | const char *name = get_DW_FORM_name (form); |
| 17011 | |
| 17012 | if (name == NULL) |
| 17013 | return "DW_FORM_<unknown>"; |
| 17014 | |
| 17015 | return name; |
| 17016 | } |
| 17017 | |
| 17018 | static char * |
| 17019 | dwarf_bool_name (unsigned mybool) |
| 17020 | { |
| 17021 | if (mybool) |
| 17022 | return "TRUE"; |
| 17023 | else |
| 17024 | return "FALSE"; |
| 17025 | } |
| 17026 | |
| 17027 | /* Convert a DWARF type code into its string name. */ |
| 17028 | |
| 17029 | static const char * |
| 17030 | dwarf_type_encoding_name (unsigned enc) |
| 17031 | { |
| 17032 | const char *name = get_DW_ATE_name (enc); |
| 17033 | |
| 17034 | if (name == NULL) |
| 17035 | return "DW_ATE_<unknown>"; |
| 17036 | |
| 17037 | return name; |
| 17038 | } |
| 17039 | |
| 17040 | static void |
| 17041 | dump_die_shallow (struct ui_file *f, int indent, struct die_info *die) |
| 17042 | { |
| 17043 | unsigned int i; |
| 17044 | |
| 17045 | print_spaces (indent, f); |
| 17046 | fprintf_unfiltered (f, "Die: %s (abbrev %d, offset 0x%x)\n", |
| 17047 | dwarf_tag_name (die->tag), die->abbrev, die->offset.sect_off); |
| 17048 | |
| 17049 | if (die->parent != NULL) |
| 17050 | { |
| 17051 | print_spaces (indent, f); |
| 17052 | fprintf_unfiltered (f, " parent at offset: 0x%x\n", |
| 17053 | die->parent->offset.sect_off); |
| 17054 | } |
| 17055 | |
| 17056 | print_spaces (indent, f); |
| 17057 | fprintf_unfiltered (f, " has children: %s\n", |
| 17058 | dwarf_bool_name (die->child != NULL)); |
| 17059 | |
| 17060 | print_spaces (indent, f); |
| 17061 | fprintf_unfiltered (f, " attributes:\n"); |
| 17062 | |
| 17063 | for (i = 0; i < die->num_attrs; ++i) |
| 17064 | { |
| 17065 | print_spaces (indent, f); |
| 17066 | fprintf_unfiltered (f, " %s (%s) ", |
| 17067 | dwarf_attr_name (die->attrs[i].name), |
| 17068 | dwarf_form_name (die->attrs[i].form)); |
| 17069 | |
| 17070 | switch (die->attrs[i].form) |
| 17071 | { |
| 17072 | case DW_FORM_addr: |
| 17073 | case DW_FORM_GNU_addr_index: |
| 17074 | fprintf_unfiltered (f, "address: "); |
| 17075 | fputs_filtered (hex_string (DW_ADDR (&die->attrs[i])), f); |
| 17076 | break; |
| 17077 | case DW_FORM_block2: |
| 17078 | case DW_FORM_block4: |
| 17079 | case DW_FORM_block: |
| 17080 | case DW_FORM_block1: |
| 17081 | fprintf_unfiltered (f, "block: size %s", |
| 17082 | pulongest (DW_BLOCK (&die->attrs[i])->size)); |
| 17083 | break; |
| 17084 | case DW_FORM_exprloc: |
| 17085 | fprintf_unfiltered (f, "expression: size %s", |
| 17086 | pulongest (DW_BLOCK (&die->attrs[i])->size)); |
| 17087 | break; |
| 17088 | case DW_FORM_ref_addr: |
| 17089 | fprintf_unfiltered (f, "ref address: "); |
| 17090 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); |
| 17091 | break; |
| 17092 | case DW_FORM_GNU_ref_alt: |
| 17093 | fprintf_unfiltered (f, "alt ref address: "); |
| 17094 | fputs_filtered (hex_string (DW_UNSND (&die->attrs[i])), f); |
| 17095 | break; |
| 17096 | case DW_FORM_ref1: |
| 17097 | case DW_FORM_ref2: |
| 17098 | case DW_FORM_ref4: |
| 17099 | case DW_FORM_ref8: |
| 17100 | case DW_FORM_ref_udata: |
| 17101 | fprintf_unfiltered (f, "constant ref: 0x%lx (adjusted)", |
| 17102 | (long) (DW_UNSND (&die->attrs[i]))); |
| 17103 | break; |
| 17104 | case DW_FORM_data1: |
| 17105 | case DW_FORM_data2: |
| 17106 | case DW_FORM_data4: |
| 17107 | case DW_FORM_data8: |
| 17108 | case DW_FORM_udata: |
| 17109 | case DW_FORM_sdata: |
| 17110 | fprintf_unfiltered (f, "constant: %s", |
| 17111 | pulongest (DW_UNSND (&die->attrs[i]))); |
| 17112 | break; |
| 17113 | case DW_FORM_sec_offset: |
| 17114 | fprintf_unfiltered (f, "section offset: %s", |
| 17115 | pulongest (DW_UNSND (&die->attrs[i]))); |
| 17116 | break; |
| 17117 | case DW_FORM_ref_sig8: |
| 17118 | if (DW_SIGNATURED_TYPE (&die->attrs[i]) != NULL) |
| 17119 | fprintf_unfiltered (f, "signatured type, offset: 0x%x", |
| 17120 | DW_SIGNATURED_TYPE (&die->attrs[i])->per_cu.offset.sect_off); |
| 17121 | else |
| 17122 | fprintf_unfiltered (f, "signatured type, offset: unknown"); |
| 17123 | break; |
| 17124 | case DW_FORM_string: |
| 17125 | case DW_FORM_strp: |
| 17126 | case DW_FORM_GNU_str_index: |
| 17127 | case DW_FORM_GNU_strp_alt: |
| 17128 | fprintf_unfiltered (f, "string: \"%s\" (%s canonicalized)", |
| 17129 | DW_STRING (&die->attrs[i]) |
| 17130 | ? DW_STRING (&die->attrs[i]) : "", |
| 17131 | DW_STRING_IS_CANONICAL (&die->attrs[i]) ? "is" : "not"); |
| 17132 | break; |
| 17133 | case DW_FORM_flag: |
| 17134 | if (DW_UNSND (&die->attrs[i])) |
| 17135 | fprintf_unfiltered (f, "flag: TRUE"); |
| 17136 | else |
| 17137 | fprintf_unfiltered (f, "flag: FALSE"); |
| 17138 | break; |
| 17139 | case DW_FORM_flag_present: |
| 17140 | fprintf_unfiltered (f, "flag: TRUE"); |
| 17141 | break; |
| 17142 | case DW_FORM_indirect: |
| 17143 | /* The reader will have reduced the indirect form to |
| 17144 | the "base form" so this form should not occur. */ |
| 17145 | fprintf_unfiltered (f, |
| 17146 | "unexpected attribute form: DW_FORM_indirect"); |
| 17147 | break; |
| 17148 | default: |
| 17149 | fprintf_unfiltered (f, "unsupported attribute form: %d.", |
| 17150 | die->attrs[i].form); |
| 17151 | break; |
| 17152 | } |
| 17153 | fprintf_unfiltered (f, "\n"); |
| 17154 | } |
| 17155 | } |
| 17156 | |
| 17157 | static void |
| 17158 | dump_die_for_error (struct die_info *die) |
| 17159 | { |
| 17160 | dump_die_shallow (gdb_stderr, 0, die); |
| 17161 | } |
| 17162 | |
| 17163 | static void |
| 17164 | dump_die_1 (struct ui_file *f, int level, int max_level, struct die_info *die) |
| 17165 | { |
| 17166 | int indent = level * 4; |
| 17167 | |
| 17168 | gdb_assert (die != NULL); |
| 17169 | |
| 17170 | if (level >= max_level) |
| 17171 | return; |
| 17172 | |
| 17173 | dump_die_shallow (f, indent, die); |
| 17174 | |
| 17175 | if (die->child != NULL) |
| 17176 | { |
| 17177 | print_spaces (indent, f); |
| 17178 | fprintf_unfiltered (f, " Children:"); |
| 17179 | if (level + 1 < max_level) |
| 17180 | { |
| 17181 | fprintf_unfiltered (f, "\n"); |
| 17182 | dump_die_1 (f, level + 1, max_level, die->child); |
| 17183 | } |
| 17184 | else |
| 17185 | { |
| 17186 | fprintf_unfiltered (f, |
| 17187 | " [not printed, max nesting level reached]\n"); |
| 17188 | } |
| 17189 | } |
| 17190 | |
| 17191 | if (die->sibling != NULL && level > 0) |
| 17192 | { |
| 17193 | dump_die_1 (f, level, max_level, die->sibling); |
| 17194 | } |
| 17195 | } |
| 17196 | |
| 17197 | /* This is called from the pdie macro in gdbinit.in. |
| 17198 | It's not static so gcc will keep a copy callable from gdb. */ |
| 17199 | |
| 17200 | void |
| 17201 | dump_die (struct die_info *die, int max_level) |
| 17202 | { |
| 17203 | dump_die_1 (gdb_stdlog, 0, max_level, die); |
| 17204 | } |
| 17205 | |
| 17206 | static void |
| 17207 | store_in_ref_table (struct die_info *die, struct dwarf2_cu *cu) |
| 17208 | { |
| 17209 | void **slot; |
| 17210 | |
| 17211 | slot = htab_find_slot_with_hash (cu->die_hash, die, die->offset.sect_off, |
| 17212 | INSERT); |
| 17213 | |
| 17214 | *slot = die; |
| 17215 | } |
| 17216 | |
| 17217 | /* DW_ADDR is always stored already as sect_offset; despite for the forms |
| 17218 | besides DW_FORM_ref_addr it is stored as cu_offset in the DWARF file. */ |
| 17219 | |
| 17220 | static int |
| 17221 | is_ref_attr (struct attribute *attr) |
| 17222 | { |
| 17223 | switch (attr->form) |
| 17224 | { |
| 17225 | case DW_FORM_ref_addr: |
| 17226 | case DW_FORM_ref1: |
| 17227 | case DW_FORM_ref2: |
| 17228 | case DW_FORM_ref4: |
| 17229 | case DW_FORM_ref8: |
| 17230 | case DW_FORM_ref_udata: |
| 17231 | case DW_FORM_GNU_ref_alt: |
| 17232 | return 1; |
| 17233 | default: |
| 17234 | return 0; |
| 17235 | } |
| 17236 | } |
| 17237 | |
| 17238 | /* Return DIE offset of ATTR. Return 0 with complaint if ATTR is not of the |
| 17239 | required kind. */ |
| 17240 | |
| 17241 | static sect_offset |
| 17242 | dwarf2_get_ref_die_offset (struct attribute *attr) |
| 17243 | { |
| 17244 | sect_offset retval = { DW_UNSND (attr) }; |
| 17245 | |
| 17246 | if (is_ref_attr (attr)) |
| 17247 | return retval; |
| 17248 | |
| 17249 | retval.sect_off = 0; |
| 17250 | complaint (&symfile_complaints, |
| 17251 | _("unsupported die ref attribute form: '%s'"), |
| 17252 | dwarf_form_name (attr->form)); |
| 17253 | return retval; |
| 17254 | } |
| 17255 | |
| 17256 | /* Return the constant value held by ATTR. Return DEFAULT_VALUE if |
| 17257 | * the value held by the attribute is not constant. */ |
| 17258 | |
| 17259 | static LONGEST |
| 17260 | dwarf2_get_attr_constant_value (struct attribute *attr, int default_value) |
| 17261 | { |
| 17262 | if (attr->form == DW_FORM_sdata) |
| 17263 | return DW_SND (attr); |
| 17264 | else if (attr->form == DW_FORM_udata |
| 17265 | || attr->form == DW_FORM_data1 |
| 17266 | || attr->form == DW_FORM_data2 |
| 17267 | || attr->form == DW_FORM_data4 |
| 17268 | || attr->form == DW_FORM_data8) |
| 17269 | return DW_UNSND (attr); |
| 17270 | else |
| 17271 | { |
| 17272 | complaint (&symfile_complaints, |
| 17273 | _("Attribute value is not a constant (%s)"), |
| 17274 | dwarf_form_name (attr->form)); |
| 17275 | return default_value; |
| 17276 | } |
| 17277 | } |
| 17278 | |
| 17279 | /* Follow reference or signature attribute ATTR of SRC_DIE. |
| 17280 | On entry *REF_CU is the CU of SRC_DIE. |
| 17281 | On exit *REF_CU is the CU of the result. */ |
| 17282 | |
| 17283 | static struct die_info * |
| 17284 | follow_die_ref_or_sig (struct die_info *src_die, struct attribute *attr, |
| 17285 | struct dwarf2_cu **ref_cu) |
| 17286 | { |
| 17287 | struct die_info *die; |
| 17288 | |
| 17289 | if (is_ref_attr (attr)) |
| 17290 | die = follow_die_ref (src_die, attr, ref_cu); |
| 17291 | else if (attr->form == DW_FORM_ref_sig8) |
| 17292 | die = follow_die_sig (src_die, attr, ref_cu); |
| 17293 | else |
| 17294 | { |
| 17295 | dump_die_for_error (src_die); |
| 17296 | error (_("Dwarf Error: Expected reference attribute [in module %s]"), |
| 17297 | (*ref_cu)->objfile->name); |
| 17298 | } |
| 17299 | |
| 17300 | return die; |
| 17301 | } |
| 17302 | |
| 17303 | /* Follow reference OFFSET. |
| 17304 | On entry *REF_CU is the CU of the source die referencing OFFSET. |
| 17305 | On exit *REF_CU is the CU of the result. |
| 17306 | Returns NULL if OFFSET is invalid. */ |
| 17307 | |
| 17308 | static struct die_info * |
| 17309 | follow_die_offset (sect_offset offset, int offset_in_dwz, |
| 17310 | struct dwarf2_cu **ref_cu) |
| 17311 | { |
| 17312 | struct die_info temp_die; |
| 17313 | struct dwarf2_cu *target_cu, *cu = *ref_cu; |
| 17314 | |
| 17315 | gdb_assert (cu->per_cu != NULL); |
| 17316 | |
| 17317 | target_cu = cu; |
| 17318 | |
| 17319 | if (cu->per_cu->is_debug_types) |
| 17320 | { |
| 17321 | /* .debug_types CUs cannot reference anything outside their CU. |
| 17322 | If they need to, they have to reference a signatured type via |
| 17323 | DW_FORM_ref_sig8. */ |
| 17324 | if (! offset_in_cu_p (&cu->header, offset)) |
| 17325 | return NULL; |
| 17326 | } |
| 17327 | else if (offset_in_dwz != cu->per_cu->is_dwz |
| 17328 | || ! offset_in_cu_p (&cu->header, offset)) |
| 17329 | { |
| 17330 | struct dwarf2_per_cu_data *per_cu; |
| 17331 | |
| 17332 | per_cu = dwarf2_find_containing_comp_unit (offset, offset_in_dwz, |
| 17333 | cu->objfile); |
| 17334 | |
| 17335 | /* If necessary, add it to the queue and load its DIEs. */ |
| 17336 | if (maybe_queue_comp_unit (cu, per_cu, cu->language)) |
| 17337 | load_full_comp_unit (per_cu, cu->language); |
| 17338 | |
| 17339 | target_cu = per_cu->cu; |
| 17340 | } |
| 17341 | else if (cu->dies == NULL) |
| 17342 | { |
| 17343 | /* We're loading full DIEs during partial symbol reading. */ |
| 17344 | gdb_assert (dwarf2_per_objfile->reading_partial_symbols); |
| 17345 | load_full_comp_unit (cu->per_cu, language_minimal); |
| 17346 | } |
| 17347 | |
| 17348 | *ref_cu = target_cu; |
| 17349 | temp_die.offset = offset; |
| 17350 | return htab_find_with_hash (target_cu->die_hash, &temp_die, offset.sect_off); |
| 17351 | } |
| 17352 | |
| 17353 | /* Follow reference attribute ATTR of SRC_DIE. |
| 17354 | On entry *REF_CU is the CU of SRC_DIE. |
| 17355 | On exit *REF_CU is the CU of the result. */ |
| 17356 | |
| 17357 | static struct die_info * |
| 17358 | follow_die_ref (struct die_info *src_die, struct attribute *attr, |
| 17359 | struct dwarf2_cu **ref_cu) |
| 17360 | { |
| 17361 | sect_offset offset = dwarf2_get_ref_die_offset (attr); |
| 17362 | struct dwarf2_cu *cu = *ref_cu; |
| 17363 | struct die_info *die; |
| 17364 | |
| 17365 | die = follow_die_offset (offset, |
| 17366 | (attr->form == DW_FORM_GNU_ref_alt |
| 17367 | || cu->per_cu->is_dwz), |
| 17368 | ref_cu); |
| 17369 | if (!die) |
| 17370 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced from DIE " |
| 17371 | "at 0x%x [in module %s]"), |
| 17372 | offset.sect_off, src_die->offset.sect_off, cu->objfile->name); |
| 17373 | |
| 17374 | return die; |
| 17375 | } |
| 17376 | |
| 17377 | /* Return DWARF block referenced by DW_AT_location of DIE at OFFSET at PER_CU. |
| 17378 | Returned value is intended for DW_OP_call*. Returned |
| 17379 | dwarf2_locexpr_baton->data has lifetime of PER_CU->OBJFILE. */ |
| 17380 | |
| 17381 | struct dwarf2_locexpr_baton |
| 17382 | dwarf2_fetch_die_loc_sect_off (sect_offset offset, |
| 17383 | struct dwarf2_per_cu_data *per_cu, |
| 17384 | CORE_ADDR (*get_frame_pc) (void *baton), |
| 17385 | void *baton) |
| 17386 | { |
| 17387 | struct dwarf2_cu *cu; |
| 17388 | struct die_info *die; |
| 17389 | struct attribute *attr; |
| 17390 | struct dwarf2_locexpr_baton retval; |
| 17391 | |
| 17392 | dw2_setup (per_cu->objfile); |
| 17393 | |
| 17394 | if (per_cu->cu == NULL) |
| 17395 | load_cu (per_cu); |
| 17396 | cu = per_cu->cu; |
| 17397 | |
| 17398 | die = follow_die_offset (offset, per_cu->is_dwz, &cu); |
| 17399 | if (!die) |
| 17400 | error (_("Dwarf Error: Cannot find DIE at 0x%x referenced in module %s"), |
| 17401 | offset.sect_off, per_cu->objfile->name); |
| 17402 | |
| 17403 | attr = dwarf2_attr (die, DW_AT_location, cu); |
| 17404 | if (!attr) |
| 17405 | { |
| 17406 | /* DWARF: "If there is no such attribute, then there is no effect.". |
| 17407 | DATA is ignored if SIZE is 0. */ |
| 17408 | |
| 17409 | retval.data = NULL; |
| 17410 | retval.size = 0; |
| 17411 | } |
| 17412 | else if (attr_form_is_section_offset (attr)) |
| 17413 | { |
| 17414 | struct dwarf2_loclist_baton loclist_baton; |
| 17415 | CORE_ADDR pc = (*get_frame_pc) (baton); |
| 17416 | size_t size; |
| 17417 | |
| 17418 | fill_in_loclist_baton (cu, &loclist_baton, attr); |
| 17419 | |
| 17420 | retval.data = dwarf2_find_location_expression (&loclist_baton, |
| 17421 | &size, pc); |
| 17422 | retval.size = size; |
| 17423 | } |
| 17424 | else |
| 17425 | { |
| 17426 | if (!attr_form_is_block (attr)) |
| 17427 | error (_("Dwarf Error: DIE at 0x%x referenced in module %s " |
| 17428 | "is neither DW_FORM_block* nor DW_FORM_exprloc"), |
| 17429 | offset.sect_off, per_cu->objfile->name); |
| 17430 | |
| 17431 | retval.data = DW_BLOCK (attr)->data; |
| 17432 | retval.size = DW_BLOCK (attr)->size; |
| 17433 | } |
| 17434 | retval.per_cu = cu->per_cu; |
| 17435 | |
| 17436 | age_cached_comp_units (); |
| 17437 | |
| 17438 | return retval; |
| 17439 | } |
| 17440 | |
| 17441 | /* Like dwarf2_fetch_die_loc_sect_off, but take a CU |
| 17442 | offset. */ |
| 17443 | |
| 17444 | struct dwarf2_locexpr_baton |
| 17445 | dwarf2_fetch_die_loc_cu_off (cu_offset offset_in_cu, |
| 17446 | struct dwarf2_per_cu_data *per_cu, |
| 17447 | CORE_ADDR (*get_frame_pc) (void *baton), |
| 17448 | void *baton) |
| 17449 | { |
| 17450 | sect_offset offset = { per_cu->offset.sect_off + offset_in_cu.cu_off }; |
| 17451 | |
| 17452 | return dwarf2_fetch_die_loc_sect_off (offset, per_cu, get_frame_pc, baton); |
| 17453 | } |
| 17454 | |
| 17455 | /* Return the type of the DIE at DIE_OFFSET in the CU named by |
| 17456 | PER_CU. */ |
| 17457 | |
| 17458 | struct type * |
| 17459 | dwarf2_get_die_type (cu_offset die_offset, |
| 17460 | struct dwarf2_per_cu_data *per_cu) |
| 17461 | { |
| 17462 | sect_offset die_offset_sect; |
| 17463 | |
| 17464 | dw2_setup (per_cu->objfile); |
| 17465 | |
| 17466 | die_offset_sect.sect_off = per_cu->offset.sect_off + die_offset.cu_off; |
| 17467 | return get_die_type_at_offset (die_offset_sect, per_cu); |
| 17468 | } |
| 17469 | |
| 17470 | /* Follow the signature attribute ATTR in SRC_DIE. |
| 17471 | On entry *REF_CU is the CU of SRC_DIE. |
| 17472 | On exit *REF_CU is the CU of the result. */ |
| 17473 | |
| 17474 | static struct die_info * |
| 17475 | follow_die_sig (struct die_info *src_die, struct attribute *attr, |
| 17476 | struct dwarf2_cu **ref_cu) |
| 17477 | { |
| 17478 | struct objfile *objfile = (*ref_cu)->objfile; |
| 17479 | struct die_info temp_die; |
| 17480 | struct signatured_type *sig_type = DW_SIGNATURED_TYPE (attr); |
| 17481 | struct dwarf2_cu *sig_cu; |
| 17482 | struct die_info *die; |
| 17483 | |
| 17484 | /* sig_type will be NULL if the signatured type is missing from |
| 17485 | the debug info. */ |
| 17486 | if (sig_type == NULL) |
| 17487 | error (_("Dwarf Error: Cannot find signatured DIE referenced from DIE " |
| 17488 | "at 0x%x [in module %s]"), |
| 17489 | src_die->offset.sect_off, objfile->name); |
| 17490 | |
| 17491 | /* If necessary, add it to the queue and load its DIEs. */ |
| 17492 | |
| 17493 | if (maybe_queue_comp_unit (*ref_cu, &sig_type->per_cu, language_minimal)) |
| 17494 | read_signatured_type (sig_type); |
| 17495 | |
| 17496 | gdb_assert (sig_type->per_cu.cu != NULL); |
| 17497 | |
| 17498 | sig_cu = sig_type->per_cu.cu; |
| 17499 | gdb_assert (sig_type->type_offset_in_section.sect_off != 0); |
| 17500 | temp_die.offset = sig_type->type_offset_in_section; |
| 17501 | die = htab_find_with_hash (sig_cu->die_hash, &temp_die, |
| 17502 | temp_die.offset.sect_off); |
| 17503 | if (die) |
| 17504 | { |
| 17505 | *ref_cu = sig_cu; |
| 17506 | return die; |
| 17507 | } |
| 17508 | |
| 17509 | error (_("Dwarf Error: Cannot find signatured DIE at 0x%x referenced " |
| 17510 | "from DIE at 0x%x [in module %s]"), |
| 17511 | temp_die.offset.sect_off, src_die->offset.sect_off, objfile->name); |
| 17512 | } |
| 17513 | |
| 17514 | /* Given an offset of a signatured type, return its signatured_type. */ |
| 17515 | |
| 17516 | static struct signatured_type * |
| 17517 | lookup_signatured_type_at_offset (struct objfile *objfile, |
| 17518 | struct dwarf2_section_info *section, |
| 17519 | sect_offset offset) |
| 17520 | { |
| 17521 | gdb_byte *info_ptr = section->buffer + offset.sect_off; |
| 17522 | unsigned int length, initial_length_size; |
| 17523 | unsigned int sig_offset; |
| 17524 | struct signatured_type find_entry, *sig_type; |
| 17525 | |
| 17526 | length = read_initial_length (objfile->obfd, info_ptr, &initial_length_size); |
| 17527 | sig_offset = (initial_length_size |
| 17528 | + 2 /*version*/ |
| 17529 | + (initial_length_size == 4 ? 4 : 8) /*debug_abbrev_offset*/ |
| 17530 | + 1 /*address_size*/); |
| 17531 | find_entry.signature = bfd_get_64 (objfile->obfd, info_ptr + sig_offset); |
| 17532 | sig_type = htab_find (dwarf2_per_objfile->signatured_types, &find_entry); |
| 17533 | |
| 17534 | /* This is only used to lookup previously recorded types. |
| 17535 | If we didn't find it, it's our bug. */ |
| 17536 | gdb_assert (sig_type != NULL); |
| 17537 | gdb_assert (offset.sect_off == sig_type->per_cu.offset.sect_off); |
| 17538 | |
| 17539 | return sig_type; |
| 17540 | } |
| 17541 | |
| 17542 | /* Load the DIEs associated with type unit PER_CU into memory. */ |
| 17543 | |
| 17544 | static void |
| 17545 | load_full_type_unit (struct dwarf2_per_cu_data *per_cu) |
| 17546 | { |
| 17547 | struct signatured_type *sig_type; |
| 17548 | |
| 17549 | /* Caller is responsible for ensuring type_unit_groups don't get here. */ |
| 17550 | gdb_assert (! IS_TYPE_UNIT_GROUP (per_cu)); |
| 17551 | |
| 17552 | /* We have the per_cu, but we need the signatured_type. |
| 17553 | Fortunately this is an easy translation. */ |
| 17554 | gdb_assert (per_cu->is_debug_types); |
| 17555 | sig_type = (struct signatured_type *) per_cu; |
| 17556 | |
| 17557 | gdb_assert (per_cu->cu == NULL); |
| 17558 | |
| 17559 | read_signatured_type (sig_type); |
| 17560 | |
| 17561 | gdb_assert (per_cu->cu != NULL); |
| 17562 | } |
| 17563 | |
| 17564 | /* die_reader_func for read_signatured_type. |
| 17565 | This is identical to load_full_comp_unit_reader, |
| 17566 | but is kept separate for now. */ |
| 17567 | |
| 17568 | static void |
| 17569 | read_signatured_type_reader (const struct die_reader_specs *reader, |
| 17570 | gdb_byte *info_ptr, |
| 17571 | struct die_info *comp_unit_die, |
| 17572 | int has_children, |
| 17573 | void *data) |
| 17574 | { |
| 17575 | struct dwarf2_cu *cu = reader->cu; |
| 17576 | |
| 17577 | gdb_assert (cu->die_hash == NULL); |
| 17578 | cu->die_hash = |
| 17579 | htab_create_alloc_ex (cu->header.length / 12, |
| 17580 | die_hash, |
| 17581 | die_eq, |
| 17582 | NULL, |
| 17583 | &cu->comp_unit_obstack, |
| 17584 | hashtab_obstack_allocate, |
| 17585 | dummy_obstack_deallocate); |
| 17586 | |
| 17587 | if (has_children) |
| 17588 | comp_unit_die->child = read_die_and_siblings (reader, info_ptr, |
| 17589 | &info_ptr, comp_unit_die); |
| 17590 | cu->dies = comp_unit_die; |
| 17591 | /* comp_unit_die is not stored in die_hash, no need. */ |
| 17592 | |
| 17593 | /* We try not to read any attributes in this function, because not |
| 17594 | all CUs needed for references have been loaded yet, and symbol |
| 17595 | table processing isn't initialized. But we have to set the CU language, |
| 17596 | or we won't be able to build types correctly. |
| 17597 | Similarly, if we do not read the producer, we can not apply |
| 17598 | producer-specific interpretation. */ |
| 17599 | prepare_one_comp_unit (cu, cu->dies, language_minimal); |
| 17600 | } |
| 17601 | |
| 17602 | /* Read in a signatured type and build its CU and DIEs. |
| 17603 | If the type is a stub for the real type in a DWO file, |
| 17604 | read in the real type from the DWO file as well. */ |
| 17605 | |
| 17606 | static void |
| 17607 | read_signatured_type (struct signatured_type *sig_type) |
| 17608 | { |
| 17609 | struct dwarf2_per_cu_data *per_cu = &sig_type->per_cu; |
| 17610 | |
| 17611 | gdb_assert (per_cu->is_debug_types); |
| 17612 | gdb_assert (per_cu->cu == NULL); |
| 17613 | |
| 17614 | init_cutu_and_read_dies (per_cu, NULL, 0, 1, |
| 17615 | read_signatured_type_reader, NULL); |
| 17616 | } |
| 17617 | |
| 17618 | /* Decode simple location descriptions. |
| 17619 | Given a pointer to a dwarf block that defines a location, compute |
| 17620 | the location and return the value. |
| 17621 | |
| 17622 | NOTE drow/2003-11-18: This function is called in two situations |
| 17623 | now: for the address of static or global variables (partial symbols |
| 17624 | only) and for offsets into structures which are expected to be |
| 17625 | (more or less) constant. The partial symbol case should go away, |
| 17626 | and only the constant case should remain. That will let this |
| 17627 | function complain more accurately. A few special modes are allowed |
| 17628 | without complaint for global variables (for instance, global |
| 17629 | register values and thread-local values). |
| 17630 | |
| 17631 | A location description containing no operations indicates that the |
| 17632 | object is optimized out. The return value is 0 for that case. |
| 17633 | FIXME drow/2003-11-16: No callers check for this case any more; soon all |
| 17634 | callers will only want a very basic result and this can become a |
| 17635 | complaint. |
| 17636 | |
| 17637 | Note that stack[0] is unused except as a default error return. */ |
| 17638 | |
| 17639 | static CORE_ADDR |
| 17640 | decode_locdesc (struct dwarf_block *blk, struct dwarf2_cu *cu) |
| 17641 | { |
| 17642 | struct objfile *objfile = cu->objfile; |
| 17643 | size_t i; |
| 17644 | size_t size = blk->size; |
| 17645 | gdb_byte *data = blk->data; |
| 17646 | CORE_ADDR stack[64]; |
| 17647 | int stacki; |
| 17648 | unsigned int bytes_read, unsnd; |
| 17649 | gdb_byte op; |
| 17650 | |
| 17651 | i = 0; |
| 17652 | stacki = 0; |
| 17653 | stack[stacki] = 0; |
| 17654 | stack[++stacki] = 0; |
| 17655 | |
| 17656 | while (i < size) |
| 17657 | { |
| 17658 | op = data[i++]; |
| 17659 | switch (op) |
| 17660 | { |
| 17661 | case DW_OP_lit0: |
| 17662 | case DW_OP_lit1: |
| 17663 | case DW_OP_lit2: |
| 17664 | case DW_OP_lit3: |
| 17665 | case DW_OP_lit4: |
| 17666 | case DW_OP_lit5: |
| 17667 | case DW_OP_lit6: |
| 17668 | case DW_OP_lit7: |
| 17669 | case DW_OP_lit8: |
| 17670 | case DW_OP_lit9: |
| 17671 | case DW_OP_lit10: |
| 17672 | case DW_OP_lit11: |
| 17673 | case DW_OP_lit12: |
| 17674 | case DW_OP_lit13: |
| 17675 | case DW_OP_lit14: |
| 17676 | case DW_OP_lit15: |
| 17677 | case DW_OP_lit16: |
| 17678 | case DW_OP_lit17: |
| 17679 | case DW_OP_lit18: |
| 17680 | case DW_OP_lit19: |
| 17681 | case DW_OP_lit20: |
| 17682 | case DW_OP_lit21: |
| 17683 | case DW_OP_lit22: |
| 17684 | case DW_OP_lit23: |
| 17685 | case DW_OP_lit24: |
| 17686 | case DW_OP_lit25: |
| 17687 | case DW_OP_lit26: |
| 17688 | case DW_OP_lit27: |
| 17689 | case DW_OP_lit28: |
| 17690 | case DW_OP_lit29: |
| 17691 | case DW_OP_lit30: |
| 17692 | case DW_OP_lit31: |
| 17693 | stack[++stacki] = op - DW_OP_lit0; |
| 17694 | break; |
| 17695 | |
| 17696 | case DW_OP_reg0: |
| 17697 | case DW_OP_reg1: |
| 17698 | case DW_OP_reg2: |
| 17699 | case DW_OP_reg3: |
| 17700 | case DW_OP_reg4: |
| 17701 | case DW_OP_reg5: |
| 17702 | case DW_OP_reg6: |
| 17703 | case DW_OP_reg7: |
| 17704 | case DW_OP_reg8: |
| 17705 | case DW_OP_reg9: |
| 17706 | case DW_OP_reg10: |
| 17707 | case DW_OP_reg11: |
| 17708 | case DW_OP_reg12: |
| 17709 | case DW_OP_reg13: |
| 17710 | case DW_OP_reg14: |
| 17711 | case DW_OP_reg15: |
| 17712 | case DW_OP_reg16: |
| 17713 | case DW_OP_reg17: |
| 17714 | case DW_OP_reg18: |
| 17715 | case DW_OP_reg19: |
| 17716 | case DW_OP_reg20: |
| 17717 | case DW_OP_reg21: |
| 17718 | case DW_OP_reg22: |
| 17719 | case DW_OP_reg23: |
| 17720 | case DW_OP_reg24: |
| 17721 | case DW_OP_reg25: |
| 17722 | case DW_OP_reg26: |
| 17723 | case DW_OP_reg27: |
| 17724 | case DW_OP_reg28: |
| 17725 | case DW_OP_reg29: |
| 17726 | case DW_OP_reg30: |
| 17727 | case DW_OP_reg31: |
| 17728 | stack[++stacki] = op - DW_OP_reg0; |
| 17729 | if (i < size) |
| 17730 | dwarf2_complex_location_expr_complaint (); |
| 17731 | break; |
| 17732 | |
| 17733 | case DW_OP_regx: |
| 17734 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
| 17735 | i += bytes_read; |
| 17736 | stack[++stacki] = unsnd; |
| 17737 | if (i < size) |
| 17738 | dwarf2_complex_location_expr_complaint (); |
| 17739 | break; |
| 17740 | |
| 17741 | case DW_OP_addr: |
| 17742 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
| 17743 | cu, &bytes_read); |
| 17744 | i += bytes_read; |
| 17745 | break; |
| 17746 | |
| 17747 | case DW_OP_const1u: |
| 17748 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); |
| 17749 | i += 1; |
| 17750 | break; |
| 17751 | |
| 17752 | case DW_OP_const1s: |
| 17753 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); |
| 17754 | i += 1; |
| 17755 | break; |
| 17756 | |
| 17757 | case DW_OP_const2u: |
| 17758 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); |
| 17759 | i += 2; |
| 17760 | break; |
| 17761 | |
| 17762 | case DW_OP_const2s: |
| 17763 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); |
| 17764 | i += 2; |
| 17765 | break; |
| 17766 | |
| 17767 | case DW_OP_const4u: |
| 17768 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); |
| 17769 | i += 4; |
| 17770 | break; |
| 17771 | |
| 17772 | case DW_OP_const4s: |
| 17773 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); |
| 17774 | i += 4; |
| 17775 | break; |
| 17776 | |
| 17777 | case DW_OP_const8u: |
| 17778 | stack[++stacki] = read_8_bytes (objfile->obfd, &data[i]); |
| 17779 | i += 8; |
| 17780 | break; |
| 17781 | |
| 17782 | case DW_OP_constu: |
| 17783 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), |
| 17784 | &bytes_read); |
| 17785 | i += bytes_read; |
| 17786 | break; |
| 17787 | |
| 17788 | case DW_OP_consts: |
| 17789 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 17790 | i += bytes_read; |
| 17791 | break; |
| 17792 | |
| 17793 | case DW_OP_dup: |
| 17794 | stack[stacki + 1] = stack[stacki]; |
| 17795 | stacki++; |
| 17796 | break; |
| 17797 | |
| 17798 | case DW_OP_plus: |
| 17799 | stack[stacki - 1] += stack[stacki]; |
| 17800 | stacki--; |
| 17801 | break; |
| 17802 | |
| 17803 | case DW_OP_plus_uconst: |
| 17804 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), |
| 17805 | &bytes_read); |
| 17806 | i += bytes_read; |
| 17807 | break; |
| 17808 | |
| 17809 | case DW_OP_minus: |
| 17810 | stack[stacki - 1] -= stack[stacki]; |
| 17811 | stacki--; |
| 17812 | break; |
| 17813 | |
| 17814 | case DW_OP_deref: |
| 17815 | /* If we're not the last op, then we definitely can't encode |
| 17816 | this using GDB's address_class enum. This is valid for partial |
| 17817 | global symbols, although the variable's address will be bogus |
| 17818 | in the psymtab. */ |
| 17819 | if (i < size) |
| 17820 | dwarf2_complex_location_expr_complaint (); |
| 17821 | break; |
| 17822 | |
| 17823 | case DW_OP_GNU_push_tls_address: |
| 17824 | /* The top of the stack has the offset from the beginning |
| 17825 | of the thread control block at which the variable is located. */ |
| 17826 | /* Nothing should follow this operator, so the top of stack would |
| 17827 | be returned. */ |
| 17828 | /* This is valid for partial global symbols, but the variable's |
| 17829 | address will be bogus in the psymtab. Make it always at least |
| 17830 | non-zero to not look as a variable garbage collected by linker |
| 17831 | which have DW_OP_addr 0. */ |
| 17832 | if (i < size) |
| 17833 | dwarf2_complex_location_expr_complaint (); |
| 17834 | stack[stacki]++; |
| 17835 | break; |
| 17836 | |
| 17837 | case DW_OP_GNU_uninit: |
| 17838 | break; |
| 17839 | |
| 17840 | case DW_OP_GNU_addr_index: |
| 17841 | case DW_OP_GNU_const_index: |
| 17842 | stack[++stacki] = read_addr_index_from_leb128 (cu, &data[i], |
| 17843 | &bytes_read); |
| 17844 | i += bytes_read; |
| 17845 | break; |
| 17846 | |
| 17847 | default: |
| 17848 | { |
| 17849 | const char *name = get_DW_OP_name (op); |
| 17850 | |
| 17851 | if (name) |
| 17852 | complaint (&symfile_complaints, _("unsupported stack op: '%s'"), |
| 17853 | name); |
| 17854 | else |
| 17855 | complaint (&symfile_complaints, _("unsupported stack op: '%02x'"), |
| 17856 | op); |
| 17857 | } |
| 17858 | |
| 17859 | return (stack[stacki]); |
| 17860 | } |
| 17861 | |
| 17862 | /* Enforce maximum stack depth of SIZE-1 to avoid writing |
| 17863 | outside of the allocated space. Also enforce minimum>0. */ |
| 17864 | if (stacki >= ARRAY_SIZE (stack) - 1) |
| 17865 | { |
| 17866 | complaint (&symfile_complaints, |
| 17867 | _("location description stack overflow")); |
| 17868 | return 0; |
| 17869 | } |
| 17870 | |
| 17871 | if (stacki <= 0) |
| 17872 | { |
| 17873 | complaint (&symfile_complaints, |
| 17874 | _("location description stack underflow")); |
| 17875 | return 0; |
| 17876 | } |
| 17877 | } |
| 17878 | return (stack[stacki]); |
| 17879 | } |
| 17880 | |
| 17881 | /* memory allocation interface */ |
| 17882 | |
| 17883 | static struct dwarf_block * |
| 17884 | dwarf_alloc_block (struct dwarf2_cu *cu) |
| 17885 | { |
| 17886 | struct dwarf_block *blk; |
| 17887 | |
| 17888 | blk = (struct dwarf_block *) |
| 17889 | obstack_alloc (&cu->comp_unit_obstack, sizeof (struct dwarf_block)); |
| 17890 | return (blk); |
| 17891 | } |
| 17892 | |
| 17893 | static struct die_info * |
| 17894 | dwarf_alloc_die (struct dwarf2_cu *cu, int num_attrs) |
| 17895 | { |
| 17896 | struct die_info *die; |
| 17897 | size_t size = sizeof (struct die_info); |
| 17898 | |
| 17899 | if (num_attrs > 1) |
| 17900 | size += (num_attrs - 1) * sizeof (struct attribute); |
| 17901 | |
| 17902 | die = (struct die_info *) obstack_alloc (&cu->comp_unit_obstack, size); |
| 17903 | memset (die, 0, sizeof (struct die_info)); |
| 17904 | return (die); |
| 17905 | } |
| 17906 | |
| 17907 | \f |
| 17908 | /* Macro support. */ |
| 17909 | |
| 17910 | /* Return the full name of file number I in *LH's file name table. |
| 17911 | Use COMP_DIR as the name of the current directory of the |
| 17912 | compilation. The result is allocated using xmalloc; the caller is |
| 17913 | responsible for freeing it. */ |
| 17914 | static char * |
| 17915 | file_full_name (int file, struct line_header *lh, const char *comp_dir) |
| 17916 | { |
| 17917 | /* Is the file number a valid index into the line header's file name |
| 17918 | table? Remember that file numbers start with one, not zero. */ |
| 17919 | if (1 <= file && file <= lh->num_file_names) |
| 17920 | { |
| 17921 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 17922 | |
| 17923 | if (IS_ABSOLUTE_PATH (fe->name)) |
| 17924 | return xstrdup (fe->name); |
| 17925 | else |
| 17926 | { |
| 17927 | const char *dir; |
| 17928 | int dir_len; |
| 17929 | char *full_name; |
| 17930 | |
| 17931 | if (fe->dir_index) |
| 17932 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 17933 | else |
| 17934 | dir = comp_dir; |
| 17935 | |
| 17936 | if (dir) |
| 17937 | { |
| 17938 | dir_len = strlen (dir); |
| 17939 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); |
| 17940 | strcpy (full_name, dir); |
| 17941 | full_name[dir_len] = '/'; |
| 17942 | strcpy (full_name + dir_len + 1, fe->name); |
| 17943 | return full_name; |
| 17944 | } |
| 17945 | else |
| 17946 | return xstrdup (fe->name); |
| 17947 | } |
| 17948 | } |
| 17949 | else |
| 17950 | { |
| 17951 | /* The compiler produced a bogus file number. We can at least |
| 17952 | record the macro definitions made in the file, even if we |
| 17953 | won't be able to find the file by name. */ |
| 17954 | char fake_name[80]; |
| 17955 | |
| 17956 | xsnprintf (fake_name, sizeof (fake_name), |
| 17957 | "<bad macro file number %d>", file); |
| 17958 | |
| 17959 | complaint (&symfile_complaints, |
| 17960 | _("bad file number in macro information (%d)"), |
| 17961 | file); |
| 17962 | |
| 17963 | return xstrdup (fake_name); |
| 17964 | } |
| 17965 | } |
| 17966 | |
| 17967 | |
| 17968 | static struct macro_source_file * |
| 17969 | macro_start_file (int file, int line, |
| 17970 | struct macro_source_file *current_file, |
| 17971 | const char *comp_dir, |
| 17972 | struct line_header *lh, struct objfile *objfile) |
| 17973 | { |
| 17974 | /* The full name of this source file. */ |
| 17975 | char *full_name = file_full_name (file, lh, comp_dir); |
| 17976 | |
| 17977 | /* We don't create a macro table for this compilation unit |
| 17978 | at all until we actually get a filename. */ |
| 17979 | if (! pending_macros) |
| 17980 | pending_macros = new_macro_table (&objfile->per_bfd->storage_obstack, |
| 17981 | objfile->per_bfd->macro_cache); |
| 17982 | |
| 17983 | if (! current_file) |
| 17984 | { |
| 17985 | /* If we have no current file, then this must be the start_file |
| 17986 | directive for the compilation unit's main source file. */ |
| 17987 | current_file = macro_set_main (pending_macros, full_name); |
| 17988 | macro_define_special (pending_macros); |
| 17989 | } |
| 17990 | else |
| 17991 | current_file = macro_include (current_file, line, full_name); |
| 17992 | |
| 17993 | xfree (full_name); |
| 17994 | |
| 17995 | return current_file; |
| 17996 | } |
| 17997 | |
| 17998 | |
| 17999 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, |
| 18000 | followed by a null byte. */ |
| 18001 | static char * |
| 18002 | copy_string (const char *buf, int len) |
| 18003 | { |
| 18004 | char *s = xmalloc (len + 1); |
| 18005 | |
| 18006 | memcpy (s, buf, len); |
| 18007 | s[len] = '\0'; |
| 18008 | return s; |
| 18009 | } |
| 18010 | |
| 18011 | |
| 18012 | static const char * |
| 18013 | consume_improper_spaces (const char *p, const char *body) |
| 18014 | { |
| 18015 | if (*p == ' ') |
| 18016 | { |
| 18017 | complaint (&symfile_complaints, |
| 18018 | _("macro definition contains spaces " |
| 18019 | "in formal argument list:\n`%s'"), |
| 18020 | body); |
| 18021 | |
| 18022 | while (*p == ' ') |
| 18023 | p++; |
| 18024 | } |
| 18025 | |
| 18026 | return p; |
| 18027 | } |
| 18028 | |
| 18029 | |
| 18030 | static void |
| 18031 | parse_macro_definition (struct macro_source_file *file, int line, |
| 18032 | const char *body) |
| 18033 | { |
| 18034 | const char *p; |
| 18035 | |
| 18036 | /* The body string takes one of two forms. For object-like macro |
| 18037 | definitions, it should be: |
| 18038 | |
| 18039 | <macro name> " " <definition> |
| 18040 | |
| 18041 | For function-like macro definitions, it should be: |
| 18042 | |
| 18043 | <macro name> "() " <definition> |
| 18044 | or |
| 18045 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> |
| 18046 | |
| 18047 | Spaces may appear only where explicitly indicated, and in the |
| 18048 | <definition>. |
| 18049 | |
| 18050 | The Dwarf 2 spec says that an object-like macro's name is always |
| 18051 | followed by a space, but versions of GCC around March 2002 omit |
| 18052 | the space when the macro's definition is the empty string. |
| 18053 | |
| 18054 | The Dwarf 2 spec says that there should be no spaces between the |
| 18055 | formal arguments in a function-like macro's formal argument list, |
| 18056 | but versions of GCC around March 2002 include spaces after the |
| 18057 | commas. */ |
| 18058 | |
| 18059 | |
| 18060 | /* Find the extent of the macro name. The macro name is terminated |
| 18061 | by either a space or null character (for an object-like macro) or |
| 18062 | an opening paren (for a function-like macro). */ |
| 18063 | for (p = body; *p; p++) |
| 18064 | if (*p == ' ' || *p == '(') |
| 18065 | break; |
| 18066 | |
| 18067 | if (*p == ' ' || *p == '\0') |
| 18068 | { |
| 18069 | /* It's an object-like macro. */ |
| 18070 | int name_len = p - body; |
| 18071 | char *name = copy_string (body, name_len); |
| 18072 | const char *replacement; |
| 18073 | |
| 18074 | if (*p == ' ') |
| 18075 | replacement = body + name_len + 1; |
| 18076 | else |
| 18077 | { |
| 18078 | dwarf2_macro_malformed_definition_complaint (body); |
| 18079 | replacement = body + name_len; |
| 18080 | } |
| 18081 | |
| 18082 | macro_define_object (file, line, name, replacement); |
| 18083 | |
| 18084 | xfree (name); |
| 18085 | } |
| 18086 | else if (*p == '(') |
| 18087 | { |
| 18088 | /* It's a function-like macro. */ |
| 18089 | char *name = copy_string (body, p - body); |
| 18090 | int argc = 0; |
| 18091 | int argv_size = 1; |
| 18092 | char **argv = xmalloc (argv_size * sizeof (*argv)); |
| 18093 | |
| 18094 | p++; |
| 18095 | |
| 18096 | p = consume_improper_spaces (p, body); |
| 18097 | |
| 18098 | /* Parse the formal argument list. */ |
| 18099 | while (*p && *p != ')') |
| 18100 | { |
| 18101 | /* Find the extent of the current argument name. */ |
| 18102 | const char *arg_start = p; |
| 18103 | |
| 18104 | while (*p && *p != ',' && *p != ')' && *p != ' ') |
| 18105 | p++; |
| 18106 | |
| 18107 | if (! *p || p == arg_start) |
| 18108 | dwarf2_macro_malformed_definition_complaint (body); |
| 18109 | else |
| 18110 | { |
| 18111 | /* Make sure argv has room for the new argument. */ |
| 18112 | if (argc >= argv_size) |
| 18113 | { |
| 18114 | argv_size *= 2; |
| 18115 | argv = xrealloc (argv, argv_size * sizeof (*argv)); |
| 18116 | } |
| 18117 | |
| 18118 | argv[argc++] = copy_string (arg_start, p - arg_start); |
| 18119 | } |
| 18120 | |
| 18121 | p = consume_improper_spaces (p, body); |
| 18122 | |
| 18123 | /* Consume the comma, if present. */ |
| 18124 | if (*p == ',') |
| 18125 | { |
| 18126 | p++; |
| 18127 | |
| 18128 | p = consume_improper_spaces (p, body); |
| 18129 | } |
| 18130 | } |
| 18131 | |
| 18132 | if (*p == ')') |
| 18133 | { |
| 18134 | p++; |
| 18135 | |
| 18136 | if (*p == ' ') |
| 18137 | /* Perfectly formed definition, no complaints. */ |
| 18138 | macro_define_function (file, line, name, |
| 18139 | argc, (const char **) argv, |
| 18140 | p + 1); |
| 18141 | else if (*p == '\0') |
| 18142 | { |
| 18143 | /* Complain, but do define it. */ |
| 18144 | dwarf2_macro_malformed_definition_complaint (body); |
| 18145 | macro_define_function (file, line, name, |
| 18146 | argc, (const char **) argv, |
| 18147 | p); |
| 18148 | } |
| 18149 | else |
| 18150 | /* Just complain. */ |
| 18151 | dwarf2_macro_malformed_definition_complaint (body); |
| 18152 | } |
| 18153 | else |
| 18154 | /* Just complain. */ |
| 18155 | dwarf2_macro_malformed_definition_complaint (body); |
| 18156 | |
| 18157 | xfree (name); |
| 18158 | { |
| 18159 | int i; |
| 18160 | |
| 18161 | for (i = 0; i < argc; i++) |
| 18162 | xfree (argv[i]); |
| 18163 | } |
| 18164 | xfree (argv); |
| 18165 | } |
| 18166 | else |
| 18167 | dwarf2_macro_malformed_definition_complaint (body); |
| 18168 | } |
| 18169 | |
| 18170 | /* Skip some bytes from BYTES according to the form given in FORM. |
| 18171 | Returns the new pointer. */ |
| 18172 | |
| 18173 | static gdb_byte * |
| 18174 | skip_form_bytes (bfd *abfd, gdb_byte *bytes, gdb_byte *buffer_end, |
| 18175 | enum dwarf_form form, |
| 18176 | unsigned int offset_size, |
| 18177 | struct dwarf2_section_info *section) |
| 18178 | { |
| 18179 | unsigned int bytes_read; |
| 18180 | |
| 18181 | switch (form) |
| 18182 | { |
| 18183 | case DW_FORM_data1: |
| 18184 | case DW_FORM_flag: |
| 18185 | ++bytes; |
| 18186 | break; |
| 18187 | |
| 18188 | case DW_FORM_data2: |
| 18189 | bytes += 2; |
| 18190 | break; |
| 18191 | |
| 18192 | case DW_FORM_data4: |
| 18193 | bytes += 4; |
| 18194 | break; |
| 18195 | |
| 18196 | case DW_FORM_data8: |
| 18197 | bytes += 8; |
| 18198 | break; |
| 18199 | |
| 18200 | case DW_FORM_string: |
| 18201 | read_direct_string (abfd, bytes, &bytes_read); |
| 18202 | bytes += bytes_read; |
| 18203 | break; |
| 18204 | |
| 18205 | case DW_FORM_sec_offset: |
| 18206 | case DW_FORM_strp: |
| 18207 | case DW_FORM_GNU_strp_alt: |
| 18208 | bytes += offset_size; |
| 18209 | break; |
| 18210 | |
| 18211 | case DW_FORM_block: |
| 18212 | bytes += read_unsigned_leb128 (abfd, bytes, &bytes_read); |
| 18213 | bytes += bytes_read; |
| 18214 | break; |
| 18215 | |
| 18216 | case DW_FORM_block1: |
| 18217 | bytes += 1 + read_1_byte (abfd, bytes); |
| 18218 | break; |
| 18219 | case DW_FORM_block2: |
| 18220 | bytes += 2 + read_2_bytes (abfd, bytes); |
| 18221 | break; |
| 18222 | case DW_FORM_block4: |
| 18223 | bytes += 4 + read_4_bytes (abfd, bytes); |
| 18224 | break; |
| 18225 | |
| 18226 | case DW_FORM_sdata: |
| 18227 | case DW_FORM_udata: |
| 18228 | case DW_FORM_GNU_addr_index: |
| 18229 | case DW_FORM_GNU_str_index: |
| 18230 | bytes = (gdb_byte *) gdb_skip_leb128 (bytes, buffer_end); |
| 18231 | if (bytes == NULL) |
| 18232 | { |
| 18233 | dwarf2_section_buffer_overflow_complaint (section); |
| 18234 | return NULL; |
| 18235 | } |
| 18236 | break; |
| 18237 | |
| 18238 | default: |
| 18239 | { |
| 18240 | complain: |
| 18241 | complaint (&symfile_complaints, |
| 18242 | _("invalid form 0x%x in `%s'"), |
| 18243 | form, |
| 18244 | section->asection->name); |
| 18245 | return NULL; |
| 18246 | } |
| 18247 | } |
| 18248 | |
| 18249 | return bytes; |
| 18250 | } |
| 18251 | |
| 18252 | /* A helper for dwarf_decode_macros that handles skipping an unknown |
| 18253 | opcode. Returns an updated pointer to the macro data buffer; or, |
| 18254 | on error, issues a complaint and returns NULL. */ |
| 18255 | |
| 18256 | static gdb_byte * |
| 18257 | skip_unknown_opcode (unsigned int opcode, |
| 18258 | gdb_byte **opcode_definitions, |
| 18259 | gdb_byte *mac_ptr, gdb_byte *mac_end, |
| 18260 | bfd *abfd, |
| 18261 | unsigned int offset_size, |
| 18262 | struct dwarf2_section_info *section) |
| 18263 | { |
| 18264 | unsigned int bytes_read, i; |
| 18265 | unsigned long arg; |
| 18266 | gdb_byte *defn; |
| 18267 | |
| 18268 | if (opcode_definitions[opcode] == NULL) |
| 18269 | { |
| 18270 | complaint (&symfile_complaints, |
| 18271 | _("unrecognized DW_MACFINO opcode 0x%x"), |
| 18272 | opcode); |
| 18273 | return NULL; |
| 18274 | } |
| 18275 | |
| 18276 | defn = opcode_definitions[opcode]; |
| 18277 | arg = read_unsigned_leb128 (abfd, defn, &bytes_read); |
| 18278 | defn += bytes_read; |
| 18279 | |
| 18280 | for (i = 0; i < arg; ++i) |
| 18281 | { |
| 18282 | mac_ptr = skip_form_bytes (abfd, mac_ptr, mac_end, defn[i], offset_size, |
| 18283 | section); |
| 18284 | if (mac_ptr == NULL) |
| 18285 | { |
| 18286 | /* skip_form_bytes already issued the complaint. */ |
| 18287 | return NULL; |
| 18288 | } |
| 18289 | } |
| 18290 | |
| 18291 | return mac_ptr; |
| 18292 | } |
| 18293 | |
| 18294 | /* A helper function which parses the header of a macro section. |
| 18295 | If the macro section is the extended (for now called "GNU") type, |
| 18296 | then this updates *OFFSET_SIZE. Returns a pointer to just after |
| 18297 | the header, or issues a complaint and returns NULL on error. */ |
| 18298 | |
| 18299 | static gdb_byte * |
| 18300 | dwarf_parse_macro_header (gdb_byte **opcode_definitions, |
| 18301 | bfd *abfd, |
| 18302 | gdb_byte *mac_ptr, |
| 18303 | unsigned int *offset_size, |
| 18304 | int section_is_gnu) |
| 18305 | { |
| 18306 | memset (opcode_definitions, 0, 256 * sizeof (gdb_byte *)); |
| 18307 | |
| 18308 | if (section_is_gnu) |
| 18309 | { |
| 18310 | unsigned int version, flags; |
| 18311 | |
| 18312 | version = read_2_bytes (abfd, mac_ptr); |
| 18313 | if (version != 4) |
| 18314 | { |
| 18315 | complaint (&symfile_complaints, |
| 18316 | _("unrecognized version `%d' in .debug_macro section"), |
| 18317 | version); |
| 18318 | return NULL; |
| 18319 | } |
| 18320 | mac_ptr += 2; |
| 18321 | |
| 18322 | flags = read_1_byte (abfd, mac_ptr); |
| 18323 | ++mac_ptr; |
| 18324 | *offset_size = (flags & 1) ? 8 : 4; |
| 18325 | |
| 18326 | if ((flags & 2) != 0) |
| 18327 | /* We don't need the line table offset. */ |
| 18328 | mac_ptr += *offset_size; |
| 18329 | |
| 18330 | /* Vendor opcode descriptions. */ |
| 18331 | if ((flags & 4) != 0) |
| 18332 | { |
| 18333 | unsigned int i, count; |
| 18334 | |
| 18335 | count = read_1_byte (abfd, mac_ptr); |
| 18336 | ++mac_ptr; |
| 18337 | for (i = 0; i < count; ++i) |
| 18338 | { |
| 18339 | unsigned int opcode, bytes_read; |
| 18340 | unsigned long arg; |
| 18341 | |
| 18342 | opcode = read_1_byte (abfd, mac_ptr); |
| 18343 | ++mac_ptr; |
| 18344 | opcode_definitions[opcode] = mac_ptr; |
| 18345 | arg = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18346 | mac_ptr += bytes_read; |
| 18347 | mac_ptr += arg; |
| 18348 | } |
| 18349 | } |
| 18350 | } |
| 18351 | |
| 18352 | return mac_ptr; |
| 18353 | } |
| 18354 | |
| 18355 | /* A helper for dwarf_decode_macros that handles the GNU extensions, |
| 18356 | including DW_MACRO_GNU_transparent_include. */ |
| 18357 | |
| 18358 | static void |
| 18359 | dwarf_decode_macro_bytes (bfd *abfd, gdb_byte *mac_ptr, gdb_byte *mac_end, |
| 18360 | struct macro_source_file *current_file, |
| 18361 | struct line_header *lh, char *comp_dir, |
| 18362 | struct dwarf2_section_info *section, |
| 18363 | int section_is_gnu, int section_is_dwz, |
| 18364 | unsigned int offset_size, |
| 18365 | struct objfile *objfile, |
| 18366 | htab_t include_hash) |
| 18367 | { |
| 18368 | enum dwarf_macro_record_type macinfo_type; |
| 18369 | int at_commandline; |
| 18370 | gdb_byte *opcode_definitions[256]; |
| 18371 | |
| 18372 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
| 18373 | &offset_size, section_is_gnu); |
| 18374 | if (mac_ptr == NULL) |
| 18375 | { |
| 18376 | /* We already issued a complaint. */ |
| 18377 | return; |
| 18378 | } |
| 18379 | |
| 18380 | /* Determines if GDB is still before first DW_MACINFO_start_file. If true |
| 18381 | GDB is still reading the definitions from command line. First |
| 18382 | DW_MACINFO_start_file will need to be ignored as it was already executed |
| 18383 | to create CURRENT_FILE for the main source holding also the command line |
| 18384 | definitions. On first met DW_MACINFO_start_file this flag is reset to |
| 18385 | normally execute all the remaining DW_MACINFO_start_file macinfos. */ |
| 18386 | |
| 18387 | at_commandline = 1; |
| 18388 | |
| 18389 | do |
| 18390 | { |
| 18391 | /* Do we at least have room for a macinfo type byte? */ |
| 18392 | if (mac_ptr >= mac_end) |
| 18393 | { |
| 18394 | dwarf2_section_buffer_overflow_complaint (section); |
| 18395 | break; |
| 18396 | } |
| 18397 | |
| 18398 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 18399 | mac_ptr++; |
| 18400 | |
| 18401 | /* Note that we rely on the fact that the corresponding GNU and |
| 18402 | DWARF constants are the same. */ |
| 18403 | switch (macinfo_type) |
| 18404 | { |
| 18405 | /* A zero macinfo type indicates the end of the macro |
| 18406 | information. */ |
| 18407 | case 0: |
| 18408 | break; |
| 18409 | |
| 18410 | case DW_MACRO_GNU_define: |
| 18411 | case DW_MACRO_GNU_undef: |
| 18412 | case DW_MACRO_GNU_define_indirect: |
| 18413 | case DW_MACRO_GNU_undef_indirect: |
| 18414 | case DW_MACRO_GNU_define_indirect_alt: |
| 18415 | case DW_MACRO_GNU_undef_indirect_alt: |
| 18416 | { |
| 18417 | unsigned int bytes_read; |
| 18418 | int line; |
| 18419 | char *body; |
| 18420 | int is_define; |
| 18421 | |
| 18422 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18423 | mac_ptr += bytes_read; |
| 18424 | |
| 18425 | if (macinfo_type == DW_MACRO_GNU_define |
| 18426 | || macinfo_type == DW_MACRO_GNU_undef) |
| 18427 | { |
| 18428 | body = read_direct_string (abfd, mac_ptr, &bytes_read); |
| 18429 | mac_ptr += bytes_read; |
| 18430 | } |
| 18431 | else |
| 18432 | { |
| 18433 | LONGEST str_offset; |
| 18434 | |
| 18435 | str_offset = read_offset_1 (abfd, mac_ptr, offset_size); |
| 18436 | mac_ptr += offset_size; |
| 18437 | |
| 18438 | if (macinfo_type == DW_MACRO_GNU_define_indirect_alt |
| 18439 | || macinfo_type == DW_MACRO_GNU_undef_indirect_alt |
| 18440 | || section_is_dwz) |
| 18441 | { |
| 18442 | struct dwz_file *dwz = dwarf2_get_dwz_file (); |
| 18443 | |
| 18444 | body = read_indirect_string_from_dwz (dwz, str_offset); |
| 18445 | } |
| 18446 | else |
| 18447 | body = read_indirect_string_at_offset (abfd, str_offset); |
| 18448 | } |
| 18449 | |
| 18450 | is_define = (macinfo_type == DW_MACRO_GNU_define |
| 18451 | || macinfo_type == DW_MACRO_GNU_define_indirect |
| 18452 | || macinfo_type == DW_MACRO_GNU_define_indirect_alt); |
| 18453 | if (! current_file) |
| 18454 | { |
| 18455 | /* DWARF violation as no main source is present. */ |
| 18456 | complaint (&symfile_complaints, |
| 18457 | _("debug info with no main source gives macro %s " |
| 18458 | "on line %d: %s"), |
| 18459 | is_define ? _("definition") : _("undefinition"), |
| 18460 | line, body); |
| 18461 | break; |
| 18462 | } |
| 18463 | if ((line == 0 && !at_commandline) |
| 18464 | || (line != 0 && at_commandline)) |
| 18465 | complaint (&symfile_complaints, |
| 18466 | _("debug info gives %s macro %s with %s line %d: %s"), |
| 18467 | at_commandline ? _("command-line") : _("in-file"), |
| 18468 | is_define ? _("definition") : _("undefinition"), |
| 18469 | line == 0 ? _("zero") : _("non-zero"), line, body); |
| 18470 | |
| 18471 | if (is_define) |
| 18472 | parse_macro_definition (current_file, line, body); |
| 18473 | else |
| 18474 | { |
| 18475 | gdb_assert (macinfo_type == DW_MACRO_GNU_undef |
| 18476 | || macinfo_type == DW_MACRO_GNU_undef_indirect |
| 18477 | || macinfo_type == DW_MACRO_GNU_undef_indirect_alt); |
| 18478 | macro_undef (current_file, line, body); |
| 18479 | } |
| 18480 | } |
| 18481 | break; |
| 18482 | |
| 18483 | case DW_MACRO_GNU_start_file: |
| 18484 | { |
| 18485 | unsigned int bytes_read; |
| 18486 | int line, file; |
| 18487 | |
| 18488 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18489 | mac_ptr += bytes_read; |
| 18490 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18491 | mac_ptr += bytes_read; |
| 18492 | |
| 18493 | if ((line == 0 && !at_commandline) |
| 18494 | || (line != 0 && at_commandline)) |
| 18495 | complaint (&symfile_complaints, |
| 18496 | _("debug info gives source %d included " |
| 18497 | "from %s at %s line %d"), |
| 18498 | file, at_commandline ? _("command-line") : _("file"), |
| 18499 | line == 0 ? _("zero") : _("non-zero"), line); |
| 18500 | |
| 18501 | if (at_commandline) |
| 18502 | { |
| 18503 | /* This DW_MACRO_GNU_start_file was executed in the |
| 18504 | pass one. */ |
| 18505 | at_commandline = 0; |
| 18506 | } |
| 18507 | else |
| 18508 | current_file = macro_start_file (file, line, |
| 18509 | current_file, comp_dir, |
| 18510 | lh, objfile); |
| 18511 | } |
| 18512 | break; |
| 18513 | |
| 18514 | case DW_MACRO_GNU_end_file: |
| 18515 | if (! current_file) |
| 18516 | complaint (&symfile_complaints, |
| 18517 | _("macro debug info has an unmatched " |
| 18518 | "`close_file' directive")); |
| 18519 | else |
| 18520 | { |
| 18521 | current_file = current_file->included_by; |
| 18522 | if (! current_file) |
| 18523 | { |
| 18524 | enum dwarf_macro_record_type next_type; |
| 18525 | |
| 18526 | /* GCC circa March 2002 doesn't produce the zero |
| 18527 | type byte marking the end of the compilation |
| 18528 | unit. Complain if it's not there, but exit no |
| 18529 | matter what. */ |
| 18530 | |
| 18531 | /* Do we at least have room for a macinfo type byte? */ |
| 18532 | if (mac_ptr >= mac_end) |
| 18533 | { |
| 18534 | dwarf2_section_buffer_overflow_complaint (section); |
| 18535 | return; |
| 18536 | } |
| 18537 | |
| 18538 | /* We don't increment mac_ptr here, so this is just |
| 18539 | a look-ahead. */ |
| 18540 | next_type = read_1_byte (abfd, mac_ptr); |
| 18541 | if (next_type != 0) |
| 18542 | complaint (&symfile_complaints, |
| 18543 | _("no terminating 0-type entry for " |
| 18544 | "macros in `.debug_macinfo' section")); |
| 18545 | |
| 18546 | return; |
| 18547 | } |
| 18548 | } |
| 18549 | break; |
| 18550 | |
| 18551 | case DW_MACRO_GNU_transparent_include: |
| 18552 | case DW_MACRO_GNU_transparent_include_alt: |
| 18553 | { |
| 18554 | LONGEST offset; |
| 18555 | void **slot; |
| 18556 | bfd *include_bfd = abfd; |
| 18557 | struct dwarf2_section_info *include_section = section; |
| 18558 | struct dwarf2_section_info alt_section; |
| 18559 | gdb_byte *include_mac_end = mac_end; |
| 18560 | int is_dwz = section_is_dwz; |
| 18561 | gdb_byte *new_mac_ptr; |
| 18562 | |
| 18563 | offset = read_offset_1 (abfd, mac_ptr, offset_size); |
| 18564 | mac_ptr += offset_size; |
| 18565 | |
| 18566 | if (macinfo_type == DW_MACRO_GNU_transparent_include_alt) |
| 18567 | { |
| 18568 | struct dwz_file *dwz = dwarf2_get_dwz_file (); |
| 18569 | |
| 18570 | dwarf2_read_section (dwarf2_per_objfile->objfile, |
| 18571 | &dwz->macro); |
| 18572 | |
| 18573 | include_bfd = dwz->macro.asection->owner; |
| 18574 | include_section = &dwz->macro; |
| 18575 | include_mac_end = dwz->macro.buffer + dwz->macro.size; |
| 18576 | is_dwz = 1; |
| 18577 | } |
| 18578 | |
| 18579 | new_mac_ptr = include_section->buffer + offset; |
| 18580 | slot = htab_find_slot (include_hash, new_mac_ptr, INSERT); |
| 18581 | |
| 18582 | if (*slot != NULL) |
| 18583 | { |
| 18584 | /* This has actually happened; see |
| 18585 | http://sourceware.org/bugzilla/show_bug.cgi?id=13568. */ |
| 18586 | complaint (&symfile_complaints, |
| 18587 | _("recursive DW_MACRO_GNU_transparent_include in " |
| 18588 | ".debug_macro section")); |
| 18589 | } |
| 18590 | else |
| 18591 | { |
| 18592 | *slot = new_mac_ptr; |
| 18593 | |
| 18594 | dwarf_decode_macro_bytes (include_bfd, new_mac_ptr, |
| 18595 | include_mac_end, current_file, |
| 18596 | lh, comp_dir, |
| 18597 | section, section_is_gnu, is_dwz, |
| 18598 | offset_size, objfile, include_hash); |
| 18599 | |
| 18600 | htab_remove_elt (include_hash, new_mac_ptr); |
| 18601 | } |
| 18602 | } |
| 18603 | break; |
| 18604 | |
| 18605 | case DW_MACINFO_vendor_ext: |
| 18606 | if (!section_is_gnu) |
| 18607 | { |
| 18608 | unsigned int bytes_read; |
| 18609 | int constant; |
| 18610 | |
| 18611 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18612 | mac_ptr += bytes_read; |
| 18613 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 18614 | mac_ptr += bytes_read; |
| 18615 | |
| 18616 | /* We don't recognize any vendor extensions. */ |
| 18617 | break; |
| 18618 | } |
| 18619 | /* FALLTHROUGH */ |
| 18620 | |
| 18621 | default: |
| 18622 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, |
| 18623 | mac_ptr, mac_end, abfd, offset_size, |
| 18624 | section); |
| 18625 | if (mac_ptr == NULL) |
| 18626 | return; |
| 18627 | break; |
| 18628 | } |
| 18629 | } while (macinfo_type != 0); |
| 18630 | } |
| 18631 | |
| 18632 | static void |
| 18633 | dwarf_decode_macros (struct dwarf2_cu *cu, unsigned int offset, |
| 18634 | char *comp_dir, int section_is_gnu) |
| 18635 | { |
| 18636 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 18637 | struct line_header *lh = cu->line_header; |
| 18638 | bfd *abfd; |
| 18639 | gdb_byte *mac_ptr, *mac_end; |
| 18640 | struct macro_source_file *current_file = 0; |
| 18641 | enum dwarf_macro_record_type macinfo_type; |
| 18642 | unsigned int offset_size = cu->header.offset_size; |
| 18643 | gdb_byte *opcode_definitions[256]; |
| 18644 | struct cleanup *cleanup; |
| 18645 | htab_t include_hash; |
| 18646 | void **slot; |
| 18647 | struct dwarf2_section_info *section; |
| 18648 | const char *section_name; |
| 18649 | |
| 18650 | if (cu->dwo_unit != NULL) |
| 18651 | { |
| 18652 | if (section_is_gnu) |
| 18653 | { |
| 18654 | section = &cu->dwo_unit->dwo_file->sections.macro; |
| 18655 | section_name = ".debug_macro.dwo"; |
| 18656 | } |
| 18657 | else |
| 18658 | { |
| 18659 | section = &cu->dwo_unit->dwo_file->sections.macinfo; |
| 18660 | section_name = ".debug_macinfo.dwo"; |
| 18661 | } |
| 18662 | } |
| 18663 | else |
| 18664 | { |
| 18665 | if (section_is_gnu) |
| 18666 | { |
| 18667 | section = &dwarf2_per_objfile->macro; |
| 18668 | section_name = ".debug_macro"; |
| 18669 | } |
| 18670 | else |
| 18671 | { |
| 18672 | section = &dwarf2_per_objfile->macinfo; |
| 18673 | section_name = ".debug_macinfo"; |
| 18674 | } |
| 18675 | } |
| 18676 | |
| 18677 | dwarf2_read_section (objfile, section); |
| 18678 | if (section->buffer == NULL) |
| 18679 | { |
| 18680 | complaint (&symfile_complaints, _("missing %s section"), section_name); |
| 18681 | return; |
| 18682 | } |
| 18683 | abfd = section->asection->owner; |
| 18684 | |
| 18685 | /* First pass: Find the name of the base filename. |
| 18686 | This filename is needed in order to process all macros whose definition |
| 18687 | (or undefinition) comes from the command line. These macros are defined |
| 18688 | before the first DW_MACINFO_start_file entry, and yet still need to be |
| 18689 | associated to the base file. |
| 18690 | |
| 18691 | To determine the base file name, we scan the macro definitions until we |
| 18692 | reach the first DW_MACINFO_start_file entry. We then initialize |
| 18693 | CURRENT_FILE accordingly so that any macro definition found before the |
| 18694 | first DW_MACINFO_start_file can still be associated to the base file. */ |
| 18695 | |
| 18696 | mac_ptr = section->buffer + offset; |
| 18697 | mac_end = section->buffer + section->size; |
| 18698 | |
| 18699 | mac_ptr = dwarf_parse_macro_header (opcode_definitions, abfd, mac_ptr, |
| 18700 | &offset_size, section_is_gnu); |
| 18701 | if (mac_ptr == NULL) |
| 18702 | { |
| 18703 | /* We already issued a complaint. */ |
| 18704 | return; |
| 18705 | } |
| 18706 | |
| 18707 | do |
| 18708 | { |
| 18709 | /* Do we at least have room for a macinfo type byte? */ |
| 18710 | if (mac_ptr >= mac_end) |
| 18711 | { |
| 18712 | /* Complaint is printed during the second pass as GDB will probably |
| 18713 | stop the first pass earlier upon finding |
| 18714 | DW_MACINFO_start_file. */ |
| 18715 | break; |
| 18716 | } |
| 18717 | |
| 18718 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 18719 | mac_ptr++; |
| 18720 | |
| 18721 | /* Note that we rely on the fact that the corresponding GNU and |
| 18722 | DWARF constants are the same. */ |
| 18723 | switch (macinfo_type) |
| 18724 | { |
| 18725 | /* A zero macinfo type indicates the end of the macro |
| 18726 | information. */ |
| 18727 | case 0: |
| 18728 | break; |
| 18729 | |
| 18730 | case DW_MACRO_GNU_define: |
| 18731 | case DW_MACRO_GNU_undef: |
| 18732 | /* Only skip the data by MAC_PTR. */ |
| 18733 | { |
| 18734 | unsigned int bytes_read; |
| 18735 | |
| 18736 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18737 | mac_ptr += bytes_read; |
| 18738 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 18739 | mac_ptr += bytes_read; |
| 18740 | } |
| 18741 | break; |
| 18742 | |
| 18743 | case DW_MACRO_GNU_start_file: |
| 18744 | { |
| 18745 | unsigned int bytes_read; |
| 18746 | int line, file; |
| 18747 | |
| 18748 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18749 | mac_ptr += bytes_read; |
| 18750 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18751 | mac_ptr += bytes_read; |
| 18752 | |
| 18753 | current_file = macro_start_file (file, line, current_file, |
| 18754 | comp_dir, lh, objfile); |
| 18755 | } |
| 18756 | break; |
| 18757 | |
| 18758 | case DW_MACRO_GNU_end_file: |
| 18759 | /* No data to skip by MAC_PTR. */ |
| 18760 | break; |
| 18761 | |
| 18762 | case DW_MACRO_GNU_define_indirect: |
| 18763 | case DW_MACRO_GNU_undef_indirect: |
| 18764 | case DW_MACRO_GNU_define_indirect_alt: |
| 18765 | case DW_MACRO_GNU_undef_indirect_alt: |
| 18766 | { |
| 18767 | unsigned int bytes_read; |
| 18768 | |
| 18769 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18770 | mac_ptr += bytes_read; |
| 18771 | mac_ptr += offset_size; |
| 18772 | } |
| 18773 | break; |
| 18774 | |
| 18775 | case DW_MACRO_GNU_transparent_include: |
| 18776 | case DW_MACRO_GNU_transparent_include_alt: |
| 18777 | /* Note that, according to the spec, a transparent include |
| 18778 | chain cannot call DW_MACRO_GNU_start_file. So, we can just |
| 18779 | skip this opcode. */ |
| 18780 | mac_ptr += offset_size; |
| 18781 | break; |
| 18782 | |
| 18783 | case DW_MACINFO_vendor_ext: |
| 18784 | /* Only skip the data by MAC_PTR. */ |
| 18785 | if (!section_is_gnu) |
| 18786 | { |
| 18787 | unsigned int bytes_read; |
| 18788 | |
| 18789 | read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 18790 | mac_ptr += bytes_read; |
| 18791 | read_direct_string (abfd, mac_ptr, &bytes_read); |
| 18792 | mac_ptr += bytes_read; |
| 18793 | } |
| 18794 | /* FALLTHROUGH */ |
| 18795 | |
| 18796 | default: |
| 18797 | mac_ptr = skip_unknown_opcode (macinfo_type, opcode_definitions, |
| 18798 | mac_ptr, mac_end, abfd, offset_size, |
| 18799 | section); |
| 18800 | if (mac_ptr == NULL) |
| 18801 | return; |
| 18802 | break; |
| 18803 | } |
| 18804 | } while (macinfo_type != 0 && current_file == NULL); |
| 18805 | |
| 18806 | /* Second pass: Process all entries. |
| 18807 | |
| 18808 | Use the AT_COMMAND_LINE flag to determine whether we are still processing |
| 18809 | command-line macro definitions/undefinitions. This flag is unset when we |
| 18810 | reach the first DW_MACINFO_start_file entry. */ |
| 18811 | |
| 18812 | include_hash = htab_create_alloc (1, htab_hash_pointer, htab_eq_pointer, |
| 18813 | NULL, xcalloc, xfree); |
| 18814 | cleanup = make_cleanup_htab_delete (include_hash); |
| 18815 | mac_ptr = section->buffer + offset; |
| 18816 | slot = htab_find_slot (include_hash, mac_ptr, INSERT); |
| 18817 | *slot = mac_ptr; |
| 18818 | dwarf_decode_macro_bytes (abfd, mac_ptr, mac_end, |
| 18819 | current_file, lh, comp_dir, section, |
| 18820 | section_is_gnu, 0, |
| 18821 | offset_size, objfile, include_hash); |
| 18822 | do_cleanups (cleanup); |
| 18823 | } |
| 18824 | |
| 18825 | /* Check if the attribute's form is a DW_FORM_block* |
| 18826 | if so return true else false. */ |
| 18827 | |
| 18828 | static int |
| 18829 | attr_form_is_block (struct attribute *attr) |
| 18830 | { |
| 18831 | return (attr == NULL ? 0 : |
| 18832 | attr->form == DW_FORM_block1 |
| 18833 | || attr->form == DW_FORM_block2 |
| 18834 | || attr->form == DW_FORM_block4 |
| 18835 | || attr->form == DW_FORM_block |
| 18836 | || attr->form == DW_FORM_exprloc); |
| 18837 | } |
| 18838 | |
| 18839 | /* Return non-zero if ATTR's value is a section offset --- classes |
| 18840 | lineptr, loclistptr, macptr or rangelistptr --- or zero, otherwise. |
| 18841 | You may use DW_UNSND (attr) to retrieve such offsets. |
| 18842 | |
| 18843 | Section 7.5.4, "Attribute Encodings", explains that no attribute |
| 18844 | may have a value that belongs to more than one of these classes; it |
| 18845 | would be ambiguous if we did, because we use the same forms for all |
| 18846 | of them. */ |
| 18847 | |
| 18848 | static int |
| 18849 | attr_form_is_section_offset (struct attribute *attr) |
| 18850 | { |
| 18851 | return (attr->form == DW_FORM_data4 |
| 18852 | || attr->form == DW_FORM_data8 |
| 18853 | || attr->form == DW_FORM_sec_offset); |
| 18854 | } |
| 18855 | |
| 18856 | /* Return non-zero if ATTR's value falls in the 'constant' class, or |
| 18857 | zero otherwise. When this function returns true, you can apply |
| 18858 | dwarf2_get_attr_constant_value to it. |
| 18859 | |
| 18860 | However, note that for some attributes you must check |
| 18861 | attr_form_is_section_offset before using this test. DW_FORM_data4 |
| 18862 | and DW_FORM_data8 are members of both the constant class, and of |
| 18863 | the classes that contain offsets into other debug sections |
| 18864 | (lineptr, loclistptr, macptr or rangelistptr). The DWARF spec says |
| 18865 | that, if an attribute's can be either a constant or one of the |
| 18866 | section offset classes, DW_FORM_data4 and DW_FORM_data8 should be |
| 18867 | taken as section offsets, not constants. */ |
| 18868 | |
| 18869 | static int |
| 18870 | attr_form_is_constant (struct attribute *attr) |
| 18871 | { |
| 18872 | switch (attr->form) |
| 18873 | { |
| 18874 | case DW_FORM_sdata: |
| 18875 | case DW_FORM_udata: |
| 18876 | case DW_FORM_data1: |
| 18877 | case DW_FORM_data2: |
| 18878 | case DW_FORM_data4: |
| 18879 | case DW_FORM_data8: |
| 18880 | return 1; |
| 18881 | default: |
| 18882 | return 0; |
| 18883 | } |
| 18884 | } |
| 18885 | |
| 18886 | /* Return the .debug_loc section to use for CU. |
| 18887 | For DWO files use .debug_loc.dwo. */ |
| 18888 | |
| 18889 | static struct dwarf2_section_info * |
| 18890 | cu_debug_loc_section (struct dwarf2_cu *cu) |
| 18891 | { |
| 18892 | if (cu->dwo_unit) |
| 18893 | return &cu->dwo_unit->dwo_file->sections.loc; |
| 18894 | return &dwarf2_per_objfile->loc; |
| 18895 | } |
| 18896 | |
| 18897 | /* A helper function that fills in a dwarf2_loclist_baton. */ |
| 18898 | |
| 18899 | static void |
| 18900 | fill_in_loclist_baton (struct dwarf2_cu *cu, |
| 18901 | struct dwarf2_loclist_baton *baton, |
| 18902 | struct attribute *attr) |
| 18903 | { |
| 18904 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
| 18905 | |
| 18906 | dwarf2_read_section (dwarf2_per_objfile->objfile, section); |
| 18907 | |
| 18908 | baton->per_cu = cu->per_cu; |
| 18909 | gdb_assert (baton->per_cu); |
| 18910 | /* We don't know how long the location list is, but make sure we |
| 18911 | don't run off the edge of the section. */ |
| 18912 | baton->size = section->size - DW_UNSND (attr); |
| 18913 | baton->data = section->buffer + DW_UNSND (attr); |
| 18914 | baton->base_address = cu->base_address; |
| 18915 | baton->from_dwo = cu->dwo_unit != NULL; |
| 18916 | } |
| 18917 | |
| 18918 | static void |
| 18919 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, |
| 18920 | struct dwarf2_cu *cu) |
| 18921 | { |
| 18922 | struct objfile *objfile = dwarf2_per_objfile->objfile; |
| 18923 | struct dwarf2_section_info *section = cu_debug_loc_section (cu); |
| 18924 | |
| 18925 | if (attr_form_is_section_offset (attr) |
| 18926 | /* .debug_loc{,.dwo} may not exist at all, or the offset may be outside |
| 18927 | the section. If so, fall through to the complaint in the |
| 18928 | other branch. */ |
| 18929 | && DW_UNSND (attr) < dwarf2_section_size (objfile, section)) |
| 18930 | { |
| 18931 | struct dwarf2_loclist_baton *baton; |
| 18932 | |
| 18933 | baton = obstack_alloc (&objfile->objfile_obstack, |
| 18934 | sizeof (struct dwarf2_loclist_baton)); |
| 18935 | |
| 18936 | fill_in_loclist_baton (cu, baton, attr); |
| 18937 | |
| 18938 | if (cu->base_known == 0) |
| 18939 | complaint (&symfile_complaints, |
| 18940 | _("Location list used without " |
| 18941 | "specifying the CU base address.")); |
| 18942 | |
| 18943 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_loclist_funcs; |
| 18944 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 18945 | } |
| 18946 | else |
| 18947 | { |
| 18948 | struct dwarf2_locexpr_baton *baton; |
| 18949 | |
| 18950 | baton = obstack_alloc (&objfile->objfile_obstack, |
| 18951 | sizeof (struct dwarf2_locexpr_baton)); |
| 18952 | baton->per_cu = cu->per_cu; |
| 18953 | gdb_assert (baton->per_cu); |
| 18954 | |
| 18955 | if (attr_form_is_block (attr)) |
| 18956 | { |
| 18957 | /* Note that we're just copying the block's data pointer |
| 18958 | here, not the actual data. We're still pointing into the |
| 18959 | info_buffer for SYM's objfile; right now we never release |
| 18960 | that buffer, but when we do clean up properly this may |
| 18961 | need to change. */ |
| 18962 | baton->size = DW_BLOCK (attr)->size; |
| 18963 | baton->data = DW_BLOCK (attr)->data; |
| 18964 | } |
| 18965 | else |
| 18966 | { |
| 18967 | dwarf2_invalid_attrib_class_complaint ("location description", |
| 18968 | SYMBOL_NATURAL_NAME (sym)); |
| 18969 | baton->size = 0; |
| 18970 | } |
| 18971 | |
| 18972 | SYMBOL_COMPUTED_OPS (sym) = &dwarf2_locexpr_funcs; |
| 18973 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 18974 | } |
| 18975 | } |
| 18976 | |
| 18977 | /* Return the OBJFILE associated with the compilation unit CU. If CU |
| 18978 | came from a separate debuginfo file, then the master objfile is |
| 18979 | returned. */ |
| 18980 | |
| 18981 | struct objfile * |
| 18982 | dwarf2_per_cu_objfile (struct dwarf2_per_cu_data *per_cu) |
| 18983 | { |
| 18984 | struct objfile *objfile = per_cu->objfile; |
| 18985 | |
| 18986 | /* Return the master objfile, so that we can report and look up the |
| 18987 | correct file containing this variable. */ |
| 18988 | if (objfile->separate_debug_objfile_backlink) |
| 18989 | objfile = objfile->separate_debug_objfile_backlink; |
| 18990 | |
| 18991 | return objfile; |
| 18992 | } |
| 18993 | |
| 18994 | /* Return comp_unit_head for PER_CU, either already available in PER_CU->CU |
| 18995 | (CU_HEADERP is unused in such case) or prepare a temporary copy at |
| 18996 | CU_HEADERP first. */ |
| 18997 | |
| 18998 | static const struct comp_unit_head * |
| 18999 | per_cu_header_read_in (struct comp_unit_head *cu_headerp, |
| 19000 | struct dwarf2_per_cu_data *per_cu) |
| 19001 | { |
| 19002 | gdb_byte *info_ptr; |
| 19003 | |
| 19004 | if (per_cu->cu) |
| 19005 | return &per_cu->cu->header; |
| 19006 | |
| 19007 | info_ptr = per_cu->info_or_types_section->buffer + per_cu->offset.sect_off; |
| 19008 | |
| 19009 | memset (cu_headerp, 0, sizeof (*cu_headerp)); |
| 19010 | read_comp_unit_head (cu_headerp, info_ptr, per_cu->objfile->obfd); |
| 19011 | |
| 19012 | return cu_headerp; |
| 19013 | } |
| 19014 | |
| 19015 | /* Return the address size given in the compilation unit header for CU. */ |
| 19016 | |
| 19017 | int |
| 19018 | dwarf2_per_cu_addr_size (struct dwarf2_per_cu_data *per_cu) |
| 19019 | { |
| 19020 | struct comp_unit_head cu_header_local; |
| 19021 | const struct comp_unit_head *cu_headerp; |
| 19022 | |
| 19023 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
| 19024 | |
| 19025 | return cu_headerp->addr_size; |
| 19026 | } |
| 19027 | |
| 19028 | /* Return the offset size given in the compilation unit header for CU. */ |
| 19029 | |
| 19030 | int |
| 19031 | dwarf2_per_cu_offset_size (struct dwarf2_per_cu_data *per_cu) |
| 19032 | { |
| 19033 | struct comp_unit_head cu_header_local; |
| 19034 | const struct comp_unit_head *cu_headerp; |
| 19035 | |
| 19036 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
| 19037 | |
| 19038 | return cu_headerp->offset_size; |
| 19039 | } |
| 19040 | |
| 19041 | /* See its dwarf2loc.h declaration. */ |
| 19042 | |
| 19043 | int |
| 19044 | dwarf2_per_cu_ref_addr_size (struct dwarf2_per_cu_data *per_cu) |
| 19045 | { |
| 19046 | struct comp_unit_head cu_header_local; |
| 19047 | const struct comp_unit_head *cu_headerp; |
| 19048 | |
| 19049 | cu_headerp = per_cu_header_read_in (&cu_header_local, per_cu); |
| 19050 | |
| 19051 | if (cu_headerp->version == 2) |
| 19052 | return cu_headerp->addr_size; |
| 19053 | else |
| 19054 | return cu_headerp->offset_size; |
| 19055 | } |
| 19056 | |
| 19057 | /* Return the text offset of the CU. The returned offset comes from |
| 19058 | this CU's objfile. If this objfile came from a separate debuginfo |
| 19059 | file, then the offset may be different from the corresponding |
| 19060 | offset in the parent objfile. */ |
| 19061 | |
| 19062 | CORE_ADDR |
| 19063 | dwarf2_per_cu_text_offset (struct dwarf2_per_cu_data *per_cu) |
| 19064 | { |
| 19065 | struct objfile *objfile = per_cu->objfile; |
| 19066 | |
| 19067 | return ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 19068 | } |
| 19069 | |
| 19070 | /* Locate the .debug_info compilation unit from CU's objfile which contains |
| 19071 | the DIE at OFFSET. Raises an error on failure. */ |
| 19072 | |
| 19073 | static struct dwarf2_per_cu_data * |
| 19074 | dwarf2_find_containing_comp_unit (sect_offset offset, |
| 19075 | unsigned int offset_in_dwz, |
| 19076 | struct objfile *objfile) |
| 19077 | { |
| 19078 | struct dwarf2_per_cu_data *this_cu; |
| 19079 | int low, high; |
| 19080 | const sect_offset *cu_off; |
| 19081 | |
| 19082 | low = 0; |
| 19083 | high = dwarf2_per_objfile->n_comp_units - 1; |
| 19084 | while (high > low) |
| 19085 | { |
| 19086 | struct dwarf2_per_cu_data *mid_cu; |
| 19087 | int mid = low + (high - low) / 2; |
| 19088 | |
| 19089 | mid_cu = dwarf2_per_objfile->all_comp_units[mid]; |
| 19090 | cu_off = &mid_cu->offset; |
| 19091 | if (mid_cu->is_dwz > offset_in_dwz |
| 19092 | || (mid_cu->is_dwz == offset_in_dwz |
| 19093 | && cu_off->sect_off >= offset.sect_off)) |
| 19094 | high = mid; |
| 19095 | else |
| 19096 | low = mid + 1; |
| 19097 | } |
| 19098 | gdb_assert (low == high); |
| 19099 | this_cu = dwarf2_per_objfile->all_comp_units[low]; |
| 19100 | cu_off = &this_cu->offset; |
| 19101 | if (this_cu->is_dwz != offset_in_dwz || cu_off->sect_off > offset.sect_off) |
| 19102 | { |
| 19103 | if (low == 0 || this_cu->is_dwz != offset_in_dwz) |
| 19104 | error (_("Dwarf Error: could not find partial DIE containing " |
| 19105 | "offset 0x%lx [in module %s]"), |
| 19106 | (long) offset.sect_off, bfd_get_filename (objfile->obfd)); |
| 19107 | |
| 19108 | gdb_assert (dwarf2_per_objfile->all_comp_units[low-1]->offset.sect_off |
| 19109 | <= offset.sect_off); |
| 19110 | return dwarf2_per_objfile->all_comp_units[low-1]; |
| 19111 | } |
| 19112 | else |
| 19113 | { |
| 19114 | this_cu = dwarf2_per_objfile->all_comp_units[low]; |
| 19115 | if (low == dwarf2_per_objfile->n_comp_units - 1 |
| 19116 | && offset.sect_off >= this_cu->offset.sect_off + this_cu->length) |
| 19117 | error (_("invalid dwarf2 offset %u"), offset.sect_off); |
| 19118 | gdb_assert (offset.sect_off < this_cu->offset.sect_off + this_cu->length); |
| 19119 | return this_cu; |
| 19120 | } |
| 19121 | } |
| 19122 | |
| 19123 | /* Initialize dwarf2_cu CU, owned by PER_CU. */ |
| 19124 | |
| 19125 | static void |
| 19126 | init_one_comp_unit (struct dwarf2_cu *cu, struct dwarf2_per_cu_data *per_cu) |
| 19127 | { |
| 19128 | memset (cu, 0, sizeof (*cu)); |
| 19129 | per_cu->cu = cu; |
| 19130 | cu->per_cu = per_cu; |
| 19131 | cu->objfile = per_cu->objfile; |
| 19132 | obstack_init (&cu->comp_unit_obstack); |
| 19133 | } |
| 19134 | |
| 19135 | /* Initialize basic fields of dwarf_cu CU according to DIE COMP_UNIT_DIE. */ |
| 19136 | |
| 19137 | static void |
| 19138 | prepare_one_comp_unit (struct dwarf2_cu *cu, struct die_info *comp_unit_die, |
| 19139 | enum language pretend_language) |
| 19140 | { |
| 19141 | struct attribute *attr; |
| 19142 | |
| 19143 | /* Set the language we're debugging. */ |
| 19144 | attr = dwarf2_attr (comp_unit_die, DW_AT_language, cu); |
| 19145 | if (attr) |
| 19146 | set_cu_language (DW_UNSND (attr), cu); |
| 19147 | else |
| 19148 | { |
| 19149 | cu->language = pretend_language; |
| 19150 | cu->language_defn = language_def (cu->language); |
| 19151 | } |
| 19152 | |
| 19153 | attr = dwarf2_attr (comp_unit_die, DW_AT_producer, cu); |
| 19154 | if (attr) |
| 19155 | cu->producer = DW_STRING (attr); |
| 19156 | } |
| 19157 | |
| 19158 | /* Release one cached compilation unit, CU. We unlink it from the tree |
| 19159 | of compilation units, but we don't remove it from the read_in_chain; |
| 19160 | the caller is responsible for that. |
| 19161 | NOTE: DATA is a void * because this function is also used as a |
| 19162 | cleanup routine. */ |
| 19163 | |
| 19164 | static void |
| 19165 | free_heap_comp_unit (void *data) |
| 19166 | { |
| 19167 | struct dwarf2_cu *cu = data; |
| 19168 | |
| 19169 | gdb_assert (cu->per_cu != NULL); |
| 19170 | cu->per_cu->cu = NULL; |
| 19171 | cu->per_cu = NULL; |
| 19172 | |
| 19173 | obstack_free (&cu->comp_unit_obstack, NULL); |
| 19174 | |
| 19175 | xfree (cu); |
| 19176 | } |
| 19177 | |
| 19178 | /* This cleanup function is passed the address of a dwarf2_cu on the stack |
| 19179 | when we're finished with it. We can't free the pointer itself, but be |
| 19180 | sure to unlink it from the cache. Also release any associated storage. */ |
| 19181 | |
| 19182 | static void |
| 19183 | free_stack_comp_unit (void *data) |
| 19184 | { |
| 19185 | struct dwarf2_cu *cu = data; |
| 19186 | |
| 19187 | gdb_assert (cu->per_cu != NULL); |
| 19188 | cu->per_cu->cu = NULL; |
| 19189 | cu->per_cu = NULL; |
| 19190 | |
| 19191 | obstack_free (&cu->comp_unit_obstack, NULL); |
| 19192 | cu->partial_dies = NULL; |
| 19193 | } |
| 19194 | |
| 19195 | /* Free all cached compilation units. */ |
| 19196 | |
| 19197 | static void |
| 19198 | free_cached_comp_units (void *data) |
| 19199 | { |
| 19200 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 19201 | |
| 19202 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 19203 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 19204 | while (per_cu != NULL) |
| 19205 | { |
| 19206 | struct dwarf2_per_cu_data *next_cu; |
| 19207 | |
| 19208 | next_cu = per_cu->cu->read_in_chain; |
| 19209 | |
| 19210 | free_heap_comp_unit (per_cu->cu); |
| 19211 | *last_chain = next_cu; |
| 19212 | |
| 19213 | per_cu = next_cu; |
| 19214 | } |
| 19215 | } |
| 19216 | |
| 19217 | /* Increase the age counter on each cached compilation unit, and free |
| 19218 | any that are too old. */ |
| 19219 | |
| 19220 | static void |
| 19221 | age_cached_comp_units (void) |
| 19222 | { |
| 19223 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 19224 | |
| 19225 | dwarf2_clear_marks (dwarf2_per_objfile->read_in_chain); |
| 19226 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 19227 | while (per_cu != NULL) |
| 19228 | { |
| 19229 | per_cu->cu->last_used ++; |
| 19230 | if (per_cu->cu->last_used <= dwarf2_max_cache_age) |
| 19231 | dwarf2_mark (per_cu->cu); |
| 19232 | per_cu = per_cu->cu->read_in_chain; |
| 19233 | } |
| 19234 | |
| 19235 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 19236 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 19237 | while (per_cu != NULL) |
| 19238 | { |
| 19239 | struct dwarf2_per_cu_data *next_cu; |
| 19240 | |
| 19241 | next_cu = per_cu->cu->read_in_chain; |
| 19242 | |
| 19243 | if (!per_cu->cu->mark) |
| 19244 | { |
| 19245 | free_heap_comp_unit (per_cu->cu); |
| 19246 | *last_chain = next_cu; |
| 19247 | } |
| 19248 | else |
| 19249 | last_chain = &per_cu->cu->read_in_chain; |
| 19250 | |
| 19251 | per_cu = next_cu; |
| 19252 | } |
| 19253 | } |
| 19254 | |
| 19255 | /* Remove a single compilation unit from the cache. */ |
| 19256 | |
| 19257 | static void |
| 19258 | free_one_cached_comp_unit (struct dwarf2_per_cu_data *target_per_cu) |
| 19259 | { |
| 19260 | struct dwarf2_per_cu_data *per_cu, **last_chain; |
| 19261 | |
| 19262 | per_cu = dwarf2_per_objfile->read_in_chain; |
| 19263 | last_chain = &dwarf2_per_objfile->read_in_chain; |
| 19264 | while (per_cu != NULL) |
| 19265 | { |
| 19266 | struct dwarf2_per_cu_data *next_cu; |
| 19267 | |
| 19268 | next_cu = per_cu->cu->read_in_chain; |
| 19269 | |
| 19270 | if (per_cu == target_per_cu) |
| 19271 | { |
| 19272 | free_heap_comp_unit (per_cu->cu); |
| 19273 | per_cu->cu = NULL; |
| 19274 | *last_chain = next_cu; |
| 19275 | break; |
| 19276 | } |
| 19277 | else |
| 19278 | last_chain = &per_cu->cu->read_in_chain; |
| 19279 | |
| 19280 | per_cu = next_cu; |
| 19281 | } |
| 19282 | } |
| 19283 | |
| 19284 | /* Release all extra memory associated with OBJFILE. */ |
| 19285 | |
| 19286 | void |
| 19287 | dwarf2_free_objfile (struct objfile *objfile) |
| 19288 | { |
| 19289 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 19290 | |
| 19291 | if (dwarf2_per_objfile == NULL) |
| 19292 | return; |
| 19293 | |
| 19294 | /* Cached DIE trees use xmalloc and the comp_unit_obstack. */ |
| 19295 | free_cached_comp_units (NULL); |
| 19296 | |
| 19297 | if (dwarf2_per_objfile->quick_file_names_table) |
| 19298 | htab_delete (dwarf2_per_objfile->quick_file_names_table); |
| 19299 | |
| 19300 | /* Everything else should be on the objfile obstack. */ |
| 19301 | } |
| 19302 | |
| 19303 | /* A set of CU "per_cu" pointer, DIE offset, and GDB type pointer. |
| 19304 | We store these in a hash table separate from the DIEs, and preserve them |
| 19305 | when the DIEs are flushed out of cache. |
| 19306 | |
| 19307 | The CU "per_cu" pointer is needed because offset alone is not enough to |
| 19308 | uniquely identify the type. A file may have multiple .debug_types sections, |
| 19309 | or the type may come from a DWO file. We have to use something in |
| 19310 | dwarf2_per_cu_data (or the pointer to it) because we can enter the lookup |
| 19311 | routine, get_die_type_at_offset, from outside this file, and thus won't |
| 19312 | necessarily have PER_CU->cu. Fortunately, PER_CU is stable for the life |
| 19313 | of the objfile. */ |
| 19314 | |
| 19315 | struct dwarf2_per_cu_offset_and_type |
| 19316 | { |
| 19317 | const struct dwarf2_per_cu_data *per_cu; |
| 19318 | sect_offset offset; |
| 19319 | struct type *type; |
| 19320 | }; |
| 19321 | |
| 19322 | /* Hash function for a dwarf2_per_cu_offset_and_type. */ |
| 19323 | |
| 19324 | static hashval_t |
| 19325 | per_cu_offset_and_type_hash (const void *item) |
| 19326 | { |
| 19327 | const struct dwarf2_per_cu_offset_and_type *ofs = item; |
| 19328 | |
| 19329 | return (uintptr_t) ofs->per_cu + ofs->offset.sect_off; |
| 19330 | } |
| 19331 | |
| 19332 | /* Equality function for a dwarf2_per_cu_offset_and_type. */ |
| 19333 | |
| 19334 | static int |
| 19335 | per_cu_offset_and_type_eq (const void *item_lhs, const void *item_rhs) |
| 19336 | { |
| 19337 | const struct dwarf2_per_cu_offset_and_type *ofs_lhs = item_lhs; |
| 19338 | const struct dwarf2_per_cu_offset_and_type *ofs_rhs = item_rhs; |
| 19339 | |
| 19340 | return (ofs_lhs->per_cu == ofs_rhs->per_cu |
| 19341 | && ofs_lhs->offset.sect_off == ofs_rhs->offset.sect_off); |
| 19342 | } |
| 19343 | |
| 19344 | /* Set the type associated with DIE to TYPE. Save it in CU's hash |
| 19345 | table if necessary. For convenience, return TYPE. |
| 19346 | |
| 19347 | The DIEs reading must have careful ordering to: |
| 19348 | * Not cause infite loops trying to read in DIEs as a prerequisite for |
| 19349 | reading current DIE. |
| 19350 | * Not trying to dereference contents of still incompletely read in types |
| 19351 | while reading in other DIEs. |
| 19352 | * Enable referencing still incompletely read in types just by a pointer to |
| 19353 | the type without accessing its fields. |
| 19354 | |
| 19355 | Therefore caller should follow these rules: |
| 19356 | * Try to fetch any prerequisite types we may need to build this DIE type |
| 19357 | before building the type and calling set_die_type. |
| 19358 | * After building type call set_die_type for current DIE as soon as |
| 19359 | possible before fetching more types to complete the current type. |
| 19360 | * Make the type as complete as possible before fetching more types. */ |
| 19361 | |
| 19362 | static struct type * |
| 19363 | set_die_type (struct die_info *die, struct type *type, struct dwarf2_cu *cu) |
| 19364 | { |
| 19365 | struct dwarf2_per_cu_offset_and_type **slot, ofs; |
| 19366 | struct objfile *objfile = cu->objfile; |
| 19367 | |
| 19368 | /* For Ada types, make sure that the gnat-specific data is always |
| 19369 | initialized (if not already set). There are a few types where |
| 19370 | we should not be doing so, because the type-specific area is |
| 19371 | already used to hold some other piece of info (eg: TYPE_CODE_FLT |
| 19372 | where the type-specific area is used to store the floatformat). |
| 19373 | But this is not a problem, because the gnat-specific information |
| 19374 | is actually not needed for these types. */ |
| 19375 | if (need_gnat_info (cu) |
| 19376 | && TYPE_CODE (type) != TYPE_CODE_FUNC |
| 19377 | && TYPE_CODE (type) != TYPE_CODE_FLT |
| 19378 | && !HAVE_GNAT_AUX_INFO (type)) |
| 19379 | INIT_GNAT_SPECIFIC (type); |
| 19380 | |
| 19381 | if (dwarf2_per_objfile->die_type_hash == NULL) |
| 19382 | { |
| 19383 | dwarf2_per_objfile->die_type_hash = |
| 19384 | htab_create_alloc_ex (127, |
| 19385 | per_cu_offset_and_type_hash, |
| 19386 | per_cu_offset_and_type_eq, |
| 19387 | NULL, |
| 19388 | &objfile->objfile_obstack, |
| 19389 | hashtab_obstack_allocate, |
| 19390 | dummy_obstack_deallocate); |
| 19391 | } |
| 19392 | |
| 19393 | ofs.per_cu = cu->per_cu; |
| 19394 | ofs.offset = die->offset; |
| 19395 | ofs.type = type; |
| 19396 | slot = (struct dwarf2_per_cu_offset_and_type **) |
| 19397 | htab_find_slot (dwarf2_per_objfile->die_type_hash, &ofs, INSERT); |
| 19398 | if (*slot) |
| 19399 | complaint (&symfile_complaints, |
| 19400 | _("A problem internal to GDB: DIE 0x%x has type already set"), |
| 19401 | die->offset.sect_off); |
| 19402 | *slot = obstack_alloc (&objfile->objfile_obstack, sizeof (**slot)); |
| 19403 | **slot = ofs; |
| 19404 | return type; |
| 19405 | } |
| 19406 | |
| 19407 | /* Look up the type for the die at OFFSET in the appropriate type_hash |
| 19408 | table, or return NULL if the die does not have a saved type. */ |
| 19409 | |
| 19410 | static struct type * |
| 19411 | get_die_type_at_offset (sect_offset offset, |
| 19412 | struct dwarf2_per_cu_data *per_cu) |
| 19413 | { |
| 19414 | struct dwarf2_per_cu_offset_and_type *slot, ofs; |
| 19415 | |
| 19416 | if (dwarf2_per_objfile->die_type_hash == NULL) |
| 19417 | return NULL; |
| 19418 | |
| 19419 | ofs.per_cu = per_cu; |
| 19420 | ofs.offset = offset; |
| 19421 | slot = htab_find (dwarf2_per_objfile->die_type_hash, &ofs); |
| 19422 | if (slot) |
| 19423 | return slot->type; |
| 19424 | else |
| 19425 | return NULL; |
| 19426 | } |
| 19427 | |
| 19428 | /* Look up the type for DIE in the appropriate type_hash table, |
| 19429 | or return NULL if DIE does not have a saved type. */ |
| 19430 | |
| 19431 | static struct type * |
| 19432 | get_die_type (struct die_info *die, struct dwarf2_cu *cu) |
| 19433 | { |
| 19434 | return get_die_type_at_offset (die->offset, cu->per_cu); |
| 19435 | } |
| 19436 | |
| 19437 | /* Add a dependence relationship from CU to REF_PER_CU. */ |
| 19438 | |
| 19439 | static void |
| 19440 | dwarf2_add_dependence (struct dwarf2_cu *cu, |
| 19441 | struct dwarf2_per_cu_data *ref_per_cu) |
| 19442 | { |
| 19443 | void **slot; |
| 19444 | |
| 19445 | if (cu->dependencies == NULL) |
| 19446 | cu->dependencies |
| 19447 | = htab_create_alloc_ex (5, htab_hash_pointer, htab_eq_pointer, |
| 19448 | NULL, &cu->comp_unit_obstack, |
| 19449 | hashtab_obstack_allocate, |
| 19450 | dummy_obstack_deallocate); |
| 19451 | |
| 19452 | slot = htab_find_slot (cu->dependencies, ref_per_cu, INSERT); |
| 19453 | if (*slot == NULL) |
| 19454 | *slot = ref_per_cu; |
| 19455 | } |
| 19456 | |
| 19457 | /* Subroutine of dwarf2_mark to pass to htab_traverse. |
| 19458 | Set the mark field in every compilation unit in the |
| 19459 | cache that we must keep because we are keeping CU. */ |
| 19460 | |
| 19461 | static int |
| 19462 | dwarf2_mark_helper (void **slot, void *data) |
| 19463 | { |
| 19464 | struct dwarf2_per_cu_data *per_cu; |
| 19465 | |
| 19466 | per_cu = (struct dwarf2_per_cu_data *) *slot; |
| 19467 | |
| 19468 | /* cu->dependencies references may not yet have been ever read if QUIT aborts |
| 19469 | reading of the chain. As such dependencies remain valid it is not much |
| 19470 | useful to track and undo them during QUIT cleanups. */ |
| 19471 | if (per_cu->cu == NULL) |
| 19472 | return 1; |
| 19473 | |
| 19474 | if (per_cu->cu->mark) |
| 19475 | return 1; |
| 19476 | per_cu->cu->mark = 1; |
| 19477 | |
| 19478 | if (per_cu->cu->dependencies != NULL) |
| 19479 | htab_traverse (per_cu->cu->dependencies, dwarf2_mark_helper, NULL); |
| 19480 | |
| 19481 | return 1; |
| 19482 | } |
| 19483 | |
| 19484 | /* Set the mark field in CU and in every other compilation unit in the |
| 19485 | cache that we must keep because we are keeping CU. */ |
| 19486 | |
| 19487 | static void |
| 19488 | dwarf2_mark (struct dwarf2_cu *cu) |
| 19489 | { |
| 19490 | if (cu->mark) |
| 19491 | return; |
| 19492 | cu->mark = 1; |
| 19493 | if (cu->dependencies != NULL) |
| 19494 | htab_traverse (cu->dependencies, dwarf2_mark_helper, NULL); |
| 19495 | } |
| 19496 | |
| 19497 | static void |
| 19498 | dwarf2_clear_marks (struct dwarf2_per_cu_data *per_cu) |
| 19499 | { |
| 19500 | while (per_cu) |
| 19501 | { |
| 19502 | per_cu->cu->mark = 0; |
| 19503 | per_cu = per_cu->cu->read_in_chain; |
| 19504 | } |
| 19505 | } |
| 19506 | |
| 19507 | /* Trivial hash function for partial_die_info: the hash value of a DIE |
| 19508 | is its offset in .debug_info for this objfile. */ |
| 19509 | |
| 19510 | static hashval_t |
| 19511 | partial_die_hash (const void *item) |
| 19512 | { |
| 19513 | const struct partial_die_info *part_die = item; |
| 19514 | |
| 19515 | return part_die->offset.sect_off; |
| 19516 | } |
| 19517 | |
| 19518 | /* Trivial comparison function for partial_die_info structures: two DIEs |
| 19519 | are equal if they have the same offset. */ |
| 19520 | |
| 19521 | static int |
| 19522 | partial_die_eq (const void *item_lhs, const void *item_rhs) |
| 19523 | { |
| 19524 | const struct partial_die_info *part_die_lhs = item_lhs; |
| 19525 | const struct partial_die_info *part_die_rhs = item_rhs; |
| 19526 | |
| 19527 | return part_die_lhs->offset.sect_off == part_die_rhs->offset.sect_off; |
| 19528 | } |
| 19529 | |
| 19530 | static struct cmd_list_element *set_dwarf2_cmdlist; |
| 19531 | static struct cmd_list_element *show_dwarf2_cmdlist; |
| 19532 | |
| 19533 | static void |
| 19534 | set_dwarf2_cmd (char *args, int from_tty) |
| 19535 | { |
| 19536 | help_list (set_dwarf2_cmdlist, "maintenance set dwarf2 ", -1, gdb_stdout); |
| 19537 | } |
| 19538 | |
| 19539 | static void |
| 19540 | show_dwarf2_cmd (char *args, int from_tty) |
| 19541 | { |
| 19542 | cmd_show_list (show_dwarf2_cmdlist, from_tty, ""); |
| 19543 | } |
| 19544 | |
| 19545 | /* Free data associated with OBJFILE, if necessary. */ |
| 19546 | |
| 19547 | static void |
| 19548 | dwarf2_per_objfile_free (struct objfile *objfile, void *d) |
| 19549 | { |
| 19550 | struct dwarf2_per_objfile *data = d; |
| 19551 | int ix; |
| 19552 | |
| 19553 | for (ix = 0; ix < dwarf2_per_objfile->n_comp_units; ++ix) |
| 19554 | VEC_free (dwarf2_per_cu_ptr, |
| 19555 | dwarf2_per_objfile->all_comp_units[ix]->s.imported_symtabs); |
| 19556 | |
| 19557 | VEC_free (dwarf2_section_info_def, data->types); |
| 19558 | |
| 19559 | if (data->dwo_files) |
| 19560 | free_dwo_files (data->dwo_files, objfile); |
| 19561 | |
| 19562 | if (data->dwz_file && data->dwz_file->dwz_bfd) |
| 19563 | gdb_bfd_unref (data->dwz_file->dwz_bfd); |
| 19564 | } |
| 19565 | |
| 19566 | \f |
| 19567 | /* The "save gdb-index" command. */ |
| 19568 | |
| 19569 | /* The contents of the hash table we create when building the string |
| 19570 | table. */ |
| 19571 | struct strtab_entry |
| 19572 | { |
| 19573 | offset_type offset; |
| 19574 | const char *str; |
| 19575 | }; |
| 19576 | |
| 19577 | /* Hash function for a strtab_entry. |
| 19578 | |
| 19579 | Function is used only during write_hash_table so no index format backward |
| 19580 | compatibility is needed. */ |
| 19581 | |
| 19582 | static hashval_t |
| 19583 | hash_strtab_entry (const void *e) |
| 19584 | { |
| 19585 | const struct strtab_entry *entry = e; |
| 19586 | return mapped_index_string_hash (INT_MAX, entry->str); |
| 19587 | } |
| 19588 | |
| 19589 | /* Equality function for a strtab_entry. */ |
| 19590 | |
| 19591 | static int |
| 19592 | eq_strtab_entry (const void *a, const void *b) |
| 19593 | { |
| 19594 | const struct strtab_entry *ea = a; |
| 19595 | const struct strtab_entry *eb = b; |
| 19596 | return !strcmp (ea->str, eb->str); |
| 19597 | } |
| 19598 | |
| 19599 | /* Create a strtab_entry hash table. */ |
| 19600 | |
| 19601 | static htab_t |
| 19602 | create_strtab (void) |
| 19603 | { |
| 19604 | return htab_create_alloc (100, hash_strtab_entry, eq_strtab_entry, |
| 19605 | xfree, xcalloc, xfree); |
| 19606 | } |
| 19607 | |
| 19608 | /* Add a string to the constant pool. Return the string's offset in |
| 19609 | host order. */ |
| 19610 | |
| 19611 | static offset_type |
| 19612 | add_string (htab_t table, struct obstack *cpool, const char *str) |
| 19613 | { |
| 19614 | void **slot; |
| 19615 | struct strtab_entry entry; |
| 19616 | struct strtab_entry *result; |
| 19617 | |
| 19618 | entry.str = str; |
| 19619 | slot = htab_find_slot (table, &entry, INSERT); |
| 19620 | if (*slot) |
| 19621 | result = *slot; |
| 19622 | else |
| 19623 | { |
| 19624 | result = XNEW (struct strtab_entry); |
| 19625 | result->offset = obstack_object_size (cpool); |
| 19626 | result->str = str; |
| 19627 | obstack_grow_str0 (cpool, str); |
| 19628 | *slot = result; |
| 19629 | } |
| 19630 | return result->offset; |
| 19631 | } |
| 19632 | |
| 19633 | /* An entry in the symbol table. */ |
| 19634 | struct symtab_index_entry |
| 19635 | { |
| 19636 | /* The name of the symbol. */ |
| 19637 | const char *name; |
| 19638 | /* The offset of the name in the constant pool. */ |
| 19639 | offset_type index_offset; |
| 19640 | /* A sorted vector of the indices of all the CUs that hold an object |
| 19641 | of this name. */ |
| 19642 | VEC (offset_type) *cu_indices; |
| 19643 | }; |
| 19644 | |
| 19645 | /* The symbol table. This is a power-of-2-sized hash table. */ |
| 19646 | struct mapped_symtab |
| 19647 | { |
| 19648 | offset_type n_elements; |
| 19649 | offset_type size; |
| 19650 | struct symtab_index_entry **data; |
| 19651 | }; |
| 19652 | |
| 19653 | /* Hash function for a symtab_index_entry. */ |
| 19654 | |
| 19655 | static hashval_t |
| 19656 | hash_symtab_entry (const void *e) |
| 19657 | { |
| 19658 | const struct symtab_index_entry *entry = e; |
| 19659 | return iterative_hash (VEC_address (offset_type, entry->cu_indices), |
| 19660 | sizeof (offset_type) * VEC_length (offset_type, |
| 19661 | entry->cu_indices), |
| 19662 | 0); |
| 19663 | } |
| 19664 | |
| 19665 | /* Equality function for a symtab_index_entry. */ |
| 19666 | |
| 19667 | static int |
| 19668 | eq_symtab_entry (const void *a, const void *b) |
| 19669 | { |
| 19670 | const struct symtab_index_entry *ea = a; |
| 19671 | const struct symtab_index_entry *eb = b; |
| 19672 | int len = VEC_length (offset_type, ea->cu_indices); |
| 19673 | if (len != VEC_length (offset_type, eb->cu_indices)) |
| 19674 | return 0; |
| 19675 | return !memcmp (VEC_address (offset_type, ea->cu_indices), |
| 19676 | VEC_address (offset_type, eb->cu_indices), |
| 19677 | sizeof (offset_type) * len); |
| 19678 | } |
| 19679 | |
| 19680 | /* Destroy a symtab_index_entry. */ |
| 19681 | |
| 19682 | static void |
| 19683 | delete_symtab_entry (void *p) |
| 19684 | { |
| 19685 | struct symtab_index_entry *entry = p; |
| 19686 | VEC_free (offset_type, entry->cu_indices); |
| 19687 | xfree (entry); |
| 19688 | } |
| 19689 | |
| 19690 | /* Create a hash table holding symtab_index_entry objects. */ |
| 19691 | |
| 19692 | static htab_t |
| 19693 | create_symbol_hash_table (void) |
| 19694 | { |
| 19695 | return htab_create_alloc (100, hash_symtab_entry, eq_symtab_entry, |
| 19696 | delete_symtab_entry, xcalloc, xfree); |
| 19697 | } |
| 19698 | |
| 19699 | /* Create a new mapped symtab object. */ |
| 19700 | |
| 19701 | static struct mapped_symtab * |
| 19702 | create_mapped_symtab (void) |
| 19703 | { |
| 19704 | struct mapped_symtab *symtab = XNEW (struct mapped_symtab); |
| 19705 | symtab->n_elements = 0; |
| 19706 | symtab->size = 1024; |
| 19707 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); |
| 19708 | return symtab; |
| 19709 | } |
| 19710 | |
| 19711 | /* Destroy a mapped_symtab. */ |
| 19712 | |
| 19713 | static void |
| 19714 | cleanup_mapped_symtab (void *p) |
| 19715 | { |
| 19716 | struct mapped_symtab *symtab = p; |
| 19717 | /* The contents of the array are freed when the other hash table is |
| 19718 | destroyed. */ |
| 19719 | xfree (symtab->data); |
| 19720 | xfree (symtab); |
| 19721 | } |
| 19722 | |
| 19723 | /* Find a slot in SYMTAB for the symbol NAME. Returns a pointer to |
| 19724 | the slot. |
| 19725 | |
| 19726 | Function is used only during write_hash_table so no index format backward |
| 19727 | compatibility is needed. */ |
| 19728 | |
| 19729 | static struct symtab_index_entry ** |
| 19730 | find_slot (struct mapped_symtab *symtab, const char *name) |
| 19731 | { |
| 19732 | offset_type index, step, hash = mapped_index_string_hash (INT_MAX, name); |
| 19733 | |
| 19734 | index = hash & (symtab->size - 1); |
| 19735 | step = ((hash * 17) & (symtab->size - 1)) | 1; |
| 19736 | |
| 19737 | for (;;) |
| 19738 | { |
| 19739 | if (!symtab->data[index] || !strcmp (name, symtab->data[index]->name)) |
| 19740 | return &symtab->data[index]; |
| 19741 | index = (index + step) & (symtab->size - 1); |
| 19742 | } |
| 19743 | } |
| 19744 | |
| 19745 | /* Expand SYMTAB's hash table. */ |
| 19746 | |
| 19747 | static void |
| 19748 | hash_expand (struct mapped_symtab *symtab) |
| 19749 | { |
| 19750 | offset_type old_size = symtab->size; |
| 19751 | offset_type i; |
| 19752 | struct symtab_index_entry **old_entries = symtab->data; |
| 19753 | |
| 19754 | symtab->size *= 2; |
| 19755 | symtab->data = XCNEWVEC (struct symtab_index_entry *, symtab->size); |
| 19756 | |
| 19757 | for (i = 0; i < old_size; ++i) |
| 19758 | { |
| 19759 | if (old_entries[i]) |
| 19760 | { |
| 19761 | struct symtab_index_entry **slot = find_slot (symtab, |
| 19762 | old_entries[i]->name); |
| 19763 | *slot = old_entries[i]; |
| 19764 | } |
| 19765 | } |
| 19766 | |
| 19767 | xfree (old_entries); |
| 19768 | } |
| 19769 | |
| 19770 | /* Add an entry to SYMTAB. NAME is the name of the symbol. |
| 19771 | CU_INDEX is the index of the CU in which the symbol appears. |
| 19772 | IS_STATIC is one if the symbol is static, otherwise zero (global). */ |
| 19773 | |
| 19774 | static void |
| 19775 | add_index_entry (struct mapped_symtab *symtab, const char *name, |
| 19776 | int is_static, gdb_index_symbol_kind kind, |
| 19777 | offset_type cu_index) |
| 19778 | { |
| 19779 | struct symtab_index_entry **slot; |
| 19780 | offset_type cu_index_and_attrs; |
| 19781 | |
| 19782 | ++symtab->n_elements; |
| 19783 | if (4 * symtab->n_elements / 3 >= symtab->size) |
| 19784 | hash_expand (symtab); |
| 19785 | |
| 19786 | slot = find_slot (symtab, name); |
| 19787 | if (!*slot) |
| 19788 | { |
| 19789 | *slot = XNEW (struct symtab_index_entry); |
| 19790 | (*slot)->name = name; |
| 19791 | /* index_offset is set later. */ |
| 19792 | (*slot)->cu_indices = NULL; |
| 19793 | } |
| 19794 | |
| 19795 | cu_index_and_attrs = 0; |
| 19796 | DW2_GDB_INDEX_CU_SET_VALUE (cu_index_and_attrs, cu_index); |
| 19797 | DW2_GDB_INDEX_SYMBOL_STATIC_SET_VALUE (cu_index_and_attrs, is_static); |
| 19798 | DW2_GDB_INDEX_SYMBOL_KIND_SET_VALUE (cu_index_and_attrs, kind); |
| 19799 | |
| 19800 | /* We don't want to record an index value twice as we want to avoid the |
| 19801 | duplication. |
| 19802 | We process all global symbols and then all static symbols |
| 19803 | (which would allow us to avoid the duplication by only having to check |
| 19804 | the last entry pushed), but a symbol could have multiple kinds in one CU. |
| 19805 | To keep things simple we don't worry about the duplication here and |
| 19806 | sort and uniqufy the list after we've processed all symbols. */ |
| 19807 | VEC_safe_push (offset_type, (*slot)->cu_indices, cu_index_and_attrs); |
| 19808 | } |
| 19809 | |
| 19810 | /* qsort helper routine for uniquify_cu_indices. */ |
| 19811 | |
| 19812 | static int |
| 19813 | offset_type_compare (const void *ap, const void *bp) |
| 19814 | { |
| 19815 | offset_type a = *(offset_type *) ap; |
| 19816 | offset_type b = *(offset_type *) bp; |
| 19817 | |
| 19818 | return (a > b) - (b > a); |
| 19819 | } |
| 19820 | |
| 19821 | /* Sort and remove duplicates of all symbols' cu_indices lists. */ |
| 19822 | |
| 19823 | static void |
| 19824 | uniquify_cu_indices (struct mapped_symtab *symtab) |
| 19825 | { |
| 19826 | int i; |
| 19827 | |
| 19828 | for (i = 0; i < symtab->size; ++i) |
| 19829 | { |
| 19830 | struct symtab_index_entry *entry = symtab->data[i]; |
| 19831 | |
| 19832 | if (entry |
| 19833 | && entry->cu_indices != NULL) |
| 19834 | { |
| 19835 | unsigned int next_to_insert, next_to_check; |
| 19836 | offset_type last_value; |
| 19837 | |
| 19838 | qsort (VEC_address (offset_type, entry->cu_indices), |
| 19839 | VEC_length (offset_type, entry->cu_indices), |
| 19840 | sizeof (offset_type), offset_type_compare); |
| 19841 | |
| 19842 | last_value = VEC_index (offset_type, entry->cu_indices, 0); |
| 19843 | next_to_insert = 1; |
| 19844 | for (next_to_check = 1; |
| 19845 | next_to_check < VEC_length (offset_type, entry->cu_indices); |
| 19846 | ++next_to_check) |
| 19847 | { |
| 19848 | if (VEC_index (offset_type, entry->cu_indices, next_to_check) |
| 19849 | != last_value) |
| 19850 | { |
| 19851 | last_value = VEC_index (offset_type, entry->cu_indices, |
| 19852 | next_to_check); |
| 19853 | VEC_replace (offset_type, entry->cu_indices, next_to_insert, |
| 19854 | last_value); |
| 19855 | ++next_to_insert; |
| 19856 | } |
| 19857 | } |
| 19858 | VEC_truncate (offset_type, entry->cu_indices, next_to_insert); |
| 19859 | } |
| 19860 | } |
| 19861 | } |
| 19862 | |
| 19863 | /* Add a vector of indices to the constant pool. */ |
| 19864 | |
| 19865 | static offset_type |
| 19866 | add_indices_to_cpool (htab_t symbol_hash_table, struct obstack *cpool, |
| 19867 | struct symtab_index_entry *entry) |
| 19868 | { |
| 19869 | void **slot; |
| 19870 | |
| 19871 | slot = htab_find_slot (symbol_hash_table, entry, INSERT); |
| 19872 | if (!*slot) |
| 19873 | { |
| 19874 | offset_type len = VEC_length (offset_type, entry->cu_indices); |
| 19875 | offset_type val = MAYBE_SWAP (len); |
| 19876 | offset_type iter; |
| 19877 | int i; |
| 19878 | |
| 19879 | *slot = entry; |
| 19880 | entry->index_offset = obstack_object_size (cpool); |
| 19881 | |
| 19882 | obstack_grow (cpool, &val, sizeof (val)); |
| 19883 | for (i = 0; |
| 19884 | VEC_iterate (offset_type, entry->cu_indices, i, iter); |
| 19885 | ++i) |
| 19886 | { |
| 19887 | val = MAYBE_SWAP (iter); |
| 19888 | obstack_grow (cpool, &val, sizeof (val)); |
| 19889 | } |
| 19890 | } |
| 19891 | else |
| 19892 | { |
| 19893 | struct symtab_index_entry *old_entry = *slot; |
| 19894 | entry->index_offset = old_entry->index_offset; |
| 19895 | entry = old_entry; |
| 19896 | } |
| 19897 | return entry->index_offset; |
| 19898 | } |
| 19899 | |
| 19900 | /* Write the mapped hash table SYMTAB to the obstack OUTPUT, with |
| 19901 | constant pool entries going into the obstack CPOOL. */ |
| 19902 | |
| 19903 | static void |
| 19904 | write_hash_table (struct mapped_symtab *symtab, |
| 19905 | struct obstack *output, struct obstack *cpool) |
| 19906 | { |
| 19907 | offset_type i; |
| 19908 | htab_t symbol_hash_table; |
| 19909 | htab_t str_table; |
| 19910 | |
| 19911 | symbol_hash_table = create_symbol_hash_table (); |
| 19912 | str_table = create_strtab (); |
| 19913 | |
| 19914 | /* We add all the index vectors to the constant pool first, to |
| 19915 | ensure alignment is ok. */ |
| 19916 | for (i = 0; i < symtab->size; ++i) |
| 19917 | { |
| 19918 | if (symtab->data[i]) |
| 19919 | add_indices_to_cpool (symbol_hash_table, cpool, symtab->data[i]); |
| 19920 | } |
| 19921 | |
| 19922 | /* Now write out the hash table. */ |
| 19923 | for (i = 0; i < symtab->size; ++i) |
| 19924 | { |
| 19925 | offset_type str_off, vec_off; |
| 19926 | |
| 19927 | if (symtab->data[i]) |
| 19928 | { |
| 19929 | str_off = add_string (str_table, cpool, symtab->data[i]->name); |
| 19930 | vec_off = symtab->data[i]->index_offset; |
| 19931 | } |
| 19932 | else |
| 19933 | { |
| 19934 | /* While 0 is a valid constant pool index, it is not valid |
| 19935 | to have 0 for both offsets. */ |
| 19936 | str_off = 0; |
| 19937 | vec_off = 0; |
| 19938 | } |
| 19939 | |
| 19940 | str_off = MAYBE_SWAP (str_off); |
| 19941 | vec_off = MAYBE_SWAP (vec_off); |
| 19942 | |
| 19943 | obstack_grow (output, &str_off, sizeof (str_off)); |
| 19944 | obstack_grow (output, &vec_off, sizeof (vec_off)); |
| 19945 | } |
| 19946 | |
| 19947 | htab_delete (str_table); |
| 19948 | htab_delete (symbol_hash_table); |
| 19949 | } |
| 19950 | |
| 19951 | /* Struct to map psymtab to CU index in the index file. */ |
| 19952 | struct psymtab_cu_index_map |
| 19953 | { |
| 19954 | struct partial_symtab *psymtab; |
| 19955 | unsigned int cu_index; |
| 19956 | }; |
| 19957 | |
| 19958 | static hashval_t |
| 19959 | hash_psymtab_cu_index (const void *item) |
| 19960 | { |
| 19961 | const struct psymtab_cu_index_map *map = item; |
| 19962 | |
| 19963 | return htab_hash_pointer (map->psymtab); |
| 19964 | } |
| 19965 | |
| 19966 | static int |
| 19967 | eq_psymtab_cu_index (const void *item_lhs, const void *item_rhs) |
| 19968 | { |
| 19969 | const struct psymtab_cu_index_map *lhs = item_lhs; |
| 19970 | const struct psymtab_cu_index_map *rhs = item_rhs; |
| 19971 | |
| 19972 | return lhs->psymtab == rhs->psymtab; |
| 19973 | } |
| 19974 | |
| 19975 | /* Helper struct for building the address table. */ |
| 19976 | struct addrmap_index_data |
| 19977 | { |
| 19978 | struct objfile *objfile; |
| 19979 | struct obstack *addr_obstack; |
| 19980 | htab_t cu_index_htab; |
| 19981 | |
| 19982 | /* Non-zero if the previous_* fields are valid. |
| 19983 | We can't write an entry until we see the next entry (since it is only then |
| 19984 | that we know the end of the entry). */ |
| 19985 | int previous_valid; |
| 19986 | /* Index of the CU in the table of all CUs in the index file. */ |
| 19987 | unsigned int previous_cu_index; |
| 19988 | /* Start address of the CU. */ |
| 19989 | CORE_ADDR previous_cu_start; |
| 19990 | }; |
| 19991 | |
| 19992 | /* Write an address entry to OBSTACK. */ |
| 19993 | |
| 19994 | static void |
| 19995 | add_address_entry (struct objfile *objfile, struct obstack *obstack, |
| 19996 | CORE_ADDR start, CORE_ADDR end, unsigned int cu_index) |
| 19997 | { |
| 19998 | offset_type cu_index_to_write; |
| 19999 | char addr[8]; |
| 20000 | CORE_ADDR baseaddr; |
| 20001 | |
| 20002 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 20003 | |
| 20004 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, start - baseaddr); |
| 20005 | obstack_grow (obstack, addr, 8); |
| 20006 | store_unsigned_integer (addr, 8, BFD_ENDIAN_LITTLE, end - baseaddr); |
| 20007 | obstack_grow (obstack, addr, 8); |
| 20008 | cu_index_to_write = MAYBE_SWAP (cu_index); |
| 20009 | obstack_grow (obstack, &cu_index_to_write, sizeof (offset_type)); |
| 20010 | } |
| 20011 | |
| 20012 | /* Worker function for traversing an addrmap to build the address table. */ |
| 20013 | |
| 20014 | static int |
| 20015 | add_address_entry_worker (void *datap, CORE_ADDR start_addr, void *obj) |
| 20016 | { |
| 20017 | struct addrmap_index_data *data = datap; |
| 20018 | struct partial_symtab *pst = obj; |
| 20019 | |
| 20020 | if (data->previous_valid) |
| 20021 | add_address_entry (data->objfile, data->addr_obstack, |
| 20022 | data->previous_cu_start, start_addr, |
| 20023 | data->previous_cu_index); |
| 20024 | |
| 20025 | data->previous_cu_start = start_addr; |
| 20026 | if (pst != NULL) |
| 20027 | { |
| 20028 | struct psymtab_cu_index_map find_map, *map; |
| 20029 | find_map.psymtab = pst; |
| 20030 | map = htab_find (data->cu_index_htab, &find_map); |
| 20031 | gdb_assert (map != NULL); |
| 20032 | data->previous_cu_index = map->cu_index; |
| 20033 | data->previous_valid = 1; |
| 20034 | } |
| 20035 | else |
| 20036 | data->previous_valid = 0; |
| 20037 | |
| 20038 | return 0; |
| 20039 | } |
| 20040 | |
| 20041 | /* Write OBJFILE's address map to OBSTACK. |
| 20042 | CU_INDEX_HTAB is used to map addrmap entries to their CU indices |
| 20043 | in the index file. */ |
| 20044 | |
| 20045 | static void |
| 20046 | write_address_map (struct objfile *objfile, struct obstack *obstack, |
| 20047 | htab_t cu_index_htab) |
| 20048 | { |
| 20049 | struct addrmap_index_data addrmap_index_data; |
| 20050 | |
| 20051 | /* When writing the address table, we have to cope with the fact that |
| 20052 | the addrmap iterator only provides the start of a region; we have to |
| 20053 | wait until the next invocation to get the start of the next region. */ |
| 20054 | |
| 20055 | addrmap_index_data.objfile = objfile; |
| 20056 | addrmap_index_data.addr_obstack = obstack; |
| 20057 | addrmap_index_data.cu_index_htab = cu_index_htab; |
| 20058 | addrmap_index_data.previous_valid = 0; |
| 20059 | |
| 20060 | addrmap_foreach (objfile->psymtabs_addrmap, add_address_entry_worker, |
| 20061 | &addrmap_index_data); |
| 20062 | |
| 20063 | /* It's highly unlikely the last entry (end address = 0xff...ff) |
| 20064 | is valid, but we should still handle it. |
| 20065 | The end address is recorded as the start of the next region, but that |
| 20066 | doesn't work here. To cope we pass 0xff...ff, this is a rare situation |
| 20067 | anyway. */ |
| 20068 | if (addrmap_index_data.previous_valid) |
| 20069 | add_address_entry (objfile, obstack, |
| 20070 | addrmap_index_data.previous_cu_start, (CORE_ADDR) -1, |
| 20071 | addrmap_index_data.previous_cu_index); |
| 20072 | } |
| 20073 | |
| 20074 | /* Return the symbol kind of PSYM. */ |
| 20075 | |
| 20076 | static gdb_index_symbol_kind |
| 20077 | symbol_kind (struct partial_symbol *psym) |
| 20078 | { |
| 20079 | domain_enum domain = PSYMBOL_DOMAIN (psym); |
| 20080 | enum address_class aclass = PSYMBOL_CLASS (psym); |
| 20081 | |
| 20082 | switch (domain) |
| 20083 | { |
| 20084 | case VAR_DOMAIN: |
| 20085 | switch (aclass) |
| 20086 | { |
| 20087 | case LOC_BLOCK: |
| 20088 | return GDB_INDEX_SYMBOL_KIND_FUNCTION; |
| 20089 | case LOC_TYPEDEF: |
| 20090 | return GDB_INDEX_SYMBOL_KIND_TYPE; |
| 20091 | case LOC_COMPUTED: |
| 20092 | case LOC_CONST_BYTES: |
| 20093 | case LOC_OPTIMIZED_OUT: |
| 20094 | case LOC_STATIC: |
| 20095 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; |
| 20096 | case LOC_CONST: |
| 20097 | /* Note: It's currently impossible to recognize psyms as enum values |
| 20098 | short of reading the type info. For now punt. */ |
| 20099 | return GDB_INDEX_SYMBOL_KIND_VARIABLE; |
| 20100 | default: |
| 20101 | /* There are other LOC_FOO values that one might want to classify |
| 20102 | as variables, but dwarf2read.c doesn't currently use them. */ |
| 20103 | return GDB_INDEX_SYMBOL_KIND_OTHER; |
| 20104 | } |
| 20105 | case STRUCT_DOMAIN: |
| 20106 | return GDB_INDEX_SYMBOL_KIND_TYPE; |
| 20107 | default: |
| 20108 | return GDB_INDEX_SYMBOL_KIND_OTHER; |
| 20109 | } |
| 20110 | } |
| 20111 | |
| 20112 | /* Add a list of partial symbols to SYMTAB. */ |
| 20113 | |
| 20114 | static void |
| 20115 | write_psymbols (struct mapped_symtab *symtab, |
| 20116 | htab_t psyms_seen, |
| 20117 | struct partial_symbol **psymp, |
| 20118 | int count, |
| 20119 | offset_type cu_index, |
| 20120 | int is_static) |
| 20121 | { |
| 20122 | for (; count-- > 0; ++psymp) |
| 20123 | { |
| 20124 | struct partial_symbol *psym = *psymp; |
| 20125 | void **slot; |
| 20126 | |
| 20127 | if (SYMBOL_LANGUAGE (psym) == language_ada) |
| 20128 | error (_("Ada is not currently supported by the index")); |
| 20129 | |
| 20130 | /* Only add a given psymbol once. */ |
| 20131 | slot = htab_find_slot (psyms_seen, psym, INSERT); |
| 20132 | if (!*slot) |
| 20133 | { |
| 20134 | gdb_index_symbol_kind kind = symbol_kind (psym); |
| 20135 | |
| 20136 | *slot = psym; |
| 20137 | add_index_entry (symtab, SYMBOL_SEARCH_NAME (psym), |
| 20138 | is_static, kind, cu_index); |
| 20139 | } |
| 20140 | } |
| 20141 | } |
| 20142 | |
| 20143 | /* Write the contents of an ("unfinished") obstack to FILE. Throw an |
| 20144 | exception if there is an error. */ |
| 20145 | |
| 20146 | static void |
| 20147 | write_obstack (FILE *file, struct obstack *obstack) |
| 20148 | { |
| 20149 | if (fwrite (obstack_base (obstack), 1, obstack_object_size (obstack), |
| 20150 | file) |
| 20151 | != obstack_object_size (obstack)) |
| 20152 | error (_("couldn't data write to file")); |
| 20153 | } |
| 20154 | |
| 20155 | /* Unlink a file if the argument is not NULL. */ |
| 20156 | |
| 20157 | static void |
| 20158 | unlink_if_set (void *p) |
| 20159 | { |
| 20160 | char **filename = p; |
| 20161 | if (*filename) |
| 20162 | unlink (*filename); |
| 20163 | } |
| 20164 | |
| 20165 | /* A helper struct used when iterating over debug_types. */ |
| 20166 | struct signatured_type_index_data |
| 20167 | { |
| 20168 | struct objfile *objfile; |
| 20169 | struct mapped_symtab *symtab; |
| 20170 | struct obstack *types_list; |
| 20171 | htab_t psyms_seen; |
| 20172 | int cu_index; |
| 20173 | }; |
| 20174 | |
| 20175 | /* A helper function that writes a single signatured_type to an |
| 20176 | obstack. */ |
| 20177 | |
| 20178 | static int |
| 20179 | write_one_signatured_type (void **slot, void *d) |
| 20180 | { |
| 20181 | struct signatured_type_index_data *info = d; |
| 20182 | struct signatured_type *entry = (struct signatured_type *) *slot; |
| 20183 | struct dwarf2_per_cu_data *per_cu = &entry->per_cu; |
| 20184 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
| 20185 | gdb_byte val[8]; |
| 20186 | |
| 20187 | write_psymbols (info->symtab, |
| 20188 | info->psyms_seen, |
| 20189 | info->objfile->global_psymbols.list |
| 20190 | + psymtab->globals_offset, |
| 20191 | psymtab->n_global_syms, info->cu_index, |
| 20192 | 0); |
| 20193 | write_psymbols (info->symtab, |
| 20194 | info->psyms_seen, |
| 20195 | info->objfile->static_psymbols.list |
| 20196 | + psymtab->statics_offset, |
| 20197 | psymtab->n_static_syms, info->cu_index, |
| 20198 | 1); |
| 20199 | |
| 20200 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
| 20201 | entry->per_cu.offset.sect_off); |
| 20202 | obstack_grow (info->types_list, val, 8); |
| 20203 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
| 20204 | entry->type_offset_in_tu.cu_off); |
| 20205 | obstack_grow (info->types_list, val, 8); |
| 20206 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, entry->signature); |
| 20207 | obstack_grow (info->types_list, val, 8); |
| 20208 | |
| 20209 | ++info->cu_index; |
| 20210 | |
| 20211 | return 1; |
| 20212 | } |
| 20213 | |
| 20214 | /* Recurse into all "included" dependencies and write their symbols as |
| 20215 | if they appeared in this psymtab. */ |
| 20216 | |
| 20217 | static void |
| 20218 | recursively_write_psymbols (struct objfile *objfile, |
| 20219 | struct partial_symtab *psymtab, |
| 20220 | struct mapped_symtab *symtab, |
| 20221 | htab_t psyms_seen, |
| 20222 | offset_type cu_index) |
| 20223 | { |
| 20224 | int i; |
| 20225 | |
| 20226 | for (i = 0; i < psymtab->number_of_dependencies; ++i) |
| 20227 | if (psymtab->dependencies[i]->user != NULL) |
| 20228 | recursively_write_psymbols (objfile, psymtab->dependencies[i], |
| 20229 | symtab, psyms_seen, cu_index); |
| 20230 | |
| 20231 | write_psymbols (symtab, |
| 20232 | psyms_seen, |
| 20233 | objfile->global_psymbols.list + psymtab->globals_offset, |
| 20234 | psymtab->n_global_syms, cu_index, |
| 20235 | 0); |
| 20236 | write_psymbols (symtab, |
| 20237 | psyms_seen, |
| 20238 | objfile->static_psymbols.list + psymtab->statics_offset, |
| 20239 | psymtab->n_static_syms, cu_index, |
| 20240 | 1); |
| 20241 | } |
| 20242 | |
| 20243 | /* Create an index file for OBJFILE in the directory DIR. */ |
| 20244 | |
| 20245 | static void |
| 20246 | write_psymtabs_to_index (struct objfile *objfile, const char *dir) |
| 20247 | { |
| 20248 | struct cleanup *cleanup; |
| 20249 | char *filename, *cleanup_filename; |
| 20250 | struct obstack contents, addr_obstack, constant_pool, symtab_obstack; |
| 20251 | struct obstack cu_list, types_cu_list; |
| 20252 | int i; |
| 20253 | FILE *out_file; |
| 20254 | struct mapped_symtab *symtab; |
| 20255 | offset_type val, size_of_contents, total_len; |
| 20256 | struct stat st; |
| 20257 | htab_t psyms_seen; |
| 20258 | htab_t cu_index_htab; |
| 20259 | struct psymtab_cu_index_map *psymtab_cu_index_map; |
| 20260 | |
| 20261 | if (!objfile->psymtabs || !objfile->psymtabs_addrmap) |
| 20262 | return; |
| 20263 | |
| 20264 | if (dwarf2_per_objfile->using_index) |
| 20265 | error (_("Cannot use an index to create the index")); |
| 20266 | |
| 20267 | if (VEC_length (dwarf2_section_info_def, dwarf2_per_objfile->types) > 1) |
| 20268 | error (_("Cannot make an index when the file has multiple .debug_types sections")); |
| 20269 | |
| 20270 | if (stat (objfile->name, &st) < 0) |
| 20271 | perror_with_name (objfile->name); |
| 20272 | |
| 20273 | filename = concat (dir, SLASH_STRING, lbasename (objfile->name), |
| 20274 | INDEX_SUFFIX, (char *) NULL); |
| 20275 | cleanup = make_cleanup (xfree, filename); |
| 20276 | |
| 20277 | out_file = fopen (filename, "wb"); |
| 20278 | if (!out_file) |
| 20279 | error (_("Can't open `%s' for writing"), filename); |
| 20280 | |
| 20281 | cleanup_filename = filename; |
| 20282 | make_cleanup (unlink_if_set, &cleanup_filename); |
| 20283 | |
| 20284 | symtab = create_mapped_symtab (); |
| 20285 | make_cleanup (cleanup_mapped_symtab, symtab); |
| 20286 | |
| 20287 | obstack_init (&addr_obstack); |
| 20288 | make_cleanup_obstack_free (&addr_obstack); |
| 20289 | |
| 20290 | obstack_init (&cu_list); |
| 20291 | make_cleanup_obstack_free (&cu_list); |
| 20292 | |
| 20293 | obstack_init (&types_cu_list); |
| 20294 | make_cleanup_obstack_free (&types_cu_list); |
| 20295 | |
| 20296 | psyms_seen = htab_create_alloc (100, htab_hash_pointer, htab_eq_pointer, |
| 20297 | NULL, xcalloc, xfree); |
| 20298 | make_cleanup_htab_delete (psyms_seen); |
| 20299 | |
| 20300 | /* While we're scanning CU's create a table that maps a psymtab pointer |
| 20301 | (which is what addrmap records) to its index (which is what is recorded |
| 20302 | in the index file). This will later be needed to write the address |
| 20303 | table. */ |
| 20304 | cu_index_htab = htab_create_alloc (100, |
| 20305 | hash_psymtab_cu_index, |
| 20306 | eq_psymtab_cu_index, |
| 20307 | NULL, xcalloc, xfree); |
| 20308 | make_cleanup_htab_delete (cu_index_htab); |
| 20309 | psymtab_cu_index_map = (struct psymtab_cu_index_map *) |
| 20310 | xmalloc (sizeof (struct psymtab_cu_index_map) |
| 20311 | * dwarf2_per_objfile->n_comp_units); |
| 20312 | make_cleanup (xfree, psymtab_cu_index_map); |
| 20313 | |
| 20314 | /* The CU list is already sorted, so we don't need to do additional |
| 20315 | work here. Also, the debug_types entries do not appear in |
| 20316 | all_comp_units, but only in their own hash table. */ |
| 20317 | for (i = 0; i < dwarf2_per_objfile->n_comp_units; ++i) |
| 20318 | { |
| 20319 | struct dwarf2_per_cu_data *per_cu |
| 20320 | = dwarf2_per_objfile->all_comp_units[i]; |
| 20321 | struct partial_symtab *psymtab = per_cu->v.psymtab; |
| 20322 | gdb_byte val[8]; |
| 20323 | struct psymtab_cu_index_map *map; |
| 20324 | void **slot; |
| 20325 | |
| 20326 | if (psymtab->user == NULL) |
| 20327 | recursively_write_psymbols (objfile, psymtab, symtab, psyms_seen, i); |
| 20328 | |
| 20329 | map = &psymtab_cu_index_map[i]; |
| 20330 | map->psymtab = psymtab; |
| 20331 | map->cu_index = i; |
| 20332 | slot = htab_find_slot (cu_index_htab, map, INSERT); |
| 20333 | gdb_assert (slot != NULL); |
| 20334 | gdb_assert (*slot == NULL); |
| 20335 | *slot = map; |
| 20336 | |
| 20337 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, |
| 20338 | per_cu->offset.sect_off); |
| 20339 | obstack_grow (&cu_list, val, 8); |
| 20340 | store_unsigned_integer (val, 8, BFD_ENDIAN_LITTLE, per_cu->length); |
| 20341 | obstack_grow (&cu_list, val, 8); |
| 20342 | } |
| 20343 | |
| 20344 | /* Dump the address map. */ |
| 20345 | write_address_map (objfile, &addr_obstack, cu_index_htab); |
| 20346 | |
| 20347 | /* Write out the .debug_type entries, if any. */ |
| 20348 | if (dwarf2_per_objfile->signatured_types) |
| 20349 | { |
| 20350 | struct signatured_type_index_data sig_data; |
| 20351 | |
| 20352 | sig_data.objfile = objfile; |
| 20353 | sig_data.symtab = symtab; |
| 20354 | sig_data.types_list = &types_cu_list; |
| 20355 | sig_data.psyms_seen = psyms_seen; |
| 20356 | sig_data.cu_index = dwarf2_per_objfile->n_comp_units; |
| 20357 | htab_traverse_noresize (dwarf2_per_objfile->signatured_types, |
| 20358 | write_one_signatured_type, &sig_data); |
| 20359 | } |
| 20360 | |
| 20361 | /* Now that we've processed all symbols we can shrink their cu_indices |
| 20362 | lists. */ |
| 20363 | uniquify_cu_indices (symtab); |
| 20364 | |
| 20365 | obstack_init (&constant_pool); |
| 20366 | make_cleanup_obstack_free (&constant_pool); |
| 20367 | obstack_init (&symtab_obstack); |
| 20368 | make_cleanup_obstack_free (&symtab_obstack); |
| 20369 | write_hash_table (symtab, &symtab_obstack, &constant_pool); |
| 20370 | |
| 20371 | obstack_init (&contents); |
| 20372 | make_cleanup_obstack_free (&contents); |
| 20373 | size_of_contents = 6 * sizeof (offset_type); |
| 20374 | total_len = size_of_contents; |
| 20375 | |
| 20376 | /* The version number. */ |
| 20377 | val = MAYBE_SWAP (7); |
| 20378 | obstack_grow (&contents, &val, sizeof (val)); |
| 20379 | |
| 20380 | /* The offset of the CU list from the start of the file. */ |
| 20381 | val = MAYBE_SWAP (total_len); |
| 20382 | obstack_grow (&contents, &val, sizeof (val)); |
| 20383 | total_len += obstack_object_size (&cu_list); |
| 20384 | |
| 20385 | /* The offset of the types CU list from the start of the file. */ |
| 20386 | val = MAYBE_SWAP (total_len); |
| 20387 | obstack_grow (&contents, &val, sizeof (val)); |
| 20388 | total_len += obstack_object_size (&types_cu_list); |
| 20389 | |
| 20390 | /* The offset of the address table from the start of the file. */ |
| 20391 | val = MAYBE_SWAP (total_len); |
| 20392 | obstack_grow (&contents, &val, sizeof (val)); |
| 20393 | total_len += obstack_object_size (&addr_obstack); |
| 20394 | |
| 20395 | /* The offset of the symbol table from the start of the file. */ |
| 20396 | val = MAYBE_SWAP (total_len); |
| 20397 | obstack_grow (&contents, &val, sizeof (val)); |
| 20398 | total_len += obstack_object_size (&symtab_obstack); |
| 20399 | |
| 20400 | /* The offset of the constant pool from the start of the file. */ |
| 20401 | val = MAYBE_SWAP (total_len); |
| 20402 | obstack_grow (&contents, &val, sizeof (val)); |
| 20403 | total_len += obstack_object_size (&constant_pool); |
| 20404 | |
| 20405 | gdb_assert (obstack_object_size (&contents) == size_of_contents); |
| 20406 | |
| 20407 | write_obstack (out_file, &contents); |
| 20408 | write_obstack (out_file, &cu_list); |
| 20409 | write_obstack (out_file, &types_cu_list); |
| 20410 | write_obstack (out_file, &addr_obstack); |
| 20411 | write_obstack (out_file, &symtab_obstack); |
| 20412 | write_obstack (out_file, &constant_pool); |
| 20413 | |
| 20414 | fclose (out_file); |
| 20415 | |
| 20416 | /* We want to keep the file, so we set cleanup_filename to NULL |
| 20417 | here. See unlink_if_set. */ |
| 20418 | cleanup_filename = NULL; |
| 20419 | |
| 20420 | do_cleanups (cleanup); |
| 20421 | } |
| 20422 | |
| 20423 | /* Implementation of the `save gdb-index' command. |
| 20424 | |
| 20425 | Note that the file format used by this command is documented in the |
| 20426 | GDB manual. Any changes here must be documented there. */ |
| 20427 | |
| 20428 | static void |
| 20429 | save_gdb_index_command (char *arg, int from_tty) |
| 20430 | { |
| 20431 | struct objfile *objfile; |
| 20432 | |
| 20433 | if (!arg || !*arg) |
| 20434 | error (_("usage: save gdb-index DIRECTORY")); |
| 20435 | |
| 20436 | ALL_OBJFILES (objfile) |
| 20437 | { |
| 20438 | struct stat st; |
| 20439 | |
| 20440 | /* If the objfile does not correspond to an actual file, skip it. */ |
| 20441 | if (stat (objfile->name, &st) < 0) |
| 20442 | continue; |
| 20443 | |
| 20444 | dwarf2_per_objfile = objfile_data (objfile, dwarf2_objfile_data_key); |
| 20445 | if (dwarf2_per_objfile) |
| 20446 | { |
| 20447 | volatile struct gdb_exception except; |
| 20448 | |
| 20449 | TRY_CATCH (except, RETURN_MASK_ERROR) |
| 20450 | { |
| 20451 | write_psymtabs_to_index (objfile, arg); |
| 20452 | } |
| 20453 | if (except.reason < 0) |
| 20454 | exception_fprintf (gdb_stderr, except, |
| 20455 | _("Error while writing index for `%s': "), |
| 20456 | objfile->name); |
| 20457 | } |
| 20458 | } |
| 20459 | } |
| 20460 | |
| 20461 | \f |
| 20462 | |
| 20463 | int dwarf2_always_disassemble; |
| 20464 | |
| 20465 | static void |
| 20466 | show_dwarf2_always_disassemble (struct ui_file *file, int from_tty, |
| 20467 | struct cmd_list_element *c, const char *value) |
| 20468 | { |
| 20469 | fprintf_filtered (file, |
| 20470 | _("Whether to always disassemble " |
| 20471 | "DWARF expressions is %s.\n"), |
| 20472 | value); |
| 20473 | } |
| 20474 | |
| 20475 | static void |
| 20476 | show_check_physname (struct ui_file *file, int from_tty, |
| 20477 | struct cmd_list_element *c, const char *value) |
| 20478 | { |
| 20479 | fprintf_filtered (file, |
| 20480 | _("Whether to check \"physname\" is %s.\n"), |
| 20481 | value); |
| 20482 | } |
| 20483 | |
| 20484 | void _initialize_dwarf2_read (void); |
| 20485 | |
| 20486 | void |
| 20487 | _initialize_dwarf2_read (void) |
| 20488 | { |
| 20489 | struct cmd_list_element *c; |
| 20490 | |
| 20491 | dwarf2_objfile_data_key |
| 20492 | = register_objfile_data_with_cleanup (NULL, dwarf2_per_objfile_free); |
| 20493 | |
| 20494 | add_prefix_cmd ("dwarf2", class_maintenance, set_dwarf2_cmd, _("\ |
| 20495 | Set DWARF 2 specific variables.\n\ |
| 20496 | Configure DWARF 2 variables such as the cache size"), |
| 20497 | &set_dwarf2_cmdlist, "maintenance set dwarf2 ", |
| 20498 | 0/*allow-unknown*/, &maintenance_set_cmdlist); |
| 20499 | |
| 20500 | add_prefix_cmd ("dwarf2", class_maintenance, show_dwarf2_cmd, _("\ |
| 20501 | Show DWARF 2 specific variables\n\ |
| 20502 | Show DWARF 2 variables such as the cache size"), |
| 20503 | &show_dwarf2_cmdlist, "maintenance show dwarf2 ", |
| 20504 | 0/*allow-unknown*/, &maintenance_show_cmdlist); |
| 20505 | |
| 20506 | add_setshow_zinteger_cmd ("max-cache-age", class_obscure, |
| 20507 | &dwarf2_max_cache_age, _("\ |
| 20508 | Set the upper bound on the age of cached dwarf2 compilation units."), _("\ |
| 20509 | Show the upper bound on the age of cached dwarf2 compilation units."), _("\ |
| 20510 | A higher limit means that cached compilation units will be stored\n\ |
| 20511 | in memory longer, and more total memory will be used. Zero disables\n\ |
| 20512 | caching, which can slow down startup."), |
| 20513 | NULL, |
| 20514 | show_dwarf2_max_cache_age, |
| 20515 | &set_dwarf2_cmdlist, |
| 20516 | &show_dwarf2_cmdlist); |
| 20517 | |
| 20518 | add_setshow_boolean_cmd ("always-disassemble", class_obscure, |
| 20519 | &dwarf2_always_disassemble, _("\ |
| 20520 | Set whether `info address' always disassembles DWARF expressions."), _("\ |
| 20521 | Show whether `info address' always disassembles DWARF expressions."), _("\ |
| 20522 | When enabled, DWARF expressions are always printed in an assembly-like\n\ |
| 20523 | syntax. When disabled, expressions will be printed in a more\n\ |
| 20524 | conversational style, when possible."), |
| 20525 | NULL, |
| 20526 | show_dwarf2_always_disassemble, |
| 20527 | &set_dwarf2_cmdlist, |
| 20528 | &show_dwarf2_cmdlist); |
| 20529 | |
| 20530 | add_setshow_boolean_cmd ("dwarf2-read", no_class, &dwarf2_read_debug, _("\ |
| 20531 | Set debugging of the dwarf2 reader."), _("\ |
| 20532 | Show debugging of the dwarf2 reader."), _("\ |
| 20533 | When enabled, debugging messages are printed during dwarf2 reading\n\ |
| 20534 | and symtab expansion."), |
| 20535 | NULL, |
| 20536 | NULL, |
| 20537 | &setdebuglist, &showdebuglist); |
| 20538 | |
| 20539 | add_setshow_zuinteger_cmd ("dwarf2-die", no_class, &dwarf2_die_debug, _("\ |
| 20540 | Set debugging of the dwarf2 DIE reader."), _("\ |
| 20541 | Show debugging of the dwarf2 DIE reader."), _("\ |
| 20542 | When enabled (non-zero), DIEs are dumped after they are read in.\n\ |
| 20543 | The value is the maximum depth to print."), |
| 20544 | NULL, |
| 20545 | NULL, |
| 20546 | &setdebuglist, &showdebuglist); |
| 20547 | |
| 20548 | add_setshow_boolean_cmd ("check-physname", no_class, &check_physname, _("\ |
| 20549 | Set cross-checking of \"physname\" code against demangler."), _("\ |
| 20550 | Show cross-checking of \"physname\" code against demangler."), _("\ |
| 20551 | When enabled, GDB's internal \"physname\" code is checked against\n\ |
| 20552 | the demangler."), |
| 20553 | NULL, show_check_physname, |
| 20554 | &setdebuglist, &showdebuglist); |
| 20555 | |
| 20556 | add_setshow_boolean_cmd ("use-deprecated-index-sections", |
| 20557 | no_class, &use_deprecated_index_sections, _("\ |
| 20558 | Set whether to use deprecated gdb_index sections."), _("\ |
| 20559 | Show whether to use deprecated gdb_index sections."), _("\ |
| 20560 | When enabled, deprecated .gdb_index sections are used anyway.\n\ |
| 20561 | Normally they are ignored either because of a missing feature or\n\ |
| 20562 | performance issue.\n\ |
| 20563 | Warning: This option must be enabled before gdb reads the file."), |
| 20564 | NULL, |
| 20565 | NULL, |
| 20566 | &setlist, &showlist); |
| 20567 | |
| 20568 | c = add_cmd ("gdb-index", class_files, save_gdb_index_command, |
| 20569 | _("\ |
| 20570 | Save a gdb-index file.\n\ |
| 20571 | Usage: save gdb-index DIRECTORY"), |
| 20572 | &save_cmdlist); |
| 20573 | set_cmd_completer (c, filename_completer); |
| 20574 | } |