| 1 | /* DWARF 2 debugging format support for GDB. |
| 2 | Copyright 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003 |
| 3 | 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 in dwarfread.c |
| 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 2 of the License, or (at |
| 17 | your option) any later version. |
| 18 | |
| 19 | This program is distributed in the hope that it will be useful, but |
| 20 | WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 22 | 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, write to the Free Software |
| 26 | Foundation, Inc., 59 Temple Place - Suite 330, |
| 27 | Boston, MA 02111-1307, USA. */ |
| 28 | |
| 29 | #include "defs.h" |
| 30 | #include "bfd.h" |
| 31 | #include "symtab.h" |
| 32 | #include "gdbtypes.h" |
| 33 | #include "symfile.h" |
| 34 | #include "objfiles.h" |
| 35 | #include "elf/dwarf2.h" |
| 36 | #include "buildsym.h" |
| 37 | #include "demangle.h" |
| 38 | #include "expression.h" |
| 39 | #include "filenames.h" /* for DOSish file names */ |
| 40 | #include "macrotab.h" |
| 41 | #include "language.h" |
| 42 | #include "complaints.h" |
| 43 | #include "bcache.h" |
| 44 | #include "dwarf2expr.h" |
| 45 | #include "dwarf2loc.h" |
| 46 | #include "cp-support.h" |
| 47 | |
| 48 | #include <fcntl.h> |
| 49 | #include "gdb_string.h" |
| 50 | #include "gdb_assert.h" |
| 51 | #include <sys/types.h> |
| 52 | |
| 53 | #ifndef DWARF2_REG_TO_REGNUM |
| 54 | #define DWARF2_REG_TO_REGNUM(REG) (REG) |
| 55 | #endif |
| 56 | |
| 57 | #if 0 |
| 58 | /* .debug_info header for a compilation unit |
| 59 | Because of alignment constraints, this structure has padding and cannot |
| 60 | be mapped directly onto the beginning of the .debug_info section. */ |
| 61 | typedef struct comp_unit_header |
| 62 | { |
| 63 | unsigned int length; /* length of the .debug_info |
| 64 | contribution */ |
| 65 | unsigned short version; /* version number -- 2 for DWARF |
| 66 | version 2 */ |
| 67 | unsigned int abbrev_offset; /* offset into .debug_abbrev section */ |
| 68 | unsigned char addr_size; /* byte size of an address -- 4 */ |
| 69 | } |
| 70 | _COMP_UNIT_HEADER; |
| 71 | #define _ACTUAL_COMP_UNIT_HEADER_SIZE 11 |
| 72 | #endif |
| 73 | |
| 74 | /* .debug_pubnames header |
| 75 | Because of alignment constraints, this structure has padding and cannot |
| 76 | be mapped directly onto the beginning of the .debug_info section. */ |
| 77 | typedef struct pubnames_header |
| 78 | { |
| 79 | unsigned int length; /* length of the .debug_pubnames |
| 80 | contribution */ |
| 81 | unsigned char version; /* version number -- 2 for DWARF |
| 82 | version 2 */ |
| 83 | unsigned int info_offset; /* offset into .debug_info section */ |
| 84 | unsigned int info_size; /* byte size of .debug_info section |
| 85 | portion */ |
| 86 | } |
| 87 | _PUBNAMES_HEADER; |
| 88 | #define _ACTUAL_PUBNAMES_HEADER_SIZE 13 |
| 89 | |
| 90 | /* .debug_pubnames header |
| 91 | Because of alignment constraints, this structure has padding and cannot |
| 92 | be mapped directly onto the beginning of the .debug_info section. */ |
| 93 | typedef struct aranges_header |
| 94 | { |
| 95 | unsigned int length; /* byte len of the .debug_aranges |
| 96 | contribution */ |
| 97 | unsigned short version; /* version number -- 2 for DWARF |
| 98 | version 2 */ |
| 99 | unsigned int info_offset; /* offset into .debug_info section */ |
| 100 | unsigned char addr_size; /* byte size of an address */ |
| 101 | unsigned char seg_size; /* byte size of segment descriptor */ |
| 102 | } |
| 103 | _ARANGES_HEADER; |
| 104 | #define _ACTUAL_ARANGES_HEADER_SIZE 12 |
| 105 | |
| 106 | /* .debug_line statement program prologue |
| 107 | Because of alignment constraints, this structure has padding and cannot |
| 108 | be mapped directly onto the beginning of the .debug_info section. */ |
| 109 | typedef struct statement_prologue |
| 110 | { |
| 111 | unsigned int total_length; /* byte length of the statement |
| 112 | information */ |
| 113 | unsigned short version; /* version number -- 2 for DWARF |
| 114 | version 2 */ |
| 115 | unsigned int prologue_length; /* # bytes between prologue & |
| 116 | stmt program */ |
| 117 | unsigned char minimum_instruction_length; /* byte size of |
| 118 | smallest instr */ |
| 119 | unsigned char default_is_stmt; /* initial value of is_stmt |
| 120 | register */ |
| 121 | char line_base; |
| 122 | unsigned char line_range; |
| 123 | unsigned char opcode_base; /* number assigned to first special |
| 124 | opcode */ |
| 125 | unsigned char *standard_opcode_lengths; |
| 126 | } |
| 127 | _STATEMENT_PROLOGUE; |
| 128 | |
| 129 | /* offsets and sizes of debugging sections */ |
| 130 | |
| 131 | static file_ptr dwarf_info_offset; |
| 132 | static file_ptr dwarf_abbrev_offset; |
| 133 | static file_ptr dwarf_line_offset; |
| 134 | static file_ptr dwarf_pubnames_offset; |
| 135 | static file_ptr dwarf_aranges_offset; |
| 136 | static file_ptr dwarf_loc_offset; |
| 137 | static file_ptr dwarf_macinfo_offset; |
| 138 | static file_ptr dwarf_str_offset; |
| 139 | static file_ptr dwarf_ranges_offset; |
| 140 | file_ptr dwarf_frame_offset; |
| 141 | file_ptr dwarf_eh_frame_offset; |
| 142 | |
| 143 | static unsigned int dwarf_info_size; |
| 144 | static unsigned int dwarf_abbrev_size; |
| 145 | static unsigned int dwarf_line_size; |
| 146 | static unsigned int dwarf_pubnames_size; |
| 147 | static unsigned int dwarf_aranges_size; |
| 148 | static unsigned int dwarf_loc_size; |
| 149 | static unsigned int dwarf_macinfo_size; |
| 150 | static unsigned int dwarf_str_size; |
| 151 | static unsigned int dwarf_ranges_size; |
| 152 | unsigned int dwarf_frame_size; |
| 153 | unsigned int dwarf_eh_frame_size; |
| 154 | |
| 155 | static asection *dwarf_info_section; |
| 156 | static asection *dwarf_abbrev_section; |
| 157 | static asection *dwarf_line_section; |
| 158 | static asection *dwarf_pubnames_section; |
| 159 | static asection *dwarf_aranges_section; |
| 160 | static asection *dwarf_loc_section; |
| 161 | static asection *dwarf_macinfo_section; |
| 162 | static asection *dwarf_str_section; |
| 163 | static asection *dwarf_ranges_section; |
| 164 | asection *dwarf_frame_section; |
| 165 | asection *dwarf_eh_frame_section; |
| 166 | |
| 167 | /* names of the debugging sections */ |
| 168 | |
| 169 | #define INFO_SECTION ".debug_info" |
| 170 | #define ABBREV_SECTION ".debug_abbrev" |
| 171 | #define LINE_SECTION ".debug_line" |
| 172 | #define PUBNAMES_SECTION ".debug_pubnames" |
| 173 | #define ARANGES_SECTION ".debug_aranges" |
| 174 | #define LOC_SECTION ".debug_loc" |
| 175 | #define MACINFO_SECTION ".debug_macinfo" |
| 176 | #define STR_SECTION ".debug_str" |
| 177 | #define RANGES_SECTION ".debug_ranges" |
| 178 | #define FRAME_SECTION ".debug_frame" |
| 179 | #define EH_FRAME_SECTION ".eh_frame" |
| 180 | |
| 181 | /* local data types */ |
| 182 | |
| 183 | /* We hold several abbreviation tables in memory at the same time. */ |
| 184 | #ifndef ABBREV_HASH_SIZE |
| 185 | #define ABBREV_HASH_SIZE 121 |
| 186 | #endif |
| 187 | |
| 188 | /* The data in a compilation unit header, after target2host |
| 189 | translation, looks like this. */ |
| 190 | struct comp_unit_head |
| 191 | { |
| 192 | unsigned long length; |
| 193 | short version; |
| 194 | unsigned int abbrev_offset; |
| 195 | unsigned char addr_size; |
| 196 | unsigned char signed_addr_p; |
| 197 | unsigned int offset_size; /* size of file offsets; either 4 or 8 */ |
| 198 | unsigned int initial_length_size; /* size of the length field; either |
| 199 | 4 or 12 */ |
| 200 | |
| 201 | /* Offset to the first byte of this compilation unit header in the |
| 202 | * .debug_info section, for resolving relative reference dies. */ |
| 203 | |
| 204 | unsigned int offset; |
| 205 | |
| 206 | /* Pointer to this compilation unit header in the .debug_info |
| 207 | * section */ |
| 208 | |
| 209 | char *cu_head_ptr; |
| 210 | |
| 211 | /* Pointer to the first die of this compilatio unit. This will |
| 212 | * be the first byte following the compilation unit header. */ |
| 213 | |
| 214 | char *first_die_ptr; |
| 215 | |
| 216 | /* Pointer to the next compilation unit header in the program. */ |
| 217 | |
| 218 | struct comp_unit_head *next; |
| 219 | |
| 220 | /* DWARF abbreviation table associated with this compilation unit */ |
| 221 | |
| 222 | struct abbrev_info *dwarf2_abbrevs[ABBREV_HASH_SIZE]; |
| 223 | |
| 224 | /* Base address of this compilation unit. */ |
| 225 | |
| 226 | CORE_ADDR base_address; |
| 227 | |
| 228 | /* Non-zero if base_address has been set. */ |
| 229 | |
| 230 | int base_known; |
| 231 | }; |
| 232 | |
| 233 | /* The line number information for a compilation unit (found in the |
| 234 | .debug_line section) begins with a "statement program header", |
| 235 | which contains the following information. */ |
| 236 | struct line_header |
| 237 | { |
| 238 | unsigned int total_length; |
| 239 | unsigned short version; |
| 240 | unsigned int header_length; |
| 241 | unsigned char minimum_instruction_length; |
| 242 | unsigned char default_is_stmt; |
| 243 | int line_base; |
| 244 | unsigned char line_range; |
| 245 | unsigned char opcode_base; |
| 246 | |
| 247 | /* standard_opcode_lengths[i] is the number of operands for the |
| 248 | standard opcode whose value is i. This means that |
| 249 | standard_opcode_lengths[0] is unused, and the last meaningful |
| 250 | element is standard_opcode_lengths[opcode_base - 1]. */ |
| 251 | unsigned char *standard_opcode_lengths; |
| 252 | |
| 253 | /* The include_directories table. NOTE! These strings are not |
| 254 | allocated with xmalloc; instead, they are pointers into |
| 255 | debug_line_buffer. If you try to free them, `free' will get |
| 256 | indigestion. */ |
| 257 | unsigned int num_include_dirs, include_dirs_size; |
| 258 | char **include_dirs; |
| 259 | |
| 260 | /* The file_names table. NOTE! These strings are not allocated |
| 261 | with xmalloc; instead, they are pointers into debug_line_buffer. |
| 262 | Don't try to free them directly. */ |
| 263 | unsigned int num_file_names, file_names_size; |
| 264 | struct file_entry |
| 265 | { |
| 266 | char *name; |
| 267 | unsigned int dir_index; |
| 268 | unsigned int mod_time; |
| 269 | unsigned int length; |
| 270 | } *file_names; |
| 271 | |
| 272 | /* The start and end of the statement program following this |
| 273 | header. These point into dwarf_line_buffer. */ |
| 274 | char *statement_program_start, *statement_program_end; |
| 275 | }; |
| 276 | |
| 277 | /* When we construct a partial symbol table entry we only |
| 278 | need this much information. */ |
| 279 | struct partial_die_info |
| 280 | { |
| 281 | enum dwarf_tag tag; |
| 282 | unsigned char has_children; |
| 283 | unsigned char is_external; |
| 284 | unsigned char is_declaration; |
| 285 | unsigned char has_type; |
| 286 | unsigned int offset; |
| 287 | unsigned int abbrev; |
| 288 | char *name; |
| 289 | int has_pc_info; |
| 290 | CORE_ADDR lowpc; |
| 291 | CORE_ADDR highpc; |
| 292 | struct dwarf_block *locdesc; |
| 293 | unsigned int language; |
| 294 | char *sibling; |
| 295 | }; |
| 296 | |
| 297 | /* This data structure holds the information of an abbrev. */ |
| 298 | struct abbrev_info |
| 299 | { |
| 300 | unsigned int number; /* number identifying abbrev */ |
| 301 | enum dwarf_tag tag; /* dwarf tag */ |
| 302 | int has_children; /* boolean */ |
| 303 | unsigned int num_attrs; /* number of attributes */ |
| 304 | struct attr_abbrev *attrs; /* an array of attribute descriptions */ |
| 305 | struct abbrev_info *next; /* next in chain */ |
| 306 | }; |
| 307 | |
| 308 | struct attr_abbrev |
| 309 | { |
| 310 | enum dwarf_attribute name; |
| 311 | enum dwarf_form form; |
| 312 | }; |
| 313 | |
| 314 | /* This data structure holds a complete die structure. */ |
| 315 | struct die_info |
| 316 | { |
| 317 | enum dwarf_tag tag; /* Tag indicating type of die */ |
| 318 | unsigned short has_children; /* Does the die have children */ |
| 319 | unsigned int abbrev; /* Abbrev number */ |
| 320 | unsigned int offset; /* Offset in .debug_info section */ |
| 321 | unsigned int num_attrs; /* Number of attributes */ |
| 322 | struct attribute *attrs; /* An array of attributes */ |
| 323 | struct die_info *next_ref; /* Next die in ref hash table */ |
| 324 | struct die_info *next; /* Next die in linked list */ |
| 325 | struct type *type; /* Cached type information */ |
| 326 | }; |
| 327 | |
| 328 | /* Attributes have a name and a value */ |
| 329 | struct attribute |
| 330 | { |
| 331 | enum dwarf_attribute name; |
| 332 | enum dwarf_form form; |
| 333 | union |
| 334 | { |
| 335 | char *str; |
| 336 | struct dwarf_block *blk; |
| 337 | unsigned long unsnd; |
| 338 | long int snd; |
| 339 | CORE_ADDR addr; |
| 340 | } |
| 341 | u; |
| 342 | }; |
| 343 | |
| 344 | struct function_range |
| 345 | { |
| 346 | const char *name; |
| 347 | CORE_ADDR lowpc, highpc; |
| 348 | int seen_line; |
| 349 | struct function_range *next; |
| 350 | }; |
| 351 | |
| 352 | static struct function_range *cu_first_fn, *cu_last_fn, *cu_cached_fn; |
| 353 | |
| 354 | /* Get at parts of an attribute structure */ |
| 355 | |
| 356 | #define DW_STRING(attr) ((attr)->u.str) |
| 357 | #define DW_UNSND(attr) ((attr)->u.unsnd) |
| 358 | #define DW_BLOCK(attr) ((attr)->u.blk) |
| 359 | #define DW_SND(attr) ((attr)->u.snd) |
| 360 | #define DW_ADDR(attr) ((attr)->u.addr) |
| 361 | |
| 362 | /* Blocks are a bunch of untyped bytes. */ |
| 363 | struct dwarf_block |
| 364 | { |
| 365 | unsigned int size; |
| 366 | char *data; |
| 367 | }; |
| 368 | |
| 369 | #ifndef ATTR_ALLOC_CHUNK |
| 370 | #define ATTR_ALLOC_CHUNK 4 |
| 371 | #endif |
| 372 | |
| 373 | /* A hash table of die offsets for following references. */ |
| 374 | #ifndef REF_HASH_SIZE |
| 375 | #define REF_HASH_SIZE 1021 |
| 376 | #endif |
| 377 | |
| 378 | static struct die_info *die_ref_table[REF_HASH_SIZE]; |
| 379 | |
| 380 | /* Obstack for allocating temporary storage used during symbol reading. */ |
| 381 | static struct obstack dwarf2_tmp_obstack; |
| 382 | |
| 383 | /* Offset to the first byte of the current compilation unit header, |
| 384 | for resolving relative reference dies. */ |
| 385 | static unsigned int cu_header_offset; |
| 386 | |
| 387 | /* Allocate fields for structs, unions and enums in this size. */ |
| 388 | #ifndef DW_FIELD_ALLOC_CHUNK |
| 389 | #define DW_FIELD_ALLOC_CHUNK 4 |
| 390 | #endif |
| 391 | |
| 392 | /* The language we are debugging. */ |
| 393 | static enum language cu_language; |
| 394 | static const struct language_defn *cu_language_defn; |
| 395 | |
| 396 | /* Actually data from the sections. */ |
| 397 | static char *dwarf_info_buffer; |
| 398 | static char *dwarf_abbrev_buffer; |
| 399 | static char *dwarf_line_buffer; |
| 400 | static char *dwarf_str_buffer; |
| 401 | static char *dwarf_macinfo_buffer; |
| 402 | static char *dwarf_ranges_buffer; |
| 403 | static char *dwarf_loc_buffer; |
| 404 | |
| 405 | /* A zeroed version of a partial die for initialization purposes. */ |
| 406 | static struct partial_die_info zeroed_partial_die; |
| 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 first |
| 414 | local scope, and all other local scopes as nested local scopes, and worked |
| 415 | fine. Check to see if we really need to distinguish these |
| 416 | in buildsym.c. */ |
| 417 | static struct pending **list_in_scope = &file_symbols; |
| 418 | |
| 419 | /* FIXME: decode_locdesc sets these variables to describe the location |
| 420 | to the caller. These ought to be a structure or something. If |
| 421 | none of the flags are set, the object lives at the address returned |
| 422 | by decode_locdesc. */ |
| 423 | |
| 424 | static int optimized_out; /* No ops in location in expression, |
| 425 | so object was optimized out. */ |
| 426 | static int isreg; /* Object lives in register. |
| 427 | decode_locdesc's return value is |
| 428 | the register number. */ |
| 429 | static int offreg; /* Object's address is the sum of the |
| 430 | register specified by basereg, plus |
| 431 | the offset returned. */ |
| 432 | static int basereg; /* See `offreg'. */ |
| 433 | static int isderef; /* Value described by flags above is |
| 434 | the address of a pointer to the object. */ |
| 435 | static int islocal; /* Variable is at the returned offset |
| 436 | from the frame start, but there's |
| 437 | no identified frame pointer for |
| 438 | this function, so we can't say |
| 439 | which register it's relative to; |
| 440 | use LOC_LOCAL. */ |
| 441 | static int is_thread_local; /* Variable is at a constant offset in the |
| 442 | thread-local storage block for the |
| 443 | current thread and the dynamic linker |
| 444 | module containing this expression. |
| 445 | decode_locdesc returns the offset from |
| 446 | that base. */ |
| 447 | |
| 448 | /* DW_AT_frame_base values for the current function. |
| 449 | frame_base_reg is -1 if DW_AT_frame_base is missing, otherwise it |
| 450 | contains the register number for the frame register. |
| 451 | frame_base_offset is the offset from the frame register to the |
| 452 | virtual stack frame. */ |
| 453 | static int frame_base_reg; |
| 454 | static CORE_ADDR frame_base_offset; |
| 455 | |
| 456 | /* This value is added to each symbol value. FIXME: Generalize to |
| 457 | the section_offsets structure used by dbxread (once this is done, |
| 458 | pass the appropriate section number to end_symtab). */ |
| 459 | static CORE_ADDR baseaddr; /* Add to each symbol value */ |
| 460 | |
| 461 | /* We put a pointer to this structure in the read_symtab_private field |
| 462 | of the psymtab. |
| 463 | The complete dwarf information for an objfile is kept in the |
| 464 | psymbol_obstack, so that absolute die references can be handled. |
| 465 | Most of the information in this structure is related to an entire |
| 466 | object file and could be passed via the sym_private field of the objfile. |
| 467 | It is however conceivable that dwarf2 might not be the only type |
| 468 | of symbols read from an object file. */ |
| 469 | |
| 470 | struct dwarf2_pinfo |
| 471 | { |
| 472 | /* Pointer to start of dwarf info buffer for the objfile. */ |
| 473 | |
| 474 | char *dwarf_info_buffer; |
| 475 | |
| 476 | /* Offset in dwarf_info_buffer for this compilation unit. */ |
| 477 | |
| 478 | unsigned long dwarf_info_offset; |
| 479 | |
| 480 | /* Pointer to start of dwarf abbreviation buffer for the objfile. */ |
| 481 | |
| 482 | char *dwarf_abbrev_buffer; |
| 483 | |
| 484 | /* Size of dwarf abbreviation section for the objfile. */ |
| 485 | |
| 486 | unsigned int dwarf_abbrev_size; |
| 487 | |
| 488 | /* Pointer to start of dwarf line buffer for the objfile. */ |
| 489 | |
| 490 | char *dwarf_line_buffer; |
| 491 | |
| 492 | /* Size of dwarf_line_buffer, in bytes. */ |
| 493 | |
| 494 | unsigned int dwarf_line_size; |
| 495 | |
| 496 | /* Pointer to start of dwarf string buffer for the objfile. */ |
| 497 | |
| 498 | char *dwarf_str_buffer; |
| 499 | |
| 500 | /* Size of dwarf string section for the objfile. */ |
| 501 | |
| 502 | unsigned int dwarf_str_size; |
| 503 | |
| 504 | /* Pointer to start of dwarf macro buffer for the objfile. */ |
| 505 | |
| 506 | char *dwarf_macinfo_buffer; |
| 507 | |
| 508 | /* Size of dwarf macinfo section for the objfile. */ |
| 509 | |
| 510 | unsigned int dwarf_macinfo_size; |
| 511 | |
| 512 | /* Pointer to start of dwarf ranges buffer for the objfile. */ |
| 513 | |
| 514 | char *dwarf_ranges_buffer; |
| 515 | |
| 516 | /* Size of dwarf ranges buffer for the objfile. */ |
| 517 | |
| 518 | unsigned int dwarf_ranges_size; |
| 519 | |
| 520 | /* Pointer to start of dwarf locations buffer for the objfile. */ |
| 521 | |
| 522 | char *dwarf_loc_buffer; |
| 523 | |
| 524 | /* Size of dwarf locations buffer for the objfile. */ |
| 525 | |
| 526 | unsigned int dwarf_loc_size; |
| 527 | }; |
| 528 | |
| 529 | #define PST_PRIVATE(p) ((struct dwarf2_pinfo *)(p)->read_symtab_private) |
| 530 | #define DWARF_INFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_info_buffer) |
| 531 | #define DWARF_INFO_OFFSET(p) (PST_PRIVATE(p)->dwarf_info_offset) |
| 532 | #define DWARF_ABBREV_BUFFER(p) (PST_PRIVATE(p)->dwarf_abbrev_buffer) |
| 533 | #define DWARF_ABBREV_SIZE(p) (PST_PRIVATE(p)->dwarf_abbrev_size) |
| 534 | #define DWARF_LINE_BUFFER(p) (PST_PRIVATE(p)->dwarf_line_buffer) |
| 535 | #define DWARF_LINE_SIZE(p) (PST_PRIVATE(p)->dwarf_line_size) |
| 536 | #define DWARF_STR_BUFFER(p) (PST_PRIVATE(p)->dwarf_str_buffer) |
| 537 | #define DWARF_STR_SIZE(p) (PST_PRIVATE(p)->dwarf_str_size) |
| 538 | #define DWARF_MACINFO_BUFFER(p) (PST_PRIVATE(p)->dwarf_macinfo_buffer) |
| 539 | #define DWARF_MACINFO_SIZE(p) (PST_PRIVATE(p)->dwarf_macinfo_size) |
| 540 | #define DWARF_RANGES_BUFFER(p) (PST_PRIVATE(p)->dwarf_ranges_buffer) |
| 541 | #define DWARF_RANGES_SIZE(p) (PST_PRIVATE(p)->dwarf_ranges_size) |
| 542 | #define DWARF_LOC_BUFFER(p) (PST_PRIVATE(p)->dwarf_loc_buffer) |
| 543 | #define DWARF_LOC_SIZE(p) (PST_PRIVATE(p)->dwarf_loc_size) |
| 544 | |
| 545 | /* Maintain an array of referenced fundamental types for the current |
| 546 | compilation unit being read. For DWARF version 1, we have to construct |
| 547 | the fundamental types on the fly, since no information about the |
| 548 | fundamental types is supplied. Each such fundamental type is created by |
| 549 | calling a language dependent routine to create the type, and then a |
| 550 | pointer to that type is then placed in the array at the index specified |
| 551 | by it's FT_<TYPENAME> value. The array has a fixed size set by the |
| 552 | FT_NUM_MEMBERS compile time constant, which is the number of predefined |
| 553 | fundamental types gdb knows how to construct. */ |
| 554 | static struct type *ftypes[FT_NUM_MEMBERS]; /* Fundamental types */ |
| 555 | |
| 556 | /* FIXME: We might want to set this from BFD via bfd_arch_bits_per_byte, |
| 557 | but this would require a corresponding change in unpack_field_as_long |
| 558 | and friends. */ |
| 559 | static int bits_per_byte = 8; |
| 560 | |
| 561 | /* The routines that read and process dies for a C struct or C++ class |
| 562 | pass lists of data member fields and lists of member function fields |
| 563 | in an instance of a field_info structure, as defined below. */ |
| 564 | struct field_info |
| 565 | { |
| 566 | /* List of data member and baseclasses fields. */ |
| 567 | struct nextfield |
| 568 | { |
| 569 | struct nextfield *next; |
| 570 | int accessibility; |
| 571 | int virtuality; |
| 572 | struct field field; |
| 573 | } |
| 574 | *fields; |
| 575 | |
| 576 | /* Number of fields. */ |
| 577 | int nfields; |
| 578 | |
| 579 | /* Number of baseclasses. */ |
| 580 | int nbaseclasses; |
| 581 | |
| 582 | /* Set if the accesibility of one of the fields is not public. */ |
| 583 | int non_public_fields; |
| 584 | |
| 585 | /* Member function fields array, entries are allocated in the order they |
| 586 | are encountered in the object file. */ |
| 587 | struct nextfnfield |
| 588 | { |
| 589 | struct nextfnfield *next; |
| 590 | struct fn_field fnfield; |
| 591 | } |
| 592 | *fnfields; |
| 593 | |
| 594 | /* Member function fieldlist array, contains name of possibly overloaded |
| 595 | member function, number of overloaded member functions and a pointer |
| 596 | to the head of the member function field chain. */ |
| 597 | struct fnfieldlist |
| 598 | { |
| 599 | char *name; |
| 600 | int length; |
| 601 | struct nextfnfield *head; |
| 602 | } |
| 603 | *fnfieldlists; |
| 604 | |
| 605 | /* Number of entries in the fnfieldlists array. */ |
| 606 | int nfnfields; |
| 607 | }; |
| 608 | |
| 609 | /* Various complaints about symbol reading that don't abort the process */ |
| 610 | |
| 611 | static void |
| 612 | dwarf2_non_const_array_bound_ignored_complaint (const char *arg1) |
| 613 | { |
| 614 | complaint (&symfile_complaints, "non-constant array bounds form '%s' ignored", |
| 615 | arg1); |
| 616 | } |
| 617 | |
| 618 | static void |
| 619 | dwarf2_statement_list_fits_in_line_number_section_complaint (void) |
| 620 | { |
| 621 | complaint (&symfile_complaints, |
| 622 | "statement list doesn't fit in .debug_line section"); |
| 623 | } |
| 624 | |
| 625 | static void |
| 626 | dwarf2_complex_location_expr_complaint (void) |
| 627 | { |
| 628 | complaint (&symfile_complaints, "location expression too complex"); |
| 629 | } |
| 630 | |
| 631 | static void |
| 632 | dwarf2_unsupported_at_frame_base_complaint (const char *arg1) |
| 633 | { |
| 634 | complaint (&symfile_complaints, |
| 635 | "unsupported DW_AT_frame_base for function '%s'", arg1); |
| 636 | } |
| 637 | |
| 638 | static void |
| 639 | dwarf2_const_value_length_mismatch_complaint (const char *arg1, int arg2, |
| 640 | int arg3) |
| 641 | { |
| 642 | complaint (&symfile_complaints, |
| 643 | "const value length mismatch for '%s', got %d, expected %d", arg1, |
| 644 | arg2, arg3); |
| 645 | } |
| 646 | |
| 647 | static void |
| 648 | dwarf2_macros_too_long_complaint (void) |
| 649 | { |
| 650 | complaint (&symfile_complaints, |
| 651 | "macro info runs off end of `.debug_macinfo' section"); |
| 652 | } |
| 653 | |
| 654 | static void |
| 655 | dwarf2_macro_malformed_definition_complaint (const char *arg1) |
| 656 | { |
| 657 | complaint (&symfile_complaints, |
| 658 | "macro debug info contains a malformed macro definition:\n`%s'", |
| 659 | arg1); |
| 660 | } |
| 661 | |
| 662 | static void |
| 663 | dwarf2_invalid_attrib_class_complaint (const char *arg1, const char *arg2) |
| 664 | { |
| 665 | complaint (&symfile_complaints, |
| 666 | "invalid attribute class or form for '%s' in '%s'", arg1, arg2); |
| 667 | } |
| 668 | |
| 669 | /* local function prototypes */ |
| 670 | |
| 671 | static void dwarf2_locate_sections (bfd *, asection *, void *); |
| 672 | |
| 673 | #if 0 |
| 674 | static void dwarf2_build_psymtabs_easy (struct objfile *, int); |
| 675 | #endif |
| 676 | |
| 677 | static void dwarf2_build_psymtabs_hard (struct objfile *, int); |
| 678 | |
| 679 | static char *scan_partial_symbols (char *, struct objfile *, |
| 680 | CORE_ADDR *, CORE_ADDR *, |
| 681 | const struct comp_unit_head *); |
| 682 | |
| 683 | static void add_partial_symbol (struct partial_die_info *, struct objfile *, |
| 684 | const struct comp_unit_head *); |
| 685 | |
| 686 | static void dwarf2_psymtab_to_symtab (struct partial_symtab *); |
| 687 | |
| 688 | static void psymtab_to_symtab_1 (struct partial_symtab *); |
| 689 | |
| 690 | char *dwarf2_read_section (struct objfile *, file_ptr, unsigned int, |
| 691 | asection *); |
| 692 | |
| 693 | static void dwarf2_read_abbrevs (bfd *abfd, struct comp_unit_head *cu_header); |
| 694 | |
| 695 | static void dwarf2_empty_abbrev_table (void *); |
| 696 | |
| 697 | static struct abbrev_info *dwarf2_lookup_abbrev (unsigned int, |
| 698 | const struct comp_unit_head *cu_header); |
| 699 | |
| 700 | static char *read_partial_die (struct partial_die_info *, |
| 701 | bfd *, char *, |
| 702 | const struct comp_unit_head *); |
| 703 | |
| 704 | static char *read_full_die (struct die_info **, bfd *, char *, |
| 705 | const struct comp_unit_head *); |
| 706 | |
| 707 | static char *read_attribute (struct attribute *, struct attr_abbrev *, |
| 708 | bfd *, char *, const struct comp_unit_head *); |
| 709 | |
| 710 | static char *read_attribute_value (struct attribute *, unsigned, |
| 711 | bfd *, char *, const struct comp_unit_head *); |
| 712 | |
| 713 | static unsigned int read_1_byte (bfd *, char *); |
| 714 | |
| 715 | static int read_1_signed_byte (bfd *, char *); |
| 716 | |
| 717 | static unsigned int read_2_bytes (bfd *, char *); |
| 718 | |
| 719 | static unsigned int read_4_bytes (bfd *, char *); |
| 720 | |
| 721 | static unsigned long read_8_bytes (bfd *, char *); |
| 722 | |
| 723 | static CORE_ADDR read_address (bfd *, char *ptr, const struct comp_unit_head *, |
| 724 | int *bytes_read); |
| 725 | |
| 726 | static LONGEST read_initial_length (bfd *, char *, |
| 727 | struct comp_unit_head *, int *bytes_read); |
| 728 | |
| 729 | static LONGEST read_offset (bfd *, char *, const struct comp_unit_head *, |
| 730 | int *bytes_read); |
| 731 | |
| 732 | static char *read_n_bytes (bfd *, char *, unsigned int); |
| 733 | |
| 734 | static char *read_string (bfd *, char *, unsigned int *); |
| 735 | |
| 736 | static char *read_indirect_string (bfd *, char *, const struct comp_unit_head *, |
| 737 | unsigned int *); |
| 738 | |
| 739 | static unsigned long read_unsigned_leb128 (bfd *, char *, unsigned int *); |
| 740 | |
| 741 | static long read_signed_leb128 (bfd *, char *, unsigned int *); |
| 742 | |
| 743 | static void set_cu_language (unsigned int); |
| 744 | |
| 745 | static struct attribute *dwarf_attr (struct die_info *, unsigned int); |
| 746 | |
| 747 | static int die_is_declaration (struct die_info *); |
| 748 | |
| 749 | static void free_line_header (struct line_header *lh); |
| 750 | |
| 751 | static struct line_header *(dwarf_decode_line_header |
| 752 | (unsigned int offset, |
| 753 | bfd *abfd, |
| 754 | const struct comp_unit_head *cu_header)); |
| 755 | |
| 756 | static void dwarf_decode_lines (struct line_header *, char *, bfd *, |
| 757 | const struct comp_unit_head *); |
| 758 | |
| 759 | static void dwarf2_start_subfile (char *, char *); |
| 760 | |
| 761 | static struct symbol *new_symbol (struct die_info *, struct type *, |
| 762 | struct objfile *, const struct comp_unit_head *); |
| 763 | |
| 764 | static void dwarf2_const_value (struct attribute *, struct symbol *, |
| 765 | struct objfile *, const struct comp_unit_head *); |
| 766 | |
| 767 | static void dwarf2_const_value_data (struct attribute *attr, |
| 768 | struct symbol *sym, |
| 769 | int bits); |
| 770 | |
| 771 | static struct type *die_type (struct die_info *, struct objfile *, |
| 772 | const struct comp_unit_head *); |
| 773 | |
| 774 | static struct type *die_containing_type (struct die_info *, struct objfile *, |
| 775 | const struct comp_unit_head *); |
| 776 | |
| 777 | #if 0 |
| 778 | static struct type *type_at_offset (unsigned int, struct objfile *); |
| 779 | #endif |
| 780 | |
| 781 | static struct type *tag_type_to_type (struct die_info *, struct objfile *, |
| 782 | const struct comp_unit_head *); |
| 783 | |
| 784 | static void read_type_die (struct die_info *, struct objfile *, |
| 785 | const struct comp_unit_head *); |
| 786 | |
| 787 | static void read_typedef (struct die_info *, struct objfile *, |
| 788 | const struct comp_unit_head *); |
| 789 | |
| 790 | static void read_base_type (struct die_info *, struct objfile *); |
| 791 | |
| 792 | static void read_file_scope (struct die_info *, struct objfile *, |
| 793 | const struct comp_unit_head *); |
| 794 | |
| 795 | static void read_func_scope (struct die_info *, struct objfile *, |
| 796 | const struct comp_unit_head *); |
| 797 | |
| 798 | static void read_lexical_block_scope (struct die_info *, struct objfile *, |
| 799 | const struct comp_unit_head *); |
| 800 | |
| 801 | static int dwarf2_get_pc_bounds (struct die_info *, |
| 802 | CORE_ADDR *, CORE_ADDR *, struct objfile *, |
| 803 | const struct comp_unit_head *); |
| 804 | |
| 805 | static void dwarf2_add_field (struct field_info *, struct die_info *, |
| 806 | struct objfile *, const struct comp_unit_head *); |
| 807 | |
| 808 | static void dwarf2_attach_fields_to_type (struct field_info *, |
| 809 | struct type *, struct objfile *); |
| 810 | |
| 811 | static void dwarf2_add_member_fn (struct field_info *, |
| 812 | struct die_info *, struct type *, |
| 813 | struct objfile *objfile, |
| 814 | const struct comp_unit_head *); |
| 815 | |
| 816 | static void dwarf2_attach_fn_fields_to_type (struct field_info *, |
| 817 | struct type *, struct objfile *); |
| 818 | |
| 819 | static void read_structure_scope (struct die_info *, struct objfile *, |
| 820 | const struct comp_unit_head *); |
| 821 | |
| 822 | static void read_common_block (struct die_info *, struct objfile *, |
| 823 | const struct comp_unit_head *); |
| 824 | |
| 825 | static void read_namespace (struct die_info *die, struct objfile *objfile, |
| 826 | const struct comp_unit_head *cu_header); |
| 827 | |
| 828 | static void read_enumeration (struct die_info *, struct objfile *, |
| 829 | const struct comp_unit_head *); |
| 830 | |
| 831 | static struct type *dwarf_base_type (int, int, struct objfile *); |
| 832 | |
| 833 | static CORE_ADDR decode_locdesc (struct dwarf_block *, struct objfile *, |
| 834 | const struct comp_unit_head *); |
| 835 | |
| 836 | static void read_array_type (struct die_info *, struct objfile *, |
| 837 | const struct comp_unit_head *); |
| 838 | |
| 839 | static void read_tag_pointer_type (struct die_info *, struct objfile *, |
| 840 | const struct comp_unit_head *); |
| 841 | |
| 842 | static void read_tag_ptr_to_member_type (struct die_info *, struct objfile *, |
| 843 | const struct comp_unit_head *); |
| 844 | |
| 845 | static void read_tag_reference_type (struct die_info *, struct objfile *, |
| 846 | const struct comp_unit_head *); |
| 847 | |
| 848 | static void read_tag_const_type (struct die_info *, struct objfile *, |
| 849 | const struct comp_unit_head *); |
| 850 | |
| 851 | static void read_tag_volatile_type (struct die_info *, struct objfile *, |
| 852 | const struct comp_unit_head *); |
| 853 | |
| 854 | static void read_tag_string_type (struct die_info *, struct objfile *); |
| 855 | |
| 856 | static void read_subroutine_type (struct die_info *, struct objfile *, |
| 857 | const struct comp_unit_head *); |
| 858 | |
| 859 | static struct die_info *read_comp_unit (char *, bfd *, |
| 860 | const struct comp_unit_head *); |
| 861 | |
| 862 | static void free_die_list (struct die_info *); |
| 863 | |
| 864 | static struct cleanup *make_cleanup_free_die_list (struct die_info *); |
| 865 | |
| 866 | static void process_die (struct die_info *, struct objfile *, |
| 867 | const struct comp_unit_head *); |
| 868 | |
| 869 | static char *dwarf2_linkage_name (struct die_info *); |
| 870 | |
| 871 | static char *dwarf2_name (struct die_info *die); |
| 872 | |
| 873 | static struct die_info *dwarf2_extension (struct die_info *die); |
| 874 | |
| 875 | static char *dwarf_tag_name (unsigned int); |
| 876 | |
| 877 | static char *dwarf_attr_name (unsigned int); |
| 878 | |
| 879 | static char *dwarf_form_name (unsigned int); |
| 880 | |
| 881 | static char *dwarf_stack_op_name (unsigned int); |
| 882 | |
| 883 | static char *dwarf_bool_name (unsigned int); |
| 884 | |
| 885 | static char *dwarf_type_encoding_name (unsigned int); |
| 886 | |
| 887 | #if 0 |
| 888 | static char *dwarf_cfi_name (unsigned int); |
| 889 | |
| 890 | struct die_info *copy_die (struct die_info *); |
| 891 | #endif |
| 892 | |
| 893 | static struct die_info *sibling_die (struct die_info *); |
| 894 | |
| 895 | static void dump_die (struct die_info *); |
| 896 | |
| 897 | static void dump_die_list (struct die_info *); |
| 898 | |
| 899 | static void store_in_ref_table (unsigned int, struct die_info *); |
| 900 | |
| 901 | static void dwarf2_empty_hash_tables (void); |
| 902 | |
| 903 | static unsigned int dwarf2_get_ref_die_offset (struct attribute *); |
| 904 | |
| 905 | static struct die_info *follow_die_ref (unsigned int); |
| 906 | |
| 907 | static struct type *dwarf2_fundamental_type (struct objfile *, int); |
| 908 | |
| 909 | /* memory allocation interface */ |
| 910 | |
| 911 | static void dwarf2_free_tmp_obstack (void *); |
| 912 | |
| 913 | static struct dwarf_block *dwarf_alloc_block (void); |
| 914 | |
| 915 | static struct abbrev_info *dwarf_alloc_abbrev (void); |
| 916 | |
| 917 | static struct die_info *dwarf_alloc_die (void); |
| 918 | |
| 919 | static void initialize_cu_func_list (void); |
| 920 | |
| 921 | static void add_to_cu_func_list (const char *, CORE_ADDR, CORE_ADDR); |
| 922 | |
| 923 | static void dwarf_decode_macros (struct line_header *, unsigned int, |
| 924 | char *, bfd *, const struct comp_unit_head *, |
| 925 | struct objfile *); |
| 926 | |
| 927 | static int attr_form_is_block (struct attribute *); |
| 928 | |
| 929 | static void |
| 930 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, |
| 931 | const struct comp_unit_head *, |
| 932 | struct objfile *objfile); |
| 933 | |
| 934 | /* Try to locate the sections we need for DWARF 2 debugging |
| 935 | information and return true if we have enough to do something. */ |
| 936 | |
| 937 | int |
| 938 | dwarf2_has_info (bfd *abfd) |
| 939 | { |
| 940 | dwarf_info_offset = 0; |
| 941 | dwarf_abbrev_offset = 0; |
| 942 | dwarf_line_offset = 0; |
| 943 | dwarf_str_offset = 0; |
| 944 | dwarf_macinfo_offset = 0; |
| 945 | dwarf_frame_offset = 0; |
| 946 | dwarf_eh_frame_offset = 0; |
| 947 | dwarf_ranges_offset = 0; |
| 948 | dwarf_loc_offset = 0; |
| 949 | |
| 950 | bfd_map_over_sections (abfd, dwarf2_locate_sections, NULL); |
| 951 | if (dwarf_info_offset && dwarf_abbrev_offset) |
| 952 | { |
| 953 | return 1; |
| 954 | } |
| 955 | else |
| 956 | { |
| 957 | return 0; |
| 958 | } |
| 959 | } |
| 960 | |
| 961 | /* This function is mapped across the sections and remembers the |
| 962 | offset and size of each of the debugging sections we are interested |
| 963 | in. */ |
| 964 | |
| 965 | static void |
| 966 | dwarf2_locate_sections (bfd *ignore_abfd, asection *sectp, void *ignore_ptr) |
| 967 | { |
| 968 | if (STREQ (sectp->name, INFO_SECTION)) |
| 969 | { |
| 970 | dwarf_info_offset = sectp->filepos; |
| 971 | dwarf_info_size = bfd_get_section_size_before_reloc (sectp); |
| 972 | dwarf_info_section = sectp; |
| 973 | } |
| 974 | else if (STREQ (sectp->name, ABBREV_SECTION)) |
| 975 | { |
| 976 | dwarf_abbrev_offset = sectp->filepos; |
| 977 | dwarf_abbrev_size = bfd_get_section_size_before_reloc (sectp); |
| 978 | dwarf_abbrev_section = sectp; |
| 979 | } |
| 980 | else if (STREQ (sectp->name, LINE_SECTION)) |
| 981 | { |
| 982 | dwarf_line_offset = sectp->filepos; |
| 983 | dwarf_line_size = bfd_get_section_size_before_reloc (sectp); |
| 984 | dwarf_line_section = sectp; |
| 985 | } |
| 986 | else if (STREQ (sectp->name, PUBNAMES_SECTION)) |
| 987 | { |
| 988 | dwarf_pubnames_offset = sectp->filepos; |
| 989 | dwarf_pubnames_size = bfd_get_section_size_before_reloc (sectp); |
| 990 | dwarf_pubnames_section = sectp; |
| 991 | } |
| 992 | else if (STREQ (sectp->name, ARANGES_SECTION)) |
| 993 | { |
| 994 | dwarf_aranges_offset = sectp->filepos; |
| 995 | dwarf_aranges_size = bfd_get_section_size_before_reloc (sectp); |
| 996 | dwarf_aranges_section = sectp; |
| 997 | } |
| 998 | else if (STREQ (sectp->name, LOC_SECTION)) |
| 999 | { |
| 1000 | dwarf_loc_offset = sectp->filepos; |
| 1001 | dwarf_loc_size = bfd_get_section_size_before_reloc (sectp); |
| 1002 | dwarf_loc_section = sectp; |
| 1003 | } |
| 1004 | else if (STREQ (sectp->name, MACINFO_SECTION)) |
| 1005 | { |
| 1006 | dwarf_macinfo_offset = sectp->filepos; |
| 1007 | dwarf_macinfo_size = bfd_get_section_size_before_reloc (sectp); |
| 1008 | dwarf_macinfo_section = sectp; |
| 1009 | } |
| 1010 | else if (STREQ (sectp->name, STR_SECTION)) |
| 1011 | { |
| 1012 | dwarf_str_offset = sectp->filepos; |
| 1013 | dwarf_str_size = bfd_get_section_size_before_reloc (sectp); |
| 1014 | dwarf_str_section = sectp; |
| 1015 | } |
| 1016 | else if (STREQ (sectp->name, FRAME_SECTION)) |
| 1017 | { |
| 1018 | dwarf_frame_offset = sectp->filepos; |
| 1019 | dwarf_frame_size = bfd_get_section_size_before_reloc (sectp); |
| 1020 | dwarf_frame_section = sectp; |
| 1021 | } |
| 1022 | else if (STREQ (sectp->name, EH_FRAME_SECTION)) |
| 1023 | { |
| 1024 | dwarf_eh_frame_offset = sectp->filepos; |
| 1025 | dwarf_eh_frame_size = bfd_get_section_size_before_reloc (sectp); |
| 1026 | dwarf_eh_frame_section = sectp; |
| 1027 | } |
| 1028 | else if (STREQ (sectp->name, RANGES_SECTION)) |
| 1029 | { |
| 1030 | dwarf_ranges_offset = sectp->filepos; |
| 1031 | dwarf_ranges_size = bfd_get_section_size_before_reloc (sectp); |
| 1032 | dwarf_ranges_section = sectp; |
| 1033 | } |
| 1034 | } |
| 1035 | |
| 1036 | /* Build a partial symbol table. */ |
| 1037 | |
| 1038 | void |
| 1039 | dwarf2_build_psymtabs (struct objfile *objfile, int mainline) |
| 1040 | { |
| 1041 | |
| 1042 | /* We definitely need the .debug_info and .debug_abbrev sections */ |
| 1043 | |
| 1044 | dwarf_info_buffer = dwarf2_read_section (objfile, |
| 1045 | dwarf_info_offset, |
| 1046 | dwarf_info_size, |
| 1047 | dwarf_info_section); |
| 1048 | dwarf_abbrev_buffer = dwarf2_read_section (objfile, |
| 1049 | dwarf_abbrev_offset, |
| 1050 | dwarf_abbrev_size, |
| 1051 | dwarf_abbrev_section); |
| 1052 | |
| 1053 | if (dwarf_line_offset) |
| 1054 | dwarf_line_buffer = dwarf2_read_section (objfile, |
| 1055 | dwarf_line_offset, |
| 1056 | dwarf_line_size, |
| 1057 | dwarf_line_section); |
| 1058 | else |
| 1059 | dwarf_line_buffer = NULL; |
| 1060 | |
| 1061 | if (dwarf_str_offset) |
| 1062 | dwarf_str_buffer = dwarf2_read_section (objfile, |
| 1063 | dwarf_str_offset, |
| 1064 | dwarf_str_size, |
| 1065 | dwarf_str_section); |
| 1066 | else |
| 1067 | dwarf_str_buffer = NULL; |
| 1068 | |
| 1069 | if (dwarf_macinfo_offset) |
| 1070 | dwarf_macinfo_buffer = dwarf2_read_section (objfile, |
| 1071 | dwarf_macinfo_offset, |
| 1072 | dwarf_macinfo_size, |
| 1073 | dwarf_macinfo_section); |
| 1074 | else |
| 1075 | dwarf_macinfo_buffer = NULL; |
| 1076 | |
| 1077 | if (dwarf_ranges_offset) |
| 1078 | dwarf_ranges_buffer = dwarf2_read_section (objfile, |
| 1079 | dwarf_ranges_offset, |
| 1080 | dwarf_ranges_size, |
| 1081 | dwarf_ranges_section); |
| 1082 | else |
| 1083 | dwarf_ranges_buffer = NULL; |
| 1084 | |
| 1085 | if (dwarf_loc_offset) |
| 1086 | dwarf_loc_buffer = dwarf2_read_section (objfile, |
| 1087 | dwarf_loc_offset, |
| 1088 | dwarf_loc_size, |
| 1089 | dwarf_loc_section); |
| 1090 | else |
| 1091 | dwarf_loc_buffer = NULL; |
| 1092 | |
| 1093 | if (mainline |
| 1094 | || (objfile->global_psymbols.size == 0 |
| 1095 | && objfile->static_psymbols.size == 0)) |
| 1096 | { |
| 1097 | init_psymbol_list (objfile, 1024); |
| 1098 | } |
| 1099 | |
| 1100 | #if 0 |
| 1101 | if (dwarf_aranges_offset && dwarf_pubnames_offset) |
| 1102 | { |
| 1103 | /* Things are significantly easier if we have .debug_aranges and |
| 1104 | .debug_pubnames sections */ |
| 1105 | |
| 1106 | dwarf2_build_psymtabs_easy (objfile, mainline); |
| 1107 | } |
| 1108 | else |
| 1109 | #endif |
| 1110 | /* only test this case for now */ |
| 1111 | { |
| 1112 | /* In this case we have to work a bit harder */ |
| 1113 | dwarf2_build_psymtabs_hard (objfile, mainline); |
| 1114 | } |
| 1115 | } |
| 1116 | |
| 1117 | #if 0 |
| 1118 | /* Build the partial symbol table from the information in the |
| 1119 | .debug_pubnames and .debug_aranges sections. */ |
| 1120 | |
| 1121 | static void |
| 1122 | dwarf2_build_psymtabs_easy (struct objfile *objfile, int mainline) |
| 1123 | { |
| 1124 | bfd *abfd = objfile->obfd; |
| 1125 | char *aranges_buffer, *pubnames_buffer; |
| 1126 | char *aranges_ptr, *pubnames_ptr; |
| 1127 | unsigned int entry_length, version, info_offset, info_size; |
| 1128 | |
| 1129 | pubnames_buffer = dwarf2_read_section (objfile, |
| 1130 | dwarf_pubnames_offset, |
| 1131 | dwarf_pubnames_size, |
| 1132 | dwarf_pubnames_section); |
| 1133 | pubnames_ptr = pubnames_buffer; |
| 1134 | while ((pubnames_ptr - pubnames_buffer) < dwarf_pubnames_size) |
| 1135 | { |
| 1136 | struct comp_unit_head cu_header; |
| 1137 | int bytes_read; |
| 1138 | |
| 1139 | entry_length = read_initial_length (abfd, pubnames_ptr, &cu_header, |
| 1140 | &bytes_read); |
| 1141 | pubnames_ptr += bytes_read; |
| 1142 | version = read_1_byte (abfd, pubnames_ptr); |
| 1143 | pubnames_ptr += 1; |
| 1144 | info_offset = read_4_bytes (abfd, pubnames_ptr); |
| 1145 | pubnames_ptr += 4; |
| 1146 | info_size = read_4_bytes (abfd, pubnames_ptr); |
| 1147 | pubnames_ptr += 4; |
| 1148 | } |
| 1149 | |
| 1150 | aranges_buffer = dwarf2_read_section (objfile, |
| 1151 | dwarf_aranges_offset, |
| 1152 | dwarf_aranges_size, |
| 1153 | dwarf_aranges_section); |
| 1154 | |
| 1155 | } |
| 1156 | #endif |
| 1157 | |
| 1158 | /* Read in the comp unit header information from the debug_info at |
| 1159 | info_ptr. */ |
| 1160 | |
| 1161 | static char * |
| 1162 | read_comp_unit_head (struct comp_unit_head *cu_header, |
| 1163 | char *info_ptr, bfd *abfd) |
| 1164 | { |
| 1165 | int signed_addr; |
| 1166 | int bytes_read; |
| 1167 | cu_header->length = read_initial_length (abfd, info_ptr, cu_header, |
| 1168 | &bytes_read); |
| 1169 | info_ptr += bytes_read; |
| 1170 | cu_header->version = read_2_bytes (abfd, info_ptr); |
| 1171 | info_ptr += 2; |
| 1172 | cu_header->abbrev_offset = read_offset (abfd, info_ptr, cu_header, |
| 1173 | &bytes_read); |
| 1174 | info_ptr += bytes_read; |
| 1175 | cu_header->addr_size = read_1_byte (abfd, info_ptr); |
| 1176 | info_ptr += 1; |
| 1177 | signed_addr = bfd_get_sign_extend_vma (abfd); |
| 1178 | if (signed_addr < 0) |
| 1179 | internal_error (__FILE__, __LINE__, |
| 1180 | "read_comp_unit_head: dwarf from non elf file"); |
| 1181 | cu_header->signed_addr_p = signed_addr; |
| 1182 | return info_ptr; |
| 1183 | } |
| 1184 | |
| 1185 | /* Build the partial symbol table by doing a quick pass through the |
| 1186 | .debug_info and .debug_abbrev sections. */ |
| 1187 | |
| 1188 | static void |
| 1189 | dwarf2_build_psymtabs_hard (struct objfile *objfile, int mainline) |
| 1190 | { |
| 1191 | /* Instead of reading this into a big buffer, we should probably use |
| 1192 | mmap() on architectures that support it. (FIXME) */ |
| 1193 | bfd *abfd = objfile->obfd; |
| 1194 | char *info_ptr, *abbrev_ptr; |
| 1195 | char *beg_of_comp_unit; |
| 1196 | struct partial_die_info comp_unit_die; |
| 1197 | struct partial_symtab *pst; |
| 1198 | struct cleanup *back_to; |
| 1199 | CORE_ADDR lowpc, highpc; |
| 1200 | |
| 1201 | info_ptr = dwarf_info_buffer; |
| 1202 | abbrev_ptr = dwarf_abbrev_buffer; |
| 1203 | |
| 1204 | /* We use dwarf2_tmp_obstack for objects that don't need to survive |
| 1205 | the partial symbol scan, like attribute values. |
| 1206 | |
| 1207 | We could reduce our peak memory consumption during partial symbol |
| 1208 | table construction by freeing stuff from this obstack more often |
| 1209 | --- say, after processing each compilation unit, or each die --- |
| 1210 | but it turns out that this saves almost nothing. For an |
| 1211 | executable with 11Mb of Dwarf 2 data, I found about 64k allocated |
| 1212 | on dwarf2_tmp_obstack. Some investigation showed: |
| 1213 | |
| 1214 | 1) 69% of the attributes used forms DW_FORM_addr, DW_FORM_data*, |
| 1215 | DW_FORM_flag, DW_FORM_[su]data, and DW_FORM_ref*. These are |
| 1216 | all fixed-length values not requiring dynamic allocation. |
| 1217 | |
| 1218 | 2) 30% of the attributes used the form DW_FORM_string. For |
| 1219 | DW_FORM_string, read_attribute simply hands back a pointer to |
| 1220 | the null-terminated string in dwarf_info_buffer, so no dynamic |
| 1221 | allocation is needed there either. |
| 1222 | |
| 1223 | 3) The remaining 1% of the attributes all used DW_FORM_block1. |
| 1224 | 75% of those were DW_AT_frame_base location lists for |
| 1225 | functions; the rest were DW_AT_location attributes, probably |
| 1226 | for the global variables. |
| 1227 | |
| 1228 | Anyway, what this all means is that the memory the dwarf2 |
| 1229 | reader uses as temporary space reading partial symbols is about |
| 1230 | 0.5% as much as we use for dwarf_*_buffer. That's noise. */ |
| 1231 | |
| 1232 | obstack_init (&dwarf2_tmp_obstack); |
| 1233 | back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); |
| 1234 | |
| 1235 | /* Since the objects we're extracting from dwarf_info_buffer vary in |
| 1236 | length, only the individual functions to extract them (like |
| 1237 | read_comp_unit_head and read_partial_die) can really know whether |
| 1238 | the buffer is large enough to hold another complete object. |
| 1239 | |
| 1240 | At the moment, they don't actually check that. If |
| 1241 | dwarf_info_buffer holds just one extra byte after the last |
| 1242 | compilation unit's dies, then read_comp_unit_head will happily |
| 1243 | read off the end of the buffer. read_partial_die is similarly |
| 1244 | casual. Those functions should be fixed. |
| 1245 | |
| 1246 | For this loop condition, simply checking whether there's any data |
| 1247 | left at all should be sufficient. */ |
| 1248 | while (info_ptr < dwarf_info_buffer + dwarf_info_size) |
| 1249 | { |
| 1250 | struct comp_unit_head cu_header; |
| 1251 | beg_of_comp_unit = info_ptr; |
| 1252 | info_ptr = read_comp_unit_head (&cu_header, info_ptr, abfd); |
| 1253 | |
| 1254 | if (cu_header.version != 2) |
| 1255 | { |
| 1256 | error ("Dwarf Error: wrong version in compilation unit header (is %d, should be %d) [in module %s]", cu_header.version, 2, bfd_get_filename (abfd)); |
| 1257 | return; |
| 1258 | } |
| 1259 | if (cu_header.abbrev_offset >= dwarf_abbrev_size) |
| 1260 | { |
| 1261 | error ("Dwarf Error: bad offset (0x%lx) in compilation unit header (offset 0x%lx + 6) [in module %s]", |
| 1262 | (long) cu_header.abbrev_offset, |
| 1263 | (long) (beg_of_comp_unit - dwarf_info_buffer), |
| 1264 | bfd_get_filename (abfd)); |
| 1265 | return; |
| 1266 | } |
| 1267 | if (beg_of_comp_unit + cu_header.length + cu_header.initial_length_size |
| 1268 | > dwarf_info_buffer + dwarf_info_size) |
| 1269 | { |
| 1270 | error ("Dwarf Error: bad length (0x%lx) in compilation unit header (offset 0x%lx + 0) [in module %s]", |
| 1271 | (long) cu_header.length, |
| 1272 | (long) (beg_of_comp_unit - dwarf_info_buffer), |
| 1273 | bfd_get_filename (abfd)); |
| 1274 | return; |
| 1275 | } |
| 1276 | /* Complete the cu_header */ |
| 1277 | cu_header.offset = beg_of_comp_unit - dwarf_info_buffer; |
| 1278 | cu_header.first_die_ptr = info_ptr; |
| 1279 | cu_header.cu_head_ptr = beg_of_comp_unit; |
| 1280 | |
| 1281 | /* Read the abbrevs for this compilation unit into a table */ |
| 1282 | dwarf2_read_abbrevs (abfd, &cu_header); |
| 1283 | make_cleanup (dwarf2_empty_abbrev_table, cu_header.dwarf2_abbrevs); |
| 1284 | |
| 1285 | /* Read the compilation unit die */ |
| 1286 | info_ptr = read_partial_die (&comp_unit_die, abfd, info_ptr, |
| 1287 | &cu_header); |
| 1288 | |
| 1289 | /* Set the language we're debugging */ |
| 1290 | set_cu_language (comp_unit_die.language); |
| 1291 | |
| 1292 | /* Allocate a new partial symbol table structure */ |
| 1293 | pst = start_psymtab_common (objfile, objfile->section_offsets, |
| 1294 | comp_unit_die.name ? comp_unit_die.name : "", |
| 1295 | comp_unit_die.lowpc, |
| 1296 | objfile->global_psymbols.next, |
| 1297 | objfile->static_psymbols.next); |
| 1298 | |
| 1299 | pst->read_symtab_private = (char *) |
| 1300 | obstack_alloc (&objfile->psymbol_obstack, sizeof (struct dwarf2_pinfo)); |
| 1301 | cu_header_offset = beg_of_comp_unit - dwarf_info_buffer; |
| 1302 | DWARF_INFO_BUFFER (pst) = dwarf_info_buffer; |
| 1303 | DWARF_INFO_OFFSET (pst) = beg_of_comp_unit - dwarf_info_buffer; |
| 1304 | DWARF_ABBREV_BUFFER (pst) = dwarf_abbrev_buffer; |
| 1305 | DWARF_ABBREV_SIZE (pst) = dwarf_abbrev_size; |
| 1306 | DWARF_LINE_BUFFER (pst) = dwarf_line_buffer; |
| 1307 | DWARF_LINE_SIZE (pst) = dwarf_line_size; |
| 1308 | DWARF_STR_BUFFER (pst) = dwarf_str_buffer; |
| 1309 | DWARF_STR_SIZE (pst) = dwarf_str_size; |
| 1310 | DWARF_MACINFO_BUFFER (pst) = dwarf_macinfo_buffer; |
| 1311 | DWARF_MACINFO_SIZE (pst) = dwarf_macinfo_size; |
| 1312 | DWARF_RANGES_BUFFER (pst) = dwarf_ranges_buffer; |
| 1313 | DWARF_RANGES_SIZE (pst) = dwarf_ranges_size; |
| 1314 | DWARF_LOC_BUFFER (pst) = dwarf_loc_buffer; |
| 1315 | DWARF_LOC_SIZE (pst) = dwarf_loc_size; |
| 1316 | baseaddr = ANOFFSET (objfile->section_offsets, SECT_OFF_TEXT (objfile)); |
| 1317 | |
| 1318 | /* Store the function that reads in the rest of the symbol table */ |
| 1319 | pst->read_symtab = dwarf2_psymtab_to_symtab; |
| 1320 | |
| 1321 | /* Check if comp unit has_children. |
| 1322 | If so, read the rest of the partial symbols from this comp unit. |
| 1323 | If not, there's no more debug_info for this comp unit. */ |
| 1324 | if (comp_unit_die.has_children) |
| 1325 | { |
| 1326 | info_ptr = scan_partial_symbols (info_ptr, objfile, &lowpc, &highpc, |
| 1327 | &cu_header); |
| 1328 | |
| 1329 | /* If the compilation unit didn't have an explicit address range, |
| 1330 | then use the information extracted from its child dies. */ |
| 1331 | if (! comp_unit_die.has_pc_info) |
| 1332 | { |
| 1333 | comp_unit_die.lowpc = lowpc; |
| 1334 | comp_unit_die.highpc = highpc; |
| 1335 | } |
| 1336 | } |
| 1337 | pst->textlow = comp_unit_die.lowpc + baseaddr; |
| 1338 | pst->texthigh = comp_unit_die.highpc + baseaddr; |
| 1339 | |
| 1340 | pst->n_global_syms = objfile->global_psymbols.next - |
| 1341 | (objfile->global_psymbols.list + pst->globals_offset); |
| 1342 | pst->n_static_syms = objfile->static_psymbols.next - |
| 1343 | (objfile->static_psymbols.list + pst->statics_offset); |
| 1344 | sort_pst_symbols (pst); |
| 1345 | |
| 1346 | /* If there is already a psymtab or symtab for a file of this |
| 1347 | name, remove it. (If there is a symtab, more drastic things |
| 1348 | also happen.) This happens in VxWorks. */ |
| 1349 | free_named_symtabs (pst->filename); |
| 1350 | |
| 1351 | info_ptr = beg_of_comp_unit + cu_header.length |
| 1352 | + cu_header.initial_length_size; |
| 1353 | } |
| 1354 | do_cleanups (back_to); |
| 1355 | } |
| 1356 | |
| 1357 | /* Read in all interesting dies to the end of the compilation unit. */ |
| 1358 | |
| 1359 | static char * |
| 1360 | scan_partial_symbols (char *info_ptr, struct objfile *objfile, |
| 1361 | CORE_ADDR *lowpc, CORE_ADDR *highpc, |
| 1362 | const struct comp_unit_head *cu_header) |
| 1363 | { |
| 1364 | bfd *abfd = objfile->obfd; |
| 1365 | struct partial_die_info pdi; |
| 1366 | |
| 1367 | /* This function is called after we've read in the comp_unit_die in |
| 1368 | order to read its children. We start the nesting level at 1 since |
| 1369 | we have pushed 1 level down in order to read the comp unit's children. |
| 1370 | The comp unit itself is at level 0, so we stop reading when we pop |
| 1371 | back to that level. */ |
| 1372 | |
| 1373 | int nesting_level = 1; |
| 1374 | |
| 1375 | /* We only want to read in symbols corresponding to variables or |
| 1376 | other similar objects that are global or static. Normally, these |
| 1377 | are all children of the DW_TAG_compile_unit die, so are all at |
| 1378 | level 1. But C++ namespaces give ries to DW_TAG_namespace dies |
| 1379 | whose children are global objects. So we keep track of what |
| 1380 | level we currently think of as referring to file scope; this |
| 1381 | should always equal 1 plus the number of namespaces that we are |
| 1382 | currently nested within. */ |
| 1383 | |
| 1384 | int file_scope_level = 1; |
| 1385 | |
| 1386 | *lowpc = ((CORE_ADDR) -1); |
| 1387 | *highpc = ((CORE_ADDR) 0); |
| 1388 | |
| 1389 | while (nesting_level) |
| 1390 | { |
| 1391 | info_ptr = read_partial_die (&pdi, abfd, info_ptr, cu_header); |
| 1392 | |
| 1393 | /* Anonymous namespaces have no name but are interesting. */ |
| 1394 | |
| 1395 | if (pdi.name != NULL || pdi.tag == DW_TAG_namespace) |
| 1396 | { |
| 1397 | switch (pdi.tag) |
| 1398 | { |
| 1399 | case DW_TAG_subprogram: |
| 1400 | if (pdi.has_pc_info) |
| 1401 | { |
| 1402 | if (pdi.lowpc < *lowpc) |
| 1403 | { |
| 1404 | *lowpc = pdi.lowpc; |
| 1405 | } |
| 1406 | if (pdi.highpc > *highpc) |
| 1407 | { |
| 1408 | *highpc = pdi.highpc; |
| 1409 | } |
| 1410 | if ((pdi.is_external || nesting_level == file_scope_level) |
| 1411 | && !pdi.is_declaration) |
| 1412 | { |
| 1413 | add_partial_symbol (&pdi, objfile, cu_header); |
| 1414 | } |
| 1415 | } |
| 1416 | break; |
| 1417 | case DW_TAG_variable: |
| 1418 | case DW_TAG_typedef: |
| 1419 | case DW_TAG_class_type: |
| 1420 | case DW_TAG_structure_type: |
| 1421 | case DW_TAG_union_type: |
| 1422 | case DW_TAG_enumeration_type: |
| 1423 | if ((pdi.is_external || nesting_level == file_scope_level) |
| 1424 | && !pdi.is_declaration) |
| 1425 | { |
| 1426 | add_partial_symbol (&pdi, objfile, cu_header); |
| 1427 | } |
| 1428 | break; |
| 1429 | case DW_TAG_enumerator: |
| 1430 | /* File scope enumerators are added to the partial |
| 1431 | symbol table. They're children of the enumeration |
| 1432 | type die, so they occur at a level one higher than we |
| 1433 | normally look for. */ |
| 1434 | if (nesting_level == file_scope_level + 1) |
| 1435 | add_partial_symbol (&pdi, objfile, cu_header); |
| 1436 | break; |
| 1437 | case DW_TAG_base_type: |
| 1438 | /* File scope base type definitions are added to the partial |
| 1439 | symbol table. */ |
| 1440 | if (nesting_level == file_scope_level) |
| 1441 | add_partial_symbol (&pdi, objfile, cu_header); |
| 1442 | break; |
| 1443 | case DW_TAG_namespace: |
| 1444 | /* FIXME: carlton/2002-10-16: we're not yet doing |
| 1445 | anything useful with this, but for now make sure that |
| 1446 | these tags at least don't cause us to miss any |
| 1447 | important symbols. */ |
| 1448 | if (pdi.has_children) |
| 1449 | file_scope_level++; |
| 1450 | default: |
| 1451 | break; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | /* If the die has a sibling, skip to the sibling. Do not skip |
| 1456 | enumeration types, we want to record their enumerators. Do |
| 1457 | not skip namespaces, we want to record symbols inside |
| 1458 | them. */ |
| 1459 | if (pdi.sibling |
| 1460 | && pdi.tag != DW_TAG_enumeration_type |
| 1461 | && pdi.tag != DW_TAG_namespace) |
| 1462 | { |
| 1463 | info_ptr = pdi.sibling; |
| 1464 | } |
| 1465 | else if (pdi.has_children) |
| 1466 | { |
| 1467 | /* Die has children, but either the optional DW_AT_sibling |
| 1468 | attribute is missing or we want to look at them. */ |
| 1469 | nesting_level++; |
| 1470 | } |
| 1471 | |
| 1472 | if (pdi.tag == 0) |
| 1473 | { |
| 1474 | nesting_level--; |
| 1475 | /* If this is the end of a DW_TAG_namespace entry, then |
| 1476 | decrease the file_scope_level, too. */ |
| 1477 | if (nesting_level < file_scope_level) |
| 1478 | { |
| 1479 | file_scope_level--; |
| 1480 | gdb_assert (nesting_level == file_scope_level); |
| 1481 | } |
| 1482 | } |
| 1483 | } |
| 1484 | |
| 1485 | /* If we didn't find a lowpc, set it to highpc to avoid complaints |
| 1486 | from `maint check'. */ |
| 1487 | if (*lowpc == ((CORE_ADDR) -1)) |
| 1488 | *lowpc = *highpc; |
| 1489 | return info_ptr; |
| 1490 | } |
| 1491 | |
| 1492 | static void |
| 1493 | add_partial_symbol (struct partial_die_info *pdi, struct objfile *objfile, |
| 1494 | const struct comp_unit_head *cu_header) |
| 1495 | { |
| 1496 | CORE_ADDR addr = 0; |
| 1497 | |
| 1498 | switch (pdi->tag) |
| 1499 | { |
| 1500 | case DW_TAG_subprogram: |
| 1501 | if (pdi->is_external) |
| 1502 | { |
| 1503 | /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr, |
| 1504 | mst_text, objfile); */ |
| 1505 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1506 | VAR_DOMAIN, LOC_BLOCK, |
| 1507 | &objfile->global_psymbols, |
| 1508 | 0, pdi->lowpc + baseaddr, cu_language, objfile); |
| 1509 | } |
| 1510 | else |
| 1511 | { |
| 1512 | /*prim_record_minimal_symbol (pdi->name, pdi->lowpc + baseaddr, |
| 1513 | mst_file_text, objfile); */ |
| 1514 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1515 | VAR_DOMAIN, LOC_BLOCK, |
| 1516 | &objfile->static_psymbols, |
| 1517 | 0, pdi->lowpc + baseaddr, cu_language, objfile); |
| 1518 | } |
| 1519 | break; |
| 1520 | case DW_TAG_variable: |
| 1521 | if (pdi->is_external) |
| 1522 | { |
| 1523 | /* Global Variable. |
| 1524 | Don't enter into the minimal symbol tables as there is |
| 1525 | a minimal symbol table entry from the ELF symbols already. |
| 1526 | Enter into partial symbol table if it has a location |
| 1527 | descriptor or a type. |
| 1528 | If the location descriptor is missing, new_symbol will create |
| 1529 | a LOC_UNRESOLVED symbol, the address of the variable will then |
| 1530 | be determined from the minimal symbol table whenever the variable |
| 1531 | is referenced. |
| 1532 | The address for the partial symbol table entry is not |
| 1533 | used by GDB, but it comes in handy for debugging partial symbol |
| 1534 | table building. */ |
| 1535 | |
| 1536 | if (pdi->locdesc) |
| 1537 | addr = decode_locdesc (pdi->locdesc, objfile, cu_header); |
| 1538 | if (pdi->locdesc || pdi->has_type) |
| 1539 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1540 | VAR_DOMAIN, LOC_STATIC, |
| 1541 | &objfile->global_psymbols, |
| 1542 | 0, addr + baseaddr, cu_language, objfile); |
| 1543 | } |
| 1544 | else |
| 1545 | { |
| 1546 | /* Static Variable. Skip symbols without location descriptors. */ |
| 1547 | if (pdi->locdesc == NULL) |
| 1548 | return; |
| 1549 | addr = decode_locdesc (pdi->locdesc, objfile, cu_header); |
| 1550 | /*prim_record_minimal_symbol (pdi->name, addr + baseaddr, |
| 1551 | mst_file_data, objfile); */ |
| 1552 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1553 | VAR_DOMAIN, LOC_STATIC, |
| 1554 | &objfile->static_psymbols, |
| 1555 | 0, addr + baseaddr, cu_language, objfile); |
| 1556 | } |
| 1557 | break; |
| 1558 | case DW_TAG_typedef: |
| 1559 | case DW_TAG_base_type: |
| 1560 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1561 | VAR_DOMAIN, LOC_TYPEDEF, |
| 1562 | &objfile->static_psymbols, |
| 1563 | 0, (CORE_ADDR) 0, cu_language, objfile); |
| 1564 | break; |
| 1565 | case DW_TAG_class_type: |
| 1566 | case DW_TAG_structure_type: |
| 1567 | case DW_TAG_union_type: |
| 1568 | case DW_TAG_enumeration_type: |
| 1569 | /* Skip aggregate types without children, these are external |
| 1570 | references. */ |
| 1571 | if (pdi->has_children == 0) |
| 1572 | return; |
| 1573 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1574 | STRUCT_DOMAIN, LOC_TYPEDEF, |
| 1575 | &objfile->static_psymbols, |
| 1576 | 0, (CORE_ADDR) 0, cu_language, objfile); |
| 1577 | |
| 1578 | if (cu_language == language_cplus) |
| 1579 | { |
| 1580 | /* For C++, these implicitly act as typedefs as well. */ |
| 1581 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1582 | VAR_DOMAIN, LOC_TYPEDEF, |
| 1583 | &objfile->static_psymbols, |
| 1584 | 0, (CORE_ADDR) 0, cu_language, objfile); |
| 1585 | } |
| 1586 | break; |
| 1587 | case DW_TAG_enumerator: |
| 1588 | add_psymbol_to_list (pdi->name, strlen (pdi->name), |
| 1589 | VAR_DOMAIN, LOC_CONST, |
| 1590 | &objfile->static_psymbols, |
| 1591 | 0, (CORE_ADDR) 0, cu_language, objfile); |
| 1592 | break; |
| 1593 | default: |
| 1594 | break; |
| 1595 | } |
| 1596 | } |
| 1597 | |
| 1598 | /* Expand this partial symbol table into a full symbol table. */ |
| 1599 | |
| 1600 | static void |
| 1601 | dwarf2_psymtab_to_symtab (struct partial_symtab *pst) |
| 1602 | { |
| 1603 | /* FIXME: This is barely more than a stub. */ |
| 1604 | if (pst != NULL) |
| 1605 | { |
| 1606 | if (pst->readin) |
| 1607 | { |
| 1608 | warning ("bug: psymtab for %s is already read in.", pst->filename); |
| 1609 | } |
| 1610 | else |
| 1611 | { |
| 1612 | if (info_verbose) |
| 1613 | { |
| 1614 | printf_filtered ("Reading in symbols for %s...", pst->filename); |
| 1615 | gdb_flush (gdb_stdout); |
| 1616 | } |
| 1617 | |
| 1618 | psymtab_to_symtab_1 (pst); |
| 1619 | |
| 1620 | /* Finish up the debug error message. */ |
| 1621 | if (info_verbose) |
| 1622 | printf_filtered ("done.\n"); |
| 1623 | } |
| 1624 | } |
| 1625 | } |
| 1626 | |
| 1627 | static void |
| 1628 | psymtab_to_symtab_1 (struct partial_symtab *pst) |
| 1629 | { |
| 1630 | struct objfile *objfile = pst->objfile; |
| 1631 | bfd *abfd = objfile->obfd; |
| 1632 | struct comp_unit_head cu_header; |
| 1633 | struct die_info *dies; |
| 1634 | unsigned long offset; |
| 1635 | CORE_ADDR lowpc, highpc; |
| 1636 | struct die_info *child_die; |
| 1637 | char *info_ptr; |
| 1638 | struct symtab *symtab; |
| 1639 | struct cleanup *back_to; |
| 1640 | struct attribute *attr; |
| 1641 | |
| 1642 | /* Set local variables from the partial symbol table info. */ |
| 1643 | offset = DWARF_INFO_OFFSET (pst); |
| 1644 | dwarf_info_buffer = DWARF_INFO_BUFFER (pst); |
| 1645 | dwarf_abbrev_buffer = DWARF_ABBREV_BUFFER (pst); |
| 1646 | dwarf_abbrev_size = DWARF_ABBREV_SIZE (pst); |
| 1647 | dwarf_line_buffer = DWARF_LINE_BUFFER (pst); |
| 1648 | dwarf_line_size = DWARF_LINE_SIZE (pst); |
| 1649 | dwarf_str_buffer = DWARF_STR_BUFFER (pst); |
| 1650 | dwarf_str_size = DWARF_STR_SIZE (pst); |
| 1651 | dwarf_macinfo_buffer = DWARF_MACINFO_BUFFER (pst); |
| 1652 | dwarf_macinfo_size = DWARF_MACINFO_SIZE (pst); |
| 1653 | dwarf_ranges_buffer = DWARF_RANGES_BUFFER (pst); |
| 1654 | dwarf_ranges_size = DWARF_RANGES_SIZE (pst); |
| 1655 | dwarf_loc_buffer = DWARF_LOC_BUFFER (pst); |
| 1656 | dwarf_loc_size = DWARF_LOC_SIZE (pst); |
| 1657 | baseaddr = ANOFFSET (pst->section_offsets, SECT_OFF_TEXT (objfile)); |
| 1658 | cu_header_offset = offset; |
| 1659 | info_ptr = dwarf_info_buffer + offset; |
| 1660 | |
| 1661 | obstack_init (&dwarf2_tmp_obstack); |
| 1662 | back_to = make_cleanup (dwarf2_free_tmp_obstack, NULL); |
| 1663 | |
| 1664 | buildsym_init (); |
| 1665 | make_cleanup (really_free_pendings, NULL); |
| 1666 | |
| 1667 | /* read in the comp_unit header */ |
| 1668 | info_ptr = read_comp_unit_head (&cu_header, info_ptr, abfd); |
| 1669 | |
| 1670 | /* Read the abbrevs for this compilation unit */ |
| 1671 | dwarf2_read_abbrevs (abfd, &cu_header); |
| 1672 | make_cleanup (dwarf2_empty_abbrev_table, cu_header.dwarf2_abbrevs); |
| 1673 | |
| 1674 | dies = read_comp_unit (info_ptr, abfd, &cu_header); |
| 1675 | |
| 1676 | make_cleanup_free_die_list (dies); |
| 1677 | |
| 1678 | /* Find the base address of the compilation unit for range lists and |
| 1679 | location lists. It will normally be specified by DW_AT_low_pc. |
| 1680 | In DWARF-3 draft 4, the base address could be overridden by |
| 1681 | DW_AT_entry_pc. It's been removed, but GCC still uses this for |
| 1682 | compilation units with discontinuous ranges. */ |
| 1683 | |
| 1684 | cu_header.base_known = 0; |
| 1685 | cu_header.base_address = 0; |
| 1686 | |
| 1687 | attr = dwarf_attr (dies, DW_AT_entry_pc); |
| 1688 | if (attr) |
| 1689 | { |
| 1690 | cu_header.base_address = DW_ADDR (attr); |
| 1691 | cu_header.base_known = 1; |
| 1692 | } |
| 1693 | else |
| 1694 | { |
| 1695 | attr = dwarf_attr (dies, DW_AT_low_pc); |
| 1696 | if (attr) |
| 1697 | { |
| 1698 | cu_header.base_address = DW_ADDR (attr); |
| 1699 | cu_header.base_known = 1; |
| 1700 | } |
| 1701 | } |
| 1702 | |
| 1703 | /* Do line number decoding in read_file_scope () */ |
| 1704 | process_die (dies, objfile, &cu_header); |
| 1705 | |
| 1706 | if (!dwarf2_get_pc_bounds (dies, &lowpc, &highpc, objfile, &cu_header)) |
| 1707 | { |
| 1708 | /* Some compilers don't define a DW_AT_high_pc attribute for |
| 1709 | the compilation unit. If the DW_AT_high_pc is missing, |
| 1710 | synthesize it, by scanning the DIE's below the compilation unit. */ |
| 1711 | highpc = 0; |
| 1712 | if (dies->has_children) |
| 1713 | { |
| 1714 | child_die = dies->next; |
| 1715 | while (child_die && child_die->tag) |
| 1716 | { |
| 1717 | if (child_die->tag == DW_TAG_subprogram) |
| 1718 | { |
| 1719 | CORE_ADDR low, high; |
| 1720 | |
| 1721 | if (dwarf2_get_pc_bounds (child_die, &low, &high, |
| 1722 | objfile, &cu_header)) |
| 1723 | { |
| 1724 | highpc = max (highpc, high); |
| 1725 | } |
| 1726 | } |
| 1727 | child_die = sibling_die (child_die); |
| 1728 | } |
| 1729 | } |
| 1730 | } |
| 1731 | symtab = end_symtab (highpc + baseaddr, objfile, SECT_OFF_TEXT (objfile)); |
| 1732 | |
| 1733 | /* Set symtab language to language from DW_AT_language. |
| 1734 | If the compilation is from a C file generated by language preprocessors, |
| 1735 | do not set the language if it was already deduced by start_subfile. */ |
| 1736 | if (symtab != NULL |
| 1737 | && !(cu_language == language_c && symtab->language != language_c)) |
| 1738 | { |
| 1739 | symtab->language = cu_language; |
| 1740 | } |
| 1741 | pst->symtab = symtab; |
| 1742 | pst->readin = 1; |
| 1743 | sort_symtab_syms (pst->symtab); |
| 1744 | |
| 1745 | do_cleanups (back_to); |
| 1746 | } |
| 1747 | |
| 1748 | /* Process a die and its children. */ |
| 1749 | |
| 1750 | static void |
| 1751 | process_die (struct die_info *die, struct objfile *objfile, |
| 1752 | const struct comp_unit_head *cu_header) |
| 1753 | { |
| 1754 | switch (die->tag) |
| 1755 | { |
| 1756 | case DW_TAG_padding: |
| 1757 | break; |
| 1758 | case DW_TAG_compile_unit: |
| 1759 | read_file_scope (die, objfile, cu_header); |
| 1760 | break; |
| 1761 | case DW_TAG_subprogram: |
| 1762 | read_subroutine_type (die, objfile, cu_header); |
| 1763 | read_func_scope (die, objfile, cu_header); |
| 1764 | break; |
| 1765 | case DW_TAG_inlined_subroutine: |
| 1766 | /* FIXME: These are ignored for now. |
| 1767 | They could be used to set breakpoints on all inlined instances |
| 1768 | of a function and make GDB `next' properly over inlined functions. */ |
| 1769 | break; |
| 1770 | case DW_TAG_lexical_block: |
| 1771 | case DW_TAG_try_block: |
| 1772 | case DW_TAG_catch_block: |
| 1773 | read_lexical_block_scope (die, objfile, cu_header); |
| 1774 | break; |
| 1775 | case DW_TAG_class_type: |
| 1776 | case DW_TAG_structure_type: |
| 1777 | case DW_TAG_union_type: |
| 1778 | read_structure_scope (die, objfile, cu_header); |
| 1779 | break; |
| 1780 | case DW_TAG_enumeration_type: |
| 1781 | read_enumeration (die, objfile, cu_header); |
| 1782 | break; |
| 1783 | case DW_TAG_subroutine_type: |
| 1784 | read_subroutine_type (die, objfile, cu_header); |
| 1785 | break; |
| 1786 | case DW_TAG_array_type: |
| 1787 | read_array_type (die, objfile, cu_header); |
| 1788 | break; |
| 1789 | case DW_TAG_pointer_type: |
| 1790 | read_tag_pointer_type (die, objfile, cu_header); |
| 1791 | break; |
| 1792 | case DW_TAG_ptr_to_member_type: |
| 1793 | read_tag_ptr_to_member_type (die, objfile, cu_header); |
| 1794 | break; |
| 1795 | case DW_TAG_reference_type: |
| 1796 | read_tag_reference_type (die, objfile, cu_header); |
| 1797 | break; |
| 1798 | case DW_TAG_string_type: |
| 1799 | read_tag_string_type (die, objfile); |
| 1800 | break; |
| 1801 | case DW_TAG_base_type: |
| 1802 | read_base_type (die, objfile); |
| 1803 | if (dwarf_attr (die, DW_AT_name)) |
| 1804 | { |
| 1805 | /* Add a typedef symbol for the base type definition. */ |
| 1806 | new_symbol (die, die->type, objfile, cu_header); |
| 1807 | } |
| 1808 | break; |
| 1809 | case DW_TAG_common_block: |
| 1810 | read_common_block (die, objfile, cu_header); |
| 1811 | break; |
| 1812 | case DW_TAG_common_inclusion: |
| 1813 | break; |
| 1814 | case DW_TAG_namespace: |
| 1815 | if (!processing_has_namespace_info) |
| 1816 | { |
| 1817 | processing_has_namespace_info = 1; |
| 1818 | processing_current_namespace = ""; |
| 1819 | } |
| 1820 | read_namespace (die, objfile, cu_header); |
| 1821 | break; |
| 1822 | case DW_TAG_imported_declaration: |
| 1823 | case DW_TAG_imported_module: |
| 1824 | /* FIXME: carlton/2002-10-16: Eventually, we should use the |
| 1825 | information contained in these. DW_TAG_imported_declaration |
| 1826 | dies shouldn't have children; DW_TAG_imported_module dies |
| 1827 | shouldn't in the C++ case, but conceivably could in the |
| 1828 | Fortran case, so we'll have to replace this gdb_assert if |
| 1829 | Fortran compilers start generating that info. */ |
| 1830 | if (!processing_has_namespace_info) |
| 1831 | { |
| 1832 | processing_has_namespace_info = 1; |
| 1833 | processing_current_namespace = ""; |
| 1834 | } |
| 1835 | gdb_assert (!die->has_children); |
| 1836 | break; |
| 1837 | default: |
| 1838 | new_symbol (die, NULL, objfile, cu_header); |
| 1839 | break; |
| 1840 | } |
| 1841 | } |
| 1842 | |
| 1843 | static void |
| 1844 | initialize_cu_func_list (void) |
| 1845 | { |
| 1846 | cu_first_fn = cu_last_fn = cu_cached_fn = NULL; |
| 1847 | } |
| 1848 | |
| 1849 | static void |
| 1850 | read_file_scope (struct die_info *die, struct objfile *objfile, |
| 1851 | const struct comp_unit_head *cu_header) |
| 1852 | { |
| 1853 | struct cleanup *back_to = make_cleanup (null_cleanup, 0); |
| 1854 | CORE_ADDR lowpc = ((CORE_ADDR) -1); |
| 1855 | CORE_ADDR highpc = ((CORE_ADDR) 0); |
| 1856 | struct attribute *attr; |
| 1857 | char *name = "<unknown>"; |
| 1858 | char *comp_dir = NULL; |
| 1859 | struct die_info *child_die; |
| 1860 | bfd *abfd = objfile->obfd; |
| 1861 | struct line_header *line_header = 0; |
| 1862 | |
| 1863 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile, cu_header)) |
| 1864 | { |
| 1865 | if (die->has_children) |
| 1866 | { |
| 1867 | child_die = die->next; |
| 1868 | while (child_die && child_die->tag) |
| 1869 | { |
| 1870 | if (child_die->tag == DW_TAG_subprogram) |
| 1871 | { |
| 1872 | CORE_ADDR low, high; |
| 1873 | |
| 1874 | if (dwarf2_get_pc_bounds (child_die, &low, &high, |
| 1875 | objfile, cu_header)) |
| 1876 | { |
| 1877 | lowpc = min (lowpc, low); |
| 1878 | highpc = max (highpc, high); |
| 1879 | } |
| 1880 | } |
| 1881 | child_die = sibling_die (child_die); |
| 1882 | } |
| 1883 | } |
| 1884 | } |
| 1885 | |
| 1886 | /* If we didn't find a lowpc, set it to highpc to avoid complaints |
| 1887 | from finish_block. */ |
| 1888 | if (lowpc == ((CORE_ADDR) -1)) |
| 1889 | lowpc = highpc; |
| 1890 | lowpc += baseaddr; |
| 1891 | highpc += baseaddr; |
| 1892 | |
| 1893 | attr = dwarf_attr (die, DW_AT_name); |
| 1894 | if (attr) |
| 1895 | { |
| 1896 | name = DW_STRING (attr); |
| 1897 | } |
| 1898 | attr = dwarf_attr (die, DW_AT_comp_dir); |
| 1899 | if (attr) |
| 1900 | { |
| 1901 | comp_dir = DW_STRING (attr); |
| 1902 | if (comp_dir) |
| 1903 | { |
| 1904 | /* Irix 6.2 native cc prepends <machine>.: to the compilation |
| 1905 | directory, get rid of it. */ |
| 1906 | char *cp = strchr (comp_dir, ':'); |
| 1907 | |
| 1908 | if (cp && cp != comp_dir && cp[-1] == '.' && cp[1] == '/') |
| 1909 | comp_dir = cp + 1; |
| 1910 | } |
| 1911 | } |
| 1912 | |
| 1913 | if (objfile->ei.entry_point >= lowpc && |
| 1914 | objfile->ei.entry_point < highpc) |
| 1915 | { |
| 1916 | objfile->ei.entry_file_lowpc = lowpc; |
| 1917 | objfile->ei.entry_file_highpc = highpc; |
| 1918 | } |
| 1919 | |
| 1920 | attr = dwarf_attr (die, DW_AT_language); |
| 1921 | if (attr) |
| 1922 | { |
| 1923 | set_cu_language (DW_UNSND (attr)); |
| 1924 | } |
| 1925 | |
| 1926 | /* We assume that we're processing GCC output. */ |
| 1927 | processing_gcc_compilation = 2; |
| 1928 | #if 0 |
| 1929 | /* FIXME:Do something here. */ |
| 1930 | if (dip->at_producer != NULL) |
| 1931 | { |
| 1932 | handle_producer (dip->at_producer); |
| 1933 | } |
| 1934 | #endif |
| 1935 | |
| 1936 | /* The compilation unit may be in a different language or objfile, |
| 1937 | zero out all remembered fundamental types. */ |
| 1938 | memset (ftypes, 0, FT_NUM_MEMBERS * sizeof (struct type *)); |
| 1939 | |
| 1940 | start_symtab (name, comp_dir, lowpc); |
| 1941 | record_debugformat ("DWARF 2"); |
| 1942 | |
| 1943 | initialize_cu_func_list (); |
| 1944 | |
| 1945 | /* Process all dies in compilation unit. */ |
| 1946 | if (die->has_children) |
| 1947 | { |
| 1948 | child_die = die->next; |
| 1949 | while (child_die && child_die->tag) |
| 1950 | { |
| 1951 | process_die (child_die, objfile, cu_header); |
| 1952 | child_die = sibling_die (child_die); |
| 1953 | } |
| 1954 | } |
| 1955 | |
| 1956 | /* Decode line number information if present. */ |
| 1957 | attr = dwarf_attr (die, DW_AT_stmt_list); |
| 1958 | if (attr) |
| 1959 | { |
| 1960 | unsigned int line_offset = DW_UNSND (attr); |
| 1961 | line_header = dwarf_decode_line_header (line_offset, |
| 1962 | abfd, cu_header); |
| 1963 | if (line_header) |
| 1964 | { |
| 1965 | make_cleanup ((make_cleanup_ftype *) free_line_header, |
| 1966 | (void *) line_header); |
| 1967 | dwarf_decode_lines (line_header, comp_dir, abfd, cu_header); |
| 1968 | } |
| 1969 | } |
| 1970 | |
| 1971 | /* Decode macro information, if present. Dwarf 2 macro information |
| 1972 | refers to information in the line number info statement program |
| 1973 | header, so we can only read it if we've read the header |
| 1974 | successfully. */ |
| 1975 | attr = dwarf_attr (die, DW_AT_macro_info); |
| 1976 | if (attr && line_header) |
| 1977 | { |
| 1978 | unsigned int macro_offset = DW_UNSND (attr); |
| 1979 | dwarf_decode_macros (line_header, macro_offset, |
| 1980 | comp_dir, abfd, cu_header, objfile); |
| 1981 | } |
| 1982 | do_cleanups (back_to); |
| 1983 | } |
| 1984 | |
| 1985 | static void |
| 1986 | add_to_cu_func_list (const char *name, CORE_ADDR lowpc, CORE_ADDR highpc) |
| 1987 | { |
| 1988 | struct function_range *thisfn; |
| 1989 | |
| 1990 | thisfn = (struct function_range *) |
| 1991 | obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct function_range)); |
| 1992 | thisfn->name = name; |
| 1993 | thisfn->lowpc = lowpc; |
| 1994 | thisfn->highpc = highpc; |
| 1995 | thisfn->seen_line = 0; |
| 1996 | thisfn->next = NULL; |
| 1997 | |
| 1998 | if (cu_last_fn == NULL) |
| 1999 | cu_first_fn = thisfn; |
| 2000 | else |
| 2001 | cu_last_fn->next = thisfn; |
| 2002 | |
| 2003 | cu_last_fn = thisfn; |
| 2004 | } |
| 2005 | |
| 2006 | static void |
| 2007 | read_func_scope (struct die_info *die, struct objfile *objfile, |
| 2008 | const struct comp_unit_head *cu_header) |
| 2009 | { |
| 2010 | register struct context_stack *new; |
| 2011 | CORE_ADDR lowpc; |
| 2012 | CORE_ADDR highpc; |
| 2013 | struct die_info *child_die; |
| 2014 | struct attribute *attr; |
| 2015 | char *name; |
| 2016 | |
| 2017 | name = dwarf2_linkage_name (die); |
| 2018 | |
| 2019 | /* Ignore functions with missing or empty names and functions with |
| 2020 | missing or invalid low and high pc attributes. */ |
| 2021 | if (name == NULL || !dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile, cu_header)) |
| 2022 | return; |
| 2023 | |
| 2024 | lowpc += baseaddr; |
| 2025 | highpc += baseaddr; |
| 2026 | |
| 2027 | /* Record the function range for dwarf_decode_lines. */ |
| 2028 | add_to_cu_func_list (name, lowpc, highpc); |
| 2029 | |
| 2030 | if (objfile->ei.entry_point >= lowpc && |
| 2031 | objfile->ei.entry_point < highpc) |
| 2032 | { |
| 2033 | objfile->ei.entry_func_lowpc = lowpc; |
| 2034 | objfile->ei.entry_func_highpc = highpc; |
| 2035 | } |
| 2036 | |
| 2037 | /* Decode DW_AT_frame_base location descriptor if present, keep result |
| 2038 | for DW_OP_fbreg operands in decode_locdesc. */ |
| 2039 | frame_base_reg = -1; |
| 2040 | frame_base_offset = 0; |
| 2041 | attr = dwarf_attr (die, DW_AT_frame_base); |
| 2042 | if (attr) |
| 2043 | { |
| 2044 | CORE_ADDR addr; |
| 2045 | |
| 2046 | /* Support the .debug_loc offsets */ |
| 2047 | if (attr_form_is_block (attr)) |
| 2048 | { |
| 2049 | addr = decode_locdesc (DW_BLOCK (attr), objfile, cu_header); |
| 2050 | } |
| 2051 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
| 2052 | { |
| 2053 | dwarf2_complex_location_expr_complaint (); |
| 2054 | addr = 0; |
| 2055 | } |
| 2056 | else |
| 2057 | { |
| 2058 | dwarf2_invalid_attrib_class_complaint ("DW_AT_frame_base", name); |
| 2059 | addr = 0; |
| 2060 | } |
| 2061 | |
| 2062 | if (isderef) |
| 2063 | dwarf2_unsupported_at_frame_base_complaint (name); |
| 2064 | else if (isreg) |
| 2065 | frame_base_reg = addr; |
| 2066 | else if (offreg) |
| 2067 | { |
| 2068 | frame_base_reg = basereg; |
| 2069 | frame_base_offset = addr; |
| 2070 | } |
| 2071 | else |
| 2072 | dwarf2_unsupported_at_frame_base_complaint (name); |
| 2073 | } |
| 2074 | |
| 2075 | new = push_context (0, lowpc); |
| 2076 | new->name = new_symbol (die, die->type, objfile, cu_header); |
| 2077 | |
| 2078 | /* If there was a location expression for DW_AT_frame_base above, |
| 2079 | record it. We still need to decode it above because not all |
| 2080 | symbols use location expressions exclusively. */ |
| 2081 | if (attr) |
| 2082 | dwarf2_symbol_mark_computed (attr, new->name, cu_header, objfile); |
| 2083 | |
| 2084 | list_in_scope = &local_symbols; |
| 2085 | |
| 2086 | if (die->has_children) |
| 2087 | { |
| 2088 | child_die = die->next; |
| 2089 | while (child_die && child_die->tag) |
| 2090 | { |
| 2091 | process_die (child_die, objfile, cu_header); |
| 2092 | child_die = sibling_die (child_die); |
| 2093 | } |
| 2094 | } |
| 2095 | |
| 2096 | new = pop_context (); |
| 2097 | /* Make a block for the local symbols within. */ |
| 2098 | finish_block (new->name, &local_symbols, new->old_blocks, |
| 2099 | lowpc, highpc, objfile); |
| 2100 | |
| 2101 | /* In C++, we can have functions nested inside functions (e.g., when |
| 2102 | a function declares a class that has methods). This means that |
| 2103 | when we finish processing a function scope, we may need to go |
| 2104 | back to building a containing block's symbol lists. */ |
| 2105 | local_symbols = new->locals; |
| 2106 | param_symbols = new->params; |
| 2107 | |
| 2108 | /* If we've finished processing a top-level function, subsequent |
| 2109 | symbols go in the file symbol list. */ |
| 2110 | if (outermost_context_p ()) |
| 2111 | list_in_scope = &file_symbols; |
| 2112 | } |
| 2113 | |
| 2114 | /* Process all the DIES contained within a lexical block scope. Start |
| 2115 | a new scope, process the dies, and then close the scope. */ |
| 2116 | |
| 2117 | static void |
| 2118 | read_lexical_block_scope (struct die_info *die, struct objfile *objfile, |
| 2119 | const struct comp_unit_head *cu_header) |
| 2120 | { |
| 2121 | register struct context_stack *new; |
| 2122 | CORE_ADDR lowpc, highpc; |
| 2123 | struct die_info *child_die; |
| 2124 | |
| 2125 | /* Ignore blocks with missing or invalid low and high pc attributes. */ |
| 2126 | /* ??? Perhaps consider discontiguous blocks defined by DW_AT_ranges |
| 2127 | as multiple lexical blocks? Handling children in a sane way would |
| 2128 | be nasty. Might be easier to properly extend generic blocks to |
| 2129 | describe ranges. */ |
| 2130 | if (!dwarf2_get_pc_bounds (die, &lowpc, &highpc, objfile, cu_header)) |
| 2131 | return; |
| 2132 | lowpc += baseaddr; |
| 2133 | highpc += baseaddr; |
| 2134 | |
| 2135 | push_context (0, lowpc); |
| 2136 | if (die->has_children) |
| 2137 | { |
| 2138 | child_die = die->next; |
| 2139 | while (child_die && child_die->tag) |
| 2140 | { |
| 2141 | process_die (child_die, objfile, cu_header); |
| 2142 | child_die = sibling_die (child_die); |
| 2143 | } |
| 2144 | } |
| 2145 | new = pop_context (); |
| 2146 | |
| 2147 | if (local_symbols != NULL) |
| 2148 | { |
| 2149 | finish_block (0, &local_symbols, new->old_blocks, new->start_addr, |
| 2150 | highpc, objfile); |
| 2151 | } |
| 2152 | local_symbols = new->locals; |
| 2153 | } |
| 2154 | |
| 2155 | /* Get low and high pc attributes from a die. Return 1 if the attributes |
| 2156 | are present and valid, otherwise, return 0. Return -1 if the range is |
| 2157 | discontinuous, i.e. derived from DW_AT_ranges information. */ |
| 2158 | static int |
| 2159 | dwarf2_get_pc_bounds (struct die_info *die, CORE_ADDR *lowpc, |
| 2160 | CORE_ADDR *highpc, struct objfile *objfile, |
| 2161 | const struct comp_unit_head *cu_header) |
| 2162 | { |
| 2163 | struct attribute *attr; |
| 2164 | bfd *obfd = objfile->obfd; |
| 2165 | CORE_ADDR low = 0; |
| 2166 | CORE_ADDR high = 0; |
| 2167 | int ret = 0; |
| 2168 | |
| 2169 | attr = dwarf_attr (die, DW_AT_high_pc); |
| 2170 | if (attr) |
| 2171 | { |
| 2172 | high = DW_ADDR (attr); |
| 2173 | attr = dwarf_attr (die, DW_AT_low_pc); |
| 2174 | if (attr) |
| 2175 | low = DW_ADDR (attr); |
| 2176 | else |
| 2177 | /* Found high w/o low attribute. */ |
| 2178 | return 0; |
| 2179 | |
| 2180 | /* Found consecutive range of addresses. */ |
| 2181 | ret = 1; |
| 2182 | } |
| 2183 | else |
| 2184 | { |
| 2185 | attr = dwarf_attr (die, DW_AT_ranges); |
| 2186 | if (attr != NULL) |
| 2187 | { |
| 2188 | unsigned int addr_size = cu_header->addr_size; |
| 2189 | CORE_ADDR mask = ~(~(CORE_ADDR)1 << (addr_size * 8 - 1)); |
| 2190 | /* Value of the DW_AT_ranges attribute is the offset in the |
| 2191 | .debug_renges section. */ |
| 2192 | unsigned int offset = DW_UNSND (attr); |
| 2193 | /* Base address selection entry. */ |
| 2194 | CORE_ADDR base; |
| 2195 | int found_base; |
| 2196 | int dummy; |
| 2197 | unsigned int i; |
| 2198 | char *buffer; |
| 2199 | CORE_ADDR marker; |
| 2200 | int low_set; |
| 2201 | |
| 2202 | found_base = cu_header->base_known; |
| 2203 | base = cu_header->base_address; |
| 2204 | buffer = dwarf_ranges_buffer + offset; |
| 2205 | |
| 2206 | /* Read in the largest possible address. */ |
| 2207 | marker = read_address (obfd, buffer, cu_header, &dummy); |
| 2208 | if ((marker & mask) == mask) |
| 2209 | { |
| 2210 | /* If we found the largest possible address, then |
| 2211 | read the base address. */ |
| 2212 | base = read_address (obfd, buffer + addr_size, |
| 2213 | cu_header, &dummy); |
| 2214 | buffer += 2 * addr_size; |
| 2215 | offset += 2 * addr_size; |
| 2216 | found_base = 1; |
| 2217 | } |
| 2218 | |
| 2219 | low_set = 0; |
| 2220 | |
| 2221 | while (1) |
| 2222 | { |
| 2223 | CORE_ADDR range_beginning, range_end; |
| 2224 | |
| 2225 | range_beginning = read_address (obfd, buffer, |
| 2226 | cu_header, &dummy); |
| 2227 | buffer += addr_size; |
| 2228 | range_end = read_address (obfd, buffer, cu_header, &dummy); |
| 2229 | buffer += addr_size; |
| 2230 | offset += 2 * addr_size; |
| 2231 | |
| 2232 | /* An end of list marker is a pair of zero addresses. */ |
| 2233 | if (range_beginning == 0 && range_end == 0) |
| 2234 | /* Found the end of list entry. */ |
| 2235 | break; |
| 2236 | |
| 2237 | /* Each base address selection entry is a pair of 2 values. |
| 2238 | The first is the largest possible address, the second is |
| 2239 | the base address. Check for a base address here. */ |
| 2240 | if ((range_beginning & mask) == mask) |
| 2241 | { |
| 2242 | /* If we found the largest possible address, then |
| 2243 | read the base address. */ |
| 2244 | base = read_address (obfd, buffer + addr_size, |
| 2245 | cu_header, &dummy); |
| 2246 | found_base = 1; |
| 2247 | continue; |
| 2248 | } |
| 2249 | |
| 2250 | if (!found_base) |
| 2251 | { |
| 2252 | /* We have no valid base address for the ranges |
| 2253 | data. */ |
| 2254 | complaint (&symfile_complaints, |
| 2255 | "Invalid .debug_ranges data (no base address)"); |
| 2256 | return 0; |
| 2257 | } |
| 2258 | |
| 2259 | range_beginning += base; |
| 2260 | range_end += base; |
| 2261 | |
| 2262 | /* FIXME: This is recording everything as a low-high |
| 2263 | segment of consecutive addresses. We should have a |
| 2264 | data structure for discontiguous block ranges |
| 2265 | instead. */ |
| 2266 | if (! low_set) |
| 2267 | { |
| 2268 | low = range_beginning; |
| 2269 | high = range_end; |
| 2270 | low_set = 1; |
| 2271 | } |
| 2272 | else |
| 2273 | { |
| 2274 | if (range_beginning < low) |
| 2275 | low = range_beginning; |
| 2276 | if (range_end > high) |
| 2277 | high = range_end; |
| 2278 | } |
| 2279 | } |
| 2280 | |
| 2281 | if (! low_set) |
| 2282 | /* If the first entry is an end-of-list marker, the range |
| 2283 | describes an empty scope, i.e. no instructions. */ |
| 2284 | return 0; |
| 2285 | |
| 2286 | ret = -1; |
| 2287 | } |
| 2288 | } |
| 2289 | |
| 2290 | if (high < low) |
| 2291 | return 0; |
| 2292 | |
| 2293 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 2294 | eliminate duplicate copies of functions and vtables and such. |
| 2295 | The linker will arbitrarily choose one and discard the others. |
| 2296 | The AT_*_pc values for such functions refer to local labels in |
| 2297 | these sections. If the section from that file was discarded, the |
| 2298 | labels are not in the output, so the relocs get a value of 0. |
| 2299 | If this is a discarded function, mark the pc bounds as invalid, |
| 2300 | so that GDB will ignore it. */ |
| 2301 | if (low == 0 && (bfd_get_file_flags (obfd) & HAS_RELOC) == 0) |
| 2302 | return 0; |
| 2303 | |
| 2304 | *lowpc = low; |
| 2305 | *highpc = high; |
| 2306 | return ret; |
| 2307 | } |
| 2308 | |
| 2309 | /* Add an aggregate field to the field list. */ |
| 2310 | |
| 2311 | static void |
| 2312 | dwarf2_add_field (struct field_info *fip, struct die_info *die, |
| 2313 | struct objfile *objfile, |
| 2314 | const struct comp_unit_head *cu_header) |
| 2315 | { |
| 2316 | struct nextfield *new_field; |
| 2317 | struct attribute *attr; |
| 2318 | struct field *fp; |
| 2319 | char *fieldname = ""; |
| 2320 | |
| 2321 | /* Allocate a new field list entry and link it in. */ |
| 2322 | new_field = (struct nextfield *) xmalloc (sizeof (struct nextfield)); |
| 2323 | make_cleanup (xfree, new_field); |
| 2324 | memset (new_field, 0, sizeof (struct nextfield)); |
| 2325 | new_field->next = fip->fields; |
| 2326 | fip->fields = new_field; |
| 2327 | fip->nfields++; |
| 2328 | |
| 2329 | /* Handle accessibility and virtuality of field. |
| 2330 | The default accessibility for members is public, the default |
| 2331 | accessibility for inheritance is private. */ |
| 2332 | if (die->tag != DW_TAG_inheritance) |
| 2333 | new_field->accessibility = DW_ACCESS_public; |
| 2334 | else |
| 2335 | new_field->accessibility = DW_ACCESS_private; |
| 2336 | new_field->virtuality = DW_VIRTUALITY_none; |
| 2337 | |
| 2338 | attr = dwarf_attr (die, DW_AT_accessibility); |
| 2339 | if (attr) |
| 2340 | new_field->accessibility = DW_UNSND (attr); |
| 2341 | if (new_field->accessibility != DW_ACCESS_public) |
| 2342 | fip->non_public_fields = 1; |
| 2343 | attr = dwarf_attr (die, DW_AT_virtuality); |
| 2344 | if (attr) |
| 2345 | new_field->virtuality = DW_UNSND (attr); |
| 2346 | |
| 2347 | fp = &new_field->field; |
| 2348 | |
| 2349 | if (die->tag == DW_TAG_member && ! die_is_declaration (die)) |
| 2350 | { |
| 2351 | /* Data member other than a C++ static data member. */ |
| 2352 | |
| 2353 | /* Get type of field. */ |
| 2354 | fp->type = die_type (die, objfile, cu_header); |
| 2355 | |
| 2356 | FIELD_STATIC_KIND (*fp) = 0; |
| 2357 | |
| 2358 | /* Get bit size of field (zero if none). */ |
| 2359 | attr = dwarf_attr (die, DW_AT_bit_size); |
| 2360 | if (attr) |
| 2361 | { |
| 2362 | FIELD_BITSIZE (*fp) = DW_UNSND (attr); |
| 2363 | } |
| 2364 | else |
| 2365 | { |
| 2366 | FIELD_BITSIZE (*fp) = 0; |
| 2367 | } |
| 2368 | |
| 2369 | /* Get bit offset of field. */ |
| 2370 | attr = dwarf_attr (die, DW_AT_data_member_location); |
| 2371 | if (attr) |
| 2372 | { |
| 2373 | FIELD_BITPOS (*fp) = |
| 2374 | decode_locdesc (DW_BLOCK (attr), objfile, cu_header) * bits_per_byte; |
| 2375 | } |
| 2376 | else |
| 2377 | FIELD_BITPOS (*fp) = 0; |
| 2378 | attr = dwarf_attr (die, DW_AT_bit_offset); |
| 2379 | if (attr) |
| 2380 | { |
| 2381 | if (BITS_BIG_ENDIAN) |
| 2382 | { |
| 2383 | /* For big endian bits, the DW_AT_bit_offset gives the |
| 2384 | additional bit offset from the MSB of the containing |
| 2385 | anonymous object to the MSB of the field. We don't |
| 2386 | have to do anything special since we don't need to |
| 2387 | know the size of the anonymous object. */ |
| 2388 | FIELD_BITPOS (*fp) += DW_UNSND (attr); |
| 2389 | } |
| 2390 | else |
| 2391 | { |
| 2392 | /* For little endian bits, compute the bit offset to the |
| 2393 | MSB of the anonymous object, subtract off the number of |
| 2394 | bits from the MSB of the field to the MSB of the |
| 2395 | object, and then subtract off the number of bits of |
| 2396 | the field itself. The result is the bit offset of |
| 2397 | the LSB of the field. */ |
| 2398 | int anonymous_size; |
| 2399 | int bit_offset = DW_UNSND (attr); |
| 2400 | |
| 2401 | attr = dwarf_attr (die, DW_AT_byte_size); |
| 2402 | if (attr) |
| 2403 | { |
| 2404 | /* The size of the anonymous object containing |
| 2405 | the bit field is explicit, so use the |
| 2406 | indicated size (in bytes). */ |
| 2407 | anonymous_size = DW_UNSND (attr); |
| 2408 | } |
| 2409 | else |
| 2410 | { |
| 2411 | /* The size of the anonymous object containing |
| 2412 | the bit field must be inferred from the type |
| 2413 | attribute of the data member containing the |
| 2414 | bit field. */ |
| 2415 | anonymous_size = TYPE_LENGTH (fp->type); |
| 2416 | } |
| 2417 | FIELD_BITPOS (*fp) += anonymous_size * bits_per_byte |
| 2418 | - bit_offset - FIELD_BITSIZE (*fp); |
| 2419 | } |
| 2420 | } |
| 2421 | |
| 2422 | /* Get name of field. */ |
| 2423 | attr = dwarf_attr (die, DW_AT_name); |
| 2424 | if (attr && DW_STRING (attr)) |
| 2425 | fieldname = DW_STRING (attr); |
| 2426 | fp->name = obsavestring (fieldname, strlen (fieldname), |
| 2427 | &objfile->type_obstack); |
| 2428 | |
| 2429 | /* Change accessibility for artificial fields (e.g. virtual table |
| 2430 | pointer or virtual base class pointer) to private. */ |
| 2431 | if (dwarf_attr (die, DW_AT_artificial)) |
| 2432 | { |
| 2433 | new_field->accessibility = DW_ACCESS_private; |
| 2434 | fip->non_public_fields = 1; |
| 2435 | } |
| 2436 | } |
| 2437 | else if (die->tag == DW_TAG_member || die->tag == DW_TAG_variable) |
| 2438 | { |
| 2439 | /* C++ static member. */ |
| 2440 | |
| 2441 | /* NOTE: carlton/2002-11-05: It should be a DW_TAG_member that |
| 2442 | is a declaration, but all versions of G++ as of this writing |
| 2443 | (so through at least 3.2.1) incorrectly generate |
| 2444 | DW_TAG_variable tags. */ |
| 2445 | |
| 2446 | char *physname; |
| 2447 | |
| 2448 | /* Get name of field. */ |
| 2449 | attr = dwarf_attr (die, DW_AT_name); |
| 2450 | if (attr && DW_STRING (attr)) |
| 2451 | fieldname = DW_STRING (attr); |
| 2452 | else |
| 2453 | return; |
| 2454 | |
| 2455 | /* Get physical name. */ |
| 2456 | physname = dwarf2_linkage_name (die); |
| 2457 | |
| 2458 | SET_FIELD_PHYSNAME (*fp, obsavestring (physname, strlen (physname), |
| 2459 | &objfile->type_obstack)); |
| 2460 | FIELD_TYPE (*fp) = die_type (die, objfile, cu_header); |
| 2461 | FIELD_NAME (*fp) = obsavestring (fieldname, strlen (fieldname), |
| 2462 | &objfile->type_obstack); |
| 2463 | } |
| 2464 | else if (die->tag == DW_TAG_inheritance) |
| 2465 | { |
| 2466 | /* C++ base class field. */ |
| 2467 | attr = dwarf_attr (die, DW_AT_data_member_location); |
| 2468 | if (attr) |
| 2469 | FIELD_BITPOS (*fp) = (decode_locdesc (DW_BLOCK (attr), objfile, cu_header) |
| 2470 | * bits_per_byte); |
| 2471 | FIELD_BITSIZE (*fp) = 0; |
| 2472 | FIELD_STATIC_KIND (*fp) = 0; |
| 2473 | FIELD_TYPE (*fp) = die_type (die, objfile, cu_header); |
| 2474 | FIELD_NAME (*fp) = type_name_no_tag (fp->type); |
| 2475 | fip->nbaseclasses++; |
| 2476 | } |
| 2477 | } |
| 2478 | |
| 2479 | /* Create the vector of fields, and attach it to the type. */ |
| 2480 | |
| 2481 | static void |
| 2482 | dwarf2_attach_fields_to_type (struct field_info *fip, struct type *type, |
| 2483 | struct objfile *objfile) |
| 2484 | { |
| 2485 | int nfields = fip->nfields; |
| 2486 | |
| 2487 | /* Record the field count, allocate space for the array of fields, |
| 2488 | and create blank accessibility bitfields if necessary. */ |
| 2489 | TYPE_NFIELDS (type) = nfields; |
| 2490 | TYPE_FIELDS (type) = (struct field *) |
| 2491 | TYPE_ALLOC (type, sizeof (struct field) * nfields); |
| 2492 | memset (TYPE_FIELDS (type), 0, sizeof (struct field) * nfields); |
| 2493 | |
| 2494 | if (fip->non_public_fields) |
| 2495 | { |
| 2496 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 2497 | |
| 2498 | TYPE_FIELD_PRIVATE_BITS (type) = |
| 2499 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 2500 | B_CLRALL (TYPE_FIELD_PRIVATE_BITS (type), nfields); |
| 2501 | |
| 2502 | TYPE_FIELD_PROTECTED_BITS (type) = |
| 2503 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 2504 | B_CLRALL (TYPE_FIELD_PROTECTED_BITS (type), nfields); |
| 2505 | |
| 2506 | TYPE_FIELD_IGNORE_BITS (type) = |
| 2507 | (B_TYPE *) TYPE_ALLOC (type, B_BYTES (nfields)); |
| 2508 | B_CLRALL (TYPE_FIELD_IGNORE_BITS (type), nfields); |
| 2509 | } |
| 2510 | |
| 2511 | /* If the type has baseclasses, allocate and clear a bit vector for |
| 2512 | TYPE_FIELD_VIRTUAL_BITS. */ |
| 2513 | if (fip->nbaseclasses) |
| 2514 | { |
| 2515 | int num_bytes = B_BYTES (fip->nbaseclasses); |
| 2516 | char *pointer; |
| 2517 | |
| 2518 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 2519 | pointer = (char *) TYPE_ALLOC (type, num_bytes); |
| 2520 | TYPE_FIELD_VIRTUAL_BITS (type) = (B_TYPE *) pointer; |
| 2521 | B_CLRALL (TYPE_FIELD_VIRTUAL_BITS (type), fip->nbaseclasses); |
| 2522 | TYPE_N_BASECLASSES (type) = fip->nbaseclasses; |
| 2523 | } |
| 2524 | |
| 2525 | /* Copy the saved-up fields into the field vector. Start from the head |
| 2526 | of the list, adding to the tail of the field array, so that they end |
| 2527 | up in the same order in the array in which they were added to the list. */ |
| 2528 | while (nfields-- > 0) |
| 2529 | { |
| 2530 | TYPE_FIELD (type, nfields) = fip->fields->field; |
| 2531 | switch (fip->fields->accessibility) |
| 2532 | { |
| 2533 | case DW_ACCESS_private: |
| 2534 | SET_TYPE_FIELD_PRIVATE (type, nfields); |
| 2535 | break; |
| 2536 | |
| 2537 | case DW_ACCESS_protected: |
| 2538 | SET_TYPE_FIELD_PROTECTED (type, nfields); |
| 2539 | break; |
| 2540 | |
| 2541 | case DW_ACCESS_public: |
| 2542 | break; |
| 2543 | |
| 2544 | default: |
| 2545 | /* Unknown accessibility. Complain and treat it as public. */ |
| 2546 | { |
| 2547 | complaint (&symfile_complaints, "unsupported accessibility %d", |
| 2548 | fip->fields->accessibility); |
| 2549 | } |
| 2550 | break; |
| 2551 | } |
| 2552 | if (nfields < fip->nbaseclasses) |
| 2553 | { |
| 2554 | switch (fip->fields->virtuality) |
| 2555 | { |
| 2556 | case DW_VIRTUALITY_virtual: |
| 2557 | case DW_VIRTUALITY_pure_virtual: |
| 2558 | SET_TYPE_FIELD_VIRTUAL (type, nfields); |
| 2559 | break; |
| 2560 | } |
| 2561 | } |
| 2562 | fip->fields = fip->fields->next; |
| 2563 | } |
| 2564 | } |
| 2565 | |
| 2566 | /* Add a member function to the proper fieldlist. */ |
| 2567 | |
| 2568 | static void |
| 2569 | dwarf2_add_member_fn (struct field_info *fip, struct die_info *die, |
| 2570 | struct type *type, struct objfile *objfile, |
| 2571 | const struct comp_unit_head *cu_header) |
| 2572 | { |
| 2573 | struct attribute *attr; |
| 2574 | struct fnfieldlist *flp; |
| 2575 | int i; |
| 2576 | struct fn_field *fnp; |
| 2577 | char *fieldname; |
| 2578 | char *physname; |
| 2579 | struct nextfnfield *new_fnfield; |
| 2580 | |
| 2581 | /* Get name of member function. */ |
| 2582 | attr = dwarf_attr (die, DW_AT_name); |
| 2583 | if (attr && DW_STRING (attr)) |
| 2584 | fieldname = DW_STRING (attr); |
| 2585 | else |
| 2586 | return; |
| 2587 | |
| 2588 | /* Get the mangled name. */ |
| 2589 | physname = dwarf2_linkage_name (die); |
| 2590 | |
| 2591 | /* Look up member function name in fieldlist. */ |
| 2592 | for (i = 0; i < fip->nfnfields; i++) |
| 2593 | { |
| 2594 | if (STREQ (fip->fnfieldlists[i].name, fieldname)) |
| 2595 | break; |
| 2596 | } |
| 2597 | |
| 2598 | /* Create new list element if necessary. */ |
| 2599 | if (i < fip->nfnfields) |
| 2600 | flp = &fip->fnfieldlists[i]; |
| 2601 | else |
| 2602 | { |
| 2603 | if ((fip->nfnfields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 2604 | { |
| 2605 | fip->fnfieldlists = (struct fnfieldlist *) |
| 2606 | xrealloc (fip->fnfieldlists, |
| 2607 | (fip->nfnfields + DW_FIELD_ALLOC_CHUNK) |
| 2608 | * sizeof (struct fnfieldlist)); |
| 2609 | if (fip->nfnfields == 0) |
| 2610 | make_cleanup (free_current_contents, &fip->fnfieldlists); |
| 2611 | } |
| 2612 | flp = &fip->fnfieldlists[fip->nfnfields]; |
| 2613 | flp->name = fieldname; |
| 2614 | flp->length = 0; |
| 2615 | flp->head = NULL; |
| 2616 | fip->nfnfields++; |
| 2617 | } |
| 2618 | |
| 2619 | /* Create a new member function field and chain it to the field list |
| 2620 | entry. */ |
| 2621 | new_fnfield = (struct nextfnfield *) xmalloc (sizeof (struct nextfnfield)); |
| 2622 | make_cleanup (xfree, new_fnfield); |
| 2623 | memset (new_fnfield, 0, sizeof (struct nextfnfield)); |
| 2624 | new_fnfield->next = flp->head; |
| 2625 | flp->head = new_fnfield; |
| 2626 | flp->length++; |
| 2627 | |
| 2628 | /* Fill in the member function field info. */ |
| 2629 | fnp = &new_fnfield->fnfield; |
| 2630 | fnp->physname = obsavestring (physname, strlen (physname), |
| 2631 | &objfile->type_obstack); |
| 2632 | fnp->type = alloc_type (objfile); |
| 2633 | if (die->type && TYPE_CODE (die->type) == TYPE_CODE_FUNC) |
| 2634 | { |
| 2635 | struct type *return_type = TYPE_TARGET_TYPE (die->type); |
| 2636 | int nparams = TYPE_NFIELDS (die->type); |
| 2637 | |
| 2638 | /* TYPE is the domain of this method, and DIE->TYPE is the type |
| 2639 | of the method itself (TYPE_CODE_METHOD). */ |
| 2640 | smash_to_method_type (fnp->type, type, |
| 2641 | TYPE_TARGET_TYPE (die->type), |
| 2642 | TYPE_FIELDS (die->type), |
| 2643 | TYPE_NFIELDS (die->type), |
| 2644 | TYPE_VARARGS (die->type)); |
| 2645 | |
| 2646 | /* Handle static member functions. |
| 2647 | Dwarf2 has no clean way to discern C++ static and non-static |
| 2648 | member functions. G++ helps GDB by marking the first |
| 2649 | parameter for non-static member functions (which is the |
| 2650 | this pointer) as artificial. We obtain this information |
| 2651 | from read_subroutine_type via TYPE_FIELD_ARTIFICIAL. */ |
| 2652 | if (nparams == 0 || TYPE_FIELD_ARTIFICIAL (die->type, 0) == 0) |
| 2653 | fnp->voffset = VOFFSET_STATIC; |
| 2654 | } |
| 2655 | else |
| 2656 | complaint (&symfile_complaints, "member function type missing for '%s'", |
| 2657 | physname); |
| 2658 | |
| 2659 | /* Get fcontext from DW_AT_containing_type if present. */ |
| 2660 | if (dwarf_attr (die, DW_AT_containing_type) != NULL) |
| 2661 | fnp->fcontext = die_containing_type (die, objfile, cu_header); |
| 2662 | |
| 2663 | /* dwarf2 doesn't have stubbed physical names, so the setting of is_const |
| 2664 | and is_volatile is irrelevant, as it is needed by gdb_mangle_name only. */ |
| 2665 | |
| 2666 | /* Get accessibility. */ |
| 2667 | attr = dwarf_attr (die, DW_AT_accessibility); |
| 2668 | if (attr) |
| 2669 | { |
| 2670 | switch (DW_UNSND (attr)) |
| 2671 | { |
| 2672 | case DW_ACCESS_private: |
| 2673 | fnp->is_private = 1; |
| 2674 | break; |
| 2675 | case DW_ACCESS_protected: |
| 2676 | fnp->is_protected = 1; |
| 2677 | break; |
| 2678 | } |
| 2679 | } |
| 2680 | |
| 2681 | /* Check for artificial methods. */ |
| 2682 | attr = dwarf_attr (die, DW_AT_artificial); |
| 2683 | if (attr && DW_UNSND (attr) != 0) |
| 2684 | fnp->is_artificial = 1; |
| 2685 | |
| 2686 | /* Get index in virtual function table if it is a virtual member function. */ |
| 2687 | attr = dwarf_attr (die, DW_AT_vtable_elem_location); |
| 2688 | if (attr) |
| 2689 | { |
| 2690 | /* Support the .debug_loc offsets */ |
| 2691 | if (attr_form_is_block (attr)) |
| 2692 | { |
| 2693 | fnp->voffset = decode_locdesc (DW_BLOCK (attr), objfile, cu_header) + 2; |
| 2694 | } |
| 2695 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
| 2696 | { |
| 2697 | dwarf2_complex_location_expr_complaint (); |
| 2698 | } |
| 2699 | else |
| 2700 | { |
| 2701 | dwarf2_invalid_attrib_class_complaint ("DW_AT_vtable_elem_location", |
| 2702 | fieldname); |
| 2703 | } |
| 2704 | } |
| 2705 | } |
| 2706 | |
| 2707 | /* Create the vector of member function fields, and attach it to the type. */ |
| 2708 | |
| 2709 | static void |
| 2710 | dwarf2_attach_fn_fields_to_type (struct field_info *fip, struct type *type, |
| 2711 | struct objfile *objfile) |
| 2712 | { |
| 2713 | struct fnfieldlist *flp; |
| 2714 | int total_length = 0; |
| 2715 | int i; |
| 2716 | |
| 2717 | ALLOCATE_CPLUS_STRUCT_TYPE (type); |
| 2718 | TYPE_FN_FIELDLISTS (type) = (struct fn_fieldlist *) |
| 2719 | TYPE_ALLOC (type, sizeof (struct fn_fieldlist) * fip->nfnfields); |
| 2720 | |
| 2721 | for (i = 0, flp = fip->fnfieldlists; i < fip->nfnfields; i++, flp++) |
| 2722 | { |
| 2723 | struct nextfnfield *nfp = flp->head; |
| 2724 | struct fn_fieldlist *fn_flp = &TYPE_FN_FIELDLIST (type, i); |
| 2725 | int k; |
| 2726 | |
| 2727 | TYPE_FN_FIELDLIST_NAME (type, i) = flp->name; |
| 2728 | TYPE_FN_FIELDLIST_LENGTH (type, i) = flp->length; |
| 2729 | fn_flp->fn_fields = (struct fn_field *) |
| 2730 | TYPE_ALLOC (type, sizeof (struct fn_field) * flp->length); |
| 2731 | for (k = flp->length; (k--, nfp); nfp = nfp->next) |
| 2732 | fn_flp->fn_fields[k] = nfp->fnfield; |
| 2733 | |
| 2734 | total_length += flp->length; |
| 2735 | } |
| 2736 | |
| 2737 | TYPE_NFN_FIELDS (type) = fip->nfnfields; |
| 2738 | TYPE_NFN_FIELDS_TOTAL (type) = total_length; |
| 2739 | } |
| 2740 | |
| 2741 | /* Called when we find the DIE that starts a structure or union scope |
| 2742 | (definition) to process all dies that define the members of the |
| 2743 | structure or union. |
| 2744 | |
| 2745 | NOTE: we need to call struct_type regardless of whether or not the |
| 2746 | DIE has an at_name attribute, since it might be an anonymous |
| 2747 | structure or union. This gets the type entered into our set of |
| 2748 | user defined types. |
| 2749 | |
| 2750 | However, if the structure is incomplete (an opaque struct/union) |
| 2751 | then suppress creating a symbol table entry for it since gdb only |
| 2752 | wants to find the one with the complete definition. Note that if |
| 2753 | it is complete, we just call new_symbol, which does it's own |
| 2754 | checking about whether the struct/union is anonymous or not (and |
| 2755 | suppresses creating a symbol table entry itself). */ |
| 2756 | |
| 2757 | static void |
| 2758 | read_structure_scope (struct die_info *die, struct objfile *objfile, |
| 2759 | const struct comp_unit_head *cu_header) |
| 2760 | { |
| 2761 | struct type *type; |
| 2762 | struct attribute *attr; |
| 2763 | |
| 2764 | type = alloc_type (objfile); |
| 2765 | |
| 2766 | INIT_CPLUS_SPECIFIC (type); |
| 2767 | attr = dwarf_attr (die, DW_AT_name); |
| 2768 | if (attr && DW_STRING (attr)) |
| 2769 | { |
| 2770 | TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr), |
| 2771 | strlen (DW_STRING (attr)), |
| 2772 | &objfile->type_obstack); |
| 2773 | } |
| 2774 | |
| 2775 | if (die->tag == DW_TAG_structure_type) |
| 2776 | { |
| 2777 | TYPE_CODE (type) = TYPE_CODE_STRUCT; |
| 2778 | } |
| 2779 | else if (die->tag == DW_TAG_union_type) |
| 2780 | { |
| 2781 | TYPE_CODE (type) = TYPE_CODE_UNION; |
| 2782 | } |
| 2783 | else |
| 2784 | { |
| 2785 | /* FIXME: TYPE_CODE_CLASS is currently defined to TYPE_CODE_STRUCT |
| 2786 | in gdbtypes.h. */ |
| 2787 | TYPE_CODE (type) = TYPE_CODE_CLASS; |
| 2788 | } |
| 2789 | |
| 2790 | attr = dwarf_attr (die, DW_AT_byte_size); |
| 2791 | if (attr) |
| 2792 | { |
| 2793 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 2794 | } |
| 2795 | else |
| 2796 | { |
| 2797 | TYPE_LENGTH (type) = 0; |
| 2798 | } |
| 2799 | |
| 2800 | /* We need to add the type field to the die immediately so we don't |
| 2801 | infinitely recurse when dealing with pointers to the structure |
| 2802 | type within the structure itself. */ |
| 2803 | die->type = type; |
| 2804 | |
| 2805 | if (die->has_children && ! die_is_declaration (die)) |
| 2806 | { |
| 2807 | struct field_info fi; |
| 2808 | struct die_info *child_die; |
| 2809 | struct cleanup *back_to = make_cleanup (null_cleanup, NULL); |
| 2810 | |
| 2811 | memset (&fi, 0, sizeof (struct field_info)); |
| 2812 | |
| 2813 | child_die = die->next; |
| 2814 | |
| 2815 | while (child_die && child_die->tag) |
| 2816 | { |
| 2817 | if (child_die->tag == DW_TAG_member |
| 2818 | || child_die->tag == DW_TAG_variable) |
| 2819 | { |
| 2820 | /* NOTE: carlton/2002-11-05: A C++ static data member |
| 2821 | should be a DW_TAG_member that is a declaration, but |
| 2822 | all versions of G++ as of this writing (so through at |
| 2823 | least 3.2.1) incorrectly generate DW_TAG_variable |
| 2824 | tags for them instead. */ |
| 2825 | dwarf2_add_field (&fi, child_die, objfile, cu_header); |
| 2826 | } |
| 2827 | else if (child_die->tag == DW_TAG_subprogram) |
| 2828 | { |
| 2829 | /* C++ member function. */ |
| 2830 | process_die (child_die, objfile, cu_header); |
| 2831 | dwarf2_add_member_fn (&fi, child_die, type, objfile, cu_header); |
| 2832 | } |
| 2833 | else if (child_die->tag == DW_TAG_inheritance) |
| 2834 | { |
| 2835 | /* C++ base class field. */ |
| 2836 | dwarf2_add_field (&fi, child_die, objfile, cu_header); |
| 2837 | } |
| 2838 | else |
| 2839 | { |
| 2840 | process_die (child_die, objfile, cu_header); |
| 2841 | } |
| 2842 | child_die = sibling_die (child_die); |
| 2843 | } |
| 2844 | |
| 2845 | /* Attach fields and member functions to the type. */ |
| 2846 | if (fi.nfields) |
| 2847 | dwarf2_attach_fields_to_type (&fi, type, objfile); |
| 2848 | if (fi.nfnfields) |
| 2849 | { |
| 2850 | dwarf2_attach_fn_fields_to_type (&fi, type, objfile); |
| 2851 | |
| 2852 | /* Get the type which refers to the base class (possibly this |
| 2853 | class itself) which contains the vtable pointer for the current |
| 2854 | class from the DW_AT_containing_type attribute. */ |
| 2855 | |
| 2856 | if (dwarf_attr (die, DW_AT_containing_type) != NULL) |
| 2857 | { |
| 2858 | struct type *t = die_containing_type (die, objfile, cu_header); |
| 2859 | |
| 2860 | TYPE_VPTR_BASETYPE (type) = t; |
| 2861 | if (type == t) |
| 2862 | { |
| 2863 | static const char vptr_name[] = |
| 2864 | {'_', 'v', 'p', 't', 'r', '\0'}; |
| 2865 | int i; |
| 2866 | |
| 2867 | /* Our own class provides vtbl ptr. */ |
| 2868 | for (i = TYPE_NFIELDS (t) - 1; |
| 2869 | i >= TYPE_N_BASECLASSES (t); |
| 2870 | --i) |
| 2871 | { |
| 2872 | char *fieldname = TYPE_FIELD_NAME (t, i); |
| 2873 | |
| 2874 | if (STREQN (fieldname, vptr_name, strlen (vptr_name) - 1) |
| 2875 | && is_cplus_marker (fieldname[strlen (vptr_name)])) |
| 2876 | { |
| 2877 | TYPE_VPTR_FIELDNO (type) = i; |
| 2878 | break; |
| 2879 | } |
| 2880 | } |
| 2881 | |
| 2882 | /* Complain if virtual function table field not found. */ |
| 2883 | if (i < TYPE_N_BASECLASSES (t)) |
| 2884 | complaint (&symfile_complaints, |
| 2885 | "virtual function table pointer not found when defining class '%s'", |
| 2886 | TYPE_TAG_NAME (type) ? TYPE_TAG_NAME (type) : |
| 2887 | ""); |
| 2888 | } |
| 2889 | else |
| 2890 | { |
| 2891 | TYPE_VPTR_FIELDNO (type) = TYPE_VPTR_FIELDNO (t); |
| 2892 | } |
| 2893 | } |
| 2894 | } |
| 2895 | |
| 2896 | new_symbol (die, type, objfile, cu_header); |
| 2897 | |
| 2898 | do_cleanups (back_to); |
| 2899 | } |
| 2900 | else |
| 2901 | { |
| 2902 | /* No children, must be stub. */ |
| 2903 | TYPE_FLAGS (type) |= TYPE_FLAG_STUB; |
| 2904 | } |
| 2905 | } |
| 2906 | |
| 2907 | /* Given a pointer to a die which begins an enumeration, process all |
| 2908 | the dies that define the members of the enumeration. |
| 2909 | |
| 2910 | This will be much nicer in draft 6 of the DWARF spec when our |
| 2911 | members will be dies instead squished into the DW_AT_element_list |
| 2912 | attribute. |
| 2913 | |
| 2914 | NOTE: We reverse the order of the element list. */ |
| 2915 | |
| 2916 | static void |
| 2917 | read_enumeration (struct die_info *die, struct objfile *objfile, |
| 2918 | const struct comp_unit_head *cu_header) |
| 2919 | { |
| 2920 | struct die_info *child_die; |
| 2921 | struct type *type; |
| 2922 | struct field *fields; |
| 2923 | struct attribute *attr; |
| 2924 | struct symbol *sym; |
| 2925 | int num_fields; |
| 2926 | int unsigned_enum = 1; |
| 2927 | |
| 2928 | type = alloc_type (objfile); |
| 2929 | |
| 2930 | TYPE_CODE (type) = TYPE_CODE_ENUM; |
| 2931 | attr = dwarf_attr (die, DW_AT_name); |
| 2932 | if (attr && DW_STRING (attr)) |
| 2933 | { |
| 2934 | TYPE_TAG_NAME (type) = obsavestring (DW_STRING (attr), |
| 2935 | strlen (DW_STRING (attr)), |
| 2936 | &objfile->type_obstack); |
| 2937 | } |
| 2938 | |
| 2939 | attr = dwarf_attr (die, DW_AT_byte_size); |
| 2940 | if (attr) |
| 2941 | { |
| 2942 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 2943 | } |
| 2944 | else |
| 2945 | { |
| 2946 | TYPE_LENGTH (type) = 0; |
| 2947 | } |
| 2948 | |
| 2949 | num_fields = 0; |
| 2950 | fields = NULL; |
| 2951 | if (die->has_children) |
| 2952 | { |
| 2953 | child_die = die->next; |
| 2954 | while (child_die && child_die->tag) |
| 2955 | { |
| 2956 | if (child_die->tag != DW_TAG_enumerator) |
| 2957 | { |
| 2958 | process_die (child_die, objfile, cu_header); |
| 2959 | } |
| 2960 | else |
| 2961 | { |
| 2962 | attr = dwarf_attr (child_die, DW_AT_name); |
| 2963 | if (attr) |
| 2964 | { |
| 2965 | sym = new_symbol (child_die, type, objfile, cu_header); |
| 2966 | if (SYMBOL_VALUE (sym) < 0) |
| 2967 | unsigned_enum = 0; |
| 2968 | |
| 2969 | if ((num_fields % DW_FIELD_ALLOC_CHUNK) == 0) |
| 2970 | { |
| 2971 | fields = (struct field *) |
| 2972 | xrealloc (fields, |
| 2973 | (num_fields + DW_FIELD_ALLOC_CHUNK) |
| 2974 | * sizeof (struct field)); |
| 2975 | } |
| 2976 | |
| 2977 | FIELD_NAME (fields[num_fields]) = DEPRECATED_SYMBOL_NAME (sym); |
| 2978 | FIELD_TYPE (fields[num_fields]) = NULL; |
| 2979 | FIELD_BITPOS (fields[num_fields]) = SYMBOL_VALUE (sym); |
| 2980 | FIELD_BITSIZE (fields[num_fields]) = 0; |
| 2981 | FIELD_STATIC_KIND (fields[num_fields]) = 0; |
| 2982 | |
| 2983 | num_fields++; |
| 2984 | } |
| 2985 | } |
| 2986 | |
| 2987 | child_die = sibling_die (child_die); |
| 2988 | } |
| 2989 | |
| 2990 | if (num_fields) |
| 2991 | { |
| 2992 | TYPE_NFIELDS (type) = num_fields; |
| 2993 | TYPE_FIELDS (type) = (struct field *) |
| 2994 | TYPE_ALLOC (type, sizeof (struct field) * num_fields); |
| 2995 | memcpy (TYPE_FIELDS (type), fields, |
| 2996 | sizeof (struct field) * num_fields); |
| 2997 | xfree (fields); |
| 2998 | } |
| 2999 | if (unsigned_enum) |
| 3000 | TYPE_FLAGS (type) |= TYPE_FLAG_UNSIGNED; |
| 3001 | } |
| 3002 | die->type = type; |
| 3003 | new_symbol (die, type, objfile, cu_header); |
| 3004 | } |
| 3005 | |
| 3006 | /* Extract all information from a DW_TAG_array_type DIE and put it in |
| 3007 | the DIE's type field. For now, this only handles one dimensional |
| 3008 | arrays. */ |
| 3009 | |
| 3010 | static void |
| 3011 | read_array_type (struct die_info *die, struct objfile *objfile, |
| 3012 | const struct comp_unit_head *cu_header) |
| 3013 | { |
| 3014 | struct die_info *child_die; |
| 3015 | struct type *type = NULL; |
| 3016 | struct type *element_type, *range_type, *index_type; |
| 3017 | struct type **range_types = NULL; |
| 3018 | struct attribute *attr; |
| 3019 | int ndim = 0; |
| 3020 | struct cleanup *back_to; |
| 3021 | |
| 3022 | /* Return if we've already decoded this type. */ |
| 3023 | if (die->type) |
| 3024 | { |
| 3025 | return; |
| 3026 | } |
| 3027 | |
| 3028 | element_type = die_type (die, objfile, cu_header); |
| 3029 | |
| 3030 | /* Irix 6.2 native cc creates array types without children for |
| 3031 | arrays with unspecified length. */ |
| 3032 | if (die->has_children == 0) |
| 3033 | { |
| 3034 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER); |
| 3035 | range_type = create_range_type (NULL, index_type, 0, -1); |
| 3036 | die->type = create_array_type (NULL, element_type, range_type); |
| 3037 | return; |
| 3038 | } |
| 3039 | |
| 3040 | back_to = make_cleanup (null_cleanup, NULL); |
| 3041 | child_die = die->next; |
| 3042 | while (child_die && child_die->tag) |
| 3043 | { |
| 3044 | if (child_die->tag == DW_TAG_subrange_type) |
| 3045 | { |
| 3046 | unsigned int low, high; |
| 3047 | |
| 3048 | /* Default bounds to an array with unspecified length. */ |
| 3049 | low = 0; |
| 3050 | high = -1; |
| 3051 | if (cu_language == language_fortran) |
| 3052 | { |
| 3053 | /* FORTRAN implies a lower bound of 1, if not given. */ |
| 3054 | low = 1; |
| 3055 | } |
| 3056 | |
| 3057 | index_type = die_type (child_die, objfile, cu_header); |
| 3058 | attr = dwarf_attr (child_die, DW_AT_lower_bound); |
| 3059 | if (attr) |
| 3060 | { |
| 3061 | if (attr->form == DW_FORM_sdata) |
| 3062 | { |
| 3063 | low = DW_SND (attr); |
| 3064 | } |
| 3065 | else if (attr->form == DW_FORM_udata |
| 3066 | || attr->form == DW_FORM_data1 |
| 3067 | || attr->form == DW_FORM_data2 |
| 3068 | || attr->form == DW_FORM_data4 |
| 3069 | || attr->form == DW_FORM_data8) |
| 3070 | { |
| 3071 | low = DW_UNSND (attr); |
| 3072 | } |
| 3073 | else |
| 3074 | { |
| 3075 | dwarf2_non_const_array_bound_ignored_complaint |
| 3076 | (dwarf_form_name (attr->form)); |
| 3077 | #ifdef FORTRAN_HACK |
| 3078 | die->type = lookup_pointer_type (element_type); |
| 3079 | return; |
| 3080 | #else |
| 3081 | low = 0; |
| 3082 | #endif |
| 3083 | } |
| 3084 | } |
| 3085 | attr = dwarf_attr (child_die, DW_AT_upper_bound); |
| 3086 | if (attr) |
| 3087 | { |
| 3088 | if (attr->form == DW_FORM_sdata) |
| 3089 | { |
| 3090 | high = DW_SND (attr); |
| 3091 | } |
| 3092 | else if (attr->form == DW_FORM_udata |
| 3093 | || attr->form == DW_FORM_data1 |
| 3094 | || attr->form == DW_FORM_data2 |
| 3095 | || attr->form == DW_FORM_data4 |
| 3096 | || attr->form == DW_FORM_data8) |
| 3097 | { |
| 3098 | high = DW_UNSND (attr); |
| 3099 | } |
| 3100 | else if (attr->form == DW_FORM_block1) |
| 3101 | { |
| 3102 | /* GCC encodes arrays with unspecified or dynamic length |
| 3103 | with a DW_FORM_block1 attribute. |
| 3104 | FIXME: GDB does not yet know how to handle dynamic |
| 3105 | arrays properly, treat them as arrays with unspecified |
| 3106 | length for now. */ |
| 3107 | high = -1; |
| 3108 | } |
| 3109 | else |
| 3110 | { |
| 3111 | dwarf2_non_const_array_bound_ignored_complaint |
| 3112 | (dwarf_form_name (attr->form)); |
| 3113 | #ifdef FORTRAN_HACK |
| 3114 | die->type = lookup_pointer_type (element_type); |
| 3115 | return; |
| 3116 | #else |
| 3117 | high = 1; |
| 3118 | #endif |
| 3119 | } |
| 3120 | } |
| 3121 | |
| 3122 | /* Create a range type and save it for array type creation. */ |
| 3123 | if ((ndim % DW_FIELD_ALLOC_CHUNK) == 0) |
| 3124 | { |
| 3125 | range_types = (struct type **) |
| 3126 | xrealloc (range_types, (ndim + DW_FIELD_ALLOC_CHUNK) |
| 3127 | * sizeof (struct type *)); |
| 3128 | if (ndim == 0) |
| 3129 | make_cleanup (free_current_contents, &range_types); |
| 3130 | } |
| 3131 | range_types[ndim++] = create_range_type (NULL, index_type, low, high); |
| 3132 | } |
| 3133 | child_die = sibling_die (child_die); |
| 3134 | } |
| 3135 | |
| 3136 | /* Dwarf2 dimensions are output from left to right, create the |
| 3137 | necessary array types in backwards order. */ |
| 3138 | type = element_type; |
| 3139 | while (ndim-- > 0) |
| 3140 | type = create_array_type (NULL, type, range_types[ndim]); |
| 3141 | |
| 3142 | /* Understand Dwarf2 support for vector types (like they occur on |
| 3143 | the PowerPC w/ AltiVec). Gcc just adds another attribute to the |
| 3144 | array type. This is not part of the Dwarf2/3 standard yet, but a |
| 3145 | custom vendor extension. The main difference between a regular |
| 3146 | array and the vector variant is that vectors are passed by value |
| 3147 | to functions. */ |
| 3148 | attr = dwarf_attr (die, DW_AT_GNU_vector); |
| 3149 | if (attr) |
| 3150 | TYPE_FLAGS (type) |= TYPE_FLAG_VECTOR; |
| 3151 | |
| 3152 | do_cleanups (back_to); |
| 3153 | |
| 3154 | /* Install the type in the die. */ |
| 3155 | die->type = type; |
| 3156 | } |
| 3157 | |
| 3158 | /* First cut: install each common block member as a global variable. */ |
| 3159 | |
| 3160 | static void |
| 3161 | read_common_block (struct die_info *die, struct objfile *objfile, |
| 3162 | const struct comp_unit_head *cu_header) |
| 3163 | { |
| 3164 | struct die_info *child_die; |
| 3165 | struct attribute *attr; |
| 3166 | struct symbol *sym; |
| 3167 | CORE_ADDR base = (CORE_ADDR) 0; |
| 3168 | |
| 3169 | attr = dwarf_attr (die, DW_AT_location); |
| 3170 | if (attr) |
| 3171 | { |
| 3172 | /* Support the .debug_loc offsets */ |
| 3173 | if (attr_form_is_block (attr)) |
| 3174 | { |
| 3175 | base = decode_locdesc (DW_BLOCK (attr), objfile, cu_header); |
| 3176 | } |
| 3177 | else if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
| 3178 | { |
| 3179 | dwarf2_complex_location_expr_complaint (); |
| 3180 | } |
| 3181 | else |
| 3182 | { |
| 3183 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 3184 | "common block member"); |
| 3185 | } |
| 3186 | } |
| 3187 | if (die->has_children) |
| 3188 | { |
| 3189 | child_die = die->next; |
| 3190 | while (child_die && child_die->tag) |
| 3191 | { |
| 3192 | sym = new_symbol (child_die, NULL, objfile, cu_header); |
| 3193 | attr = dwarf_attr (child_die, DW_AT_data_member_location); |
| 3194 | if (attr) |
| 3195 | { |
| 3196 | SYMBOL_VALUE_ADDRESS (sym) = |
| 3197 | base + decode_locdesc (DW_BLOCK (attr), objfile, cu_header); |
| 3198 | add_symbol_to_list (sym, &global_symbols); |
| 3199 | } |
| 3200 | child_die = sibling_die (child_die); |
| 3201 | } |
| 3202 | } |
| 3203 | } |
| 3204 | |
| 3205 | /* Read a C++ namespace. */ |
| 3206 | |
| 3207 | static void |
| 3208 | read_namespace (struct die_info *die, struct objfile *objfile, |
| 3209 | const struct comp_unit_head *cu_header) |
| 3210 | { |
| 3211 | const char *previous_namespace = processing_current_namespace; |
| 3212 | const char *name = NULL; |
| 3213 | int is_anonymous; |
| 3214 | struct die_info *current_die; |
| 3215 | |
| 3216 | /* Loop through the extensions until we find a name. */ |
| 3217 | |
| 3218 | for (current_die = die; |
| 3219 | current_die != NULL; |
| 3220 | current_die = dwarf2_extension (die)) |
| 3221 | { |
| 3222 | name = dwarf2_name (current_die); |
| 3223 | if (name != NULL) |
| 3224 | break; |
| 3225 | } |
| 3226 | |
| 3227 | /* Is it an anonymous namespace? */ |
| 3228 | |
| 3229 | is_anonymous = (name == NULL); |
| 3230 | if (is_anonymous) |
| 3231 | name = "(anonymous namespace)"; |
| 3232 | |
| 3233 | /* Now build the name of the current namespace. */ |
| 3234 | |
| 3235 | if (previous_namespace[0] == '\0') |
| 3236 | { |
| 3237 | processing_current_namespace = name; |
| 3238 | } |
| 3239 | else |
| 3240 | { |
| 3241 | /* We need temp_name around because processing_current_namespace |
| 3242 | is a const char *. */ |
| 3243 | char *temp_name = alloca (strlen (previous_namespace) |
| 3244 | + 2 + strlen(name) + 1); |
| 3245 | strcpy (temp_name, previous_namespace); |
| 3246 | strcat (temp_name, "::"); |
| 3247 | strcat (temp_name, name); |
| 3248 | |
| 3249 | processing_current_namespace = temp_name; |
| 3250 | } |
| 3251 | |
| 3252 | /* If it's an anonymous namespace that we're seeing for the first |
| 3253 | time, add a using directive. */ |
| 3254 | |
| 3255 | if (is_anonymous && dwarf_attr (die, DW_AT_extension) == NULL) |
| 3256 | cp_add_using_directive (processing_current_namespace, |
| 3257 | strlen (previous_namespace), |
| 3258 | strlen (processing_current_namespace)); |
| 3259 | |
| 3260 | if (die->has_children) |
| 3261 | { |
| 3262 | struct die_info *child_die = die->next; |
| 3263 | |
| 3264 | while (child_die && child_die->tag) |
| 3265 | { |
| 3266 | process_die (child_die, objfile, cu_header); |
| 3267 | child_die = sibling_die (child_die); |
| 3268 | } |
| 3269 | } |
| 3270 | |
| 3271 | processing_current_namespace = previous_namespace; |
| 3272 | } |
| 3273 | |
| 3274 | /* Extract all information from a DW_TAG_pointer_type DIE and add to |
| 3275 | the user defined type vector. */ |
| 3276 | |
| 3277 | static void |
| 3278 | read_tag_pointer_type (struct die_info *die, struct objfile *objfile, |
| 3279 | const struct comp_unit_head *cu_header) |
| 3280 | { |
| 3281 | struct type *type; |
| 3282 | struct attribute *attr_byte_size; |
| 3283 | struct attribute *attr_address_class; |
| 3284 | int byte_size, addr_class; |
| 3285 | |
| 3286 | if (die->type) |
| 3287 | { |
| 3288 | return; |
| 3289 | } |
| 3290 | |
| 3291 | type = lookup_pointer_type (die_type (die, objfile, cu_header)); |
| 3292 | |
| 3293 | attr_byte_size = dwarf_attr (die, DW_AT_byte_size); |
| 3294 | if (attr_byte_size) |
| 3295 | byte_size = DW_UNSND (attr_byte_size); |
| 3296 | else |
| 3297 | byte_size = cu_header->addr_size; |
| 3298 | |
| 3299 | attr_address_class = dwarf_attr (die, DW_AT_address_class); |
| 3300 | if (attr_address_class) |
| 3301 | addr_class = DW_UNSND (attr_address_class); |
| 3302 | else |
| 3303 | addr_class = DW_ADDR_none; |
| 3304 | |
| 3305 | /* If the pointer size or address class is different than the |
| 3306 | default, create a type variant marked as such and set the |
| 3307 | length accordingly. */ |
| 3308 | if (TYPE_LENGTH (type) != byte_size || addr_class != DW_ADDR_none) |
| 3309 | { |
| 3310 | if (ADDRESS_CLASS_TYPE_FLAGS_P ()) |
| 3311 | { |
| 3312 | int type_flags; |
| 3313 | |
| 3314 | type_flags = ADDRESS_CLASS_TYPE_FLAGS (byte_size, addr_class); |
| 3315 | gdb_assert ((type_flags & ~TYPE_FLAG_ADDRESS_CLASS_ALL) == 0); |
| 3316 | type = make_type_with_address_space (type, type_flags); |
| 3317 | } |
| 3318 | else if (TYPE_LENGTH (type) != byte_size) |
| 3319 | { |
| 3320 | complaint (&symfile_complaints, "invalid pointer size %d", byte_size); |
| 3321 | } |
| 3322 | else { |
| 3323 | /* Should we also complain about unhandled address classes? */ |
| 3324 | } |
| 3325 | } |
| 3326 | |
| 3327 | TYPE_LENGTH (type) = byte_size; |
| 3328 | die->type = type; |
| 3329 | } |
| 3330 | |
| 3331 | /* Extract all information from a DW_TAG_ptr_to_member_type DIE and add to |
| 3332 | the user defined type vector. */ |
| 3333 | |
| 3334 | static void |
| 3335 | read_tag_ptr_to_member_type (struct die_info *die, struct objfile *objfile, |
| 3336 | const struct comp_unit_head *cu_header) |
| 3337 | { |
| 3338 | struct type *type; |
| 3339 | struct type *to_type; |
| 3340 | struct type *domain; |
| 3341 | |
| 3342 | if (die->type) |
| 3343 | { |
| 3344 | return; |
| 3345 | } |
| 3346 | |
| 3347 | type = alloc_type (objfile); |
| 3348 | to_type = die_type (die, objfile, cu_header); |
| 3349 | domain = die_containing_type (die, objfile, cu_header); |
| 3350 | smash_to_member_type (type, domain, to_type); |
| 3351 | |
| 3352 | die->type = type; |
| 3353 | } |
| 3354 | |
| 3355 | /* Extract all information from a DW_TAG_reference_type DIE and add to |
| 3356 | the user defined type vector. */ |
| 3357 | |
| 3358 | static void |
| 3359 | read_tag_reference_type (struct die_info *die, struct objfile *objfile, |
| 3360 | const struct comp_unit_head *cu_header) |
| 3361 | { |
| 3362 | struct type *type; |
| 3363 | struct attribute *attr; |
| 3364 | |
| 3365 | if (die->type) |
| 3366 | { |
| 3367 | return; |
| 3368 | } |
| 3369 | |
| 3370 | type = lookup_reference_type (die_type (die, objfile, cu_header)); |
| 3371 | attr = dwarf_attr (die, DW_AT_byte_size); |
| 3372 | if (attr) |
| 3373 | { |
| 3374 | TYPE_LENGTH (type) = DW_UNSND (attr); |
| 3375 | } |
| 3376 | else |
| 3377 | { |
| 3378 | TYPE_LENGTH (type) = cu_header->addr_size; |
| 3379 | } |
| 3380 | die->type = type; |
| 3381 | } |
| 3382 | |
| 3383 | static void |
| 3384 | read_tag_const_type (struct die_info *die, struct objfile *objfile, |
| 3385 | const struct comp_unit_head *cu_header) |
| 3386 | { |
| 3387 | struct type *base_type; |
| 3388 | |
| 3389 | if (die->type) |
| 3390 | { |
| 3391 | return; |
| 3392 | } |
| 3393 | |
| 3394 | base_type = die_type (die, objfile, cu_header); |
| 3395 | die->type = make_cv_type (1, TYPE_VOLATILE (base_type), base_type, 0); |
| 3396 | } |
| 3397 | |
| 3398 | static void |
| 3399 | read_tag_volatile_type (struct die_info *die, struct objfile *objfile, |
| 3400 | const struct comp_unit_head *cu_header) |
| 3401 | { |
| 3402 | struct type *base_type; |
| 3403 | |
| 3404 | if (die->type) |
| 3405 | { |
| 3406 | return; |
| 3407 | } |
| 3408 | |
| 3409 | base_type = die_type (die, objfile, cu_header); |
| 3410 | die->type = make_cv_type (TYPE_CONST (base_type), 1, base_type, 0); |
| 3411 | } |
| 3412 | |
| 3413 | /* Extract all information from a DW_TAG_string_type DIE and add to |
| 3414 | the user defined type vector. It isn't really a user defined type, |
| 3415 | but it behaves like one, with other DIE's using an AT_user_def_type |
| 3416 | attribute to reference it. */ |
| 3417 | |
| 3418 | static void |
| 3419 | read_tag_string_type (struct die_info *die, struct objfile *objfile) |
| 3420 | { |
| 3421 | struct type *type, *range_type, *index_type, *char_type; |
| 3422 | struct attribute *attr; |
| 3423 | unsigned int length; |
| 3424 | |
| 3425 | if (die->type) |
| 3426 | { |
| 3427 | return; |
| 3428 | } |
| 3429 | |
| 3430 | attr = dwarf_attr (die, DW_AT_string_length); |
| 3431 | if (attr) |
| 3432 | { |
| 3433 | length = DW_UNSND (attr); |
| 3434 | } |
| 3435 | else |
| 3436 | { |
| 3437 | /* check for the DW_AT_byte_size attribute */ |
| 3438 | attr = dwarf_attr (die, DW_AT_byte_size); |
| 3439 | if (attr) |
| 3440 | { |
| 3441 | length = DW_UNSND (attr); |
| 3442 | } |
| 3443 | else |
| 3444 | { |
| 3445 | length = 1; |
| 3446 | } |
| 3447 | } |
| 3448 | index_type = dwarf2_fundamental_type (objfile, FT_INTEGER); |
| 3449 | range_type = create_range_type (NULL, index_type, 1, length); |
| 3450 | if (cu_language == language_fortran) |
| 3451 | { |
| 3452 | /* Need to create a unique string type for bounds |
| 3453 | information */ |
| 3454 | type = create_string_type (0, range_type); |
| 3455 | } |
| 3456 | else |
| 3457 | { |
| 3458 | char_type = dwarf2_fundamental_type (objfile, FT_CHAR); |
| 3459 | type = create_string_type (char_type, range_type); |
| 3460 | } |
| 3461 | die->type = type; |
| 3462 | } |
| 3463 | |
| 3464 | /* Handle DIES due to C code like: |
| 3465 | |
| 3466 | struct foo |
| 3467 | { |
| 3468 | int (*funcp)(int a, long l); |
| 3469 | int b; |
| 3470 | }; |
| 3471 | |
| 3472 | ('funcp' generates a DW_TAG_subroutine_type DIE) |
| 3473 | */ |
| 3474 | |
| 3475 | static void |
| 3476 | read_subroutine_type (struct die_info *die, struct objfile *objfile, |
| 3477 | const struct comp_unit_head *cu_header) |
| 3478 | { |
| 3479 | struct type *type; /* Type that this function returns */ |
| 3480 | struct type *ftype; /* Function that returns above type */ |
| 3481 | struct attribute *attr; |
| 3482 | |
| 3483 | /* Decode the type that this subroutine returns */ |
| 3484 | if (die->type) |
| 3485 | { |
| 3486 | return; |
| 3487 | } |
| 3488 | type = die_type (die, objfile, cu_header); |
| 3489 | ftype = lookup_function_type (type); |
| 3490 | |
| 3491 | /* All functions in C++ have prototypes. */ |
| 3492 | attr = dwarf_attr (die, DW_AT_prototyped); |
| 3493 | if ((attr && (DW_UNSND (attr) != 0)) |
| 3494 | || cu_language == language_cplus) |
| 3495 | TYPE_FLAGS (ftype) |= TYPE_FLAG_PROTOTYPED; |
| 3496 | |
| 3497 | if (die->has_children) |
| 3498 | { |
| 3499 | struct die_info *child_die; |
| 3500 | int nparams = 0; |
| 3501 | int iparams = 0; |
| 3502 | |
| 3503 | /* Count the number of parameters. |
| 3504 | FIXME: GDB currently ignores vararg functions, but knows about |
| 3505 | vararg member functions. */ |
| 3506 | child_die = die->next; |
| 3507 | while (child_die && child_die->tag) |
| 3508 | { |
| 3509 | if (child_die->tag == DW_TAG_formal_parameter) |
| 3510 | nparams++; |
| 3511 | else if (child_die->tag == DW_TAG_unspecified_parameters) |
| 3512 | TYPE_FLAGS (ftype) |= TYPE_FLAG_VARARGS; |
| 3513 | child_die = sibling_die (child_die); |
| 3514 | } |
| 3515 | |
| 3516 | /* Allocate storage for parameters and fill them in. */ |
| 3517 | TYPE_NFIELDS (ftype) = nparams; |
| 3518 | TYPE_FIELDS (ftype) = (struct field *) |
| 3519 | TYPE_ALLOC (ftype, nparams * sizeof (struct field)); |
| 3520 | |
| 3521 | child_die = die->next; |
| 3522 | while (child_die && child_die->tag) |
| 3523 | { |
| 3524 | if (child_die->tag == DW_TAG_formal_parameter) |
| 3525 | { |
| 3526 | /* Dwarf2 has no clean way to discern C++ static and non-static |
| 3527 | member functions. G++ helps GDB by marking the first |
| 3528 | parameter for non-static member functions (which is the |
| 3529 | this pointer) as artificial. We pass this information |
| 3530 | to dwarf2_add_member_fn via TYPE_FIELD_ARTIFICIAL. */ |
| 3531 | attr = dwarf_attr (child_die, DW_AT_artificial); |
| 3532 | if (attr) |
| 3533 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = DW_UNSND (attr); |
| 3534 | else |
| 3535 | TYPE_FIELD_ARTIFICIAL (ftype, iparams) = 0; |
| 3536 | TYPE_FIELD_TYPE (ftype, iparams) = die_type (child_die, objfile, |
| 3537 | cu_header); |
| 3538 | iparams++; |
| 3539 | } |
| 3540 | child_die = sibling_die (child_die); |
| 3541 | } |
| 3542 | } |
| 3543 | |
| 3544 | die->type = ftype; |
| 3545 | } |
| 3546 | |
| 3547 | static void |
| 3548 | read_typedef (struct die_info *die, struct objfile *objfile, |
| 3549 | const struct comp_unit_head *cu_header) |
| 3550 | { |
| 3551 | struct attribute *attr; |
| 3552 | char *name = NULL; |
| 3553 | |
| 3554 | if (!die->type) |
| 3555 | { |
| 3556 | attr = dwarf_attr (die, DW_AT_name); |
| 3557 | if (attr && DW_STRING (attr)) |
| 3558 | { |
| 3559 | name = DW_STRING (attr); |
| 3560 | } |
| 3561 | die->type = init_type (TYPE_CODE_TYPEDEF, 0, TYPE_FLAG_TARGET_STUB, name, objfile); |
| 3562 | TYPE_TARGET_TYPE (die->type) = die_type (die, objfile, cu_header); |
| 3563 | } |
| 3564 | } |
| 3565 | |
| 3566 | /* Find a representation of a given base type and install |
| 3567 | it in the TYPE field of the die. */ |
| 3568 | |
| 3569 | static void |
| 3570 | read_base_type (struct die_info *die, struct objfile *objfile) |
| 3571 | { |
| 3572 | struct type *type; |
| 3573 | struct attribute *attr; |
| 3574 | int encoding = 0, size = 0; |
| 3575 | |
| 3576 | /* If we've already decoded this die, this is a no-op. */ |
| 3577 | if (die->type) |
| 3578 | { |
| 3579 | return; |
| 3580 | } |
| 3581 | |
| 3582 | attr = dwarf_attr (die, DW_AT_encoding); |
| 3583 | if (attr) |
| 3584 | { |
| 3585 | encoding = DW_UNSND (attr); |
| 3586 | } |
| 3587 | attr = dwarf_attr (die, DW_AT_byte_size); |
| 3588 | if (attr) |
| 3589 | { |
| 3590 | size = DW_UNSND (attr); |
| 3591 | } |
| 3592 | attr = dwarf_attr (die, DW_AT_name); |
| 3593 | if (attr && DW_STRING (attr)) |
| 3594 | { |
| 3595 | enum type_code code = TYPE_CODE_INT; |
| 3596 | int type_flags = 0; |
| 3597 | |
| 3598 | switch (encoding) |
| 3599 | { |
| 3600 | case DW_ATE_address: |
| 3601 | /* Turn DW_ATE_address into a void * pointer. */ |
| 3602 | code = TYPE_CODE_PTR; |
| 3603 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 3604 | break; |
| 3605 | case DW_ATE_boolean: |
| 3606 | code = TYPE_CODE_BOOL; |
| 3607 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 3608 | break; |
| 3609 | case DW_ATE_complex_float: |
| 3610 | code = TYPE_CODE_COMPLEX; |
| 3611 | break; |
| 3612 | case DW_ATE_float: |
| 3613 | code = TYPE_CODE_FLT; |
| 3614 | break; |
| 3615 | case DW_ATE_signed: |
| 3616 | case DW_ATE_signed_char: |
| 3617 | break; |
| 3618 | case DW_ATE_unsigned: |
| 3619 | case DW_ATE_unsigned_char: |
| 3620 | type_flags |= TYPE_FLAG_UNSIGNED; |
| 3621 | break; |
| 3622 | default: |
| 3623 | complaint (&symfile_complaints, "unsupported DW_AT_encoding: '%s'", |
| 3624 | dwarf_type_encoding_name (encoding)); |
| 3625 | break; |
| 3626 | } |
| 3627 | type = init_type (code, size, type_flags, DW_STRING (attr), objfile); |
| 3628 | if (encoding == DW_ATE_address) |
| 3629 | TYPE_TARGET_TYPE (type) = dwarf2_fundamental_type (objfile, FT_VOID); |
| 3630 | else if (encoding == DW_ATE_complex_float) |
| 3631 | { |
| 3632 | if (size == 32) |
| 3633 | TYPE_TARGET_TYPE (type) |
| 3634 | = dwarf2_fundamental_type (objfile, FT_EXT_PREC_FLOAT); |
| 3635 | else if (size == 16) |
| 3636 | TYPE_TARGET_TYPE (type) |
| 3637 | = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT); |
| 3638 | else if (size == 8) |
| 3639 | TYPE_TARGET_TYPE (type) |
| 3640 | = dwarf2_fundamental_type (objfile, FT_FLOAT); |
| 3641 | } |
| 3642 | } |
| 3643 | else |
| 3644 | { |
| 3645 | type = dwarf_base_type (encoding, size, objfile); |
| 3646 | } |
| 3647 | die->type = type; |
| 3648 | } |
| 3649 | |
| 3650 | /* Read a whole compilation unit into a linked list of dies. */ |
| 3651 | |
| 3652 | static struct die_info * |
| 3653 | read_comp_unit (char *info_ptr, bfd *abfd, |
| 3654 | const struct comp_unit_head *cu_header) |
| 3655 | { |
| 3656 | struct die_info *first_die, *last_die, *die; |
| 3657 | char *cur_ptr; |
| 3658 | int nesting_level; |
| 3659 | |
| 3660 | /* Reset die reference table; we are |
| 3661 | building new ones now. */ |
| 3662 | dwarf2_empty_hash_tables (); |
| 3663 | |
| 3664 | cur_ptr = info_ptr; |
| 3665 | nesting_level = 0; |
| 3666 | first_die = last_die = NULL; |
| 3667 | do |
| 3668 | { |
| 3669 | cur_ptr = read_full_die (&die, abfd, cur_ptr, cu_header); |
| 3670 | if (die->has_children) |
| 3671 | { |
| 3672 | nesting_level++; |
| 3673 | } |
| 3674 | if (die->tag == 0) |
| 3675 | { |
| 3676 | nesting_level--; |
| 3677 | } |
| 3678 | |
| 3679 | die->next = NULL; |
| 3680 | |
| 3681 | /* Enter die in reference hash table */ |
| 3682 | store_in_ref_table (die->offset, die); |
| 3683 | |
| 3684 | if (!first_die) |
| 3685 | { |
| 3686 | first_die = last_die = die; |
| 3687 | } |
| 3688 | else |
| 3689 | { |
| 3690 | last_die->next = die; |
| 3691 | last_die = die; |
| 3692 | } |
| 3693 | } |
| 3694 | while (nesting_level > 0); |
| 3695 | return first_die; |
| 3696 | } |
| 3697 | |
| 3698 | /* Free a linked list of dies. */ |
| 3699 | |
| 3700 | static void |
| 3701 | free_die_list (struct die_info *dies) |
| 3702 | { |
| 3703 | struct die_info *die, *next; |
| 3704 | |
| 3705 | die = dies; |
| 3706 | while (die) |
| 3707 | { |
| 3708 | next = die->next; |
| 3709 | xfree (die->attrs); |
| 3710 | xfree (die); |
| 3711 | die = next; |
| 3712 | } |
| 3713 | } |
| 3714 | |
| 3715 | static void |
| 3716 | do_free_die_list_cleanup (void *dies) |
| 3717 | { |
| 3718 | free_die_list (dies); |
| 3719 | } |
| 3720 | |
| 3721 | static struct cleanup * |
| 3722 | make_cleanup_free_die_list (struct die_info *dies) |
| 3723 | { |
| 3724 | return make_cleanup (do_free_die_list_cleanup, dies); |
| 3725 | } |
| 3726 | |
| 3727 | |
| 3728 | /* Read the contents of the section at OFFSET and of size SIZE from the |
| 3729 | object file specified by OBJFILE into the psymbol_obstack and return it. */ |
| 3730 | |
| 3731 | char * |
| 3732 | dwarf2_read_section (struct objfile *objfile, file_ptr offset, |
| 3733 | unsigned int size, asection *sectp) |
| 3734 | { |
| 3735 | bfd *abfd = objfile->obfd; |
| 3736 | char *buf, *retbuf; |
| 3737 | |
| 3738 | if (size == 0) |
| 3739 | return NULL; |
| 3740 | |
| 3741 | buf = (char *) obstack_alloc (&objfile->psymbol_obstack, size); |
| 3742 | retbuf |
| 3743 | = (char *) symfile_relocate_debug_section (abfd, sectp, (bfd_byte *) buf); |
| 3744 | if (retbuf != NULL) |
| 3745 | return retbuf; |
| 3746 | |
| 3747 | if ((bfd_seek (abfd, offset, SEEK_SET) != 0) || |
| 3748 | (bfd_bread (buf, size, abfd) != size)) |
| 3749 | { |
| 3750 | buf = NULL; |
| 3751 | error ("Dwarf Error: Can't read DWARF data from '%s'", |
| 3752 | bfd_get_filename (abfd)); |
| 3753 | } |
| 3754 | return buf; |
| 3755 | } |
| 3756 | |
| 3757 | /* In DWARF version 2, the description of the debugging information is |
| 3758 | stored in a separate .debug_abbrev section. Before we read any |
| 3759 | dies from a section we read in all abbreviations and install them |
| 3760 | in a hash table. */ |
| 3761 | |
| 3762 | static void |
| 3763 | dwarf2_read_abbrevs (bfd *abfd, struct comp_unit_head *cu_header) |
| 3764 | { |
| 3765 | char *abbrev_ptr; |
| 3766 | struct abbrev_info *cur_abbrev; |
| 3767 | unsigned int abbrev_number, bytes_read, abbrev_name; |
| 3768 | unsigned int abbrev_form, hash_number; |
| 3769 | |
| 3770 | /* Initialize dwarf2 abbrevs */ |
| 3771 | memset (cu_header->dwarf2_abbrevs, 0, |
| 3772 | ABBREV_HASH_SIZE*sizeof (struct abbrev_info *)); |
| 3773 | |
| 3774 | abbrev_ptr = dwarf_abbrev_buffer + cu_header->abbrev_offset; |
| 3775 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3776 | abbrev_ptr += bytes_read; |
| 3777 | |
| 3778 | /* loop until we reach an abbrev number of 0 */ |
| 3779 | while (abbrev_number) |
| 3780 | { |
| 3781 | cur_abbrev = dwarf_alloc_abbrev (); |
| 3782 | |
| 3783 | /* read in abbrev header */ |
| 3784 | cur_abbrev->number = abbrev_number; |
| 3785 | cur_abbrev->tag = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3786 | abbrev_ptr += bytes_read; |
| 3787 | cur_abbrev->has_children = read_1_byte (abfd, abbrev_ptr); |
| 3788 | abbrev_ptr += 1; |
| 3789 | |
| 3790 | /* now read in declarations */ |
| 3791 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3792 | abbrev_ptr += bytes_read; |
| 3793 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3794 | abbrev_ptr += bytes_read; |
| 3795 | while (abbrev_name) |
| 3796 | { |
| 3797 | if ((cur_abbrev->num_attrs % ATTR_ALLOC_CHUNK) == 0) |
| 3798 | { |
| 3799 | cur_abbrev->attrs = (struct attr_abbrev *) |
| 3800 | xrealloc (cur_abbrev->attrs, |
| 3801 | (cur_abbrev->num_attrs + ATTR_ALLOC_CHUNK) |
| 3802 | * sizeof (struct attr_abbrev)); |
| 3803 | } |
| 3804 | cur_abbrev->attrs[cur_abbrev->num_attrs].name = abbrev_name; |
| 3805 | cur_abbrev->attrs[cur_abbrev->num_attrs++].form = abbrev_form; |
| 3806 | abbrev_name = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3807 | abbrev_ptr += bytes_read; |
| 3808 | abbrev_form = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3809 | abbrev_ptr += bytes_read; |
| 3810 | } |
| 3811 | |
| 3812 | hash_number = abbrev_number % ABBREV_HASH_SIZE; |
| 3813 | cur_abbrev->next = cu_header->dwarf2_abbrevs[hash_number]; |
| 3814 | cu_header->dwarf2_abbrevs[hash_number] = cur_abbrev; |
| 3815 | |
| 3816 | /* Get next abbreviation. |
| 3817 | Under Irix6 the abbreviations for a compilation unit are not |
| 3818 | always properly terminated with an abbrev number of 0. |
| 3819 | Exit loop if we encounter an abbreviation which we have |
| 3820 | already read (which means we are about to read the abbreviations |
| 3821 | for the next compile unit) or if the end of the abbreviation |
| 3822 | table is reached. */ |
| 3823 | if ((unsigned int) (abbrev_ptr - dwarf_abbrev_buffer) |
| 3824 | >= dwarf_abbrev_size) |
| 3825 | break; |
| 3826 | abbrev_number = read_unsigned_leb128 (abfd, abbrev_ptr, &bytes_read); |
| 3827 | abbrev_ptr += bytes_read; |
| 3828 | if (dwarf2_lookup_abbrev (abbrev_number, cu_header) != NULL) |
| 3829 | break; |
| 3830 | } |
| 3831 | } |
| 3832 | |
| 3833 | /* Empty the abbrev table for a new compilation unit. */ |
| 3834 | |
| 3835 | /* ARGSUSED */ |
| 3836 | static void |
| 3837 | dwarf2_empty_abbrev_table (void *ptr_to_abbrevs_table) |
| 3838 | { |
| 3839 | int i; |
| 3840 | struct abbrev_info *abbrev, *next; |
| 3841 | struct abbrev_info **abbrevs; |
| 3842 | |
| 3843 | abbrevs = (struct abbrev_info **)ptr_to_abbrevs_table; |
| 3844 | |
| 3845 | for (i = 0; i < ABBREV_HASH_SIZE; ++i) |
| 3846 | { |
| 3847 | next = NULL; |
| 3848 | abbrev = abbrevs[i]; |
| 3849 | while (abbrev) |
| 3850 | { |
| 3851 | next = abbrev->next; |
| 3852 | xfree (abbrev->attrs); |
| 3853 | xfree (abbrev); |
| 3854 | abbrev = next; |
| 3855 | } |
| 3856 | abbrevs[i] = NULL; |
| 3857 | } |
| 3858 | } |
| 3859 | |
| 3860 | /* Lookup an abbrev_info structure in the abbrev hash table. */ |
| 3861 | |
| 3862 | static struct abbrev_info * |
| 3863 | dwarf2_lookup_abbrev (unsigned int number, const struct comp_unit_head *cu_header) |
| 3864 | { |
| 3865 | unsigned int hash_number; |
| 3866 | struct abbrev_info *abbrev; |
| 3867 | |
| 3868 | hash_number = number % ABBREV_HASH_SIZE; |
| 3869 | abbrev = cu_header->dwarf2_abbrevs[hash_number]; |
| 3870 | |
| 3871 | while (abbrev) |
| 3872 | { |
| 3873 | if (abbrev->number == number) |
| 3874 | return abbrev; |
| 3875 | else |
| 3876 | abbrev = abbrev->next; |
| 3877 | } |
| 3878 | return NULL; |
| 3879 | } |
| 3880 | |
| 3881 | /* Read a minimal amount of information into the minimal die structure. */ |
| 3882 | |
| 3883 | static char * |
| 3884 | read_partial_die (struct partial_die_info *part_die, bfd *abfd, |
| 3885 | char *info_ptr, const struct comp_unit_head *cu_header) |
| 3886 | { |
| 3887 | unsigned int abbrev_number, bytes_read, i; |
| 3888 | struct abbrev_info *abbrev; |
| 3889 | struct attribute attr; |
| 3890 | struct attribute spec_attr; |
| 3891 | int found_spec_attr = 0; |
| 3892 | int has_low_pc_attr = 0; |
| 3893 | int has_high_pc_attr = 0; |
| 3894 | |
| 3895 | *part_die = zeroed_partial_die; |
| 3896 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 3897 | info_ptr += bytes_read; |
| 3898 | if (!abbrev_number) |
| 3899 | return info_ptr; |
| 3900 | |
| 3901 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu_header); |
| 3902 | if (!abbrev) |
| 3903 | { |
| 3904 | error ("Dwarf Error: Could not find abbrev number %d [in module %s]", abbrev_number, |
| 3905 | bfd_get_filename (abfd)); |
| 3906 | } |
| 3907 | part_die->offset = info_ptr - dwarf_info_buffer; |
| 3908 | part_die->tag = abbrev->tag; |
| 3909 | part_die->has_children = abbrev->has_children; |
| 3910 | part_die->abbrev = abbrev_number; |
| 3911 | |
| 3912 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 3913 | { |
| 3914 | info_ptr = read_attribute (&attr, &abbrev->attrs[i], abfd, |
| 3915 | info_ptr, cu_header); |
| 3916 | |
| 3917 | /* Store the data if it is of an attribute we want to keep in a |
| 3918 | partial symbol table. */ |
| 3919 | switch (attr.name) |
| 3920 | { |
| 3921 | case DW_AT_name: |
| 3922 | |
| 3923 | /* Prefer DW_AT_MIPS_linkage_name over DW_AT_name. */ |
| 3924 | if (part_die->name == NULL) |
| 3925 | part_die->name = DW_STRING (&attr); |
| 3926 | break; |
| 3927 | case DW_AT_MIPS_linkage_name: |
| 3928 | part_die->name = DW_STRING (&attr); |
| 3929 | break; |
| 3930 | case DW_AT_low_pc: |
| 3931 | has_low_pc_attr = 1; |
| 3932 | part_die->lowpc = DW_ADDR (&attr); |
| 3933 | break; |
| 3934 | case DW_AT_high_pc: |
| 3935 | has_high_pc_attr = 1; |
| 3936 | part_die->highpc = DW_ADDR (&attr); |
| 3937 | break; |
| 3938 | case DW_AT_location: |
| 3939 | /* Support the .debug_loc offsets */ |
| 3940 | if (attr_form_is_block (&attr)) |
| 3941 | { |
| 3942 | part_die->locdesc = DW_BLOCK (&attr); |
| 3943 | } |
| 3944 | else if (attr.form == DW_FORM_data4 || attr.form == DW_FORM_data8) |
| 3945 | { |
| 3946 | dwarf2_complex_location_expr_complaint (); |
| 3947 | } |
| 3948 | else |
| 3949 | { |
| 3950 | dwarf2_invalid_attrib_class_complaint ("DW_AT_location", |
| 3951 | "partial symbol information"); |
| 3952 | } |
| 3953 | break; |
| 3954 | case DW_AT_language: |
| 3955 | part_die->language = DW_UNSND (&attr); |
| 3956 | break; |
| 3957 | case DW_AT_external: |
| 3958 | part_die->is_external = DW_UNSND (&attr); |
| 3959 | break; |
| 3960 | case DW_AT_declaration: |
| 3961 | part_die->is_declaration = DW_UNSND (&attr); |
| 3962 | break; |
| 3963 | case DW_AT_type: |
| 3964 | part_die->has_type = 1; |
| 3965 | break; |
| 3966 | case DW_AT_abstract_origin: |
| 3967 | case DW_AT_specification: |
| 3968 | found_spec_attr = 1; |
| 3969 | spec_attr = attr; |
| 3970 | break; |
| 3971 | case DW_AT_sibling: |
| 3972 | /* Ignore absolute siblings, they might point outside of |
| 3973 | the current compile unit. */ |
| 3974 | if (attr.form == DW_FORM_ref_addr) |
| 3975 | complaint (&symfile_complaints, "ignoring absolute DW_AT_sibling"); |
| 3976 | else |
| 3977 | part_die->sibling = |
| 3978 | dwarf_info_buffer + dwarf2_get_ref_die_offset (&attr); |
| 3979 | break; |
| 3980 | default: |
| 3981 | break; |
| 3982 | } |
| 3983 | } |
| 3984 | |
| 3985 | /* If we found a reference attribute and the die has no name, try |
| 3986 | to find a name in the referred to die. */ |
| 3987 | |
| 3988 | if (found_spec_attr && part_die->name == NULL) |
| 3989 | { |
| 3990 | struct partial_die_info spec_die; |
| 3991 | char *spec_ptr; |
| 3992 | int dummy; |
| 3993 | |
| 3994 | spec_ptr = dwarf_info_buffer + dwarf2_get_ref_die_offset (&spec_attr); |
| 3995 | read_partial_die (&spec_die, abfd, spec_ptr, cu_header); |
| 3996 | if (spec_die.name) |
| 3997 | { |
| 3998 | part_die->name = spec_die.name; |
| 3999 | |
| 4000 | /* Copy DW_AT_external attribute if it is set. */ |
| 4001 | if (spec_die.is_external) |
| 4002 | part_die->is_external = spec_die.is_external; |
| 4003 | } |
| 4004 | } |
| 4005 | |
| 4006 | /* When using the GNU linker, .gnu.linkonce. sections are used to |
| 4007 | eliminate duplicate copies of functions and vtables and such. |
| 4008 | The linker will arbitrarily choose one and discard the others. |
| 4009 | The AT_*_pc values for such functions refer to local labels in |
| 4010 | these sections. If the section from that file was discarded, the |
| 4011 | labels are not in the output, so the relocs get a value of 0. |
| 4012 | If this is a discarded function, mark the pc bounds as invalid, |
| 4013 | so that GDB will ignore it. */ |
| 4014 | if (has_low_pc_attr && has_high_pc_attr |
| 4015 | && part_die->lowpc < part_die->highpc |
| 4016 | && (part_die->lowpc != 0 |
| 4017 | || (bfd_get_file_flags (abfd) & HAS_RELOC))) |
| 4018 | part_die->has_pc_info = 1; |
| 4019 | return info_ptr; |
| 4020 | } |
| 4021 | |
| 4022 | /* Read the die from the .debug_info section buffer. And set diep to |
| 4023 | point to a newly allocated die with its information. */ |
| 4024 | |
| 4025 | static char * |
| 4026 | read_full_die (struct die_info **diep, bfd *abfd, char *info_ptr, |
| 4027 | const struct comp_unit_head *cu_header) |
| 4028 | { |
| 4029 | unsigned int abbrev_number, bytes_read, i, offset; |
| 4030 | struct abbrev_info *abbrev; |
| 4031 | struct die_info *die; |
| 4032 | |
| 4033 | offset = info_ptr - dwarf_info_buffer; |
| 4034 | abbrev_number = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4035 | info_ptr += bytes_read; |
| 4036 | if (!abbrev_number) |
| 4037 | { |
| 4038 | die = dwarf_alloc_die (); |
| 4039 | die->tag = 0; |
| 4040 | die->abbrev = abbrev_number; |
| 4041 | die->type = NULL; |
| 4042 | *diep = die; |
| 4043 | return info_ptr; |
| 4044 | } |
| 4045 | |
| 4046 | abbrev = dwarf2_lookup_abbrev (abbrev_number, cu_header); |
| 4047 | if (!abbrev) |
| 4048 | { |
| 4049 | error ("Dwarf Error: could not find abbrev number %d [in module %s]", abbrev_number, |
| 4050 | bfd_get_filename (abfd)); |
| 4051 | } |
| 4052 | die = dwarf_alloc_die (); |
| 4053 | die->offset = offset; |
| 4054 | die->tag = abbrev->tag; |
| 4055 | die->has_children = abbrev->has_children; |
| 4056 | die->abbrev = abbrev_number; |
| 4057 | die->type = NULL; |
| 4058 | |
| 4059 | die->num_attrs = abbrev->num_attrs; |
| 4060 | die->attrs = (struct attribute *) |
| 4061 | xmalloc (die->num_attrs * sizeof (struct attribute)); |
| 4062 | |
| 4063 | for (i = 0; i < abbrev->num_attrs; ++i) |
| 4064 | { |
| 4065 | info_ptr = read_attribute (&die->attrs[i], &abbrev->attrs[i], |
| 4066 | abfd, info_ptr, cu_header); |
| 4067 | } |
| 4068 | |
| 4069 | *diep = die; |
| 4070 | return info_ptr; |
| 4071 | } |
| 4072 | |
| 4073 | /* Read an attribute value described by an attribute form. */ |
| 4074 | |
| 4075 | static char * |
| 4076 | read_attribute_value (struct attribute *attr, unsigned form, |
| 4077 | bfd *abfd, char *info_ptr, |
| 4078 | const struct comp_unit_head *cu_header) |
| 4079 | { |
| 4080 | unsigned int bytes_read; |
| 4081 | struct dwarf_block *blk; |
| 4082 | |
| 4083 | attr->form = form; |
| 4084 | switch (form) |
| 4085 | { |
| 4086 | case DW_FORM_addr: |
| 4087 | case DW_FORM_ref_addr: |
| 4088 | DW_ADDR (attr) = read_address (abfd, info_ptr, cu_header, &bytes_read); |
| 4089 | info_ptr += bytes_read; |
| 4090 | break; |
| 4091 | case DW_FORM_block2: |
| 4092 | blk = dwarf_alloc_block (); |
| 4093 | blk->size = read_2_bytes (abfd, info_ptr); |
| 4094 | info_ptr += 2; |
| 4095 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 4096 | info_ptr += blk->size; |
| 4097 | DW_BLOCK (attr) = blk; |
| 4098 | break; |
| 4099 | case DW_FORM_block4: |
| 4100 | blk = dwarf_alloc_block (); |
| 4101 | blk->size = read_4_bytes (abfd, info_ptr); |
| 4102 | info_ptr += 4; |
| 4103 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 4104 | info_ptr += blk->size; |
| 4105 | DW_BLOCK (attr) = blk; |
| 4106 | break; |
| 4107 | case DW_FORM_data2: |
| 4108 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); |
| 4109 | info_ptr += 2; |
| 4110 | break; |
| 4111 | case DW_FORM_data4: |
| 4112 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); |
| 4113 | info_ptr += 4; |
| 4114 | break; |
| 4115 | case DW_FORM_data8: |
| 4116 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); |
| 4117 | info_ptr += 8; |
| 4118 | break; |
| 4119 | case DW_FORM_string: |
| 4120 | DW_STRING (attr) = read_string (abfd, info_ptr, &bytes_read); |
| 4121 | info_ptr += bytes_read; |
| 4122 | break; |
| 4123 | case DW_FORM_strp: |
| 4124 | DW_STRING (attr) = read_indirect_string (abfd, info_ptr, cu_header, |
| 4125 | &bytes_read); |
| 4126 | info_ptr += bytes_read; |
| 4127 | break; |
| 4128 | case DW_FORM_block: |
| 4129 | blk = dwarf_alloc_block (); |
| 4130 | blk->size = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4131 | info_ptr += bytes_read; |
| 4132 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 4133 | info_ptr += blk->size; |
| 4134 | DW_BLOCK (attr) = blk; |
| 4135 | break; |
| 4136 | case DW_FORM_block1: |
| 4137 | blk = dwarf_alloc_block (); |
| 4138 | blk->size = read_1_byte (abfd, info_ptr); |
| 4139 | info_ptr += 1; |
| 4140 | blk->data = read_n_bytes (abfd, info_ptr, blk->size); |
| 4141 | info_ptr += blk->size; |
| 4142 | DW_BLOCK (attr) = blk; |
| 4143 | break; |
| 4144 | case DW_FORM_data1: |
| 4145 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 4146 | info_ptr += 1; |
| 4147 | break; |
| 4148 | case DW_FORM_flag: |
| 4149 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 4150 | info_ptr += 1; |
| 4151 | break; |
| 4152 | case DW_FORM_sdata: |
| 4153 | DW_SND (attr) = read_signed_leb128 (abfd, info_ptr, &bytes_read); |
| 4154 | info_ptr += bytes_read; |
| 4155 | break; |
| 4156 | case DW_FORM_udata: |
| 4157 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4158 | info_ptr += bytes_read; |
| 4159 | break; |
| 4160 | case DW_FORM_ref1: |
| 4161 | DW_UNSND (attr) = read_1_byte (abfd, info_ptr); |
| 4162 | info_ptr += 1; |
| 4163 | break; |
| 4164 | case DW_FORM_ref2: |
| 4165 | DW_UNSND (attr) = read_2_bytes (abfd, info_ptr); |
| 4166 | info_ptr += 2; |
| 4167 | break; |
| 4168 | case DW_FORM_ref4: |
| 4169 | DW_UNSND (attr) = read_4_bytes (abfd, info_ptr); |
| 4170 | info_ptr += 4; |
| 4171 | break; |
| 4172 | case DW_FORM_ref8: |
| 4173 | DW_UNSND (attr) = read_8_bytes (abfd, info_ptr); |
| 4174 | info_ptr += 8; |
| 4175 | break; |
| 4176 | case DW_FORM_ref_udata: |
| 4177 | DW_UNSND (attr) = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4178 | info_ptr += bytes_read; |
| 4179 | break; |
| 4180 | case DW_FORM_indirect: |
| 4181 | form = read_unsigned_leb128 (abfd, info_ptr, &bytes_read); |
| 4182 | info_ptr += bytes_read; |
| 4183 | info_ptr = read_attribute_value (attr, form, abfd, info_ptr, cu_header); |
| 4184 | break; |
| 4185 | default: |
| 4186 | error ("Dwarf Error: Cannot handle %s in DWARF reader [in module %s]", |
| 4187 | dwarf_form_name (form), |
| 4188 | bfd_get_filename (abfd)); |
| 4189 | } |
| 4190 | return info_ptr; |
| 4191 | } |
| 4192 | |
| 4193 | /* Read an attribute described by an abbreviated attribute. */ |
| 4194 | |
| 4195 | static char * |
| 4196 | read_attribute (struct attribute *attr, struct attr_abbrev *abbrev, |
| 4197 | bfd *abfd, char *info_ptr, |
| 4198 | const struct comp_unit_head *cu_header) |
| 4199 | { |
| 4200 | attr->name = abbrev->name; |
| 4201 | return read_attribute_value (attr, abbrev->form, abfd, info_ptr, cu_header); |
| 4202 | } |
| 4203 | |
| 4204 | /* read dwarf information from a buffer */ |
| 4205 | |
| 4206 | static unsigned int |
| 4207 | read_1_byte (bfd *abfd, char *buf) |
| 4208 | { |
| 4209 | return bfd_get_8 (abfd, (bfd_byte *) buf); |
| 4210 | } |
| 4211 | |
| 4212 | static int |
| 4213 | read_1_signed_byte (bfd *abfd, char *buf) |
| 4214 | { |
| 4215 | return bfd_get_signed_8 (abfd, (bfd_byte *) buf); |
| 4216 | } |
| 4217 | |
| 4218 | static unsigned int |
| 4219 | read_2_bytes (bfd *abfd, char *buf) |
| 4220 | { |
| 4221 | return bfd_get_16 (abfd, (bfd_byte *) buf); |
| 4222 | } |
| 4223 | |
| 4224 | static int |
| 4225 | read_2_signed_bytes (bfd *abfd, char *buf) |
| 4226 | { |
| 4227 | return bfd_get_signed_16 (abfd, (bfd_byte *) buf); |
| 4228 | } |
| 4229 | |
| 4230 | static unsigned int |
| 4231 | read_4_bytes (bfd *abfd, char *buf) |
| 4232 | { |
| 4233 | return bfd_get_32 (abfd, (bfd_byte *) buf); |
| 4234 | } |
| 4235 | |
| 4236 | static int |
| 4237 | read_4_signed_bytes (bfd *abfd, char *buf) |
| 4238 | { |
| 4239 | return bfd_get_signed_32 (abfd, (bfd_byte *) buf); |
| 4240 | } |
| 4241 | |
| 4242 | static unsigned long |
| 4243 | read_8_bytes (bfd *abfd, char *buf) |
| 4244 | { |
| 4245 | return bfd_get_64 (abfd, (bfd_byte *) buf); |
| 4246 | } |
| 4247 | |
| 4248 | static CORE_ADDR |
| 4249 | read_address (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, |
| 4250 | int *bytes_read) |
| 4251 | { |
| 4252 | CORE_ADDR retval = 0; |
| 4253 | |
| 4254 | if (cu_header->signed_addr_p) |
| 4255 | { |
| 4256 | switch (cu_header->addr_size) |
| 4257 | { |
| 4258 | case 2: |
| 4259 | retval = bfd_get_signed_16 (abfd, (bfd_byte *) buf); |
| 4260 | break; |
| 4261 | case 4: |
| 4262 | retval = bfd_get_signed_32 (abfd, (bfd_byte *) buf); |
| 4263 | break; |
| 4264 | case 8: |
| 4265 | retval = bfd_get_signed_64 (abfd, (bfd_byte *) buf); |
| 4266 | break; |
| 4267 | default: |
| 4268 | internal_error (__FILE__, __LINE__, |
| 4269 | "read_address: bad switch, signed [in module %s]", |
| 4270 | bfd_get_filename (abfd)); |
| 4271 | } |
| 4272 | } |
| 4273 | else |
| 4274 | { |
| 4275 | switch (cu_header->addr_size) |
| 4276 | { |
| 4277 | case 2: |
| 4278 | retval = bfd_get_16 (abfd, (bfd_byte *) buf); |
| 4279 | break; |
| 4280 | case 4: |
| 4281 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); |
| 4282 | break; |
| 4283 | case 8: |
| 4284 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); |
| 4285 | break; |
| 4286 | default: |
| 4287 | internal_error (__FILE__, __LINE__, |
| 4288 | "read_address: bad switch, unsigned [in module %s]", |
| 4289 | bfd_get_filename (abfd)); |
| 4290 | } |
| 4291 | } |
| 4292 | |
| 4293 | *bytes_read = cu_header->addr_size; |
| 4294 | return retval; |
| 4295 | } |
| 4296 | |
| 4297 | /* Read the initial length from a section. The (draft) DWARF 3 |
| 4298 | specification allows the initial length to take up either 4 bytes |
| 4299 | or 12 bytes. If the first 4 bytes are 0xffffffff, then the next 8 |
| 4300 | bytes describe the length and all offsets will be 8 bytes in length |
| 4301 | instead of 4. |
| 4302 | |
| 4303 | An older, non-standard 64-bit format is also handled by this |
| 4304 | function. The older format in question stores the initial length |
| 4305 | as an 8-byte quantity without an escape value. Lengths greater |
| 4306 | than 2^32 aren't very common which means that the initial 4 bytes |
| 4307 | is almost always zero. Since a length value of zero doesn't make |
| 4308 | sense for the 32-bit format, this initial zero can be considered to |
| 4309 | be an escape value which indicates the presence of the older 64-bit |
| 4310 | format. As written, the code can't detect (old format) lengths |
| 4311 | greater than 4GB. If it becomes necessary to handle lengths somewhat |
| 4312 | larger than 4GB, we could allow other small values (such as the |
| 4313 | non-sensical values of 1, 2, and 3) to also be used as escape values |
| 4314 | indicating the presence of the old format. |
| 4315 | |
| 4316 | The value returned via bytes_read should be used to increment |
| 4317 | the relevant pointer after calling read_initial_length(). |
| 4318 | |
| 4319 | As a side effect, this function sets the fields initial_length_size |
| 4320 | and offset_size in cu_header to the values appropriate for the |
| 4321 | length field. (The format of the initial length field determines |
| 4322 | the width of file offsets to be fetched later with fetch_offset().) |
| 4323 | |
| 4324 | [ Note: read_initial_length() and read_offset() are based on the |
| 4325 | document entitled "DWARF Debugging Information Format", revision |
| 4326 | 3, draft 8, dated November 19, 2001. This document was obtained |
| 4327 | from: |
| 4328 | |
| 4329 | http://reality.sgiweb.org/davea/dwarf3-draft8-011125.pdf |
| 4330 | |
| 4331 | This document is only a draft and is subject to change. (So beware.) |
| 4332 | |
| 4333 | Details regarding the older, non-standard 64-bit format were |
| 4334 | determined empirically by examining 64-bit ELF files produced |
| 4335 | by the SGI toolchain on an IRIX 6.5 machine. |
| 4336 | |
| 4337 | - Kevin, July 16, 2002 |
| 4338 | ] */ |
| 4339 | |
| 4340 | static LONGEST |
| 4341 | read_initial_length (bfd *abfd, char *buf, struct comp_unit_head *cu_header, |
| 4342 | int *bytes_read) |
| 4343 | { |
| 4344 | LONGEST retval = 0; |
| 4345 | |
| 4346 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); |
| 4347 | |
| 4348 | if (retval == 0xffffffff) |
| 4349 | { |
| 4350 | retval = bfd_get_64 (abfd, (bfd_byte *) buf + 4); |
| 4351 | *bytes_read = 12; |
| 4352 | if (cu_header != NULL) |
| 4353 | { |
| 4354 | cu_header->initial_length_size = 12; |
| 4355 | cu_header->offset_size = 8; |
| 4356 | } |
| 4357 | } |
| 4358 | else if (retval == 0) |
| 4359 | { |
| 4360 | /* Handle (non-standard) 64-bit DWARF2 formats such as that used |
| 4361 | by IRIX. */ |
| 4362 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); |
| 4363 | *bytes_read = 8; |
| 4364 | if (cu_header != NULL) |
| 4365 | { |
| 4366 | cu_header->initial_length_size = 8; |
| 4367 | cu_header->offset_size = 8; |
| 4368 | } |
| 4369 | } |
| 4370 | else |
| 4371 | { |
| 4372 | *bytes_read = 4; |
| 4373 | if (cu_header != NULL) |
| 4374 | { |
| 4375 | cu_header->initial_length_size = 4; |
| 4376 | cu_header->offset_size = 4; |
| 4377 | } |
| 4378 | } |
| 4379 | |
| 4380 | return retval; |
| 4381 | } |
| 4382 | |
| 4383 | /* Read an offset from the data stream. The size of the offset is |
| 4384 | given by cu_header->offset_size. */ |
| 4385 | |
| 4386 | static LONGEST |
| 4387 | read_offset (bfd *abfd, char *buf, const struct comp_unit_head *cu_header, |
| 4388 | int *bytes_read) |
| 4389 | { |
| 4390 | LONGEST retval = 0; |
| 4391 | |
| 4392 | switch (cu_header->offset_size) |
| 4393 | { |
| 4394 | case 4: |
| 4395 | retval = bfd_get_32 (abfd, (bfd_byte *) buf); |
| 4396 | *bytes_read = 4; |
| 4397 | break; |
| 4398 | case 8: |
| 4399 | retval = bfd_get_64 (abfd, (bfd_byte *) buf); |
| 4400 | *bytes_read = 8; |
| 4401 | break; |
| 4402 | default: |
| 4403 | internal_error (__FILE__, __LINE__, |
| 4404 | "read_offset: bad switch [in module %s]", |
| 4405 | bfd_get_filename (abfd)); |
| 4406 | } |
| 4407 | |
| 4408 | return retval; |
| 4409 | } |
| 4410 | |
| 4411 | static char * |
| 4412 | read_n_bytes (bfd *abfd, char *buf, unsigned int size) |
| 4413 | { |
| 4414 | /* If the size of a host char is 8 bits, we can return a pointer |
| 4415 | to the buffer, otherwise we have to copy the data to a buffer |
| 4416 | allocated on the temporary obstack. */ |
| 4417 | gdb_assert (HOST_CHAR_BIT == 8); |
| 4418 | return buf; |
| 4419 | } |
| 4420 | |
| 4421 | static char * |
| 4422 | read_string (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
| 4423 | { |
| 4424 | /* If the size of a host char is 8 bits, we can return a pointer |
| 4425 | to the string, otherwise we have to copy the string to a buffer |
| 4426 | allocated on the temporary obstack. */ |
| 4427 | gdb_assert (HOST_CHAR_BIT == 8); |
| 4428 | if (*buf == '\0') |
| 4429 | { |
| 4430 | *bytes_read_ptr = 1; |
| 4431 | return NULL; |
| 4432 | } |
| 4433 | *bytes_read_ptr = strlen (buf) + 1; |
| 4434 | return buf; |
| 4435 | } |
| 4436 | |
| 4437 | static char * |
| 4438 | read_indirect_string (bfd *abfd, char *buf, |
| 4439 | const struct comp_unit_head *cu_header, |
| 4440 | unsigned int *bytes_read_ptr) |
| 4441 | { |
| 4442 | LONGEST str_offset = read_offset (abfd, buf, cu_header, |
| 4443 | (int *) bytes_read_ptr); |
| 4444 | |
| 4445 | if (dwarf_str_buffer == NULL) |
| 4446 | { |
| 4447 | error ("DW_FORM_strp used without .debug_str section [in module %s]", |
| 4448 | bfd_get_filename (abfd)); |
| 4449 | return NULL; |
| 4450 | } |
| 4451 | if (str_offset >= dwarf_str_size) |
| 4452 | { |
| 4453 | error ("DW_FORM_strp pointing outside of .debug_str section [in module %s]", |
| 4454 | bfd_get_filename (abfd)); |
| 4455 | return NULL; |
| 4456 | } |
| 4457 | gdb_assert (HOST_CHAR_BIT == 8); |
| 4458 | if (dwarf_str_buffer[str_offset] == '\0') |
| 4459 | return NULL; |
| 4460 | return dwarf_str_buffer + str_offset; |
| 4461 | } |
| 4462 | |
| 4463 | static unsigned long |
| 4464 | read_unsigned_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
| 4465 | { |
| 4466 | unsigned long result; |
| 4467 | unsigned int num_read; |
| 4468 | int i, shift; |
| 4469 | unsigned char byte; |
| 4470 | |
| 4471 | result = 0; |
| 4472 | shift = 0; |
| 4473 | num_read = 0; |
| 4474 | i = 0; |
| 4475 | while (1) |
| 4476 | { |
| 4477 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); |
| 4478 | buf++; |
| 4479 | num_read++; |
| 4480 | result |= ((unsigned long)(byte & 127) << shift); |
| 4481 | if ((byte & 128) == 0) |
| 4482 | { |
| 4483 | break; |
| 4484 | } |
| 4485 | shift += 7; |
| 4486 | } |
| 4487 | *bytes_read_ptr = num_read; |
| 4488 | return result; |
| 4489 | } |
| 4490 | |
| 4491 | static long |
| 4492 | read_signed_leb128 (bfd *abfd, char *buf, unsigned int *bytes_read_ptr) |
| 4493 | { |
| 4494 | long result; |
| 4495 | int i, shift, size, num_read; |
| 4496 | unsigned char byte; |
| 4497 | |
| 4498 | result = 0; |
| 4499 | shift = 0; |
| 4500 | size = 32; |
| 4501 | num_read = 0; |
| 4502 | i = 0; |
| 4503 | while (1) |
| 4504 | { |
| 4505 | byte = bfd_get_8 (abfd, (bfd_byte *) buf); |
| 4506 | buf++; |
| 4507 | num_read++; |
| 4508 | result |= ((long)(byte & 127) << shift); |
| 4509 | shift += 7; |
| 4510 | if ((byte & 128) == 0) |
| 4511 | { |
| 4512 | break; |
| 4513 | } |
| 4514 | } |
| 4515 | if ((shift < size) && (byte & 0x40)) |
| 4516 | { |
| 4517 | result |= -(1 << shift); |
| 4518 | } |
| 4519 | *bytes_read_ptr = num_read; |
| 4520 | return result; |
| 4521 | } |
| 4522 | |
| 4523 | static void |
| 4524 | set_cu_language (unsigned int lang) |
| 4525 | { |
| 4526 | switch (lang) |
| 4527 | { |
| 4528 | case DW_LANG_C89: |
| 4529 | case DW_LANG_C: |
| 4530 | cu_language = language_c; |
| 4531 | break; |
| 4532 | case DW_LANG_C_plus_plus: |
| 4533 | cu_language = language_cplus; |
| 4534 | break; |
| 4535 | case DW_LANG_Fortran77: |
| 4536 | case DW_LANG_Fortran90: |
| 4537 | case DW_LANG_Fortran95: |
| 4538 | cu_language = language_fortran; |
| 4539 | break; |
| 4540 | case DW_LANG_Mips_Assembler: |
| 4541 | cu_language = language_asm; |
| 4542 | break; |
| 4543 | case DW_LANG_Java: |
| 4544 | cu_language = language_java; |
| 4545 | break; |
| 4546 | case DW_LANG_Ada83: |
| 4547 | case DW_LANG_Ada95: |
| 4548 | case DW_LANG_Cobol74: |
| 4549 | case DW_LANG_Cobol85: |
| 4550 | case DW_LANG_Pascal83: |
| 4551 | case DW_LANG_Modula2: |
| 4552 | default: |
| 4553 | cu_language = language_minimal; |
| 4554 | break; |
| 4555 | } |
| 4556 | cu_language_defn = language_def (cu_language); |
| 4557 | } |
| 4558 | |
| 4559 | /* Return the named attribute or NULL if not there. */ |
| 4560 | |
| 4561 | static struct attribute * |
| 4562 | dwarf_attr (struct die_info *die, unsigned int name) |
| 4563 | { |
| 4564 | unsigned int i; |
| 4565 | struct attribute *spec = NULL; |
| 4566 | |
| 4567 | for (i = 0; i < die->num_attrs; ++i) |
| 4568 | { |
| 4569 | if (die->attrs[i].name == name) |
| 4570 | { |
| 4571 | return &die->attrs[i]; |
| 4572 | } |
| 4573 | if (die->attrs[i].name == DW_AT_specification |
| 4574 | || die->attrs[i].name == DW_AT_abstract_origin) |
| 4575 | spec = &die->attrs[i]; |
| 4576 | } |
| 4577 | if (spec) |
| 4578 | { |
| 4579 | struct die_info *ref_die = |
| 4580 | follow_die_ref (dwarf2_get_ref_die_offset (spec)); |
| 4581 | |
| 4582 | if (ref_die) |
| 4583 | return dwarf_attr (ref_die, name); |
| 4584 | } |
| 4585 | |
| 4586 | return NULL; |
| 4587 | } |
| 4588 | |
| 4589 | static int |
| 4590 | die_is_declaration (struct die_info *die) |
| 4591 | { |
| 4592 | return (dwarf_attr (die, DW_AT_declaration) |
| 4593 | && ! dwarf_attr (die, DW_AT_specification)); |
| 4594 | } |
| 4595 | |
| 4596 | |
| 4597 | /* Free the line_header structure *LH, and any arrays and strings it |
| 4598 | refers to. */ |
| 4599 | static void |
| 4600 | free_line_header (struct line_header *lh) |
| 4601 | { |
| 4602 | if (lh->standard_opcode_lengths) |
| 4603 | xfree (lh->standard_opcode_lengths); |
| 4604 | |
| 4605 | /* Remember that all the lh->file_names[i].name pointers are |
| 4606 | pointers into debug_line_buffer, and don't need to be freed. */ |
| 4607 | if (lh->file_names) |
| 4608 | xfree (lh->file_names); |
| 4609 | |
| 4610 | /* Similarly for the include directory names. */ |
| 4611 | if (lh->include_dirs) |
| 4612 | xfree (lh->include_dirs); |
| 4613 | |
| 4614 | xfree (lh); |
| 4615 | } |
| 4616 | |
| 4617 | |
| 4618 | /* Add an entry to LH's include directory table. */ |
| 4619 | static void |
| 4620 | add_include_dir (struct line_header *lh, char *include_dir) |
| 4621 | { |
| 4622 | /* Grow the array if necessary. */ |
| 4623 | if (lh->include_dirs_size == 0) |
| 4624 | { |
| 4625 | lh->include_dirs_size = 1; /* for testing */ |
| 4626 | lh->include_dirs = xmalloc (lh->include_dirs_size |
| 4627 | * sizeof (*lh->include_dirs)); |
| 4628 | } |
| 4629 | else if (lh->num_include_dirs >= lh->include_dirs_size) |
| 4630 | { |
| 4631 | lh->include_dirs_size *= 2; |
| 4632 | lh->include_dirs = xrealloc (lh->include_dirs, |
| 4633 | (lh->include_dirs_size |
| 4634 | * sizeof (*lh->include_dirs))); |
| 4635 | } |
| 4636 | |
| 4637 | lh->include_dirs[lh->num_include_dirs++] = include_dir; |
| 4638 | } |
| 4639 | |
| 4640 | |
| 4641 | /* Add an entry to LH's file name table. */ |
| 4642 | static void |
| 4643 | add_file_name (struct line_header *lh, |
| 4644 | char *name, |
| 4645 | unsigned int dir_index, |
| 4646 | unsigned int mod_time, |
| 4647 | unsigned int length) |
| 4648 | { |
| 4649 | struct file_entry *fe; |
| 4650 | |
| 4651 | /* Grow the array if necessary. */ |
| 4652 | if (lh->file_names_size == 0) |
| 4653 | { |
| 4654 | lh->file_names_size = 1; /* for testing */ |
| 4655 | lh->file_names = xmalloc (lh->file_names_size |
| 4656 | * sizeof (*lh->file_names)); |
| 4657 | } |
| 4658 | else if (lh->num_file_names >= lh->file_names_size) |
| 4659 | { |
| 4660 | lh->file_names_size *= 2; |
| 4661 | lh->file_names = xrealloc (lh->file_names, |
| 4662 | (lh->file_names_size |
| 4663 | * sizeof (*lh->file_names))); |
| 4664 | } |
| 4665 | |
| 4666 | fe = &lh->file_names[lh->num_file_names++]; |
| 4667 | fe->name = name; |
| 4668 | fe->dir_index = dir_index; |
| 4669 | fe->mod_time = mod_time; |
| 4670 | fe->length = length; |
| 4671 | } |
| 4672 | |
| 4673 | |
| 4674 | /* Read the statement program header starting at OFFSET in |
| 4675 | dwarf_line_buffer, according to the endianness of ABFD. Return a |
| 4676 | pointer to a struct line_header, allocated using xmalloc. |
| 4677 | |
| 4678 | NOTE: the strings in the include directory and file name tables of |
| 4679 | the returned object point into debug_line_buffer, and must not be |
| 4680 | freed. */ |
| 4681 | static struct line_header * |
| 4682 | dwarf_decode_line_header (unsigned int offset, bfd *abfd, |
| 4683 | const struct comp_unit_head *cu_header) |
| 4684 | { |
| 4685 | struct cleanup *back_to; |
| 4686 | struct line_header *lh; |
| 4687 | char *line_ptr; |
| 4688 | int bytes_read; |
| 4689 | int i; |
| 4690 | char *cur_dir, *cur_file; |
| 4691 | |
| 4692 | if (dwarf_line_buffer == NULL) |
| 4693 | { |
| 4694 | complaint (&symfile_complaints, "missing .debug_line section"); |
| 4695 | return 0; |
| 4696 | } |
| 4697 | |
| 4698 | /* Make sure that at least there's room for the total_length field. That |
| 4699 | could be 12 bytes long, but we're just going to fudge that. */ |
| 4700 | if (offset + 4 >= dwarf_line_size) |
| 4701 | { |
| 4702 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 4703 | return 0; |
| 4704 | } |
| 4705 | |
| 4706 | lh = xmalloc (sizeof (*lh)); |
| 4707 | memset (lh, 0, sizeof (*lh)); |
| 4708 | back_to = make_cleanup ((make_cleanup_ftype *) free_line_header, |
| 4709 | (void *) lh); |
| 4710 | |
| 4711 | line_ptr = dwarf_line_buffer + offset; |
| 4712 | |
| 4713 | /* read in the header */ |
| 4714 | lh->total_length = read_initial_length (abfd, line_ptr, NULL, &bytes_read); |
| 4715 | line_ptr += bytes_read; |
| 4716 | if (line_ptr + lh->total_length > dwarf_line_buffer + dwarf_line_size) |
| 4717 | { |
| 4718 | dwarf2_statement_list_fits_in_line_number_section_complaint (); |
| 4719 | return 0; |
| 4720 | } |
| 4721 | lh->statement_program_end = line_ptr + lh->total_length; |
| 4722 | lh->version = read_2_bytes (abfd, line_ptr); |
| 4723 | line_ptr += 2; |
| 4724 | lh->header_length = read_offset (abfd, line_ptr, cu_header, &bytes_read); |
| 4725 | line_ptr += bytes_read; |
| 4726 | lh->minimum_instruction_length = read_1_byte (abfd, line_ptr); |
| 4727 | line_ptr += 1; |
| 4728 | lh->default_is_stmt = read_1_byte (abfd, line_ptr); |
| 4729 | line_ptr += 1; |
| 4730 | lh->line_base = read_1_signed_byte (abfd, line_ptr); |
| 4731 | line_ptr += 1; |
| 4732 | lh->line_range = read_1_byte (abfd, line_ptr); |
| 4733 | line_ptr += 1; |
| 4734 | lh->opcode_base = read_1_byte (abfd, line_ptr); |
| 4735 | line_ptr += 1; |
| 4736 | lh->standard_opcode_lengths |
| 4737 | = (unsigned char *) xmalloc (lh->opcode_base * sizeof (unsigned char)); |
| 4738 | |
| 4739 | lh->standard_opcode_lengths[0] = 1; /* This should never be used anyway. */ |
| 4740 | for (i = 1; i < lh->opcode_base; ++i) |
| 4741 | { |
| 4742 | lh->standard_opcode_lengths[i] = read_1_byte (abfd, line_ptr); |
| 4743 | line_ptr += 1; |
| 4744 | } |
| 4745 | |
| 4746 | /* Read directory table */ |
| 4747 | while ((cur_dir = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 4748 | { |
| 4749 | line_ptr += bytes_read; |
| 4750 | add_include_dir (lh, cur_dir); |
| 4751 | } |
| 4752 | line_ptr += bytes_read; |
| 4753 | |
| 4754 | /* Read file name table */ |
| 4755 | while ((cur_file = read_string (abfd, line_ptr, &bytes_read)) != NULL) |
| 4756 | { |
| 4757 | unsigned int dir_index, mod_time, length; |
| 4758 | |
| 4759 | line_ptr += bytes_read; |
| 4760 | dir_index = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4761 | line_ptr += bytes_read; |
| 4762 | mod_time = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4763 | line_ptr += bytes_read; |
| 4764 | length = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4765 | line_ptr += bytes_read; |
| 4766 | |
| 4767 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 4768 | } |
| 4769 | line_ptr += bytes_read; |
| 4770 | lh->statement_program_start = line_ptr; |
| 4771 | |
| 4772 | if (line_ptr > dwarf_line_buffer + dwarf_line_size) |
| 4773 | complaint (&symfile_complaints, |
| 4774 | "line number info header doesn't fit in `.debug_line' section"); |
| 4775 | |
| 4776 | discard_cleanups (back_to); |
| 4777 | return lh; |
| 4778 | } |
| 4779 | |
| 4780 | /* This function exists to work around a bug in certain compilers |
| 4781 | (particularly GCC 2.95), in which the first line number marker of a |
| 4782 | function does not show up until after the prologue, right before |
| 4783 | the second line number marker. This function shifts ADDRESS down |
| 4784 | to the beginning of the function if necessary, and is called on |
| 4785 | addresses passed to record_line. */ |
| 4786 | |
| 4787 | static CORE_ADDR |
| 4788 | check_cu_functions (CORE_ADDR address) |
| 4789 | { |
| 4790 | struct function_range *fn; |
| 4791 | |
| 4792 | /* Find the function_range containing address. */ |
| 4793 | if (!cu_first_fn) |
| 4794 | return address; |
| 4795 | |
| 4796 | if (!cu_cached_fn) |
| 4797 | cu_cached_fn = cu_first_fn; |
| 4798 | |
| 4799 | fn = cu_cached_fn; |
| 4800 | while (fn) |
| 4801 | if (fn->lowpc <= address && fn->highpc > address) |
| 4802 | goto found; |
| 4803 | else |
| 4804 | fn = fn->next; |
| 4805 | |
| 4806 | fn = cu_first_fn; |
| 4807 | while (fn && fn != cu_cached_fn) |
| 4808 | if (fn->lowpc <= address && fn->highpc > address) |
| 4809 | goto found; |
| 4810 | else |
| 4811 | fn = fn->next; |
| 4812 | |
| 4813 | return address; |
| 4814 | |
| 4815 | found: |
| 4816 | if (fn->seen_line) |
| 4817 | return address; |
| 4818 | if (address != fn->lowpc) |
| 4819 | complaint (&symfile_complaints, |
| 4820 | "misplaced first line number at 0x%lx for '%s'", |
| 4821 | (unsigned long) address, fn->name); |
| 4822 | fn->seen_line = 1; |
| 4823 | return fn->lowpc; |
| 4824 | } |
| 4825 | |
| 4826 | /* Decode the line number information for the compilation unit whose |
| 4827 | line number info is at OFFSET in the .debug_line section. |
| 4828 | The compilation directory of the file is passed in COMP_DIR. */ |
| 4829 | |
| 4830 | static void |
| 4831 | dwarf_decode_lines (struct line_header *lh, char *comp_dir, bfd *abfd, |
| 4832 | const struct comp_unit_head *cu_header) |
| 4833 | { |
| 4834 | char *line_ptr; |
| 4835 | char *line_end; |
| 4836 | unsigned int i, bytes_read; |
| 4837 | char *cur_dir; |
| 4838 | unsigned char op_code, extended_op, adj_opcode; |
| 4839 | |
| 4840 | line_ptr = lh->statement_program_start; |
| 4841 | line_end = lh->statement_program_end; |
| 4842 | |
| 4843 | /* Read the statement sequences until there's nothing left. */ |
| 4844 | while (line_ptr < line_end) |
| 4845 | { |
| 4846 | /* state machine registers */ |
| 4847 | CORE_ADDR address = 0; |
| 4848 | unsigned int file = 1; |
| 4849 | unsigned int line = 1; |
| 4850 | unsigned int column = 0; |
| 4851 | int is_stmt = lh->default_is_stmt; |
| 4852 | int basic_block = 0; |
| 4853 | int end_sequence = 0; |
| 4854 | |
| 4855 | /* Start a subfile for the current file of the state machine. */ |
| 4856 | if (lh->num_file_names >= file) |
| 4857 | { |
| 4858 | /* lh->include_dirs and lh->file_names are 0-based, but the |
| 4859 | directory and file name numbers in the statement program |
| 4860 | are 1-based. */ |
| 4861 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 4862 | char *dir; |
| 4863 | if (fe->dir_index) |
| 4864 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 4865 | else |
| 4866 | dir = comp_dir; |
| 4867 | dwarf2_start_subfile (fe->name, dir); |
| 4868 | } |
| 4869 | |
| 4870 | /* Decode the table. */ |
| 4871 | while (!end_sequence) |
| 4872 | { |
| 4873 | op_code = read_1_byte (abfd, line_ptr); |
| 4874 | line_ptr += 1; |
| 4875 | |
| 4876 | if (op_code >= lh->opcode_base) |
| 4877 | { /* Special operand. */ |
| 4878 | adj_opcode = op_code - lh->opcode_base; |
| 4879 | address += (adj_opcode / lh->line_range) |
| 4880 | * lh->minimum_instruction_length; |
| 4881 | line += lh->line_base + (adj_opcode % lh->line_range); |
| 4882 | /* append row to matrix using current values */ |
| 4883 | record_line (current_subfile, line, |
| 4884 | check_cu_functions (address)); |
| 4885 | basic_block = 1; |
| 4886 | } |
| 4887 | else switch (op_code) |
| 4888 | { |
| 4889 | case DW_LNS_extended_op: |
| 4890 | line_ptr += 1; /* ignore length */ |
| 4891 | extended_op = read_1_byte (abfd, line_ptr); |
| 4892 | line_ptr += 1; |
| 4893 | switch (extended_op) |
| 4894 | { |
| 4895 | case DW_LNE_end_sequence: |
| 4896 | end_sequence = 1; |
| 4897 | record_line (current_subfile, 0, address); |
| 4898 | break; |
| 4899 | case DW_LNE_set_address: |
| 4900 | address = read_address (abfd, line_ptr, cu_header, &bytes_read); |
| 4901 | line_ptr += bytes_read; |
| 4902 | address += baseaddr; |
| 4903 | break; |
| 4904 | case DW_LNE_define_file: |
| 4905 | { |
| 4906 | char *cur_file; |
| 4907 | unsigned int dir_index, mod_time, length; |
| 4908 | |
| 4909 | cur_file = read_string (abfd, line_ptr, &bytes_read); |
| 4910 | line_ptr += bytes_read; |
| 4911 | dir_index = |
| 4912 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4913 | line_ptr += bytes_read; |
| 4914 | mod_time = |
| 4915 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4916 | line_ptr += bytes_read; |
| 4917 | length = |
| 4918 | read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4919 | line_ptr += bytes_read; |
| 4920 | add_file_name (lh, cur_file, dir_index, mod_time, length); |
| 4921 | } |
| 4922 | break; |
| 4923 | default: |
| 4924 | complaint (&symfile_complaints, |
| 4925 | "mangled .debug_line section"); |
| 4926 | return; |
| 4927 | } |
| 4928 | break; |
| 4929 | case DW_LNS_copy: |
| 4930 | record_line (current_subfile, line, |
| 4931 | check_cu_functions (address)); |
| 4932 | basic_block = 0; |
| 4933 | break; |
| 4934 | case DW_LNS_advance_pc: |
| 4935 | address += lh->minimum_instruction_length |
| 4936 | * read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4937 | line_ptr += bytes_read; |
| 4938 | break; |
| 4939 | case DW_LNS_advance_line: |
| 4940 | line += read_signed_leb128 (abfd, line_ptr, &bytes_read); |
| 4941 | line_ptr += bytes_read; |
| 4942 | break; |
| 4943 | case DW_LNS_set_file: |
| 4944 | { |
| 4945 | /* lh->include_dirs and lh->file_names are 0-based, |
| 4946 | but the directory and file name numbers in the |
| 4947 | statement program are 1-based. */ |
| 4948 | struct file_entry *fe; |
| 4949 | char *dir; |
| 4950 | file = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4951 | line_ptr += bytes_read; |
| 4952 | fe = &lh->file_names[file - 1]; |
| 4953 | if (fe->dir_index) |
| 4954 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 4955 | else |
| 4956 | dir = comp_dir; |
| 4957 | dwarf2_start_subfile (fe->name, dir); |
| 4958 | } |
| 4959 | break; |
| 4960 | case DW_LNS_set_column: |
| 4961 | column = read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4962 | line_ptr += bytes_read; |
| 4963 | break; |
| 4964 | case DW_LNS_negate_stmt: |
| 4965 | is_stmt = (!is_stmt); |
| 4966 | break; |
| 4967 | case DW_LNS_set_basic_block: |
| 4968 | basic_block = 1; |
| 4969 | break; |
| 4970 | /* Add to the address register of the state machine the |
| 4971 | address increment value corresponding to special opcode |
| 4972 | 255. Ie, this value is scaled by the minimum instruction |
| 4973 | length since special opcode 255 would have scaled the |
| 4974 | the increment. */ |
| 4975 | case DW_LNS_const_add_pc: |
| 4976 | address += (lh->minimum_instruction_length |
| 4977 | * ((255 - lh->opcode_base) / lh->line_range)); |
| 4978 | break; |
| 4979 | case DW_LNS_fixed_advance_pc: |
| 4980 | address += read_2_bytes (abfd, line_ptr); |
| 4981 | line_ptr += 2; |
| 4982 | break; |
| 4983 | default: |
| 4984 | { /* Unknown standard opcode, ignore it. */ |
| 4985 | int i; |
| 4986 | for (i = 0; i < lh->standard_opcode_lengths[op_code]; i++) |
| 4987 | { |
| 4988 | (void) read_unsigned_leb128 (abfd, line_ptr, &bytes_read); |
| 4989 | line_ptr += bytes_read; |
| 4990 | } |
| 4991 | } |
| 4992 | } |
| 4993 | } |
| 4994 | } |
| 4995 | } |
| 4996 | |
| 4997 | /* Start a subfile for DWARF. FILENAME is the name of the file and |
| 4998 | DIRNAME the name of the source directory which contains FILENAME |
| 4999 | or NULL if not known. |
| 5000 | This routine tries to keep line numbers from identical absolute and |
| 5001 | relative file names in a common subfile. |
| 5002 | |
| 5003 | Using the `list' example from the GDB testsuite, which resides in |
| 5004 | /srcdir and compiling it with Irix6.2 cc in /compdir using a filename |
| 5005 | of /srcdir/list0.c yields the following debugging information for list0.c: |
| 5006 | |
| 5007 | DW_AT_name: /srcdir/list0.c |
| 5008 | DW_AT_comp_dir: /compdir |
| 5009 | files.files[0].name: list0.h |
| 5010 | files.files[0].dir: /srcdir |
| 5011 | files.files[1].name: list0.c |
| 5012 | files.files[1].dir: /srcdir |
| 5013 | |
| 5014 | The line number information for list0.c has to end up in a single |
| 5015 | subfile, so that `break /srcdir/list0.c:1' works as expected. */ |
| 5016 | |
| 5017 | static void |
| 5018 | dwarf2_start_subfile (char *filename, char *dirname) |
| 5019 | { |
| 5020 | /* If the filename isn't absolute, try to match an existing subfile |
| 5021 | with the full pathname. */ |
| 5022 | |
| 5023 | if (!IS_ABSOLUTE_PATH (filename) && dirname != NULL) |
| 5024 | { |
| 5025 | struct subfile *subfile; |
| 5026 | char *fullname = concat (dirname, "/", filename, NULL); |
| 5027 | |
| 5028 | for (subfile = subfiles; subfile; subfile = subfile->next) |
| 5029 | { |
| 5030 | if (FILENAME_CMP (subfile->name, fullname) == 0) |
| 5031 | { |
| 5032 | current_subfile = subfile; |
| 5033 | xfree (fullname); |
| 5034 | return; |
| 5035 | } |
| 5036 | } |
| 5037 | xfree (fullname); |
| 5038 | } |
| 5039 | start_subfile (filename, dirname); |
| 5040 | } |
| 5041 | |
| 5042 | static void |
| 5043 | var_decode_location (struct attribute *attr, struct symbol *sym, |
| 5044 | struct objfile *objfile, |
| 5045 | const struct comp_unit_head *cu_header) |
| 5046 | { |
| 5047 | /* NOTE drow/2003-01-30: There used to be a comment and some special |
| 5048 | code here to turn a symbol with DW_AT_external and a |
| 5049 | SYMBOL_VALUE_ADDRESS of 0 into a LOC_UNRESOLVED symbol. This was |
| 5050 | necessary for platforms (maybe Alpha, certainly PowerPC GNU/Linux |
| 5051 | with some versions of binutils) where shared libraries could have |
| 5052 | relocations against symbols in their debug information - the |
| 5053 | minimal symbol would have the right address, but the debug info |
| 5054 | would not. It's no longer necessary, because we will explicitly |
| 5055 | apply relocations when we read in the debug information now. */ |
| 5056 | |
| 5057 | /* A DW_AT_location attribute with no contents indicates that a |
| 5058 | variable has been optimized away. */ |
| 5059 | if (attr_form_is_block (attr) && DW_BLOCK (attr)->size == 0) |
| 5060 | { |
| 5061 | SYMBOL_CLASS (sym) = LOC_OPTIMIZED_OUT; |
| 5062 | return; |
| 5063 | } |
| 5064 | |
| 5065 | /* Handle one degenerate form of location expression specially, to |
| 5066 | preserve GDB's previous behavior when section offsets are |
| 5067 | specified. If this is just a DW_OP_addr then mark this symbol |
| 5068 | as LOC_STATIC. */ |
| 5069 | |
| 5070 | if (attr_form_is_block (attr) |
| 5071 | && DW_BLOCK (attr)->size == 1 + cu_header->addr_size |
| 5072 | && DW_BLOCK (attr)->data[0] == DW_OP_addr) |
| 5073 | { |
| 5074 | int dummy; |
| 5075 | |
| 5076 | SYMBOL_VALUE_ADDRESS (sym) = |
| 5077 | read_address (objfile->obfd, DW_BLOCK (attr)->data + 1, cu_header, |
| 5078 | &dummy); |
| 5079 | fixup_symbol_section (sym, objfile); |
| 5080 | SYMBOL_VALUE_ADDRESS (sym) += ANOFFSET (objfile->section_offsets, |
| 5081 | SYMBOL_SECTION (sym)); |
| 5082 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 5083 | return; |
| 5084 | } |
| 5085 | |
| 5086 | /* NOTE drow/2002-01-30: It might be worthwhile to have a static |
| 5087 | expression evaluator, and use LOC_COMPUTED only when necessary |
| 5088 | (i.e. when the value of a register or memory location is |
| 5089 | referenced, or a thread-local block, etc.). Then again, it might |
| 5090 | not be worthwhile. I'm assuming that it isn't unless performance |
| 5091 | or memory numbers show me otherwise. */ |
| 5092 | |
| 5093 | dwarf2_symbol_mark_computed (attr, sym, cu_header, objfile); |
| 5094 | SYMBOL_CLASS (sym) = LOC_COMPUTED; |
| 5095 | } |
| 5096 | |
| 5097 | /* Given a pointer to a DWARF information entry, figure out if we need |
| 5098 | to make a symbol table entry for it, and if so, create a new entry |
| 5099 | and return a pointer to it. |
| 5100 | If TYPE is NULL, determine symbol type from the die, otherwise |
| 5101 | used the passed type. */ |
| 5102 | |
| 5103 | static struct symbol * |
| 5104 | new_symbol (struct die_info *die, struct type *type, struct objfile *objfile, |
| 5105 | const struct comp_unit_head *cu_header) |
| 5106 | { |
| 5107 | struct symbol *sym = NULL; |
| 5108 | char *name; |
| 5109 | struct attribute *attr = NULL; |
| 5110 | struct attribute *attr2 = NULL; |
| 5111 | CORE_ADDR addr = 0; |
| 5112 | |
| 5113 | name = dwarf2_linkage_name (die); |
| 5114 | if (name) |
| 5115 | { |
| 5116 | sym = (struct symbol *) obstack_alloc (&objfile->symbol_obstack, |
| 5117 | sizeof (struct symbol)); |
| 5118 | OBJSTAT (objfile, n_syms++); |
| 5119 | memset (sym, 0, sizeof (struct symbol)); |
| 5120 | |
| 5121 | /* Cache this symbol's name and the name's demangled form (if any). */ |
| 5122 | SYMBOL_LANGUAGE (sym) = cu_language; |
| 5123 | SYMBOL_SET_NAMES (sym, name, strlen (name), objfile); |
| 5124 | |
| 5125 | /* Default assumptions. |
| 5126 | Use the passed type or decode it from the die. */ |
| 5127 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 5128 | SYMBOL_CLASS (sym) = LOC_STATIC; |
| 5129 | if (type != NULL) |
| 5130 | SYMBOL_TYPE (sym) = type; |
| 5131 | else |
| 5132 | SYMBOL_TYPE (sym) = die_type (die, objfile, cu_header); |
| 5133 | attr = dwarf_attr (die, DW_AT_decl_line); |
| 5134 | if (attr) |
| 5135 | { |
| 5136 | SYMBOL_LINE (sym) = DW_UNSND (attr); |
| 5137 | } |
| 5138 | switch (die->tag) |
| 5139 | { |
| 5140 | case DW_TAG_label: |
| 5141 | attr = dwarf_attr (die, DW_AT_low_pc); |
| 5142 | if (attr) |
| 5143 | { |
| 5144 | SYMBOL_VALUE_ADDRESS (sym) = DW_ADDR (attr) + baseaddr; |
| 5145 | } |
| 5146 | SYMBOL_CLASS (sym) = LOC_LABEL; |
| 5147 | break; |
| 5148 | case DW_TAG_subprogram: |
| 5149 | /* SYMBOL_BLOCK_VALUE (sym) will be filled in later by |
| 5150 | finish_block. */ |
| 5151 | SYMBOL_CLASS (sym) = LOC_BLOCK; |
| 5152 | attr2 = dwarf_attr (die, DW_AT_external); |
| 5153 | if (attr2 && (DW_UNSND (attr2) != 0)) |
| 5154 | { |
| 5155 | add_symbol_to_list (sym, &global_symbols); |
| 5156 | } |
| 5157 | else |
| 5158 | { |
| 5159 | add_symbol_to_list (sym, list_in_scope); |
| 5160 | } |
| 5161 | break; |
| 5162 | case DW_TAG_variable: |
| 5163 | /* Compilation with minimal debug info may result in variables |
| 5164 | with missing type entries. Change the misleading `void' type |
| 5165 | to something sensible. */ |
| 5166 | if (TYPE_CODE (SYMBOL_TYPE (sym)) == TYPE_CODE_VOID) |
| 5167 | SYMBOL_TYPE (sym) = init_type (TYPE_CODE_INT, |
| 5168 | TARGET_INT_BIT / HOST_CHAR_BIT, 0, |
| 5169 | "<variable, no debug info>", |
| 5170 | objfile); |
| 5171 | attr = dwarf_attr (die, DW_AT_const_value); |
| 5172 | if (attr) |
| 5173 | { |
| 5174 | dwarf2_const_value (attr, sym, objfile, cu_header); |
| 5175 | attr2 = dwarf_attr (die, DW_AT_external); |
| 5176 | if (attr2 && (DW_UNSND (attr2) != 0)) |
| 5177 | add_symbol_to_list (sym, &global_symbols); |
| 5178 | else |
| 5179 | add_symbol_to_list (sym, list_in_scope); |
| 5180 | break; |
| 5181 | } |
| 5182 | attr = dwarf_attr (die, DW_AT_location); |
| 5183 | if (attr) |
| 5184 | { |
| 5185 | var_decode_location (attr, sym, objfile, cu_header); |
| 5186 | attr2 = dwarf_attr (die, DW_AT_external); |
| 5187 | if (attr2 && (DW_UNSND (attr2) != 0)) |
| 5188 | add_symbol_to_list (sym, &global_symbols); |
| 5189 | else |
| 5190 | add_symbol_to_list (sym, list_in_scope); |
| 5191 | } |
| 5192 | else |
| 5193 | { |
| 5194 | /* We do not know the address of this symbol. |
| 5195 | If it is an external symbol and we have type information |
| 5196 | for it, enter the symbol as a LOC_UNRESOLVED symbol. |
| 5197 | The address of the variable will then be determined from |
| 5198 | the minimal symbol table whenever the variable is |
| 5199 | referenced. */ |
| 5200 | attr2 = dwarf_attr (die, DW_AT_external); |
| 5201 | if (attr2 && (DW_UNSND (attr2) != 0) |
| 5202 | && dwarf_attr (die, DW_AT_type) != NULL) |
| 5203 | { |
| 5204 | SYMBOL_CLASS (sym) = LOC_UNRESOLVED; |
| 5205 | add_symbol_to_list (sym, &global_symbols); |
| 5206 | } |
| 5207 | } |
| 5208 | break; |
| 5209 | case DW_TAG_formal_parameter: |
| 5210 | attr = dwarf_attr (die, DW_AT_location); |
| 5211 | if (attr) |
| 5212 | { |
| 5213 | SYMBOL_VALUE (sym) = |
| 5214 | decode_locdesc (DW_BLOCK (attr), objfile, cu_header); |
| 5215 | if (isreg) |
| 5216 | { |
| 5217 | SYMBOL_CLASS (sym) = LOC_REGPARM; |
| 5218 | SYMBOL_VALUE (sym) = |
| 5219 | DWARF2_REG_TO_REGNUM (SYMBOL_VALUE (sym)); |
| 5220 | } |
| 5221 | else if (offreg) |
| 5222 | { |
| 5223 | if (isderef) |
| 5224 | { |
| 5225 | if (basereg != frame_base_reg) |
| 5226 | dwarf2_complex_location_expr_complaint (); |
| 5227 | SYMBOL_CLASS (sym) = LOC_REF_ARG; |
| 5228 | } |
| 5229 | else |
| 5230 | { |
| 5231 | SYMBOL_CLASS (sym) = LOC_BASEREG_ARG; |
| 5232 | SYMBOL_BASEREG (sym) = DWARF2_REG_TO_REGNUM (basereg); |
| 5233 | } |
| 5234 | } |
| 5235 | else |
| 5236 | { |
| 5237 | SYMBOL_CLASS (sym) = LOC_ARG; |
| 5238 | } |
| 5239 | } |
| 5240 | attr = dwarf_attr (die, DW_AT_const_value); |
| 5241 | if (attr) |
| 5242 | { |
| 5243 | dwarf2_const_value (attr, sym, objfile, cu_header); |
| 5244 | } |
| 5245 | add_symbol_to_list (sym, list_in_scope); |
| 5246 | break; |
| 5247 | case DW_TAG_unspecified_parameters: |
| 5248 | /* From varargs functions; gdb doesn't seem to have any |
| 5249 | interest in this information, so just ignore it for now. |
| 5250 | (FIXME?) */ |
| 5251 | break; |
| 5252 | case DW_TAG_class_type: |
| 5253 | case DW_TAG_structure_type: |
| 5254 | case DW_TAG_union_type: |
| 5255 | case DW_TAG_enumeration_type: |
| 5256 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 5257 | SYMBOL_DOMAIN (sym) = STRUCT_DOMAIN; |
| 5258 | add_symbol_to_list (sym, list_in_scope); |
| 5259 | |
| 5260 | /* The semantics of C++ state that "struct foo { ... }" also |
| 5261 | defines a typedef for "foo". Synthesize a typedef symbol so |
| 5262 | that "ptype foo" works as expected. */ |
| 5263 | if (cu_language == language_cplus) |
| 5264 | { |
| 5265 | struct symbol *typedef_sym = (struct symbol *) |
| 5266 | obstack_alloc (&objfile->symbol_obstack, |
| 5267 | sizeof (struct symbol)); |
| 5268 | *typedef_sym = *sym; |
| 5269 | SYMBOL_DOMAIN (typedef_sym) = VAR_DOMAIN; |
| 5270 | if (TYPE_NAME (SYMBOL_TYPE (sym)) == 0) |
| 5271 | TYPE_NAME (SYMBOL_TYPE (sym)) = |
| 5272 | obsavestring (DEPRECATED_SYMBOL_NAME (sym), |
| 5273 | strlen (DEPRECATED_SYMBOL_NAME (sym)), |
| 5274 | &objfile->type_obstack); |
| 5275 | add_symbol_to_list (typedef_sym, list_in_scope); |
| 5276 | } |
| 5277 | break; |
| 5278 | case DW_TAG_typedef: |
| 5279 | case DW_TAG_base_type: |
| 5280 | SYMBOL_CLASS (sym) = LOC_TYPEDEF; |
| 5281 | SYMBOL_DOMAIN (sym) = VAR_DOMAIN; |
| 5282 | add_symbol_to_list (sym, list_in_scope); |
| 5283 | break; |
| 5284 | case DW_TAG_enumerator: |
| 5285 | attr = dwarf_attr (die, DW_AT_const_value); |
| 5286 | if (attr) |
| 5287 | { |
| 5288 | dwarf2_const_value (attr, sym, objfile, cu_header); |
| 5289 | } |
| 5290 | add_symbol_to_list (sym, list_in_scope); |
| 5291 | break; |
| 5292 | default: |
| 5293 | /* Not a tag we recognize. Hopefully we aren't processing |
| 5294 | trash data, but since we must specifically ignore things |
| 5295 | we don't recognize, there is nothing else we should do at |
| 5296 | this point. */ |
| 5297 | complaint (&symfile_complaints, "unsupported tag: '%s'", |
| 5298 | dwarf_tag_name (die->tag)); |
| 5299 | break; |
| 5300 | } |
| 5301 | } |
| 5302 | return (sym); |
| 5303 | } |
| 5304 | |
| 5305 | /* Copy constant value from an attribute to a symbol. */ |
| 5306 | |
| 5307 | static void |
| 5308 | dwarf2_const_value (struct attribute *attr, struct symbol *sym, |
| 5309 | struct objfile *objfile, |
| 5310 | const struct comp_unit_head *cu_header) |
| 5311 | { |
| 5312 | struct dwarf_block *blk; |
| 5313 | |
| 5314 | switch (attr->form) |
| 5315 | { |
| 5316 | case DW_FORM_addr: |
| 5317 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != cu_header->addr_size) |
| 5318 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
| 5319 | cu_header->addr_size, |
| 5320 | TYPE_LENGTH (SYMBOL_TYPE |
| 5321 | (sym))); |
| 5322 | SYMBOL_VALUE_BYTES (sym) = (char *) |
| 5323 | obstack_alloc (&objfile->symbol_obstack, cu_header->addr_size); |
| 5324 | /* NOTE: cagney/2003-05-09: In-lined store_address call with |
| 5325 | it's body - store_unsigned_integer. */ |
| 5326 | store_unsigned_integer (SYMBOL_VALUE_BYTES (sym), cu_header->addr_size, |
| 5327 | DW_ADDR (attr)); |
| 5328 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 5329 | break; |
| 5330 | case DW_FORM_block1: |
| 5331 | case DW_FORM_block2: |
| 5332 | case DW_FORM_block4: |
| 5333 | case DW_FORM_block: |
| 5334 | blk = DW_BLOCK (attr); |
| 5335 | if (TYPE_LENGTH (SYMBOL_TYPE (sym)) != blk->size) |
| 5336 | dwarf2_const_value_length_mismatch_complaint (DEPRECATED_SYMBOL_NAME (sym), |
| 5337 | blk->size, |
| 5338 | TYPE_LENGTH (SYMBOL_TYPE |
| 5339 | (sym))); |
| 5340 | SYMBOL_VALUE_BYTES (sym) = (char *) |
| 5341 | obstack_alloc (&objfile->symbol_obstack, blk->size); |
| 5342 | memcpy (SYMBOL_VALUE_BYTES (sym), blk->data, blk->size); |
| 5343 | SYMBOL_CLASS (sym) = LOC_CONST_BYTES; |
| 5344 | break; |
| 5345 | |
| 5346 | /* The DW_AT_const_value attributes are supposed to carry the |
| 5347 | symbol's value "represented as it would be on the target |
| 5348 | architecture." By the time we get here, it's already been |
| 5349 | converted to host endianness, so we just need to sign- or |
| 5350 | zero-extend it as appropriate. */ |
| 5351 | case DW_FORM_data1: |
| 5352 | dwarf2_const_value_data (attr, sym, 8); |
| 5353 | break; |
| 5354 | case DW_FORM_data2: |
| 5355 | dwarf2_const_value_data (attr, sym, 16); |
| 5356 | break; |
| 5357 | case DW_FORM_data4: |
| 5358 | dwarf2_const_value_data (attr, sym, 32); |
| 5359 | break; |
| 5360 | case DW_FORM_data8: |
| 5361 | dwarf2_const_value_data (attr, sym, 64); |
| 5362 | break; |
| 5363 | |
| 5364 | case DW_FORM_sdata: |
| 5365 | SYMBOL_VALUE (sym) = DW_SND (attr); |
| 5366 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 5367 | break; |
| 5368 | |
| 5369 | case DW_FORM_udata: |
| 5370 | SYMBOL_VALUE (sym) = DW_UNSND (attr); |
| 5371 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 5372 | break; |
| 5373 | |
| 5374 | default: |
| 5375 | complaint (&symfile_complaints, |
| 5376 | "unsupported const value attribute form: '%s'", |
| 5377 | dwarf_form_name (attr->form)); |
| 5378 | SYMBOL_VALUE (sym) = 0; |
| 5379 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 5380 | break; |
| 5381 | } |
| 5382 | } |
| 5383 | |
| 5384 | |
| 5385 | /* Given an attr with a DW_FORM_dataN value in host byte order, sign- |
| 5386 | or zero-extend it as appropriate for the symbol's type. */ |
| 5387 | static void |
| 5388 | dwarf2_const_value_data (struct attribute *attr, |
| 5389 | struct symbol *sym, |
| 5390 | int bits) |
| 5391 | { |
| 5392 | LONGEST l = DW_UNSND (attr); |
| 5393 | |
| 5394 | if (bits < sizeof (l) * 8) |
| 5395 | { |
| 5396 | if (TYPE_UNSIGNED (SYMBOL_TYPE (sym))) |
| 5397 | l &= ((LONGEST) 1 << bits) - 1; |
| 5398 | else |
| 5399 | l = (l << (sizeof (l) * 8 - bits)) >> (sizeof (l) * 8 - bits); |
| 5400 | } |
| 5401 | |
| 5402 | SYMBOL_VALUE (sym) = l; |
| 5403 | SYMBOL_CLASS (sym) = LOC_CONST; |
| 5404 | } |
| 5405 | |
| 5406 | |
| 5407 | /* Return the type of the die in question using its DW_AT_type attribute. */ |
| 5408 | |
| 5409 | static struct type * |
| 5410 | die_type (struct die_info *die, struct objfile *objfile, |
| 5411 | const struct comp_unit_head *cu_header) |
| 5412 | { |
| 5413 | struct type *type; |
| 5414 | struct attribute *type_attr; |
| 5415 | struct die_info *type_die; |
| 5416 | unsigned int ref; |
| 5417 | |
| 5418 | type_attr = dwarf_attr (die, DW_AT_type); |
| 5419 | if (!type_attr) |
| 5420 | { |
| 5421 | /* A missing DW_AT_type represents a void type. */ |
| 5422 | return dwarf2_fundamental_type (objfile, FT_VOID); |
| 5423 | } |
| 5424 | else |
| 5425 | { |
| 5426 | ref = dwarf2_get_ref_die_offset (type_attr); |
| 5427 | type_die = follow_die_ref (ref); |
| 5428 | if (!type_die) |
| 5429 | { |
| 5430 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", |
| 5431 | ref, objfile->name); |
| 5432 | return NULL; |
| 5433 | } |
| 5434 | } |
| 5435 | type = tag_type_to_type (type_die, objfile, cu_header); |
| 5436 | if (!type) |
| 5437 | { |
| 5438 | dump_die (type_die); |
| 5439 | error ("Dwarf Error: Problem turning type die at offset into gdb type [in module %s]", |
| 5440 | objfile->name); |
| 5441 | } |
| 5442 | return type; |
| 5443 | } |
| 5444 | |
| 5445 | /* Return the containing type of the die in question using its |
| 5446 | DW_AT_containing_type attribute. */ |
| 5447 | |
| 5448 | static struct type * |
| 5449 | die_containing_type (struct die_info *die, struct objfile *objfile, |
| 5450 | const struct comp_unit_head *cu_header) |
| 5451 | { |
| 5452 | struct type *type = NULL; |
| 5453 | struct attribute *type_attr; |
| 5454 | struct die_info *type_die = NULL; |
| 5455 | unsigned int ref; |
| 5456 | |
| 5457 | type_attr = dwarf_attr (die, DW_AT_containing_type); |
| 5458 | if (type_attr) |
| 5459 | { |
| 5460 | ref = dwarf2_get_ref_die_offset (type_attr); |
| 5461 | type_die = follow_die_ref (ref); |
| 5462 | if (!type_die) |
| 5463 | { |
| 5464 | error ("Dwarf Error: Cannot find referent at offset %d [in module %s]", ref, |
| 5465 | objfile->name); |
| 5466 | return NULL; |
| 5467 | } |
| 5468 | type = tag_type_to_type (type_die, objfile, cu_header); |
| 5469 | } |
| 5470 | if (!type) |
| 5471 | { |
| 5472 | if (type_die) |
| 5473 | dump_die (type_die); |
| 5474 | error ("Dwarf Error: Problem turning containing type into gdb type [in module %s]", |
| 5475 | objfile->name); |
| 5476 | } |
| 5477 | return type; |
| 5478 | } |
| 5479 | |
| 5480 | #if 0 |
| 5481 | static struct type * |
| 5482 | type_at_offset (unsigned int offset, struct objfile *objfile) |
| 5483 | { |
| 5484 | struct die_info *die; |
| 5485 | struct type *type; |
| 5486 | |
| 5487 | die = follow_die_ref (offset); |
| 5488 | if (!die) |
| 5489 | { |
| 5490 | error ("Dwarf Error: Cannot find type referent at offset %d.", offset); |
| 5491 | return NULL; |
| 5492 | } |
| 5493 | type = tag_type_to_type (die, objfile); |
| 5494 | return type; |
| 5495 | } |
| 5496 | #endif |
| 5497 | |
| 5498 | static struct type * |
| 5499 | tag_type_to_type (struct die_info *die, struct objfile *objfile, |
| 5500 | const struct comp_unit_head *cu_header) |
| 5501 | { |
| 5502 | if (die->type) |
| 5503 | { |
| 5504 | return die->type; |
| 5505 | } |
| 5506 | else |
| 5507 | { |
| 5508 | read_type_die (die, objfile, cu_header); |
| 5509 | if (!die->type) |
| 5510 | { |
| 5511 | dump_die (die); |
| 5512 | error ("Dwarf Error: Cannot find type of die [in module %s]", |
| 5513 | objfile->name); |
| 5514 | } |
| 5515 | return die->type; |
| 5516 | } |
| 5517 | } |
| 5518 | |
| 5519 | static void |
| 5520 | read_type_die (struct die_info *die, struct objfile *objfile, |
| 5521 | const struct comp_unit_head *cu_header) |
| 5522 | { |
| 5523 | switch (die->tag) |
| 5524 | { |
| 5525 | case DW_TAG_class_type: |
| 5526 | case DW_TAG_structure_type: |
| 5527 | case DW_TAG_union_type: |
| 5528 | read_structure_scope (die, objfile, cu_header); |
| 5529 | break; |
| 5530 | case DW_TAG_enumeration_type: |
| 5531 | read_enumeration (die, objfile, cu_header); |
| 5532 | break; |
| 5533 | case DW_TAG_subprogram: |
| 5534 | case DW_TAG_subroutine_type: |
| 5535 | read_subroutine_type (die, objfile, cu_header); |
| 5536 | break; |
| 5537 | case DW_TAG_array_type: |
| 5538 | read_array_type (die, objfile, cu_header); |
| 5539 | break; |
| 5540 | case DW_TAG_pointer_type: |
| 5541 | read_tag_pointer_type (die, objfile, cu_header); |
| 5542 | break; |
| 5543 | case DW_TAG_ptr_to_member_type: |
| 5544 | read_tag_ptr_to_member_type (die, objfile, cu_header); |
| 5545 | break; |
| 5546 | case DW_TAG_reference_type: |
| 5547 | read_tag_reference_type (die, objfile, cu_header); |
| 5548 | break; |
| 5549 | case DW_TAG_const_type: |
| 5550 | read_tag_const_type (die, objfile, cu_header); |
| 5551 | break; |
| 5552 | case DW_TAG_volatile_type: |
| 5553 | read_tag_volatile_type (die, objfile, cu_header); |
| 5554 | break; |
| 5555 | case DW_TAG_string_type: |
| 5556 | read_tag_string_type (die, objfile); |
| 5557 | break; |
| 5558 | case DW_TAG_typedef: |
| 5559 | read_typedef (die, objfile, cu_header); |
| 5560 | break; |
| 5561 | case DW_TAG_base_type: |
| 5562 | read_base_type (die, objfile); |
| 5563 | break; |
| 5564 | default: |
| 5565 | complaint (&symfile_complaints, "unexepected tag in read_type_die: '%s'", |
| 5566 | dwarf_tag_name (die->tag)); |
| 5567 | break; |
| 5568 | } |
| 5569 | } |
| 5570 | |
| 5571 | static struct type * |
| 5572 | dwarf_base_type (int encoding, int size, struct objfile *objfile) |
| 5573 | { |
| 5574 | /* FIXME - this should not produce a new (struct type *) |
| 5575 | every time. It should cache base types. */ |
| 5576 | struct type *type; |
| 5577 | switch (encoding) |
| 5578 | { |
| 5579 | case DW_ATE_address: |
| 5580 | type = dwarf2_fundamental_type (objfile, FT_VOID); |
| 5581 | return type; |
| 5582 | case DW_ATE_boolean: |
| 5583 | type = dwarf2_fundamental_type (objfile, FT_BOOLEAN); |
| 5584 | return type; |
| 5585 | case DW_ATE_complex_float: |
| 5586 | if (size == 16) |
| 5587 | { |
| 5588 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_COMPLEX); |
| 5589 | } |
| 5590 | else |
| 5591 | { |
| 5592 | type = dwarf2_fundamental_type (objfile, FT_COMPLEX); |
| 5593 | } |
| 5594 | return type; |
| 5595 | case DW_ATE_float: |
| 5596 | if (size == 8) |
| 5597 | { |
| 5598 | type = dwarf2_fundamental_type (objfile, FT_DBL_PREC_FLOAT); |
| 5599 | } |
| 5600 | else |
| 5601 | { |
| 5602 | type = dwarf2_fundamental_type (objfile, FT_FLOAT); |
| 5603 | } |
| 5604 | return type; |
| 5605 | case DW_ATE_signed: |
| 5606 | switch (size) |
| 5607 | { |
| 5608 | case 1: |
| 5609 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR); |
| 5610 | break; |
| 5611 | case 2: |
| 5612 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_SHORT); |
| 5613 | break; |
| 5614 | default: |
| 5615 | case 4: |
| 5616 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER); |
| 5617 | break; |
| 5618 | } |
| 5619 | return type; |
| 5620 | case DW_ATE_signed_char: |
| 5621 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_CHAR); |
| 5622 | return type; |
| 5623 | case DW_ATE_unsigned: |
| 5624 | switch (size) |
| 5625 | { |
| 5626 | case 1: |
| 5627 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR); |
| 5628 | break; |
| 5629 | case 2: |
| 5630 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_SHORT); |
| 5631 | break; |
| 5632 | default: |
| 5633 | case 4: |
| 5634 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_INTEGER); |
| 5635 | break; |
| 5636 | } |
| 5637 | return type; |
| 5638 | case DW_ATE_unsigned_char: |
| 5639 | type = dwarf2_fundamental_type (objfile, FT_UNSIGNED_CHAR); |
| 5640 | return type; |
| 5641 | default: |
| 5642 | type = dwarf2_fundamental_type (objfile, FT_SIGNED_INTEGER); |
| 5643 | return type; |
| 5644 | } |
| 5645 | } |
| 5646 | |
| 5647 | #if 0 |
| 5648 | struct die_info * |
| 5649 | copy_die (struct die_info *old_die) |
| 5650 | { |
| 5651 | struct die_info *new_die; |
| 5652 | int i, num_attrs; |
| 5653 | |
| 5654 | new_die = (struct die_info *) xmalloc (sizeof (struct die_info)); |
| 5655 | memset (new_die, 0, sizeof (struct die_info)); |
| 5656 | |
| 5657 | new_die->tag = old_die->tag; |
| 5658 | new_die->has_children = old_die->has_children; |
| 5659 | new_die->abbrev = old_die->abbrev; |
| 5660 | new_die->offset = old_die->offset; |
| 5661 | new_die->type = NULL; |
| 5662 | |
| 5663 | num_attrs = old_die->num_attrs; |
| 5664 | new_die->num_attrs = num_attrs; |
| 5665 | new_die->attrs = (struct attribute *) |
| 5666 | xmalloc (num_attrs * sizeof (struct attribute)); |
| 5667 | |
| 5668 | for (i = 0; i < old_die->num_attrs; ++i) |
| 5669 | { |
| 5670 | new_die->attrs[i].name = old_die->attrs[i].name; |
| 5671 | new_die->attrs[i].form = old_die->attrs[i].form; |
| 5672 | new_die->attrs[i].u.addr = old_die->attrs[i].u.addr; |
| 5673 | } |
| 5674 | |
| 5675 | new_die->next = NULL; |
| 5676 | return new_die; |
| 5677 | } |
| 5678 | #endif |
| 5679 | |
| 5680 | /* Return sibling of die, NULL if no sibling. */ |
| 5681 | |
| 5682 | static struct die_info * |
| 5683 | sibling_die (struct die_info *die) |
| 5684 | { |
| 5685 | int nesting_level = 0; |
| 5686 | |
| 5687 | if (!die->has_children) |
| 5688 | { |
| 5689 | if (die->next && (die->next->tag == 0)) |
| 5690 | { |
| 5691 | return NULL; |
| 5692 | } |
| 5693 | else |
| 5694 | { |
| 5695 | return die->next; |
| 5696 | } |
| 5697 | } |
| 5698 | else |
| 5699 | { |
| 5700 | do |
| 5701 | { |
| 5702 | if (die->has_children) |
| 5703 | { |
| 5704 | nesting_level++; |
| 5705 | } |
| 5706 | if (die->tag == 0) |
| 5707 | { |
| 5708 | nesting_level--; |
| 5709 | } |
| 5710 | die = die->next; |
| 5711 | } |
| 5712 | while (nesting_level); |
| 5713 | if (die && (die->tag == 0)) |
| 5714 | { |
| 5715 | return NULL; |
| 5716 | } |
| 5717 | else |
| 5718 | { |
| 5719 | return die; |
| 5720 | } |
| 5721 | } |
| 5722 | } |
| 5723 | |
| 5724 | /* Get linkage name of a die, return NULL if not found. */ |
| 5725 | |
| 5726 | static char * |
| 5727 | dwarf2_linkage_name (struct die_info *die) |
| 5728 | { |
| 5729 | struct attribute *attr; |
| 5730 | |
| 5731 | attr = dwarf_attr (die, DW_AT_MIPS_linkage_name); |
| 5732 | if (attr && DW_STRING (attr)) |
| 5733 | return DW_STRING (attr); |
| 5734 | attr = dwarf_attr (die, DW_AT_name); |
| 5735 | if (attr && DW_STRING (attr)) |
| 5736 | return DW_STRING (attr); |
| 5737 | return NULL; |
| 5738 | } |
| 5739 | |
| 5740 | /* Get name of a die, return NULL if not found. */ |
| 5741 | |
| 5742 | static char * |
| 5743 | dwarf2_name (struct die_info *die) |
| 5744 | { |
| 5745 | struct attribute *attr; |
| 5746 | |
| 5747 | attr = dwarf_attr (die, DW_AT_name); |
| 5748 | if (attr && DW_STRING (attr)) |
| 5749 | return DW_STRING (attr); |
| 5750 | return NULL; |
| 5751 | } |
| 5752 | |
| 5753 | /* Return the die that this die in an extension of, or NULL if there |
| 5754 | is none. */ |
| 5755 | |
| 5756 | static struct die_info * |
| 5757 | dwarf2_extension (struct die_info *die) |
| 5758 | { |
| 5759 | struct attribute *attr; |
| 5760 | struct die_info *extension_die; |
| 5761 | unsigned int ref; |
| 5762 | |
| 5763 | attr = dwarf_attr (die, DW_AT_extension); |
| 5764 | if (attr == NULL) |
| 5765 | return NULL; |
| 5766 | |
| 5767 | ref = dwarf2_get_ref_die_offset (attr); |
| 5768 | extension_die = follow_die_ref (ref); |
| 5769 | if (!extension_die) |
| 5770 | { |
| 5771 | error ("Dwarf Error: Cannot find referent at offset %d.", ref); |
| 5772 | } |
| 5773 | |
| 5774 | return extension_die; |
| 5775 | } |
| 5776 | |
| 5777 | /* Convert a DIE tag into its string name. */ |
| 5778 | |
| 5779 | static char * |
| 5780 | dwarf_tag_name (register unsigned tag) |
| 5781 | { |
| 5782 | switch (tag) |
| 5783 | { |
| 5784 | case DW_TAG_padding: |
| 5785 | return "DW_TAG_padding"; |
| 5786 | case DW_TAG_array_type: |
| 5787 | return "DW_TAG_array_type"; |
| 5788 | case DW_TAG_class_type: |
| 5789 | return "DW_TAG_class_type"; |
| 5790 | case DW_TAG_entry_point: |
| 5791 | return "DW_TAG_entry_point"; |
| 5792 | case DW_TAG_enumeration_type: |
| 5793 | return "DW_TAG_enumeration_type"; |
| 5794 | case DW_TAG_formal_parameter: |
| 5795 | return "DW_TAG_formal_parameter"; |
| 5796 | case DW_TAG_imported_declaration: |
| 5797 | return "DW_TAG_imported_declaration"; |
| 5798 | case DW_TAG_label: |
| 5799 | return "DW_TAG_label"; |
| 5800 | case DW_TAG_lexical_block: |
| 5801 | return "DW_TAG_lexical_block"; |
| 5802 | case DW_TAG_member: |
| 5803 | return "DW_TAG_member"; |
| 5804 | case DW_TAG_pointer_type: |
| 5805 | return "DW_TAG_pointer_type"; |
| 5806 | case DW_TAG_reference_type: |
| 5807 | return "DW_TAG_reference_type"; |
| 5808 | case DW_TAG_compile_unit: |
| 5809 | return "DW_TAG_compile_unit"; |
| 5810 | case DW_TAG_string_type: |
| 5811 | return "DW_TAG_string_type"; |
| 5812 | case DW_TAG_structure_type: |
| 5813 | return "DW_TAG_structure_type"; |
| 5814 | case DW_TAG_subroutine_type: |
| 5815 | return "DW_TAG_subroutine_type"; |
| 5816 | case DW_TAG_typedef: |
| 5817 | return "DW_TAG_typedef"; |
| 5818 | case DW_TAG_union_type: |
| 5819 | return "DW_TAG_union_type"; |
| 5820 | case DW_TAG_unspecified_parameters: |
| 5821 | return "DW_TAG_unspecified_parameters"; |
| 5822 | case DW_TAG_variant: |
| 5823 | return "DW_TAG_variant"; |
| 5824 | case DW_TAG_common_block: |
| 5825 | return "DW_TAG_common_block"; |
| 5826 | case DW_TAG_common_inclusion: |
| 5827 | return "DW_TAG_common_inclusion"; |
| 5828 | case DW_TAG_inheritance: |
| 5829 | return "DW_TAG_inheritance"; |
| 5830 | case DW_TAG_inlined_subroutine: |
| 5831 | return "DW_TAG_inlined_subroutine"; |
| 5832 | case DW_TAG_module: |
| 5833 | return "DW_TAG_module"; |
| 5834 | case DW_TAG_ptr_to_member_type: |
| 5835 | return "DW_TAG_ptr_to_member_type"; |
| 5836 | case DW_TAG_set_type: |
| 5837 | return "DW_TAG_set_type"; |
| 5838 | case DW_TAG_subrange_type: |
| 5839 | return "DW_TAG_subrange_type"; |
| 5840 | case DW_TAG_with_stmt: |
| 5841 | return "DW_TAG_with_stmt"; |
| 5842 | case DW_TAG_access_declaration: |
| 5843 | return "DW_TAG_access_declaration"; |
| 5844 | case DW_TAG_base_type: |
| 5845 | return "DW_TAG_base_type"; |
| 5846 | case DW_TAG_catch_block: |
| 5847 | return "DW_TAG_catch_block"; |
| 5848 | case DW_TAG_const_type: |
| 5849 | return "DW_TAG_const_type"; |
| 5850 | case DW_TAG_constant: |
| 5851 | return "DW_TAG_constant"; |
| 5852 | case DW_TAG_enumerator: |
| 5853 | return "DW_TAG_enumerator"; |
| 5854 | case DW_TAG_file_type: |
| 5855 | return "DW_TAG_file_type"; |
| 5856 | case DW_TAG_friend: |
| 5857 | return "DW_TAG_friend"; |
| 5858 | case DW_TAG_namelist: |
| 5859 | return "DW_TAG_namelist"; |
| 5860 | case DW_TAG_namelist_item: |
| 5861 | return "DW_TAG_namelist_item"; |
| 5862 | case DW_TAG_packed_type: |
| 5863 | return "DW_TAG_packed_type"; |
| 5864 | case DW_TAG_subprogram: |
| 5865 | return "DW_TAG_subprogram"; |
| 5866 | case DW_TAG_template_type_param: |
| 5867 | return "DW_TAG_template_type_param"; |
| 5868 | case DW_TAG_template_value_param: |
| 5869 | return "DW_TAG_template_value_param"; |
| 5870 | case DW_TAG_thrown_type: |
| 5871 | return "DW_TAG_thrown_type"; |
| 5872 | case DW_TAG_try_block: |
| 5873 | return "DW_TAG_try_block"; |
| 5874 | case DW_TAG_variant_part: |
| 5875 | return "DW_TAG_variant_part"; |
| 5876 | case DW_TAG_variable: |
| 5877 | return "DW_TAG_variable"; |
| 5878 | case DW_TAG_volatile_type: |
| 5879 | return "DW_TAG_volatile_type"; |
| 5880 | case DW_TAG_dwarf_procedure: |
| 5881 | return "DW_TAG_dwarf_procedure"; |
| 5882 | case DW_TAG_restrict_type: |
| 5883 | return "DW_TAG_restrict_type"; |
| 5884 | case DW_TAG_interface_type: |
| 5885 | return "DW_TAG_interface_type"; |
| 5886 | case DW_TAG_namespace: |
| 5887 | return "DW_TAG_namespace"; |
| 5888 | case DW_TAG_imported_module: |
| 5889 | return "DW_TAG_imported_module"; |
| 5890 | case DW_TAG_unspecified_type: |
| 5891 | return "DW_TAG_unspecified_type"; |
| 5892 | case DW_TAG_partial_unit: |
| 5893 | return "DW_TAG_partial_unit"; |
| 5894 | case DW_TAG_imported_unit: |
| 5895 | return "DW_TAG_imported_unit"; |
| 5896 | case DW_TAG_MIPS_loop: |
| 5897 | return "DW_TAG_MIPS_loop"; |
| 5898 | case DW_TAG_format_label: |
| 5899 | return "DW_TAG_format_label"; |
| 5900 | case DW_TAG_function_template: |
| 5901 | return "DW_TAG_function_template"; |
| 5902 | case DW_TAG_class_template: |
| 5903 | return "DW_TAG_class_template"; |
| 5904 | default: |
| 5905 | return "DW_TAG_<unknown>"; |
| 5906 | } |
| 5907 | } |
| 5908 | |
| 5909 | /* Convert a DWARF attribute code into its string name. */ |
| 5910 | |
| 5911 | static char * |
| 5912 | dwarf_attr_name (register unsigned attr) |
| 5913 | { |
| 5914 | switch (attr) |
| 5915 | { |
| 5916 | case DW_AT_sibling: |
| 5917 | return "DW_AT_sibling"; |
| 5918 | case DW_AT_location: |
| 5919 | return "DW_AT_location"; |
| 5920 | case DW_AT_name: |
| 5921 | return "DW_AT_name"; |
| 5922 | case DW_AT_ordering: |
| 5923 | return "DW_AT_ordering"; |
| 5924 | case DW_AT_subscr_data: |
| 5925 | return "DW_AT_subscr_data"; |
| 5926 | case DW_AT_byte_size: |
| 5927 | return "DW_AT_byte_size"; |
| 5928 | case DW_AT_bit_offset: |
| 5929 | return "DW_AT_bit_offset"; |
| 5930 | case DW_AT_bit_size: |
| 5931 | return "DW_AT_bit_size"; |
| 5932 | case DW_AT_element_list: |
| 5933 | return "DW_AT_element_list"; |
| 5934 | case DW_AT_stmt_list: |
| 5935 | return "DW_AT_stmt_list"; |
| 5936 | case DW_AT_low_pc: |
| 5937 | return "DW_AT_low_pc"; |
| 5938 | case DW_AT_high_pc: |
| 5939 | return "DW_AT_high_pc"; |
| 5940 | case DW_AT_language: |
| 5941 | return "DW_AT_language"; |
| 5942 | case DW_AT_member: |
| 5943 | return "DW_AT_member"; |
| 5944 | case DW_AT_discr: |
| 5945 | return "DW_AT_discr"; |
| 5946 | case DW_AT_discr_value: |
| 5947 | return "DW_AT_discr_value"; |
| 5948 | case DW_AT_visibility: |
| 5949 | return "DW_AT_visibility"; |
| 5950 | case DW_AT_import: |
| 5951 | return "DW_AT_import"; |
| 5952 | case DW_AT_string_length: |
| 5953 | return "DW_AT_string_length"; |
| 5954 | case DW_AT_common_reference: |
| 5955 | return "DW_AT_common_reference"; |
| 5956 | case DW_AT_comp_dir: |
| 5957 | return "DW_AT_comp_dir"; |
| 5958 | case DW_AT_const_value: |
| 5959 | return "DW_AT_const_value"; |
| 5960 | case DW_AT_containing_type: |
| 5961 | return "DW_AT_containing_type"; |
| 5962 | case DW_AT_default_value: |
| 5963 | return "DW_AT_default_value"; |
| 5964 | case DW_AT_inline: |
| 5965 | return "DW_AT_inline"; |
| 5966 | case DW_AT_is_optional: |
| 5967 | return "DW_AT_is_optional"; |
| 5968 | case DW_AT_lower_bound: |
| 5969 | return "DW_AT_lower_bound"; |
| 5970 | case DW_AT_producer: |
| 5971 | return "DW_AT_producer"; |
| 5972 | case DW_AT_prototyped: |
| 5973 | return "DW_AT_prototyped"; |
| 5974 | case DW_AT_return_addr: |
| 5975 | return "DW_AT_return_addr"; |
| 5976 | case DW_AT_start_scope: |
| 5977 | return "DW_AT_start_scope"; |
| 5978 | case DW_AT_stride_size: |
| 5979 | return "DW_AT_stride_size"; |
| 5980 | case DW_AT_upper_bound: |
| 5981 | return "DW_AT_upper_bound"; |
| 5982 | case DW_AT_abstract_origin: |
| 5983 | return "DW_AT_abstract_origin"; |
| 5984 | case DW_AT_accessibility: |
| 5985 | return "DW_AT_accessibility"; |
| 5986 | case DW_AT_address_class: |
| 5987 | return "DW_AT_address_class"; |
| 5988 | case DW_AT_artificial: |
| 5989 | return "DW_AT_artificial"; |
| 5990 | case DW_AT_base_types: |
| 5991 | return "DW_AT_base_types"; |
| 5992 | case DW_AT_calling_convention: |
| 5993 | return "DW_AT_calling_convention"; |
| 5994 | case DW_AT_count: |
| 5995 | return "DW_AT_count"; |
| 5996 | case DW_AT_data_member_location: |
| 5997 | return "DW_AT_data_member_location"; |
| 5998 | case DW_AT_decl_column: |
| 5999 | return "DW_AT_decl_column"; |
| 6000 | case DW_AT_decl_file: |
| 6001 | return "DW_AT_decl_file"; |
| 6002 | case DW_AT_decl_line: |
| 6003 | return "DW_AT_decl_line"; |
| 6004 | case DW_AT_declaration: |
| 6005 | return "DW_AT_declaration"; |
| 6006 | case DW_AT_discr_list: |
| 6007 | return "DW_AT_discr_list"; |
| 6008 | case DW_AT_encoding: |
| 6009 | return "DW_AT_encoding"; |
| 6010 | case DW_AT_external: |
| 6011 | return "DW_AT_external"; |
| 6012 | case DW_AT_frame_base: |
| 6013 | return "DW_AT_frame_base"; |
| 6014 | case DW_AT_friend: |
| 6015 | return "DW_AT_friend"; |
| 6016 | case DW_AT_identifier_case: |
| 6017 | return "DW_AT_identifier_case"; |
| 6018 | case DW_AT_macro_info: |
| 6019 | return "DW_AT_macro_info"; |
| 6020 | case DW_AT_namelist_items: |
| 6021 | return "DW_AT_namelist_items"; |
| 6022 | case DW_AT_priority: |
| 6023 | return "DW_AT_priority"; |
| 6024 | case DW_AT_segment: |
| 6025 | return "DW_AT_segment"; |
| 6026 | case DW_AT_specification: |
| 6027 | return "DW_AT_specification"; |
| 6028 | case DW_AT_static_link: |
| 6029 | return "DW_AT_static_link"; |
| 6030 | case DW_AT_type: |
| 6031 | return "DW_AT_type"; |
| 6032 | case DW_AT_use_location: |
| 6033 | return "DW_AT_use_location"; |
| 6034 | case DW_AT_variable_parameter: |
| 6035 | return "DW_AT_variable_parameter"; |
| 6036 | case DW_AT_virtuality: |
| 6037 | return "DW_AT_virtuality"; |
| 6038 | case DW_AT_vtable_elem_location: |
| 6039 | return "DW_AT_vtable_elem_location"; |
| 6040 | case DW_AT_allocated: |
| 6041 | return "DW_AT_allocated"; |
| 6042 | case DW_AT_associated: |
| 6043 | return "DW_AT_associated"; |
| 6044 | case DW_AT_data_location: |
| 6045 | return "DW_AT_data_location"; |
| 6046 | case DW_AT_stride: |
| 6047 | return "DW_AT_stride"; |
| 6048 | case DW_AT_entry_pc: |
| 6049 | return "DW_AT_entry_pc"; |
| 6050 | case DW_AT_use_UTF8: |
| 6051 | return "DW_AT_use_UTF8"; |
| 6052 | case DW_AT_extension: |
| 6053 | return "DW_AT_extension"; |
| 6054 | case DW_AT_ranges: |
| 6055 | return "DW_AT_ranges"; |
| 6056 | case DW_AT_trampoline: |
| 6057 | return "DW_AT_trampoline"; |
| 6058 | case DW_AT_call_column: |
| 6059 | return "DW_AT_call_column"; |
| 6060 | case DW_AT_call_file: |
| 6061 | return "DW_AT_call_file"; |
| 6062 | case DW_AT_call_line: |
| 6063 | return "DW_AT_call_line"; |
| 6064 | #ifdef MIPS |
| 6065 | case DW_AT_MIPS_fde: |
| 6066 | return "DW_AT_MIPS_fde"; |
| 6067 | case DW_AT_MIPS_loop_begin: |
| 6068 | return "DW_AT_MIPS_loop_begin"; |
| 6069 | case DW_AT_MIPS_tail_loop_begin: |
| 6070 | return "DW_AT_MIPS_tail_loop_begin"; |
| 6071 | case DW_AT_MIPS_epilog_begin: |
| 6072 | return "DW_AT_MIPS_epilog_begin"; |
| 6073 | case DW_AT_MIPS_loop_unroll_factor: |
| 6074 | return "DW_AT_MIPS_loop_unroll_factor"; |
| 6075 | case DW_AT_MIPS_software_pipeline_depth: |
| 6076 | return "DW_AT_MIPS_software_pipeline_depth"; |
| 6077 | case DW_AT_MIPS_linkage_name: |
| 6078 | return "DW_AT_MIPS_linkage_name"; |
| 6079 | #endif |
| 6080 | |
| 6081 | case DW_AT_sf_names: |
| 6082 | return "DW_AT_sf_names"; |
| 6083 | case DW_AT_src_info: |
| 6084 | return "DW_AT_src_info"; |
| 6085 | case DW_AT_mac_info: |
| 6086 | return "DW_AT_mac_info"; |
| 6087 | case DW_AT_src_coords: |
| 6088 | return "DW_AT_src_coords"; |
| 6089 | case DW_AT_body_begin: |
| 6090 | return "DW_AT_body_begin"; |
| 6091 | case DW_AT_body_end: |
| 6092 | return "DW_AT_body_end"; |
| 6093 | case DW_AT_GNU_vector: |
| 6094 | return "DW_AT_GNU_vector"; |
| 6095 | default: |
| 6096 | return "DW_AT_<unknown>"; |
| 6097 | } |
| 6098 | } |
| 6099 | |
| 6100 | /* Convert a DWARF value form code into its string name. */ |
| 6101 | |
| 6102 | static char * |
| 6103 | dwarf_form_name (register unsigned form) |
| 6104 | { |
| 6105 | switch (form) |
| 6106 | { |
| 6107 | case DW_FORM_addr: |
| 6108 | return "DW_FORM_addr"; |
| 6109 | case DW_FORM_block2: |
| 6110 | return "DW_FORM_block2"; |
| 6111 | case DW_FORM_block4: |
| 6112 | return "DW_FORM_block4"; |
| 6113 | case DW_FORM_data2: |
| 6114 | return "DW_FORM_data2"; |
| 6115 | case DW_FORM_data4: |
| 6116 | return "DW_FORM_data4"; |
| 6117 | case DW_FORM_data8: |
| 6118 | return "DW_FORM_data8"; |
| 6119 | case DW_FORM_string: |
| 6120 | return "DW_FORM_string"; |
| 6121 | case DW_FORM_block: |
| 6122 | return "DW_FORM_block"; |
| 6123 | case DW_FORM_block1: |
| 6124 | return "DW_FORM_block1"; |
| 6125 | case DW_FORM_data1: |
| 6126 | return "DW_FORM_data1"; |
| 6127 | case DW_FORM_flag: |
| 6128 | return "DW_FORM_flag"; |
| 6129 | case DW_FORM_sdata: |
| 6130 | return "DW_FORM_sdata"; |
| 6131 | case DW_FORM_strp: |
| 6132 | return "DW_FORM_strp"; |
| 6133 | case DW_FORM_udata: |
| 6134 | return "DW_FORM_udata"; |
| 6135 | case DW_FORM_ref_addr: |
| 6136 | return "DW_FORM_ref_addr"; |
| 6137 | case DW_FORM_ref1: |
| 6138 | return "DW_FORM_ref1"; |
| 6139 | case DW_FORM_ref2: |
| 6140 | return "DW_FORM_ref2"; |
| 6141 | case DW_FORM_ref4: |
| 6142 | return "DW_FORM_ref4"; |
| 6143 | case DW_FORM_ref8: |
| 6144 | return "DW_FORM_ref8"; |
| 6145 | case DW_FORM_ref_udata: |
| 6146 | return "DW_FORM_ref_udata"; |
| 6147 | case DW_FORM_indirect: |
| 6148 | return "DW_FORM_indirect"; |
| 6149 | default: |
| 6150 | return "DW_FORM_<unknown>"; |
| 6151 | } |
| 6152 | } |
| 6153 | |
| 6154 | /* Convert a DWARF stack opcode into its string name. */ |
| 6155 | |
| 6156 | static char * |
| 6157 | dwarf_stack_op_name (register unsigned op) |
| 6158 | { |
| 6159 | switch (op) |
| 6160 | { |
| 6161 | case DW_OP_addr: |
| 6162 | return "DW_OP_addr"; |
| 6163 | case DW_OP_deref: |
| 6164 | return "DW_OP_deref"; |
| 6165 | case DW_OP_const1u: |
| 6166 | return "DW_OP_const1u"; |
| 6167 | case DW_OP_const1s: |
| 6168 | return "DW_OP_const1s"; |
| 6169 | case DW_OP_const2u: |
| 6170 | return "DW_OP_const2u"; |
| 6171 | case DW_OP_const2s: |
| 6172 | return "DW_OP_const2s"; |
| 6173 | case DW_OP_const4u: |
| 6174 | return "DW_OP_const4u"; |
| 6175 | case DW_OP_const4s: |
| 6176 | return "DW_OP_const4s"; |
| 6177 | case DW_OP_const8u: |
| 6178 | return "DW_OP_const8u"; |
| 6179 | case DW_OP_const8s: |
| 6180 | return "DW_OP_const8s"; |
| 6181 | case DW_OP_constu: |
| 6182 | return "DW_OP_constu"; |
| 6183 | case DW_OP_consts: |
| 6184 | return "DW_OP_consts"; |
| 6185 | case DW_OP_dup: |
| 6186 | return "DW_OP_dup"; |
| 6187 | case DW_OP_drop: |
| 6188 | return "DW_OP_drop"; |
| 6189 | case DW_OP_over: |
| 6190 | return "DW_OP_over"; |
| 6191 | case DW_OP_pick: |
| 6192 | return "DW_OP_pick"; |
| 6193 | case DW_OP_swap: |
| 6194 | return "DW_OP_swap"; |
| 6195 | case DW_OP_rot: |
| 6196 | return "DW_OP_rot"; |
| 6197 | case DW_OP_xderef: |
| 6198 | return "DW_OP_xderef"; |
| 6199 | case DW_OP_abs: |
| 6200 | return "DW_OP_abs"; |
| 6201 | case DW_OP_and: |
| 6202 | return "DW_OP_and"; |
| 6203 | case DW_OP_div: |
| 6204 | return "DW_OP_div"; |
| 6205 | case DW_OP_minus: |
| 6206 | return "DW_OP_minus"; |
| 6207 | case DW_OP_mod: |
| 6208 | return "DW_OP_mod"; |
| 6209 | case DW_OP_mul: |
| 6210 | return "DW_OP_mul"; |
| 6211 | case DW_OP_neg: |
| 6212 | return "DW_OP_neg"; |
| 6213 | case DW_OP_not: |
| 6214 | return "DW_OP_not"; |
| 6215 | case DW_OP_or: |
| 6216 | return "DW_OP_or"; |
| 6217 | case DW_OP_plus: |
| 6218 | return "DW_OP_plus"; |
| 6219 | case DW_OP_plus_uconst: |
| 6220 | return "DW_OP_plus_uconst"; |
| 6221 | case DW_OP_shl: |
| 6222 | return "DW_OP_shl"; |
| 6223 | case DW_OP_shr: |
| 6224 | return "DW_OP_shr"; |
| 6225 | case DW_OP_shra: |
| 6226 | return "DW_OP_shra"; |
| 6227 | case DW_OP_xor: |
| 6228 | return "DW_OP_xor"; |
| 6229 | case DW_OP_bra: |
| 6230 | return "DW_OP_bra"; |
| 6231 | case DW_OP_eq: |
| 6232 | return "DW_OP_eq"; |
| 6233 | case DW_OP_ge: |
| 6234 | return "DW_OP_ge"; |
| 6235 | case DW_OP_gt: |
| 6236 | return "DW_OP_gt"; |
| 6237 | case DW_OP_le: |
| 6238 | return "DW_OP_le"; |
| 6239 | case DW_OP_lt: |
| 6240 | return "DW_OP_lt"; |
| 6241 | case DW_OP_ne: |
| 6242 | return "DW_OP_ne"; |
| 6243 | case DW_OP_skip: |
| 6244 | return "DW_OP_skip"; |
| 6245 | case DW_OP_lit0: |
| 6246 | return "DW_OP_lit0"; |
| 6247 | case DW_OP_lit1: |
| 6248 | return "DW_OP_lit1"; |
| 6249 | case DW_OP_lit2: |
| 6250 | return "DW_OP_lit2"; |
| 6251 | case DW_OP_lit3: |
| 6252 | return "DW_OP_lit3"; |
| 6253 | case DW_OP_lit4: |
| 6254 | return "DW_OP_lit4"; |
| 6255 | case DW_OP_lit5: |
| 6256 | return "DW_OP_lit5"; |
| 6257 | case DW_OP_lit6: |
| 6258 | return "DW_OP_lit6"; |
| 6259 | case DW_OP_lit7: |
| 6260 | return "DW_OP_lit7"; |
| 6261 | case DW_OP_lit8: |
| 6262 | return "DW_OP_lit8"; |
| 6263 | case DW_OP_lit9: |
| 6264 | return "DW_OP_lit9"; |
| 6265 | case DW_OP_lit10: |
| 6266 | return "DW_OP_lit10"; |
| 6267 | case DW_OP_lit11: |
| 6268 | return "DW_OP_lit11"; |
| 6269 | case DW_OP_lit12: |
| 6270 | return "DW_OP_lit12"; |
| 6271 | case DW_OP_lit13: |
| 6272 | return "DW_OP_lit13"; |
| 6273 | case DW_OP_lit14: |
| 6274 | return "DW_OP_lit14"; |
| 6275 | case DW_OP_lit15: |
| 6276 | return "DW_OP_lit15"; |
| 6277 | case DW_OP_lit16: |
| 6278 | return "DW_OP_lit16"; |
| 6279 | case DW_OP_lit17: |
| 6280 | return "DW_OP_lit17"; |
| 6281 | case DW_OP_lit18: |
| 6282 | return "DW_OP_lit18"; |
| 6283 | case DW_OP_lit19: |
| 6284 | return "DW_OP_lit19"; |
| 6285 | case DW_OP_lit20: |
| 6286 | return "DW_OP_lit20"; |
| 6287 | case DW_OP_lit21: |
| 6288 | return "DW_OP_lit21"; |
| 6289 | case DW_OP_lit22: |
| 6290 | return "DW_OP_lit22"; |
| 6291 | case DW_OP_lit23: |
| 6292 | return "DW_OP_lit23"; |
| 6293 | case DW_OP_lit24: |
| 6294 | return "DW_OP_lit24"; |
| 6295 | case DW_OP_lit25: |
| 6296 | return "DW_OP_lit25"; |
| 6297 | case DW_OP_lit26: |
| 6298 | return "DW_OP_lit26"; |
| 6299 | case DW_OP_lit27: |
| 6300 | return "DW_OP_lit27"; |
| 6301 | case DW_OP_lit28: |
| 6302 | return "DW_OP_lit28"; |
| 6303 | case DW_OP_lit29: |
| 6304 | return "DW_OP_lit29"; |
| 6305 | case DW_OP_lit30: |
| 6306 | return "DW_OP_lit30"; |
| 6307 | case DW_OP_lit31: |
| 6308 | return "DW_OP_lit31"; |
| 6309 | case DW_OP_reg0: |
| 6310 | return "DW_OP_reg0"; |
| 6311 | case DW_OP_reg1: |
| 6312 | return "DW_OP_reg1"; |
| 6313 | case DW_OP_reg2: |
| 6314 | return "DW_OP_reg2"; |
| 6315 | case DW_OP_reg3: |
| 6316 | return "DW_OP_reg3"; |
| 6317 | case DW_OP_reg4: |
| 6318 | return "DW_OP_reg4"; |
| 6319 | case DW_OP_reg5: |
| 6320 | return "DW_OP_reg5"; |
| 6321 | case DW_OP_reg6: |
| 6322 | return "DW_OP_reg6"; |
| 6323 | case DW_OP_reg7: |
| 6324 | return "DW_OP_reg7"; |
| 6325 | case DW_OP_reg8: |
| 6326 | return "DW_OP_reg8"; |
| 6327 | case DW_OP_reg9: |
| 6328 | return "DW_OP_reg9"; |
| 6329 | case DW_OP_reg10: |
| 6330 | return "DW_OP_reg10"; |
| 6331 | case DW_OP_reg11: |
| 6332 | return "DW_OP_reg11"; |
| 6333 | case DW_OP_reg12: |
| 6334 | return "DW_OP_reg12"; |
| 6335 | case DW_OP_reg13: |
| 6336 | return "DW_OP_reg13"; |
| 6337 | case DW_OP_reg14: |
| 6338 | return "DW_OP_reg14"; |
| 6339 | case DW_OP_reg15: |
| 6340 | return "DW_OP_reg15"; |
| 6341 | case DW_OP_reg16: |
| 6342 | return "DW_OP_reg16"; |
| 6343 | case DW_OP_reg17: |
| 6344 | return "DW_OP_reg17"; |
| 6345 | case DW_OP_reg18: |
| 6346 | return "DW_OP_reg18"; |
| 6347 | case DW_OP_reg19: |
| 6348 | return "DW_OP_reg19"; |
| 6349 | case DW_OP_reg20: |
| 6350 | return "DW_OP_reg20"; |
| 6351 | case DW_OP_reg21: |
| 6352 | return "DW_OP_reg21"; |
| 6353 | case DW_OP_reg22: |
| 6354 | return "DW_OP_reg22"; |
| 6355 | case DW_OP_reg23: |
| 6356 | return "DW_OP_reg23"; |
| 6357 | case DW_OP_reg24: |
| 6358 | return "DW_OP_reg24"; |
| 6359 | case DW_OP_reg25: |
| 6360 | return "DW_OP_reg25"; |
| 6361 | case DW_OP_reg26: |
| 6362 | return "DW_OP_reg26"; |
| 6363 | case DW_OP_reg27: |
| 6364 | return "DW_OP_reg27"; |
| 6365 | case DW_OP_reg28: |
| 6366 | return "DW_OP_reg28"; |
| 6367 | case DW_OP_reg29: |
| 6368 | return "DW_OP_reg29"; |
| 6369 | case DW_OP_reg30: |
| 6370 | return "DW_OP_reg30"; |
| 6371 | case DW_OP_reg31: |
| 6372 | return "DW_OP_reg31"; |
| 6373 | case DW_OP_breg0: |
| 6374 | return "DW_OP_breg0"; |
| 6375 | case DW_OP_breg1: |
| 6376 | return "DW_OP_breg1"; |
| 6377 | case DW_OP_breg2: |
| 6378 | return "DW_OP_breg2"; |
| 6379 | case DW_OP_breg3: |
| 6380 | return "DW_OP_breg3"; |
| 6381 | case DW_OP_breg4: |
| 6382 | return "DW_OP_breg4"; |
| 6383 | case DW_OP_breg5: |
| 6384 | return "DW_OP_breg5"; |
| 6385 | case DW_OP_breg6: |
| 6386 | return "DW_OP_breg6"; |
| 6387 | case DW_OP_breg7: |
| 6388 | return "DW_OP_breg7"; |
| 6389 | case DW_OP_breg8: |
| 6390 | return "DW_OP_breg8"; |
| 6391 | case DW_OP_breg9: |
| 6392 | return "DW_OP_breg9"; |
| 6393 | case DW_OP_breg10: |
| 6394 | return "DW_OP_breg10"; |
| 6395 | case DW_OP_breg11: |
| 6396 | return "DW_OP_breg11"; |
| 6397 | case DW_OP_breg12: |
| 6398 | return "DW_OP_breg12"; |
| 6399 | case DW_OP_breg13: |
| 6400 | return "DW_OP_breg13"; |
| 6401 | case DW_OP_breg14: |
| 6402 | return "DW_OP_breg14"; |
| 6403 | case DW_OP_breg15: |
| 6404 | return "DW_OP_breg15"; |
| 6405 | case DW_OP_breg16: |
| 6406 | return "DW_OP_breg16"; |
| 6407 | case DW_OP_breg17: |
| 6408 | return "DW_OP_breg17"; |
| 6409 | case DW_OP_breg18: |
| 6410 | return "DW_OP_breg18"; |
| 6411 | case DW_OP_breg19: |
| 6412 | return "DW_OP_breg19"; |
| 6413 | case DW_OP_breg20: |
| 6414 | return "DW_OP_breg20"; |
| 6415 | case DW_OP_breg21: |
| 6416 | return "DW_OP_breg21"; |
| 6417 | case DW_OP_breg22: |
| 6418 | return "DW_OP_breg22"; |
| 6419 | case DW_OP_breg23: |
| 6420 | return "DW_OP_breg23"; |
| 6421 | case DW_OP_breg24: |
| 6422 | return "DW_OP_breg24"; |
| 6423 | case DW_OP_breg25: |
| 6424 | return "DW_OP_breg25"; |
| 6425 | case DW_OP_breg26: |
| 6426 | return "DW_OP_breg26"; |
| 6427 | case DW_OP_breg27: |
| 6428 | return "DW_OP_breg27"; |
| 6429 | case DW_OP_breg28: |
| 6430 | return "DW_OP_breg28"; |
| 6431 | case DW_OP_breg29: |
| 6432 | return "DW_OP_breg29"; |
| 6433 | case DW_OP_breg30: |
| 6434 | return "DW_OP_breg30"; |
| 6435 | case DW_OP_breg31: |
| 6436 | return "DW_OP_breg31"; |
| 6437 | case DW_OP_regx: |
| 6438 | return "DW_OP_regx"; |
| 6439 | case DW_OP_fbreg: |
| 6440 | return "DW_OP_fbreg"; |
| 6441 | case DW_OP_bregx: |
| 6442 | return "DW_OP_bregx"; |
| 6443 | case DW_OP_piece: |
| 6444 | return "DW_OP_piece"; |
| 6445 | case DW_OP_deref_size: |
| 6446 | return "DW_OP_deref_size"; |
| 6447 | case DW_OP_xderef_size: |
| 6448 | return "DW_OP_xderef_size"; |
| 6449 | case DW_OP_nop: |
| 6450 | return "DW_OP_nop"; |
| 6451 | /* DWARF 3 extensions. */ |
| 6452 | case DW_OP_push_object_address: |
| 6453 | return "DW_OP_push_object_address"; |
| 6454 | case DW_OP_call2: |
| 6455 | return "DW_OP_call2"; |
| 6456 | case DW_OP_call4: |
| 6457 | return "DW_OP_call4"; |
| 6458 | case DW_OP_call_ref: |
| 6459 | return "DW_OP_call_ref"; |
| 6460 | /* GNU extensions. */ |
| 6461 | case DW_OP_GNU_push_tls_address: |
| 6462 | return "DW_OP_GNU_push_tls_address"; |
| 6463 | default: |
| 6464 | return "OP_<unknown>"; |
| 6465 | } |
| 6466 | } |
| 6467 | |
| 6468 | static char * |
| 6469 | dwarf_bool_name (unsigned mybool) |
| 6470 | { |
| 6471 | if (mybool) |
| 6472 | return "TRUE"; |
| 6473 | else |
| 6474 | return "FALSE"; |
| 6475 | } |
| 6476 | |
| 6477 | /* Convert a DWARF type code into its string name. */ |
| 6478 | |
| 6479 | static char * |
| 6480 | dwarf_type_encoding_name (register unsigned enc) |
| 6481 | { |
| 6482 | switch (enc) |
| 6483 | { |
| 6484 | case DW_ATE_address: |
| 6485 | return "DW_ATE_address"; |
| 6486 | case DW_ATE_boolean: |
| 6487 | return "DW_ATE_boolean"; |
| 6488 | case DW_ATE_complex_float: |
| 6489 | return "DW_ATE_complex_float"; |
| 6490 | case DW_ATE_float: |
| 6491 | return "DW_ATE_float"; |
| 6492 | case DW_ATE_signed: |
| 6493 | return "DW_ATE_signed"; |
| 6494 | case DW_ATE_signed_char: |
| 6495 | return "DW_ATE_signed_char"; |
| 6496 | case DW_ATE_unsigned: |
| 6497 | return "DW_ATE_unsigned"; |
| 6498 | case DW_ATE_unsigned_char: |
| 6499 | return "DW_ATE_unsigned_char"; |
| 6500 | case DW_ATE_imaginary_float: |
| 6501 | return "DW_ATE_imaginary_float"; |
| 6502 | default: |
| 6503 | return "DW_ATE_<unknown>"; |
| 6504 | } |
| 6505 | } |
| 6506 | |
| 6507 | /* Convert a DWARF call frame info operation to its string name. */ |
| 6508 | |
| 6509 | #if 0 |
| 6510 | static char * |
| 6511 | dwarf_cfi_name (register unsigned cfi_opc) |
| 6512 | { |
| 6513 | switch (cfi_opc) |
| 6514 | { |
| 6515 | case DW_CFA_advance_loc: |
| 6516 | return "DW_CFA_advance_loc"; |
| 6517 | case DW_CFA_offset: |
| 6518 | return "DW_CFA_offset"; |
| 6519 | case DW_CFA_restore: |
| 6520 | return "DW_CFA_restore"; |
| 6521 | case DW_CFA_nop: |
| 6522 | return "DW_CFA_nop"; |
| 6523 | case DW_CFA_set_loc: |
| 6524 | return "DW_CFA_set_loc"; |
| 6525 | case DW_CFA_advance_loc1: |
| 6526 | return "DW_CFA_advance_loc1"; |
| 6527 | case DW_CFA_advance_loc2: |
| 6528 | return "DW_CFA_advance_loc2"; |
| 6529 | case DW_CFA_advance_loc4: |
| 6530 | return "DW_CFA_advance_loc4"; |
| 6531 | case DW_CFA_offset_extended: |
| 6532 | return "DW_CFA_offset_extended"; |
| 6533 | case DW_CFA_restore_extended: |
| 6534 | return "DW_CFA_restore_extended"; |
| 6535 | case DW_CFA_undefined: |
| 6536 | return "DW_CFA_undefined"; |
| 6537 | case DW_CFA_same_value: |
| 6538 | return "DW_CFA_same_value"; |
| 6539 | case DW_CFA_register: |
| 6540 | return "DW_CFA_register"; |
| 6541 | case DW_CFA_remember_state: |
| 6542 | return "DW_CFA_remember_state"; |
| 6543 | case DW_CFA_restore_state: |
| 6544 | return "DW_CFA_restore_state"; |
| 6545 | case DW_CFA_def_cfa: |
| 6546 | return "DW_CFA_def_cfa"; |
| 6547 | case DW_CFA_def_cfa_register: |
| 6548 | return "DW_CFA_def_cfa_register"; |
| 6549 | case DW_CFA_def_cfa_offset: |
| 6550 | return "DW_CFA_def_cfa_offset"; |
| 6551 | |
| 6552 | /* DWARF 3 */ |
| 6553 | case DW_CFA_def_cfa_expression: |
| 6554 | return "DW_CFA_def_cfa_expression"; |
| 6555 | case DW_CFA_expression: |
| 6556 | return "DW_CFA_expression"; |
| 6557 | case DW_CFA_offset_extended_sf: |
| 6558 | return "DW_CFA_offset_extended_sf"; |
| 6559 | case DW_CFA_def_cfa_sf: |
| 6560 | return "DW_CFA_def_cfa_sf"; |
| 6561 | case DW_CFA_def_cfa_offset_sf: |
| 6562 | return "DW_CFA_def_cfa_offset_sf"; |
| 6563 | |
| 6564 | /* SGI/MIPS specific */ |
| 6565 | case DW_CFA_MIPS_advance_loc8: |
| 6566 | return "DW_CFA_MIPS_advance_loc8"; |
| 6567 | |
| 6568 | /* GNU extensions */ |
| 6569 | case DW_CFA_GNU_window_save: |
| 6570 | return "DW_CFA_GNU_window_save"; |
| 6571 | case DW_CFA_GNU_args_size: |
| 6572 | return "DW_CFA_GNU_args_size"; |
| 6573 | case DW_CFA_GNU_negative_offset_extended: |
| 6574 | return "DW_CFA_GNU_negative_offset_extended"; |
| 6575 | |
| 6576 | default: |
| 6577 | return "DW_CFA_<unknown>"; |
| 6578 | } |
| 6579 | } |
| 6580 | #endif |
| 6581 | |
| 6582 | static void |
| 6583 | dump_die (struct die_info *die) |
| 6584 | { |
| 6585 | unsigned int i; |
| 6586 | |
| 6587 | fprintf_unfiltered (gdb_stderr, "Die: %s (abbrev = %d, offset = %d)\n", |
| 6588 | dwarf_tag_name (die->tag), die->abbrev, die->offset); |
| 6589 | fprintf_unfiltered (gdb_stderr, "\thas children: %s\n", |
| 6590 | dwarf_bool_name (die->has_children)); |
| 6591 | |
| 6592 | fprintf_unfiltered (gdb_stderr, "\tattributes:\n"); |
| 6593 | for (i = 0; i < die->num_attrs; ++i) |
| 6594 | { |
| 6595 | fprintf_unfiltered (gdb_stderr, "\t\t%s (%s) ", |
| 6596 | dwarf_attr_name (die->attrs[i].name), |
| 6597 | dwarf_form_name (die->attrs[i].form)); |
| 6598 | switch (die->attrs[i].form) |
| 6599 | { |
| 6600 | case DW_FORM_ref_addr: |
| 6601 | case DW_FORM_addr: |
| 6602 | fprintf_unfiltered (gdb_stderr, "address: "); |
| 6603 | print_address_numeric (DW_ADDR (&die->attrs[i]), 1, gdb_stderr); |
| 6604 | break; |
| 6605 | case DW_FORM_block2: |
| 6606 | case DW_FORM_block4: |
| 6607 | case DW_FORM_block: |
| 6608 | case DW_FORM_block1: |
| 6609 | fprintf_unfiltered (gdb_stderr, "block: size %d", DW_BLOCK (&die->attrs[i])->size); |
| 6610 | break; |
| 6611 | case DW_FORM_data1: |
| 6612 | case DW_FORM_data2: |
| 6613 | case DW_FORM_data4: |
| 6614 | case DW_FORM_data8: |
| 6615 | case DW_FORM_ref1: |
| 6616 | case DW_FORM_ref2: |
| 6617 | case DW_FORM_ref4: |
| 6618 | case DW_FORM_udata: |
| 6619 | case DW_FORM_sdata: |
| 6620 | fprintf_unfiltered (gdb_stderr, "constant: %ld", DW_UNSND (&die->attrs[i])); |
| 6621 | break; |
| 6622 | case DW_FORM_string: |
| 6623 | case DW_FORM_strp: |
| 6624 | fprintf_unfiltered (gdb_stderr, "string: \"%s\"", |
| 6625 | DW_STRING (&die->attrs[i]) |
| 6626 | ? DW_STRING (&die->attrs[i]) : ""); |
| 6627 | break; |
| 6628 | case DW_FORM_flag: |
| 6629 | if (DW_UNSND (&die->attrs[i])) |
| 6630 | fprintf_unfiltered (gdb_stderr, "flag: TRUE"); |
| 6631 | else |
| 6632 | fprintf_unfiltered (gdb_stderr, "flag: FALSE"); |
| 6633 | break; |
| 6634 | case DW_FORM_indirect: |
| 6635 | /* the reader will have reduced the indirect form to |
| 6636 | the "base form" so this form should not occur */ |
| 6637 | fprintf_unfiltered (gdb_stderr, "unexpected attribute form: DW_FORM_indirect"); |
| 6638 | break; |
| 6639 | default: |
| 6640 | fprintf_unfiltered (gdb_stderr, "unsupported attribute form: %d.", |
| 6641 | die->attrs[i].form); |
| 6642 | } |
| 6643 | fprintf_unfiltered (gdb_stderr, "\n"); |
| 6644 | } |
| 6645 | } |
| 6646 | |
| 6647 | static void |
| 6648 | dump_die_list (struct die_info *die) |
| 6649 | { |
| 6650 | while (die) |
| 6651 | { |
| 6652 | dump_die (die); |
| 6653 | die = die->next; |
| 6654 | } |
| 6655 | } |
| 6656 | |
| 6657 | static void |
| 6658 | store_in_ref_table (unsigned int offset, struct die_info *die) |
| 6659 | { |
| 6660 | int h; |
| 6661 | struct die_info *old; |
| 6662 | |
| 6663 | h = (offset % REF_HASH_SIZE); |
| 6664 | old = die_ref_table[h]; |
| 6665 | die->next_ref = old; |
| 6666 | die_ref_table[h] = die; |
| 6667 | } |
| 6668 | |
| 6669 | |
| 6670 | static void |
| 6671 | dwarf2_empty_hash_tables (void) |
| 6672 | { |
| 6673 | memset (die_ref_table, 0, sizeof (die_ref_table)); |
| 6674 | } |
| 6675 | |
| 6676 | static unsigned int |
| 6677 | dwarf2_get_ref_die_offset (struct attribute *attr) |
| 6678 | { |
| 6679 | unsigned int result = 0; |
| 6680 | |
| 6681 | switch (attr->form) |
| 6682 | { |
| 6683 | case DW_FORM_ref_addr: |
| 6684 | result = DW_ADDR (attr); |
| 6685 | break; |
| 6686 | case DW_FORM_ref1: |
| 6687 | case DW_FORM_ref2: |
| 6688 | case DW_FORM_ref4: |
| 6689 | case DW_FORM_ref8: |
| 6690 | case DW_FORM_ref_udata: |
| 6691 | result = cu_header_offset + DW_UNSND (attr); |
| 6692 | break; |
| 6693 | default: |
| 6694 | complaint (&symfile_complaints, |
| 6695 | "unsupported die ref attribute form: '%s'", |
| 6696 | dwarf_form_name (attr->form)); |
| 6697 | } |
| 6698 | return result; |
| 6699 | } |
| 6700 | |
| 6701 | static struct die_info * |
| 6702 | follow_die_ref (unsigned int offset) |
| 6703 | { |
| 6704 | struct die_info *die; |
| 6705 | int h; |
| 6706 | |
| 6707 | h = (offset % REF_HASH_SIZE); |
| 6708 | die = die_ref_table[h]; |
| 6709 | while (die) |
| 6710 | { |
| 6711 | if (die->offset == offset) |
| 6712 | { |
| 6713 | return die; |
| 6714 | } |
| 6715 | die = die->next_ref; |
| 6716 | } |
| 6717 | return NULL; |
| 6718 | } |
| 6719 | |
| 6720 | static struct type * |
| 6721 | dwarf2_fundamental_type (struct objfile *objfile, int typeid) |
| 6722 | { |
| 6723 | if (typeid < 0 || typeid >= FT_NUM_MEMBERS) |
| 6724 | { |
| 6725 | error ("Dwarf Error: internal error - invalid fundamental type id %d [in module %s]", |
| 6726 | typeid, objfile->name); |
| 6727 | } |
| 6728 | |
| 6729 | /* Look for this particular type in the fundamental type vector. If |
| 6730 | one is not found, create and install one appropriate for the |
| 6731 | current language and the current target machine. */ |
| 6732 | |
| 6733 | if (ftypes[typeid] == NULL) |
| 6734 | { |
| 6735 | ftypes[typeid] = cu_language_defn->la_fund_type (objfile, typeid); |
| 6736 | } |
| 6737 | |
| 6738 | return (ftypes[typeid]); |
| 6739 | } |
| 6740 | |
| 6741 | /* Decode simple location descriptions. |
| 6742 | Given a pointer to a dwarf block that defines a location, compute |
| 6743 | the location and return the value. |
| 6744 | |
| 6745 | FIXME: This is a kludge until we figure out a better |
| 6746 | way to handle the location descriptions. |
| 6747 | Gdb's design does not mesh well with the DWARF2 notion of a location |
| 6748 | computing interpreter, which is a shame because the flexibility goes unused. |
| 6749 | FIXME: Implement more operations as necessary. |
| 6750 | |
| 6751 | A location description containing no operations indicates that the |
| 6752 | object is optimized out. The global optimized_out flag is set for |
| 6753 | those, the return value is meaningless. |
| 6754 | |
| 6755 | When the result is a register number, the global isreg flag is set, |
| 6756 | otherwise it is cleared. |
| 6757 | |
| 6758 | When the result is a base register offset, the global offreg flag is set |
| 6759 | and the register number is returned in basereg, otherwise it is cleared. |
| 6760 | |
| 6761 | When the DW_OP_fbreg operation is encountered without a corresponding |
| 6762 | DW_AT_frame_base attribute, the global islocal flag is set. |
| 6763 | Hopefully the machine dependent code knows how to set up a virtual |
| 6764 | frame pointer for the local references. |
| 6765 | |
| 6766 | Note that stack[0] is unused except as a default error return. |
| 6767 | Note that stack overflow is not yet handled. */ |
| 6768 | |
| 6769 | static CORE_ADDR |
| 6770 | decode_locdesc (struct dwarf_block *blk, struct objfile *objfile, |
| 6771 | const struct comp_unit_head *cu_header) |
| 6772 | { |
| 6773 | int i; |
| 6774 | int size = blk->size; |
| 6775 | char *data = blk->data; |
| 6776 | CORE_ADDR stack[64]; |
| 6777 | int stacki; |
| 6778 | unsigned int bytes_read, unsnd; |
| 6779 | unsigned char op; |
| 6780 | |
| 6781 | i = 0; |
| 6782 | stacki = 0; |
| 6783 | stack[stacki] = 0; |
| 6784 | isreg = 0; |
| 6785 | offreg = 0; |
| 6786 | isderef = 0; |
| 6787 | islocal = 0; |
| 6788 | is_thread_local = 0; |
| 6789 | optimized_out = 1; |
| 6790 | |
| 6791 | while (i < size) |
| 6792 | { |
| 6793 | optimized_out = 0; |
| 6794 | op = data[i++]; |
| 6795 | switch (op) |
| 6796 | { |
| 6797 | case DW_OP_lit0: |
| 6798 | case DW_OP_lit1: |
| 6799 | case DW_OP_lit2: |
| 6800 | case DW_OP_lit3: |
| 6801 | case DW_OP_lit4: |
| 6802 | case DW_OP_lit5: |
| 6803 | case DW_OP_lit6: |
| 6804 | case DW_OP_lit7: |
| 6805 | case DW_OP_lit8: |
| 6806 | case DW_OP_lit9: |
| 6807 | case DW_OP_lit10: |
| 6808 | case DW_OP_lit11: |
| 6809 | case DW_OP_lit12: |
| 6810 | case DW_OP_lit13: |
| 6811 | case DW_OP_lit14: |
| 6812 | case DW_OP_lit15: |
| 6813 | case DW_OP_lit16: |
| 6814 | case DW_OP_lit17: |
| 6815 | case DW_OP_lit18: |
| 6816 | case DW_OP_lit19: |
| 6817 | case DW_OP_lit20: |
| 6818 | case DW_OP_lit21: |
| 6819 | case DW_OP_lit22: |
| 6820 | case DW_OP_lit23: |
| 6821 | case DW_OP_lit24: |
| 6822 | case DW_OP_lit25: |
| 6823 | case DW_OP_lit26: |
| 6824 | case DW_OP_lit27: |
| 6825 | case DW_OP_lit28: |
| 6826 | case DW_OP_lit29: |
| 6827 | case DW_OP_lit30: |
| 6828 | case DW_OP_lit31: |
| 6829 | stack[++stacki] = op - DW_OP_lit0; |
| 6830 | break; |
| 6831 | |
| 6832 | case DW_OP_reg0: |
| 6833 | case DW_OP_reg1: |
| 6834 | case DW_OP_reg2: |
| 6835 | case DW_OP_reg3: |
| 6836 | case DW_OP_reg4: |
| 6837 | case DW_OP_reg5: |
| 6838 | case DW_OP_reg6: |
| 6839 | case DW_OP_reg7: |
| 6840 | case DW_OP_reg8: |
| 6841 | case DW_OP_reg9: |
| 6842 | case DW_OP_reg10: |
| 6843 | case DW_OP_reg11: |
| 6844 | case DW_OP_reg12: |
| 6845 | case DW_OP_reg13: |
| 6846 | case DW_OP_reg14: |
| 6847 | case DW_OP_reg15: |
| 6848 | case DW_OP_reg16: |
| 6849 | case DW_OP_reg17: |
| 6850 | case DW_OP_reg18: |
| 6851 | case DW_OP_reg19: |
| 6852 | case DW_OP_reg20: |
| 6853 | case DW_OP_reg21: |
| 6854 | case DW_OP_reg22: |
| 6855 | case DW_OP_reg23: |
| 6856 | case DW_OP_reg24: |
| 6857 | case DW_OP_reg25: |
| 6858 | case DW_OP_reg26: |
| 6859 | case DW_OP_reg27: |
| 6860 | case DW_OP_reg28: |
| 6861 | case DW_OP_reg29: |
| 6862 | case DW_OP_reg30: |
| 6863 | case DW_OP_reg31: |
| 6864 | isreg = 1; |
| 6865 | stack[++stacki] = op - DW_OP_reg0; |
| 6866 | break; |
| 6867 | |
| 6868 | case DW_OP_regx: |
| 6869 | isreg = 1; |
| 6870 | unsnd = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
| 6871 | i += bytes_read; |
| 6872 | stack[++stacki] = unsnd; |
| 6873 | break; |
| 6874 | |
| 6875 | case DW_OP_breg0: |
| 6876 | case DW_OP_breg1: |
| 6877 | case DW_OP_breg2: |
| 6878 | case DW_OP_breg3: |
| 6879 | case DW_OP_breg4: |
| 6880 | case DW_OP_breg5: |
| 6881 | case DW_OP_breg6: |
| 6882 | case DW_OP_breg7: |
| 6883 | case DW_OP_breg8: |
| 6884 | case DW_OP_breg9: |
| 6885 | case DW_OP_breg10: |
| 6886 | case DW_OP_breg11: |
| 6887 | case DW_OP_breg12: |
| 6888 | case DW_OP_breg13: |
| 6889 | case DW_OP_breg14: |
| 6890 | case DW_OP_breg15: |
| 6891 | case DW_OP_breg16: |
| 6892 | case DW_OP_breg17: |
| 6893 | case DW_OP_breg18: |
| 6894 | case DW_OP_breg19: |
| 6895 | case DW_OP_breg20: |
| 6896 | case DW_OP_breg21: |
| 6897 | case DW_OP_breg22: |
| 6898 | case DW_OP_breg23: |
| 6899 | case DW_OP_breg24: |
| 6900 | case DW_OP_breg25: |
| 6901 | case DW_OP_breg26: |
| 6902 | case DW_OP_breg27: |
| 6903 | case DW_OP_breg28: |
| 6904 | case DW_OP_breg29: |
| 6905 | case DW_OP_breg30: |
| 6906 | case DW_OP_breg31: |
| 6907 | offreg = 1; |
| 6908 | basereg = op - DW_OP_breg0; |
| 6909 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 6910 | i += bytes_read; |
| 6911 | break; |
| 6912 | |
| 6913 | case DW_OP_bregx: |
| 6914 | offreg = 1; |
| 6915 | basereg = read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
| 6916 | i += bytes_read; |
| 6917 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 6918 | i += bytes_read; |
| 6919 | break; |
| 6920 | |
| 6921 | case DW_OP_fbreg: |
| 6922 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 6923 | i += bytes_read; |
| 6924 | if (frame_base_reg >= 0) |
| 6925 | { |
| 6926 | offreg = 1; |
| 6927 | basereg = frame_base_reg; |
| 6928 | stack[stacki] += frame_base_offset; |
| 6929 | } |
| 6930 | else |
| 6931 | { |
| 6932 | complaint (&symfile_complaints, |
| 6933 | "DW_AT_frame_base missing for DW_OP_fbreg"); |
| 6934 | islocal = 1; |
| 6935 | } |
| 6936 | break; |
| 6937 | |
| 6938 | case DW_OP_addr: |
| 6939 | stack[++stacki] = read_address (objfile->obfd, &data[i], |
| 6940 | cu_header, &bytes_read); |
| 6941 | i += bytes_read; |
| 6942 | break; |
| 6943 | |
| 6944 | case DW_OP_const1u: |
| 6945 | stack[++stacki] = read_1_byte (objfile->obfd, &data[i]); |
| 6946 | i += 1; |
| 6947 | break; |
| 6948 | |
| 6949 | case DW_OP_const1s: |
| 6950 | stack[++stacki] = read_1_signed_byte (objfile->obfd, &data[i]); |
| 6951 | i += 1; |
| 6952 | break; |
| 6953 | |
| 6954 | case DW_OP_const2u: |
| 6955 | stack[++stacki] = read_2_bytes (objfile->obfd, &data[i]); |
| 6956 | i += 2; |
| 6957 | break; |
| 6958 | |
| 6959 | case DW_OP_const2s: |
| 6960 | stack[++stacki] = read_2_signed_bytes (objfile->obfd, &data[i]); |
| 6961 | i += 2; |
| 6962 | break; |
| 6963 | |
| 6964 | case DW_OP_const4u: |
| 6965 | stack[++stacki] = read_4_bytes (objfile->obfd, &data[i]); |
| 6966 | i += 4; |
| 6967 | break; |
| 6968 | |
| 6969 | case DW_OP_const4s: |
| 6970 | stack[++stacki] = read_4_signed_bytes (objfile->obfd, &data[i]); |
| 6971 | i += 4; |
| 6972 | break; |
| 6973 | |
| 6974 | case DW_OP_constu: |
| 6975 | stack[++stacki] = read_unsigned_leb128 (NULL, (data + i), |
| 6976 | &bytes_read); |
| 6977 | i += bytes_read; |
| 6978 | break; |
| 6979 | |
| 6980 | case DW_OP_consts: |
| 6981 | stack[++stacki] = read_signed_leb128 (NULL, (data + i), &bytes_read); |
| 6982 | i += bytes_read; |
| 6983 | break; |
| 6984 | |
| 6985 | case DW_OP_dup: |
| 6986 | stack[stacki + 1] = stack[stacki]; |
| 6987 | stacki++; |
| 6988 | break; |
| 6989 | |
| 6990 | case DW_OP_plus: |
| 6991 | stack[stacki - 1] += stack[stacki]; |
| 6992 | stacki--; |
| 6993 | break; |
| 6994 | |
| 6995 | case DW_OP_plus_uconst: |
| 6996 | stack[stacki] += read_unsigned_leb128 (NULL, (data + i), &bytes_read); |
| 6997 | i += bytes_read; |
| 6998 | break; |
| 6999 | |
| 7000 | case DW_OP_minus: |
| 7001 | stack[stacki - 1] -= stack[stacki]; |
| 7002 | stacki--; |
| 7003 | break; |
| 7004 | |
| 7005 | case DW_OP_deref: |
| 7006 | isderef = 1; |
| 7007 | /* If we're not the last op, then we definitely can't encode |
| 7008 | this using GDB's address_class enum. */ |
| 7009 | if (i < size) |
| 7010 | dwarf2_complex_location_expr_complaint (); |
| 7011 | break; |
| 7012 | |
| 7013 | case DW_OP_GNU_push_tls_address: |
| 7014 | is_thread_local = 1; |
| 7015 | /* The top of the stack has the offset from the beginning |
| 7016 | of the thread control block at which the variable is located. */ |
| 7017 | /* Nothing should follow this operator, so the top of stack would |
| 7018 | be returned. */ |
| 7019 | if (i < size) |
| 7020 | dwarf2_complex_location_expr_complaint (); |
| 7021 | break; |
| 7022 | |
| 7023 | default: |
| 7024 | complaint (&symfile_complaints, "unsupported stack op: '%s'", |
| 7025 | dwarf_stack_op_name (op)); |
| 7026 | return (stack[stacki]); |
| 7027 | } |
| 7028 | } |
| 7029 | return (stack[stacki]); |
| 7030 | } |
| 7031 | |
| 7032 | /* memory allocation interface */ |
| 7033 | |
| 7034 | /* ARGSUSED */ |
| 7035 | static void |
| 7036 | dwarf2_free_tmp_obstack (void *ignore) |
| 7037 | { |
| 7038 | obstack_free (&dwarf2_tmp_obstack, NULL); |
| 7039 | } |
| 7040 | |
| 7041 | static struct dwarf_block * |
| 7042 | dwarf_alloc_block (void) |
| 7043 | { |
| 7044 | struct dwarf_block *blk; |
| 7045 | |
| 7046 | blk = (struct dwarf_block *) |
| 7047 | obstack_alloc (&dwarf2_tmp_obstack, sizeof (struct dwarf_block)); |
| 7048 | return (blk); |
| 7049 | } |
| 7050 | |
| 7051 | static struct abbrev_info * |
| 7052 | dwarf_alloc_abbrev (void) |
| 7053 | { |
| 7054 | struct abbrev_info *abbrev; |
| 7055 | |
| 7056 | abbrev = (struct abbrev_info *) xmalloc (sizeof (struct abbrev_info)); |
| 7057 | memset (abbrev, 0, sizeof (struct abbrev_info)); |
| 7058 | return (abbrev); |
| 7059 | } |
| 7060 | |
| 7061 | static struct die_info * |
| 7062 | dwarf_alloc_die (void) |
| 7063 | { |
| 7064 | struct die_info *die; |
| 7065 | |
| 7066 | die = (struct die_info *) xmalloc (sizeof (struct die_info)); |
| 7067 | memset (die, 0, sizeof (struct die_info)); |
| 7068 | return (die); |
| 7069 | } |
| 7070 | |
| 7071 | \f |
| 7072 | /* Macro support. */ |
| 7073 | |
| 7074 | |
| 7075 | /* Return the full name of file number I in *LH's file name table. |
| 7076 | Use COMP_DIR as the name of the current directory of the |
| 7077 | compilation. The result is allocated using xmalloc; the caller is |
| 7078 | responsible for freeing it. */ |
| 7079 | static char * |
| 7080 | file_full_name (int file, struct line_header *lh, const char *comp_dir) |
| 7081 | { |
| 7082 | struct file_entry *fe = &lh->file_names[file - 1]; |
| 7083 | |
| 7084 | if (IS_ABSOLUTE_PATH (fe->name)) |
| 7085 | return xstrdup (fe->name); |
| 7086 | else |
| 7087 | { |
| 7088 | const char *dir; |
| 7089 | int dir_len; |
| 7090 | char *full_name; |
| 7091 | |
| 7092 | if (fe->dir_index) |
| 7093 | dir = lh->include_dirs[fe->dir_index - 1]; |
| 7094 | else |
| 7095 | dir = comp_dir; |
| 7096 | |
| 7097 | if (dir) |
| 7098 | { |
| 7099 | dir_len = strlen (dir); |
| 7100 | full_name = xmalloc (dir_len + 1 + strlen (fe->name) + 1); |
| 7101 | strcpy (full_name, dir); |
| 7102 | full_name[dir_len] = '/'; |
| 7103 | strcpy (full_name + dir_len + 1, fe->name); |
| 7104 | return full_name; |
| 7105 | } |
| 7106 | else |
| 7107 | return xstrdup (fe->name); |
| 7108 | } |
| 7109 | } |
| 7110 | |
| 7111 | |
| 7112 | static struct macro_source_file * |
| 7113 | macro_start_file (int file, int line, |
| 7114 | struct macro_source_file *current_file, |
| 7115 | const char *comp_dir, |
| 7116 | struct line_header *lh, struct objfile *objfile) |
| 7117 | { |
| 7118 | /* The full name of this source file. */ |
| 7119 | char *full_name = file_full_name (file, lh, comp_dir); |
| 7120 | |
| 7121 | /* We don't create a macro table for this compilation unit |
| 7122 | at all until we actually get a filename. */ |
| 7123 | if (! pending_macros) |
| 7124 | pending_macros = new_macro_table (&objfile->symbol_obstack, |
| 7125 | objfile->macro_cache); |
| 7126 | |
| 7127 | if (! current_file) |
| 7128 | /* If we have no current file, then this must be the start_file |
| 7129 | directive for the compilation unit's main source file. */ |
| 7130 | current_file = macro_set_main (pending_macros, full_name); |
| 7131 | else |
| 7132 | current_file = macro_include (current_file, line, full_name); |
| 7133 | |
| 7134 | xfree (full_name); |
| 7135 | |
| 7136 | return current_file; |
| 7137 | } |
| 7138 | |
| 7139 | |
| 7140 | /* Copy the LEN characters at BUF to a xmalloc'ed block of memory, |
| 7141 | followed by a null byte. */ |
| 7142 | static char * |
| 7143 | copy_string (const char *buf, int len) |
| 7144 | { |
| 7145 | char *s = xmalloc (len + 1); |
| 7146 | memcpy (s, buf, len); |
| 7147 | s[len] = '\0'; |
| 7148 | |
| 7149 | return s; |
| 7150 | } |
| 7151 | |
| 7152 | |
| 7153 | static const char * |
| 7154 | consume_improper_spaces (const char *p, const char *body) |
| 7155 | { |
| 7156 | if (*p == ' ') |
| 7157 | { |
| 7158 | complaint (&symfile_complaints, |
| 7159 | "macro definition contains spaces in formal argument list:\n`%s'", |
| 7160 | body); |
| 7161 | |
| 7162 | while (*p == ' ') |
| 7163 | p++; |
| 7164 | } |
| 7165 | |
| 7166 | return p; |
| 7167 | } |
| 7168 | |
| 7169 | |
| 7170 | static void |
| 7171 | parse_macro_definition (struct macro_source_file *file, int line, |
| 7172 | const char *body) |
| 7173 | { |
| 7174 | const char *p; |
| 7175 | |
| 7176 | /* The body string takes one of two forms. For object-like macro |
| 7177 | definitions, it should be: |
| 7178 | |
| 7179 | <macro name> " " <definition> |
| 7180 | |
| 7181 | For function-like macro definitions, it should be: |
| 7182 | |
| 7183 | <macro name> "() " <definition> |
| 7184 | or |
| 7185 | <macro name> "(" <arg name> ( "," <arg name> ) * ") " <definition> |
| 7186 | |
| 7187 | Spaces may appear only where explicitly indicated, and in the |
| 7188 | <definition>. |
| 7189 | |
| 7190 | The Dwarf 2 spec says that an object-like macro's name is always |
| 7191 | followed by a space, but versions of GCC around March 2002 omit |
| 7192 | the space when the macro's definition is the empty string. |
| 7193 | |
| 7194 | The Dwarf 2 spec says that there should be no spaces between the |
| 7195 | formal arguments in a function-like macro's formal argument list, |
| 7196 | but versions of GCC around March 2002 include spaces after the |
| 7197 | commas. */ |
| 7198 | |
| 7199 | |
| 7200 | /* Find the extent of the macro name. The macro name is terminated |
| 7201 | by either a space or null character (for an object-like macro) or |
| 7202 | an opening paren (for a function-like macro). */ |
| 7203 | for (p = body; *p; p++) |
| 7204 | if (*p == ' ' || *p == '(') |
| 7205 | break; |
| 7206 | |
| 7207 | if (*p == ' ' || *p == '\0') |
| 7208 | { |
| 7209 | /* It's an object-like macro. */ |
| 7210 | int name_len = p - body; |
| 7211 | char *name = copy_string (body, name_len); |
| 7212 | const char *replacement; |
| 7213 | |
| 7214 | if (*p == ' ') |
| 7215 | replacement = body + name_len + 1; |
| 7216 | else |
| 7217 | { |
| 7218 | dwarf2_macro_malformed_definition_complaint (body); |
| 7219 | replacement = body + name_len; |
| 7220 | } |
| 7221 | |
| 7222 | macro_define_object (file, line, name, replacement); |
| 7223 | |
| 7224 | xfree (name); |
| 7225 | } |
| 7226 | else if (*p == '(') |
| 7227 | { |
| 7228 | /* It's a function-like macro. */ |
| 7229 | char *name = copy_string (body, p - body); |
| 7230 | int argc = 0; |
| 7231 | int argv_size = 1; |
| 7232 | char **argv = xmalloc (argv_size * sizeof (*argv)); |
| 7233 | |
| 7234 | p++; |
| 7235 | |
| 7236 | p = consume_improper_spaces (p, body); |
| 7237 | |
| 7238 | /* Parse the formal argument list. */ |
| 7239 | while (*p && *p != ')') |
| 7240 | { |
| 7241 | /* Find the extent of the current argument name. */ |
| 7242 | const char *arg_start = p; |
| 7243 | |
| 7244 | while (*p && *p != ',' && *p != ')' && *p != ' ') |
| 7245 | p++; |
| 7246 | |
| 7247 | if (! *p || p == arg_start) |
| 7248 | dwarf2_macro_malformed_definition_complaint (body); |
| 7249 | else |
| 7250 | { |
| 7251 | /* Make sure argv has room for the new argument. */ |
| 7252 | if (argc >= argv_size) |
| 7253 | { |
| 7254 | argv_size *= 2; |
| 7255 | argv = xrealloc (argv, argv_size * sizeof (*argv)); |
| 7256 | } |
| 7257 | |
| 7258 | argv[argc++] = copy_string (arg_start, p - arg_start); |
| 7259 | } |
| 7260 | |
| 7261 | p = consume_improper_spaces (p, body); |
| 7262 | |
| 7263 | /* Consume the comma, if present. */ |
| 7264 | if (*p == ',') |
| 7265 | { |
| 7266 | p++; |
| 7267 | |
| 7268 | p = consume_improper_spaces (p, body); |
| 7269 | } |
| 7270 | } |
| 7271 | |
| 7272 | if (*p == ')') |
| 7273 | { |
| 7274 | p++; |
| 7275 | |
| 7276 | if (*p == ' ') |
| 7277 | /* Perfectly formed definition, no complaints. */ |
| 7278 | macro_define_function (file, line, name, |
| 7279 | argc, (const char **) argv, |
| 7280 | p + 1); |
| 7281 | else if (*p == '\0') |
| 7282 | { |
| 7283 | /* Complain, but do define it. */ |
| 7284 | dwarf2_macro_malformed_definition_complaint (body); |
| 7285 | macro_define_function (file, line, name, |
| 7286 | argc, (const char **) argv, |
| 7287 | p); |
| 7288 | } |
| 7289 | else |
| 7290 | /* Just complain. */ |
| 7291 | dwarf2_macro_malformed_definition_complaint (body); |
| 7292 | } |
| 7293 | else |
| 7294 | /* Just complain. */ |
| 7295 | dwarf2_macro_malformed_definition_complaint (body); |
| 7296 | |
| 7297 | xfree (name); |
| 7298 | { |
| 7299 | int i; |
| 7300 | |
| 7301 | for (i = 0; i < argc; i++) |
| 7302 | xfree (argv[i]); |
| 7303 | } |
| 7304 | xfree (argv); |
| 7305 | } |
| 7306 | else |
| 7307 | dwarf2_macro_malformed_definition_complaint (body); |
| 7308 | } |
| 7309 | |
| 7310 | |
| 7311 | static void |
| 7312 | dwarf_decode_macros (struct line_header *lh, unsigned int offset, |
| 7313 | char *comp_dir, bfd *abfd, |
| 7314 | const struct comp_unit_head *cu_header, |
| 7315 | struct objfile *objfile) |
| 7316 | { |
| 7317 | char *mac_ptr, *mac_end; |
| 7318 | struct macro_source_file *current_file = 0; |
| 7319 | |
| 7320 | if (dwarf_macinfo_buffer == NULL) |
| 7321 | { |
| 7322 | complaint (&symfile_complaints, "missing .debug_macinfo section"); |
| 7323 | return; |
| 7324 | } |
| 7325 | |
| 7326 | mac_ptr = dwarf_macinfo_buffer + offset; |
| 7327 | mac_end = dwarf_macinfo_buffer + dwarf_macinfo_size; |
| 7328 | |
| 7329 | for (;;) |
| 7330 | { |
| 7331 | enum dwarf_macinfo_record_type macinfo_type; |
| 7332 | |
| 7333 | /* Do we at least have room for a macinfo type byte? */ |
| 7334 | if (mac_ptr >= mac_end) |
| 7335 | { |
| 7336 | dwarf2_macros_too_long_complaint (); |
| 7337 | return; |
| 7338 | } |
| 7339 | |
| 7340 | macinfo_type = read_1_byte (abfd, mac_ptr); |
| 7341 | mac_ptr++; |
| 7342 | |
| 7343 | switch (macinfo_type) |
| 7344 | { |
| 7345 | /* A zero macinfo type indicates the end of the macro |
| 7346 | information. */ |
| 7347 | case 0: |
| 7348 | return; |
| 7349 | |
| 7350 | case DW_MACINFO_define: |
| 7351 | case DW_MACINFO_undef: |
| 7352 | { |
| 7353 | int bytes_read; |
| 7354 | int line; |
| 7355 | char *body; |
| 7356 | |
| 7357 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 7358 | mac_ptr += bytes_read; |
| 7359 | body = read_string (abfd, mac_ptr, &bytes_read); |
| 7360 | mac_ptr += bytes_read; |
| 7361 | |
| 7362 | if (! current_file) |
| 7363 | complaint (&symfile_complaints, |
| 7364 | "debug info gives macro %s outside of any file: %s", |
| 7365 | macinfo_type == |
| 7366 | DW_MACINFO_define ? "definition" : macinfo_type == |
| 7367 | DW_MACINFO_undef ? "undefinition" : |
| 7368 | "something-or-other", body); |
| 7369 | else |
| 7370 | { |
| 7371 | if (macinfo_type == DW_MACINFO_define) |
| 7372 | parse_macro_definition (current_file, line, body); |
| 7373 | else if (macinfo_type == DW_MACINFO_undef) |
| 7374 | macro_undef (current_file, line, body); |
| 7375 | } |
| 7376 | } |
| 7377 | break; |
| 7378 | |
| 7379 | case DW_MACINFO_start_file: |
| 7380 | { |
| 7381 | int bytes_read; |
| 7382 | int line, file; |
| 7383 | |
| 7384 | line = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 7385 | mac_ptr += bytes_read; |
| 7386 | file = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 7387 | mac_ptr += bytes_read; |
| 7388 | |
| 7389 | current_file = macro_start_file (file, line, |
| 7390 | current_file, comp_dir, |
| 7391 | lh, objfile); |
| 7392 | } |
| 7393 | break; |
| 7394 | |
| 7395 | case DW_MACINFO_end_file: |
| 7396 | if (! current_file) |
| 7397 | complaint (&symfile_complaints, |
| 7398 | "macro debug info has an unmatched `close_file' directive"); |
| 7399 | else |
| 7400 | { |
| 7401 | current_file = current_file->included_by; |
| 7402 | if (! current_file) |
| 7403 | { |
| 7404 | enum dwarf_macinfo_record_type next_type; |
| 7405 | |
| 7406 | /* GCC circa March 2002 doesn't produce the zero |
| 7407 | type byte marking the end of the compilation |
| 7408 | unit. Complain if it's not there, but exit no |
| 7409 | matter what. */ |
| 7410 | |
| 7411 | /* Do we at least have room for a macinfo type byte? */ |
| 7412 | if (mac_ptr >= mac_end) |
| 7413 | { |
| 7414 | dwarf2_macros_too_long_complaint (); |
| 7415 | return; |
| 7416 | } |
| 7417 | |
| 7418 | /* We don't increment mac_ptr here, so this is just |
| 7419 | a look-ahead. */ |
| 7420 | next_type = read_1_byte (abfd, mac_ptr); |
| 7421 | if (next_type != 0) |
| 7422 | complaint (&symfile_complaints, |
| 7423 | "no terminating 0-type entry for macros in `.debug_macinfo' section"); |
| 7424 | |
| 7425 | return; |
| 7426 | } |
| 7427 | } |
| 7428 | break; |
| 7429 | |
| 7430 | case DW_MACINFO_vendor_ext: |
| 7431 | { |
| 7432 | int bytes_read; |
| 7433 | int constant; |
| 7434 | char *string; |
| 7435 | |
| 7436 | constant = read_unsigned_leb128 (abfd, mac_ptr, &bytes_read); |
| 7437 | mac_ptr += bytes_read; |
| 7438 | string = read_string (abfd, mac_ptr, &bytes_read); |
| 7439 | mac_ptr += bytes_read; |
| 7440 | |
| 7441 | /* We don't recognize any vendor extensions. */ |
| 7442 | } |
| 7443 | break; |
| 7444 | } |
| 7445 | } |
| 7446 | } |
| 7447 | |
| 7448 | /* Check if the attribute's form is a DW_FORM_block* |
| 7449 | if so return true else false. */ |
| 7450 | static int |
| 7451 | attr_form_is_block (struct attribute *attr) |
| 7452 | { |
| 7453 | return (attr == NULL ? 0 : |
| 7454 | attr->form == DW_FORM_block1 |
| 7455 | || attr->form == DW_FORM_block2 |
| 7456 | || attr->form == DW_FORM_block4 |
| 7457 | || attr->form == DW_FORM_block); |
| 7458 | } |
| 7459 | |
| 7460 | static void |
| 7461 | dwarf2_symbol_mark_computed (struct attribute *attr, struct symbol *sym, |
| 7462 | const struct comp_unit_head *cu_header, |
| 7463 | struct objfile *objfile) |
| 7464 | { |
| 7465 | if (attr->form == DW_FORM_data4 || attr->form == DW_FORM_data8) |
| 7466 | { |
| 7467 | struct dwarf2_loclist_baton *baton; |
| 7468 | |
| 7469 | baton = obstack_alloc (&objfile->symbol_obstack, |
| 7470 | sizeof (struct dwarf2_loclist_baton)); |
| 7471 | baton->objfile = objfile; |
| 7472 | |
| 7473 | /* We don't know how long the location list is, but make sure we |
| 7474 | don't run off the edge of the section. */ |
| 7475 | baton->size = dwarf_loc_size - DW_UNSND (attr); |
| 7476 | baton->data = dwarf_loc_buffer + DW_UNSND (attr); |
| 7477 | baton->base_address = cu_header->base_address; |
| 7478 | if (cu_header->base_known == 0) |
| 7479 | complaint (&symfile_complaints, |
| 7480 | "Location list used without specifying the CU base address."); |
| 7481 | |
| 7482 | SYMBOL_LOCATION_FUNCS (sym) = &dwarf2_loclist_funcs; |
| 7483 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 7484 | } |
| 7485 | else |
| 7486 | { |
| 7487 | struct dwarf2_locexpr_baton *baton; |
| 7488 | |
| 7489 | baton = obstack_alloc (&objfile->symbol_obstack, |
| 7490 | sizeof (struct dwarf2_locexpr_baton)); |
| 7491 | baton->objfile = objfile; |
| 7492 | |
| 7493 | if (attr_form_is_block (attr)) |
| 7494 | { |
| 7495 | /* Note that we're just copying the block's data pointer |
| 7496 | here, not the actual data. We're still pointing into the |
| 7497 | dwarf_info_buffer for SYM's objfile; right now we never |
| 7498 | release that buffer, but when we do clean up properly |
| 7499 | this may need to change. */ |
| 7500 | baton->size = DW_BLOCK (attr)->size; |
| 7501 | baton->data = DW_BLOCK (attr)->data; |
| 7502 | } |
| 7503 | else |
| 7504 | { |
| 7505 | dwarf2_invalid_attrib_class_complaint ("location description", |
| 7506 | SYMBOL_NATURAL_NAME (sym)); |
| 7507 | baton->size = 0; |
| 7508 | baton->data = NULL; |
| 7509 | } |
| 7510 | |
| 7511 | SYMBOL_LOCATION_FUNCS (sym) = &dwarf2_locexpr_funcs; |
| 7512 | SYMBOL_LOCATION_BATON (sym) = baton; |
| 7513 | } |
| 7514 | } |